lldp: merge branch 'th/lldp-raw'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/529
This commit is contained in:
Thomas Haller 2020-06-11 18:23:46 +02:00
commit e8aaa95354
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
8 changed files with 675 additions and 639 deletions

View file

@ -860,6 +860,7 @@ typedef enum /*< flags >*/ {
#undef NM_AVAILABLE_IN_1_8
#endif
#define NM_LLDP_ATTR_RAW "raw"
#define NM_LLDP_ATTR_DESTINATION "destination"
#define NM_LLDP_ATTR_CHASSIS_ID_TYPE "chassis-id-type"
#define NM_LLDP_ATTR_CHASSIS_ID "chassis-id"

View file

@ -13,6 +13,7 @@
#include <sys/syscall.h>
#include <glib-unix.h>
#include <net/if.h>
#include <net/ethernet.h>
#include "nm-errno.h"
#include "nm-str-buf.h"
@ -88,6 +89,11 @@ nm_ip_addr_set_from_untrusted (int addr_family,
/*****************************************************************************/
G_STATIC_ASSERT (ETH_ALEN == sizeof (struct ether_addr));
G_STATIC_ASSERT (ETH_ALEN == 6);
/*****************************************************************************/
gsize
nm_utils_get_next_realloc_size (gboolean true_realloc, gsize requested)
{
@ -2699,6 +2705,17 @@ nm_utils_buf_utf8safe_escape_bytes (GBytes *bytes, NMUtilsStrUtf8SafeFlags flags
return nm_utils_buf_utf8safe_escape (p, l, flags, to_free);
}
char *
nm_utils_buf_utf8safe_escape_cp (gconstpointer buf, gssize buflen, NMUtilsStrUtf8SafeFlags flags)
{
const char *s_const;
char *s;
s_const = nm_utils_buf_utf8safe_escape (buf, buflen, flags, &s);
nm_assert (!s || s == s_const);
return s ?: g_strdup (s_const);
}
/*****************************************************************************/
const char *

View file

@ -178,6 +178,24 @@ nm_ip4_addr_is_localhost (in_addr_t addr4)
/*****************************************************************************/
struct ether_addr;
static inline int
nm_utils_ether_addr_cmp (const struct ether_addr *a1, const struct ether_addr *a2)
{
nm_assert (a1);
nm_assert (a2);
return memcmp (a1, a2, 6 /*ETH_ALEN*/);
}
static inline gboolean
nm_utils_ether_addr_equal (const struct ether_addr *a1, const struct ether_addr *a2)
{
return nm_utils_ether_addr_cmp (a1, a2) == 0;
}
/*****************************************************************************/
#define NM_UTILS_INET_ADDRSTRLEN INET6_ADDRSTRLEN
static inline const char *
@ -1208,6 +1226,7 @@ typedef enum {
} NMUtilsStrUtf8SafeFlags;
const char *nm_utils_buf_utf8safe_escape (gconstpointer buf, gssize buflen, NMUtilsStrUtf8SafeFlags flags, char **to_free);
char *nm_utils_buf_utf8safe_escape_cp (gconstpointer buf, gssize buflen, NMUtilsStrUtf8SafeFlags flags);
const char *nm_utils_buf_utf8safe_escape_bytes (GBytes *bytes, NMUtilsStrUtf8SafeFlags flags, char **to_free);
gconstpointer nm_utils_buf_utf8safe_unescape (const char *str, NMUtilsStrUtf8SafeFlags flags, gsize *out_len, gpointer *to_free);
@ -1262,6 +1281,30 @@ nm_g_variant_is_of_type (GVariant *value,
&& g_variant_is_of_type (value, type);
}
static inline void
nm_g_variant_builder_add_sv (GVariantBuilder *builder, const char *key, GVariant *val)
{
g_variant_builder_add (builder, "{sv}", key, val);
}
static inline void
nm_g_variant_builder_add_sv_bytearray (GVariantBuilder *builder, const char *key, const guint8 *arr, gsize len)
{
g_variant_builder_add (builder, "{sv}", key, g_variant_new_fixed_array (G_VARIANT_TYPE_BYTE, arr, len, 1));
}
static inline void
nm_g_variant_builder_add_sv_uint32 (GVariantBuilder *builder, const char *key, guint32 val)
{
nm_g_variant_builder_add_sv (builder, key, g_variant_new_uint32 (val));
}
static inline void
nm_g_variant_builder_add_sv_str (GVariantBuilder *builder, const char *key, const char *str)
{
nm_g_variant_builder_add_sv (builder, key, g_variant_new_string (str));
}
static inline void
nm_g_source_destroy_and_unref (GSource *source)
{

View file

@ -2326,6 +2326,43 @@ _nmtst_variant_new_vardict (int dummy, ...)
g_assert_cmpint (_l, ==, strlen (_str)); \
} G_STMT_END
#ifdef __NM_SHARED_UTILS_H__
#define _nmtst_assert_variant_bytestring_cmp_str(_ptr, _ptr2, _len) \
G_STMT_START { \
if (memcmp (_ptr2, _ptr, _len) != 0) { \
gs_free char *_x1 = NULL; \
gs_free char *_x2 = NULL; \
const char *_xx1; \
const char *_xx2; \
\
_xx1 = nm_utils_buf_utf8safe_escape (_ptr, _len, NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, &_x1); \
_xx2 = nm_utils_buf_utf8safe_escape (_ptr2, _len, NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, &_x2); \
g_assert_cmpstr (_xx1, ==, _xx2); \
g_assert_not_reached (); \
} \
} G_STMT_END
#else
#define _nmtst_assert_variant_bytestring_cmp_str(_ptr, _ptr2, _len) G_STMT_START { } G_STMT_END
#endif
#define nmtst_assert_variant_bytestring(variant, ptr, len) \
G_STMT_START { \
GVariant *_variant = (variant); \
gconstpointer _ptr = (ptr); \
gconstpointer _ptr2; \
gsize _len = (len); \
gsize _len2; \
\
nmtst_assert_variant_is_of_type (_variant, G_VARIANT_TYPE_BYTESTRING); \
_ptr2 = g_variant_get_fixed_array (_variant, &_len2, 1); \
g_assert_cmpint (_len2, ==, _len); \
if ( _len != 0 \
&& _ptr) { \
_nmtst_assert_variant_bytestring_cmp_str(_ptr, _ptr2, _len); \
g_assert_cmpmem (_ptr2, _len2, _ptr, _len); \
} \
} G_STMT_END
typedef enum {
NMTST_VARIANT_EDITOR_CONNECTION,
NMTST_VARIANT_EDITOR_SETTING,

View file

@ -3845,7 +3845,8 @@ nm_device_update_dynamic_ip_setup (NMDevice *self)
/* FIXME: todo */
}
if (priv->lldp_listener && nm_lldp_listener_is_running (priv->lldp_listener)) {
if ( priv->lldp_listener
&& nm_lldp_listener_is_running (priv->lldp_listener)) {
nm_lldp_listener_stop (priv->lldp_listener);
if (!nm_lldp_listener_start (priv->lldp_listener, nm_device_get_ifindex (self), &error)) {
_LOGD (LOGD_DEVICE, "LLDP listener %p could not be restarted: %s",
@ -7157,7 +7158,8 @@ lldp_init (NMDevice *self, gboolean restart)
gs_free_error GError *error = NULL;
if (priv->lldp_listener) {
if (restart && nm_lldp_listener_is_running (priv->lldp_listener))
if ( restart
&& nm_lldp_listener_is_running (priv->lldp_listener))
nm_lldp_listener_stop (priv->lldp_listener);
} else {
priv->lldp_listener = nm_lldp_listener_new ();

File diff suppressed because it is too large Load diff

View file

@ -25,4 +25,7 @@ gboolean nm_lldp_listener_is_running (NMLldpListener *self);
GVariant *nm_lldp_listener_get_neighbors (NMLldpListener *self);
GVariant *nmtst_lldp_parse_from_raw (const guint8 *raw_data,
gsize raw_len);
#endif /* __NM_LLDP_LISTENER__ */

View file

@ -77,10 +77,12 @@ typedef struct {
typedef struct {
gsize frame_len;
const uint8_t *frame;
const char *as_variant;
} TestRecvFrame;
#define TEST_RECV_FRAME_DEFINE(name, ...) \
#define TEST_RECV_FRAME_DEFINE(name, _as_variant, ...) \
static const guint8 _##name##_v[] = { __VA_ARGS__ }; \
static const TestRecvFrame name = { \
.as_variant = _as_variant, \
.frame_len = sizeof (_##name##_v), \
.frame = _##name##_v, \
}
@ -102,6 +104,7 @@ typedef struct {
#define TEST_IFNAME "nm-tap-test0"
TEST_RECV_FRAME_DEFINE (_test_recv_data0_frame0,
"{'raw': <[byte 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x88, 0xcc, 0x02, 0x07, 0x04, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x04, 0x04, 0x05, 0x31, 0x2f, 0x33, 0x06, 0x02, 0x00, 0x78, 0x08, 0x04, 0x50, 0x6f, 0x72, 0x74, 0x0a, 0x03, 0x53, 0x59, 0x53, 0x0c, 0x04, 0x66, 0x6f, 0x6f, 0x00, 0x00, 0x00]>, 'chassis-id-type': <uint32 4>, 'chassis-id': <'00:01:02:03:04:05'>, 'port-id-type': <uint32 5>, 'port-id': <'1/3'>, 'destination': <'nearest-non-tpmr-bridge'>, 'port-description': <'Port'>, 'system-name': <'SYS'>, 'system-description': <'foo'>}",
/* Ethernet header */
0x01, 0x80, 0xc2, 0x00, 0x00, 0x03, /* Destination MAC */
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, /* Source MAC */
@ -119,7 +122,7 @@ TEST_RECV_FRAME_DEFINE (_test_recv_data0_frame0,
);
static void
_test_recv_data0_check (GMainLoop *loop, NMLldpListener *listener)
_test_recv_data0_check_do (GMainLoop *loop, NMLldpListener *listener, const TestRecvFrame *frame)
{
GVariant *neighbors, *attr;
gs_unref_variant GVariant *neighbor = NULL;
@ -132,7 +135,11 @@ _test_recv_data0_check (GMainLoop *loop, NMLldpListener *listener)
SD_LLDP_CHASSIS_SUBTYPE_MAC_ADDRESS, "00:01:02:03:04:05",
SD_LLDP_PORT_SUBTYPE_INTERFACE_NAME, "1/3");
g_assert (neighbor);
g_assert_cmpint (g_variant_n_children (neighbor), ==, 4 + 4);
g_assert_cmpint (g_variant_n_children (neighbor), ==, 1 + 4 + 4);
attr = g_variant_lookup_value (neighbor, NM_LLDP_ATTR_RAW, G_VARIANT_TYPE_BYTESTRING);
nmtst_assert_variant_bytestring (attr, frame->frame, frame->frame_len);
nm_clear_g_variant (&attr);
attr = g_variant_lookup_value (neighbor, NM_LLDP_ATTR_PORT_DESCRIPTION, G_VARIANT_TYPE_STRING);
nmtst_assert_variant_string (attr, "Port");
@ -151,13 +158,19 @@ _test_recv_data0_check (GMainLoop *loop, NMLldpListener *listener)
nm_clear_g_variant (&attr);
}
static void
_test_recv_data0_check (GMainLoop *loop, NMLldpListener *listener)
{
_test_recv_data0_check_do (loop, listener, &_test_recv_data0_frame0);
}
TEST_RECV_DATA_DEFINE (_test_recv_data0, 1, _test_recv_data0_check, &_test_recv_data0_frame0);
TEST_RECV_DATA_DEFINE (_test_recv_data0_twice, 1, _test_recv_data0_check, &_test_recv_data0_frame0, &_test_recv_data0_frame0);
TEST_RECV_FRAME_DEFINE (_test_recv_data1_frame0,
/* lldp.detailed.pcap from
* https://wiki.wireshark.org/SampleCaptures#Link_Layer_Discovery_Protocol_.28LLDP.29 */
"{'raw': <[byte 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e, 0x00, 0x01, 0x30, 0xf9, 0xad, 0xa0, 0x88, 0xcc, 0x02, 0x07, 0x04, 0x00, 0x01, 0x30, 0xf9, 0xad, 0xa0, 0x04, 0x04, 0x05, 0x31, 0x2f, 0x31, 0x06, 0x02, 0x00, 0x78, 0x08, 0x17, 0x53, 0x75, 0x6d, 0x6d, 0x69, 0x74, 0x33, 0x30, 0x30, 0x2d, 0x34, 0x38, 0x2d, 0x50, 0x6f, 0x72, 0x74, 0x20, 0x31, 0x30, 0x30, 0x31, 0x00, 0x0a, 0x0d, 0x53, 0x75, 0x6d, 0x6d, 0x69, 0x74, 0x33, 0x30, 0x30, 0x2d, 0x34, 0x38, 0x00, 0x0c, 0x4c, 0x53, 0x75, 0x6d, 0x6d, 0x69, 0x74, 0x33, 0x30, 0x30, 0x2d, 0x34, 0x38, 0x20, 0x2d, 0x20, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x37, 0x2e, 0x34, 0x65, 0x2e, 0x31, 0x20, 0x28, 0x42, 0x75, 0x69, 0x6c, 0x64, 0x20, 0x35, 0x29, 0x20, 0x62, 0x79, 0x20, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x5f, 0x4d, 0x61, 0x73, 0x74, 0x65, 0x72, 0x20, 0x30, 0x35, 0x2f, 0x32, 0x37, 0x2f, 0x30, 0x35, 0x20, 0x30, 0x34, 0x3a, 0x35, 0x33, 0x3a, 0x31, 0x31, 0x00, 0x0e, 0x04, 0x00, 0x14, 0x00, 0x14, 0x10, 0x0e, 0x07, 0x06, 0x00, 0x01, 0x30, 0xf9, 0xad, 0xa0, 0x02, 0x00, 0x00, 0x03, 0xe9, 0x00, 0xfe, 0x07, 0x00, 0x12, 0x0f, 0x02, 0x07, 0x01, 0x00, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x01, 0x03, 0x6c, 0x00, 0x00, 0x10, 0xfe, 0x09, 0x00, 0x12, 0x0f, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0x00, 0x12, 0x0f, 0x04, 0x05, 0xf2, 0xfe, 0x06, 0x00, 0x80, 0xc2, 0x01, 0x01, 0xe8, 0xfe, 0x07, 0x00, 0x80, 0xc2, 0x02, 0x01, 0x00, 0x00, 0xfe, 0x16, 0x00, 0x80, 0xc2, 0x03, 0x01, 0xe8, 0x0f, 0x76, 0x32, 0x2d, 0x30, 0x34, 0x38, 0x38, 0x2d, 0x30, 0x33, 0x2d, 0x30, 0x35, 0x30, 0x35, 0xfe, 0x05, 0x00, 0x80, 0xc2, 0x04, 0x00, 0x00, 0x00]>, 'chassis-id-type': <uint32 4>, 'chassis-id': <'00:01:30:F9:AD:A0'>, 'port-id-type': <uint32 5>, 'port-id': <'1/1'>, 'destination': <'nearest-bridge'>, 'port-description': <'Summit300-48-Port 1001'>, 'system-name': <'Summit300-48'>, 'system-description': <'Summit300-48 - Version 7.4e.1 (Build 5) by Release_Master 05/27/05 04:53:11'>, 'system-capabilities': <uint32 20>, 'management-addresses': <[{'address-subtype': <uint32 6>, 'address': <[byte 0x00, 0x01, 0x30, 0xf9, 0xad, 0xa0]>, 'interface-number-subtype': <uint32 2>, 'interface-number': <uint32 1001>, 'object-id': <@ay []>}]>, 'ieee-802-1-pvid': <uint32 488>, 'ieee-802-1-ppvid': <uint32 0>, 'ieee-802-1-ppvid-flags': <uint32 1>, 'ieee-802-1-ppvids': <[{'ppvid': <uint32 0>, 'flags': <uint32 1>}]>, 'ieee-802-1-vid': <uint32 488>, 'ieee-802-1-vlan-name': <'v2-0488-03-0505'>, 'ieee-802-1-vlans': <[{'vid': <uint32 488>, 'name': <'v2-0488-03-0505'>}]>, 'ieee-802-3-mac-phy-conf': <{'autoneg': <uint32 3>, 'pmd-autoneg-cap': <uint32 27648>, 'operational-mau-type': <uint32 16>}>, 'ieee-802-3-power-via-mdi': <{'mdi-power-support': <uint32 7>, 'pse-power-pair': <uint32 1>, 'power-class': <uint32 0>}>, 'ieee-802-3-max-frame-size': <uint32 1522>}",
/* ethernet header */
0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e, /* destination mac */
0x00, 0x01, 0x30, 0xf9, 0xad, 0xa0, /* source mac */
@ -229,7 +242,11 @@ _test_recv_data1_check (GMainLoop *loop, NMLldpListener *listener)
SD_LLDP_CHASSIS_SUBTYPE_MAC_ADDRESS, "00:01:30:F9:AD:A0",
SD_LLDP_PORT_SUBTYPE_INTERFACE_NAME, "1/1");
g_assert (neighbor);
g_assert_cmpint (g_variant_n_children (neighbor), ==, 4 + 16);
g_assert_cmpint (g_variant_n_children (neighbor), ==, 1 + 4 + 16);
attr = g_variant_lookup_value (neighbor, NM_LLDP_ATTR_RAW, G_VARIANT_TYPE_BYTESTRING);
nmtst_assert_variant_bytestring (attr, _test_recv_data1_frame0.frame, _test_recv_data1_frame0.frame_len);
nm_clear_g_variant (&attr);
attr = g_variant_lookup_value (neighbor, NM_LLDP_ATTR_DESTINATION, G_VARIANT_TYPE_STRING);
nmtst_assert_variant_string (attr, NM_LLDP_DEST_NEAREST_BRIDGE);
@ -263,11 +280,11 @@ _test_recv_data1_check (GMainLoop *loop, NMLldpListener *listener)
g_assert_cmpuint (g_variant_n_children (attr), ==, 1);
child = g_variant_get_child_value (attr, 0);
g_assert (child);
g_variant_lookup (child, "interface-number", "u", &v_uint);
g_assert (g_variant_lookup (child, "interface-number", "u", &v_uint));
g_assert_cmpint (v_uint, ==, 1001);
g_variant_lookup (child, "interface-number-subtype", "u", &v_uint);
g_assert (g_variant_lookup (child, "interface-number-subtype", "u", &v_uint));
g_assert_cmpint (v_uint, ==, 2);
g_variant_lookup (child, "address-subtype", "u", &v_uint);
g_assert (g_variant_lookup (child, "address-subtype", "u", &v_uint));
g_assert_cmpint (v_uint, ==, 6);
nm_clear_g_variant (&child);
nm_clear_g_variant (&attr);
@ -275,22 +292,22 @@ _test_recv_data1_check (GMainLoop *loop, NMLldpListener *listener)
/* IEEE 802.3 - Power Via MDI */
attr = g_variant_lookup_value (neighbor, NM_LLDP_ATTR_IEEE_802_3_POWER_VIA_MDI, G_VARIANT_TYPE_VARDICT);
g_assert (attr);
g_variant_lookup (attr, "mdi-power-support", "u", &v_uint);
g_assert (g_variant_lookup (attr, "mdi-power-support", "u", &v_uint));
g_assert_cmpint (v_uint, ==, 7);
g_variant_lookup (attr, "pse-power-pair", "u", &v_uint);
g_assert (g_variant_lookup (attr, "pse-power-pair", "u", &v_uint));
g_assert_cmpint (v_uint, ==, 1);
g_variant_lookup (attr, "power-class", "u", &v_uint);
g_assert (g_variant_lookup (attr, "power-class", "u", &v_uint));
g_assert_cmpint (v_uint, ==, 0);
nm_clear_g_variant (&attr);
/* IEEE 802.3 - MAC/PHY Configuration/Status */
attr = g_variant_lookup_value (neighbor, NM_LLDP_ATTR_IEEE_802_3_MAC_PHY_CONF, G_VARIANT_TYPE_VARDICT);
g_assert (attr);
g_variant_lookup (attr, "autoneg", "u", &v_uint);
g_assert (g_variant_lookup (attr, "autoneg", "u", &v_uint));
g_assert_cmpint (v_uint, ==, 3);
g_variant_lookup (attr, "pmd-autoneg-cap", "u", &v_uint);
g_assert (g_variant_lookup (attr, "pmd-autoneg-cap", "u", &v_uint));
g_assert_cmpint (v_uint, ==, 0x6c00);
g_variant_lookup (attr, "operational-mau-type", "u", &v_uint);
g_assert (g_variant_lookup (attr, "operational-mau-type", "u", &v_uint));
g_assert_cmpint (v_uint, ==, 16);
nm_clear_g_variant (&attr);
@ -319,9 +336,9 @@ _test_recv_data1_check (GMainLoop *loop, NMLldpListener *listener)
g_assert_cmpuint (g_variant_n_children (attr), ==, 1);
child = g_variant_get_child_value (attr, 0);
g_assert (child);
g_variant_lookup (child, "ppvid", "u", &v_uint);
g_assert (g_variant_lookup (child, "ppvid", "u", &v_uint));
g_assert_cmpint (v_uint, ==, 0);
g_variant_lookup (child, "flags", "u", &v_uint);
g_assert (g_variant_lookup (child, "flags", "u", &v_uint));
g_assert_cmpint (v_uint, ==, 1);
nm_clear_g_variant (&child);
nm_clear_g_variant (&attr);
@ -339,9 +356,9 @@ _test_recv_data1_check (GMainLoop *loop, NMLldpListener *listener)
g_assert_cmpuint (g_variant_n_children (attr), ==, 1);
child = g_variant_get_child_value (attr, 0);
g_assert (child);
g_variant_lookup (child, "vid", "u", &v_uint);
g_assert (g_variant_lookup (child, "vid", "u", &v_uint));
g_assert_cmpint (v_uint, ==, 488);
g_variant_lookup (child, "name", "&s", &v_str);
g_assert (g_variant_lookup (child, "name", "&s", &v_str));
g_assert_cmpstr (v_str, ==, "v2-0488-03-0505");
nm_clear_g_variant (&child);
nm_clear_g_variant (&attr);
@ -352,6 +369,7 @@ _test_recv_data1_check (GMainLoop *loop, NMLldpListener *listener)
TEST_RECV_DATA_DEFINE (_test_recv_data1, 1, _test_recv_data1_check, &_test_recv_data1_frame0);
TEST_RECV_FRAME_DEFINE (_test_recv_data2_frame0_ttl1,
"{'raw': <[byte 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x88, 0xcc, 0x02, 0x07, 0x04, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x04, 0x04, 0x05, 0x31, 0x2f, 0x33, 0x06, 0x02, 0x00, 0x01, 0x08, 0x04, 0x50, 0x6f, 0x72, 0x74, 0x0a, 0x03, 0x53, 0x59, 0x53, 0x0c, 0x04, 0x66, 0x6f, 0x6f, 0x00, 0x00, 0x00]>, 'chassis-id-type': <uint32 4>, 'chassis-id': <'00:01:02:03:04:05'>, 'port-id-type': <uint32 5>, 'port-id': <'1/3'>, 'destination': <'nearest-non-tpmr-bridge'>, 'port-description': <'Port'>, 'system-name': <'SYS'>, 'system-description': <'foo'>}",
/* Ethernet header */
0x01, 0x80, 0xc2, 0x00, 0x00, 0x03, /* Destination MAC */
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, /* Source MAC */
@ -374,7 +392,7 @@ _test_recv_data2_ttl1_check (GMainLoop *loop, NMLldpListener *listener)
gulong notify_id;
GVariant *neighbors;
_test_recv_data0_check (loop, listener);
_test_recv_data0_check_do (loop, listener, &_test_recv_data2_frame0_ttl1);
/* wait for signal. */
notify_id = g_signal_connect (listener, "notify::" NM_LLDP_LISTENER_NEIGHBORS,
@ -513,6 +531,28 @@ _test_recv_fixture_teardown (TestRecvFixture *fixture, gconstpointer user_data)
/*****************************************************************************/
static void
test_parse_frames (gconstpointer test_data)
{
const TestRecvFrame *frame = test_data;
gs_unref_variant GVariant *v_neighbor = NULL;
gs_unref_variant GVariant *attr = NULL;
gs_free char *as_variant = NULL;
v_neighbor = nmtst_lldp_parse_from_raw (frame->frame, frame->frame_len);
g_assert (v_neighbor);
attr = g_variant_lookup_value (v_neighbor, NM_LLDP_ATTR_RAW, G_VARIANT_TYPE_BYTESTRING);
nmtst_assert_variant_bytestring (attr, frame->frame, frame->frame_len);
nm_clear_g_variant (&attr);
as_variant = g_variant_print (v_neighbor, TRUE);
g_assert (as_variant);
g_assert_cmpstr (frame->as_variant, ==, as_variant);
}
/*****************************************************************************/
NMTstpSetupFunc const _nmtstp_setup_platform_func = nm_linux_platform_setup;
void
@ -530,4 +570,8 @@ _nmtstp_setup_tests (void)
_TEST_ADD_RECV ("/lldp/recv/0_twice", &_test_recv_data0_twice);
_TEST_ADD_RECV ("/lldp/recv/1", &_test_recv_data1);
_TEST_ADD_RECV ("/lldp/recv/2_ttl1", &_test_recv_data2_ttl1);
g_test_add_data_func ("/lldp/parse-frames/0", &_test_recv_data0_frame0, test_parse_frames);
g_test_add_data_func ("/lldp/parse-frames/1", &_test_recv_data1_frame0, test_parse_frames);
g_test_add_data_func ("/lldp/parse-frames/2", &_test_recv_data2_frame0_ttl1, test_parse_frames);
}