/***********************************************************
Copyright IBM Corporation 1987
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
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.
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
******************************************************************/
* ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison
/* $Header: clnp_raw.c,v 4.2 88/06/29 14:58:56 hagens Exp $ */
/* $Source: /usr/argo/sys/netiso/RCS/clnp_raw.c,v $ */
/* @(#)clnp_raw.c 7.7 (Berkeley) %G% */
static char *rcsid
= "$Header: clnp_raw.c,v 4.2 88/06/29 14:58:56 hagens Exp $";
#include "../net/route.h"
#include "../net/raw_cb.h"
#include "tp_user.h"/* XXX -- defines SOL_NETWORK */
struct sockproto rclnp_proto
= { PF_ISO
, 0 };
* PURPOSE: Setup generic address an protocol structures for
* raw input routine, then pass them along with the
* NOTES: The protocol field of rclnp_proto is set to zero indicating
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 (trollctl
.tr_ops
& TR_CHUCK
) {
if (raw_input(m
, &rclnp_proto
, (struct sockaddr
*)src
,
(struct sockaddr
*)dst
) == 0) {
clnp_stat
.cns_delivered
--;
* PURPOSE: Prepare to send a raw clnp packet. Setup src and dest
* addresses, count the number of bytes to send, and
* failure - an appropriate error code
struct mbuf
*m0
; /* packet to send */
struct socket
*so
; /* socket to send from */
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 */
if (0 == m0
->m_flags
& M_PKTHDR
)
* 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
) {
/* set up dest address */
if (rp
->risop_rcb
.rcb_faddr
== 0)
rp
->risop_isop
.isop_sfaddr
=
*(struct sockaddr_iso
*)rp
->risop_rcb
.rcb_faddr
;
rp
->risop_isop
.isop_faddr
= &rp
->risop_isop
.isop_sfaddr
;
/* get flags and ship it off */
flags
= rp
->risop_flags
& CLNP_VFLAGS
;
error
= clnp_output(m0
, &rp
->risop_isop
, m0
->m_pkthdr
.len
,
* FUNCTION: rclnp_ctloutput
* PURPOSE: Raw clnp socket option processing
* All options are stored inside an mbuf.
* failure - unix error code
* SIDE EFFECTS: If the options mbuf does not exist, it the mbuf passed
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 */
register struct rawisopcb
*rp
= sotorawisopcb(so
);/* raw cb ptr */
printf("rclnp_ctloutput: op = x%x, level = x%x, name = x%x\n",
printf("rclnp_ctloutput: %d bytes of mbuf data\n", (*m
)->m_len
);
dump_buf(mtod((*m
), caddr_t
), (*m
)->m_len
);
if (level
!= SOL_NETWORK
)
* Insure that the data passed has exactly one short in it
if ((*m
== NULL
) || ((*m
)->m_len
!= sizeof(short))) {
* Don't allow invalid flags to be set
usr_flags
= (*mtod((*m
), short *));
if ((usr_flags
& (CLNP_VFLAGS
)) != usr_flags
) {
rp
->risop_flags
|= usr_flags
;
if (error
= clnp_set_opts(&rp
->risop_isop
.isop_options
, m
))
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
,
/* commented out to keep hi C quiet */
/* note: m_freem does not barf is *m is NULL */
clnp_usrreq(so
, req
, m
, nam
, control
)
register struct socket
*so
;
struct mbuf
*m
, *nam
, *control
;
register struct rawisopcb
*rp
= sotorawisopcb(so
);
MALLOC(rp
, struct rawisopcb
*, sizeof *rp
, M_PCB
, M_WAITOK
);
bzero((caddr_t
)rp
, sizeof *rp
);
so
->so_pcb
= (caddr_t
)rp
;
if (rp
->risop_isop
.isop_options
)
m_freem(rp
->risop_isop
.isop_options
);
if (rp
->risop_isop
.isop_route
.ro_rt
)
RTFREE(rp
->risop_isop
.isop_route
.ro_rt
);
if (rp
->risop_rcb
.rcb_laddr
)
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
*);
if (clcp
->clc_hdr
!= NULL
) {
m_free(rp
->risop_isop
.isop_clnpcache
);
if (rp
->risop_isop
.isop_optindex
!= NULL
)
m_free(rp
->risop_isop
.isop_optindex
);
struct sockaddr_iso
*addr
= mtod(nam
, struct sockaddr_iso
*);
if (nam
->m_len
!= sizeof(*addr
))
(addr
->siso_family
!= AF_ISO
) ||
(addr
->siso_addr
.isoa_len
&&
ifa_ifwithaddr((struct sockaddr
*)addr
) == 0))
rp
->risop_isop
.isop_sladdr
= *addr
;
rp
->risop_rcb
.rcb_laddr
= (struct sockaddr
*)
(rp
->risop_isop
.isop_laddr
= &rp
->risop_isop
.isop_sladdr
);
struct sockaddr_iso
*addr
= mtod(nam
, struct sockaddr_iso
*);
if ((nam
->m_len
> sizeof(*addr
)) || (addr
->siso_len
> sizeof(*addr
)))
if (addr
->siso_family
!= AF_ISO
)
rp
->risop_isop
.isop_sfaddr
= *addr
;
rp
->risop_rcb
.rcb_faddr
= (struct sockaddr
*)
(rp
->risop_isop
.isop_faddr
= &rp
->risop_isop
.isop_sfaddr
);
error
= raw_usrreq(so
, req
, m
, nam
, control
);
if (error
&& req
== PRU_ATTACH
&& so
->so_pcb
)
free((caddr_t
)rp
, M_PCB
);