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.
This commit is contained in:
parent
ebef02dd8f
commit
99b06a2f5c
|
@ -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);
|
||||
|
|
|
@ -103,6 +103,20 @@ int sd_ipv4ll_set_ifindex(sd_ipv4ll *ll, int ifindex) {
|
|||
return sd_ipv4acd_set_ifindex(ll->acd, ifindex);
|
||||
}
|
||||
|
||||
int sd_ipv4ll_get_ifindex(sd_ipv4ll *ll) {
|
||||
if (!ll)
|
||||
return -EINVAL;
|
||||
|
||||
return sd_ipv4acd_get_ifindex(ll->acd);
|
||||
}
|
||||
|
||||
const char *sd_ipv4ll_get_ifname(sd_ipv4ll *ll) {
|
||||
if (!ll)
|
||||
return NULL;
|
||||
|
||||
return sd_ipv4acd_get_ifname(ll->acd);
|
||||
}
|
||||
|
||||
int sd_ipv4ll_set_mac(sd_ipv4ll *ll, const struct ether_addr *addr) {
|
||||
int r;
|
||||
|
||||
|
|
|
@ -126,7 +126,6 @@ static void test_public_api_setters(sd_event *e) {
|
|||
assert_se(sd_ipv4ll_set_ifindex(ll, -1) == -EINVAL);
|
||||
assert_se(sd_ipv4ll_set_ifindex(ll, -99) == -EINVAL);
|
||||
assert_se(sd_ipv4ll_set_ifindex(ll, 1) == 0);
|
||||
assert_se(sd_ipv4ll_set_ifindex(ll, 99) == 0);
|
||||
|
||||
assert_se(sd_ipv4ll_ref(ll) == ll);
|
||||
assert_se(sd_ipv4ll_unref(ll) == NULL);
|
||||
|
|
|
@ -43,6 +43,8 @@ int sd_ipv4acd_get_address(sd_ipv4acd *acd, struct in_addr *address);
|
|||
int sd_ipv4acd_set_callback(sd_ipv4acd *acd, sd_ipv4acd_callback_t cb, void *userdata);
|
||||
int sd_ipv4acd_set_mac(sd_ipv4acd *acd, const struct ether_addr *addr);
|
||||
int sd_ipv4acd_set_ifindex(sd_ipv4acd *acd, int interface_index);
|
||||
int sd_ipv4acd_get_ifindex(sd_ipv4acd *acd);
|
||||
const char *sd_ipv4acd_get_ifname(sd_ipv4acd *acd);
|
||||
int sd_ipv4acd_set_address(sd_ipv4acd *acd, const struct in_addr *address);
|
||||
int sd_ipv4acd_is_running(sd_ipv4acd *acd);
|
||||
int sd_ipv4acd_start(sd_ipv4acd *acd, bool reset_conflicts);
|
||||
|
|
|
@ -43,6 +43,8 @@ int sd_ipv4ll_get_address(sd_ipv4ll *ll, struct in_addr *address);
|
|||
int sd_ipv4ll_set_callback(sd_ipv4ll *ll, sd_ipv4ll_callback_t cb, void *userdata);
|
||||
int sd_ipv4ll_set_mac(sd_ipv4ll *ll, const struct ether_addr *addr);
|
||||
int sd_ipv4ll_set_ifindex(sd_ipv4ll *ll, int interface_index);
|
||||
int sd_ipv4ll_get_ifindex(sd_ipv4ll *ll);
|
||||
const char *sd_ipv4ll_get_ifname(sd_ipv4ll *ll);
|
||||
int sd_ipv4ll_set_address(sd_ipv4ll *ll, const struct in_addr *address);
|
||||
int sd_ipv4ll_set_address_seed(sd_ipv4ll *ll, uint64_t seed);
|
||||
int sd_ipv4ll_is_running(sd_ipv4ll *ll);
|
||||
|
|
Loading…
Reference in New Issue