1 /* $OpenBSD: rad.h,v 1.25 2023/04/27 16:56:52 phessler 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 router_lifetime; /* default router lifetime */ 97 uint32_t reachable_time; 98 uint32_t retrans_timer; 99 uint32_t mtu; 100 uint32_t rdns_lifetime; 101 SIMPLEQ_HEAD(, ra_rdnss_conf) ra_rdnss_list; 102 int rdnss_count; 103 SIMPLEQ_HEAD(, ra_dnssl_conf) ra_dnssl_list; 104 int dnssl_len; 105 SIMPLEQ_HEAD(, ra_pref64_conf) ra_pref64_list; 106 }; 107 108 /* RFC 4861 Section 4.6.2 */ 109 struct ra_prefix_conf { 110 SIMPLEQ_ENTRY(ra_prefix_conf) entry; 111 struct in6_addr prefix; /* prefix */ 112 int prefixlen; /* prefix length */ 113 uint32_t vltime; /* valid lifetime */ 114 uint32_t pltime; /* preferred lifetime */ 115 int lflag; /* on-link flag*/ 116 int aflag; /* autonom. addr flag */ 117 }; 118 119 struct ra_iface_conf { 120 SIMPLEQ_ENTRY(ra_iface_conf) entry; 121 struct ra_options_conf ra_options; 122 struct ra_prefix_conf *autoprefix; 123 SIMPLEQ_HEAD(ra_prefix_conf_head, 124 ra_prefix_conf) ra_prefix_list; 125 char name[IF_NAMESIZE]; 126 }; 127 128 struct rad_conf { 129 struct ra_options_conf ra_options; 130 SIMPLEQ_HEAD(ra_iface_conf_head, ra_iface_conf) ra_iface_list; 131 }; 132 133 struct imsg_ra_rs { 134 uint32_t if_index; 135 struct sockaddr_in6 from; 136 ssize_t len; 137 uint8_t packet[1500]; 138 }; 139 140 struct imsg_send_ra { 141 uint32_t if_index; 142 struct sockaddr_in6 to; 143 }; 144 145 extern uint32_t cmd_opts; 146 147 /* rad.c */ 148 int main_imsg_compose_frontend(int, int, void *, uint16_t); 149 void main_imsg_compose_engine(int, pid_t, void *, uint16_t); 150 void merge_config(struct rad_conf *, struct rad_conf *); 151 void imsg_event_add(struct imsgev *); 152 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, 153 int, void *, uint16_t); 154 155 struct rad_conf *config_new_empty(void); 156 void config_clear(struct rad_conf *); 157 void free_ra_iface_conf(struct ra_iface_conf *); 158 void free_dns_options(struct ra_options_conf *); 159 void mask_prefix(struct in6_addr*, int len); 160 const char *sin6_to_str(struct sockaddr_in6 *); 161 const char *in6_to_str(struct in6_addr *); 162 163 /* printconf.c */ 164 void print_config(struct rad_conf *); 165 166 /* parse.y */ 167 struct rad_conf *parse_config(char *); 168 int cmdline_symset(char *); 169