From 44002d6615d6c8bd3390333b51c89dc99c235207 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Tue, 9 Jun 2009 07:42:32 +0200 Subject: [PATCH] Set h_ifindex correctly. 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 | 18 ++++++++++++++---- src/lldpd.c | 3 ++- src/lldpd.h | 7 ++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/interfaces.c b/src/interfaces.c index d5a37687..297fc0a0 100644 --- a/src/interfaces.c +++ b/src/interfaces.c @@ -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, ð_ops)) == NULL) { + if ((hardware = lldpd_get_hardware(cfg, + ifa->ifa_name, + if_nametoindex(ifa->ifa_name), + ð_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 = ð_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) diff --git a/src/lldpd.c b/src/lldpd.c index 13ecdfd1..63989b55 100644 --- a/src/lldpd.c +++ b/src/lldpd.c @@ -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; } diff --git a/src/lldpd.h b/src/lldpd.h index 402974ce..de76fa63 100644 --- a/src/lldpd.h +++ b/src/lldpd.h @@ -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 -- 2.39.2