Skip to content

Commit 793b147

Browse files
Brian Haleydavem330
authored andcommitted
IPv6: data structure changes for new socket options
Add underlying data structure changes and basic setsockopt() and getsockopt() support for IPV6_RECVPATHMTU, IPV6_PATHMTU, and IPV6_DONTFRAG. IPV6_PATHMTU is actually fully functional at this point. Signed-off-by: Brian Haley <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3a73702 commit 793b147

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

include/linux/in6.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,10 @@ struct in6_flowlabel_req {
221221
#define IPV6_RTHDR 57
222222
#define IPV6_RECVDSTOPTS 58
223223
#define IPV6_DSTOPTS 59
224-
#if 0 /* not yet */
225224
#define IPV6_RECVPATHMTU 60
226225
#define IPV6_PATHMTU 61
227226
#define IPV6_DONTFRAG 62
227+
#if 0 /* not yet */
228228
#define IPV6_USE_MIN_MTU 63
229229
#endif
230230

include/linux/ipv6.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ struct in6_pktinfo {
2121
int ipi6_ifindex;
2222
};
2323

24+
struct ip6_mtuinfo {
25+
struct sockaddr_in6 ip6m_addr;
26+
__u32 ip6m_mtu;
27+
};
2428

2529
struct in6_ifreq {
2630
struct in6_addr ifr6_addr;
@@ -334,22 +338,25 @@ struct ipv6_pinfo {
334338
dstopts:1,
335339
odstopts:1,
336340
rxflow:1,
337-
rxtclass:1;
341+
rxtclass:1,
342+
rxpmtu:1;
338343
} bits;
339344
__u16 all;
340345
} rxopt;
341346

342347
/* sockopt flags */
343-
__u8 recverr:1,
348+
__u16 recverr:1,
344349
sndflow:1,
345350
pmtudisc:2,
346351
ipv6only:1,
347-
srcprefs:3; /* 001: prefer temporary address
352+
srcprefs:3, /* 001: prefer temporary address
348353
* 010: prefer public address
349354
* 100: prefer care-of address
350355
*/
356+
dontfrag:1;
351357
__u8 min_hopcount;
352358
__u8 tclass;
359+
__u8 padding;
353360

354361
__u32 dst_cookie;
355362

net/ipv6/ipv6_sockglue.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,13 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
337337
retv = 0;
338338
break;
339339

340+
case IPV6_RECVPATHMTU:
341+
if (optlen < sizeof(int))
342+
goto e_inval;
343+
np->rxopt.bits.rxpmtu = valbool;
344+
retv = 0;
345+
break;
346+
340347
case IPV6_HOPOPTS:
341348
case IPV6_RTHDRDSTOPTS:
342349
case IPV6_RTHDR:
@@ -773,6 +780,9 @@ static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
773780
if (val < 0 || val > 255)
774781
goto e_inval;
775782
np->min_hopcount = val;
783+
break;
784+
case IPV6_DONTFRAG:
785+
np->dontfrag = valbool;
776786
retv = 0;
777787
break;
778788
}
@@ -1063,6 +1073,38 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
10631073
val = np->rxopt.bits.rxflow;
10641074
break;
10651075

1076+
case IPV6_RECVPATHMTU:
1077+
val = np->rxopt.bits.rxpmtu;
1078+
break;
1079+
1080+
case IPV6_PATHMTU:
1081+
{
1082+
struct dst_entry *dst;
1083+
struct ip6_mtuinfo mtuinfo;
1084+
1085+
if (len < sizeof(mtuinfo))
1086+
return -EINVAL;
1087+
1088+
len = sizeof(mtuinfo);
1089+
memset(&mtuinfo, 0, sizeof(mtuinfo));
1090+
1091+
rcu_read_lock();
1092+
dst = __sk_dst_get(sk);
1093+
if (dst)
1094+
mtuinfo.ip6m_mtu = dst_mtu(dst);
1095+
rcu_read_unlock();
1096+
if (!mtuinfo.ip6m_mtu)
1097+
return -ENOTCONN;
1098+
1099+
if (put_user(len, optlen))
1100+
return -EFAULT;
1101+
if (copy_to_user(optval, &mtuinfo, len))
1102+
return -EFAULT;
1103+
1104+
return 0;
1105+
break;
1106+
}
1107+
10661108
case IPV6_UNICAST_HOPS:
10671109
case IPV6_MULTICAST_HOPS:
10681110
{
@@ -1128,6 +1170,10 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
11281170
val = np->min_hopcount;
11291171
break;
11301172

1173+
case IPV6_DONTFRAG:
1174+
val = np->dontfrag;
1175+
break;
1176+
11311177
default:
11321178
return -ENOPROTOOPT;
11331179
}

0 commit comments

Comments
 (0)