hardware->h_ifname);
interfaces_setup_multicast(cfg, hardware->h_ifname, 1);
interfaces_setup_multicast(cfg, master->name, 1);
- free(hardware->h_data);
+ free(hardware->h_data); hardware->h_data = NULL;
return 0;
}
struct interfaces_device *master;
struct lldpd_hardware *hardware;
struct bond_master *bmaster;
+ int created;
TAILQ_FOREACH(iface, interfaces, next) {
if (!(iface->type & IFACE_PHYSICAL_T)) continue;
if (iface->ignore) continue;
master = iface->upper;
log_debug("interfaces", "%s is an acceptable enslaved device (master=%s)",
iface->name, master->name);
+ created = 0;
if ((hardware = lldpd_get_hardware(cfg,
iface->name,
- iface->index,
- &bond_ops)) == NULL) {
+ iface->index)) == NULL) {
if ((hardware = lldpd_alloc_hardware(cfg,
iface->name,
iface->index)) == NULL) {
iface->name);
continue;
}
+ created = 1;
+ }
+ if (hardware->h_flags) continue;
+ if (hardware->h_ops != &bond_ops) {
+ if (!created) {
+ log_debug("interfaces",
+ "bond %s is converted from another type of interface",
+ hardware->h_ifname);
+ if (hardware->h_ops && hardware->h_ops->cleanup)
+ hardware->h_ops->cleanup(cfg, hardware);
+ levent_hardware_release(hardware);
+ levent_hardware_init(hardware);
+ }
bmaster = hardware->h_data = calloc(1, sizeof(struct bond_master));
if (!bmaster) {
log_warn("interfaces", "not enough memory");
lldpd_hardware_cleanup(cfg, hardware);
continue;
}
- bmaster->index = master->index;
- strlcpy(bmaster->name, master->name, IFNAMSIZ);
+ } else bmaster = hardware->h_data;
+ bmaster->index = master->index;
+ strlcpy(bmaster->name, master->name, IFNAMSIZ);
+ if (hardware->h_ops != &bond_ops) {
if (iface_bond_init(cfg, hardware) != 0) {
log_warn("interfaces", "unable to initialize %s",
hardware->h_ifname);
}
hardware->h_ops = &bond_ops;
hardware->h_mangle = 1;
+ }
+ if (created)
interfaces_helper_add_hardware(cfg, hardware);
- } else {
- if (hardware->h_flags) continue; /* Already seen this time */
- bmaster = hardware->h_data;
- memset(bmaster, 0, sizeof(struct bond_master));
- bmaster->index = master->index;
- strlcpy(bmaster->name, master->name, IFNAMSIZ);
+ else
lldpd_port_cleanup(&hardware->h_lport, 0);
- }
hardware->h_flags = iface->flags;
iface->ignore = 1;
struct interfaces_device *lower)
{
struct lldpd_hardware *hardware =
- lldpd_get_hardware(cfg, lower->name, lower->index, NULL);
+ lldpd_get_hardware(cfg, lower->name, lower->index);
struct lldpd_port *port;
struct lldpd_vlan *v;
if ((hardware = lldpd_get_hardware(cfg,
iface->name,
- iface->index,
- NULL)) == NULL)
+ iface->index)) == NULL)
/* That's odd. Let's skip. */
continue;
{
struct interfaces_device *iface;
struct lldpd_hardware *hardware;
+ int created;
TAILQ_FOREACH(iface, interfaces, next) {
if (!(iface->type & IFACE_PHYSICAL_T)) continue;
log_debug("interfaces", "%s is an acceptable ethernet device",
iface->name);
+ created = 0;
if ((hardware = lldpd_get_hardware(cfg,
iface->name,
- iface->index,
- ops)) == NULL) {
+ iface->index)) == NULL) {
if ((hardware = lldpd_alloc_hardware(cfg,
iface->name,
iface->index)) == NULL) {
iface->name);
continue;
}
+ created = 1;
+ }
+ if (hardware->h_flags)
+ continue;
+ if (hardware->h_ops != ops) {
+ if (!created) {
+ log_debug("interfaces",
+ "interface %s is converted from another type of interface",
+ hardware->h_ifname);
+ if (hardware->h_ops && hardware->h_ops->cleanup) {
+ hardware->h_ops->cleanup(cfg, hardware);
+ levent_hardware_release(hardware);
+ levent_hardware_init(hardware);
+ }
+ }
if (init(cfg, hardware) != 0) {
log_warnx("interfaces",
"unable to initialize %s",
hardware->h_ops = ops;
hardware->h_mangle = (iface->upper &&
iface->upper->type & IFACE_BOND_T);
+ }
+ if (created)
interfaces_helper_add_hardware(cfg, hardware);
- } else {
- if (hardware->h_flags) continue; /* Already seen this time */
+ else
lldpd_port_cleanup(&hardware->h_lport, 0);
- }
hardware->h_flags = iface->flags; /* Should be non-zero */
iface->ignore = 1; /* Future handlers
#ifdef ENABLE_DOT3
if (iface->upper && iface->upper->type & IFACE_BOND_T)
hardware->h_lport.p_aggregid = iface->upper->index;
+ else
+ hardware->h_lport.p_aggregid = 0;
#endif
}
}
}
struct lldpd_hardware *
-lldpd_get_hardware(struct lldpd *cfg, char *name, int index, struct lldpd_ops *ops)
+lldpd_get_hardware(struct lldpd *cfg, char *name, int index)
{
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)))
+ (hardware->h_ifindex == index))
break;
}
return hardware;
/* lldpd.c */
struct lldpd_hardware *lldpd_get_hardware(struct lldpd *,
- char *, int, struct lldpd_ops *);
+ char *, int);
struct lldpd_hardware *lldpd_alloc_hardware(struct lldpd *, char *, int);
void lldpd_hardware_cleanup(struct lldpd*, struct lldpd_hardware *);
struct lldpd_mgmt *lldpd_alloc_mgmt(int family, void *addr, size_t addrsize, u_int32_t iface);