1 /* $OpenBSD: rad.h,v 1.21 2021/02/27 10:35:20 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 604800 /* 7 days */ 33 #define ADV_VALID_LIFETIME 2592000 /* 30 days */ 34 #define MAX_SEARCH 1025 /* MAXDNAME in arpa/nameser.h */ 35 #define DEFAULT_RDNS_LIFETIME 600 * 1.5 36 37 #define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE) 38 39 struct imsgev { 40 struct imsgbuf ibuf; 41 void (*handler)(int, short, void *); 42 struct event ev; 43 short events; 44 }; 45 46 enum imsg_type { 47 IMSG_NONE, 48 IMSG_CTL_LOG_VERBOSE, 49 IMSG_CTL_RELOAD, 50 IMSG_RECONF_CONF, 51 IMSG_RECONF_RA_IFACE, 52 IMSG_RECONF_RA_AUTOPREFIX, 53 IMSG_RECONF_RA_PREFIX, 54 IMSG_RECONF_RA_RDNSS, 55 IMSG_RECONF_RA_DNSSL, 56 IMSG_RECONF_END, 57 IMSG_ICMP6SOCK, 58 IMSG_OPEN_ICMP6SOCK, 59 IMSG_ROUTESOCK, 60 IMSG_CONTROLFD, 61 IMSG_STARTUP, 62 IMSG_RA_RS, 63 IMSG_SEND_RA, 64 IMSG_UPDATE_IF, 65 IMSG_REMOVE_IF, 66 IMSG_SOCKET_IPC 67 }; 68 69 /* RFC 8106 */ 70 struct ra_rdnss_conf { 71 SIMPLEQ_ENTRY(ra_rdnss_conf) entry; 72 struct in6_addr rdnss; 73 }; 74 struct ra_dnssl_conf { 75 SIMPLEQ_ENTRY(ra_dnssl_conf) entry; 76 char search[MAX_SEARCH]; 77 }; 78 79 /* RFC 4861 Sections 4.2 and 4.6.4 */ 80 struct ra_options_conf { 81 int dfr; /* is default router? */ 82 int cur_hl; /* current hop limit */ 83 int m_flag; /* managed address conf flag */ 84 int o_flag; /* other conf flag */ 85 int router_lifetime; /* default router lifetime */ 86 uint32_t reachable_time; 87 uint32_t retrans_timer; 88 uint32_t mtu; 89 uint32_t rdns_lifetime; 90 SIMPLEQ_HEAD(, ra_rdnss_conf) ra_rdnss_list; 91 int rdnss_count; 92 SIMPLEQ_HEAD(, ra_dnssl_conf) ra_dnssl_list; 93 int dnssl_len; 94 }; 95 96 /* RFC 4861 Section 4.6.2 */ 97 struct ra_prefix_conf { 98 SIMPLEQ_ENTRY(ra_prefix_conf) entry; 99 struct in6_addr prefix; /* prefix */ 100 int prefixlen; /* prefix length */ 101 uint32_t vltime; /* valid lifetime */ 102 uint32_t pltime; /* prefered lifetime */ 103 int lflag; /* on-link flag*/ 104 int aflag; /* autonom. addr flag */ 105 }; 106 107 struct ra_iface_conf { 108 SIMPLEQ_ENTRY(ra_iface_conf) entry; 109 struct ra_options_conf ra_options; 110 struct ra_prefix_conf *autoprefix; 111 SIMPLEQ_HEAD(ra_prefix_conf_head, 112 ra_prefix_conf) ra_prefix_list; 113 char name[IF_NAMESIZE]; 114 }; 115 116 struct rad_conf { 117 struct ra_options_conf ra_options; 118 SIMPLEQ_HEAD(ra_iface_conf_head, ra_iface_conf) ra_iface_list; 119 }; 120 121 struct imsg_ra_rs { 122 uint32_t if_index; 123 struct sockaddr_in6 from; 124 ssize_t len; 125 uint8_t packet[1500]; 126 }; 127 128 struct imsg_send_ra { 129 uint32_t if_index; 130 struct sockaddr_in6 to; 131 }; 132 133 extern uint32_t cmd_opts; 134 135 /* rad.c */ 136 int main_imsg_compose_frontend(int, int, void *, uint16_t); 137 void main_imsg_compose_engine(int, pid_t, void *, uint16_t); 138 void merge_config(struct rad_conf *, struct rad_conf *); 139 void imsg_event_add(struct imsgev *); 140 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, 141 int, void *, uint16_t); 142 143 struct rad_conf *config_new_empty(void); 144 void config_clear(struct rad_conf *); 145 void free_ra_iface_conf(struct ra_iface_conf *); 146 void free_dns_options(struct ra_options_conf *); 147 void mask_prefix(struct in6_addr*, int len); 148 const char *sin6_to_str(struct sockaddr_in6 *); 149 const char *in6_to_str(struct in6_addr *); 150 151 /* printconf.c */ 152 void print_config(struct rad_conf *); 153 154 /* parse.y */ 155 struct rad_conf *parse_config(char *); 156 int cmdline_symset(char *); 157