]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: use peer->ifp->ifindex instead of peer->ifindex
authorDaniel Walton <dwalton@cumulusnetworks.com>
Mon, 26 Feb 2018 22:13:22 +0000 (22:13 +0000)
committerDaniel Walton <dwalton@cumulusnetworks.com>
Mon, 26 Feb 2018 22:13:22 +0000 (22:13 +0000)
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
peer->ifindex was only used in two places but it was never populated so
neither of them worked as they should.  'struct peer' also has a 'struct
interface' pointer which we can use to get the ifindex.

bgpd/bgp_dump.c
bgpd/bgp_mpath.c
bgpd/bgpd.c
bgpd/bgpd.h

index 08313690624631ce9b47923e79663829a3414fe6..4e998b1fd9cd5cdd498aa37533de0ca696a56036 100644 (file)
@@ -465,7 +465,7 @@ static void bgp_dump_common(struct stream *obuf, struct peer *peer,
        }
 
        if (peer->su.sa.sa_family == AF_INET) {
-               stream_putw(obuf, peer->ifindex);
+               stream_putw(obuf, peer->ifp ? peer->ifp->ifindex : 0);
                stream_putw(obuf, AFI_IP);
 
                stream_put(obuf, &peer->su.sin.sin_addr, IPV4_MAX_BYTELEN);
@@ -477,7 +477,7 @@ static void bgp_dump_common(struct stream *obuf, struct peer *peer,
                        stream_put(obuf, empty, IPV4_MAX_BYTELEN);
        } else if (peer->su.sa.sa_family == AF_INET6) {
                /* Interface Index and Address family. */
-               stream_putw(obuf, peer->ifindex);
+               stream_putw(obuf, peer->ifp ? peer->ifp->ifindex : 0);
                stream_putw(obuf, AFI_IP6);
 
                /* Source IP Address and Destination IP Address. */
index 9d32c4bee11d916937162ef007df83be9b957c49..5d83192a3022418f9787f6382bd42c3c503f0baa 100644 (file)
@@ -92,6 +92,26 @@ int bgp_maximum_paths_unset(struct bgp *bgp, afi_t afi, safi_t safi,
        return 0;
 }
 
+/*
+ * bgp_interface_same
+ *
+ * Return true if ifindex for ifp1 and ifp2 are the same, else return false.
+ */
+static int bgp_interface_same(struct interface *ifp1, struct interface *ifp2)
+{
+       if (!ifp1 && !ifp2)
+               return 1;
+
+       if (!ifp1 && ifp2)
+               return 0;
+
+       if (ifp1 && !ifp2)
+               return 0;
+
+       return (ifp1->ifindex == ifp2->ifindex);
+}
+
+
 /*
  * bgp_info_nexthop_cmp
  *
@@ -130,7 +150,8 @@ int bgp_info_nexthop_cmp(struct bgp_info *bi1, struct bgp_info *bi2)
 
                                if (!bi1->attr->mp_nexthop_prefer_global &&
                                    !bi2->attr->mp_nexthop_prefer_global)
-                                       compare = !(bi1->peer->ifindex == bi2->peer->ifindex);
+                                       compare = !bgp_interface_same(bi1->peer->ifp, bi2->peer->ifp);
+
                                if (!compare)
                                        compare = IPV6_ADDR_CMP(&addr1, &addr2);
                                break;
index 78e748fb6c5d2c5765af9ee67f6121f8b838c9ee..93493001b509a6257e41d128db809710d1d4fa8f 100644 (file)
@@ -1200,7 +1200,6 @@ void peer_xfer_config(struct peer *peer_dst, struct peer *peer_src)
        peer_dst->config = peer_src->config;
 
        peer_dst->local_as = peer_src->local_as;
-       peer_dst->ifindex = peer_src->ifindex;
        peer_dst->port = peer_src->port;
        (void)peer_sort(peer_dst);
        peer_dst->rmap_type = peer_src->rmap_type;
index 220b6d989e43b551f98b8275d4884b85f7c6c14d..dd0f64f56594ed47b3f30c830fcef4711a8dc7f8 100644 (file)
@@ -686,7 +686,6 @@ struct peer {
        time_t readtime;     /* Last read time */
        time_t resettime;    /* Last reset time */
 
-       ifindex_t ifindex;     /* ifindex of the BGP connection. */
        char *conf_if;   /* neighbor interface config name. */
        struct interface *ifp; /* corresponding interface */
        char *ifname;     /* bind interface name. */