1 /* $OpenBSD: bgpd.h,v 1.483 2024/01/23 16:13:35 claudio Exp $ */ 2 3 /* 4 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 #ifndef __BGPD_H__ 19 #define __BGPD_H__ 20 21 #include <sys/types.h> 22 #include <sys/socket.h> 23 #include <sys/queue.h> 24 #include <sys/tree.h> 25 #include <netinet/in.h> 26 #include <arpa/inet.h> 27 #include <net/if.h> 28 29 #include <poll.h> 30 #include <stdarg.h> 31 #include <stdint.h> 32 33 #include <imsg.h> 34 35 #define BGP_VERSION 4 36 #define BGP_PORT 179 37 #define RTR_PORT 323 38 #define CONFFILE "/etc/bgpd.conf" 39 #define BGPD_USER "_bgpd" 40 #define PEER_DESCR_LEN 32 41 #define REASON_LEN 256 /* includes NUL terminator */ 42 #define PFTABLE_LEN 32 43 #define ROUTELABEL_LEN 32 44 #define TCP_MD5_KEY_LEN 80 45 #define IPSEC_ENC_KEY_LEN 32 46 #define IPSEC_AUTH_KEY_LEN 20 47 #define SET_NAME_LEN 128 48 49 #define MAX_PKTSIZE 4096 50 #define MIN_HOLDTIME 3 51 #define READ_BUF_SIZE 65535 52 #define MAX_SOCK_BUF (4 * READ_BUF_SIZE) 53 #define RT_BUF_SIZE 16384 54 #define MAX_RTSOCK_BUF (2 * 1024 * 1024) 55 #define MAX_COMM_MATCH 3 56 57 #define BGPD_OPT_VERBOSE 0x0001 58 #define BGPD_OPT_VERBOSE2 0x0002 59 #define BGPD_OPT_NOACTION 0x0004 60 #define BGPD_OPT_FORCE_DEMOTE 0x0008 61 62 #define BGPD_FLAG_REFLECTOR 0x0004 63 #define BGPD_FLAG_NEXTHOP_BGP 0x0010 64 #define BGPD_FLAG_NEXTHOP_DEFAULT 0x0020 65 #define BGPD_FLAG_DECISION_MASK 0x0f00 66 #define BGPD_FLAG_DECISION_ROUTEAGE 0x0100 67 #define BGPD_FLAG_DECISION_TRANS_AS 0x0200 68 #define BGPD_FLAG_DECISION_MED_ALWAYS 0x0400 69 #define BGPD_FLAG_DECISION_ALL_PATHS 0x0800 70 #define BGPD_FLAG_NO_AS_SET 0x1000 71 72 #define BGPD_LOG_UPDATES 0x0001 73 74 #define SOCKET_NAME "/var/run/bgpd.sock" 75 76 #define F_BGPD 0x0001 77 #define F_BGPD_INSERTED 0x0002 78 #define F_CONNECTED 0x0004 79 #define F_STATIC 0x0008 80 #define F_NEXTHOP 0x0010 81 #define F_REJECT 0x0020 82 #define F_BLACKHOLE 0x0040 83 #define F_MPLS 0x0080 84 #define F_LONGER 0x0200 85 #define F_SHORTER 0x0400 86 #define F_CTL_DETAIL 0x1000 /* only set on requests */ 87 #define F_CTL_ADJ_IN 0x2000 /* only set on requests */ 88 #define F_CTL_ADJ_OUT 0x4000 /* only set on requests */ 89 #define F_CTL_BEST 0x8000 90 #define F_CTL_INELIGIBLE 0x10000 /* only set on requests */ 91 #define F_CTL_LEAKED 0x20000 /* only set on requests */ 92 #define F_CTL_INVALID 0x40000 /* only set on requests */ 93 #define F_CTL_OVS_VALID 0x80000 94 #define F_CTL_OVS_INVALID 0x100000 95 #define F_CTL_OVS_NOTFOUND 0x200000 96 #define F_CTL_NEIGHBORS 0x400000 /* only used by bgpctl */ 97 #define F_CTL_HAS_PATHID 0x800000 /* only set on requests */ 98 #define F_CTL_AVS_VALID 0x1000000 99 #define F_CTL_AVS_INVALID 0x2000000 100 #define F_CTL_AVS_UNKNOWN 0x4000000 101 #define F_CTL_SSV 0x80000000 /* only used by bgpctl */ 102 103 #define CTASSERT(x) extern char _ctassert[(x) ? 1 : -1 ] \ 104 __attribute__((__unused__)) 105 106 /* 107 * Note that these numeric assignments differ from the numbers commonly 108 * used in route origin validation context. 109 */ 110 #define ROA_NOTFOUND 0x0 /* default */ 111 #define ROA_INVALID 0x1 112 #define ROA_VALID 0x2 113 #define ROA_MASK 0x3 114 115 #define ASPA_UNKNOWN 0x00 /* default */ 116 #define ASPA_INVALID 0x01 117 #define ASPA_VALID 0x02 118 #define ASPA_MASK 0x03 119 #define ASPA_NEVER_KNOWN 0x08 /* unknown and check never needed */ 120 121 /* 122 * Limit the number of messages queued in the session engine. 123 * The SE will send an IMSG_XOFF messages to the RDE if the high water mark 124 * is reached. The RDE should then throttle this peer or control connection. 125 * Once the message queue in the SE drops below the low water mark an 126 * IMSG_XON message will be sent and the RDE will produce more messages again. 127 */ 128 #define RDE_RUNNER_ROUNDS 100 129 #define SESS_MSG_HIGH_MARK 2000 130 #define SESS_MSG_LOW_MARK 500 131 #define CTL_MSG_HIGH_MARK 500 132 #define CTL_MSG_LOW_MARK 100 133 134 enum bgpd_process { 135 PROC_MAIN, 136 PROC_SE, 137 PROC_RDE, 138 PROC_RTR, 139 }; 140 141 enum reconf_action { 142 RECONF_NONE, 143 RECONF_KEEP, 144 RECONF_REINIT, 145 RECONF_RELOAD, 146 RECONF_DELETE 147 }; 148 149 /* Address Family Numbers as per RFC 1700 */ 150 #define AFI_UNSPEC 0 151 #define AFI_IPv4 1 152 #define AFI_IPv6 2 153 154 /* Subsequent Address Family Identifier as per RFC 4760 */ 155 #define SAFI_NONE 0 156 #define SAFI_UNICAST 1 157 #define SAFI_MULTICAST 2 158 #define SAFI_MPLS 4 159 #define SAFI_MPLSVPN 128 160 #define SAFI_FLOWSPEC 133 161 #define SAFI_VPNFLOWSPEC 134 162 163 struct aid { 164 uint16_t afi; 165 sa_family_t af; 166 uint8_t safi; 167 const char *name; 168 }; 169 170 extern const struct aid aid_vals[]; 171 172 #define AID_UNSPEC 0 173 #define AID_INET 1 174 #define AID_INET6 2 175 #define AID_VPN_IPv4 3 176 #define AID_VPN_IPv6 4 177 #define AID_FLOWSPECv4 5 178 #define AID_FLOWSPECv6 6 179 #define AID_MAX 7 180 #define AID_MIN 1 /* skip AID_UNSPEC since that is a dummy */ 181 182 #define AID_VALS { \ 183 /* afi, af, safii, name */ \ 184 { AFI_UNSPEC, AF_UNSPEC, SAFI_NONE, "unspec"}, \ 185 { AFI_IPv4, AF_INET, SAFI_UNICAST, "IPv4 unicast" }, \ 186 { AFI_IPv6, AF_INET6, SAFI_UNICAST, "IPv6 unicast" }, \ 187 { AFI_IPv4, AF_INET, SAFI_MPLSVPN, "IPv4 vpn" }, \ 188 { AFI_IPv6, AF_INET6, SAFI_MPLSVPN, "IPv6 vpn" }, \ 189 { AFI_IPv4, AF_INET, SAFI_FLOWSPEC, "IPv4 flowspec" }, \ 190 { AFI_IPv6, AF_INET6, SAFI_FLOWSPEC, "IPv6 flowspec" }, \ 191 } 192 193 #define BGP_MPLS_BOS 0x01 194 195 struct bgpd_addr { 196 union { 197 struct in_addr v4; 198 struct in6_addr v6; 199 /* maximum size for a prefix is 256 bits */ 200 } ba; /* 128-bit address */ 201 uint64_t rd; /* route distinguisher for VPN addrs */ 202 uint32_t scope_id; /* iface scope id for v6 */ 203 uint8_t aid; 204 uint8_t labellen; /* size of the labelstack */ 205 uint8_t labelstack[18]; /* max that makes sense */ 206 #define v4 ba.v4 207 #define v6 ba.v6 208 }; 209 210 #define DEFAULT_LISTENER 0x01 211 #define LISTENER_LISTENING 0x02 212 213 struct listen_addr { 214 TAILQ_ENTRY(listen_addr) entry; 215 struct sockaddr_storage sa; 216 int fd; 217 enum reconf_action reconf; 218 socklen_t sa_len; 219 uint8_t flags; 220 }; 221 222 TAILQ_HEAD(listen_addrs, listen_addr); 223 TAILQ_HEAD(filter_set_head, filter_set); 224 225 struct peer; 226 RB_HEAD(peer_head, peer); 227 228 struct l3vpn; 229 SIMPLEQ_HEAD(l3vpn_head, l3vpn); 230 231 struct network; 232 TAILQ_HEAD(network_head, network); 233 234 struct flowspec_config; 235 RB_HEAD(flowspec_tree, flowspec_config); 236 237 struct prefixset; 238 SIMPLEQ_HEAD(prefixset_head, prefixset); 239 struct prefixset_item; 240 RB_HEAD(prefixset_tree, prefixset_item); 241 242 struct tentry_v4; 243 struct tentry_v6; 244 struct trie_head { 245 struct tentry_v4 *root_v4; 246 struct tentry_v6 *root_v6; 247 int match_default_v4; 248 int match_default_v6; 249 size_t v4_cnt; 250 size_t v6_cnt; 251 }; 252 253 struct rde_prefixset { 254 char name[SET_NAME_LEN]; 255 struct trie_head th; 256 SIMPLEQ_ENTRY(rde_prefixset) entry; 257 time_t lastchange; 258 int dirty; 259 }; 260 SIMPLEQ_HEAD(rde_prefixset_head, rde_prefixset); 261 262 struct roa { 263 RB_ENTRY(roa) entry; 264 uint8_t aid; 265 uint8_t prefixlen; 266 uint8_t maxlen; 267 uint8_t pad; 268 uint32_t asnum; 269 time_t expires; 270 union { 271 struct in_addr inet; 272 struct in6_addr inet6; 273 } prefix; 274 }; 275 276 RB_HEAD(roa_tree, roa); 277 struct aspa_set; 278 RB_HEAD(aspa_tree, aspa_set); 279 280 struct set_table; 281 struct as_set; 282 SIMPLEQ_HEAD(as_set_head, as_set); 283 284 struct filter_rule; 285 TAILQ_HEAD(filter_head, filter_rule); 286 287 struct rtr_config; 288 SIMPLEQ_HEAD(rtr_config_head, rtr_config); 289 290 struct bgpd_config { 291 struct peer_head peers; 292 struct l3vpn_head l3vpns; 293 struct network_head networks; 294 struct flowspec_tree flowspecs; 295 struct filter_head *filters; 296 struct listen_addrs *listen_addrs; 297 struct mrt_head *mrt; 298 struct prefixset_head prefixsets; 299 struct prefixset_head originsets; 300 struct roa_tree roa; 301 struct aspa_tree aspa; 302 struct rde_prefixset_head rde_prefixsets; 303 struct rde_prefixset_head rde_originsets; 304 struct as_set_head as_sets; 305 struct rtr_config_head rtrs; 306 char *csock; 307 char *rcsock; 308 int flags; 309 int log; 310 u_int default_tableid; 311 uint32_t bgpid; 312 uint32_t clusterid; 313 uint32_t as; 314 uint16_t short_as; 315 uint16_t holdtime; 316 uint16_t min_holdtime; 317 uint16_t connectretry; 318 uint8_t fib_priority; 319 }; 320 321 extern int cmd_opts; 322 323 enum addpath_mode { 324 ADDPATH_EVAL_NONE, 325 ADDPATH_EVAL_BEST, 326 ADDPATH_EVAL_ECMP, 327 ADDPATH_EVAL_AS_WIDE, 328 ADDPATH_EVAL_ALL, 329 }; 330 331 struct addpath_eval { 332 enum addpath_mode mode; 333 int extrapaths; 334 int maxpaths; 335 }; 336 337 enum export_type { 338 EXPORT_UNSET, 339 EXPORT_NONE, 340 EXPORT_DEFAULT_ROUTE 341 }; 342 343 enum enforce_as { 344 ENFORCE_AS_UNDEF, 345 ENFORCE_AS_OFF, 346 ENFORCE_AS_ON 347 }; 348 349 enum role { 350 ROLE_NONE, 351 ROLE_CUSTOMER, 352 ROLE_PROVIDER, 353 ROLE_RS, 354 ROLE_RS_CLIENT, 355 ROLE_PEER, 356 }; 357 358 enum auth_method { 359 AUTH_NONE, 360 AUTH_MD5SIG, 361 AUTH_IPSEC_MANUAL_ESP, 362 AUTH_IPSEC_MANUAL_AH, 363 AUTH_IPSEC_IKE_ESP, 364 AUTH_IPSEC_IKE_AH 365 }; 366 367 enum auth_alg { 368 AUTH_AALG_NONE, 369 AUTH_AALG_SHA1HMAC, 370 AUTH_AALG_MD5HMAC, 371 }; 372 373 enum auth_enc_alg { 374 AUTH_EALG_NONE, 375 AUTH_EALG_3DESCBC, 376 AUTH_EALG_AES, 377 }; 378 379 struct peer_auth { 380 char md5key[TCP_MD5_KEY_LEN]; 381 char auth_key_in[IPSEC_AUTH_KEY_LEN]; 382 char auth_key_out[IPSEC_AUTH_KEY_LEN]; 383 char enc_key_in[IPSEC_ENC_KEY_LEN]; 384 char enc_key_out[IPSEC_ENC_KEY_LEN]; 385 uint32_t spi_in; 386 uint32_t spi_out; 387 enum auth_method method; 388 enum auth_alg auth_alg_in; 389 enum auth_alg auth_alg_out; 390 enum auth_enc_alg enc_alg_in; 391 enum auth_enc_alg enc_alg_out; 392 uint8_t md5key_len; 393 uint8_t auth_keylen_in; 394 uint8_t auth_keylen_out; 395 uint8_t enc_keylen_in; 396 uint8_t enc_keylen_out; 397 }; 398 399 struct capabilities { 400 struct { 401 int16_t timeout; /* graceful restart timeout */ 402 int8_t flags[AID_MAX]; /* graceful restart per AID flags */ 403 int8_t restart; /* graceful restart, RFC 4724 */ 404 } grestart; 405 int8_t mp[AID_MAX]; /* multiprotocol extensions, RFC 4760 */ 406 int8_t add_path[AID_MAX]; /* ADD_PATH, RFC 7911 */ 407 int8_t refresh; /* route refresh, RFC 2918 */ 408 int8_t as4byte; /* 4-byte ASnum, RFC 4893 */ 409 int8_t enhanced_rr; /* enhanced route refresh, RFC 7313 */ 410 int8_t policy; /* Open Policy, RFC 9234, 2 = enforce */ 411 }; 412 413 /* flags for RFC 4724 - graceful restart */ 414 #define CAPA_GR_PRESENT 0x01 415 #define CAPA_GR_RESTART 0x02 416 #define CAPA_GR_FORWARD 0x04 417 #define CAPA_GR_RESTARTING 0x08 418 #define CAPA_GR_TIMEMASK 0x0fff 419 #define CAPA_GR_R_FLAG 0x8000 420 #define CAPA_GR_F_FLAG 0x80 421 422 /* flags for RFC 7911 - enhanced router refresh */ 423 #define CAPA_AP_RECV 0x01 424 #define CAPA_AP_SEND 0x02 425 #define CAPA_AP_BIDIR 0x03 426 427 /* values for RFC 9234 - BGP Open Policy */ 428 #define CAPA_ROLE_PROVIDER 0x00 429 #define CAPA_ROLE_RS 0x01 430 #define CAPA_ROLE_RS_CLIENT 0x02 431 #define CAPA_ROLE_CUSTOMER 0x03 432 #define CAPA_ROLE_PEER 0x04 433 434 struct peer_config { 435 struct bgpd_addr remote_addr; 436 struct bgpd_addr local_addr_v4; 437 struct bgpd_addr local_addr_v6; 438 struct peer_auth auth; 439 struct capabilities capabilities; 440 struct addpath_eval eval; 441 char group[PEER_DESCR_LEN]; 442 char descr[PEER_DESCR_LEN]; 443 char reason[REASON_LEN]; 444 char rib[PEER_DESCR_LEN]; 445 char if_depend[IFNAMSIZ]; 446 char demote_group[IFNAMSIZ]; 447 uint32_t id; 448 uint32_t groupid; 449 uint32_t remote_as; 450 uint32_t local_as; 451 uint32_t max_prefix; 452 uint32_t max_out_prefix; 453 enum export_type export_type; 454 enum enforce_as enforce_as; 455 enum enforce_as enforce_local_as; 456 enum role role; 457 uint16_t max_prefix_restart; 458 uint16_t max_out_prefix_restart; 459 uint16_t holdtime; 460 uint16_t min_holdtime; 461 uint16_t local_short_as; 462 uint16_t remote_port; 463 uint8_t template; 464 uint8_t remote_masklen; 465 uint8_t ebgp; /* 0 = ibgp else ebgp */ 466 uint8_t distance; /* 1 = direct, >1 = multihop */ 467 uint8_t passive; 468 uint8_t down; 469 uint8_t announce_capa; 470 uint8_t reflector_client; 471 uint8_t ttlsec; /* TTL security hack */ 472 uint8_t flags; 473 }; 474 475 #define PEER_ID_NONE 0 476 #define PEER_ID_SELF 1 477 #define PEER_ID_STATIC_MIN 2 /* exclude self */ 478 #define PEER_ID_STATIC_MAX (UINT_MAX / 2) 479 #define PEER_ID_DYN_MAX UINT_MAX 480 481 #define PEERFLAG_TRANS_AS 0x01 482 #define PEERFLAG_LOG_UPDATES 0x02 483 #define PEERFLAG_EVALUATE_ALL 0x04 484 #define PEERFLAG_NO_AS_SET 0x08 485 486 struct rde_peer_stats { 487 uint64_t prefix_rcvd_update; 488 uint64_t prefix_rcvd_withdraw; 489 uint64_t prefix_rcvd_eor; 490 uint64_t prefix_sent_update; 491 uint64_t prefix_sent_withdraw; 492 uint64_t prefix_sent_eor; 493 uint32_t prefix_cnt; 494 uint32_t prefix_out_cnt; 495 uint32_t pending_update; 496 uint32_t pending_withdraw; 497 }; 498 499 enum network_type { 500 NETWORK_DEFAULT, /* from network statements */ 501 NETWORK_STATIC, 502 NETWORK_CONNECTED, 503 NETWORK_RTLABEL, 504 NETWORK_MRTCLONE, 505 NETWORK_PRIORITY, 506 NETWORK_PREFIXSET, 507 }; 508 509 struct network_config { 510 struct bgpd_addr prefix; 511 struct filter_set_head attrset; 512 char psname[SET_NAME_LEN]; 513 uint64_t rd; 514 enum network_type type; 515 uint16_t rtlabel; 516 uint8_t prefixlen; 517 uint8_t priority; 518 uint8_t old; /* used for reloading */ 519 }; 520 521 struct network { 522 struct network_config net; 523 TAILQ_ENTRY(network) entry; 524 }; 525 526 struct flowspec { 527 uint16_t len; 528 uint8_t aid; 529 uint8_t flags; 530 uint8_t data[1]; 531 }; 532 #define FLOWSPEC_SIZE (offsetof(struct flowspec, data)) 533 534 struct flowspec_config { 535 RB_ENTRY(flowspec_config) entry; 536 struct filter_set_head attrset; 537 struct flowspec *flow; 538 enum reconf_action reconf_action; 539 }; 540 541 enum rtr_error { 542 NO_ERROR = -1, 543 CORRUPT_DATA = 0, 544 INTERNAL_ERROR, 545 NO_DATA_AVAILABLE, 546 INVALID_REQUEST, 547 UNSUPP_PROTOCOL_VERS, 548 UNSUPP_PDU_TYPE, 549 UNK_REC_WDRAWL, 550 DUP_REC_RECV, 551 UNEXP_PROTOCOL_VERS, 552 }; 553 554 struct rtr_config { 555 SIMPLEQ_ENTRY(rtr_config) entry; 556 char descr[PEER_DESCR_LEN]; 557 struct bgpd_addr remote_addr; 558 struct bgpd_addr local_addr; 559 uint32_t id; 560 uint16_t remote_port; 561 }; 562 563 struct ctl_show_rtr { 564 char descr[PEER_DESCR_LEN]; 565 char state[PEER_DESCR_LEN]; 566 struct bgpd_addr remote_addr; 567 struct bgpd_addr local_addr; 568 uint32_t serial; 569 uint32_t refresh; 570 uint32_t retry; 571 uint32_t expire; 572 int session_id; 573 uint16_t remote_port; 574 uint8_t version; 575 enum rtr_error last_sent_error; 576 enum rtr_error last_recv_error; 577 char last_sent_msg[REASON_LEN]; 578 char last_recv_msg[REASON_LEN]; 579 }; 580 581 enum imsg_type { 582 IMSG_NONE, 583 IMSG_CTL_END, 584 IMSG_CTL_RELOAD, 585 IMSG_CTL_FIB_COUPLE, 586 IMSG_CTL_FIB_DECOUPLE, 587 IMSG_CTL_NEIGHBOR_UP, 588 IMSG_CTL_NEIGHBOR_DOWN, 589 IMSG_CTL_NEIGHBOR_CLEAR, 590 IMSG_CTL_NEIGHBOR_RREFRESH, 591 IMSG_CTL_NEIGHBOR_DESTROY, 592 IMSG_CTL_KROUTE, 593 IMSG_CTL_KROUTE_ADDR, 594 IMSG_CTL_RESULT, 595 IMSG_CTL_SHOW_NEIGHBOR, 596 IMSG_CTL_SHOW_NEXTHOP, 597 IMSG_CTL_SHOW_INTERFACE, 598 IMSG_CTL_SHOW_RIB, 599 IMSG_CTL_SHOW_RIB_PREFIX, 600 IMSG_CTL_SHOW_RIB_COMMUNITIES, 601 IMSG_CTL_SHOW_RIB_ATTR, 602 IMSG_CTL_SHOW_NETWORK, 603 IMSG_CTL_SHOW_FLOWSPEC, 604 IMSG_CTL_SHOW_RIB_MEM, 605 IMSG_CTL_SHOW_TERSE, 606 IMSG_CTL_SHOW_TIMER, 607 IMSG_CTL_LOG_VERBOSE, 608 IMSG_CTL_SHOW_FIB_TABLES, 609 IMSG_CTL_SHOW_SET, 610 IMSG_CTL_SHOW_RTR, 611 IMSG_CTL_TERMINATE, 612 IMSG_NETWORK_ADD, 613 IMSG_NETWORK_ASPATH, 614 IMSG_NETWORK_ATTR, 615 IMSG_NETWORK_REMOVE, 616 IMSG_NETWORK_FLUSH, 617 IMSG_NETWORK_DONE, 618 IMSG_FLOWSPEC_ADD, 619 IMSG_FLOWSPEC_DONE, 620 IMSG_FLOWSPEC_REMOVE, 621 IMSG_FLOWSPEC_FLUSH, 622 IMSG_FILTER_SET, 623 IMSG_SOCKET_CONN, 624 IMSG_SOCKET_CONN_CTL, 625 IMSG_SOCKET_CONN_RTR, 626 IMSG_RECONF_CONF, 627 IMSG_RECONF_RIB, 628 IMSG_RECONF_PEER, 629 IMSG_RECONF_FILTER, 630 IMSG_RECONF_LISTENER, 631 IMSG_RECONF_CTRL, 632 IMSG_RECONF_VPN, 633 IMSG_RECONF_VPN_EXPORT, 634 IMSG_RECONF_VPN_IMPORT, 635 IMSG_RECONF_VPN_DONE, 636 IMSG_RECONF_PREFIX_SET, 637 IMSG_RECONF_PREFIX_SET_ITEM, 638 IMSG_RECONF_AS_SET, 639 IMSG_RECONF_AS_SET_ITEMS, 640 IMSG_RECONF_AS_SET_DONE, 641 IMSG_RECONF_ORIGIN_SET, 642 IMSG_RECONF_ROA_SET, 643 IMSG_RECONF_ROA_ITEM, 644 IMSG_RECONF_ASPA, 645 IMSG_RECONF_ASPA_TAS, 646 IMSG_RECONF_ASPA_DONE, 647 IMSG_RECONF_ASPA_PREP, 648 IMSG_RECONF_RTR_CONFIG, 649 IMSG_RECONF_DRAIN, 650 IMSG_RECONF_DONE, 651 IMSG_UPDATE, 652 IMSG_UPDATE_ERR, 653 IMSG_SESSION_ADD, 654 IMSG_SESSION_UP, 655 IMSG_SESSION_DOWN, 656 IMSG_SESSION_STALE, 657 IMSG_SESSION_NOGRACE, 658 IMSG_SESSION_FLUSH, 659 IMSG_SESSION_RESTARTED, 660 IMSG_SESSION_DEPENDON, 661 IMSG_PFKEY_RELOAD, 662 IMSG_MRT_OPEN, 663 IMSG_MRT_REOPEN, 664 IMSG_MRT_CLOSE, 665 IMSG_KROUTE_CHANGE, 666 IMSG_KROUTE_DELETE, 667 IMSG_KROUTE_FLUSH, 668 IMSG_NEXTHOP_ADD, 669 IMSG_NEXTHOP_REMOVE, 670 IMSG_NEXTHOP_UPDATE, 671 IMSG_PFTABLE_ADD, 672 IMSG_PFTABLE_REMOVE, 673 IMSG_PFTABLE_COMMIT, 674 IMSG_REFRESH, 675 IMSG_DEMOTE, 676 IMSG_XON, 677 IMSG_XOFF 678 }; 679 680 struct demote_msg { 681 char demote_group[IFNAMSIZ]; 682 int level; 683 }; 684 685 enum ctl_results { 686 CTL_RES_OK, 687 CTL_RES_NOSUCHPEER, 688 CTL_RES_DENIED, 689 CTL_RES_NOCAP, 690 CTL_RES_PARSE_ERROR, 691 CTL_RES_PENDING, 692 CTL_RES_NOMEM, 693 CTL_RES_BADPEER, 694 CTL_RES_BADSTATE, 695 CTL_RES_NOSUCHRIB, 696 CTL_RES_OPNOTSUPP, 697 }; 698 699 /* needed for session.h parse prototype */ 700 LIST_HEAD(mrt_head, mrt); 701 702 /* error codes and subcodes needed in SE and RDE */ 703 enum err_codes { 704 ERR_HEADER = 1, 705 ERR_OPEN, 706 ERR_UPDATE, 707 ERR_HOLDTIMEREXPIRED, 708 ERR_FSM, 709 ERR_CEASE, 710 ERR_RREFRESH 711 }; 712 713 enum suberr_update { 714 ERR_UPD_UNSPECIFIC, 715 ERR_UPD_ATTRLIST, 716 ERR_UPD_UNKNWN_WK_ATTR, 717 ERR_UPD_MISSNG_WK_ATTR, 718 ERR_UPD_ATTRFLAGS, 719 ERR_UPD_ATTRLEN, 720 ERR_UPD_ORIGIN, 721 ERR_UPD_LOOP, 722 ERR_UPD_NEXTHOP, 723 ERR_UPD_OPTATTR, 724 ERR_UPD_NETWORK, 725 ERR_UPD_ASPATH 726 }; 727 728 enum suberr_cease { 729 ERR_CEASE_MAX_PREFIX = 1, 730 ERR_CEASE_ADMIN_DOWN, 731 ERR_CEASE_PEER_UNCONF, 732 ERR_CEASE_ADMIN_RESET, 733 ERR_CEASE_CONN_REJECT, 734 ERR_CEASE_OTHER_CHANGE, 735 ERR_CEASE_COLLISION, 736 ERR_CEASE_RSRC_EXHAUST, 737 ERR_CEASE_HARD_RESET, 738 ERR_CEASE_MAX_SENT_PREFIX 739 }; 740 741 enum suberr_rrefresh { 742 ERR_RR_INV_LEN = 1 743 }; 744 745 struct kroute; 746 struct kroute6; 747 struct knexthop; 748 struct kredist_node; 749 RB_HEAD(kroute_tree, kroute); 750 RB_HEAD(kroute6_tree, kroute6); 751 RB_HEAD(knexthop_tree, knexthop); 752 RB_HEAD(kredist_tree, kredist_node); 753 754 struct ktable { 755 char descr[PEER_DESCR_LEN]; 756 struct kroute_tree krt; 757 struct kroute6_tree krt6; 758 struct knexthop_tree knt; 759 struct kredist_tree kredist; 760 struct network_head krn; 761 u_int rtableid; 762 u_int nhtableid; /* rdomain id for nexthop lookup */ 763 int nhrefcnt; /* refcnt for nexthop table */ 764 enum reconf_action state; 765 uint8_t fib_conf; /* configured FIB sync flag */ 766 uint8_t fib_sync; /* is FIB synced with kernel? */ 767 }; 768 769 struct kroute_full { 770 struct bgpd_addr prefix; 771 struct bgpd_addr nexthop; 772 char label[ROUTELABEL_LEN]; 773 uint32_t mplslabel; 774 uint16_t flags; 775 u_short ifindex; 776 uint8_t prefixlen; 777 uint8_t priority; 778 }; 779 780 struct kroute_nexthop { 781 struct bgpd_addr nexthop; 782 struct bgpd_addr gateway; 783 struct bgpd_addr net; 784 uint8_t netlen; 785 uint8_t valid; 786 uint8_t connected; 787 }; 788 789 struct session_dependon { 790 char ifname[IFNAMSIZ]; 791 uint8_t depend_state; /* for session depend on */ 792 }; 793 794 struct session_up { 795 struct bgpd_addr local_v4_addr; 796 struct bgpd_addr local_v6_addr; 797 struct bgpd_addr remote_addr; 798 struct capabilities capa; 799 uint32_t remote_bgpid; 800 unsigned int if_scope; 801 uint16_t short_as; 802 }; 803 804 struct route_refresh { 805 uint8_t aid; 806 uint8_t subtype; 807 }; 808 #define ROUTE_REFRESH_REQUEST 0 809 #define ROUTE_REFRESH_BEGIN_RR 1 810 #define ROUTE_REFRESH_END_RR 2 811 812 struct pftable_msg { 813 struct bgpd_addr addr; 814 char pftable[PFTABLE_LEN]; 815 uint8_t len; 816 }; 817 818 struct ctl_show_interface { 819 char ifname[IFNAMSIZ]; 820 char linkstate[32]; 821 char media[32]; 822 uint64_t baudrate; 823 u_int rdomain; 824 uint8_t nh_reachable; 825 uint8_t is_up; 826 }; 827 828 struct ctl_show_nexthop { 829 struct bgpd_addr addr; 830 struct ctl_show_interface iface; 831 struct kroute_full kr; 832 uint8_t valid; 833 uint8_t krvalid; 834 }; 835 836 struct ctl_show_set { 837 char name[SET_NAME_LEN]; 838 time_t lastchange; 839 size_t v4_cnt; 840 size_t v6_cnt; 841 size_t as_cnt; 842 enum { 843 ASNUM_SET, 844 PREFIX_SET, 845 ORIGIN_SET, 846 ROA_SET, 847 ASPA_SET, 848 } type; 849 }; 850 851 struct ctl_neighbor { 852 struct bgpd_addr addr; 853 char descr[PEER_DESCR_LEN]; 854 char reason[REASON_LEN]; 855 int show_timers; 856 int is_group; 857 }; 858 859 #define F_PREF_ELIGIBLE 0x001 860 #define F_PREF_BEST 0x002 861 #define F_PREF_INTERNAL 0x004 862 #define F_PREF_ANNOUNCE 0x008 863 #define F_PREF_STALE 0x010 864 #define F_PREF_INVALID 0x020 865 #define F_PREF_PATH_ID 0x040 866 #define F_PREF_OTC_LEAK 0x080 867 #define F_PREF_ECMP 0x100 868 #define F_PREF_AS_WIDE 0x200 869 870 struct ctl_show_rib { 871 struct bgpd_addr true_nexthop; 872 struct bgpd_addr exit_nexthop; 873 struct bgpd_addr prefix; 874 struct bgpd_addr remote_addr; 875 char descr[PEER_DESCR_LEN]; 876 time_t age; 877 uint32_t remote_id; 878 uint32_t path_id; 879 uint32_t local_pref; 880 uint32_t med; 881 uint32_t weight; 882 uint32_t flags; 883 uint8_t prefixlen; 884 uint8_t origin; 885 uint8_t roa_validation_state; 886 uint8_t aspa_validation_state; 887 int8_t dmetric; 888 /* plus an aspath */ 889 }; 890 891 enum as_spec { 892 AS_UNDEF, 893 AS_ALL, 894 AS_SOURCE, 895 AS_TRANSIT, 896 AS_PEER, 897 AS_EMPTY 898 }; 899 900 enum aslen_spec { 901 ASLEN_NONE, 902 ASLEN_MAX, 903 ASLEN_SEQ 904 }; 905 906 #define AS_FLAG_NEIGHBORAS 0x01 907 #define AS_FLAG_AS_SET_NAME 0x02 908 #define AS_FLAG_AS_SET 0x04 909 910 struct filter_as { 911 char name[SET_NAME_LEN]; 912 struct as_set *aset; 913 uint32_t as_min; 914 uint32_t as_max; 915 enum as_spec type; 916 uint8_t flags; 917 uint8_t op; 918 }; 919 920 struct filter_aslen { 921 u_int aslen; 922 enum aslen_spec type; 923 }; 924 925 #define PREFIXSET_FLAG_FILTER 0x01 926 #define PREFIXSET_FLAG_DIRTY 0x02 /* prefix-set changed at reload */ 927 #define PREFIXSET_FLAG_OPS 0x04 /* indiv. prefixes have prefixlenops */ 928 #define PREFIXSET_FLAG_LONGER 0x08 /* filter all prefixes with or-longer */ 929 930 struct filter_prefixset { 931 int flags; 932 char name[SET_NAME_LEN]; 933 struct rde_prefixset *ps; 934 }; 935 936 struct filter_originset { 937 char name[SET_NAME_LEN]; 938 struct rde_prefixset *ps; 939 }; 940 941 struct filter_vs { 942 uint8_t validity; 943 uint8_t is_set; 944 }; 945 946 /* 947 * Communities are encoded depending on their type. The low byte of flags 948 * is the COMMUNITY_TYPE (BASIC, LARGE, EXT). BASIC encoding is just using 949 * data1 and data2, LARGE uses all data fields and EXT is also using all 950 * data fields. The 4-byte flags fields consists of up to 3 data flags 951 * for e.g. COMMUNITY_ANY and the low byte is the community type. 952 * If flags is 0 the community struct is unused. If the upper 24bit of 953 * flags is 0 a fast compare can be used. 954 * The code uses a type cast to uint8_t to access the type. 955 */ 956 struct community { 957 uint32_t flags; 958 uint32_t data1; 959 uint32_t data2; 960 uint32_t data3; 961 }; 962 963 struct ctl_show_rib_request { 964 char rib[PEER_DESCR_LEN]; 965 struct ctl_neighbor neighbor; 966 struct bgpd_addr prefix; 967 struct filter_as as; 968 struct community community; 969 uint32_t flags; 970 uint32_t path_id; 971 pid_t pid; 972 enum imsg_type type; 973 uint8_t validation_state; 974 uint8_t prefixlen; 975 uint8_t aid; 976 }; 977 978 struct ctl_kroute_req { 979 int flags; 980 sa_family_t af; 981 }; 982 983 enum filter_actions { 984 ACTION_NONE, 985 ACTION_ALLOW, 986 ACTION_DENY 987 }; 988 989 enum directions { 990 DIR_IN = 1, 991 DIR_OUT 992 }; 993 994 enum from_spec { 995 FROM_ALL, 996 FROM_ADDRESS, 997 FROM_DESCR, 998 FROM_GROUP 999 }; 1000 1001 enum comp_ops { 1002 OP_NONE, 1003 OP_RANGE, 1004 OP_XRANGE, 1005 OP_EQ, 1006 OP_NE, 1007 OP_LE, 1008 OP_LT, 1009 OP_GE, 1010 OP_GT 1011 }; 1012 1013 struct filter_peers { 1014 uint32_t peerid; 1015 uint32_t groupid; 1016 uint32_t remote_as; 1017 uint16_t ribid; 1018 uint8_t ebgp; 1019 uint8_t ibgp; 1020 }; 1021 1022 /* special community type, keep in sync with the attribute type */ 1023 #define COMMUNITY_TYPE_NONE 0 1024 #define COMMUNITY_TYPE_BASIC 8 1025 #define COMMUNITY_TYPE_EXT 16 1026 #define COMMUNITY_TYPE_LARGE 32 1027 1028 #define COMMUNITY_ANY 1 1029 #define COMMUNITY_NEIGHBOR_AS 2 1030 #define COMMUNITY_LOCAL_AS 3 1031 1032 /* wellknown community definitions */ 1033 #define COMMUNITY_WELLKNOWN 0xffff 1034 #define COMMUNITY_GRACEFUL_SHUTDOWN 0x0000 /* RFC 8326 */ 1035 #define COMMUNITY_BLACKHOLE 0x029A /* RFC 7999 */ 1036 #define COMMUNITY_NO_EXPORT 0xff01 1037 #define COMMUNITY_NO_ADVERTISE 0xff02 1038 #define COMMUNITY_NO_EXPSUBCONFED 0xff03 1039 #define COMMUNITY_NO_PEER 0xff04 /* RFC 3765 */ 1040 1041 /* extended community definitions */ 1042 #define EXT_COMMUNITY_IANA 0x80 1043 #define EXT_COMMUNITY_NON_TRANSITIVE 0x40 1044 #define EXT_COMMUNITY_VALUE 0x3f 1045 /* extended transitive types */ 1046 #define EXT_COMMUNITY_TRANS_TWO_AS 0x00 /* 2 octet AS specific */ 1047 #define EXT_COMMUNITY_TRANS_IPV4 0x01 /* IPv4 specific */ 1048 #define EXT_COMMUNITY_TRANS_FOUR_AS 0x02 /* 4 octet AS specific */ 1049 #define EXT_COMMUNITY_TRANS_OPAQUE 0x03 /* opaque ext community */ 1050 #define EXT_COMMUNITY_TRANS_EVPN 0x06 /* EVPN RFC 7432 */ 1051 /* extended non-transitive types */ 1052 #define EXT_COMMUNITY_NON_TRANS_TWO_AS 0x40 /* 2 octet AS specific */ 1053 #define EXT_COMMUNITY_NON_TRANS_IPV4 0x41 /* IPv4 specific */ 1054 #define EXT_COMMUNITY_NON_TRANS_FOUR_AS 0x42 /* 4 octet AS specific */ 1055 #define EXT_COMMUNITY_NON_TRANS_OPAQUE 0x43 /* opaque ext community */ 1056 #define EXT_COMMUNITY_UNKNOWN -1 1057 /* generic transitive types */ 1058 #define EXT_COMMUNITY_GEN_TWO_AS 0x80 /* 2 octet AS specific */ 1059 #define EXT_COMMUNITY_GEN_IPV4 0x81 /* IPv4 specific */ 1060 #define EXT_COMMUNITY_GEN_FOUR_AS 0x82 /* 4 octet AS specific */ 1061 1062 /* BGP Origin Validation State Extended Community RFC 8097 */ 1063 #define EXT_COMMUNITY_SUBTYPE_OVS 0 1064 #define EXT_COMMUNITY_OVS_VALID 0 1065 #define EXT_COMMUNITY_OVS_NOTFOUND 1 1066 #define EXT_COMMUNITY_OVS_INVALID 2 1067 1068 /* other handy defines */ 1069 #define EXT_COMMUNITY_OPAQUE_MAX 0xffffffffffffULL 1070 #define EXT_COMMUNITY_FLAG_VALID 0x01 1071 1072 struct ext_comm_pairs { 1073 uint8_t type; 1074 uint8_t subtype; 1075 const char *subname; 1076 }; 1077 1078 #define IANA_EXT_COMMUNITIES { \ 1079 { EXT_COMMUNITY_TRANS_TWO_AS, 0x02, "rt" }, \ 1080 { EXT_COMMUNITY_TRANS_TWO_AS, 0x03, "soo" }, \ 1081 { EXT_COMMUNITY_TRANS_TWO_AS, 0x05, "odi" }, \ 1082 { EXT_COMMUNITY_TRANS_TWO_AS, 0x08, "bdc" }, \ 1083 { EXT_COMMUNITY_TRANS_TWO_AS, 0x09, "srcas" }, \ 1084 { EXT_COMMUNITY_TRANS_TWO_AS, 0x0a, "l2vid" }, \ 1085 \ 1086 { EXT_COMMUNITY_TRANS_FOUR_AS, 0x02, "rt" }, \ 1087 { EXT_COMMUNITY_TRANS_FOUR_AS, 0x03, "soo" }, \ 1088 { EXT_COMMUNITY_TRANS_FOUR_AS, 0x05, "odi" }, \ 1089 { EXT_COMMUNITY_TRANS_FOUR_AS, 0x08, "bdc" }, \ 1090 { EXT_COMMUNITY_TRANS_FOUR_AS, 0x09, "srcas" }, \ 1091 \ 1092 { EXT_COMMUNITY_TRANS_IPV4, 0x02, "rt" }, \ 1093 { EXT_COMMUNITY_TRANS_IPV4, 0x03, "soo" }, \ 1094 { EXT_COMMUNITY_TRANS_IPV4, 0x05, "odi" }, \ 1095 { EXT_COMMUNITY_TRANS_IPV4, 0x07, "ori" }, \ 1096 { EXT_COMMUNITY_TRANS_IPV4, 0x0a, "l2vid" }, \ 1097 { EXT_COMMUNITY_TRANS_IPV4, 0x0b, "vrfri" }, \ 1098 \ 1099 { EXT_COMMUNITY_TRANS_OPAQUE, 0x06, "ort" }, \ 1100 { EXT_COMMUNITY_TRANS_OPAQUE, 0x0d, "defgw" }, \ 1101 \ 1102 { EXT_COMMUNITY_NON_TRANS_OPAQUE, EXT_COMMUNITY_SUBTYPE_OVS, "ovs" }, \ 1103 \ 1104 { EXT_COMMUNITY_TRANS_EVPN, 0x00, "mac-mob" }, \ 1105 { EXT_COMMUNITY_TRANS_EVPN, 0x01, "esi-lab" }, \ 1106 { EXT_COMMUNITY_TRANS_EVPN, 0x02, "esi-rt" }, \ 1107 \ 1108 { EXT_COMMUNITY_GEN_TWO_AS, 0x06, "flow-rate" }, \ 1109 { EXT_COMMUNITY_GEN_TWO_AS, 0x0c, "flow-pps" }, \ 1110 { EXT_COMMUNITY_GEN_TWO_AS, 0x07, "flow-action" }, \ 1111 { EXT_COMMUNITY_GEN_TWO_AS, 0x08, "flow-rt-redir" }, \ 1112 { EXT_COMMUNITY_GEN_IPV4, 0x08, "flow-rt-redir" }, \ 1113 { EXT_COMMUNITY_GEN_FOUR_AS, 0x08, "flow-rt-redir" }, \ 1114 { EXT_COMMUNITY_GEN_TWO_AS, 0x09, "flow-dscp" }, \ 1115 \ 1116 { 0 } \ 1117 } 1118 1119 extern const struct ext_comm_pairs iana_ext_comms[]; 1120 1121 /* BGP flowspec defines RFC 8955 and 8956 */ 1122 #define FLOWSPEC_LEN_LIMIT 0xf0 1123 #define FLOWSPEC_OP_EOL 0x80 1124 #define FLOWSPEC_OP_AND 0x40 1125 #define FLOWSPEC_OP_LEN_MASK 0x30 1126 #define FLOWSPEC_OP_LEN_SHIFT 4 1127 #define FLOWSPEC_OP_LEN(op) \ 1128 (1 << (((op) & FLOWSPEC_OP_LEN_MASK) >> FLOWSPEC_OP_LEN_SHIFT)) 1129 #define FLOWSPEC_OP_NUM_LT 0x04 1130 #define FLOWSPEC_OP_NUM_GT 0x02 1131 #define FLOWSPEC_OP_NUM_EQ 0x01 1132 #define FLOWSPEC_OP_NUM_LE (FLOWSPEC_OP_NUM_LT | FLOWSPEC_OP_NUM_EQ) 1133 #define FLOWSPEC_OP_NUM_GE (FLOWSPEC_OP_NUM_GT | FLOWSPEC_OP_NUM_EQ) 1134 #define FLOWSPEC_OP_NUM_NOT (FLOWSPEC_OP_NUM_GT | FLOWSPEC_OP_NUM_LT) 1135 #define FLOWSPEC_OP_NUM_MASK 0x07 1136 #define FLOWSPEC_OP_BIT_NOT 0x02 1137 #define FLOWSPEC_OP_BIT_MATCH 0x01 1138 #define FLOWSPEC_OP_BIT_MASK 0x03 1139 1140 #define FLOWSPEC_TYPE_MIN 1 1141 #define FLOWSPEC_TYPE_DEST 1 1142 #define FLOWSPEC_TYPE_SOURCE 2 1143 #define FLOWSPEC_TYPE_PROTO 3 1144 #define FLOWSPEC_TYPE_PORT 4 1145 #define FLOWSPEC_TYPE_DST_PORT 5 1146 #define FLOWSPEC_TYPE_SRC_PORT 6 1147 #define FLOWSPEC_TYPE_ICMP_TYPE 7 1148 #define FLOWSPEC_TYPE_ICMP_CODE 8 1149 #define FLOWSPEC_TYPE_TCP_FLAGS 9 1150 #define FLOWSPEC_TYPE_PKT_LEN 10 1151 #define FLOWSPEC_TYPE_DSCP 11 1152 #define FLOWSPEC_TYPE_FRAG 12 1153 #define FLOWSPEC_TYPE_FLOW 13 1154 #define FLOWSPEC_TYPE_MAX 14 1155 1156 #define FLOWSPEC_TCP_FLAG_STRING "FSRPAUEW" 1157 #define FLOWSPEC_FRAG_STRING4 "DIFL" 1158 #define FLOWSPEC_FRAG_STRING6 " IFL" 1159 1160 struct filter_prefix { 1161 struct bgpd_addr addr; 1162 uint8_t op; 1163 uint8_t len; 1164 uint8_t len_min; 1165 uint8_t len_max; 1166 }; 1167 1168 struct filter_nexthop { 1169 struct bgpd_addr addr; 1170 uint8_t flags; 1171 #define FILTER_NEXTHOP_ADDR 1 1172 #define FILTER_NEXTHOP_NEIGHBOR 2 1173 }; 1174 1175 struct filter_match { 1176 struct filter_prefix prefix; 1177 struct filter_nexthop nexthop; 1178 struct filter_as as; 1179 struct filter_aslen aslen; 1180 struct community community[MAX_COMM_MATCH]; 1181 struct filter_prefixset prefixset; 1182 struct filter_originset originset; 1183 struct filter_vs ovs; 1184 struct filter_vs avs; 1185 int maxcomm; 1186 int maxextcomm; 1187 int maxlargecomm; 1188 }; 1189 1190 struct filter_rule { 1191 TAILQ_ENTRY(filter_rule) entry; 1192 char rib[PEER_DESCR_LEN]; 1193 struct filter_peers peer; 1194 struct filter_match match; 1195 struct filter_set_head set; 1196 #define RDE_FILTER_SKIP_PEERID 0 1197 #define RDE_FILTER_SKIP_GROUPID 1 1198 #define RDE_FILTER_SKIP_REMOTE_AS 2 1199 #define RDE_FILTER_SKIP_COUNT 3 1200 struct filter_rule *skip[RDE_FILTER_SKIP_COUNT]; 1201 enum filter_actions action; 1202 enum directions dir; 1203 uint8_t quick; 1204 }; 1205 1206 enum action_types { 1207 ACTION_SET_LOCALPREF, 1208 ACTION_SET_RELATIVE_LOCALPREF, 1209 ACTION_SET_MED, 1210 ACTION_SET_RELATIVE_MED, 1211 ACTION_SET_WEIGHT, 1212 ACTION_SET_RELATIVE_WEIGHT, 1213 ACTION_SET_PREPEND_SELF, 1214 ACTION_SET_PREPEND_PEER, 1215 ACTION_SET_AS_OVERRIDE, 1216 ACTION_SET_NEXTHOP, 1217 ACTION_SET_NEXTHOP_REF, 1218 ACTION_SET_NEXTHOP_REJECT, 1219 ACTION_SET_NEXTHOP_BLACKHOLE, 1220 ACTION_SET_NEXTHOP_NOMODIFY, 1221 ACTION_SET_NEXTHOP_SELF, 1222 ACTION_DEL_COMMUNITY, 1223 ACTION_SET_COMMUNITY, 1224 ACTION_PFTABLE, 1225 ACTION_PFTABLE_ID, 1226 ACTION_RTLABEL, 1227 ACTION_RTLABEL_ID, 1228 ACTION_SET_ORIGIN 1229 }; 1230 1231 struct nexthop; 1232 struct filter_set { 1233 TAILQ_ENTRY(filter_set) entry; 1234 union { 1235 uint8_t prepend; 1236 uint16_t id; 1237 uint32_t metric; 1238 int32_t relative; 1239 struct bgpd_addr nexthop; 1240 struct nexthop *nh_ref; 1241 struct community community; 1242 char pftable[PFTABLE_LEN]; 1243 char rtlabel[ROUTELABEL_LEN]; 1244 uint8_t origin; 1245 } action; 1246 enum action_types type; 1247 }; 1248 1249 struct roa_set { 1250 uint32_t as; /* must be first */ 1251 uint32_t maxlen; /* change type for better struct layout */ 1252 }; 1253 1254 struct prefixset_item { 1255 struct filter_prefix p; 1256 RB_ENTRY(prefixset_item) entry; 1257 }; 1258 1259 struct prefixset { 1260 int sflags; 1261 char name[SET_NAME_LEN]; 1262 struct prefixset_tree psitems; 1263 struct roa_tree roaitems; 1264 SIMPLEQ_ENTRY(prefixset) entry; 1265 }; 1266 1267 struct as_set { 1268 char name[SET_NAME_LEN]; 1269 SIMPLEQ_ENTRY(as_set) entry; 1270 struct set_table *set; 1271 time_t lastchange; 1272 int dirty; 1273 }; 1274 1275 struct aspa_set { 1276 time_t expires; 1277 uint32_t as; 1278 uint32_t num; 1279 uint32_t *tas; 1280 RB_ENTRY(aspa_set) entry; 1281 }; 1282 1283 struct aspa_prep { 1284 size_t datasize; 1285 uint32_t entries; 1286 }; 1287 1288 struct l3vpn { 1289 SIMPLEQ_ENTRY(l3vpn) entry; 1290 char descr[PEER_DESCR_LEN]; 1291 char ifmpe[IFNAMSIZ]; 1292 struct filter_set_head import; 1293 struct filter_set_head export; 1294 struct network_head net_l; 1295 uint64_t rd; 1296 u_int rtableid; 1297 u_int label; 1298 int flags; 1299 }; 1300 1301 struct rde_rib { 1302 SIMPLEQ_ENTRY(rde_rib) entry; 1303 char name[PEER_DESCR_LEN]; 1304 u_int rtableid; 1305 uint16_t id; 1306 uint16_t flags; 1307 }; 1308 SIMPLEQ_HEAD(rib_names, rde_rib); 1309 extern struct rib_names ribnames; 1310 1311 /* rde_rib flags */ 1312 #define F_RIB_LOCAL 0x0001 1313 #define F_RIB_NOEVALUATE 0x0002 1314 #define F_RIB_NOFIB 0x0004 1315 #define F_RIB_NOFIBSYNC 0x0008 1316 1317 /* 4-byte magic AS number */ 1318 #define AS_TRANS 23456 1319 /* AS_NONE for origin validation */ 1320 #define AS_NONE 0 1321 1322 struct rde_memstats { 1323 long long path_cnt; 1324 long long path_refs; 1325 long long prefix_cnt; 1326 long long rib_cnt; 1327 long long pt_cnt[AID_MAX]; 1328 long long pt_size[AID_MAX]; 1329 long long nexthop_cnt; 1330 long long aspath_cnt; 1331 long long aspath_size; 1332 long long comm_cnt; 1333 long long comm_nmemb; 1334 long long comm_size; 1335 long long comm_refs; 1336 long long attr_cnt; 1337 long long attr_refs; 1338 long long attr_data; 1339 long long attr_dcnt; 1340 long long aset_cnt; 1341 long long aset_size; 1342 long long aset_nmemb; 1343 long long pset_cnt; 1344 long long pset_size; 1345 }; 1346 1347 #define MRT_FILE_LEN 512 1348 #define MRT2MC(x) ((struct mrt_config *)(x)) 1349 1350 enum mrt_type { 1351 MRT_NONE, 1352 MRT_TABLE_DUMP, 1353 MRT_TABLE_DUMP_MP, 1354 MRT_TABLE_DUMP_V2, 1355 MRT_ALL_IN, 1356 MRT_ALL_OUT, 1357 MRT_UPDATE_IN, 1358 MRT_UPDATE_OUT 1359 }; 1360 1361 enum mrt_state { 1362 MRT_STATE_RUNNING, 1363 MRT_STATE_OPEN, 1364 MRT_STATE_REOPEN, 1365 MRT_STATE_REMOVE 1366 }; 1367 1368 struct mrt { 1369 char rib[PEER_DESCR_LEN]; 1370 struct msgbuf wbuf; 1371 LIST_ENTRY(mrt) entry; 1372 uint32_t peer_id; 1373 uint32_t group_id; 1374 enum mrt_type type; 1375 enum mrt_state state; 1376 uint16_t seqnum; 1377 }; 1378 1379 struct mrt_config { 1380 struct mrt conf; 1381 char name[MRT_FILE_LEN]; /* base file name */ 1382 char file[MRT_FILE_LEN]; /* actual file name */ 1383 time_t ReopenTimer; 1384 int ReopenTimerInterval; 1385 }; 1386 1387 /* prototypes */ 1388 /* bgpd.c */ 1389 void send_nexthop_update(struct kroute_nexthop *); 1390 void send_imsg_session(int, pid_t, void *, uint16_t); 1391 int send_network(int, struct network_config *, 1392 struct filter_set_head *); 1393 int bgpd_oknexthop(struct kroute_full *); 1394 void set_pollfd(struct pollfd *, struct imsgbuf *); 1395 int handle_pollfd(struct pollfd *, struct imsgbuf *); 1396 1397 /* control.c */ 1398 int control_imsg_relay(struct imsg *, struct peer *); 1399 1400 /* config.c */ 1401 struct bgpd_config *new_config(void); 1402 void copy_config(struct bgpd_config *, struct bgpd_config *); 1403 void network_free(struct network *); 1404 struct flowspec_config *flowspec_alloc(uint8_t, int); 1405 void flowspec_free(struct flowspec_config *); 1406 void free_l3vpns(struct l3vpn_head *); 1407 void free_config(struct bgpd_config *); 1408 void free_prefixsets(struct prefixset_head *); 1409 void free_rde_prefixsets(struct rde_prefixset_head *); 1410 void free_prefixtree(struct prefixset_tree *); 1411 void free_roatree(struct roa_tree *); 1412 void free_aspa(struct aspa_set *); 1413 void free_aspatree(struct aspa_tree *); 1414 void free_rtrs(struct rtr_config_head *); 1415 void filterlist_free(struct filter_head *); 1416 int host(const char *, struct bgpd_addr *, uint8_t *); 1417 uint32_t get_bgpid(void); 1418 void expand_networks(struct bgpd_config *, struct network_head *); 1419 RB_PROTOTYPE(prefixset_tree, prefixset_item, entry, prefixset_cmp); 1420 RB_PROTOTYPE(roa_tree, roa, entry, roa_cmp); 1421 RB_PROTOTYPE(aspa_tree, aspa_set, entry, aspa_cmp); 1422 RB_PROTOTYPE(flowspec_tree, flowspec_config, entry, flowspec_config_cmp); 1423 1424 /* kroute.c */ 1425 int kr_init(int *, uint8_t); 1426 int kr_default_prio(void); 1427 int kr_check_prio(long long); 1428 int ktable_update(u_int, char *, int); 1429 void ktable_preload(void); 1430 void ktable_postload(void); 1431 int ktable_exists(u_int, u_int *); 1432 int kr_change(u_int, struct kroute_full *); 1433 int kr_delete(u_int, struct kroute_full *); 1434 int kr_flush(u_int); 1435 void kr_shutdown(void); 1436 void kr_fib_couple(u_int); 1437 void kr_fib_couple_all(void); 1438 void kr_fib_decouple(u_int); 1439 void kr_fib_decouple_all(void); 1440 void kr_fib_prio_set(uint8_t); 1441 int kr_dispatch_msg(void); 1442 int kr_nexthop_add(uint32_t, struct bgpd_addr *); 1443 void kr_nexthop_delete(uint32_t, struct bgpd_addr *); 1444 void kr_show_route(struct imsg *); 1445 void kr_ifinfo(char *); 1446 void kr_net_reload(u_int, uint64_t, struct network_head *); 1447 int kr_reload(void); 1448 int get_mpe_config(const char *, u_int *, u_int *); 1449 uint8_t mask2prefixlen(sa_family_t, struct sockaddr *); 1450 1451 /* log.c */ 1452 void log_peer_info(const struct peer_config *, const char *, ...) 1453 __attribute__((__format__ (printf, 2, 3))); 1454 void log_peer_warn(const struct peer_config *, const char *, ...) 1455 __attribute__((__format__ (printf, 2, 3))); 1456 void log_peer_warnx(const struct peer_config *, const char *, ...) 1457 __attribute__((__format__ (printf, 2, 3))); 1458 1459 /* mrt.c */ 1460 void mrt_clear_seq(void); 1461 void mrt_write(struct mrt *); 1462 void mrt_clean(struct mrt *); 1463 void mrt_init(struct imsgbuf *, struct imsgbuf *); 1464 time_t mrt_timeout(struct mrt_head *); 1465 void mrt_reconfigure(struct mrt_head *); 1466 void mrt_handler(struct mrt_head *); 1467 struct mrt *mrt_get(struct mrt_head *, struct mrt *); 1468 void mrt_mergeconfig(struct mrt_head *, struct mrt_head *); 1469 1470 /* name2id.c */ 1471 uint16_t rib_name2id(const char *); 1472 const char *rib_id2name(uint16_t); 1473 void rib_unref(uint16_t); 1474 void rib_ref(uint16_t); 1475 uint16_t rtlabel_name2id(const char *); 1476 const char *rtlabel_id2name(uint16_t); 1477 void rtlabel_unref(uint16_t); 1478 uint16_t rtlabel_ref(uint16_t); 1479 uint16_t pftable_name2id(const char *); 1480 const char *pftable_id2name(uint16_t); 1481 void pftable_unref(uint16_t); 1482 uint16_t pftable_ref(uint16_t); 1483 1484 /* parse.y */ 1485 int cmdline_symset(char *); 1486 struct prefixset *find_prefixset(char *, struct prefixset_head *); 1487 struct bgpd_config *parse_config(char *, struct peer_head *, 1488 struct rtr_config_head *); 1489 1490 /* pftable.c */ 1491 int pftable_exists(const char *); 1492 int pftable_add(const char *); 1493 int pftable_clear_all(void); 1494 int pftable_addr_add(struct pftable_msg *); 1495 int pftable_addr_remove(struct pftable_msg *); 1496 int pftable_commit(void); 1497 1498 /* rde_filter.c */ 1499 void filterset_free(struct filter_set_head *); 1500 int filterset_cmp(struct filter_set *, struct filter_set *); 1501 void filterset_move(struct filter_set_head *, struct filter_set_head *); 1502 void filterset_copy(struct filter_set_head *, struct filter_set_head *); 1503 const char *filterset_name(enum action_types); 1504 1505 /* rde_sets.c */ 1506 struct as_set *as_sets_lookup(struct as_set_head *, const char *); 1507 struct as_set *as_sets_new(struct as_set_head *, const char *, size_t, 1508 size_t); 1509 void as_sets_free(struct as_set_head *); 1510 void as_sets_mark_dirty(struct as_set_head *, struct as_set_head *); 1511 int as_set_match(const struct as_set *, uint32_t); 1512 1513 struct set_table *set_new(size_t, size_t); 1514 void set_free(struct set_table *); 1515 int set_add(struct set_table *, void *, size_t); 1516 void *set_get(struct set_table *, size_t *); 1517 void set_prep(struct set_table *); 1518 void *set_match(const struct set_table *, uint32_t); 1519 int set_equal(const struct set_table *, 1520 const struct set_table *); 1521 size_t set_nmemb(const struct set_table *); 1522 1523 /* rde_trie.c */ 1524 int trie_add(struct trie_head *, struct bgpd_addr *, uint8_t, uint8_t, 1525 uint8_t); 1526 int trie_roa_add(struct trie_head *, struct roa *); 1527 void trie_free(struct trie_head *); 1528 int trie_match(struct trie_head *, struct bgpd_addr *, uint8_t, int); 1529 int trie_roa_check(struct trie_head *, struct bgpd_addr *, uint8_t, 1530 uint32_t); 1531 void trie_dump(struct trie_head *); 1532 int trie_equal(struct trie_head *, struct trie_head *); 1533 1534 /* timer.c */ 1535 time_t getmonotime(void); 1536 1537 /* util.c */ 1538 const char *log_addr(const struct bgpd_addr *); 1539 const char *log_in6addr(const struct in6_addr *); 1540 const char *log_sockaddr(struct sockaddr *, socklen_t); 1541 const char *log_as(uint32_t); 1542 const char *log_rd(uint64_t); 1543 const char *log_ext_subtype(int, uint8_t); 1544 const char *log_reason(const char *); 1545 const char *log_roa(struct roa *); 1546 const char *log_aspa(struct aspa_set *); 1547 const char *log_rtr_error(enum rtr_error); 1548 const char *log_policy(enum role); 1549 int aspath_snprint(char *, size_t, void *, uint16_t); 1550 int aspath_asprint(char **, void *, uint16_t); 1551 size_t aspath_strlen(void *, uint16_t); 1552 uint32_t aspath_extract(const void *, int); 1553 int aspath_verify(void *, uint16_t, int, int); 1554 #define AS_ERR_LEN -1 1555 #define AS_ERR_TYPE -2 1556 #define AS_ERR_BAD -3 1557 #define AS_ERR_SOFT -4 1558 u_char *aspath_inflate(void *, uint16_t, uint16_t *); 1559 int extract_prefix(const u_char *, int, void *, uint8_t, uint8_t); 1560 int nlri_get_prefix(struct ibuf *, struct bgpd_addr *, uint8_t *); 1561 int nlri_get_prefix6(struct ibuf *, struct bgpd_addr *, uint8_t *); 1562 int nlri_get_vpn4(struct ibuf *, struct bgpd_addr *, uint8_t *, 1563 int); 1564 int nlri_get_vpn6(struct ibuf *, struct bgpd_addr *, uint8_t *, 1565 int); 1566 int prefix_compare(const struct bgpd_addr *, 1567 const struct bgpd_addr *, int); 1568 void inet4applymask(struct in_addr *, const struct in_addr *, int); 1569 void inet6applymask(struct in6_addr *, const struct in6_addr *, 1570 int); 1571 void applymask(struct bgpd_addr *, const struct bgpd_addr *, int); 1572 const char *aid2str(uint8_t); 1573 int aid2afi(uint8_t, uint16_t *, uint8_t *); 1574 int afi2aid(uint16_t, uint8_t, uint8_t *); 1575 sa_family_t aid2af(uint8_t); 1576 int af2aid(sa_family_t, uint8_t, uint8_t *); 1577 struct sockaddr *addr2sa(const struct bgpd_addr *, uint16_t, socklen_t *); 1578 void sa2addr(struct sockaddr *, struct bgpd_addr *, uint16_t *); 1579 const char * get_baudrate(unsigned long long, char *); 1580 1581 /* flowspec.c */ 1582 int flowspec_valid(const uint8_t *, int, int); 1583 int flowspec_cmp(const uint8_t *, int, const uint8_t *, int, int); 1584 int flowspec_get_component(const uint8_t *, int, int, int, 1585 const uint8_t **, int *); 1586 int flowspec_get_addr(const uint8_t *, int, int, int, struct bgpd_addr *, 1587 uint8_t *, uint8_t *); 1588 const char *flowspec_fmt_label(int); 1589 const char *flowspec_fmt_num_op(const uint8_t *, int, int *); 1590 const char *flowspec_fmt_bin_op(const uint8_t *, int, int *, const char *); 1591 1592 static const char * const log_procnames[] = { 1593 "parent", 1594 "SE", 1595 "RDE", 1596 "RTR" 1597 }; 1598 1599 /* logmsg.c and needed by bgpctl */ 1600 static const char * const statenames[] = { 1601 "None", 1602 "Idle", 1603 "Connect", 1604 "Active", 1605 "OpenSent", 1606 "OpenConfirm", 1607 "Established" 1608 }; 1609 1610 static const char * const msgtypenames[] = { 1611 "NONE", 1612 "OPEN", 1613 "UPDATE", 1614 "NOTIFICATION", 1615 "KEEPALIVE", 1616 "RREFRESH" 1617 }; 1618 1619 static const char * const eventnames[] = { 1620 "None", 1621 "Start", 1622 "Stop", 1623 "Connection opened", 1624 "Connection closed", 1625 "Connection open failed", 1626 "Fatal error", 1627 "ConnectRetryTimer expired", 1628 "HoldTimer expired", 1629 "KeepaliveTimer expired", 1630 "SendHoldTimer expired", 1631 "OPEN message received", 1632 "KEEPALIVE message received", 1633 "UPDATE message received", 1634 "NOTIFICATION received" 1635 }; 1636 1637 static const char * const errnames[] = { 1638 "none", 1639 "Header error", 1640 "error in OPEN message", 1641 "error in UPDATE message", 1642 "HoldTimer expired", 1643 "Finite State Machine error", 1644 "Cease", 1645 "error in ROUTE-REFRESH message" 1646 }; 1647 1648 static const char * const suberr_header_names[] = { 1649 "none", 1650 "synchronization error", 1651 "wrong length", 1652 "unknown message type" 1653 }; 1654 1655 static const char * const suberr_open_names[] = { 1656 "none", 1657 "version mismatch", 1658 "AS unacceptable", 1659 "BGPID invalid", 1660 "optional parameter error", 1661 "authentication error", 1662 "unacceptable holdtime", 1663 "unsupported capability", 1664 NULL, 1665 NULL, 1666 NULL, 1667 "role mismatch", 1668 }; 1669 1670 static const char * const suberr_fsm_names[] = { 1671 "unspecified error", 1672 "received unexpected message in OpenSent", 1673 "received unexpected message in OpenConfirm", 1674 "received unexpected message in Established" 1675 }; 1676 1677 static const char * const suberr_update_names[] = { 1678 "none", 1679 "attribute list error", 1680 "unknown well-known attribute", 1681 "well-known attribute missing", 1682 "attribute flags error", 1683 "attribute length wrong", 1684 "origin unacceptable", 1685 "loop detected", 1686 "nexthop unacceptable", 1687 "optional attribute error", 1688 "network unacceptable", 1689 "AS-Path unacceptable" 1690 }; 1691 1692 static const char * const suberr_cease_names[] = { 1693 "none", 1694 "received max-prefix exceeded", 1695 "administratively down", 1696 "peer unconfigured", 1697 "administrative reset", 1698 "connection rejected", 1699 "other config change", 1700 "collision", 1701 "resource exhaustion", 1702 "hard reset", 1703 "sent max-prefix exceeded" 1704 }; 1705 1706 static const char * const suberr_rrefresh_names[] = { 1707 "none", 1708 "invalid message length" 1709 }; 1710 1711 static const char * const ctl_res_strerror[] = { 1712 "no error", 1713 "no such neighbor", 1714 "permission denied", 1715 "neighbor does not have this capability", 1716 "config file has errors, reload failed", 1717 "previous reload still running", 1718 "out of memory", 1719 "not a cloned peer", 1720 "peer still active, down peer first", 1721 "no such RIB", 1722 "operation not supported", 1723 }; 1724 1725 static const char * const timernames[] = { 1726 "None", 1727 "ConnectRetryTimer", 1728 "KeepaliveTimer", 1729 "HoldTimer", 1730 "SendHoldTimer", 1731 "IdleHoldTimer", 1732 "IdleHoldResetTimer", 1733 "CarpUndemoteTimer", 1734 "RestartTimer", 1735 "RTR RefreshTimer", 1736 "RTR RetryTimer", 1737 "RTR ExpireTimer", 1738 "RTR ActiveTimer", 1739 "" 1740 }; 1741 1742 #endif /* __BGPD_H__ */ 1743