summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-06-07 16:35:07 +0200
committerThomas Haller <thaller@redhat.com>2020-06-11 16:51:49 +0200
commit4aa0b9180afdcb0be6bc56863e842f392d228d97 (patch)
tree7992e8146d930f17965f02392f0bc3c0dac01c71
parent94ee6f4fe1b17c4f7cec96006402e2474f7178ad (diff)
downloadNetworkManager-4aa0b9180afdcb0be6bc56863e842f392d228d97.tar.gz
lldp: add LLDP attributes to GVariant builder without intermediate parsing (1)
The intermediate parsing step serves very little purpose. The only use is to ensure that we always add the keys in a stable order, but we can easily ensure that otherwise.
-rw-r--r--src/devices/nm-lldp-listener.c39
1 files changed, 13 insertions, 26 deletions
diff --git a/src/devices/nm-lldp-listener.c b/src/devices/nm-lldp-listener.c
index d87f40a609..65f37c3130 100644
--- a/src/devices/nm-lldp-listener.c
+++ b/src/devices/nm-lldp-listener.c
@@ -34,10 +34,6 @@ typedef enum {
typedef enum {
/* the order of the enum values determines the order of the fields in
* the variant. */
- LLDP_ATTR_ID_PORT_DESCRIPTION,
- LLDP_ATTR_ID_SYSTEM_NAME,
- LLDP_ATTR_ID_SYSTEM_DESCRIPTION,
- LLDP_ATTR_ID_SYSTEM_CAPABILITIES,
LLDP_ATTR_ID_MANAGEMENT_ADDRESSES,
LLDP_ATTR_ID_IEEE_802_1_PVID,
LLDP_ATTR_ID_IEEE_802_1_PPVID,
@@ -169,10 +165,6 @@ static const char *
_lldp_attr_id_to_name (LldpAttrId attr_id)
{
static const char *const names[_LLDP_ATTR_ID_COUNT] = {
- [LLDP_ATTR_ID_PORT_DESCRIPTION] = NM_LLDP_ATTR_PORT_DESCRIPTION,
- [LLDP_ATTR_ID_SYSTEM_NAME] = NM_LLDP_ATTR_SYSTEM_NAME,
- [LLDP_ATTR_ID_SYSTEM_DESCRIPTION] = NM_LLDP_ATTR_SYSTEM_DESCRIPTION,
- [LLDP_ATTR_ID_SYSTEM_CAPABILITIES] = NM_LLDP_ATTR_SYSTEM_CAPABILITIES,
[LLDP_ATTR_ID_MANAGEMENT_ADDRESSES] = NM_LLDP_ATTR_MANAGEMENT_ADDRESSES,
[LLDP_ATTR_ID_IEEE_802_1_PVID] = NM_LLDP_ATTR_IEEE_802_1_PVID,
[LLDP_ATTR_ID_IEEE_802_1_PPVID] = NM_LLDP_ATTR_IEEE_802_1_PPVID,
@@ -197,10 +189,6 @@ static LldpAttrType
_lldp_attr_id_to_type (LldpAttrId attr_id)
{
static const LldpAttrType types[_LLDP_ATTR_ID_COUNT] = {
- [LLDP_ATTR_ID_PORT_DESCRIPTION] = LLDP_ATTR_TYPE_STRING,
- [LLDP_ATTR_ID_SYSTEM_NAME] = LLDP_ATTR_TYPE_STRING,
- [LLDP_ATTR_ID_SYSTEM_DESCRIPTION] = LLDP_ATTR_TYPE_STRING,
- [LLDP_ATTR_ID_SYSTEM_CAPABILITIES] = LLDP_ATTR_TYPE_UINT32,
[LLDP_ATTR_ID_MANAGEMENT_ADDRESSES] = LLDP_ATTR_TYPE_ARRAY_OF_VARIANTS,
[LLDP_ATTR_ID_IEEE_802_1_PVID] = LLDP_ATTR_TYPE_UINT32,
[LLDP_ATTR_ID_IEEE_802_1_PPVID] = LLDP_ATTR_TYPE_UINT32,
@@ -555,24 +543,10 @@ static void
_lldp_attrs_parse (LldpAttrs *attrs,
sd_lldp_neighbor *neighbor_sd)
{
- const char *str;
- uint16_t data16;
uint8_t *data8;
gsize len;
int r;
- if (sd_lldp_neighbor_get_port_description (neighbor_sd, &str) == 0)
- _lldp_attrs_set_str (attrs, LLDP_ATTR_ID_PORT_DESCRIPTION, str);
-
- if (sd_lldp_neighbor_get_system_name (neighbor_sd, &str) == 0)
- _lldp_attrs_set_str (attrs, LLDP_ATTR_ID_SYSTEM_NAME, str);
-
- if (sd_lldp_neighbor_get_system_description (neighbor_sd, &str) == 0)
- _lldp_attrs_set_str (attrs, LLDP_ATTR_ID_SYSTEM_DESCRIPTION, str);
-
- if (sd_lldp_neighbor_get_system_capabilities (neighbor_sd, &data16) == 0)
- _lldp_attrs_set_uint32 (attrs, LLDP_ATTR_ID_SYSTEM_CAPABILITIES, data16);
-
r = sd_lldp_neighbor_tlv_rewind (neighbor_sd);
if (r < 0) {
nm_assert_not_reached ();
@@ -838,6 +812,7 @@ lldp_neighbor_to_variant (LldpNeighbor *neigh)
const guint8 *raw_data;
gsize raw_len;
LldpAttrs attrs;
+ uint16_t u16;
if (neigh->variant)
return neigh->variant;
@@ -866,6 +841,18 @@ lldp_neighbor_to_variant (LldpNeighbor *neigh)
if (str)
nm_g_variant_builder_add_sv_str (&builder, NM_LLDP_ATTR_DESTINATION, str);
+ if (sd_lldp_neighbor_get_port_description (neigh->neighbor_sd, &str) == 0)
+ nm_g_variant_builder_add_sv_str (&builder, NM_LLDP_ATTR_PORT_DESCRIPTION, str);
+
+ if (sd_lldp_neighbor_get_system_name (neigh->neighbor_sd, &str) == 0)
+ nm_g_variant_builder_add_sv_str (&builder, NM_LLDP_ATTR_SYSTEM_NAME, str);
+
+ if (sd_lldp_neighbor_get_system_description (neigh->neighbor_sd, &str) == 0)
+ nm_g_variant_builder_add_sv_str (&builder, NM_LLDP_ATTR_SYSTEM_DESCRIPTION, str);
+
+ if (sd_lldp_neighbor_get_system_capabilities (neigh->neighbor_sd, &u16) == 0)
+ nm_g_variant_builder_add_sv_uint32 (&builder, NM_LLDP_ATTR_SYSTEM_CAPABILITIES, u16);
+
attrs = (LldpAttrs) { };
_lldp_attrs_parse (&attrs, neigh->neighbor_sd);