Date: Tue, 5 Jun 2012 22:33:54 +0200 From: Michael Tuexen <Michael.Tuexen@lurchi.franken.de> To: "freebsd-net@freebsd.org mailing list" <freebsd-net@freebsd.org> Subject: IP_RECVTOS Message-ID: <1D03F00E-2777-4B0B-8E1C-860EA115B6AF@lurchi.franken.de>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
Dear all,
there is currently no way to receive the TOS byte of a received UDP/IPv4 packet.
The attached patch adds a socket option (IP_RECVTOS) which you can use
to get a cmsg of type (IP_RECVTOS) which contains the TOS byte. Much like
IP_RECVTTL does for TTL. Any comments/objections? If there are none, I would
like to commit this to head soon.
Best regards
Michael
[-- Attachment #2 --]
Index: in.h
===================================================================
--- in.h (revision 236601)
+++ in.h (working copy)
@@ -462,6 +462,7 @@
#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 */
Index: in_pcb.c
===================================================================
--- in_pcb.c (revision 236601)
+++ in_pcb.c (working copy)
@@ -2295,6 +2295,10 @@
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;
Index: in_pcb.h
===================================================================
--- in_pcb.h (revision 236601)
+++ in_pcb.h (working copy)
@@ -509,6 +509,7 @@
#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 */
@@ -528,7 +529,7 @@
#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|\
Index: ip_output.c
===================================================================
--- ip_output.c (revision 236601)
+++ ip_output.c (working copy)
@@ -984,6 +984,7 @@
case IP_FAITH:
case IP_ONESBCAST:
case IP_DONTFRAG:
+ case IP_RECVTOS:
error = sooptcopyin(sopt, &optval, sizeof optval,
sizeof optval);
if (error)
@@ -1047,6 +1048,9 @@
case IP_BINDANY:
OPTSET(INP_BINDANY);
break;
+ case IP_RECVTOS:
+ OPTSET(INP_RECVTOS);
+ break;
}
break;
#undef OPTSET
@@ -1156,6 +1160,7 @@
case IP_ONESBCAST:
case IP_DONTFRAG:
case IP_BINDANY:
+ case IP_RECVTOS:
switch (sopt->sopt_name) {
case IP_TOS:
@@ -1214,6 +1219,9 @@
case IP_BINDANY:
optval = OPTBIT(INP_BINDANY);
break;
+ case IP_RECVTOS:
+ optval = OPTBIT(INP_RECVTOS);
+ break;
}
error = sooptcopyout(sopt, &optval, sizeof optval);
break;
Index: ip_input.c
===================================================================
--- ip_input.c (revision 236601)
+++ ip_input.c (working copy)
@@ -1684,6 +1684,12 @@
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;
+ }
}
/*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1D03F00E-2777-4B0B-8E1C-860EA115B6AF>
