}
}
+/* Fill out chassis ID if not already done. This handler is special
+ because we will only handle interfaces that are already handled. */
+void
+lldpd_ifh_chassis(struct lldpd *cfg, struct ifaddrs *ifap)
+{
+ struct ifaddrs *ifa;
+ struct lldpd_hardware *hardware;
+
+ if (LOCAL_CHASSIS(cfg)->c_id != NULL &&
+ LOCAL_CHASSIS(cfg)->c_id_subtype == LLDP_CHASSISID_SUBTYPE_LLADDR)
+ return; /* We already have one */
+
+ for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
+ if (ifa->ifa_flags) continue; /* This interface is not valid */
+
+ if ((hardware = lldpd_get_hardware(cfg,
+ ifa->ifa_name,
+ if_nametoindex(ifa->ifa_name),
+ NULL)) == NULL)
+ /* That's odd. Let's skip. */
+ continue;
+
+ char *name = malloc(sizeof(hardware->h_lladdr));
+ if (!name) {
+ LLOG_WARN("Not enough memory for chassis ID");
+ return;
+ }
+ free(LOCAL_CHASSIS(cfg)->c_id);
+ memcpy(name, hardware->h_lladdr, sizeof(hardware->h_lladdr));
+ LOCAL_CHASSIS(cfg)->c_id = name;
+ LOCAL_CHASSIS(cfg)->c_id_len = sizeof(hardware->h_lladdr);
+ LOCAL_CHASSIS(cfg)->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
+ return;
+ }
+}
+
struct lldpd_ops eth_ops = {
.send = iface_eth_send,
.recv = iface_eth_recv,
char *hp;
int f;
char status;
- struct lldpd_hardware *hardware;
/* Set system name and description */
if (uname(&un) != 0)
LOCAL_CHASSIS(cfg)->c_med_sw = strdup("Unknown");
#endif
- /* Set chassis ID if needed */
- if ((LOCAL_CHASSIS(cfg)->c_id == NULL) &&
- (hardware = TAILQ_FIRST(&cfg->g_hardware))) {
- if ((LOCAL_CHASSIS(cfg)->c_id =
- malloc(sizeof(hardware->h_lladdr))) == NULL)
+ /* Set chassis ID if needed. This is only done if chassis ID
+ has not been set previously (with the MAC address of an
+ interface for example)
+ */
+ if (LOCAL_CHASSIS(cfg)->c_id == NULL) {
+ if (!(LOCAL_CHASSIS(cfg)->c_id = strdup(LOCAL_CHASSIS(cfg)->c_name)))
fatal(NULL);
- LOCAL_CHASSIS(cfg)->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
- LOCAL_CHASSIS(cfg)->c_id_len = sizeof(hardware->h_lladdr);
- memcpy(LOCAL_CHASSIS(cfg)->c_id,
- hardware->h_lladdr, sizeof(hardware->h_lladdr));
+ LOCAL_CHASSIS(cfg)->c_id_len = strlen(LOCAL_CHASSIS(cfg)->c_name);
+ LOCAL_CHASSIS(cfg)->c_id_subtype = LLDP_CHASSISID_SUBTYPE_LOCAL;
}
}
lldpd_ifh_vlan, /* Handle VLAN */
#endif
lldpd_ifh_mgmt, /* Handle management address (if not already handled) */
+ lldpd_ifh_chassis, /* Handle chassis ID (if not already handled) */
NULL
};
lldpd_ifhandlers *ifh;
void lldpd_ifh_vlan(struct lldpd *, struct ifaddrs *);
#endif
void lldpd_ifh_mgmt(struct lldpd *, struct ifaddrs *);
+void lldpd_ifh_chassis(struct lldpd *, struct ifaddrs *);
/* dmi.c */
#ifdef ENABLE_LLDPMED