diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2006-10-11 09:29:21 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2006-10-11 09:29:21 +0000 |
commit | 38d0057501a91a9d902cdb4a7ed20385b9613034 (patch) | |
tree | b970c268320ff7656c424ff27cfb61d1e92f497d /sys/netinet | |
parent | 99c080a083c1cc366cfc123fed9104129efbd87f (diff) |
implement IP_RECVTTL socket option.
when set on raw or udp sockets, userland receives the incoming packet's TTL
as ancillary data (cmsg shitz). modeled after the FreeBSD implementation.
ok claudio djm deraadt
Diffstat (limited to 'sys/netinet')
-rw-r--r-- | sys/netinet/in.h | 3 | ||||
-rw-r--r-- | sys/netinet/in_pcb.h | 5 | ||||
-rw-r--r-- | sys/netinet/ip_input.c | 8 | ||||
-rw-r--r-- | sys/netinet/ip_output.c | 11 |
4 files changed, 22 insertions, 5 deletions
diff --git a/sys/netinet/in.h b/sys/netinet/in.h index eb27cf0b2cb..22923c5352c 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in.h,v 1.71 2006/06/18 11:47:45 pascoe Exp $ */ +/* $OpenBSD: in.h,v 1.72 2006/10/11 09:29:20 henning Exp $ */ /* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */ /* @@ -265,6 +265,7 @@ struct ip_opts { #define IP_IPSEC_REMOTE_AUTH 28 /* buf; IPsec remote auth material */ #define IP_IPCOMP_LEVEL 29 /* int; compression used */ #define IP_RECVIF 30 /* bool; receive reception if w/dgram */ +#define IP_RECVTTL 31 /* bool; receive IP TTL w/dgram */ /* * Security levels - IPsec, not IPSO diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index a6a0d22e021..28614c186c7 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.h,v 1.55 2006/09/26 21:10:53 deraadt Exp $ */ +/* $OpenBSD: in_pcb.h,v 1.56 2006/10/11 09:29:20 henning Exp $ */ /* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */ /* @@ -168,9 +168,10 @@ struct inpcbtable { #define INP_HIGHPORT 0x010 /* user wants "high" port binding */ #define INP_LOWPORT 0x020 /* user wants "low" port binding */ #define INP_RECVIF 0x080 /* receive incoming interface */ +#define INP_RECVTTL 0x040 /* receive incoming IP TTL */ #define INP_CONTROLOPTS (INP_RECVOPTS|INP_RECVRETOPTS|INP_RECVDSTADDR| \ - INP_RXSRCRT|INP_HOPLIMIT|INP_RECVIF) + INP_RXSRCRT|INP_HOPLIMIT|INP_RECVIF|INP_RECVTTL) /* * These flags' values should be determined by either the transport diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 29803454585..366fb593b16 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_input.c,v 1.143 2006/06/18 12:03:19 pascoe Exp $ */ +/* $OpenBSD: ip_input.c,v 1.144 2006/10/11 09:29:20 henning Exp $ */ /* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */ /* @@ -1697,5 +1697,11 @@ ip_savecontrol(struct inpcb *inp, struct mbuf **mp, struct ip *ip, 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; + } } diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 65e8698445f..3a42e2f72b0 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_output.c,v 1.180 2006/06/18 11:47:45 pascoe Exp $ */ +/* $OpenBSD: ip_output.c,v 1.181 2006/10/11 09:29:20 henning Exp $ */ /* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */ /* @@ -1048,6 +1048,7 @@ ip_ctloutput(op, so, level, optname, mp) case IP_RECVRETOPTS: case IP_RECVDSTADDR: case IP_RECVIF: + case IP_RECVTTL: if (m == NULL || m->m_len != sizeof(int)) error = EINVAL; else { @@ -1061,6 +1062,7 @@ ip_ctloutput(op, so, level, optname, mp) case IP_TTL: inp->inp_ip.ip_ttl = optval; break; + #define OPTSET(bit) \ if (optval) \ inp->inp_flags |= bit; \ @@ -1081,6 +1083,9 @@ ip_ctloutput(op, so, level, optname, mp) case IP_RECVIF: OPTSET(INP_RECVIF); break; + case IP_RECVTTL: + OPTSET(INP_RECVTTL); + break; } } break; @@ -1383,6 +1388,7 @@ ip_ctloutput(op, so, level, optname, mp) case IP_RECVRETOPTS: case IP_RECVDSTADDR: case IP_RECVIF: + case IP_RECVTTL: *mp = m = m_get(M_WAIT, MT_SOOPTS); m->m_len = sizeof(int); switch (optname) { @@ -1411,6 +1417,9 @@ ip_ctloutput(op, so, level, optname, mp) case IP_RECVIF: optval = OPTBIT(INP_RECVIF); break; + case IP_RECVTTL: + optval = OPTBIT(INP_RECVTTL); + break; } *mtod(m, int *) = optval; break; |