summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--share/man/man4/ip.422
-rw-r--r--sys/netinet/in.h2
-rw-r--r--sys/netinet/in_pcb.h3
-rw-r--r--sys/netinet/ip_input.c6
-rw-r--r--sys/netinet/ip_output.c10
5 files changed, 42 insertions, 1 deletions
diff --git a/share/man/man4/ip.4 b/share/man/man4/ip.4
index 93bf0de..14f8592 100644
--- a/share/man/man4/ip.4
+++ b/share/man/man4/ip.4
@@ -164,6 +164,28 @@ control message from
can be used directly as a control message for
.Xr sendmsg 2 .
.Pp
+If the
+.Dv IP_RECVTTL
+option is enabled on a
+.Dv SOCK_DGRAM
+socket, the
+.Xr recvmsg 2
+call will return the
+.Tn IP
+.Tn TTL
+(time to live) 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 TTL .
+The cmsghdr fields have the following values:
+.Bd -literal
+cmsg_len = sizeof(u_char)
+cmsg_level = IPPROTO_IP
+cmsg_type = IP_RECVTTL
+.Ed
+.Pp
If the
.Dv IP_RECVIF
option is enabled on a
diff --git a/sys/netinet/in.h b/sys/netinet/in.h
index 83eeae7..0144416 100644
--- a/sys/netinet/in.h
+++ b/sys/netinet/in.h
@@ -399,6 +399,8 @@ __END_DECLS
#define IP_DUMMYNET_FLUSH 62 /* flush dummynet */
#define IP_DUMMYNET_GET 64 /* get entire dummynet pipes */
+#define IP_RECVTTL 65 /* bool; receive IP TTL w/dgram */
+
/*
* Defaults and limits for options
*/
diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h
index efb7862..9893af6 100644
--- a/sys/netinet/in_pcb.h
+++ b/sys/netinet/in_pcb.h
@@ -276,6 +276,7 @@ struct inpcbinfo { /* XXX documentation, prefixes */
#define INP_RECVIF 0x80 /* receive incoming interface */
#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 IN6P_IPV6_V6ONLY 0x008000 /* restrict AF_INET6 socket for v6 */
@@ -288,7 +289,7 @@ struct inpcbinfo { /* XXX documentation, prefixes */
#define IN6P_AUTOFLOWLABEL 0x800000 /* attach flowlabel automatically */
#define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR|\
- INP_RECVIF|\
+ INP_RECVIF|INP_RECVTTL|\
IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\
IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\
IN6P_AUTOFLOWLABEL)
diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c
index 5cf4ff4..32f2b6d 100644
--- a/sys/netinet/ip_input.c
+++ b/sys/netinet/ip_input.c
@@ -2052,6 +2052,12 @@ ip_savecontrol(inp, mp, ip, m)
if (*mp)
mp = &(*mp)->m_next;
}
+ if (inp->inp_flags & INP_RECVTTL) {
+ *mp = sbcreatecontrol((caddr_t) &ip->ip_ttl,
+ sizeof(u_char), IP_RECVTTL, IPPROTO_IP);
+ if (*mp)
+ mp = &(*mp)->m_next;
+ }
#ifdef notyet
/* XXX
* Moving these out of udp_input() made them even more broken
diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c
index 1a28ed7..773768c 100644
--- a/sys/netinet/ip_output.c
+++ b/sys/netinet/ip_output.c
@@ -1424,6 +1424,7 @@ ip_ctloutput(so, sopt)
case IP_RECVOPTS:
case IP_RECVRETOPTS:
case IP_RECVDSTADDR:
+ case IP_RECVTTL:
case IP_RECVIF:
case IP_FAITH:
error = sooptcopyin(sopt, &optval, sizeof optval,
@@ -1457,6 +1458,10 @@ ip_ctloutput(so, sopt)
OPTSET(INP_RECVDSTADDR);
break;
+ case IP_RECVTTL:
+ OPTSET(INP_RECVTTL);
+ break;
+
case IP_RECVIF:
OPTSET(INP_RECVIF);
break;
@@ -1553,6 +1558,7 @@ ip_ctloutput(so, sopt)
case IP_RECVOPTS:
case IP_RECVRETOPTS:
case IP_RECVDSTADDR:
+ case IP_RECVTTL:
case IP_RECVIF:
case IP_PORTRANGE:
case IP_FAITH:
@@ -1580,6 +1586,10 @@ ip_ctloutput(so, sopt)
optval = OPTBIT(INP_RECVDSTADDR);
break;
+ case IP_RECVTTL:
+ optval = OPTBIT(INP_RECVTTL);
+ break;
+
case IP_RECVIF:
optval = OPTBIT(INP_RECVIF);
break;
OpenPOWER on IntegriCloud