]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
One VLAN can be associated to multiple interfaces through bridge or
authorVincent Bernat <bernat@luffy.cx>
Thu, 4 Jun 2009 19:44:40 +0000 (21:44 +0200)
committerVincent Bernat <bernat@luffy.cx>
Thu, 4 Jun 2009 19:44:40 +0000 (21:44 +0200)
bond. Handle those cases appropriately.

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

index 04294803a60f8236a0a99af343e1861bebc20d77..acd35c4921cdab0b36a84ee8b555e7aa809095bf 100644 (file)
@@ -92,6 +92,10 @@ static void   iface_mtu(struct lldpd *, struct lldpd_hardware *);
 static void     iface_multicast(struct lldpd *, const char *, int);
 static int      iface_eth_init(struct lldpd *, struct lldpd_hardware *);
 static int      iface_bond_init(struct lldpd *, struct lldpd_hardware *);
+#ifdef ENABLE_DOT1
+static void     iface_append_vlan(struct lldpd *,
+    struct lldpd_hardware *, struct ifaddrs *);
+#endif
 
 static int      iface_eth_send(struct lldpd *, struct lldpd_hardware*, char *, size_t);
 static int      iface_eth_recv(struct lldpd *, struct lldpd_hardware*, int, char*, size_t);
@@ -836,15 +840,41 @@ lldpd_ifh_bond(struct lldpd *cfg, struct ifaddrs *ifap)
        }
 }
 
+#ifdef ENABLE_DOT1
+static void
+iface_append_vlan(struct lldpd *cfg,
+    struct lldpd_hardware *hardware, struct ifaddrs *ifa)
+{
+       struct lldpd_port *port = &hardware->h_lport;
+       struct lldpd_vlan *vlan;
+       struct vlan_ioctl_args ifv;
+
+       if ((vlan = (struct lldpd_vlan *)
+               calloc(1, sizeof(struct lldpd_vlan))) == NULL)
+               return;
+       if ((vlan->v_name = strdup(ifa->ifa_name)) == NULL) {
+               free(vlan);
+               return;
+       }
+       memset(&ifv, 0, sizeof(ifv));
+       ifv.cmd = GET_VLAN_VID_CMD;
+       strlcpy(ifv.device1, ifa->ifa_name, sizeof(ifv.device1));
+       if (ioctl(cfg->g_sock, SIOCGIFVLAN, &ifv) < 0) {
+               /* Dunno what happened */
+               free(vlan->v_name);
+               free(vlan);
+       } else {
+               vlan->v_vid = ifv.u.VID;
+               TAILQ_INSERT_TAIL(&port->p_vlans, vlan, v_entries);
+       }
+}
+
 void
 lldpd_ifh_vlan(struct lldpd *cfg, struct ifaddrs *ifap)
 {
-#ifdef ENABLE_DOT1
        struct ifaddrs *ifa;
-       struct lldpd_vlan *vlan;
        struct vlan_ioctl_args ifv;
        struct lldpd_hardware *hardware;
-       struct lldpd_port *port;
 
        for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) {
                if (!ifa->ifa_flags)
@@ -871,40 +901,23 @@ lldpd_ifh_vlan(struct lldpd *cfg, struct ifaddrs *ifap)
                                            if (iface_is_bond_slave(cfg,
                                                    hardware->h_ifname,
                                                    ifv.u.device2, NULL))
-                                                   break;
+                                                   iface_append_vlan(cfg,
+                                                       hardware, ifa);
                                } else if (iface_is_bridge(cfg, ifv.u.device2)) {
                                        TAILQ_FOREACH(hardware, &cfg->g_hardware,
                                            h_entries)
                                            if (iface_is_bridged_to(cfg,
                                                    hardware->h_ifname,
                                                    ifv.u.device2))
-                                                   break;
+                                                   iface_append_vlan(cfg,
+                                                       hardware, ifa);
                                }
-                       }
-                       if (!hardware) continue;
-                       port = &hardware->h_lport;
-                       if ((vlan = (struct lldpd_vlan *)
-                            calloc(1, sizeof(struct lldpd_vlan))) == NULL)
-                               continue;
-                       if ((vlan->v_name = strdup(ifa->ifa_name)) == NULL) {
-                               free(vlan);
-                               continue;
-                       }
-                       memset(&ifv, 0, sizeof(ifv));
-                       ifv.cmd = GET_VLAN_VID_CMD;
-                       strlcpy(ifv.device1, ifa->ifa_name, sizeof(ifv.device1));
-                       if (ioctl(cfg->g_sock, SIOCGIFVLAN, &ifv) < 0) {
-                               /* Dunno what happened */
-                               free(vlan->v_name);
-                               free(vlan);
-                       } else {
-                               vlan->v_vid = ifv.u.VID;
-                               TAILQ_INSERT_TAIL(&port->p_vlans, vlan, v_entries);
-                       }
+                       } else iface_append_vlan(cfg,
+                           hardware, ifa);
                }
        }
-#endif
 }
+#endif
 
 /* Find a management address in all available interfaces, even those that were
    already handled. This is a special interface handler because it does not
index b12138c5a883eaf48f14d8012a4edb8fddb33731..635a300195e6079c17a379b94b29bc2724783fbf 100644 (file)
@@ -638,7 +638,9 @@ lldpd_update_localports(struct lldpd *cfg)
        lldpd_ifhandlers ifhs[] = {
                lldpd_ifh_bond, /* Handle bond */
                lldpd_ifh_eth,  /* Handle classic ethernet interfaces */
+#ifdef ENABLE_DOT1
                lldpd_ifh_vlan, /* Handle VLAN */
+#endif
                lldpd_ifh_mgmt, /* Handle management address (if not already handled) */
                NULL
        };
index 56b962dcbf42d7cc2259281ad5f419672d554d44..19e0f9bf43005f2c2a3aa9082faede792ff4398b 100644 (file)
@@ -378,7 +378,9 @@ int  ctl_msg_unpack_structure(char *, void *, unsigned int, struct hmsg *, void
 /* interfaces.c */
 void    lldpd_ifh_bond(struct lldpd *, struct ifaddrs *);
 void    lldpd_ifh_eth(struct lldpd *, struct ifaddrs *);
+#ifdef ENABLE_DOT1
 void    lldpd_ifh_vlan(struct lldpd *, struct ifaddrs *);
+#endif
 void    lldpd_ifh_mgmt(struct lldpd *, struct ifaddrs *);
 
 /* dmi.c */