blob: 332714c4f845e4aebd22cff4d8db86df23e001e0 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information base
2 Copyright (C) 1996, 97, 98, 2000 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
paul00d252c2005-05-23 14:19:54 +000021#ifndef _QUAGGA_BGP_ROUTE_H
22#define _QUAGGA_BGP_ROUTE_H
23
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050024#include "queue.h"
paul200df112005-06-01 11:17:05 +000025#include "bgp_table.h"
26
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050027struct bgp_nexthop_cache;
28
Paul Jakmafb982c22007-05-04 20:15:47 +000029/* Ancillary information to struct bgp_info,
30 * used for uncommonly used data (aggregation, MPLS, etc.)
31 * and lazily allocated to save memory.
32 */
33struct bgp_info_extra
34{
35 /* Pointer to dampening structure. */
36 struct bgp_damp_info *damp_info;
37
38 /* This route is suppressed with aggregation. */
39 int suppress;
40
41 /* Nexthop reachability check. */
42 u_int32_t igpmetric;
43
44 /* MPLS label. */
45 u_char tag[3];
46};
47
paul718e3742002-12-13 20:15:29 +000048struct bgp_info
49{
50 /* For linked list. */
51 struct bgp_info *next;
52 struct bgp_info *prev;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050053
54 /* For nexthop linked list */
55 LIST_ENTRY(bgp_info) nh_thread;
56
57 /* Back pointer to the prefix node */
58 struct bgp_node *net;
59
60 /* Back pointer to the nexthop structure */
61 struct bgp_nexthop_cache *nexthop;
62
Paul Jakmacbdfbaa2006-03-30 13:20:48 +000063 /* Peer structure. */
64 struct peer *peer;
65
66 /* Attribute structure. */
67 struct attr *attr;
Paul Jakmafb982c22007-05-04 20:15:47 +000068
69 /* Extra information */
70 struct bgp_info_extra *extra;
71
Josh Baileyde8d5df2011-07-20 20:46:01 -070072
73 /* Multipath information */
74 struct bgp_info_mpath *mpath;
75
Paul Jakmacbdfbaa2006-03-30 13:20:48 +000076 /* Uptime. */
77 time_t uptime;
78
paul200df112005-06-01 11:17:05 +000079 /* reference count */
Chris Caputo228da422009-07-18 05:44:03 +000080 int lock;
paul200df112005-06-01 11:17:05 +000081
paul718e3742002-12-13 20:15:29 +000082 /* BGP information status. */
hasso93406d82005-02-02 14:40:33 +000083 u_int16_t flags;
paul718e3742002-12-13 20:15:29 +000084#define BGP_INFO_IGP_CHANGED (1 << 0)
85#define BGP_INFO_DAMPED (1 << 1)
86#define BGP_INFO_HISTORY (1 << 2)
87#define BGP_INFO_SELECTED (1 << 3)
88#define BGP_INFO_VALID (1 << 4)
89#define BGP_INFO_ATTR_CHANGED (1 << 5)
90#define BGP_INFO_DMED_CHECK (1 << 6)
91#define BGP_INFO_DMED_SELECTED (1 << 7)
hasso93406d82005-02-02 14:40:33 +000092#define BGP_INFO_STALE (1 << 8)
paulb40d9392005-08-22 22:34:41 +000093#define BGP_INFO_REMOVED (1 << 9)
paul902212c2006-02-05 17:51:19 +000094#define BGP_INFO_COUNTED (1 << 10)
Josh Baileyde8d5df2011-07-20 20:46:01 -070095#define BGP_INFO_MULTIPATH (1 << 11)
96#define BGP_INFO_MULTIPATH_CHG (1 << 12)
paul718e3742002-12-13 20:15:29 +000097
Paul Jakmacbdfbaa2006-03-30 13:20:48 +000098 /* BGP route type. This can be static, RIP, OSPF, BGP etc. */
99 u_char type;
100
101 /* When above type is BGP. This sub type specify BGP sub type
102 information. */
103 u_char sub_type;
104#define BGP_ROUTE_NORMAL 0
105#define BGP_ROUTE_STATIC 1
106#define BGP_ROUTE_AGGREGATE 2
107#define BGP_ROUTE_REDISTRIBUTE 3
paul718e3742002-12-13 20:15:29 +0000108};
109
110/* BGP static route configuration. */
111struct bgp_static
112{
113 /* Backdoor configuration. */
114 int backdoor;
115
116 /* Import check status. */
117 u_char valid;
118
119 /* IGP metric. */
120 u_int32_t igpmetric;
121
122 /* IGP nexthop. */
123 struct in_addr igpnexthop;
124
Paul Jakma41367172007-08-06 15:24:51 +0000125 /* Atomic set reference count (ie cause of pathlimit) */
126 u_int32_t atomic;
127
paul718e3742002-12-13 20:15:29 +0000128 /* BGP redistribute route-map. */
129 struct
130 {
131 char *name;
132 struct route_map *map;
133 } rmap;
134
Lou Bergera76d9ca2016-01-12 13:41:53 -0500135 /* Route Distinguisher */
136 struct prefix_rd prd;
137
paul718e3742002-12-13 20:15:29 +0000138 /* MPLS label. */
139 u_char tag[3];
140};
141
Daniel Waltone25a9742015-11-09 20:21:50 -0500142#define BGP_INFO_COUNTABLE(BI) \
143 (! CHECK_FLAG ((BI)->flags, BGP_INFO_HISTORY) \
144 && ! CHECK_FLAG ((BI)->flags, BGP_INFO_REMOVED))
145
Paul Jakma1a392d42006-09-07 00:24:49 +0000146/* Flags which indicate a route is unuseable in some form */
147#define BGP_INFO_UNUSEABLE \
148 (BGP_INFO_HISTORY|BGP_INFO_DAMPED|BGP_INFO_REMOVED)
149/* Macro to check BGP information is alive or not. Sadly,
150 * not equivalent to just checking previous, because of the
151 * sense of the additional VALID flag.
152 */
153#define BGP_INFO_HOLDDOWN(BI) \
154 (! CHECK_FLAG ((BI)->flags, BGP_INFO_VALID) \
155 || CHECK_FLAG ((BI)->flags, BGP_INFO_UNUSEABLE))
156
paul718e3742002-12-13 20:15:29 +0000157#define DISTRIBUTE_IN_NAME(F) ((F)->dlist[FILTER_IN].name)
158#define DISTRIBUTE_IN(F) ((F)->dlist[FILTER_IN].alist)
159#define DISTRIBUTE_OUT_NAME(F) ((F)->dlist[FILTER_OUT].name)
160#define DISTRIBUTE_OUT(F) ((F)->dlist[FILTER_OUT].alist)
161
162#define PREFIX_LIST_IN_NAME(F) ((F)->plist[FILTER_IN].name)
163#define PREFIX_LIST_IN(F) ((F)->plist[FILTER_IN].plist)
164#define PREFIX_LIST_OUT_NAME(F) ((F)->plist[FILTER_OUT].name)
165#define PREFIX_LIST_OUT(F) ((F)->plist[FILTER_OUT].plist)
166
167#define FILTER_LIST_IN_NAME(F) ((F)->aslist[FILTER_IN].name)
168#define FILTER_LIST_IN(F) ((F)->aslist[FILTER_IN].aslist)
169#define FILTER_LIST_OUT_NAME(F) ((F)->aslist[FILTER_OUT].name)
170#define FILTER_LIST_OUT(F) ((F)->aslist[FILTER_OUT].aslist)
171
paulfee0f4c2004-09-13 05:12:46 +0000172#define ROUTE_MAP_IN_NAME(F) ((F)->map[RMAP_IN].name)
173#define ROUTE_MAP_IN(F) ((F)->map[RMAP_IN].map)
174#define ROUTE_MAP_OUT_NAME(F) ((F)->map[RMAP_OUT].name)
175#define ROUTE_MAP_OUT(F) ((F)->map[RMAP_OUT].map)
176
177#define ROUTE_MAP_IMPORT_NAME(F) ((F)->map[RMAP_IMPORT].name)
178#define ROUTE_MAP_IMPORT(F) ((F)->map[RMAP_IMPORT].map)
179#define ROUTE_MAP_EXPORT_NAME(F) ((F)->map[RMAP_EXPORT].name)
180#define ROUTE_MAP_EXPORT(F) ((F)->map[RMAP_EXPORT].map)
paul718e3742002-12-13 20:15:29 +0000181
182#define UNSUPPRESS_MAP_NAME(F) ((F)->usmap.name)
183#define UNSUPPRESS_MAP(F) ((F)->usmap.map)
184
Chris Caputo228da422009-07-18 05:44:03 +0000185enum bgp_clear_route_type
186{
187 BGP_CLEAR_ROUTE_NORMAL,
188 BGP_CLEAR_ROUTE_MY_RSCLIENT
189};
190
Daniel Walton59fe0ee2015-05-19 17:58:11 -0700191enum bgp_path_type
192{
193 BGP_PATH_ALL,
194 BGP_PATH_BESTPATH,
195 BGP_PATH_MULTIPATH
196};
197
paul718e3742002-12-13 20:15:29 +0000198/* Prototypes. */
paul94f2b392005-06-28 12:44:16 +0000199extern void bgp_route_init (void);
Chris Caputo228da422009-07-18 05:44:03 +0000200extern void bgp_route_finish (void);
paul94f2b392005-06-28 12:44:16 +0000201extern void bgp_cleanup_routes (void);
202extern void bgp_announce_route (struct peer *, afi_t, safi_t);
203extern void bgp_announce_route_all (struct peer *);
204extern void bgp_default_originate (struct peer *, afi_t, safi_t, int);
205extern void bgp_soft_reconfig_in (struct peer *, afi_t, safi_t);
206extern void bgp_soft_reconfig_rsclient (struct peer *, afi_t, safi_t);
207extern void bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi);
Chris Caputo228da422009-07-18 05:44:03 +0000208extern void bgp_clear_route (struct peer *, afi_t, safi_t,
209 enum bgp_clear_route_type);
paul94f2b392005-06-28 12:44:16 +0000210extern void bgp_clear_route_all (struct peer *);
211extern void bgp_clear_adj_in (struct peer *, afi_t, safi_t);
212extern void bgp_clear_stale_route (struct peer *, afi_t, safi_t);
paul718e3742002-12-13 20:15:29 +0000213
paul200df112005-06-01 11:17:05 +0000214extern struct bgp_info *bgp_info_lock (struct bgp_info *);
215extern struct bgp_info *bgp_info_unlock (struct bgp_info *);
216extern void bgp_info_add (struct bgp_node *rn, struct bgp_info *ri);
217extern void bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri);
Paul Jakmafb982c22007-05-04 20:15:47 +0000218extern struct bgp_info_extra *bgp_info_extra_get (struct bgp_info *);
Paul Jakma1a392d42006-09-07 00:24:49 +0000219extern void bgp_info_set_flag (struct bgp_node *, struct bgp_info *, u_int32_t);
220extern void bgp_info_unset_flag (struct bgp_node *, struct bgp_info *, u_int32_t);
paul200df112005-06-01 11:17:05 +0000221
Paul Jakma518a4b72016-02-04 13:27:04 +0000222extern int bgp_nlri_parse_ip (struct peer *, struct attr *, struct bgp_nlri *);
paul718e3742002-12-13 20:15:29 +0000223
paul94f2b392005-06-28 12:44:16 +0000224extern int bgp_maximum_prefix_overflow (struct peer *, afi_t, safi_t, int);
paul718e3742002-12-13 20:15:29 +0000225
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +0400226extern void bgp_redistribute_add (struct prefix *, const struct in_addr *,
227 const struct in6_addr *,
Paul Jakma96d10602016-07-01 14:23:45 +0100228 u_int32_t, u_char, route_tag_t);
paul94f2b392005-06-28 12:44:16 +0000229extern void bgp_redistribute_delete (struct prefix *, u_char);
230extern void bgp_redistribute_withdraw (struct bgp *, afi_t, int);
paul718e3742002-12-13 20:15:29 +0000231
paul94f2b392005-06-28 12:44:16 +0000232extern void bgp_static_delete (struct bgp *);
233extern void bgp_static_update (struct bgp *, struct prefix *, struct bgp_static *,
paul718e3742002-12-13 20:15:29 +0000234 afi_t, safi_t);
paul94f2b392005-06-28 12:44:16 +0000235extern void bgp_static_withdraw (struct bgp *, struct prefix *, afi_t, safi_t);
paul718e3742002-12-13 20:15:29 +0000236
Lou Bergera76d9ca2016-01-12 13:41:53 -0500237extern int bgp_static_set_safi (safi_t safi, struct vty *vty, const char *,
238 const char *, const char *, const char *);
paul718e3742002-12-13 20:15:29 +0000239
Lou Bergera76d9ca2016-01-12 13:41:53 -0500240extern int bgp_static_unset_safi (safi_t safi, struct vty *, const char *,
paulfd79ac92004-10-13 05:06:08 +0000241 const char *, const char *);
paul718e3742002-12-13 20:15:29 +0000242
paul94f2b392005-06-28 12:44:16 +0000243/* this is primarily for MPLS-VPN */
244extern int bgp_update (struct peer *, struct prefix *, struct attr *,
245 afi_t, safi_t, int, int, struct prefix_rd *,
246 u_char *, int);
247extern int bgp_withdraw (struct peer *, struct prefix *, struct attr *,
248 afi_t, safi_t, int, int, struct prefix_rd *, u_char *);
paul718e3742002-12-13 20:15:29 +0000249
paul94f2b392005-06-28 12:44:16 +0000250/* for bgp_nexthop and bgp_damp */
251extern void bgp_process (struct bgp *, struct bgp_node *, afi_t, safi_t);
paul94f2b392005-06-28 12:44:16 +0000252extern int bgp_config_write_network (struct vty *, struct bgp *, afi_t, safi_t, int *);
Roman Hoog Antink6184c392014-03-17 14:01:42 +0100253extern int bgp_config_write_distance (struct vty *, struct bgp *, afi_t, safi_t, int *);
paul94f2b392005-06-28 12:44:16 +0000254
255extern void bgp_aggregate_increment (struct bgp *, struct prefix *, struct bgp_info *,
paul718e3742002-12-13 20:15:29 +0000256 afi_t, safi_t);
paul94f2b392005-06-28 12:44:16 +0000257extern void bgp_aggregate_decrement (struct bgp *, struct prefix *, struct bgp_info *,
paul718e3742002-12-13 20:15:29 +0000258 afi_t, safi_t);
259
paul94f2b392005-06-28 12:44:16 +0000260extern u_char bgp_distance_apply (struct prefix *, struct bgp_info *, struct bgp *);
Roman Hoog Antink6184c392014-03-17 14:01:42 +0100261extern u_char ipv6_bgp_distance_apply (struct prefix *, struct bgp_info *, struct bgp *);
paul718e3742002-12-13 20:15:29 +0000262
paul94f2b392005-06-28 12:44:16 +0000263extern afi_t bgp_node_afi (struct vty *);
264extern safi_t bgp_node_safi (struct vty *);
ajs5a646652004-11-05 01:25:55 +0000265
paul94f2b392005-06-28 12:44:16 +0000266extern void route_vty_out (struct vty *, struct prefix *, struct bgp_info *, int, safi_t);
267extern void route_vty_out_tag (struct vty *, struct prefix *, struct bgp_info *, int, safi_t);
268extern void route_vty_out_tmp (struct vty *, struct prefix *, struct attr *, safi_t);
paul00d252c2005-05-23 14:19:54 +0000269
Lou Berger82dd7072016-01-12 13:41:57 -0500270extern void bgp_peer_clear_node_queue_drain_immediate (struct peer *peer);
271extern void bgp_process_queues_drain_immediate (void);
272
paul00d252c2005-05-23 14:19:54 +0000273#endif /* _QUAGGA_BGP_ROUTE_H */