diff options
author | YASUOKA Masahiko <yasuoka@cvs.openbsd.org> | 2012-09-17 20:01:27 +0000 |
---|---|---|
committer | YASUOKA Masahiko <yasuoka@cvs.openbsd.org> | 2012-09-17 20:01:27 +0000 |
commit | 7ae5b4210777fba0c46da75f69da33ac20326c6f (patch) | |
tree | 85cc8a11c1f4039aeb90935008177596da0f4adf /sys | |
parent | 67aae5022f47ddfd5a5fcd6c9d001d3dfc52b80d (diff) |
add IPV6_RECVDSTPORT socket option, which enables us to get original
(= before divert) destination port of a UDP packet. The way to use
this option is same as IP_RECVDSTPORT.
from UMEZAWA Takeshi
tweaks from jmc; ok henning bluhm
Diffstat (limited to 'sys')
-rw-r--r-- | sys/netinet/in_pcb.h | 5 | ||||
-rw-r--r-- | sys/netinet/udp_usrreq.c | 12 | ||||
-rw-r--r-- | sys/netinet6/in6.h | 4 | ||||
-rw-r--r-- | sys/netinet6/ip6_output.c | 11 |
4 files changed, 27 insertions, 5 deletions
diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index 9d4f0d96c91..0ec3cdc01ec 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in_pcb.h,v 1.72 2012/07/16 18:05:36 markus Exp $ */ +/* $OpenBSD: in_pcb.h,v 1.73 2012/09/17 20:01:26 yasuoka Exp $ */ /* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */ /* @@ -196,6 +196,7 @@ struct inpcbtable { */ #define IN6P_HIGHPORT INP_HIGHPORT /* user wants "high" port */ #define IN6P_LOWPORT INP_LOWPORT /* user wants "low" port */ +#define IN6P_RECVDSTPORT INP_RECVDSTPORT /* receive IP dst addr before rdr */ #define IN6P_PKTINFO 0x010000 /* receive IP6 dst and I/F */ #define IN6P_HOPLIMIT 0x020000 /* receive hoplimit */ #define IN6P_HOPOPTS 0x040000 /* receive hop-by-hop options */ @@ -215,7 +216,7 @@ struct inpcbtable { #define IN6P_CONTROLOPTS (IN6P_PKTINFO|IN6P_HOPLIMIT|IN6P_HOPOPTS|\ IN6P_DSTOPTS|IN6P_RTHDR|IN6P_RTHDRDSTOPTS|\ IN6P_TCLASS|IN6P_AUTOFLOWLABEL|IN6P_RFC2292|\ - IN6P_MTU) + IN6P_MTU|IN6P_RECVDSTPORT) #endif #define INPLOOKUP_WILDCARD 1 diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 5a8d8e596e4..48700af5473 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: udp_usrreq.c,v 1.149 2012/07/17 03:18:57 yasuoka Exp $ */ +/* $OpenBSD: udp_usrreq.c,v 1.150 2012/09/17 20:01:26 yasuoka Exp $ */ /* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */ /* @@ -688,6 +688,16 @@ udp_input(struct mbuf *m, ...) if (ip && (inp->inp_flags & INP_CONTROLOPTS || inp->inp_socket->so_options & SO_TIMESTAMP)) ip_savecontrol(inp, &opts, ip, m); +#ifdef INET6 + if (ip6 && (inp->inp_flags & IN6P_RECVDSTPORT)) { + struct mbuf **mp = &opts; + + while (*mp) + mp = &(*mp)->m_next; + *mp = sbcreatecontrol((caddr_t)&uh->uh_dport, sizeof(u_int16_t), + IPV6_RECVDSTPORT, IPPROTO_IPV6); + } +#endif /* INET6 */ if (ip && (inp->inp_flags & INP_RECVDSTPORT)) { struct mbuf **mp = &opts; diff --git a/sys/netinet6/in6.h b/sys/netinet6/in6.h index 70a5f0858c6..9bbec7df68d 100644 --- a/sys/netinet6/in6.h +++ b/sys/netinet6/in6.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in6.h,v 1.58 2012/09/15 00:47:08 guenther Exp $ */ +/* $OpenBSD: in6.h,v 1.59 2012/09/17 20:01:26 yasuoka Exp $ */ /* $KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $ */ /* @@ -451,6 +451,8 @@ struct route_in6 { #define IPV6_DONTFRAG 62 /* bool; disable IPv6 fragmentation */ #define IPV6_PIPEX 63 /* bool; using PIPEX */ +#define IPV6_RECVDSTPORT 64 /* bool; receive IP dst port w/dgram */ + #define IPV6_RTABLE 0x1021 /* int; routing table, see SO_RTABLE */ /* to define items, should talk with KAME guys first, for *BSD compatibility */ diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index 07aedeed4d2..05126b62c7f 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip6_output.c,v 1.125 2012/07/16 18:05:36 markus Exp $ */ +/* $OpenBSD: ip6_output.c,v 1.126 2012/09/17 20:01:26 yasuoka Exp $ */ /* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */ /* @@ -1356,6 +1356,7 @@ ip6_ctloutput(int op, struct socket *so, int level, int optname, case IPV6_RECVTCLASS: case IPV6_V6ONLY: case IPV6_AUTOFLOWLABEL: + case IPV6_RECVDSTPORT: if (m == NULL || m->m_len != sizeof(int)) { error = EINVAL; break; @@ -1504,6 +1505,9 @@ do { \ OPTSET(IN6P_AUTOFLOWLABEL); break; + case IPV6_RECVDSTPORT: + OPTSET(IN6P_RECVDSTPORT); + break; } break; @@ -1766,6 +1770,7 @@ do { \ case IPV6_PORTRANGE: case IPV6_RECVTCLASS: case IPV6_AUTOFLOWLABEL: + case IPV6_RECVDSTPORT: switch (optname) { case IPV6_RECVHOPOPTS: @@ -1827,6 +1832,10 @@ do { \ case IPV6_AUTOFLOWLABEL: optval = OPTBIT(IN6P_AUTOFLOWLABEL); break; + + case IPV6_RECVDSTPORT: + optval = OPTBIT(IN6P_RECVDSTPORT); + break; } if (error) break; |