version 1.134.2.6, 2005/12/29 16:10:18 |
version 1.146.2.1, 2006/02/05 03:09:11 |
Line 104 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 104 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <netinet/ip6.h> |
#include <netinet/ip6.h> |
#include <netinet/icmp6.h> |
#include <netinet/icmp6.h> |
#include <netinet6/ip6_var.h> |
#include <netinet6/ip6_var.h> |
#include <netinet6/in6_pcb.h> |
|
#include <netinet6/udp6_var.h> |
#include <netinet6/udp6_var.h> |
|
#include <netinet6/scope6_var.h> |
#endif |
#endif |
|
|
#ifndef INET6 |
#ifndef INET6 |
Line 146 int udpcksum = 1; |
|
Line 146 int udpcksum = 1; |
|
#else |
#else |
int udpcksum = 0; /* XXX */ |
int udpcksum = 0; /* XXX */ |
#endif |
#endif |
|
int udp_do_loopback_cksum = 0; |
|
|
struct inpcbtable udbtable; |
struct inpcbtable udbtable; |
struct udpstat udpstat; |
struct udpstat udpstat; |
Line 186 struct mowner udp_tx_mowner = { "udp", " |
|
Line 187 struct mowner udp_tx_mowner = { "udp", " |
|
#ifdef UDP_CSUM_COUNTERS |
#ifdef UDP_CSUM_COUNTERS |
#include <sys/device.h> |
#include <sys/device.h> |
|
|
|
#if defined(INET) |
struct evcnt udp_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
struct evcnt udp_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
NULL, "udp", "hwcsum bad"); |
NULL, "udp", "hwcsum bad"); |
struct evcnt udp_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
struct evcnt udp_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
Line 195 struct evcnt udp_hwcsum_data = EVCNT_INI |
|
Line 197 struct evcnt udp_hwcsum_data = EVCNT_INI |
|
struct evcnt udp_swcsum = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
struct evcnt udp_swcsum = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
NULL, "udp", "swcsum"); |
NULL, "udp", "swcsum"); |
|
|
#define UDP_CSUM_COUNTER_INCR(ev) (ev)->ev_count++ |
|
|
|
EVCNT_ATTACH_STATIC(udp_hwcsum_bad); |
EVCNT_ATTACH_STATIC(udp_hwcsum_bad); |
EVCNT_ATTACH_STATIC(udp_hwcsum_ok); |
EVCNT_ATTACH_STATIC(udp_hwcsum_ok); |
EVCNT_ATTACH_STATIC(udp_hwcsum_data); |
EVCNT_ATTACH_STATIC(udp_hwcsum_data); |
EVCNT_ATTACH_STATIC(udp_swcsum); |
EVCNT_ATTACH_STATIC(udp_swcsum); |
|
#endif /* defined(INET) */ |
|
|
|
#if defined(INET6) |
|
struct evcnt udp6_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
|
NULL, "udp6", "hwcsum bad"); |
|
struct evcnt udp6_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
|
NULL, "udp6", "hwcsum ok"); |
|
struct evcnt udp6_hwcsum_data = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
|
NULL, "udp6", "hwcsum data"); |
|
struct evcnt udp6_swcsum = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
|
NULL, "udp6", "swcsum"); |
|
|
|
EVCNT_ATTACH_STATIC(udp6_hwcsum_bad); |
|
EVCNT_ATTACH_STATIC(udp6_hwcsum_ok); |
|
EVCNT_ATTACH_STATIC(udp6_hwcsum_data); |
|
EVCNT_ATTACH_STATIC(udp6_swcsum); |
|
#endif /* defined(INET6) */ |
|
|
|
#define UDP_CSUM_COUNTER_INCR(ev) (ev)->ev_count++ |
|
|
#else |
#else |
|
|
|
|
udp6_input_checksum(struct mbuf *m, const struct udphdr *uh, int off, int len) |
udp6_input_checksum(struct mbuf *m, const struct udphdr *uh, int off, int len) |
{ |
{ |
|
|
|
/* |
|
* XXX it's better to record and check if this mbuf is |
|
* already checked. |
|
*/ |
|
|
if (__predict_false((m->m_flags & M_LOOP) && !udp_do_loopback_cksum)) { |
if (__predict_false((m->m_flags & M_LOOP) && !udp_do_loopback_cksum)) { |
goto good; |
goto good; |
} |
} |
Line 452 udp6_input_checksum(struct mbuf *m, cons |
|
Line 476 udp6_input_checksum(struct mbuf *m, cons |
|
udp6stat.udp6s_nosum++; |
udp6stat.udp6s_nosum++; |
goto bad; |
goto bad; |
} |
} |
if (in6_cksum(m, IPPROTO_UDP, off, len) != 0) { |
|
|
switch (m->m_pkthdr.csum_flags & |
|
((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_UDPv6) | |
|
M_CSUM_TCP_UDP_BAD | M_CSUM_DATA)) { |
|
case M_CSUM_UDPv6|M_CSUM_TCP_UDP_BAD: |
|
UDP_CSUM_COUNTER_INCR(&udp6_hwcsum_bad); |
udp6stat.udp6s_badsum++; |
udp6stat.udp6s_badsum++; |
goto bad; |
goto bad; |
|
|
|
#if 0 /* notyet */ |
|
case M_CSUM_UDPv6|M_CSUM_DATA: |
|
#endif |
|
|
|
case M_CSUM_UDPv6: |
|
/* Checksum was okay. */ |
|
UDP_CSUM_COUNTER_INCR(&udp6_hwcsum_ok); |
|
break; |
|
|
|
default: |
|
/* |
|
* Need to compute it ourselves. Maybe skip checksum |
|
* on loopback interfaces. |
|
*/ |
|
UDP_CSUM_COUNTER_INCR(&udp6_swcsum); |
|
if (in6_cksum(m, IPPROTO_UDP, off, len) != 0) { |
|
udp6stat.udp6s_badsum++; |
|
goto bad; |
|
} |
} |
} |
|
|
good: |
good: |
Line 526 udp6_input(struct mbuf **mp, int *offp, |
|
Line 575 udp6_input(struct mbuf **mp, int *offp, |
|
|
|
/* |
/* |
* Construct source and dst sockaddrs. |
* Construct source and dst sockaddrs. |
* Note that ifindex (s6_addr16[1]) is already filled. |
|
*/ |
*/ |
bzero(&src, sizeof(src)); |
bzero(&src, sizeof(src)); |
src.sin6_family = AF_INET6; |
src.sin6_family = AF_INET6; |
src.sin6_len = sizeof(struct sockaddr_in6); |
src.sin6_len = sizeof(struct sockaddr_in6); |
/* KAME hack: recover scopeid */ |
src.sin6_addr = ip6->ip6_src; |
(void)in6_recoverscope(&src, &ip6->ip6_src, m->m_pkthdr.rcvif); |
|
src.sin6_port = uh->uh_sport; |
src.sin6_port = uh->uh_sport; |
bzero(&dst, sizeof(dst)); |
bzero(&dst, sizeof(dst)); |
dst.sin6_family = AF_INET6; |
dst.sin6_family = AF_INET6; |
dst.sin6_len = sizeof(struct sockaddr_in6); |
dst.sin6_len = sizeof(struct sockaddr_in6); |
/* KAME hack: recover scopeid */ |
dst.sin6_addr = ip6->ip6_dst; |
(void)in6_recoverscope(&dst, &ip6->ip6_dst, m->m_pkthdr.rcvif); |
|
dst.sin6_port = uh->uh_dport; |
dst.sin6_port = uh->uh_dport; |
|
|
if (udp6_realinput(AF_INET6, &src, &dst, m, off) == 0) { |
if (udp6_realinput(AF_INET6, &src, &dst, m, off) == 0) { |
Line 796 udp6_realinput(int af, struct sockaddr_i |
|
Line 842 udp6_realinput(int af, struct sockaddr_i |
|
{ |
{ |
u_int16_t sport, dport; |
u_int16_t sport, dport; |
int rcvcnt; |
int rcvcnt; |
struct in6_addr src6, dst6; |
struct in6_addr src6, *dst6; |
const struct in_addr *dst4; |
const struct in_addr *dst4; |
struct inpcb_hdr *inph; |
struct inpcb_hdr *inph; |
struct in6pcb *in6p; |
struct in6pcb *in6p; |
Line 809 udp6_realinput(int af, struct sockaddr_i |
|
Line 855 udp6_realinput(int af, struct sockaddr_i |
|
if (src->sin6_family != AF_INET6 || dst->sin6_family != AF_INET6) |
if (src->sin6_family != AF_INET6 || dst->sin6_family != AF_INET6) |
goto bad; |
goto bad; |
|
|
in6_embedscope(&src6, src, NULL, NULL); |
src6 = src->sin6_addr; |
|
if (sa6_recoverscope(src) != 0) { |
|
/* XXX: should be impossible. */ |
|
goto bad; |
|
} |
sport = src->sin6_port; |
sport = src->sin6_port; |
in6_embedscope(&dst6, dst, NULL, NULL); |
|
dport = dst->sin6_port; |
dport = dst->sin6_port; |
dst4 = (struct in_addr *)&dst->sin6_addr.s6_addr[12]; |
dst4 = (struct in_addr *)&dst->sin6_addr.s6_addr[12]; |
|
dst6 = &dst->sin6_addr; |
|
|
if (IN6_IS_ADDR_MULTICAST(&dst6) || |
if (IN6_IS_ADDR_MULTICAST(dst6) || |
(af == AF_INET && IN_MULTICAST(dst4->s_addr))) { |
(af == AF_INET && IN_MULTICAST(dst4->s_addr))) { |
/* |
/* |
* Deliver a multicast or broadcast datagram to *all* sockets |
* Deliver a multicast or broadcast datagram to *all* sockets |
Line 848 udp6_realinput(int af, struct sockaddr_i |
|
Line 899 udp6_realinput(int af, struct sockaddr_i |
|
if (in6p->in6p_lport != dport) |
if (in6p->in6p_lport != dport) |
continue; |
continue; |
if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) { |
if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) { |
if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, &dst6)) |
if (!IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, |
|
dst6)) |
continue; |
continue; |
} else { |
} else { |
if (IN6_IS_ADDR_V4MAPPED(&dst6) && |
if (IN6_IS_ADDR_V4MAPPED(dst6) && |
(in6p->in6p_flags & IN6P_IPV6_V6ONLY)) |
(in6p->in6p_flags & IN6P_IPV6_V6ONLY)) |
continue; |
continue; |
} |
} |
Line 885 udp6_realinput(int af, struct sockaddr_i |
|
Line 937 udp6_realinput(int af, struct sockaddr_i |
|
/* |
/* |
* Locate pcb for datagram. |
* Locate pcb for datagram. |
*/ |
*/ |
in6p = in6_pcblookup_connect(&udbtable, &src6, sport, |
in6p = in6_pcblookup_connect(&udbtable, &src6, sport, dst6, |
&dst6, dport, 0); |
dport, 0); |
if (in6p == 0) { |
if (in6p == 0) { |
++udpstat.udps_pcbhashmiss; |
++udpstat.udps_pcbhashmiss; |
in6p = in6_pcblookup_bind(&udbtable, &dst6, dport, 0); |
in6p = in6_pcblookup_bind(&udbtable, dst6, dport, 0); |
if (in6p == 0) |
if (in6p == 0) |
return rcvcnt; |
return rcvcnt; |
} |
} |
Line 1126 int udp_recvspace = 40 * (1024 + sizeof( |
|
Line 1178 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(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, |
struct mbuf *control, struct proc *p) |
struct mbuf *control, struct lwp *l) |
{ |
{ |
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 1195 udp_usrreq(struct socket *so, int req, s |
|
Line 1249 udp_usrreq(struct socket *so, int req, s |
|
break; |
break; |
|
|
case PRU_CONNECT: |
case PRU_CONNECT: |
error = in_pcbconnect(inp, nam); |
error = in_pcbconnect(inp, nam, p); |
if (error) |
if (error) |
break; |
break; |
soisconnected(so); |
soisconnected(so); |
Line 1237 udp_usrreq(struct socket *so, int req, s |
|
Line 1291 udp_usrreq(struct socket *so, int req, s |
|
error = EISCONN; |
error = EISCONN; |
goto die; |
goto die; |
} |
} |
error = in_pcbconnect(inp, nam); |
error = in_pcbconnect(inp, nam, p); |
if (error) |
if (error) |
goto die; |
goto die; |
} else { |
} else { |
Line 1351 SYSCTL_SETUP(sysctl_net_inet_udp_setup, |
|
Line 1405 SYSCTL_SETUP(sysctl_net_inet_udp_setup, |
|
sysctl_inpcblist, 0, &udbtable, 0, |
sysctl_inpcblist, 0, &udbtable, 0, |
CTL_NET, PF_INET, IPPROTO_UDP, CTL_CREATE, |
CTL_NET, PF_INET, IPPROTO_UDP, CTL_CREATE, |
CTL_EOL); |
CTL_EOL); |
|
sysctl_createv(clog, 0, NULL, NULL, |
|
CTLFLAG_PERMANENT, |
|
CTLTYPE_STRUCT, "stats", |
|
SYSCTL_DESCR("UDP statistics"), |
|
NULL, 0, &udpstat, sizeof(udpstat), |
|
CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_STATS, |
|
CTL_EOL); |
} |
} |
#endif |
#endif |
|
|