1 /* $OpenBSD: rad.h,v 1.18 2020/03/30 17:47:48 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 CONF_FILE "/etc/rad.conf" 22 #define 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 enum { 40 PROC_MAIN, 41 PROC_ENGINE, 42 PROC_FRONTEND 43 } rad_process; 44 45 static const char * const log_procnames[] = { 46 "main", 47 "engine", 48 "frontend", 49 }; 50 51 struct imsgev { 52 struct imsgbuf ibuf; 53 void (*handler)(int, short, void *); 54 struct event ev; 55 short events; 56 }; 57 58 enum imsg_type { 59 IMSG_NONE, 60 IMSG_CTL_LOG_VERBOSE, 61 IMSG_CTL_RELOAD, 62 IMSG_RECONF_CONF, 63 IMSG_RECONF_RA_IFACE, 64 IMSG_RECONF_RA_AUTOPREFIX, 65 IMSG_RECONF_RA_PREFIX, 66 IMSG_RECONF_RA_RDNSS, 67 IMSG_RECONF_RA_DNSSL, 68 IMSG_RECONF_END, 69 IMSG_ICMP6SOCK, 70 IMSG_ROUTESOCK, 71 IMSG_CONTROLFD, 72 IMSG_STARTUP, 73 IMSG_STARTUP_DONE, 74 IMSG_RA_RS, 75 IMSG_SEND_RA, 76 IMSG_UPDATE_IF, 77 IMSG_REMOVE_IF, 78 IMSG_SOCKET_IPC 79 }; 80 81 /* RFC 8106 */ 82 struct ra_rdnss_conf { 83 SIMPLEQ_ENTRY(ra_rdnss_conf) entry; 84 struct in6_addr rdnss; 85 }; 86 struct ra_dnssl_conf { 87 SIMPLEQ_ENTRY(ra_dnssl_conf) entry; 88 char search[MAX_SEARCH]; 89 }; 90 91 /* RFC 4861 Sections 4.2 and 4.6.4 */ 92 struct ra_options_conf { 93 int dfr; /* is default router? */ 94 int cur_hl; /* current hop limit */ 95 int m_flag; /* managed address conf flag */ 96 int o_flag; /* other conf flag */ 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 }; 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; /* prefered 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 void main_imsg_compose_frontend(int, pid_t, void *, uint16_t); 149 void main_imsg_compose_frontend_fd(int, pid_t, int); 150 151 void main_imsg_compose_engine(int, pid_t, void *, uint16_t); 152 void merge_config(struct rad_conf *, struct rad_conf *); 153 void imsg_event_add(struct imsgev *); 154 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, 155 int, void *, uint16_t); 156 157 struct rad_conf *config_new_empty(void); 158 void config_clear(struct rad_conf *); 159 void free_ra_iface_conf(struct ra_iface_conf *); 160 void free_dns_options(struct ra_options_conf *); 161 void mask_prefix(struct in6_addr*, int len); 162 const char *sin6_to_str(struct sockaddr_in6 *); 163 const char *in6_to_str(struct in6_addr *); 164 165 /* printconf.c */ 166 void print_config(struct rad_conf *); 167 168 /* parse.y */ 169 struct rad_conf *parse_config(char *); 170 int cmdline_symset(char *); 171