From e64e052e17b2f3a7a19c3bcbc3b326088f388f3a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 23 Feb 2021 03:05:24 +0900 Subject: [PATCH] sd-netlink: introduce sd_rtnl_message_nexthop_get_protocol() --- src/libsystemd/sd-netlink/rtnl-message.c | 16 ++++++++++++++++ src/systemd/sd-netlink.h | 1 + 2 files changed, 17 insertions(+) diff --git a/src/libsystemd/sd-netlink/rtnl-message.c b/src/libsystemd/sd-netlink/rtnl-message.c index b8c11d1181c..d14fa1a5cb7 100644 --- a/src/libsystemd/sd-netlink/rtnl-message.c +++ b/src/libsystemd/sd-netlink/rtnl-message.c @@ -329,6 +329,8 @@ int sd_rtnl_message_nexthop_get_family(const sd_netlink_message *m, uint8_t *fam assert_return(m, -EINVAL); assert_return(m->hdr, -EINVAL); + assert_return(rtnl_message_type_is_nexthop(m->hdr->nlmsg_type), -EINVAL); + assert_return(family, -EINVAL); nhm = NLMSG_DATA(m->hdr); *family = nhm->nh_family; @@ -336,6 +338,20 @@ int sd_rtnl_message_nexthop_get_family(const sd_netlink_message *m, uint8_t *fam return 0; } +int sd_rtnl_message_nexthop_get_protocol(const sd_netlink_message *m, uint8_t *protocol) { + struct nhmsg *nhm; + + assert_return(m, -EINVAL); + assert_return(m->hdr, -EINVAL); + assert_return(rtnl_message_type_is_nexthop(m->hdr->nlmsg_type), -EINVAL); + assert_return(protocol, -EINVAL); + + nhm = NLMSG_DATA(m->hdr); + *protocol = nhm->nh_protocol; + + return 0; +} + int sd_rtnl_message_neigh_set_flags(sd_netlink_message *m, uint8_t flags) { struct ndmsg *ndm; diff --git a/src/systemd/sd-netlink.h b/src/systemd/sd-netlink.h index 8820c65e230..276108b38d9 100644 --- a/src/systemd/sd-netlink.h +++ b/src/systemd/sd-netlink.h @@ -184,6 +184,7 @@ int sd_rtnl_message_route_get_type(const sd_netlink_message *m, unsigned char *t int sd_rtnl_message_new_nexthop(sd_netlink *rtnl, sd_netlink_message **ret, uint16_t nhmsg_type, int nh_family, unsigned char nh_protocol); int sd_rtnl_message_nexthop_set_flags(sd_netlink_message *m, uint8_t flags); int sd_rtnl_message_nexthop_get_family(const sd_netlink_message *m, uint8_t *family); +int sd_rtnl_message_nexthop_get_protocol(const sd_netlink_message *m, uint8_t *protocol); int sd_rtnl_message_new_neigh(sd_netlink *nl, sd_netlink_message **ret, uint16_t msg_type, int index, int nda_family); int sd_rtnl_message_neigh_set_flags(sd_netlink_message *m, uint8_t flags); -- 2.47.3