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