version 1.75.2.6, 2002/01/08 00:34:12 |
version 1.121, 2004/05/07 00:55:15 |
|
|
/* |
/* |
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
* All rights reserved. |
* All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* modification, are permitted provided that the following conditions |
* are met: |
* are met: |
|
|
* 3. Neither the name of the project nor the names of its contributors |
* 3. Neither the name of the project nor the names of its contributors |
* may be used to endorse or promote products derived from this software |
* may be used to endorse or promote products derived from this software |
* without specific prior written permission. |
* without specific prior written permission. |
* |
* |
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND |
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
* 2. Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* documentation and/or other materials provided with the distribution. |
* 3. All advertising materials mentioning features or use of this software |
* 3. Neither the name of the University nor the names of its contributors |
* must display the following acknowledgement: |
|
* This product includes software developed by the University of |
|
* California, Berkeley and its contributors. |
|
* 4. Neither the name of the University nor the names of its contributors |
|
* may be used to endorse or promote products derived from this software |
* may be used to endorse or promote products derived from this software |
* without specific prior written permission. |
* without specific prior written permission. |
* |
* |
Line 71 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 67 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#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 <sys/param.h> |
#include <sys/param.h> |
#include <sys/malloc.h> |
#include <sys/malloc.h> |
Line 106 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 103 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <netinet6/udp6_var.h> |
#include <netinet6/udp6_var.h> |
#endif |
#endif |
|
|
#ifdef PULLDOWN_TEST |
|
#ifndef INET6 |
#ifndef INET6 |
/* always need ip6.h for IP6_EXTHDR_GET */ |
/* always need ip6.h for IP6_EXTHDR_GET */ |
#include <netinet/ip6.h> |
#include <netinet/ip6.h> |
#endif |
#endif |
#endif |
|
|
|
#include "faith.h" |
#include "faith.h" |
#if defined(NFAITH) && NFAITH > 0 |
#if defined(NFAITH) && NFAITH > 0 |
Line 120 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 115 __KERNEL_RCSID(0, "$NetBSD$"); |
|
|
|
#include <machine/stdarg.h> |
#include <machine/stdarg.h> |
|
|
|
#ifdef FAST_IPSEC |
|
#include <netipsec/ipsec.h> |
|
#include <netipsec/ipsec_var.h> /* XXX ipsecstat namespace */ |
|
#ifdef INET6 |
|
#include <netipsec/ipsec6.h> |
|
#endif |
|
#endif /* FAST_IPSEC*/ |
|
|
#ifdef IPSEC |
#ifdef IPSEC |
#include <netinet6/ipsec.h> |
#include <netinet6/ipsec.h> |
#include <netkey/key.h> |
#include <netkey/key.h> |
Line 139 int udpcksum = 1; |
|
Line 142 int udpcksum = 1; |
|
int udpcksum = 0; /* XXX */ |
int udpcksum = 0; /* XXX */ |
#endif |
#endif |
|
|
|
struct inpcbtable udbtable; |
|
struct udpstat udpstat; |
|
|
#ifdef INET |
#ifdef INET |
static void udp4_sendup __P((struct mbuf *, int, struct sockaddr *, |
static void udp4_sendup (struct mbuf *, int, struct sockaddr *, |
struct socket *)); |
struct socket *); |
static int udp4_realinput __P((struct sockaddr_in *, struct sockaddr_in *, |
static int udp4_realinput (struct sockaddr_in *, struct sockaddr_in *, |
struct mbuf *, int)); |
struct mbuf *, int); |
#endif |
#endif |
#ifdef INET6 |
#ifdef INET6 |
static void udp6_sendup __P((struct mbuf *, int, struct sockaddr *, |
static void udp6_sendup (struct mbuf *, int, struct sockaddr *, |
struct socket *)); |
struct socket *); |
static int udp6_realinput __P((int, struct sockaddr_in6 *, |
static int udp6_realinput (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 __P((struct inpcb *, int)); |
static void udp_notify (struct inpcb *, int); |
#endif |
#endif |
|
|
#ifndef UDBHASHSIZE |
#ifndef UDBHASHSIZE |
Line 160 static void udp_notify __P((struct inpcb |
|
Line 166 static void udp_notify __P((struct inpcb |
|
#endif |
#endif |
int udbhashsize = UDBHASHSIZE; |
int udbhashsize = UDBHASHSIZE; |
|
|
|
#ifdef MBUFTRACE |
|
struct mowner udp_mowner = { "udp" }; |
|
struct mowner udp_rx_mowner = { "udp", "rx" }; |
|
struct mowner udp_tx_mowner = { "udp", "tx" }; |
|
#endif |
|
|
#ifdef UDP_CSUM_COUNTERS |
#ifdef UDP_CSUM_COUNTERS |
#include <sys/device.h> |
#include <sys/device.h> |
|
|
Line 174 struct evcnt udp_swcsum = EVCNT_INITIALI |
|
Line 186 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 181 struct evcnt udp_swcsum = EVCNT_INITIALI |
|
Line 198 struct evcnt udp_swcsum = EVCNT_INITIALI |
|
#endif /* UDP_CSUM_COUNTERS */ |
#endif /* UDP_CSUM_COUNTERS */ |
|
|
void |
void |
udp_init() |
udp_init(void) |
{ |
{ |
|
|
#ifdef INET |
|
in_pcbinit(&udbtable, udbhashsize, udbhashsize); |
in_pcbinit(&udbtable, udbhashsize, udbhashsize); |
#endif |
|
|
|
#ifdef UDP_CSUM_COUNTERS |
MOWNER_ATTACH(&udp_tx_mowner); |
evcnt_attach_static(&udp_hwcsum_bad); |
MOWNER_ATTACH(&udp_rx_mowner); |
evcnt_attach_static(&udp_hwcsum_ok); |
MOWNER_ATTACH(&udp_mowner); |
evcnt_attach_static(&udp_hwcsum_data); |
|
evcnt_attach_static(&udp_swcsum); |
|
#endif /* UDP_CSUM_COUNTERS */ |
|
} |
} |
|
|
#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; |
struct ip *ip; |
struct ip *ip; |
struct udphdr *uh; |
struct udphdr *uh; |
int iphlen, proto; |
int iphlen; |
int len; |
int len; |
int n; |
int n; |
|
u_int16_t ip_len; |
|
|
va_start(ap, m); |
va_start(ap, m); |
iphlen = va_arg(ap, int); |
iphlen = va_arg(ap, int); |
proto = va_arg(ap, int); |
(void)va_arg(ap, int); /* ignore value, advance ap */ |
va_end(ap); |
va_end(ap); |
|
|
|
MCLAIM(m, &udp_rx_mowner); |
udpstat.udps_ipackets++; |
udpstat.udps_ipackets++; |
|
|
#ifndef PULLDOWN_TEST |
|
/* |
|
* Strip IP options, if any; should skip this, |
|
* make available to user, and use on returned packets, |
|
* but we don't yet have a way to check the checksum |
|
* with options still present. |
|
*/ |
|
if (iphlen > sizeof (struct ip)) { |
|
ip_stripoptions(m, (struct mbuf *)0); |
|
iphlen = sizeof(struct ip); |
|
} |
|
#else |
|
/* |
|
* we may enable the above code if we save and pass IPv4 options |
|
* to the userland. |
|
*/ |
|
#endif |
|
|
|
/* |
/* |
* Get IP and UDP header together in first mbuf. |
* Get IP and UDP header together in first mbuf. |
*/ |
*/ |
ip = mtod(m, struct ip *); |
ip = mtod(m, struct ip *); |
#ifndef PULLDOWN_TEST |
|
if (m->m_len < iphlen + sizeof(struct udphdr)) { |
|
if ((m = m_pullup(m, iphlen + sizeof(struct udphdr))) == 0) { |
|
udpstat.udps_hdrops++; |
|
return; |
|
} |
|
ip = mtod(m, struct ip *); |
|
} |
|
uh = (struct udphdr *)((caddr_t)ip + iphlen); |
|
#else |
|
IP6_EXTHDR_GET(uh, struct udphdr *, m, iphlen, sizeof(struct udphdr)); |
IP6_EXTHDR_GET(uh, struct udphdr *, m, iphlen, sizeof(struct udphdr)); |
if (uh == NULL) { |
if (uh == NULL) { |
udpstat.udps_hdrops++; |
udpstat.udps_hdrops++; |
return; |
return; |
} |
} |
#endif |
KASSERT(UDP_HDR_ALIGNED_P(uh)); |
|
|
/* destination port of 0 is illegal, based on RFC768. */ |
/* destination port of 0 is illegal, based on RFC768. */ |
if (uh->uh_dport == 0) |
if (uh->uh_dport == 0) |
Line 268 udp_input(m, va_alist) |
|
Line 248 udp_input(m, va_alist) |
|
* Make mbuf data length reflect UDP length. |
* Make mbuf data length reflect UDP length. |
* If not enough data to reflect UDP length, drop. |
* If not enough data to reflect UDP length, drop. |
*/ |
*/ |
|
ip_len = ntohs(ip->ip_len); |
len = ntohs((u_int16_t)uh->uh_ulen); |
len = ntohs((u_int16_t)uh->uh_ulen); |
if (ip->ip_len != iphlen + len) { |
if (ip_len != iphlen + len) { |
if (ip->ip_len < iphlen + len || len < sizeof(struct udphdr)) { |
if (ip_len < iphlen + len || len < sizeof(struct udphdr)) { |
udpstat.udps_badlen++; |
udpstat.udps_badlen++; |
goto bad; |
goto bad; |
} |
} |
m_adj(m, iphlen + len - ip->ip_len); |
m_adj(m, iphlen + len - ip_len); |
} |
} |
|
|
/* |
/* |
Line 282 udp_input(m, va_alist) |
|
Line 263 udp_input(m, va_alist) |
|
*/ |
*/ |
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; |
|
|
case M_CSUM_UDPv4|M_CSUM_DATA: |
case M_CSUM_UDPv4|M_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_data ^ 0xffff) != 0) |
if (m->m_pkthdr.csum_flags & M_CSUM_NO_PSEUDOHDR) |
|
hw_csum = in_cksum_phdr(ip->ip_src.s_addr, |
|
ip->ip_dst.s_addr, |
|
htons(hw_csum + len + IPPROTO_UDP)); |
|
if ((hw_csum ^ 0xffff) != 0) |
goto badcsum; |
goto badcsum; |
break; |
break; |
|
} |
|
|
case M_CSUM_UDPv4: |
case M_CSUM_UDPv4: |
/* Checksum was okay. */ |
/* Checksum was okay. */ |
|
|
|
|
#ifdef INET6 |
#ifdef INET6 |
int |
int |
udp6_input(mp, offp, proto) |
udp6_input(struct mbuf **mp, int *offp, int proto) |
struct mbuf **mp; |
|
int *offp, proto; |
|
{ |
{ |
struct mbuf *m = *mp; |
struct mbuf *m = *mp; |
int off = *offp; |
int off = *offp; |
Line 389 udp6_input(mp, offp, proto) |
|
Line 374 udp6_input(mp, offp, proto) |
|
struct udphdr *uh; |
struct udphdr *uh; |
u_int32_t plen, ulen; |
u_int32_t plen, ulen; |
|
|
#ifndef PULLDOWN_TEST |
|
IP6_EXTHDR_CHECK(m, off, sizeof(struct udphdr), IPPROTO_DONE); |
|
#endif |
|
ip6 = mtod(m, struct ip6_hdr *); |
ip6 = mtod(m, struct ip6_hdr *); |
|
|
#if defined(NFAITH) && 0 < NFAITH |
#if defined(NFAITH) && 0 < NFAITH |
Line 406 udp6_input(mp, offp, proto) |
|
Line 388 udp6_input(mp, offp, proto) |
|
|
|
/* check for jumbogram is done in ip6_input. we can trust pkthdr.len */ |
/* check for jumbogram is done in ip6_input. we can trust pkthdr.len */ |
plen = m->m_pkthdr.len - off; |
plen = m->m_pkthdr.len - off; |
#ifndef PULLDOWN_TEST |
|
uh = (struct udphdr *)((caddr_t)ip6 + off); |
|
#else |
|
IP6_EXTHDR_GET(uh, struct udphdr *, m, off, sizeof(struct udphdr)); |
IP6_EXTHDR_GET(uh, struct udphdr *, m, off, sizeof(struct udphdr)); |
if (uh == NULL) { |
if (uh == NULL) { |
ip6stat.ip6s_tooshort++; |
ip6stat.ip6s_tooshort++; |
return IPPROTO_DONE; |
return IPPROTO_DONE; |
} |
} |
#endif |
KASSERT(UDP_HDR_ALIGNED_P(uh)); |
ulen = ntohs((u_short)uh->uh_ulen); |
ulen = ntohs((u_short)uh->uh_ulen); |
/* |
/* |
* RFC2675 section 4: jumbograms will have 0 in the UDP header field, |
* RFC2675 section 4: jumbograms will have 0 in the UDP header field, |
Line 442 udp6_input(mp, offp, proto) |
|
Line 421 udp6_input(mp, offp, proto) |
|
/* |
/* |
* 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++; |
else if (in6_cksum(m, IPPROTO_UDP, off, ulen) != 0) { |
goto bad; |
|
} |
|
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(m, off, src, so) |
udp4_sendup(struct mbuf *m, int off /* offset of data portion */, |
struct mbuf *m; |
struct sockaddr *src, struct socket *so) |
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; |
struct inpcb *inp = NULL; |
struct inpcb *inp = NULL; |
#ifdef INET6 |
|
struct in6pcb *in6p = NULL; |
|
#endif |
|
|
|
if (!so) |
if (!so) |
return; |
return; |
Line 506 udp4_sendup(m, off, src, so) |
|
Line 481 udp4_sendup(m, off, src, so) |
|
break; |
break; |
#ifdef INET6 |
#ifdef INET6 |
case AF_INET6: |
case AF_INET6: |
in6p = sotoin6pcb(so); |
|
break; |
break; |
#endif |
#endif |
default: |
default: |
return; |
return; |
} |
} |
|
|
#ifdef IPSEC |
#if defined(IPSEC) || defined(FAST_IPSEC) |
/* check AH/ESP integrity. */ |
/* check AH/ESP integrity. */ |
if (so != NULL && ipsec4_in_reject_so(m, so)) { |
if (so != NULL && ipsec4_in_reject_so(m, so)) { |
ipsecstat.in_polvio++; |
ipsecstat.in_polvio++; |
|
if ((n = m_copy(m, 0, M_COPYALL)) != NULL) |
|
icmp_error(n, ICMP_UNREACH, ICMP_UNREACH_ADMIN_PROHIBIT, |
|
0, 0); |
return; |
return; |
} |
} |
#endif /*IPSEC*/ |
#endif /*IPSEC*/ |
Line 543 udp4_sendup(m, off, src, so) |
|
Line 520 udp4_sendup(m, off, src, so) |
|
|
|
#ifdef INET6 |
#ifdef INET6 |
static void |
static void |
udp6_sendup(m, off, src, so) |
udp6_sendup(struct mbuf *m, int off /* offset of data portion */, |
struct mbuf *m; |
struct sockaddr *src, struct socket *so) |
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 559 udp6_sendup(m, off, src, so) |
|
Line 533 udp6_sendup(m, off, src, so) |
|
return; |
return; |
in6p = sotoin6pcb(so); |
in6p = sotoin6pcb(so); |
|
|
#ifdef IPSEC |
#if defined(IPSEC) || defined(FAST_IPSEC) |
/* check AH/ESP integrity. */ |
/* check AH/ESP integrity. */ |
if (so != NULL && ipsec6_in_reject_so(m, so)) { |
if (so != NULL && ipsec6_in_reject_so(m, so)) { |
ipsec6stat.in_polvio++; |
ipsec6stat.in_polvio++; |
|
if ((n = m_copy(m, 0, M_COPYALL)) != NULL) |
|
icmp6_error(n, ICMP6_DST_UNREACH, |
|
ICMP6_DST_UNREACH_ADMIN, 0); |
return; |
return; |
} |
} |
#endif /*IPSEC*/ |
#endif /*IPSEC*/ |
Line 588 udp6_sendup(m, off, src, so) |
|
Line 565 udp6_sendup(m, off, src, so) |
|
|
|
#ifdef INET |
#ifdef INET |
static int |
static int |
udp4_realinput(src, dst, m, off) |
udp4_realinput(struct sockaddr_in *src, struct sockaddr_in *dst, |
struct sockaddr_in *src; |
struct mbuf *m, int off /* offset of udphdr */) |
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; |
struct in_addr *src4, *dst4; |
struct in_addr *src4, *dst4; |
|
struct inpcb_hdr *inph; |
struct inpcb *inp; |
struct inpcb *inp; |
|
|
rcvcnt = 0; |
rcvcnt = 0; |
Line 612 udp4_realinput(src, dst, m, off) |
|
Line 587 udp4_realinput(src, dst, m, off) |
|
|
|
if (IN_MULTICAST(dst4->s_addr) || |
if (IN_MULTICAST(dst4->s_addr) || |
in_broadcast(*dst4, m->m_pkthdr.rcvif)) { |
in_broadcast(*dst4, m->m_pkthdr.rcvif)) { |
struct inpcb *last; |
|
/* |
/* |
* 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 636 udp4_realinput(src, dst, m, off) |
|
Line 610 udp4_realinput(src, dst, m, off) |
|
/* |
/* |
* Locate pcb(s) for datagram. |
* Locate pcb(s) for datagram. |
*/ |
*/ |
CIRCLEQ_FOREACH(inp, &udbtable.inpt_queue, inp_queue) { |
CIRCLEQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { |
|
inp = (struct inpcb *)inph; |
|
if (inp->inp_af != AF_INET) |
|
continue; |
|
|
if (inp->inp_lport != *dport) |
if (inp->inp_lport != *dport) |
continue; |
continue; |
if (!in_nullhost(inp->inp_laddr)) { |
if (!in_nullhost(inp->inp_laddr)) { |
Line 649 udp4_realinput(src, dst, m, off) |
|
Line 627 udp4_realinput(src, dst, m, off) |
|
continue; |
continue; |
} |
} |
|
|
last = inp; |
|
udp4_sendup(m, off, (struct sockaddr *)src, |
udp4_sendup(m, off, (struct sockaddr *)src, |
inp->inp_socket); |
inp->inp_socket); |
rcvcnt++; |
rcvcnt++; |
|
|
|
|
#ifdef INET6 |
#ifdef INET6 |
static int |
static int |
udp6_realinput(af, src, dst, m, off) |
udp6_realinput(int af, struct sockaddr_in6 *src, struct sockaddr_in6 *dst, |
int af; /* af on packet */ |
struct mbuf *m, int off) |
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; |
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 in6pcb *in6p; |
struct in6pcb *in6p; |
|
|
rcvcnt = 0; |
rcvcnt = 0; |
Line 718 udp6_realinput(af, src, dst, m, off) |
|
Line 692 udp6_realinput(af, src, dst, m, off) |
|
|
|
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))) { |
struct in6pcb *last; |
|
/* |
/* |
* 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 742 udp6_realinput(af, src, dst, m, off) |
|
Line 715 udp6_realinput(af, src, dst, m, off) |
|
/* |
/* |
* Locate pcb(s) for datagram. |
* Locate pcb(s) for datagram. |
*/ |
*/ |
for (in6p = udb6.in6p_next; in6p != &udb6; |
CIRCLEQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { |
in6p = in6p->in6p_next) { |
in6p = (struct in6pcb *)inph; |
|
if (in6p->in6p_af != AF_INET6) |
|
continue; |
|
|
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)) { |
Line 764 udp6_realinput(af, src, dst, m, off) |
|
Line 740 udp6_realinput(af, src, dst, m, off) |
|
continue; |
continue; |
} |
} |
|
|
last = in6p; |
|
udp6_sendup(m, off, (struct sockaddr *)src, |
udp6_sendup(m, off, (struct sockaddr *)src, |
in6p->in6p_socket); |
in6p->in6p_socket); |
rcvcnt++; |
rcvcnt++; |
Line 785 udp6_realinput(af, src, dst, m, off) |
|
Line 760 udp6_realinput(af, src, dst, m, off) |
|
/* |
/* |
* Locate pcb for datagram. |
* Locate pcb for datagram. |
*/ |
*/ |
in6p = in6_pcblookup_connect(&udb6, &src6, sport, |
in6p = in6_pcblookup_connect(&udbtable, &src6, sport, |
&dst6, dport, 0); |
&dst6, dport, 0); |
if (in6p == 0) { |
if (in6p == 0) { |
++udpstat.udps_pcbhashmiss; |
++udpstat.udps_pcbhashmiss; |
in6p = in6_pcblookup_bind(&udb6, &dst6, dport, 0); |
in6p = in6_pcblookup_bind(&udbtable, &dst6, dport, 0); |
if (in6p == 0) |
if (in6p == 0) |
return rcvcnt; |
return 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(inp, errno) |
udp_notify(struct inpcb *inp, int 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(cmd, sa, v) |
udp_ctlinput(int cmd, struct sockaddr *sa, void *v) |
int cmd; |
|
struct sockaddr *sa; |
|
void *v; |
|
{ |
{ |
struct ip *ip = v; |
struct ip *ip = v; |
struct udphdr *uh; |
struct udphdr *uh; |
void (*notify) __P((struct inpcb *, int)) = udp_notify; |
void (*notify)(struct inpcb *, int) = udp_notify; |
int errno; |
int errno; |
|
|
if (sa->sa_family != AF_INET |
if (sa->sa_family != AF_INET |
Line 855 udp_ctlinput(cmd, sa, v) |
|
Line 824 udp_ctlinput(cmd, sa, v) |
|
} |
} |
|
|
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 869 udp_output(m, va_alist) |
|
Line 832 udp_output(m, va_alist) |
|
int error = 0; |
int error = 0; |
va_list ap; |
va_list ap; |
|
|
|
MCLAIM(m, &udp_tx_mowner); |
va_start(ap, m); |
va_start(ap, m); |
inp = va_arg(ap, struct inpcb *); |
inp = va_arg(ap, struct inpcb *); |
va_end(ap); |
va_end(ap); |
Line 887 udp_output(m, va_alist) |
|
Line 851 udp_output(m, va_alist) |
|
* Compute the packet length of the IP header, and |
* Compute the packet length of the IP header, and |
* punt if the length looks bogus. |
* punt if the length looks bogus. |
*/ |
*/ |
if ((len + sizeof(struct udpiphdr)) > IP_MAXPACKET) { |
if (len + sizeof(struct udpiphdr) > IP_MAXPACKET) { |
error = EMSGSIZE; |
error = EMSGSIZE; |
goto release; |
goto release; |
} |
} |
Line 919 udp_output(m, va_alist) |
|
Line 883 udp_output(m, va_alist) |
|
m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum); |
m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum); |
} else |
} else |
ui->ui_sum = 0; |
ui->ui_sum = 0; |
((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len; |
((struct ip *)ui)->ip_len = htons(sizeof (struct udpiphdr) + len); |
((struct ip *)ui)->ip_ttl = inp->inp_ip.ip_ttl; /* XXX */ |
((struct ip *)ui)->ip_ttl = inp->inp_ip.ip_ttl; /* XXX */ |
((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos; /* XXX */ |
((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos; /* XXX */ |
udpstat.udps_opackets++; |
udpstat.udps_opackets++; |
|
|
#ifdef IPSEC |
|
if (ipsec_setsocket(m, inp->inp_socket) != 0) { |
|
error = ENOBUFS; |
|
goto release; |
|
} |
|
#endif /*IPSEC*/ |
|
|
|
return (ip_output(m, inp->inp_options, &inp->inp_route, |
return (ip_output(m, inp->inp_options, &inp->inp_route, |
inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST), |
inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST), |
inp->inp_moptions)); |
inp->inp_moptions, inp->inp_socket)); |
|
|
release: |
release: |
m_freem(m); |
m_freem(m); |
Line 946 int udp_recvspace = 40 * (1024 + sizeof( |
|
Line 903 int udp_recvspace = 40 * (1024 + sizeof( |
|
|
|
/*ARGSUSED*/ |
/*ARGSUSED*/ |
int |
int |
udp_usrreq(so, req, m, nam, control, p) |
udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, |
struct socket *so; |
struct mbuf *control, struct proc *p) |
int req; |
|
struct mbuf *m, *nam, *control; |
|
struct proc *p; |
|
{ |
{ |
struct inpcb *inp; |
struct inpcb *inp; |
int s; |
int s; |
Line 989 udp_usrreq(so, req, m, nam, control, p) |
|
Line 943 udp_usrreq(so, req, m, nam, control, p) |
|
error = EISCONN; |
error = EISCONN; |
break; |
break; |
} |
} |
|
#ifdef MBUFTRACE |
|
so->so_mowner = &udp_mowner; |
|
so->so_rcv.sb_mowner = &udp_rx_mowner; |
|
so->so_snd.sb_mowner = &udp_tx_mowner; |
|
#endif |
if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { |
if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { |
error = soreserve(so, udp_sendspace, udp_recvspace); |
error = soreserve(so, udp_sendspace, udp_recvspace); |
if (error) |
if (error) |
Line 1057 udp_usrreq(so, req, m, nam, control, p) |
|
Line 1016 udp_usrreq(so, req, m, nam, control, p) |
|
goto die; |
goto die; |
} |
} |
error = in_pcbconnect(inp, nam); |
error = in_pcbconnect(inp, nam); |
if (error) { |
if (error) |
die: |
goto die; |
m_freem(m); |
|
break; |
|
} |
|
} else { |
} else { |
if ((so->so_state & SS_ISCONNECTED) == 0) { |
if ((so->so_state & SS_ISCONNECTED) == 0) { |
error = ENOTCONN; |
error = ENOTCONN; |
Line 1069 udp_usrreq(so, req, m, nam, control, p) |
|
Line 1025 udp_usrreq(so, req, m, nam, control, p) |
|
} |
} |
} |
} |
error = udp_output(m, inp); |
error = udp_output(m, inp); |
|
m = NULL; |
if (nam) { |
if (nam) { |
in_pcbdisconnect(inp); |
in_pcbdisconnect(inp); |
inp->inp_laddr = laddr; /* XXX */ |
inp->inp_laddr = laddr; /* XXX */ |
in_pcbstate(inp, INP_BOUND); /* XXX */ |
in_pcbstate(inp, INP_BOUND); /* XXX */ |
} |
} |
|
die: |
|
if (m) |
|
m_freem(m); |
} |
} |
break; |
break; |
|
|
|
|
/* |
/* |
* Sysctl for udp variables. |
* Sysctl for udp variables. |
*/ |
*/ |
int |
SYSCTL_SETUP(sysctl_net_inet_udp_setup, "sysctl net.inet.udp subtree setup") |
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. */ |
|
if (namelen != 1) |
sysctl_createv(clog, 0, NULL, NULL, |
return (ENOTDIR); |
CTLFLAG_PERMANENT, |
|
CTLTYPE_NODE, "net", NULL, |
switch (name[0]) { |
NULL, 0, NULL, 0, |
case UDPCTL_CHECKSUM: |
CTL_NET, CTL_EOL); |
return (sysctl_int(oldp, oldlenp, newp, newlen, &udpcksum)); |
sysctl_createv(clog, 0, NULL, NULL, |
case UDPCTL_SENDSPACE: |
CTLFLAG_PERMANENT, |
return (sysctl_int(oldp, oldlenp, newp, newlen, |
CTLTYPE_NODE, "inet", NULL, |
&udp_sendspace)); |
NULL, 0, NULL, 0, |
case UDPCTL_RECVSPACE: |
CTL_NET, PF_INET, CTL_EOL); |
return (sysctl_int(oldp, oldlenp, newp, newlen, |
sysctl_createv(clog, 0, NULL, NULL, |
&udp_recvspace)); |
CTLFLAG_PERMANENT, |
default: |
CTLTYPE_NODE, "udp", NULL, |
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", NULL, |
|
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", NULL, |
|
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", NULL, |
|
NULL, 0, &udp_recvspace, 0, |
|
CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_RECVSPACE, |
|
CTL_EOL); |
} |
} |
#endif |
#endif |