1 /* $OpenBSD: dvmrpd.h,v 1.21 2015/09/27 17:29:45 stsp Exp $ */ 2 3 /* 4 * Copyright (c) 2004, 2005, 2006 Esben Norby <norby@openbsd.org> 5 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #ifndef _DVMRPD_H_ 21 #define _DVMRPD_H_ 22 23 #include <sys/queue.h> 24 #include <sys/socket.h> 25 #include <sys/time.h> 26 #include <sys/tree.h> 27 #include <net/if.h> 28 #include <netinet/in.h> 29 #include <event.h> 30 31 #include <imsg.h> 32 33 #define CONF_FILE "/etc/dvmrpd.conf" 34 #define DVMRPD_SOCKET "/var/run/dvmrpd.sock" 35 #define DVMRPD_USER "_dvmrpd" 36 37 #define NBR_HASHSIZE 128 38 39 #define NBR_IDSELF 1 40 #define NBR_CNTSTART (NBR_IDSELF + 1) 41 42 #define RT_BUF_SIZE 16384 43 44 #define DVMRPD_FLAG_NO_FIB_UPDATE 0x0001 45 46 #define F_DVMRPD_INSERTED 0x0001 47 #define F_KERNEL 0x0002 48 #define F_CONNECTED 0x0004 49 #define F_DOWN 0x0010 50 #define F_STATIC 0x0020 51 #define F_LONGER 0x0040 52 53 #define MAXVIFS 32 /* XXX */ 54 55 struct imsgev { 56 struct imsgbuf ibuf; 57 void (*handler)(int, short, void *); 58 struct event ev; 59 void *data; 60 short events; 61 }; 62 63 enum imsg_type { 64 IMSG_NONE, 65 IMSG_CTL_RELOAD, 66 IMSG_CTL_SHOW_IFACE, 67 IMSG_CTL_SHOW_IGMP, 68 IMSG_CTL_SHOW_NBR, 69 IMSG_CTL_SHOW_RIB, 70 IMSG_CTL_SHOW_MFC, 71 IMSG_CTL_MFC_COUPLE, 72 IMSG_CTL_MFC_DECOUPLE, 73 IMSG_CTL_KROUTE, 74 IMSG_CTL_KROUTE_ADDR, 75 IMSG_CTL_IFINFO, 76 IMSG_CTL_SHOW_SUM, 77 IMSG_CTL_END, 78 IMSG_CTL_LOG_VERBOSE, 79 IMSG_IFINFO, 80 IMSG_ROUTE_REPORT, 81 IMSG_FULL_ROUTE_REPORT, 82 IMSG_FULL_ROUTE_REPORT_END, 83 IMSG_MFC_ADD, 84 IMSG_MFC_DEL, 85 IMSG_GROUP_ADD, 86 IMSG_GROUP_DEL, 87 IMSG_NBR_DEL, 88 IMSG_SEND_PRUNE, 89 IMSG_RECV_PRUNE, 90 IMSG_FLASH_UPDATE, 91 IMSG_FLASH_UPDATE_DS 92 }; 93 94 /* interface states */ 95 #define IF_STA_DOWN 0x01 96 #define IF_STA_QUERIER 0x02 97 #define IF_STA_NONQUERIER 0x04 98 #define IF_STA_ANY 0x07 99 #define IF_STA_ACTIVE (~IF_STA_DOWN) 100 101 /* interface events */ 102 enum iface_event { 103 IF_EVT_NOTHING, 104 IF_EVT_UP, 105 IF_EVT_QTMOUT, /* query timer expired */ 106 IF_EVT_QRECVD, /* query received, check for lower IP */ 107 IF_EVT_QPRSNTTMOUT, /* other querier present timeout */ 108 IF_EVT_DOWN 109 }; 110 111 /* interface actions */ 112 enum iface_action { 113 IF_ACT_NOTHING, 114 IF_ACT_STRT, 115 IF_ACT_QPRSNT, 116 IF_ACT_RST 117 }; 118 119 /* interface types */ 120 enum iface_type { 121 IF_TYPE_POINTOPOINT, 122 IF_TYPE_BROADCAST 123 }; 124 125 /* neighbor states */ 126 #define NBR_STA_DOWN 0x01 127 #define NBR_STA_1_WAY 0x02 128 #define NBR_STA_2_WAY 0x04 129 #define NBR_STA_ACTIVE (~NBR_STA_DOWN) 130 #define NBR_STA_ANY 0xff 131 132 struct group { 133 TAILQ_ENTRY(group) entry; 134 struct event dead_timer; 135 struct event v1_host_timer; 136 struct event retrans_timer; 137 138 struct in_addr addr; 139 140 struct iface *iface; 141 142 time_t uptime; 143 int state; 144 }; 145 146 struct rde_group { 147 TAILQ_ENTRY(rde_group) entry; 148 struct in_addr rde_group; 149 }; 150 151 struct mfc { 152 struct in_addr origin; 153 struct in_addr group; 154 u_short ifindex; 155 u_int8_t ttls[MAXVIFS]; 156 }; 157 158 struct prune { 159 struct in_addr origin; 160 struct in_addr netmask; 161 struct in_addr group; 162 struct in_addr nexthop; 163 u_short ifindex; 164 u_int32_t lifetime; 165 }; 166 167 struct nbr_msg { 168 struct in_addr address; 169 unsigned int ifindex; 170 }; 171 172 TAILQ_HEAD(rr_head, rr_entry); 173 RB_HEAD(src_head, src_node); 174 175 struct iface { 176 LIST_ENTRY(iface) entry; 177 struct event probe_timer; 178 struct event query_timer; 179 struct event querier_present_timer; 180 time_t uptime; 181 LIST_HEAD(, nbr) nbr_list; 182 TAILQ_HEAD(, group) group_list; 183 TAILQ_HEAD(, rde_group) rde_group_list; 184 struct rr_head rr_list; 185 186 char name[IF_NAMESIZE]; 187 struct in_addr addr; 188 struct in_addr dst; 189 struct in_addr mask; 190 struct in_addr querier; /* designated querier */ 191 192 u_int64_t baudrate; 193 u_int32_t gen_id; 194 u_int32_t group_cnt; 195 u_int32_t probe_interval; 196 197 u_int32_t query_interval; 198 u_int32_t query_resp_interval; 199 u_int32_t recv_query_resp_interval; 200 u_int32_t group_member_interval; 201 u_int32_t querier_present_interval; 202 u_int32_t startup_query_interval; 203 u_int32_t startup_query_cnt; 204 u_int32_t last_member_query_interval; 205 u_int32_t last_member_query_cnt; 206 u_int32_t last_member_query_time; 207 u_int32_t v1_querier_present_tmout; 208 u_int32_t v1_host_present_interval; 209 u_int32_t startup_query_counter; /* actual counter */ 210 u_int32_t dead_interval; 211 212 unsigned int ifindex; /* ifindex and vif */ 213 int fd; 214 int state; 215 int mtu; 216 int nbr_cnt; 217 int adj_cnt; 218 219 u_int16_t flags; 220 u_int16_t metric; 221 enum iface_type type; 222 223 u_int8_t robustness; 224 u_int8_t linkstate; 225 u_int8_t if_type; 226 u_int8_t passive; 227 u_int8_t igmp_version; 228 }; 229 230 /* dvmrp_conf */ 231 enum { 232 PROC_MAIN, 233 PROC_DVMRP_ENGINE, 234 PROC_RDE_ENGINE 235 } dvmrpd_process; 236 237 struct dvmrpd_conf { 238 struct event ev; 239 struct event report_timer; 240 u_int32_t gen_id; 241 u_int32_t opts; 242 #define DVMRPD_OPT_VERBOSE 0x00000001 243 #define DVMRPD_OPT_VERBOSE2 0x00000002 244 #define DVMRPD_OPT_NOACTION 0x00000004 245 int maxdepth; 246 LIST_HEAD(, iface) iface_list; 247 int dvmrp_socket; 248 int mroute_socket; 249 int flags; 250 }; 251 252 /* kroute */ 253 struct kroute { 254 struct in_addr prefix; 255 struct in_addr nexthop; 256 u_int16_t flags; 257 u_short ifindex; 258 u_int8_t prefixlen; 259 }; 260 261 struct kif { 262 char ifname[IF_NAMESIZE]; 263 u_int64_t baudrate; 264 int flags; 265 int mtu; 266 u_short ifindex; 267 u_int8_t if_type; 268 u_int8_t link_state; 269 u_int8_t nh_reachable; /* for nexthop verification */ 270 }; 271 272 /* control data structures */ 273 struct ctl_iface { 274 char name[IF_NAMESIZE]; 275 struct in_addr addr; 276 struct in_addr mask; 277 struct in_addr querier; 278 279 time_t probe_timer; 280 time_t query_timer; 281 time_t querier_present_timer; 282 time_t uptime; 283 284 u_int64_t baudrate; 285 u_int32_t gen_id; 286 u_int32_t group_cnt; 287 u_int32_t probe_interval; 288 u_int32_t query_interval; 289 u_int32_t query_resp_interval; 290 u_int32_t recv_query_resp_interval; 291 u_int32_t group_member_interval; 292 u_int32_t querier_present_interval; 293 u_int32_t startup_query_interval; 294 u_int32_t startup_query_cnt; 295 u_int32_t last_member_query_interval; 296 u_int32_t last_member_query_cnt; 297 u_int32_t last_member_query_time; 298 u_int32_t v1_querier_present_tmout; 299 u_int32_t v1_host_present_interval; 300 u_int32_t dead_interval; 301 302 unsigned int ifindex; 303 int state; 304 int mtu; 305 int nbr_cnt; 306 int adj_cnt; 307 308 u_int16_t flags; 309 u_int16_t metric; 310 enum iface_type type; 311 u_int8_t robustness; 312 u_int8_t linkstate; 313 u_int8_t if_type; 314 u_int8_t passive; 315 u_int8_t igmp_version; 316 }; 317 318 struct ctl_group { 319 time_t dead_timer; 320 time_t v1_host_timer; 321 time_t retrans_timer; 322 time_t uptime; 323 struct in_addr addr; 324 int state; 325 }; 326 327 struct ctl_nbr { 328 char name[IF_NAMESIZE]; 329 struct in_addr id; 330 struct in_addr addr; 331 time_t dead_timer; 332 time_t uptime; 333 int state; 334 }; 335 336 struct ctl_rt { 337 struct in_addr prefix; 338 struct in_addr nexthop; 339 struct in_addr area; 340 struct in_addr adv_rtr; 341 time_t uptime; 342 time_t expire; 343 u_int32_t cost; 344 u_int8_t flags; 345 u_int8_t prefixlen; 346 }; 347 348 struct ctl_mfc { 349 u_int8_t ttls[MAXVIFS]; /* outgoing vif(s) */ 350 struct in_addr origin; 351 struct in_addr group; 352 time_t uptime; 353 time_t expire; 354 u_short ifindex; /* incoming vif */ 355 }; 356 357 struct ctl_sum { 358 struct in_addr rtr_id; 359 u_int32_t hold_time; 360 }; 361 362 /* dvmrpd.c */ 363 void main_imsg_compose_dvmrpe(int, pid_t, void *, u_int16_t); 364 365 /* parse.y */ 366 struct dvmrpd_conf *parse_config(char *, int); 367 int cmdline_symset(char *); 368 369 int imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t, pid_t, 370 int, void *, u_int16_t); 371 void imsg_event_add(struct imsgev *); 372 373 /* in_cksum.c */ 374 u_int16_t in_cksum(void *, size_t); 375 376 /* kroute.c */ 377 int kif_init(void); 378 void kif_clear(void); 379 int kr_init(void); 380 void kr_shutdown(void); 381 void kr_dispatch_msg(int, short, void *); 382 void kr_ifinfo(char *); 383 struct kif *kif_findname(char *); 384 385 u_int8_t prefixlen_classful(in_addr_t); 386 u_int8_t mask2prefixlen(in_addr_t); 387 in_addr_t prefixlen2mask(u_int8_t); 388 389 /* kmroute.c */ 390 int kmr_init(int); 391 void kmr_shutdown(void); 392 void kmr_recv_msg(int, short, void *); 393 void kmr_mfc_couple(void); 394 void kmr_mfc_decouple(void); 395 void kmroute_clear(void); 396 int mrt_init(int); 397 int mrt_done(int); 398 int mrt_add_vif(int, struct iface *); 399 void mrt_del_vif(int, struct iface *); 400 int mrt_add_mfc(int, struct mfc *); 401 int mrt_del_mfc(int, struct mfc *); 402 403 /* log.h */ 404 const char *nbr_state_name(int); 405 const char *if_state_name(int); 406 const char *if_type_name(enum iface_type); 407 const char *group_state_name(int); 408 409 /* printconf.c */ 410 void print_config(struct dvmrpd_conf *); 411 412 /* interface.c */ 413 struct iface *if_find_index(u_short); 414 415 #define PREFIX_SIZE(x) (((x) + 7) / 8) 416 417 #endif /* _DVMRPD_H_ */ 418