diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-12-02 15:00:06 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-12-02 18:40:24 +0900 |
commit | 99b06a2f5c9794cf7f767bffc6aa6649cc979f17 (patch) | |
tree | b589fb1cd0f78cadbd7c9766b05e01599b131df6 /src/libsystemd-network/sd-ipv4acd.c | |
parent | ebef02dd8f35f8b6ee58060b71b7f321a5027760 (diff) | |
download | systemd-99b06a2f5c9794cf7f767bffc6aa6649cc979f17.tar.gz |
sd-ipv4acd,sd-ipv4ll: introduce _get_ifindex() and _get_ifname()
They will be used in later commits.
This also makes sd_ipv4acd_set_ifindex() check the existence of the interface.
Diffstat (limited to 'src/libsystemd-network/sd-ipv4acd.c')
-rw-r--r-- | src/libsystemd-network/sd-ipv4acd.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/libsystemd-network/sd-ipv4acd.c b/src/libsystemd-network/sd-ipv4acd.c index 2e1e46c1c5..9d6638af48 100644 --- a/src/libsystemd-network/sd-ipv4acd.c +++ b/src/libsystemd-network/sd-ipv4acd.c @@ -16,8 +16,8 @@ #include "ether-addr-util.h" #include "event-util.h" #include "fd-util.h" +#include "format-util.h" #include "in-addr-util.h" -#include "list.h" #include "random-util.h" #include "siphash24.h" #include "string-util.h" @@ -54,6 +54,7 @@ struct sd_ipv4acd { int ifindex; int fd; + char ifname[IF_NAMESIZE + 1]; unsigned n_iteration; unsigned n_conflict; @@ -378,15 +379,35 @@ fail: } int sd_ipv4acd_set_ifindex(sd_ipv4acd *acd, int ifindex) { + char ifname[IF_NAMESIZE + 1]; + assert_return(acd, -EINVAL); assert_return(ifindex > 0, -EINVAL); assert_return(acd->state == IPV4ACD_STATE_INIT, -EBUSY); + if (!format_ifname(ifindex, ifname)) + return -ENODEV; + + strcpy(acd->ifname, ifname); acd->ifindex = ifindex; return 0; } +int sd_ipv4acd_get_ifindex(sd_ipv4acd *acd) { + if (!acd) + return -EINVAL; + + return acd->ifindex; +} + +const char *sd_ipv4acd_get_ifname(sd_ipv4acd *acd) { + if (!acd) + return NULL; + + return empty_to_null(acd->ifname); +} + int sd_ipv4acd_set_mac(sd_ipv4acd *acd, const struct ether_addr *addr) { assert_return(acd, -EINVAL); assert_return(addr, -EINVAL); |