diff options
author | phk <phk@FreeBSD.org> | 1998-09-15 08:23:17 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 1998-09-15 08:23:17 +0000 |
commit | c3dd1fa899d435ea4bf79897f646a93cb80c94ac (patch) | |
tree | 98dfbc96e3c6aa7ff1f322855f6484c4e609819d /lib/libatm | |
parent | 9ed6892f4808d56de443849229e151f8f7ad43b0 (diff) | |
download | FreeBSD-src-c3dd1fa899d435ea4bf79897f646a93cb80c94ac.zip FreeBSD-src-c3dd1fa899d435ea4bf79897f646a93cb80c94ac.tar.gz |
Add new files for HARP3
Host ATM Research Platform (HARP), Network Computing Services, Inc.
This software was developed with the support of the Defense Advanced
Research Projects Agency (DARPA).
Diffstat (limited to 'lib/libatm')
-rw-r--r-- | lib/libatm/Makefile | 37 | ||||
-rw-r--r-- | lib/libatm/atm_addr.c | 327 | ||||
-rw-r--r-- | lib/libatm/cache_key.c | 115 | ||||
-rw-r--r-- | lib/libatm/ioctl_subr.c | 515 | ||||
-rw-r--r-- | lib/libatm/ip_addr.c | 167 | ||||
-rw-r--r-- | lib/libatm/ip_checksum.c | 102 | ||||
-rw-r--r-- | lib/libatm/libatm.h | 118 | ||||
-rw-r--r-- | lib/libatm/timer.c | 261 |
8 files changed, 1642 insertions, 0 deletions
diff --git a/lib/libatm/Makefile b/lib/libatm/Makefile new file mode 100644 index 0000000..d861b81 --- /dev/null +++ b/lib/libatm/Makefile @@ -0,0 +1,37 @@ +# +# +# =================================== +# HARP | Host ATM Research Platform +# =================================== +# +# +# This Host ATM Research Platform ("HARP") file (the "Software") is +# made available by Network Computing Services, Inc. ("NetworkCS") +# "AS IS". NetworkCS does not provide maintenance, improvements or +# support of any kind. +# +# NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED, +# INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE +# SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE. +# In no event shall NetworkCS be responsible for any damages, including +# but not limited to consequential damages, arising from or relating to +# any use of the Software or related support. +# +# Copyright 1994-1998 Network Computing Services, Inc. +# +# Copies of this Software may be made, however, the above copyright +# notice must be reproduced on all copies. +# +# @(#) $Id: Makefile,v 1.5 1998/07/10 16:01:58 jpt Exp $ +# +# + +LIB= atm +SRCS= atm_addr.c cache_key.c ioctl_subr.c ip_addr.c ip_checksum.c timer.c + +beforeinstall: + ${INSTALL} -C -o ${BINOWN} -g ${BINGRP} -m 444 ${.CURDIR}/libatm.h \ + ${DESTDIR}/usr/include + +.include <bsd.lib.mk> diff --git a/lib/libatm/atm_addr.c b/lib/libatm/atm_addr.c new file mode 100644 index 0000000..032107c --- /dev/null +++ b/lib/libatm/atm_addr.c @@ -0,0 +1,327 @@ +/* + * + * =================================== + * HARP | Host ATM Research Platform + * =================================== + * + * + * This Host ATM Research Platform ("HARP") file (the "Software") is + * made available by Network Computing Services, Inc. ("NetworkCS") + * "AS IS". NetworkCS does not provide maintenance, improvements or + * support of any kind. + * + * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED, + * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE + * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE. + * In no event shall NetworkCS be responsible for any damages, including + * but not limited to consequential damages, arising from or relating to + * any use of the Software or related support. + * + * Copyright 1994-1998 Network Computing Services, Inc. + * + * Copies of this Software may be made, however, the above copyright + * notice must be reproduced on all copies. + * + * @(#) $Id: atm_addr.c,v 1.1 1998/07/09 21:45:18 johnc Exp $ + * + */ + +/* + * User Space Library Functions + * ---------------------------- + * + * ATM address utility functions + * + */ + +#ifndef lint +static char *RCSid = "@(#) $Id: atm_addr.c,v 1.1 1998/07/09 21:45:18 johnc Exp $"; +#endif + +#include <sys/types.h> +#include <sys/param.h> +#include <string.h> + +#include <sys/socket.h> +#include <net/if.h> +#include <netinet/in.h> +#include <netatm/port.h> +#include <netatm/atm.h> +#include <netatm/atm_if.h> +#include <netatm/atm_sap.h> +#include <netatm/atm_sys.h> +#include <netatm/atm_ioctl.h> + +#include "libatm.h" + + +extern char *prog; + + +/* + * Get NSAP, NSAP prefix or MAC address + * + * Arguments: + * in pointer to an address in ASCII + * out pointer to a buffer for the converted address + * len the length of the output buffer + * + * Returns: + * 0 error in format + * len the length of the data in the output buffer + * + */ +int +get_hex_atm_addr(in, out, len) + char *in; + u_char *out; + int len; +{ + int c_type, c_value, i, out_len, state, val; + + /* + * Character table + */ + static struct { + char c; + int type; + int value; + } char_table[] = { + {'.', 0, 0}, /* Type 0 -- period */ + {':', 0, 0}, /* Type 0 -- colon */ + {'0', 1, 0}, /* Type 1 -- hex digit */ + {'1', 1, 1}, + {'2', 1, 2}, + {'3', 1, 3}, + {'4', 1, 4}, + {'5', 1, 5}, + {'6', 1, 6}, + {'7', 1, 7}, + {'8', 1, 8}, + {'9', 1, 9}, + {'a', 1, 10}, + {'b', 1, 11}, + {'c', 1, 12}, + {'d', 1, 13}, + {'e', 1, 14}, + {'f', 1, 15}, + {'A', 1, 10}, + {'B', 1, 11}, + {'C', 1, 12}, + {'D', 1, 13}, + {'E', 1, 14}, + {'F', 1, 15}, + {'\0', 2, 0}, /* Type 2 -- end of input */ + }; + + /* + * State table + */ + static struct { + int action; + int state; + } state_table[3][3] = { + /* Period Hex End */ + { { 0, 0 }, { 1, 1 }, { 2, 0} }, /* Init */ + { { 4, 0 }, { 3, 2 }, { 4, 0} }, /* C1 */ + { { 0, 2 }, { 1, 1 }, { 2, 0} }, /* C2 */ + }; + + /* + * Initialize + */ + state = 0; + out_len = 0; + if (!strncasecmp(in, "0x", 2)) { + in += 2; + } + + /* + * Loop through input until state table says to return + */ + while (1) { + /* + * Get the character type and value + */ + for (i=0; char_table[i].c; i++) + if (char_table[i].c == *in) + break; + if (char_table[i].c != *in) + return(0); + c_type = char_table[i].type; + c_value = char_table[i].value; + + /* + * Process next character based on state and type + */ + switch(state_table[state][c_type].action) { + case 0: + /* + * Ignore the character + */ + break; + + case 1: + /* + * Save the character's value + */ + val = c_value; + break; + + case 2: + /* + * Return the assembled NSAP + */ + return(out_len); + + case 3: + /* + * Assemble and save the output byte + */ + val = val << 4; + val += c_value; + out[out_len] = (u_char) val; + out_len++; + break; + + case 4: + /* + * Invalid input sequence + */ + return(0); + + default: + return(0); + } + + /* + * Set the next state and go on to the next character + */ + state = state_table[state][c_type].state; + in++; + } +} + + +/* + * Format an ATM address into a string + * + * Arguments: + * addr pointer to an atm address + * + * Returns: + * none + * + */ +char * +format_atm_addr(addr) + Atm_addr *addr; +{ + int i; + char *nsap_format; + Atm_addr_nsap *atm_nsap; + Atm_addr_e164 *atm_e164; + Atm_addr_spans *atm_spans; + Atm_addr_pvc *atm_pvc; + static char str[256]; + union { + int w; + char c[4]; + } u1, u2; + + static char nsap_format_DCC[] = "0x%02x.%02x%02x.%02x.%02x%02x%02x.%02x%02x.%02x%02x.%02x%02x.%02x%02x%02x%02x%02x%02x.%02x"; + static char nsap_format_ICD[] = "0x%02x.%02x%02x.%02x.%02x%02x%02x.%02x%02x.%02x%02x.%02x%02x.%02x%02x%02x%02x%02x%02x.%02x"; + static char nsap_format_E164[] = "0x%02x.%02x%02x%02x%02x%02x%02x%02x%02x.%02x%02x.%02x%02x.%02x%02x%02x%02x%02x%02x.%02x"; + + /* + * Clear the returned string + */ + UM_ZERO(str, sizeof(str)); + strcpy(str, "-"); + + /* + * Print format is determined by address type + */ + switch (addr->address_format) { + case T_ATM_ENDSYS_ADDR: + atm_nsap = (Atm_addr_nsap *)addr->address; + switch(atm_nsap->aan_afi) { + default: + case AFI_DCC: + nsap_format = nsap_format_DCC; + break; + case AFI_ICD: + nsap_format = nsap_format_ICD; + break; + case AFI_E164: + nsap_format = nsap_format_E164; + break; + } + sprintf(str, nsap_format, + atm_nsap->aan_afi, + atm_nsap->aan_afspec[0], + atm_nsap->aan_afspec[1], + atm_nsap->aan_afspec[2], + atm_nsap->aan_afspec[3], + atm_nsap->aan_afspec[4], + atm_nsap->aan_afspec[5], + atm_nsap->aan_afspec[6], + atm_nsap->aan_afspec[7], + atm_nsap->aan_afspec[8], + atm_nsap->aan_afspec[9], + atm_nsap->aan_afspec[10], + atm_nsap->aan_afspec[11], + atm_nsap->aan_esi[0], + atm_nsap->aan_esi[1], + atm_nsap->aan_esi[2], + atm_nsap->aan_esi[3], + atm_nsap->aan_esi[4], + atm_nsap->aan_esi[5], + atm_nsap->aan_sel); + break; + + case T_ATM_E164_ADDR: + atm_e164 = (Atm_addr_e164 *)addr->address; + for(i=0; i<addr->address_length; i++) { + sprintf(&str[strlen(str)], "%c\0", + atm_e164->aae_addr[i]); + } + break; + + case T_ATM_SPANS_ADDR: + /* + * Print SPANS address as two words, xxxx.yyyy + */ + atm_spans = (Atm_addr_spans *)addr->address; + u1.c[0] = atm_spans->aas_addr[0]; + u1.c[1] = atm_spans->aas_addr[1]; + u1.c[2] = atm_spans->aas_addr[2]; + u1.c[3] = atm_spans->aas_addr[3]; + + u2.c[0] = atm_spans->aas_addr[4]; + u2.c[1] = atm_spans->aas_addr[5]; + u2.c[2] = atm_spans->aas_addr[6]; + u2.c[3] = atm_spans->aas_addr[7]; + + if (!(u1.w == 0 && u2.w == 0)) + sprintf(str, "0x%08x.%08x", u1.w, u2.w); + break; + + case T_ATM_PVC_ADDR: + /* + * Print PVC as VPI, VCI + */ + atm_pvc = (Atm_addr_pvc *)addr->address; + sprintf(str, "%d, %d", + ATM_PVC_GET_VPI(atm_pvc), + ATM_PVC_GET_VCI(atm_pvc)); + break; + + case T_ATM_ABSENT: + default: + break; + } + + return(str); +} diff --git a/lib/libatm/cache_key.c b/lib/libatm/cache_key.c new file mode 100644 index 0000000..f0d6650 --- /dev/null +++ b/lib/libatm/cache_key.c @@ -0,0 +1,115 @@ +/* + * + * =================================== + * HARP | Host ATM Research Platform + * =================================== + * + * + * This Host ATM Research Platform ("HARP") file (the "Software") is + * made available by Network Computing Services, Inc. ("NetworkCS") + * "AS IS". NetworkCS does not provide maintenance, improvements or + * support of any kind. + * + * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED, + * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE + * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE. + * In no event shall NetworkCS be responsible for any damages, including + * but not limited to consequential damages, arising from or relating to + * any use of the Software or related support. + * + * Copyright 1994-1998 Network Computing Services, Inc. + * + * Copies of this Software may be made, however, the above copyright + * notice must be reproduced on all copies. + * + * @(#) $Id: cache_key.c,v 1.1 1998/07/09 21:45:27 johnc Exp $ + * + */ + + +/* + * User Space Library Functions + * ---------------------------- + * + * SCSP cache key computation + * + */ + + +#ifndef lint +static char *RCSid = "@(#) $Id: cache_key.c,v 1.1 1998/07/09 21:45:27 johnc Exp $"; +#endif + +#include <sys/types.h> +#include <sys/param.h> + +#include <sys/socket.h> +#include <net/if.h> +#include <netinet/in.h> +#include <netatm/port.h> +#include <netatm/atm.h> +#include <netatm/atm_if.h> +#include <netatm/atm_sap.h> +#include <netatm/atm_sys.h> +#include <netatm/atm_ioctl.h> + +#include <md5.h> +#include "libatm.h" + + +/* + * Compute an SCSP cache key + * + * Arguments: + * ap pointer to an Atm_addr with the ATM address + * ip pointer to a struct in_addr with the IP address + * ol the required length of the cache key + * op pointer to receive cache key + * + * Returns: + * none + * + */ +void +scsp_cache_key(ap, ip, ol, op) + Atm_addr *ap; + struct in_addr *ip; + int ol; + char *op; +{ + int i, key, len; + char *cp; + char buff[32], digest[16]; + MD5_CTX context; + + /* + * Initialize + */ + UM_ZERO(buff, sizeof(buff)); + + /* + * Copy the addresses into a buffer for MD5 computation + */ + len = sizeof(struct in_addr) + ap->address_length; + if (len > sizeof(buff)) + len = sizeof(buff); + UM_COPY(ip, buff, sizeof(struct in_addr)); + UM_COPY(ap->address, &buff[sizeof(struct in_addr)], + len - sizeof(struct in_addr)); + + /* + * Compute the MD5 digest of the combined IP and ATM addresses + */ + MD5Init(&context); + MD5Update(&context, buff, len); + MD5Final(digest, &context); + + /* + * Fold the 16-byte digest to the required length + */ + UM_ZERO((caddr_t)op, ol); + for (i = 0; i < 16; i++) { + op[i % ol] = op[i % ol] ^ digest[i]; + } +} diff --git a/lib/libatm/ioctl_subr.c b/lib/libatm/ioctl_subr.c new file mode 100644 index 0000000..a77d79f --- /dev/null +++ b/lib/libatm/ioctl_subr.c @@ -0,0 +1,515 @@ +/* + * + * =================================== + * HARP | Host ATM Research Platform + * =================================== + * + * + * This Host ATM Research Platform ("HARP") file (the "Software") is + * made available by Network Computing Services, Inc. ("NetworkCS") + * "AS IS". NetworkCS does not provide maintenance, improvements or + * support of any kind. + * + * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED, + * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE + * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE. + * In no event shall NetworkCS be responsible for any damages, including + * but not limited to consequential damages, arising from or relating to + * any use of the Software or related support. + * + * Copyright 1994-1998 Network Computing Services, Inc. + * + * Copies of this Software may be made, however, the above copyright + * notice must be reproduced on all copies. + * + * @(#) $Id: ioctl_subr.c,v 1.2 1998/07/10 17:09:20 root Exp $ + * + */ + +/* + * User Space Library Functions + * ---------------------------- + * + * IOCTL subroutines + * + */ + +#ifndef lint +static char *RCSid = "@(#) $Id: ioctl_subr.c,v 1.2 1998/07/10 17:09:20 root Exp $"; +#endif + +#include <sys/types.h> +#include <sys/param.h> + +#include <errno.h> +#include <sys/socket.h> +#include <sys/sockio.h> +#include <net/if.h> +#include <netinet/in.h> +#include <netatm/port.h> +#include <netatm/atm.h> +#include <netatm/atm_if.h> +#include <netatm/atm_sap.h> +#include <netatm/atm_sys.h> +#include <netatm/atm_ioctl.h> + +#include "libatm.h" + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +extern char *prog; + + +/* + * Issue an informational IOCTL + * + * The user fills out the opcode and any subtype information. This + * routine will allocate a buffer and issue the IOCTL. If the request + * fails because the buffer wasn't big enough, this routine will double + * the buffer size and retry the request repeatedly. The buffer must + * be freed by the caller. + * + * Arguments: + * req pointer to an ATM information request IOCTL structure + * buf_len length of buffer to be allocated + * + * Returns: + * -1 error encountered (reason in errno) + * int length of the returned VCC information + * + */ +int +do_info_ioctl(req, buf_len) + struct atminfreq *req; + int buf_len; +{ + int rc, s; + caddr_t buf; + + /* + * Open a socket for the IOCTL + */ + s = socket(AF_ATM, SOCK_DGRAM, 0); + if (s < 0) { + return(-1); + } + + /* + * Get memory for returned information + */ +mem_retry: + buf = (caddr_t)UM_ALLOC(buf_len); + if (buf == NULL) { + errno = ENOMEM; + return(-1); + } + + /* + * Set the buffer address and length in the request + */ + req->air_buf_addr = buf; + req->air_buf_len = buf_len; + + /* + * Issue the IOCTL + */ + rc = ioctl(s, AIOCINFO, (caddr_t)req); + if (rc) { + UM_FREE(buf); + if (errno == ENOSPC) { + buf_len = buf_len * 2; + goto mem_retry; + } + return(-1); + } + (void)close(s); + /* + * Set a pointer to the returned info in the request + * and return its length + */ + req->air_buf_addr = buf; + return(req->air_buf_len); +} + + +/* + * Get VCC information + * + * Arguments: + * intf pointer to interface name (or null string) + * vccp pointer to a pointer to a struct air_vcc_rsp for the + * address of the returned VCC information + * + * Returns: + * int length of the retuned VCC information + * + */ +int +get_vcc_info(intf, vccp) + char *intf; + struct air_vcc_rsp **vccp; +{ + int buf_len = sizeof(struct air_vcc_rsp) * 100; + struct atminfreq air; + + /* + * Initialize IOCTL request + */ + air.air_opcode = AIOCS_INF_VCC; + UM_ZERO(air.air_vcc_intf, sizeof(air.air_vcc_intf)); + if (intf != NULL && strlen(intf) != 0) + strcpy(air.air_vcc_intf, intf); + + buf_len = do_info_ioctl(&air, buf_len); + + /* + * Return a pointer to the VCC info and its length + */ + *vccp = (struct air_vcc_rsp *) air.air_buf_addr; + return(buf_len); +} + + +/* + * Count number of open VCCs + * + * Issue a AIOCS_INF_VCC to get info on all open VCCs. Count them and + * return the answer. + * + * Arguments: + * intf pointer to interface name (or null string) + * + * Returns: + * int number of VCCs + * + */ +int +count_vccs ( intf ) +char *intf; +{ + int vcc_info_len; + int count = 0; + char *cp; + struct air_vcc_rsp *vcc_info, *vcc_info_base; + + vcc_info_len = get_vcc_info ( intf, &vcc_info ); + if ( !vcc_info ) + return ( 0 ); + vcc_info_base = vcc_info; + + for ( ; vcc_info_len >= sizeof ( struct air_vcc_rsp ); + vcc_info_len -= sizeof ( struct air_vcc_rsp ), + vcc_info++ ) { + count++; + } + free ( vcc_info_base ); + return ( count ); +} + + +/* + * Get subnet mask + * + * Arguments: + * intf pointer to an interface name + * mask pointer to a struct sockaddr_in to receive the mask + * + * Returns: + * 0 good completion + * -1 error + * + */ +int +get_subnet_mask(intf, mask) + char *intf; + struct sockaddr_in *mask; +{ + int rc, s; + struct ifreq req; + struct sockaddr_in *ip_mask; + + /* + * Check parameters + */ + if (!intf || !mask || + strlen(intf) == 0 || + strlen(intf) > IFNAMSIZ-1) + return(-1); + + /* + * Open a socket for the IOCTL + */ + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) + return(-1); + + /* + * Set up and issue the IOCTL + */ + UM_ZERO(&req, sizeof(req)); + strcpy(req.ifr_name, intf); + rc = ioctl(s, SIOCGIFNETMASK, (caddr_t)&req); + (void)close(s); + if (rc) + return(-1); + + /* + * Give the answer back to the caller + */ + ip_mask = (struct sockaddr_in *)&req.ifr_addr; + *mask = *ip_mask; + mask->sin_family = AF_INET; + + return(0); +} + + +/* + * Get an interface's MTU + * + * Arguments: + * intf pointer to an interface name + * mtu pointer to an int to receive the MTU + * + * Returns: + * >= 0 interface MTU + * -1 error + * + */ +int +get_mtu(intf) + char *intf; +{ + int rc, s; + struct ifreq req; + + /* + * Check parameters + */ + if (!intf || strlen(intf) == 0 || + strlen(intf) > IFNAMSIZ-1) + return(-1); + + /* + * Open a socket for the IOCTL + */ + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) + return(-1); + + /* + * Set up and issue the IOCTL + */ + UM_ZERO(&req, sizeof(req)); + strcpy(req.ifr_name, intf); + rc = ioctl(s, SIOCGIFMTU, (caddr_t)&req); + (void)close(s); + + /* + * Set the appropriate return value + */ + if (rc) + return(-1); + else + return(req.ifr_mtu); +} + + +/* + * Verify netif name + * + * This routine issues an IOCTL to check whether the passed string is + * a valid network interface name. + * + * Arguments: + * req pointer to an ATM information request IOCTL structure + * + * Returns: + * -1 error encountered + * FALSE (0) the string is not a NIF name + * TRUE (> 0) the string is a valid NIF name + * + */ +int +verify_nif_name(name) + char *name; +{ + int rc, s; + caddr_t buf; + struct atminfreq air; + struct air_netif_rsp *nif_info; + + /* + * Check whether name is of a valid length + */ + if (strlen(name) > IFNAMSIZ - 1 || + strlen(name) < 1) { + return(FALSE); + } + + /* + * Open a socket for the IOCTL + */ + s = socket(AF_ATM, SOCK_DGRAM, 0); + if (s < 0) { + return(-1); + } + + /* + * Get memory for returned information + */ + nif_info = (struct air_netif_rsp *)UM_ALLOC( + sizeof(struct air_netif_rsp)); + if (nif_info == NULL) { + errno = ENOMEM; + return(-1); + } + + /* + * Set up the request + */ + air.air_opcode = AIOCS_INF_NIF; + air.air_buf_addr = (caddr_t)nif_info; + air.air_buf_len = sizeof(struct air_netif_rsp); + UM_ZERO(air.air_netif_intf, sizeof(air.air_netif_intf)); + strcpy(air.air_netif_intf, name); + + /* + * Issue the IOCTL + */ + rc = ioctl(s, AIOCINFO, (caddr_t)&air); + UM_FREE(nif_info); + (void)close(s); + + /* + * Base return value on IOCTL return code + */ + if (rc) + return(FALSE); + else + return(TRUE); +} + +/* + * Get Config information + * + * Arguments: + * intf pointer to interface name (or null string) + * cfgp pointer to a pointer to a struct air_cfg_rsp for the + * address of the returned Config information + * + * Returns: + * int length of returned Config information + * + */ +int +get_cfg_info ( intf, cfgp ) + char *intf; + struct air_cfg_rsp **cfgp; +{ + int buf_len = sizeof(struct air_cfg_rsp) * 4; + struct atminfreq air; + + /* + * Initialize IOCTL request + */ + air.air_opcode = AIOCS_INF_CFG; + UM_ZERO ( air.air_cfg_intf, sizeof(air.air_cfg_intf)); + if ( intf != NULL && strlen(intf) != 0 ) + strcpy ( air.air_cfg_intf, intf ); + + buf_len = do_info_ioctl ( &air, buf_len ); + + /* + * Return a pointer to the Config info and its length + */ + *cfgp = (struct air_cfg_rsp *) air.air_buf_addr; + return ( buf_len ); + +} + +/* + * Get Physical Interface information + * + * Arguments: + * intf pointer to interface name (or null string) + * intp pointer to a pointer to a struct air_cfg_rsp for the + * address of the returned Config information + * + * Returns: + * int length of returned Config information + * + */ +int +get_intf_info ( intf, intp ) + char *intf; + struct air_int_rsp **intp; +{ + int buf_len = sizeof(struct air_int_rsp) * 4; + struct atminfreq air; + + /* + * Initialize IOCTL request + */ + air.air_opcode = AIOCS_INF_INT; + UM_ZERO ( air.air_int_intf, sizeof(air.air_int_intf)); + if ( intf != NULL && strlen(intf) != 0 ) + strcpy ( air.air_int_intf, intf ); + + buf_len = do_info_ioctl ( &air, buf_len ); + + /* + * Return a pointer to the Physical Interface info and its length + */ + *intp = (struct air_int_rsp *) air.air_buf_addr; + return ( buf_len ); + +} + + +/* + * Get Netif information + * + * Arguments: + * intf pointer to interface name (or null string) + * netp pointer to a pointer to a struct air_netif_rsp for the + * address of the returned Netif information + * + * Returns: + * int length of returned Netif information + * + */ +int +get_netif_info ( intf, netp ) + char *intf; + struct air_netif_rsp **netp; +{ + int buf_len = sizeof(struct air_netif_rsp) * 10; + struct atminfreq air; + + /* + * Initialize IOCTL request + */ + air.air_opcode = AIOCS_INF_NIF; + UM_ZERO ( air.air_int_intf, sizeof(air.air_int_intf) ); + if ( intf != NULL && strlen(intf) != 0 ) + strcpy ( air.air_int_intf, intf ); + + buf_len = do_info_ioctl ( &air, buf_len ); + + /* + * Return a pointer to the Netif info and its length + */ + *netp = (struct air_netif_rsp *) air.air_buf_addr; + return ( buf_len ); + +} + + diff --git a/lib/libatm/ip_addr.c b/lib/libatm/ip_addr.c new file mode 100644 index 0000000..aee3368 --- /dev/null +++ b/lib/libatm/ip_addr.c @@ -0,0 +1,167 @@ +/* + * + * =================================== + * HARP | Host ATM Research Platform + * =================================== + * + * + * This Host ATM Research Platform ("HARP") file (the "Software") is + * made available by Network Computing Services, Inc. ("NetworkCS") + * "AS IS". NetworkCS does not provide maintenance, improvements or + * support of any kind. + * + * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED, + * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE + * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE. + * In no event shall NetworkCS be responsible for any damages, including + * but not limited to consequential damages, arising from or relating to + * any use of the Software or related support. + * + * Copyright 1994-1998 Network Computing Services, Inc. + * + * Copies of this Software may be made, however, the above copyright + * notice must be reproduced on all copies. + * + * @(#) $Id: ip_addr.c,v 1.1 1998/07/09 21:45:42 johnc Exp $ + * + */ + +/* + * User Space Library Functions + * ---------------------------- + * + * IP address utilities + * + */ + +#ifndef lint +static char *RCSid = "@(#) $Id: ip_addr.c,v 1.1 1998/07/09 21:45:42 johnc Exp $"; +#endif + +#include <sys/types.h> +#include <sys/param.h> + +#include <netdb.h> +#include <sys/socket.h> +#include <net/if.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <netatm/port.h> +#include <netatm/atm.h> +#include <netatm/atm_if.h> +#include <netatm/atm_sap.h> +#include <netatm/atm_sys.h> +#include <netatm/atm_ioctl.h> + +#include "libatm.h" + + +/* + * Get IP address + * + * Return an IP address in a socket address structure, given a character + * string with a domain name or a dotted decimal number. + * + * Arguments: + * p pointer to a host name or IP address + * + * Returns: + * null error was encountered + * struct sockaddr_in * a pointer to a socket address with the + * requested IP address + * + */ +struct sockaddr_in * +get_ip_addr(p) + char *p; +{ + struct hostent *ip_host; + static struct sockaddr_in sin; + + /* + * Get IP address of specified host name + */ + UM_ZERO(&sin, sizeof(sin)); + sin.sin_family = AF_INET; + if (p[0] >= '0' && p[0] <= '9') { + /* + * IP address is in dotted decimal format + */ + if ((sin.sin_addr.s_addr = inet_addr(p)) == -1) { + return((struct sockaddr_in *)0); + } + } else { + /* + * Host name is in domain name system format + */ + ip_host = gethostbyname(p); + if (!ip_host || + ip_host->h_addrtype != AF_INET) { + return((struct sockaddr_in *)0); + } + sin.sin_addr.s_addr = *(u_long *)ip_host->h_addr_list[0]; + } + return(&sin); +} + + +/* + * Format an IP address + * + * Return a text-formatted string with an IP address and domain name + * given a sockaddr_in with an IP address. + * + * Arguments: + * p pointer to sockaddr_in with an IP address + * + * Returns: + * char * pointer to a text-formatted string + * + */ +char * +format_ip_addr(addr) + struct in_addr *addr; +{ + static char host_name[128]; + char *ip_num; + struct hostent *ip_host; + + /* + * Initialize + */ + UM_ZERO(host_name, sizeof(host_name)); + + /* + * Check for a zero address + */ + if (!addr || addr->s_addr == 0) { + return("-"); + } + + /* + * Get address in dotted decimal format + */ + ip_num = inet_ntoa(*addr); + + /* + * Look up name in DNS + */ + ip_host = gethostbyaddr((char *)addr, sizeof(addr), AF_INET); + if (ip_host && ip_host->h_name && + strlen(ip_host->h_name)) { + /* + * Return host name followed by dotted decimal address + */ + strcpy(host_name, ip_host->h_name); + strcat(host_name, " ("); + strcat(host_name, ip_num); + strcat(host_name, ")"); + return(host_name); + } else { + /* + * No host name -- just return dotted decimal address + */ + return(ip_num); + } +} diff --git a/lib/libatm/ip_checksum.c b/lib/libatm/ip_checksum.c new file mode 100644 index 0000000..478f6ca --- /dev/null +++ b/lib/libatm/ip_checksum.c @@ -0,0 +1,102 @@ +/* + * + * =================================== + * HARP | Host ATM Research Platform + * =================================== + * + * + * This Host ATM Research Platform ("HARP") file (the "Software") is + * made available by Network Computing Services, Inc. ("NetworkCS") + * "AS IS". NetworkCS does not provide maintenance, improvements or + * support of any kind. + * + * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED, + * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE + * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE. + * In no event shall NetworkCS be responsible for any damages, including + * but not limited to consequential damages, arising from or relating to + * any use of the Software or related support. + * + * Copyright 1994-1998 Network Computing Services, Inc. + * + * Copies of this Software may be made, however, the above copyright + * notice must be reproduced on all copies. + * + * @(#) $Id: ip_checksum.c,v 1.4 1998/08/11 18:11:48 johnc Exp $ + * + */ + + +/* + * User Space Library Functions + * ---------------------------- + * + * IP checksum computation + * + */ + + +#ifndef lint +static char *RCSid = "@(#) $Id: ip_checksum.c,v 1.4 1998/08/11 18:11:48 johnc Exp $"; +#endif + +#include <sys/types.h> +#include <sys/param.h> + +#include <sys/socket.h> +#include <net/if.h> +#include <netinet/in.h> +#include <netatm/port.h> +#include <netatm/atm.h> +#include <netatm/atm_if.h> +#include <netatm/atm_sap.h> +#include <netatm/atm_sys.h> +#include <netatm/atm_ioctl.h> + +#include "libatm.h" + + +/* + * Compute an IP checksum + * + * This code was taken from RFC 1071. + * + * "The following "C" code algorithm computes the checksum with an inner + * loop that sums 16 bits at a time in a 32-bit accumulator." + * + * Arguments: + * addr pointer to the buffer whose checksum is to be computed + * count number of bytes to include in the checksum + * + * Returns: + * the computed checksum + * + */ +short +ip_checksum(addr, count) + char *addr; + int count; +{ + /* Compute Internet Checksum for "count" bytes + * beginning at location "addr". + */ + register long sum = 0; + + while( count > 1 ) { + /* This is the inner loop */ + sum += ntohs(* (unsigned short *) addr); + addr += sizeof(unsigned short); + count -= sizeof(unsigned short); + } + + /* Add left-over byte, if any */ + if( count > 0 ) + sum += * (unsigned char *) addr; + + /* Fold 32-bit sum to 16 bits */ + while (sum>>16) + sum = (sum & 0xffff) + (sum >> 16); + + return((short)~sum); +} diff --git a/lib/libatm/libatm.h b/lib/libatm/libatm.h new file mode 100644 index 0000000..3462431 --- /dev/null +++ b/lib/libatm/libatm.h @@ -0,0 +1,118 @@ +/* + * + * =================================== + * HARP | Host ATM Research Platform + * =================================== + * + * + * This Host ATM Research Platform ("HARP") file (the "Software") is + * made available by Network Computing Services, Inc. ("NetworkCS") + * "AS IS". NetworkCS does not provide maintenance, improvements or + * support of any kind. + * + * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED, + * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE + * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE. + * In no event shall NetworkCS be responsible for any damages, including + * but not limited to consequential damages, arising from or relating to + * any use of the Software or related support. + * + * Copyright 1994-1998 Network Computing Services, Inc. + * + * Copies of this Software may be made, however, the above copyright + * notice must be reproduced on all copies. + * + * @(#) $Id: libatm.h,v 1.5 1998/08/06 16:56:27 johnc Exp $ + * + */ + +/* + * User Space Library Functions + * ---------------------------- + * + * Library functions + * + */ + +#ifndef _HARP_LIBHARP_H +#define _HARP_LIBHARP_H + +/* + * Start a HARP user-space timer + * + * tp pointer to timer control block + * time number of seconds for timer to run + * fp pointer to function to call at expiration + */ +#define HARP_TIMER(tp, time, fp) \ +{ \ + (tp)->ht_ticks = (time); \ + (tp)->ht_mark = 0; \ + (tp)->ht_func = (fp); \ + LINK2HEAD((tp), Harp_timer, harp_timer_head, ht_next); \ +} + +/* + * Cancel a HARP user-space timer + * + * tp pointer to timer control block + */ +#define HARP_CANCEL(tp) \ +{ \ + UNLINK((tp), Harp_timer, harp_timer_head, ht_next); \ +} + + +/* + * HARP user-space timer control block + */ +struct harp_timer { + struct harp_timer *ht_next; /* Timer chain */ + int ht_ticks; /* Seconds till exp */ + int ht_mark; /* Processing flag */ + void (*ht_func)(); /* Function to call */ +}; +typedef struct harp_timer Harp_timer; + + +/* + * Externally-visible variables and functions + */ + +/* atm_addr.c */ +extern int get_hex_atm_addr __P((char *, u_char *, int)); +extern char *format_atm_addr __P((Atm_addr *)); + +/* cache_key.c */ +extern void scsp_cache_key __P((Atm_addr *, + struct in_addr *, int, char *)); + +/* ioctl_subr.c */ +extern int do_info_ioctl __P((struct atminfreq *, int)); +extern int get_vcc_info __P((char *, + struct air_vcc_rsp **)); +extern int get_subnet_mask __P((char *, + struct sockaddr_in *)); +extern int get_mtu __P((char *)); +extern int verify_nif_name __P((char *)); +extern int get_cfg_info __P((char *, + struct air_cfg_rsp **)); + +/* ip_addr.c */ +extern struct sockaddr_in *get_ip_addr __P((char *)); +extern char *format_ip_addr __P((struct in_addr *)); + +/* ip_checksum.c */ +extern short ip_checksum __P((char *, int)); + +/* timer.c */ +extern Harp_timer *harp_timer_head; +extern int harp_timer_exec; +extern void timer_proc __P(()); +extern int init_timer __P(()); +extern int block_timer __P(()); +extern void enable_timer __P((int)); + + +#endif /* _HARP_LIBHARP_H */ diff --git a/lib/libatm/timer.c b/lib/libatm/timer.c new file mode 100644 index 0000000..fc8b64f --- /dev/null +++ b/lib/libatm/timer.c @@ -0,0 +1,261 @@ +/* + * + * =================================== + * HARP | Host ATM Research Platform + * =================================== + * + * + * This Host ATM Research Platform ("HARP") file (the "Software") is + * made available by Network Computing Services, Inc. ("NetworkCS") + * "AS IS". NetworkCS does not provide maintenance, improvements or + * support of any kind. + * + * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED, + * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE + * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE. + * In no event shall NetworkCS be responsible for any damages, including + * but not limited to consequential damages, arising from or relating to + * any use of the Software or related support. + * + * Copyright 1994-1998 Network Computing Services, Inc. + * + * Copies of this Software may be made, however, the above copyright + * notice must be reproduced on all copies. + * + * @(#) $Id: timer.c,v 1.4 1998/07/16 15:50:26 johnc Exp $ + * + */ + +/* + * User Space Library Functions + * ---------------------------- + * + * Timer functions + * + */ + +#ifndef lint +static char *RCSid = "@(#) $Id: timer.c,v 1.4 1998/07/16 15:50:26 johnc Exp $"; +#endif + +#include <sys/types.h> +#include <sys/param.h> + +#include <errno.h> +#include <sys/socket.h> +#include <net/if.h> +#include <netinet/in.h> +#include <netatm/port.h> +#include <netatm/queue.h> +#include <netatm/atm.h> +#include <netatm/atm_if.h> +#include <netatm/atm_sap.h> +#include <netatm/atm_sys.h> +#include <netatm/atm_ioctl.h> + +#include "libatm.h" + +Harp_timer *harp_timer_head; +int harp_timer_exec; + + +/* + * Process a HARP timer tick + * + * This function is called via the SIGALRM signal. It increments + * harp_timer_exec. The user should check this flag frequently and + * call timer_proc when it is set. + * + * Arguments: + * None + * + * Returns: + * None + * + */ +static void +timer_tick() +{ + /* + * Bump the timer flag + */ + harp_timer_exec++; +} + + +/* + * Process HARP timers + * + * This function is called after a SIGALRM signal is posted. It runs + * down the list of timer entries, calling the specified functions + * for any timers that have expired. + * + * Arguments: + * None + * + * Returns: + * None + * + */ +void +timer_proc() +{ + Harp_timer *htp; + void (*f)(); + + /* + * Reset marks in all timers on the queue + */ + for (htp = harp_timer_head; htp; htp = htp->ht_next) { + htp->ht_mark = -1; + } + + /* + * Run through timer chain decrementing each timer. + * If an expired timer is found, take the timer block + * off the chain and call the specified function. A + * timer's action can result in other timers being + * cancelled (taken off the queue), so every time we + * call a user function, we start over from the top of + * the list. + */ +timer_cont: + for (htp = harp_timer_head; htp; htp = htp->ht_next) { + /* + * Make sure we only process each entry once and + * don't process entries that are put on the queue + * by user functions we call for this tick + */ + if (htp->ht_mark == -1) { + /* + * Decrement the timer and mark that we've + * processed the entry + */ + htp->ht_ticks -= harp_timer_exec; + htp->ht_mark = 1; + + /* + * Check whether the timer is expired + */ + if (htp->ht_ticks <= 0) { + /* + * Unlink the timer block and call + * the user function + */ + f = htp->ht_func; + UNLINK(htp, Harp_timer, harp_timer_head, + ht_next); + f(htp); + + /* + * Start over + */ + goto timer_cont; + } + } + } + + /* + * Reset the timer exec flag + */ + harp_timer_exec = 0; +} + + +/* + * Start the timer + * + * Set up the SIGALRM signal handler and set up the real-time + * timer to tick once per second. + * + * Arguments: + * None + * + * Returns: + * 0 success + * errno reason for failure + * + */ +int +init_timer() +{ + int rc = 0; + struct itimerval timeval; + + /* + * Clear the timer flag + */ + harp_timer_exec = 0; + + /* + * Set up signal handler + */ + if ((int)signal(SIGALRM, timer_tick) == -1) { + return(errno); + } + + /* + * Start timer + */ + timeval.it_value.tv_sec = 1; + timeval.it_value.tv_usec = 0; + timeval.it_interval.tv_sec = 1; + timeval.it_interval.tv_usec = 0; + + if (setitimer(ITIMER_REAL, &timeval, + (struct itimerval *)0) == -1) { + rc = errno; + (void)signal(SIGALRM, SIG_DFL); + } + + return(rc); +} + + +/* + * Block timers from firing + * + * Block the SIGALRM signal. + * + * Arguments: + * None + * + * Returns: + * mask the previous blocked signal mask + * + */ +int +block_timer() +{ + /* + * Block the SIGALRM signal + */ + return(sigblock(sigmask(SIGALRM))); +} + + +/* + * Re-enable timers + * + * Restore the signal mask (presumably one that was returned by + * block_timer). + * + * Arguments: + * mask the signal mask to be restored + * + * Returns: + * mask the previous blocked signal mask + * + */ +void +enable_timer(mask) + int mask; +{ + /* + * Set the signal mask + */ + sigsetmask(mask); + + return; +} |