]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #3560 from opensourcerouting/fix-sh-bgp-community
authorRuss White <russ@riw.us>
Thu, 3 Jan 2019 02:42:50 +0000 (21:42 -0500)
committerGitHub <noreply@github.com>
Thu, 3 Jan 2019 02:42:50 +0000 (21:42 -0500)
bgpd: fix parsing of community number in the "show bgp community" command

bgpd/bgp_evpn_vty.c
lib/zclient.c
sharpd/sharp_main.c
sharpd/sharp_vty.c
sharpd/sharp_zebra.c
sharpd/sharp_zebra.h
vtysh/extract.pl.in
vtysh/vtysh.c
zebra/kernel_netlink.c
zebra/zapi_msg.c

index 13f899e8806245f0159cd1997df73d23cc1deb55..776f8f8ef730d0df2fdca1353499700e4ba628e4 100644 (file)
@@ -2883,6 +2883,12 @@ DEFUN (bgp_evpn_advertise_default_gw,
        if (!bgp)
                return CMD_WARNING;
 
+       if (bgp->vrf_id != VRF_DEFAULT) {
+               vty_out(vty,
+                       "This command is only supported under Default VRF\n");
+               return CMD_WARNING;
+       }
+
        evpn_set_advertise_default_gw(bgp, NULL);
 
        return CMD_SUCCESS;
@@ -2899,6 +2905,12 @@ DEFUN (no_bgp_evpn_advertise_default_gw,
        if (!bgp)
                return CMD_WARNING;
 
+       if (bgp->vrf_id != VRF_DEFAULT) {
+               vty_out(vty,
+                       "This command is only supported under Default VRF\n");
+               return CMD_WARNING;
+       }
+
        evpn_unset_advertise_default_gw(bgp, NULL);
 
        return CMD_SUCCESS;
@@ -3011,6 +3023,12 @@ DEFPY (dup_addr_detection,
        if (!bgp_vrf)
                return CMD_WARNING;
 
+       if (bgp_vrf->vrf_id != VRF_DEFAULT) {
+               vty_out(vty,
+                       "This command is only supported under Default VRF\n");
+               return CMD_WARNING;
+       }
+
        bgp_vrf->evpn_info->dup_addr_detect = true;
 
        if (time_val)
@@ -3037,6 +3055,12 @@ DEFPY (dup_addr_detection_auto_recovery,
        if (!bgp_vrf)
                return CMD_WARNING;
 
+       if (bgp_vrf->vrf_id != VRF_DEFAULT) {
+               vty_out(vty,
+                       "This command is only supported under Default VRF\n");
+               return CMD_WARNING;
+       }
+
        bgp_vrf->evpn_info->dup_addr_detect = true;
        bgp_vrf->evpn_info->dad_freeze = true;
        bgp_vrf->evpn_info->dad_freeze_time = freeze_time;
@@ -3066,6 +3090,12 @@ DEFPY (no_dup_addr_detection,
        if (!bgp_vrf)
                return CMD_WARNING;
 
+       if (bgp_vrf->vrf_id != VRF_DEFAULT) {
+               vty_out(vty,
+                       "This command is only supported under Default VRF\n");
+               return CMD_WARNING;
+       }
+
        if (argc == 2) {
                if (!bgp_vrf->evpn_info->dup_addr_detect)
                        return CMD_SUCCESS;
index beb3ca4f345e844131af5b4d7e91265600ac946c..d2a6c75548f41698834c1ec3efacc1f6eff85e9a 100644 (file)
@@ -1770,19 +1770,19 @@ struct interface *zebra_interface_vrf_update_read(struct stream *s,
                                                  vrf_id_t vrf_id,
                                                  vrf_id_t *new_vrf_id)
 {
-       unsigned int ifindex;
+       char ifname[INTERFACE_NAMSIZ];
        struct interface *ifp;
        vrf_id_t new_id;
 
-       /* Get interface index. */
-       ifindex = stream_getl(s);
+       /* Read interface name. */
+       stream_get(ifname, s, INTERFACE_NAMSIZ);
 
        /* Lookup interface. */
-       ifp = if_lookup_by_index(ifindex, vrf_id);
+       ifp = if_lookup_by_name(ifname, vrf_id);
        if (ifp == NULL) {
                flog_err(EC_LIB_ZAPI_ENCODE,
-                        "INTERFACE_VRF_UPDATE: Cannot find IF %u in VRF %d",
-                        ifindex, vrf_id);
+                        "INTERFACE_VRF_UPDATE: Cannot find IF %s in VRF %d",
+                        ifname, vrf_id);
                return NULL;
        }
 
index 20cdd21e7d23498af780700ddf7535b4fe65b7a7..175a276089b6962b1e0ad8a3cdc707c3501411e3 100644 (file)
@@ -42,6 +42,7 @@
 #include "distribute.h"
 #include "libfrr.h"
 #include "routemap.h"
+#include "nexthop_group.h"
 
 #include "sharp_zebra.h"
 #include "sharp_vty.h"
@@ -150,6 +151,7 @@ int main(int argc, char **argv, char **envp)
 
        master = frr_init();
 
+       nexthop_group_init(NULL, NULL, NULL, NULL);
        vrf_init(NULL, NULL, NULL, NULL, NULL);
 
        access_list_init();
index 797e336c2d2de814d91a6a5e3437d34e9146a9a0..3aed8eb1231623cc40eafc22f44f0dc5ef5eb99e 100644 (file)
@@ -28,6 +28,7 @@
 #include "log.h"
 #include "vrf.h"
 #include "zclient.h"
+#include "nexthop_group.h"
 
 #include "sharpd/sharp_zebra.h"
 #include "sharpd/sharp_vty.h"
@@ -81,7 +82,7 @@ DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
 
 DEFPY (install_routes,
        install_routes_cmd,
-       "sharp install routes A.B.C.D$start nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6> (1-1000000)$routes [instance (0-255)$instance]",
+       "sharp install routes A.B.C.D$start <nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6>|nexthop-group NAME$nexthop_group> (1-1000000)$routes [instance (0-255)$instance]",
        "Sharp routing Protocol\n"
        "install some routes\n"
        "Routes to install\n"
@@ -89,6 +90,8 @@ DEFPY (install_routes,
        "Nexthop to use(Can be an IPv4 or IPv6 address)\n"
        "V4 Nexthop address to use\n"
        "V6 Nexthop address to use\n"
+       "Nexthop-Group to use\n"
+       "The Name of the nexthop-group\n"
        "How many to create\n"
        "Instance to use\n"
        "Instance\n")
@@ -96,6 +99,7 @@ DEFPY (install_routes,
        int i;
        struct prefix p;
        struct nexthop nhop;
+       struct nexthop_group nhg;
        uint32_t temp;
 
        total_routes = routes;
@@ -103,24 +107,38 @@ DEFPY (install_routes,
 
        memset(&p, 0, sizeof(p));
        memset(&nhop, 0, sizeof(nhop));
+       memset(&nhg, 0, sizeof(nhg));
 
        p.family = AF_INET;
        p.prefixlen = 32;
        p.u.prefix4 = start;
 
-       if (nexthop4.s_addr != INADDR_ANY) {
-               nhop.gate.ipv4 = nexthop4;
-               nhop.type = NEXTHOP_TYPE_IPV4;
+       if (nexthop_group) {
+               struct nexthop_group_cmd *nhgc = nhgc_find(nexthop_group);
+               if (!nhgc) {
+                       vty_out(vty,
+                               "Specified Nexthop Group: %s does not exist\n",
+                               nexthop_group);
+                       return CMD_WARNING;
+               }
+
+               nhg.nexthop = nhgc->nhg.nexthop;
        } else {
-               memcpy(&nhop.gate.ipv6, &nexthop6, IPV6_MAX_BYTELEN);
-               nhop.type = NEXTHOP_TYPE_IPV6;
+               if (nexthop4.s_addr != INADDR_ANY) {
+                       nhop.gate.ipv4 = nexthop4;
+                       nhop.type = NEXTHOP_TYPE_IPV4;
+               } else {
+                       nhop.gate.ipv6 = nexthop6;
+                       nhop.type = NEXTHOP_TYPE_IPV6;
+               }
+
+               nhg.nexthop = &nhop;
        }
-
        zlog_debug("Inserting %ld routes", routes);
 
        temp = ntohl(p.u.prefix4.s_addr);
        for (i = 0; i < routes; i++) {
-               route_add(&p, (uint8_t)instance, &nhop);
+               route_add(&p, (uint8_t)instance, &nhg);
                p.u.prefix4.s_addr = htonl(++temp);
        }
 
index f752009eb8fc61312e35b08e0d13bbe44e26aabf..4a88b6c8ee13e984f03c90ca2b1fe15210153d59 100644 (file)
@@ -34,6 +34,7 @@
 #include "plist.h"
 #include "log.h"
 #include "nexthop.h"
+#include "nexthop_group.h"
 
 #include "sharp_zebra.h"
 
@@ -176,10 +177,12 @@ void vrf_label_add(vrf_id_t vrf_id, afi_t afi, mpls_label_t label)
        zclient_send_vrf_label(zclient, vrf_id, afi, label, ZEBRA_LSP_SHARP);
 }
 
-void route_add(struct prefix *p, uint8_t instance, struct nexthop *nh)
+void route_add(struct prefix *p, uint8_t instance, struct nexthop_group *nhg)
 {
        struct zapi_route api;
        struct zapi_nexthop *api_nh;
+       struct nexthop *nh;
+       int i = 0;
 
        memset(&api, 0, sizeof(api));
        api.vrf_id = VRF_DEFAULT;
@@ -191,12 +194,35 @@ void route_add(struct prefix *p, uint8_t instance, struct nexthop *nh)
        SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION);
        SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
 
-       api_nh = &api.nexthops[0];
-       api_nh->vrf_id = VRF_DEFAULT;
-       api_nh->gate = nh->gate;
-       api_nh->type = nh->type;
-       api_nh->ifindex = nh->ifindex;
-       api.nexthop_num = 1;
+       for (ALL_NEXTHOPS_PTR(nhg, nh)) {
+               api_nh = &api.nexthops[i];
+               api_nh->vrf_id = VRF_DEFAULT;
+               api_nh->type = nh->type;
+               switch (nh->type) {
+               case NEXTHOP_TYPE_IPV4:
+                       api_nh->gate = nh->gate;
+                       break;
+               case NEXTHOP_TYPE_IPV4_IFINDEX:
+                       api_nh->gate = nh->gate;
+                       api_nh->ifindex = nh->ifindex;
+                       break;
+               case NEXTHOP_TYPE_IFINDEX:
+                       api_nh->ifindex = nh->ifindex;
+                       break;
+               case NEXTHOP_TYPE_IPV6:
+                       memcpy(&api_nh->gate.ipv6, &nh->gate.ipv6, 16);
+                       break;
+               case NEXTHOP_TYPE_IPV6_IFINDEX:
+                       api_nh->ifindex = nh->ifindex;
+                       memcpy(&api_nh->gate.ipv6, &nh->gate.ipv6, 16);
+                       break;
+               case NEXTHOP_TYPE_BLACKHOLE:
+                       api_nh->bh_type = nh->bh_type;
+                       break;
+               }
+               i++;
+       }
+       api.nexthop_num = i;
 
        zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
 }
index 58438ed01d821b2f9b8c1f9eda64062e493254e5..ffe21df9b807af57ee0c19e426619b1f040c06e7 100644 (file)
@@ -25,7 +25,8 @@
 extern void sharp_zebra_init(void);
 
 extern void vrf_label_add(vrf_id_t vrf_id, afi_t afi, mpls_label_t label);
-extern void route_add(struct prefix *p, uint8_t instance, struct nexthop *nh);
+extern void route_add(struct prefix *p, uint8_t instance,
+                     struct nexthop_group *nhg);
 extern void route_delete(struct prefix *p, uint8_t instance);
 extern void sharp_zebra_nexthop_watch(struct prefix *p, bool watch);
 #endif
index 596f01738ad19a09bd8fe904d82a3a2dcad4e844..2b48f1f3609a2f91bd9f0af912a811ec3a073de9 100755 (executable)
@@ -109,7 +109,7 @@ sub scan_file {
             $protocol = "VTYSH_ZEBRA";
         }
        elsif ($file =~ /lib\/nexthop_group\.c$/) {
-           $protocol = "VTYSH_PBRD";
+           $protocol = "VTYSH_PBRD | VTYSH_SHARPD";
        }
         elsif ($file =~ /lib\/plist\.c$/) {
             if ($defun_array[1] =~ m/ipv6/) {
index 2327f2b46d7e04219518ab89d5d7fe849d307db9..6cf45789dd97459ea5aa216c39e0139fd86c1059 100644 (file)
@@ -2110,7 +2110,7 @@ DEFSH(VTYSH_ZEBRA, vtysh_no_logicalrouter_cmd,
       "The Name Space\n"
       "The file name in " NS_RUN_DIR ", or a full pathname\n")
 
-DEFUNSH(VTYSH_PBRD, vtysh_nexthop_group, vtysh_nexthop_group_cmd,
+DEFUNSH(VTYSH_PBRD | VTYSH_SHARPD, vtysh_nexthop_group, vtysh_nexthop_group_cmd,
        "nexthop-group NAME",
        "Nexthop Group configuration\n"
        "Name of the Nexthop Group\n")
@@ -2119,7 +2119,8 @@ DEFUNSH(VTYSH_PBRD, vtysh_nexthop_group, vtysh_nexthop_group_cmd,
        return CMD_SUCCESS;
 }
 
-DEFSH(VTYSH_PBRD, vtysh_no_nexthop_group_cmd, "no nexthop-group NAME",
+DEFSH(VTYSH_PBRD | VTYSH_SHARPD, vtysh_no_nexthop_group_cmd,
+      "no nexthop-group NAME",
       NO_STR
       "Nexthop Group Configuration\n"
       "Name of the Nexthop Group\n")
index afc3985854a8ee696fa3fa20233c867cff012d2a..360f596b8f0fa51658916efad201d798843f0296 100644 (file)
@@ -784,7 +784,8 @@ int netlink_parse_info(int (*filter)(struct nlmsghdr *, ns_id_t, int),
 
                                if (h->nlmsg_len
                                    < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
-                                       zlog_err("%s error: message truncated",
+                                       flog_err(EC_ZEBRA_NETLINK_LENGTH_ERROR,
+                                                "%s error: message truncated",
                                                 nl->name);
                                        return -1;
                                }
@@ -820,14 +821,6 @@ int netlink_parse_info(int (*filter)(struct nlmsghdr *, ns_id_t, int),
                                        continue;
                                }
 
-                               if (h->nlmsg_len
-                                   < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
-                                       flog_err(EC_ZEBRA_NETLINK_LENGTH_ERROR,
-                                                "%s error: message truncated",
-                                                nl->name);
-                                       return -1;
-                               }
-
                                /* Deal with errors that occur because of races
                                 * in link handling */
                                if (zns->is_cmd
index 26a3cd5b42a03fca4dd06072525006c85cd3f5c9..32614f408e6085384db76d641f2ac550b33b8686 100644 (file)
@@ -432,8 +432,8 @@ int zsend_interface_vrf_update(struct zserv *client, struct interface *ifp,
 
        zclient_create_header(s, ZEBRA_INTERFACE_VRF_UPDATE, ifp->vrf_id);
 
-       /* Fill in the ifIndex of the interface and its new VRF (id) */
-       stream_putl(s, ifp->ifindex);
+       /* Fill in the name of the interface and its new VRF (id) */
+       stream_put(s, ifp->name, INTERFACE_NAMSIZ);
        stream_putl(s, vrf_id);
 
        /* Write packet size. */