From 0597109ddf62ba26446cb81418fd6e2e0d90c5f0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 15 Jun 2025 10:20:12 +0900 Subject: [PATCH] sd-lldp-tx: append capabilities before MUD URL No functional change, but let's append vendor specific informations after others to sort the TLVs with their type. --- src/libsystemd-network/sd-lldp-tx.c | 22 +++++++++++----------- src/systemd/sd-lldp-tx.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libsystemd-network/sd-lldp-tx.c b/src/libsystemd-network/sd-lldp-tx.c index 3f73d881d4d..92b8ac51612 100644 --- a/src/libsystemd-network/sd-lldp-tx.c +++ b/src/libsystemd-network/sd-lldp-tx.c @@ -238,10 +238,10 @@ static size_t lldp_tx_calculate_maximum_packet_size(sd_lldp_tx *lldp_tx, const c 2 + strlen_ptr(hostname) + /* System description */ 2 + strlen_ptr(pretty_hostname) + - /* MUD URL */ - 2 + sizeof(SD_LLDP_OUI_IANA_MUD) + strlen_ptr(lldp_tx->mud_url) + /* System Capabilities */ 2 + 4 + + /* MUD URL */ + 2 + sizeof(SD_LLDP_OUI_IANA_MUD) + strlen_ptr(lldp_tx->mud_url) + /* End */ 2; } @@ -428,6 +428,15 @@ static int lldp_tx_create_packet(sd_lldp_tx *lldp_tx, size_t *ret_packet_size, u if (r < 0) return r; + r = packet_append_tlv_header(packet, packet_size, &offset, SD_LLDP_TYPE_SYSTEM_CAPABILITIES, 4); + if (r < 0) + return r; + + unaligned_write_be16(packet + offset, lldp_tx->supported_capabilities); + offset += 2; + unaligned_write_be16(packet + offset, lldp_tx->enabled_capabilities); + offset += 2; + /* See section 12 of RFC 8520. * +--------+--------+----------+---------+-------------- * |TLV Type| len | OUI |subtype | MUDString @@ -448,15 +457,6 @@ static int lldp_tx_create_packet(sd_lldp_tx *lldp_tx, size_t *ret_packet_size, u if (r < 0) return r; - r = packet_append_tlv_header(packet, packet_size, &offset, SD_LLDP_TYPE_SYSTEM_CAPABILITIES, 4); - if (r < 0) - return r; - - unaligned_write_be16(packet + offset, lldp_tx->supported_capabilities); - offset += 2; - unaligned_write_be16(packet + offset, lldp_tx->enabled_capabilities); - offset += 2; - r = packet_append_tlv_header(packet, packet_size, &offset, SD_LLDP_TYPE_END, 0); if (r < 0) return r; diff --git a/src/systemd/sd-lldp-tx.h b/src/systemd/sd-lldp-tx.h index 107292027da..520f5a20831 100644 --- a/src/systemd/sd-lldp-tx.h +++ b/src/systemd/sd-lldp-tx.h @@ -56,8 +56,8 @@ int sd_lldp_tx_set_hwaddr(sd_lldp_tx *lldp_tx, const struct ether_addr *hwaddr); int sd_lldp_tx_set_port_description(sd_lldp_tx *lldp_tx, const char *port_description); int sd_lldp_tx_set_hostname(sd_lldp_tx *lldp_tx, const char *hostname); int sd_lldp_tx_set_pretty_hostname(sd_lldp_tx *lldp_tx, const char *pretty_hostname); -int sd_lldp_tx_set_mud_url(sd_lldp_tx *lldp_tx, const char *mud_url); int sd_lldp_tx_set_capabilities(sd_lldp_tx *lldp_tx, uint16_t supported, uint16_t enabled); +int sd_lldp_tx_set_mud_url(sd_lldp_tx *lldp_tx, const char *mud_url); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_lldp_tx, sd_lldp_tx_unref); -- 2.47.3