blob: b0c2fccf74652ee4e6cd3761bc7aaefebb9dffdd [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
paul718e3742002-12-13 20:15:29 +000026struct bgp_info
27{
28 /* For linked list. */
29 struct bgp_info *next;
30 struct bgp_info *prev;
paul200df112005-06-01 11:17:05 +000031
Paul Jakmacbdfbaa2006-03-30 13:20:48 +000032 /* Peer structure. */
33 struct peer *peer;
34
35 /* Attribute structure. */
36 struct attr *attr;
37
38 /* Pointer to dampening structure. */
39 struct bgp_damp_info *damp_info;
40
41 /* Uptime. */
42 time_t uptime;
43
44 /* This route is suppressed with aggregation. */
45 int suppress;
46
47 /* Nexthop reachability check. */
48 u_int32_t igpmetric;
49
paul200df112005-06-01 11:17:05 +000050 /* reference count */
51 unsigned int lock;
52
paul718e3742002-12-13 20:15:29 +000053 /* BGP information status. */
hasso93406d82005-02-02 14:40:33 +000054 u_int16_t flags;
paul718e3742002-12-13 20:15:29 +000055#define BGP_INFO_IGP_CHANGED (1 << 0)
56#define BGP_INFO_DAMPED (1 << 1)
57#define BGP_INFO_HISTORY (1 << 2)
58#define BGP_INFO_SELECTED (1 << 3)
59#define BGP_INFO_VALID (1 << 4)
60#define BGP_INFO_ATTR_CHANGED (1 << 5)
61#define BGP_INFO_DMED_CHECK (1 << 6)
62#define BGP_INFO_DMED_SELECTED (1 << 7)
hasso93406d82005-02-02 14:40:33 +000063#define BGP_INFO_STALE (1 << 8)
paulb40d9392005-08-22 22:34:41 +000064#define BGP_INFO_REMOVED (1 << 9)
paul902212c2006-02-05 17:51:19 +000065#define BGP_INFO_COUNTED (1 << 10)
paul718e3742002-12-13 20:15:29 +000066
paul718e3742002-12-13 20:15:29 +000067 /* MPLS label. */
68 u_char tag[3];
Paul Jakmacbdfbaa2006-03-30 13:20:48 +000069
70 /* BGP route type. This can be static, RIP, OSPF, BGP etc. */
71 u_char type;
72
73 /* When above type is BGP. This sub type specify BGP sub type
74 information. */
75 u_char sub_type;
76#define BGP_ROUTE_NORMAL 0
77#define BGP_ROUTE_STATIC 1
78#define BGP_ROUTE_AGGREGATE 2
79#define BGP_ROUTE_REDISTRIBUTE 3
paul718e3742002-12-13 20:15:29 +000080};
81
82/* BGP static route configuration. */
83struct bgp_static
84{
85 /* Backdoor configuration. */
86 int backdoor;
87
88 /* Import check status. */
89 u_char valid;
90
91 /* IGP metric. */
92 u_int32_t igpmetric;
93
94 /* IGP nexthop. */
95 struct in_addr igpnexthop;
96
97 /* BGP redistribute route-map. */
98 struct
99 {
100 char *name;
101 struct route_map *map;
102 } rmap;
103
104 /* MPLS label. */
105 u_char tag[3];
106};
107
Paul Jakma1a392d42006-09-07 00:24:49 +0000108/* Flags which indicate a route is unuseable in some form */
109#define BGP_INFO_UNUSEABLE \
110 (BGP_INFO_HISTORY|BGP_INFO_DAMPED|BGP_INFO_REMOVED)
111/* Macro to check BGP information is alive or not. Sadly,
112 * not equivalent to just checking previous, because of the
113 * sense of the additional VALID flag.
114 */
115#define BGP_INFO_HOLDDOWN(BI) \
116 (! CHECK_FLAG ((BI)->flags, BGP_INFO_VALID) \
117 || CHECK_FLAG ((BI)->flags, BGP_INFO_UNUSEABLE))
118
paul718e3742002-12-13 20:15:29 +0000119#define DISTRIBUTE_IN_NAME(F) ((F)->dlist[FILTER_IN].name)
120#define DISTRIBUTE_IN(F) ((F)->dlist[FILTER_IN].alist)
121#define DISTRIBUTE_OUT_NAME(F) ((F)->dlist[FILTER_OUT].name)
122#define DISTRIBUTE_OUT(F) ((F)->dlist[FILTER_OUT].alist)
123
124#define PREFIX_LIST_IN_NAME(F) ((F)->plist[FILTER_IN].name)
125#define PREFIX_LIST_IN(F) ((F)->plist[FILTER_IN].plist)
126#define PREFIX_LIST_OUT_NAME(F) ((F)->plist[FILTER_OUT].name)
127#define PREFIX_LIST_OUT(F) ((F)->plist[FILTER_OUT].plist)
128
129#define FILTER_LIST_IN_NAME(F) ((F)->aslist[FILTER_IN].name)
130#define FILTER_LIST_IN(F) ((F)->aslist[FILTER_IN].aslist)
131#define FILTER_LIST_OUT_NAME(F) ((F)->aslist[FILTER_OUT].name)
132#define FILTER_LIST_OUT(F) ((F)->aslist[FILTER_OUT].aslist)
133
paulfee0f4c2004-09-13 05:12:46 +0000134#define ROUTE_MAP_IN_NAME(F) ((F)->map[RMAP_IN].name)
135#define ROUTE_MAP_IN(F) ((F)->map[RMAP_IN].map)
136#define ROUTE_MAP_OUT_NAME(F) ((F)->map[RMAP_OUT].name)
137#define ROUTE_MAP_OUT(F) ((F)->map[RMAP_OUT].map)
138
139#define ROUTE_MAP_IMPORT_NAME(F) ((F)->map[RMAP_IMPORT].name)
140#define ROUTE_MAP_IMPORT(F) ((F)->map[RMAP_IMPORT].map)
141#define ROUTE_MAP_EXPORT_NAME(F) ((F)->map[RMAP_EXPORT].name)
142#define ROUTE_MAP_EXPORT(F) ((F)->map[RMAP_EXPORT].map)
paul718e3742002-12-13 20:15:29 +0000143
144#define UNSUPPRESS_MAP_NAME(F) ((F)->usmap.name)
145#define UNSUPPRESS_MAP(F) ((F)->usmap.map)
146
147/* Prototypes. */
paul94f2b392005-06-28 12:44:16 +0000148extern void bgp_route_init (void);
149extern void bgp_cleanup_routes (void);
150extern void bgp_announce_route (struct peer *, afi_t, safi_t);
151extern void bgp_announce_route_all (struct peer *);
152extern void bgp_default_originate (struct peer *, afi_t, safi_t, int);
153extern void bgp_soft_reconfig_in (struct peer *, afi_t, safi_t);
154extern void bgp_soft_reconfig_rsclient (struct peer *, afi_t, safi_t);
155extern void bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi);
156extern void bgp_clear_route (struct peer *, afi_t, safi_t);
157extern void bgp_clear_route_all (struct peer *);
158extern void bgp_clear_adj_in (struct peer *, afi_t, safi_t);
159extern void bgp_clear_stale_route (struct peer *, afi_t, safi_t);
paul718e3742002-12-13 20:15:29 +0000160
paul200df112005-06-01 11:17:05 +0000161extern struct bgp_info *bgp_info_lock (struct bgp_info *);
162extern struct bgp_info *bgp_info_unlock (struct bgp_info *);
163extern void bgp_info_add (struct bgp_node *rn, struct bgp_info *ri);
164extern void bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri);
Paul Jakma1a392d42006-09-07 00:24:49 +0000165extern void bgp_info_set_flag (struct bgp_node *, struct bgp_info *, u_int32_t);
166extern void bgp_info_unset_flag (struct bgp_node *, struct bgp_info *, u_int32_t);
paul200df112005-06-01 11:17:05 +0000167
paul94f2b392005-06-28 12:44:16 +0000168extern int bgp_nlri_sanity_check (struct peer *, int, u_char *, bgp_size_t);
169extern int bgp_nlri_parse (struct peer *, struct attr *, struct bgp_nlri *);
paul718e3742002-12-13 20:15:29 +0000170
paul94f2b392005-06-28 12:44:16 +0000171extern int bgp_maximum_prefix_overflow (struct peer *, afi_t, safi_t, int);
paul718e3742002-12-13 20:15:29 +0000172
paul94f2b392005-06-28 12:44:16 +0000173extern void bgp_redistribute_add (struct prefix *, struct in_addr *, u_int32_t, u_char);
174extern void bgp_redistribute_delete (struct prefix *, u_char);
175extern void bgp_redistribute_withdraw (struct bgp *, afi_t, int);
paul718e3742002-12-13 20:15:29 +0000176
paul94f2b392005-06-28 12:44:16 +0000177extern void bgp_static_delete (struct bgp *);
178extern void bgp_static_update (struct bgp *, struct prefix *, struct bgp_static *,
paul718e3742002-12-13 20:15:29 +0000179 afi_t, safi_t);
paul94f2b392005-06-28 12:44:16 +0000180extern void bgp_static_withdraw (struct bgp *, struct prefix *, afi_t, safi_t);
paul718e3742002-12-13 20:15:29 +0000181
paul94f2b392005-06-28 12:44:16 +0000182extern int bgp_static_set_vpnv4 (struct vty *vty, const char *,
paulfd79ac92004-10-13 05:06:08 +0000183 const char *, const char *);
paul718e3742002-12-13 20:15:29 +0000184
paul94f2b392005-06-28 12:44:16 +0000185extern int bgp_static_unset_vpnv4 (struct vty *, const char *,
paulfd79ac92004-10-13 05:06:08 +0000186 const char *, const char *);
paul718e3742002-12-13 20:15:29 +0000187
paul94f2b392005-06-28 12:44:16 +0000188/* this is primarily for MPLS-VPN */
189extern int bgp_update (struct peer *, struct prefix *, struct attr *,
190 afi_t, safi_t, int, int, struct prefix_rd *,
191 u_char *, int);
192extern int bgp_withdraw (struct peer *, struct prefix *, struct attr *,
193 afi_t, safi_t, int, int, struct prefix_rd *, u_char *);
paul718e3742002-12-13 20:15:29 +0000194
paul94f2b392005-06-28 12:44:16 +0000195/* for bgp_nexthop and bgp_damp */
196extern void bgp_process (struct bgp *, struct bgp_node *, afi_t, safi_t);
paul94f2b392005-06-28 12:44:16 +0000197extern int bgp_config_write_network (struct vty *, struct bgp *, afi_t, safi_t, int *);
198extern int bgp_config_write_distance (struct vty *, struct bgp *);
199
200extern void bgp_aggregate_increment (struct bgp *, struct prefix *, struct bgp_info *,
paul718e3742002-12-13 20:15:29 +0000201 afi_t, safi_t);
paul94f2b392005-06-28 12:44:16 +0000202extern void bgp_aggregate_decrement (struct bgp *, struct prefix *, struct bgp_info *,
paul718e3742002-12-13 20:15:29 +0000203 afi_t, safi_t);
204
paul94f2b392005-06-28 12:44:16 +0000205extern u_char bgp_distance_apply (struct prefix *, struct bgp_info *, struct bgp *);
paul718e3742002-12-13 20:15:29 +0000206
paul94f2b392005-06-28 12:44:16 +0000207extern afi_t bgp_node_afi (struct vty *);
208extern safi_t bgp_node_safi (struct vty *);
ajs5a646652004-11-05 01:25:55 +0000209
paul94f2b392005-06-28 12:44:16 +0000210extern void route_vty_out (struct vty *, struct prefix *, struct bgp_info *, int, safi_t);
211extern void route_vty_out_tag (struct vty *, struct prefix *, struct bgp_info *, int, safi_t);
212extern void route_vty_out_tmp (struct vty *, struct prefix *, struct attr *, safi_t);
paul00d252c2005-05-23 14:19:54 +0000213
214#endif /* _QUAGGA_BGP_ROUTE_H */