summaryrefslogtreecommitdiff
path: root/sys/netiso/clnp_raw.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/clnp_raw.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/clnp_raw.c')
-rw-r--r--sys/netiso/clnp_raw.c295
1 files changed, 163 insertions, 132 deletions
diff --git a/sys/netiso/clnp_raw.c b/sys/netiso/clnp_raw.c
index e09411038b7..67694c2b68d 100644
--- a/sys/netiso/clnp_raw.c
+++ b/sys/netiso/clnp_raw.c
@@ -1,4 +1,5 @@
-/* $NetBSD: clnp_raw.c,v 1.8 1995/08/17 02:57:30 mycroft Exp $ */
+/* $OpenBSD: clnp_raw.c,v 1.2 1996/03/04 10:34:59 mickey Exp $ */
+/* $NetBSD: clnp_raw.c,v 1.9 1996/02/13 22:08:42 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -40,13 +41,13 @@
All Rights Reserved
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
-both that copyright notice and this permission notice appear in
+both that copyright notice and this permission notice appear in
supporting documentation, and that the name of IBM not be
used in advertising or publicity pertaining to distribution of the
-software without specific, written prior permission.
+software without specific, written prior permission.
IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
@@ -70,6 +71,7 @@ SOFTWARE.
#include <sys/socketvar.h>
#include <sys/errno.h>
#include <sys/time.h>
+#include <sys/systm.h>
#include <net/if.h>
#include <net/route.h>
@@ -81,36 +83,50 @@ SOFTWARE.
#include <netiso/clnp_stat.h>
#include <netiso/argo_debug.h>
-#include <netiso/tp_user.h> /* XXX -- defines SOL_NETWORK */
+#include <netiso/tp_user.h> /* XXX -- defines SOL_NETWORK */
-struct sockproto rclnp_proto = { PF_ISO, 0 };
+#include <machine/stdarg.h>
+
+struct sockproto rclnp_proto = {PF_ISO, 0};
/*
* FUNCTION: rclnp_input
*
- * PURPOSE: Setup generic address an protocol structures for
- * raw input routine, then pass them along with the
- * mbuf chain.
+ * PURPOSE: Setup generic address an protocol structures for
+ * raw input routine, then pass them along with the
+ * mbuf chain.
*
- * RETURNS: none
+ * RETURNS: none
*
- * SIDE EFFECTS:
+ * SIDE EFFECTS:
*
- * NOTES: The protocol field of rclnp_proto is set to zero indicating
- * no protocol.
+ * NOTES: The protocol field of rclnp_proto is set to zero
+ * indicating no protocol.
*/
void
-rclnp_input(m, src, dst, hdrlen)
-struct mbuf *m; /* ptr to packet */
-struct sockaddr_iso *src; /* ptr to src address */
-struct sockaddr_iso *dst; /* ptr to dest address */
-int hdrlen; /* length (in bytes) of clnp header */
+#if __STDC__
+rclnp_input(struct mbuf *m, ...)
+#else
+rclnp_input(m, va_alist)
+ struct mbuf *m; /* ptr to packet */
+ va_dcl
+#endif
{
+ struct sockaddr_iso *src; /* ptr to src address */
+ struct sockaddr_iso *dst; /* ptr to dest address */
+ int hdrlen; /* length (in bytes) of clnp header */
+ va_list ap;
+
+ va_start(ap, m);
+ src = va_arg(ap, struct sockaddr_iso *);
+ dst = va_arg(ap, struct sockaddr_iso *);
+ hdrlen = va_arg(ap, int);
+ va_end(ap);
#ifdef TROLL
if (trollctl.tr_ops & TR_CHUCK) {
m_freem(m);
return;
}
-#endif /* TROLL */
+#endif /* TROLL */
raw_input(m, &rclnp_proto, sisotosa(src), sisotosa(dst));
}
@@ -125,31 +141,41 @@ int hdrlen; /* length (in bytes) of clnp header */
* RETURNS: success - 0
* failure - an appropriate error code
*
- * SIDE EFFECTS:
+ * SIDE EFFECTS:
*
- * NOTES:
+ * NOTES:
*/
-rclnp_output(m0, so)
-struct mbuf *m0; /* packet to send */
-struct socket *so; /* socket to send from */
+int
+#if __STDC__
+rclnp_output(struct mbuf *m0, ...)
+#else
+rclnp_output(m0, va_alist)
+ struct mbuf *m0; /* packet to send */
+ va_dcl
+#endif
{
- register struct mbuf *m; /* used to scan a chain */
- int len = 0; /* store length of chain here */
- struct rawisopcb *rp = sotorawisopcb(so); /* ptr to raw cb */
- int error; /* return value of function */
- int flags; /* flags for clnp_output */
+ struct socket *so; /* socket to send from */
+ struct rawisopcb *rp; /* ptr to raw cb */
+ int error; /* return value of function */
+ int flags; /* flags for clnp_output */
+ va_list ap;
+
+ va_start(ap, m0);
+ so = va_arg(ap, struct socket *);
+ va_end(ap);
+ rp = sotorawisopcb(so);
- if (0 == (m0->m_flags & M_PKTHDR))
+ if ((m0->m_flags & M_PKTHDR) == 0)
return (EINVAL);
/*
- * Set up src address. If user has bound socket to an address, use it.
- * Otherwise, do not specify src (clnp_output will fill it in).
+ * Set up src address. If user has bound socket to an address, use it.
+ * Otherwise, do not specify src (clnp_output will fill it in).
*/
if (rp->risop_rcb.rcb_laddr) {
if (rp->risop_isop.isop_sladdr.siso_family != AF_ISO) {
-bad:
+ bad:
m_freem(m0);
- return(EAFNOSUPPORT);
+ return (EAFNOSUPPORT);
}
}
/* set up dest address */
@@ -162,7 +188,7 @@ bad:
flags = rp->risop_flags & CLNP_VFLAGS;
error = clnp_output(m0, &rp->risop_isop, m0->m_pkthdr.len,
- flags|CLNP_NOCACHE);
+ flags | CLNP_NOCACHE);
return (error);
}
@@ -171,7 +197,7 @@ bad:
* FUNCTION: rclnp_ctloutput
*
* PURPOSE: Raw clnp socket option processing
- * All options are stored inside an mbuf.
+ * All options are stored inside an mbuf.
*
* RETURNS: success - 0
* failure - unix error code
@@ -179,101 +205,106 @@ bad:
* SIDE EFFECTS: If the options mbuf does not exist, it the mbuf passed
* is used.
*
- * NOTES:
+ * NOTES:
*/
+int
rclnp_ctloutput(op, so, level, optname, m)
-int op; /* type of operation */
-struct socket *so; /* ptr to socket */
-int level; /* level of option */
-int optname; /* name of option */
-struct mbuf **m; /* ptr to ptr to option data */
+ int op; /* type of operation */
+ struct socket *so; /* ptr to socket */
+ int level; /* level of option */
+ int optname;/* name of option */
+ struct mbuf **m; /* ptr to ptr to option data */
{
- int error = 0;
- register struct rawisopcb *rp = sotorawisopcb(so);/* raw cb ptr */
+ int error = 0;
+ register struct rawisopcb *rp = sotorawisopcb(so); /* raw cb ptr */
- IFDEBUG(D_CTLOUTPUT)
+#ifdef ARGO_DEBUG
+ if (argo_debug[D_CTLOUTPUT]) {
printf("rclnp_ctloutput: op = x%x, level = x%x, name = x%x\n",
- op, level, optname);
+ op, level, optname);
if (*m != NULL) {
printf("rclnp_ctloutput: %d bytes of mbuf data\n", (*m)->m_len);
dump_buf(mtod((*m), caddr_t), (*m)->m_len);
}
- ENDDEBUG
+ }
+#endif
#ifdef SOL_NETWORK
if (level != SOL_NETWORK)
error = EINVAL;
- else switch (op) {
+ else
+ switch (op) {
#else
switch (op) {
-#endif /* SOL_NETWORK */
- case PRCO_SETOPT:
- switch (optname) {
- case CLNPOPT_FLAGS: {
- u_short usr_flags;
- /*
- * Insure that the data passed has exactly one short in it
- */
- if ((*m == NULL) || ((*m)->m_len != sizeof(short))) {
- error = EINVAL;
- break;
- }
-
- /*
- * Don't allow invalid flags to be set
- */
- usr_flags = (*mtod((*m), short *));
-
- if ((usr_flags & (CLNP_VFLAGS)) != usr_flags) {
- error = EINVAL;
- } else
- rp->risop_flags |= usr_flags;
-
- } break;
-
- case CLNPOPT_OPTS:
- if (error = clnp_set_opts(&rp->risop_isop.isop_options, m))
- break;
- rp->risop_isop.isop_optindex = m_get(M_WAIT, MT_SOOPTS);
- (void) clnp_opt_sanity(rp->risop_isop.isop_options,
- mtod(rp->risop_isop.isop_options, caddr_t),
- rp->risop_isop.isop_options->m_len,
- mtod(rp->risop_isop.isop_optindex,
- struct clnp_optidx *));
+#endif /* SOL_NETWORK */
+ case PRCO_SETOPT:
+ switch (optname) {
+ case CLNPOPT_FLAGS:{
+ u_short usr_flags;
+ /*
+ * Insure that the data passed has exactly
+ * one short in it
+ */
+ if ((*m == NULL) || ((*m)->m_len != sizeof(short))) {
+ error = EINVAL;
break;
- }
- break;
+ }
+ /*
+ * Don't allow invalid flags to be set
+ */
+ usr_flags = (*mtod((*m), short *));
- case PRCO_GETOPT:
-#ifdef notdef
- /* commented out to keep hi C quiet */
- switch (optname) {
- default:
+ if ((usr_flags & (CLNP_VFLAGS)) != usr_flags) {
error = EINVAL;
- break;
- }
-#endif /* notdef */
+ } else
+ rp->risop_flags |= usr_flags;
+
+ } break;
+
+ case CLNPOPT_OPTS:
+ error = clnp_set_opts(&rp->risop_isop.isop_options, m);
+ if (error)
+ break;
+ rp->risop_isop.isop_optindex = m_get(M_WAIT, MT_SOOPTS);
+ (void) clnp_opt_sanity(rp->risop_isop.isop_options,
+ mtod(rp->risop_isop.isop_options, caddr_t),
+ rp->risop_isop.isop_options->m_len,
+ mtod(rp->risop_isop.isop_optindex,
+ struct clnp_optidx *));
break;
+ }
+ break;
+
+ case PRCO_GETOPT:
+#ifdef notdef
+ /* commented out to keep hi C quiet */
+ switch (optname) {
default:
error = EINVAL;
break;
+ }
+#endif /* notdef */
+ break;
+ default:
+ error = EINVAL;
+ break;
}
if (op == PRCO_SETOPT) {
/* note: m_freem does not barf is *m is NULL */
m_freem(*m);
*m = NULL;
}
-
return error;
}
-/*ARGSUSED*/
+/* ARGSUSED */
+int
clnp_usrreq(so, req, m, nam, control)
register struct socket *so;
- int req;
- struct mbuf *m, *nam, *control;
+ int req;
+ struct mbuf *m, *nam, *control;
{
- register int error = 0;
+ register int error = 0;
register struct rawisopcb *rp = sotorawisopcb(so);
rp = sotorawisopcb(so);
@@ -285,7 +316,7 @@ clnp_usrreq(so, req, m, nam, control)
MALLOC(rp, struct rawisopcb *, sizeof *rp, M_PCB, M_WAITOK);
if (rp == 0)
return (ENOBUFS);
- bzero((caddr_t)rp, sizeof *rp);
+ bzero(rp, sizeof *rp);
so->so_pcb = rp;
break;
@@ -300,8 +331,8 @@ clnp_usrreq(so, req, m, nam, control)
rp->risop_rcb.rcb_laddr = 0;
/* free clnp cached hdr if necessary */
if (rp->risop_isop.isop_clnpcache != NULL) {
- struct clnp_cache *clcp =
- mtod(rp->risop_isop.isop_clnpcache, struct clnp_cache *);
+ struct clnp_cache *clcp =
+ mtod(rp->risop_isop.isop_clnpcache, struct clnp_cache *);
if (clcp->clc_hdr != NULL) {
m_free(clcp->clc_hdr);
}
@@ -313,40 +344,40 @@ clnp_usrreq(so, req, m, nam, control)
break;
case PRU_BIND:
- {
- struct sockaddr_iso *addr = mtod(nam, struct sockaddr_iso *);
-
- if (nam->m_len != sizeof(*addr))
- return (EINVAL);
- if ((ifnet.tqh_first == 0) ||
- (addr->siso_family != AF_ISO) ||
- (addr->siso_addr.isoa_len &&
- ifa_ifwithaddr(sisotosa(addr)) == 0))
- return (EADDRNOTAVAIL);
- rp->risop_isop.isop_sladdr = *addr;
- rp->risop_rcb.rcb_laddr = sisotosa(
- (rp->risop_isop.isop_laddr = &rp->risop_isop.isop_sladdr));
- return (0);
- }
+ {
+ struct sockaddr_iso *addr = mtod(nam, struct sockaddr_iso *);
+
+ if (nam->m_len != sizeof(*addr))
+ return (EINVAL);
+ if ((ifnet.tqh_first == 0) ||
+ (addr->siso_family != AF_ISO) ||
+ (addr->siso_addr.isoa_len &&
+ ifa_ifwithaddr(sisotosa(addr)) == 0))
+ return (EADDRNOTAVAIL);
+ rp->risop_isop.isop_sladdr = *addr;
+ rp->risop_rcb.rcb_laddr = sisotosa(
+ (rp->risop_isop.isop_laddr = &rp->risop_isop.isop_sladdr));
+ return (0);
+ }
case PRU_CONNECT:
- {
- struct sockaddr_iso *addr = mtod(nam, struct sockaddr_iso *);
-
- if ((nam->m_len > sizeof(*addr)) || (addr->siso_len > sizeof(*addr)))
- return (EINVAL);
- if (ifnet.tqh_first == 0)
- return (EADDRNOTAVAIL);
- if (addr->siso_family != AF_ISO)
- rp->risop_isop.isop_sfaddr = *addr;
- rp->risop_rcb.rcb_faddr = sisotosa(
- (rp->risop_isop.isop_faddr = &rp->risop_isop.isop_sfaddr));
- soisconnected(so);
- return (0);
- }
+ {
+ struct sockaddr_iso *addr = mtod(nam, struct sockaddr_iso *);
+
+ if ((nam->m_len > sizeof(*addr)) || (addr->siso_len > sizeof(*addr)))
+ return (EINVAL);
+ if (ifnet.tqh_first == 0)
+ return (EADDRNOTAVAIL);
+ if (addr->siso_family != AF_ISO)
+ rp->risop_isop.isop_sfaddr = *addr;
+ rp->risop_rcb.rcb_faddr = sisotosa(
+ (rp->risop_isop.isop_faddr = &rp->risop_isop.isop_sfaddr));
+ soisconnected(so);
+ return (0);
+ }
}
- error = raw_usrreq(so, req, m, nam, control);
+ error = raw_usrreq(so, req, m, nam, control);
if (error && req == PRU_ATTACH && so->so_pcb)
- free((caddr_t)rp, M_PCB);
+ free((caddr_t) rp, M_PCB);
return (error);
}