Skip to content

Commit

Permalink
network: introduce callback fucntions to check the sender MAC address…
Browse files Browse the repository at this point in the history
… for IPv4ACD and IPv4LL

Fixes systemd#12145.
  • Loading branch information
yuwata committed Jun 30, 2021
1 parent 76a86ff commit d7ab6ef
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/network/networkd-ipv4acd.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ static void dhcp4_address_on_acd(sd_ipv4acd *acd, int event, void *userdata) {
on_acd(acd, event, userdata, false);
}

static int ipv4acd_check_mac(sd_ipv4acd *acd, const struct ether_addr *mac, void *userdata) {
Manager *m = userdata;
struct hw_addr_data hw_addr;

assert(m);
assert(mac);

hw_addr = (struct hw_addr_data) {
.length = ETH_ALEN,
.ether = *mac,
};

return link_get_by_hw_addr(m, &hw_addr, NULL) >= 0;
}

static int ipv4acd_configure(Link *link, const Address *a) {
_cleanup_(address_freep) Address *address = NULL;
int r;
Expand Down Expand Up @@ -177,6 +192,10 @@ static int ipv4acd_configure(Link *link, const Address *a) {
if (r < 0)
return r;

r = sd_ipv4acd_set_check_mac_callback(address->acd, ipv4acd_check_mac, link->manager);
if (r < 0)
return r;

if (link_has_carrier(link)) {
r = sd_ipv4acd_start(address->acd, true);
if (r < 0)
Expand Down
17 changes: 16 additions & 1 deletion src/network/networkd-ipv4ll.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ static void ipv4ll_handler(sd_ipv4ll *ll, int event, void *userdata) {
}
}

static int ipv4ll_check_mac(sd_ipv4ll *ll, const struct ether_addr *mac, void *userdata) {
Manager *m = userdata;
struct hw_addr_data hw_addr;

assert(m);
assert(mac);

hw_addr = (struct hw_addr_data) {
.length = ETH_ALEN,
.ether = *mac,
};

return link_get_by_hw_addr(m, &hw_addr, NULL) >= 0;
}

int ipv4ll_configure(Link *link) {
uint64_t seed;
int r;
Expand Down Expand Up @@ -180,7 +195,7 @@ int ipv4ll_configure(Link *link) {
if (r < 0)
return r;

return 0;
return sd_ipv4ll_set_check_mac_callback(link->ipv4ll, ipv4ll_check_mac, link->manager);
}

int ipv4ll_update_mac(Link *link) {
Expand Down

0 comments on commit d7ab6ef

Please sign in to comment.