summaryrefslogtreecommitdiffstats
path: root/sys/netiso/tuba_subr.c
diff options
context:
space:
mode:
authormickey <mickey@openbsd.org>1996-03-04 10:34:33 +0000
committermickey <mickey@openbsd.org>1996-03-04 10:34:33 +0000
commite40e4b677814ba392b54e11c9b6244420cf49d2e (patch)
tree03a0452a6e2d78ac2ee0de216974fbd025360aef /sys/netiso/tuba_subr.c
parentfixes of the 960217 import. (diff)
downloadwireguard-openbsd-e40e4b677814ba392b54e11c9b6244420cf49d2e.tar.xz
wireguard-openbsd-e40e4b677814ba392b54e11c9b6244420cf49d2e.zip
Initial commit of NetBSD 960217 netiso.
all the rest is the fixes to the import by Niklas.
Diffstat (limited to 'sys/netiso/tuba_subr.c')
-rw-r--r--sys/netiso/tuba_subr.c165
1 files changed, 98 insertions, 67 deletions
diff --git a/sys/netiso/tuba_subr.c b/sys/netiso/tuba_subr.c
index 927fea34a12..0bc3fa9464c 100644
--- a/sys/netiso/tuba_subr.c
+++ b/sys/netiso/tuba_subr.c
@@ -1,4 +1,5 @@
-/* $NetBSD: tuba_subr.c,v 1.5 1995/11/21 01:07:54 cgd Exp $ */
+/* $OpenBSD: tuba_subr.c,v 1.3 1996/03/04 10:36:49 mickey Exp $ */
+/* $NetBSD: tuba_subr.c,v 1.7 1996/02/13 22:12:32 christos Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -69,13 +70,29 @@
#include <netiso/iso_var.h>
#include <netiso/tuba_table.h>
-static struct sockaddr_iso null_siso = { sizeof(null_siso), AF_ISO, };
-extern int tuba_table_size, tcp_keepidle, tcp_keepintvl, tcp_maxidle;
-extern int tcppcbcachemiss, tcppredack, tcppreddat, tcprexmtthresh;
-extern struct tcpiphdr tcp_saveti;
-struct inpcbtable tuba_inpcb;
-struct inpcb *tuba_last_inpcb = 0;
-struct isopcb tuba_isopcb;
+#include <machine/stdarg.h>
+
+static struct sockaddr_iso null_siso = {sizeof(null_siso), AF_ISO,};
+extern int tuba_table_size, tcp_keepidle, tcp_keepintvl, tcp_maxidle;
+extern int tcppcbcachemiss, tcppredack, tcppreddat, tcprexmtthresh;
+extern struct tcpiphdr tcp_saveti;
+struct inpcbtable tuba_inpcb;
+struct isopcb tuba_isopcb;
+
+#ifndef TUBA_INPCBHASHSIZE
+#define TUBA_INPCBHASHSIZE 128
+#endif
+int tuba_inpcbhashsize = TUBA_INPCBHASHSIZE;
+
+
+struct addr_arg {
+ int error;
+ int offset;
+ u_long sum;
+};
+
+static void tuba_getaddr __P((struct addr_arg *, struct sockaddr_iso **,
+ u_long));
/*
* Tuba initialization
*/
@@ -85,7 +102,7 @@ tuba_init()
#define TUBAHDRSIZE (3 /*LLC*/ + 9 /*CLNP Fixed*/ + 42 /*Addresses*/ \
+ 6 /*CLNP Segment*/ + 20 /*TCP*/)
- in_pcbinit(&tuba_inpcb);
+ in_pcbinit(&tuba_inpcb, tuba_inpcbhashsize);
tuba_isopcb.isop_next = tuba_isopcb.isop_prev = &tuba_isopcb;
tuba_isopcb.isop_faddr = &tuba_isopcb.isop_sfaddr;
tuba_isopcb.isop_laddr = &tuba_isopcb.isop_sladdr;
@@ -95,12 +112,6 @@ tuba_init()
panic("tuba_init");
}
-struct addr_arg {
- int error;
- int offset;
- u_long sum;
-};
-
/*
* Calculate contribution to fudge factor for TCP checksum,
* and coincidentally set pointer for convenience of clnp_output
@@ -110,29 +121,30 @@ static void
tuba_getaddr(arg, siso, index)
register struct addr_arg *arg;
struct sockaddr_iso **siso;
- u_long index;
+ u_long index;
{
register struct tuba_cache *tc;
if (index <= tuba_table_size && (tc = tuba_table[index])) {
if (siso)
*siso = &tc->tc_siso;
arg->sum += (arg->offset & 1 ? tc->tc_ssum : tc->tc_sum)
- + (0xffff ^ index);
+ + (0xffff ^ index);
arg->offset += tc->tc_siso.siso_nlen + 1;
} else
arg->error = 1;
}
+int
tuba_output(m, tp)
register struct mbuf *m;
- struct tcpcb *tp;
+ struct tcpcb *tp;
{
register struct tcpiphdr *n;
- struct isopcb *isop;
- struct addr_arg arg;
+ struct isopcb *isop;
+ struct addr_arg arg;
- if (tp == 0 || (n = tp->t_template) == 0 ||
- (isop = (struct isopcb *)tp->t_tuba_pcb) == 0) {
+ if (tp == 0 || (n = tp->t_template) == 0 ||
+ (isop = (struct isopcb *) tp->t_tuba_pcb) == 0) {
isop = &tuba_isopcb;
n = mtod(m, struct tcpiphdr *);
arg.error = arg.sum = arg.offset = 0;
@@ -143,29 +155,31 @@ tuba_output(m, tp)
}
if (n->ti_sum == 0) {
arg.error = arg.sum = arg.offset = 0;
- tuba_getaddr(&arg, (struct sockaddr_iso **)0, n->ti_dst.s_addr);
- tuba_getaddr(&arg, (struct sockaddr_iso **)0, n->ti_src.s_addr);
+ tuba_getaddr(&arg, (struct sockaddr_iso **) 0, n->ti_dst.s_addr);
+ tuba_getaddr(&arg, (struct sockaddr_iso **) 0, n->ti_src.s_addr);
REDUCE(arg.sum, arg.sum);
n->ti_sum = arg.sum;
n = mtod(m, struct tcpiphdr *);
- adjust:
+adjust:
if (arg.error) {
m_freem(m);
return (EADDRNOTAVAIL);
}
REDUCE(n->ti_sum, n->ti_sum + (0xffff ^ arg.sum));
}
- m->m_len -= sizeof (struct ip);
- m->m_pkthdr.len -= sizeof (struct ip);
- m->m_data += sizeof (struct ip);
+ m->m_len -= sizeof(struct ip);
+ m->m_pkthdr.len -= sizeof(struct ip);
+ m->m_data += sizeof(struct ip);
return (clnp_output(m, isop, m->m_pkthdr.len, 0));
}
+void
tuba_refcnt(isop, delta)
- struct isopcb *isop;
+ struct isopcb *isop;
+ int delta;
{
register struct tuba_cache *tc;
- unsigned index, sum;
+ unsigned index;
if (delta != 1)
delta = -1;
@@ -175,16 +189,18 @@ tuba_refcnt(isop, delta)
return;
isop->isop_tuba_cached = (delta == 1);
if ((index = tuba_lookup(isop->isop_faddr, M_DONTWAIT)) != 0 &&
- (tc = tuba_table[index]) != 0 && (delta == 1 || tc->tc_refcnt > 0))
+ (tc = tuba_table[index]) != 0 && (delta == 1 || tc->tc_refcnt > 0))
tc->tc_refcnt += delta;
if ((index = tuba_lookup(isop->isop_laddr, M_DONTWAIT)) != 0 &&
- (tc = tuba_table[index]) != 0 && (delta == 1 || tc->tc_refcnt > 0))
+ (tc = tuba_table[index]) != 0 && (delta == 1 || tc->tc_refcnt > 0))
tc->tc_refcnt += delta;
}
-tuba_pcbdetach(isop)
- struct isopcb *isop;
+void
+tuba_pcbdetach(v)
+ void *v;
{
+ struct isopcb *isop = v;
if (isop == 0)
return;
tuba_refcnt(isop, -1);
@@ -195,21 +211,23 @@ tuba_pcbdetach(isop)
/*
* Avoid in_pcbconnect in faked out tcp_input()
*/
-tuba_pcbconnect(inp, nam)
- register struct inpcb *inp;
- struct mbuf *nam;
+int
+tuba_pcbconnect(v, nam)
+ void *v;
+ struct mbuf *nam;
{
+ register struct inpcb *inp = v;
register struct sockaddr_iso *siso;
struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
- struct tcpcb *tp = intotcpcb(inp);
- struct isopcb *isop = (struct isopcb *)tp->t_tuba_pcb;
- int error;
+ struct tcpcb *tp = intotcpcb(inp);
+ struct isopcb *isop = (struct isopcb *) tp->t_tuba_pcb;
+ int error;
/* hardwire iso_pcbbind() here */
siso = isop->isop_laddr = &isop->isop_sladdr;
*siso = tuba_table[inp->inp_laddr.s_addr]->tc_siso;
siso->siso_tlen = sizeof(inp->inp_lport);
- bcopy((caddr_t)&inp->inp_lport, TSEL(siso), sizeof(inp->inp_lport));
+ bcopy((caddr_t) & inp->inp_lport, TSEL(siso), sizeof(inp->inp_lport));
/* hardwire in_pcbconnect() here without assigning route */
inp->inp_fport = sin->sin_port;
@@ -220,7 +238,7 @@ tuba_pcbconnect(inp, nam)
siso = mtod(nam, struct sockaddr_iso *);
*siso = tuba_table[inp->inp_faddr.s_addr]->tc_siso;
siso->siso_tlen = sizeof(inp->inp_fport);
- bcopy((caddr_t)&inp->inp_fport, TSEL(siso), sizeof(inp->inp_fport));
+ bcopy((caddr_t) & inp->inp_fport, TSEL(siso), sizeof(inp->inp_fport));
if ((error = iso_pcbconnect(isop, nam)) == 0)
tuba_refcnt(isop, 1);
@@ -233,28 +251,41 @@ tuba_pcbconnect(inp, nam)
* FUNCTION and ARGUMENTS:
* Take a packet (m) from clnp, strip off the clnp header
* and do tcp input processing.
- * No return value.
+ * No return value.
*/
-tuba_tcpinput(m, src, dst)
- register struct mbuf *m;
- struct sockaddr_iso *src, *dst;
+void
+#if __STDC__
+tuba_tcpinput(struct mbuf *m, ...)
+#else
+tuba_tcpinput(m, va_alist)
+ struct mbuf *m; /* ptr to first mbuf of pkt */
+ va_dcl
+#endif
{
- unsigned long sum, lindex, findex;
+ unsigned long lindex, findex;
register struct tcpiphdr *ti;
register struct inpcb *inp;
- caddr_t optp = NULL;
- int optlen;
- int len, tlen, off;
+ caddr_t optp = NULL;
+ int optlen = 0;
+ int len, tlen, off;
register struct tcpcb *tp = 0;
- int tiflags;
- struct socket *so;
- int todrop, acked, ourfinisacked, needoutput = 0;
- short ostate;
- struct in_addr laddr;
- int dropsocket = 0, iss = 0;
- u_long tiwin;
- u_int32_t ts_val, ts_ecr;
- int ts_present = 0;
+ int tiflags;
+ struct socket *so = NULL;
+ int todrop, acked, ourfinisacked, needoutput = 0;
+ short ostate = 0;
+ struct in_addr laddr;
+ int dropsocket = 0, iss = 0;
+ u_long tiwin;
+ u_int32_t ts_val, ts_ecr;
+ int ts_present = 0;
+ struct sockaddr_iso *src, *dst;
+ va_list ap;
+
+ va_start(ap, m);
+ src = va_arg(ap, struct sockaddr_iso *);
+ dst = va_arg(ap, struct sockaddr_iso *);
+ va_end(ap);
+
if ((m->m_flags & M_PKTHDR) == 0)
panic("tuba_tcpinput");
@@ -276,7 +307,8 @@ tuba_tcpinput(m, src, dst)
m->m_data -= sizeof(struct ip);
m->m_len += sizeof(struct ip);
m->m_pkthdr.len += sizeof(struct ip);
- m->m_flags &= ~(M_MCAST|M_BCAST); /* XXX should do this in clnp_input */
+ m->m_flags &= ~(M_MCAST | M_BCAST); /* XXX should do this in
+ * clnp_input */
/*
* The reassembly code assumes it will be overwriting a useless
* part of the packet, which is why we need to have it point
@@ -286,13 +318,13 @@ tuba_tcpinput(m, src, dst)
* so that we can save copying the tcp header.
* This code knows way too much about the structure of mbufs!
*/
- off = ((sizeof (long) - 1) & ((m->m_flags & M_EXT) ?
- (m->m_data - m->m_ext.ext_buf) : (m->m_data - m->m_pktdat)));
+ off = ((sizeof(long) - 1) & ((m->m_flags & M_EXT) ?
+ (m->m_data - m->m_ext.ext_buf) : (m->m_data - m->m_pktdat)));
if (off || len < sizeof(struct tcphdr)) {
- struct mbuf *m0 = m;
+ struct mbuf *m0 = m;
MGETHDR(m, M_DONTWAIT, MT_DATA);
- if (m == 0) {
+ if (m == 0) {
m = m0;
goto drop;
}
@@ -328,8 +360,8 @@ tuba_tcpinput(m, src, dst)
ti->ti_src.s_addr = tuba_table[findex]->tc_ssum;
bzero(ti->ti_x1, sizeof ti->ti_x1);
ti->ti_pr = ISOPROTO_TCP;
- ti->ti_len = htons((u_short)tlen);
- if (ti->ti_sum = in_cksum(m, m->m_pkthdr.len)) {
+ ti->ti_len = htons((u_short) tlen);
+ if ((ti->ti_sum = in_cksum(m, m->m_pkthdr.len)) != 0) {
tcpstat.tcps_rcvbadsum++;
goto drop;
}
@@ -341,7 +373,6 @@ tuba_tcpinput(m, src, dst)
#define TUBA_INCLUDE
#define in_pcbconnect tuba_pcbconnect
#define tcb tuba_inpcb
-#define tcp_last_inpcb tuba_last_inpcb
#include <netinet/tcp_input.c>
}