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