version 1.103.2.4, 2004/09/21 13:37:15 |
version 1.111, 2003/09/25 00:59:32 |
Line 117 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 117 __KERNEL_RCSID(0, "$NetBSD$"); |
|
|
|
#ifdef FAST_IPSEC |
#ifdef FAST_IPSEC |
#include <netipsec/ipsec.h> |
#include <netipsec/ipsec.h> |
#include <netipsec/ipsec_var.h> /* XXX ipsecstat namespace */ |
|
#ifdef INET6 |
#ifdef INET6 |
#include <netipsec/ipsec6.h> |
#include <netipsec/ipsec6.h> |
#endif |
#endif |
Line 146 struct inpcbtable udbtable; |
|
Line 145 struct inpcbtable udbtable; |
|
struct udpstat udpstat; |
struct udpstat udpstat; |
|
|
#ifdef INET |
#ifdef INET |
static void udp4_sendup (struct mbuf *, int, struct sockaddr *, |
static void udp4_sendup __P((struct mbuf *, int, struct sockaddr *, |
struct socket *); |
struct socket *)); |
static int udp4_realinput (struct sockaddr_in *, struct sockaddr_in *, |
static int udp4_realinput __P((struct sockaddr_in *, struct sockaddr_in *, |
struct mbuf *, int); |
struct mbuf *, int)); |
#endif |
#endif |
#ifdef INET6 |
#ifdef INET6 |
static void udp6_sendup (struct mbuf *, int, struct sockaddr *, |
static void udp6_sendup __P((struct mbuf *, int, struct sockaddr *, |
struct socket *); |
struct socket *)); |
static int udp6_realinput (int, struct sockaddr_in6 *, |
static int udp6_realinput __P((int, struct sockaddr_in6 *, |
struct sockaddr_in6 *, struct mbuf *, int); |
struct sockaddr_in6 *, struct mbuf *, int)); |
#endif |
#endif |
#ifdef INET |
#ifdef INET |
static void udp_notify (struct inpcb *, int); |
static void udp_notify __P((struct inpcb *, int)); |
#endif |
#endif |
|
|
#ifndef UDBHASHSIZE |
#ifndef UDBHASHSIZE |
Line 186 struct evcnt udp_swcsum = EVCNT_INITIALI |
|
Line 185 struct evcnt udp_swcsum = EVCNT_INITIALI |
|
|
|
#define UDP_CSUM_COUNTER_INCR(ev) (ev)->ev_count++ |
#define UDP_CSUM_COUNTER_INCR(ev) (ev)->ev_count++ |
|
|
EVCNT_ATTACH_STATIC(udp_hwcsum_bad); |
|
EVCNT_ATTACH_STATIC(udp_hwcsum_ok); |
|
EVCNT_ATTACH_STATIC(udp_hwcsum_data); |
|
EVCNT_ATTACH_STATIC(udp_swcsum); |
|
|
|
#else |
#else |
|
|
#define UDP_CSUM_COUNTER_INCR(ev) /* nothing */ |
#define UDP_CSUM_COUNTER_INCR(ev) /* nothing */ |
Line 198 EVCNT_ATTACH_STATIC(udp_swcsum); |
|
Line 192 EVCNT_ATTACH_STATIC(udp_swcsum); |
|
#endif /* UDP_CSUM_COUNTERS */ |
#endif /* UDP_CSUM_COUNTERS */ |
|
|
void |
void |
udp_init(void) |
udp_init() |
{ |
{ |
|
|
in_pcbinit(&udbtable, udbhashsize, udbhashsize); |
in_pcbinit(&udbtable, udbhashsize, udbhashsize); |
|
|
|
#ifdef UDP_CSUM_COUNTERS |
|
evcnt_attach_static(&udp_hwcsum_bad); |
|
evcnt_attach_static(&udp_hwcsum_ok); |
|
evcnt_attach_static(&udp_hwcsum_data); |
|
evcnt_attach_static(&udp_swcsum); |
|
#endif /* UDP_CSUM_COUNTERS */ |
|
|
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 |
#ifdef INET |
void |
void |
|
#if __STDC__ |
udp_input(struct mbuf *m, ...) |
udp_input(struct mbuf *m, ...) |
|
#else |
|
udp_input(m, va_alist) |
|
struct mbuf *m; |
|
va_dcl |
|
#endif |
{ |
{ |
va_list ap; |
va_list ap; |
struct sockaddr_in src, dst; |
struct sockaddr_in src, dst; |
Line 263 udp_input(struct mbuf *m, ...) |
|
Line 270 udp_input(struct mbuf *m, ...) |
|
*/ |
*/ |
if (uh->uh_sum) { |
if (uh->uh_sum) { |
switch (m->m_pkthdr.csum_flags & |
switch (m->m_pkthdr.csum_flags & |
((m->m_pkthdr.rcvif->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); |
goto badcsum; |
goto badcsum; |
Line 273 udp_input(struct mbuf *m, ...) |
|
Line 280 udp_input(struct mbuf *m, ...) |
|
u_int32_t hw_csum = m->m_pkthdr.csum_data; |
u_int32_t hw_csum = m->m_pkthdr.csum_data; |
UDP_CSUM_COUNTER_INCR(&udp_hwcsum_data); |
UDP_CSUM_COUNTER_INCR(&udp_hwcsum_data); |
if (m->m_pkthdr.csum_flags & M_CSUM_NO_PSEUDOHDR) |
if (m->m_pkthdr.csum_flags & M_CSUM_NO_PSEUDOHDR) |
hw_csum = in_cksum_phdr(ip->ip_src.s_addr, |
hw_csum = in_cksum_phdr(ip->ip_src.s_addr, ip->ip_dst.s_addr, |
ip->ip_dst.s_addr, |
htonl(hw_csum + ntohs(ip->ip_len) + IPPROTO_UDP)); |
htons(hw_csum + len + IPPROTO_UDP)); |
|
if ((hw_csum ^ 0xffff) != 0) |
if ((hw_csum ^ 0xffff) != 0) |
goto badcsum; |
goto badcsum; |
break; |
break; |
|
|
|
|
#ifdef INET6 |
#ifdef INET6 |
int |
int |
udp6_input(struct mbuf **mp, int *offp, int proto) |
udp6_input(mp, offp, proto) |
|
struct mbuf **mp; |
|
int *offp, proto; |
{ |
{ |
struct mbuf *m = *mp; |
struct mbuf *m = *mp; |
int off = *offp; |
int off = *offp; |
Line 421 udp6_input(struct mbuf **mp, int *offp, |
|
Line 429 udp6_input(struct mbuf **mp, int *offp, |
|
/* |
/* |
* Checksum extended UDP header and data. |
* Checksum extended UDP header and data. |
*/ |
*/ |
if (uh->uh_sum == 0) { |
if (uh->uh_sum == 0) |
udp6stat.udp6s_nosum++; |
udp6stat.udp6s_nosum++; |
goto bad; |
else if (in6_cksum(m, IPPROTO_UDP, off, ulen) != 0) { |
} |
|
if (in6_cksum(m, IPPROTO_UDP, off, ulen) != 0) { |
|
udp6stat.udp6s_badsum++; |
udp6stat.udp6s_badsum++; |
goto bad; |
goto bad; |
} |
} |
|
|
|
|
#ifdef INET |
#ifdef INET |
static void |
static void |
udp4_sendup(struct mbuf *m, int off /* offset of data portion */, |
udp4_sendup(m, off, src, so) |
struct sockaddr *src, struct socket *so) |
struct mbuf *m; |
|
int off; /* offset of data portion */ |
|
struct sockaddr *src; |
|
struct socket *so; |
{ |
{ |
struct mbuf *opts = NULL; |
struct mbuf *opts = NULL; |
struct mbuf *n; |
struct mbuf *n; |
Line 511 udp4_sendup(struct mbuf *m, int off /* o |
|
Line 520 udp4_sendup(struct mbuf *m, int off /* o |
|
m_freem(n); |
m_freem(n); |
if (opts) |
if (opts) |
m_freem(opts); |
m_freem(opts); |
so->so_rcv.sb_overflowed++; |
|
udpstat.udps_fullsock++; |
udpstat.udps_fullsock++; |
} else |
} else |
sorwakeup(so); |
sorwakeup(so); |
Line 521 udp4_sendup(struct mbuf *m, int off /* o |
|
Line 529 udp4_sendup(struct mbuf *m, int off /* o |
|
|
|
#ifdef INET6 |
#ifdef INET6 |
static void |
static void |
udp6_sendup(struct mbuf *m, int off /* offset of data portion */, |
udp6_sendup(m, off, src, so) |
struct sockaddr *src, struct socket *so) |
struct mbuf *m; |
|
int off; /* offset of data portion */ |
|
struct sockaddr *src; |
|
struct socket *so; |
{ |
{ |
struct mbuf *opts = NULL; |
struct mbuf *opts = NULL; |
struct mbuf *n; |
struct mbuf *n; |
Line 557 udp6_sendup(struct mbuf *m, int off /* o |
|
Line 568 udp6_sendup(struct mbuf *m, int off /* o |
|
m_freem(n); |
m_freem(n); |
if (opts) |
if (opts) |
m_freem(opts); |
m_freem(opts); |
so->so_rcv.sb_overflowed++; |
|
udp6stat.udp6s_fullsock++; |
udp6stat.udp6s_fullsock++; |
} else |
} else |
sorwakeup(so); |
sorwakeup(so); |
Line 567 udp6_sendup(struct mbuf *m, int off /* o |
|
Line 577 udp6_sendup(struct mbuf *m, int off /* o |
|
|
|
#ifdef INET |
#ifdef INET |
static int |
static int |
udp4_realinput(struct sockaddr_in *src, struct sockaddr_in *dst, |
udp4_realinput(src, dst, m, off) |
struct mbuf *m, int off /* offset of udphdr */) |
struct sockaddr_in *src; |
|
struct sockaddr_in *dst; |
|
struct mbuf *m; |
|
int off; /* offset of udphdr */ |
{ |
{ |
u_int16_t *sport, *dport; |
u_int16_t *sport, *dport; |
int rcvcnt; |
int rcvcnt; |
|
|
|
|
#ifdef INET6 |
#ifdef INET6 |
static int |
static int |
udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst, |
udp6_realinput(af, src, dst, m, off) |
struct mbuf *m, int off) |
int af; /* af on packet */ |
|
struct sockaddr_in6 *src; |
|
struct sockaddr_in6 *dst; |
|
struct mbuf *m; |
|
int off; /* offset of udphdr */ |
{ |
{ |
u_int16_t sport, dport; |
u_int16_t sport, dport; |
int rcvcnt; |
int rcvcnt; |
|
|
* just wake up so that he can collect error status. |
* just wake up so that he can collect error status. |
*/ |
*/ |
static void |
static void |
udp_notify(struct inpcb *inp, int errno) |
udp_notify(inp, errno) |
|
struct inpcb *inp; |
|
int errno; |
{ |
{ |
|
|
inp->inp_socket->so_error = errno; |
inp->inp_socket->so_error = errno; |
sorwakeup(inp->inp_socket); |
sorwakeup(inp->inp_socket); |
sowwakeup(inp->inp_socket); |
sowwakeup(inp->inp_socket); |
} |
} |
|
|
void * |
void * |
udp_ctlinput(int cmd, struct sockaddr *sa, void *v) |
udp_ctlinput(cmd, sa, v) |
|
int cmd; |
|
struct sockaddr *sa; |
|
void *v; |
{ |
{ |
struct ip *ip = v; |
struct ip *ip = v; |
struct udphdr *uh; |
struct udphdr *uh; |
void (*notify)(struct inpcb *, int) = udp_notify; |
void (*notify) __P((struct inpcb *, int)) = udp_notify; |
int errno; |
int errno; |
|
|
if (sa->sa_family != AF_INET |
if (sa->sa_family != AF_INET |
Line 826 udp_ctlinput(int cmd, struct sockaddr *s |
|
Line 849 udp_ctlinput(int cmd, struct sockaddr *s |
|
} |
} |
|
|
int |
int |
|
#if __STDC__ |
udp_output(struct mbuf *m, ...) |
udp_output(struct mbuf *m, ...) |
|
#else |
|
udp_output(m, va_alist) |
|
struct mbuf *m; |
|
va_dcl |
|
#endif |
{ |
{ |
struct inpcb *inp; |
struct inpcb *inp; |
struct udpiphdr *ui; |
struct udpiphdr *ui; |
Line 905 int udp_recvspace = 40 * (1024 + sizeof( |
|
Line 934 int udp_recvspace = 40 * (1024 + sizeof( |
|
|
|
/*ARGSUSED*/ |
/*ARGSUSED*/ |
int |
int |
udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, |
udp_usrreq(so, req, m, nam, control, p) |
struct mbuf *control, struct lwp *l) |
struct socket *so; |
|
int req; |
|
struct mbuf *m, *nam, *control; |
|
struct proc *p; |
{ |
{ |
struct inpcb *inp; |
struct inpcb *inp; |
struct proc *p; |
|
int s; |
int s; |
int error = 0; |
int error = 0; |
|
|
p = l ? l->l_proc : NULL; |
|
if (req == PRU_CONTROL) |
if (req == PRU_CONTROL) |
return (in_control(so, (long)m, (caddr_t)nam, |
return (in_control(so, (long)m, (caddr_t)nam, |
(struct ifnet *)control, p)); |
(struct ifnet *)control, p)); |
Line 992 udp_usrreq(struct socket *so, int req, s |
|
Line 1022 udp_usrreq(struct socket *so, int req, s |
|
so->so_state &= ~SS_ISCONNECTED; /* XXX */ |
so->so_state &= ~SS_ISCONNECTED; /* XXX */ |
in_pcbdisconnect(inp); |
in_pcbdisconnect(inp); |
inp->inp_laddr = zeroin_addr; /* XXX */ |
inp->inp_laddr = zeroin_addr; /* XXX */ |
|
if (inp->inp_ia != NULL) { |
|
LIST_REMOVE(inp, inp_ialink); |
|
IFAFREE(&inp->inp_ia->ia_ifa); |
|
inp->inp_ia = NULL; |
|
} |
in_pcbstate(inp, INP_BOUND); /* XXX */ |
in_pcbstate(inp, INP_BOUND); /* XXX */ |
break; |
break; |
|
|
Line 1036 udp_usrreq(struct socket *so, int req, s |
|
Line 1071 udp_usrreq(struct socket *so, int req, s |
|
in_pcbstate(inp, INP_BOUND); /* XXX */ |
in_pcbstate(inp, INP_BOUND); /* XXX */ |
} |
} |
die: |
die: |
|
if (inp->inp_ia != NULL && in_nullhost(inp->inp_laddr)) { |
|
LIST_REMOVE(inp, inp_ialink); |
|
IFAFREE(&inp->inp_ia->ia_ifa); |
|
inp->inp_ia = NULL; |
|
} |
if (m) |
if (m) |
m_freem(m); |
m_freem(m); |
} |
} |
|
|
/* |
/* |
* Sysctl for udp variables. |
* Sysctl for udp variables. |
*/ |
*/ |
SYSCTL_SETUP(sysctl_net_inet_udp_setup, "sysctl net.inet.udp subtree setup") |
int |
|
udp_sysctl(name, namelen, oldp, oldlenp, newp, newlen) |
|
int *name; |
|
u_int namelen; |
|
void *oldp; |
|
size_t *oldlenp; |
|
void *newp; |
|
size_t newlen; |
{ |
{ |
|
/* All sysctl names at this level are terminal. */ |
sysctl_createv(clog, 0, NULL, NULL, |
if (namelen != 1) |
CTLFLAG_PERMANENT, |
return (ENOTDIR); |
CTLTYPE_NODE, "net", NULL, |
|
NULL, 0, NULL, 0, |
switch (name[0]) { |
CTL_NET, CTL_EOL); |
case UDPCTL_CHECKSUM: |
sysctl_createv(clog, 0, NULL, NULL, |
return (sysctl_int(oldp, oldlenp, newp, newlen, &udpcksum)); |
CTLFLAG_PERMANENT, |
case UDPCTL_SENDSPACE: |
CTLTYPE_NODE, "inet", NULL, |
return (sysctl_int(oldp, oldlenp, newp, newlen, |
NULL, 0, NULL, 0, |
&udp_sendspace)); |
CTL_NET, PF_INET, CTL_EOL); |
case UDPCTL_RECVSPACE: |
sysctl_createv(clog, 0, NULL, NULL, |
return (sysctl_int(oldp, oldlenp, newp, newlen, |
CTLFLAG_PERMANENT, |
&udp_recvspace)); |
CTLTYPE_NODE, "udp", |
default: |
SYSCTL_DESCR("UDPv4 related settings"), |
return (ENOPROTOOPT); |
NULL, 0, NULL, 0, |
} |
CTL_NET, PF_INET, IPPROTO_UDP, CTL_EOL); |
/* NOTREACHED */ |
|
|
sysctl_createv(clog, 0, NULL, NULL, |
|
CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
|
CTLTYPE_INT, "checksum", |
|
SYSCTL_DESCR("Compute UDP checksums"), |
|
NULL, 0, &udpcksum, 0, |
|
CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_CHECKSUM, |
|
CTL_EOL); |
|
sysctl_createv(clog, 0, NULL, NULL, |
|
CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
|
CTLTYPE_INT, "sendspace", |
|
SYSCTL_DESCR("Default UDP send buffer size"), |
|
NULL, 0, &udp_sendspace, 0, |
|
CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_SENDSPACE, |
|
CTL_EOL); |
|
sysctl_createv(clog, 0, NULL, NULL, |
|
CTLFLAG_PERMANENT|CTLFLAG_READWRITE, |
|
CTLTYPE_INT, "recvspace", |
|
SYSCTL_DESCR("Default UDP receive buffer size"), |
|
NULL, 0, &udp_recvspace, 0, |
|
CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_RECVSPACE, |
|
CTL_EOL); |
|
} |
} |
#endif |
#endif |