[packages] quagga: Refresh patches
[packages.git] / net / quagga / patches / 161-pgbgp-addon.patch
1 From: Paul Jakma <paul.jakma@sun.com>
2 Date: Thu, 4 Sep 2008 22:27:13 +0000 (+0100)
3 Subject: [bgp/pgbgp] Add some pgbgp commands to restricted-mode and other command tweaks
4 X-Git-Url: http://git.ozo.com/?p=quagga-pgbg.git;a=commitdiff_plain;h=06ac72f9f6021635e9e1e5105c3e22bf7eb0d6c3
5
6 [bgp/pgbgp] Add some pgbgp commands to restricted-mode and other command tweaks
7
8 * bgp_pgbgp.c:
9   (edge_neighbor_iterator) make ASN==0 mean 'iterate over all ASNs'
10   (bgp_pgbgp_stats_origin_one) new function, to display one origin AS status.
11   (bgp_pgbgp_stats_origins) adapt to use previous.
12   Adapt to iterate over all stats if no prefix was giving.
13   (show_ip_bgp_pgbgp_neighbors_cmd) recognise no ASN argument case
14   (show_ip_bgp_pgbgp_neighbors_all_cmd) Iterate over all
15   (show_ip_bgp_pgbgp_origins_cmd) similar
16   (show_ip_bgp_pgbgp_origins_all_cmd)
17   (bgp_pgbgp_enable) install the lookup commands to ther new RESTRICTED_NODE
18 * bgp_route.c:
19   (route_vty_short_status_out) only allowed to print one char for anomalous
20   status.
21   (route_vty_out_detail) Add support for printing out more detail on
22   PG-BGP status
23 ---
24
25 --- a/bgpd/bgp_pgbgp.c
26 +++ b/bgpd/bgp_pgbgp.c
27 @@ -227,7 +227,7 @@ static void
28  edge_neighbor_iterator (struct hash_backet *backet, struct nsearch *pns)
29  {
30    struct bgp_pgbgp_edge *hedge = backet->data;
31 -  if ((hedge->e.a == pns->asn || hedge->e.b == pns->asn)
32 +  if ((!pns->asn || hedge->e.a == pns->asn || hedge->e.b == pns->asn)
33        && hedge->e.a != hedge->e.b)
34      {
35        struct vty *vty = pns->pvty;
36 @@ -254,13 +254,39 @@ bgp_pgbgp_stats_neighbors (struct vty *v
37    return CMD_SUCCESS;
38  }
39  
40 +static void
41 +bgp_pgbgp_stats_origin_one (struct vty *vty, struct bgp_node *rn,
42 +                            time_t t_now)
43 +{
44 +  char str[INET6_BUFSIZ];
45 +  
46 +  if (!rn->hist)
47 +    return;
48 +  
49 +  prefix2str (&rn->p, str, sizeof(str));
50 +  vty_out (vty, "%s%s", str, VTY_NEWLINE);
51 +  
52 +  for (struct bgp_pgbgp_origin * cur = rn->hist->o; cur != NULL;
53 +       cur = cur->next)
54 +    {
55 +      if (cur->deprefUntil > t_now)
56 +        vty_out (vty, "Untrusted Origin AS: %d%s", cur->originAS,
57 +                 VTY_NEWLINE);
58 +      else
59 +        vty_out (vty, "Trusted Origin AS: %d%s", cur->originAS,
60 +                 VTY_NEWLINE);
61 +    } 
62 +}
63 +
64  static int
65  bgp_pgbgp_stats_origins (struct vty *vty, afi_t afi, safi_t safi,
66                           const char *prefix)
67  {
68    struct bgp *bgp;
69    struct bgp_table *table;
70 +  struct bgp_node *rn;
71    time_t t_now = time (NULL);
72 +  
73    bgp = bgp_get_default ();
74    if (bgp == NULL)
75      return CMD_WARNING;
76 @@ -269,28 +295,22 @@ bgp_pgbgp_stats_origins (struct vty *vty
77    table = bgp->rib[afi][safi];
78    if (table == NULL)
79      return CMD_WARNING;
80 -
81 -  struct prefix p;
82 -  str2prefix (prefix, &p);
83 -  struct bgp_node *rn = bgp_node_match (table, &p);
84 -  vty_out (vty, "%s%s", prefix, VTY_NEWLINE);
85 -  if (rn)
86 +  
87 +  if (prefix)
88      {
89 +      struct prefix p;
90 +      str2prefix (prefix, &p);
91 +      rn = bgp_node_match (table, &p);
92        if (rn->hist)
93 -        {
94 -          for (struct bgp_pgbgp_origin * cur = rn->hist->o; cur != NULL;
95 -               cur = cur->next)
96 -            {
97 -              if (cur->deprefUntil > t_now)
98 -                vty_out (vty, "Untrusted Origin AS: %d%s", cur->originAS,
99 -                         VTY_NEWLINE);
100 -              else
101 -                vty_out (vty, "Trusted Origin AS: %d%s", cur->originAS,
102 -                         VTY_NEWLINE);
103 -            }
104 -        }
105 +        bgp_pgbgp_stats_origin_one (vty, rn, t_now);
106        bgp_unlock_node (rn);
107 +      return CMD_SUCCESS;
108      }
109 +  
110 +  for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
111 +    if (rn->hist)
112 +      bgp_pgbgp_stats_origin_one (vty, rn, t_now);
113 +
114    return CMD_SUCCESS;
115  }
116  
117 @@ -377,7 +397,7 @@ bgp_pgbgp_stats (struct vty *vty, afi_t
118  DEFUN (show_ip_bgp_pgbgp,
119         show_ip_bgp_pgbgp_cmd,
120         "show ip bgp pgbgp",
121 -       SHOW_STR IP_STR BGP_STR "Display PGBGP statistics\n")
122 +       SHOW_STR IP_STR BGP_STR "Pretty-Good BGP statistics\n")
123  {
124    return bgp_pgbgp_stats (vty, AFI_IP, SAFI_UNICAST);
125  }
126 @@ -385,29 +405,46 @@ DEFUN (show_ip_bgp_pgbgp,
127  DEFUN (show_ip_bgp_pgbgp_neighbors,
128         show_ip_bgp_pgbgp_neighbors_cmd,
129         "show ip bgp pgbgp neighbors WORD",
130 -       SHOW_STR
131 -       IP_STR
132 -       BGP_STR
133 -       "BGP pgbgp\n"
134 -       "BGP pgbgp neighbors\n" "ASN whos neighbors should be displayed\n")
135 +       SHOW_STR IP_STR BGP_STR
136 +       "Pretty-Good BGP statistics\n"
137 +       "PG-BGP neighbor information\n"
138 +       "AS to show neighbors of\n")
139  {
140    return bgp_pgbgp_stats_neighbors (vty, AFI_IP, SAFI_UNICAST,
141 -                                    atoi (argv[0]));
142 +                                    argc == 1 ? atoi (argv[0]) : 0);
143  }
144  
145 +ALIAS (show_ip_bgp_pgbgp_neighbors,
146 +       show_ip_bgp_pgbgp_neighbors_all_cmd,
147 +       "show ip bgp pgbgp neighbors",
148 +       SHOW_STR
149 +       IP_STR
150 +       BGP_STR
151 +       "Pretty-Good BGP statistics\n"
152 +       "PG-BGP neighbors information\n")
153 +
154  DEFUN (show_ip_bgp_pgbgp_origins,
155         show_ip_bgp_pgbgp_origins_cmd,
156         "show ip bgp pgbgp origins A.B.C.D/M",
157         SHOW_STR
158         IP_STR
159         BGP_STR
160 -       "BGP pgbgp\n"
161 -       "BGP pgbgp neighbors\n" "Prefix to look up origin ASes of\n")
162 +       "Pretty-Good BGP statistics\n"
163 +       "PG-BGP prefix origin information\n"
164 +       "Prefix to look up origin ASes of\n")
165  {
166 -  return bgp_pgbgp_stats_origins (vty, AFI_IP, SAFI_UNICAST, argv[0]);
167 +  return bgp_pgbgp_stats_origins (vty, AFI_IP, SAFI_UNICAST,
168 +                                  argc == 1 ? argv[0] : NULL);
169  }
170  
171 -
172 +ALIAS (show_ip_bgp_pgbgp_origins,
173 +       show_ip_bgp_pgbgp_origins_all_cmd,
174 +       "show ip bgp pgbgp origins",
175 +       SHOW_STR
176 +       IP_STR
177 +       BGP_STR
178 +       "Pretty-Good BGP statistics\n"
179 +       "PG-BGP prefixes origin information")
180  
181  
182  /*! --------------- VTY (others exist in bgp_route.c)  ------------------ !*/
183 @@ -749,12 +786,19 @@ bgp_pgbgp_enable (struct bgp *bgp, afi_t
184    pgbgp->lastgc = time (NULL);
185    pgbgp->lastStore = time (NULL);
186    pgbgp->startTime = time (NULL);
187 +  install_element (RESTRICTED_NODE, &show_ip_bgp_pgbgp_cmd);
188 +  install_element (RESTRICTED_NODE, &show_ip_bgp_pgbgp_neighbors_cmd);
189 +  install_element (RESTRICTED_NODE, &show_ip_bgp_pgbgp_origins_cmd);
190    install_element (VIEW_NODE, &show_ip_bgp_pgbgp_cmd);
191 -  install_element (ENABLE_NODE, &show_ip_bgp_pgbgp_cmd);
192    install_element (VIEW_NODE, &show_ip_bgp_pgbgp_neighbors_cmd);
193 -  install_element (ENABLE_NODE, &show_ip_bgp_pgbgp_neighbors_cmd);
194    install_element (VIEW_NODE, &show_ip_bgp_pgbgp_origins_cmd);
195 +  install_element (VIEW_NODE, &show_ip_bgp_pgbgp_neighbors_all_cmd);
196 +  install_element (VIEW_NODE, &show_ip_bgp_pgbgp_origins_all_cmd);
197 +  install_element (ENABLE_NODE, &show_ip_bgp_pgbgp_cmd);
198 +  install_element (ENABLE_NODE, &show_ip_bgp_pgbgp_neighbors_cmd);
199    install_element (ENABLE_NODE, &show_ip_bgp_pgbgp_origins_cmd);
200 +  install_element (ENABLE_NODE, &show_ip_bgp_pgbgp_neighbors_all_cmd);
201 +  install_element (ENABLE_NODE, &show_ip_bgp_pgbgp_origins_all_cmd);
202    pgbgp->edgeT = hash_create_size (131072, edge_key_make, edge_cmp);
203    bgp_pgbgp_restore ();
204    return 0;
205 --- a/bgpd/bgp_route.c
206 +++ b/bgpd/bgp_route.c
207 @@ -5597,20 +5597,6 @@ enum bgp_display_type
208  static void
209  route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
210  {
211 -  if (ANOMALOUS(binfo->flags))
212 -    {
213 -      vty_out(vty, "a[");
214 -      if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_P))
215 -       vty_out(vty, "i");
216 -      if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_O))
217 -       vty_out(vty, "p");
218 -      if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_E))
219 -       vty_out(vty, "e");
220 -      if (CHECK_FLAG(binfo->flags, BGP_INFO_IGNORED_P))
221 -       vty_out(vty, "s");
222 -      vty_out(vty, "] ");
223 -    }
224 -
225   /* Route status display. */
226    if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
227      vty_out (vty, "R");
228 @@ -5626,6 +5612,17 @@ route_vty_short_status_out (struct vty *
229    /* Selected */
230    if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
231      vty_out (vty, "h");
232 +  else if (ANOMALOUS(binfo->flags))
233 +    {
234 +      if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_O)) 
235 +        vty_out(vty, "p");
236 +      else if (CHECK_FLAG(binfo->flags, BGP_INFO_IGNORED_P))
237 +        vty_out(vty, "P");
238 +      else if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_P))
239 +        vty_out(vty, "a");
240 +      if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_E))
241 +        vty_out(vty, "a");
242 +    }
243    else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
244      vty_out (vty, "d");
245    else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
246 @@ -6104,7 +6101,22 @@ route_vty_out_detail (struct vty *vty, s
247        if (binfo->extra && binfo->extra->damp_info)
248         bgp_damp_info_vty (vty, binfo);
249  
250 -      /* Line 7 display Uptime */
251 +      /* 8: PGBGP status */
252 +      if (ANOMALOUS(binfo->flags))
253 +        {
254 +         vty_out (vty, "      Anomalous:");
255 +         if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_P))
256 +           vty_out (vty, " divergent sub-prefixes,");
257 +         if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_O))
258 +           vty_out (vty, " origin AS (prefix hijack?),");
259 +         if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_E))
260 +           vty_out (vty, " new edge in path,");
261 +         if (CHECK_FLAG(binfo->flags, BGP_INFO_IGNORED_P))
262 +           vty_out (vty, " origin AS (sub-prefix hijack?),");
263 +         vty_out (vty, "%s", VTY_NEWLINE);
264 +       } 
265 +
266 +      /* Line 9 display Uptime */      
267  #ifdef HAVE_CLOCK_MONOTONIC
268        tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
269        vty_out (vty, "      Last update: %s", ctime(&tbuf));
270 @@ -6115,8 +6127,9 @@ route_vty_out_detail (struct vty *vty, s
271    vty_out (vty, "%s", VTY_NEWLINE);
272  }  
273  \f
274 -#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,%s              r RIB-failure, S Stale, R Removed%s"
275 -#define BGP_SHOW_PCODE_HEADER "Status code: a (anomalous) of:  [p] prefix hijack, [s] sub-prefix hijack,%s              [i] informant of sub-prefix [e] new edge%s"
276 +#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,%s" \
277 +  "              r RIB-failure, S Stale, R Removed, %s" \
278 +  "              p prefix hijack, P sub-prefix hijack, a other anomaly%s"
279  #define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
280  #define BGP_SHOW_HEADER "   Network          Next Hop            Metric LocPrf Weight Path%s"
281  #define BGP_SHOW_DAMP_HEADER "   Network          From             Reuse    Path%s"
282 @@ -6325,8 +6338,7 @@ bgp_show_table (struct vty *vty, struct
283             if (header)
284               {
285                 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
286 -               vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
287 -               vty_out (vty, BGP_SHOW_PCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
288 +               vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
289                 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
290                 if (type == bgp_show_type_dampend_paths
291                     || type == bgp_show_type_damp_neighbor)
292 @@ -9858,7 +9870,7 @@ show_adj_route (struct vty *vty, struct
293                           PEER_STATUS_DEFAULT_ORIGINATE))
294      {
295        vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
296 -      vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
297 +      vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
298        vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
299  
300        vty_out (vty, "Originating default network 0.0.0.0%s%s",
301 @@ -9875,7 +9887,7 @@ show_adj_route (struct vty *vty, struct
302               if (header1)
303                 {
304                   vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
305 -                 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
306 +                 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
307                   vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
308                   header1 = 0;
309                 }
310 @@ -9899,7 +9911,7 @@ show_adj_route (struct vty *vty, struct
311               if (header1)
312                 {
313                   vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
314 -                 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
315 +                 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
316                   vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
317                   header1 = 0;
318                 }