summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/conf/files3
-rw-r--r--sys/netinet/in_pcb.h3
-rw-r--r--sys/netinet/udp_usrreq.c9
-rw-r--r--sys/netinet/udp_var.h6
-rw-r--r--sys/netinet6/in6_proto.c4
-rw-r--r--sys/netinet6/udp6_output.c295
6 files changed, 314 insertions, 6 deletions
diff --git a/sys/conf/files b/sys/conf/files
index 9fbf1874a92..45539127730 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -1,4 +1,4 @@
-# $OpenBSD: files,v 1.169 2000/06/17 17:16:04 provos Exp $
+# $OpenBSD: files,v 1.170 2000/06/18 17:32:42 itojun Exp $
# $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@@ -778,6 +778,7 @@ file netinet6/nd6_rtr.c inet6
#file netinet6/tcp6_timer.c inet6 & tcp6
#file netinet6/tcp6_usrreq.c inet6 & tcp6
#file netinet6/udp6_usrreq.c inet6
+file netinet6/udp6_output.c inet6
# ... PF_KEY
file net/pfkey.c key | ipsec | tcp_signature
diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h
index 0ed2bc044aa..6ac62c01529 100644
--- a/sys/netinet/in_pcb.h
+++ b/sys/netinet/in_pcb.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: in_pcb.h,v 1.24 2000/06/13 10:12:00 itojun Exp $ */
+/* $OpenBSD: in_pcb.h,v 1.25 2000/06/18 17:32:48 itojun Exp $ */
/* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */
/*
@@ -271,6 +271,7 @@ struct in6_addr *in6_selectsrc __P((struct sockaddr_in6 *,
struct route_in6 *,
struct in6_addr *, int *));
int in6_selecthlim __P((struct inpcb *, struct ifnet *));
+int in6_pcbsetport __P((struct in6_addr *, struct inpcb *));
int in6_embedscope __P((struct in6_addr *, const struct sockaddr_in6 *,
struct inpcb *, struct ifnet **));
int in6_recoverscope __P((struct sockaddr_in6 *, const struct in6_addr *,
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index 090a52b1d5f..f57471be513 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: udp_usrreq.c,v 1.44 2000/06/13 11:47:24 itojun Exp $ */
+/* $OpenBSD: udp_usrreq.c,v 1.45 2000/06/18 17:32:48 itojun Exp $ */
/* $NetBSD: udp_usrreq.c,v 1.28 1996/03/16 23:54:03 christos Exp $ */
/*
@@ -1165,7 +1165,14 @@ udp_usrreq(so, req, m, addr, control)
if (error)
return (error);
#endif
+#ifdef INET6
+ if (inp->inp_flags & INP_IPV6)
+ return (udp6_output(inp, m, addr, control));
+ else
+ return (udp_output(m, inp, addr, control));
+#else
return (udp_output(m, inp, addr, control));
+#endif
case PRU_ABORT:
soisdisconnected(so);
diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h
index e1e409e3985..b6064b0cc89 100644
--- a/sys/netinet/udp_var.h
+++ b/sys/netinet/udp_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: udp_var.h,v 1.9 1999/12/08 06:50:20 itojun Exp $ */
+/* $OpenBSD: udp_var.h,v 1.10 2000/06/18 17:32:48 itojun Exp $ */
/* $NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $ */
/*
@@ -99,6 +99,10 @@ int udp6_usrreq __P((struct socket *,
void *udp_ctlinput __P((int, struct sockaddr *, void *));
void udp_init __P((void));
void udp_input __P((struct mbuf *, ...));
+#ifdef INET6
+int udp6_output __P((struct inpcb *, struct mbuf *, struct mbuf *,
+ struct mbuf *));
+#endif
int udp_output __P((struct mbuf *, ...));
int udp_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
int udp_usrreq __P((struct socket *,
diff --git a/sys/netinet6/in6_proto.c b/sys/netinet6/in6_proto.c
index d771bd67761..65424304f3d 100644
--- a/sys/netinet6/in6_proto.c
+++ b/sys/netinet6/in6_proto.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in6_proto.c,v 1.21 2000/05/25 01:22:00 itojun Exp $ */
+/* $OpenBSD: in6_proto.c,v 1.22 2000/06/18 17:32:48 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -125,7 +125,7 @@ struct ip6protosw inet6sw[] = {
},
{ SOCK_DGRAM, &inet6domain, IPPROTO_UDP, PR_ATOMIC | PR_ADDR,
udp6_input, 0, udp6_ctlinput, ip6_ctloutput,
- udp6_usrreq, 0,
+ udp6_usrreq, 0,
0, 0, 0,
udp_sysctl,
},
diff --git a/sys/netinet6/udp6_output.c b/sys/netinet6/udp6_output.c
new file mode 100644
index 00000000000..1a2b5e5d853
--- /dev/null
+++ b/sys/netinet6/udp6_output.c
@@ -0,0 +1,295 @@
+/* $KAME: udp6_output.c,v 1.14 2000/06/13 10:31:23 itojun Exp $ */
+
+/*
+ * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 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
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * 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
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)udp_var.h 8.1 (Berkeley) 6/10/93
+ */
+
+#include <sys/param.h>
+#include <sys/malloc.h>
+#include <sys/mbuf.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/syslog.h>
+
+#include <net/if.h>
+#include <net/route.h>
+#include <net/if_types.h>
+
+#include <netinet/in.h>
+#include <netinet/in_var.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_var.h>
+#include <netinet/in_pcb.h>
+#include <netinet/udp.h>
+#include <netinet/udp_var.h>
+#include <netinet/ip6.h>
+#include <netinet6/ip6_var.h>
+#include <netinet/icmp6.h>
+#include <netinet6/ip6protosw.h>
+
+#undef IPSEC
+
+#include "faith.h"
+
+#include <net/net_osdep.h>
+
+/*
+ * UDP protocol inplementation.
+ * Per RFC 768, August, 1980.
+ */
+
+#define in6pcb inpcb
+#define in6p_outputopts inp_outputopts6
+#define in6p_socket inp_socket
+#define in6p_faddr inp_faddr6
+#define in6p_laddr inp_laddr6
+#define in6p_fport inp_fport
+#define in6p_lport inp_lport
+#define in6p_flags inp_flags
+#define in6p_moptions inp_moptions6
+#define in6p_route inp_route6
+#define in6p_flowinfo inp_fflowinfo
+#define udp6stat udpstat
+#define udp6s_opackets udps_opackets
+
+int
+udp6_output(in6p, m, addr6, control)
+ register struct in6pcb *in6p;
+ register struct mbuf *m;
+ struct mbuf *addr6, *control;
+{
+ register u_int32_t ulen = m->m_pkthdr.len;
+ u_int32_t plen = sizeof(struct udphdr) + ulen;
+ struct ip6_hdr *ip6;
+ struct udphdr *udp6;
+ struct in6_addr *laddr, *faddr;
+ u_short fport;
+ int error = 0;
+ struct ip6_pktopts opt, *stickyopt;
+ int priv;
+ int af, hlen;
+ int flags;
+ struct sockaddr_in6 tmp;
+
+ priv = 0;
+ if ((in6p->in6p_socket->so_state & SS_PRIV) != 0)
+ priv = 1;
+ stickyopt = in6p->in6p_outputopts;
+ if (control) {
+ if ((error = ip6_setpktoptions(control, &opt, priv)) != 0)
+ goto release;
+ in6p->in6p_outputopts = &opt;
+ }
+
+ if (addr6) {
+ /*
+ * IPv4 version of udp_output calls in_pcbconnect in this case,
+ * which needs splnet and affects performance.
+ * Since we saw no essential reason for calling in_pcbconnect,
+ * we get rid of such kind of logic, and call in6_selectsrc
+ * and in6_pcbsetport in order to fill in the local address
+ * and the local port.
+ */
+ struct sockaddr_in6 *sin6 = mtod(addr6, struct sockaddr_in6 *);
+
+ if (addr6->m_len != sizeof(*sin6)) {
+ error = EINVAL;
+ goto release;
+ }
+ if (sin6->sin6_family != AF_INET6) {
+ error = EAFNOSUPPORT;
+ goto release;
+ }
+ if (sin6->sin6_port == 0) {
+ error = EADDRNOTAVAIL;
+ goto release;
+ }
+
+ if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) {
+ error = EISCONN;
+ goto release;
+ }
+
+ /* protect *sin6 from overwrites */
+ tmp = *sin6;
+ sin6 = &tmp;
+
+ faddr = &sin6->sin6_addr;
+ fport = sin6->sin6_port; /* allow 0 port */
+
+ /* KAME hack: embed scopeid */
+ if (in6_embedscope(&sin6->sin6_addr, sin6, in6p, NULL) != 0) {
+ error = EINVAL;
+ goto release;
+ }
+
+ if (1) { /* we don't support IPv4 mapped address */
+ laddr = in6_selectsrc(sin6, in6p->in6p_outputopts,
+ in6p->in6p_moptions,
+ &in6p->in6p_route,
+ &in6p->in6p_laddr, &error);
+ } else
+ laddr = &in6p->in6p_laddr; /*XXX*/
+ if (laddr == NULL) {
+ if (error == 0)
+ error = EADDRNOTAVAIL;
+ goto release;
+ }
+ if (in6p->in6p_lport == 0 &&
+ (error = in6_pcbsetport(laddr, in6p)) != 0)
+ goto release;
+ } else {
+ if (IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) {
+ error = ENOTCONN;
+ goto release;
+ }
+ laddr = &in6p->in6p_laddr;
+ faddr = &in6p->in6p_faddr;
+ fport = in6p->in6p_fport;
+ }
+
+ if (1) { /* we don't support IPv4 mapped address */
+ af = AF_INET6;
+ hlen = sizeof(struct ip6_hdr);
+ } else {
+ af = AF_INET;
+ hlen = sizeof(struct ip);
+ }
+
+ /*
+ * Calculate data length and get a mbuf
+ * for UDP and IP6 headers.
+ */
+ M_PREPEND(m, hlen + sizeof(struct udphdr), M_DONTWAIT);
+ if (m == 0) {
+ error = ENOBUFS;
+ goto release;
+ }
+
+ /*
+ * Stuff checksum and output datagram.
+ */
+ udp6 = (struct udphdr *)(mtod(m, caddr_t) + hlen);
+ udp6->uh_sport = in6p->in6p_lport; /* lport is always set in the PCB */
+ udp6->uh_dport = fport;
+ if (plen <= 0xffff)
+ udp6->uh_ulen = htons((u_short)plen);
+ else
+ udp6->uh_ulen = 0;
+ udp6->uh_sum = 0;
+
+ switch (af) {
+ case AF_INET6:
+ ip6 = mtod(m, struct ip6_hdr *);
+ ip6->ip6_flow = in6p->in6p_flowinfo & IPV6_FLOWINFO_MASK;
+ ip6->ip6_vfc &= ~IPV6_VERSION_MASK;
+ ip6->ip6_vfc |= IPV6_VERSION;
+#if 0 /* ip6_plen will be filled in ip6_output. */
+ ip6->ip6_plen = htons((u_short)plen);
+#endif
+ ip6->ip6_nxt = IPPROTO_UDP;
+ ip6->ip6_hlim = in6_selecthlim(in6p,
+ in6p->in6p_route.ro_rt ?
+ in6p->in6p_route.ro_rt->rt_ifp : NULL);
+ ip6->ip6_src = *laddr;
+ ip6->ip6_dst = *faddr;
+
+ if ((udp6->uh_sum = in6_cksum(m, IPPROTO_UDP,
+ sizeof(struct ip6_hdr), plen)) == 0) {
+ udp6->uh_sum = 0xffff;
+ }
+
+ flags = 0;
+#ifdef IPV6_MINMTU
+ if (in6p->in6p_flags & IN6P_MINMTU)
+ flags |= IPV6_MINMTU;
+#endif
+
+ udp6stat.udp6s_opackets++;
+#ifdef IPSEC
+ ipsec_setsocket(m, in6p->in6p_socket);
+#endif /*IPSEC*/
+ error = ip6_output(m, in6p->in6p_outputopts, &in6p->in6p_route,
+ flags, in6p->in6p_moptions, NULL);
+ break;
+ case AF_INET:
+ error = EAFNOSUPPORT;
+ goto release;
+ }
+ goto releaseopt;
+
+release:
+ m_freem(m);
+
+releaseopt:
+ if (control) {
+ in6p->in6p_outputopts = stickyopt;
+ m_freem(control);
+ }
+ return(error);
+}