]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Set h_ifindex correctly.
authorVincent Bernat <bernat@luffy.cx>
Tue, 9 Jun 2009 05:42:32 +0000 (07:42 +0200)
committerVincent Bernat <bernat@luffy.cx>
Tue, 9 Jun 2009 05:42:32 +0000 (07:42 +0200)
We also use this index as a way to define an interface. The following
comment has been added to lldpd.h:

An interface is uniquely identified by h_ifindex, h_ifname and h_ops.
This means if an interface becomes enslaved, it will be considered as
a new interface. The same applies for renaming and we include the
index in case of renaming to an existing interface.

src/interfaces.c
src/lldpd.c
src/lldpd.h

index d5a376877bb4abd4db43c46ed3d4c30f4d6189d4..297fc0a0032ee0d0ae9b45931e98b64a978f9131 100644 (file)
@@ -641,7 +641,10 @@ lldpd_ifh_eth(struct lldpd *cfg, struct ifaddrs *ifap)
                if (!iface_minimal_checks(cfg, ifa))
                        continue;
 
-               if ((hardware = lldpd_get_hardware(cfg, ifa->ifa_name, &eth_ops)) == NULL) {
+               if ((hardware = lldpd_get_hardware(cfg,
+                           ifa->ifa_name,
+                           if_nametoindex(ifa->ifa_name),
+                           &eth_ops)) == NULL) {
                        if  ((hardware = lldpd_alloc_hardware(cfg,
                                    ifa->ifa_name)) == NULL) {
                                LLOG_WARNX("Unable to allocate space for %s",
@@ -654,6 +657,7 @@ lldpd_ifh_eth(struct lldpd *cfg, struct ifaddrs *ifap)
                                continue;
                        }
                        hardware->h_ops = &eth_ops;
+                       hardware->h_ifindex = if_nametoindex(ifa->ifa_name);
                        TAILQ_INSERT_TAIL(&cfg->g_hardware, hardware, h_entries);
                } else {
                        if (hardware->h_flags) continue; /* Already seen this time */
@@ -783,7 +787,7 @@ iface_bond_recv(struct lldpd *cfg, struct lldpd_hardware *hardware,
                /* We received this on the physical interface. */
                return n;
        /* We received this on the bonding interface. Is it really for us? */
-       if (from.sll_ifindex == if_nametoindex(hardware->h_ifname))
+       if (from.sll_ifindex == hardware->h_ifindex)
                /* This is for us */
                return n;
        if (from.sll_ifindex == if_nametoindex((char*)hardware->h_data))
@@ -819,7 +823,10 @@ lldpd_ifh_bond(struct lldpd *cfg, struct ifaddrs *ifap)
                if ((master = iface_is_enslaved(cfg, ifa->ifa_name)) == -1)
                        continue;
 
-               if ((hardware = lldpd_get_hardware(cfg, ifa->ifa_name, &bond_ops)) == NULL) {
+               if ((hardware = lldpd_get_hardware(cfg,
+                           ifa->ifa_name,
+                           if_nametoindex(ifa->ifa_name),
+                           &bond_ops)) == NULL) {
                        if  ((hardware = lldpd_alloc_hardware(cfg,
                                    ifa->ifa_name)) == NULL) {
                                LLOG_WARNX("Unable to allocate space for %s",
@@ -835,6 +842,7 @@ lldpd_ifh_bond(struct lldpd *cfg, struct ifaddrs *ifap)
                                continue;
                        }
                        hardware->h_ops = &bond_ops;
+                       hardware->h_ifindex = if_nametoindex(ifa->ifa_name);
                        TAILQ_INSERT_TAIL(&cfg->g_hardware, hardware, h_entries);
                } else {
                        if (hardware->h_flags) continue; /* Already seen this time */
@@ -1015,7 +1023,9 @@ lldpd_ifh_vlan(struct lldpd *cfg, struct ifaddrs *ifap)
                            3. we get a bridge
                        */
                        if ((hardware = lldpd_get_hardware(cfg,
-                                   ifv.u.device2, NULL)) == NULL) {
+                                   ifv.u.device2,
+                                   if_nametoindex(ifv.u.device2),
+                                   NULL)) == NULL) {
                                if (iface_is_bond(cfg, ifv.u.device2)) {
                                        TAILQ_FOREACH(hardware, &cfg->g_hardware,
                                            h_entries)
index 13ecdfd1937c8900432a72f001ad992d7c82e043..63989b55a4b004ea21ca89d3ce5ca05ce6770267 100644 (file)
@@ -97,11 +97,12 @@ usage(void)
 }
 
 struct lldpd_hardware *
-lldpd_get_hardware(struct lldpd *cfg, char *name, struct lldpd_ops *ops)
+lldpd_get_hardware(struct lldpd *cfg, char *name, int index, struct lldpd_ops *ops)
 {
        struct lldpd_hardware *hardware;
        TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) {
                if ((strcmp(hardware->h_ifname, name) == 0) &&
+                   (hardware->h_ifindex == index) &&
                    ((!ops) || (ops == hardware->h_ops)))
                        break;
        }
index 402974ce2846e203c7d50ca3df8d352fa9cf31e2..de76fa639ae72b8389bbd795ade5b5a8d0b8f599 100644 (file)
@@ -206,6 +206,10 @@ struct lldpd_ops {
        int(*cleanup)(struct lldpd *, struct lldpd_hardware *); /* Cleanup function. */
 };
 
+/* An interface is uniquely identified by h_ifindex, h_ifname and h_ops. This
+ * means if an interface becomes enslaved, it will be considered as a new
+ * interface. The same applies for renaming and we include the index in case of
+ * renaming to an existing interface. */
 struct lldpd_hardware {
        TAILQ_ENTRY(lldpd_hardware)      h_entries;
 
@@ -328,7 +332,8 @@ struct hmsg {
 #define MAX_HMSGSIZE           8192
 
 /* lldpd.c */
-struct lldpd_hardware  *lldpd_get_hardware(struct lldpd *, char *, struct lldpd_ops *);
+struct lldpd_hardware  *lldpd_get_hardware(struct lldpd *,
+    char *, int, struct lldpd_ops *);
 struct lldpd_hardware  *lldpd_alloc_hardware(struct lldpd *, char *);
 void    lldpd_hardware_cleanup(struct lldpd*, struct lldpd_hardware *);
 #ifdef ENABLE_DOT1