From: Yu Watanabe Date: Sun, 15 Jun 2025 01:35:18 +0000 (+0900) Subject: sd-lldp-tx: allow to emit VLAN ID X-Git-Tag: v258-rc1~296^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=898513783ee3b973514ba9dbf89f4a05fb450652;p=thirdparty%2Fsystemd.git sd-lldp-tx: allow to emit VLAN ID --- diff --git a/src/libsystemd-network/sd-lldp-tx.c b/src/libsystemd-network/sd-lldp-tx.c index 92b8ac51612..4c6f263f8d0 100644 --- a/src/libsystemd-network/sd-lldp-tx.c +++ b/src/libsystemd-network/sd-lldp-tx.c @@ -64,6 +64,7 @@ struct sd_lldp_tx { char *mud_url; uint16_t supported_capabilities; uint16_t enabled_capabilities; + uint16_t vlan_id; }; #define log_lldp_tx_errno(lldp_tx, error, fmt, ...) \ @@ -221,6 +222,13 @@ int sd_lldp_tx_set_mud_url(sd_lldp_tx *lldp_tx, const char *mud_url) { return free_and_strdup(&lldp_tx->mud_url, empty_to_null(mud_url)); } +int sd_lldp_tx_set_vlan_id(sd_lldp_tx *lldp_tx, uint16_t vlan_id) { + assert_return(lldp_tx, -EINVAL); + + lldp_tx->vlan_id = vlan_id; + return 0; +} + static size_t lldp_tx_calculate_maximum_packet_size(sd_lldp_tx *lldp_tx, const char *hostname, const char *pretty_hostname) { assert(lldp_tx); assert(lldp_tx->ifindex > 0); @@ -242,6 +250,8 @@ static size_t lldp_tx_calculate_maximum_packet_size(sd_lldp_tx *lldp_tx, const c 2 + 4 + /* MUD URL */ 2 + sizeof(SD_LLDP_OUI_IANA_MUD) + strlen_ptr(lldp_tx->mud_url) + + /* VLAN ID */ + 2 + sizeof(SD_LLDP_OUI_802_1_VLAN_ID) + sizeof(uint16_t) + /* End */ 2; } @@ -457,6 +467,19 @@ static int lldp_tx_create_packet(sd_lldp_tx *lldp_tx, size_t *ret_packet_size, u if (r < 0) return r; + /* VLAN ID */ + if (lldp_tx->vlan_id > 0) { + r = packet_append_tlv_header(packet, packet_size, &offset, SD_LLDP_TYPE_PRIVATE, + sizeof(SD_LLDP_OUI_802_1_VLAN_ID) + sizeof(uint16_t)); + if (r < 0) + return r; + + memcpy_safe(packet + offset, SD_LLDP_OUI_802_1_VLAN_ID, sizeof(SD_LLDP_OUI_802_1_VLAN_ID)); + offset += sizeof(SD_LLDP_OUI_802_1_VLAN_ID); + unaligned_write_be16(packet + offset, lldp_tx->vlan_id); + 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 520f5a20831..4d92ca5ebed 100644 --- a/src/systemd/sd-lldp-tx.h +++ b/src/systemd/sd-lldp-tx.h @@ -58,6 +58,7 @@ 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_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); +int sd_lldp_tx_set_vlan_id(sd_lldp_tx *lldp_tx, uint16_t vlan_id); _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_lldp_tx, sd_lldp_tx_unref);