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