blob: 5eed3486d1083af20badc7ab1ef66d251657e56b [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
paul200df112005-06-01 11:17:05 +000024#include "bgp_table.h"
25
Paul Jakmafb982c22007-05-04 20:15:47 +000026/* Ancillary information to struct bgp_info,
27 * used for uncommonly used data (aggregation, MPLS, etc.)
28 * and lazily allocated to save memory.
29 */
30struct bgp_info_extra
31{
32 /* Pointer to dampening structure. */
33 struct bgp_damp_info *damp_info;
34
35 /* This route is suppressed with aggregation. */
36 int suppress;
37
38 /* Nexthop reachability check. */
39 u_int32_t igpmetric;
40
41 /* MPLS label. */
42 u_char tag[3];
43};
44
paul718e3742002-12-13 20:15:29 +000045struct bgp_info
46{
47 /* For linked list. */
48 struct bgp_info *next;
49 struct bgp_info *prev;
paul200df112005-06-01 11:17:05 +000050
Paul Jakmacbdfbaa2006-03-30 13:20:48 +000051 /* Peer structure. */
52 struct peer *peer;
53
54 /* Attribute structure. */
55 struct attr *attr;
Paul Jakmafb982c22007-05-04 20:15:47 +000056
57 /* Extra information */
58 struct bgp_info_extra *extra;
59
Paul Jakmacbdfbaa2006-03-30 13:20:48 +000060 /* Uptime. */
61 time_t uptime;
62
paul200df112005-06-01 11:17:05 +000063 /* reference count */
Chris Caputo228da422009-07-18 05:44:03 +000064 int lock;
paul200df112005-06-01 11:17:05 +000065
paul718e3742002-12-13 20:15:29 +000066 /* BGP information status. */
hasso93406d82005-02-02 14:40:33 +000067 u_int16_t flags;
paul718e3742002-12-13 20:15:29 +000068#define BGP_INFO_IGP_CHANGED (1 << 0)
69#define BGP_INFO_DAMPED (1 << 1)
70#define BGP_INFO_HISTORY (1 << 2)
71#define BGP_INFO_SELECTED (1 << 3)
72#define BGP_INFO_VALID (1 << 4)
73#define BGP_INFO_ATTR_CHANGED (1 << 5)
74#define BGP_INFO_DMED_CHECK (1 << 6)
75#define BGP_INFO_DMED_SELECTED (1 << 7)
hasso93406d82005-02-02 14:40:33 +000076#define BGP_INFO_STALE (1 << 8)
paulb40d9392005-08-22 22:34:41 +000077#define BGP_INFO_REMOVED (1 << 9)
paul902212c2006-02-05 17:51:19 +000078#define BGP_INFO_COUNTED (1 << 10)
paul718e3742002-12-13 20:15:29 +000079
Paul Jakmacbdfbaa2006-03-30 13:20:48 +000080 /* BGP route type. This can be static, RIP, OSPF, BGP etc. */
81 u_char type;
82
83 /* When above type is BGP. This sub type specify BGP sub type
84 information. */
85 u_char sub_type;
86#define BGP_ROUTE_NORMAL 0
87#define BGP_ROUTE_STATIC 1
88#define BGP_ROUTE_AGGREGATE 2
89#define BGP_ROUTE_REDISTRIBUTE 3
paul718e3742002-12-13 20:15:29 +000090};
91
92/* BGP static route configuration. */
93struct bgp_static
94{
95 /* Backdoor configuration. */
96 int backdoor;
97
98 /* Import check status. */
99 u_char valid;
100
101 /* IGP metric. */
102 u_int32_t igpmetric;
103
104 /* IGP nexthop. */
105 struct in_addr igpnexthop;
106
Paul Jakma41367172007-08-06 15:24:51 +0000107 /* Atomic set reference count (ie cause of pathlimit) */
108 u_int32_t atomic;
109
paul718e3742002-12-13 20:15:29 +0000110 /* BGP redistribute route-map. */
111 struct
112 {
113 char *name;
114 struct route_map *map;
115 } rmap;
116
117 /* MPLS label. */
118 u_char tag[3];
Paul Jakma41367172007-08-06 15:24:51 +0000119
120 /* AS-Pathlimit TTL */
121 u_char ttl;
paul718e3742002-12-13 20:15:29 +0000122};
123
Paul Jakma1a392d42006-09-07 00:24:49 +0000124/* Flags which indicate a route is unuseable in some form */
125#define BGP_INFO_UNUSEABLE \
126 (BGP_INFO_HISTORY|BGP_INFO_DAMPED|BGP_INFO_REMOVED)
127/* Macro to check BGP information is alive or not. Sadly,
128 * not equivalent to just checking previous, because of the
129 * sense of the additional VALID flag.
130 */
131#define BGP_INFO_HOLDDOWN(BI) \
132 (! CHECK_FLAG ((BI)->flags, BGP_INFO_VALID) \
133 || CHECK_FLAG ((BI)->flags, BGP_INFO_UNUSEABLE))
134
paul718e3742002-12-13 20:15:29 +0000135#define DISTRIBUTE_IN_NAME(F) ((F)->dlist[FILTER_IN].name)
136#define DISTRIBUTE_IN(F) ((F)->dlist[FILTER_IN].alist)
137#define DISTRIBUTE_OUT_NAME(F) ((F)->dlist[FILTER_OUT].name)
138#define DISTRIBUTE_OUT(F) ((F)->dlist[FILTER_OUT].alist)
139
140#define PREFIX_LIST_IN_NAME(F) ((F)->plist[FILTER_IN].name)
141#define PREFIX_LIST_IN(F) ((F)->plist[FILTER_IN].plist)
142#define PREFIX_LIST_OUT_NAME(F) ((F)->plist[FILTER_OUT].name)
143#define PREFIX_LIST_OUT(F) ((F)->plist[FILTER_OUT].plist)
144
145#define FILTER_LIST_IN_NAME(F) ((F)->aslist[FILTER_IN].name)
146#define FILTER_LIST_IN(F) ((F)->aslist[FILTER_IN].aslist)
147#define FILTER_LIST_OUT_NAME(F) ((F)->aslist[FILTER_OUT].name)
148#define FILTER_LIST_OUT(F) ((F)->aslist[FILTER_OUT].aslist)
149
paulfee0f4c2004-09-13 05:12:46 +0000150#define ROUTE_MAP_IN_NAME(F) ((F)->map[RMAP_IN].name)
151#define ROUTE_MAP_IN(F) ((F)->map[RMAP_IN].map)
152#define ROUTE_MAP_OUT_NAME(F) ((F)->map[RMAP_OUT].name)
153#define ROUTE_MAP_OUT(F) ((F)->map[RMAP_OUT].map)
154
155#define ROUTE_MAP_IMPORT_NAME(F) ((F)->map[RMAP_IMPORT].name)
156#define ROUTE_MAP_IMPORT(F) ((F)->map[RMAP_IMPORT].map)
157#define ROUTE_MAP_EXPORT_NAME(F) ((F)->map[RMAP_EXPORT].name)
158#define ROUTE_MAP_EXPORT(F) ((F)->map[RMAP_EXPORT].map)
paul718e3742002-12-13 20:15:29 +0000159
160#define UNSUPPRESS_MAP_NAME(F) ((F)->usmap.name)
161#define UNSUPPRESS_MAP(F) ((F)->usmap.map)
162
Chris Caputo228da422009-07-18 05:44:03 +0000163enum bgp_clear_route_type
164{
165 BGP_CLEAR_ROUTE_NORMAL,
166 BGP_CLEAR_ROUTE_MY_RSCLIENT
167};
168
paul718e3742002-12-13 20:15:29 +0000169/* Prototypes. */
paul94f2b392005-06-28 12:44:16 +0000170extern void bgp_route_init (void);
Chris Caputo228da422009-07-18 05:44:03 +0000171extern void bgp_route_finish (void);
paul94f2b392005-06-28 12:44:16 +0000172extern void bgp_cleanup_routes (void);
173extern void bgp_announce_route (struct peer *, afi_t, safi_t);
174extern void bgp_announce_route_all (struct peer *);
175extern void bgp_default_originate (struct peer *, afi_t, safi_t, int);
176extern void bgp_soft_reconfig_in (struct peer *, afi_t, safi_t);
177extern void bgp_soft_reconfig_rsclient (struct peer *, afi_t, safi_t);
178extern void bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi);
Chris Caputo228da422009-07-18 05:44:03 +0000179extern void bgp_clear_route (struct peer *, afi_t, safi_t,
180 enum bgp_clear_route_type);
paul94f2b392005-06-28 12:44:16 +0000181extern void bgp_clear_route_all (struct peer *);
182extern void bgp_clear_adj_in (struct peer *, afi_t, safi_t);
183extern void bgp_clear_stale_route (struct peer *, afi_t, safi_t);
paul718e3742002-12-13 20:15:29 +0000184
paul200df112005-06-01 11:17:05 +0000185extern struct bgp_info *bgp_info_lock (struct bgp_info *);
186extern struct bgp_info *bgp_info_unlock (struct bgp_info *);
187extern void bgp_info_add (struct bgp_node *rn, struct bgp_info *ri);
188extern void bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri);
Paul Jakmafb982c22007-05-04 20:15:47 +0000189extern struct bgp_info_extra *bgp_info_extra_get (struct bgp_info *);
Paul Jakma1a392d42006-09-07 00:24:49 +0000190extern void bgp_info_set_flag (struct bgp_node *, struct bgp_info *, u_int32_t);
191extern void bgp_info_unset_flag (struct bgp_node *, struct bgp_info *, u_int32_t);
paul200df112005-06-01 11:17:05 +0000192
paul94f2b392005-06-28 12:44:16 +0000193extern int bgp_nlri_sanity_check (struct peer *, int, u_char *, bgp_size_t);
194extern int bgp_nlri_parse (struct peer *, struct attr *, struct bgp_nlri *);
paul718e3742002-12-13 20:15:29 +0000195
paul94f2b392005-06-28 12:44:16 +0000196extern int bgp_maximum_prefix_overflow (struct peer *, afi_t, safi_t, int);
paul718e3742002-12-13 20:15:29 +0000197
paul94f2b392005-06-28 12:44:16 +0000198extern void bgp_redistribute_add (struct prefix *, struct in_addr *, u_int32_t, u_char);
199extern void bgp_redistribute_delete (struct prefix *, u_char);
200extern void bgp_redistribute_withdraw (struct bgp *, afi_t, int);
paul718e3742002-12-13 20:15:29 +0000201
paul94f2b392005-06-28 12:44:16 +0000202extern void bgp_static_delete (struct bgp *);
203extern void bgp_static_update (struct bgp *, struct prefix *, struct bgp_static *,
paul718e3742002-12-13 20:15:29 +0000204 afi_t, safi_t);
paul94f2b392005-06-28 12:44:16 +0000205extern void bgp_static_withdraw (struct bgp *, struct prefix *, afi_t, safi_t);
paul718e3742002-12-13 20:15:29 +0000206
paul94f2b392005-06-28 12:44:16 +0000207extern int bgp_static_set_vpnv4 (struct vty *vty, const char *,
paulfd79ac92004-10-13 05:06:08 +0000208 const char *, const char *);
paul718e3742002-12-13 20:15:29 +0000209
paul94f2b392005-06-28 12:44:16 +0000210extern int bgp_static_unset_vpnv4 (struct vty *, const char *,
paulfd79ac92004-10-13 05:06:08 +0000211 const char *, const char *);
paul718e3742002-12-13 20:15:29 +0000212
paul94f2b392005-06-28 12:44:16 +0000213/* this is primarily for MPLS-VPN */
214extern int bgp_update (struct peer *, struct prefix *, struct attr *,
215 afi_t, safi_t, int, int, struct prefix_rd *,
216 u_char *, int);
217extern int bgp_withdraw (struct peer *, struct prefix *, struct attr *,
218 afi_t, safi_t, int, int, struct prefix_rd *, u_char *);
paul718e3742002-12-13 20:15:29 +0000219
paul94f2b392005-06-28 12:44:16 +0000220/* for bgp_nexthop and bgp_damp */
221extern void bgp_process (struct bgp *, struct bgp_node *, afi_t, safi_t);
paul94f2b392005-06-28 12:44:16 +0000222extern int bgp_config_write_network (struct vty *, struct bgp *, afi_t, safi_t, int *);
223extern int bgp_config_write_distance (struct vty *, struct bgp *);
224
225extern void bgp_aggregate_increment (struct bgp *, struct prefix *, struct bgp_info *,
paul718e3742002-12-13 20:15:29 +0000226 afi_t, safi_t);
paul94f2b392005-06-28 12:44:16 +0000227extern void bgp_aggregate_decrement (struct bgp *, struct prefix *, struct bgp_info *,
paul718e3742002-12-13 20:15:29 +0000228 afi_t, safi_t);
229
paul94f2b392005-06-28 12:44:16 +0000230extern u_char bgp_distance_apply (struct prefix *, struct bgp_info *, struct bgp *);
paul718e3742002-12-13 20:15:29 +0000231
paul94f2b392005-06-28 12:44:16 +0000232extern afi_t bgp_node_afi (struct vty *);
233extern safi_t bgp_node_safi (struct vty *);
ajs5a646652004-11-05 01:25:55 +0000234
paul94f2b392005-06-28 12:44:16 +0000235extern void route_vty_out (struct vty *, struct prefix *, struct bgp_info *, int, safi_t);
236extern void route_vty_out_tag (struct vty *, struct prefix *, struct bgp_info *, int, safi_t);
237extern void route_vty_out_tmp (struct vty *, struct prefix *, struct attr *, safi_t);
paul00d252c2005-05-23 14:19:54 +0000238
239#endif /* _QUAGGA_BGP_ROUTE_H */