Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/netinet/udp_usrreq.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/netinet/udp_usrreq.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.179 retrieving revision 1.190 diff -u -p -r1.179 -r1.190 --- src/sys/netinet/udp_usrreq.c 2009/09/16 15:23:05 1.179 +++ src/sys/netinet/udp_usrreq.c 2013/06/05 19:01:26 1.190 @@ -1,4 +1,4 @@ -/* $NetBSD: udp_usrreq.c,v 1.179 2009/09/16 15:23:05 pooka Exp $ */ +/* $NetBSD: udp_usrreq.c,v 1.190 2013/06/05 19:01:26 christos Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.179 2009/09/16 15:23:05 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.190 2013/06/05 19:01:26 christos Exp $"); #include "opt_inet.h" #include "opt_compat_netbsd.h" @@ -118,9 +118,7 @@ __KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c #include #endif -#include - -#ifdef FAST_IPSEC +#ifdef IPSEC #include #include #include @@ -128,14 +126,7 @@ __KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c #ifdef INET6 #include #endif -#endif /* FAST_IPSEC */ - -#ifdef IPSEC -#include -#include -#include -#include -#endif /* IPSEC */ +#endif /* IPSEC */ #ifdef COMPAT_50 #include @@ -157,7 +148,7 @@ struct inpcbtable udbtable; percpu_t *udpstat_percpu; #ifdef INET -#ifdef IPSEC_NAT_T +#ifdef IPSEC static int udp4_espinudp (struct mbuf **, int, struct sockaddr *, struct socket *); #endif @@ -413,6 +404,14 @@ udp_input(struct mbuf *m, ...) UDP_STATINC(UDP_STAT_HDROPS); 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 if (IN_MULTICAST(ip->ip_dst.s_addr) || n == 0) { struct sockaddr_in6 src6, dst6; @@ -635,7 +634,7 @@ udp4_sendup(struct mbuf *m, int off /* o return; } -#if defined(IPSEC) || defined(FAST_IPSEC) +#if defined(IPSEC) /* check AH/ESP integrity. */ if (so != NULL && ipsec4_in_reject_so(m, so)) { IPSEC_STATINC(IPSEC_STAT_IN_POLVIO); @@ -685,7 +684,7 @@ udp6_sendup(struct mbuf *m, int off /* o return; in6p = sotoin6pcb(so); -#if defined(IPSEC) || defined(FAST_IPSEC) +#if defined(IPSEC) /* check AH/ESP integrity. */ if (so != NULL && ipsec6_in_reject_so(m, so)) { IPSEC6_STATINC(IPSEC_STAT_IN_POLVIO); @@ -804,7 +803,8 @@ udp4_realinput(struct sockaddr_in *src, /* * 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) { UDP_STATINC(UDP_STAT_PCBHASHMISS); inp = in_pcblookup_bind(&udbtable, *dst4, *dport); @@ -812,7 +812,7 @@ udp4_realinput(struct sockaddr_in *src, return rcvcnt; } -#ifdef IPSEC_NAT_T +#ifdef IPSEC /* Handle ESP over UDP */ if (inp->inp_flags & INP_ESPINUDP_ALL) { struct sockaddr *sa = (struct sockaddr *)src; @@ -958,7 +958,7 @@ udp6_realinput(int af, struct sockaddr_i * Locate pcb for datagram. */ in6p = in6_pcblookup_connect(&udbtable, &src6, sport, dst6, - dport, 0); + dport, 0, 0); if (in6p == 0) { UDP_STATINC(UDP_STAT_PCBHASHMISS); in6p = in6_pcblookup_bind(&udbtable, dst6, dport, 0); @@ -1066,7 +1066,6 @@ udp_ctloutput(int op, struct socket *so, break; switch(optval) { -#ifdef IPSEC_NAT_T case 0: inp->inp_flags &= ~INP_ESPINUDP_ALL; break; @@ -1080,13 +1079,12 @@ udp_ctloutput(int op, struct socket *so, inp->inp_flags &= ~INP_ESPINUDP_ALL; inp->inp_flags |= INP_ESPINUDP_NON_IKE; break; -#endif default: error = EINVAL; break; } break; - + default: error = ENOPROTOOPT; break; @@ -1299,6 +1297,7 @@ udp_usrreq(struct socket *so, int req, s { struct in_addr laddr; /* XXX */ + memset(&laddr, 0, sizeof laddr); if (nam) { laddr = inp->inp_laddr; /* XXX */ if ((so->so_state & SS_ISCONNECTED) != 0) { @@ -1374,7 +1373,6 @@ sysctl_net_inet_udp_stats(SYSCTLFN_ARGS) static void sysctl_net_inet_udp_setup(struct sysctllog **clog) { - sysctl_createv(clog, 0, NULL, NULL, CTLFLAG_PERMANENT, CTLTYPE_NODE, "net", NULL, @@ -1445,7 +1443,7 @@ udp_statinc(u_int stat) UDP_STATINC(stat); } -#if (defined INET && defined IPSEC_NAT_T) +#if defined(INET) && defined(IPSEC) /* * Returns: * 1 if the packet was processed @@ -1463,7 +1461,6 @@ udp4_espinudp(struct mbuf **mp, int off, size_t minlen; size_t iphdrlen; struct ip *ip; - struct mbuf *n; struct m_tag *tag; struct udphdr *udphdr; u_int16_t sport, dport; @@ -1491,6 +1488,8 @@ udp4_espinudp(struct mbuf **mp, int off, /* Ignore keepalive packets */ if ((len == 1) && (*(unsigned char *)data == 0xff)) { + m_free(m); + *mp = NULL; /* avoid any further processiong by caller ... */ return 1; } @@ -1550,16 +1549,9 @@ udp4_espinudp(struct mbuf **mp, int off, ip->ip_p = IPPROTO_ESP; /* - * Copy the mbuf to avoid multiple free, as both - * esp4_input (which we call) and udp_input (which - * 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; - } - - /* + * We have modified the packet - it is now ESP, so we should not + * return to UDP processing ... + * * Add a PACKET_TAG_IPSEC_NAT_T_PORT tag to remember * the source UDP port. This is required if we want * to select the right SPD for multiple hosts behind @@ -1568,20 +1560,21 @@ udp4_espinudp(struct mbuf **mp, int off, if ((tag = m_tag_get(PACKET_TAG_IPSEC_NAT_T_PORTS, sizeof(sport) + sizeof(dport), M_DONTWAIT)) == NULL) { printf("udp4_espinudp: m_tag_get failed\n"); - m_freem(n); - return 0; + m_freem(m); + return -1; } ((u_int16_t *)(tag + 1))[0] = sport; ((u_int16_t *)(tag + 1))[1] = dport; - m_tag_prepend(n, tag); + m_tag_prepend(m, tag); -#ifdef FAST_IPSEC - ipsec4_common_input(n, iphdrlen, IPPROTO_ESP); +#ifdef IPSEC + ipsec4_common_input(m, iphdrlen, IPPROTO_ESP); #else - esp4_input(n, iphdrlen); + esp4_input(m, iphdrlen); #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; } #endif