Implement IP_DONTFRAG IP socket option enabling the Don't Fragment

flag on IP packets.  Currently this option is only repected on udp
and raw ip sockets.  On tcp sockets the DF flag is controlled by the
path MTU discovery option.

Sending a packet larger than the MTU size of the egress interface
returns an EMSGSIZE error.

Discussed with:	rwatson
Sponsored by:	TCP/IP Optimization Fundraise 2005
This commit is contained in:
Andre Oppermann 2005-09-26 20:25:16 +00:00
parent 25067ba265
commit b2828ad291
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=150594
5 changed files with 24 additions and 2 deletions

View File

@ -416,6 +416,7 @@ __END_DECLS
#define IP_RECVTTL 65 /* bool; receive IP TTL w/dgram */
#define IP_MINTTL 66 /* minimum TTL for packet or drop */
#define IP_DONTFRAG 67 /* don't fragment packet */
/*
* Defaults and limits for options

View File

@ -283,6 +283,7 @@ struct inpcbinfo { /* XXX documentation, prefixes */
#define INP_MTUDISC 0x100 /* user can do MTU discovery */
#define INP_FAITH 0x200 /* accept FAITH'ed connections */
#define INP_RECVTTL 0x400 /* receive incoming IP TTL */
#define INP_DONTFRAG 0x800 /* don't fragment packet */
#define IN6P_IPV6_V6ONLY 0x008000 /* restrict AF_INET6 socket for v6 */

View File

@ -142,7 +142,7 @@ ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro,
#endif /* FAST_IPSEC */
M_ASSERTPKTHDR(m);
if (ro == NULL) {
ro = &iproute;
bzero(ro, sizeof (*ro));
@ -1197,6 +1197,7 @@ ip_ctloutput(so, sopt)
case IP_RECVIF:
case IP_FAITH:
case IP_ONESBCAST:
case IP_DONTFRAG:
error = sooptcopyin(sopt, &optval, sizeof optval,
sizeof optval);
if (error)
@ -1254,6 +1255,9 @@ ip_ctloutput(so, sopt)
case IP_ONESBCAST:
OPTSET(INP_ONESBCAST);
break;
case IP_DONTFRAG:
OPTSET(INP_DONTFRAG);
break;
}
break;
#undef OPTSET
@ -1351,6 +1355,7 @@ ip_ctloutput(so, sopt)
case IP_PORTRANGE:
case IP_FAITH:
case IP_ONESBCAST:
case IP_DONTFRAG:
switch (sopt->sopt_name) {
case IP_TOS:
@ -1403,6 +1408,9 @@ ip_ctloutput(so, sopt)
case IP_ONESBCAST:
optval = OPTBIT(INP_ONESBCAST);
break;
case IP_DONTFRAG:
optval = OPTBIT(INP_DONTFRAG);
break;
}
error = sooptcopyout(sopt, &optval, sizeof optval);
break;

View File

@ -271,7 +271,10 @@ rip_output(struct mbuf *m, struct socket *so, u_long dst)
INP_LOCK(inp);
ip = mtod(m, struct ip *);
ip->ip_tos = inp->inp_ip_tos;
ip->ip_off = 0;
if (inp->inp_flags & INP_DONTFRAG)
ip->ip_off = IP_DF;
else
ip->ip_off = 0;
ip->ip_p = inp->inp_ip_p;
ip->ip_len = m->m_pkthdr.len;
if (jailed(inp->inp_socket->so_cred))

View File

@ -846,6 +846,15 @@ udp_output(inp, m, addr, control, td)
ui->ui_dport = fport;
ui->ui_ulen = htons((u_short)len + sizeof(struct udphdr));
/*
* Set the Don't Fragment bit in the IP header.
*/
if (inp->inp_flags & INP_DONTFRAG) {
struct ip *ip;
ip = (struct ip *)&ui->ui_i;
ip->ip_off |= IP_DF;
}
ipflags = 0;
if (inp->inp_socket->so_options & SO_DONTROUTE)
ipflags |= IP_ROUTETOIF;