]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
Move Dot3 MAC/Phy stuff into a separate structure.
authorVincent Bernat <bernat@luffy.cx>
Sat, 8 May 2010 14:59:06 +0000 (16:59 +0200)
committerVincent Bernat <bernat@luffy.cx>
Tue, 26 Apr 2011 05:48:15 +0000 (07:48 +0200)
src/agent.c
src/display.c
src/interfaces.c
src/lldp.c
src/lldpd.h
tests/check_lldp.c

index 17c16d723f80ec0641582e89a4b8a2c83cf422ab..5cfd11f4cccc2bce9c9ac3249291ac7c0d236251 100644 (file)
@@ -1061,16 +1061,16 @@ agent_h_local_port(struct variable *vp, oid *name, size_t *length,
                return (u_char *)hardware->h_lport.p_descr;
 #ifdef ENABLE_DOT3
         case LLDP_SNMP_LOCAL_DOT3_AUTONEG_SUPPORT:
-                long_ret = 2 - hardware->h_lport.p_autoneg_support;
+                long_ret = 2 - hardware->h_lport.p_macphy.autoneg_support;
                 return (u_char *)&long_ret;
         case LLDP_SNMP_LOCAL_DOT3_AUTONEG_ENABLED:
-                long_ret = 2 - hardware->h_lport.p_autoneg_enabled;
+                long_ret = 2 - hardware->h_lport.p_macphy.autoneg_enabled;
                 return (u_char *)&long_ret;
         case LLDP_SNMP_LOCAL_DOT3_AUTONEG_ADVERTISED:
                 *var_len = 2;
-                return (u_char *)&hardware->h_lport.p_autoneg_advertised;
+                return (u_char *)&hardware->h_lport.p_macphy.autoneg_advertised;
         case LLDP_SNMP_LOCAL_DOT3_AUTONEG_MAU:
-                long_ret = hardware->h_lport.p_mau_type;
+                long_ret = hardware->h_lport.p_macphy.mau_type;
                 return (u_char *)&long_ret;
         case LLDP_SNMP_LOCAL_DOT3_AGG_STATUS:
                 bit = swap_bits((hardware->h_lport.p_aggregid > 0) ? 3 : 0);
@@ -1180,16 +1180,16 @@ agent_h_remote_port(struct variable *vp, oid *name, size_t *length,
                return (u_char *)&bit;
 #ifdef ENABLE_DOT3
         case LLDP_SNMP_REMOTE_DOT3_AUTONEG_SUPPORT:
-                long_ret = 2 - port->p_autoneg_support;
+                long_ret = 2 - port->p_macphy.autoneg_support;
                 return (u_char *)&long_ret;
         case LLDP_SNMP_REMOTE_DOT3_AUTONEG_ENABLED:
-                long_ret = 2 - port->p_autoneg_enabled;
+                long_ret = 2 - port->p_macphy.autoneg_enabled;
                 return (u_char *)&long_ret;
         case LLDP_SNMP_REMOTE_DOT3_AUTONEG_ADVERTISED:
                 *var_len = 2;
-                return (u_char *)&port->p_autoneg_advertised;
+                return (u_char *)&port->p_macphy.autoneg_advertised;
         case LLDP_SNMP_REMOTE_DOT3_AUTONEG_MAU:
-                long_ret = port->p_mau_type;
+                long_ret = port->p_macphy.mau_type;
                 return (u_char *)&long_ret;
         case LLDP_SNMP_REMOTE_DOT3_AGG_STATUS:
                 bit = swap_bits((port->p_aggregid > 0) ? 3 : 0);
index 5a7fbbf23b94b5180fe0baa0204acc7603ca7b51..0010fee148dcc022f06f5d2ff988aa730f43f1e2 100644 (file)
@@ -791,14 +791,14 @@ display_chassis(struct writer * w, struct lldpd_chassis *chassis)
 static void
 display_autoneg(struct writer * w, struct lldpd_port *port, int bithd, int bitfd, char *desc)
 {
-       if (!((port->p_autoneg_advertised & bithd) ||
-               (port->p_autoneg_advertised & bitfd)))
+       if (!((port->p_macphy.autoneg_advertised & bithd) ||
+               (port->p_macphy.autoneg_advertised & bitfd)))
                return;
 
        tag_start(w, "advertised", "Adv");
        tag_attr(w, "type", "", desc);
-       tag_attr(w, "hd", "HD", (port->p_autoneg_advertised & bithd)?"yes":"no");
-       tag_attr(w, "fd", "FD", (port->p_autoneg_advertised)?"yes":"no");
+       tag_attr(w, "hd", "HD", (port->p_macphy.autoneg_advertised & bithd)?"yes":"no");
+       tag_attr(w, "fd", "FD", (port->p_macphy.autoneg_advertised)?"yes":"no");
        tag_end (w);
 }
 #endif
@@ -852,13 +852,15 @@ display_port(struct writer * w, struct lldpd_port *port)
                tag_datatag(w, "aggregation", " Port is aggregated. PortAggregID",
                            u2str(port->p_aggregid));
 
-       if (port->p_autoneg_support || port->p_autoneg_enabled ||
-           port->p_mau_type) {
+       if (port->p_macphy.autoneg_support || port->p_macphy.autoneg_enabled ||
+           port->p_macphy.mau_type) {
                tag_start(w, "auto-negotiation", "PMD autoneg");
-               tag_attr (w, "supported", "supported", port->p_autoneg_support?"yes":"no");
-               tag_attr (w, "enabled", "enabled", port->p_autoneg_enabled?"yes":"no");
+               tag_attr (w, "supported", "supported",
+                   port->p_macphy.autoneg_support?"yes":"no");
+               tag_attr (w, "enabled", "enabled",
+                   port->p_macphy.autoneg_enabled?"yes":"no");
 
-               if (port->p_autoneg_enabled) {
+               if (port->p_macphy.autoneg_enabled) {
                        display_autoneg(w, port, LLDP_DOT3_LINK_AUTONEG_10BASE_T,
                            LLDP_DOT3_LINK_AUTONEG_10BASET_FD,
                            "10Base-T");
@@ -876,7 +878,7 @@ display_port(struct writer * w, struct lldpd_port *port)
                            "1000Base-T");
                }
                tag_datatag(w, "current", "MAU oper type",
-                       map_lookup(operational_mau_type_values, port->p_mau_type));
+                       map_lookup(operational_mau_type_values, port->p_macphy.mau_type));
                tag_end(w);
        }
 #endif
index 30cc185d9d8fe28e12d46c66743754ebcb6ef64d..eded64daa9adfe45a7cfe0e4e9d795cad008c8e8 100644 (file)
@@ -527,45 +527,45 @@ iface_macphy(struct lldpd_hardware *hardware)
                {0,0}};
 
        if (priv_ethtool(hardware->h_ifname, &ethc) == 0) {
-               port->p_autoneg_support = (ethc.supported & SUPPORTED_Autoneg) ? 1 : 0;
-               port->p_autoneg_enabled = (ethc.autoneg == AUTONEG_DISABLE) ? 0 : 1;
+               port->p_macphy.autoneg_support = (ethc.supported & SUPPORTED_Autoneg) ? 1 : 0;
+               port->p_macphy.autoneg_enabled = (ethc.autoneg == AUTONEG_DISABLE) ? 0 : 1;
                for (j=0; advertised_ethtool_to_rfc3636[j][0]; j++) {
                        if (ethc.advertising & advertised_ethtool_to_rfc3636[j][0])
-                               port->p_autoneg_advertised |= 
+                               port->p_macphy.autoneg_advertised |= 
                                    advertised_ethtool_to_rfc3636[j][1];
                }
                switch (ethc.speed) {
                case SPEED_10:
-                       port->p_mau_type = (ethc.duplex == DUPLEX_FULL) ? \
+                       port->p_macphy.mau_type = (ethc.duplex == DUPLEX_FULL) ? \
                            LLDP_DOT3_MAU_10BASETFD : LLDP_DOT3_MAU_10BASETHD;
-                       if (ethc.port == PORT_BNC) port->p_mau_type = LLDP_DOT3_MAU_10BASE2;
+                       if (ethc.port == PORT_BNC) port->p_macphy.mau_type = LLDP_DOT3_MAU_10BASE2;
                        if (ethc.port == PORT_FIBRE)
-                               port->p_mau_type = (ethc.duplex == DUPLEX_FULL) ? \
+                               port->p_macphy.mau_type = (ethc.duplex == DUPLEX_FULL) ? \
                                    LLDP_DOT3_MAU_10BASEFLDF : LLDP_DOT3_MAU_10BASEFLHD;
                        break;
                case SPEED_100:
-                       port->p_mau_type = (ethc.duplex == DUPLEX_FULL) ? \
+                       port->p_macphy.mau_type = (ethc.duplex == DUPLEX_FULL) ? \
                            LLDP_DOT3_MAU_100BASETXFD : LLDP_DOT3_MAU_100BASETXHD;
                        if (ethc.port == PORT_BNC)
-                               port->p_mau_type = (ethc.duplex == DUPLEX_FULL) ? \
+                               port->p_macphy.mau_type = (ethc.duplex == DUPLEX_FULL) ? \
                                    LLDP_DOT3_MAU_100BASET2DF : LLDP_DOT3_MAU_100BASET2HD;
                        if (ethc.port == PORT_FIBRE)
-                               port->p_mau_type = (ethc.duplex == DUPLEX_FULL) ? \
+                               port->p_macphy.mau_type = (ethc.duplex == DUPLEX_FULL) ? \
                                    LLDP_DOT3_MAU_100BASEFXFD : LLDP_DOT3_MAU_100BASEFXHD;
                        break;
                case SPEED_1000:
-                       port->p_mau_type = (ethc.duplex == DUPLEX_FULL) ? \
+                       port->p_macphy.mau_type = (ethc.duplex == DUPLEX_FULL) ? \
                            LLDP_DOT3_MAU_1000BASETFD : LLDP_DOT3_MAU_1000BASETHD;
                        if (ethc.port == PORT_FIBRE)
-                               port->p_mau_type = (ethc.duplex == DUPLEX_FULL) ? \
+                               port->p_macphy.mau_type = (ethc.duplex == DUPLEX_FULL) ? \
                                    LLDP_DOT3_MAU_1000BASEXFD : LLDP_DOT3_MAU_1000BASEXHD;
                        break;
                case SPEED_10000:
-                       port->p_mau_type = (ethc.port == PORT_FIBRE) ?  \
+                       port->p_macphy.mau_type = (ethc.port == PORT_FIBRE) ?   \
                                        LLDP_DOT3_MAU_10GIGBASEX : LLDP_DOT3_MAU_10GIGBASER;
                        break;
                }
-               if (ethc.port == PORT_AUI) port->p_mau_type = LLDP_DOT3_MAU_AUI;
+               if (ethc.port == PORT_AUI) port->p_macphy.mau_type = LLDP_DOT3_MAU_AUI;
        }
 #endif
 }
