]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Add link_nsid to zebra interface 13266/head
authorXiao Liang <shaw.leon@gmail.com>
Tue, 21 Feb 2023 06:00:36 +0000 (14:00 +0800)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Tue, 11 Apr 2023 21:39:31 +0000 (21:39 +0000)
Create VRF and interfaces:

    ip netns add vrf1
    ip link add veth1 index 100 type veth
    ip link add link veth1 veth1.200 type vlan id 200
    ip link set veth1.200 netns vrf1
    ip -n vrf1 link add veth2 index 100 type veth

After reloading zebra, "show interface veth1.200" shows wrong parent
interface:

    test# show interface veth1.200
    Interface veth1.200 is down
      ...
      Parent interface: veth2

This is because veth1.200 and veth1 are in different netns, and veth2
happens to have the same ifindex as veth1, in the same netns of
veth1.200.
When looking for parent, link-ifindex 100 should be looked up within
link-netns, rather than that of the child interface.

Add link_nsid to zebra interface, so that the <link_nsid, link_ifindex>
pair can uniquely identify the link interface.

Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
(cherry picked from commit af19624b005452dbaf25215ba371e35f61835e03)

zebra/interface.c
zebra/interface.h

index 59563834ef9c64d2ec2035f9ad56c0d0febbfe62..84e52d4b432ccfe6b7ff44faff7e0fc7f63983ee 100644 (file)
@@ -151,6 +151,8 @@ static int if_zebra_new_hook(struct interface *ifp)
        zebra_if->multicast = IF_ZEBRA_DATA_UNSPEC;
        zebra_if->shutdown = IF_ZEBRA_DATA_OFF;
 
+       zebra_if->link_nsid = NS_UNKNOWN;
+
        zebra_if_nhg_dependents_init(zebra_if);
 
        zebra_ptm_if_init(zebra_if);
@@ -318,6 +320,14 @@ struct interface *if_lookup_by_name_per_ns(struct zebra_ns *ns,
        return NULL;
 }
 
+struct interface *if_lookup_by_index_per_nsid(ns_id_t ns_id, uint32_t ifindex)
+{
+       struct zebra_ns *zns;
+
+       zns = zebra_ns_lookup(ns_id);
+       return zns ? if_lookup_by_index_per_ns(zns, ifindex) : NULL;
+}
+
 const char *ifindex2ifname_per_ns(struct zebra_ns *zns, unsigned int ifindex)
 {
        struct interface *ifp;
@@ -1004,7 +1014,6 @@ void if_up(struct interface *ifp, bool install_connected)
 {
        struct zebra_if *zif;
        struct interface *link_if;
-       struct zebra_vrf *zvrf = ifp->vrf->info;
 
        zif = ifp->info;
        zif->up_count++;
@@ -1037,8 +1046,7 @@ void if_up(struct interface *ifp, bool install_connected)
                link_if = ifp;
                zebra_vxlan_svi_up(ifp, link_if);
        } else if (IS_ZEBRA_IF_VLAN(ifp)) {
-               link_if = if_lookup_by_index_per_ns(zvrf->zns,
-                                                   zif->link_ifindex);
+               link_if = zif->link;
                if (link_if)
                        zebra_vxlan_svi_up(ifp, link_if);
        } else if (IS_ZEBRA_IF_MACVLAN(ifp)) {
@@ -1062,7 +1070,6 @@ void if_down(struct interface *ifp)
 {
        struct zebra_if *zif;
        struct interface *link_if;
-       struct zebra_vrf *zvrf = ifp->vrf->info;
 
        zif = ifp->info;
        zif->down_count++;
@@ -1081,8 +1088,7 @@ void if_down(struct interface *ifp)
                link_if = ifp;
                zebra_vxlan_svi_down(ifp, link_if);
        } else if (IS_ZEBRA_IF_VLAN(ifp)) {
-               link_if = if_lookup_by_index_per_ns(zvrf->zns,
-                                                   zif->link_ifindex);
+               link_if = zif->link;
                if (link_if)
                        zebra_vxlan_svi_down(ifp, link_if);
        } else if (IS_ZEBRA_IF_MACVLAN(ifp)) {
@@ -1122,6 +1128,7 @@ void zebra_if_update_link(struct interface *ifp, ifindex_t link_ifindex,
        if (IS_ZEBRA_IF_VETH(ifp))
                return;
        zif = (struct zebra_if *)ifp->info;
+       zif->link_nsid = ns_id;
        zif->link_ifindex = link_ifindex;
        zif->link = if_lookup_by_index_per_ns(zebra_ns_lookup(ns_id),
                                              link_ifindex);
@@ -1158,8 +1165,8 @@ void zebra_if_update_all_links(struct zebra_ns *zns)
 
                /* update SVI linkages */
                if ((zif->link_ifindex != IFINDEX_INTERNAL) && !zif->link) {
-                       zif->link = if_lookup_by_index_per_ns(
-                               zns, zif->link_ifindex);
+                       zif->link = if_lookup_by_index_per_nsid(
+                               zif->link_nsid, zif->link_ifindex);
                        if (IS_ZEBRA_DEBUG_KERNEL)
                                zlog_debug("interface %s/%d's lower fixup to %s/%d",
                                                ifp->name, ifp->ifindex,
index 0242438dc2284a5845ced1c892fc49f69764954a..7062236c830df67eec68f8f845c6d61182d8c234 100644 (file)
@@ -209,6 +209,7 @@ struct zebra_if {
        struct list *mac_list;
 
        /* Link fields - for sub-interfaces. */
+       ns_id_t link_nsid;
        ifindex_t link_ifindex;
        struct interface *link;
 
@@ -273,6 +274,8 @@ extern struct interface *if_lookup_by_index_per_ns(struct zebra_ns *, uint32_t);
 extern struct interface *if_lookup_by_name_per_ns(struct zebra_ns *,
                                                  const char *);
 extern struct interface *if_link_per_ns(struct zebra_ns *, struct interface *);
+extern struct interface *if_lookup_by_index_per_nsid(ns_id_t nsid,
+                                                    uint32_t ifindex);
 extern const char *ifindex2ifname_per_ns(struct zebra_ns *, unsigned int);
 
 extern void if_unlink_per_ns(struct interface *);