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.183.2.3 retrieving revision 1.183.6.1 diff -u -p -r1.183.2.3 -r1.183.6.1 --- src/sys/netinet/udp_usrreq.c 2014/05/22 11:41:10 1.183.2.3 +++ src/sys/netinet/udp_usrreq.c 2012/02/18 07:35:41 1.183.6.1 @@ -1,4 +1,4 @@ -/* $NetBSD: udp_usrreq.c,v 1.183.2.3 2014/05/22 11:41:10 yamt Exp $ */ +/* $NetBSD: udp_usrreq.c,v 1.183.6.1 2012/02/18 07:35:41 mrg Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.183.2.3 2014/05/22 11:41:10 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.183.6.1 2012/02/18 07:35:41 mrg Exp $"); #include "opt_inet.h" #include "opt_compat_netbsd.h" @@ -73,7 +73,6 @@ __KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c #include #include #include -#include #include #include #include @@ -97,6 +96,7 @@ __KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c #include #include #include +#include #ifdef INET6 #include @@ -119,7 +119,7 @@ __KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c #include #endif -#ifdef IPSEC +#ifdef FAST_IPSEC #include #include #include @@ -127,7 +127,14 @@ __KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c #ifdef INET6 #include #endif -#endif /* IPSEC */ +#endif /* FAST_IPSEC */ + +#ifdef KAME_IPSEC +#include +#include +#include +#include +#endif /* KAME_IPSEC */ #ifdef COMPAT_50 #include @@ -149,7 +156,7 @@ struct inpcbtable udbtable; percpu_t *udpstat_percpu; #ifdef INET -#ifdef IPSEC +#ifdef IPSEC_NAT_T static int udp4_espinudp (struct mbuf **, int, struct sockaddr *, struct socket *); #endif @@ -226,35 +233,24 @@ EVCNT_ATTACH_STATIC(udp6_swcsum); static void sysctl_net_inet_udp_setup(struct sysctllog **); -static int -do_udpinit(void) +void +udp_init(void) { + sysctl_net_inet_udp_setup(NULL); + in_pcbinit(&udbtable, udbhashsize, udbhashsize); - udpstat_percpu = percpu_alloc(sizeof(uint64_t) * UDP_NSTATS); MOWNER_ATTACH(&udp_tx_mowner); MOWNER_ATTACH(&udp_rx_mowner); MOWNER_ATTACH(&udp_mowner); - return 0; -} - -void -udp_init_common(void) -{ - static ONCE_DECL(doudpinit); - - RUN_ONCE(&doudpinit, do_udpinit); -} - -void -udp_init(void) -{ - - sysctl_net_inet_udp_setup(NULL); - - udp_init_common(); +#ifdef INET + udpstat_percpu = percpu_alloc(sizeof(uint64_t) * UDP_NSTATS); +#endif +#ifdef INET6 + udp6stat_percpu = percpu_alloc(sizeof(uint64_t) * UDP6_NSTATS); +#endif } /* @@ -416,14 +412,6 @@ 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; @@ -646,7 +634,7 @@ udp4_sendup(struct mbuf *m, int off /* o return; } -#if defined(IPSEC) +#if defined(KAME_IPSEC) || defined(FAST_IPSEC) /* check AH/ESP integrity. */ if (so != NULL && ipsec4_in_reject_so(m, so)) { IPSEC_STATINC(IPSEC_STAT_IN_POLVIO); @@ -696,7 +684,7 @@ udp6_sendup(struct mbuf *m, int off /* o return; in6p = sotoin6pcb(so); -#if defined(IPSEC) +#if defined(KAME_IPSEC) || defined(FAST_IPSEC) /* check AH/ESP integrity. */ if (so != NULL && ipsec6_in_reject_so(m, so)) { IPSEC6_STATINC(IPSEC_STAT_IN_POLVIO); @@ -778,7 +766,7 @@ udp4_realinput(struct sockaddr_in *src, /* * Locate pcb(s) for datagram. */ - TAILQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { + CIRCLEQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { inp = (struct inpcb *)inph; if (inp->inp_af != AF_INET) continue; @@ -824,7 +812,7 @@ udp4_realinput(struct sockaddr_in *src, return rcvcnt; } -#ifdef IPSEC +#ifdef IPSEC_NAT_T /* Handle ESP over UDP */ if (inp->inp_flags & INP_ESPINUDP_ALL) { struct sockaddr *sa = (struct sockaddr *)src; @@ -923,7 +911,7 @@ udp6_realinput(int af, struct sockaddr_i /* * Locate pcb(s) for datagram. */ - TAILQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { + CIRCLEQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { in6p = (struct in6pcb *)inph; if (in6p->in6p_af != AF_INET6) continue; @@ -1078,6 +1066,7 @@ udp_ctloutput(int op, struct socket *so, break; switch(optval) { +#ifdef IPSEC_NAT_T case 0: inp->inp_flags &= ~INP_ESPINUDP_ALL; break; @@ -1091,12 +1080,22 @@ 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; + case UDP_RFC6056ALGO: + error = sockopt_getint(sopt, &optval); + if (error) + break; + + error = rfc6056_algo_index_select( + (struct inpcb_hdr *)inp, optval); + break; + default: error = ENOPROTOOPT; break; @@ -1385,7 +1384,13 @@ sysctl_net_inet_udp_stats(SYSCTLFN_ARGS) static void sysctl_net_inet_udp_setup(struct sysctllog **clog) { - + const struct sysctlnode *rfc6056_node; + + sysctl_createv(clog, 0, NULL, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, "net", NULL, + NULL, 0, NULL, 0, + CTL_NET, CTL_EOL); sysctl_createv(clog, 0, NULL, NULL, CTLFLAG_PERMANENT, CTLTYPE_NODE, "inet", NULL, @@ -1440,6 +1445,25 @@ sysctl_net_inet_udp_setup(struct sysctll sysctl_net_inet_udp_stats, 0, NULL, 0, CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_STATS, CTL_EOL); + /* RFC6056 subtree */ + sysctl_createv(clog, 0, NULL, &rfc6056_node, + CTLFLAG_PERMANENT, + CTLTYPE_NODE, "rfc6056", + SYSCTL_DESCR("RFC 6056"), + NULL, 0, NULL, 0, + CTL_NET, PF_INET, IPPROTO_UDP, CTL_CREATE, CTL_EOL); + sysctl_createv(clog, 0, &rfc6056_node, NULL, + CTLFLAG_PERMANENT, + CTLTYPE_STRING, "available", + SYSCTL_DESCR("RFC 6056 available algorithms"), + sysctl_rfc6056_available, 0, NULL, RFC6056_MAXLEN, + CTL_CREATE, CTL_EOL); + sysctl_createv(clog, 0, &rfc6056_node, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_STRING, "selected", + SYSCTL_DESCR("RFC 6056 selected algorithm"), + sysctl_rfc6056_selected, 0, NULL, RFC6056_MAXLEN, + CTL_CREATE, CTL_EOL); } #endif @@ -1451,7 +1475,7 @@ udp_statinc(u_int stat) UDP_STATINC(stat); } -#if defined(INET) && defined(IPSEC) +#if (defined INET && defined IPSEC_NAT_T) /* * Returns: * 1 if the packet was processed @@ -1469,6 +1493,7 @@ 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; @@ -1496,8 +1521,6 @@ 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; } @@ -1557,9 +1580,16 @@ udp4_espinudp(struct mbuf **mp, int off, ip->ip_p = IPPROTO_ESP; /* - * We have modified the packet - it is now ESP, so we should not - * return to UDP processing ... - * + * 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; + } + + /* * 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,21 +1598,20 @@ 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(m); - return -1; + m_freem(n); + return 0; } ((u_int16_t *)(tag + 1))[0] = sport; ((u_int16_t *)(tag + 1))[1] = dport; - m_tag_prepend(m, tag); + m_tag_prepend(n, tag); -#ifdef IPSEC - ipsec4_common_input(m, iphdrlen, IPPROTO_ESP); +#ifdef FAST_IPSEC + ipsec4_common_input(n, iphdrlen, IPPROTO_ESP); #else - esp4_input(m, iphdrlen); + esp4_input(n, iphdrlen); #endif /* We handled it, it shouldn't be handled by UDP */ - *mp = NULL; /* avoid free by caller ... */ return 1; } #endif