index 35633008e1542e2a796dcadbf16d47d52bd446a2..09143f2c0d9d32782a068986b7c13ba93ac9031a 100644 (file)
@@ -183,10 +183,10 @@ lldp_send(struct lldpd *global,
              POKE_START_LLDP_TLV(LLDP_TLV_ORG) &&
              POKE_BYTES(dot3, sizeof(dot3)) &&
              POKE_UINT8(LLDP_TLV_DOT3_MAC) &&
-             POKE_UINT8(port->p_autoneg_support |
-                        (port->p_autoneg_enabled << 1)) &&
-             POKE_UINT16(port->p_autoneg_advertised) &&
-             POKE_UINT16(port->p_mau_type) &&
+             POKE_UINT8(port->p_macphy.autoneg_support |
+                        (port->p_macphy.autoneg_enabled << 1)) &&
+             POKE_UINT16(port->p_macphy.autoneg_advertised) &&
+             POKE_UINT16(port->p_macphy.mau_type) &&
              POKE_END_LLDP_TLV))
                goto toobig;
 
@@ -565,14 +565,14 @@ lldp_decode(struct lldpd *cfg, char *frame, int s,
                                switch (tlv_subtype) {
                                case LLDP_TLV_DOT3_MAC:
                                        CHECK_TLV_SIZE(9, "MAC/PHY");
-                                       port->p_autoneg_support = PEEK_UINT8;
-                                       port->p_autoneg_enabled =
-                                           port->p_autoneg_support && 0x2;
-                                       port->p_autoneg_support =
-                                           port->p_autoneg_support && 0x1;
-                                       port->p_autoneg_advertised =
+                                       port->p_macphy.autoneg_support = PEEK_UINT8;
+                                       port->p_macphy.autoneg_enabled =
+                                           port->p_macphy.autoneg_support && 0x2;
+                                       port->p_macphy.autoneg_support =
+                                           port->p_macphy.autoneg_support && 0x1;
+                                       port->p_macphy.autoneg_advertised =
                                            PEEK_UINT16;
-                                       port->p_mau_type = PEEK_UINT16;
+                                       port->p_macphy.mau_type = PEEK_UINT16;
                                        break;
                                case LLDP_TLV_DOT3_LA:
                                        CHECK_TLV_SIZE(9, "Link aggregation");
index db1b4de9fc678b551f345e36b3a690b1b2c50e20..89b0d3d2c78312d0c8759a0723fa5b1b5ba4d1cc 100644 (file)
@@ -102,6 +102,16 @@ struct lldpd_med_power {
 };
 #endif
 
+#ifdef ENABLE_DOT3
+#define STRUCT_LLDPD_DOT3_MACPHY "(bbww)"
+struct lldpd_dot3_macphy {
+       u_int8_t                 autoneg_support;
+       u_int8_t                 autoneg_enabled;
+       u_int16_t                autoneg_advertised;
+       u_int16_t                mau_type;
+};
+#endif
+
 struct lldpd_chassis {
        TAILQ_ENTRY(lldpd_chassis) c_entries;
        u_int16_t                c_refcount; /* Reference count by ports */
@@ -155,13 +165,10 @@ struct lldpd_port {
        u_int8_t                 p_hidden_out:2; /* Considered as hidden for emission */
 
 #ifdef ENABLE_DOT3
-#define STRUCT_LLDPD_PORT_DOT3 "lbbww"
+#define STRUCT_LLDPD_PORT_DOT3 "l" STRUCT_LLDPD_DOT3_MACPHY
        /* Dot3 stuff */
        u_int32_t                p_aggregid;
-       u_int8_t                 p_autoneg_support;
-       u_int8_t                 p_autoneg_enabled;
-       u_int16_t                p_autoneg_advertised;
-       u_int16_t                p_mau_type;
+       struct lldpd_dot3_macphy p_macphy;
 #else
 #define STRUCT_LLDPD_PORT_DOT3 ""
 #endif
index 8cec23e1bda39bdcabf3d9e2d357f008534378e8..9f2ada6d473cfee1dfa568cfe61bc4eeb9d5a347 100644 (file)
@@ -684,12 +684,12 @@ Link Layer Discovery Protocol
        hardware.h_lport.p_descr = "Fake port description";
        hardware.h_lport.p_mfs = 1516;
        hardware.h_lport.p_aggregid = 5;
-       hardware.h_lport.p_autoneg_support = 1;
-       hardware.h_lport.p_autoneg_enabled = 1;
-       hardware.h_lport.p_autoneg_advertised = LLDP_DOT3_LINK_AUTONEG_10BASE_T |
+       hardware.h_lport.p_macphy.autoneg_support = 1;
+       hardware.h_lport.p_macphy.autoneg_enabled = 1;
+       hardware.h_lport.p_macphy.autoneg_advertised = LLDP_DOT3_LINK_AUTONEG_10BASE_T |
                LLDP_DOT3_LINK_AUTONEG_10BASET_FD | LLDP_DOT3_LINK_AUTONEG_100BASE_TX |
                LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD;
-       hardware.h_lport.p_mau_type = LLDP_DOT3_MAU_100BASETXFD;
+       hardware.h_lport.p_macphy.mau_type = LLDP_DOT3_MAU_100BASETXFD;
        chassis.c_id_subtype = LLDP_CHASSISID_SUBTYPE_LLADDR;
        chassis.c_id = macaddress;
        chassis.c_id_len = ETH_ALEN;
@@ -988,16 +988,16 @@ Link Layer Discovery Protocol
        ck_assert_int_eq(nchassis->c_mgmt_if, 3);
 #ifdef ENABLE_DOT3
        ck_assert_int_eq(nport->p_aggregid, 0);
-       ck_assert_int_eq(nport->p_autoneg_enabled, 1);
-       ck_assert_int_eq(nport->p_autoneg_support, 1);
-       ck_assert_int_eq(nport->p_autoneg_advertised,
+       ck_assert_int_eq(nport->p_macphy.autoneg_enabled, 1);
+       ck_assert_int_eq(nport->p_macphy.autoneg_support, 1);
+       ck_assert_int_eq(nport->p_macphy.autoneg_advertised,
            LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD |
            LLDP_DOT3_LINK_AUTONEG_1000BASE_T |
            LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD |
            LLDP_DOT3_LINK_AUTONEG_100BASE_TX |
            LLDP_DOT3_LINK_AUTONEG_10BASET_FD |
            LLDP_DOT3_LINK_AUTONEG_10BASE_T);
-       ck_assert_int_eq(nport->p_mau_type,
+       ck_assert_int_eq(nport->p_macphy.mau_type,
            LLDP_DOT3_MAU_100BASETXFD);
        ck_assert_int_eq(nport->p_mfs, 1500);
 #endif
@@ -1394,14 +1394,14 @@ Link Layer Discovery Protocol
            (u_int32_t)inet_addr("15.255.122.148"));
        ck_assert_int_eq(nchassis->c_mgmt_if, 0);
 #ifdef ENABLE_DOT3
-       ck_assert_int_eq(nport->p_autoneg_enabled, 1);
-       ck_assert_int_eq(nport->p_autoneg_support, 1);
-       ck_assert_int_eq(nport->p_autoneg_advertised,
+       ck_assert_int_eq(nport->p_macphy.autoneg_enabled, 1);
+       ck_assert_int_eq(nport->p_macphy.autoneg_support, 1);
+       ck_assert_int_eq(nport->p_macphy.autoneg_advertised,
            LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD |
            LLDP_DOT3_LINK_AUTONEG_100BASE_TX |
            LLDP_DOT3_LINK_AUTONEG_10BASET_FD |
            LLDP_DOT3_LINK_AUTONEG_10BASE_T);
-       ck_assert_int_eq(nport->p_mau_type,
+       ck_assert_int_eq(nport->p_macphy.mau_type,
            LLDP_DOT3_MAU_100BASETXFD);
 #endif
        ck_assert_int_eq(nchassis->c_med_cap_available,