summaryrefslogtreecommitdiffstats
path: root/src/libsystemd/sd-netlink/rtnl-message.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-02-15 01:15:06 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-02-16 17:21:03 +0100
commit735a3d73b710513a180cd4a7232a49cf837484d1 (patch)
treee7440411cb4748f7dd1df24e37f9d90e338e83f3 /src/libsystemd/sd-netlink/rtnl-message.c
parentresolved: reduce indentation level a bit (diff)
downloadsystemd-735a3d73b710513a180cd4a7232a49cf837484d1.tar.xz
systemd-735a3d73b710513a180cd4a7232a49cf837484d1.zip
netlink: fix assertions
Diffstat (limited to '')
-rw-r--r--src/libsystemd/sd-netlink/rtnl-message.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/libsystemd/sd-netlink/rtnl-message.c b/src/libsystemd/sd-netlink/rtnl-message.c
index ea97b1e6ad..bd51fac47a 100644
--- a/src/libsystemd/sd-netlink/rtnl-message.c
+++ b/src/libsystemd/sd-netlink/rtnl-message.c
@@ -294,8 +294,19 @@ int sd_rtnl_message_new_nexthop(sd_netlink *rtnl, sd_netlink_message **ret,
int r;
assert_return(rtnl_message_type_is_nexthop(nhmsg_type), -EINVAL);
- assert_return((nhmsg_type == RTM_GETNEXTHOP && nh_family == AF_UNSPEC) ||
- IN_SET(nh_family, AF_INET, AF_INET6), -EINVAL);
+ switch(nhmsg_type) {
+ case RTM_DELNEXTHOP:
+ assert_return(nh_family == AF_UNSPEC, -EINVAL);
+ _fallthrough_;
+ case RTM_GETNEXTHOP:
+ assert_return(nh_protocol == RTPROT_UNSPEC, -EINVAL);
+ break;
+ case RTM_NEWNEXTHOP:
+ assert_return(IN_SET(nh_family, AF_UNSPEC, AF_INET, AF_INET6), -EINVAL);
+ break;
+ default:
+ assert_not_reached("Invalid message type.");
+ }
assert_return(ret, -EINVAL);
r = message_new(rtnl, ret, nhmsg_type);
@@ -319,7 +330,7 @@ int sd_rtnl_message_nexthop_set_flags(sd_netlink_message *m, uint8_t flags) {
assert_return(m, -EINVAL);
assert_return(m->hdr, -EINVAL);
- assert_return(rtnl_message_type_is_nexthop(m->hdr->nlmsg_type), -EINVAL);
+ assert_return(m->hdr->nlmsg_type == RTM_NEWNEXTHOP, -EINVAL);
nhm = NLMSG_DATA(m->hdr);
nhm->nh_flags |= flags;
@@ -346,7 +357,7 @@ int sd_rtnl_message_nexthop_get_family(const sd_netlink_message *m, uint8_t *fam
assert_return(m->hdr, -EINVAL);
nhm = NLMSG_DATA(m->hdr);
- *family = nhm->nh_family ;
+ *family = nhm->nh_family;
return 0;
}