version 1.175, 2009/03/18 16:00:22 |
version 1.188, 2013/06/04 22:47:37 |
Line 118 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 118 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <net/if_faith.h> |
#include <net/if_faith.h> |
#endif |
#endif |
|
|
#include <machine/stdarg.h> |
|
|
|
#ifdef FAST_IPSEC |
#ifdef FAST_IPSEC |
#include <netipsec/ipsec.h> |
#include <netipsec/ipsec.h> |
#include <netipsec/ipsec_var.h> |
#include <netipsec/ipsec_var.h> |
Line 130 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 128 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#endif |
#endif |
#endif /* FAST_IPSEC */ |
#endif /* FAST_IPSEC */ |
|
|
#ifdef IPSEC |
|
#include <netinet6/ipsec.h> |
|
#include <netinet6/ipsec_private.h> |
|
#include <netinet6/esp.h> |
|
#include <netkey/key.h> |
|
#endif /* IPSEC */ |
|
|
|
#ifdef COMPAT_50 |
#ifdef COMPAT_50 |
#include <compat/sys/socket.h> |
#include <compat/sys/socket.h> |
#endif |
#endif |
Line 157 struct inpcbtable udbtable; |
|
Line 148 struct inpcbtable udbtable; |
|
percpu_t *udpstat_percpu; |
percpu_t *udpstat_percpu; |
|
|
#ifdef INET |
#ifdef INET |
#ifdef IPSEC_NAT_T |
|
static int udp4_espinudp (struct mbuf **, int, struct sockaddr *, |
static int udp4_espinudp (struct mbuf **, int, struct sockaddr *, |
struct socket *); |
struct socket *); |
#endif |
|
static void udp4_sendup (struct mbuf *, int, struct sockaddr *, |
static void udp4_sendup (struct mbuf *, int, struct sockaddr *, |
struct socket *); |
struct socket *); |
static int udp4_realinput (struct sockaddr_in *, struct sockaddr_in *, |
static int udp4_realinput (struct sockaddr_in *, struct sockaddr_in *, |
Line 232 EVCNT_ATTACH_STATIC(udp6_swcsum); |
|
Line 221 EVCNT_ATTACH_STATIC(udp6_swcsum); |
|
|
|
#endif /* UDP_CSUM_COUNTERS */ |
#endif /* UDP_CSUM_COUNTERS */ |
|
|
|
static void sysctl_net_inet_udp_setup(struct sysctllog **); |
|
|
void |
void |
udp_init(void) |
udp_init(void) |
{ |
{ |
|
|
|
sysctl_net_inet_udp_setup(NULL); |
|
|
in_pcbinit(&udbtable, udbhashsize, udbhashsize); |
in_pcbinit(&udbtable, udbhashsize, udbhashsize); |
|
|
MOWNER_ATTACH(&udp_tx_mowner); |
MOWNER_ATTACH(&udp_tx_mowner); |
Line 409 udp_input(struct mbuf *m, ...) |
|
Line 402 udp_input(struct mbuf *m, ...) |
|
UDP_STATINC(UDP_STAT_HDROPS); |
UDP_STATINC(UDP_STAT_HDROPS); |
return; |
return; |
} |
} |
|
if (m == NULL) { |
|
/* |
|
* packet has been processed by ESP stuff - |
|
* e.g. dropped NAT-T-keep-alive-packet ... |
|
*/ |
|
return; |
|
} |
|
ip = mtod(m, struct ip *); |
#ifdef INET6 |
#ifdef INET6 |
if (IN_MULTICAST(ip->ip_dst.s_addr) || n == 0) { |
if (IN_MULTICAST(ip->ip_dst.s_addr) || n == 0) { |
struct sockaddr_in6 src6, dst6; |
struct sockaddr_in6 src6, dst6; |
Line 417 udp_input(struct mbuf *m, ...) |
|
Line 418 udp_input(struct mbuf *m, ...) |
|
src6.sin6_family = AF_INET6; |
src6.sin6_family = AF_INET6; |
src6.sin6_len = sizeof(struct sockaddr_in6); |
src6.sin6_len = sizeof(struct sockaddr_in6); |
src6.sin6_addr.s6_addr[10] = src6.sin6_addr.s6_addr[11] = 0xff; |
src6.sin6_addr.s6_addr[10] = src6.sin6_addr.s6_addr[11] = 0xff; |
bcopy(&ip->ip_src, &src6.sin6_addr.s6_addr[12], |
memcpy(&src6.sin6_addr.s6_addr[12], &ip->ip_src, |
sizeof(ip->ip_src)); |
sizeof(ip->ip_src)); |
src6.sin6_port = uh->uh_sport; |
src6.sin6_port = uh->uh_sport; |
memset(&dst6, 0, sizeof(dst6)); |
memset(&dst6, 0, sizeof(dst6)); |
dst6.sin6_family = AF_INET6; |
dst6.sin6_family = AF_INET6; |
dst6.sin6_len = sizeof(struct sockaddr_in6); |
dst6.sin6_len = sizeof(struct sockaddr_in6); |
dst6.sin6_addr.s6_addr[10] = dst6.sin6_addr.s6_addr[11] = 0xff; |
dst6.sin6_addr.s6_addr[10] = dst6.sin6_addr.s6_addr[11] = 0xff; |
bcopy(&ip->ip_dst, &dst6.sin6_addr.s6_addr[12], |
memcpy(&dst6.sin6_addr.s6_addr[12], &ip->ip_dst, |
sizeof(ip->ip_dst)); |
sizeof(ip->ip_dst)); |
dst6.sin6_port = uh->uh_dport; |
dst6.sin6_port = uh->uh_dport; |
|
|
Line 631 udp4_sendup(struct mbuf *m, int off /* o |
|
Line 632 udp4_sendup(struct mbuf *m, int off /* o |
|
return; |
return; |
} |
} |
|
|
#if defined(IPSEC) || defined(FAST_IPSEC) |
#if defined(FAST_IPSEC) |
/* check AH/ESP integrity. */ |
/* check AH/ESP integrity. */ |
if (so != NULL && ipsec4_in_reject_so(m, so)) { |
if (so != NULL && ipsec4_in_reject_so(m, so)) { |
IPSEC_STATINC(IPSEC_STAT_IN_POLVIO); |
IPSEC_STATINC(IPSEC_STAT_IN_POLVIO); |
Line 681 udp6_sendup(struct mbuf *m, int off /* o |
|
Line 682 udp6_sendup(struct mbuf *m, int off /* o |
|
return; |
return; |
in6p = sotoin6pcb(so); |
in6p = sotoin6pcb(so); |
|
|
#if defined(IPSEC) || defined(FAST_IPSEC) |
#if defined(FAST_IPSEC) |
/* check AH/ESP integrity. */ |
/* check AH/ESP integrity. */ |
if (so != NULL && ipsec6_in_reject_so(m, so)) { |
if (so != NULL && ipsec6_in_reject_so(m, so)) { |
IPSEC6_STATINC(IPSEC_STAT_IN_POLVIO); |
IPSEC6_STATINC(IPSEC_STAT_IN_POLVIO); |
Line 800 udp4_realinput(struct sockaddr_in *src, |
|
Line 801 udp4_realinput(struct sockaddr_in *src, |
|
/* |
/* |
* Locate pcb for datagram. |
* Locate pcb for datagram. |
*/ |
*/ |
inp = in_pcblookup_connect(&udbtable, *src4, *sport, *dst4, *dport); |
inp = in_pcblookup_connect(&udbtable, *src4, *sport, *dst4, |
|
*dport, 0); |
if (inp == 0) { |
if (inp == 0) { |
UDP_STATINC(UDP_STAT_PCBHASHMISS); |
UDP_STATINC(UDP_STAT_PCBHASHMISS); |
inp = in_pcblookup_bind(&udbtable, *dst4, *dport); |
inp = in_pcblookup_bind(&udbtable, *dst4, *dport); |
Line 808 udp4_realinput(struct sockaddr_in *src, |
|
Line 810 udp4_realinput(struct sockaddr_in *src, |
|
return rcvcnt; |
return rcvcnt; |
} |
} |
|
|
#ifdef IPSEC_NAT_T |
|
/* Handle ESP over UDP */ |
/* Handle ESP over UDP */ |
if (inp->inp_flags & INP_ESPINUDP_ALL) { |
if (inp->inp_flags & INP_ESPINUDP_ALL) { |
struct sockaddr *sa = (struct sockaddr *)src; |
struct sockaddr *sa = (struct sockaddr *)src; |
Line 834 udp4_realinput(struct sockaddr_in *src, |
|
Line 835 udp4_realinput(struct sockaddr_in *src, |
|
break; |
break; |
} |
} |
} |
} |
#endif |
|
|
/* |
|
* Check the minimum TTL for socket. |
|
*/ |
|
if (mtod(m, struct ip *)->ip_ttl < inp->inp_ip_minttl) |
|
goto bad; |
|
|
udp4_sendup(m, off, (struct sockaddr *)src, inp->inp_socket); |
udp4_sendup(m, off, (struct sockaddr *)src, inp->inp_socket); |
rcvcnt++; |
rcvcnt++; |
Line 948 udp6_realinput(int af, struct sockaddr_i |
|
Line 954 udp6_realinput(int af, struct sockaddr_i |
|
* Locate pcb for datagram. |
* Locate pcb for datagram. |
*/ |
*/ |
in6p = in6_pcblookup_connect(&udbtable, &src6, sport, dst6, |
in6p = in6_pcblookup_connect(&udbtable, &src6, sport, dst6, |
dport, 0); |
dport, 0, 0); |
if (in6p == 0) { |
if (in6p == 0) { |
UDP_STATINC(UDP_STAT_PCBHASHMISS); |
UDP_STATINC(UDP_STAT_PCBHASHMISS); |
in6p = in6_pcblookup_bind(&udbtable, dst6, dport, 0); |
in6p = in6_pcblookup_bind(&udbtable, dst6, dport, 0); |
Line 1056 udp_ctloutput(int op, struct socket *so, |
|
Line 1062 udp_ctloutput(int op, struct socket *so, |
|
break; |
break; |
|
|
switch(optval) { |
switch(optval) { |
#ifdef IPSEC_NAT_T |
|
case 0: |
case 0: |
inp->inp_flags &= ~INP_ESPINUDP_ALL; |
inp->inp_flags &= ~INP_ESPINUDP_ALL; |
break; |
break; |
Line 1070 udp_ctloutput(int op, struct socket *so, |
|
Line 1075 udp_ctloutput(int op, struct socket *so, |
|
inp->inp_flags &= ~INP_ESPINUDP_ALL; |
inp->inp_flags &= ~INP_ESPINUDP_ALL; |
inp->inp_flags |= INP_ESPINUDP_NON_IKE; |
inp->inp_flags |= INP_ESPINUDP_NON_IKE; |
break; |
break; |
#endif |
|
default: |
default: |
error = EINVAL; |
error = EINVAL; |
break; |
break; |
} |
} |
break; |
break; |
|
|
default: |
default: |
error = ENOPROTOOPT; |
error = ENOPROTOOPT; |
break; |
break; |
Line 1289 udp_usrreq(struct socket *so, int req, s |
|
Line 1293 udp_usrreq(struct socket *so, int req, s |
|
{ |
{ |
struct in_addr laddr; /* XXX */ |
struct in_addr laddr; /* XXX */ |
|
|
|
memset(&laddr, 0, sizeof laddr); |
if (nam) { |
if (nam) { |
laddr = inp->inp_laddr; /* XXX */ |
laddr = inp->inp_laddr; /* XXX */ |
if ((so->so_state & SS_ISCONNECTED) != 0) { |
if ((so->so_state & SS_ISCONNECTED) != 0) { |
Line 1361 sysctl_net_inet_udp_stats(SYSCTLFN_ARGS) |
|
Line 1366 sysctl_net_inet_udp_stats(SYSCTLFN_ARGS) |
|
/* |
/* |
* Sysctl for udp variables. |
* Sysctl for udp variables. |
*/ |
*/ |
SYSCTL_SETUP(sysctl_net_inet_udp_setup, "sysctl net.inet.udp subtree setup") |
static void |
|
sysctl_net_inet_udp_setup(struct sysctllog **clog) |
{ |
{ |
|
|
sysctl_createv(clog, 0, NULL, NULL, |
sysctl_createv(clog, 0, NULL, NULL, |
CTLFLAG_PERMANENT, |
CTLFLAG_PERMANENT, |
CTLTYPE_NODE, "net", NULL, |
CTLTYPE_NODE, "net", NULL, |
Line 1434 udp_statinc(u_int stat) |
|
Line 1439 udp_statinc(u_int stat) |
|
UDP_STATINC(stat); |
UDP_STATINC(stat); |
} |
} |
|
|
#if (defined INET && defined IPSEC_NAT_T) |
#if defined(INET) |
/* |
/* |
* Returns: |
* Returns: |
* 1 if the packet was processed |
* 1 if the packet was processed |
Line 1452 udp4_espinudp(struct mbuf **mp, int off, |
|
Line 1457 udp4_espinudp(struct mbuf **mp, int off, |
|
size_t minlen; |
size_t minlen; |
size_t iphdrlen; |
size_t iphdrlen; |
struct ip *ip; |
struct ip *ip; |
struct mbuf *n; |
|
struct m_tag *tag; |
struct m_tag *tag; |
struct udphdr *udphdr; |
struct udphdr *udphdr; |
u_int16_t sport, dport; |
u_int16_t sport, dport; |
Line 1480 udp4_espinudp(struct mbuf **mp, int off, |
|
Line 1484 udp4_espinudp(struct mbuf **mp, int off, |
|
|
|
/* Ignore keepalive packets */ |
/* Ignore keepalive packets */ |
if ((len == 1) && (*(unsigned char *)data == 0xff)) { |
if ((len == 1) && (*(unsigned char *)data == 0xff)) { |
|
m_free(m); |
|
*mp = NULL; /* avoid any further processiong by caller ... */ |
return 1; |
return 1; |
} |
} |
|
|
Line 1539 udp4_espinudp(struct mbuf **mp, int off, |
|
Line 1545 udp4_espinudp(struct mbuf **mp, int off, |
|
ip->ip_p = IPPROTO_ESP; |
ip->ip_p = IPPROTO_ESP; |
|
|
/* |
/* |
* Copy the mbuf to avoid multiple free, as both |
* We have modified the packet - it is now ESP, so we should not |
* esp4_input (which we call) and udp_input (which |
* return to UDP processing ... |
* called us) free the mbuf. |
* |
*/ |
|
if ((n = m_dup(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) { |
|
printf("udp4_espinudp: m_dup failed\n"); |
|
return 0; |
|
} |
|
|
|
/* |
|
* Add a PACKET_TAG_IPSEC_NAT_T_PORT tag to remember |
* Add a PACKET_TAG_IPSEC_NAT_T_PORT tag to remember |
* the source UDP port. This is required if we want |
* the source UDP port. This is required if we want |
* to select the right SPD for multiple hosts behind |
* to select the right SPD for multiple hosts behind |
Line 1557 udp4_espinudp(struct mbuf **mp, int off, |
|
Line 1556 udp4_espinudp(struct mbuf **mp, int off, |
|
if ((tag = m_tag_get(PACKET_TAG_IPSEC_NAT_T_PORTS, |
if ((tag = m_tag_get(PACKET_TAG_IPSEC_NAT_T_PORTS, |
sizeof(sport) + sizeof(dport), M_DONTWAIT)) == NULL) { |
sizeof(sport) + sizeof(dport), M_DONTWAIT)) == NULL) { |
printf("udp4_espinudp: m_tag_get failed\n"); |
printf("udp4_espinudp: m_tag_get failed\n"); |
m_freem(n); |
m_freem(m); |
return 0; |
return -1; |
} |
} |
((u_int16_t *)(tag + 1))[0] = sport; |
((u_int16_t *)(tag + 1))[0] = sport; |
((u_int16_t *)(tag + 1))[1] = dport; |
((u_int16_t *)(tag + 1))[1] = dport; |
m_tag_prepend(n, tag); |
m_tag_prepend(m, tag); |
|
|
#ifdef FAST_IPSEC |
#ifdef FAST_IPSEC |
ipsec4_common_input(n, iphdrlen, IPPROTO_ESP); |
ipsec4_common_input(m, iphdrlen, IPPROTO_ESP); |
#else |
#else |
esp4_input(n, iphdrlen); |
esp4_input(m, iphdrlen); |
#endif |
#endif |
|
|
/* We handled it, it shoudln't be handled by UDP */ |
/* We handled it, it shouldn't be handled by UDP */ |
|
*mp = NULL; /* avoid free by caller ... */ |
return 1; |
return 1; |
} |
} |
#endif |
#endif |