bgpd.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  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. #ifndef _QUAGGA_BGPD_H
  17. #define _QUAGGA_BGPD_H
  18. /* For union sockunion. */
  19. #include "sockunion.h"
  20. /* Typedef BGP specific types. */
  21. typedef u_int32_t as_t;
  22. typedef u_int16_t as16_t; /* we may still encounter 16 Bit asnums */
  23. typedef u_int16_t bgp_size_t;
  24. /* BGP master for system wide configurations and variables. */
  25. struct bgp_master
  26. {
  27. /* BGP instance list. */
  28. struct list *bgp;
  29. /* BGP thread master. */
  30. struct thread_master *master;
  31. /* work queues */
  32. struct work_queue *process_main_queue;
  33. struct work_queue *process_rsclient_queue;
  34. /* Listening sockets */
  35. struct list *listen_sockets;
  36. /* BGP port number. */
  37. u_int16_t port;
  38. /* Listener address */
  39. char *address;
  40. /* BGP start time. */
  41. time_t start_time;
  42. /* Various BGP global configuration. */
  43. u_char options;
  44. #define BGP_OPT_NO_FIB (1 << 0)
  45. #define BGP_OPT_MULTIPLE_INSTANCE (1 << 1)
  46. #define BGP_OPT_CONFIG_CISCO (1 << 2)
  47. };
  48. /* BGP instance structure. */
  49. struct bgp
  50. {
  51. /* AS number of this BGP instance. */
  52. as_t as;
  53. /* Name of this BGP instance. */
  54. char *name;
  55. /* Reference count to allow peer_delete to finish after bgp_delete */
  56. int lock;
  57. /* Self peer. */
  58. struct peer *peer_self;
  59. /* BGP peer. */
  60. struct list *peer;
  61. /* BGP peer group. */
  62. struct list *group;
  63. /* BGP route-server-clients. */
  64. struct list *rsclient;
  65. /* BGP configuration. */
  66. u_int16_t config;
  67. #define BGP_CONFIG_ROUTER_ID (1 << 0)
  68. #define BGP_CONFIG_CLUSTER_ID (1 << 1)
  69. #define BGP_CONFIG_CONFEDERATION (1 << 2)
  70. /* BGP router identifier. */
  71. struct in_addr router_id;
  72. struct in_addr router_id_static;
  73. /* BGP route reflector cluster ID. */
  74. struct in_addr cluster_id;
  75. /* BGP confederation information. */
  76. as_t confed_id;
  77. as_t *confed_peers;
  78. int confed_peers_cnt;
  79. /* BGP flags. */
  80. u_int16_t flags;
  81. #define BGP_FLAG_ALWAYS_COMPARE_MED (1 << 0)
  82. #define BGP_FLAG_DETERMINISTIC_MED (1 << 1)
  83. #define BGP_FLAG_MED_MISSING_AS_WORST (1 << 2)
  84. #define BGP_FLAG_MED_CONFED (1 << 3)
  85. #define BGP_FLAG_NO_DEFAULT_IPV4 (1 << 4)
  86. #define BGP_FLAG_NO_CLIENT_TO_CLIENT (1 << 5)
  87. #define BGP_FLAG_ENFORCE_FIRST_AS (1 << 6)
  88. #define BGP_FLAG_COMPARE_ROUTER_ID (1 << 7)
  89. #define BGP_FLAG_ASPATH_IGNORE (1 << 8)
  90. #define BGP_FLAG_IMPORT_CHECK (1 << 9)
  91. #define BGP_FLAG_NO_FAST_EXT_FAILOVER (1 << 10)
  92. #define BGP_FLAG_LOG_NEIGHBOR_CHANGES (1 << 11)
  93. #define BGP_FLAG_GRACEFUL_RESTART (1 << 12)
  94. #define BGP_FLAG_ASPATH_CONFED (1 << 13)
  95. /* BGP Per AF flags */
  96. u_int16_t af_flags[AFI_MAX][SAFI_MAX];
  97. #define BGP_CONFIG_DAMPENING (1 << 0)
  98. /* Static route configuration. */
  99. struct bgp_table *route[AFI_MAX][SAFI_MAX];
  100. /* Aggregate address configuration. */
  101. struct bgp_table *aggregate[AFI_MAX][SAFI_MAX];
  102. /* BGP routing information base. */
  103. struct bgp_table *rib[AFI_MAX][SAFI_MAX];
  104. /* BGP redistribute configuration. */
  105. u_char redist[AFI_MAX][ZEBRA_ROUTE_MAX];
  106. /* BGP redistribute metric configuration. */
  107. u_char redist_metric_flag[AFI_MAX][ZEBRA_ROUTE_MAX];
  108. u_int32_t redist_metric[AFI_MAX][ZEBRA_ROUTE_MAX];
  109. /* BGP redistribute route-map. */
  110. struct
  111. {
  112. char *name;
  113. struct route_map *map;
  114. } rmap[AFI_MAX][ZEBRA_ROUTE_MAX];
  115. /* BGP distance configuration. */
  116. u_char distance_ebgp;
  117. u_char distance_ibgp;
  118. u_char distance_local;
  119. /* BGP default local-preference. */
  120. u_int32_t default_local_pref;
  121. /* BGP default timer. */
  122. u_int32_t default_holdtime;
  123. u_int32_t default_keepalive;
  124. /* BGP graceful restart */
  125. u_int32_t restart_time;
  126. u_int32_t stalepath_time;
  127. };
  128. /* BGP peer-group support. */
  129. struct peer_group
  130. {
  131. /* Name of the peer-group. */
  132. char *name;
  133. /* Pointer to BGP. */
  134. struct bgp *bgp;
  135. /* Peer-group client list. */
  136. struct list *peer;
  137. /* Peer-group config */
  138. struct peer *conf;
  139. };
  140. /* BGP Notify message format. */
  141. struct bgp_notify
  142. {
  143. u_char code;
  144. u_char subcode;
  145. char *data;
  146. bgp_size_t length;
  147. };
  148. /* Next hop self address. */
  149. struct bgp_nexthop
  150. {
  151. struct interface *ifp;
  152. struct in_addr v4;
  153. #ifdef HAVE_IPV6
  154. struct in6_addr v6_global;
  155. struct in6_addr v6_local;
  156. #endif /* HAVE_IPV6 */
  157. };
  158. /* BGP router distinguisher value. */
  159. #define BGP_RD_SIZE 8
  160. struct bgp_rd
  161. {
  162. u_char val[BGP_RD_SIZE];
  163. };
  164. #define RMAP_IN 0
  165. #define RMAP_OUT 1
  166. #define RMAP_IMPORT 2
  167. #define RMAP_EXPORT 3
  168. #define RMAP_MAX 4
  169. /* BGP filter structure. */
  170. struct bgp_filter
  171. {
  172. /* Distribute-list. */
  173. struct
  174. {
  175. char *name;
  176. struct access_list *alist;
  177. } dlist[FILTER_MAX];
  178. /* Prefix-list. */
  179. struct
  180. {
  181. char *name;
  182. struct prefix_list *plist;
  183. } plist[FILTER_MAX];
  184. /* Filter-list. */
  185. struct
  186. {
  187. char *name;
  188. struct as_list *aslist;
  189. } aslist[FILTER_MAX];
  190. /* Route-map. */
  191. struct
  192. {
  193. char *name;
  194. struct route_map *map;
  195. } map[RMAP_MAX];
  196. /* Unsuppress-map. */
  197. struct
  198. {
  199. char *name;
  200. struct route_map *map;
  201. } usmap;
  202. };
  203. /* BGP neighbor structure. */
  204. struct peer
  205. {
  206. /* BGP structure. */
  207. struct bgp *bgp;
  208. /* reference count, primarily to allow bgp_process'ing of route_node's
  209. * to be done after a struct peer is deleted.
  210. *
  211. * named 'lock' for hysterical reasons within Quagga.
  212. */
  213. int lock;
  214. /* BGP peer group. */
  215. struct peer_group *group;
  216. u_char af_group[AFI_MAX][SAFI_MAX];
  217. /* Peer's remote AS number. */
  218. as_t as;
  219. /* Peer's local AS number. */
  220. as_t local_as;
  221. /* Peer's Change local AS number. */
  222. as_t change_local_as;
  223. /* Remote router ID. */
  224. struct in_addr remote_id;
  225. /* Local router ID. */
  226. struct in_addr local_id;
  227. /* Peer specific RIB when configured as route-server-client. */
  228. struct bgp_table *rib[AFI_MAX][SAFI_MAX];
  229. /* Packet receive and send buffer. */
  230. struct stream *ibuf;
  231. struct stream_fifo *obuf;
  232. struct stream *work;
  233. /* Status of the peer. */
  234. int status;
  235. int ostatus;
  236. /* Peer index, used for dumping TABLE_DUMP_V2 format */
  237. uint16_t table_dump_index;
  238. /* Peer information */
  239. int fd; /* File descriptor */
  240. int ttl; /* TTL of TCP connection to the peer. */
  241. char *desc; /* Description of the peer. */
  242. unsigned short port; /* Destination port for peer */
  243. char *host; /* Printable address of the peer. */
  244. union sockunion su; /* Sockunion address of the peer. */
  245. time_t uptime; /* Last Up/Down time */
  246. time_t readtime; /* Last read time */
  247. time_t resettime; /* Last reset time */
  248. unsigned int ifindex; /* ifindex of the BGP connection. */
  249. char *ifname; /* bind interface name. */
  250. char *update_if;
  251. union sockunion *update_source;
  252. struct zlog *log;
  253. union sockunion *su_local; /* Sockunion of local address. */
  254. union sockunion *su_remote; /* Sockunion of remote address. */
  255. int shared_network; /* Is this peer shared same network. */
  256. struct bgp_nexthop nexthop; /* Nexthop */
  257. /* Peer address family configuration. */
  258. u_char afc[AFI_MAX][SAFI_MAX];
  259. u_char afc_nego[AFI_MAX][SAFI_MAX];
  260. u_char afc_adv[AFI_MAX][SAFI_MAX];
  261. u_char afc_recv[AFI_MAX][SAFI_MAX];
  262. /* Capability flags (reset in bgp_stop) */
  263. u_int16_t cap;
  264. #define PEER_CAP_REFRESH_ADV (1 << 0) /* refresh advertised */
  265. #define PEER_CAP_REFRESH_OLD_RCV (1 << 1) /* refresh old received */
  266. #define PEER_CAP_REFRESH_NEW_RCV (1 << 2) /* refresh rfc received */
  267. #define PEER_CAP_DYNAMIC_ADV (1 << 3) /* dynamic advertised */
  268. #define PEER_CAP_DYNAMIC_RCV (1 << 4) /* dynamic received */
  269. #define PEER_CAP_RESTART_ADV (1 << 5) /* restart advertised */
  270. #define PEER_CAP_RESTART_RCV (1 << 6) /* restart received */
  271. #define PEER_CAP_AS4_ADV (1 << 7) /* as4 advertised */
  272. #define PEER_CAP_AS4_RCV (1 << 8) /* as4 received */
  273. /* Capability flags (reset in bgp_stop) */
  274. u_int16_t af_cap[AFI_MAX][SAFI_MAX];
  275. #define PEER_CAP_ORF_PREFIX_SM_ADV (1 << 0) /* send-mode advertised */
  276. #define PEER_CAP_ORF_PREFIX_RM_ADV (1 << 1) /* receive-mode advertised */
  277. #define PEER_CAP_ORF_PREFIX_SM_RCV (1 << 2) /* send-mode received */
  278. #define PEER_CAP_ORF_PREFIX_RM_RCV (1 << 3) /* receive-mode received */
  279. #define PEER_CAP_ORF_PREFIX_SM_OLD_RCV (1 << 4) /* send-mode received */
  280. #define PEER_CAP_ORF_PREFIX_RM_OLD_RCV (1 << 5) /* receive-mode received */
  281. #define PEER_CAP_RESTART_AF_RCV (1 << 6) /* graceful restart afi/safi received */
  282. #define PEER_CAP_RESTART_AF_PRESERVE_RCV (1 << 7) /* graceful restart afi/safi F-bit received */
  283. /* Global configuration flags. */
  284. u_int32_t flags;
  285. #define PEER_FLAG_PASSIVE (1 << 0) /* passive mode */
  286. #define PEER_FLAG_SHUTDOWN (1 << 1) /* shutdown */
  287. #define PEER_FLAG_DONT_CAPABILITY (1 << 2) /* dont-capability */
  288. #define PEER_FLAG_OVERRIDE_CAPABILITY (1 << 3) /* override-capability */
  289. #define PEER_FLAG_STRICT_CAP_MATCH (1 << 4) /* strict-match */
  290. #define PEER_FLAG_DYNAMIC_CAPABILITY (1 << 5) /* dynamic capability */
  291. #define PEER_FLAG_DISABLE_CONNECTED_CHECK (1 << 6) /* disable-connected-check */
  292. #define PEER_FLAG_LOCAL_AS_NO_PREPEND (1 << 7) /* local-as no-prepend */
  293. /* NSF mode (graceful restart) */
  294. u_char nsf[AFI_MAX][SAFI_MAX];
  295. /* Per AF configuration flags. */
  296. u_int32_t af_flags[AFI_MAX][SAFI_MAX];
  297. #define PEER_FLAG_SEND_COMMUNITY (1 << 0) /* send-community */
  298. #define PEER_FLAG_SEND_EXT_COMMUNITY (1 << 1) /* send-community ext. */
  299. #define PEER_FLAG_NEXTHOP_SELF (1 << 2) /* next-hop-self */
  300. #define PEER_FLAG_REFLECTOR_CLIENT (1 << 3) /* reflector-client */
  301. #define PEER_FLAG_RSERVER_CLIENT (1 << 4) /* route-server-client */
  302. #define PEER_FLAG_SOFT_RECONFIG (1 << 5) /* soft-reconfiguration */
  303. #define PEER_FLAG_AS_PATH_UNCHANGED (1 << 6) /* transparent-as */
  304. #define PEER_FLAG_NEXTHOP_UNCHANGED (1 << 7) /* transparent-next-hop */
  305. #define PEER_FLAG_MED_UNCHANGED (1 << 8) /* transparent-next-hop */
  306. #define PEER_FLAG_DEFAULT_ORIGINATE (1 << 9) /* default-originate */
  307. #define PEER_FLAG_REMOVE_PRIVATE_AS (1 << 10) /* remove-private-as */
  308. #define PEER_FLAG_ALLOWAS_IN (1 << 11) /* set allowas-in */
  309. #define PEER_FLAG_ORF_PREFIX_SM (1 << 12) /* orf capability send-mode */
  310. #define PEER_FLAG_ORF_PREFIX_RM (1 << 13) /* orf capability receive-mode */
  311. #define PEER_FLAG_MAX_PREFIX (1 << 14) /* maximum prefix */
  312. #define PEER_FLAG_MAX_PREFIX_WARNING (1 << 15) /* maximum prefix warning-only */
  313. #define PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED (1 << 16) /* leave link-local nexthop unchanged */
  314. /* MD5 password */
  315. char *password;
  316. /* default-originate route-map. */
  317. struct
  318. {
  319. char *name;
  320. struct route_map *map;
  321. } default_rmap[AFI_MAX][SAFI_MAX];
  322. /* Peer status flags. */
  323. u_int16_t sflags;
  324. #define PEER_STATUS_ACCEPT_PEER (1 << 0) /* accept peer */
  325. #define PEER_STATUS_PREFIX_OVERFLOW (1 << 1) /* prefix-overflow */
  326. #define PEER_STATUS_CAPABILITY_OPEN (1 << 2) /* capability open send */
  327. #define PEER_STATUS_HAVE_ACCEPT (1 << 3) /* accept peer's parent */
  328. #define PEER_STATUS_GROUP (1 << 4) /* peer-group conf */
  329. #define PEER_STATUS_NSF_MODE (1 << 5) /* NSF aware peer */
  330. #define PEER_STATUS_NSF_WAIT (1 << 6) /* wait comeback peer */
  331. /* Peer status af flags (reset in bgp_stop) */
  332. u_int16_t af_sflags[AFI_MAX][SAFI_MAX];
  333. #define PEER_STATUS_ORF_PREFIX_SEND (1 << 0) /* prefix-list send peer */
  334. #define PEER_STATUS_ORF_WAIT_REFRESH (1 << 1) /* wait refresh received peer */
  335. #define PEER_STATUS_DEFAULT_ORIGINATE (1 << 2) /* default-originate peer */
  336. #define PEER_STATUS_PREFIX_THRESHOLD (1 << 3) /* exceed prefix-threshold */
  337. #define PEER_STATUS_PREFIX_LIMIT (1 << 4) /* exceed prefix-limit */
  338. #define PEER_STATUS_EOR_SEND (1 << 5) /* end-of-rib send to peer */
  339. #define PEER_STATUS_EOR_RECEIVED (1 << 6) /* end-of-rib received from peer */
  340. /* Default attribute value for the peer. */
  341. u_int32_t config;
  342. #define PEER_CONFIG_WEIGHT (1 << 0) /* Default weight. */
  343. #define PEER_CONFIG_TIMER (1 << 1) /* keepalive & holdtime */
  344. #define PEER_CONFIG_CONNECT (1 << 2) /* connect */
  345. #define PEER_CONFIG_ROUTEADV (1 << 3) /* route advertise */
  346. u_int32_t weight;
  347. u_int32_t holdtime;
  348. u_int32_t keepalive;
  349. u_int32_t connect;
  350. u_int32_t routeadv;
  351. /* Timer values. */
  352. u_int32_t v_start;
  353. u_int32_t v_connect;
  354. u_int32_t v_holdtime;
  355. u_int32_t v_keepalive;
  356. u_int32_t v_asorig;
  357. u_int32_t v_routeadv;
  358. u_int32_t v_pmax_restart;
  359. u_int32_t v_gr_restart;
  360. /* Threads. */
  361. struct thread *t_read;
  362. struct thread *t_write;
  363. struct thread *t_start;
  364. struct thread *t_connect;
  365. struct thread *t_holdtime;
  366. struct thread *t_keepalive;
  367. struct thread *t_asorig;
  368. struct thread *t_routeadv;
  369. struct thread *t_pmax_restart;
  370. struct thread *t_gr_restart;
  371. struct thread *t_gr_stale;
  372. /* workqueues */
  373. struct work_queue *clear_node_queue;
  374. /* Statistics field */
  375. u_int32_t open_in; /* Open message input count */
  376. u_int32_t open_out; /* Open message output count */
  377. u_int32_t update_in; /* Update message input count */
  378. u_int32_t update_out; /* Update message ouput count */
  379. time_t update_time; /* Update message received time. */
  380. u_int32_t keepalive_in; /* Keepalive input count */
  381. u_int32_t keepalive_out; /* Keepalive output count */
  382. u_int32_t notify_in; /* Notify input count */
  383. u_int32_t notify_out; /* Notify output count */
  384. u_int32_t refresh_in; /* Route Refresh input count */
  385. u_int32_t refresh_out; /* Route Refresh output count */
  386. u_int32_t dynamic_cap_in; /* Dynamic Capability input count. */
  387. u_int32_t dynamic_cap_out; /* Dynamic Capability output count. */
  388. /* BGP state count */
  389. u_int32_t established; /* Established */
  390. u_int32_t dropped; /* Dropped */
  391. /* Syncronization list and time. */
  392. struct bgp_synchronize *sync[AFI_MAX][SAFI_MAX];
  393. time_t synctime;
  394. /* Send prefix count. */
  395. unsigned long scount[AFI_MAX][SAFI_MAX];
  396. /* Announcement attribute hash. */
  397. struct hash *hash[AFI_MAX][SAFI_MAX];
  398. /* Notify data. */
  399. struct bgp_notify notify;
  400. /* Whole packet size to be read. */
  401. unsigned long packet_size;
  402. /* Filter structure. */
  403. struct bgp_filter filter[AFI_MAX][SAFI_MAX];
  404. /* ORF Prefix-list */
  405. struct prefix_list *orf_plist[AFI_MAX][SAFI_MAX];
  406. /* Prefix count. */
  407. unsigned long pcount[AFI_MAX][SAFI_MAX];
  408. /* Max prefix count. */
  409. unsigned long pmax[AFI_MAX][SAFI_MAX];
  410. u_char pmax_threshold[AFI_MAX][SAFI_MAX];
  411. u_int16_t pmax_restart[AFI_MAX][SAFI_MAX];
  412. #define MAXIMUM_PREFIX_THRESHOLD_DEFAULT 75
  413. /* allowas-in. */
  414. char allowas_in[AFI_MAX][SAFI_MAX];
  415. /* peer reset cause */
  416. char last_reset;
  417. #define PEER_DOWN_RID_CHANGE 1 /* bgp router-id command */
  418. #define PEER_DOWN_REMOTE_AS_CHANGE 2 /* neighbor remote-as command */
  419. #define PEER_DOWN_LOCAL_AS_CHANGE 3 /* neighbor local-as command */
  420. #define PEER_DOWN_CLID_CHANGE 4 /* bgp cluster-id command */
  421. #define PEER_DOWN_CONFED_ID_CHANGE 5 /* bgp confederation identifier command */
  422. #define PEER_DOWN_CONFED_PEER_CHANGE 6 /* bgp confederation peer command */
  423. #define PEER_DOWN_RR_CLIENT_CHANGE 7 /* neighbor route-reflector-client command */
  424. #define PEER_DOWN_RS_CLIENT_CHANGE 8 /* neighbor route-server-client command */
  425. #define PEER_DOWN_UPDATE_SOURCE_CHANGE 9 /* neighbor update-source command */
  426. #define PEER_DOWN_AF_ACTIVATE 10 /* neighbor activate command */
  427. #define PEER_DOWN_USER_SHUTDOWN 11 /* neighbor shutdown command */
  428. #define PEER_DOWN_USER_RESET 12 /* clear ip bgp command */
  429. #define PEER_DOWN_NOTIFY_RECEIVED 13 /* notification received */
  430. #define PEER_DOWN_NOTIFY_SEND 14 /* notification send */
  431. #define PEER_DOWN_CLOSE_SESSION 15 /* tcp session close */
  432. #define PEER_DOWN_NEIGHBOR_DELETE 16 /* neghbor delete */
  433. #define PEER_DOWN_RMAP_BIND 17 /* neghbor peer-group command */
  434. #define PEER_DOWN_RMAP_UNBIND 18 /* no neighbor peer-group command */
  435. #define PEER_DOWN_CAPABILITY_CHANGE 19 /* neighbor capability command */
  436. #define PEER_DOWN_PASSIVE_CHANGE 20 /* neighbor passive command */
  437. #define PEER_DOWN_MULTIHOP_CHANGE 21 /* neighbor multihop command */
  438. #define PEER_DOWN_NSF_CLOSE_SESSION 22 /* NSF tcp session close */
  439. /* The kind of route-map Flags.*/
  440. u_char rmap_type;
  441. #define PEER_RMAP_TYPE_IN (1 << 0) /* neighbor route-map in */
  442. #define PEER_RMAP_TYPE_OUT (1 << 1) /* neighbor route-map out */
  443. #define PEER_RMAP_TYPE_NETWORK (1 << 2) /* network route-map */
  444. #define PEER_RMAP_TYPE_REDISTRIBUTE (1 << 3) /* redistribute route-map */
  445. #define PEER_RMAP_TYPE_DEFAULT (1 << 4) /* default-originate route-map */
  446. #define PEER_RMAP_TYPE_NOSET (1 << 5) /* not allow to set commands */
  447. #define PEER_RMAP_TYPE_IMPORT (1 << 6) /* neighbor route-map import */
  448. #define PEER_RMAP_TYPE_EXPORT (1 << 7) /* neighbor route-map export */
  449. };
  450. #define PEER_PASSWORD_MINLEN (1)
  451. #define PEER_PASSWORD_MAXLEN (80)
  452. /* This structure's member directly points incoming packet data
  453. stream. */
  454. struct bgp_nlri
  455. {
  456. /* AFI. */
  457. afi_t afi;
  458. /* SAFI. */
  459. safi_t safi;
  460. /* Pointer to NLRI byte stream. */
  461. u_char *nlri;
  462. /* Length of whole NLRI. */
  463. bgp_size_t length;
  464. };
  465. /* BGP versions. */
  466. #define BGP_VERSION_4 4
  467. /* Default BGP port number. */
  468. #define BGP_PORT_DEFAULT 179
  469. /* BGP message header and packet size. */
  470. #define BGP_MARKER_SIZE 16
  471. #define BGP_HEADER_SIZE 19
  472. #define BGP_MAX_PACKET_SIZE 4096
  473. /* BGP minimum message size. */
  474. #define BGP_MSG_OPEN_MIN_SIZE (BGP_HEADER_SIZE + 10)
  475. #define BGP_MSG_UPDATE_MIN_SIZE (BGP_HEADER_SIZE + 4)
  476. #define BGP_MSG_NOTIFY_MIN_SIZE (BGP_HEADER_SIZE + 2)
  477. #define BGP_MSG_KEEPALIVE_MIN_SIZE (BGP_HEADER_SIZE + 0)
  478. #define BGP_MSG_ROUTE_REFRESH_MIN_SIZE (BGP_HEADER_SIZE + 4)
  479. #define BGP_MSG_CAPABILITY_MIN_SIZE (BGP_HEADER_SIZE + 3)
  480. /* BGP message types. */
  481. #define BGP_MSG_OPEN 1
  482. #define BGP_MSG_UPDATE 2
  483. #define BGP_MSG_NOTIFY 3
  484. #define BGP_MSG_KEEPALIVE 4
  485. #define BGP_MSG_ROUTE_REFRESH_NEW 5
  486. #define BGP_MSG_CAPABILITY 6
  487. #define BGP_MSG_ROUTE_REFRESH_OLD 128
  488. /* BGP open optional parameter. */
  489. #define BGP_OPEN_OPT_AUTH 1
  490. #define BGP_OPEN_OPT_CAP 2
  491. /* BGP4 attribute type codes. */
  492. #define BGP_ATTR_ORIGIN 1
  493. #define BGP_ATTR_AS_PATH 2
  494. #define BGP_ATTR_NEXT_HOP 3
  495. #define BGP_ATTR_MULTI_EXIT_DISC 4
  496. #define BGP_ATTR_LOCAL_PREF 5
  497. #define BGP_ATTR_ATOMIC_AGGREGATE 6
  498. #define BGP_ATTR_AGGREGATOR 7
  499. #define BGP_ATTR_COMMUNITIES 8
  500. #define BGP_ATTR_ORIGINATOR_ID 9
  501. #define BGP_ATTR_CLUSTER_LIST 10
  502. #define BGP_ATTR_DPA 11
  503. #define BGP_ATTR_ADVERTISER 12
  504. #define BGP_ATTR_RCID_PATH 13
  505. #define BGP_ATTR_MP_REACH_NLRI 14
  506. #define BGP_ATTR_MP_UNREACH_NLRI 15
  507. #define BGP_ATTR_EXT_COMMUNITIES 16
  508. #define BGP_ATTR_AS4_PATH 17
  509. #define BGP_ATTR_AS4_AGGREGATOR 18
  510. #define BGP_ATTR_AS_PATHLIMIT 21
  511. /* BGP update origin. */
  512. #define BGP_ORIGIN_IGP 0
  513. #define BGP_ORIGIN_EGP 1
  514. #define BGP_ORIGIN_INCOMPLETE 2
  515. /* BGP notify message codes. */
  516. #define BGP_NOTIFY_HEADER_ERR 1
  517. #define BGP_NOTIFY_OPEN_ERR 2
  518. #define BGP_NOTIFY_UPDATE_ERR 3
  519. #define BGP_NOTIFY_HOLD_ERR 4
  520. #define BGP_NOTIFY_FSM_ERR 5
  521. #define BGP_NOTIFY_CEASE 6
  522. #define BGP_NOTIFY_CAPABILITY_ERR 7
  523. #define BGP_NOTIFY_MAX 8
  524. /* BGP_NOTIFY_HEADER_ERR sub codes. */
  525. #define BGP_NOTIFY_HEADER_NOT_SYNC 1
  526. #define BGP_NOTIFY_HEADER_BAD_MESLEN 2
  527. #define BGP_NOTIFY_HEADER_BAD_MESTYPE 3
  528. #define BGP_NOTIFY_HEADER_MAX 4
  529. /* BGP_NOTIFY_OPEN_ERR sub codes. */
  530. #define BGP_NOTIFY_OPEN_UNSUP_VERSION 1
  531. #define BGP_NOTIFY_OPEN_BAD_PEER_AS 2
  532. #define BGP_NOTIFY_OPEN_BAD_BGP_IDENT 3
  533. #define BGP_NOTIFY_OPEN_UNSUP_PARAM 4
  534. #define BGP_NOTIFY_OPEN_AUTH_FAILURE 5
  535. #define BGP_NOTIFY_OPEN_UNACEP_HOLDTIME 6
  536. #define BGP_NOTIFY_OPEN_UNSUP_CAPBL 7
  537. #define BGP_NOTIFY_OPEN_MAX 8
  538. /* BGP_NOTIFY_UPDATE_ERR sub codes. */
  539. #define BGP_NOTIFY_UPDATE_MAL_ATTR 1
  540. #define BGP_NOTIFY_UPDATE_UNREC_ATTR 2
  541. #define BGP_NOTIFY_UPDATE_MISS_ATTR 3
  542. #define BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR 4
  543. #define BGP_NOTIFY_UPDATE_ATTR_LENG_ERR 5
  544. #define BGP_NOTIFY_UPDATE_INVAL_ORIGIN 6
  545. #define BGP_NOTIFY_UPDATE_AS_ROUTE_LOOP 7
  546. #define BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP 8
  547. #define BGP_NOTIFY_UPDATE_OPT_ATTR_ERR 9
  548. #define BGP_NOTIFY_UPDATE_INVAL_NETWORK 10
  549. #define BGP_NOTIFY_UPDATE_MAL_AS_PATH 11
  550. #define BGP_NOTIFY_UPDATE_MAX 12
  551. /* BGP_NOTIFY_CEASE sub codes (draft-ietf-idr-cease-subcode-05). */
  552. #define BGP_NOTIFY_CEASE_MAX_PREFIX 1
  553. #define BGP_NOTIFY_CEASE_ADMIN_SHUTDOWN 2
  554. #define BGP_NOTIFY_CEASE_PEER_UNCONFIG 3
  555. #define BGP_NOTIFY_CEASE_ADMIN_RESET 4
  556. #define BGP_NOTIFY_CEASE_CONNECT_REJECT 5
  557. #define BGP_NOTIFY_CEASE_CONFIG_CHANGE 6
  558. #define BGP_NOTIFY_CEASE_COLLISION_RESOLUTION 7
  559. #define BGP_NOTIFY_CEASE_OUT_OF_RESOURCE 8
  560. #define BGP_NOTIFY_CEASE_MAX 9
  561. /* BGP_NOTIFY_CAPABILITY_ERR sub codes (draft-ietf-idr-dynamic-cap-02). */
  562. #define BGP_NOTIFY_CAPABILITY_INVALID_ACTION 1
  563. #define BGP_NOTIFY_CAPABILITY_INVALID_LENGTH 2
  564. #define BGP_NOTIFY_CAPABILITY_MALFORMED_CODE 3
  565. #define BGP_NOTIFY_CAPABILITY_MAX 4
  566. /* BGP finite state machine status. */
  567. #define Idle 1
  568. #define Connect 2
  569. #define Active 3
  570. #define OpenSent 4
  571. #define OpenConfirm 5
  572. #define Established 6
  573. #define Clearing 7
  574. #define Deleted 8
  575. #define BGP_STATUS_MAX 9
  576. /* BGP finite state machine events. */
  577. #define BGP_Start 1
  578. #define BGP_Stop 2
  579. #define TCP_connection_open 3
  580. #define TCP_connection_closed 4
  581. #define TCP_connection_open_failed 5
  582. #define TCP_fatal_error 6
  583. #define ConnectRetry_timer_expired 7
  584. #define Hold_Timer_expired 8
  585. #define KeepAlive_timer_expired 9
  586. #define Receive_OPEN_message 10
  587. #define Receive_KEEPALIVE_message 11
  588. #define Receive_UPDATE_message 12
  589. #define Receive_NOTIFICATION_message 13
  590. #define Clearing_Completed 14
  591. #define BGP_EVENTS_MAX 15
  592. /* BGP timers default value. */
  593. #define BGP_INIT_START_TIMER 5
  594. #define BGP_ERROR_START_TIMER 30
  595. #define BGP_DEFAULT_HOLDTIME 180
  596. #define BGP_DEFAULT_KEEPALIVE 60
  597. #define BGP_DEFAULT_ASORIGINATE 15
  598. #define BGP_DEFAULT_EBGP_ROUTEADV 30
  599. #define BGP_DEFAULT_IBGP_ROUTEADV 5
  600. #define BGP_CLEAR_CONNECT_RETRY 20
  601. #define BGP_DEFAULT_CONNECT_RETRY 120
  602. /* BGP default local preference. */
  603. #define BGP_DEFAULT_LOCAL_PREF 100
  604. /* BGP graceful restart */
  605. #define BGP_DEFAULT_RESTART_TIME 120
  606. #define BGP_DEFAULT_STALEPATH_TIME 360
  607. /* SAFI which used in open capability negotiation. */
  608. #define BGP_SAFI_VPNV4 128
  609. #define BGP_SAFI_VPNV6 129
  610. /* Max TTL value. */
  611. #define TTL_MAX 255
  612. /* BGP uptime string length. */
  613. #define BGP_UPTIME_LEN 25
  614. /* Default configuration settings for bgpd. */
  615. #define BGP_VTY_PORT 2605
  616. #define BGP_DEFAULT_CONFIG "bgpd.conf"
  617. /* Check AS path loop when we send NLRI. */
  618. /* #define BGP_SEND_ASPATH_CHECK */
  619. /* IBGP/EBGP identifier. We also have a CONFED peer, which is to say,
  620. a peer who's AS is part of our Confederation. */
  621. enum
  622. {
  623. BGP_PEER_IBGP,
  624. BGP_PEER_EBGP,
  625. BGP_PEER_INTERNAL,
  626. BGP_PEER_CONFED
  627. };
  628. /* Flag for peer_clear_soft(). */
  629. enum bgp_clear_type
  630. {
  631. BGP_CLEAR_SOFT_NONE,
  632. BGP_CLEAR_SOFT_OUT,
  633. BGP_CLEAR_SOFT_IN,
  634. BGP_CLEAR_SOFT_BOTH,
  635. BGP_CLEAR_SOFT_IN_ORF_PREFIX,
  636. BGP_CLEAR_SOFT_RSCLIENT
  637. };
  638. /* Macros. */
  639. #define BGP_INPUT(P) ((P)->ibuf)
  640. #define BGP_INPUT_PNT(P) (STREAM_PNT(BGP_INPUT(P)))
  641. /* Count prefix size from mask length */
  642. #define PSIZE(a) (((a) + 7) / (8))
  643. /* BGP error codes. */
  644. #define BGP_SUCCESS 0
  645. #define BGP_ERR_INVALID_VALUE -1
  646. #define BGP_ERR_INVALID_FLAG -2
  647. #define BGP_ERR_INVALID_AS -3
  648. #define BGP_ERR_INVALID_BGP -4
  649. #define BGP_ERR_PEER_GROUP_MEMBER -5
  650. #define BGP_ERR_MULTIPLE_INSTANCE_USED -6
  651. #define BGP_ERR_PEER_GROUP_MEMBER_EXISTS -7
  652. #define BGP_ERR_PEER_BELONGS_TO_GROUP -8
  653. #define BGP_ERR_PEER_GROUP_AF_UNCONFIGURED -9
  654. #define BGP_ERR_PEER_GROUP_NO_REMOTE_AS -10
  655. #define BGP_ERR_PEER_GROUP_CANT_CHANGE -11
  656. #define BGP_ERR_PEER_GROUP_MISMATCH -12
  657. #define BGP_ERR_PEER_GROUP_PEER_TYPE_DIFFERENT -13
  658. #define BGP_ERR_MULTIPLE_INSTANCE_NOT_SET -14
  659. #define BGP_ERR_AS_MISMATCH -15
  660. #define BGP_ERR_PEER_INACTIVE -16
  661. #define BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER -17
  662. #define BGP_ERR_PEER_GROUP_HAS_THE_FLAG -18
  663. #define BGP_ERR_PEER_FLAG_CONFLICT -19
  664. #define BGP_ERR_PEER_GROUP_SHUTDOWN -20
  665. #define BGP_ERR_PEER_FILTER_CONFLICT -21
  666. #define BGP_ERR_NOT_INTERNAL_PEER -22
  667. #define BGP_ERR_REMOVE_PRIVATE_AS -23
  668. #define BGP_ERR_AF_UNCONFIGURED -24
  669. #define BGP_ERR_SOFT_RECONFIG_UNCONFIGURED -25
  670. #define BGP_ERR_INSTANCE_MISMATCH -26
  671. #define BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP -27
  672. #define BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS -28
  673. #define BGP_ERR_TCPSIG_FAILED -29
  674. #define BGP_ERR_MAX -30
  675. extern struct bgp_master *bm;
  676. extern struct thread_master *master;
  677. /* Prototypes. */
  678. extern void bgp_terminate (void);
  679. extern void bgp_reset (void);
  680. extern time_t bgp_clock (void);
  681. extern void bgp_zclient_reset (void);
  682. extern int bgp_nexthop_set (union sockunion *, union sockunion *,
  683. struct bgp_nexthop *, struct peer *);
  684. extern struct bgp *bgp_get_default (void);
  685. extern struct bgp *bgp_lookup (as_t, const char *);
  686. extern struct bgp *bgp_lookup_by_name (const char *);
  687. extern struct peer *peer_lookup (struct bgp *, union sockunion *);
  688. extern struct peer_group *peer_group_lookup (struct bgp *, const char *);
  689. extern struct peer_group *peer_group_get (struct bgp *, const char *);
  690. extern struct peer *peer_lookup_with_open (union sockunion *, as_t, struct in_addr *,
  691. int *);
  692. extern struct peer *peer_lock (struct peer *);
  693. extern struct peer *peer_unlock (struct peer *);
  694. extern int peer_sort (struct peer *peer);
  695. extern int peer_active (struct peer *);
  696. extern int peer_active_nego (struct peer *);
  697. extern struct peer *peer_create_accept (struct bgp *);
  698. extern char *peer_uptime (time_t, char *, size_t);
  699. extern int bgp_config_write (struct vty *);
  700. extern void bgp_config_write_family_header (struct vty *, afi_t, safi_t, int *);
  701. extern void bgp_master_init (void);
  702. extern void bgp_init (void);
  703. extern void bgp_route_map_init (void);
  704. extern int bgp_option_set (int);
  705. extern int bgp_option_unset (int);
  706. extern int bgp_option_check (int);
  707. extern int bgp_get (struct bgp **, as_t *, const char *);
  708. extern int bgp_delete (struct bgp *);
  709. extern int bgp_flag_set (struct bgp *, int);
  710. extern int bgp_flag_unset (struct bgp *, int);
  711. extern int bgp_flag_check (struct bgp *, int);
  712. extern void bgp_lock (struct bgp *);
  713. extern void bgp_unlock (struct bgp *);
  714. extern int bgp_router_id_set (struct bgp *, struct in_addr *);
  715. extern int bgp_cluster_id_set (struct bgp *, struct in_addr *);
  716. extern int bgp_cluster_id_unset (struct bgp *);
  717. extern int bgp_confederation_id_set (struct bgp *, as_t);
  718. extern int bgp_confederation_id_unset (struct bgp *);
  719. extern int bgp_confederation_peers_check (struct bgp *, as_t);
  720. extern int bgp_confederation_peers_add (struct bgp *, as_t);
  721. extern int bgp_confederation_peers_remove (struct bgp *, as_t);
  722. extern int bgp_timers_set (struct bgp *, u_int32_t, u_int32_t);
  723. extern int bgp_timers_unset (struct bgp *);
  724. extern int bgp_default_local_preference_set (struct bgp *, u_int32_t);
  725. extern int bgp_default_local_preference_unset (struct bgp *);
  726. extern int peer_rsclient_active (struct peer *);
  727. extern int peer_remote_as (struct bgp *, union sockunion *, as_t *, afi_t, safi_t);
  728. extern int peer_group_remote_as (struct bgp *, const char *, as_t *);
  729. extern int peer_delete (struct peer *peer);
  730. extern int peer_group_delete (struct peer_group *);
  731. extern int peer_group_remote_as_delete (struct peer_group *);
  732. extern int peer_activate (struct peer *, afi_t, safi_t);
  733. extern int peer_deactivate (struct peer *, afi_t, safi_t);
  734. extern int peer_group_bind (struct bgp *, union sockunion *, struct peer_group *,
  735. afi_t, safi_t, as_t *);
  736. extern int peer_group_unbind (struct bgp *, struct peer *, struct peer_group *,
  737. afi_t, safi_t);
  738. extern int peer_flag_set (struct peer *, u_int32_t);
  739. extern int peer_flag_unset (struct peer *, u_int32_t);
  740. extern int peer_af_flag_set (struct peer *, afi_t, safi_t, u_int32_t);
  741. extern int peer_af_flag_unset (struct peer *, afi_t, safi_t, u_int32_t);
  742. extern int peer_af_flag_check (struct peer *, afi_t, safi_t, u_int32_t);
  743. extern int peer_ebgp_multihop_set (struct peer *, int);
  744. extern int peer_ebgp_multihop_unset (struct peer *);
  745. extern int peer_description_set (struct peer *, char *);
  746. extern int peer_description_unset (struct peer *);
  747. extern int peer_update_source_if_set (struct peer *, const char *);
  748. extern int peer_update_source_addr_set (struct peer *, union sockunion *);
  749. extern int peer_update_source_unset (struct peer *);
  750. extern int peer_default_originate_set (struct peer *, afi_t, safi_t, const char *);
  751. extern int peer_default_originate_unset (struct peer *, afi_t, safi_t);
  752. extern int peer_port_set (struct peer *, u_int16_t);
  753. extern int peer_port_unset (struct peer *);
  754. extern int peer_weight_set (struct peer *, u_int16_t);
  755. extern int peer_weight_unset (struct peer *);
  756. extern int peer_timers_set (struct peer *, u_int32_t, u_int32_t);
  757. extern int peer_timers_unset (struct peer *);
  758. extern int peer_timers_connect_set (struct peer *, u_int32_t);
  759. extern int peer_timers_connect_unset (struct peer *);
  760. extern int peer_advertise_interval_set (struct peer *, u_int32_t);
  761. extern int peer_advertise_interval_unset (struct peer *);
  762. extern int peer_interface_set (struct peer *, const char *);
  763. extern int peer_interface_unset (struct peer *);
  764. extern int peer_distribute_set (struct peer *, afi_t, safi_t, int, const char *);
  765. extern int peer_distribute_unset (struct peer *, afi_t, safi_t, int);
  766. extern int peer_allowas_in_set (struct peer *, afi_t, safi_t, int);
  767. extern int peer_allowas_in_unset (struct peer *, afi_t, safi_t);
  768. extern int peer_local_as_set (struct peer *, as_t, int);
  769. extern int peer_local_as_unset (struct peer *);
  770. extern int peer_prefix_list_set (struct peer *, afi_t, safi_t, int, const char *);
  771. extern int peer_prefix_list_unset (struct peer *, afi_t, safi_t, int);
  772. extern int peer_aslist_set (struct peer *, afi_t, safi_t, int, const char *);
  773. extern int peer_aslist_unset (struct peer *,afi_t, safi_t, int);
  774. extern int peer_route_map_set (struct peer *, afi_t, safi_t, int, const char *);
  775. extern int peer_route_map_unset (struct peer *, afi_t, safi_t, int);
  776. extern int peer_unsuppress_map_set (struct peer *, afi_t, safi_t, const char *);
  777. extern int peer_password_set (struct peer *, const char *);
  778. extern int peer_password_unset (struct peer *);
  779. extern int peer_unsuppress_map_unset (struct peer *, afi_t, safi_t);
  780. extern int peer_maximum_prefix_set (struct peer *, afi_t, safi_t, u_int32_t, u_char, int, u_int16_t);
  781. extern int peer_maximum_prefix_unset (struct peer *, afi_t, safi_t);
  782. extern int peer_clear (struct peer *);
  783. extern int peer_clear_soft (struct peer *, afi_t, safi_t, enum bgp_clear_type);
  784. #endif /* _QUAGGA_BGPD_H */