bgpd.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. /* BGP message definition header.
  2. Copyright (C) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro
  3. This file is part of GNU Zebra.
  4. GNU Zebra is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. GNU Zebra is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Zebra; see the file COPYING. If not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA. */
  16. /* For union sockunion. */
  17. #include "sockunion.h"
  18. /* Typedef BGP specific types. */
  19. typedef u_int16_t as_t;
  20. typedef u_int16_t bgp_size_t;
  21. /* BGP master for system wide configurations and variables. */
  22. struct bgp_master
  23. {
  24. /* BGP instance list. */
  25. struct list *bgp;
  26. /* BGP thread master. */
  27. struct thread_master *master;
  28. /* BGP port number. */
  29. u_int16_t port;
  30. /* BGP start time. */
  31. time_t start_time;
  32. /* Various BGP global configuration. */
  33. u_char options;
  34. #define BGP_OPT_NO_FIB (1 << 0)
  35. #define BGP_OPT_MULTIPLE_INSTANCE (1 << 1)
  36. #define BGP_OPT_CONFIG_CISCO (1 << 2)
  37. };
  38. /* BGP instance structure. */
  39. struct bgp
  40. {
  41. /* AS number of this BGP instance. */
  42. as_t as;
  43. /* Name of this BGP instance. */
  44. char *name;
  45. /* Self peer. */
  46. struct peer *peer_self;
  47. /* BGP peer. */
  48. struct list *peer;
  49. /* BGP peer group. */
  50. struct list *group;
  51. /* BGP configuration. */
  52. u_int16_t config;
  53. #define BGP_CONFIG_ROUTER_ID (1 << 0)
  54. #define BGP_CONFIG_CLUSTER_ID (1 << 1)
  55. #define BGP_CONFIG_CONFEDERATION (1 << 2)
  56. #define BGP_CONFIG_DEFAULT_LOCAL_PREF (1 << 3)
  57. /* BGP router identifier. */
  58. struct in_addr router_id;
  59. /* BGP route reflector cluster ID. */
  60. struct in_addr cluster_id;
  61. /* BGP confederation information. */
  62. as_t confed_id;
  63. as_t *confed_peers;
  64. int confed_peers_cnt;
  65. /* BGP flags. */
  66. u_int16_t flags;
  67. #define BGP_FLAG_ALWAYS_COMPARE_MED (1 << 0)
  68. #define BGP_FLAG_DETERMINISTIC_MED (1 << 1)
  69. #define BGP_FLAG_MED_MISSING_AS_WORST (1 << 2)
  70. #define BGP_FLAG_MED_CONFED (1 << 3)
  71. #define BGP_FLAG_NO_DEFAULT_IPV4 (1 << 4)
  72. #define BGP_FLAG_NO_CLIENT_TO_CLIENT (1 << 5)
  73. #define BGP_FLAG_ENFORCE_FIRST_AS (1 << 6)
  74. #define BGP_FLAG_COMPARE_ROUTER_ID (1 << 7)
  75. #define BGP_FLAG_ASPATH_IGNORE (1 << 8)
  76. #define BGP_FLAG_IMPORT_CHECK (1 << 9)
  77. #define BGP_FLAG_NO_FAST_EXT_FAILOVER (1 << 10)
  78. /* BGP Per AF flags */
  79. u_int16_t af_flags[AFI_MAX][SAFI_MAX];
  80. #define BGP_CONFIG_DAMPENING (1 << 0)
  81. /* Static route configuration. */
  82. struct bgp_table *route[AFI_MAX][SAFI_MAX];
  83. /* Aggregate address configuration. */
  84. struct bgp_table *aggregate[AFI_MAX][SAFI_MAX];
  85. /* BGP routing information base. */
  86. struct bgp_table *rib[AFI_MAX][SAFI_MAX];
  87. /* BGP redistribute configuration. */
  88. u_char redist[AFI_MAX][ZEBRA_ROUTE_MAX];
  89. /* BGP redistribute metric configuration. */
  90. u_char redist_metric_flag[AFI_MAX][ZEBRA_ROUTE_MAX];
  91. u_int32_t redist_metric[AFI_MAX][ZEBRA_ROUTE_MAX];
  92. /* BGP redistribute route-map. */
  93. struct
  94. {
  95. char *name;
  96. struct route_map *map;
  97. } rmap[AFI_MAX][ZEBRA_ROUTE_MAX];
  98. /* BGP distance configuration. */
  99. u_char distance_ebgp;
  100. u_char distance_ibgp;
  101. u_char distance_local;
  102. /* BGP default local-preference. */
  103. u_int32_t default_local_pref;
  104. /* BGP default timer. */
  105. u_int32_t default_holdtime;
  106. u_int32_t default_keepalive;
  107. };
  108. /* BGP peer-group support. */
  109. struct peer_group
  110. {
  111. /* Name of the peer-group. */
  112. char *name;
  113. /* Pointer to BGP. */
  114. struct bgp *bgp;
  115. /* Peer-group client list. */
  116. struct list *peer;
  117. /* Peer-group config */
  118. struct peer *conf;
  119. };
  120. /* BGP Notify message format. */
  121. struct bgp_notify
  122. {
  123. u_char code;
  124. u_char subcode;
  125. char *data;
  126. bgp_size_t length;
  127. };
  128. /* Next hop self address. */
  129. struct bgp_nexthop
  130. {
  131. struct interface *ifp;
  132. struct in_addr v4;
  133. #ifdef HAVE_IPV6
  134. struct in6_addr v6_global;
  135. struct in6_addr v6_local;
  136. #endif /* HAVE_IPV6 */
  137. };
  138. /* BGP router distinguisher value. */
  139. #define BGP_RD_SIZE 8
  140. struct bgp_rd
  141. {
  142. u_char val[BGP_RD_SIZE];
  143. };
  144. /* BGP filter structure. */
  145. struct bgp_filter
  146. {
  147. /* Distribute-list. */
  148. struct
  149. {
  150. char *name;
  151. struct access_list *alist;
  152. } dlist[FILTER_MAX];
  153. /* Prefix-list. */
  154. struct
  155. {
  156. char *name;
  157. struct prefix_list *plist;
  158. } plist[FILTER_MAX];
  159. /* Filter-list. */
  160. struct
  161. {
  162. char *name;
  163. struct as_list *aslist;
  164. } aslist[FILTER_MAX];
  165. /* Route-map. */
  166. struct
  167. {
  168. char *name;
  169. struct route_map *map;
  170. } map[FILTER_MAX];
  171. /* Unsuppress-map. */
  172. struct
  173. {
  174. char *name;
  175. struct route_map *map;
  176. } usmap;
  177. };
  178. /* BGP neighbor structure. */
  179. struct peer
  180. {
  181. /* BGP structure. */
  182. struct bgp *bgp;
  183. /* BGP peer group. */
  184. struct peer_group *group;
  185. u_char af_group[AFI_MAX][SAFI_MAX];
  186. /* Peer's remote AS number. */
  187. as_t as;
  188. /* Peer's local AS number. */
  189. as_t local_as;
  190. /* Peer's Change local AS number. */
  191. as_t change_local_as;
  192. /* Remote router ID. */
  193. struct in_addr remote_id;
  194. /* Local router ID. */
  195. struct in_addr local_id;
  196. /* Packet receive and send buffer. */
  197. struct stream *ibuf;
  198. struct stream_fifo *obuf;
  199. struct stream *work;
  200. /* Status of the peer. */
  201. int status;
  202. int ostatus;
  203. /* Peer information */
  204. int fd; /* File descriptor */
  205. int ttl; /* TTL of TCP connection to the peer. */
  206. char *desc; /* Description of the peer. */
  207. unsigned short port; /* Destination port for peer */
  208. char *host; /* Printable address of the peer. */
  209. union sockunion su; /* Sockunion address of the peer. */
  210. time_t uptime; /* Last Up/Down time */
  211. time_t readtime; /* Last read time */
  212. unsigned int ifindex; /* ifindex of the BGP connection. */
  213. char *ifname; /* bind interface name. */
  214. char *update_if;
  215. union sockunion *update_source;
  216. struct zlog *log;
  217. u_char version; /* Peer BGP version. */
  218. union sockunion *su_local; /* Sockunion of local address. */
  219. union sockunion *su_remote; /* Sockunion of remote address. */
  220. int shared_network; /* Is this peer shared same network. */
  221. struct bgp_nexthop nexthop; /* Nexthop */
  222. /* Peer address family configuration. */
  223. u_char afc[AFI_MAX][SAFI_MAX];
  224. u_char afc_nego[AFI_MAX][SAFI_MAX];
  225. u_char afc_adv[AFI_MAX][SAFI_MAX];
  226. u_char afc_recv[AFI_MAX][SAFI_MAX];
  227. /* Capability Flags.*/
  228. u_char cap;
  229. #define PEER_CAP_REFRESH_ADV (1 << 0) /* refresh advertised */
  230. #define PEER_CAP_REFRESH_OLD_RCV (1 << 1) /* refresh old received */
  231. #define PEER_CAP_REFRESH_NEW_RCV (1 << 2) /* refresh rfc received */
  232. #define PEER_CAP_DYNAMIC_ADV (1 << 3) /* dynamic advertised */
  233. #define PEER_CAP_DYNAMIC_RCV (1 << 4) /* dynamic received */
  234. /* Capability Flags.*/
  235. u_int16_t af_cap[AFI_MAX][SAFI_MAX];
  236. #define PEER_CAP_ORF_PREFIX_SM_ADV (1 << 0) /* send-mode advertised */
  237. #define PEER_CAP_ORF_PREFIX_RM_ADV (1 << 1) /* receive-mode advertised */
  238. #define PEER_CAP_ORF_PREFIX_SM_RCV (1 << 2) /* send-mode received */
  239. #define PEER_CAP_ORF_PREFIX_RM_RCV (1 << 3) /* receive-mode received */
  240. #define PEER_CAP_ORF_PREFIX_SM_OLD_RCV (1 << 4) /* send-mode received */
  241. #define PEER_CAP_ORF_PREFIX_RM_OLD_RCV (1 << 5) /* receive-mode received */
  242. /* Global configuration flags. */
  243. u_int32_t flags;
  244. #define PEER_FLAG_PASSIVE (1 << 0) /* passive mode */
  245. #define PEER_FLAG_SHUTDOWN (1 << 1) /* shutdown */
  246. #define PEER_FLAG_DONT_CAPABILITY (1 << 2) /* dont-capability */
  247. #define PEER_FLAG_OVERRIDE_CAPABILITY (1 << 3) /* override-capability */
  248. #define PEER_FLAG_STRICT_CAP_MATCH (1 << 4) /* strict-match */
  249. #define PEER_FLAG_NO_ROUTE_REFRESH_CAP (1 << 5) /* route-refresh */
  250. #define PEER_FLAG_DYNAMIC_CAPABILITY (1 << 6) /* dynamic capability */
  251. #define PEER_FLAG_ENFORCE_MULTIHOP (1 << 7) /* enforce-multihop */
  252. #define PEER_FLAG_LOCAL_AS_NO_PREPEND (1 << 8) /* local-as no-prepend */
  253. /* Per AF configuration flags. */
  254. u_int32_t af_flags[AFI_MAX][SAFI_MAX];
  255. #define PEER_FLAG_SEND_COMMUNITY (1 << 0) /* send-community */
  256. #define PEER_FLAG_SEND_EXT_COMMUNITY (1 << 1) /* send-community ext. */
  257. #define PEER_FLAG_NEXTHOP_SELF (1 << 2) /* next-hop-self */
  258. #define PEER_FLAG_REFLECTOR_CLIENT (1 << 3) /* reflector-client */
  259. #define PEER_FLAG_RSERVER_CLIENT (1 << 4) /* route-server-client */
  260. #define PEER_FLAG_SOFT_RECONFIG (1 << 5) /* soft-reconfiguration */
  261. #define PEER_FLAG_AS_PATH_UNCHANGED (1 << 6) /* transparent-as */
  262. #define PEER_FLAG_NEXTHOP_UNCHANGED (1 << 7) /* transparent-next-hop */
  263. #define PEER_FLAG_MED_UNCHANGED (1 << 8) /* transparent-next-hop */
  264. #define PEER_FLAG_DEFAULT_ORIGINATE (1 << 9) /* default-originate */
  265. #define PEER_FLAG_REMOVE_PRIVATE_AS (1 << 10) /* remove-private-as */
  266. #define PEER_FLAG_ALLOWAS_IN (1 << 11) /* set allowas-in */
  267. #define PEER_FLAG_ORF_PREFIX_SM (1 << 12) /* orf capability send-mode */
  268. #define PEER_FLAG_ORF_PREFIX_RM (1 << 13) /* orf capability receive-mode */
  269. #define PEER_FLAG_MAX_PREFIX (1 << 14) /* maximum prefix */
  270. #define PEER_FLAG_MAX_PREFIX_WARNING (1 << 15) /* maximum prefix warning-only */
  271. /* default-originate route-map. */
  272. struct
  273. {
  274. char *name;
  275. struct route_map *map;
  276. } default_rmap[AFI_MAX][SAFI_MAX];
  277. /* Peer status flags. */
  278. u_int16_t sflags;
  279. #define PEER_STATUS_ACCEPT_PEER (1 << 0) /* accept peer */
  280. #define PEER_STATUS_PREFIX_OVERFLOW (1 << 1) /* prefix-overflow */
  281. #define PEER_STATUS_CAPABILITY_OPEN (1 << 2) /* capability open send */
  282. #define PEER_STATUS_HAVE_ACCEPT (1 << 3) /* accept peer's parent */
  283. #define PEER_STATUS_GROUP (1 << 4) /* peer-group conf */
  284. /* Peer status af flags. */
  285. u_int16_t af_sflags[AFI_MAX][SAFI_MAX];
  286. #define PEER_STATUS_ORF_PREFIX_SEND (1 << 0) /* prefix-list send peer */
  287. #define PEER_STATUS_ORF_WAIT_REFRESH (1 << 1) /* wait refresh received peer */
  288. #define PEER_STATUS_DEFAULT_ORIGINATE (1 << 2) /* default-originate peer */
  289. /* Default attribute value for the peer. */
  290. u_int32_t config;
  291. #define PEER_CONFIG_WEIGHT (1 << 0) /* Default weight. */
  292. #define PEER_CONFIG_TIMER (1 << 1) /* keepalive & holdtime */
  293. #define PEER_CONFIG_CONNECT (1 << 2) /* connect */
  294. #define PEER_CONFIG_ROUTEADV (1 << 3) /* route advertise */
  295. u_int32_t weight;
  296. u_int32_t holdtime;
  297. u_int32_t keepalive;
  298. u_int32_t connect;
  299. u_int32_t routeadv;
  300. /* Timer values. */
  301. u_int32_t v_start;
  302. u_int32_t v_connect;
  303. u_int32_t v_holdtime;
  304. u_int32_t v_keepalive;
  305. u_int32_t v_asorig;
  306. u_int32_t v_routeadv;
  307. /* Threads. */
  308. struct thread *t_read;
  309. struct thread *t_write;
  310. struct thread *t_start;
  311. struct thread *t_connect;
  312. struct thread *t_holdtime;
  313. struct thread *t_keepalive;
  314. struct thread *t_asorig;
  315. struct thread *t_routeadv;
  316. /* Statistics field */
  317. u_int32_t open_in; /* Open message input count */
  318. u_int32_t open_out; /* Open message output count */
  319. u_int32_t update_in; /* Update message input count */
  320. u_int32_t update_out; /* Update message ouput count */
  321. time_t update_time; /* Update message received time. */
  322. u_int32_t keepalive_in; /* Keepalive input count */
  323. u_int32_t keepalive_out; /* Keepalive output count */
  324. u_int32_t notify_in; /* Notify input count */
  325. u_int32_t notify_out; /* Notify output count */
  326. u_int32_t refresh_in; /* Route Refresh input count */
  327. u_int32_t refresh_out; /* Route Refresh output count */
  328. u_int32_t dynamic_cap_in; /* Dynamic Capability input count. */
  329. u_int32_t dynamic_cap_out; /* Dynamic Capability output count. */
  330. /* BGP state count */
  331. u_int32_t established; /* Established */
  332. u_int32_t dropped; /* Dropped */
  333. /* Syncronization list and time. */
  334. struct bgp_synchronize *sync[AFI_MAX][SAFI_MAX];
  335. time_t synctime;
  336. /* Send prefix count. */
  337. unsigned long scount[AFI_MAX][SAFI_MAX];
  338. /* Announcement attribute hash. */
  339. struct hash *hash[AFI_MAX][SAFI_MAX];
  340. /* Notify data. */
  341. struct bgp_notify notify;
  342. /* Whole packet size to be read. */
  343. unsigned long packet_size;
  344. /* Filter structure. */
  345. struct bgp_filter filter[AFI_MAX][SAFI_MAX];
  346. /* ORF Prefix-list */
  347. struct prefix_list *orf_plist[AFI_MAX][SAFI_MAX];
  348. /* Prefix count. */
  349. unsigned long pcount[AFI_MAX][SAFI_MAX];
  350. /* Max prefix count. */
  351. unsigned long pmax[AFI_MAX][SAFI_MAX];
  352. /* allowas-in. */
  353. char allowas_in[AFI_MAX][SAFI_MAX];
  354. };
  355. /* This structure's member directly points incoming packet data
  356. stream. */
  357. struct bgp_nlri
  358. {
  359. /* AFI. */
  360. afi_t afi;
  361. /* SAFI. */
  362. safi_t safi;
  363. /* Pointer to NLRI byte stream. */
  364. u_char *nlri;
  365. /* Length of whole NLRI. */
  366. bgp_size_t length;
  367. };
  368. /* BGP versions. */
  369. #define BGP_VERSION_4 4
  370. #define BGP_VERSION_MP_4_DRAFT_00 40
  371. /* Default BGP port number. */
  372. #define BGP_PORT_DEFAULT 179
  373. /* BGP message header and packet size. */
  374. #define BGP_MARKER_SIZE 16
  375. #define BGP_HEADER_SIZE 19
  376. #define BGP_MAX_PACKET_SIZE 4096
  377. /* BGP minimum message size. */
  378. #define BGP_MSG_OPEN_MIN_SIZE (BGP_HEADER_SIZE + 10)
  379. #define BGP_MSG_UPDATE_MIN_SIZE (BGP_HEADER_SIZE + 4)
  380. #define BGP_MSG_NOTIFY_MIN_SIZE (BGP_HEADER_SIZE + 2)
  381. #define BGP_MSG_KEEPALIVE_MIN_SIZE (BGP_HEADER_SIZE + 0)
  382. #define BGP_MSG_ROUTE_REFRESH_MIN_SIZE (BGP_HEADER_SIZE + 4)
  383. #define BGP_MSG_CAPABILITY_MIN_SIZE (BGP_HEADER_SIZE + 3)
  384. /* BGP message types. */
  385. #define BGP_MSG_OPEN 1
  386. #define BGP_MSG_UPDATE 2
  387. #define BGP_MSG_NOTIFY 3
  388. #define BGP_MSG_KEEPALIVE 4
  389. #define BGP_MSG_ROUTE_REFRESH_NEW 5
  390. #define BGP_MSG_CAPABILITY 6
  391. #define BGP_MSG_ROUTE_REFRESH_OLD 128
  392. /* BGP open optional parameter. */
  393. #define BGP_OPEN_OPT_AUTH 1
  394. #define BGP_OPEN_OPT_CAP 2
  395. /* BGP4 attribute type codes. */
  396. #define BGP_ATTR_ORIGIN 1
  397. #define BGP_ATTR_AS_PATH 2
  398. #define BGP_ATTR_NEXT_HOP 3
  399. #define BGP_ATTR_MULTI_EXIT_DISC 4
  400. #define BGP_ATTR_LOCAL_PREF 5
  401. #define BGP_ATTR_ATOMIC_AGGREGATE 6
  402. #define BGP_ATTR_AGGREGATOR 7
  403. #define BGP_ATTR_COMMUNITIES 8
  404. #define BGP_ATTR_ORIGINATOR_ID 9
  405. #define BGP_ATTR_CLUSTER_LIST 10
  406. #define BGP_ATTR_DPA 11
  407. #define BGP_ATTR_ADVERTISER 12
  408. #define BGP_ATTR_RCID_PATH 13
  409. #define BGP_ATTR_MP_REACH_NLRI 14
  410. #define BGP_ATTR_MP_UNREACH_NLRI 15
  411. #define BGP_ATTR_EXT_COMMUNITIES 16
  412. /* BGP update origin. */
  413. #define BGP_ORIGIN_IGP 0
  414. #define BGP_ORIGIN_EGP 1
  415. #define BGP_ORIGIN_INCOMPLETE 2
  416. /* BGP notify message codes. */
  417. #define BGP_NOTIFY_HEADER_ERR 1
  418. #define BGP_NOTIFY_OPEN_ERR 2
  419. #define BGP_NOTIFY_UPDATE_ERR 3
  420. #define BGP_NOTIFY_HOLD_ERR 4
  421. #define BGP_NOTIFY_FSM_ERR 5
  422. #define BGP_NOTIFY_CEASE 6
  423. #define BGP_NOTIFY_CAPABILITY_ERR 7
  424. #define BGP_NOTIFY_MAX 8
  425. /* BGP_NOTIFY_HEADER_ERR sub codes. */
  426. #define BGP_NOTIFY_HEADER_NOT_SYNC 1
  427. #define BGP_NOTIFY_HEADER_BAD_MESLEN 2
  428. #define BGP_NOTIFY_HEADER_BAD_MESTYPE 3
  429. #define BGP_NOTIFY_HEADER_MAX 4
  430. /* BGP_NOTIFY_OPEN_ERR sub codes. */
  431. #define BGP_NOTIFY_OPEN_UNSUP_VERSION 1
  432. #define BGP_NOTIFY_OPEN_BAD_PEER_AS 2
  433. #define BGP_NOTIFY_OPEN_BAD_BGP_IDENT 3
  434. #define BGP_NOTIFY_OPEN_UNSUP_PARAM 4
  435. #define BGP_NOTIFY_OPEN_AUTH_FAILURE 5
  436. #define BGP_NOTIFY_OPEN_UNACEP_HOLDTIME 6
  437. #define BGP_NOTIFY_OPEN_UNSUP_CAPBL 7
  438. #define BGP_NOTIFY_OPEN_MAX 8
  439. /* BGP_NOTIFY_UPDATE_ERR sub codes. */
  440. #define BGP_NOTIFY_UPDATE_MAL_ATTR 1
  441. #define BGP_NOTIFY_UPDATE_UNREC_ATTR 2
  442. #define BGP_NOTIFY_UPDATE_MISS_ATTR 3
  443. #define BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR 4
  444. #define BGP_NOTIFY_UPDATE_ATTR_LENG_ERR 5
  445. #define BGP_NOTIFY_UPDATE_INVAL_ORIGIN 6
  446. #define BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP 7
  447. #define BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP 8
  448. #define BGP_NOTIFY_UPDATE_OPT_ATTR_ERR 9
  449. #define BGP_NOTIFY_UPDATE_INVAL_NETWORK 10
  450. #define BGP_NOTIFY_UPDATE_MAL_AS_PATH 11
  451. #define BGP_NOTIFY_UPDATE_MAX 12
  452. /* BGP_NOTIFY_CEASE sub codes (draft-ietf-idr-cease-subcode-00). */
  453. #define BGP_NOTIFY_CEASE_MAX_PREFIX 1
  454. #define BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN 2
  455. #define BGP_NOTIFY_CEASE_PEER_UNCONFIG 3
  456. #define BGP_NOTIFY_CEASE_ADMIN_RESET 4
  457. #define BGP_NOTIFY_CEASE_CONNECT_REJECT 5
  458. #define BGP_NOTIFY_CEASE_CONFIG_CHANGE 6
  459. #define BGP_NOTIFY_CEASE_MAX 7
  460. /* BGP_NOTIFY_CAPABILITY_ERR sub codes (draft-ietf-idr-dynamic-cap-02). */
  461. #define BGP_NOTIFY_CAPABILITY_INVALID_ACTION 1
  462. #define BGP_NOTIFY_CAPABILITY_INVALID_LENGTH 2
  463. #define BGP_NOTIFY_CAPABILITY_MALFORMED_CODE 3
  464. #define BGP_NOTIFY_CAPABILITY_MAX 4
  465. /* BGP finite state machine status. */
  466. #define Idle 1
  467. #define Connect 2
  468. #define Active 3
  469. #define OpenSent 4
  470. #define OpenConfirm 5
  471. #define Established 6
  472. #define BGP_STATUS_MAX 7
  473. /* BGP finite state machine events. */
  474. #define BGP_Start 1
  475. #define BGP_Stop 2
  476. #define TCP_connection_open 3
  477. #define TCP_connection_closed 4
  478. #define TCP_connection_open_failed 5
  479. #define TCP_fatal_error 6
  480. #define ConnectRetry_timer_expired 7
  481. #define Hold_Timer_expired 8
  482. #define KeepAlive_timer_expired 9
  483. #define Receive_OPEN_message 10
  484. #define Receive_KEEPALIVE_message 11
  485. #define Receive_UPDATE_message 12
  486. #define Receive_NOTIFICATION_message 13
  487. #define BGP_EVENTS_MAX 14
  488. /* BGP timers default value. */
  489. #define BGP_INIT_START_TIMER 5
  490. #define BGP_ERROR_START_TIMER 30
  491. #define BGP_DEFAULT_HOLDTIME 180
  492. #define BGP_DEFAULT_KEEPALIVE 60
  493. #define BGP_DEFAULT_ASORIGINATE 15
  494. #define BGP_DEFAULT_EBGP_ROUTEADV 30
  495. #define BGP_DEFAULT_IBGP_ROUTEADV 5
  496. #define BGP_CLEAR_CONNECT_RETRY 20
  497. #define BGP_DEFAULT_CONNECT_RETRY 120
  498. /* BGP default local preference. */
  499. #define BGP_DEFAULT_LOCAL_PREF 100
  500. /* SAFI which used in open capability negotiation. */
  501. #define BGP_SAFI_VPNV4 128
  502. #define BGP_SAFI_VPNV6 129
  503. /* Max TTL value. */
  504. #define TTL_MAX 255
  505. /* BGP uptime string length. */
  506. #define BGP_UPTIME_LEN 25
  507. /* Default configuration settings for bgpd. */
  508. #define BGP_VTY_PORT 2605
  509. #define BGP_DEFAULT_CONFIG "bgpd.conf"
  510. /* Check AS path loop when we send NLRI. */
  511. /* #define BGP_SEND_ASPATH_CHECK */
  512. /* IBGP/EBGP identifier. We also have a CONFED peer, which is to say,
  513. a peer who's AS is part of our Confederation. */
  514. enum
  515. {
  516. BGP_PEER_IBGP,
  517. BGP_PEER_EBGP,
  518. BGP_PEER_INTERNAL,
  519. BGP_PEER_CONFED
  520. };
  521. /* Flag for peer_clear_soft(). */
  522. enum bgp_clear_type
  523. {
  524. BGP_CLEAR_SOFT_NONE,
  525. BGP_CLEAR_SOFT_OUT,
  526. BGP_CLEAR_SOFT_IN,
  527. BGP_CLEAR_SOFT_BOTH,
  528. BGP_CLEAR_SOFT_IN_ORF_PREFIX
  529. };
  530. /* Macros. */
  531. #define BGP_INPUT(P) ((P)->ibuf)
  532. #define BGP_INPUT_PNT(P) (STREAM_PNT(BGP_INPUT(P)))
  533. /* Macro to check BGP information is alive or not. */
  534. #define BGP_INFO_HOLDDOWN(BI) \
  535. (! CHECK_FLAG ((BI)->flags, BGP_INFO_VALID) \
  536. || CHECK_FLAG ((BI)->flags, BGP_INFO_HISTORY) \
  537. || CHECK_FLAG ((BI)->flags, BGP_INFO_DAMPED))
  538. /* Count prefix size from mask length */
  539. #define PSIZE(a) (((a) + 7) / (8))
  540. /* BGP error codes. */
  541. #define BGP_SUCCESS 0
  542. #define BGP_ERR_INVALID_VALUE -1
  543. #define BGP_ERR_INVALID_FLAG -2
  544. #define BGP_ERR_INVALID_AS -3
  545. #define BGP_ERR_INVALID_BGP -4
  546. #define BGP_ERR_PEER_GROUP_MEMBER -5
  547. #define BGP_ERR_MULTIPLE_INSTANCE_USED -6
  548. #define BGP_ERR_PEER_GROUP_MEMBER_EXISTS -7
  549. #define BGP_ERR_PEER_BELONGS_TO_GROUP -8
  550. #define BGP_ERR_PEER_GROUP_AF_UNCONFIGURED -9
  551. #define BGP_ERR_PEER_GROUP_NO_REMOTE_AS -10
  552. #define BGP_ERR_PEER_GROUP_CANT_CHANGE -11
  553. #define BGP_ERR_PEER_GROUP_MISMATCH -12
  554. #define BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT -13
  555. #define BGP_ERR_MULTIPLE_INSTANCE_NOT_SET -14
  556. #define BGP_ERR_AS_MISMATCH -15
  557. #define BGP_ERR_PEER_INACTIVE -16
  558. #define BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER -17
  559. #define BGP_ERR_PEER_GROUP_HAS_THE_FLAG -18
  560. #define BGP_ERR_PEER_FLAG_CONFLICT -19
  561. #define BGP_ERR_PEER_GROUP_SHUTDOWN -20
  562. #define BGP_ERR_PEER_FILTER_CONFLICT -21
  563. #define BGP_ERR_NOT_INTERNAL_PEER -22
  564. #define BGP_ERR_REMOVE_PRIVATE_AS -23
  565. #define BGP_ERR_AF_UNCONFIGURED -24
  566. #define BGP_ERR_SOFT_RECONFIG_UNCONFIGURED -25
  567. #define BGP_ERR_INSTANCE_MISMATCH -26
  568. #define BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP -27
  569. #define BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS -28
  570. #define BGP_ERR_MAX -29
  571. extern struct bgp_master *bm;
  572. extern struct thread_master *master;
  573. /* Prototypes. */
  574. void bgp_terminate (void);
  575. void bgp_reset (void);
  576. void bgp_zclient_reset ();
  577. int bgp_nexthop_set (union sockunion *, union sockunion *,
  578. struct bgp_nexthop *, struct peer *);
  579. struct bgp_master *bgp_get_master ();
  580. struct bgp *bgp_get_default ();
  581. struct bgp *bgp_lookup (as_t, char *);
  582. struct bgp *bgp_lookup_by_name (char *);
  583. struct peer *peer_lookup (struct bgp *, union sockunion *);
  584. struct peer_group *peer_group_lookup (struct bgp *, char *);
  585. struct peer_group *peer_group_get (struct bgp *, char *);
  586. struct peer *peer_lookup_with_open (union sockunion *, as_t, struct in_addr *,
  587. int *);
  588. int peer_sort (struct peer *peer);
  589. int peer_active (struct peer *);
  590. int peer_active_nego (struct peer *);
  591. struct peer *peer_create_accept (struct bgp *);
  592. char *peer_uptime (time_t, char *, size_t);
  593. void bgp_config_write_family_header (struct vty *, afi_t, safi_t, int *);
  594. void bgp_master_init ();
  595. void bgp_init ();
  596. int bgp_option_set (int);
  597. int bgp_option_unset (int);
  598. int bgp_option_check (int);
  599. int bgp_get (struct bgp **, as_t *, char *);
  600. int bgp_delete (struct bgp *);
  601. int bgp_flag_set (struct bgp *, int);
  602. int bgp_flag_unset (struct bgp *, int);
  603. int bgp_flag_check (struct bgp *, int);
  604. int bgp_router_id_set (struct bgp *, struct in_addr *);
  605. int bgp_router_id_unset (struct bgp *);
  606. int bgp_cluster_id_set (struct bgp *, struct in_addr *);
  607. int bgp_cluster_id_unset (struct bgp *);
  608. int bgp_confederation_id_set (struct bgp *, as_t);
  609. int bgp_confederation_id_unset (struct bgp *);
  610. int bgp_confederation_peers_check (struct bgp *, as_t);
  611. int bgp_confederation_peers_add (struct bgp *, as_t);
  612. int bgp_confederation_peers_remove (struct bgp *, as_t);
  613. int bgp_timers_set (struct bgp *, u_int32_t, u_int32_t);
  614. int bgp_timers_unset (struct bgp *);
  615. int bgp_default_local_preference_set (struct bgp *, u_int32_t);
  616. int bgp_default_local_preference_unset (struct bgp *);
  617. int peer_remote_as (struct bgp *, union sockunion *, as_t *, afi_t, safi_t);
  618. int peer_group_remote_as (struct bgp *, char *, as_t *);
  619. int peer_delete (struct peer *peer);
  620. int peer_group_delete (struct peer_group *);
  621. int peer_group_remote_as_delete (struct peer_group *);
  622. int peer_activate (struct peer *, afi_t, safi_t);
  623. int peer_deactivate (struct peer *, afi_t, safi_t);
  624. int peer_group_bind (struct bgp *, union sockunion *, struct peer_group *,
  625. afi_t, safi_t, as_t *);
  626. int peer_group_unbind (struct bgp *, struct peer *, struct peer_group *,
  627. afi_t, safi_t);
  628. int peer_flag_set (struct peer *, u_int32_t);
  629. int peer_flag_unset (struct peer *, u_int32_t);
  630. int peer_af_flag_set (struct peer *, afi_t, safi_t, u_int32_t);
  631. int peer_af_flag_unset (struct peer *, afi_t, safi_t, u_int32_t);
  632. int peer_af_flag_check (struct peer *, afi_t, safi_t, u_int32_t);
  633. int peer_ebgp_multihop_set (struct peer *, int);
  634. int peer_ebgp_multihop_unset (struct peer *);
  635. int peer_description_set (struct peer *, char *);
  636. int peer_description_unset (struct peer *);
  637. int peer_update_source_if_set (struct peer *, char *);
  638. int peer_update_source_addr_set (struct peer *, union sockunion *);
  639. int peer_update_source_unset (struct peer *);
  640. int peer_default_originate_set (struct peer *, afi_t, safi_t, char *);
  641. int peer_default_originate_unset (struct peer *, afi_t, safi_t);
  642. int peer_port_set (struct peer *, u_int16_t);
  643. int peer_port_unset (struct peer *);
  644. int peer_weight_set (struct peer *, u_int16_t);
  645. int peer_weight_unset (struct peer *);
  646. int peer_timers_set (struct peer *, u_int32_t, u_int32_t);
  647. int peer_timers_unset (struct peer *);
  648. int peer_timers_connect_set (struct peer *, u_int32_t);
  649. int peer_timers_connect_unset (struct peer *);
  650. int peer_advertise_interval_set (struct peer *, u_int32_t);
  651. int peer_advertise_interval_unset (struct peer *);
  652. int peer_version_set (struct peer *, int);
  653. int peer_version_unset (struct peer *);
  654. int peer_interface_set (struct peer *, char *);
  655. int peer_interface_unset (struct peer *);
  656. int peer_distribute_set (struct peer *, afi_t, safi_t, int, char *);
  657. int peer_distribute_unset (struct peer *, afi_t, safi_t, int);
  658. int peer_allowas_in_set (struct peer *, afi_t, safi_t, int);
  659. int peer_allowas_in_unset (struct peer *, afi_t, safi_t);
  660. int peer_local_as_set (struct peer *, as_t, int);
  661. int peer_local_as_unset (struct peer *);
  662. int peer_prefix_list_set (struct peer *, afi_t, safi_t, int, char *);
  663. int peer_prefix_list_unset (struct peer *, afi_t, safi_t, int);
  664. int peer_aslist_set (struct peer *, afi_t, safi_t, int, char *);
  665. int peer_aslist_unset (struct peer *,afi_t, safi_t, int);
  666. int peer_route_map_set (struct peer *, afi_t, safi_t, int, char *);
  667. int peer_route_map_unset (struct peer *, afi_t, safi_t, int);
  668. int peer_unsuppress_map_set (struct peer *, afi_t, safi_t, char *);
  669. int peer_unsuppress_map_unset (struct peer *, afi_t, safi_t);
  670. int peer_maximum_prefix_set (struct peer *, afi_t, safi_t, u_int32_t, int);
  671. int peer_maximum_prefix_unset (struct peer *, afi_t, safi_t);
  672. int peer_clear (struct peer *);
  673. int peer_clear_soft (struct peer *, afi_t, safi_t, enum bgp_clear_type);