1996-10-13 06:03:00 +04:00
|
|
|
/* $NetBSD: tp_cons.c,v 1.10 1996/10/13 02:04:33 christos Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
/*-
|
1994-05-13 10:08:03 +04:00
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-04-09 16:00:07 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
1994-06-29 10:39:25 +04:00
|
|
|
* @(#)tp_cons.c 8.1 (Berkeley) 6/10/93
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/***********************************************************
|
|
|
|
Copyright IBM Corporation 1987
|
|
|
|
|
|
|
|
All Rights Reserved
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
1993-04-09 16:00:07 +04:00
|
|
|
provided that the above copyright notice appear in all copies and that
|
1996-02-14 01:07:57 +03:00
|
|
|
both that copyright notice and this permission notice appear in
|
1993-04-09 16:00:07 +04:00
|
|
|
supporting documentation, and that the name of IBM not be
|
|
|
|
used in advertising or publicity pertaining to distribution of the
|
1996-02-14 01:07:57 +03:00
|
|
|
software without specific, written prior permission.
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
|
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
|
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
SOFTWARE.
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* Here is where you find the iso- and cons-dependent code. We've tried keep
|
|
|
|
* all net-level and (primarily) address-family-dependent stuff out of the tp
|
|
|
|
* source, and everthing here is reached indirectly through a switch table
|
|
|
|
* (struct nl_protosw *) tpcb->tp_nlproto (see tp_pcb.c). The routines here
|
|
|
|
* are: tpcons_input: pullup and call tp_input w/ correct arguments
|
|
|
|
* tpcons_output: package a pkt for cons given an isopcb & some data
|
|
|
|
* cons_chan_to_tpcb: find a tpcb based on the channel #
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef ISO
|
|
|
|
#ifdef TPCONS
|
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/param.h>
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <sys/systm.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/time.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/route.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netiso/tp_param.h>
|
|
|
|
#include <netiso/argo_debug.h>
|
|
|
|
#include <netiso/tp_stat.h>
|
|
|
|
#include <netiso/tp_pcb.h>
|
|
|
|
#include <netiso/tp_trace.h>
|
|
|
|
#include <netiso/tp_stat.h>
|
|
|
|
#include <netiso/tp_tpdu.h>
|
|
|
|
#include <netiso/iso.h>
|
|
|
|
#include <netiso/iso_errno.h>
|
|
|
|
#include <netiso/iso_pcb.h>
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <netiso/iso_var.h>
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netiso/cons.h>
|
|
|
|
#include <netiso/tp_seq.h>
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <netiso/tp_var.h>
|
|
|
|
#include <netiso/clnp.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
#undef FALSE
|
|
|
|
#undef TRUE
|
1993-12-18 03:40:47 +03:00
|
|
|
#include <netccitt/x25.h>
|
|
|
|
#include <netccitt/pk.h>
|
|
|
|
#include <netccitt/pk_var.h>
|
1996-02-14 01:07:57 +03:00
|
|
|
#include <netccitt/pk_extern.h>
|
|
|
|
|
|
|
|
#include <machine/stdarg.h>
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1993-12-18 07:54:21 +03:00
|
|
|
#include <netiso/if_cons.c>
|
1996-02-14 01:07:57 +03:00
|
|
|
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CALLED FROM:
|
|
|
|
* tp_route_to() for PRU_CONNECT
|
|
|
|
* FUNCTION, ARGUMENTS, SIDE EFFECTS and RETURN VALUE:
|
|
|
|
* version of the previous procedure for X.25
|
|
|
|
*/
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
|
|
|
tpcons_pcbconnect(v, nam)
|
|
|
|
void *v;
|
|
|
|
register struct mbuf *nam;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct isopcb *isop = v;
|
|
|
|
int error;
|
|
|
|
if ((error = iso_pcbconnect(isop, nam)) != 0)
|
1993-04-09 16:00:07 +04:00
|
|
|
return error;
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((isop->isop_chan = (caddr_t) pk_attach((struct socket *) 0)) == 0) {
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CCONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("tpcons_pcbconnect: no pklcd; returns 0x%x\n", error);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
return ENOBUFS;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((error = cons_connect(isop)) != 0) { /* if it doesn't work */
|
1993-04-09 16:00:07 +04:00
|
|
|
/* oh, dear, throw packet away */
|
1996-02-14 01:07:57 +03:00
|
|
|
pk_disconnect((struct pklcd *) isop->isop_chan);
|
1993-04-09 16:00:07 +04:00
|
|
|
isop->isop_chan = 0;
|
1996-02-14 01:07:57 +03:00
|
|
|
} else
|
1993-04-09 16:00:07 +04:00
|
|
|
isop->isop_refcnt = 1;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CALLED FROM:
|
|
|
|
* cons
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* THIS MAYBE BELONGS IN SOME OTHER PLACE??? but i think not -
|
|
|
|
*/
|
1996-02-14 01:07:57 +03:00
|
|
|
void *
|
|
|
|
tpcons_ctlinput(cmd, siso, v)
|
|
|
|
int cmd;
|
|
|
|
struct sockaddr *siso;
|
|
|
|
void *v;
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct isopcb *isop = v;
|
1994-05-13 10:08:03 +04:00
|
|
|
register struct tp_pcb *tpcb = 0;
|
|
|
|
|
|
|
|
if (isop->isop_socket)
|
1996-02-14 01:07:57 +03:00
|
|
|
tpcb = (struct tp_pcb *) isop->isop_socket->so_pcb;
|
1993-04-09 16:00:07 +04:00
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case PRC_CONS_SEND_DONE:
|
1994-05-13 10:08:03 +04:00
|
|
|
if (tpcb) {
|
1996-02-14 01:07:57 +03:00
|
|
|
struct tp_event E;
|
|
|
|
int error = 0;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1994-05-13 10:08:03 +04:00
|
|
|
if (tpcb->tp_class == TP_CLASS_0) {
|
1996-02-14 01:07:57 +03:00
|
|
|
/*
|
|
|
|
* only if class is exactly class zero, not
|
1993-04-09 16:00:07 +04:00
|
|
|
* still in class negotiation
|
|
|
|
*/
|
|
|
|
/* fake an ack */
|
1996-02-14 01:07:57 +03:00
|
|
|
register SeqNum seq = SEQ_ADD(tpcb, tpcb->tp_snduna, 1);
|
|
|
|
|
|
|
|
#ifdef TPPT
|
|
|
|
if(tp_traceflags[D_DATA])
|
|
|
|
tptrace(TPPTmisc, "FAKE ACK seq cdt 1",
|
|
|
|
seq, 0, 0, 0);
|
|
|
|
#endif
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_DATA]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("FAKE ACK seq 0x%x cdt 1\n", seq);
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
E.TP_ATTR(AK_TPDU).e_cdt = 1;
|
|
|
|
E.TP_ATTR(AK_TPDU).e_seq = seq;
|
|
|
|
E.TP_ATTR(AK_TPDU).e_subseq = 0;
|
|
|
|
E.TP_ATTR(AK_TPDU).e_fcc_present = 0;
|
|
|
|
error = DoEvent(AK_TPDU);
|
|
|
|
if (error) {
|
1993-04-09 16:00:07 +04:00
|
|
|
tpcb->tp_sock->so_error = error;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
} /* else ignore it */
|
1994-05-13 10:08:03 +04:00
|
|
|
}
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
case PRC_ROUTEDEAD:
|
1994-05-13 10:08:03 +04:00
|
|
|
if (tpcb && tpcb->tp_class == TP_CLASS_0) {
|
1993-04-09 16:00:07 +04:00
|
|
|
tpiso_reset(isop);
|
|
|
|
break;
|
1996-02-14 01:07:57 +03:00
|
|
|
} /* else drop through */
|
1993-04-09 16:00:07 +04:00
|
|
|
default:
|
1996-02-14 01:07:57 +03:00
|
|
|
tpclnp_ctlinput(cmd, siso, NULL);
|
1993-04-09 16:00:07 +04:00
|
|
|
break;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
return NULL;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CALLED FROM:
|
|
|
|
* cons's intr routine
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* Take a packet (m) from cons, pullup m as required by tp,
|
1996-02-14 01:07:57 +03:00
|
|
|
* ignore the socket argument, and call tp_input.
|
|
|
|
* No return value.
|
1993-04-09 16:00:07 +04:00
|
|
|
*/
|
1994-05-13 10:08:03 +04:00
|
|
|
void
|
1996-02-14 01:07:57 +03:00
|
|
|
#if __STDC__
|
|
|
|
tpcons_input(struct mbuf *m, ...)
|
|
|
|
#else
|
|
|
|
tpcons_input(m, va_alist)
|
|
|
|
struct mbuf *m;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct sockaddr *faddr, *laddr;
|
|
|
|
caddr_t channel;
|
|
|
|
va_list ap;
|
|
|
|
if (m == NULL)
|
1994-05-13 10:08:03 +04:00
|
|
|
return;
|
1996-02-14 01:07:57 +03:00
|
|
|
va_start(ap, m);
|
|
|
|
faddr = va_arg(ap, struct sockaddr *);
|
|
|
|
laddr = va_arg(ap, struct sockaddr *);
|
|
|
|
channel = va_arg(ap, caddr_t);
|
1993-04-09 16:00:07 +04:00
|
|
|
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
m = (struct mbuf *) tp_inputprep(m);
|
|
|
|
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_TPINPUT]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("tpcons_input before tp_input(m 0x%x)\n", m);
|
1996-02-14 01:07:57 +03:00
|
|
|
dump_buf(m, 12 + m->m_len);
|
|
|
|
}
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
tp_input(m, faddr, laddr, channel, tpcons_output, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CALLED FROM:
|
|
|
|
* tp_emit()
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* Take a packet(m0) from tp and package it so that cons will accept it.
|
|
|
|
* This means filling in a few of the fields.
|
|
|
|
* inp is the isopcb structure; datalen is the length of the data in the
|
|
|
|
* mbuf string m0.
|
|
|
|
* RETURN VALUE:
|
|
|
|
* whatever (E*) is returned form the net layer output routine.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
1996-02-14 01:07:57 +03:00
|
|
|
#if __STDC__
|
|
|
|
tpcons_output(struct mbuf *m0, ...)
|
|
|
|
#else
|
|
|
|
tpcons_output(m0, va_alist)
|
|
|
|
struct mbuf *m0;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
struct isopcb *isop;
|
|
|
|
int datalen;
|
|
|
|
int nochksum;
|
|
|
|
register struct mbuf *m = m0;
|
|
|
|
int error;
|
|
|
|
va_list ap;
|
1993-04-09 16:00:07 +04:00
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
va_start(ap, m0);
|
|
|
|
datalen = va_arg(ap, int);
|
|
|
|
isop = va_arg(ap, struct isopcb *);
|
|
|
|
nochksum = va_arg(ap, int);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_EMIT]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf(
|
1996-02-14 01:07:57 +03:00
|
|
|
"tpcons_output(isop 0x%x, m 0x%x, len 0x%x socket 0x%x\n",
|
|
|
|
isop, m0, datalen, isop->isop_socket);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (m == NULL)
|
1993-04-09 16:00:07 +04:00
|
|
|
return 0;
|
|
|
|
if ((m->m_flags & M_PKTHDR) == 0) {
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == 0)
|
|
|
|
return ENOBUFS;
|
|
|
|
m->m_next = m0;
|
|
|
|
}
|
|
|
|
m->m_pkthdr.len = datalen;
|
1994-05-13 10:08:03 +04:00
|
|
|
if (isop->isop_chan == 0) {
|
|
|
|
/* got a restart maybe? */
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((isop->isop_chan = (caddr_t) pk_attach((struct socket *) 0)) == 0) {
|
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CCONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("tpcons_output: no pklcd\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1994-05-13 10:08:03 +04:00
|
|
|
error = ENOBUFS;
|
|
|
|
}
|
1996-02-14 01:07:57 +03:00
|
|
|
if ((error = cons_connect(isop)) != 0) {
|
|
|
|
pk_disconnect((struct pklcd *) isop->isop_chan);
|
1994-05-13 10:08:03 +04:00
|
|
|
isop->isop_chan = 0;
|
1996-02-14 01:07:57 +03:00
|
|
|
#ifdef ARGO_DEBUG
|
|
|
|
if (argo_debug[D_CCONS]) {
|
1996-10-13 06:03:00 +04:00
|
|
|
printf("tpcons_output: can't reconnect\n");
|
1996-02-14 01:07:57 +03:00
|
|
|
}
|
|
|
|
#endif
|
1994-05-13 10:08:03 +04:00
|
|
|
}
|
|
|
|
} else {
|
1996-02-14 01:07:57 +03:00
|
|
|
error = pk_send(m, isop->isop_chan);
|
1994-05-13 10:08:03 +04:00
|
|
|
IncStat(ts_tpdu_sent);
|
|
|
|
}
|
1993-04-09 16:00:07 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* CALLED FROM:
|
|
|
|
* tp_error_emit()
|
|
|
|
* FUNCTION and ARGUMENTS:
|
|
|
|
* Take a packet(m0) from tp and package it so that cons will accept it.
|
|
|
|
* chan is the cons channel to use; datalen is the length of the data in the
|
|
|
|
* mbuf string m0.
|
|
|
|
* RETURN VALUE:
|
|
|
|
* whatever (E*) is returned form the net layer output routine.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
1996-02-14 01:07:57 +03:00
|
|
|
#if __STDC__
|
|
|
|
tpcons_output_dg(struct mbuf *m0, ...)
|
|
|
|
#else
|
|
|
|
tpcons_output_dg(m0, va_alist)
|
|
|
|
struct mbuf *m0;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
int datalen;
|
|
|
|
caddr_t chan;
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, m0);
|
|
|
|
datalen = va_arg(ap, int);
|
|
|
|
chan = va_arg(ap, caddr_t);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return tpcons_output(m0, datalen,
|
|
|
|
((struct pklcd *) chan)->lcd_upnext,
|
|
|
|
0);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
|
1996-02-15 00:32:37 +03:00
|
|
|
#include <sys/param.h>
|
1996-02-14 01:07:57 +03:00
|
|
|
|
|
|
|
struct mbuf;
|
1996-02-15 00:32:37 +03:00
|
|
|
|
|
|
|
int tpcons_output __P((struct mbuf *m0, ...));
|
|
|
|
|
1996-02-14 01:07:57 +03:00
|
|
|
int
|
|
|
|
#if __STDC__
|
|
|
|
tpcons_output(struct mbuf *m0, ...)
|
|
|
|
#else
|
|
|
|
tpcons_output(m0, va_alist)
|
|
|
|
struct mbuf *m0;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
1993-04-09 16:00:07 +04:00
|
|
|
{
|
1996-02-14 01:07:57 +03:00
|
|
|
return 0;
|
1993-04-09 16:00:07 +04:00
|
|
|
}
|
1994-05-13 10:08:03 +04:00
|
|
|
#endif /* TPCONS */
|
|
|
|
#endif /* ISO */
|