summaryrefslogtreecommitdiff
path: root/src/libsystemd-network/icmp6-util.c
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-11-23 15:59:58 +0100
committerTom Gundersen <teg@jklm.no>2015-11-25 18:30:31 +0100
commitcddf4d81eacfc81cf761619fcb67bc07a744a6d1 (patch)
tree5ad00fafa1d883eee418fd5cd048cc8c5b49d0c8 /src/libsystemd-network/icmp6-util.c
parent6d06ac1faa1b06a9fb5793c970bccd5b47825d07 (diff)
sd-ndisc: better validate RA packets
Verify the hoplimit and that the received packet is large enough for the RA header. See <http://tools.ietf.org/html/rfc4861#section-6.1.2>.
Diffstat (limited to 'src/libsystemd-network/icmp6-util.c')
-rw-r--r--src/libsystemd-network/icmp6-util.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/libsystemd-network/icmp6-util.c b/src/libsystemd-network/icmp6-util.c
index 03505fc47b..acad9d7d6a 100644
--- a/src/libsystemd-network/icmp6-util.c
+++ b/src/libsystemd-network/icmp6-util.c
@@ -47,17 +47,15 @@ int icmp6_bind_router_solicitation(int index) {
.ipv6mr_interface = index,
};
_cleanup_close_ int s = -1;
- int r, zero = 0, hops = 255;
+ int r, zero = 0, one = 1, hops = 255;
- s = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK,
- IPPROTO_ICMPV6);
+ s = socket(AF_INET6, SOCK_RAW | SOCK_CLOEXEC | SOCK_NONBLOCK, IPPROTO_ICMPV6);
if (s < 0)
return -errno;
ICMP6_FILTER_SETBLOCKALL(&filter);
ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filter);
- r = setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER, &filter,
- sizeof(filter));
+ r = setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER, &filter, sizeof(filter));
if (r < 0)
return -errno;
@@ -65,23 +63,23 @@ int icmp6_bind_router_solicitation(int index) {
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(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, &index,
- sizeof(index));
+ r = setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_IF, &index, sizeof(index));
if (r < 0)
return -errno;
- r = setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &zero,
- sizeof(zero));
+ r = setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &zero, sizeof(zero));
if (r < 0)
return -errno;
- r = setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &hops,
- sizeof(hops));
+ r = setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &hops, sizeof(hops));
if (r < 0)
return -errno;
- r = setsockopt(s, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq,
- sizeof(mreq));
+ r = setsockopt(s, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
+ if (r < 0)
+ return -errno;
+
+ r = setsockopt(s, SOL_IPV6, IPV6_RECVHOPLIMIT, &one, sizeof(one));
if (r < 0)
return -errno;