/***********************************************************
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.c,v 4.11 88/09/19 14:58:35 root Exp $
* $Source: /usr/argo/sys/netiso/RCS/iso.c,v $
* @(#)iso.c 7.7 (Berkeley) %G%
* iso.c: miscellaneous routines to support the iso address family
static char *rcsid
= "$Header: iso.c,v 4.11 88/09/19 14:58:35 root Exp $";
#include "../net/route.h"
#include "argoxtwentyfive.h"
int iso_interfaces
= 0; /* number of external interfaces */
extern struct ifnet loif
; /* loopback interface */
* PURPOSE: initialize the iso address family
* SIDE EFFECTS: 1) zeros the maptab table.
* 2) initializes the routing table.
struct radix_node_head
*iso_rnhead
;
extern struct spna_cache iso_snpac
[];
extern u_int iso_snpac_size
;
if (iso_init_done
== 0) {
bzero((caddr_t
)iso_snpac
, iso_snpac_size
* sizeof(struct snpa_cache
));
rn_inithead(&iso_rnhead
, 40, AF_ISO
);
* FUNCTION: iso_addrmatch1
* PURPOSE: decide if the two iso_addrs passed are equal
* RETURNS: true if the addrs match, false if they do not
iso_addrmatch1(isoaa
, isoab
)
register struct iso_addr
*isoaa
, *isoab
; /* addresses to check */
printf("iso_addrmatch1: comparing lengths: %d to %d\n", isoaa
->isoa_len
,
dump_buf(isoaa
->isoa_genaddr
, isoaa
->isoa_len
);
dump_buf(isoab
->isoa_genaddr
, isoab
->isoa_len
);
if ((compare_len
= isoaa
->isoa_len
) != isoab
->isoa_len
) {
printf("iso_addrmatch1: returning false because of lengths\n");
/* TODO : generalize this to all afis with masks */
if( isoaa
->isoa_afi
== AFI_37
) {
/* must not compare 2 least significant digits, or for
compare_len
= ADDR37_IDI_LEN
- 1;
for (i
=0; i
<compare_len
; i
++) {
printf("<%x=%x>", a
[i
]&0xff, b
[i
]&0xff);
printf("\naddrs are not equal at byte %d\n", i
);
printf("addrs are equal\n");
return (!bcmp(isoaa
->isoa_genaddr
, isoab
->isoa_genaddr
, compare_len
));
* FUNCTION: iso_addrmatch
* PURPOSE: decide if the two sockadrr_isos passed are equal
* RETURNS: true if the addrs match, false if they do not
iso_addrmatch(sisoa
, sisob
)
struct sockaddr_iso
*sisoa
, *sisob
; /* addresses to check */
return(iso_addrmatch1(&sisoa
->siso_addr
, &sisob
->siso_addr
));
* PURPOSE: similar to iso_addrmatch but takes sockaddr_iso
* RETURNS: true if same net, false if not
iso_netmatch(sisoa
, sisob
)
struct sockaddr_iso
*sisoa
, *sisob
;
u_char bufa
[sizeof(struct sockaddr_iso
)];
u_char bufb
[sizeof(struct sockaddr_iso
)];
lena
= iso_netof(&sisoa
->siso_addr
, bufa
);
lenb
= iso_netof(&sisob
->siso_addr
, bufb
);
printf("iso_netmatch: comparing lengths: %d to %d\n", lena
, lenb
);
return ((lena
== lenb
) && (!bcmp(bufa
, bufb
, lena
)));
* PURPOSE: Hash all character in the buffer specified into
* a long. Return the long.
* RETURNS: The hash value.
* NOTES: The hash is achieved by exclusive ORing 4 byte
register caddr_t buf
; /* buffer to pack from */
register int len
; /* length of buffer */
/* buffer not multiple of 4 */
printf("iso_hashchar: unexpected value x%x\n", len
- i
);
* PURPOSE: Fill in fields of afhash structure based upon addr passed.
struct sockaddr_iso
*siso
; /* address to perform hash on */
struct afhash
*hp
; /* RETURN: hash info here */
u_long buf
[sizeof(struct sockaddr_iso
)+1/4];
bufsize
= iso_netof(&siso
->siso_addr
, buf
);
hp
->afh_nethash
= iso_hashchar((caddr_t
)buf
, bufsize
);
printf("iso_hash: iso_netof: bufsize = %d\n", bufsize
);
hp
->afh_hosthash
= iso_hashchar((caddr_t
)&siso
->siso_addr
,
siso
->siso_addr
.isoa_len
);
printf("iso_hash: %s: nethash = x%x, hosthash = x%x\n",
clnp_iso_addrp(&siso
->siso_addr
), hp
->afh_nethash
,
* PURPOSE: Extract the network portion of the iso address.
* The network portion of the iso address varies depending
* on the type of address. The network portion of the
* address will include the IDP. The network portion is:
* t37 The AFI and x.121 (IDI)
* osinet The AFI, orgid, snetid
* rfc986 The AFI, vers and network part of
* RETURNS: number of bytes placed into buf.
* NOTES: Buf is assumed to be big enough
struct iso_addr
*isoa
; /* address */
caddr_t buf
; /* RESULT: network portion of address here */
u_int len
= 1; /* length of afi */
switch (isoa
->isoa_afi
) {
* Due to classic x.25 tunnel vision, there is no
* net portion of an x.121 address. For our purposes
* the AFI will do, so that all x.25 -type addresses
* map to the single x.25 SNPA. (Cannot have more than
u_short idi
; /* value of idi */
/* osinet and rfc986 have idi in the same place */
CTOH(isoa
->rfc986_idi
[0], isoa
->rfc986_idi
[1], idi
);
* Network portion of OSINET address can only be the IDI. Clearly,
* with one x25 interface, one could get to several orgids, and
len += (ADDROSINET_IDI_LEN + OVLOSINET_ORGID_LEN +
len
+= ADDROSINET_IDI_LEN
;
else if (idi
== IDI_RFC986
) {
struct ovl_rfc986
*o986
= (struct ovl_rfc986
*)isoa
;
/* bump len to include idi and version (1 byte) */
len
+= ADDRRFC986_IDI_LEN
+ 1;
/* get inet addr long aligned */
bcopy(o986
->o986_inetaddr
, &inetaddr
, sizeof(inetaddr
));
inetaddr
= ntohl(inetaddr
); /* convert to host byte order */
printf("iso_netof: isoa ");
dump_buf(isoa
, sizeof(*isoa
));
printf("iso_netof: inetaddr 0x%x ", inetaddr
);
/* bump len by size of network portion of inet address */
if (IN_CLASSA(inetaddr
)) {
len
+= 4-IN_CLASSA_NSHIFT
/8;
printf("iso_netof: class A net len is now %d\n", len
);
} else if (IN_CLASSB(inetaddr
)) {
len
+= 4-IN_CLASSB_NSHIFT
/8;
printf("iso_netof: class B net len is now %d\n", len
);
len
+= 4-IN_CLASSC_NSHIFT
/8;
printf("iso_netof: class C net len is now %d\n", len
);
bcopy((caddr_t
)isoa
, buf
, len
);
printf("in_netof: isoa ");
printf("in_netof: net ");
* Generic iso control operations (ioctl's).
* Ifp is 0 if not an interface-specific ioctl.
iso_control(so
, cmd
, data
, ifp
)
register struct ifnet
*ifp
;
register struct iso_ifreq
*ifr
= (struct iso_ifreq
*)data
;
register struct iso_ifaddr
*ia
= 0;
register struct ifaddr
*ifa
;
struct iso_aliasreq
*ifra
= (struct iso_aliasreq
*)data
;
int error
, hostIsNew
, maskIsNew
;
* Find address for this interface, if it exists.
for (ia
= iso_ifaddr
; ia
; ia
= ia
->ia_next
)
if (ifra
->ifra_addr
.siso_family
== AF_ISO
)
for (oia
= ia
; ia
; ia
= ia
->ia_next
) {
SAME_ISOADDR(&ia
->ia_addr
, &ifra
->ifra_addr
))
if (error
= suser(u
.u_cred
, &u
.u_acflag
))
if (ia
== (struct iso_ifaddr
*)0) {
if (cmd
== SIOCDIFADDR_ISO
)
MALLOC(nia
, struct iso_ifaddr
*, sizeof(*nia
),
if (nia
== (struct iso_ifaddr
*)0)
bzero((caddr_t
)nia
, sizeof(*nia
));
for ( ; ia
->ia_next
; ia
= ia
->ia_next
)
if (ifa
= ifp
->if_addrlist
) {
for ( ; ifa
->ifa_next
; ifa
= ifa
->ifa_next
)
ifa
->ifa_next
= (struct ifaddr
*) ia
;
ifp
->if_addrlist
= (struct ifaddr
*) ia
;
ia
->ia_ifa
.ifa_addr
= (struct sockaddr
*)&ia
->ia_addr
;
= (struct sockaddr
*)&ia
->ia_dstaddr
;
= (struct sockaddr
*)&ia
->ia_sockmask
;
#define cmdbyte(x) (((x) >> 8) & 0xff)
return (snpac_ioctl(cmd
, data
));
if (ia
== (struct iso_ifaddr
*)0)
ifr
->ifr_Addr
= ia
->ia_addr
;
if ((ifp
->if_flags
& IFF_POINTOPOINT
) == 0)
ifr
->ifr_Addr
= ia
->ia_dstaddr
;
ifr
->ifr_Addr
= ia
->ia_sockmask
;
maskIsNew
= 0; hostIsNew
= 1; error
= u
.u_error
;
if (ia
->ia_addr
.siso_family
== AF_ISO
) {
if (ifra
->ifra_addr
.siso_len
== 0) {
ifra
->ifra_addr
= ia
->ia_addr
;
} else if (SAME_ISOADDR(&ia
->ia_addr
, &ifra
->ifra_addr
))
if (ifra
->ifra_mask
.siso_len
) {
ia
->ia_sockmask
= ifra
->ifra_mask
;
if ((ifp
->if_flags
& IFF_POINTOPOINT
) &&
(ifra
->ifra_dstaddr
.siso_family
== AF_ISO
)) {
ia
->ia_dstaddr
= ifra
->ifra_dstaddr
;
maskIsNew
= 1; /* We lie; but the effect's the same */
if (ifra
->ifra_addr
.siso_family
== AF_ISO
&&
(hostIsNew
|| maskIsNew
)) {
error
= iso_ifinit(ifp
, ia
, &ifra
->ifra_addr
, 0);
if (ifra
->ifra_snpaoffset
)
ia
->ia_snpaoffset
= ifra
->ifra_snpaoffset
;
if ((ifa
= ifp
->if_addrlist
) == (struct ifaddr
*)ia
)
ifp
->if_addrlist
= ifa
->ifa_next
;
(ifa
->ifa_next
!= (struct ifaddr
*)ia
))
ifa
->ifa_next
= ((struct ifaddr
*)ia
)->ifa_next
;
printf("Couldn't unlink isoifaddr from ifp\n");
if (oia
== (ia
= iso_ifaddr
)) {
iso_ifaddr
= ia
->ia_next
;
while (ia
->ia_next
&& (ia
->ia_next
!= oia
)) {
ia
->ia_next
= oia
->ia_next
;
printf("Didn't unlink isoifadr from list\n");
free((caddr_t
)oia
, M_IFADDR
);
if (ifp
== 0 || ifp
->if_ioctl
== 0)
return ((*ifp
->if_ioctl
)(ifp
, cmd
, data
));
* Delete any existing route for an interface.
register struct ifnet
*ifp
;
register struct iso_ifaddr
*ia
;
if ((ia
->ia_flags
& IFA_ROUTE
) == 0)
if (ifp
->if_flags
& IFF_LOOPBACK
)
rtinit(&(ia
->ia_ifa
), (int)RTM_DELETE
, RTF_HOST
);
else if (ifp
->if_flags
& IFF_POINTOPOINT
)
rtinit(&(ia
->ia_ifa
), (int)RTM_DELETE
, RTF_HOST
);
rtinit(&(ia
->ia_ifa
), (int)RTM_DELETE
, 0);
ia
->ia_flags
&= ~IFA_ROUTE
;
* Initialize an interface's internet address
* and routing table entry.
iso_ifinit(ifp
, ia
, siso
, scrub
)
register struct ifnet
*ifp
;
register struct iso_ifaddr
*ia
;
struct sockaddr_iso
*siso
;
struct sockaddr_iso oldaddr
;
* Give the interface a chance to initialize
* if this is its first address,
* and to validate the address if necessary.
if (ifp
->if_ioctl
&& (error
= (*ifp
->if_ioctl
)(ifp
, SIOCSIFADDR
, ia
))) {
ia
->ia_ifa
.ifa_addr
= (struct sockaddr
*)&oldaddr
;
ia
->ia_ifa
.ifa_addr
= (struct sockaddr
*)&ia
->ia_addr
;
* Add route for the network.
if (ifp
->if_flags
& IFF_LOOPBACK
) {
ia
->ia_ifa
.ifa_dstaddr
= ia
->ia_ifa
.ifa_addr
;
rtinit(&(ia
->ia_ifa
), (int)RTM_ADD
, RTF_HOST
|RTF_UP
);
} else if (ifp
->if_flags
& IFF_POINTOPOINT
&&
ia
->ia_dstaddr
.siso_family
== AF_ISO
)
rtinit(&(ia
->ia_ifa
), (int)RTM_ADD
, RTF_HOST
|RTF_UP
);
rtinit(&(ia
->ia_ifa
), (int)RTM_ADD
, RTF_UP
);
ia
->ia_flags
|= IFA_ROUTE
;
register struct sockaddr
*addr
;
register struct ifnet
*ifp
;
register struct ifaddr
*ifa
;
register u_int af
= addr
->sa_family
;
printf(">>> iso_ifwithidi addr\n");
dump_isoaddr( (struct sockaddr_iso
*)(addr
));
for (ifp
= ifnet
; ifp
; ifp
= ifp
->if_next
) {
printf("iso_ifwithidi ifnet %s\n", ifp
->if_name
);
for (ifa
= ifp
->if_addrlist
; ifa
; ifa
= ifa
->ifa_next
) {
printf("iso_ifwithidi address ");
dump_isoaddr( (struct sockaddr_iso
*)(ifa
->ifa_addr
));
if (ifa
->ifa_addr
->sa_family
!= addr
->sa_family
)
((struct sockaddr_iso *)((ifa)->ifa_addr))
printf(" af same, args to iso_eqtype:\n");
printf("0x%x ", IFA_SIS(ifa
)->siso_addr
);
&(((struct sockaddr_iso
*)addr
)->siso_addr
));
if (iso_eqtype(&(IFA_SIS(ifa
)->siso_addr
),
&(((struct sockaddr_iso
*)addr
)->siso_addr
))) {
printf("ifa_ifwithidi: ifa found\n");
printf(" iso_eqtype failed\n");
return ((struct ifaddr
*)0);
* PURPOSE: return true if the iso_addr passed is
* within the legal size limit for an iso address.
struct iso_addr
*isoa
; /* address to check */
return (isoa
->isoa_len
<= 20);
* PURPOSE: Determine if two iso addresses are of the same type.
* This is flaky. Really we should consider all type 47 addrs to be the
* same - but there do exist different structures for 47 addrs.
* RETURNS: true if the addresses are the same type
* NOTES: By type, I mean rfc986, t37, or osinet
* This will first compare afis. If they match, then
* if the addr is not t37, the idis must be compared.
struct iso_addr
*isoaa
; /* first addr to check */
struct iso_addr
*isoab
; /* other addr to check */
if (isoaa
->isoa_afi
== isoab
->isoa_afi
) {
if (isoaa
->isoa_afi
== AFI_37
)
return (!bcmp(&isoaa
->isoa_u
, &isoab
->isoa_u
, 2));
* FUNCTION: iso_localifa()
* PURPOSE: Find an interface addresss having a given destination
* or at least matching the net.
* RETURNS: ptr to an interface address
register struct sockaddr_iso
*siso
;
register struct iso_ifaddr
*ia
;
register char *cp1
, *cp2
, *cp3
;
register struct ifnet
*ifp
;
struct iso_ifaddr
*ia_maybe
= 0;
* We make one pass looking for both net matches and an exact
for (ia
= iso_ifaddr
; ia
; ia
= ia
->ia_next
) {
if ((ifp
= ia
->ia_ifp
) == 0 || ((ifp
->if_flags
& IFF_UP
) == 0))
if (ifp
->if_flags
& IFF_POINTOPOINT
) {
if ((ia
->ia_dstaddr
.siso_family
== AF_ISO
) &&
SAME_ISOADDR(&ia
->ia_dstaddr
, siso
))
if (SAME_ISOADDR(&ia
->ia_addr
, siso
))
if (ia
->ia_sockmask
.siso_len
) {
char *cplim
= ia
->ia_sockmask
.siso_len
+ (char *)&ia
->ia_sockmask
;
cp1
= ia
->ia_sockmask
.siso_data
;
cp3
= ia
->ia_addr
.siso_data
;
if (*cp1
++ & (*cp2
++ ^ *cp3
++))
if (SAME_ISOADDR(&ia
->ia_addr
, siso
))
#ifdef NARGOXTWENTYFIVE > 0
#endif NARGOXTWENTYFIVE > 0
* FUNCTION: iso_nlctloutput
* PURPOSE: Set options at the network level
* NOTES: This could embody some of the functions of
* rclnp_ctloutput and cons_ctloutput.
iso_nlctloutput(cmd
, optname
, pcb
, m
)
int cmd
; /* command:set or get */
int optname
; /* option of interest */
caddr_t pcb
; /* nl pcb */
struct mbuf
*m
; /* data for set, buffer for get */
struct isopcb
*isop
= (struct isopcb
*)pcb
;
int error
= 0; /* return value */
caddr_t data
; /* data for option */
int data_len
; /* data's length */
printf("iso_nlctloutput: cmd %x, opt %x, pcb %x, m %x\n",
if ((cmd
!= PRCO_GETOPT
) && (cmd
!= PRCO_SETOPT
))
printf("iso_nlctloutput: data is:\n");
dump_buf(data
, data_len
);
#ifdef NARGOXTWENTYFIVE > 0
if (cmd
== PRCO_GETOPT
) {
if (data_len
> MAXX25CRUDLEN
) {
printf("iso_nlctloutput: setting x25 crud\n");
bcopy(data
, (caddr_t
)isop
->isop_x25crud
, (unsigned)data_len
);
isop
->isop_x25crud_len
= data_len
;
#endif NARGOXTWENTYFIVE > 0
if( s
->siso_family
== AF_ISO
) {
printf("ISO address: suffixlen %d, %s\n",
s
->siso_tlen
, clnp_saddr_isop(s
));
} else if( s
->siso_family
== AF_INET
) {
struct sockaddr_in
*sin
= (struct sockaddr_in
*)s
;
printf("%d.%d.%d.%d: %d",
(sin
->sin_addr
.s_addr
>>24)&0xff,
(sin
->sin_addr
.s_addr
>>16)&0xff,
(sin
->sin_addr
.s_addr
>>8)&0xff,
(sin
->sin_addr
.s_addr
)&0xff,