summaryrefslogtreecommitdiffstats
path: root/sys/netinet/udp_usrreq.c
diff options
context:
space:
mode:
authorniklas <niklas@openbsd.org>1996-03-03 22:30:24 +0000
committerniklas <niklas@openbsd.org>1996-03-03 22:30:24 +0000
commitb400e1581cddb46a65450a8de0c05f1c073dfc16 (patch)
treea3f55afeac650cff86821ceb59869e002564d6d4 /sys/netinet/udp_usrreq.c
parentFrom NetBSD: 960217 merge (diff)
downloadwireguard-openbsd-b400e1581cddb46a65450a8de0c05f1c073dfc16.tar.xz
wireguard-openbsd-b400e1581cddb46a65450a8de0c05f1c073dfc16.zip
From NetBSD: 960217 merge
Diffstat (limited to 'sys/netinet/udp_usrreq.c')
-rw-r--r--sys/netinet/udp_usrreq.c86
1 files changed, 58 insertions, 28 deletions
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index b7647352803..08bd09b1a79 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -1,4 +1,5 @@
-/* $NetBSD: udp_usrreq.c,v 1.25 1995/11/21 01:07:46 cgd Exp $ */
+/* $OpenBSD: udp_usrreq.c,v 1.3 1996/03/03 22:30:51 niklas Exp $ */
+/* $NetBSD: udp_usrreq.c,v 1.27 1996/02/13 23:44:32 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1990, 1993
@@ -43,6 +44,11 @@
#include <sys/socketvar.h>
#include <sys/errno.h>
#include <sys/stat.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+
+#include <vm/vm.h>
+#include <sys/sysctl.h>
#include <net/if.h>
#include <net/route.h>
@@ -57,6 +63,8 @@
#include <netinet/udp.h>
#include <netinet/udp_var.h>
+#include <machine/stdarg.h>
+
/*
* UDP protocol implementation.
* Per RFC 768, August, 1980.
@@ -68,23 +76,31 @@ int udpcksum = 0; /* XXX */
#endif
struct sockaddr_in udp_in = { sizeof(udp_in), AF_INET };
-struct inpcb *udp_last_inpcb = 0;
static void udp_detach __P((struct inpcb *));
static void udp_notify __P((struct inpcb *, int));
static struct mbuf *udp_saveopt __P((caddr_t, int, int));
+#ifndef UDBHASHSIZE
+#define UDBHASHSIZE 128
+#endif
+int udbhashsize = UDBHASHSIZE;
+
void
udp_init()
{
- in_pcbinit(&udbtable);
+ in_pcbinit(&udbtable, udbhashsize);
}
void
-udp_input(m, iphlen)
- register struct mbuf *m;
- int iphlen;
+#if __STDC__
+udp_input(struct mbuf *m, ...)
+#else
+udp_input(m, va_alist)
+ struct mbuf *m;
+ va_dcl
+#endif
{
register struct ip *ip;
register struct udphdr *uh;
@@ -92,6 +108,12 @@ udp_input(m, iphlen)
struct mbuf *opts = 0;
int len;
struct ip save_ip;
+ int iphlen;
+ va_list ap;
+
+ va_start(ap, m);
+ iphlen = va_arg(ap, int);
+ va_end(ap);
udpstat.udps_ipackets++;
@@ -145,7 +167,7 @@ udp_input(m, iphlen)
bzero(((struct ipovly *)ip)->ih_x1,
sizeof ((struct ipovly *)ip)->ih_x1);
((struct ipovly *)ip)->ih_len = uh->uh_ulen;
- if (uh->uh_sum = in_cksum(m, len + sizeof (struct ip))) {
+ if ((uh->uh_sum = in_cksum(m, len + sizeof (struct ip))) != 0) {
udpstat.udps_badsum++;
m_freem(m);
return;
@@ -246,13 +268,10 @@ udp_input(m, iphlen)
/*
* Locate pcb for datagram.
*/
- inp = udp_last_inpcb;
- if (inp == 0 ||
- inp->inp_lport != uh->uh_dport ||
- inp->inp_fport != uh->uh_sport ||
- inp->inp_faddr.s_addr != ip->ip_src.s_addr ||
- inp->inp_laddr.s_addr != ip->ip_dst.s_addr) {
- udpstat.udpps_pcbcachemiss++;
+ inp = in_pcbhashlookup(&udbtable, ip->ip_src, uh->uh_sport,
+ ip->ip_dst, uh->uh_dport);
+ if (inp == 0) {
+ ++udpstat.udps_pcbhashmiss;
inp = in_pcblookup(&udbtable, ip->ip_src, uh->uh_sport,
ip->ip_dst, uh->uh_dport, INPLOOKUP_WILDCARD);
if (inp == 0) {
@@ -266,7 +285,6 @@ udp_input(m, iphlen)
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0);
return;
}
- udp_last_inpcb = inp;
}
/*
@@ -357,45 +375,58 @@ udp_notify(inp, errno)
sowwakeup(inp->inp_socket);
}
-void
-udp_ctlinput(cmd, sa, ip)
+void *
+udp_ctlinput(cmd, sa, v)
int cmd;
struct sockaddr *sa;
- register struct ip *ip;
+ void *v;
{
+ register struct ip *ip = v;
register struct udphdr *uh;
- extern struct in_addr zeroin_addr;
extern int inetctlerrmap[];
void (*notify) __P((struct inpcb *, int)) = udp_notify;
int errno;
if ((unsigned)cmd >= PRC_NCMDS)
- return;
+ return NULL;
errno = inetctlerrmap[cmd];
if (PRC_IS_REDIRECT(cmd))
notify = in_rtchange, ip = 0;
else if (cmd == PRC_HOSTDEAD)
ip = 0;
else if (errno == 0)
- return;
+ return NULL;
if (ip) {
uh = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2));
in_pcbnotify(&udbtable, sa, uh->uh_dport, ip->ip_src,
uh->uh_sport, errno, notify);
} else
in_pcbnotifyall(&udbtable, sa, errno, notify);
+ return NULL;
}
int
-udp_output(inp, m, addr, control)
+#if __STDC__
+udp_output(struct mbuf *m, ...)
+#else
+udp_output(m, va_alist)
+ struct mbuf *m;
+ va_dcl
+#endif
+{
register struct inpcb *inp;
- register struct mbuf *m;
struct mbuf *addr, *control;
-{
register struct udpiphdr *ui;
register int len = m->m_pkthdr.len;
struct in_addr laddr;
- int s, error = 0;
+ int s = 0, error = 0;
+ va_list ap;
+
+ va_start(ap, m);
+ inp = va_arg(ap, struct inpcb *);
+ addr = va_arg(ap, struct mbuf *);
+ control = va_arg(ap, struct mbuf *);
+ va_end(ap);
if (control)
m_freem(control); /* XXX */
@@ -568,7 +599,7 @@ udp_usrreq(so, req, m, addr, control)
break;
case PRU_SEND:
- return (udp_output(inp, m, addr, control));
+ return (udp_output(m, inp, addr, control));
case PRU_ABORT:
soisdisconnected(so);
@@ -621,8 +652,6 @@ udp_detach(inp)
{
int s = splsoftnet();
- if (inp == udp_last_inpcb)
- udp_last_inpcb = 0;
in_pcbdetach(inp);
splx(s);
}
@@ -630,6 +659,7 @@ udp_detach(inp)
/*
* Sysctl for udp variables.
*/
+int
udp_sysctl(name, namelen, oldp, oldlenp, newp, newlen)
int *name;
u_int namelen;