Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Move udp6_input(), udp6_sendup(), udp6_realinput() and u...
details: https://anonhg.NetBSD.org/src/rev/c8992b008bfe
branches: trunk
changeset: 329394:c8992b008bfe
user: rmind <rmind%NetBSD.org@localhost>
date: Thu May 22 22:56:53 2014 +0000
description:
Move udp6_input(), udp6_sendup(), udp6_realinput() and udp6_input_checksum()
from udp_usrreq.c to udp6_usrreq.c where they belong. No functional change.
diffstat:
sys/netinet/udp_usrreq.c | 362 +--------------------------------------------
sys/netinet6/in6_proto.c | 9 +-
sys/netinet6/udp6_usrreq.c | 351 ++++++++++++++++++++++++++++++++++++++++++-
sys/netinet6/udp6_var.h | 5 +-
4 files changed, 354 insertions(+), 373 deletions(-)
diffs (truncated from 906 to 300 lines):
diff -r 4a7de01058a0 -r c8992b008bfe sys/netinet/udp_usrreq.c
--- a/sys/netinet/udp_usrreq.c Thu May 22 22:01:12 2014 +0000
+++ b/sys/netinet/udp_usrreq.c Thu May 22 22:56:53 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: udp_usrreq.c,v 1.197 2014/05/20 19:04:00 rmind Exp $ */
+/* $NetBSD: udp_usrreq.c,v 1.198 2014/05/22 22:56:53 rmind Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -60,8 +60,13 @@
* @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95
*/
+/*
+ * UDP protocol implementation.
+ * Per RFC 768, August, 1980.
+ */
+
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.197 2014/05/20 19:04:00 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.198 2014/05/22 22:56:53 rmind Exp $");
#include "opt_inet.h"
#include "opt_compat_netbsd.h"
@@ -71,14 +76,11 @@
#include "opt_mbuftrace.h"
#include <sys/param.h>
-#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/once.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
-#include <sys/errno.h>
-#include <sys/stat.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/domain.h>
@@ -106,7 +108,6 @@
#include <netinet6/in6_pcb.h>
#include <netinet6/udp6_var.h>
#include <netinet6/udp6_private.h>
-#include <netinet6/scope6_var.h>
#endif
#ifndef INET6
@@ -114,11 +115,6 @@
#include <netinet/ip6.h>
#endif
-#include "faith.h"
-#if defined(NFAITH) && NFAITH > 0
-#include <net/if_faith.h>
-#endif
-
#ifdef IPSEC
#include <netipsec/ipsec.h>
#include <netipsec/ipsec_var.h>
@@ -137,10 +133,6 @@
#include <ipkdb/ipkdb.h>
#endif
-/*
- * UDP protocol implementation.
- * Per RFC 768, August, 1980.
- */
int udpcksum = 1;
int udp_do_loopback_cksum = 0;
@@ -159,13 +151,6 @@
struct mbuf **, int);
static int udp4_input_checksum(struct mbuf *, const struct udphdr *, int, int);
#endif
-#ifdef INET6
-static void udp6_sendup (struct mbuf *, int, struct sockaddr *,
- struct socket *);
-static int udp6_realinput (int, struct sockaddr_in6 *,
- struct sockaddr_in6 *, struct mbuf *, int);
-static int udp6_input_checksum(struct mbuf *, const struct udphdr *, int, int);
-#endif
#ifdef INET
static void udp_notify (struct inpcb *, int);
#endif
@@ -206,28 +191,9 @@
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
-
#define UDP_CSUM_COUNTER_INCR(ev) /* nothing */
-
#endif /* UDP_CSUM_COUNTERS */
static void sysctl_net_inet_udp_setup(struct sysctllog **);
@@ -484,151 +450,6 @@
}
#endif
-#ifdef INET6
-static int
-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)) {
- goto good;
- }
- if (uh->uh_sum == 0) {
- UDP6_STATINC(UDP6_STAT_NOSUM);
- goto bad;
- }
-
- 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);
- UDP6_STATINC(UDP6_STAT_BADSUM);
- 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) {
- UDP6_STATINC(UDP6_STAT_BADSUM);
- goto bad;
- }
- }
-
-good:
- return 0;
-bad:
- return -1;
-}
-
-int
-udp6_input(struct mbuf **mp, int *offp, int proto)
-{
- struct mbuf *m = *mp;
- int off = *offp;
- struct sockaddr_in6 src, dst;
- struct ip6_hdr *ip6;
- struct udphdr *uh;
- u_int32_t plen, ulen;
-
- ip6 = mtod(m, struct ip6_hdr *);
-
-#if defined(NFAITH) && 0 < NFAITH
- if (faithprefix(&ip6->ip6_dst)) {
- /* send icmp6 host unreach? */
- m_freem(m);
- return IPPROTO_DONE;
- }
-#endif
-
- UDP6_STATINC(UDP6_STAT_IPACKETS);
-
- /* check for jumbogram is done in ip6_input. we can trust pkthdr.len */
- plen = m->m_pkthdr.len - off;
- IP6_EXTHDR_GET(uh, struct udphdr *, m, off, sizeof(struct udphdr));
- if (uh == NULL) {
- IP6_STATINC(IP6_STAT_TOOSHORT);
- return IPPROTO_DONE;
- }
- KASSERT(UDP_HDR_ALIGNED_P(uh));
- ulen = ntohs((u_short)uh->uh_ulen);
- /*
- * RFC2675 section 4: jumbograms will have 0 in the UDP header field,
- * iff payload length > 0xffff.
- */
- if (ulen == 0 && plen > 0xffff)
- ulen = plen;
-
- if (plen != ulen) {
- UDP6_STATINC(UDP6_STAT_BADLEN);
- goto bad;
- }
-
- /* destination port of 0 is illegal, based on RFC768. */
- if (uh->uh_dport == 0)
- goto bad;
-
- /* Be proactive about malicious use of IPv4 mapped address */
- if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) ||
- IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
- /* XXX stat */
- goto bad;
- }
-
- /*
- * Checksum extended UDP header and data. Maybe skip checksum
- * on loopback interfaces.
- */
- if (udp6_input_checksum(m, uh, off, ulen))
- goto bad;
-
- /*
- * Construct source and dst sockaddrs.
- */
- memset(&src, 0, sizeof(src));
- src.sin6_family = AF_INET6;
- src.sin6_len = sizeof(struct sockaddr_in6);
- src.sin6_addr = ip6->ip6_src;
- src.sin6_port = uh->uh_sport;
- memset(&dst, 0, sizeof(dst));
- dst.sin6_family = AF_INET6;
- dst.sin6_len = sizeof(struct sockaddr_in6);
- dst.sin6_addr = ip6->ip6_dst;
- dst.sin6_port = uh->uh_dport;
-
- if (udp6_realinput(AF_INET6, &src, &dst, m, off) == 0) {
- if (m->m_flags & M_MCAST) {
- UDP6_STATINC(UDP6_STAT_NOPORTMCAST);
- goto bad;
- }
- UDP6_STATINC(UDP6_STAT_NOPORT);
- icmp6_error(m, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT, 0);
- m = NULL;
- }
-
-bad:
- if (m)
- m_freem(m);
- return IPPROTO_DONE;
-}
-#endif
-
#ifdef INET
static void
udp4_sendup(struct mbuf *m, int off /* offset of data portion */,
@@ -687,55 +508,6 @@
}
#endif
-#ifdef INET6
-static void
-udp6_sendup(struct mbuf *m, int off /* offset of data portion */,
- struct sockaddr *src, struct socket *so)
-{
- struct mbuf *opts = NULL;
- struct mbuf *n;
- struct in6pcb *in6p = NULL;
-
- if (!so)
- return;
- if (so->so_proto->pr_domain->dom_family != AF_INET6)
- return;
- in6p = sotoin6pcb(so);
-
-#if defined(IPSEC)
- /* check AH/ESP integrity. */
- if (so != NULL && ipsec6_in_reject_so(m, so)) {
- IPSEC6_STATINC(IPSEC_STAT_IN_POLVIO);
- if ((n = m_copypacket(m, M_DONTWAIT)) != NULL)
- icmp6_error(n, ICMP6_DST_UNREACH,
- ICMP6_DST_UNREACH_ADMIN, 0);
- return;
- }
-#endif /*IPSEC*/
-
- if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) {
- if (in6p && (in6p->in6p_flags & IN6P_CONTROLOPTS
-#ifdef SO_OTIMESTAMP
- || in6p->in6p_socket->so_options & SO_OTIMESTAMP
-#endif
Home |
Main Index |
Thread Index |
Old Index