svn commit: r247944 - in stable/8: lib/libc/net share/man/man4 sys/netinet
Michael Tuexen
tuexen at FreeBSD.org
Thu Mar 7 21:17:39 UTC 2013
Author: tuexen
Date: Thu Mar 7 21:17:37 2013
New Revision: 247944
URL: http://svnweb.freebsd.org/changeset/base/247944
Log:
MFC r236959:
Add a IP_RECVTOS socket option to receive for received UDP/IPv4
packets a cmsg of type IP_RECVTOS which contains the TOS byte.
Much like IP_RECVTTL does for TTL. This allows to implement a
protocol on top of UDP and implementing ECN.
Modified:
stable/8/lib/libc/net/sctp_sys_calls.c
stable/8/share/man/man4/ip.4
stable/8/sys/netinet/in.h
stable/8/sys/netinet/in_pcb.c
stable/8/sys/netinet/in_pcb.h
stable/8/sys/netinet/ip_input.c
stable/8/sys/netinet/ip_output.c
Directory Properties:
stable/8/ (props changed)
stable/8/lib/ (props changed)
stable/8/lib/libc/ (props changed)
stable/8/share/ (props changed)
stable/8/share/man/ (props changed)
stable/8/share/man/man4/ (props changed)
stable/8/sys/ (props changed)
stable/8/sys/netinet/ (props changed)
Modified: stable/8/lib/libc/net/sctp_sys_calls.c
==============================================================================
--- stable/8/lib/libc/net/sctp_sys_calls.c Thu Mar 7 21:11:16 2013 (r247943)
+++ stable/8/lib/libc/net/sctp_sys_calls.c Thu Mar 7 21:17:37 2013 (r247944)
@@ -1,7 +1,7 @@
/*-
* Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
- * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved.
- * Copyright (c) 2008-2011, by Michael Tuexen. All rights reserved.
+ * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
+ * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -32,6 +32,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+
#include <stdio.h>
#include <string.h>
#include <errno.h>
Modified: stable/8/share/man/man4/ip.4
==============================================================================
--- stable/8/share/man/man4/ip.4 Thu Mar 7 21:11:16 2013 (r247943)
+++ stable/8/share/man/man4/ip.4 Thu Mar 7 21:17:37 2013 (r247944)
@@ -32,7 +32,7 @@
.\" @(#)ip.4 8.2 (Berkeley) 11/30/93
.\" $FreeBSD$
.\"
-.Dd June 1, 2009
+.Dd June 12, 2012
.Dt IP 4
.Os
.Sh NAME
@@ -165,7 +165,7 @@ The
.Vt cmsghdr
fields have the following values:
.Bd -literal
-cmsg_len = sizeof(struct in_addr)
+cmsg_len = CMSG_LEN(sizeof(struct in_addr))
cmsg_level = IPPROTO_IP
cmsg_type = IP_RECVDSTADDR
.Ed
@@ -184,7 +184,7 @@ structure followed by the
address.
The cmsghdr fields should have the following values:
.Bd -literal
-cmsg_len = sizeof(struct in_addr)
+cmsg_len = CMSG_LEN(sizeof(struct in_addr))
cmsg_level = IPPROTO_IP
cmsg_type = IP_SENDSRCADDR
.Ed
@@ -279,13 +279,36 @@ that contains a cmsghdr structure follow
.Tn TTL .
The cmsghdr fields have the following values:
.Bd -literal
-cmsg_len = sizeof(u_char)
+cmsg_len = CMSG_LEN(sizeof(u_char))
cmsg_level = IPPROTO_IP
cmsg_type = IP_RECVTTL
.Ed
.\"
.Pp
If the
+.Dv IP_RECVTOS
+option is enabled on a
+.Dv SOCK_DGRAM
+socket, the
+.Xr recvmsg 2
+call will return the
+.Tn IP
+.Tn TOS
+(type of service) field for a
+.Tn UDP
+datagram.
+The msg_control field in the msghdr structure points to a buffer
+that contains a cmsghdr structure followed by the
+.Tn TOS .
+The cmsghdr fields have the following values:
+.Bd -literal
+cmsg_len = CMSG_LEN(sizeof(u_char))
+cmsg_level = IPPROTO_IP
+cmsg_type = IP_RECVTOS
+.Ed
+.\"
+.Pp
+If the
.Dv IP_RECVIF
option is enabled on a
.Dv SOCK_DGRAM
@@ -307,7 +330,7 @@ The
.Vt cmsghdr
fields have the following values:
.Bd -literal
-cmsg_len = sizeof(struct sockaddr_dl)
+cmsg_len = CMSG_LEN(sizeof(struct sockaddr_dl))
cmsg_level = IPPROTO_IP
cmsg_type = IP_RECVIF
.Ed
Modified: stable/8/sys/netinet/in.h
==============================================================================
--- stable/8/sys/netinet/in.h Thu Mar 7 21:11:16 2013 (r247943)
+++ stable/8/sys/netinet/in.h Thu Mar 7 21:17:37 2013 (r247944)
@@ -477,6 +477,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 */
+#define IP_RECVTOS 68 /* bool; receive IP TOS w/dgram */
/* IPv4 Source Filter Multicast API [RFC3678] */
#define IP_ADD_SOURCE_MEMBERSHIP 70 /* join a source-specific group */
Modified: stable/8/sys/netinet/in_pcb.c
==============================================================================
--- stable/8/sys/netinet/in_pcb.c Thu Mar 7 21:11:16 2013 (r247943)
+++ stable/8/sys/netinet/in_pcb.c Thu Mar 7 21:17:37 2013 (r247944)
@@ -1863,6 +1863,10 @@ db_print_inpflags(int inp_flags)
db_printf("%sINP_DONTFRAG", comma ? ", " : "");
comma = 1;
}
+ if (inp_flags & INP_RECVTOS) {
+ db_printf("%sINP_RECVTOS", comma ? ", " : "");
+ comma = 1;
+ }
if (inp_flags & IN6P_IPV6_V6ONLY) {
db_printf("%sIN6P_IPV6_V6ONLY", comma ? ", " : "");
comma = 1;
Modified: stable/8/sys/netinet/in_pcb.h
==============================================================================
--- stable/8/sys/netinet/in_pcb.h Thu Mar 7 21:11:16 2013 (r247943)
+++ stable/8/sys/netinet/in_pcb.h Thu Mar 7 21:17:37 2013 (r247944)
@@ -413,6 +413,7 @@ void inp_4tuple_get(struct inpcb *inp,
#define INP_DONTFRAG 0x00000800 /* don't fragment packet */
#define INP_BINDANY 0x00001000 /* allow bind to any address */
#define INP_INHASHLIST 0x00002000 /* in_pcbinshash() has been called */
+#define INP_RECVTOS 0x00004000 /* receive incoming IP TOS */
#define IN6P_IPV6_V6ONLY 0x00008000 /* restrict AF_INET6 socket for v6 */
#define IN6P_PKTINFO 0x00010000 /* receive IP6 dst and I/F */
#define IN6P_HOPLIMIT 0x00020000 /* receive hoplimit */
@@ -432,7 +433,7 @@ void inp_4tuple_get(struct inpcb *inp,
#define IN6P_MTU 0x80000000 /* receive path MTU */
#define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
- INP_RECVIF|INP_RECVTTL|\
+ INP_RECVIF|INP_RECVTTL|INP_RECVTOS|\
IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\
Modified: stable/8/sys/netinet/ip_input.c
==============================================================================
--- stable/8/sys/netinet/ip_input.c Thu Mar 7 21:11:16 2013 (r247943)
+++ stable/8/sys/netinet/ip_input.c Thu Mar 7 21:17:37 2013 (r247944)
@@ -1711,6 +1711,12 @@ makedummy:
if (*mp)
mp = &(*mp)->m_next;
}
+ if (inp->inp_flags & INP_RECVTOS) {
+ *mp = sbcreatecontrol((caddr_t) &ip->ip_tos,
+ sizeof(u_char), IP_RECVTOS, IPPROTO_IP);
+ if (*mp)
+ mp = &(*mp)->m_next;
+ }
}
/*
Modified: stable/8/sys/netinet/ip_output.c
==============================================================================
--- stable/8/sys/netinet/ip_output.c Thu Mar 7 21:11:16 2013 (r247943)
+++ stable/8/sys/netinet/ip_output.c Thu Mar 7 21:17:37 2013 (r247944)
@@ -956,6 +956,7 @@ ip_ctloutput(struct socket *so, struct s
case IP_FAITH:
case IP_ONESBCAST:
case IP_DONTFRAG:
+ case IP_RECVTOS:
error = sooptcopyin(sopt, &optval, sizeof optval,
sizeof optval);
if (error)
@@ -1019,6 +1020,9 @@ ip_ctloutput(struct socket *so, struct s
case IP_BINDANY:
OPTSET(INP_BINDANY);
break;
+ case IP_RECVTOS:
+ OPTSET(INP_RECVTOS);
+ break;
}
break;
#undef OPTSET
@@ -1128,6 +1132,7 @@ ip_ctloutput(struct socket *so, struct s
case IP_ONESBCAST:
case IP_DONTFRAG:
case IP_BINDANY:
+ case IP_RECVTOS:
switch (sopt->sopt_name) {
case IP_TOS:
@@ -1186,6 +1191,9 @@ ip_ctloutput(struct socket *so, struct s
case IP_BINDANY:
optval = OPTBIT(INP_BINDANY);
break;
+ case IP_RECVTOS:
+ optval = OPTBIT(INP_RECVTOS);
+ break;
}
error = sooptcopyout(sopt, &optval, sizeof optval);
break;
More information about the svn-src-stable
mailing list