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