sd-ndisc: ignore Router Advertisement messages sent by the same interface

This commit is contained in:
Yu Watanabe
2024-02-28 11:40:50 +09:00
parent c34cb1d645
commit 25413fbfc7
4 changed files with 23 additions and 7 deletions
+1
View File
@@ -24,6 +24,7 @@ struct sd_ndisc {
sd_event *event;
int event_priority;
struct in6_addr link_local_addr;
struct ether_addr mac_addr;
sd_event_source *recv_event_source;
+17
View File
@@ -96,6 +96,18 @@ int sd_ndisc_get_ifname(sd_ndisc *nd, const char **ret) {
return 0;
}
int sd_ndisc_set_link_local_address(sd_ndisc *nd, const struct in6_addr *addr) {
assert_return(nd, -EINVAL);
assert_return(!addr || in6_addr_is_link_local(addr), -EINVAL);
if (addr)
nd->link_local_addr = *addr;
else
zero(nd->link_local_addr);
return 0;
}
int sd_ndisc_set_mac(sd_ndisc *nd, const struct ether_addr *mac_addr) {
assert_return(nd, -EINVAL);
@@ -233,6 +245,11 @@ static int ndisc_recv(sd_event_source *s, int fd, uint32_t revents, void *userda
return 0;
}
if (in6_addr_equal(&packet->sender_address, &nd->link_local_addr)) {
log_ndisc(nd, "Received an ICMPv6 packet sent by the same interface, ignoring.");
return 0;
}
r = icmp6_packet_get_type(packet);
if (r < 0) {
log_ndisc_errno(nd, r, "Received an invalid ICMPv6 packet, ignoring: %m");
+4 -7
View File
@@ -456,13 +456,6 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
if (r < 0)
return log_link_warning_errno(link, r, "Failed to get gateway address from RA: %m");
if (link_get_ipv6_address(link, &gateway, 0, NULL) >= 0) {
if (DEBUG_LOGGING)
log_link_debug(link, "No NDisc route added, gateway %s matches local address",
IN6_ADDR_TO_STRING(&gateway));
return 0;
}
r = sd_ndisc_router_get_preference(rt, &preference);
if (r < 0)
return log_link_warning_errno(link, r, "Failed to get router preference from RA: %m");
@@ -1815,6 +1808,10 @@ int ndisc_start(Link *link) {
if (in6_addr_is_null(&link->ipv6ll_address))
return 0;
r = sd_ndisc_set_link_local_address(link->ndisc, &link->ipv6ll_address);
if (r < 0)
return r;
log_link_debug(link, "Discovering IPv6 routers");
r = sd_ndisc_start(link->ndisc);
+1
View File
@@ -62,6 +62,7 @@ int sd_ndisc_set_callback(sd_ndisc *nd, sd_ndisc_callback_t cb, void *userdata);
int sd_ndisc_set_ifindex(sd_ndisc *nd, int interface_index);
int sd_ndisc_set_ifname(sd_ndisc *nd, const char *interface_name);
int sd_ndisc_get_ifname(sd_ndisc *nd, const char **ret);
int sd_ndisc_set_link_local_address(sd_ndisc *nd, const struct in6_addr *addr);
int sd_ndisc_set_mac(sd_ndisc *nd, const struct ether_addr *mac_addr);
_SD_END_DECLARATIONS;