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
6 [bgp/pgbgp] Add some pgbgp commands to restricted-mode and other command tweaks
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
19 (route_vty_short_status_out) only allowed to print one char for anomalous
21 (route_vty_out_detail) Add support for printing out more detail on
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)
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)
35 struct vty *vty = pns->pvty;
36 @@ -254,13 +254,39 @@ bgp_pgbgp_stats_neighbors (struct vty *v
41 +bgp_pgbgp_stats_origin_one (struct vty *vty, struct bgp_node *rn,
44 + char str[INET6_BUFSIZ];
49 + prefix2str (&rn->p, str, sizeof(str));
50 + vty_out (vty, "%s%s", str, VTY_NEWLINE);
52 + for (struct bgp_pgbgp_origin * cur = rn->hist->o; cur != NULL;
55 + if (cur->deprefUntil > t_now)
56 + vty_out (vty, "Untrusted Origin AS: %d%s", cur->originAS,
59 + vty_out (vty, "Trusted Origin AS: %d%s", cur->originAS,
65 bgp_pgbgp_stats_origins (struct vty *vty, afi_t afi, safi_t safi,
69 struct bgp_table *table;
70 + struct bgp_node *rn;
71 time_t t_now = time (NULL);
73 bgp = bgp_get_default ();
76 @@ -269,28 +295,22 @@ bgp_pgbgp_stats_origins (struct vty *vty
77 table = bgp->rib[afi][safi];
82 - str2prefix (prefix, &p);
83 - struct bgp_node *rn = bgp_node_match (table, &p);
84 - vty_out (vty, "%s%s", prefix, VTY_NEWLINE);
90 + str2prefix (prefix, &p);
91 + rn = bgp_node_match (table, &p);
94 - for (struct bgp_pgbgp_origin * cur = rn->hist->o; cur != NULL;
97 - if (cur->deprefUntil > t_now)
98 - vty_out (vty, "Untrusted Origin AS: %d%s", cur->originAS,
101 - vty_out (vty, "Trusted Origin AS: %d%s", cur->originAS,
105 + bgp_pgbgp_stats_origin_one (vty, rn, t_now);
106 bgp_unlock_node (rn);
107 + return CMD_SUCCESS;
110 + for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
112 + bgp_pgbgp_stats_origin_one (vty, rn, t_now);
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,
121 - SHOW_STR IP_STR BGP_STR "Display PGBGP statistics\n")
122 + SHOW_STR IP_STR BGP_STR "Pretty-Good BGP statistics\n")
124 return bgp_pgbgp_stats (vty, AFI_IP, SAFI_UNICAST);
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",
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")
140 return bgp_pgbgp_stats_neighbors (vty, AFI_IP, SAFI_UNICAST,
142 + argc == 1 ? atoi (argv[0]) : 0);
145 +ALIAS (show_ip_bgp_pgbgp_neighbors,
146 + show_ip_bgp_pgbgp_neighbors_all_cmd,
147 + "show ip bgp pgbgp neighbors",
151 + "Pretty-Good BGP statistics\n"
152 + "PG-BGP neighbors information\n")
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",
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")
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);
172 +ALIAS (show_ip_bgp_pgbgp_origins,
173 + show_ip_bgp_pgbgp_origins_all_cmd,
174 + "show ip bgp pgbgp origins",
178 + "Pretty-Good BGP statistics\n"
179 + "PG-BGP prefixes origin information")
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 ();
205 --- a/bgpd/bgp_route.c
206 +++ b/bgpd/bgp_route.c
207 @@ -5581,20 +5581,6 @@ enum bgp_display_type
209 route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
211 - if (ANOMALOUS(binfo->flags))
213 - vty_out(vty, "a[");
214 - if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_P))
216 - if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_O))
218 - if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_E))
220 - if (CHECK_FLAG(binfo->flags, BGP_INFO_IGNORED_P))
222 - vty_out(vty, "] ");
225 /* Route status display. */
226 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
228 @@ -5610,6 +5596,17 @@ route_vty_short_status_out (struct vty *
230 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
232 + else if (ANOMALOUS(binfo->flags))
234 + if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_O))
236 + else if (CHECK_FLAG(binfo->flags, BGP_INFO_IGNORED_P))
238 + else if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_P))
240 + if (CHECK_FLAG(binfo->flags, BGP_INFO_SUSPICIOUS_E))
243 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
245 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
246 @@ -6088,7 +6085,22 @@ route_vty_out_detail (struct vty *vty, s
247 if (binfo->extra && binfo->extra->damp_info)
248 bgp_damp_info_vty (vty, binfo);
250 - /* Line 7 display Uptime */
251 + /* 8: PGBGP status */
252 + if (ANOMALOUS(binfo->flags))
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);
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 @@ -6099,8 +6111,9 @@ route_vty_out_detail (struct vty *vty, s
271 vty_out (vty, "%s", VTY_NEWLINE);
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 @@ -6309,8 +6322,7 @@ bgp_show_table (struct vty *vty, struct
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 @@ -9842,7 +9854,7 @@ show_adj_route (struct vty *vty, struct
293 PEER_STATUS_DEFAULT_ORIGINATE))
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);
300 vty_out (vty, "Originating default network 0.0.0.0%s%s",
301 @@ -9859,7 +9871,7 @@ show_adj_route (struct vty *vty, struct
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);
310 @@ -9883,7 +9895,7 @@ show_adj_route (struct vty *vty, struct
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);