Skip to content

Commit

Permalink
test-netlink: Gracefully handle the loopback interface being down
Browse files Browse the repository at this point in the history
(cherry picked from commit d098b8df6e5c1b4c834272dd1397345483116db6)
(cherry picked from commit f6f96b05585ef3b05cef843a2c1cb2c55e77d3ba)
(cherry picked from commit 77ee2a8)
  • Loading branch information
DaanDeMeyer authored and bluca committed Sep 11, 2024
1 parent 35c4cd5 commit 8096e23
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/libsystemd/sd-netlink/test-netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,24 @@ TEST(message_address) {
struct in_addr in_data;
struct ifa_cacheinfo cache;
const char *label;
int r;

assert_se(sd_netlink_open(&rtnl) >= 0);
ifindex = (int) if_nametoindex("lo");

assert_se(sd_rtnl_message_new_addr(rtnl, &message, RTM_GETADDR, ifindex, AF_INET) >= 0);
assert_se(sd_netlink_message_set_request_dump(message, true) >= 0);
assert_se(sd_netlink_call(rtnl, message, 0, &reply) == 1);

assert_se(sd_netlink_message_read_in_addr(reply, IFA_LOCAL, &in_data) >= 0);
assert_se(sd_netlink_message_read_in_addr(reply, IFA_ADDRESS, &in_data) >= 0);
assert_se(sd_netlink_message_read_string(reply, IFA_LABEL, &label) >= 0);
assert_se(sd_netlink_message_read_cache_info(reply, IFA_CACHEINFO, &cache) == 0);
r = sd_netlink_call(rtnl, message, 0, &reply);
assert_se(r >= 0);

/* If the loopback device is down we won't get any results. */
if (r > 0) {
assert_se(sd_netlink_message_read_in_addr(reply, IFA_LOCAL, &in_data) >= 0);
assert_se(sd_netlink_message_read_in_addr(reply, IFA_ADDRESS, &in_data) >= 0);
assert_se(sd_netlink_message_read_string(reply, IFA_LABEL, &label) >= 0);
assert_se(sd_netlink_message_read_cache_info(reply, IFA_CACHEINFO, &cache) == 0);
}
}

TEST(message_route) {
Expand Down

0 comments on commit 8096e23

Please sign in to comment.