1/* 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
21struct bgp_info
22{
23  /* For linked list. */
24  struct bgp_info *next;
25  struct bgp_info *prev;
26
27  /* BGP route type.  This can be static, RIP, OSPF, BGP etc.  */
28  u_char type;
29
30  /* When above type is BGP.  This sub type specify BGP sub type
31     information.  */
32  u_char sub_type;
33#define BGP_ROUTE_NORMAL       0
34#define BGP_ROUTE_STATIC       1
35#define BGP_ROUTE_AGGREGATE    2
36#define BGP_ROUTE_REDISTRIBUTE 3
37
38  /* BGP information status.  */
39  u_char flags;
40#define BGP_INFO_IGP_CHANGED    (1 << 0)
41#define BGP_INFO_DAMPED         (1 << 1)
42#define BGP_INFO_HISTORY        (1 << 2)
43#define BGP_INFO_SELECTED       (1 << 3)
44#define BGP_INFO_VALID          (1 << 4)
45#define BGP_INFO_ATTR_CHANGED   (1 << 5)
46#define BGP_INFO_DMED_CHECK     (1 << 6)
47#define BGP_INFO_DMED_SELECTED  (1 << 7)
48
49  /* Peer structure.  */
50  struct peer *peer;
51
52  /* Attribute structure.  */
53  struct attr *attr;
54
55  /* This route is suppressed with aggregation.  */
56  int suppress;
57
58  /* Nexthop reachability check.  */
59  u_int32_t igpmetric;
60
61  /* Uptime.  */
62  time_t uptime;
63
64  /* Pointer to dampening structure.  */
65  struct bgp_damp_info *damp_info;
66
67  /* MPLS label.  */
68  u_char tag[3];
69};
70
71/* BGP static route configuration. */
72struct bgp_static
73{
74  /* Backdoor configuration.  */
75  int backdoor;
76
77  /* Import check status.  */
78  u_char valid;
79
80  /* IGP metric. */
81  u_int32_t igpmetric;
82
83  /* IGP nexthop. */
84  struct in_addr igpnexthop;
85
86  /* BGP redistribute route-map.  */
87  struct
88  {
89    char *name;
90    struct route_map *map;
91  } rmap;
92
93  /* MPLS label.  */
94  u_char tag[3];
95};
96
97#define DISTRIBUTE_IN_NAME(F)   ((F)->dlist[FILTER_IN].name)
98#define DISTRIBUTE_IN(F)        ((F)->dlist[FILTER_IN].alist)
99#define DISTRIBUTE_OUT_NAME(F)  ((F)->dlist[FILTER_OUT].name)
100#define DISTRIBUTE_OUT(F)       ((F)->dlist[FILTER_OUT].alist)
101
102#define PREFIX_LIST_IN_NAME(F)  ((F)->plist[FILTER_IN].name)
103#define PREFIX_LIST_IN(F)       ((F)->plist[FILTER_IN].plist)
104#define PREFIX_LIST_OUT_NAME(F) ((F)->plist[FILTER_OUT].name)
105#define PREFIX_LIST_OUT(F)      ((F)->plist[FILTER_OUT].plist)
106
107#define FILTER_LIST_IN_NAME(F)  ((F)->aslist[FILTER_IN].name)
108#define FILTER_LIST_IN(F)       ((F)->aslist[FILTER_IN].aslist)
109#define FILTER_LIST_OUT_NAME(F) ((F)->aslist[FILTER_OUT].name)
110#define FILTER_LIST_OUT(F)      ((F)->aslist[FILTER_OUT].aslist)
111
112#define ROUTE_MAP_IN_NAME(F)    ((F)->map[FILTER_IN].name)
113#define ROUTE_MAP_IN(F)         ((F)->map[FILTER_IN].map)
114#define ROUTE_MAP_OUT_NAME(F)   ((F)->map[FILTER_OUT].name)
115#define ROUTE_MAP_OUT(F)        ((F)->map[FILTER_OUT].map)
116
117#define UNSUPPRESS_MAP_NAME(F)  ((F)->usmap.name)
118#define UNSUPPRESS_MAP(F)       ((F)->usmap.map)
119
120/* Prototypes. */
121void bgp_route_init ();
122void bgp_announce_route (struct peer *, afi_t, safi_t);
123void bgp_announce_route_all (struct peer *);
124void bgp_default_originate (struct peer *, afi_t, safi_t, int);
125void bgp_soft_reconfig_in (struct peer *, afi_t, safi_t);
126void bgp_clear_route (struct peer *, afi_t, safi_t);
127void bgp_clear_route_all (struct peer *);
128void bgp_clear_adj_in (struct peer *, afi_t, safi_t);
129
130int bgp_nlri_sanity_check (struct peer *, int, u_char *, bgp_size_t);
131int bgp_nlri_parse (struct peer *, struct attr *, struct bgp_nlri *);
132
133int bgp_maximum_prefix_overflow (struct peer *, afi_t, safi_t);
134
135void bgp_redistribute_add (struct prefix *, struct in_addr *, u_int32_t, u_char);
136void bgp_redistribute_delete (struct prefix *, u_char);
137void bgp_redistribute_withdraw (struct bgp *, afi_t, int);
138
139void bgp_static_delete (struct bgp *);
140void bgp_static_update (struct bgp *, struct prefix *, struct bgp_static *,
141			afi_t, safi_t);
142void bgp_static_withdraw (struct bgp *, struct prefix *, afi_t, safi_t);
143
144int bgp_static_set_vpnv4 (struct vty *vty, char *, char *, char *);
145
146int bgp_static_unset_vpnv4 (struct vty *, char *, char *, char *);
147
148int bgp_config_write_network (struct vty *, struct bgp *, afi_t, safi_t, int *);
149int bgp_config_write_distance (struct vty *, struct bgp *);
150
151void route_vty_out_detail (struct vty *, struct prefix *, struct bgp_info *,
152			   afi_t, safi_t);
153
154void bgp_aggregate_increment (struct bgp *, struct prefix *, struct bgp_info *,
155			      afi_t, safi_t);
156void bgp_aggregate_decrement (struct bgp *, struct prefix *, struct bgp_info *,
157			      afi_t, safi_t);
158
159u_char bgp_distance_apply (struct prefix *, struct bgp_info *, struct bgp *);
160
161afi_t bgp_node_afi (struct vty *);
162safi_t bgp_node_safi (struct vty *);
163