1 /* $OpenBSD: rad.h,v 1.26 2024/04/23 22:11:59 florian Exp $ */ 2 3 /* 4 * Copyright (c) 2018 Florian Obser <florian@openbsd.org> 5 * Copyright (c) 2004 Esben Norby <norby@openbsd.org> 6 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> 7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 */ 20 21 #define _PATH_CONF_FILE "/etc/rad.conf" 22 #define _PATH_RAD_SOCKET "/var/run/rad.sock" 23 #define RAD_USER "_rad" 24 25 #define OPT_VERBOSE 0x00000001 26 #define OPT_VERBOSE2 0x00000002 27 #define OPT_NOACTION 0x00000004 28 29 #define MAX_RTR_ADV_INTERVAL 600 30 #define MIN_RTR_ADV_INTERVAL 200 31 #define ADV_DEFAULT_LIFETIME 3 * MAX_RTR_ADV_INTERVAL 32 #define ADV_PREFERRED_LIFETIME 2700 /* 45 minutes */ 33 #define ADV_VALID_LIFETIME 5400 /* 90 minutes */ 34 #define MAX_RA_DELAY_TIME 500 /* 500 milliseconds */ 35 #define MIN_DELAY_BETWEEN_RAS 3 /* 3 seconds */ 36 #define MAX_SEARCH 1025 /* MAXDNAME in arpa/nameser.h */ 37 #define DEFAULT_RDNS_LIFETIME 600 * 1.5 38 39 #define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE) 40 41 struct imsgev { 42 struct imsgbuf ibuf; 43 void (*handler)(int, short, void *); 44 struct event ev; 45 short events; 46 }; 47 48 enum imsg_type { 49 IMSG_NONE, 50 IMSG_CTL_LOG_VERBOSE, 51 IMSG_CTL_RELOAD, 52 IMSG_RECONF_CONF, 53 IMSG_RECONF_RA_IFACE, 54 IMSG_RECONF_RA_AUTOPREFIX, 55 IMSG_RECONF_RA_PREFIX, 56 IMSG_RECONF_RA_RDNSS, 57 IMSG_RECONF_RA_DNSSL, 58 IMSG_RECONF_RA_PREF64, 59 IMSG_RECONF_END, 60 IMSG_ICMP6SOCK, 61 IMSG_OPEN_ICMP6SOCK, 62 IMSG_ROUTESOCK, 63 IMSG_CONTROLFD, 64 IMSG_STARTUP, 65 IMSG_RA_RS, 66 IMSG_SEND_RA, 67 IMSG_UPDATE_IF, 68 IMSG_REMOVE_IF, 69 IMSG_SOCKET_IPC 70 }; 71 72 /* RFC 8106 */ 73 struct ra_rdnss_conf { 74 SIMPLEQ_ENTRY(ra_rdnss_conf) entry; 75 struct in6_addr rdnss; 76 }; 77 struct ra_dnssl_conf { 78 SIMPLEQ_ENTRY(ra_dnssl_conf) entry; 79 char search[MAX_SEARCH]; 80 }; 81 82 /* RFC 8781 Section 4 */ 83 struct ra_pref64_conf { 84 SIMPLEQ_ENTRY(ra_pref64_conf) entry; 85 struct in6_addr prefix; /* prefix */ 86 int prefixlen; /* prefix length */ 87 uint32_t ltime; /* lifetime */ 88 }; 89 90 /* RFC 4861 Sections 4.2 and 4.6.4 */ 91 struct ra_options_conf { 92 int dfr; /* is default router? */ 93 int cur_hl; /* current hop limit */ 94 int m_flag; /* managed address conf flag */ 95 int o_flag; /* other conf flag */ 96 int rtpref; /* router preference */ 97 int router_lifetime; /* default router lifetime */ 98 uint32_t reachable_time; 99 uint32_t retrans_timer; 100 uint32_t mtu; 101 uint32_t rdns_lifetime; 102 SIMPLEQ_HEAD(, ra_rdnss_conf) ra_rdnss_list; 103 int rdnss_count; 104 SIMPLEQ_HEAD(, ra_dnssl_conf) ra_dnssl_list; 105 int dnssl_len; 106 SIMPLEQ_HEAD(, ra_pref64_conf) ra_pref64_list; 107 }; 108 109 /* RFC 4861 Section 4.6.2 */ 110 struct ra_prefix_conf { 111 SIMPLEQ_ENTRY(ra_prefix_conf) entry; 112 struct in6_addr prefix; /* prefix */ 113 int prefixlen; /* prefix length */ 114 uint32_t vltime; /* valid lifetime */ 115 uint32_t pltime; /* preferred lifetime */ 116 int lflag; /* on-link flag*/ 117 int aflag; /* autonom. addr flag */ 118 }; 119 120 struct ra_iface_conf { 121 SIMPLEQ_ENTRY(ra_iface_conf) entry; 122 struct ra_options_conf ra_options; 123 struct ra_prefix_conf *autoprefix; 124 SIMPLEQ_HEAD(ra_prefix_conf_head, 125 ra_prefix_conf) ra_prefix_list; 126 char name[IF_NAMESIZE]; 127 }; 128 129 struct rad_conf { 130 struct ra_options_conf ra_options; 131 SIMPLEQ_HEAD(ra_iface_conf_head, ra_iface_conf) ra_iface_list; 132 }; 133 134 struct imsg_ra_rs { 135 uint32_t if_index; 136 struct sockaddr_in6 from; 137 ssize_t len; 138 uint8_t packet[1500]; 139 }; 140 141 struct imsg_send_ra { 142 uint32_t if_index; 143 struct sockaddr_in6 to; 144 }; 145 146 extern uint32_t cmd_opts; 147 148 /* rad.c */ 149 int main_imsg_compose_frontend(int, int, void *, uint16_t); 150 void main_imsg_compose_engine(int, pid_t, void *, uint16_t); 151 void merge_config(struct rad_conf *, struct rad_conf *); 152 void imsg_event_add(struct imsgev *); 153 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, 154 int, void *, uint16_t); 155 156 struct rad_conf *config_new_empty(void); 157 void config_clear(struct rad_conf *); 158 void free_ra_iface_conf(struct ra_iface_conf *); 159 void free_dns_options(struct ra_options_conf *); 160 void mask_prefix(struct in6_addr*, int len); 161 const char *sin6_to_str(struct sockaddr_in6 *); 162 const char *in6_to_str(struct in6_addr *); 163 164 /* printconf.c */ 165 void print_config(struct rad_conf *); 166 167 /* parse.y */ 168 struct rad_conf *parse_config(char *); 169 int cmdline_symset(char *); 170