/***********************************************************
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
/* @(#)esis.c 7.6 (Berkeley) %G% */
static char *rcsid
= "$Header: esis.c,v 4.10 88/09/15 18:57:03 hagens Exp $";
#include "../net/route.h"
* Global variables to esis implementation
* esis_holding_time - the holding time (sec) parameter for outgoing pdus
* esis_config_time - the frequency (sec) that hellos are generated
int esis_sendspace
= 2048;
int esis_recvspace
= 2048;
short esis_holding_time
= ESIS_HT
;
short esis_config_time
= ESIS_CONFIG
;
extern struct snpa_cache all_es
, all_is
;
#define EXTEND_PACKET(m, mhdr, cp)\
if (((m)->m_next = m_getclr(M_DONTWAIT, MT_HEADER)) == NULL) {\
(cp) = mtod((m), caddr_t);\
* PURPOSE: Initialize the kernel portion of esis protocol
extern struct clnl_protosw clnl_protox
[256];
esis_pcb
.isop_next
= esis_pcb
.isop_prev
= &esis_pcb
;
clnl_protox
[ISO9542_ESIS
].clnl_input
= esis_input
;
timeout(snpac_age
, (caddr_t
)0, hz
);
timeout(esis_config
, (caddr_t
)0, hz
);
clnl_protox
[ISO9542X25_ESIS
].clnl_input
= x25esis_input
;
* PURPOSE: Handle user level esis requests
* RETURNS: 0 or appropriate errno
* NOTES: This is here only so esis gets initialized.
esis_usrreq(so
, req
, m
, nam
, control
)
struct socket
*so
; /* socket: used only to get to this code */
struct mbuf
*m
; /* data for request */
struct mbuf
*nam
; /* optional name */
struct mbuf
*control
; /* optional control */
* PURPOSE: Process an incoming esis packet
struct mbuf
*m0
; /* ptr to first mbuf of pkt */
struct snpa_hdr
*shp
; /* subnetwork header */
struct esis_fixed
*pdu
= mtod(m0
, struct esis_fixed
*);
printf("esis_input: pdu on ifp x%x (%s%d): from:", shp
->snh_ifp
,
shp
->snh_ifp
->if_name
, shp
->snh_ifp
->if_unit
);
printf("%x%c", shp
->snh_shost
[i
]&0xff, (i
<5) ? ':' : ' ');
printf("%x%c", shp
->snh_dhost
[i
]&0xff, (i
<5) ? ':' : ' ');
* check checksum if necessary
if (ESIS_CKSUM_REQUIRED(pdu
) && iso_check_csum(m0
, (int)pdu
->esis_hdr_len
)) {
if (pdu
->esis_vers
!= ESIS_VERSION
) {
type
= pdu
->esis_type
& 0x1f;
* FUNCTION: esis_rdoutput
* PURPOSE: Transmit a redirect pdu
* NOTES: Assumes there is enough space for fixed part of header,
* DA, BSNPA and NET in first mbuf.
esis_rdoutput(inbound_shp
, inbound_m
, inbound_oidx
, rd_dstnsap
, nhop_sc
)
struct snpa_hdr
*inbound_shp
; /* snpa hdr from incoming packet */
struct mbuf
*inbound_m
; /* incoming pkt itself */
struct clnp_optidx
*inbound_oidx
; /* clnp options assoc with incoming pkt */
struct iso_addr
*rd_dstnsap
; /* ultimate destination of pkt */
struct snpa_cache
*nhop_sc
; /* snpa cache info regarding next hop of
struct sockaddr_iso siso
;
struct ifnet
*ifp
= inbound_shp
->snh_ifp
;
printf("esis_rdoutput: ifp x%x (%s%d), ht %d, m x%x, oidx x%x\n",
ifp
, ifp
->if_name
, ifp
->if_unit
, esis_holding_time
, inbound_m
,
printf("\tdestination: %s\n", clnp_iso_addrp(rd_dstnsap
));
printf("\tredirected toward:%s\n", clnp_iso_addrp(&nhop_sc
->sc_nsap
));
if ((m0
= m
= m_gethdr(M_DONTWAIT
, MT_HEADER
)) == NULL
) {
bzero(mtod(m
, caddr_t
), MHLEN
);
pdu
= mtod(m
, struct esis_fixed
*);
cp
= (caddr_t
)(pdu
+ 1); /*pointer arith.; 1st byte after header */
len
= sizeof(struct esis_fixed
);
* Build fixed part of header
pdu
->esis_proto_id
= ISO9542_ESIS
;
pdu
->esis_vers
= ESIS_VERSION
;
pdu
->esis_type
= ESIS_RD
;
HTOC(pdu
->esis_ht_msb
, pdu
->esis_ht_lsb
, esis_holding_time
);
/* Insert destination address */
(void) esis_insert_addr(&cp
, &len
, rd_dstnsap
, m
);
/* Insert the snpa of better next hop */
bcopy((caddr_t
)nhop_sc
->sc_snpa
, cp
, nhop_sc
->sc_len
);
len
+= (nhop_sc
->sc_len
+ 1);
* If the next hop is not the destination, then it ought to be
* an IS and it should be inserted next. Else, set the
/* PHASE2 use mask from ifp of outgoing interface */
if (!iso_addrmatch1(rd_dstnsap
, &nhop_sc
->sc_nsap
)) {
if ((nhop_sc
->sc_flags
& SNPA_IS
) == 0) {
/* this should not happen */
printf("esis_rdoutput: next hop is not dst and not an IS\n");
(void) esis_insert_addr(&cp
, &len
, &nhop_sc
->sc_nsap
, m
);
* If redirect is to an IS, add an address mask. The mask to be
* used should be the mask present in the routing entry used to
* forward the original data packet.
* Copy Qos, priority, or security options present in original npdu
/* THIS CODE IS CURRENTLY UNTESTED */
if (inbound_oidx
->cni_qos_formatp
)
optlen
+= (inbound_oidx
->cni_qos_len
+ 2);
if (inbound_oidx
->cni_priorp
) /* priority option is 1 byte long */
if (inbound_oidx
->cni_securep
)
optlen
+= (inbound_oidx
->cni_secure_len
+ 2);
if (M_TRAILINGSPACE(m
) < optlen
) {
EXTEND_PACKET(m
, m0
, cp
);
/* assumes MLEN > optlen */
/* assume MLEN-len > optlen */
* When copying options, copy from ptr - 2 in order to grab
* the option code and length
if (inbound_oidx
->cni_qos_formatp
) {
bcopy((caddr_t
)(inbound_m
+ inbound_oidx
->cni_qos_formatp
- 2), cp
,
(unsigned)(inbound_oidx
->cni_qos_len
+ 2));
len
+= inbound_oidx
->cni_qos_len
+ 2;
if (inbound_oidx
->cni_priorp
) {
bcopy((caddr_t
)(inbound_m
+ inbound_oidx
->cni_priorp
- 2), cp
, 3);
if (inbound_oidx
->cni_securep
) {
bcopy((caddr_t
)(inbound_m
+ inbound_oidx
->cni_securep
- 2), cp
,
(unsigned)(inbound_oidx
->cni_secure_len
+ 2));
len
+= inbound_oidx
->cni_secure_len
+ 2;
pdu
->esis_hdr_len
= m0
->m_pkthdr
.len
= len
;
iso_gen_csum(m0
, ESIS_CKSUM_OFF
, (int)pdu
->esis_hdr_len
);
bzero((caddr_t
)&siso
, sizeof(siso
));
siso
.siso_family
= AF_ISO
;
siso
.siso_data
[0] = AFI_SNA
;
siso
.siso_nlen
= 6 + 1; /* should be taken from snpa_hdr */
bcopy(inbound_shp
->snh_shost
, siso
.siso_data
+ 1, 6);
(ifp
->if_output
)(ifp
, m0
, &siso
, 0);
* FUNCTION: esis_insert_addr
* PURPOSE: Insert an iso_addr into a buffer
* RETURNS: true if buffer was big enough, else false
* SIDE EFFECTS: Increment buf & len according to size of iso_addr
* NOTES: Plus 1 here is for length byte
esis_insert_addr(buf
, len
, isoa
, m
)
caddr_t
*buf
; /* ptr to buffer to put address into */
int *len
; /* ptr to length of buffer so far */
struct iso_addr
*isoa
; /* ptr to address */
register struct mbuf
*m
; /* determine if there remains space */
register int newlen
= isoa
->isoa_len
+ 1;
if (newlen
> M_TRAILINGSPACE(m
))
bcopy((caddr_t
)isoa
, *buf
, newlen
);
#define ESIS_EXTRACT_ADDR(d, b) { d = (struct iso_addr *)(b); b += (1 + *b); \
if (b > buflim) {esis_stat.es_toosmall++; goto bad;}}
#define ESIS_NEXT_OPTION(b) { b += (2 + b[1]); \
if (b > buflim) {esis_stat.es_toosmall++; goto bad;}}
* FUNCTION: esis_eshinput
* PURPOSE: Process an incoming ESH pdu
struct mbuf
*m
; /* esh pdu */
struct snpa_hdr
*shp
; /* subnetwork header */
struct esis_fixed
*pdu
= mtod(m
, struct esis_fixed
*);
u_short ht
; /* holding time */
u_char
*buf
= (u_char
*)(pdu
+ 1);
u_char
*buflim
= pdu
->esis_hdr_len
+ (u_char
*)pdu
;
CTOH(pdu
->esis_ht_msb
, pdu
->esis_ht_lsb
, ht
);
printf("esis_eshinput: esh: ht %d, naddr %d\n", ht
, naddr
);
ESIS_EXTRACT_ADDR(nsap
, buf
);
new_entry
= (snpac_look(nsap
) == NULL
);
printf("esis_eshinput: nsap %s is %s\n",
clnp_iso_addrp(nsap
), new_entry
? "new" : "old");
snpac_add(shp
->snh_ifp
, nsap
, shp
->snh_shost
, 6, SNPA_ES
, ht
);
esis_shoutput(shp
->snh_ifp
,
iso_systype
& SNPA_ES
? ESIS_ESH
: ESIS_ISH
,
esis_holding_time
, shp
->snh_shost
, 6);
* FUNCTION: esis_ishinput
* PURPOSE: process an incoming ISH pdu
struct mbuf
*m
; /* esh pdu */
struct snpa_hdr
*shp
; /* subnetwork header */
struct esis_fixed
*pdu
= mtod(m
, struct esis_fixed
*);
u_short ht
; /* holding time */
struct iso_addr
*nsap
; /* Network Entity Title */
register u_char
*buf
= (u_char
*) (pdu
+ 1);
register u_char
*buflim
= pdu
->esis_hdr_len
+ (u_char
*)pdu
;
CTOH(pdu
->esis_ht_msb
, pdu
->esis_ht_lsb
, ht
);
printf("esis_ishinput: ish: ht %d\n", ht
);
ESIS_EXTRACT_ADDR(nsap
, buf
);
CTOH(buf
[2], buf
[3], esis_config_time
);
printf("Unknown ISH option: %x\n", *buf
);
new_entry
= (snpac_look(nsap
) == NULL
);
printf("esis_ishinput: nsap %s is %s\n",
clnp_iso_addrp(nsap
), new_entry
? "new" : "old");
snpac_add(shp
->snh_ifp
, nsap
, shp
->snh_shost
, 6, SNPA_IS
, ht
);
esis_shoutput(shp
->snh_ifp
,
iso_systype
& SNPA_ES
? ESIS_ESH
: ESIS_ISH
,
esis_holding_time
, shp
->snh_shost
, 6);
* PURPOSE: Process an incoming RD pdu
struct mbuf
*m0
; /* esh pdu */
struct snpa_hdr
*shp
; /* subnetwork header */
struct esis_fixed
*pdu
= mtod(m0
, struct esis_fixed
*);
u_short ht
; /* holding time */
struct iso_addr
*da
, *net
= 0, *netmask
= 0, *snpamask
= 0;
register struct iso_addr
*bsnpa
;
register u_char
*buf
= (u_char
*)(pdu
+ 1);
register u_char
*buflim
= pdu
->esis_hdr_len
+ (u_char
*)pdu
;
/* intermediate systems ignore redirects */
if (iso_systype
& SNPA_IS
)
CTOH(pdu
->esis_ht_msb
, pdu
->esis_ht_lsb
, ht
);
ESIS_EXTRACT_ADDR(da
, buf
);
/* Extract better snpa */
ESIS_EXTRACT_ADDR(bsnpa
, buf
);
/* Extract NET if present */
ESIS_EXTRACT_ADDR(net
, buf
);
if (snpamask
) /* duplicate */
snpamask
= (struct iso_addr
*)(buf
+ 1);
if (netmask
) /* duplicate */
netmask
= (struct iso_addr
*)(buf
+ 1);
printf("Unknown option in ESIS RD (0x%x)\n", buf
[-1]);
printf("esis_rdinput: rd: ht %d, da %s\n", ht
, clnp_iso_addrp(da
));
printf("\t: net %s\n", clnp_iso_addrp(net
));
* If netl is zero, then redirect is to an ES. We need to add an entry
* to the snpa cache for (destination, better snpa).
* If netl is not zero, then the redirect is to an IS. In this
* case, add an snpa cache entry for (net, better snpa).
* If the redirect is to an IS, add a route entry towards that
if (net
== 0 || net
->isoa_len
== 0 || snpamask
) {
snpac_add(shp
->snh_ifp
, da
,
bsnpa
->isoa_genaddr
, bsnpa
->isoa_len
, SNPA_ES
, ht
);
snpac_add(shp
->snh_ifp
, net
,
bsnpa
->isoa_genaddr
, bsnpa
->isoa_len
, SNPA_IS
, ht
);
snpac_addrt(shp
->snh_ifp
, da
, net
, netmask
);
* PURPOSE: Report configuration
* NOTES: Called every esis_config_time seconds
register struct ifnet
*ifp
;
timeout(esis_config
, (caddr_t
)0, hz
* esis_config_time
);
* Report configuration for each interface that
* - has broadcast capabilities
for (ifp
= ifnet
; ifp
; ifp
= ifp
->if_next
) {
if ((ifp
->if_flags
& IFF_UP
) &&
(ifp
->if_flags
& IFF_BROADCAST
) &&
((ifp
->if_flags
& IFF_LOOPBACK
) == 0)) {
/* search for an ISO address family */
for (ia
= ifp
->if_addrlist
; ia
; ia
= ia
->ifa_next
) {
if (ia
->ifa_addr
->sa_family
== AF_ISO
) {
iso_systype
& SNPA_ES
? ESIS_ESH
: ESIS_ISH
,
(caddr_t
)(iso_systype
& SNPA_ES
? all_is
.sc_snpa
:
* FUNCTION: esis_shoutput
* PURPOSE: Transmit an esh or ish pdu
esis_shoutput(ifp
, type
, ht
, sn_addr
, sn_len
)
struct sockaddr_iso siso
;
else if (type
== ESIS_ISH
)
printf("esis_shoutput: bad pdu type\n");
printf("esis_shoutput: ifp x%x (%s%d), %s, ht %d, to: [%d] ",
ifp
, ifp
->if_name
, ifp
->if_unit
, type
== ESIS_ESH
? "esh" : "ish",
printf("%x%c", *(sn_addr
+i
), i
< (sn_len
-1) ? ':' : ' ');
if ((m0
= m
= m_gethdr(M_DONTWAIT
, MT_HEADER
)) == NULL
) {
bzero(mtod(m
, caddr_t
), MHLEN
);
pdu
= mtod(m
, struct esis_fixed
*);
naddrp
= cp
= (caddr_t
)(pdu
+ 1);
len
= sizeof(struct esis_fixed
);
* Build fixed part of header
pdu
->esis_proto_id
= ISO9542_ESIS
;
pdu
->esis_vers
= ESIS_VERSION
;
HTOC(pdu
->esis_ht_msb
, pdu
->esis_ht_lsb
, ht
);
for (ifa
= ifp
->if_addrlist
; ifa
; ifa
=ifa
->ifa_next
) {
if (ifa
->ifa_addr
->sa_family
== AF_ISO
) {
printf("esis_shoutput: adding nsap %s\n",
clnp_iso_addrp(&IA_SIS(ifa
)->siso_addr
));
if (!esis_insert_addr(&cp
, &len
, &IA_SIS(ifa
)->siso_addr
, m
)) {
EXTEND_PACKET(m
, m0
, cp
);
(void) esis_insert_addr(&cp
, &len
, &IA_SIS(ifa
)->siso_addr
, m
);
iso_gen_csum(m0
, ESIS_CKSUM_OFF
, (int)pdu
->esis_hdr_len
);
bzero((caddr_t
)&siso
, sizeof(siso
));
siso
.siso_family
= AF_ISO
;
siso
.siso_data
[0] = AFI_SNA
;
siso
.siso_nlen
= sn_len
+ 1;
siso
.siso_len
= sn_len
+ 6;
bcopy(sn_addr
, siso
.siso_data
+ 1, (unsigned)sn_len
);
(ifp
->if_output
)(ifp
, m0
, &siso
, 0);
* FUNCTION: esis_ctlinput
* PURPOSE: Handle the PRC_IFDOWN transition
* NOTES: Calls snpac_flush for interface specified.
* The loop through iso_ifaddr is stupid because
* back in if_down, we knew the ifp...
int req
; /* request: we handle only PRC_IFDOWN */
struct sockaddr_iso
*siso
; /* address of ifp */
register struct iso_ifaddr
*ia
; /* scan through interface addresses */
for (ia
= iso_ifaddr
; ia
; ia
= ia
->ia_next
) {
if (iso_addrmatch(IA_SIS(ia
), siso
))
snpac_flushifp(ia
->ia_ifp
);