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