]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
interfaces: move "mangle" function for bond slaves
authorVincent Bernat <bernat@luffy.cx>
Sun, 11 Aug 2013 19:42:12 +0000 (21:42 +0200)
committerVincent Bernat <bernat@luffy.cx>
Sun, 11 Aug 2013 19:42:12 +0000 (21:42 +0200)
This will allow it to be used by other OS.

src/daemon/interfaces-linux.c
src/daemon/interfaces.c
src/daemon/lldpd.h

index 2f362d22983017eb88b335ad0c011992abd83a80..804d5eed19f67a6fa99f034684e718894434565f 100644 (file)
@@ -465,38 +465,6 @@ iface_bond_init(struct lldpd *cfg, struct lldpd_hardware *hardware)
        return 0;
 }
 
-/**
- * Mangle the MAC address to avoid duplicates.
- *
- * With bonds, we have duplicate MAC address on different physical
- * interfaces. We need to alter the source MAC address when we send on
- * an inactive slave. We try to set "local" bit to 1 first. If it is
- * already set to 1, use an unused MAC address instead.
- */
-static void
-iface_mangle_mac(struct lldpd *cfg, char *src_mac)
-{
-#define MAC_UL_ADMINISTERED_BIT_MASK 0x02
-       char arbitrary[] = { 0x00, 0x60, 0x08, 0x69, 0x97, 0xef};
-
-       switch (cfg->g_config.c_bond_slave_src_mac_type) {
-       case LLDP_BOND_SLAVE_SRC_MAC_TYPE_LOCALLY_ADMINISTERED:
-               if (*src_mac & MAC_UL_ADMINISTERED_BIT_MASK) {
-                       /* If locally administered bit already set,
-                        * use zero mac
-                        */
-                       memset(src_mac, 0, ETHER_ADDR_LEN);
-                       return;
-               }
-       case LLDP_BOND_SLAVE_SRC_MAC_TYPE_FIXED:
-               memcpy(src_mac, arbitrary, ETHER_ADDR_LEN);
-               return;
-       case LLDP_BOND_SLAVE_SRC_MAC_TYPE_ZERO:
-               memset(src_mac, 0, ETHER_ADDR_LEN);
-               return;
-       }
-}
-
 static int
 iface_bond_send(struct lldpd *cfg, struct lldpd_hardware *hardware,
     char *buffer, size_t size)
@@ -509,7 +477,7 @@ iface_bond_send(struct lldpd *cfg, struct lldpd_hardware *hardware,
                    hardware->h_ifname);
                return 0;
        }
-       iface_mangle_mac(cfg, buffer + ETHER_ADDR_LEN);
+       interfaces_helper_mangle_mac(cfg, buffer + ETHER_ADDR_LEN);
        return write(hardware->h_sendfd,
            buffer, size);
 }
index 3f80c12d94bcbc6e3f1336a70cc5ced530a10e9a..f1c5fa4316dd9832f6002bf7956cb211211b89e6 100644 (file)
@@ -556,3 +556,35 @@ interfaces_helper_physical(struct lldpd *cfg,
 #endif
        }
 }
+
+/**
+ * Mangle the MAC address to avoid duplicates.
+ *
+ * With bonds, we have duplicate MAC address on different physical
+ * interfaces. We need to alter the source MAC address when we send on
+ * an inactive slave. We try to set "local" bit to 1 first. If it is
+ * already set to 1, use an unused MAC address instead.
+ */
+void
+interfaces_helper_mangle_mac(struct lldpd *cfg, char *src_mac)
+{
+#define MAC_UL_ADMINISTERED_BIT_MASK 0x02
+       char arbitrary[] = { 0x00, 0x60, 0x08, 0x69, 0x97, 0xef};
+
+       switch (cfg->g_config.c_bond_slave_src_mac_type) {
+       case LLDP_BOND_SLAVE_SRC_MAC_TYPE_LOCALLY_ADMINISTERED:
+               if (*src_mac & MAC_UL_ADMINISTERED_BIT_MASK) {
+                       /* If locally administered bit already set,
+                        * use zero mac
+                        */
+                       memset(src_mac, 0, ETHER_ADDR_LEN);
+                       return;
+               }
+       case LLDP_BOND_SLAVE_SRC_MAC_TYPE_FIXED:
+               memcpy(src_mac, arbitrary, ETHER_ADDR_LEN);
+               return;
+       case LLDP_BOND_SLAVE_SRC_MAC_TYPE_ZERO:
+               memset(src_mac, 0, ETHER_ADDR_LEN);
+               return;
+       }
+}
index 58d86768ca24becf0edd026d0c4721b5a048a6d8..da8aea8ac2d4d09162d91088625f3d6f9c0e2d1d 100644 (file)
@@ -364,6 +364,7 @@ void interfaces_helper_mgmt(struct lldpd *,
 void interfaces_helper_vlan(struct lldpd *,
     struct interfaces_device_list *);
 #endif
+void interfaces_helper_mangle_mac(struct lldpd *, char *);
 
 void interfaces_setup_multicast(struct lldpd *, const char *, int);
 int interfaces_routing_enabled(struct lldpd *);