version 1.217.4.8, 2017/02/05 13:40:59 |
version 1.218, 2015/04/03 20:01:07 |
|
|
#include <sys/cdefs.h> |
#include <sys/cdefs.h> |
__KERNEL_RCSID(0, "$NetBSD$"); |
__KERNEL_RCSID(0, "$NetBSD$"); |
|
|
#ifdef _KERNEL_OPT |
|
#include "opt_inet.h" |
#include "opt_inet.h" |
#include "opt_compat_netbsd.h" |
#include "opt_compat_netbsd.h" |
#include "opt_ipsec.h" |
#include "opt_ipsec.h" |
#include "opt_inet_csum.h" |
#include "opt_inet_csum.h" |
#include "opt_ipkdb.h" |
#include "opt_ipkdb.h" |
#include "opt_mbuftrace.h" |
#include "opt_mbuftrace.h" |
#include "opt_net_mpsafe.h" |
|
#endif |
|
|
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/mbuf.h> |
#include <sys/mbuf.h> |
Line 90 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 87 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <sys/sysctl.h> |
#include <sys/sysctl.h> |
|
|
#include <net/if.h> |
#include <net/if.h> |
|
#include <net/route.h> |
|
|
#include <netinet/in.h> |
#include <netinet/in.h> |
#include <netinet/in_systm.h> |
#include <netinet/in_systm.h> |
Line 277 udp4_input_checksum(struct mbuf *m, cons |
|
Line 275 udp4_input_checksum(struct mbuf *m, cons |
|
return 0; |
return 0; |
|
|
switch (m->m_pkthdr.csum_flags & |
switch (m->m_pkthdr.csum_flags & |
((m_get_rcvif_NOMPSAFE(m)->if_csum_flags_rx & M_CSUM_UDPv4) | |
((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_UDPv4) | |
M_CSUM_TCP_UDP_BAD | M_CSUM_DATA)) { |
M_CSUM_TCP_UDP_BAD | M_CSUM_DATA)) { |
case M_CSUM_UDPv4|M_CSUM_TCP_UDP_BAD: |
case M_CSUM_UDPv4|M_CSUM_TCP_UDP_BAD: |
UDP_CSUM_COUNTER_INCR(&udp_hwcsum_bad); |
UDP_CSUM_COUNTER_INCR(&udp_hwcsum_bad); |
Line 310 udp4_input_checksum(struct mbuf *m, cons |
|
Line 308 udp4_input_checksum(struct mbuf *m, cons |
|
* Need to compute it ourselves. Maybe skip checksum |
* Need to compute it ourselves. Maybe skip checksum |
* on loopback interfaces. |
* on loopback interfaces. |
*/ |
*/ |
if (__predict_true(!(m_get_rcvif_NOMPSAFE(m)->if_flags & |
if (__predict_true(!(m->m_pkthdr.rcvif->if_flags & |
IFF_LOOPBACK) || |
IFF_LOOPBACK) || |
udp_do_loopback_cksum)) { |
udp_do_loopback_cksum)) { |
UDP_CSUM_COUNTER_INCR(&udp_swcsum); |
UDP_CSUM_COUNTER_INCR(&udp_swcsum); |
Line 356 udp_input(struct mbuf *m, ...) |
|
Line 354 udp_input(struct mbuf *m, ...) |
|
UDP_STATINC(UDP_STAT_HDROPS); |
UDP_STATINC(UDP_STAT_HDROPS); |
return; |
return; |
} |
} |
/* |
|
* Enforce alignment requirements that are violated in |
|
* some cases, see kern/50766 for details. |
|
*/ |
|
if (UDP_HDR_ALIGNED_P(uh) == 0) { |
|
m = m_copyup(m, iphlen + sizeof(struct udphdr), 0); |
|
if (m == NULL) { |
|
UDP_STATINC(UDP_STAT_HDROPS); |
|
return; |
|
} |
|
ip = mtod(m, struct ip *); |
|
uh = (struct udphdr *)(mtod(m, char *) + iphlen); |
|
} |
|
KASSERT(UDP_HDR_ALIGNED_P(uh)); |
KASSERT(UDP_HDR_ALIGNED_P(uh)); |
|
|
/* destination port of 0 is illegal, based on RFC768. */ |
/* destination port of 0 is illegal, based on RFC768. */ |
Line 418 udp_input(struct mbuf *m, ...) |
|
Line 403 udp_input(struct mbuf *m, ...) |
|
memset(&src6, 0, sizeof(src6)); |
memset(&src6, 0, sizeof(src6)); |
src6.sin6_family = AF_INET6; |
src6.sin6_family = AF_INET6; |
src6.sin6_len = sizeof(struct sockaddr_in6); |
src6.sin6_len = sizeof(struct sockaddr_in6); |
in6_in_2_v4mapin6(&ip->ip_src, &src6.sin6_addr); |
src6.sin6_addr.s6_addr[10] = src6.sin6_addr.s6_addr[11] = 0xff; |
|
memcpy(&src6.sin6_addr.s6_addr[12], &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); |
in6_in_2_v4mapin6(&ip->ip_dst, &dst6.sin6_addr); |
dst6.sin6_addr.s6_addr[10] = dst6.sin6_addr.s6_addr[11] = 0xff; |
|
memcpy(&dst6.sin6_addr.s6_addr[12], &ip->ip_dst, |
|
sizeof(ip->ip_dst)); |
dst6.sin6_port = uh->uh_dport; |
dst6.sin6_port = uh->uh_dport; |
|
|
n += udp6_realinput(AF_INET, &src6, &dst6, m, iphlen); |
n += udp6_realinput(AF_INET, &src6, &dst6, m, iphlen); |
Line 543 udp4_realinput(struct sockaddr_in *src, |
|
Line 532 udp4_realinput(struct sockaddr_in *src, |
|
dport = &dst->sin_port; |
dport = &dst->sin_port; |
|
|
if (IN_MULTICAST(dst4->s_addr) || |
if (IN_MULTICAST(dst4->s_addr) || |
in_broadcast(*dst4, m_get_rcvif_NOMPSAFE(m))) { |
in_broadcast(*dst4, m->m_pkthdr.rcvif)) { |
/* |
/* |
* Deliver a multicast or broadcast datagram to *all* sockets |
* Deliver a multicast or broadcast datagram to *all* sockets |
* for which the local and remote addresses and ports match |
* for which the local and remote addresses and ports match |
Line 631 udp4_realinput(struct sockaddr_in *src, |
|
Line 620 udp4_realinput(struct sockaddr_in *src, |
|
|
|
case 0: /* plain UDP */ |
case 0: /* plain UDP */ |
default: /* Unexpected */ |
default: /* Unexpected */ |
/* |
/* |
* Normal UDP processing will take place |
* Normal UDP processing will take place |
* m may have changed. |
* m may have changed. |
*/ |
*/ |
m = *mp; |
m = *mp; |
Line 765 udp_ctloutput(int op, struct socket *so, |
|
Line 754 udp_ctloutput(int op, struct socket *so, |
|
break; |
break; |
} |
} |
break; |
break; |
|
|
default: |
default: |
error = ENOPROTOOPT; |
error = ENOPROTOOPT; |
break; |
break; |
|
|
|
|
|
|
int |
int |
udp_output(struct mbuf *m, struct inpcb *inp) |
udp_output(struct mbuf *m, ...) |
{ |
{ |
|
struct inpcb *inp; |
struct udpiphdr *ui; |
struct udpiphdr *ui; |
struct route *ro; |
struct route *ro; |
int len = m->m_pkthdr.len; |
int len = m->m_pkthdr.len; |
int error = 0; |
int error = 0; |
|
va_list ap; |
|
|
MCLAIM(m, &udp_tx_mowner); |
MCLAIM(m, &udp_tx_mowner); |
|
va_start(ap, m); |
|
inp = va_arg(ap, struct inpcb *); |
|
va_end(ap); |
|
|
/* |
/* |
* Calculate data length and get a mbuf |
* Calculate data length and get a mbuf |
Line 901 udp_detach(struct socket *so) |
|
Line 895 udp_detach(struct socket *so) |
|
} |
} |
|
|
static int |
static int |
udp_accept(struct socket *so, struct sockaddr *nam) |
udp_accept(struct socket *so, struct mbuf *nam) |
{ |
{ |
KASSERT(solocked(so)); |
KASSERT(solocked(so)); |
|
|
Line 938 udp_listen(struct socket *so, struct lwp |
|
Line 932 udp_listen(struct socket *so, struct lwp |
|
} |
} |
|
|
static int |
static int |
udp_connect(struct socket *so, struct sockaddr *nam, struct lwp *l) |
udp_connect(struct socket *so, struct mbuf *nam, struct lwp *l) |
{ |
{ |
struct inpcb *inp = sotoinpcb(so); |
struct inpcb *inp = sotoinpcb(so); |
int error = 0; |
int error = 0; |
Line 949 udp_connect(struct socket *so, struct so |
|
Line 943 udp_connect(struct socket *so, struct so |
|
KASSERT(nam != NULL); |
KASSERT(nam != NULL); |
|
|
s = splsoftnet(); |
s = splsoftnet(); |
error = in_pcbconnect(inp, (struct sockaddr_in *)nam, l); |
error = in_pcbconnect(inp, nam, l); |
if (! error) |
if (! error) |
soisconnected(so); |
soisconnected(so); |
splx(s); |
splx(s); |
Line 1024 udp_stat(struct socket *so, struct stat |
|
Line 1018 udp_stat(struct socket *so, struct stat |
|
} |
} |
|
|
static int |
static int |
udp_peeraddr(struct socket *so, struct sockaddr *nam) |
udp_peeraddr(struct socket *so, struct mbuf *nam) |
{ |
{ |
int s; |
int s; |
|
|
Line 1033 udp_peeraddr(struct socket *so, struct s |
|
Line 1027 udp_peeraddr(struct socket *so, struct s |
|
KASSERT(nam != NULL); |
KASSERT(nam != NULL); |
|
|
s = splsoftnet(); |
s = splsoftnet(); |
in_setpeeraddr(sotoinpcb(so), (struct sockaddr_in *)nam); |
in_setpeeraddr(sotoinpcb(so), nam); |
splx(s); |
splx(s); |
|
|
return 0; |
return 0; |
} |
} |
|
|
static int |
static int |
udp_sockaddr(struct socket *so, struct sockaddr *nam) |
udp_sockaddr(struct socket *so, struct mbuf *nam) |
{ |
{ |
int s; |
int s; |
|
|
Line 1049 udp_sockaddr(struct socket *so, struct s |
|
Line 1043 udp_sockaddr(struct socket *so, struct s |
|
KASSERT(nam != NULL); |
KASSERT(nam != NULL); |
|
|
s = splsoftnet(); |
s = splsoftnet(); |
in_setsockaddr(sotoinpcb(so), (struct sockaddr_in *)nam); |
in_setsockaddr(sotoinpcb(so), nam); |
splx(s); |
splx(s); |
|
|
return 0; |
return 0; |
Line 1072 udp_recvoob(struct socket *so, struct mb |
|
Line 1066 udp_recvoob(struct socket *so, struct mb |
|
} |
} |
|
|
static int |
static int |
udp_send(struct socket *so, struct mbuf *m, struct sockaddr *nam, |
udp_send(struct socket *so, struct mbuf *m, struct mbuf *nam, |
struct mbuf *control, struct lwp *l) |
struct mbuf *control, struct lwp *l) |
{ |
{ |
struct inpcb *inp = sotoinpcb(so); |
struct inpcb *inp = sotoinpcb(so); |
Line 1099 udp_send(struct socket *so, struct mbuf |
|
Line 1093 udp_send(struct socket *so, struct mbuf |
|
error = EISCONN; |
error = EISCONN; |
goto die; |
goto die; |
} |
} |
error = in_pcbconnect(inp, (struct sockaddr_in *)nam, l); |
error = in_pcbconnect(inp, nam, l); |
if (error) |
if (error) |
goto die; |
goto die; |
} else { |
} else { |
Line 1142 udp_purgeif(struct socket *so, struct if |
|
Line 1136 udp_purgeif(struct socket *so, struct if |
|
s = splsoftnet(); |
s = splsoftnet(); |
mutex_enter(softnet_lock); |
mutex_enter(softnet_lock); |
in_pcbpurgeif0(&udbtable, ifp); |
in_pcbpurgeif0(&udbtable, ifp); |
#ifdef NET_MPSAFE |
|
mutex_exit(softnet_lock); |
|
#endif |
|
in_purgeif(ifp); |
in_purgeif(ifp); |
#ifdef NET_MPSAFE |
|
mutex_enter(softnet_lock); |
|
#endif |
|
in_pcbpurgeif(&udbtable, ifp); |
in_pcbpurgeif(&udbtable, ifp); |
mutex_exit(softnet_lock); |
mutex_exit(softnet_lock); |
splx(s); |
splx(s); |
Line 1157 udp_purgeif(struct socket *so, struct if |
|
Line 1145 udp_purgeif(struct socket *so, struct if |
|
} |
} |
|
|
static int |
static int |
|
udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, |
|
struct mbuf *control, struct lwp *l) |
|
{ |
|
KASSERT(req != PRU_ATTACH); |
|
KASSERT(req != PRU_DETACH); |
|
KASSERT(req != PRU_ACCEPT); |
|
KASSERT(req != PRU_BIND); |
|
KASSERT(req != PRU_LISTEN); |
|
KASSERT(req != PRU_CONNECT); |
|
KASSERT(req != PRU_CONNECT2); |
|
KASSERT(req != PRU_DISCONNECT); |
|
KASSERT(req != PRU_SHUTDOWN); |
|
KASSERT(req != PRU_ABORT); |
|
KASSERT(req != PRU_CONTROL); |
|
KASSERT(req != PRU_SENSE); |
|
KASSERT(req != PRU_PEERADDR); |
|
KASSERT(req != PRU_SOCKADDR); |
|
KASSERT(req != PRU_RCVD); |
|
KASSERT(req != PRU_RCVOOB); |
|
KASSERT(req != PRU_SEND); |
|
KASSERT(req != PRU_SENDOOB); |
|
KASSERT(req != PRU_PURGEIF); |
|
|
|
KASSERT(solocked(so)); |
|
|
|
if (sotoinpcb(so) == NULL) |
|
return EINVAL; |
|
|
|
panic("udp_usrreq"); |
|
|
|
return 0; |
|
} |
|
|
|
static int |
sysctl_net_inet_udp_stats(SYSCTLFN_ARGS) |
sysctl_net_inet_udp_stats(SYSCTLFN_ARGS) |
{ |
{ |
|
|
Line 1310 udp4_espinudp(struct mbuf **mp, int off, |
|
Line 1332 udp4_espinudp(struct mbuf **mp, int off, |
|
} |
} |
|
|
/* |
/* |
* Get the UDP ports. They are handled in network |
* Get the UDP ports. They are handled in network |
* order everywhere in IPSEC_NAT_T code. |
* order everywhere in IPSEC_NAT_T code. |
*/ |
*/ |
udphdr = (struct udphdr *)((char *)data - skip); |
udphdr = (struct udphdr *)((char *)data - skip); |
Line 1342 udp4_espinudp(struct mbuf **mp, int off, |
|
Line 1364 udp4_espinudp(struct mbuf **mp, int off, |
|
|
|
/* |
/* |
* We have modified the packet - it is now ESP, so we should not |
* We have modified the packet - it is now ESP, so we should not |
* return to UDP processing ... |
* return to UDP processing ... |
* |
* |
* 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 |
* same NAT |
* same NAT |
*/ |
*/ |
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) { |
Line 1359 udp4_espinudp(struct mbuf **mp, int off, |
|
Line 1381 udp4_espinudp(struct mbuf **mp, int off, |
|
((u_int16_t *)(tag + 1))[1] = dport; |
((u_int16_t *)(tag + 1))[1] = dport; |
m_tag_prepend(m, tag); |
m_tag_prepend(m, tag); |
|
|
|
#ifdef IPSEC |
if (ipsec_used) |
if (ipsec_used) |
ipsec4_common_input(m, iphdrlen, IPPROTO_ESP); |
ipsec4_common_input(m, iphdrlen, IPPROTO_ESP); |
/* XXX: else */ |
/* XXX: else */ |
|
#else |
|
esp4_input(m, iphdrlen); |
|
#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 ... */ |
*mp = NULL; /* avoid free by caller ... */ |
Line 1389 PR_WRAP_USRREQS(udp) |
|
Line 1415 PR_WRAP_USRREQS(udp) |
|
#define udp_send udp_send_wrapper |
#define udp_send udp_send_wrapper |
#define udp_sendoob udp_sendoob_wrapper |
#define udp_sendoob udp_sendoob_wrapper |
#define udp_purgeif udp_purgeif_wrapper |
#define udp_purgeif udp_purgeif_wrapper |
|
#define udp_usrreq udp_usrreq_wrapper |
|
|
const struct pr_usrreqs udp_usrreqs = { |
const struct pr_usrreqs udp_usrreqs = { |
.pr_attach = udp_attach, |
.pr_attach = udp_attach, |
Line 1410 const struct pr_usrreqs udp_usrreqs = { |
|
Line 1437 const struct pr_usrreqs udp_usrreqs = { |
|
.pr_send = udp_send, |
.pr_send = udp_send, |
.pr_sendoob = udp_sendoob, |
.pr_sendoob = udp_sendoob, |
.pr_purgeif = udp_purgeif, |
.pr_purgeif = udp_purgeif, |
|
.pr_generic = udp_usrreq, |
}; |
}; |