/***********************************************************
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: iso_pcb.c,v 4.5 88/06/29 14:59:56 hagens Exp $
* $Source: /usr/argo/sys/netiso/RCS/iso_pcb.c,v $
* Iso address family net-layer(s) pcb stuff. NEH 1/29/87
static char *rcsid
= "$Header: iso_pcb.c,v 4.5 88/06/29 14:59:56 hagens Exp $";
#include "../h/socketvar.h"
#include "../netiso/argo_debug.h"
#include "../netiso/iso.h"
#include "../netiso/clnp.h"
#include "../netinet/in_systm.h"
#include "../net/route.h"
#include "../netiso/iso_pcb.h"
#include "../netiso/iso_var.h"
#define PCBNULL (struct isopcb *)0
struct iso_addr zeroiso_addr
= {
* PURPOSE: creates an isopcb structure in an mbuf,
* puts it in the queue with head (head)
* RETURNS: 0 if OK, ENOBUFS if can't alloc the necessary mbuf
register struct isopcb
*isop
;
printf("iso_pcballoc(so 0x%x)\n", so
);
m
= m_getclr(M_DONTWAIT
, MT_PCB
);
isop
= mtod(m
, struct isopcb
*);
so
->so_pcb
= (caddr_t
)isop
;
* PURPOSE: binds the address given in *(nam) to the socket
* specified by the isopcb in *(isop)
* If the given address is zero, it makes sure the
* address isn't already in use and if it's got a network
* portion, we look for an interface with that network
* address. If the address given is zero, we allocate
* a port and stuff it in the (nam) structure.
* RETURNS: errno E* or 0 if ok.
* SIDE EFFECTS: increments head->isop_lport if it allocates a port #
register struct isopcb
*isop
;
register struct isopcb
*head
= isop
->isop_head
;
register struct sockaddr_iso
*siso
;
printf("iso_pcbbind(isop 0x%x, nam 0x%x)\n", isop
, nam
);
if (iso_ifaddr
== 0) /* any interfaces attached? */
if (isop
->isop_lport
) /* already bound */
if(nam
== (struct mbuf
*)0)
siso
= mtod(nam
, struct sockaddr_iso
*);
printf("iso_pcbbind(name len 0x%x)\n", nam
->m_len
);
printf("The address is %s\n", clnp_iso_addrp(&siso
->siso_addr
));
* We would like sort of length check but since some OSI addrs
* do not have fixed length, we can't really do much.
* The ONLY thing we can say is that an osi addr has to have
* at LEAST an afi and one more byte and had better fit into
* However, in fact the size of the whole thing is a struct
* sockaddr_iso, so probably this is what we should check for.
if( (nam
->m_len
< 2) || (nam
->m_len
> sizeof(struct sockaddr_iso
))) {
suf
= siso
->siso_tsuffix
;
if (bcmp(&siso
->siso_addr
,&zeroiso_addr
, 1)) {
/* non-zero net addr- better match one of our interfaces */
printf("iso_pcbbind: bind to NOT zeroisoaddr\n");
siso
->siso_tsuffix
= 0; /* yech... */
/* PHASE 2: this call is ok */
if ((ia
= ifa_ifwithaddr((struct sockaddr
*)siso
))
bcopy( (caddr_t
)&((struct sockaddr_iso
*)&(ia
->ifa_addr
))->siso_addr
,
(caddr_t
)&(isop
->isop_laddr
.siso_addr
),
sizeof(struct sockaddr_iso
) );
isop
->isop_laddr
.siso_tsuffix
= suf
;
/* copy also to the nam parameter */
bcopy( (caddr_t
)&(isop
->isop_laddr
.siso_addr
),
(caddr_t
)&(siso
->siso_addr
), sizeof(struct sockaddr_iso
));
siso
->siso_tsuffix
= suf
;
if((suf
< ISO_PORT_RESERVED
) && (u
.u_uid
!= 0))
if ((isop
->isop_socket
->so_options
& SO_REUSEADDR
) == 0 &&
iso_pcblookup(head
, 0, &(isop
->isop_laddr
.siso_addr
), suf
, 0) )
/* copy the if addr to the result (siso) and to the isopcb */
printf("iso_pcbbind noname\n");
if (head
->isop_lport
++ < ISO_PORT_RESERVED
||
head
->isop_lport
> ISO_PORT_USERRESERVED
)
head
->isop_lport
= ISO_PORT_RESERVED
;
} while (iso_pcblookup(head
, 0, &(isop
->isop_laddr
.siso_addr
), suf
, 0));
printf("iso_pcbbind returns 0, suf 0x%x\n", suf
);
* FUNCTION: iso_pcbconnect
* PURPOSE: Make the isopcb (isop) look like it's connected.
* In other words, give it the peer address given in
* the mbuf * (nam). Make sure such a combination
* of local, peer addresses doesn't already exist
* for this protocol. Internet mentality prevails here,
* wherein a src,dst pair uniquely identifies a connection.
* Both net address and port must be specified in argument
* If we don't have a local address for this socket yet,
* we pick one by calling iso_pcbbind().
* RETURNS: errno E* or 0 if ok.
* SIDE EFFECTS: Looks up a route, which may cause one to be left
#define satosiso(sa) ((struct sockaddr_iso *)(sa))
iso_pcbconnect(isop
, nam
)
struct ifnet
*ifp
= (struct ifnet
*)0;
struct sockaddr_iso ifaddr
;
register struct sockaddr_iso
*siso
= mtod(nam
, struct sockaddr_iso
*);
"iso_pcbconnect(isop 0x%x sock 0x%x nam 0x%x nam->m_len 0x%x), addr:\n",
isop
, isop
->isop_socket
, nam
, nam
->m_len
);
if (nam
->m_len
> sizeof (*siso
))
return ENAMETOOLONG
; /* not great but better than EINVAL! */
if (siso
->siso_family
!= AF_ISO
)
/* removed for the sake of extended tsels -
* user may setsockopt for extended tsel (foreign) and then
* connect to nsap w/ tsuffix zero
if (siso
->siso_tsuffix
== 0)
local_zero
= iso_addrmatch1(&(isop
->isop_laddr
.siso_addr
), &zeroiso_addr
);
local_zero
= !bcmp(&(isop
->isop_laddr
.siso_addr
), &zeroiso_addr
, 1);
* We need to get the local nsap address.
* First, route to the destination. This will provide us with
* an ifp. Second, determine which local address linked on
* that ifp is appropriate
struct sockaddr_iso
*first_hop
; /* filled by clnp_route */
struct ifnet
*ifp
; /* filled by clnp_route */
struct iso_addr
*localaddr
;
if (err
= clnp_route(&siso
->siso_addr
, &isop
->isop_route
, /* flags */0,
/* determine local address based upon ifp */
if ((localaddr
= clnp_srcaddr(ifp
, &first_hop
->siso_addr
)) == NULL
)
ifaddr
.siso_family
= AF_ISO
;
ifaddr
.siso_addr
= *localaddr
;
if (isop
->isop_lport
== 0)
(void)iso_pcbbind(isop
, (struct mbuf
*)0);
isop
->isop_laddr
= ifaddr
;
register struct route
*ro
;
printf("iso_pcbconnect localzero 1\n");
ia
= (struct iso_ifaddr
*)0;
* If route is known or can be allocated now,
* our src addr is taken from the i/f, else punt.
printf("iso_pcbconnect rtalloc 1.1, ro->ro_rt 0x%x\n",
if (ro
->ro_rt
&& ! iso_addrmatch1( &(satosiso(&ro
->ro_dst
)->siso_addr
),
ro
->ro_rt
= (struct rtentry
*)0;
* TODO: it seems this code has a lot in common with clnp_route.
* Maybe they could be combined? (RAH)
if ((isop
->isop_socket
->so_options
& SO_DONTROUTE
) == 0 && /*XXX*/
(ro
->ro_rt
== (struct rtentry
*)0 ||
(ifp
= ro
->ro_rt
->rt_ifp
) == (struct ifnet
*)0)) {
/* No route yet, so try to acquire one */
ro
->ro_dst
.sa_family
= AF_ISO
;
((struct sockaddr_iso
*) &ro
->ro_dst
)->siso_addr
=
printf("iso_pcbconnect rtalloc 1.5, ro->ro_rt 0x%x\n",
printf("ro->ro_rt->rt_refcnt %d\n",
printf("rt entry rt_gateway (as sockaddr):\n");
dump_buf(&ro
->ro_rt
->rt_gateway
,
sizeof (struct sockaddr
));
* If we found a route, use the address
* corresponding to the outgoing interface
* unless it is the loopback (in case a route
* to our address on another net goes to loopback).
* We must check to use the address that is of the
* same type (in the case where the interface has more
* than one type associated with it). (ie ecn0 has
* both t37 and osinet addresses.
if (ro
->ro_rt
&& (ifp
= ro
->ro_rt
->rt_ifp
) &&
(ifp
->if_flags
& IFF_LOOPBACK
) == 0)
for (ia
= iso_ifaddr
; ia
; ia
= ia
->ia_next
) {
struct iso_addr
*isoap
= &IA_SIS(ia
)->siso_addr
;
printf("iso_pcbconnect: ia x%x yields: %s\n",
ia
, clnp_iso_addrp(isoap
));
if ((ia
->ia_ifp
== ifp
) &&
(iso_eqtype(&siso
->siso_addr
, isoap
)))
printf("iso_pcbconnect localzero 2: ia x%x\n", ia
);
ia
= (struct iso_ifaddr
*)
ifa_ifwithdstaddr((struct sockaddr
*)siso
);
ia
= iso_iaonnetof(siso
);
ifaddr
= *(struct sockaddr_iso
*)&ia
->ia_addr
;
printf("in iso_pcbconnect before lookup isop 0x%x isop->sock 0x%x\n",
isop
, isop
->isop_socket
);
if (isop
->isop_lport
== 0)
(void)iso_pcbbind(isop
, (struct mbuf
*)0);
isop
->isop_laddr
.siso_addr
= ifaddr
.siso_addr
;
isop
->isop_laddr
.siso_family
= AF_ISO
;
printf("in iso_pcbconnect before bcopy isop 0x%x isop->sock 0x%x\n",
isop
, isop
->isop_socket
);
bcopy((caddr_t
) &(siso
->siso_addr
), (caddr_t
) &(isop
->isop_faddr
.siso_addr
),
sizeof(struct iso_addr
));
printf("in iso_pcbconnect after bcopy isop 0x%x isop->sock 0x%x\n",
isop
, isop
->isop_socket
);
isop
->isop_faddr
.siso_family
= AF_ISO
;
isop
->isop_fport
= siso
->siso_tsuffix
;
printf("in iso_pcbconnect end isop 0x%x isop->sock 0x%x\n",
isop
, isop
->isop_socket
);
printf("iso_pcbconnect connected to addr:\n");
dump_isoaddr(&isop
->isop_faddr
);
printf("iso_pcbconnect end: src addr:\n");
dump_isoaddr(&isop
->isop_laddr
);
* FUNCTION: iso_pcbdisconnect()
* PURPOSE: washes away the peer address info so the socket
* appears to be disconnected.
* If there's no file descriptor associated with the socket
* SIDE EFFECTS: May detach the pcb.
printf("iso_pcbdisconnect(isop 0x%x)\n", isop
);
isop
->isop_laddr
.siso_addr
= zeroiso_addr
;
if (isop
->isop_socket
->so_state
& SS_NOFDREF
)
* FUNCTION: iso_pcbdetach
* PURPOSE: detach the pcb at *(isop) from it's socket and free
* the mbufs associated with the pcb..
* Dequeues (isop) from its head.
struct socket
*so
= isop
->isop_socket
;
printf("iso_pcbdetach(isop 0x%x socket 0x%x so 0x%x)\n",
isop
, isop
->isop_socket
, so
);
if (so
) { /* in the x.25 domain, we sometimes have no socket */
printf("iso_pcbdetach 2 \n");
(void)m_free(isop
->isop_options
);
printf("iso_pcbdetach 3 \n");
if (isop
->isop_route
.ro_rt
)
rtfree(isop
->isop_route
.ro_rt
);
printf("iso_pcbdetach 3.1\n");
if (isop
->isop_clnpcache
!= NULL
) {
struct clnp_cache
*clcp
=
mtod(isop
->isop_clnpcache
, struct clnp_cache
*);
printf("iso_pcbdetach 3.2: clcp 0x%x freeing clc_hdr x%x\n",
if (clcp
->clc_hdr
!= NULL
)
printf("iso_pcbdetach 3.3: freeing cache x%x\n",
m_free(isop
->isop_clnpcache
);
printf("iso_pcbdetach 4 \n");
printf("iso_pcbdetach 5 \n");
(void) m_free(dtom(isop
));
iso_setsockaddr(isop
, nam
)
register struct isopcb
*isop
;
register struct sockaddr_iso
*siso
= mtod(nam
, struct sockaddr_iso
*);
nam
->m_len
= sizeof (*siso
);
siso
= mtod(nam
, struct sockaddr_iso
*);
bzero((caddr_t
)siso
, sizeof (*siso
));
siso
->siso_family
= AF_ISO
;
siso
->siso_tsuffix
= isop
->isop_lport
;
siso
->siso_addr
= isop
->isop_laddr
.siso_addr
;
iso_setpeeraddr(isop
, nam
)
register struct isopcb
*isop
;
register struct sockaddr_iso
*siso
= mtod(nam
, struct sockaddr_iso
*);
nam
->m_len
= sizeof (*siso
);
siso
= mtod(nam
, struct sockaddr_iso
*);
bzero((caddr_t
)siso
, sizeof (*siso
));
siso
->siso_family
= AF_ISO
;
siso
->siso_tsuffix
= isop
->isop_fport
;
siso
->siso_addr
= isop
->isop_faddr
.siso_addr
;
* FUNCTION: iso_pcbnotify
* PURPOSE: notify all connections in this protocol's queue (head)
* that have peer address (dst) of the problem (errno)
* by calling (notify) on the connections' isopcbs.
* NOTES: (notify) is called at splimp!
iso_pcbnotify(head
, dst
, errno
, notify
)
register struct iso_addr
*dst
;
register struct isopcb
*isop
, *oisop
;
printf("iso_pcbnotify(head 0x%x, notify 0x%x) dst:\n", head
, notify
);
for (isop
= head
->isop_next
; isop
!= head
;) {
if (!iso_addrmatch1(&(isop
->isop_faddr
.siso_addr
), dst
) ||
isop
->isop_socket
== 0) {
printf("iso_pcbnotify: CONTINUE isop 0x%x, sock 0x%x\n" ,
isop
, isop
->isop_socket
);
printf("addrmatch cmp'd with (0x%x):\n",
&(isop
->isop_faddr
.siso_addr
));
dump_isoaddr(&isop
->isop_faddr
);
isop
->isop_socket
->so_error
= errno
;
printf("END OF iso_pcbnotify\n" );
* FUNCTION: iso_pcblookup
* PURPOSE: looks for a given combination of (faddr), (fport),
* (lport), (laddr) in the queue named by (head).
* Argument (flags) is ignored.
* RETURNS: ptr to the isopcb if it finds a connection matching
* these arguments, o.w. returns zero.
iso_pcblookup(head
, fport
, laddr
, lport
, flags
)
register struct isopcb
*isop
;
printf("iso_pcblookup(head 0x%x lport 0x%x fport 0x%x)\n",
for (isop
= head
->isop_next
; isop
!= head
; isop
= isop
->isop_next
) {
* This should be changed to do bcmp on lsuffix in the tpcb instead
* since we should be ignoring the lport concept.
if (isop
->isop_lport
!= lport
)
if (isop
->isop_fport
!= fport
)
* addrmatch1 should be iso_addrmatch(a, b, mask)
* where mask is taken from isop->isop_laddrmask (new field)
* isop_lnetmask will also be available in isop
if (laddr
!= &zeroiso_addr
&&
!iso_addrmatch1(laddr
, &(isop
->isop_laddr
.siso_addr
)))
return (struct isopcb
*)0;