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