Merge pull request #31583 from yuwata/sd-lldp-json-follow-up
sd-lldp: fix assignment of capabilities in JSON output
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "fd-util.h"
|
||||
#include "fuzz.h"
|
||||
#include "lldp-network.h"
|
||||
#include "lldp-rx-internal.h"
|
||||
|
||||
static int test_fd[2] = EBADF_PAIR;
|
||||
|
||||
@@ -22,6 +23,7 @@ int lldp_network_bind_raw_socket(int ifindex) {
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
_cleanup_(sd_event_unrefp) sd_event *e = NULL;
|
||||
_cleanup_(sd_lldp_rx_unrefp) sd_lldp_rx *lldp_rx = NULL;
|
||||
_cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
|
||||
|
||||
if (outside_size_range(size, 0, 2048))
|
||||
return 0;
|
||||
@@ -37,6 +39,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||
assert_se(write(test_fd[1], data, size) == (ssize_t) size);
|
||||
assert_se(sd_event_run(e, 0) >= 0);
|
||||
|
||||
assert_se(lldp_rx_build_neighbors_json(lldp_rx, &v) >= 0);
|
||||
|
||||
assert_se(sd_lldp_rx_stop(lldp_rx) >= 0);
|
||||
assert_se(sd_lldp_rx_detach_event(lldp_rx) >= 0);
|
||||
test_fd[1] = safe_close(test_fd[1]);
|
||||
|
||||
@@ -776,7 +776,7 @@ int lldp_neighbor_build_json(sd_lldp_neighbor *n, JsonVariant **ret) {
|
||||
(void) sd_lldp_neighbor_get_system_name(n, &system_name);
|
||||
(void) sd_lldp_neighbor_get_system_description(n, &system_description);
|
||||
|
||||
valid_cc = sd_lldp_neighbor_get_enabled_capabilities(n, &cc);
|
||||
valid_cc = sd_lldp_neighbor_get_enabled_capabilities(n, &cc) >= 0;
|
||||
|
||||
return json_build(ret, JSON_BUILD_OBJECT(
|
||||
JSON_BUILD_PAIR_STRING_NON_EMPTY("ChassisID", chassis_id),
|
||||
|
||||
@@ -5328,7 +5328,7 @@ class NetworkdLLDPTests(unittest.TestCase, Utilities):
|
||||
|
||||
output = networkctl('lldp')
|
||||
print(output)
|
||||
if re.search(r'veth99 .* veth-peer', output):
|
||||
if re.search(r'veth99 .* veth-peer .* .......a...', output):
|
||||
break
|
||||
else:
|
||||
self.fail()
|
||||
@@ -5336,30 +5336,87 @@ class NetworkdLLDPTests(unittest.TestCase, Utilities):
|
||||
# With interface name
|
||||
output = networkctl('lldp', 'veth99');
|
||||
print(output)
|
||||
self.assertRegex(output, r'veth99 .* veth-peer')
|
||||
self.assertRegex(output, r'veth99 .* veth-peer .* .......a...')
|
||||
|
||||
# With interface name pattern
|
||||
output = networkctl('lldp', 've*9');
|
||||
print(output)
|
||||
self.assertRegex(output, r'veth99 .* veth-peer')
|
||||
self.assertRegex(output, r'veth99 .* veth-peer .* .......a...')
|
||||
|
||||
# json format
|
||||
output = networkctl('--json=short', 'lldp')
|
||||
print(output)
|
||||
self.assertIn('"InterfaceName":"veth99"', output)
|
||||
self.assertIn('"PortID":"veth-peer"', output)
|
||||
self.assertIn('"EnabledCapabilities":128', output)
|
||||
|
||||
# json format with interface name
|
||||
output = networkctl('--json=short', 'lldp', 'veth99')
|
||||
print(output)
|
||||
self.assertIn('"InterfaceName":"veth99"', output)
|
||||
self.assertIn('"PortID":"veth-peer"', output)
|
||||
self.assertIn('"EnabledCapabilities":128', output)
|
||||
|
||||
# json format with interface name pattern
|
||||
output = networkctl('--json=short', 'lldp', 've*9')
|
||||
print(output)
|
||||
self.assertIn('"InterfaceName":"veth99"', output)
|
||||
self.assertIn('"PortID":"veth-peer"', output)
|
||||
self.assertIn('"EnabledCapabilities":128', output)
|
||||
|
||||
# LLDP neighbors in status
|
||||
output = networkctl_status('veth99')
|
||||
print(output)
|
||||
self.assertRegex(output, r'Connected To: .* on port veth-peer')
|
||||
|
||||
# enable forwarding, to enable the Router flag
|
||||
with open(os.path.join(network_unit_dir, '23-emit-lldp.network'), mode='a', encoding='utf-8') as f:
|
||||
f.write('[Network]\nIPv4Forwarding=yes\n')
|
||||
|
||||
networkctl_reload()
|
||||
self.wait_online('veth-peer:degraded')
|
||||
|
||||
for trial in range(10):
|
||||
if trial > 0:
|
||||
time.sleep(1)
|
||||
|
||||
output = networkctl('lldp')
|
||||
print(output)
|
||||
if re.search(r'veth99 .* veth-peer .* ....r......', output):
|
||||
break
|
||||
else:
|
||||
self.fail()
|
||||
|
||||
# With interface name
|
||||
output = networkctl('lldp', 'veth99');
|
||||
print(output)
|
||||
self.assertRegex(output, r'veth99 .* veth-peer .* ....r......')
|
||||
|
||||
# With interface name pattern
|
||||
output = networkctl('lldp', 've*9');
|
||||
print(output)
|
||||
self.assertRegex(output, r'veth99 .* veth-peer .* ....r......')
|
||||
|
||||
# json format
|
||||
output = networkctl('--json=short', 'lldp')
|
||||
print(output)
|
||||
self.assertIn('"InterfaceName":"veth99"', output)
|
||||
self.assertIn('"PortID":"veth-peer"', output)
|
||||
self.assertIn('"EnabledCapabilities":16', output)
|
||||
|
||||
# json format with interface name
|
||||
output = networkctl('--json=short', 'lldp', 'veth99')
|
||||
print(output)
|
||||
self.assertIn('"InterfaceName":"veth99"', output)
|
||||
self.assertIn('"PortID":"veth-peer"', output)
|
||||
self.assertIn('"EnabledCapabilities":16', output)
|
||||
|
||||
# json format with interface name pattern
|
||||
output = networkctl('--json=short', 'lldp', 've*9')
|
||||
print(output)
|
||||
self.assertIn('"InterfaceName":"veth99"', output)
|
||||
self.assertIn('"PortID":"veth-peer"', output)
|
||||
self.assertIn('"EnabledCapabilities":16', output)
|
||||
|
||||
# LLDP neighbors in status
|
||||
output = networkctl_status('veth99')
|
||||
|
||||
Reference in New Issue
Block a user