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