diff options
author | Susant Sahani <susant@redhat.com> | 2017-04-25 16:06:12 +0530 |
---|---|---|
committer | Susant Sahani <susant@redhat.com> | 2017-04-26 16:00:44 +0530 |
commit | 30746d6088ccfec802972fd5ee12a1e945a0f69b (patch) | |
tree | 21dc95a6c429597eeffc32b0df5ad11fa83c8312 /src/libsystemd/sd-netlink/rtnl-message.c | |
parent | 6385cb31ef443be3e0d6da5ea62a267a49174688 (diff) | |
download | systemd-30746d6088ccfec802972fd5ee12a1e945a0f69b.tar.gz |
sd-netlink: add support for address label
Diffstat (limited to 'src/libsystemd/sd-netlink/rtnl-message.c')
-rw-r--r-- | src/libsystemd/sd-netlink/rtnl-message.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/libsystemd/sd-netlink/rtnl-message.c b/src/libsystemd/sd-netlink/rtnl-message.c index b543b5f20c..d5f8b7d15e 100644 --- a/src/libsystemd/sd-netlink/rtnl-message.c +++ b/src/libsystemd/sd-netlink/rtnl-message.c @@ -18,6 +18,7 @@ ***/ #include <netinet/in.h> +#include <linux/if_addrlabel.h> #include <stdbool.h> #include <unistd.h> @@ -700,3 +701,42 @@ int sd_rtnl_message_get_family(sd_netlink_message *m, int *family) { return -EOPNOTSUPP; } + +int sd_rtnl_message_new_addrlabel(sd_netlink *rtnl, sd_netlink_message **ret, uint16_t nlmsg_type, int ifindex, int ifal_family) { + struct ifaddrlblmsg *addrlabel; + int r; + + assert_return(rtnl_message_type_is_addrlabel(nlmsg_type), -EINVAL); + assert_return(ret, -EINVAL); + + r = message_new(rtnl, ret, nlmsg_type); + if (r < 0) + return r; + + if (nlmsg_type == RTM_NEWADDRLABEL) + (*ret)->hdr->nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL; + + addrlabel = NLMSG_DATA((*ret)->hdr); + + addrlabel->ifal_family = ifal_family; + addrlabel->ifal_index = ifindex; + + return 0; +} + +int sd_rtnl_message_addrlabel_set_prefixlen(sd_netlink_message *m, unsigned char prefixlen) { + struct ifaddrlblmsg *addrlabel; + + assert_return(m, -EINVAL); + assert_return(m->hdr, -EINVAL); + assert_return(rtnl_message_type_is_addrlabel(m->hdr->nlmsg_type), -EINVAL); + + addrlabel = NLMSG_DATA(m->hdr); + + if (prefixlen > 128) + return -ERANGE; + + addrlabel->ifal_prefixlen = prefixlen; + + return 0; +} |