From b51146856e660bcec723f535c17dc1c38b2f6efc Mon Sep 17 00:00:00 2001 From: Vyacheslav Trushkin Date: Fri, 25 Nov 2011 18:51:48 +0400 Subject: quagga: option "-z" ("--socket ") added All daemons modified to support custom path to zserv socket. lib: generalize a zclient connection zclient_socket_connect added. zclient_socket and zclient_socket_un were hidden under static expression. "zclient_serv_path_set" modified. --- bgpd/bgp_nexthop.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'bgpd/bgp_nexthop.c') diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 719cb966..60efa195 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -1098,12 +1098,7 @@ zlookup_connect (struct thread *t) if (zlookup->sock != -1) return 0; -#ifdef HAVE_TCP_ZEBRA - zlookup->sock = zclient_socket (); -#else - zlookup->sock = zclient_socket_un (ZEBRA_SERV_PATH); -#endif /* HAVE_TCP_ZEBRA */ - if (zlookup->sock < 0) + if (zclient_socket_connect (zlookup) < 0) return -1; return 0; -- cgit v1.2.1 From 8e80bdf20f493a71bcf74262ed3aa3a2437f4df6 Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Fri, 5 Aug 2011 18:52:52 +0400 Subject: bgpd: touch nexthop handling code bgp_nexthop_lookup_ipv6(): declare variables where they are actually used, drop no-op initialization (the field is already 0) bgp_nexthop_lookup(): ditto bgp_nexthop_check_ebgp(): rename to bgp_nexthop_onlink() bgp_nexthop_cache_changed(): rename to bgp_nexthop_cache_different() --- bgpd/bgp_nexthop.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'bgpd/bgp_nexthop.c') diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 60efa195..d888c8f2 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -146,7 +146,7 @@ bgp_nexthop_same (struct nexthop *next1, struct nexthop *next2) } static int -bgp_nexthop_cache_changed (struct bgp_nexthop_cache *bnc1, +bgp_nexthop_cache_different (struct bgp_nexthop_cache *bnc1, struct bgp_nexthop_cache *bnc2) { int i; @@ -171,7 +171,7 @@ bgp_nexthop_cache_changed (struct bgp_nexthop_cache *bnc1, /* If nexthop exists on connected network return 1. */ int -bgp_nexthop_check_ebgp (afi_t afi, struct attr *attr) +bgp_nexthop_onlink (afi_t afi, struct attr *attr) { struct bgp_node *rn; @@ -256,12 +256,11 @@ bgp_nexthop_lookup_ipv6 (struct peer *peer, struct bgp_info *ri, int *changed, bnc = zlookup_query_ipv6 (&attr->extra->mp_nexthop_global); if (bnc) { - struct bgp_table *old; - struct bgp_node *oldrn; - struct bgp_nexthop_cache *oldbnc; - if (changed) { + struct bgp_table *old; + struct bgp_node *oldrn; + if (bgp_nexthop_cache_table[AFI_IP6] == cache1_table[AFI_IP6]) old = cache2_table[AFI_IP6]; else @@ -270,9 +269,9 @@ bgp_nexthop_lookup_ipv6 (struct peer *peer, struct bgp_info *ri, int *changed, oldrn = bgp_node_lookup (old, &p); if (oldrn) { - oldbnc = oldrn->info; + struct bgp_nexthop_cache *oldbnc = oldrn->info; - bnc->changed = bgp_nexthop_cache_changed (bnc, oldbnc); + bnc->changed = bgp_nexthop_cache_different (bnc, oldbnc); if (bnc->metric != oldbnc->metric) bnc->metricchanged = 1; @@ -284,7 +283,6 @@ bgp_nexthop_lookup_ipv6 (struct peer *peer, struct bgp_info *ri, int *changed, else { bnc = bnc_new (); - bnc->valid = 0; } rn->info = bnc; } @@ -347,12 +345,11 @@ bgp_nexthop_lookup (afi_t afi, struct peer *peer, struct bgp_info *ri, bnc = zlookup_query (addr); if (bnc) { - struct bgp_table *old; - struct bgp_node *oldrn; - struct bgp_nexthop_cache *oldbnc; - if (changed) { + struct bgp_table *old; + struct bgp_node *oldrn; + if (bgp_nexthop_cache_table[AFI_IP] == cache1_table[AFI_IP]) old = cache2_table[AFI_IP]; else @@ -361,9 +358,9 @@ bgp_nexthop_lookup (afi_t afi, struct peer *peer, struct bgp_info *ri, oldrn = bgp_node_lookup (old, &p); if (oldrn) { - oldbnc = oldrn->info; + struct bgp_nexthop_cache *oldbnc = oldrn->info; - bnc->changed = bgp_nexthop_cache_changed (bnc, oldbnc); + bnc->changed = bgp_nexthop_cache_different (bnc, oldbnc); if (bnc->metric != oldbnc->metric) bnc->metricchanged = 1; @@ -375,7 +372,6 @@ bgp_nexthop_lookup (afi_t afi, struct peer *peer, struct bgp_info *ri, else { bnc = bnc_new (); - bnc->valid = 0; } rn->info = bnc; } @@ -462,7 +458,7 @@ bgp_scan (afi_t afi, safi_t safi) metricchanged = 0; if (peer_sort (bi->peer) == BGP_PEER_EBGP && bi->peer->ttl == 1) - valid = bgp_nexthop_check_ebgp (afi, bi->attr); + valid = bgp_nexthop_onlink (afi, bi->attr); else valid = bgp_nexthop_lookup (afi, bi->peer, bi, &changed, &metricchanged); -- cgit v1.2.1 From 318f0d8a7f5e8e87086bbf2a9e7c4b35638951ac Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Fri, 5 Aug 2011 21:47:08 +0400 Subject: bgpd: add "show ip bgp scan detail" command * bgp_nexthop.c: (show_ip_bgp_scan) transform into show_ip_bgp_scan_tables(), which uses inet_ntop() and can dump nexthops on request; (show_ip_bgp_scan_detail_cmd) new function --- bgpd/bgp_nexthop.c | 59 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 15 deletions(-) (limited to 'bgpd/bgp_nexthop.c') diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index d888c8f2..db121d2c 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -1192,16 +1192,13 @@ ALIAS (no_bgp_scan_time, "Configure background scanner interval\n" "Scanner interval (seconds)\n") -DEFUN (show_ip_bgp_scan, - show_ip_bgp_scan_cmd, - "show ip bgp scan", - SHOW_STR - IP_STR - BGP_STR - "BGP scan status\n") +static int +show_ip_bgp_scan_tables (struct vty *vty, const char detail) { struct bgp_node *rn; struct bgp_nexthop_cache *bnc; + char buf[INET6_ADDRSTRLEN]; + u_char i; if (bgp_scan_thread) vty_out (vty, "BGP scan is running%s", VTY_NEWLINE); @@ -1214,28 +1211,37 @@ DEFUN (show_ip_bgp_scan, if ((bnc = rn->info) != NULL) { if (bnc->valid) + { vty_out (vty, " %s valid [IGP metric %d]%s", - inet_ntoa (rn->p.u.prefix4), bnc->metric, VTY_NEWLINE); + inet_ntop (AF_INET, &rn->p.u.prefix4, buf, INET6_ADDRSTRLEN), bnc->metric, VTY_NEWLINE); + if (detail) + for (i = 0; i < bnc->nexthop_num; i++) + vty_out (vty, " %s%s", inet_ntop (AF_INET, &bnc->nexthop[i].gate.ipv4, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); + } else vty_out (vty, " %s invalid%s", - inet_ntoa (rn->p.u.prefix4), VTY_NEWLINE); + inet_ntop (AF_INET, &rn->p.u.prefix4, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); } #ifdef HAVE_IPV6 { - char buf[BUFSIZ]; for (rn = bgp_table_top (bgp_nexthop_cache_table[AFI_IP6]); rn; rn = bgp_route_next (rn)) if ((bnc = rn->info) != NULL) { if (bnc->valid) + { vty_out (vty, " %s valid [IGP metric %d]%s", - inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ), + inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, INET6_ADDRSTRLEN), bnc->metric, VTY_NEWLINE); + if (detail) + for (i = 0; i < bnc->nexthop_num; i++) + vty_out (vty, " %s%s", inet_ntop (AF_INET6, &bnc->nexthop[i].gate.ipv4, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); + } else vty_out (vty, " %s invalid%s", - inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ), + inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); } } @@ -1251,14 +1257,12 @@ DEFUN (show_ip_bgp_scan, #ifdef HAVE_IPV6 { - char buf[BUFSIZ]; - for (rn = bgp_table_top (bgp_connected_table[AFI_IP6]); rn; rn = bgp_route_next (rn)) if (rn->info != NULL) vty_out (vty, " %s/%d%s", - inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, BUFSIZ), + inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, INET6_ADDRSTRLEN), rn->p.prefixlen, VTY_NEWLINE); } @@ -1267,6 +1271,29 @@ DEFUN (show_ip_bgp_scan, return CMD_SUCCESS; } +DEFUN (show_ip_bgp_scan, + show_ip_bgp_scan_cmd, + "show ip bgp scan", + SHOW_STR + IP_STR + BGP_STR + "BGP scan status\n") +{ + return show_ip_bgp_scan_tables (vty, 0); +} + +DEFUN (show_ip_bgp_scan_detail, + show_ip_bgp_scan_detail_cmd, + "show ip bgp scan detail", + SHOW_STR + IP_STR + BGP_STR + "BGP scan status\n" + "More detailed output\n") +{ + return show_ip_bgp_scan_tables (vty, 1); +} + int bgp_config_write_scan_time (struct vty *vty) { @@ -1308,8 +1335,10 @@ bgp_scan_init (void) install_element (BGP_NODE, &no_bgp_scan_time_cmd); install_element (BGP_NODE, &no_bgp_scan_time_val_cmd); install_element (VIEW_NODE, &show_ip_bgp_scan_cmd); + install_element (VIEW_NODE, &show_ip_bgp_scan_detail_cmd); install_element (RESTRICTED_NODE, &show_ip_bgp_scan_cmd); install_element (ENABLE_NODE, &show_ip_bgp_scan_cmd); + install_element (ENABLE_NODE, &show_ip_bgp_scan_detail_cmd); } void -- cgit v1.2.1 From b64bfc1c4a552fc0b4dd024d5f77171ec848a5df Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Mon, 8 Aug 2011 19:36:44 +0400 Subject: bgpd: dismiss some zlookup checks bgp_nexthop_onlink(): zlookup is not used here at all bgp_nexthop_lookup_ipv6(): rely on the detection performed by "query" function (this also changes the fallback value to 0), reorder if-block bgp_nexthop_lookup(): idem --- bgpd/bgp_nexthop.c | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) (limited to 'bgpd/bgp_nexthop.c') diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index db121d2c..dc448f9f 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -175,10 +175,6 @@ bgp_nexthop_onlink (afi_t afi, struct attr *attr) { struct bgp_node *rn; - /* If zebra is not enabled return */ - if (zlookup->sock < 0) - return 1; - /* Lookup the address is onlink or not. */ if (afi == AFI_IP) { @@ -223,14 +219,6 @@ bgp_nexthop_lookup_ipv6 (struct peer *peer, struct bgp_info *ri, int *changed, struct bgp_nexthop_cache *bnc; struct attr *attr; - /* If lookup is not enabled, return valid. */ - if (zlookup->sock < 0) - { - if (ri->extra) - ri->extra->igpmetric = 0; - return 1; - } - /* Only check IPv6 global address only nexthop. */ attr = ri->attr; @@ -253,8 +241,9 @@ bgp_nexthop_lookup_ipv6 (struct peer *peer, struct bgp_info *ri, int *changed, } else { - bnc = zlookup_query_ipv6 (&attr->extra->mp_nexthop_global); - if (bnc) + if (NULL == (bnc = zlookup_query_ipv6 (&attr->extra->mp_nexthop_global))) + bnc = bnc_new (); + else { if (changed) { @@ -280,10 +269,6 @@ bgp_nexthop_lookup_ipv6 (struct peer *peer, struct bgp_info *ri, int *changed, } } } - else - { - bnc = bnc_new (); - } rn->info = bnc; } @@ -312,14 +297,6 @@ bgp_nexthop_lookup (afi_t afi, struct peer *peer, struct bgp_info *ri, struct bgp_nexthop_cache *bnc; struct in_addr addr; - /* If lookup is not enabled, return valid. */ - if (zlookup->sock < 0) - { - if (ri->extra) - ri->extra->igpmetric = 0; - return 1; - } - #ifdef HAVE_IPV6 if (afi == AFI_IP6) return bgp_nexthop_lookup_ipv6 (peer, ri, changed, metricchanged); @@ -342,8 +319,9 @@ bgp_nexthop_lookup (afi_t afi, struct peer *peer, struct bgp_info *ri, } else { - bnc = zlookup_query (addr); - if (bnc) + if (NULL == (bnc = zlookup_query (addr))) + bnc = bnc_new (); + else { if (changed) { @@ -369,10 +347,6 @@ bgp_nexthop_lookup (afi_t afi, struct peer *peer, struct bgp_info *ri, } } } - else - { - bnc = bnc_new (); - } rn->info = bnc; } -- cgit v1.2.1 From 0e8032d69961ae196c11ba6ead856084c7acf7c2 Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Tue, 9 Aug 2011 14:42:58 +0400 Subject: bgpd: improve "show ip bgp scan detail" * bgp_nexthop.c (show_ip_bgp_scan_tables): access proper structure field in AF_INET6 case, handle ifindex NH type properly --- bgpd/bgp_nexthop.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'bgpd/bgp_nexthop.c') diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index dc448f9f..e9c78b3f 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -1190,7 +1190,17 @@ show_ip_bgp_scan_tables (struct vty *vty, const char detail) inet_ntop (AF_INET, &rn->p.u.prefix4, buf, INET6_ADDRSTRLEN), bnc->metric, VTY_NEWLINE); if (detail) for (i = 0; i < bnc->nexthop_num; i++) - vty_out (vty, " %s%s", inet_ntop (AF_INET, &bnc->nexthop[i].gate.ipv4, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); + switch (bnc->nexthop[i].type) + { + case NEXTHOP_TYPE_IPV4: + vty_out (vty, " gate %s%s", inet_ntop (AF_INET, &bnc->nexthop[i].gate.ipv4, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); + break; + case NEXTHOP_TYPE_IFINDEX: + vty_out (vty, " ifidx %u%s", bnc->nexthop[i].ifindex, VTY_NEWLINE); + break; + default: + vty_out (vty, " invalid nexthop type %u%s", bnc->nexthop[i].type, VTY_NEWLINE); + } } else vty_out (vty, " %s invalid%s", @@ -1211,7 +1221,17 @@ show_ip_bgp_scan_tables (struct vty *vty, const char detail) bnc->metric, VTY_NEWLINE); if (detail) for (i = 0; i < bnc->nexthop_num; i++) - vty_out (vty, " %s%s", inet_ntop (AF_INET6, &bnc->nexthop[i].gate.ipv4, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); + switch (bnc->nexthop[i].type) + { + case NEXTHOP_TYPE_IPV6: + vty_out (vty, " gate %s%s", inet_ntop (AF_INET6, &bnc->nexthop[i].gate.ipv6, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); + break; + case NEXTHOP_TYPE_IFINDEX: + vty_out (vty, " ifidx %u%s", bnc->nexthop[i].ifindex, VTY_NEWLINE); + break; + default: + vty_out (vty, " invalid nexthop type %u%s", bnc->nexthop[i].type, VTY_NEWLINE); + } } else vty_out (vty, " %s invalid%s", -- cgit v1.2.1 From fc98d16ea77372f4ab4231e8904f8467e8d1ef71 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Mon, 9 Jan 2012 11:36:23 +0000 Subject: bgpd: reinstate zlookup checks, required for BGP without zebra * bgp_nexthop.c: The nexthop lookup cache has to return success for queried nexthops if bgpd isn't connected to zebra, or else BGP without zebra doesn't work. --- bgpd/bgp_nexthop.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'bgpd/bgp_nexthop.c') diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index e9c78b3f..fdf251b2 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -174,7 +174,11 @@ int bgp_nexthop_onlink (afi_t afi, struct attr *attr) { struct bgp_node *rn; - + + /* If zebra is not enabled return */ + if (zlookup->sock < 0) + return 1; + /* Lookup the address is onlink or not. */ if (afi == AFI_IP) { @@ -218,7 +222,15 @@ bgp_nexthop_lookup_ipv6 (struct peer *peer, struct bgp_info *ri, int *changed, struct prefix p; struct bgp_nexthop_cache *bnc; struct attr *attr; - + + /* If lookup is not enabled, return valid. */ + if (zlookup->sock < 0) + { + if (ri->extra) + ri->extra->igpmetric = 0; + return 1; + } + /* Only check IPv6 global address only nexthop. */ attr = ri->attr; @@ -296,7 +308,15 @@ bgp_nexthop_lookup (afi_t afi, struct peer *peer, struct bgp_info *ri, struct prefix p; struct bgp_nexthop_cache *bnc; struct in_addr addr; - + + /* If lookup is not enabled, return valid. */ + if (zlookup->sock < 0) + { + if (ri->extra) + ri->extra->igpmetric = 0; + return 1; + } + #ifdef HAVE_IPV6 if (afi == AFI_IP6) return bgp_nexthop_lookup_ipv6 (peer, ri, changed, metricchanged); -- cgit v1.2.1