1 /* $OpenBSD: ospf6d.h,v 1.45 2020/01/21 20:38:52 remi Exp $ */ 2 3 /* 4 * Copyright (c) 2004, 2007 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 _OSPF6D_H_ 21 #define _OSPF6D_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 #include "ospf6.h" 33 #include "log.h" 34 35 #define CONF_FILE "/etc/ospf6d.conf" 36 #define OSPF6D_SOCKET "/var/run/ospf6d.sock" 37 #define OSPF6D_USER "_ospf6d" 38 39 #define NBR_HASHSIZE 128 40 #define LSA_HASHSIZE 512 41 42 #define NBR_IDSELF 1 43 #define NBR_CNTSTART (NBR_IDSELF + 1) 44 45 #define READ_BUF_SIZE 65535 46 #define PKG_DEF_SIZE 512 /* compromise */ 47 #define RT_BUF_SIZE 16384 48 #define MAX_RTSOCK_BUF (2 * 1024 * 1024) 49 50 #define OSPFD_FLAG_NO_FIB_UPDATE 0x0001 51 #define OSPFD_FLAG_STUB_ROUTER 0x0002 52 53 #define F_OSPFD_INSERTED 0x0001 54 #define F_KERNEL 0x0002 55 #define F_CONNECTED 0x0008 56 #define F_DOWN 0x0010 57 #define F_STATIC 0x0020 58 #define F_DYNAMIC 0x0040 59 #define F_REJECT 0x0080 60 #define F_BLACKHOLE 0x0100 61 #define F_REDISTRIBUTED 0x0200 62 63 static const char * const log_procnames[] = { 64 "parent", 65 "ospfe", 66 "rde" 67 }; 68 69 struct imsgev { 70 struct imsgbuf ibuf; 71 void (*handler)(int, short, void *); 72 struct event ev; 73 void *data; 74 short events; 75 }; 76 77 enum imsg_type { 78 IMSG_NONE, 79 IMSG_CTL_RELOAD, 80 IMSG_CTL_SHOW_INTERFACE, 81 IMSG_CTL_SHOW_DATABASE, 82 IMSG_CTL_SHOW_DB_EXT, 83 IMSG_CTL_SHOW_DB_LINK, 84 IMSG_CTL_SHOW_DB_NET, 85 IMSG_CTL_SHOW_DB_RTR, 86 IMSG_CTL_SHOW_DB_INTRA, 87 IMSG_CTL_SHOW_DB_SELF, 88 IMSG_CTL_SHOW_DB_SUM, 89 IMSG_CTL_SHOW_DB_ASBR, 90 IMSG_CTL_SHOW_NBR, 91 IMSG_CTL_SHOW_RIB, 92 IMSG_CTL_SHOW_SUM, 93 IMSG_CTL_SHOW_SUM_AREA, 94 IMSG_CTL_FIB_COUPLE, 95 IMSG_CTL_FIB_DECOUPLE, 96 IMSG_CTL_AREA, 97 IMSG_CTL_IFACE, 98 IMSG_CTL_KROUTE, 99 IMSG_CTL_KROUTE_ADDR, 100 IMSG_CTL_END, 101 IMSG_CTL_LOG_VERBOSE, 102 IMSG_CONTROLFD, 103 IMSG_KROUTE_CHANGE, 104 IMSG_KROUTE_DELETE, 105 IMSG_IFINFO, 106 IMSG_IFADD, 107 IMSG_IFDELETE, 108 IMSG_IFADDRNEW, 109 IMSG_IFADDRDEL, 110 IMSG_NEIGHBOR_UP, 111 IMSG_NEIGHBOR_DOWN, 112 IMSG_NEIGHBOR_CHANGE, 113 IMSG_NETWORK_ADD, 114 IMSG_NETWORK_DEL, 115 IMSG_AREA_CHANGE, 116 IMSG_DD, 117 IMSG_DD_END, 118 IMSG_DB_SNAPSHOT, 119 IMSG_DB_END, 120 IMSG_LS_REQ, 121 IMSG_LS_UPD, 122 IMSG_LS_SNAP, 123 IMSG_LS_ACK, 124 IMSG_LS_FLOOD, 125 IMSG_LS_BADREQ, 126 IMSG_LS_MAXAGE, 127 IMSG_ABR_UP, 128 IMSG_ABR_DOWN, 129 IMSG_RECONF_CONF, 130 IMSG_RECONF_AREA, 131 IMSG_RECONF_END, 132 IMSG_DEMOTE 133 }; 134 135 /* area */ 136 struct vertex; 137 struct rde_nbr; 138 RB_HEAD(lsa_tree, vertex); 139 140 struct area { 141 LIST_ENTRY(area) entry; 142 struct in_addr id; 143 struct lsa_tree lsa_tree; 144 145 LIST_HEAD(, iface) iface_list; 146 LIST_HEAD(, rde_nbr) nbr_list; 147 /* list addr_range_list; */ 148 char demote_group[IFNAMSIZ]; 149 u_int32_t stub_default_cost; 150 u_int32_t num_spf_calc; 151 int active; 152 u_int8_t transit; 153 u_int8_t stub; 154 u_int8_t dirty; 155 u_int8_t demote_level; 156 }; 157 158 /* interface states */ 159 #define IF_STA_NEW 0x00 /* dummy state for reload */ 160 #define IF_STA_DOWN 0x01 161 #define IF_STA_LOOPBACK 0x02 162 #define IF_STA_WAITING 0x04 163 #define IF_STA_POINTTOPOINT 0x08 164 #define IF_STA_DROTHER 0x10 165 #define IF_STA_BACKUP 0x20 166 #define IF_STA_DR 0x40 167 #define IF_STA_DRORBDR (IF_STA_DR | IF_STA_BACKUP) 168 #define IF_STA_MULTI (IF_STA_DROTHER | IF_STA_BACKUP | IF_STA_DR) 169 #define IF_STA_ANY 0x7f 170 171 /* interface events */ 172 enum iface_event { 173 IF_EVT_NOTHING, 174 IF_EVT_UP, 175 IF_EVT_WTIMER, 176 IF_EVT_BACKUP_SEEN, 177 IF_EVT_NBR_CHNG, 178 IF_EVT_LOOP, 179 IF_EVT_UNLOOP, 180 IF_EVT_DOWN 181 }; 182 183 /* interface actions */ 184 enum iface_action { 185 IF_ACT_NOTHING, 186 IF_ACT_STRT, 187 IF_ACT_ELECT, 188 IF_ACT_RST 189 }; 190 191 /* interface types */ 192 enum iface_type { 193 IF_TYPE_POINTOPOINT, 194 IF_TYPE_BROADCAST, 195 IF_TYPE_NBMA, 196 IF_TYPE_POINTOMULTIPOINT, 197 IF_TYPE_VIRTUALLINK 198 }; 199 200 /* neighbor states */ 201 #define NBR_STA_DOWN 0x0001 202 #define NBR_STA_ATTEMPT 0x0002 203 #define NBR_STA_INIT 0x0004 204 #define NBR_STA_2_WAY 0x0008 205 #define NBR_STA_XSTRT 0x0010 206 #define NBR_STA_SNAP 0x0020 207 #define NBR_STA_XCHNG 0x0040 208 #define NBR_STA_LOAD 0x0080 209 #define NBR_STA_FULL 0x0100 210 #define NBR_STA_ACTIVE (~NBR_STA_DOWN) 211 #define NBR_STA_FLOOD (NBR_STA_XCHNG | NBR_STA_LOAD | NBR_STA_FULL) 212 #define NBR_STA_ADJFORM (NBR_STA_XSTRT | NBR_STA_SNAP | NBR_STA_FLOOD) 213 #define NBR_STA_BIDIR (NBR_STA_2_WAY | NBR_STA_ADJFORM) 214 #define NBR_STA_PRELIM (NBR_STA_DOWN | NBR_STA_ATTEMPT | NBR_STA_INIT) 215 #define NBR_STA_ANY 0xffff 216 217 /* neighbor events */ 218 enum nbr_event { 219 NBR_EVT_NOTHING, 220 NBR_EVT_HELLO_RCVD, 221 NBR_EVT_2_WAY_RCVD, 222 NBR_EVT_NEG_DONE, 223 NBR_EVT_SNAP_DONE, 224 NBR_EVT_XCHNG_DONE, 225 NBR_EVT_BAD_LS_REQ, 226 NBR_EVT_LOAD_DONE, 227 NBR_EVT_ADJ_OK, 228 NBR_EVT_SEQ_NUM_MIS, 229 NBR_EVT_1_WAY_RCVD, 230 NBR_EVT_KILL_NBR, 231 NBR_EVT_ITIMER, 232 NBR_EVT_LL_DOWN, 233 NBR_EVT_ADJTMOUT 234 }; 235 236 /* neighbor actions */ 237 enum nbr_action { 238 NBR_ACT_NOTHING, 239 NBR_ACT_RST_ITIMER, 240 NBR_ACT_STRT_ITIMER, 241 NBR_ACT_EVAL, 242 NBR_ACT_SNAP, 243 NBR_ACT_SNAP_DONE, 244 NBR_ACT_XCHNG_DONE, 245 NBR_ACT_ADJ_OK, 246 NBR_ACT_RESTRT_DD, 247 NBR_ACT_DEL, 248 NBR_ACT_CLR_LST, 249 NBR_ACT_HELLO_CHK 250 }; 251 252 /* spf states */ 253 enum spf_state { 254 SPF_IDLE, 255 SPF_DELAY, 256 SPF_HOLD, 257 SPF_HOLDQUEUE 258 }; 259 260 enum dst_type { 261 DT_NET, 262 DT_RTR 263 }; 264 265 enum path_type { 266 PT_INTRA_AREA, 267 PT_INTER_AREA, 268 PT_TYPE1_EXT, 269 PT_TYPE2_EXT 270 }; 271 272 enum rib_type { 273 RIB_NET = 1, 274 RIB_RTR, 275 RIB_EXT 276 }; 277 278 struct iface_addr { 279 TAILQ_ENTRY(iface_addr) entry; 280 struct in6_addr addr; 281 struct in6_addr dstbrd; 282 u_int8_t prefixlen; 283 u_int8_t redistribute; 284 }; 285 286 /* lsa list used in RDE and OE */ 287 TAILQ_HEAD(lsa_head, lsa_entry); 288 289 struct iface { 290 LIST_ENTRY(iface) entry; 291 TAILQ_ENTRY(iface) list; 292 struct event hello_timer; 293 struct event wait_timer; 294 struct event lsack_tx_timer; 295 296 LIST_HEAD(, nbr) nbr_list; 297 TAILQ_HEAD(, iface_addr) ifa_list; 298 struct lsa_head ls_ack_list; 299 300 struct lsa_tree lsa_tree; /* LSA with link local scope */ 301 302 char name[IF_NAMESIZE]; 303 char demote_group[IFNAMSIZ]; 304 char dependon[IFNAMSIZ]; 305 struct in6_addr addr; 306 struct in6_addr dst; 307 struct in_addr abr_id; 308 struct nbr *dr; /* designated router */ 309 struct nbr *bdr; /* backup designated router */ 310 struct nbr *self; 311 struct area *area; 312 313 u_int64_t baudrate; 314 u_int32_t ls_ack_cnt; 315 time_t uptime; 316 unsigned int ifindex; 317 u_int rdomain; 318 int fd; 319 int state; 320 int mtu; 321 int depend_ok; 322 u_int16_t flags; 323 u_int16_t transmit_delay; 324 u_int16_t hello_interval; 325 u_int16_t rxmt_interval; 326 u_int16_t dead_interval; 327 u_int16_t metric; 328 enum iface_type type; 329 u_int8_t if_type; 330 u_int8_t linkstate; 331 u_int8_t priority; 332 u_int8_t cflags; 333 #define F_IFACE_PASSIVE 0x01 334 #define F_IFACE_CONFIGURED 0x02 335 #define F_IFACE_AVAIL 0x04 336 }; 337 338 struct ifaddrchange { 339 struct in6_addr addr; 340 struct in6_addr dstbrd; 341 unsigned int ifindex; 342 u_int8_t prefixlen; 343 }; 344 345 /* ospf_conf */ 346 enum { 347 PROC_MAIN, 348 PROC_OSPF_ENGINE, 349 PROC_RDE_ENGINE 350 } ospfd_process; 351 352 #define REDIST_CONNECTED 0x01 353 #define REDIST_STATIC 0x02 354 #define REDIST_LABEL 0x04 355 #define REDIST_ADDR 0x08 356 #define REDIST_NO 0x10 357 #define REDIST_DEFAULT 0x20 358 359 struct redistribute { 360 SIMPLEQ_ENTRY(redistribute) entry; 361 struct in6_addr addr; 362 u_int32_t metric; 363 u_int16_t label; 364 u_int16_t type; 365 u_int8_t prefixlen; 366 char dependon[IFNAMSIZ]; 367 }; 368 SIMPLEQ_HEAD(redist_list, redistribute); 369 370 struct ospfd_conf { 371 struct event ev; 372 struct in_addr rtr_id; 373 LIST_HEAD(, area) area_list; 374 LIST_HEAD(, vertex) cand_list; 375 struct redist_list redist_list; 376 377 u_int32_t opts; 378 #define OSPFD_OPT_VERBOSE 0x00000001 379 #define OSPFD_OPT_VERBOSE2 0x00000002 380 #define OSPFD_OPT_NOACTION 0x00000004 381 #define OSPFD_OPT_STUB_ROUTER 0x00000008 382 #define OSPFD_OPT_FORCE_DEMOTE 0x00000010 383 u_int32_t spf_delay; 384 u_int32_t spf_hold_time; 385 time_t uptime; 386 int spf_state; 387 int ospf_socket; 388 int flags; 389 int redist_label_or_prefix; 390 u_int8_t border; 391 u_int8_t redistribute; 392 u_int8_t fib_priority; 393 u_int rdomain; 394 char *csock; 395 }; 396 397 /* kroute */ 398 struct kroute { 399 struct in6_addr prefix; 400 struct in6_addr nexthop; 401 u_int32_t ext_tag; 402 u_int32_t metric; 403 unsigned int scope; /* scope of nexthop */ 404 u_int16_t flags; 405 u_int16_t rtlabel; 406 u_short ifindex; 407 u_int8_t prefixlen; 408 u_int8_t priority; 409 }; 410 411 /* name2id */ 412 struct n2id_label { 413 TAILQ_ENTRY(n2id_label) entry; 414 char *name; 415 u_int16_t id; 416 u_int32_t ext_tag; 417 int ref; 418 }; 419 420 TAILQ_HEAD(n2id_labels, n2id_label); 421 extern struct n2id_labels rt_labels; 422 423 /* control data structures */ 424 struct ctl_iface { 425 char name[IF_NAMESIZE]; 426 struct in6_addr addr; 427 struct in_addr area; 428 struct in_addr rtr_id; 429 struct in_addr dr_id; 430 struct in6_addr dr_addr; 431 struct in_addr bdr_id; 432 struct in6_addr bdr_addr; 433 time_t hello_timer; 434 time_t uptime; 435 u_int64_t baudrate; 436 u_int32_t dead_interval; 437 unsigned int ifindex; 438 int state; 439 int mtu; 440 int nbr_cnt; 441 int adj_cnt; 442 u_int16_t transmit_delay; 443 u_int16_t hello_interval; 444 u_int16_t flags; 445 u_int16_t metric; 446 u_int16_t rxmt_interval; 447 enum iface_type type; 448 u_int8_t linkstate; 449 u_int8_t if_type; 450 u_int8_t priority; 451 u_int8_t passive; 452 }; 453 454 struct ctl_nbr { 455 char name[IF_NAMESIZE]; 456 struct in_addr id; 457 struct in6_addr addr; 458 struct in_addr dr; 459 struct in_addr bdr; 460 struct in_addr area; 461 time_t dead_timer; 462 time_t uptime; 463 u_int32_t db_sum_lst_cnt; 464 u_int32_t ls_req_lst_cnt; 465 u_int32_t ls_retrans_lst_cnt; 466 u_int32_t state_chng_cnt; 467 u_int32_t options; 468 int nbr_state; 469 int iface_state; 470 u_int8_t priority; 471 }; 472 473 struct ctl_rt { 474 struct in6_addr prefix; 475 struct in6_addr nexthop; 476 struct in_addr area; 477 struct in_addr adv_rtr; 478 time_t uptime; 479 u_int32_t cost; 480 u_int32_t cost2; 481 unsigned int ifindex; /* scope of nexthop */ 482 enum path_type p_type; 483 enum dst_type d_type; 484 u_int8_t flags; 485 u_int8_t prefixlen; 486 }; 487 488 struct ctl_sum { 489 struct in_addr rtr_id; 490 u_int32_t spf_delay; 491 u_int32_t spf_hold_time; 492 u_int32_t num_ext_lsa; 493 u_int32_t num_area; 494 time_t uptime; 495 }; 496 497 struct ctl_sum_area { 498 struct in_addr area; 499 u_int32_t num_iface; 500 u_int32_t num_adj_nbr; 501 u_int32_t num_spf_calc; 502 u_int32_t num_lsa; 503 }; 504 505 struct demote_msg { 506 char demote_group[IF_NAMESIZE]; 507 int level; 508 }; 509 510 /* area.c */ 511 struct area *area_new(void); 512 int area_del(struct area *); 513 struct area *area_find(struct ospfd_conf *, struct in_addr); 514 void area_track(struct area *); 515 int area_border_router(struct ospfd_conf *); 516 u_int32_t area_ospf_options(struct area *); 517 518 /* carp.c */ 519 int carp_demote_init(char *, int); 520 void carp_demote_shutdown(void); 521 int carp_demote_get(char *); 522 int carp_demote_set(char *, int); 523 524 /* parse.y */ 525 struct ospfd_conf *parse_config(char *, int); 526 int cmdline_symset(char *); 527 void conf_clear_redist_list(struct redist_list *); 528 529 /* interface.c */ 530 int if_init(void); 531 struct iface *if_find(unsigned int); 532 struct iface *if_findname(char *); 533 struct iface *if_new(u_short, char *); 534 void if_update(struct iface *, int, int, u_int8_t, u_int8_t, 535 u_int64_t, u_int32_t); 536 537 /* in_cksum.c */ 538 u_int16_t in_cksum(void *, size_t); 539 540 /* iso_cksum.c */ 541 u_int16_t iso_cksum(void *, u_int16_t, u_int16_t); 542 543 /* kroute.c */ 544 int kr_init(int, u_int, int, u_int8_t); 545 int kr_change(struct kroute *, int); 546 int kr_delete(struct kroute *); 547 void kr_shutdown(void); 548 void kr_fib_couple(void); 549 void kr_fib_decouple(void); 550 void kr_fib_update_prio(u_int8_t); 551 void kr_dispatch_msg(int, short, void *); 552 void kr_show_route(struct imsg *); 553 void kr_reload(int); 554 555 void embedscope(struct sockaddr_in6 *); 556 void recoverscope(struct sockaddr_in6 *); 557 void addscope(struct sockaddr_in6 *, u_int32_t); 558 void clearscope(struct in6_addr *); 559 u_int8_t mask2prefixlen(struct sockaddr_in6 *); 560 struct in6_addr *prefixlen2mask(u_int8_t); 561 void inet6applymask(struct in6_addr *, const struct in6_addr *, int); 562 563 int fetchifs(u_short); 564 565 /* logmsg.h */ 566 const char *log_in6addr(const struct in6_addr *); 567 const char *log_in6addr_scope(const struct in6_addr *, unsigned int); 568 const char *log_rtr_id(u_int32_t); 569 const char *log_sockaddr(void *); 570 const char *nbr_state_name(int); 571 const char *if_state_name(int); 572 const char *if_type_name(enum iface_type); 573 const char *dst_type_name(enum dst_type); 574 const char *path_type_name(enum path_type); 575 576 /* name2id.c */ 577 u_int16_t rtlabel_name2id(const char *); 578 const char *rtlabel_id2name(u_int16_t); 579 void rtlabel_unref(u_int16_t); 580 u_int32_t rtlabel_id2tag(u_int16_t); 581 u_int16_t rtlabel_tag2id(u_int32_t); 582 void rtlabel_tag(u_int16_t, u_int32_t); 583 584 /* ospf6d.c */ 585 void main_imsg_compose_ospfe(int, pid_t, void *, u_int16_t); 586 void main_imsg_compose_ospfe_fd(int, pid_t, int); 587 void main_imsg_compose_rde(int, pid_t, void *, u_int16_t); 588 int ospf_redistribute(struct kroute *, u_int32_t *); 589 void merge_config(struct ospfd_conf *, struct ospfd_conf *); 590 void imsg_event_add(struct imsgev *); 591 int imsg_compose_event(struct imsgev *, u_int16_t, u_int32_t, 592 pid_t, int, void *, u_int16_t); 593 int ifstate_is_up(struct iface *iface); 594 595 /* printconf.c */ 596 void print_config(struct ospfd_conf *); 597 598 #endif /* _OSPF6D_H_ */ 599