version 1.148, 2006/07/23 22:06:13 |
version 1.158.2.1, 2007/06/08 14:17:48 |
Line 139 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 139 __KERNEL_RCSID(0, "$NetBSD$"); |
|
* UDP protocol implementation. |
* UDP protocol implementation. |
* Per RFC 768, August, 1980. |
* Per RFC 768, August, 1980. |
*/ |
*/ |
#ifndef COMPAT_42 |
|
int udpcksum = 1; |
int udpcksum = 1; |
#else |
|
int udpcksum = 0; /* XXX */ |
|
#endif |
|
int udp_do_loopback_cksum = 0; |
int udp_do_loopback_cksum = 0; |
|
|
struct inpcbtable udbtable; |
struct inpcbtable udbtable; |
Line 177 static void udp_notify (struct inpcb *, |
|
Line 173 static void udp_notify (struct inpcb *, |
|
int udbhashsize = UDBHASHSIZE; |
int udbhashsize = UDBHASHSIZE; |
|
|
#ifdef MBUFTRACE |
#ifdef MBUFTRACE |
struct mowner udp_mowner = { "udp" }; |
struct mowner udp_mowner = MOWNER_INIT("udp", ""); |
struct mowner udp_rx_mowner = { "udp", "rx" }; |
struct mowner udp_rx_mowner = MOWNER_INIT("udp", "rx"); |
struct mowner udp_tx_mowner = { "udp", "tx" }; |
struct mowner udp_tx_mowner = MOWNER_INIT("udp", "tx"); |
#endif |
#endif |
|
|
#ifdef UDP_CSUM_COUNTERS |
#ifdef UDP_CSUM_COUNTERS |
Line 388 udp_input(struct mbuf *m, ...) |
|
Line 384 udp_input(struct mbuf *m, ...) |
|
goto badcsum; |
goto badcsum; |
|
|
/* construct source and dst sockaddrs. */ |
/* construct source and dst sockaddrs. */ |
bzero(&src, sizeof(src)); |
sockaddr_in_init(&src, &ip->ip_src, uh->uh_sport); |
src.sin_family = AF_INET; |
sockaddr_in_init(&dst, &ip->ip_dst, uh->uh_dport); |
src.sin_len = sizeof(struct sockaddr_in); |
|
bcopy(&ip->ip_src, &src.sin_addr, sizeof(src.sin_addr)); |
|
src.sin_port = uh->uh_sport; |
|
bzero(&dst, sizeof(dst)); |
|
dst.sin_family = AF_INET; |
|
dst.sin_len = sizeof(struct sockaddr_in); |
|
bcopy(&ip->ip_dst, &dst.sin_addr, sizeof(dst.sin_addr)); |
|
dst.sin_port = uh->uh_dport; |
|
|
|
if ((n = udp4_realinput(&src, &dst, &m, iphlen)) == -1) { |
if ((n = udp4_realinput(&src, &dst, &m, iphlen)) == -1) { |
udpstat.udps_hdrops++; |
udpstat.udps_hdrops++; |
Line 967 udp_notify(struct inpcb *inp, int errno) |
|
Line 955 udp_notify(struct inpcb *inp, int errno) |
|
} |
} |
|
|
void * |
void * |
udp_ctlinput(int cmd, struct sockaddr *sa, void *v) |
udp_ctlinput(int cmd, const struct sockaddr *sa, void *v) |
{ |
{ |
struct ip *ip = v; |
struct ip *ip = v; |
struct udphdr *uh; |
struct udphdr *uh; |
Line 987 udp_ctlinput(int cmd, struct sockaddr *s |
|
Line 975 udp_ctlinput(int cmd, struct sockaddr *s |
|
else if (errno == 0) |
else if (errno == 0) |
return NULL; |
return NULL; |
if (ip) { |
if (ip) { |
uh = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2)); |
uh = (struct udphdr *)((char *)ip + (ip->ip_hl << 2)); |
in_pcbnotify(&udbtable, satosin(sa)->sin_addr, uh->uh_dport, |
in_pcbnotify(&udbtable, satocsin(sa)->sin_addr, uh->uh_dport, |
ip->ip_src, uh->uh_sport, errno, notify); |
ip->ip_src, uh->uh_sport, errno, notify); |
|
|
/* XXX mapped address case */ |
/* XXX mapped address case */ |
} else |
} else |
in_pcbnotifyall(&udbtable, satosin(sa)->sin_addr, errno, |
in_pcbnotifyall(&udbtable, satocsin(sa)->sin_addr, errno, |
notify); |
notify); |
return NULL; |
return NULL; |
} |
} |
|
|
int |
int |
udp_ctloutput(op, so, level, optname, mp) |
udp_ctloutput(int op, struct socket *so, int level, int optname, |
int op; |
struct mbuf **mp) |
struct socket *so; |
|
int level, optname; |
|
struct mbuf **mp; |
|
{ |
{ |
int s; |
int s; |
int error = 0; |
int error = 0; |
Line 1034 udp_ctloutput(op, so, level, optname, mp |
|
Line 1019 udp_ctloutput(op, so, level, optname, mp |
|
default: |
default: |
error = EAFNOSUPPORT; |
error = EAFNOSUPPORT; |
goto end; |
goto end; |
break; |
|
} |
} |
|
|
|
|
Line 1047 udp_ctloutput(op, so, level, optname, mp |
|
Line 1031 udp_ctloutput(op, so, level, optname, mp |
|
case UDP_ENCAP: |
case UDP_ENCAP: |
if (m == NULL || m->m_len < sizeof (int)) { |
if (m == NULL || m->m_len < sizeof (int)) { |
error = EINVAL; |
error = EINVAL; |
goto end; |
break; |
} |
} |
|
|
switch(*mtod(m, int *)) { |
switch(*mtod(m, int *)) { |
Line 1068 udp_ctloutput(op, so, level, optname, mp |
|
Line 1052 udp_ctloutput(op, so, level, optname, mp |
|
#endif |
#endif |
default: |
default: |
error = EINVAL; |
error = EINVAL; |
goto end; |
|
break; |
break; |
} |
} |
break; |
break; |
|
|
default: |
default: |
error = ENOPROTOOPT; |
error = ENOPROTOOPT; |
goto end; |
|
break; |
break; |
} |
} |
|
if (m != NULL) { |
|
m_free(m); |
|
} |
break; |
break; |
|
|
default: |
default: |
error = EINVAL; |
error = EINVAL; |
goto end; |
|
break; |
break; |
} |
} |
|
|
Line 1183 udp_usrreq(struct socket *so, int req, s |
|
Line 1167 udp_usrreq(struct socket *so, int req, s |
|
int error = 0; |
int error = 0; |
|
|
if (req == PRU_CONTROL) |
if (req == PRU_CONTROL) |
return (in_control(so, (long)m, (caddr_t)nam, |
return (in_control(so, (long)m, (void *)nam, |
(struct ifnet *)control, l)); |
(struct ifnet *)control, l)); |
|
|
|
s = splsoftnet(); |
|
|
if (req == PRU_PURGEIF) { |
if (req == PRU_PURGEIF) { |
in_pcbpurgeif0(&udbtable, (struct ifnet *)control); |
in_pcbpurgeif0(&udbtable, (struct ifnet *)control); |
in_purgeif((struct ifnet *)control); |
in_purgeif((struct ifnet *)control); |
in_pcbpurgeif(&udbtable, (struct ifnet *)control); |
in_pcbpurgeif(&udbtable, (struct ifnet *)control); |
|
splx(s); |
return (0); |
return (0); |
} |
} |
|
|
s = splsoftnet(); |
|
inp = sotoinpcb(so); |
inp = sotoinpcb(so); |
#ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
if (req != PRU_SEND && req != PRU_SENDOOB && control) |
if (req != PRU_SEND && req != PRU_SENDOOB && control) |
Line 1419 SYSCTL_SETUP(sysctl_net_inet_udp_setup, |
|
Line 1405 SYSCTL_SETUP(sysctl_net_inet_udp_setup, |
|
* -1 if an error occurent and m was freed |
* -1 if an error occurent and m was freed |
*/ |
*/ |
static int |
static int |
udp4_espinudp(mp, off, src, so) |
udp4_espinudp(struct mbuf **mp, int off, struct sockaddr *src, |
struct mbuf **mp; |
struct socket *so) |
int off; |
|
struct sockaddr *src; |
|
struct socket *so; |
|
{ |
{ |
size_t len; |
size_t len; |
caddr_t data; |
void *data; |
struct inpcb *inp; |
struct inpcb *inp; |
size_t skip = 0; |
size_t skip = 0; |
size_t minlen; |
size_t minlen; |
Line 1455 udp4_espinudp(mp, off, src, so) |
|
Line 1438 udp4_espinudp(mp, off, src, so) |
|
} |
} |
|
|
len = m->m_len - off; |
len = m->m_len - off; |
data = mtod(m, caddr_t) + off; |
data = mtod(m, char *) + off; |
inp = sotoinpcb(so); |
inp = sotoinpcb(so); |
|
|
/* Ignore keepalive packets */ |
/* Ignore keepalive packets */ |
if ((len == 1) && (data[0] == '\xff')) { |
if ((len == 1) && (*(unsigned char *)data == 0xff)) { |
return 1; |
return 1; |
} |
} |
|
|
Line 1491 udp4_espinudp(mp, off, src, so) |
|
Line 1474 udp4_espinudp(mp, off, src, so) |
|
* 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 *)(data - skip); |
udphdr = (struct udphdr *)((char *)data - skip); |
sport = udphdr->uh_sport; |
sport = udphdr->uh_sport; |
dport = udphdr->uh_dport; |
dport = udphdr->uh_dport; |
|
|
Line 1511 udp4_espinudp(mp, off, src, so) |
|
Line 1494 udp4_espinudp(mp, off, src, so) |
|
* <-skip-> |
* <-skip-> |
*/ |
*/ |
iphdrlen = off - sizeof(struct udphdr); |
iphdrlen = off - sizeof(struct udphdr); |
memmove(mtod(m, caddr_t) + skip, mtod(m, caddr_t), iphdrlen); |
memmove(mtod(m, char *) + skip, mtod(m, void *), iphdrlen); |
m_adj(m, skip); |
m_adj(m, skip); |
|
|
ip = mtod(m, struct ip *); |
ip = mtod(m, struct ip *); |