Skip to content

Commit fb92f57

Browse files
committed
Merge branch 'icmp6-support-rfc-4884'
Willem de Bruijn says: ==================== icmp6: support rfc 4884 Extend the feature merged earlier this week for IPv4 to IPv6. I expected this to be a single patch, but patch 1 seemed better to be stand-alone patch 1: small fix in length calculation patch 2: factor out ipv4-specific patch 3: add ipv6 changes v1->v2: add missing static keyword in patch 3 ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents 623b57b + 0137043 commit fb92f57

8 files changed

Lines changed: 53 additions & 21 deletions

File tree

‎include/linux/icmp.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static inline bool icmp_is_err(int type)
3737
}
3838

3939
void ip_icmp_error_rfc4884(const struct sk_buff *skb,
40-
struct sock_ee_data_rfc4884 *out);
40+
struct sock_ee_data_rfc4884 *out,
41+
int thlen, int off);
4142

4243
#endif /* _LINUX_ICMP_H */

‎include/linux/ipv6.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ struct ipv6_pinfo {
283283
autoflowlabel:1,
284284
autoflowlabel_set:1,
285285
mc_all:1,
286+
recverr_rfc4884:1,
286287
rtalert_isolate:1;
287288
__u8 min_hopcount;
288289
__u8 tclass;

‎include/uapi/linux/icmpv6.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct icmp6hdr {
6868
#define icmp6_mtu icmp6_dataun.un_data32[0]
6969
#define icmp6_unused icmp6_dataun.un_data32[0]
7070
#define icmp6_maxdelay icmp6_dataun.un_data16[0]
71+
#define icmp6_datagram_len icmp6_dataun.un_data8[0]
7172
#define icmp6_router icmp6_dataun.u_nd_advt.router
7273
#define icmp6_solicited icmp6_dataun.u_nd_advt.solicited
7374
#define icmp6_override icmp6_dataun.u_nd_advt.override

‎include/uapi/linux/in6.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ struct in6_flowlabel_req {
179179
#define IPV6_LEAVE_ANYCAST 28
180180
#define IPV6_MULTICAST_ALL 29
181181
#define IPV6_ROUTER_ALERT_ISOLATE 30
182+
#define IPV6_RECVERR_RFC4884 31
182183

183184
/* IPV6_MTU_DISCOVER values */
184185
#define IPV6_PMTUDISC_DONT 0

‎net/ipv4/icmp.c‎

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,29 +1151,16 @@ static bool ip_icmp_error_rfc4884_validate(const struct sk_buff *skb, int off)
11511151
}
11521152

11531153
void ip_icmp_error_rfc4884(const struct sk_buff *skb,
1154-
struct sock_ee_data_rfc4884 *out)
1154+
struct sock_ee_data_rfc4884 *out,
1155+
int thlen, int off)
11551156
{
1156-
int hlen, off;
1157+
int hlen;
11571158

1158-
switch (icmp_hdr(skb)->type) {
1159-
case ICMP_DEST_UNREACH:
1160-
case ICMP_TIME_EXCEEDED:
1161-
case ICMP_PARAMETERPROB:
1162-
break;
1163-
default:
1164-
return;
1165-
}
1166-
1167-
/* outer headers up to inner iph. skb->data is at inner payload */
1168-
hlen = -skb_transport_offset(skb) - sizeof(struct icmphdr);
1169-
1170-
/* per rfc 791: maximum packet length of 576 bytes */
1171-
if (hlen + skb->len > 576)
1172-
return;
1159+
/* original datagram headers: end of icmph to payload (skb->data) */
1160+
hlen = -skb_transport_offset(skb) - thlen;
11731161

11741162
/* per rfc 4884: minimal datagram length of 128 bytes */
1175-
off = icmp_hdr(skb)->un.reserved[1] * sizeof(u32);
1176-
if (off < 128)
1163+
if (off < 128 || off < hlen)
11771164
return;
11781165

11791166
/* kernel has stripped headers: return payload offset in bytes */
@@ -1186,6 +1173,7 @@ void ip_icmp_error_rfc4884(const struct sk_buff *skb,
11861173
if (!ip_icmp_error_rfc4884_validate(skb, off))
11871174
out->flags |= SO_EE_RFC4884_FLAG_INVALID;
11881175
}
1176+
EXPORT_SYMBOL_GPL(ip_icmp_error_rfc4884);
11891177

11901178
int icmp_err(struct sk_buff *skb, u32 info)
11911179
{

‎net/ipv4/ip_sockglue.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,18 @@ int ip_ra_control(struct sock *sk, unsigned char on,
390390
return 0;
391391
}
392392

393+
static void ipv4_icmp_error_rfc4884(const struct sk_buff *skb,
394+
struct sock_ee_data_rfc4884 *out)
395+
{
396+
switch (icmp_hdr(skb)->type) {
397+
case ICMP_DEST_UNREACH:
398+
case ICMP_TIME_EXCEEDED:
399+
case ICMP_PARAMETERPROB:
400+
ip_icmp_error_rfc4884(skb, out, sizeof(struct icmphdr),
401+
icmp_hdr(skb)->un.reserved[1] * 4);
402+
}
403+
}
404+
393405
void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err,
394406
__be16 port, u32 info, u8 *payload)
395407
{
@@ -413,7 +425,7 @@ void ip_icmp_error(struct sock *sk, struct sk_buff *skb, int err,
413425

414426
if (skb_pull(skb, payload - skb->data)) {
415427
if (inet_sk(sk)->recverr_rfc4884)
416-
ip_icmp_error_rfc4884(skb, &serr->ee.ee_rfc4884);
428+
ipv4_icmp_error_rfc4884(skb, &serr->ee.ee_rfc4884);
417429

418430
skb_reset_transport_header(skb);
419431
if (sock_queue_err_skb(sk, skb) == 0)

‎net/ipv6/datagram.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/route.h>
2020
#include <linux/slab.h>
2121
#include <linux/export.h>
22+
#include <linux/icmp.h>
2223

2324
#include <net/ipv6.h>
2425
#include <net/ndisc.h>
@@ -284,6 +285,17 @@ int ip6_datagram_connect_v6_only(struct sock *sk, struct sockaddr *uaddr,
284285
}
285286
EXPORT_SYMBOL_GPL(ip6_datagram_connect_v6_only);
286287

288+
static void ipv6_icmp_error_rfc4884(const struct sk_buff *skb,
289+
struct sock_ee_data_rfc4884 *out)
290+
{
291+
switch (icmp6_hdr(skb)->icmp6_type) {
292+
case ICMPV6_TIME_EXCEED:
293+
case ICMPV6_DEST_UNREACH:
294+
ip_icmp_error_rfc4884(skb, out, sizeof(struct icmp6hdr),
295+
icmp6_hdr(skb)->icmp6_datagram_len * 8);
296+
}
297+
}
298+
287299
void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err,
288300
__be16 port, u32 info, u8 *payload)
289301
{
@@ -313,6 +325,10 @@ void ipv6_icmp_error(struct sock *sk, struct sk_buff *skb, int err,
313325
serr->port = port;
314326

315327
__skb_pull(skb, payload - skb->data);
328+
329+
if (inet6_sk(sk)->recverr_rfc4884)
330+
ipv6_icmp_error_rfc4884(skb, &serr->ee.ee_rfc4884);
331+
316332
skb_reset_transport_header(skb);
317333

318334
if (sock_queue_err_skb(sk, skb))

‎net/ipv6/ipv6_sockglue.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,14 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
965965
np->rxopt.bits.recvfragsize = valbool;
966966
retv = 0;
967967
break;
968+
case IPV6_RECVERR_RFC4884:
969+
if (optlen < sizeof(int))
970+
goto e_inval;
971+
if (val < 0 || val > 1)
972+
goto e_inval;
973+
np->recverr_rfc4884 = valbool;
974+
retv = 0;
975+
break;
968976
}
969977

970978
release_sock(sk);
@@ -1439,6 +1447,10 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
14391447
val = np->rtalert_isolate;
14401448
break;
14411449

1450+
case IPV6_RECVERR_RFC4884:
1451+
val = np->recverr_rfc4884;
1452+
break;
1453+
14421454
default:
14431455
return -ENOPROTOOPT;
14441456
}

0 commit comments

Comments
 (0)