From: Vincent Bernat Date: Sat, 8 May 2010 14:59:06 +0000 (+0200) Subject: Move Dot3 MAC/Phy stuff into a separate structure. X-Git-Tag: 0.5.4~14 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3fd015c03942d2c96400b88e7ae676cc56a0d9e0;p=thirdparty%2Flldpd.git Move Dot3 MAC/Phy stuff into a separate structure. --- diff --git a/src/agent.c b/src/agent.c index 17c16d72..5cfd11f4 100644 --- a/src/agent.c +++ b/src/agent.c @@ -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); diff --git a/src/display.c b/src/display.c index 5a7fbbf2..0010fee1 100644 --- a/src/display.c +++ b/src/display.c @@ -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 diff --git a/src/interfaces.c b/src/interfaces.c index 30cc185d..eded64da 100644 --- a/src/interfaces.c +++ b/src/interfaces.c @@ -527,45 +527,45 @@ iface_macphy(struct lldpd_hardware *hardware) {0,0}}; if (priv_ethtool(hardware->h_ifname, ðc) == 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 } diff --git a/src/lldp.c b/src/lldp.c index 35633008..09143f2c 100644 --- a/src/lldp.c +++ b/src/lldp.c @@ -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"); diff --git a/src/lldpd.h b/src/lldpd.h index db1b4de9..89b0d3d2 100644 --- a/src/lldpd.h +++ b/src/lldpd.h @@ -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 diff --git a/tests/check_lldp.c b/tests/check_lldp.c index 8cec23e1..9f2ada6d 100644 --- a/tests/check_lldp.c +++ b/tests/check_lldp.c @@ -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,