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:
parent
25067ba265
commit
b2828ad291
@ -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
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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;
|
||||
|
@ -271,6 +271,9 @@ 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;
|
||||
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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user