]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-ndisc: ignore Router Advertisement messages sent by the same interface 31492/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 26 Feb 2024 04:26:52 +0000 (13:26 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Feb 2024 02:40:50 +0000 (11:40 +0900)
src/libsystemd-network/ndisc-internal.h
src/libsystemd-network/sd-ndisc.c
src/network/networkd-ndisc.c
src/systemd/sd-ndisc.h

index 615de0db51851a176663c9e73f7cd0bfdb9b0247..4e82fd5a86db84fd9269831412d8f3a942c9d0d7 100644 (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;
index 87f5e5693e76f353d694f5b7168eb9a0cc145fc4..939fa87d302355aef2edaac891c0696d9ca1c60e 100644 (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");
index 24808413c185b1f4489aab742b487b669afd3463..11ba35c5980ecdb0203448c414d2be5fe24556e7 100644 (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);
index 94f6da04879d25205d4fc636c19b214d0ff982e6..5f4f6caf8d2e5259c260dc5ef9f2c09947c4b0ee 100644 (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;