summaryrefslogtreecommitdiff
path: root/sys/netiso/tuba_usrreq.c
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>1996-03-04 10:37:32 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>1996-03-04 10:37:32 +0000
commit19b3595c2000294ed57cd7cb23e1d91ee553215d (patch)
tree404b337fc172b005d07d5f30eeeb873a270a9eac /sys/netiso/tuba_usrreq.c
parentd4b3fca05966647ecd8191d973cdce74570844ca (diff)
Initial commit of NetBSD 960217 netiso.
all the rest is the fixes to the import by Niklas.
Diffstat (limited to 'sys/netiso/tuba_usrreq.c')
-rw-r--r--sys/netiso/tuba_usrreq.c196
1 files changed, 100 insertions, 96 deletions
diff --git a/sys/netiso/tuba_usrreq.c b/sys/netiso/tuba_usrreq.c
index 9887528021c..0fc605cdea5 100644
--- a/sys/netiso/tuba_usrreq.c
+++ b/sys/netiso/tuba_usrreq.c
@@ -1,4 +1,5 @@
-/* $NetBSD: tuba_usrreq.c,v 1.7 1995/08/12 23:59:55 mycroft Exp $ */
+/* $OpenBSD: tuba_usrreq.c,v 1.2 1996/03/04 10:36:54 mickey Exp $ */
+/* $NetBSD: tuba_usrreq.c,v 1.8 1996/02/13 22:12:40 christos Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -70,32 +71,33 @@
/*
* TCP protocol interface to socket abstraction.
*/
-extern char *tcpstates[];
-extern struct inpcbtable tuba_inpcb;
-extern struct isopcb tuba_isopcb;
+extern char *tcpstates[];
+extern struct inpcbtable tuba_inpcb;
+extern struct isopcb tuba_isopcb;
/*
* Process a TCP user request for TCP tb. If this is a send request
* then m is the mbuf chain of send data. If this is a timer expiration
* (called from the software clock routine), then timertype tells which timer.
*/
-/*ARGSUSED*/
+/* ARGSUSED */
+int
tuba_usrreq(so, req, m, nam, control)
- struct socket *so;
- int req;
- struct mbuf *m, *nam, *control;
+ struct socket *so;
+ int req;
+ struct mbuf *m, *nam, *control;
{
register struct inpcb *inp;
- register struct isopcb *isop;
- register struct tcpcb *tp;
- int s;
- int error = 0;
- int ostate;
+ register struct isopcb *isop = NULL;
+ register struct tcpcb *tp = NULL;
+ int s;
+ int error = 0;
+ int ostate;
struct sockaddr_iso *siso;
if (req == PRU_CONTROL)
- return (iso_control(so, (long)m, (caddr_t)nam,
- (struct ifnet *)control));
+ return (iso_control(so, (long) m, (caddr_t) nam,
+ (struct ifnet *) control));
s = splsoftnet();
inp = sotoinpcb(so);
@@ -104,42 +106,42 @@ tuba_usrreq(so, req, m, nam, control)
* a (struct inpcb) pointed at by the socket, and this
* structure will point at a subsidary (struct tcpcb).
*/
- if (inp == 0 && req != PRU_ATTACH) {
+ if (inp == 0 && req != PRU_ATTACH) {
splx(s);
- return (EINVAL); /* XXX */
+ return (EINVAL);/* XXX */
}
if (inp) {
tp = intotcpcb(inp);
if (tp == 0)
panic("tuba_usrreq");
ostate = tp->t_state;
- isop = (struct isopcb *)tp->t_tuba_pcb;
+ isop = (struct isopcb *) tp->t_tuba_pcb;
if (isop == 0)
panic("tuba_usrreq 2");
} else
ostate = 0;
switch (req) {
- /*
- * TCP attaches to socket via PRU_ATTACH, reserving space,
- * and an internet control block. We also need to
- * allocate an isopcb and separate the control block from
- * tcp/ip ones.
- */
+ /*
+ * TCP attaches to socket via PRU_ATTACH, reserving space,
+ * and an internet control block. We also need to
+ * allocate an isopcb and separate the control block from
+ * tcp/ip ones.
+ */
case PRU_ATTACH:
- if (error = iso_pcballoc(so, &tuba_isopcb))
+ if ((error = iso_pcballoc(so, &tuba_isopcb)) != 0)
break;
- isop = (struct isopcb *)so->so_pcb;
+ isop = (struct isopcb *) so->so_pcb;
so->so_pcb = 0;
- if (error = tcp_usrreq(so, req, m, nam, control)) {
+ if ((error = tcp_usrreq(so, req, m, nam, control)) != 0) {
isop->isop_socket = 0;
iso_pcbdetach(isop);
} else {
inp = sotoinpcb(so);
CIRCLEQ_REMOVE(&inp->inp_table->inpt_queue, inp,
- inp_queue);
+ inp_queue);
CIRCLEQ_INSERT_HEAD(&tuba_inpcb.inpt_queue, inp,
- inp_queue);
+ inp_queue);
inp->inp_table = &tuba_inpcb;
tp = intotcpcb(inp);
if (tp == 0)
@@ -148,13 +150,13 @@ tuba_usrreq(so, req, m, nam, control)
}
goto notrace;
- /*
- * PRU_DETACH detaches the TCP protocol from the socket.
- * If the protocol state is non-embryonic, then can't
- * do this directly: have to initiate a PRU_DISCONNECT,
- * which may finish later; embryonic TCB's can just
- * be discarded here.
- */
+ /*
+ * PRU_DETACH detaches the TCP protocol from the socket.
+ * If the protocol state is non-embryonic, then can't
+ * do this directly: have to initiate a PRU_DISCONNECT,
+ * which may finish later; embryonic TCB's can just
+ * be discarded here.
+ */
case PRU_DETACH:
if (tp->t_state > TCPS_LISTEN)
tp = tcp_disconnect(tp);
@@ -164,16 +166,16 @@ tuba_usrreq(so, req, m, nam, control)
tuba_pcbdetach(isop);
break;
- /*
- * Give the socket an address.
- */
+ /*
+ * Give the socket an address.
+ */
case PRU_BIND:
siso = mtod(nam, struct sockaddr_iso *);
if (siso->siso_tlen && siso->siso_tlen != 2) {
error = EINVAL;
break;
}
- if ((error = iso_pcbbind(isop, nam)) ||
+ if ((error = iso_pcbbind(isop, nam)) ||
(siso = isop->isop_laddr) == 0)
break;
bcopy(TSEL(siso), &inp->inp_lport, 2);
@@ -182,29 +184,29 @@ tuba_usrreq(so, req, m, nam, control)
error = ENOBUFS;
break;
- /*
- * Prepare to accept connections.
- */
+ /*
+ * Prepare to accept connections.
+ */
case PRU_CONNECT:
case PRU_LISTEN:
if (inp->inp_lport == 0 &&
- (error = iso_pcbbind(isop, (struct mbuf *)0)))
+ (error = iso_pcbbind(isop, NULL)))
break;
bcopy(TSEL(isop->isop_laddr), &inp->inp_lport, 2);
if (req == PRU_LISTEN) {
tp->t_state = TCPS_LISTEN;
break;
}
- /*FALLTHROUGH*/
- /*
- * Initiate connection to peer.
- * Create a template for use in transmissions on this connection.
- * Enter SYN_SENT state, and mark socket as connecting.
- * Start keep-alive timer, and seed output sequence space.
- * Send initial segment on connection.
- */
- /* case PRU_CONNECT: */
- if (error = iso_pcbconnect(isop, nam))
+ /* FALLTHROUGH */
+ /*
+ * Initiate connection to peer.
+ * Create a template for use in transmissions on this connection.
+ * Enter SYN_SENT state, and mark socket as connecting.
+ * Start keep-alive timer, and seed output sequence space.
+ * Send initial segment on connection.
+ */
+ /* case PRU_CONNECT: */
+ if ((error = iso_pcbconnect(isop, nam)) != 0)
break;
if ((siso = isop->isop_laddr) && siso->siso_nlen > 1)
siso->siso_data[siso->siso_nlen - 1] = ISOPROTO_TCP;
@@ -212,15 +214,15 @@ tuba_usrreq(so, req, m, nam, control)
panic("tuba_usrreq: connect");
siso = mtod(nam, struct sockaddr_iso *);
if (!(inp->inp_faddr.s_addr = tuba_lookup(siso, M_WAITOK))) {
- unconnect:
+ unconnect:
iso_pcbdisconnect(isop);
error = ENOBUFS;
break;
}
bcopy(TSEL(isop->isop_faddr), &inp->inp_fport, 2);
if (inp->inp_laddr.s_addr == 0 &&
- (inp->inp_laddr.s_addr =
- tuba_lookup(isop->isop_laddr, M_WAITOK)) == 0)
+ (inp->inp_laddr.s_addr =
+ tuba_lookup(isop->isop_laddr, M_WAITOK)) == 0)
goto unconnect;
if ((tp->t_template = tcp_template(tp)) == 0)
goto unconnect;
@@ -228,41 +230,42 @@ tuba_usrreq(so, req, m, nam, control)
tcpstat.tcps_connattempt++;
tp->t_state = TCPS_SYN_SENT;
tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
- tp->iss = tcp_iss; tcp_iss += TCP_ISSINCR/2;
+ tp->iss = tcp_iss;
+ tcp_iss += TCP_ISSINCR / 2;
tcp_sendseqinit(tp);
error = tcp_output(tp);
tuba_refcnt(isop, 1);
break;
- /*
- * Initiate disconnect from peer.
- * If connection never passed embryonic stage, just drop;
- * else if don't need to let data drain, then can just drop anyways,
- * else have to begin TCP shutdown process: mark socket disconnecting,
- * drain unread data, state switch to reflect user close, and
- * send segment (e.g. FIN) to peer. Socket will be really disconnected
- * when peer sends FIN and acks ours.
- *
- * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
- */
+ /*
+ * Initiate disconnect from peer.
+ * If connection never passed embryonic stage, just drop;
+ * else if don't need to let data drain, then can just drop anyways,
+ * else have to begin TCP shutdown process: mark socket disconnecting,
+ * drain unread data, state switch to reflect user close, and
+ * send segment (e.g. FIN) to peer. Socket will be really disconnected
+ * when peer sends FIN and acks ours.
+ *
+ * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
+ */
case PRU_DISCONNECT:
if ((tp = tcp_disconnect(tp)) == 0)
tuba_pcbdetach(isop);
break;
- /*
- * Accept a connection. Essentially all the work is
- * done at higher levels; just return the address
- * of the peer, storing through addr.
- */
+ /*
+ * Accept a connection. Essentially all the work is
+ * done at higher levels; just return the address
+ * of the peer, storing through addr.
+ */
case PRU_ACCEPT:
- bcopy((caddr_t)isop->isop_faddr, mtod(nam, caddr_t),
- nam->m_len = isop->isop_faddr->siso_len);
+ bcopy((caddr_t) isop->isop_faddr, mtod(nam, caddr_t),
+ nam->m_len = isop->isop_faddr->siso_len);
break;
- /*
- * Mark the connection as being incapable of further output.
- */
+ /*
+ * Mark the connection as being incapable of further output.
+ */
case PRU_SHUTDOWN:
socantsendmore(so);
tp = tcp_usrclosed(tp);
@@ -271,9 +274,9 @@ tuba_usrreq(so, req, m, nam, control)
else
tuba_pcbdetach(isop);
break;
- /*
- * Abort the TCP.
- */
+ /*
+ * Abort the TCP.
+ */
case PRU_ABORT:
if ((tp = tcp_drop(tp, ECONNABORTED)) == 0)
tuba_pcbdetach(isop);
@@ -282,14 +285,14 @@ tuba_usrreq(so, req, m, nam, control)
case PRU_SOCKADDR:
if (isop->isop_laddr)
- bcopy((caddr_t)isop->isop_laddr, mtod(nam, caddr_t),
- nam->m_len = isop->isop_laddr->siso_len);
+ bcopy((caddr_t) isop->isop_laddr, mtod(nam, caddr_t),
+ nam->m_len = isop->isop_laddr->siso_len);
break;
case PRU_PEERADDR:
if (isop->isop_faddr)
- bcopy((caddr_t)isop->isop_faddr, mtod(nam, caddr_t),
- nam->m_len = isop->isop_faddr->siso_len);
+ bcopy((caddr_t) isop->isop_faddr, mtod(nam, caddr_t),
+ nam->m_len = isop->isop_faddr->siso_len);
break;
default:
@@ -297,20 +300,21 @@ tuba_usrreq(so, req, m, nam, control)
goto notrace;
}
if (tp && (so->so_options & SO_DEBUG))
- tcp_trace(TA_USER, ostate, tp, (struct tcpiphdr *)0, req);
+ tcp_trace(TA_USER, ostate, tp, (struct tcpiphdr *) 0, req);
notrace:
splx(s);
- return(error);
+ return (error);
}
+int
tuba_ctloutput(op, so, level, optname, mp)
- int op;
- struct socket *so;
- int level, optname;
- struct mbuf **mp;
+ int op;
+ struct socket *so;
+ int level, optname;
+ struct mbuf **mp;
{
- int clnp_ctloutput(), tcp_ctloutput();
-
- return ((level != IPPROTO_TCP ? clnp_ctloutput : tcp_ctloutput)
- (op, so, level, optname, mp));
+ if (level != IPPROTO_TCP)
+ return rclnp_ctloutput(op, so, level, optname, mp);
+ else
+ return tcp_ctloutput(op, so, level, optname, mp);
}