version 1.183.2.2, 2012/10/30 17:22:47 |
version 1.193, 2014/01/04 14:18:12 |
Line 73 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 73 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/malloc.h> |
#include <sys/malloc.h> |
#include <sys/mbuf.h> |
#include <sys/mbuf.h> |
|
#include <sys/once.h> |
#include <sys/protosw.h> |
#include <sys/protosw.h> |
#include <sys/socket.h> |
#include <sys/socket.h> |
#include <sys/socketvar.h> |
#include <sys/socketvar.h> |
Line 118 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 119 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <net/if_faith.h> |
#include <net/if_faith.h> |
#endif |
#endif |
|
|
#ifdef FAST_IPSEC |
#ifdef IPSEC |
#include <netipsec/ipsec.h> |
#include <netipsec/ipsec.h> |
#include <netipsec/ipsec_var.h> |
#include <netipsec/ipsec_var.h> |
#include <netipsec/ipsec_private.h> |
#include <netipsec/ipsec_private.h> |
Line 126 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 127 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#ifdef INET6 |
#ifdef INET6 |
#include <netipsec/ipsec6.h> |
#include <netipsec/ipsec6.h> |
#endif |
#endif |
#endif /* FAST_IPSEC */ |
#endif /* IPSEC */ |
|
|
#ifdef COMPAT_50 |
#ifdef COMPAT_50 |
#include <compat/sys/socket.h> |
#include <compat/sys/socket.h> |
Line 148 struct inpcbtable udbtable; |
|
Line 149 struct inpcbtable udbtable; |
|
percpu_t *udpstat_percpu; |
percpu_t *udpstat_percpu; |
|
|
#ifdef INET |
#ifdef INET |
#ifdef IPSEC_NAT_T |
#ifdef IPSEC |
static int udp4_espinudp (struct mbuf **, int, struct sockaddr *, |
static int udp4_espinudp (struct mbuf **, int, struct sockaddr *, |
struct socket *); |
struct socket *); |
#endif |
#endif |
Line 225 EVCNT_ATTACH_STATIC(udp6_swcsum); |
|
Line 226 EVCNT_ATTACH_STATIC(udp6_swcsum); |
|
|
|
static void sysctl_net_inet_udp_setup(struct sysctllog **); |
static void sysctl_net_inet_udp_setup(struct sysctllog **); |
|
|
void |
static int |
udp_init(void) |
do_udpinit(void) |
{ |
{ |
|
|
sysctl_net_inet_udp_setup(NULL); |
|
|
|
in_pcbinit(&udbtable, udbhashsize, udbhashsize); |
in_pcbinit(&udbtable, udbhashsize, udbhashsize); |
|
udpstat_percpu = percpu_alloc(sizeof(uint64_t) * UDP_NSTATS); |
|
|
MOWNER_ATTACH(&udp_tx_mowner); |
MOWNER_ATTACH(&udp_tx_mowner); |
MOWNER_ATTACH(&udp_rx_mowner); |
MOWNER_ATTACH(&udp_rx_mowner); |
MOWNER_ATTACH(&udp_mowner); |
MOWNER_ATTACH(&udp_mowner); |
|
|
#ifdef INET |
return 0; |
udpstat_percpu = percpu_alloc(sizeof(uint64_t) * UDP_NSTATS); |
} |
#endif |
|
#ifdef INET6 |
void |
udp6stat_percpu = percpu_alloc(sizeof(uint64_t) * UDP6_NSTATS); |
udp_init_common(void) |
#endif |
{ |
|
static ONCE_DECL(doudpinit); |
|
|
|
RUN_ONCE(&doudpinit, do_udpinit); |
|
} |
|
|
|
void |
|
udp_init(void) |
|
{ |
|
|
|
sysctl_net_inet_udp_setup(NULL); |
|
|
|
udp_init_common(); |
} |
} |
|
|
/* |
/* |
Line 404 udp_input(struct mbuf *m, ...) |
|
Line 416 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 626 udp4_sendup(struct mbuf *m, int off /* o |
|
Line 646 udp4_sendup(struct mbuf *m, int off /* o |
|
return; |
return; |
} |
} |
|
|
#if defined(FAST_IPSEC) |
#if defined(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 676 udp6_sendup(struct mbuf *m, int off /* o |
|
Line 696 udp6_sendup(struct mbuf *m, int off /* o |
|
return; |
return; |
in6p = sotoin6pcb(so); |
in6p = sotoin6pcb(so); |
|
|
#if defined(FAST_IPSEC) |
#if defined(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 758 udp4_realinput(struct sockaddr_in *src, |
|
Line 778 udp4_realinput(struct sockaddr_in *src, |
|
/* |
/* |
* Locate pcb(s) for datagram. |
* Locate pcb(s) for datagram. |
*/ |
*/ |
CIRCLEQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { |
TAILQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { |
inp = (struct inpcb *)inph; |
inp = (struct inpcb *)inph; |
if (inp->inp_af != AF_INET) |
if (inp->inp_af != AF_INET) |
continue; |
continue; |
Line 804 udp4_realinput(struct sockaddr_in *src, |
|
Line 824 udp4_realinput(struct sockaddr_in *src, |
|
return rcvcnt; |
return rcvcnt; |
} |
} |
|
|
#ifdef IPSEC_NAT_T |
#ifdef IPSEC |
/* 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 903 udp6_realinput(int af, struct sockaddr_i |
|
Line 923 udp6_realinput(int af, struct sockaddr_i |
|
/* |
/* |
* Locate pcb(s) for datagram. |
* Locate pcb(s) for datagram. |
*/ |
*/ |
CIRCLEQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { |
TAILQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { |
in6p = (struct in6pcb *)inph; |
in6p = (struct in6pcb *)inph; |
if (in6p->in6p_af != AF_INET6) |
if (in6p->in6p_af != AF_INET6) |
continue; |
continue; |
Line 1058 udp_ctloutput(int op, struct socket *so, |
|
Line 1078 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 1072 udp_ctloutput(int op, struct socket *so, |
|
Line 1091 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; |
Line 1437 udp_statinc(u_int stat) |
|
Line 1455 udp_statinc(u_int stat) |
|
UDP_STATINC(stat); |
UDP_STATINC(stat); |
} |
} |
|
|
#if (defined INET && defined IPSEC_NAT_T) |
#if defined(INET) && defined(IPSEC) |
/* |
/* |
* Returns: |
* Returns: |
* 1 if the packet was processed |
* 1 if the packet was processed |
Line 1455 udp4_espinudp(struct mbuf **mp, int off, |
|
Line 1473 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 1483 udp4_espinudp(struct mbuf **mp, int off, |
|
Line 1500 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 1542 udp4_espinudp(struct mbuf **mp, int off, |
|
Line 1561 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 1560 udp4_espinudp(struct mbuf **mp, int off, |
|
Line 1572 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 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 shouldn'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 |