summaryrefslogtreecommitdiffstats
path: root/src/libsystemd-network/icmp6-util.c
diff options
context:
space:
mode:
authorLuca Boccassi <bluca@debian.org>2024-02-25 14:07:53 +0100
committerGitHub <noreply@github.com>2024-02-25 14:07:53 +0100
commit9529ae85f0a31720b7b17b71aef9ef4513473506 (patch)
treee78372713d08789e6256ea0426096a2bf6859074 /src/libsystemd-network/icmp6-util.c
parentin-addr-util: introduce in{4,6}_addr_is_multicast() (diff)
parenttest: split out {dump,verify}_ra_message() (diff)
downloadsystemd-9529ae85f0a31720b7b17b71aef9ef4513473506.tar.xz
systemd-9529ae85f0a31720b7b17b71aef9ef4513473506.zip
Merge pull request #31440 from yuwata/sd-ndisc-sd-radv-cleanups
sd-ndisc,sd-radv: several trivial cleanups
Diffstat (limited to 'src/libsystemd-network/icmp6-util.c')
-rw-r--r--src/libsystemd-network/icmp6-util.c69
1 files changed, 24 insertions, 45 deletions
diff --git a/src/libsystemd-network/icmp6-util.c b/src/libsystemd-network/icmp6-util.c
index acfaa9838c..559167847f 100644
--- a/src/libsystemd-network/icmp6-util.c
+++ b/src/libsystemd-network/icmp6-util.c
@@ -21,37 +21,42 @@
#include "network-common.h"
#include "socket-util.h"
-#define IN6ADDR_ALL_ROUTERS_MULTICAST_INIT \
- { { { 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 } } }
-
-#define IN6ADDR_ALL_NODES_MULTICAST_INIT \
- { { { 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } } }
-
-static int icmp6_bind_router_message(const struct icmp6_filter *filter,
- const struct ipv6_mreq *mreq) {
- int ifindex = mreq->ipv6mr_interface;
+int icmp6_bind(int ifindex, bool is_router) {
+ struct icmp6_filter filter = {};
+ struct ipv6_mreq mreq;
_cleanup_close_ int s = -EBADF;
int r;
- assert(filter);
- assert(mreq);
+ assert(ifindex > 0);
+
+ ICMP6_FILTER_SETBLOCKALL(&filter);
+ if (is_router) {
+ mreq = (struct ipv6_mreq) {
+ .ipv6mr_multiaddr = IN6ADDR_ALL_ROUTERS_MULTICAST_INIT,
+ .ipv6mr_interface = ifindex,
+ };
+ ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filter);
+ } else {
+ mreq = (struct ipv6_mreq) {
+ .ipv6mr_multiaddr = IN6ADDR_ALL_NODES_MULTICAST_INIT,
+ .ipv6mr_interface = ifindex,
+ };
+ ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filter);
+ }
s = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, IPPROTO_ICMPV6);
if (s < 0)
return -errno;
- if (setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER, filter, sizeof(*filter)) < 0)
+ if (setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER, &filter, sizeof(filter)) < 0)
return -errno;
- if (setsockopt(s, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, mreq, sizeof(*mreq)) < 0)
+ if (setsockopt(s, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
return -errno;
- /* RFC 3315, section 6.7, bullet point 2 may indicate that an
- IPV6_PKTINFO socket option also applies for ICMPv6 multicast.
- Empirical experiments indicates otherwise and therefore an
- IPV6_MULTICAST_IF socket option is used here instead */
+ /* RFC 3315, section 6.7, bullet point 2 may indicate that an IPV6_PKTINFO socket option also applies
+ * for ICMPv6 multicast. Empirical experiments indicates otherwise and therefore an IPV6_MULTICAST_IF
+ * socket option is used here instead. */
r = setsockopt_int(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, ifindex);
if (r < 0)
return r;
@@ -83,32 +88,6 @@ static int icmp6_bind_router_message(const struct icmp6_filter *filter,
return TAKE_FD(s);
}
-int icmp6_bind_router_solicitation(int ifindex) {
- struct icmp6_filter filter = {};
- struct ipv6_mreq mreq = {
- .ipv6mr_multiaddr = IN6ADDR_ALL_NODES_MULTICAST_INIT,
- .ipv6mr_interface = ifindex,
- };
-
- ICMP6_FILTER_SETBLOCKALL(&filter);
- ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filter);
-
- return icmp6_bind_router_message(&filter, &mreq);
-}
-
-int icmp6_bind_router_advertisement(int ifindex) {
- struct icmp6_filter filter = {};
- struct ipv6_mreq mreq = {
- .ipv6mr_multiaddr = IN6ADDR_ALL_ROUTERS_MULTICAST_INIT,
- .ipv6mr_interface = ifindex,
- };
-
- ICMP6_FILTER_SETBLOCKALL(&filter);
- ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filter);
-
- return icmp6_bind_router_message(&filter, &mreq);
-}
-
int icmp6_send_router_solicitation(int s, const struct ether_addr *ether_addr) {
struct sockaddr_in6 dst = {
.sin6_family = AF_INET6,