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