original files of m241
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
#################################################################
|
||||
#
|
||||
# Makefile for building WMSNMP
|
||||
#
|
||||
# This makefile implements a simplified build system for building
|
||||
# WindManageSNMP for Wind River Platforms.
|
||||
#
|
||||
# Author: Tim Neale
|
||||
# Date: Aug. 30, 2002
|
||||
#
|
||||
# Revision History:
|
||||
# Nov 29 2016 Support openssl-1_0_1 for fixing VXW6-85952
|
||||
# Sep 23 2002 Changed name from makefile to Makefile
|
||||
# Added script for modifying ADDED_CFLAGS
|
||||
# 16-Jul-2003 pservita reworked to avoid unecessary rebuilds
|
||||
#
|
||||
#################################################################
|
||||
|
||||
ifeq (,$(CPU))
|
||||
CPU=none
|
||||
endif
|
||||
|
||||
ifeq (,$(TOOL))
|
||||
TOOL=gnu
|
||||
endif
|
||||
|
||||
|
||||
|
||||
ifeq (,$(SNMPV3))
|
||||
SNMPV3=OFF
|
||||
endif
|
||||
|
||||
ifeq (,$(AGENTX))
|
||||
AGENTX=OFF
|
||||
endif
|
||||
|
||||
ifeq (,$(SNMP_CONFIG))
|
||||
SNMP_CONFIG=NONE
|
||||
endif
|
||||
|
||||
ifeq (,$(SNMP_IPV6))
|
||||
SNMP_IPV6=OFF
|
||||
endif
|
||||
ifeq (,$(SNMP_IPV4))
|
||||
SNMP_IPV4=OFF
|
||||
endif
|
||||
|
||||
SNMP_VSTACK=OFF
|
||||
|
||||
ifeq (USER,$(SPACE))
|
||||
SNMP_BUILD_TARGET=snmp_rtp
|
||||
SNMP_CLEAN_TARGET=rclean_rtp
|
||||
RTP_BUILD_MODE=RTP
|
||||
AGENTX=ON
|
||||
else
|
||||
ifeq (user,$(SPACE))
|
||||
SNMP_BUILD_TARGET=snmp_rtp
|
||||
SNMP_CLEAN_TARGET=rclean_rtp
|
||||
RTP_BUILD_MODE=RTP
|
||||
AGENTX=ON
|
||||
else
|
||||
TGT_DIR = $(WIND_BASE)/target
|
||||
include $(TGT_DIR)/h/make/defs.library
|
||||
ifdef _WRS_CONFIG_COMPONENT_SNMP
|
||||
SNMP_BUILD_TARGET=snmp
|
||||
SNMP_CLEAN_TARGET=rclean_kernel
|
||||
|
||||
ifdef _WRS_CONFIG_FEATURE_IPNET_INET6
|
||||
SNMP_IPV6=ON
|
||||
SNMP_IPV4=ON
|
||||
endif
|
||||
ifdef _WRS_CONFIG_FEATURE_IPNET_INET6_ONLY
|
||||
SNMP_IPV6=ON
|
||||
SNMP_IPV4=OFF
|
||||
endif
|
||||
ifdef _WRS_CONFIG_FEATURE_IPNET_INET4_ONLY
|
||||
SNMP_IPV6=OFF
|
||||
SNMP_IPV4=ON
|
||||
endif
|
||||
ifdef _WRS_CONFIG_FEATURE_SNMP_V3
|
||||
SNMPV3=ON
|
||||
endif
|
||||
ifdef _WRS_CONFIG_FEATURE_SNMP_AGENTX
|
||||
AGENTX=ON
|
||||
endif
|
||||
else
|
||||
#SNMP_BUILD_TARGET=rclean_kernel
|
||||
#SNMP_CLEAN_TARGET=rclean_kernel
|
||||
endif
|
||||
BUILD_MODE=KERNEL
|
||||
endif
|
||||
endif
|
||||
|
||||
CONFIG_FILE=snmp.cfg
|
||||
|
||||
|
||||
WIND_BASE := $(subst \,/,$(WIND_BASE))
|
||||
TGT_DIR := $(WIND_BASE)/target
|
||||
|
||||
|
||||
ifneq (,$(findstring solaris,$(WIND_HOST_TYPE)))
|
||||
TOUCH = touch
|
||||
MAKMAK = makmak
|
||||
RUN_MAKMAK = $(MAKMAK) $(CONFIG_FILE)
|
||||
OUTPUT_CFG = $(WIND_BASE)/target/src/wrn/wm/$(CONFIG_FILE)
|
||||
RTP_OUTPUT_CFG = $(WIND_BASE)/target/src/wrn/wm/$(CONFIG_FILE)
|
||||
CFG_BUILD_TAG = $(WIND_BASE)/target/src/wrn/wm/snmp_build.tag
|
||||
else
|
||||
ifneq (,$(findstring linux,$(WIND_HOST_TYPE)))
|
||||
TOUCH = touch
|
||||
MAKMAK = makmak
|
||||
RUN_MAKMAK = $(MAKMAK) $(CONFIG_FILE)
|
||||
OUTPUT_CFG = $(WIND_BASE)/target/src/wrn/wm/$(CONFIG_FILE)
|
||||
RTP_OUTPUT_CFG = $(WIND_BASE)/target/src/wrn/wm/$(CONFIG_FILE)
|
||||
CFG_BUILD_TAG = $(WIND_BASE)/target/src/wrn/wm/snmp_build.tag
|
||||
else
|
||||
ifneq (,$(findstring win32,$(WIND_HOST_TYPE)))
|
||||
TOUCH = echo.>
|
||||
MAKMAK = makmak
|
||||
RUN_MAKMAK = $(MAKMAK) $(CONFIG_FILE)
|
||||
OUTPUT_CFG = $(WIND_BASE)\target\src\wrn\wm\$(CONFIG_FILE)
|
||||
RTP_OUTPUT_CFG = $(WIND_BASE)\target\src\wrn\wm\$(CONFIG_FILE)
|
||||
CFG_BUILD_TAG = $(WIND_BASE)\target\src\wrn\wm\snmp_build.tag
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
include $(VSB_DIR)/h/config/auto.conf
|
||||
|
||||
ifeq ($(_WRS_CONFIG_COMPONENT_IPCRYPTO_OPENSSL_1_0_1),y)
|
||||
SNMP_TEMP_INCLUDES = ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcrypto/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcrypto/config ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcrypto/openssl-1_0_1/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipssl2/openssl-1_0_1/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipssl2/openssl-1_0_1/ssl ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/config ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/port/vxworks/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/port/vxworks/config
|
||||
endif
|
||||
|
||||
ifeq ($(_WRS_CONFIG_COMPONENT_IPCRYPTO_OPENSSL_1_0_2),y)
|
||||
SNMP_TEMP_INCLUDES = ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcrypto/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcrypto/config ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcrypto/openssl-1_0_2/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipssl2/openssl-1_0_2/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipssl2/openssl-1_0_2/ssl ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/config ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/port/vxworks/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/port/vxworks/config
|
||||
endif
|
||||
|
||||
ifeq ($(_WRS_CONFIG_COMPONENT_IPCRYPTO_OPENSSL_0_9_8),y)
|
||||
SNMP_TEMP_INCLUDES = ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcrypto/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcrypto/config ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcrypto/openssl-0_9_8/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipssl2/openssl-0_9_8/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipssl2/openssl-0_9_8/ssl ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/config ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/port/vxworks/include ADDED_CFLAGS+=-I$(WRVX_COMPBASE)/$(COMP_IPNET2)/ipcom/port/vxworks/config
|
||||
endif
|
||||
|
||||
default: $(SNMP_BUILD_TARGET)
|
||||
|
||||
snmp:snmp_build_and_install
|
||||
|
||||
snmp_tag_this_build:
|
||||
rm -f $(CFG_BUILD_TAG)
|
||||
cp $(OUTPUT_CFG) $(CFG_BUILD_TAG)
|
||||
|
||||
snmp_tag_this_rtp_build:
|
||||
rm -f $(CFG_BUILD_TAG)
|
||||
cp $(RTP_OUTPUT_CFG) $(CFG_BUILD_TAG)
|
||||
|
||||
snmp_makefiles:
|
||||
sh getcfg.sh $(CPU) $(TOOL) $(SNMPV3) $(AGENTX) $(CONFIG_FILE) $(SNMP_CONFIG) $(SNMP_IPV6) $(SNMP_VSTACK) $(BUILD_MODE) $(SNMP_IPV4)
|
||||
sh snmp_run_makmak.sh $(WIND_BASE) $(CPU) $(TOOL) $(OUTPUT_CFG) $(CFG_BUILD_TAG)
|
||||
sh chflags.sh
|
||||
rm -f $(CFG_BUILD_TAG)
|
||||
|
||||
snmp_build_and_install:
|
||||
make CPU=$(CPU) TOOL=$(TOOL) $(SNMP_TEMP_INCLUDES) -C snmp all
|
||||
|
||||
ifndef _WRS_CONFIG_LP64
|
||||
snmp_rtp: snmp_build_and_install_rtp
|
||||
else
|
||||
snmp_rtp:
|
||||
endif
|
||||
|
||||
snmp_build_and_install_rtp:
|
||||
make CPU=$(CPU) TOOL=$(TOOL) $(SNMP_TEMP_INCLUDES) SPACE=user -C snmp/engine
|
||||
make CPU=$(CPU) TOOL=$(TOOL) $(SNMP_TEMP_INCLUDES) SPACE=user -C common/desreal
|
||||
make CPU=$(CPU) TOOL=$(TOOL) $(SNMP_TEMP_INCLUDES) SPACE=user -C common/lib
|
||||
|
||||
rclean: $(SNMP_CLEAN_TARGET)
|
||||
|
||||
rclean_kernel:
|
||||
make CPU=$(CPU) TOOL=$(TOOL) $(SNMP_TEMP_INCLUDES) -C snmp clean
|
||||
|
||||
rclean_rtp:
|
||||
make CPU=$(CPU) TOOL=$(TOOL) $(SNMP_TEMP_INCLUDES) SPACE=user -C snmp/engine clean
|
||||
make CPU=$(CPU) TOOL=$(TOOL) $(SNMP_TEMP_INCLUDES) SPACE=user -C common/desreal clean
|
||||
make CPU=$(CPU) TOOL=$(TOOL) $(SNMP_TEMP_INCLUDES) SPACE=user -C common/lib clean
|
||||
|
||||
man:
|
||||
make -C snmp/engine man
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
###############################################################################
|
||||
#
|
||||
# Main script starts here
|
||||
#
|
||||
# This script manipulates the top-level makefile for WMSNMP
|
||||
# This is needed for WMSNMP for Wind River Platforms to overcome
|
||||
# a conflict in the definition of "ADDED_CFLAGS"
|
||||
#
|
||||
# Author: Tim Neale
|
||||
# Date: Sep 23, 2002
|
||||
#
|
||||
# Revision History:
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
|
||||
PROGNAME="chflags.sh"
|
||||
echo "Running ${PROGNAME}"
|
||||
|
||||
#
|
||||
# Create sed command file:
|
||||
#
|
||||
rm -f sed.cmds
|
||||
touch sed.cmds
|
||||
|
||||
CHANGE_FLAGS="s/ADDED_CFLAGS =/override ADDED_CFLAGS +=/g"
|
||||
CHANGE_MAKE='s/$(MAKE) -C/$(MAKE) ADDED_CFLAGS="$(ADDED_CFLAGS)" -C/g'
|
||||
echo ${CHANGE_FLAGS} >> sed.cmds
|
||||
echo ${CHANGE_MAKE} >> sed.cmds
|
||||
sed -f sed.cmds ${WIND_BASE}/target/src/wrn/wm/makefile.wmsnmp > makefile.tmp
|
||||
if [ -f makefile.tmp ]; then
|
||||
mv makefile.tmp ${WIND_BASE}/target/src/wrn/wm/makefile.wmsnmp
|
||||
else
|
||||
echo "Unable to modify makefile to allow ADDED_CFLAGS."
|
||||
rm -f sed.cmds
|
||||
exit 255
|
||||
fi
|
||||
rm -f sed.cmds
|
||||
exit 0
|
||||
@@ -0,0 +1,58 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/backstop/common.h,v 1.1.1.1 2001/11/05 17:48:38 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: common.h,v $
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:38 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.5 2001/01/19 22:21:24 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.4 2000/03/17 00:16:12 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.3 1998/02/25 04:43:22 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.2 1998/02/05 22:01:27 josh
|
||||
* moved top-level backstop include files into common/backstop
|
||||
*
|
||||
* Revision 1.1 1997/08/21 17:23:40 sra
|
||||
* Begin moving configuration stuff that's common to all products to common.h
|
||||
* Minor cleanups to common/lib/prng.c. Add pnrg seed function to snarkbsd.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,20apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Backstop common.h.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_PREAMBLE
|
||||
|
||||
#else /* CONFIG_PREAMBLE */
|
||||
|
||||
#endif /* CONFIG_PREAMBLE */
|
||||
@@ -0,0 +1,63 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/backstop/oemtypes.h,v 1.1.1.1 2001/11/05 17:48:38 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Backstop type definitions file. Just gets size_t from the standard place.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: oemtypes.h,v $
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:38 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.4 2001/01/19 22:21:24 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.3 2000/03/17 00:16:12 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.2 1998/02/25 04:43:23 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.1 1998/02/05 22:01:28 josh
|
||||
* moved top-level backstop include files into common/backstop
|
||||
*
|
||||
* Revision 1.3 1997/03/20 06:58:18 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 1.2 1997/02/25 10:57:29 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 1.1 1993/06/17 16:21:50 dab
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,20apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* The now standard place to find size_t's definition.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
@@ -0,0 +1,48 @@
|
||||
;;; $Header: /usr/cvsroot/target/src/wrn/wm/common/common.cfg,v 1.2 2003/01/16 18:18:52 josh Exp $
|
||||
|
||||
;;; The standard configuration for Epilogue common code.
|
||||
;;;
|
||||
;;; Don't modify this file. If you want to change any of these values,
|
||||
;;; do so by putting overriding definitions into your main config file.
|
||||
|
||||
|
||||
;;; Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
;;; Copyright 1998 Integrated Systems, Inc.
|
||||
;;; All rights reserved.
|
||||
|
||||
;;; Copyright (C) 1999-2004 Wind River Systems, Inc.
|
||||
;;; All rights reserved. Provided under license only.
|
||||
;;; Distribution or other use of this software is only
|
||||
;;; permitted pursuant to the terms of a license agreement
|
||||
;;; from Wind River Systems (and is otherwise prohibited).
|
||||
;;; Refer to that license agreement for terms of use.
|
||||
|
||||
|
||||
|
||||
;;; enabled by default, uninstall in the OEM's config file if not wanted
|
||||
install COMMON
|
||||
install COMMON_FIXED64
|
||||
|
||||
;;; disabled by default, install in the OEM's config file if wanted
|
||||
uninstall COMMON_PRNG
|
||||
uninstall COMMON_MD4
|
||||
uninstall COMMON_MD5
|
||||
uninstall COMMON_SHA
|
||||
uninstall COMMON_HMAC
|
||||
uninstall COMMON_DES
|
||||
uninstall COMMON_3DES
|
||||
uninstall COMMON_ESP_3DES
|
||||
uninstall COMMON_DES_TEST
|
||||
uninstall COMMON_DES_FAKE
|
||||
|
||||
;;; string functions in case they aren't available on the system
|
||||
uninstall COMMON_STRTOL
|
||||
uninstall COMMON_STRTOUL
|
||||
uninstall COMMON_STRICMP
|
||||
uninstall COMMON_STRNICMP
|
||||
uninstall COMMON_MEMCMP
|
||||
uninstall COMMON_SNPRINTF
|
||||
|
||||
uninstall COMMON_DYNAMIC_COMP_CONFIG
|
||||
|
||||
;;; must be defined one way or the other, needs no further attention
|
||||
@@ -0,0 +1,156 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/desfake/desfake.c,v 1.3 2003/01/16 18:18:52 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: desfake.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:52 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 21:52:00 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:38 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.3 2001/01/19 22:21:25 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.2 2000/03/17 00:16:16 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.1 1998/06/23 21:17:09 josh
|
||||
* Building a fake DES library. All the cool entry points, no nasty
|
||||
* export-controlled code.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,20apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/des.h>
|
||||
|
||||
int Asmversion = 0;
|
||||
|
||||
/* Encrypt or decrypt a block of data in ECB mode */
|
||||
void des (DES_KS ks, bits8_t *block, bits8_t *out)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
/* Encrypt or decrypt a block of data in ECB mode */
|
||||
void des3(DES3_KS ks, bits8_t *block, bits8_t *out)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
void deskey (DES_KS k, bits8_t *key, int decrypt)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
#if INSTALL_COMMON_3DES
|
||||
|
||||
void des3key (DES3_KS k, bits8_t *key, int decrypt)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
#endif /* INSTALL_COMMON_3DES */
|
||||
|
||||
void desecb_block_encrypt (DES_CTX *ctx, bits8_t *in, bits8_t *out)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
void descbc_block_encrypt (DES_CTX *ctx, bits8_t *in, bits8_t *out)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
void descbc_block_decrypt (DES_CTX *ctx, bits8_t *in, bits8_t *out)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
#if INSTALL_COMMON_ESP_3DES
|
||||
void des3ecb_block_encrypt (DES3_CTX *ctx, bits8_t *in, bits8_t *out)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
void des3cbc_block_encrypt (DES3_CTX *ctx, bits8_t *in, bits8_t *out)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
void des3cbc_block_decrypt (DES3_CTX *ctx, bits8_t *in, bits8_t *out)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
#endif /* INSTALL_COMMON_ESP_3DES */
|
||||
|
||||
/* algtable context glue */
|
||||
|
||||
void descbc_init_context (void *ctx, bits8_t *key, int decrypt)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
void descbc_iv_context (void *ctx, bits8_t *iv)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
void descbc_crypt (void *ctx, bits8_t *in, bits8_t *out, bits32_t n)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
#if INSTALL_COMMON_ESP_3DES
|
||||
|
||||
void des3cbc_init_context (void *ctx, bits8_t *key, int decrypt)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
void des3cbc_iv_context (void *ctx, bits8_t *iv)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
void des3cbc_crypt (void *ctx, bits8_t *in, bits8_t *out, bits32_t n)
|
||||
{
|
||||
/* Do nothing...just a dummy routine. */
|
||||
}
|
||||
|
||||
#endif /* INSTALL_COMMON_ESP_3DES */
|
||||
|
||||
/* A function to determine whether we're actually getting DES-style
|
||||
* encryption instead of just dummy routines.
|
||||
* Returns: 1 if real DES, 0 if dummy DES.
|
||||
*/
|
||||
|
||||
int des_is_real()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
#
|
||||
# Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
# All rights reserved. Provided under license only.
|
||||
# Distribution or other use of this software is only
|
||||
# permitted pursuant to the terms of a license agreement
|
||||
# from Wind River Systems (and is otherwise prohibited).
|
||||
# Refer to that license agreement for terms of use.
|
||||
#
|
||||
|
||||
# [clearcase]
|
||||
# modification history
|
||||
# -------------------
|
||||
# 01a,20apr05,job update copyright notices
|
||||
#
|
||||
|
||||
#
|
||||
# common/lib
|
||||
#
|
||||
|
||||
$#equate(PRODUCTH $#filepath($(SRCDIR) target h wrn wm common))
|
||||
|
||||
$#makefile-init()
|
||||
|
||||
##############################################################################
|
||||
# OBJECT FILE DEFINITION SECTION
|
||||
|
||||
$#equate(DES_OBJS $#objs(desfake))
|
||||
|
||||
all: des.tag $#filepath($(SRCDIR) target src wrn wm common lib $#libs(epdes)) $#dummy()
|
||||
|
||||
##############################################################################
|
||||
# Make the library itself
|
||||
|
||||
des.tag: $(MAKEFILENAME) $#dummy()
|
||||
-$(RM) $#filepath($(SRCDIR) target src wrn wm common lib $#libs(epdes))
|
||||
$(TOUCH) des.tag
|
||||
|
||||
$#makelib-nodel($#filepath($(SRCDIR) target src wrn wm common lib) epdes $#(DES_OBJS) $(MAKEFILENAME))
|
||||
|
||||
##############################################################################
|
||||
# commands to figure out how big this all compiles to
|
||||
|
||||
sizes: $#dummy()
|
||||
$#makesize(DES $(DES_OBJS))
|
||||
|
||||
clean: $#dummy()
|
||||
-$(RM) $#objs(*)
|
||||
-$(RM) des.tag
|
||||
-$(RM) epdes.tag
|
||||
-$(RM) $#filepath($(SRCDIR) target src wrn wm common lib $#libs(epdes))
|
||||
$#clean()
|
||||
|
||||
##############################################################################
|
||||
# file dependencies
|
||||
|
||||
$#objs(desfake) : desfake.c $(SRCDIR)/target/h/wrn/wm/common/des.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/config.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/install.h
|
||||
@@ -0,0 +1,66 @@
|
||||
#
|
||||
# Copyright (C) 2013 Wind River Systems, Inc.
|
||||
# All rights reserved. Provided under license only.
|
||||
# Distribution or other use of this software is only
|
||||
# permitted pursuant to the terms of a license agreement
|
||||
# from Wind River Systems (and is otherwise prohibited).
|
||||
# Refer to that license agreement for terms of use.
|
||||
#
|
||||
|
||||
# Revision history
|
||||
# -------------------
|
||||
# 01c,31jan13,bbz create this file
|
||||
#
|
||||
#
|
||||
# common/lib
|
||||
#
|
||||
OEM=
|
||||
SOFTPORT=$(SRCDIR)/target/usr/h/wrn/wm/util/port/vxworks
|
||||
HARDPORT=
|
||||
SRCDIR=$(WIND_BASE)
|
||||
XCFLAGS=
|
||||
EXTRA_PRODUCTS=
|
||||
WMSNMP_ADDED_OBJS=
|
||||
WMSNMP_ADDED_MIBS=
|
||||
MIBCOMPILER=mibcomp
|
||||
TOUCH=touch
|
||||
MAKEFILENAME=makefile.wmsnmp
|
||||
CLEAN_LIST=
|
||||
ETC_INI_FILES=etc.ini
|
||||
TGT_DIR=$(WIND_BASE)/target
|
||||
WMINC=$(SRCDIR)/target/h
|
||||
MIBCOMPFLAGS=-l $(SRCDIR)/target/src/wrn/wm/snmp/std-mibs -quiet
|
||||
|
||||
|
||||
|
||||
PRODUCTH=$(SRCDIR)/target/h/wrn/wm/common
|
||||
|
||||
|
||||
|
||||
WIND_BASE := $(subst \,/,$(WIND_BASE))
|
||||
|
||||
ifeq ($(EXTRA_DEFINE),)
|
||||
export EXTRA_DEFINE=
|
||||
endif
|
||||
|
||||
override EXTRA_DEFINE+=-fno-strict-aliasing
|
||||
|
||||
OBJ = o
|
||||
LIBEXT = a
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# These next 3 lines must come before any of the application rules.
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
include $(WIND_USR)/make/defs.default
|
||||
include $(WIND_USR)/tool/$(TOOL_FAMILY)/make.$(CPU)$(TOOL)
|
||||
|
||||
OBJS=snmpDes.o snmpDesKey.o snmpDesSp.o snmpDesModes.o
|
||||
|
||||
LIB_BASE_NAME=epdes
|
||||
|
||||
include $(WIND_USR)/make/rules.library
|
||||
|
||||
# -$(RM) $(VSB_DIR)/usr/lib/$(VX_CPU_FAMILY)/$(CPU)/$(SF_32)$(TOOL_COMMON_DIR)/obj$(LIB_BASE_NAME)/*.o
|
||||
# -$(RM) $(VSB_DIR)/usr/lib/$(VX_CPU_FAMILY)/$(CPU)/$(SF_32)$(TOOL_COMMON_DIR)/lib$(LIB_BASE_NAME).a
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
* this DES implementation derived from Phil Karns public domain DES.
|
||||
* thanks, Phil.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: des3.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:53 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:35:33 tneale
|
||||
* Fixed for newest file structure
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:38 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.3 2001/01/19 22:21:25 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.2 2000/03/17 00:16:21 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.1 1998/06/24 13:29:12 josh
|
||||
* DES files have been moved to new directory to handle export
|
||||
* restrictions more cleanly
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/des.h>
|
||||
|
||||
/* Combined SP lookup table, linked in
|
||||
* For best results, ensure that this is aligned on a 32-bit boundary;
|
||||
* Borland C++ 3.1 doesn't guarantee this!
|
||||
*/
|
||||
extern bits32_t Spbox[8][64]; /* Combined S and P boxes */
|
||||
|
||||
/* Primitive function F.
|
||||
* Input is r, subkey array in keys, output is XORed into l.
|
||||
* Each round consumes eight 6-bit subkeys, one for
|
||||
* each of the 8 S-boxes, 2 longs for each round.
|
||||
* Each long contains four 6-bit subkeys, each taking up a byte.
|
||||
* The first long contains, from high to low end, the subkeys for
|
||||
* S-boxes 1, 3, 5 & 7; the second contains the subkeys for S-boxes
|
||||
* 2, 4, 6 & 8 (using the origin-1 S-box numbering in the standard,
|
||||
* not the origin-0 numbering used elsewhere in this code)
|
||||
* See comments elsewhere about the pre-rotated values of r and Spbox.
|
||||
*/
|
||||
#define F(l,r,key){\
|
||||
work = ((r >> 4) | (r << 28)) ^ key[0];\
|
||||
l ^= Spbox[6][(int) (work & 0x3f)];\
|
||||
l ^= Spbox[4][(int) ((work >> 8) & 0x3f)];\
|
||||
l ^= Spbox[2][(int) ((work >> 16) & 0x3f)];\
|
||||
l ^= Spbox[0][(int) ((work >> 24) & 0x3f)];\
|
||||
work = r ^ key[1];\
|
||||
l ^= Spbox[7][(int) (work & 0x3f)];\
|
||||
l ^= Spbox[5][(int) ((work >> 8) & 0x3f)];\
|
||||
l ^= Spbox[3][(int) ((work >> 16) & 0x3f)];\
|
||||
l ^= Spbox[1][(int) ((work >> 24) & 0x3f)];\
|
||||
}
|
||||
/* Encrypt or decrypt a block of data in ECB mode */
|
||||
void des3(DES3_KS ks, bits8_t *block, bits8_t *out)
|
||||
{
|
||||
bits32_t left,right,work;
|
||||
|
||||
/* Read input block and place in left/right in big-endian order */
|
||||
left = ((bits32_t)block[0] << 24)
|
||||
| ((bits32_t)block[1] << 16)
|
||||
| ((bits32_t)block[2] << 8)
|
||||
| (bits32_t)block[3];
|
||||
right = ((bits32_t)block[4] << 24)
|
||||
| ((bits32_t)block[5] << 16)
|
||||
| ((bits32_t)block[6] << 8)
|
||||
| (bits32_t)block[7];
|
||||
|
||||
/* Hoey's clever initial permutation algorithm, from Outerbridge
|
||||
* (see Schneier p 478)
|
||||
*
|
||||
* The convention here is the same as Outerbridge: rotate each
|
||||
* register left by 1 bit, i.e., so that "left" contains permuted
|
||||
* input bits 2, 3, 4, ... 1 and "right" contains 33, 34, 35, ... 32
|
||||
* (using origin-1 numbering as in the FIPS). This allows us to avoid
|
||||
* one of the two rotates that would otherwise be required in each of
|
||||
* the 16 rounds.
|
||||
*/
|
||||
work = ((left >> 4) ^ right) & 0x0f0f0f0fL;
|
||||
right ^= work;
|
||||
left ^= work << 4;
|
||||
work = ((left >> 16) ^ right) & 0xffff;
|
||||
right ^= work;
|
||||
left ^= work << 16;
|
||||
work = ((right >> 2) ^ left) & 0x33333333L;
|
||||
left ^= work;
|
||||
right ^= (work << 2);
|
||||
work = ((right >> 8) ^ left) & 0xff00ffL;
|
||||
left ^= work;
|
||||
right ^= (work << 8);
|
||||
right = (right << 1) | (right >> 31);
|
||||
work = (left ^ right) & 0xaaaaaaaaL;
|
||||
left ^= work;
|
||||
right ^= work;
|
||||
left = (left << 1) | (left >> 31);
|
||||
|
||||
/* First key */
|
||||
F(left,right,ks[0]);
|
||||
F(right,left,ks[1]);
|
||||
F(left,right,ks[2]);
|
||||
F(right,left,ks[3]);
|
||||
F(left,right,ks[4]);
|
||||
F(right,left,ks[5]);
|
||||
F(left,right,ks[6]);
|
||||
F(right,left,ks[7]);
|
||||
F(left,right,ks[8]);
|
||||
F(right,left,ks[9]);
|
||||
F(left,right,ks[10]);
|
||||
F(right,left,ks[11]);
|
||||
F(left,right,ks[12]);
|
||||
F(right,left,ks[13]);
|
||||
F(left,right,ks[14]);
|
||||
F(right,left,ks[15]);
|
||||
|
||||
/* Second key (must be created in opposite mode to first key) */
|
||||
F(right,left,ks[16]);
|
||||
F(left,right,ks[17]);
|
||||
F(right,left,ks[18]);
|
||||
F(left,right,ks[19]);
|
||||
F(right,left,ks[20]);
|
||||
F(left,right,ks[21]);
|
||||
F(right,left,ks[22]);
|
||||
F(left,right,ks[23]);
|
||||
F(right,left,ks[24]);
|
||||
F(left,right,ks[25]);
|
||||
F(right,left,ks[26]);
|
||||
F(left,right,ks[27]);
|
||||
F(right,left,ks[28]);
|
||||
F(left,right,ks[29]);
|
||||
F(right,left,ks[30]);
|
||||
F(left,right,ks[31]);
|
||||
|
||||
/* First key again */
|
||||
F(left,right,ks[32]);
|
||||
F(right,left,ks[33]);
|
||||
F(left,right,ks[34]);
|
||||
F(right,left,ks[35]);
|
||||
F(left,right,ks[36]);
|
||||
F(right,left,ks[37]);
|
||||
F(left,right,ks[38]);
|
||||
F(right,left,ks[39]);
|
||||
F(left,right,ks[40]);
|
||||
F(right,left,ks[41]);
|
||||
F(left,right,ks[42]);
|
||||
F(right,left,ks[43]);
|
||||
F(left,right,ks[44]);
|
||||
F(right,left,ks[45]);
|
||||
F(left,right,ks[46]);
|
||||
F(right,left,ks[47]);
|
||||
|
||||
/* Inverse permutation, also from Hoey via Outerbridge and Schneier */
|
||||
right = (right << 31) | (right >> 1);
|
||||
work = (left ^ right) & 0xaaaaaaaaL;
|
||||
left ^= work;
|
||||
|
||||
right ^= work;
|
||||
left = (left >> 1) | (left << 31);
|
||||
work = ((left >> 8) ^ right) & 0xff00ffL;
|
||||
right ^= work;
|
||||
left ^= work << 8;
|
||||
work = ((left >> 2) ^ right) & 0x33333333L;
|
||||
right ^= work;
|
||||
left ^= work << 2;
|
||||
work = ((right >> 16) ^ left) & 0xffffL;
|
||||
left ^= work;
|
||||
right ^= work << 16;
|
||||
work = ((right >> 4) ^ left) & 0x0f0f0f0fL;
|
||||
left ^= work;
|
||||
right ^= work << 4;
|
||||
|
||||
/* Put the block back into the user's buffer with final swap */
|
||||
out[0] = (bits8_t) (right >> 24);
|
||||
out[1] = (bits8_t) (right >> 16);
|
||||
out[2] = (bits8_t) (right >> 8);
|
||||
out[3] = (bits8_t) (right);
|
||||
out[4] = (bits8_t) (left >> 24);
|
||||
out[5] = (bits8_t) (left >> 16);
|
||||
out[6] = (bits8_t) (left >> 8);
|
||||
out[7] = (bits8_t) (left);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
#
|
||||
# Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
# All rights reserved. Provided under license only.
|
||||
# Distribution or other use of this software is only
|
||||
# permitted pursuant to the terms of a license agreement
|
||||
# from Wind River Systems (and is otherwise prohibited).
|
||||
# Refer to that license agreement for terms of use.
|
||||
#
|
||||
|
||||
# [clearcase]
|
||||
# modification history
|
||||
# -------------------
|
||||
# 01c,01aug07,jbl filenames change so makefile changes
|
||||
# 01b,20apr05,job update copyright notices
|
||||
# 01a,27sep04,job modify makefile to use generic OBJS object group
|
||||
# designation
|
||||
#
|
||||
|
||||
#
|
||||
# common/lib
|
||||
#
|
||||
|
||||
$#equate(PRODUCTH $#filepath($(SRCDIR) target h wrn wm common))
|
||||
|
||||
$#makefile-init()
|
||||
|
||||
##############################################################################
|
||||
# OBJECT FILE DEFINITION SECTION
|
||||
|
||||
$#equate(OBJS $#objs(snmpDes snmpDesKey snmpDesSp snmpDesModes)
|
||||
$#if-installed(COMMON_3DES $#objs(des3)))
|
||||
|
||||
all: des.tag $#filepath($(SRCDIR) target src wrn wm common lib $#libs(epdes)) $#dummy()
|
||||
|
||||
##############################################################################
|
||||
# Make the library itself
|
||||
|
||||
des.tag: $(MAKEFILENAME) $#dummy()
|
||||
-$(RM) $#filepath($(SRCDIR) target src wrn wm common lib $#libs(epdes))
|
||||
$(TOUCH) des.tag
|
||||
|
||||
$#makelib-nodel($#filepath($(SRCDIR) target src wrn wm common lib) epdes $#(OBJS) $(MAKEFILENAME))
|
||||
|
||||
##############################################################################
|
||||
# commands to figure out how big this all compiles to
|
||||
|
||||
sizes: $#dummy()
|
||||
$#makesize(DES $(DES_OBJS))
|
||||
|
||||
clean: $#dummy()
|
||||
-$(RM) $#objs(*)
|
||||
-$(RM) des.tag
|
||||
-$(RM) epdes.tag
|
||||
-$(RM) $#filepath($(SRCDIR) target src wrn wm common lib $#libs(epdes))
|
||||
$#clean()
|
||||
|
||||
##############################################################################
|
||||
# file dependencies
|
||||
$#equate(SRC_HDIR $#filepath($(SRCDIR) target h wrn wm))
|
||||
|
||||
$#objs(des) : des.c $(SRC_HDIR)/common/des.h \
|
||||
$(SRC_HDIR)/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$(SRC_HDIR)/common/config.h $(SRC_HDIR)/common/install.h
|
||||
$#objs(des3) : des3.c $(SRC_HDIR)/common/des.h \
|
||||
$(SRC_HDIR)/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$(SRC_HDIR)/common/config.h $(SRC_HDIR)/common/install.h
|
||||
$#objs(des_sp) : des_sp.c $(SRC_HDIR)/common/des.h \
|
||||
$(SRC_HDIR)/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$(SRC_HDIR)/common/config.h $(SRC_HDIR)/common/install.h
|
||||
$#objs(desmodes) : desmodes.c $(SRC_HDIR)/common/des.h \
|
||||
$(SRC_HDIR)/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$(SRC_HDIR)/common/config.h $(SRC_HDIR)/common/install.h
|
||||
$#objs(des_key) : des_key.c $(SRC_HDIR)/common/des.h \
|
||||
$(SRC_HDIR)/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$(SRC_HDIR)/common/config.h $(SRC_HDIR)/common/install.h
|
||||
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* this DES implementation derived from Phil Karns public domain DES.
|
||||
* thanks, Phil.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: des.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:53 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:35:33 tneale
|
||||
* Fixed for newest file structure
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:38 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.3 2001/01/19 22:21:25 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.2 2000/03/17 00:16:21 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.1 1998/06/24 13:29:11 josh
|
||||
* DES files have been moved to new directory to handle export
|
||||
* restrictions more cleanly
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/des.h>
|
||||
|
||||
/* Tables defined in the Data Encryption Standard documents
|
||||
* Three of these tables, the initial permutation, the final
|
||||
* permutation and the expansion operator, are regular enough that
|
||||
* for speed, we hard-code them. They're here for reference only.
|
||||
* Also, the S and P boxes are used by a separate program, gensp.c,
|
||||
* to build the combined SP box, Spbox[]. They're also here just
|
||||
* for reference.
|
||||
*/
|
||||
#if 0
|
||||
/* initial permutation IP */
|
||||
static bits8_t ip[] = {
|
||||
58, 50, 42, 34, 26, 18, 10, 2,
|
||||
60, 52, 44, 36, 28, 20, 12, 4,
|
||||
62, 54, 46, 38, 30, 22, 14, 6,
|
||||
64, 56, 48, 40, 32, 24, 16, 8,
|
||||
57, 49, 41, 33, 25, 17, 9, 1,
|
||||
59, 51, 43, 35, 27, 19, 11, 3,
|
||||
61, 53, 45, 37, 29, 21, 13, 5,
|
||||
63, 55, 47, 39, 31, 23, 15, 7
|
||||
};
|
||||
|
||||
/* final permutation IP^-1 */
|
||||
static bits8_t fp[] = {
|
||||
40, 8, 48, 16, 56, 24, 64, 32,
|
||||
39, 7, 47, 15, 55, 23, 63, 31,
|
||||
38, 6, 46, 14, 54, 22, 62, 30,
|
||||
37, 5, 45, 13, 53, 21, 61, 29,
|
||||
36, 4, 44, 12, 52, 20, 60, 28,
|
||||
35, 3, 43, 11, 51, 19, 59, 27,
|
||||
34, 2, 42, 10, 50, 18, 58, 26,
|
||||
33, 1, 41, 9, 49, 17, 57, 25
|
||||
};
|
||||
/* expansion operation matrix */
|
||||
static bits8_t ei[] = {
|
||||
32, 1, 2, 3, 4, 5,
|
||||
4, 5, 6, 7, 8, 9,
|
||||
8, 9, 10, 11, 12, 13,
|
||||
12, 13, 14, 15, 16, 17,
|
||||
16, 17, 18, 19, 20, 21,
|
||||
20, 21, 22, 23, 24, 25,
|
||||
24, 25, 26, 27, 28, 29,
|
||||
28, 29, 30, 31, 32, 1
|
||||
};
|
||||
/* The (in)famous S-boxes */
|
||||
static bits8_t sbox[8][64] = {
|
||||
/* S1 */
|
||||
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
|
||||
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
|
||||
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
|
||||
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13,
|
||||
|
||||
/* S2 */
|
||||
15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
|
||||
3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
|
||||
0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
|
||||
13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9,
|
||||
|
||||
/* S3 */
|
||||
10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
|
||||
13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
|
||||
13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
|
||||
1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12,
|
||||
|
||||
/* S4 */
|
||||
7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
|
||||
13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
|
||||
10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
|
||||
3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14,
|
||||
|
||||
/* S5 */
|
||||
2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
|
||||
14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
|
||||
4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
|
||||
11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3,
|
||||
|
||||
/* S6 */
|
||||
12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
|
||||
10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
|
||||
9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
|
||||
4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13,
|
||||
|
||||
/* S7 */
|
||||
4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
|
||||
13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
|
||||
1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
|
||||
6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12,
|
||||
|
||||
/* S8 */
|
||||
13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
|
||||
1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
|
||||
7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
|
||||
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11
|
||||
};
|
||||
|
||||
/* 32-bit permutation function P used on the output of the S-boxes */
|
||||
static bits8_t p32i[] = {
|
||||
16, 7, 20, 21,
|
||||
29, 12, 28, 17,
|
||||
1, 15, 23, 26,
|
||||
5, 18, 31, 10,
|
||||
2, 8, 24, 14,
|
||||
32, 27, 3, 9,
|
||||
19, 13, 30, 6,
|
||||
22, 11, 4, 25
|
||||
};
|
||||
#endif /* 0 */
|
||||
|
||||
int Asmversion = 0;
|
||||
|
||||
/* Combined SP lookup table, linked in
|
||||
* For best results, ensure that this is aligned on a 32-bit boundary;
|
||||
* Borland C++ 3.1 doesn't guarantee this!
|
||||
*/
|
||||
extern bits32_t Spbox[8][64]; /* Combined S and P boxes */
|
||||
|
||||
/* Primitive function F.
|
||||
* Input is r, subkey array in keys, output is XORed into l.
|
||||
* Each round consumes eight 6-bit subkeys, one for
|
||||
* each of the 8 S-boxes, 2 longs for each round.
|
||||
* Each long contains four 6-bit subkeys, each taking up a byte.
|
||||
* The first long contains, from high to low end, the subkeys for
|
||||
* S-boxes 1, 3, 5 & 7; the second contains the subkeys for S-boxes
|
||||
* 2, 4, 6 & 8 (using the origin-1 S-box numbering in the standard,
|
||||
* not the origin-0 numbering used elsewhere in this code)
|
||||
* See comments elsewhere about the pre-rotated values of r and Spbox.
|
||||
*/
|
||||
#define F(l,r,key){\
|
||||
work = ((r >> 4) | (r << 28));\
|
||||
work = work ^ (key [0]);\
|
||||
l ^= Spbox[6][(int) (work & 0x3f)];\
|
||||
l ^= Spbox[4][(int) ((work >> 8) & 0x3f)];\
|
||||
l ^= Spbox[2][(int) ((work >> 16) & 0x3f)];\
|
||||
l ^= Spbox[0][(int) ((work >> 24) & 0x3f)];\
|
||||
work = r ^ key[1];\
|
||||
l ^= Spbox[7][(int) (work & 0x3f)];\
|
||||
l ^= Spbox[5][(int) ((work >> 8) & 0x3f)];\
|
||||
l ^= Spbox[3][(int) ((work >> 16) & 0x3f)];\
|
||||
l ^= Spbox[1][(int) ((work >> 24) & 0x3f)];\
|
||||
}
|
||||
/* Encrypt or decrypt a block of data in ECB mode */
|
||||
void des (DES_KS ks, bits8_t *block, bits8_t *out)
|
||||
{
|
||||
bits32_t left,right,work;
|
||||
|
||||
/* Read input block and place in left/right in big-endian order */
|
||||
left = ((bits32_t)block[0] << 24)
|
||||
| ((bits32_t)block[1] << 16)
|
||||
| ((bits32_t)block[2] << 8)
|
||||
| (bits32_t)block[3];
|
||||
right = ((bits32_t)block[4] << 24)
|
||||
| ((bits32_t)block[5] << 16)
|
||||
| ((bits32_t)block[6] << 8)
|
||||
| (bits32_t)block[7];
|
||||
|
||||
/* Hoey's clever initial permutation algorithm, from Outerbridge
|
||||
* (see Schneier p 478)
|
||||
*
|
||||
* The convention here is the same as Outerbridge: rotate each
|
||||
* register left by 1 bit, i.e., so that "left" contains permuted
|
||||
* input bits 2, 3, 4, ... 1 and "right" contains 33, 34, 35, ... 32
|
||||
* (using origin-1 numbering as in the FIPS). This allows us to avoid
|
||||
* one of the two rotates that would otherwise be required in each of
|
||||
* the 16 rounds.
|
||||
*/
|
||||
work = ((left >> 4) ^ right) & 0x0f0f0f0fL;
|
||||
right ^= work;
|
||||
left ^= work << 4;
|
||||
work = ((left >> 16) ^ right) & 0xffff;
|
||||
right ^= work;
|
||||
left ^= work << 16;
|
||||
work = ((right >> 2) ^ left) & 0x33333333L;
|
||||
left ^= work;
|
||||
right ^= (work << 2);
|
||||
work = ((right >> 8) ^ left) & 0xff00ffL;
|
||||
left ^= work;
|
||||
right ^= (work << 8);
|
||||
right = (right << 1) | (right >> 31);
|
||||
work = (left ^ right) & 0xaaaaaaaaL;
|
||||
left ^= work;
|
||||
right ^= work;
|
||||
left = (left << 1) | (left >> 31);
|
||||
|
||||
/* Now do the 16 rounds */
|
||||
F(left,right,ks[0]);
|
||||
F(right,left,ks[1]);
|
||||
F(left,right,ks[2]);
|
||||
F(right,left,ks[3]);
|
||||
F(left,right,ks[4]);
|
||||
F(right,left,ks[5]);
|
||||
F(left,right,ks[6]);
|
||||
F(right,left,ks[7]);
|
||||
F(left,right,ks[8]);
|
||||
F(right,left,ks[9]);
|
||||
F(left,right,ks[10]);
|
||||
F(right,left,ks[11]);
|
||||
F(left,right,ks[12]);
|
||||
F(right,left,ks[13]);
|
||||
F(left,right,ks[14]);
|
||||
F(right,left,ks[15]);
|
||||
|
||||
/* Inverse permutation, also from Hoey via Outerbridge and Schneier */
|
||||
right = (right << 31) | (right >> 1);
|
||||
work = (left ^ right) & 0xaaaaaaaaL;
|
||||
left ^= work;
|
||||
right ^= work;
|
||||
left = (left >> 1) | (left << 31);
|
||||
work = ((left >> 8) ^ right) & 0xff00ffL;
|
||||
right ^= work;
|
||||
left ^= work << 8;
|
||||
work = ((left >> 2) ^ right) & 0x33333333L;
|
||||
right ^= work;
|
||||
left ^= work << 2;
|
||||
work = ((right >> 16) ^ left) & 0xffff;
|
||||
left ^= work;
|
||||
right ^= work << 16;
|
||||
work = ((right >> 4) ^ left) & 0x0f0f0f0fL;
|
||||
left ^= work;
|
||||
right ^= work << 4;
|
||||
|
||||
/* Put the block back into the user's buffer with final swap */
|
||||
out [0] = (bits8_t) (right >> 24);
|
||||
out [1] = (bits8_t) (right >> 16);
|
||||
out [2] = (bits8_t) (right >> 8);
|
||||
out [3] = (bits8_t) (right);
|
||||
out [4] = (bits8_t) (left >> 24);
|
||||
out [5] = (bits8_t) (left >> 16);
|
||||
out [6] = (bits8_t) (left >> 8);
|
||||
out [7] = (bits8_t) (left);
|
||||
}
|
||||
|
||||
/* A function to determine whether we're actually getting DES-style
|
||||
* encryption instead of just dummy routines.
|
||||
* Returns: 1 if real DES, 0 if dummy DES.
|
||||
*/
|
||||
|
||||
int des_is_real()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* this DES implementation derived from Phil Karns public domain DES.
|
||||
* thanks, Phil.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: des_key.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:53 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:35:34 tneale
|
||||
* Fixed for newest file structure
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:38 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.3 2001/01/19 22:21:26 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.2 2000/03/17 00:16:22 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.1 1998/06/24 13:29:12 josh
|
||||
* DES files have been moved to new directory to handle export
|
||||
* restrictions more cleanly
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Portable C code to create DES key schedules from user-provided keys
|
||||
*/
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/des.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
/* Key schedule-related tables from FIPS-46 */
|
||||
|
||||
/* permuted choice table (key) */
|
||||
static bits8_t pc1[] = {
|
||||
57, 49, 41, 33, 25, 17, 9,
|
||||
1, 58, 50, 42, 34, 26, 18,
|
||||
10, 2, 59, 51, 43, 35, 27,
|
||||
19, 11, 3, 60, 52, 44, 36,
|
||||
|
||||
63, 55, 47, 39, 31, 23, 15,
|
||||
7, 62, 54, 46, 38, 30, 22,
|
||||
14, 6, 61, 53, 45, 37, 29,
|
||||
21, 13, 5, 28, 20, 12, 4
|
||||
};
|
||||
|
||||
/* number left rotations of pc1 */
|
||||
static bits8_t totrot[] = {
|
||||
1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28
|
||||
};
|
||||
|
||||
/* permuted choice key (table) */
|
||||
static bits8_t pc2[] = {
|
||||
14, 17, 11, 24, 1, 5,
|
||||
3, 28, 15, 6, 21, 10,
|
||||
23, 19, 12, 4, 26, 8,
|
||||
16, 7, 27, 20, 13, 2,
|
||||
41, 52, 31, 37, 47, 55,
|
||||
30, 40, 51, 45, 33, 48,
|
||||
44, 49, 39, 56, 34, 53,
|
||||
46, 42, 50, 36, 29, 32
|
||||
};
|
||||
|
||||
/* End of DES-defined tables */
|
||||
|
||||
/* bit 0 is left-most in byte */
|
||||
static sbits16_t bytebit[] = {
|
||||
0200,0100,040,020,010,04,02,01
|
||||
};
|
||||
|
||||
|
||||
/* Generate key schedule for encryption or decryption
|
||||
* depending on the value of "decrypt"
|
||||
*/
|
||||
|
||||
/* 0 = encrypt, 1 = decrypt */
|
||||
void deskey (DES_KS k, bits8_t *key, int decrypt)
|
||||
{
|
||||
bits8_t pc1m[56]; /* place to modify pc1 into */
|
||||
bits8_t pcr[56]; /* place to rotate pc1 into */
|
||||
register int i,j,l;
|
||||
int m;
|
||||
bits8_t ks[8];
|
||||
|
||||
for (j=0; j<56; j++) { /* convert pc1 to bits of key */
|
||||
l=pc1[j]-1; /* integer bit location */
|
||||
m = l & 07; /* find bit */
|
||||
pc1m[j]=(key[l>>3] & /* find which key byte l is in */
|
||||
bytebit[m]) /* and which bit of that byte */
|
||||
? 1 : 0; /* and store 1-bit result */
|
||||
}
|
||||
for (i=0; i<16; i++) { /* key chunk for each iteration */
|
||||
MEMSET(ks, 0, sizeof(ks)); /* Clear key schedule */
|
||||
for (j=0; j<56; j++) /* rotate pc1 the right amount */
|
||||
pcr[j] = pc1m[(l=j+totrot[decrypt? 15-i : i])<(j<28? 28 : 56) ? l: l-28];
|
||||
/* rotate left and right halves independently */
|
||||
for (j=0; j<48; j++){ /* select bits individually */
|
||||
/* check bit that goes to ks[j] */
|
||||
if (pcr[pc2[j]-1]){
|
||||
/* mask it in if it's there */
|
||||
l= j % 6;
|
||||
ks[j/6] |= bytebit[l] >> 2;
|
||||
}
|
||||
}
|
||||
/* Now convert to packed odd/even interleaved form */
|
||||
k[i][0] = ((sbits32_t)ks[0] << 24)
|
||||
| ((sbits32_t)ks[2] << 16)
|
||||
| ((sbits32_t)ks[4] << 8)
|
||||
| ((sbits32_t)ks[6]);
|
||||
k[i][1] = ((sbits32_t)ks[1] << 24)
|
||||
| ((sbits32_t)ks[3] << 16)
|
||||
| ((sbits32_t)ks[5] << 8)
|
||||
| ((sbits32_t)ks[7]);
|
||||
}
|
||||
}
|
||||
|
||||
#if INSTALL_COMMON_3DES
|
||||
|
||||
/* Generate key schedule for triple DES in E-D-E (or D-E-D) mode.
|
||||
*
|
||||
* The key argument is taken to be 24 bytes. The first 8 bytes are K1
|
||||
* for the first stage, the second 8 bytes are K2 for the middle stage
|
||||
* and the third 8 bytes are K3 for the last stage.
|
||||
*
|
||||
* DES3_KS k key schedule to be initialized
|
||||
* bits8_t *key 192 bits (24 bytes) of key (will use only 168)
|
||||
* int decrypt 0 = encrypt, 1 = decrypt
|
||||
*/
|
||||
void des3key (DES3_KS k, bits8_t *key, int decrypt)
|
||||
{
|
||||
if (!decrypt)
|
||||
{ deskey(&k[0],&key[0],0);
|
||||
deskey(&k[16],&key[8],1);
|
||||
deskey(&k[32],&key[16],0);
|
||||
}
|
||||
else
|
||||
{ deskey(&k[32],&key[0],1);
|
||||
deskey(&k[16],&key[8],0);
|
||||
deskey(&k[0],&key[16],1);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* INSTALL_COMMON_3DES */
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* different modes for DES use. ECB, CBC
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: desmodes.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:54 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:35:34 tneale
|
||||
* Fixed for newest file structure
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.3 2001/01/19 22:21:26 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.2 2000/03/17 00:16:23 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.1 1998/06/24 13:29:12 josh
|
||||
* DES files have been moved to new directory to handle export
|
||||
* restrictions more cleanly
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/bug.h>
|
||||
#include <wrn/wm/common/des.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
void desecb_block_encrypt (DES_CTX *ctx, bits8_t *in, bits8_t *out)
|
||||
{ des (ctx->keysched, in, out);
|
||||
}
|
||||
|
||||
void descbc_block_encrypt (DES_CTX *ctx, bits8_t *in, bits8_t *out)
|
||||
{
|
||||
int i = 8;
|
||||
bits8_t *cp = ctx->iv;
|
||||
bits8_t *inp = in;
|
||||
|
||||
#ifdef IPSEC_DES_DEBUG
|
||||
PRINTF ("descbc_block_encrypt: input %2x %2x %2x %2x %2x %2x %2x %2x\n",
|
||||
(unsigned char) in [0], (unsigned char) in [1],
|
||||
(unsigned char) in [2], (unsigned char) in [3],
|
||||
(unsigned char) in [4], (unsigned char) in [5],
|
||||
(unsigned char) in [6], (unsigned char) in [7]);
|
||||
#endif
|
||||
while (i--)
|
||||
*cp++ ^= *inp++;
|
||||
|
||||
#ifdef IPSEC_DES_DEBUG
|
||||
PRINTF ("descbc_block_encrypt: xiv %2x %2x %2x %2x %2x %2x %2x %2x\n",
|
||||
(unsigned char) ctx->iv [0], (unsigned char) ctx->iv [1],
|
||||
(unsigned char) ctx->iv [2], (unsigned char) ctx->iv [3],
|
||||
(unsigned char) ctx->iv [4], (unsigned char) ctx->iv [5],
|
||||
(unsigned char) ctx->iv [6], (unsigned char) ctx->iv [7]);
|
||||
#endif
|
||||
|
||||
des (ctx->keysched, ctx->iv, out);
|
||||
|
||||
#ifdef IPSEC_DES_DEBUG
|
||||
PRINTF ("descbc_block_encrypt: out %2x %2x %2x %2x %2x %2x %2x %2x\n",
|
||||
(unsigned char) out [0], (unsigned char) out [1],
|
||||
(unsigned char) out [2], (unsigned char) out [3],
|
||||
(unsigned char) out [4], (unsigned char) out [5],
|
||||
(unsigned char) out [6], (unsigned char) out [7]);
|
||||
#endif
|
||||
MEMCPY(ctx->iv, out, 8);
|
||||
}
|
||||
|
||||
void descbc_block_decrypt (DES_CTX *ctx, bits8_t *in, bits8_t *out)
|
||||
{
|
||||
int i = 8;
|
||||
|
||||
bits8_t *cp = ctx->iv; /* == C[i-1] from last iteration, or IV */
|
||||
bits8_t *outp = out;
|
||||
bits8_t nextiv [8];
|
||||
|
||||
/* save current input C[i] to be next blocks IV */
|
||||
|
||||
MEMCPY(nextiv, in, 8);
|
||||
|
||||
des (ctx->keysched, in, out);
|
||||
|
||||
while (i--)
|
||||
*outp++ ^= *cp++; /* P[i] = D(C[i]) XOR C[i-1] */
|
||||
MEMCPY(ctx->iv, nextiv, 8); /* save C[i] for next iteration */
|
||||
}
|
||||
|
||||
#if INSTALL_COMMON_ESP_3DES
|
||||
void des3ecb_block_encrypt (DES3_CTX *ctx, bits8_t *in, bits8_t *out)
|
||||
{ des3 (ctx->keysched, in, out);
|
||||
}
|
||||
|
||||
void des3cbc_block_encrypt (DES3_CTX *ctx, bits8_t *in, bits8_t *out)
|
||||
{
|
||||
int i = 8;
|
||||
bits8_t *cp = ctx->iv;
|
||||
bits8_t *inp = in;
|
||||
while (i--)
|
||||
*cp++ ^= *inp++;
|
||||
|
||||
des3 (ctx->keysched, ctx->iv, out);
|
||||
MEMCPY(ctx->iv, out, 8);
|
||||
}
|
||||
|
||||
void des3cbc_block_decrypt (DES3_CTX *ctx, bits8_t *in, bits8_t *out)
|
||||
{
|
||||
int i = 8;
|
||||
|
||||
bits8_t *cp = ctx->iv; /* == C[i-1] from last iteration, or IV */
|
||||
bits8_t *outp = out;
|
||||
|
||||
des3 (ctx->keysched, in, out);
|
||||
|
||||
while (i--)
|
||||
*outp++ ^= *cp++; /* P[i] = D(C[i]) XOR C[i-1] */
|
||||
MEMCPY(ctx->iv, in, 8); /* save C[i] for next iteration */
|
||||
}
|
||||
|
||||
#endif /* INSTALL_COMMON_ESP_3DES */
|
||||
|
||||
/* algtable context glue */
|
||||
|
||||
void descbc_init_context (void *ctx, bits8_t *key, int decrypt)
|
||||
{
|
||||
deskey ( ((DES_CTX *) ctx)->keysched, key, decrypt);
|
||||
((DES_CTX *) ctx)->decrypt = decrypt;
|
||||
}
|
||||
|
||||
void descbc_iv_context (void *ctx, bits8_t *iv)
|
||||
{
|
||||
MEMCPY( ((DES_CTX *)ctx)->iv, iv, 8);
|
||||
}
|
||||
|
||||
void descbc_crypt (void *ctx, bits8_t *in, bits8_t *out, bits32_t n)
|
||||
{
|
||||
int decrypt = ((DES_CTX *) ctx)->decrypt;
|
||||
|
||||
while (n >= 8)
|
||||
{ if (decrypt)
|
||||
descbc_block_decrypt (((DES_CTX *) ctx), in, out);
|
||||
else
|
||||
descbc_block_encrypt (((DES_CTX *) ctx), in, out);
|
||||
in += 8;
|
||||
out += 8;
|
||||
n -= 8;
|
||||
}
|
||||
}
|
||||
|
||||
#if INSTALL_COMMON_ESP_3DES
|
||||
|
||||
void des3cbc_init_context (void *ctx, bits8_t *key, int decrypt)
|
||||
{
|
||||
des3key ( ((DES3_CTX *) ctx)->keysched, key, decrypt);
|
||||
((DES3_CTX *) ctx)->decrypt = decrypt;
|
||||
}
|
||||
|
||||
void des3cbc_iv_context (void *ctx, bits8_t *iv)
|
||||
{
|
||||
MEMCPY( ((DES3_CTX *)ctx)->iv, iv, 8);
|
||||
}
|
||||
|
||||
void des3cbc_crypt (void *ctx, bits8_t *in, bits8_t *out, bits32_t n)
|
||||
{
|
||||
int decrypt = ((DES3_CTX *) ctx)->decrypt;
|
||||
|
||||
while (n >= 8)
|
||||
{ if (decrypt)
|
||||
des3cbc_block_decrypt (((DES3_CTX *) ctx), in, out);
|
||||
else
|
||||
des3cbc_block_encrypt (((DES3_CTX *) ctx), in, out);
|
||||
in += 8;
|
||||
out += 8;
|
||||
n -= 8;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* INSTALL_COMMON_ESP_3DES */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* this DES implementation derived from Phil Karns public domain DES.
|
||||
* thanks, Phil.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: des_sp.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:54 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:35:34 tneale
|
||||
* Fixed for newest file structure
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.3 2001/01/19 22:21:26 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.2 2000/03/17 00:16:22 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.1 1998/06/24 13:29:12 josh
|
||||
* DES files have been moved to new directory to handle export
|
||||
* restrictions more cleanly
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/des.h>
|
||||
|
||||
bits32_t Spbox[512] = {
|
||||
0x01010400L,0x00000000L,0x00010000L,0x01010404L,
|
||||
0x01010004L,0x00010404L,0x00000004L,0x00010000L,
|
||||
0x00000400L,0x01010400L,0x01010404L,0x00000400L,
|
||||
0x01000404L,0x01010004L,0x01000000L,0x00000004L,
|
||||
0x00000404L,0x01000400L,0x01000400L,0x00010400L,
|
||||
0x00010400L,0x01010000L,0x01010000L,0x01000404L,
|
||||
0x00010004L,0x01000004L,0x01000004L,0x00010004L,
|
||||
0x00000000L,0x00000404L,0x00010404L,0x01000000L,
|
||||
0x00010000L,0x01010404L,0x00000004L,0x01010000L,
|
||||
0x01010400L,0x01000000L,0x01000000L,0x00000400L,
|
||||
0x01010004L,0x00010000L,0x00010400L,0x01000004L,
|
||||
0x00000400L,0x00000004L,0x01000404L,0x00010404L,
|
||||
0x01010404L,0x00010004L,0x01010000L,0x01000404L,
|
||||
0x01000004L,0x00000404L,0x00010404L,0x01010400L,
|
||||
0x00000404L,0x01000400L,0x01000400L,0x00000000L,
|
||||
0x00010004L,0x00010400L,0x00000000L,0x01010004L,
|
||||
0x80108020L,0x80008000L,0x00008000L,0x00108020L,
|
||||
0x00100000L,0x00000020L,0x80100020L,0x80008020L,
|
||||
0x80000020L,0x80108020L,0x80108000L,0x80000000L,
|
||||
0x80008000L,0x00100000L,0x00000020L,0x80100020L,
|
||||
0x00108000L,0x00100020L,0x80008020L,0x00000000L,
|
||||
0x80000000L,0x00008000L,0x00108020L,0x80100000L,
|
||||
0x00100020L,0x80000020L,0x00000000L,0x00108000L,
|
||||
0x00008020L,0x80108000L,0x80100000L,0x00008020L,
|
||||
0x00000000L,0x00108020L,0x80100020L,0x00100000L,
|
||||
0x80008020L,0x80100000L,0x80108000L,0x00008000L,
|
||||
0x80100000L,0x80008000L,0x00000020L,0x80108020L,
|
||||
0x00108020L,0x00000020L,0x00008000L,0x80000000L,
|
||||
0x00008020L,0x80108000L,0x00100000L,0x80000020L,
|
||||
0x00100020L,0x80008020L,0x80000020L,0x00100020L,
|
||||
0x00108000L,0x00000000L,0x80008000L,0x00008020L,
|
||||
0x80000000L,0x80100020L,0x80108020L,0x00108000L,
|
||||
0x00000208L,0x08020200L,0x00000000L,0x08020008L,
|
||||
0x08000200L,0x00000000L,0x00020208L,0x08000200L,
|
||||
0x00020008L,0x08000008L,0x08000008L,0x00020000L,
|
||||
0x08020208L,0x00020008L,0x08020000L,0x00000208L,
|
||||
0x08000000L,0x00000008L,0x08020200L,0x00000200L,
|
||||
0x00020200L,0x08020000L,0x08020008L,0x00020208L,
|
||||
0x08000208L,0x00020200L,0x00020000L,0x08000208L,
|
||||
0x00000008L,0x08020208L,0x00000200L,0x08000000L,
|
||||
0x08020200L,0x08000000L,0x00020008L,0x00000208L,
|
||||
0x00020000L,0x08020200L,0x08000200L,0x00000000L,
|
||||
0x00000200L,0x00020008L,0x08020208L,0x08000200L,
|
||||
0x08000008L,0x00000200L,0x00000000L,0x08020008L,
|
||||
0x08000208L,0x00020000L,0x08000000L,0x08020208L,
|
||||
0x00000008L,0x00020208L,0x00020200L,0x08000008L,
|
||||
0x08020000L,0x08000208L,0x00000208L,0x08020000L,
|
||||
0x00020208L,0x00000008L,0x08020008L,0x00020200L,
|
||||
0x00802001L,0x00002081L,0x00002081L,0x00000080L,
|
||||
0x00802080L,0x00800081L,0x00800001L,0x00002001L,
|
||||
0x00000000L,0x00802000L,0x00802000L,0x00802081L,
|
||||
0x00000081L,0x00000000L,0x00800080L,0x00800001L,
|
||||
0x00000001L,0x00002000L,0x00800000L,0x00802001L,
|
||||
0x00000080L,0x00800000L,0x00002001L,0x00002080L,
|
||||
0x00800081L,0x00000001L,0x00002080L,0x00800080L,
|
||||
0x00002000L,0x00802080L,0x00802081L,0x00000081L,
|
||||
0x00800080L,0x00800001L,0x00802000L,0x00802081L,
|
||||
0x00000081L,0x00000000L,0x00000000L,0x00802000L,
|
||||
0x00002080L,0x00800080L,0x00800081L,0x00000001L,
|
||||
0x00802001L,0x00002081L,0x00002081L,0x00000080L,
|
||||
0x00802081L,0x00000081L,0x00000001L,0x00002000L,
|
||||
0x00800001L,0x00002001L,0x00802080L,0x00800081L,
|
||||
0x00002001L,0x00002080L,0x00800000L,0x00802001L,
|
||||
0x00000080L,0x00800000L,0x00002000L,0x00802080L,
|
||||
0x00000100L,0x02080100L,0x02080000L,0x42000100L,
|
||||
0x00080000L,0x00000100L,0x40000000L,0x02080000L,
|
||||
0x40080100L,0x00080000L,0x02000100L,0x40080100L,
|
||||
0x42000100L,0x42080000L,0x00080100L,0x40000000L,
|
||||
0x02000000L,0x40080000L,0x40080000L,0x00000000L,
|
||||
0x40000100L,0x42080100L,0x42080100L,0x02000100L,
|
||||
0x42080000L,0x40000100L,0x00000000L,0x42000000L,
|
||||
0x02080100L,0x02000000L,0x42000000L,0x00080100L,
|
||||
0x00080000L,0x42000100L,0x00000100L,0x02000000L,
|
||||
0x40000000L,0x02080000L,0x42000100L,0x40080100L,
|
||||
0x02000100L,0x40000000L,0x42080000L,0x02080100L,
|
||||
0x40080100L,0x00000100L,0x02000000L,0x42080000L,
|
||||
0x42080100L,0x00080100L,0x42000000L,0x42080100L,
|
||||
0x02080000L,0x00000000L,0x40080000L,0x42000000L,
|
||||
0x00080100L,0x02000100L,0x40000100L,0x00080000L,
|
||||
0x00000000L,0x40080000L,0x02080100L,0x40000100L,
|
||||
0x20000010L,0x20400000L,0x00004000L,0x20404010L,
|
||||
0x20400000L,0x00000010L,0x20404010L,0x00400000L,
|
||||
0x20004000L,0x00404010L,0x00400000L,0x20000010L,
|
||||
0x00400010L,0x20004000L,0x20000000L,0x00004010L,
|
||||
0x00000000L,0x00400010L,0x20004010L,0x00004000L,
|
||||
0x00404000L,0x20004010L,0x00000010L,0x20400010L,
|
||||
0x20400010L,0x00000000L,0x00404010L,0x20404000L,
|
||||
0x00004010L,0x00404000L,0x20404000L,0x20000000L,
|
||||
0x20004000L,0x00000010L,0x20400010L,0x00404000L,
|
||||
0x20404010L,0x00400000L,0x00004010L,0x20000010L,
|
||||
0x00400000L,0x20004000L,0x20000000L,0x00004010L,
|
||||
0x20000010L,0x20404010L,0x00404000L,0x20400000L,
|
||||
0x00404010L,0x20404000L,0x00000000L,0x20400010L,
|
||||
0x00000010L,0x00004000L,0x20400000L,0x00404010L,
|
||||
0x00004000L,0x00400010L,0x20004010L,0x00000000L,
|
||||
0x20404000L,0x20000000L,0x00400010L,0x20004010L,
|
||||
0x00200000L,0x04200002L,0x04000802L,0x00000000L,
|
||||
0x00000800L,0x04000802L,0x00200802L,0x04200800L,
|
||||
0x04200802L,0x00200000L,0x00000000L,0x04000002L,
|
||||
0x00000002L,0x04000000L,0x04200002L,0x00000802L,
|
||||
0x04000800L,0x00200802L,0x00200002L,0x04000800L,
|
||||
0x04000002L,0x04200000L,0x04200800L,0x00200002L,
|
||||
0x04200000L,0x00000800L,0x00000802L,0x04200802L,
|
||||
0x00200800L,0x00000002L,0x04000000L,0x00200800L,
|
||||
0x04000000L,0x00200800L,0x00200000L,0x04000802L,
|
||||
0x04000802L,0x04200002L,0x04200002L,0x00000002L,
|
||||
0x00200002L,0x04000000L,0x04000800L,0x00200000L,
|
||||
0x04200800L,0x00000802L,0x00200802L,0x04200800L,
|
||||
0x00000802L,0x04000002L,0x04200802L,0x04200000L,
|
||||
0x00200800L,0x00000000L,0x00000002L,0x04200802L,
|
||||
0x00000000L,0x00200802L,0x04200000L,0x00000800L,
|
||||
0x04000002L,0x04000800L,0x00000800L,0x00200002L,
|
||||
0x10001040L,0x00001000L,0x00040000L,0x10041040L,
|
||||
0x10000000L,0x10001040L,0x00000040L,0x10000000L,
|
||||
0x00040040L,0x10040000L,0x10041040L,0x00041000L,
|
||||
0x10041000L,0x00041040L,0x00001000L,0x00000040L,
|
||||
0x10040000L,0x10000040L,0x10001000L,0x00001040L,
|
||||
0x00041000L,0x00040040L,0x10040040L,0x10041000L,
|
||||
0x00001040L,0x00000000L,0x00000000L,0x10040040L,
|
||||
0x10000040L,0x10001000L,0x00041040L,0x00040000L,
|
||||
0x00041040L,0x00040000L,0x10041000L,0x00001000L,
|
||||
0x00000040L,0x10040040L,0x00001000L,0x00041040L,
|
||||
0x10001000L,0x00000040L,0x10000040L,0x10040000L,
|
||||
0x10040040L,0x10000000L,0x00040000L,0x10001040L,
|
||||
0x00000000L,0x10041040L,0x00040040L,0x10000040L,
|
||||
0x10040000L,0x10001000L,0x10001040L,0x00000000L,
|
||||
0x10041040L,0x00041000L,0x00041000L,0x00001040L,
|
||||
0x00001040L,0x00040040L,0x10000000L,0x10041000L,
|
||||
};
|
||||
@@ -0,0 +1,78 @@
|
||||
#
|
||||
# Copyright (C) 2013 Wind River Systems, Inc.
|
||||
# All rights reserved. Provided under license only.
|
||||
# Distribution or other use of this software is only
|
||||
# permitted pursuant to the terms of a license agreement
|
||||
# from Wind River Systems (and is otherwise prohibited).
|
||||
# Refer to that license agreement for terms of use.
|
||||
#
|
||||
# Revision history
|
||||
# -------------------
|
||||
# 01c,31jan13,bbz create this file
|
||||
#
|
||||
# common/lib
|
||||
#
|
||||
|
||||
|
||||
OEM=
|
||||
SOFTPORT=$(SRCDIR)/target/usr/h/wrn/wm/util/port/vxworks
|
||||
HARDPORT=
|
||||
SRCDIR=$(WIND_BASE)
|
||||
XCFLAGS=
|
||||
EXTRA_PRODUCTS=
|
||||
WMSNMP_ADDED_OBJS=
|
||||
WMSNMP_ADDED_MIBS=
|
||||
MIBCOMPILER=mibcomp
|
||||
TOUCH=touch
|
||||
MAKEFILENAME=makefile.wmsnmp
|
||||
CLEAN_LIST=
|
||||
ETC_INI_FILES=etc.ini
|
||||
TGT_DIR=$(WIND_BASE)/target
|
||||
WMINC=$(SRCDIR)/target/h
|
||||
MIBCOMPFLAGS=-l $(SRCDIR)/target/src/wrn/wm/snmp/std-mibs -quiet
|
||||
|
||||
PRODUCTH=$(SRCDIR)/target/h/wrn/wm/common
|
||||
|
||||
WIND_BASE := $(subst \,/,$(WIND_BASE))
|
||||
|
||||
ifeq ($(EXTRA_DEFINE),)
|
||||
export EXTRA_DEFINE=
|
||||
endif
|
||||
|
||||
override EXTRA_DEFINE+=-fno-strict-aliasing
|
||||
|
||||
OBJ = o
|
||||
LIBEXT = a
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# These next 3 lines must come before any of the application rules.
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
include $(WIND_USR)/make/defs.default
|
||||
include $(WIND_USR)/tool/$(TOOL_FAMILY)/make.$(CPU)$(TOOL)
|
||||
|
||||
|
||||
|
||||
##############################################################################
|
||||
# OBJECT FILE DEFINITION SECTION
|
||||
|
||||
WEAKPRNG_OBJS=weakprng.o
|
||||
PRNG_OBJS=
|
||||
MD4_OBJS=
|
||||
MD5_OBJS=snmpMd5.o
|
||||
SHA_OBJS=snmpSha.o
|
||||
HMAC_OBJS=snmpHmac.o
|
||||
DESTESTOBJS=des_test.o
|
||||
|
||||
STRING_OBJS=
|
||||
|
||||
THREAD_OBJS=
|
||||
|
||||
FIXED64_OBJS=fixed64.o
|
||||
|
||||
OBJS=cmn_init.o $(WEAKPRNG_OBJS) $(PRNG_OBJS) $(MD4_OBJS) $(MD5_OBJS) $(SHA_OBJS) $(HMAC_OBJS) $(STRING_OBJS) $(THREAD_OBJS) $(FIXED64_OBJS)
|
||||
|
||||
LIB_BASE_NAME=epcommon
|
||||
|
||||
include $(WIND_USR)/make/rules.library
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/cmn_init.c,v 1.3 2003/01/16 18:18:54 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1999 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: cmn_init.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:54 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:50 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.4 2001/01/19 22:21:30 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.3 2000/03/17 00:16:52 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.2 2000/02/04 21:46:25 josh
|
||||
* added some prototypes and includes so the vxWorks compiler
|
||||
* is happy
|
||||
*
|
||||
* Revision 1.1 1999/03/06 06:54:36 paul
|
||||
* moved common_init from prng.c to cmn_init.c
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
|
||||
#include <wrn/wm/common/cmn_init.h>
|
||||
|
||||
#if INSTALL_COMMON_PRNG
|
||||
#include <wrn/wm/common/prng.h>
|
||||
#endif
|
||||
|
||||
void
|
||||
etc_common_init(void)
|
||||
{
|
||||
#if INSTALL_COMMON_PRNG
|
||||
prng_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
/****************************************************************************
|
||||
* Copyright 1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
/*
|
||||
* DES test cases from NBS DES certification suite
|
||||
*/
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/des.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#ifndef PRINTF
|
||||
#define PRINTF printf
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#define DES_TEST_CASES 34
|
||||
|
||||
bits8_t keys [DES_TEST_CASES][8] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 },
|
||||
{ 0x7C, 0xA1, 0x10, 0x45, 0x4A, 0x1A, 0x6E, 0x57 },
|
||||
{ 0x01, 0x31, 0xD9, 0x61, 0x9D, 0xC1, 0x37, 0x6E },
|
||||
{ 0x07, 0xA1, 0x13, 0x3E, 0x4A, 0x0B, 0x26, 0x86 },
|
||||
{ 0x38, 0x49, 0x67, 0x4C, 0x26, 0x02, 0x31, 0x9E },
|
||||
{ 0x04, 0xB9, 0x15, 0xBA, 0x43, 0xFE, 0xB5, 0xB6 },
|
||||
{ 0x01, 0x13, 0xB9, 0x70, 0xFD, 0x34, 0xF2, 0xCE },
|
||||
{ 0x01, 0x70, 0xF1, 0x75, 0x46, 0x8F, 0xB5, 0xE6 },
|
||||
{ 0x43, 0x29, 0x7F, 0xAD, 0x38, 0xE3, 0x73, 0xFE },
|
||||
{ 0x07, 0xA7, 0x13, 0x70, 0x45, 0xDA, 0x2A, 0x16 },
|
||||
{ 0x04, 0x68, 0x91, 0x04, 0xC2, 0xFD, 0x3B, 0x2F },
|
||||
{ 0x37, 0xD0, 0x6B, 0xB5, 0x16, 0xCB, 0x75, 0x46 },
|
||||
{ 0x1F, 0x08, 0x26, 0x0D, 0x1A, 0xC2, 0x46, 0x5E },
|
||||
{ 0x58, 0x40, 0x23, 0x64, 0x1A, 0xBA, 0x61, 0x76 },
|
||||
{ 0x02, 0x58, 0x16, 0x16, 0x46, 0x29, 0xB0, 0x07 },
|
||||
{ 0x49, 0x79, 0x3E, 0xBC, 0x79, 0xB3, 0x25, 0x8F },
|
||||
{ 0x4F, 0xB0, 0x5E, 0x15, 0x15, 0xAB, 0x73, 0xA7 },
|
||||
{ 0x49, 0xE9, 0x5D, 0x6D, 0x4C, 0xA2, 0x29, 0xBF },
|
||||
{ 0x01, 0x83, 0x10, 0xDC, 0x40, 0x9B, 0x26, 0xD6 },
|
||||
{ 0x1C, 0x58, 0x7F, 0x1C, 0x13, 0x92, 0x4F, 0xEF },
|
||||
{ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
|
||||
{ 0x1F, 0x1F, 0x1F, 0x1F, 0x0E, 0x0E, 0x0E, 0x0E },
|
||||
{ 0xE0, 0xFE, 0xE0, 0xFE, 0xF1, 0xFE, 0xF1, 0xFE },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }
|
||||
};
|
||||
|
||||
bits8_t ptext [DES_TEST_CASES][8] =
|
||||
{
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
|
||||
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
|
||||
{ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11 },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x01, 0xA1, 0xD6, 0xD0, 0x39, 0x77, 0x67, 0x42 },
|
||||
{ 0x5C, 0xD5, 0x4C, 0xA8, 0x3D, 0xEF, 0x57, 0xDA },
|
||||
{ 0x02, 0x48, 0xD4, 0x38, 0x06, 0xF6, 0x71, 0x72 },
|
||||
{ 0x51, 0x45, 0x4B, 0x58, 0x2D, 0xDF, 0x44, 0x0A },
|
||||
{ 0x42, 0xFD, 0x44, 0x30, 0x59, 0x57, 0x7F, 0xA2 },
|
||||
{ 0x05, 0x9B, 0x5E, 0x08, 0x51, 0xCF, 0x14, 0x3A },
|
||||
{ 0x07, 0x56, 0xD8, 0xE0, 0x77, 0x47, 0x61, 0xD2 },
|
||||
{ 0x76, 0x25, 0x14, 0xB8, 0x29, 0xBF, 0x48, 0x6A },
|
||||
{ 0x3B, 0xDD, 0x11, 0x90, 0x49, 0x37, 0x28, 0x02 },
|
||||
{ 0x26, 0x95, 0x5F, 0x68, 0x35, 0xAF, 0x60, 0x9A },
|
||||
{ 0x16, 0x4D, 0x5E, 0x40, 0x4F, 0x27, 0x52, 0x32 },
|
||||
{ 0x6B, 0x05, 0x6E, 0x18, 0x75, 0x9F, 0x5C, 0xCA },
|
||||
{ 0x00, 0x4B, 0xD6, 0xEF, 0x09, 0x17, 0x60, 0x62 },
|
||||
{ 0x48, 0x0D, 0x39, 0x00, 0x6E, 0xE7, 0x62, 0xF2 },
|
||||
{ 0x43, 0x75, 0x40, 0xC8, 0x69, 0x8F, 0x3C, 0xFA },
|
||||
{ 0x07, 0x2D, 0x43, 0xA0, 0x77, 0x07, 0x52, 0x92 },
|
||||
{ 0x02, 0xFE, 0x55, 0x77, 0x81, 0x17, 0xF1, 0x2A },
|
||||
{ 0x1D, 0x9D, 0x5C, 0x50, 0x18, 0xF7, 0x28, 0xC2 },
|
||||
{ 0x30, 0x55, 0x32, 0x28, 0x6D, 0x6F, 0x29, 0x5A },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
|
||||
};
|
||||
|
||||
bits8_t ctext [DES_TEST_CASES][8] =
|
||||
{
|
||||
{ 0x8C, 0xA6, 0x4D, 0xE9, 0xC1, 0xB1, 0x23, 0xA7 },
|
||||
{ 0x73, 0x59, 0xB2, 0x16, 0x3E, 0x4E, 0xDC, 0x58 },
|
||||
{ 0x95, 0x8E, 0x6E, 0x62, 0x7A, 0x05, 0x55, 0x7B },
|
||||
{ 0xF4, 0x03, 0x79, 0xAB, 0x9E, 0x0E, 0xC5, 0x33 },
|
||||
{ 0x17, 0x66, 0x8D, 0xFC, 0x72, 0x92, 0x53, 0x2D },
|
||||
{ 0x8A, 0x5A, 0xE1, 0xF8, 0x1A, 0xB8, 0xF2, 0xDD },
|
||||
{ 0x8C, 0xA6, 0x4D, 0xE9, 0xC1, 0xB1, 0x23, 0xA7 },
|
||||
{ 0xED, 0x39, 0xD9, 0x50, 0xFA, 0x74, 0xBC, 0xC4 },
|
||||
{ 0x69, 0x0F, 0x5B, 0x0D, 0x9A, 0x26, 0x93, 0x9B },
|
||||
{ 0x7A, 0x38, 0x9D, 0x10, 0x35, 0x4B, 0xD2, 0x71 },
|
||||
{ 0x86, 0x8E, 0xBB, 0x51, 0xCA, 0xB4, 0x59, 0x9A },
|
||||
{ 0x71, 0x78, 0x87, 0x6E, 0x01, 0xF1, 0x9B, 0x2A },
|
||||
{ 0xAF, 0x37, 0xFB, 0x42, 0x1F, 0x8C, 0x40, 0x95 },
|
||||
{ 0x86, 0xA5, 0x60, 0xF1, 0x0E, 0xC6, 0xD8, 0x5B },
|
||||
{ 0x0C, 0xD3, 0xDA, 0x02, 0x00, 0x21, 0xDC, 0x09 },
|
||||
{ 0xEA, 0x67, 0x6B, 0x2C, 0xB7, 0xDB, 0x2B, 0x7A },
|
||||
{ 0xDF, 0xD6, 0x4A, 0x81, 0x5C, 0xAF, 0x1A, 0x0F },
|
||||
{ 0x5C, 0x51, 0x3C, 0x9C, 0x48, 0x86, 0xC0, 0x88 },
|
||||
{ 0x0A, 0x2A, 0xEE, 0xAE, 0x3F, 0xF4, 0xAB, 0x77 },
|
||||
{ 0xEF, 0x1B, 0xF0, 0x3E, 0x5D, 0xFA, 0x57, 0x5A },
|
||||
{ 0x88, 0xBF, 0x0D, 0xB6, 0xD7, 0x0D, 0xEE, 0x56 },
|
||||
{ 0xA1, 0xF9, 0x91, 0x55, 0x41, 0x02, 0x0B, 0x56 },
|
||||
{ 0x6F, 0xBF, 0x1C, 0xAF, 0xCF, 0xFD, 0x05, 0x56 },
|
||||
{ 0x2F, 0x22, 0xE4, 0x9B, 0xAB, 0x7C, 0xA1, 0xAC },
|
||||
{ 0x5A, 0x6B, 0x61, 0x2C, 0xC2, 0x6C, 0xCE, 0x4A },
|
||||
{ 0x5F, 0x4C, 0x03, 0x8E, 0xD1, 0x2B, 0x2E, 0x41 },
|
||||
{ 0x63, 0xFA, 0xC0, 0xD0, 0x34, 0xD9, 0xF7, 0x93 },
|
||||
{ 0x61, 0x7B, 0x3A, 0x0C, 0xE8, 0xF0, 0x71, 0x00 },
|
||||
{ 0xDB, 0x95, 0x86, 0x05, 0xF8, 0xC8, 0xC6, 0x06 },
|
||||
{ 0xED, 0xBF, 0xD1, 0xC6, 0x6C, 0x29, 0xCC, 0xC7 },
|
||||
{ 0x35, 0x55, 0x50, 0xB2, 0x15, 0x0E, 0x24, 0x51 },
|
||||
{ 0xCA, 0xAA, 0xAF, 0x4D, 0xEA, 0xF1, 0xDB, 0xAE },
|
||||
{ 0xD5, 0xD4, 0x4F, 0xF7, 0x20, 0x68, 0x3D, 0x0D },
|
||||
{ 0x2A, 0x2B, 0xB0, 0x08, 0xDF, 0x97, 0xC2, 0xF2 }
|
||||
};
|
||||
|
||||
int main ()
|
||||
{
|
||||
int i;
|
||||
DES_KS k;
|
||||
int err = 0;
|
||||
|
||||
|
||||
for (i = 0 ; i < DES_TEST_CASES ; i++)
|
||||
{ deskey (k, keys [i], 0);
|
||||
des (k, ptext [i], ptext [i]);
|
||||
if (MEMCMP (ptext [i], ctext [i], 8) != 0)
|
||||
{
|
||||
err++;
|
||||
PRINTF("failure on test %d\n", i);
|
||||
}
|
||||
else
|
||||
PRINTF("success on test %d\n", i);
|
||||
}
|
||||
|
||||
return (err != 0);
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/fixed64.c,v 1.3 2003/01/16 18:18:55 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1999 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Fixed-point 64-bit math routines, intended primarily for time conversion
|
||||
* between Attache milliseconds and pSOSystem "ticks". These routines
|
||||
* are in the common library because they may be useful for other
|
||||
* applications, but these functions are not a full-fleged 64-bit math
|
||||
* library.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: fixed64.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:55 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:50 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.3 2001/01/19 22:21:30 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.2 2000/03/17 00:16:53 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.1 1999/03/01 20:08:56 sra
|
||||
* Add fixed-point 64-bit math routines; these are primarily intended for
|
||||
* converting between Attache and pSOSystem clock values, but the
|
||||
* functions themselves aren't specific to that.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/bug.h>
|
||||
#include <wrn/wm/common/fixed64.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
/*
|
||||
* Multiply two-64 bit unsigned fixed-point numbers (32 integer bits, 32
|
||||
* fractional bits) and return the integer part of the result, mod 2**32.
|
||||
*
|
||||
* The algorithm here is from Knuth, volume 2, 2nd edition, page 278.
|
||||
* We're trying to multiply two 2N-bit numbers u and v:
|
||||
*
|
||||
* u = 2**N * u1 + u0
|
||||
* v = 2**N * v1 + v0
|
||||
*
|
||||
* u * v = (2**(2*N) + 2**N ) * (u1 * v1)
|
||||
* + ( 2**N ) * ((u1 - u0) * (v0 - v1))
|
||||
* + ( 2**N + 1) * (u0 * v0)
|
||||
*
|
||||
* We use this algorithm twice, once with N=32, once with N=16.
|
||||
*
|
||||
* The final calculation yields a 128 bit result, but we can drop some
|
||||
* terms because we know they're just going to be outside the range of
|
||||
* the final result anyway. All we really want are the bits of the
|
||||
* result from 2**32 through 2**63, inclusive. So we can throw away
|
||||
* the 2**64 term, and we can use native arithmetic for all the 2**32
|
||||
* terms because we don't care about any high bits in those terms.
|
||||
* However, we have to calculate all 64 bits of the (u0 * v0) product
|
||||
* because of possible carries from the final term (1 * u0 * v0),
|
||||
* so we use this algorithm again, this time with N=16 (that is, using
|
||||
* the low 16 bits of 32-bit integers, so that we don't lose any bits).
|
||||
*
|
||||
* Most of the work here is just calculating the (x0 * y0) product,
|
||||
* and most of that is just the grunt work of summing up the 16-bit
|
||||
* partial products. The only tricky bit is handling the sign of the
|
||||
* "b" term; the multiplication itself comes out correctly, but the
|
||||
* sign bit doesn't propegate correctly through the summation without
|
||||
* some help.
|
||||
*/
|
||||
|
||||
bits32_t fixed64_mul(bits32_t x1, /* high bits of X */
|
||||
bits32_t x0, /* low bits of X */
|
||||
bits32_t y1, /* high bits of Y */
|
||||
bits32_t y0) /* low bits of Y */
|
||||
{
|
||||
bits32_t u1 = x0 >> 16, u0 = x0 & 0xFFFF;
|
||||
bits32_t v1 = y0 >> 16, v0 = y0 & 0xFFFF;
|
||||
bits32_t a = u1 * v1;
|
||||
bits32_t b = (u1 - u0) * (v0 - v1);
|
||||
bits32_t c = u0 * v0;
|
||||
bits32_t p1 = a, p0 = c, w;
|
||||
|
||||
w = p0, p0 += (a << 16), p1 += (a >> 16) + (p0 < w);
|
||||
w = p0, p0 += (c << 16), p1 += (c >> 16) + (p0 < w);
|
||||
|
||||
w = p0;
|
||||
if ((u1 < u0) != (v0 < v1))
|
||||
p0 -= (-b << 16), p1 -= (-b >> 16) + (p0 > w);
|
||||
else
|
||||
p0 += ( b << 16), p1 += ( b >> 16) + (p0 < w);
|
||||
|
||||
return x1 * y1 + (x1 - x0) * (y0 - y1) + p0 + p1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Divide a 32-bit unsigned integer by another 32-bit unsigned integer
|
||||
* to form a 64-bit unsigned fixed point number (32 integer bits, 32
|
||||
* fractional bits).
|
||||
*
|
||||
* We only expect to use this function at boot time, so it's optimized
|
||||
* for small code space and readability rather than speed of the
|
||||
* algorithm. Intended use is to compute things like the conversion
|
||||
* ratios between milliseconds (Attache) and "ticks" (pSOSystem).
|
||||
*/
|
||||
|
||||
void fixed64_div(bits32_t numerator,
|
||||
bits32_t denominator,
|
||||
bits32_t *integer,
|
||||
bits32_t *fractional)
|
||||
{
|
||||
bits32_t dividend;
|
||||
bits32_t remainder;
|
||||
bits32_t overflow;
|
||||
|
||||
BUG_ASSERT(denominator != 0 && integer != 0 && fractional != 0);
|
||||
|
||||
*integer = numerator / denominator;
|
||||
remainder = numerator % denominator;
|
||||
*fractional = 0;
|
||||
|
||||
for (dividend = 0x80000000;
|
||||
dividend && remainder;
|
||||
dividend >>= 1) {
|
||||
overflow = remainder & 0x80000000;
|
||||
remainder <<= 1;
|
||||
if (overflow || remainder >= denominator) {
|
||||
remainder -= denominator;
|
||||
*fractional += dividend;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
#
|
||||
# Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
# All rights reserved. Provided under license only.
|
||||
# Distribution or other use of this software is only
|
||||
# permitted pursuant to the terms of a license agreement
|
||||
# from Wind River Systems (and is otherwise prohibited).
|
||||
# Refer to that license agreement for terms of use.
|
||||
#
|
||||
|
||||
# [clearcase]
|
||||
# modification history
|
||||
# -------------------
|
||||
# 01b,01aug07,jbl filenames change so makefile changes
|
||||
# 01a,20apr05,job update copyright notices
|
||||
#
|
||||
#
|
||||
# common/lib
|
||||
#
|
||||
|
||||
$#equate(PRODUCTH $#filepath($(SRCDIR) target h wrn wm common))
|
||||
|
||||
$#makefile-init()
|
||||
|
||||
##############################################################################
|
||||
# OBJECT FILE DEFINITION SECTION
|
||||
|
||||
$#equate(WEAKPRNG_OBJS $#objs(weakprng))
|
||||
$#equate(PRNG_OBJS $#if-installed(COMMON_PRNG $#objs(prng)))
|
||||
$#equate(MD4_OBJS $#if-installed(COMMON_MD4 $#objs(md4)))
|
||||
$#equate(MD5_OBJS $#if-installed(COMMON_MD5 $#objs(snmpMd5)))
|
||||
$#equate(SHA_OBJS $#if-installed(COMMON_SHA $#objs(snmpSha)))
|
||||
$#equate(HMAC_OBJS $#if-installed(COMMON_HMAC $#objs(snmpHmac)))
|
||||
$#equate(DESTESTOBJS $#objs(des_test))
|
||||
|
||||
$#equate(STRING_OBJS
|
||||
$#if-installed(COMMON_STRTOL $#objs(strtol))
|
||||
$#if-installed(COMMON_STRTOUL $#objs(strtoul))
|
||||
$#if-installed(COMMON_STRICMP $#objs(stricmp))
|
||||
$#if-installed(COMMON_STRNICMP $#objs(strnicmp))
|
||||
$#if-installed(COMMON_MEMCMP $#objs(memcmp))
|
||||
$#if-installed(COMMON_SNPRINTF $#objs(snprintf))
|
||||
$#if-installed(COMMON_STRNCPY $#objs(strncpy))
|
||||
)
|
||||
|
||||
$#equate(THREAD_OBJS $#if-installed(THREAD_DEBUG $#objs(thd_dbg)))
|
||||
|
||||
$#equate(FIXED64_OBJS $#if-installed(COMMON_FIXED64 $#objs(fixed64)))
|
||||
|
||||
$#equate(OBJS $#objs(cmn_init)
|
||||
$#(WEAKPRNG_OBJS)
|
||||
$#(PRNG_OBJS)
|
||||
$#(MD4_OBJS)
|
||||
$#(MD5_OBJS)
|
||||
$#(SHA_OBJS)
|
||||
$#(HMAC_OBJS)
|
||||
$#(STRING_OBJS)
|
||||
$#(THREAD_OBJS)
|
||||
$#(FIXED64_OBJS))
|
||||
|
||||
all: $#libs(epcommon) $#if-installed(COMMON_DES_TEST $#exes(des_test)) $#dummy()
|
||||
|
||||
##############################################################################
|
||||
# Make the library itself
|
||||
|
||||
$#makelib(epcommon $#(OBJS) $(MAKEFILENAME))
|
||||
|
||||
##############################################################################
|
||||
# Make the des verification program
|
||||
$#makeexe(des_test $#progn($#(DESTESTOBJS)) $#progn($#libs(epcommon) $#libs(epdes)) $(MAKEFILENAME))
|
||||
|
||||
##############################################################################
|
||||
# commands to figure out how big this all compiles to
|
||||
|
||||
sizes: $#dummy()
|
||||
$#makesizehdr(Epilogue Common)
|
||||
$#if-installed(COMMON_PRNG $#makesize(PRNG $(PRNG_OBJS))
|
||||
$#makesizenone(PRNG))
|
||||
$#if-installed(COMMON_MD4 $#makesize(MD4 $(MD4_OBJS))
|
||||
$#makesizenone(MD4))
|
||||
$#if-installed(COMMON_MD5 $#makesize(MD5 $(MD5_OBJS))
|
||||
$#makesizenone(MD5))
|
||||
$#if-installed(COMMON_SHA $#makesize(SHA $(SHA_OBJS))
|
||||
$#makesizenone(SHA))
|
||||
$#if-installed(COMMON_HMAC $#makesize(HMAC $(HMAC_OBJS))
|
||||
$#makesizenone(HMAC))
|
||||
$#makesize(WEAKPRNG $(WEAKPRNG_OBJS))
|
||||
|
||||
clean: $#dummy()
|
||||
-$(RM) $#objs(*)
|
||||
-$(RM) $#libs(epcommon)
|
||||
-$(RM) $#libs(epdes)
|
||||
-$(RM) $#exes(des_test)
|
||||
$#clean()
|
||||
|
||||
##############################################################################
|
||||
# file dependencies
|
||||
|
||||
$#objs(cmn_init) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common cmn_init.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common prng.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
cmn_init.c
|
||||
)
|
||||
$#objs(des_test) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common des.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
des_test.c
|
||||
)
|
||||
$#objs(fixed64) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common bug.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common bugdef.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common fixed64.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
fixed64.c
|
||||
)
|
||||
$#objs(hmac) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common hmac.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
hmac.c
|
||||
)
|
||||
$#objs(md4) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common glue.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common md4.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common snprintf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
md4.c
|
||||
)
|
||||
$#objs(md5) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common md5.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
md5.c
|
||||
)
|
||||
$#objs(memcmp) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
memcmp.c
|
||||
)
|
||||
$#objs(prng) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common md5.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common prng.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
prng.c
|
||||
)
|
||||
$#objs(sha) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common sha.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
sha.c
|
||||
)
|
||||
$#objs(snprintf) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common snprintf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
snprintf.c
|
||||
)
|
||||
$#objs(stricmp) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
stricmp.c
|
||||
)
|
||||
$#objs(strncpy) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
strncpy.c
|
||||
)
|
||||
$#objs(strnicmp) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
strnicmp.c
|
||||
)
|
||||
$#objs(strtol) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
strtol.c
|
||||
)
|
||||
$#objs(strtoul) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common stdf.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
strtoul.c
|
||||
)
|
||||
$#objs(thd_dbg) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm attache config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm attache packet.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common bug.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common bugdef.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common thread.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(attache.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
$#port-hdr(thdport.h)
|
||||
thd_dbg.c
|
||||
)
|
||||
$#objs(weakprng) : $##backslashes(
|
||||
$#filepath($(SRCDIR) target h wrn wm common config.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common glue.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common types.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common weakprng.h)
|
||||
$#filepath($(SRCDIR) target h wrn wm common install.h)
|
||||
$#port-hdr(common.h)
|
||||
$#port-hdr(oemtypes.h)
|
||||
weakprng.c
|
||||
)
|
||||
@@ -0,0 +1,324 @@
|
||||
/*
|
||||
* $Log: md4.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:55 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:51 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.4 2001/01/19 22:21:31 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.3 2000/03/17 00:16:54 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.2 1999/09/13 19:23:20 wes
|
||||
* Rename index to idx to squelch compiler warning
|
||||
*
|
||||
* Revision 1.1 1999/08/11 21:18:04 bala
|
||||
* MD4 functions
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
/* Epilogue changes for type names and CVS info only */
|
||||
|
||||
/* MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm
|
||||
*/
|
||||
|
||||
/* Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved.
|
||||
|
||||
License to copy and use this software is granted provided that it
|
||||
is identified as the "RSA Data Security, Inc. MD4 Message-Digest
|
||||
Algorithm" in all material mentioning or referencing this software
|
||||
or this function.
|
||||
|
||||
License is also granted to make and use derivative works provided
|
||||
that such works are identified as "derived from the RSA Data
|
||||
Security, Inc. MD4 Message-Digest Algorithm" in all material
|
||||
mentioning or referencing the derived work.
|
||||
|
||||
RSA Data Security, Inc. makes no representations concerning either
|
||||
the merchantability of this software or the suitability of this
|
||||
software for any particular purpose. It is provided "as is"
|
||||
without express or implied warranty of any kind.
|
||||
|
||||
These notices must be retained in any copies of any part of this
|
||||
documentation and/or software.
|
||||
*/
|
||||
#ifndef EPILOGUE_INSTALL_H
|
||||
#include <wrn/wm/common/install.h>
|
||||
#endif
|
||||
|
||||
#if INSTALL_COMMON_MD4
|
||||
|
||||
#ifndef EPILOGUE_TYPES_H
|
||||
#include <wrn/wm/common/types.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_CONFIG_H
|
||||
#include <wrn/wm/common/config.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_GLUE_H
|
||||
#include <wrn/wm/common/glue.h>
|
||||
#endif
|
||||
|
||||
#ifndef __MD4_INCLUDE__
|
||||
#include <wrn/wm/common/md4.h>
|
||||
#endif
|
||||
|
||||
/* Constants for MD4Transform routine.
|
||||
*/
|
||||
#define S11 3
|
||||
#define S12 7
|
||||
#define S13 11
|
||||
#define S14 19
|
||||
#define S21 3
|
||||
#define S22 5
|
||||
#define S23 9
|
||||
#define S24 13
|
||||
#define S31 3
|
||||
#define S32 9
|
||||
#define S33 11
|
||||
#define S34 15
|
||||
|
||||
static void MD4Transform __((bits32_t [4], bits8_t [64]));
|
||||
static void Encode __((bits8_t *, bits32_t *, bits32_t));
|
||||
static void Decode __((bits32_t *, bits8_t *, bits32_t));
|
||||
|
||||
static bits8_t PADDING[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
/* F, G and H are basic MD4 functions.
|
||||
*/
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
|
||||
/* ROTATE_LEFT rotates x left n bits.
|
||||
*/
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
/* FF, GG and HH are transformations for rounds 1, 2 and 3 */
|
||||
/* Rotation is separate from addition to prevent recomputation */
|
||||
|
||||
#define FF(a, b, c, d, x, s) { \
|
||||
(a) += F ((b), (c), (d)) + (x); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
}
|
||||
#define GG(a, b, c, d, x, s) { \
|
||||
(a) += G ((b), (c), (d)) + (x) + (bits32_t)0x5a827999; \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
}
|
||||
#define HH(a, b, c, d, x, s) { \
|
||||
(a) += H ((b), (c), (d)) + (x) + (bits32_t)0x6ed9eba1; \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
}
|
||||
|
||||
/* MD4 initialization. Begins an MD4 operation, writing a new context.
|
||||
*/
|
||||
void MD4Init (context)
|
||||
MD4_CTX *context; /* context */
|
||||
{
|
||||
context->count[0] = context->count[1] = 0;
|
||||
|
||||
/* Load magic initialization constants.
|
||||
*/
|
||||
context->state[0] = 0x67452301;
|
||||
context->state[1] = 0xefcdab89;
|
||||
context->state[2] = 0x98badcfe;
|
||||
context->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
/* MD4 block update operation. Continues an MD4 message-digest
|
||||
operation, processing another message block, and updating the
|
||||
context.
|
||||
*/
|
||||
void MD4Update (context, input, inputLen)
|
||||
MD4_CTX *context; /* context */
|
||||
bits8_t *input; /* input block */
|
||||
bits32_t inputLen; /* length of input block */
|
||||
{
|
||||
bits32_t i, idx, partLen;
|
||||
|
||||
/* Compute number of bytes mod 64 */
|
||||
idx = (bits32_t)((context->count[0] >> 3) & 0x3F);
|
||||
/* Update number of bits */
|
||||
if ((context->count[0] += ((bits32_t)inputLen << 3))
|
||||
< ((bits32_t)inputLen << 3))
|
||||
context->count[1]++;
|
||||
context->count[1] += ((bits32_t)inputLen >> 29);
|
||||
|
||||
partLen = 64 - idx;
|
||||
|
||||
/* Transform as many times as possible.
|
||||
*/
|
||||
if (inputLen >= partLen) {
|
||||
MEMCPY(&context->buffer[idx], input, partLen);
|
||||
MD4Transform (context->state, context->buffer);
|
||||
|
||||
for (i = partLen; i + 63 < inputLen; i += 64)
|
||||
MD4Transform (context->state, &input[i]);
|
||||
|
||||
idx = 0;
|
||||
}
|
||||
else
|
||||
i = 0;
|
||||
|
||||
/* Buffer remaining input */
|
||||
MEMCPY(&context->buffer[idx], &input[i],
|
||||
inputLen-i);
|
||||
}
|
||||
|
||||
/* MD4 finalization. Ends an MD4 message-digest operation, writing the
|
||||
the message digest and zeroizing the context.
|
||||
*/
|
||||
void MD4Final (digest, context)
|
||||
bits8_t digest[16]; /* message digest */
|
||||
MD4_CTX *context; /* context */
|
||||
{
|
||||
bits8_t bits[8];
|
||||
bits32_t idx, padLen;
|
||||
|
||||
/* Save number of bits */
|
||||
Encode (bits, context->count, 8);
|
||||
|
||||
/* Pad out to 56 mod 64.
|
||||
*/
|
||||
idx = (bits32_t)((context->count[0] >> 3) & 0x3f);
|
||||
padLen = (idx < 56) ? (56 - idx) : (120 - idx);
|
||||
MD4Update (context, PADDING, padLen);
|
||||
|
||||
/* Append length (before padding) */
|
||||
MD4Update (context, bits, 8);
|
||||
/* Store state in digest */
|
||||
Encode (digest, context->state, 16);
|
||||
|
||||
/* Zeroize sensitive information.
|
||||
*/
|
||||
MEMSET(context, 0, sizeof (*context));
|
||||
}
|
||||
|
||||
/* MD4 basic transformation. Transforms state based on block.
|
||||
*/
|
||||
static void MD4Transform (state, block)
|
||||
bits32_t state[4];
|
||||
bits8_t block[64];
|
||||
{
|
||||
bits32_t a = state[0], b = state[1], c = state[2], d = state[3], x[16];
|
||||
|
||||
Decode (x, block, 64);
|
||||
|
||||
/* Round 1 */
|
||||
FF (a, b, c, d, x[ 0], S11); /* 1 */
|
||||
FF (d, a, b, c, x[ 1], S12); /* 2 */
|
||||
FF (c, d, a, b, x[ 2], S13); /* 3 */
|
||||
FF (b, c, d, a, x[ 3], S14); /* 4 */
|
||||
FF (a, b, c, d, x[ 4], S11); /* 5 */
|
||||
FF (d, a, b, c, x[ 5], S12); /* 6 */
|
||||
FF (c, d, a, b, x[ 6], S13); /* 7 */
|
||||
FF (b, c, d, a, x[ 7], S14); /* 8 */
|
||||
FF (a, b, c, d, x[ 8], S11); /* 9 */
|
||||
FF (d, a, b, c, x[ 9], S12); /* 10 */
|
||||
FF (c, d, a, b, x[10], S13); /* 11 */
|
||||
FF (b, c, d, a, x[11], S14); /* 12 */
|
||||
FF (a, b, c, d, x[12], S11); /* 13 */
|
||||
FF (d, a, b, c, x[13], S12); /* 14 */
|
||||
FF (c, d, a, b, x[14], S13); /* 15 */
|
||||
FF (b, c, d, a, x[15], S14); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
GG (a, b, c, d, x[ 0], S21); /* 17 */
|
||||
GG (d, a, b, c, x[ 4], S22); /* 18 */
|
||||
GG (c, d, a, b, x[ 8], S23); /* 19 */
|
||||
GG (b, c, d, a, x[12], S24); /* 20 */
|
||||
GG (a, b, c, d, x[ 1], S21); /* 21 */
|
||||
GG (d, a, b, c, x[ 5], S22); /* 22 */
|
||||
GG (c, d, a, b, x[ 9], S23); /* 23 */
|
||||
GG (b, c, d, a, x[13], S24); /* 24 */
|
||||
GG (a, b, c, d, x[ 2], S21); /* 25 */
|
||||
GG (d, a, b, c, x[ 6], S22); /* 26 */
|
||||
GG (c, d, a, b, x[10], S23); /* 27 */
|
||||
GG (b, c, d, a, x[14], S24); /* 28 */
|
||||
GG (a, b, c, d, x[ 3], S21); /* 29 */
|
||||
GG (d, a, b, c, x[ 7], S22); /* 30 */
|
||||
GG (c, d, a, b, x[11], S23); /* 31 */
|
||||
GG (b, c, d, a, x[15], S24); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
HH (a, b, c, d, x[ 0], S31); /* 33 */
|
||||
HH (d, a, b, c, x[ 8], S32); /* 34 */
|
||||
HH (c, d, a, b, x[ 4], S33); /* 35 */
|
||||
HH (b, c, d, a, x[12], S34); /* 36 */
|
||||
HH (a, b, c, d, x[ 2], S31); /* 37 */
|
||||
HH (d, a, b, c, x[10], S32); /* 38 */
|
||||
HH (c, d, a, b, x[ 6], S33); /* 39 */
|
||||
HH (b, c, d, a, x[14], S34); /* 40 */
|
||||
HH (a, b, c, d, x[ 1], S31); /* 41 */
|
||||
HH (d, a, b, c, x[ 9], S32); /* 42 */
|
||||
HH (c, d, a, b, x[ 5], S33); /* 43 */
|
||||
HH (b, c, d, a, x[13], S34); /* 44 */
|
||||
HH (a, b, c, d, x[ 3], S31); /* 45 */
|
||||
HH (d, a, b, c, x[11], S32); /* 46 */
|
||||
HH (c, d, a, b, x[ 7], S33); /* 47 */
|
||||
HH (b, c, d, a, x[15], S34); /* 48 */
|
||||
|
||||
state[0] += a;
|
||||
state[1] += b;
|
||||
state[2] += c;
|
||||
state[3] += d;
|
||||
|
||||
/* Zeroize sensitive information.
|
||||
*/
|
||||
MEMSET(x, 0, sizeof (x));
|
||||
}
|
||||
|
||||
/* Encodes input (bits32_t) into output (bits8_t). Assumes len is
|
||||
a multiple of 4.
|
||||
*/
|
||||
static void Encode (output, input, len)
|
||||
bits8_t *output;
|
||||
bits32_t *input;
|
||||
bits32_t len;
|
||||
{
|
||||
bits32_t i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4) {
|
||||
output[j] = (bits8_t)(input[i] & 0xff);
|
||||
output[j+1] = (bits8_t)((input[i] >> 8) & 0xff);
|
||||
output[j+2] = (bits8_t)((input[i] >> 16) & 0xff);
|
||||
output[j+3] = (bits8_t)((input[i] >> 24) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
/* Decodes input (bits8_t) into output (bits32_t). Assumes len is
|
||||
a multiple of 4.
|
||||
*/
|
||||
static void Decode (output, input, len)
|
||||
|
||||
bits32_t *output;
|
||||
bits8_t *input;
|
||||
bits32_t len;
|
||||
{
|
||||
bits32_t i, j;
|
||||
|
||||
for (i = 0, j = 0; j < len; i++, j += 4)
|
||||
output[i] = ((bits32_t)input[j]) | (((bits32_t)input[j+1]) << 8) |
|
||||
(((bits32_t)input[j+2]) << 16) | (((bits32_t)input[j+3]) << 24);
|
||||
}
|
||||
|
||||
#endif /* INSTALL_COMMON_MD4 */
|
||||
@@ -0,0 +1,79 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/memcmp.c,v 1.3 2003/01/16 18:18:56 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: memcmp.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:56 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:52 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.5 2001/01/19 22:21:31 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.4 2000/03/17 00:16:54 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.3 1999/04/09 20:33:47 wes
|
||||
* re-constify. let's see what, if anything, blows up
|
||||
*
|
||||
* Revision 1.2 1998/07/04 00:29:23 sra
|
||||
* Remove "const" tags, more trouble than they are worth.
|
||||
*
|
||||
* Revision 1.1 1998/07/03 20:19:16 sra
|
||||
* Add etc_memcmp().
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/stdf.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
/*
|
||||
* Portable implementation of ISO C memcmp() function for platforms
|
||||
* that don't have it or have a broken version.
|
||||
*
|
||||
* ISO C clearly states that memcmp() compares unsigned characters
|
||||
* (each byte to be considered in the range 0..255), but a number
|
||||
* of implementations seem to get this wrong, probably for historical
|
||||
* reasons.
|
||||
*/
|
||||
|
||||
int
|
||||
etc_memcmp(const void *v1, const void *v2, size_t len)
|
||||
{
|
||||
unsigned const char *b1 = v1, *b2 = v2;
|
||||
int result = 0;
|
||||
|
||||
while (len-- > 0)
|
||||
if ((result = (*b1++) - (*b2++)) != 0)
|
||||
break;
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/prng.c,v 1.3 2003/01/16 18:18:56 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998-1999 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: prng.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:56 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:53 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.17 2001/01/19 22:21:31 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.16 2000/03/17 00:16:55 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.15 2000/03/13 21:21:47 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 1.14 1999/04/28 23:53:24 sra
|
||||
* Clean up various minor installation option glitches.
|
||||
*
|
||||
* Revision 1.13 1999/03/06 06:54:36 paul
|
||||
* moved common_init from prng.c to cmn_init.c
|
||||
*
|
||||
* Revision 1.11.2.1 1999/01/04 20:57:58 wes
|
||||
* Shut up purify.
|
||||
*
|
||||
* Revision 1.11 1998/09/11 16:30:41 paul
|
||||
* Auto-initialize common library.
|
||||
*
|
||||
* Revision 1.10 1998/06/25 20:40:06 sra
|
||||
* Fix CAD-UL warning in prng_init().
|
||||
*
|
||||
* Revision 1.9 1998/02/25 04:43:28 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.8 1997/10/30 16:42:34 sra
|
||||
* Fix copyright date.
|
||||
*
|
||||
* Revision 1.7 1997/08/21 17:23:43 sra
|
||||
* Begin moving configuration stuff that's common to all products to common.h
|
||||
* Minor cleanups to common/lib/prng.c. Add pnrg seed function to snarkbsd.
|
||||
*
|
||||
* Revision 1.6 1997/08/19 23:05:54 meister
|
||||
* Made some variables static that were global (and shouldnt have been).
|
||||
* Generated reasonable values for the two magic constants PRNG_MAGIC[12]
|
||||
*
|
||||
* Revision 1.5 1997/08/14 21:42:13 meister
|
||||
* ifdef'd out the linear congruential generator, and added the crypto-strong
|
||||
* one.
|
||||
*
|
||||
* Revision 1.4 1997/08/14 16:04:39 lowell
|
||||
* boilerplate
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#ifndef EPILOGUE_INSTALL_H
|
||||
#include <wrn/wm/common/install.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_CONFIG_H
|
||||
#include <wrn/wm/common/config.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_PRNG_H
|
||||
#include <wrn/wm/common/prng.h>
|
||||
#endif
|
||||
|
||||
#ifndef __MD5_INCLUDE__
|
||||
#include <wrn/wm/common/md5.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_GLUE_H
|
||||
#include <wrn/wm/common/glue.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file implements a cryptographically strong random number generator.
|
||||
* The algorithm is based on the ANSI X9.17 generator. Keyed MD5 is used
|
||||
* as the basic transform rather than TDES. The DT value is augmented with
|
||||
* a monotonically increasing counter. See [Stallings - Network and
|
||||
* Internetwork Security pp 102-103] or ANSI X9.17 Appendix C.
|
||||
*/
|
||||
|
||||
static void prng_iterate (void);
|
||||
|
||||
/*
|
||||
* these next 2 bits of magic are used to seed the generator with
|
||||
* less than 32 bytes of randomness. If the user hands in N < 32 bytes (call
|
||||
* them "B") we generate MD5 (MAGIC1 "+" B "+" MAGIC1), and
|
||||
* MD5 (MAGIC2 "+" B "+" MAGIC2), and combine them to get our needed 32 bytes.
|
||||
* The actual values here are *not* of any importance, although having a
|
||||
* reasonably "random" bit distribution is useful. These were generated by
|
||||
* running some real-time system statistics through MD5.
|
||||
*/
|
||||
|
||||
static bits8_t PRNG_MAGIC1 [] =
|
||||
{ 0xb4, 0x33, 0x4b, 0xf5, 0x9b, 0x7a, 0x24, 0x19,
|
||||
0x8c, 0x04, 0xa5, 0xd1, 0x1e, 0xab, 0xa2, 0xe9
|
||||
};
|
||||
|
||||
static bits8_t PRNG_MAGIC2 [] =
|
||||
{ 0xaa, 0x9b, 0x49, 0xd4, 0x0f, 0x4c, 0xa7, 0x1b,
|
||||
0x1d, 0x0e, 0x83, 0xd6, 0xe7, 0x9c, 0xab, 0xf8
|
||||
};
|
||||
|
||||
#define PRNG_SEEDBYTES_NEEDED 32
|
||||
|
||||
static MD5_CTX PRNG_MD5_CTX;
|
||||
|
||||
/* new seed buffer for prng_get_seed () */
|
||||
static bits8_t PRNG_SB [PRNG_SEEDBYTES_NEEDED];
|
||||
|
||||
static bits8_t PRNG_MD5_K [16]; /* MD5 keyed hash key */
|
||||
static bits8_t PRNG_SV [16]; /* current seed value */
|
||||
static bits8_t PRNG_R [16]; /* current random pool */
|
||||
static bits32_t PRNG_DT; /* "date+time" value */
|
||||
static bits32_t PRNG_CNT; /* counter; increments with each call */
|
||||
static bits8_t PRNG_N; /* number of "random" bytes currently available */
|
||||
static bits8_t PRNG_INJIDX; /* index of PRNG_SV where prng_inject_random8 will
|
||||
xor next random input into */
|
||||
|
||||
/*
|
||||
* Initialize the prng system. This involves calling out for seed bytes. 32
|
||||
* of them, in fact.
|
||||
*/
|
||||
void prng_init (void)
|
||||
{
|
||||
bits8_t seedvalues [PRNG_SEEDBYTES_NEEDED];
|
||||
bits32_t actual;
|
||||
|
||||
MEMSET(seedvalues, 0, PRNG_SEEDBYTES_NEEDED);
|
||||
|
||||
actual = GLUE_SEED_PRNG(seedvalues, PRNG_SEEDBYTES_NEEDED);
|
||||
|
||||
if (actual < PRNG_SEEDBYTES_NEEDED)
|
||||
{
|
||||
MD5Init (&PRNG_MD5_CTX);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MAGIC1, 16);
|
||||
if (actual > 0)
|
||||
MD5Update (&PRNG_MD5_CTX, (bits8_t *) seedvalues, actual);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MAGIC1, 16);
|
||||
MD5Final (&PRNG_MD5_CTX);
|
||||
MEMCPY(PRNG_MD5_K, PRNG_MD5_CTX.digest, 16);
|
||||
|
||||
MD5Init (&PRNG_MD5_CTX);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MAGIC2, 16);
|
||||
MD5Update (&PRNG_MD5_CTX, (bits8_t *) seedvalues, actual);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MAGIC2, 16);
|
||||
MD5Final (&PRNG_MD5_CTX);
|
||||
MEMCPY(PRNG_SV, PRNG_MD5_CTX.digest, 16);
|
||||
|
||||
MEMCPY(&PRNG_CNT, seedvalues, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
MEMCPY(PRNG_SV, seedvalues, 16);
|
||||
MEMCPY(PRNG_MD5_K, seedvalues + 16, 16);
|
||||
MEMCPY(&PRNG_CNT, seedvalues, 4);
|
||||
}
|
||||
PRNG_DT = GLUE_NOW();
|
||||
PRNG_N = PRNG_INJIDX = 0;
|
||||
prng_iterate (); /* kick start the PRNG */
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* compute next seed value and state
|
||||
*/
|
||||
|
||||
static void prng_iterate (void)
|
||||
{
|
||||
int i;
|
||||
bits8_t *p, *q;
|
||||
bits8_t digest [16];
|
||||
|
||||
/* step 1. R = MD5_K (MD5_K ((DT concat (++CNT)) XOR SV)) */
|
||||
|
||||
/* digest <-- MD5 ((DT concat (++CNT)) XOR SV */
|
||||
++PRNG_CNT;
|
||||
PRNG_DT = GLUE_NOW();
|
||||
MD5Init (&PRNG_MD5_CTX);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MD5_K, 16);
|
||||
MD5Update (&PRNG_MD5_CTX, (bits8_t *) &PRNG_DT, 4);
|
||||
MD5Update (&PRNG_MD5_CTX, (bits8_t *) &PRNG_CNT, 4);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MD5_K, 16);
|
||||
MD5Final (&PRNG_MD5_CTX);
|
||||
MEMCPY(digest, PRNG_MD5_CTX.digest, 16);
|
||||
|
||||
/* PRNG_SV <-- (PRNG_SV XOR digest) */
|
||||
/* leave digest alone as we'll need it again when we compute new SV */
|
||||
for (i = 0, p = PRNG_SV, q = digest; i < 16 ; i++)
|
||||
*p++ ^= *q++;
|
||||
|
||||
/* PRNG_R <-- MD5 (PRNG_SV) */
|
||||
MD5Init (&PRNG_MD5_CTX);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MD5_K, 16);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_SV, 16);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MD5_K, 16);
|
||||
MD5Final (&PRNG_MD5_CTX);
|
||||
MEMCPY(PRNG_R, PRNG_MD5_CTX.digest, 16);
|
||||
|
||||
/*
|
||||
* step 2. SV = MD5_K (MD5_K ((DT concat (++CNT)) XOR R))
|
||||
*
|
||||
* digest is still MD5_K ((DT concat (++CNT)), so we dont need another
|
||||
* MD5 operation
|
||||
*/
|
||||
/* PRNG_SV <-- (PRNG_SV XOR digest) */
|
||||
for (i = 0, p = PRNG_R, q = digest; i < 16 ; i++)
|
||||
*q++ ^= *p++;
|
||||
|
||||
MD5Init (&PRNG_MD5_CTX);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MD5_K, 16);
|
||||
MD5Update (&PRNG_MD5_CTX, (bits8_t *) digest, 16);
|
||||
MD5Update (&PRNG_MD5_CTX, PRNG_MD5_K, 16);
|
||||
MD5Final (&PRNG_MD5_CTX);
|
||||
MEMCPY(PRNG_SV, PRNG_MD5_CTX.digest, 16);
|
||||
|
||||
/* now we have another 16 bytes of usable R */
|
||||
|
||||
PRNG_N = 16;
|
||||
}
|
||||
|
||||
/*
|
||||
* hand back a "random" byte
|
||||
*/
|
||||
|
||||
bits8_t prng_random8 (void)
|
||||
{
|
||||
if (!PRNG_N)
|
||||
prng_iterate ();
|
||||
|
||||
return PRNG_R [--PRNG_N];
|
||||
}
|
||||
|
||||
/*
|
||||
* fill up a buffer with "random" bytes
|
||||
*/
|
||||
|
||||
void prng_random (bits8_t *buf, int N)
|
||||
{
|
||||
while (N--)
|
||||
*buf++ = prng_random8 ();
|
||||
}
|
||||
|
||||
void prng_get_seed(bits8_t **buffer, int * bufsize)
|
||||
{
|
||||
prng_iterate ();
|
||||
|
||||
MEMCPY(PRNG_SB, PRNG_SV, 16);
|
||||
MEMCPY(PRNG_SB + 16, PRNG_R, 16);
|
||||
|
||||
prng_iterate ();
|
||||
|
||||
*buffer = PRNG_SB;
|
||||
*bufsize = PRNG_SEEDBYTES_NEEDED;
|
||||
}
|
||||
|
||||
void prng_inject_random8 (bits8_t in)
|
||||
{
|
||||
PRNG_SV [PRNG_INJIDX & 0xF] ^= in;
|
||||
PRNG_INJIDX++;
|
||||
|
||||
#ifndef PRNG_INJECT_IMMEDIATE_EFFECT
|
||||
prng_iterate ();
|
||||
#else
|
||||
if (!(PRNG_INJIDX & 0xF))
|
||||
prng_iterate ();
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/hmac.c,v 1.3 2003/01/16 18:18:55 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005, 2013 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: hmac.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:55 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:51 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.6 2001/01/19 22:21:30 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.5 2000/03/17 00:16:53 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.4 1998/09/04 14:02:28 sar
|
||||
* Convert some ints to unsigned ints to make some compliers happier
|
||||
*
|
||||
* Revision 1.3 1998/06/21 21:40:55 sar
|
||||
* More type checking stuff to keep compilers happy
|
||||
*
|
||||
* Revision 1.2 1998/06/18 04:11:23 sar
|
||||
* clean u psome type info, make the lengths be bits32_t
|
||||
*
|
||||
* Revision 1.1 1998/05/22 18:03:07 sar
|
||||
* HMAC functions, this code is arranged so that the user can insert their
|
||||
* own digest functions such as MD5 or SHA
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01d,14may13,bbz correct the VSB building errors(WIND00417424)
|
||||
01c,08may13,bbz clear the high impact warning from prevent.pl(WIND00416598)
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#ifndef EPILOGUE_INSTALL_H
|
||||
#include <wrn/wm/common/install.h>
|
||||
#endif /* EPILOGUE_INSTALL_H */
|
||||
|
||||
#ifndef EPILOGUE_TYPES_H
|
||||
#include <wrn/wm/common/types.h>
|
||||
#endif /* EPILOGUE_TYPES_H */
|
||||
|
||||
#ifndef COMMON_CONFIG_H
|
||||
#include <wrn/wm/common/config.h>
|
||||
#endif /* COMMON_CONFIG_H */
|
||||
|
||||
#ifndef COMMON_GLUE_H
|
||||
#include <wrn/wm/common/glue.h>
|
||||
#endif /* COMMON_GLUE_H */
|
||||
|
||||
#include <wrn/wm/common/hmac.h>
|
||||
|
||||
/* initialize an HMAC context */
|
||||
void InitHmacCTX (HMAC_CTX *ctx,
|
||||
hashfcn_init_t init,
|
||||
hashfcn_update_t update,
|
||||
hashfcn_final_t final,
|
||||
bits32_t hashsiz)
|
||||
{
|
||||
ctx->hmac_hashinit = init;
|
||||
ctx->hmac_hashupdate = update;
|
||||
ctx->hmac_hashfinal = final;
|
||||
ctx->hmac_hashlen = hashsiz;
|
||||
}
|
||||
|
||||
void hmac_init (HMAC_CTX *ctx,
|
||||
bits8_t *key,
|
||||
bits32_t keylen)
|
||||
{
|
||||
bits8_t xk [64];
|
||||
unsigned int i;
|
||||
|
||||
/*
|
||||
* if we have more than 64 bytes of key, hash that first using the
|
||||
* given hash algorithm.
|
||||
*/
|
||||
if (keylen > 64)
|
||||
{
|
||||
(*(ctx->hmac_hashinit))(ctx->hmac_state);
|
||||
(*(ctx->hmac_hashupdate))(ctx->hmac_state, key, keylen);
|
||||
(*(ctx->hmac_hashfinal))(ctx->hmac_state, xk);
|
||||
|
||||
/* K XOR input pad of 0x36's */
|
||||
for (i = 0 ; i < ctx->hmac_hashlen; i++)
|
||||
xk [i] ^= ((bits8_t) 0x36);
|
||||
|
||||
MEMSET (xk + (unsigned int)ctx->hmac_hashlen, 0x36,
|
||||
64 - (unsigned int)ctx->hmac_hashlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* K XOR input pad of 0x36's */
|
||||
for (i = 0 ; i < keylen; i++)
|
||||
xk [i] = key [i] ^ ((bits8_t) 0x36);
|
||||
if (keylen < 64)
|
||||
MEMSET (xk + (unsigned int)keylen, 0x36, 64 - (unsigned int)keylen);
|
||||
|
||||
}
|
||||
|
||||
(*(ctx->hmac_hashinit))(ctx->hmac_state);
|
||||
(*(ctx->hmac_hashupdate))(ctx->hmac_state, xk, 64);
|
||||
|
||||
}
|
||||
|
||||
void hmac_update (HMAC_CTX *ctx,
|
||||
bits8_t *data,
|
||||
bits32_t len)
|
||||
{
|
||||
(*(ctx->hmac_hashupdate))(ctx->hmac_state, data, len);
|
||||
}
|
||||
|
||||
void hmac_final (HMAC_CTX *ctx,
|
||||
bits8_t *key,
|
||||
bits32_t keylen,
|
||||
bits8_t *output)
|
||||
{
|
||||
|
||||
bits8_t xk [64];
|
||||
unsigned int i;
|
||||
|
||||
(*(ctx->hmac_hashfinal))(ctx->hmac_state, ctx->hmac_tmp);
|
||||
|
||||
/*
|
||||
* if we have more than 64 bytes of key, hash that first using the
|
||||
* given hash algorithm.
|
||||
*/
|
||||
if (keylen > 64)
|
||||
{
|
||||
(*(ctx->hmac_hashinit))(ctx->hmac_state);
|
||||
(*(ctx->hmac_hashupdate))(ctx->hmac_state, key, keylen);
|
||||
(*(ctx->hmac_hashfinal))(ctx->hmac_state, xk);
|
||||
|
||||
/* K XOR output pad of 0x5c's */
|
||||
for (i = 0 ; i < ctx->hmac_hashlen; i++)
|
||||
xk [i] ^= ((bits8_t) 0x5c);
|
||||
|
||||
MEMSET (xk + (unsigned int)ctx->hmac_hashlen, 0x5c,
|
||||
64 - (unsigned int)ctx->hmac_hashlen);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* K XOR output pad of 0x5c's */
|
||||
for (i = 0 ; i < keylen; i++)
|
||||
xk [i] = key [i] ^ ((bits8_t) 0x5c);
|
||||
if (keylen < 64)
|
||||
MEMSET (xk + (unsigned int)keylen, 0x5c, 64 - (unsigned int)keylen);
|
||||
}
|
||||
|
||||
(*(ctx->hmac_hashinit))(ctx->hmac_state);
|
||||
(*(ctx->hmac_hashupdate))(ctx->hmac_state, xk, 64);
|
||||
(*(ctx->hmac_hashupdate))(ctx->hmac_state, ctx->hmac_tmp,
|
||||
ctx->hmac_hashlen);
|
||||
(*(ctx->hmac_hashfinal))(ctx->hmac_state, output);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,343 @@
|
||||
/* Wind River changed symbol names to remove conflicts */
|
||||
/* Epilogue changes for type names and CVS info only */
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
** md5.c -- the source code for MD5 routines **
|
||||
** RSA Data Security, Inc. MD5 Message-Digest Algorithm **
|
||||
** Created: 2/17/90 RLR **
|
||||
** Revised: 1/91 SRD,AJ,BSK,JT Reference C ver., 7/10 constant corr. **
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
|
||||
** **
|
||||
** License to copy and use this software is granted provided that **
|
||||
** it is identified as the "RSA Data Security, Inc. MD5 Message- **
|
||||
** Digest Algorithm" in all material mentioning or referencing this **
|
||||
** software or this function. **
|
||||
** **
|
||||
** License is also granted to make and use derivative works **
|
||||
** provided that such works are identified as "derived from the RSA **
|
||||
** Data Security, Inc. MD5 Message-Digest Algorithm" in all **
|
||||
** material mentioning or referencing the derived work. **
|
||||
** **
|
||||
** RSA Data Security, Inc. makes no representations concerning **
|
||||
** either the merchantability of this software or the suitability **
|
||||
** of this software for any particular purpose. It is provided "as **
|
||||
** is" without express or implied warranty of any kind. **
|
||||
** **
|
||||
** These notices must be retained in any copies of any part of this **
|
||||
** documentation and/or software. **
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: md5.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:56 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:52 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.7 1998/03/11 23:06:04 meister
|
||||
* fix conversion warnings on lines 193 and 152 (mdi = ...)
|
||||
*
|
||||
* Revision 1.6 1998/02/25 15:21:13 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 1.5 1998/02/25 01:37:18 sra
|
||||
* Fix up CVS/RCS keywords.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,31aug07,josh fix symbol conflicts
|
||||
*/
|
||||
|
||||
|
||||
#ifndef EPILOGUE_INSTALL_H
|
||||
#include <wrn/wm/common/install.h>
|
||||
#endif /* EPILOGUE_INSTALL_H */
|
||||
|
||||
#if INSTALL_COMMON_MD5
|
||||
|
||||
#ifndef EPILOGUE_TYPES_H
|
||||
#include <wrn/wm/common/types.h>
|
||||
#endif /* EPILOGUE_TYPES_H */
|
||||
#include <wrn/wm/common/md5.h>
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
** Message-digest routines: **
|
||||
** To form the message digest for a message M **
|
||||
** (1) Initialize a context buffer mdContext using MD5Init **
|
||||
** (2) Call MD5Update on mdContext and M **
|
||||
** (3) Call MD5Final on mdContext **
|
||||
** The message digest is now in mdContext->digest[0...15] **
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
/* forward declaration */
|
||||
static void WrsnmpCommonTransform (bits32_t *buf, bits32_t *in);
|
||||
|
||||
static bits8_t WRSNMP_COMMON_PADDING[64] = {
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
/* F, G, H and I are basic MD5 functions */
|
||||
#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
|
||||
#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
|
||||
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
||||
#define I(x, y, z) ((y) ^ ((x) | (~z)))
|
||||
|
||||
/* ROTATE_LEFT rotates x left n bits */
|
||||
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
|
||||
|
||||
/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4 */
|
||||
/* Rotation is separate from addition to prevent recomputation */
|
||||
#define FF(a, b, c, d, x, s, ac) \
|
||||
{(a) += F ((b), (c), (d)) + (x) + (bits32_t)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define GG(a, b, c, d, x, s, ac) \
|
||||
{(a) += G ((b), (c), (d)) + (x) + (bits32_t)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define HH(a, b, c, d, x, s, ac) \
|
||||
{(a) += H ((b), (c), (d)) + (x) + (bits32_t)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
#define II(a, b, c, d, x, s, ac) \
|
||||
{(a) += I ((b), (c), (d)) + (x) + (bits32_t)(ac); \
|
||||
(a) = ROTATE_LEFT ((a), (s)); \
|
||||
(a) += (b); \
|
||||
}
|
||||
|
||||
#ifdef __STDC__
|
||||
#define UL(x) x##U
|
||||
#else
|
||||
#define UL(x) x
|
||||
#endif
|
||||
|
||||
/* The routine WRSNMP_MD5Init initializes the message-digest context
|
||||
mdContext. All fields are set to zero.
|
||||
*/
|
||||
void WrsnmpCommonMD5Init (mdContext)
|
||||
MD5_CTX *mdContext;
|
||||
{
|
||||
mdContext->i[0] = mdContext->i[1] = (bits32_t)0;
|
||||
|
||||
/* Load magic initialization constants.
|
||||
*/
|
||||
mdContext->buf[0] = (bits32_t)0x67452301L;
|
||||
mdContext->buf[1] = (bits32_t)0xefcdab89L;
|
||||
mdContext->buf[2] = (bits32_t)0x98badcfeL;
|
||||
mdContext->buf[3] = (bits32_t)0x10325476L;
|
||||
}
|
||||
|
||||
/* The routine WRSNMP_MD5Update updates the message-digest context to
|
||||
account for the presence of each of the characters inBuf[0..inLen-1]
|
||||
in the message whose digest is being computed.
|
||||
*/
|
||||
void WrsnmpCommonMD5Update (mdContext, inBuf, inLen)
|
||||
MD5_CTX *mdContext;
|
||||
bits8_t *inBuf;
|
||||
bits32_t inLen;
|
||||
{
|
||||
bits32_t in[16];
|
||||
unsigned int mdi;
|
||||
unsigned int i, ii;
|
||||
|
||||
/* compute number of bytes mod 64 */
|
||||
mdi = (unsigned int)((mdContext->i[0] >> 3) & 0x3F);
|
||||
|
||||
/* update number of bits */
|
||||
if ((mdContext->i[0] + ((bits32_t)inLen << 3)) < mdContext->i[0])
|
||||
mdContext->i[1]++;
|
||||
mdContext->i[0] += ((bits32_t)inLen << 3);
|
||||
mdContext->i[1] += ((bits32_t)inLen >> 29);
|
||||
|
||||
while (inLen--) {
|
||||
/* add new character to buffer, increment mdi */
|
||||
mdContext->in[mdi++] = *inBuf++;
|
||||
|
||||
/* transform if necessary */
|
||||
if (mdi == 0x40) {
|
||||
for (i = 0, ii = 0; i < 16; i++, ii += 4)
|
||||
in[i] = (((bits32_t)mdContext->in[ii+3]) << 24) |
|
||||
(((bits32_t)mdContext->in[ii+2]) << 16) |
|
||||
(((bits32_t)mdContext->in[ii+1]) << 8) |
|
||||
((bits32_t)mdContext->in[ii]);
|
||||
WrsnmpCommonTransform (mdContext->buf, in);
|
||||
mdi = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* The routine WRSNMP_MD5Final terminates the message-digest computation and
|
||||
ends with the desired message digest in mdContext->digest[0...15].
|
||||
*/
|
||||
void WrsnmpCommonMD5Final (mdContext)
|
||||
MD5_CTX *mdContext;
|
||||
{
|
||||
bits32_t in[16];
|
||||
unsigned int mdi;
|
||||
unsigned int i, ii;
|
||||
bits32_t padLen;
|
||||
|
||||
/* save number of bits */
|
||||
in[14] = mdContext->i[0];
|
||||
in[15] = mdContext->i[1];
|
||||
|
||||
/* compute number of bytes mod 64 */
|
||||
mdi = (unsigned int)((mdContext->i[0] >> 3) & 0x3F);
|
||||
|
||||
/* pad out to 56 mod 64 */
|
||||
padLen = (mdi < 56) ? (56 - mdi) : (120 - mdi);
|
||||
MD5Update (mdContext, WRSNMP_COMMON_PADDING, padLen);
|
||||
|
||||
/* append length in bits and transform */
|
||||
for (i = 0, ii = 0; i < 14; i++, ii += 4)
|
||||
in[i] = (((bits32_t)mdContext->in[ii+3]) << 24) |
|
||||
(((bits32_t)mdContext->in[ii+2]) << 16) |
|
||||
(((bits32_t)mdContext->in[ii+1]) << 8) |
|
||||
((bits32_t)mdContext->in[ii]);
|
||||
WrsnmpCommonTransform (mdContext->buf, in);
|
||||
|
||||
/* store buffer in digest */
|
||||
for (i = 0, ii = 0; i < 4; i++, ii += 4) {
|
||||
mdContext->digest[ii] = (bits8_t)(mdContext->buf[i] & 0xFF);
|
||||
mdContext->digest[ii+1] =
|
||||
(bits8_t)((mdContext->buf[i] >> 8) & 0xFF);
|
||||
mdContext->digest[ii+2] =
|
||||
(bits8_t)((mdContext->buf[i] >> 16) & 0xFF);
|
||||
mdContext->digest[ii+3] =
|
||||
(bits8_t)((mdContext->buf[i] >> 24) & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
/* Basic MD5 step. Transforms buf based on in.
|
||||
*/
|
||||
static void WrsnmpCommonTransform (bits32_t *buf, bits32_t *in)
|
||||
{
|
||||
bits32_t a = buf[0], b = buf[1], c = buf[2], d = buf[3];
|
||||
|
||||
/* Round 1 */
|
||||
#define S11 7
|
||||
#define S12 12
|
||||
#define S13 17
|
||||
#define S14 22
|
||||
FF ( a, b, c, d, in[ 0], S11, UL(3614090360L)); /* 1 */
|
||||
FF ( d, a, b, c, in[ 1], S12, UL(3905402710L)); /* 2 */
|
||||
FF ( c, d, a, b, in[ 2], S13, UL( 606105819L)); /* 3 */
|
||||
FF ( b, c, d, a, in[ 3], S14, UL(3250441966L)); /* 4 */
|
||||
FF ( a, b, c, d, in[ 4], S11, UL(4118548399L)); /* 5 */
|
||||
FF ( d, a, b, c, in[ 5], S12, UL(1200080426L)); /* 6 */
|
||||
FF ( c, d, a, b, in[ 6], S13, UL(2821735955L)); /* 7 */
|
||||
FF ( b, c, d, a, in[ 7], S14, UL(4249261313L)); /* 8 */
|
||||
FF ( a, b, c, d, in[ 8], S11, UL(1770035416L)); /* 9 */
|
||||
FF ( d, a, b, c, in[ 9], S12, UL(2336552879L)); /* 10 */
|
||||
FF ( c, d, a, b, in[10], S13, UL(4294925233L)); /* 11 */
|
||||
FF ( b, c, d, a, in[11], S14, UL(2304563134L)); /* 12 */
|
||||
FF ( a, b, c, d, in[12], S11, UL(1804603682L)); /* 13 */
|
||||
FF ( d, a, b, c, in[13], S12, UL(4254626195L)); /* 14 */
|
||||
FF ( c, d, a, b, in[14], S13, UL(2792965006L)); /* 15 */
|
||||
FF ( b, c, d, a, in[15], S14, UL(1236535329L)); /* 16 */
|
||||
|
||||
/* Round 2 */
|
||||
#define S21 5
|
||||
#define S22 9
|
||||
#define S23 14
|
||||
#define S24 20
|
||||
GG ( a, b, c, d, in[ 1], S21, UL(4129170786L)); /* 17 */
|
||||
GG ( d, a, b, c, in[ 6], S22, UL(3225465664L)); /* 18 */
|
||||
GG ( c, d, a, b, in[11], S23, UL( 643717713L)); /* 19 */
|
||||
GG ( b, c, d, a, in[ 0], S24, UL(3921069994L)); /* 20 */
|
||||
GG ( a, b, c, d, in[ 5], S21, UL(3593408605L)); /* 21 */
|
||||
GG ( d, a, b, c, in[10], S22, UL( 38016083L)); /* 22 */
|
||||
GG ( c, d, a, b, in[15], S23, UL(3634488961L)); /* 23 */
|
||||
GG ( b, c, d, a, in[ 4], S24, UL(3889429448L)); /* 24 */
|
||||
GG ( a, b, c, d, in[ 9], S21, UL( 568446438L)); /* 25 */
|
||||
GG ( d, a, b, c, in[14], S22, UL(3275163606L)); /* 26 */
|
||||
GG ( c, d, a, b, in[ 3], S23, UL(4107603335L)); /* 27 */
|
||||
GG ( b, c, d, a, in[ 8], S24, UL(1163531501L)); /* 28 */
|
||||
GG ( a, b, c, d, in[13], S21, UL(2850285829L)); /* 29 */
|
||||
GG ( d, a, b, c, in[ 2], S22, UL(4243563512L)); /* 30 */
|
||||
GG ( c, d, a, b, in[ 7], S23, UL(1735328473L)); /* 31 */
|
||||
GG ( b, c, d, a, in[12], S24, UL(2368359562L)); /* 32 */
|
||||
|
||||
/* Round 3 */
|
||||
#define S31 4
|
||||
#define S32 11
|
||||
#define S33 16
|
||||
#define S34 23
|
||||
HH ( a, b, c, d, in[ 5], S31, UL(4294588738L)); /* 33 */
|
||||
HH ( d, a, b, c, in[ 8], S32, UL(2272392833L)); /* 34 */
|
||||
HH ( c, d, a, b, in[11], S33, UL(1839030562L)); /* 35 */
|
||||
HH ( b, c, d, a, in[14], S34, UL(4259657740L)); /* 36 */
|
||||
HH ( a, b, c, d, in[ 1], S31, UL(2763975236L)); /* 37 */
|
||||
HH ( d, a, b, c, in[ 4], S32, UL(1272893353L)); /* 38 */
|
||||
HH ( c, d, a, b, in[ 7], S33, UL(4139469664L)); /* 39 */
|
||||
HH ( b, c, d, a, in[10], S34, UL(3200236656L)); /* 40 */
|
||||
HH ( a, b, c, d, in[13], S31, UL( 681279174L)); /* 41 */
|
||||
HH ( d, a, b, c, in[ 0], S32, UL(3936430074L)); /* 42 */
|
||||
HH ( c, d, a, b, in[ 3], S33, UL(3572445317L)); /* 43 */
|
||||
HH ( b, c, d, a, in[ 6], S34, UL( 76029189L)); /* 44 */
|
||||
HH ( a, b, c, d, in[ 9], S31, UL(3654602809L)); /* 45 */
|
||||
HH ( d, a, b, c, in[12], S32, UL(3873151461L)); /* 46 */
|
||||
HH ( c, d, a, b, in[15], S33, UL( 530742520L)); /* 47 */
|
||||
HH ( b, c, d, a, in[ 2], S34, UL(3299628645L)); /* 48 */
|
||||
|
||||
/* Round 4 */
|
||||
#define S41 6
|
||||
#define S42 10
|
||||
#define S43 15
|
||||
#define S44 21
|
||||
II ( a, b, c, d, in[ 0], S41, UL(4096336452L)); /* 49 */
|
||||
II ( d, a, b, c, in[ 7], S42, UL(1126891415L)); /* 50 */
|
||||
II ( c, d, a, b, in[14], S43, UL(2878612391L)); /* 51 */
|
||||
II ( b, c, d, a, in[ 5], S44, UL(4237533241L)); /* 52 */
|
||||
II ( a, b, c, d, in[12], S41, UL(1700485571L)); /* 53 */
|
||||
II ( d, a, b, c, in[ 3], S42, UL(2399980690L)); /* 54 */
|
||||
II ( c, d, a, b, in[10], S43, UL(4293915773L)); /* 55 */
|
||||
II ( b, c, d, a, in[ 1], S44, UL(2240044497L)); /* 56 */
|
||||
II ( a, b, c, d, in[ 8], S41, UL(1873313359L)); /* 57 */
|
||||
II ( d, a, b, c, in[15], S42, UL(4264355552L)); /* 58 */
|
||||
II ( c, d, a, b, in[ 6], S43, UL(2734768916L)); /* 59 */
|
||||
II ( b, c, d, a, in[13], S44, UL(1309151649L)); /* 60 */
|
||||
II ( a, b, c, d, in[ 4], S41, UL(4149444226L)); /* 61 */
|
||||
II ( d, a, b, c, in[11], S42, UL(3174756917L)); /* 62 */
|
||||
II ( c, d, a, b, in[ 2], S43, UL( 718787259L)); /* 63 */
|
||||
II ( b, c, d, a, in[ 9], S44, UL(3951481745L)); /* 64 */
|
||||
|
||||
buf[0] += a;
|
||||
buf[1] += b;
|
||||
buf[2] += c;
|
||||
buf[3] += d;
|
||||
}
|
||||
|
||||
/*
|
||||
***********************************************************************
|
||||
** End of md5.c **
|
||||
******************************** (cut) ********************************
|
||||
*/
|
||||
|
||||
#endif /* INSTALL_COMMON_MD5 */
|
||||
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* $Log: sha.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:56 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:53 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.4 2001/01/19 22:21:31 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.3 2000/03/17 00:16:56 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.2 1998/06/16 05:12:26 sar
|
||||
* Clean up some type questions
|
||||
*
|
||||
* Revision 1.1 1998/05/22 18:03:35 sar
|
||||
* SHA digest functions
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
/* NIST Secure Hash Algorithm */
|
||||
/* heavily modified by Uwe Hollerbach <uh@alumni.caltech edu> */
|
||||
/* from Peter C. Gutmann's implementation as found in */
|
||||
/* Applied Cryptography by Bruce Schneier */
|
||||
/* Further modifications to include the "UNRAVEL" stuff, below */
|
||||
|
||||
/* This code is in the public domain */
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#include <wrn/wm/common/sha.h>
|
||||
|
||||
|
||||
/* Always use version 1, but leave the code around in case
|
||||
somebody wants to know that the difference is */
|
||||
#define SHA_VERSION 1
|
||||
|
||||
/* SHA f()-functions */
|
||||
|
||||
#define f1(x,y,z) ((x & y) | (~x & z))
|
||||
#define f2(x,y,z) (x ^ y ^ z)
|
||||
#define f3(x,y,z) ((x & y) | (x & z) | (y & z))
|
||||
#define f4(x,y,z) (x ^ y ^ z)
|
||||
|
||||
/* SHA constants */
|
||||
|
||||
#define CONST1 0x5a827999L
|
||||
#define CONST2 0x6ed9eba1L
|
||||
#define CONST3 0x8f1bbcdcL
|
||||
#define CONST4 0xca62c1d6L
|
||||
|
||||
/* 32-bit rotate */
|
||||
|
||||
#define R32(x,n) ((x << n) | (x >> (32 - n)))
|
||||
|
||||
#define FG(n) \
|
||||
T = R32(A,5) + f##n(B,C,D) + E + *WP++ + CONST##n; \
|
||||
E = D; D = C; C = R32(B,30); B = A; A = T
|
||||
|
||||
/* do SHA transformation */
|
||||
|
||||
static void sha_transform (SHA_CTX *sha_info)
|
||||
{
|
||||
int i;
|
||||
bits8_t *dp;
|
||||
bits32_t T, A, B, C, D, E, W[80], *WP;
|
||||
|
||||
dp = sha_info->data;
|
||||
|
||||
#if (INSTALL_ON_LITTLE_ENDIAN)
|
||||
for (i = 0; i < 16; ++i)
|
||||
{
|
||||
T = *((bits32_t *) dp);
|
||||
dp += 4;
|
||||
W[i] = ((T << 24) & 0xff000000L) | ((T << 8) & 0x00ff0000L) |
|
||||
((T >> 8) & 0x0000ff00) | ((T >> 24) & 0x000000ff);
|
||||
}
|
||||
#endif /* #if (INSTALL_ON_LITTLE_ENDIAN) */
|
||||
|
||||
#if (INSTALL_ON_BIG_ENDIAN)
|
||||
for (i = 0; i < 16; ++i)
|
||||
{
|
||||
T = *((bits32_t *) dp);
|
||||
dp += 4;
|
||||
W[i] = T;
|
||||
}
|
||||
#endif /* #if (INSTALL_ON_BIG_ENDIAN) **/
|
||||
|
||||
for (i = 16; i < 80; ++i)
|
||||
{
|
||||
W[i] = W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16];
|
||||
#if (SHA_VERSION == 1)
|
||||
W[i] = R32(W[i], 1);
|
||||
#endif /* SHA_VERSION */
|
||||
}
|
||||
|
||||
A = sha_info->buf[0];
|
||||
B = sha_info->buf[1];
|
||||
C = sha_info->buf[2];
|
||||
D = sha_info->buf[3];
|
||||
E = sha_info->buf[4];
|
||||
WP = W;
|
||||
|
||||
for (i = 0; i < 20; ++i) { FG(1); }
|
||||
for (i = 20; i < 40; ++i) { FG(2); }
|
||||
for (i = 40; i < 60; ++i) { FG(3); }
|
||||
for (i = 60; i < 80; ++i) { FG(4); }
|
||||
|
||||
sha_info->buf[0] += A;
|
||||
sha_info->buf[1] += B;
|
||||
sha_info->buf[2] += C;
|
||||
sha_info->buf[3] += D;
|
||||
sha_info->buf[4] += E;
|
||||
|
||||
}
|
||||
|
||||
/* initialize the SHA digest */
|
||||
|
||||
void sha_init(SHA_CTX *sha_info)
|
||||
{
|
||||
sha_info->buf[0] = 0x67452301L;
|
||||
sha_info->buf[1] = 0xefcdab89L;
|
||||
sha_info->buf[2] = 0x98badcfeL;
|
||||
sha_info->buf[3] = 0x10325476L;
|
||||
sha_info->buf[4] = 0xc3d2e1f0L;
|
||||
sha_info->count_lo = 0L;
|
||||
sha_info->count_hi = 0L;
|
||||
sha_info->local = 0;
|
||||
}
|
||||
|
||||
/* update the SHA digest */
|
||||
|
||||
void sha_update(SHA_CTX *sha_info,
|
||||
bits8_t *buffer,
|
||||
bits32_t count)
|
||||
{
|
||||
bits32_t clo;
|
||||
size_t i;
|
||||
|
||||
clo = sha_info->count_lo + ((bits32_t) count << 3);
|
||||
if (clo < sha_info->count_lo) {
|
||||
++sha_info->count_hi;
|
||||
}
|
||||
sha_info->count_lo = clo;
|
||||
sha_info->count_hi += (bits32_t) count >> 29;
|
||||
if (sha_info->local)
|
||||
{
|
||||
i = SHA_BLOCKSIZE - sha_info->local;
|
||||
if (i > count)
|
||||
i = (size_t)count;
|
||||
|
||||
MEMCPY(sha_info->data + sha_info->local, buffer, i);
|
||||
count -= i;
|
||||
buffer += i;
|
||||
sha_info->local += i;
|
||||
if (sha_info->local == SHA_BLOCKSIZE)
|
||||
sha_transform(sha_info);
|
||||
else
|
||||
return;
|
||||
}
|
||||
while (count >= SHA_BLOCKSIZE)
|
||||
{ MEMCPY (sha_info->data, buffer, SHA_BLOCKSIZE);
|
||||
buffer += SHA_BLOCKSIZE;
|
||||
count -= SHA_BLOCKSIZE;
|
||||
sha_transform (sha_info);
|
||||
}
|
||||
if (count) {
|
||||
MEMCPY (sha_info->data, buffer, (size_t)count);
|
||||
}
|
||||
sha_info->local = (size_t)count;
|
||||
|
||||
}
|
||||
|
||||
/* finish computing the SHA digest */
|
||||
|
||||
void sha_final (SHA_CTX *sha_info)
|
||||
{
|
||||
int count, i, ii;
|
||||
bits32_t lo_bit_count, hi_bit_count;
|
||||
|
||||
lo_bit_count = sha_info->count_lo;
|
||||
hi_bit_count = sha_info->count_hi;
|
||||
count = (int) ((lo_bit_count >> 3) & 0x3f);
|
||||
((bits8_t *) sha_info->data)[count++] = 0x80;
|
||||
if (count > SHA_BLOCKSIZE - 8) {
|
||||
MEMSET(sha_info->data + count, 0, SHA_BLOCKSIZE - count);
|
||||
sha_transform(sha_info);
|
||||
MEMSET(sha_info->data, 0, SHA_BLOCKSIZE - 8);
|
||||
} else {
|
||||
MEMSET(sha_info->data + count, 0, SHA_BLOCKSIZE - 8 - count);
|
||||
}
|
||||
sha_info->data[56] = (bits8_t) ((hi_bit_count >> 24) & 0xffL);
|
||||
sha_info->data[57] = (bits8_t) ((hi_bit_count >> 16) & 0xffL);
|
||||
sha_info->data[58] = (bits8_t) ((hi_bit_count >> 8) & 0xffL);
|
||||
sha_info->data[59] = (bits8_t) ((hi_bit_count ) & 0xffL);
|
||||
sha_info->data[60] = (bits8_t) ((lo_bit_count >> 24) & 0xffL);
|
||||
sha_info->data[61] = (bits8_t) ((lo_bit_count >> 16) & 0xffL);
|
||||
sha_info->data[62] = (bits8_t) ((lo_bit_count >> 8) & 0xffL);
|
||||
sha_info->data[63] = (bits8_t) ((lo_bit_count ) & 0xffL);
|
||||
|
||||
sha_transform(sha_info);
|
||||
|
||||
/* store buffer in digest */
|
||||
for(i = 0, ii = 0; i < 5; i++, ii += 4) {
|
||||
sha_info->digest[ii] = (bits8_t)((sha_info->buf[i] >> 24) & 0xFF);
|
||||
sha_info->digest[ii+1] = (bits8_t)((sha_info->buf[i] >> 16) & 0xFF);
|
||||
sha_info->digest[ii+2] = (bits8_t)((sha_info->buf[i] >> 8) & 0xFF);
|
||||
sha_info->digest[ii+3] = (bits8_t)((sha_info->buf[i]) & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,496 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/snprintf.c,v 1.3 2003/01/16 18:18:57 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1999 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Portable implementation of snprintf() and vsnprintf(). This is
|
||||
* derived from publicly-available code, modified to fit Epilogue
|
||||
* coding conventions and strip out the floating point support (which
|
||||
* we don't need).
|
||||
*
|
||||
* Original author's copyright notice:
|
||||
*
|
||||
* Copyright Patrick Powell 1995
|
||||
* This code is based on code written by Patrick Powell (papowell@astart.com)
|
||||
* It may be used for any purpose as long as this notice remains intact
|
||||
* on all source code distributions
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: snprintf.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:57 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:53 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.5 2001/01/19 22:21:31 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.4 2000/03/17 00:16:56 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.3 1999/05/21 16:43:51 sra
|
||||
* Minor tweaks to debugging code.
|
||||
*
|
||||
* Revision 1.2 1999/05/20 22:15:12 wes
|
||||
* Call etc_vsnprintf from etc_snprintf
|
||||
*
|
||||
* Revision 1.1 1999/05/20 20:28:17 sra
|
||||
* Add etc_snprintf() and etc_vsnprintf().
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/snprintf.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
static void dopr (char *buffer, size_t maxlen, const char *format,
|
||||
va_list args);
|
||||
static void fmtstr (char *buffer, size_t *currlen, size_t maxlen,
|
||||
char *value, int flags, int min, int max);
|
||||
static void fmtint (char *buffer, size_t *currlen, size_t maxlen,
|
||||
long value, int base, int min, int max, int flags);
|
||||
static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c );
|
||||
|
||||
/*
|
||||
* dopr(): poor man's version of doprintf
|
||||
*/
|
||||
|
||||
/* format read states */
|
||||
#define DP_S_DEFAULT 0
|
||||
#define DP_S_FLAGS 1
|
||||
#define DP_S_MIN 2
|
||||
#define DP_S_DOT 3
|
||||
#define DP_S_MAX 4
|
||||
#define DP_S_MOD 5
|
||||
#define DP_S_CONV 6
|
||||
#define DP_S_DONE 7
|
||||
|
||||
/* format flags - Bits */
|
||||
#define DP_F_MINUS (1 << 0)
|
||||
#define DP_F_PLUS (1 << 1)
|
||||
#define DP_F_SPACE (1 << 2)
|
||||
#define DP_F_NUM (1 << 3)
|
||||
#define DP_F_ZERO (1 << 4)
|
||||
#define DP_F_UP (1 << 5)
|
||||
#define DP_F_UNSIGNED (1 << 6)
|
||||
|
||||
/* Conversion Flags */
|
||||
#define DP_C_SHORT 1
|
||||
#define DP_C_LONG 2
|
||||
|
||||
#define char_to_int(p) (p - '0')
|
||||
#define MAX(p,q) ((p >= q) ? p : q)
|
||||
|
||||
static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
|
||||
{
|
||||
char ch;
|
||||
long value;
|
||||
char *strvalue;
|
||||
int min;
|
||||
int max;
|
||||
int state;
|
||||
int flags;
|
||||
int cflags;
|
||||
size_t currlen;
|
||||
|
||||
state = DP_S_DEFAULT;
|
||||
currlen = flags = cflags = min = 0;
|
||||
max = -1;
|
||||
ch = *format++;
|
||||
|
||||
while (state != DP_S_DONE) {
|
||||
if ((ch == '\0') || (currlen >= maxlen))
|
||||
state = DP_S_DONE;
|
||||
|
||||
switch(state) {
|
||||
case DP_S_DEFAULT:
|
||||
if (ch == '%')
|
||||
state = DP_S_FLAGS;
|
||||
else
|
||||
dopr_outch (buffer, &currlen, maxlen, ch);
|
||||
ch = *format++;
|
||||
break;
|
||||
case DP_S_FLAGS:
|
||||
switch (ch) {
|
||||
case '-':
|
||||
flags |= DP_F_MINUS;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '+':
|
||||
flags |= DP_F_PLUS;
|
||||
ch = *format++;
|
||||
break;
|
||||
case ' ':
|
||||
flags |= DP_F_SPACE;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '#':
|
||||
flags |= DP_F_NUM;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '0':
|
||||
flags |= DP_F_ZERO;
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
state = DP_S_MIN;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case DP_S_MIN:
|
||||
if (isdigit((int) ch)) {
|
||||
min = 10*min + char_to_int (ch);
|
||||
ch = *format++;
|
||||
} else if (ch == '*') {
|
||||
min = va_arg (args, int);
|
||||
ch = *format++;
|
||||
state = DP_S_DOT;
|
||||
} else {
|
||||
state = DP_S_DOT;
|
||||
}
|
||||
break;
|
||||
case DP_S_DOT:
|
||||
if (ch == '.') {
|
||||
state = DP_S_MAX;
|
||||
ch = *format++;
|
||||
} else {
|
||||
state = DP_S_MOD;
|
||||
}
|
||||
break;
|
||||
case DP_S_MAX:
|
||||
if (isdigit((int) ch)) {
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
max = 10*max + char_to_int (ch);
|
||||
ch = *format++;
|
||||
} else if (ch == '*') {
|
||||
max = va_arg (args, int);
|
||||
ch = *format++;
|
||||
state = DP_S_MOD;
|
||||
} else {
|
||||
state = DP_S_MOD;
|
||||
}
|
||||
break;
|
||||
case DP_S_MOD:
|
||||
/* Currently, we don't support Long Long, bummer */
|
||||
switch (ch) {
|
||||
case 'h':
|
||||
cflags = DP_C_SHORT;
|
||||
ch = *format++;
|
||||
break;
|
||||
case 'l':
|
||||
cflags = DP_C_LONG;
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
state = DP_S_CONV;
|
||||
break;
|
||||
case DP_S_CONV:
|
||||
switch (ch) {
|
||||
case 'd':
|
||||
case 'i':
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, short int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg (args, long int);
|
||||
else
|
||||
value = va_arg (args, int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
|
||||
break;
|
||||
case 'o':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, unsigned short int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg (args, unsigned long int);
|
||||
else
|
||||
value = va_arg (args, unsigned int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags);
|
||||
break;
|
||||
case 'u':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, unsigned short int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg (args, unsigned long int);
|
||||
else
|
||||
value = va_arg (args, unsigned int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
|
||||
break;
|
||||
case 'X':
|
||||
flags |= DP_F_UP;
|
||||
case 'x':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, unsigned short int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg (args, unsigned long int);
|
||||
else
|
||||
value = va_arg (args, unsigned int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
|
||||
break;
|
||||
case 'c':
|
||||
dopr_outch (buffer, &currlen, maxlen, va_arg (args, int));
|
||||
break;
|
||||
case 's':
|
||||
strvalue = va_arg (args, char *);
|
||||
if (max < 0)
|
||||
max = maxlen; /* ie, no max */
|
||||
fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max);
|
||||
break;
|
||||
case 'p':
|
||||
strvalue = va_arg (args, void *);
|
||||
fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
|
||||
break;
|
||||
case 'n':
|
||||
if (cflags == DP_C_SHORT) {
|
||||
short int *num;
|
||||
num = va_arg (args, short int *);
|
||||
*num = currlen;
|
||||
} else if (cflags == DP_C_LONG) {
|
||||
long int *num;
|
||||
num = va_arg (args, long int *);
|
||||
*num = currlen;
|
||||
} else {
|
||||
int *num;
|
||||
num = va_arg (args, int *);
|
||||
*num = currlen;
|
||||
}
|
||||
break;
|
||||
case '%':
|
||||
dopr_outch (buffer, &currlen, maxlen, ch);
|
||||
break;
|
||||
case 'w':
|
||||
/* not supported yet, treat as next char */
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
/* Unknown, skip */
|
||||
break;
|
||||
}
|
||||
ch = *format++;
|
||||
state = DP_S_DEFAULT;
|
||||
flags = cflags = min = 0;
|
||||
max = -1;
|
||||
break;
|
||||
case DP_S_DONE:
|
||||
break;
|
||||
default: /* hmm? */
|
||||
break; /* some picky compilers need this */
|
||||
}
|
||||
}
|
||||
if (currlen < maxlen - 1)
|
||||
buffer[currlen] = '\0';
|
||||
else
|
||||
buffer[maxlen - 1] = '\0';
|
||||
}
|
||||
|
||||
static void fmtstr (char *buffer, size_t *currlen, size_t maxlen,
|
||||
char *value, int flags, int min, int max)
|
||||
{
|
||||
int padlen; /* amount to pad */
|
||||
int cnt = 0;
|
||||
|
||||
if (value == 0)
|
||||
value = "<NULL>";
|
||||
|
||||
padlen = min - STRLEN(value);
|
||||
if (padlen < 0)
|
||||
padlen = 0;
|
||||
if (flags & DP_F_MINUS)
|
||||
padlen = -padlen; /* Left Justify */
|
||||
|
||||
while ((padlen > 0) && (cnt < max)) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
--padlen;
|
||||
++cnt;
|
||||
}
|
||||
while (*value && (cnt < max)) {
|
||||
dopr_outch (buffer, currlen, maxlen, *value++);
|
||||
++cnt;
|
||||
}
|
||||
while ((padlen < 0) && (cnt < max)) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
++padlen;
|
||||
++cnt;
|
||||
}
|
||||
}
|
||||
|
||||
/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
|
||||
|
||||
static void fmtint (char *buffer, size_t *currlen, size_t maxlen,
|
||||
long value, int base, int min, int max, int flags)
|
||||
{
|
||||
int signvalue = 0;
|
||||
unsigned long uvalue;
|
||||
char convert[20];
|
||||
int place = 0;
|
||||
int spadlen = 0; /* amount to space pad */
|
||||
int zpadlen = 0; /* amount to zero pad */
|
||||
char *chars = ((flags & DP_F_UP)
|
||||
? "0123456789ABCDEF"
|
||||
: "0123456789abcdef");
|
||||
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
|
||||
uvalue = value;
|
||||
|
||||
if (!(flags & DP_F_UNSIGNED)) {
|
||||
if (value < 0) {
|
||||
signvalue = '-';
|
||||
uvalue = -value;
|
||||
} else if (flags & DP_F_PLUS) { /* Do a sign (+/i) */
|
||||
signvalue = '+';
|
||||
} else if (flags & DP_F_SPACE) {
|
||||
signvalue = ' ';
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
convert[place++] = chars[uvalue % (unsigned) base];
|
||||
uvalue = (uvalue / (unsigned)base );
|
||||
} while(uvalue && (place < 20));
|
||||
if (place == 20)
|
||||
place--;
|
||||
convert[place] = 0;
|
||||
|
||||
zpadlen = max - place;
|
||||
spadlen = min - MAX (max, place) - (signvalue ? 1 : 0);
|
||||
if (zpadlen < 0)
|
||||
zpadlen = 0;
|
||||
if (spadlen < 0)
|
||||
spadlen = 0;
|
||||
if (flags & DP_F_ZERO) {
|
||||
zpadlen = MAX(zpadlen, spadlen);
|
||||
spadlen = 0;
|
||||
}
|
||||
if (flags & DP_F_MINUS)
|
||||
spadlen = -spadlen; /* Left Justifty */
|
||||
|
||||
/* Spaces */
|
||||
while (spadlen > 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
--spadlen;
|
||||
}
|
||||
|
||||
/* Sign */
|
||||
if (signvalue)
|
||||
dopr_outch (buffer, currlen, maxlen, signvalue);
|
||||
|
||||
/* Zeros */
|
||||
if (zpadlen > 0) {
|
||||
while (zpadlen > 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, '0');
|
||||
--zpadlen;
|
||||
}
|
||||
}
|
||||
|
||||
/* Digits */
|
||||
while (place > 0)
|
||||
dopr_outch (buffer, currlen, maxlen, convert[--place]);
|
||||
|
||||
/* Left Justified spaces */
|
||||
while (spadlen < 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
++spadlen;
|
||||
}
|
||||
}
|
||||
|
||||
static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c)
|
||||
{
|
||||
if (*currlen < maxlen)
|
||||
buffer[(*currlen)++] = c;
|
||||
}
|
||||
|
||||
int etc_vsnprintf (char *str, size_t count, const char *fmt, va_list args)
|
||||
{
|
||||
str[0] = 0;
|
||||
dopr(str, count, fmt, args);
|
||||
return(STRLEN(str));
|
||||
}
|
||||
|
||||
int etc_snprintf (char *str, size_t count, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
etc_vsnprintf(str, count, fmt, ap);
|
||||
va_end(ap);
|
||||
return(STRLEN(str));
|
||||
}
|
||||
|
||||
#ifndef INSTALL_ETC_SNPRINTF_TEST
|
||||
#define INSTALL_ETC_SNPRINTF_TEST defined(ETC_SNPRINTF_TEST_OUTPUT)
|
||||
#endif
|
||||
|
||||
#if INSTALL_ETC_SNPRINTF_TEST
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
char buf1[1024];
|
||||
char buf2[1024];
|
||||
char *int_fmt[] = { "%-1.5d", "%1.5d", "%123.9d", "%5.5d", "%10.5d",
|
||||
"% 10.5d", "%+22.33d", "%01.3d", "%4d", 0 };
|
||||
long int_nums[] = { -1, 134, 91340, 341, 0203, 0};
|
||||
int x, y;
|
||||
int fail = 0;
|
||||
int num = 0;
|
||||
|
||||
ETC_SNPRINTF_TEST_OUTPUT("Testing etc_snprintf() against sprintf()...");
|
||||
|
||||
for (x = 0; int_fmt[x] != 0; x++) {
|
||||
for (y = 0; int_nums[y] != 0 ; y++) {
|
||||
etc_snprintf (buf1, sizeof (buf1), int_fmt[x], int_nums[y]);
|
||||
sprintf (buf2, int_fmt[x], int_nums[y]);
|
||||
if (STRCMP (buf1, buf2)) {
|
||||
ETC_SNPRINTF_TEST_OUTPUT("\netc_snprintf() doesn't match format: ");
|
||||
ETC_SNPRINTF_TEST_OUTPUT(int_fmt[x]);
|
||||
ETC_SNPRINTF_TEST_OUTPUT("\n\tetc_snprintf() = ");
|
||||
ETC_SNPRINTF_TEST_OUTPUT(buf1);
|
||||
ETC_SNPRINTF_TEST_OUTPUT("\n\tsprintf() = ");
|
||||
ETC_SNPRINTF_TEST_OUTPUT(buf2);
|
||||
ETC_SNPRINTF_TEST_OUTPUT("\n");
|
||||
fail++;
|
||||
} else {
|
||||
ETC_SNPRINTF_TEST_OUTPUT(".");
|
||||
}
|
||||
num++;
|
||||
}
|
||||
}
|
||||
ETC_SNPRINTF_TEST_OUTPUT("\n");
|
||||
return fail;
|
||||
}
|
||||
|
||||
#endif /* INSTALL_ETC_SNPRINTF_TEST */
|
||||
@@ -0,0 +1,102 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/stricmp.c,v 1.3 2003/01/16 18:18:57 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: stricmp.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:57 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:54 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:39 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.6 2001/05/24 20:32:30 paul
|
||||
* CAD-UL compiler is picky.
|
||||
*
|
||||
* Revision 1.5 2001/01/19 22:21:32 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.4 2000/03/17 00:16:57 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.3 1999/04/09 20:33:48 wes
|
||||
* re-constify. let's see what, if anything, blows up
|
||||
*
|
||||
* Revision 1.2 1998/06/17 18:28:33 meister
|
||||
* This function returned -1 for both cases of non-matching strings. Fixed
|
||||
* to return 1 or -1 as appropriate.
|
||||
*
|
||||
* Revision 1.1 1998/06/03 20:12:51 sar
|
||||
* Added some common string functions. The user can choose to install
|
||||
* these if his library doesn't include them or they are broken.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/stdf.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* PORTABLE 'Standard' C FUNCTIONS - these are written in C because not
|
||||
* all systems provide them consistently. Sometimes they're even broken.
|
||||
* This code used to be in snark/snmptalk/stdf.c but was moved here to
|
||||
* be available to more code.
|
||||
*/
|
||||
|
||||
int
|
||||
etc_stricmp(register const char *s,
|
||||
register const char *t)
|
||||
{
|
||||
int a, b;
|
||||
|
||||
while (*s && *t) {
|
||||
a = (int)*s; b = (int)*t;
|
||||
|
||||
/* we only call tolower() if we're sure we need to because
|
||||
* on some systems, calling tolower() on something other
|
||||
* than an uppercase character will break the character.
|
||||
*/
|
||||
if (isupper(a))
|
||||
a = tolower(a);
|
||||
if (isupper(b))
|
||||
b = tolower(b);
|
||||
if (a != b)
|
||||
return (a > b ? 1 : -1);
|
||||
|
||||
s++;
|
||||
t++;
|
||||
}
|
||||
|
||||
if (*s != *t)
|
||||
return (*s > *t ? 1 : -1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/strncpy.c,v 1.3 2003/01/16 18:18:57 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: strncpy.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:57 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:54 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:40 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.3 2001/02/09 21:23:58 paul
|
||||
* Return dst (duh).
|
||||
*
|
||||
* Revision 1.2 2001/02/09 20:16:42 paul
|
||||
* Fixed Header line.
|
||||
*
|
||||
* Revision 1.1 2001/02/09 20:13:42 paul
|
||||
* Our own version of strncpy(), just in case the user doesn't have one.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/stdf.h>
|
||||
|
||||
char *
|
||||
etc_strncpy(char *dst, const char *src, size_t n)
|
||||
{
|
||||
char *ret = dst;
|
||||
|
||||
for ( ; (n > 0) && ((*dst++ = *src++) != '\0'); --n) {
|
||||
}
|
||||
for ( ; n > 0; --n) {
|
||||
*dst++ = '\0';
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/strnicmp.c,v 1.3 2003/01/16 18:18:57 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: strnicmp.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:57 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:55 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:40 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.6 2001/05/24 20:32:30 paul
|
||||
* CAD-UL compiler is picky.
|
||||
*
|
||||
* Revision 1.5 2001/01/19 22:21:32 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.4 2000/03/17 00:16:57 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.3 1999/04/09 20:33:48 wes
|
||||
* re-constify. let's see what, if anything, blows up
|
||||
*
|
||||
* Revision 1.2 1998/06/17 18:25:54 meister
|
||||
* This function only returned 0 or -1, now fixed to return 0, 1, or -1
|
||||
* as appropriate.
|
||||
*
|
||||
* Revision 1.1 1998/06/03 20:12:51 sar
|
||||
* Added some common string functions. The user can choose to install
|
||||
* these if his library doesn't include them or they are broken.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/stdf.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* PORTABLE 'Standard' C FUNCTIONS - these are written in C because not
|
||||
* all systems provide them consistently. Sometimes they're even broken.
|
||||
* This code used to be in snark/snmptalk/stdf.c but was moved here to
|
||||
* be available to more code.
|
||||
*/
|
||||
|
||||
int
|
||||
etc_strnicmp(register const char *s,
|
||||
register const char *t,
|
||||
size_t len)
|
||||
{
|
||||
int a, b;
|
||||
|
||||
while (*s && *t && len) {
|
||||
len--;
|
||||
a = (int)*s; b = (int)*t;
|
||||
if (isupper(a))
|
||||
a = tolower(a);
|
||||
if (isupper(b))
|
||||
b = tolower(b);
|
||||
if (a != b)
|
||||
return (a > b ? 1 : -1);
|
||||
s++;
|
||||
t++;
|
||||
}
|
||||
|
||||
/* if we're here because len is zero, don't do the final compare,
|
||||
* which verifies that both strings are null terminated, cause
|
||||
* chances are, they're not.
|
||||
*/
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
if (*s != *t) {
|
||||
return (*s > *t ? 1 : -1);
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/strtol.c,v 1.3 2003/01/16 18:18:57 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: strtol.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:57 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:55 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:40 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.4 2001/01/19 22:21:32 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.3 2000/03/17 00:16:58 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.2 1998/10/14 13:03:20 sar
|
||||
* Removed setting of errno on errors as it isn't portable enough.
|
||||
*
|
||||
* Revision 1.1 1998/06/03 20:12:52 sar
|
||||
* Added some common string functions. The user can choose to install
|
||||
* these if his library doesn't include them or they are broken.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/stdf.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* PORTABLE 'Standard' C FUNCTIONS - these are written in C because not
|
||||
* all systems provide them consistently. Sometimes they're even broken.
|
||||
* This code used to be in snark/snmptalk/stdf.c but was moved here to
|
||||
* be available to more code.
|
||||
*/
|
||||
|
||||
/* This doesn't accept 0x if the radix is 16. The overflow code assumes
|
||||
* a 2's complement architecture */
|
||||
long
|
||||
etc_strtol(char *string,
|
||||
char **endptr,
|
||||
int radix)
|
||||
{
|
||||
char *s;
|
||||
long value;
|
||||
long new_value;
|
||||
int sign;
|
||||
int increment;
|
||||
|
||||
value = 0;
|
||||
sign = 1;
|
||||
s = string;
|
||||
|
||||
if ((radix == 1) || (radix > 36) || (radix < 0)) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* skip whitespace */
|
||||
while ((*s == ' ') || (*s == '\t') || (*s == '\n') || (*s == '\r'))
|
||||
s++;
|
||||
|
||||
if (*s == '-') {
|
||||
sign = -1; s++;
|
||||
}
|
||||
else if (*s == '+')
|
||||
s++;
|
||||
|
||||
if (radix == 0) {
|
||||
if (*s == '0') {
|
||||
s++;
|
||||
if ((*s == 'x') || (*s == 'X')) {
|
||||
s++;
|
||||
radix = 16;
|
||||
}
|
||||
else
|
||||
radix = 8;
|
||||
}
|
||||
else
|
||||
radix = 10;
|
||||
}
|
||||
|
||||
/* read number */
|
||||
while (1) {
|
||||
if ((*s >= '0') && (*s <= '9'))
|
||||
increment = *s - '0';
|
||||
else if ((*s >= 'a') && (*s <= 'z'))
|
||||
increment = *s - 'a' + 10;
|
||||
else if ((*s >= 'A') && (*s <= 'Z'))
|
||||
increment = *s - 'A' + 10;
|
||||
else
|
||||
break;
|
||||
|
||||
if (increment >= radix)
|
||||
break;
|
||||
|
||||
new_value = value * radix + increment;
|
||||
/* detect overflow */
|
||||
if ((new_value - increment)/radix != value) {
|
||||
s = string;
|
||||
value = -1 >> 1;
|
||||
if (sign < 0)
|
||||
value += 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
value = new_value;
|
||||
s++;
|
||||
}
|
||||
|
||||
done:
|
||||
if (endptr)
|
||||
*endptr = s;
|
||||
return value*sign;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/strtoul.c,v 1.3 2003/01/16 18:18:58 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: strtoul.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:58 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:55 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:40 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.4 2001/01/19 22:21:32 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.3 2000/03/17 00:16:59 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.2 1998/10/14 13:03:20 sar
|
||||
* Removed setting of errno on errors as it isn't portable enough.
|
||||
*
|
||||
* Revision 1.1 1998/06/03 20:12:52 sar
|
||||
* Added some common string functions. The user can choose to install
|
||||
* these if his library doesn't include them or they are broken.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/stdf.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
/* PORTABLE 'Standard' C FUNCTIONS - these are written in C because not
|
||||
* all systems provide them consistently. Sometimes they're even broken.
|
||||
* This code used to be in snark/snmptalk/stdf.c but was moved here to
|
||||
* be available to more code.
|
||||
*/
|
||||
|
||||
/* This doesn't accept 0x if the radix is 16. The overflow code assumes
|
||||
* a 2's complement architecture */
|
||||
unsigned long
|
||||
etc_strtoul(char *string,
|
||||
char **endptr,
|
||||
int radix)
|
||||
{
|
||||
char *s;
|
||||
unsigned long value;
|
||||
unsigned long new_value;
|
||||
int sign;
|
||||
int increment;
|
||||
|
||||
value = 0;
|
||||
sign = 1;
|
||||
s = string;
|
||||
|
||||
if ((radix == 1) || (radix > 36) || (radix < 0)) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* skip whitespace */
|
||||
while ((*s == ' ') || (*s == '\t') || (*s == '\n') || (*s == '\r'))
|
||||
s++;
|
||||
|
||||
if (*s == '-') {
|
||||
sign = -1; s++;
|
||||
}
|
||||
else if (*s == '+')
|
||||
s++;
|
||||
|
||||
if (radix == 0) {
|
||||
if (*s == '0') {
|
||||
s++;
|
||||
if ((*s == 'x') || (*s == 'X')) {
|
||||
s++;
|
||||
radix = 16;
|
||||
}
|
||||
else
|
||||
radix = 8;
|
||||
}
|
||||
else
|
||||
radix = 10;
|
||||
}
|
||||
|
||||
/* read number */
|
||||
while (1) {
|
||||
if ((*s >= '0') && (*s <= '9'))
|
||||
increment = *s - '0';
|
||||
else if ((*s >= 'a') && (*s <= 'z'))
|
||||
increment = *s - 'a' + 10;
|
||||
else if ((*s >= 'A') && (*s <= 'Z'))
|
||||
increment = *s - 'A' + 10;
|
||||
else
|
||||
break;
|
||||
|
||||
if (increment >= radix)
|
||||
break;
|
||||
|
||||
new_value = value * radix + increment;
|
||||
/* detect overflow */
|
||||
if ((new_value - increment)/radix != value) {
|
||||
s = string;
|
||||
value = -1 >> 1;
|
||||
if (sign < 0)
|
||||
value += 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
value = new_value;
|
||||
s++;
|
||||
}
|
||||
|
||||
done:
|
||||
if (endptr)
|
||||
*endptr = s;
|
||||
return value*sign;
|
||||
}
|
||||
@@ -0,0 +1,478 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/thd_dbg.c,v 1.3 2003/01/16 18:18:58 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998-1999 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: thd_dbg.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:58 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:56 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:40 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.12 2001/06/12 08:06:07 paul
|
||||
* Mutex priorities are unsigned.
|
||||
* Added debugging to condition variable routines.
|
||||
*
|
||||
* Revision 1.11 2001/03/22 16:54:08 paul
|
||||
* Mutex and condition variable functions now return errors.
|
||||
*
|
||||
* Revision 1.10 2001/03/20 17:11:38 paul
|
||||
* Removed unused local variable.
|
||||
*
|
||||
* Revision 1.9 2001/01/19 22:21:32 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.8 2000/10/16 19:22:06 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 1.6 2000/03/17 00:16:59 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.5 1999/09/02 20:58:18 wes
|
||||
* Create a new memory pool for thread debug state, and use it instead of
|
||||
* using malloc/free.
|
||||
*
|
||||
* Revision 1.4 1999/05/20 19:44:32 wes
|
||||
* Print out more info for thread assertion failures
|
||||
*
|
||||
* Revision 1.3 1999/05/19 21:27:33 wes
|
||||
* Fix signed vs unsigned comparison glitch
|
||||
*
|
||||
* Revision 1.2 1999/04/21 20:05:18 wes
|
||||
* Silence DIAB compiler warnings
|
||||
*
|
||||
* Revision 1.1 1999/02/18 17:45:57 wes
|
||||
* 8.3ize thread_debug.c to thd_dbg.c
|
||||
*
|
||||
* Revision 1.2 1999/02/18 04:41:23 wes
|
||||
* Sockets merge: Everything Else
|
||||
* - memory pools
|
||||
* - thread support
|
||||
* - port-specific headers
|
||||
*
|
||||
* Revision 1.1.6.10 1999/02/05 18:33:57 paul
|
||||
* Changed the way we identify the thread for trace statements, due to
|
||||
* differences between various pthreads implementations.
|
||||
*
|
||||
* Revision 1.1.6.9 1999/01/22 19:49:15 paul
|
||||
* Added this_thread() to allow other parts of the code to print the
|
||||
* current thread.
|
||||
* Added copyright notice.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/thread.h>
|
||||
#include <wrn/attache/config.h> /* !!!??? */
|
||||
#include <wrn/attache/glue.h> /* !!!??? */
|
||||
#include <wrn/wm/common/bug.h>
|
||||
|
||||
#define ASSERT1(cond, lock, file, line) \
|
||||
do {if (!(cond)) { thread_preabort(file, line, lock); \
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_FATAL, 0, \
|
||||
(BUG_OUT, "Lock assertion \"%s\" failed, file %s, line %d", \
|
||||
#cond, file, line)); } } while (0)
|
||||
|
||||
glue_mutex_t etc_meta_mutex;
|
||||
|
||||
enum thread_debug_state {
|
||||
THREAD_DEBUG_RUNNABLE,
|
||||
THREAD_DEBUG_MUTEX_WAIT,
|
||||
THREAD_DEBUG_COND_WAIT
|
||||
};
|
||||
|
||||
typedef struct _tdit thread_debug_info_t;
|
||||
|
||||
struct _tdit {
|
||||
thread_debug_info_t *next_thread;
|
||||
char *thread_name;
|
||||
enum thread_debug_state thread_state;
|
||||
etc_mutex_t *thread_held_locks;
|
||||
etc_mutex_t *thread_wanted_lock;
|
||||
etc_cond_t *thread_wanted_cond;
|
||||
glue_thread_t tid;
|
||||
};
|
||||
|
||||
size_t thd_debug_size = sizeof(thread_debug_info_t);
|
||||
|
||||
void debug_state_free(void *debug)
|
||||
{
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "Freeing thread state %p", debug));
|
||||
GLUE_FREE_TO_POOL(debug, MEMPOOL_THD_DBG);
|
||||
}
|
||||
|
||||
|
||||
void common_thread_init(void)
|
||||
{
|
||||
GLUE_THREAD_INIT();
|
||||
GLUE_MUTEX_INIT_MAGIC(&etc_meta_mutex);
|
||||
|
||||
GLUE_THD_COOKIE_INIT(debug_state_free);
|
||||
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "Threading!"));
|
||||
}
|
||||
|
||||
thread_debug_info_t *thread_debug_state(void)
|
||||
{
|
||||
thread_debug_info_t *dip;
|
||||
|
||||
GLUE_THD_COOKIE_GET(&dip);
|
||||
|
||||
if (dip == NULL) {
|
||||
dip = GLUE_ALLOC_FROM_POOL(sizeof(*dip), MEMPOOL_THD_DBG);
|
||||
BUG_ASSERT(dip != NULL);
|
||||
|
||||
dip->tid = GLUE_THD_SELF();
|
||||
dip->next_thread = NULL;
|
||||
dip->thread_name = NULL;
|
||||
dip->thread_state = THREAD_DEBUG_RUNNABLE;
|
||||
dip->thread_held_locks = NULL;
|
||||
dip->thread_wanted_lock = NULL;
|
||||
dip->thread_wanted_cond = NULL;
|
||||
GLUE_THD_COOKIE_SET(dip);
|
||||
}
|
||||
return dip;
|
||||
}
|
||||
|
||||
static unsigned compute_lock_prio(thread_debug_info_t *tdi)
|
||||
{
|
||||
unsigned prio = 0;
|
||||
etc_mutex_t *lock;
|
||||
|
||||
for (lock = tdi->thread_held_locks; lock != NULL; lock = lock->next_lock)
|
||||
{
|
||||
if (lock->lock_prio > prio)
|
||||
prio = lock->lock_prio;
|
||||
}
|
||||
|
||||
return prio;
|
||||
}
|
||||
|
||||
#if INSTALL_BUG
|
||||
static char *indent_string(int level)
|
||||
{
|
||||
static char indentfu[10]="\t\t\t\t\t\t\t\t\t\t";
|
||||
if (level < 0) level=0;
|
||||
if (level > (int)sizeof(indentfu)) level = sizeof(indentfu);
|
||||
|
||||
return &indentfu[sizeof(indentfu) - level];
|
||||
}
|
||||
#endif
|
||||
|
||||
void print_proc (int level, char *tag, thread_debug_info_t *tdi)
|
||||
{
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "%s%s: %p", indent_string(level), tag, tdi));
|
||||
}
|
||||
|
||||
void print_lock(int level, char *tag, etc_mutex_t *lock)
|
||||
{
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "%s%s: %s (%p) (pri %u)", indent_string(level),
|
||||
tag, lock->lock_name, lock, lock->lock_prio));
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "%slock last locked in %s, line %d",
|
||||
indent_string(level+1), lock->last_lock_file, lock->last_lock_line));
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "%slock last unlocked in %s, line %d",
|
||||
indent_string(level+1), lock->last_unlock_file,
|
||||
lock->last_unlock_line));
|
||||
if (lock->lock_owner != NULL) {
|
||||
print_proc(level+1, "Held by", lock->lock_owner);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void thread_preabort(char *file, int line, etc_mutex_t *errlock)
|
||||
{
|
||||
thread_debug_info_t *tdi = thread_debug_state();
|
||||
etc_mutex_t *lock;
|
||||
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "locking error detected on lock %p at %s, line %d",
|
||||
errlock,
|
||||
file, line));
|
||||
|
||||
print_lock(0, "bad lock", errlock);
|
||||
|
||||
if (tdi->thread_wanted_lock == NULL) {
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "No locks wanted"));
|
||||
} else {
|
||||
print_lock(0, "waiting for", tdi->thread_wanted_lock);
|
||||
}
|
||||
if (tdi->thread_held_locks == NULL) {
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "No locks held"));
|
||||
} else {
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "Held locks:"));
|
||||
for (lock = tdi->thread_held_locks; lock != NULL; lock = lock->next_lock) {
|
||||
BUG(BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "\t%s (%p) (pri %u)", lock->lock_name, lock, lock->lock_prio));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int etc_mutex_lock_debug (etc_mutex_t *lock, unsigned prio,
|
||||
char *file, int line)
|
||||
{
|
||||
thread_debug_info_t *us = thread_debug_state();
|
||||
unsigned curlockprio = compute_lock_prio(us);
|
||||
int ret;
|
||||
|
||||
ASSERT1((lock->magic == ETC_LOCK_MAGIC), lock, file, line);
|
||||
|
||||
us->thread_state = THREAD_DEBUG_MUTEX_WAIT;
|
||||
us->thread_wanted_lock = lock;
|
||||
|
||||
ASSERT1((lock->lock_owner != us), lock, file, line);
|
||||
ASSERT1((lock->lock_prio > curlockprio), lock, file, line);
|
||||
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "waiting to lock %s (%p) at %s, line %d",
|
||||
lock->lock_name, lock, file, line));
|
||||
|
||||
if (GLUE_MUTEX_TRYLOCK(&(lock)->m, prio)) {
|
||||
ETC_META_UNLOCK();
|
||||
ret = (int)GLUE_MUTEX_LOCK(&(lock)->m, prio);
|
||||
ETC_META_LOCK();
|
||||
if (ret) {
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "!!failed to lock %s (%p) at %s, line %d", lock->lock_name,
|
||||
lock, file, line));
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "locked %s (%p) at %s, line %d", lock->lock_name,
|
||||
lock, file, line));
|
||||
|
||||
us->thread_state = THREAD_DEBUG_RUNNABLE;
|
||||
us->thread_wanted_lock = NULL;
|
||||
|
||||
ASSERT1((lock->lock_prio == prio), lock, file, line);
|
||||
ASSERT1((lock->lock_owner == NULL), lock, file, line);
|
||||
|
||||
lock->last_lock_file = file;
|
||||
lock->last_lock_line = line;
|
||||
lock->lock_owner = us;
|
||||
lock->next_lock = us->thread_held_locks;
|
||||
us->thread_held_locks = lock;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int etc_mutex_unlock_debug (etc_mutex_t *lock, unsigned prio,
|
||||
char *file, int line)
|
||||
{
|
||||
thread_debug_info_t *us = thread_debug_state();
|
||||
|
||||
ASSERT1((lock->magic == ETC_LOCK_MAGIC), lock, file, line);
|
||||
|
||||
ASSERT1((lock->lock_owner == us), lock, file, line);
|
||||
ASSERT1((lock->lock_prio == prio), lock, file, line);
|
||||
lock->lock_owner = NULL;
|
||||
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "unlocking %s (%p) at %s, line %d",
|
||||
lock->lock_name, lock, file, line));
|
||||
|
||||
if (lock == us->thread_held_locks) {
|
||||
us->thread_held_locks = lock->next_lock;
|
||||
lock->next_lock = NULL;
|
||||
} else {
|
||||
etc_mutex_t *l1;
|
||||
|
||||
for (l1 = us->thread_held_locks; l1 != NULL; l1 = l1->next_lock) {
|
||||
if (l1->next_lock == lock) {
|
||||
l1->next_lock = lock->next_lock;
|
||||
lock->next_lock = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ASSERT1((lock->next_lock == NULL), lock, file, line);
|
||||
|
||||
lock->last_unlock_file = file;
|
||||
lock->last_unlock_line = line;
|
||||
|
||||
return (int)GLUE_MUTEX_UNLOCK(&(lock)->m, prio);
|
||||
}
|
||||
|
||||
|
||||
void etc_mutex_lock_assert (etc_mutex_t *lock, unsigned prio,
|
||||
char *file, int line)
|
||||
{
|
||||
thread_debug_info_t *us = thread_debug_state();
|
||||
|
||||
ETC_META_LOCK();
|
||||
|
||||
ASSERT1((lock->magic == ETC_LOCK_MAGIC), lock, file, line);
|
||||
|
||||
ASSERT1((lock->lock_owner == us), lock, file, line);
|
||||
ASSERT1((lock->lock_prio == prio), lock, file, line);
|
||||
|
||||
ETC_META_UNLOCK();
|
||||
}
|
||||
|
||||
int etc_mutex_destroy (etc_mutex_t *lock, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
|
||||
BUG(BUG_THREAD_TRACE, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "destroying mutex %s (%p)",
|
||||
lock->lock_name, lock));
|
||||
|
||||
ASSERT1((lock->magic == ETC_LOCK_MAGIC), lock, file, line);
|
||||
ret = (int)GLUE_MUTEX_DESTROY(&(lock)->m);
|
||||
(lock)->magic = ~ETC_LOCK_MAGIC;
|
||||
lock->last_unlock_file = file;
|
||||
lock->last_unlock_line = line;
|
||||
|
||||
ETC_META_UNLOCK();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *this_thread(void)
|
||||
{
|
||||
thread_debug_info_t *us = thread_debug_state();
|
||||
|
||||
return (void *)us;
|
||||
}
|
||||
|
||||
int etc_mutex_init(etc_mutex_t *lock, unsigned prio, char *name)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
lock->magic = ETC_LOCK_MAGIC;
|
||||
lock->lock_owner = NULL;
|
||||
lock->lock_name = name;
|
||||
lock->lock_prio = prio;
|
||||
lock->next_lock = NULL;
|
||||
ret = (int)GLUE_MUTEX_INIT(&lock->m, prio);
|
||||
ETC_META_UNLOCK();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_mutex_lock(etc_mutex_t *lock, unsigned prio, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
ret = etc_mutex_lock_debug(lock, prio, file, line);
|
||||
ETC_META_UNLOCK();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_mutex_unlock(etc_mutex_t *lock, unsigned prio, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
ret = etc_mutex_unlock_debug(lock, prio, file, line);
|
||||
ETC_META_UNLOCK();
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_cond_init(etc_cond_t *cond, etc_mutex_t *mutex, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
cond->m = mutex;
|
||||
ret = (int)GLUE_COND_INIT(&cond->c, &mutex->m);
|
||||
ETC_META_UNLOCK();
|
||||
/* pthread_cond_init() and cv_create() both return 0 on success */
|
||||
BUG_IF((ret != 0), BUG_ASSERTION_FAILED, BUG_CONTINUABLE, 0,
|
||||
(BUG_OUT, "GLUE_COND_INIT returned %d, file %s, line %d", ret, file, line));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_cond_wait(etc_cond_t *cond, etc_mutex_t *mutex, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
etc_mutex_unlock_debug(mutex, mutex->lock_prio, file, line);
|
||||
ret = (int)GLUE_COND_WAIT(&cond->c, &etc_meta_mutex);
|
||||
etc_mutex_lock_debug(mutex, mutex->lock_prio, file, line);
|
||||
ETC_META_UNLOCK();
|
||||
/* pthread_cond_wait() and cv_wait() both return 0 on success */
|
||||
BUG_IF((ret != 0), BUG_ASSERTION_FAILED, BUG_FATAL, 0,
|
||||
(BUG_OUT, "GLUE_COND_WAIT returned %d, file %s, line %d", ret, file, line));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_cond_wakeup(etc_cond_t *cond, etc_mutex_t *mutex, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
ret = (int)GLUE_COND_WAKEUP(&cond->c, mutex);
|
||||
ETC_META_UNLOCK();
|
||||
/* pthread_cond_signal() and cv_signal() both return 0 on success */
|
||||
BUG_IF((ret != 0), BUG_ASSERTION_FAILED, BUG_FATAL, 0,
|
||||
(BUG_OUT, "GLUE_COND_WAKEUP returned %d, file %s, line %d", ret, file, line));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_cond_broadcast(etc_cond_t *cond, etc_mutex_t *mutex, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
ret = (int)GLUE_COND_BROADCAST(&cond->c, mutex);
|
||||
ETC_META_UNLOCK();
|
||||
/* pthread_cond_broadcast() and cv_broadcast() both return 0 on success */
|
||||
BUG_IF((ret != 0), BUG_ASSERTION_FAILED, BUG_FATAL, 0,
|
||||
(BUG_OUT, "GLUE_COND_BROADCAST returned %d, file %s, line %d", ret, file, line));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int etc_cond_destroy(etc_cond_t *cond, char *file, int line)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ETC_META_LOCK();
|
||||
ret = (int)GLUE_COND_DESTROY(&cond->c);
|
||||
ETC_META_UNLOCK();
|
||||
/* pthread_cond_destroy() and cv_delete() both return 0 on success */
|
||||
BUG_IF((ret != 0), BUG_ASSERTION_FAILED, BUG_FATAL, 0,
|
||||
(BUG_OUT, "GLUE_COND_DESTROY returned %d, file %s, line %d", ret, file, line));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/weakprng.c,v 1.3 2003/01/16 18:18:58 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: weakprng.c,v $
|
||||
* Revision 1.3 2003/01/16 18:18:58 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/06 22:15:56 tneale
|
||||
* Fixed for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:40 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.9 2001/01/19 22:21:33 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.8 2000/03/17 00:17:00 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.7 1998/03/06 20:30:45 sra
|
||||
* Fiddle seeding algorithm per Phil's recommendation.
|
||||
*
|
||||
* Revision 1.6 1998/02/25 22:08:28 mrf
|
||||
* Correct copyright dates.
|
||||
*
|
||||
* Revision 1.5 1998/02/25 15:17:07 mrf
|
||||
* Fix msvc5 compiler warnings.
|
||||
*
|
||||
* Revision 1.4 1998/02/25 04:43:28 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.3 1998/02/21 23:38:34 sra
|
||||
* Minor changes to WeakPRNG module.
|
||||
*
|
||||
* Revision 1.1 1998/02/21 22:05:36 mrf
|
||||
* Added weak random number generator.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,20apr05,job update copyright notices
|
||||
01a,11dec03,job fix copyright statements
|
||||
*/
|
||||
|
||||
|
||||
#ifndef EPILOGUE_INSTALL_H
|
||||
#include <wrn/wm/common/install.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_CONFIG_H
|
||||
#include <wrn/wm/common/config.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_GLUE_H
|
||||
#include <wrn/wm/common/glue.h>
|
||||
#endif
|
||||
|
||||
#ifndef COMMON_WEAKPRNG_H
|
||||
#include <wrn/wm/common/weakprng.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This file implements a cryptographically WEAK random number generator
|
||||
* suitable only for dithering protocol responses to avoid collisions or
|
||||
* other situations where the purpose of the "random" number is to avoid
|
||||
* simultaneity or repeated use of the same values. For any cryptographic
|
||||
* purposes, the cryptographically strong random number generator (found
|
||||
* in common/lib/prng.c) should be used instead.
|
||||
*
|
||||
* This weak generator is useful for dithering for those protocols which
|
||||
* require it (such as DHCP, RIP, IGMP, Router Discovery and IPv6 Neighbor
|
||||
* Discovery). It has relatively low processing overhead (compared to the
|
||||
* strong random number generator), and it is seeded automatically by
|
||||
* Attache.
|
||||
*
|
||||
* It is the purpose of this weak random number generator, not to produce
|
||||
* truly random numbers, but to produce numbers which are likely to be
|
||||
* different for different hosts on a given link. In order to obtain
|
||||
* this result, it is important that different hosts use different seeds.
|
||||
* Attache seeds (and re-seeds) the generator in several places with values
|
||||
* that are likely to be unique for this host. Seeds include the GLUE_NOW()
|
||||
* value at the end of the attache_init() call, the hardware address or
|
||||
* IPv6 address token provided in the net_if structure during each if_attach()
|
||||
* call, if any, and the IP addresses provided to route_add_address() each
|
||||
* time it is called. Successive seeds do not reset the generator. If a
|
||||
* customer has additional seed information that may help to improve the
|
||||
* uniqueness of the generated values for a particular host (e.g. a box
|
||||
* serial number), he can also input those seeds using the seed call below.
|
||||
*/
|
||||
|
||||
static bits32_t ep_weak_prng_value;
|
||||
|
||||
/* ep_seed_weak_prng --
|
||||
* Seeds the weak random number generator with (hopefully unique
|
||||
* for this host) seed data. Data is provided as a buffer of
|
||||
* unsigned bytes and a length (in bytes). We run the generator
|
||||
* as part of the seeding process to reduce the chance of losing
|
||||
* this seed if the generator is seeded again before it is used.
|
||||
*/
|
||||
void
|
||||
ep_seed_weak_prng(bits8_t *seed_string, size_t len)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (int) len; i++) {
|
||||
ep_weak_prng_value ^= ((bits32_t) (seed_string[i])) << (8 * (i & 3));
|
||||
if ((i & 3) == 3)
|
||||
ep_weak_prng(0xFFFFFFFFL);
|
||||
}
|
||||
ep_weak_prng(0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
/* ep_weak_prng --
|
||||
* Returns a "random" 32_bit integer less than or equal to 'max'.
|
||||
*
|
||||
* The algorithm is a linear congruential random number generator,
|
||||
* equivilent to the ANSI C rand() function but with constants that
|
||||
* provide better results than those used in the BSD rand() function.
|
||||
*
|
||||
* These constants are from Knuth, chap 3, pp 102 & 170. Don't change
|
||||
* them unless you really understand the underlying math.
|
||||
*/
|
||||
bits32_t
|
||||
ep_weak_prng(bits32_t max)
|
||||
{
|
||||
ep_weak_prng_value = (ep_weak_prng_value + 1) * 16664525L;
|
||||
|
||||
return ++max ? ep_weak_prng_value % max : ep_weak_prng_value;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#
|
||||
# Top-level makefile for Epilogue common code.
|
||||
#
|
||||
|
||||
#
|
||||
# Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
# All rights reserved. Provided under license only.
|
||||
# Distribution or other use of this software is only
|
||||
# permitted pursuant to the terms of a license agreement
|
||||
# from Wind River Systems (and is otherwise prohibited).
|
||||
# Refer to that license agreement for terms of use.
|
||||
#
|
||||
|
||||
# [clearcase]
|
||||
# modification history
|
||||
# -------------------
|
||||
# 01a,20apr05,job update copyright notices
|
||||
#
|
||||
|
||||
|
||||
$#equate(COMMON_DIRS
|
||||
$#if-installed(COMMON_DES desreal
|
||||
$#if-installed(COMMON_DES_FAKE desfake))
|
||||
lib)
|
||||
|
||||
$#makefile-init()
|
||||
|
||||
$##make-makefiles($#@($#(COMMON_DIRS)))
|
||||
|
||||
all: $#dummy()
|
||||
$##make-all($#@($#(COMMON_DIRS)))
|
||||
|
||||
sizes: $#dummy()
|
||||
$##make-sizes($#@($#(COMMON_DIRS)))
|
||||
|
||||
clean: $#dummy()
|
||||
$##make-clean($#@($#(COMMON_DIRS)))
|
||||
@@ -0,0 +1,35 @@
|
||||
;;;
|
||||
;;; Example top-level configuration for WindManage products
|
||||
;;;
|
||||
|
||||
;;; load system and compiler configurations
|
||||
loadconfig 'solgcc'
|
||||
|
||||
;;; load configurations from various products
|
||||
loadconfig 'util/common/common.cfg'
|
||||
loadconfig 'snmp/envoy.cfg'
|
||||
;loadconfig 'attache/attache.cfg'
|
||||
;loadconfig 'attache/ipv6.cfg'
|
||||
;loadconfig 'attache/tcp.cfg'
|
||||
;loadconfig 'demo/snark.cfg'
|
||||
|
||||
;;; set the top-level directory and the port directory
|
||||
equate SRCDIR '$(WIND_BASE)'
|
||||
equate SOFTPORT '$(SRCDIR)/port/solaris'
|
||||
|
||||
;;; put any modifications to the default configuration here
|
||||
;;; see product documentation for options
|
||||
|
||||
;;; write out install.h
|
||||
write-install.h '../../../h/wrn/wm/util/common/install.h'
|
||||
|
||||
;;; start building makefiles
|
||||
make-makefile '.'
|
||||
|
||||
;;; Compilation command for GNU Emacs. Keep this at the end of this file.
|
||||
;;; The lisp expression just sets the compile command for this buffer to
|
||||
;;; the command "makmak <this buffer's file name>".
|
||||
;;;
|
||||
;;; Local Variables:
|
||||
;;; eval: (set (make-local-variable 'compile-command) (concat "makmak " buffer-file-name))
|
||||
;;; End:
|
||||
@@ -0,0 +1,43 @@
|
||||
;;;
|
||||
;;; $Log$
|
||||
;;;
|
||||
;;; Config file for building an SNMP for Windows on Win32 with MSVC 6.0
|
||||
;;; Before using this file define the environment variable "WMINSTALLDIR"
|
||||
;;; to be the location of your Wind Manage SNMP installation, which must
|
||||
;;; be in a different place than the Tornado installation directory when
|
||||
;;; building a Windows agent.
|
||||
;;;
|
||||
|
||||
;;; load system and compiler configurations
|
||||
loadconfig 'msvc60'
|
||||
|
||||
;;; load configurations from various products
|
||||
loadconfig 'common/common.cfg'
|
||||
loadconfig 'snmp/envoy.cfg'
|
||||
loadconfig 'demo/snark.cfg'
|
||||
|
||||
;;; set the top-level directory and the port directory
|
||||
equate SRCDIR '$(WMINSTALLDIR)'
|
||||
equate SOFTPORT '$(SRCDIR)/target/h/wrn/wm/util/port/winsock'
|
||||
equate WMINC '$(SRCDIR)/target/h/'
|
||||
equate MIBCOMPFLAGS '-l $(WIND_BASE)/target/src/wrn/wm/snmp/std-mibs'
|
||||
|
||||
;;; put any modifications to the default configuration here
|
||||
;;; see product documentation for options
|
||||
|
||||
install ENVOY_WINSOCK_AGENT
|
||||
install COMMON_SNPRINTF
|
||||
|
||||
;;; write out install.h
|
||||
write-install.h '../../../h/wrn/wm/common/install.h'
|
||||
|
||||
;;; start building makefiles
|
||||
make-makefile '.'
|
||||
|
||||
;;; Compilation command for GNU Emacs. Keep this at the end of this file.
|
||||
;;; The lisp expression just sets the compile command for this buffer to
|
||||
;;; the command "makmak <this buffer's file name>".
|
||||
;;;
|
||||
;;; Local Variables:
|
||||
;;; eval: (set (make-local-variable 'compile-command) (concat "makmak " buffer-file-name))
|
||||
;;; End:
|
||||
@@ -0,0 +1,51 @@
|
||||
;;;
|
||||
;;; $Log$
|
||||
;;;
|
||||
;;; Config file for building an SNMP for Windows on Win32 with MSVC 6.0
|
||||
;;; Before using this file define the environment variable "WMINSTALLDIR"
|
||||
;;; to be the location of your Wind Manage SNMP installation which must
|
||||
;;; be in a different place than the Tornado installation directory when
|
||||
;;; building snmptalk
|
||||
;;;
|
||||
|
||||
;;; load system and compiler configurations
|
||||
loadconfig 'msvc60'
|
||||
|
||||
;;; load configurations from various products
|
||||
loadconfig 'common/common.cfg'
|
||||
loadconfig 'snmp/envoy.cfg'
|
||||
loadconfig 'demo/snark.cfg'
|
||||
|
||||
;;; set the top-level directory and the port directory
|
||||
equate SRCDIR '$(WMINSTALLDIR)'
|
||||
equate SOFTPORT '$(SRCDIR)/target/h/wrn/wm/util/port/winsock'
|
||||
equate WMINC '$(SRCDIR)/target/h/'
|
||||
equate MIBCOMPFLAGS '-l $(WIND_BASE)/target/src/wrn/wm/snmp/std-mibs'
|
||||
|
||||
;;; put any modifications to the default configuration here
|
||||
;;; see product documentation for options
|
||||
|
||||
install ENVOY_SNMPTALK
|
||||
install COMMON_SNPRINTF
|
||||
install ENVOY_SNMP_VERSION_3
|
||||
install SNMP_VERSION_3_LICENSED
|
||||
install ENVOY_DES
|
||||
install COMMON_MD5
|
||||
install COMMON_SHA
|
||||
install COMMON_DES
|
||||
install COMMON_HMAC
|
||||
|
||||
;;; write out install.h
|
||||
write-install.h '../../../h/wrn/wm/common/install.h'
|
||||
|
||||
;;; start building makefiles
|
||||
make-makefile '.'
|
||||
|
||||
;;; Compilation command for GNU Emacs. Keep this at the end of this file.
|
||||
;;; The lisp expression just sets the compile command for this buffer to
|
||||
;;; the command "makmak <this buffer's file name>".
|
||||
;;;
|
||||
;;; Local Variables:
|
||||
;;; eval: (set (make-local-variable 'compile-command) (concat "makmak " buffer-file-name))
|
||||
;;; End:
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
;;; $Header: /usr/cvsroot/target/src/wrn/wm/demo/deconpna.cfg,v 1.1.1.1 2001/11/05 17:48:40 tneale Exp $
|
||||
|
||||
;;; The standard configuration for pSOS
|
||||
;;;
|
||||
;;; Don't modify this file. If you want to change any of these values,
|
||||
;;; do so by putting overriding definitions into your main config file.
|
||||
|
||||
|
||||
;;; *** Restricted Rights Legend ***
|
||||
;;;
|
||||
;;; The programs and information contained herein are licensed only
|
||||
;;; pursuant to a license agreement that contains use, reverse
|
||||
;;; engineering, disclosure, and other restrictions; accordingly, it
|
||||
;;; is "Unpublished--all rights reserved under the applicable
|
||||
;;; copyright laws".
|
||||
;;;
|
||||
;;; Use duplication, or disclosure by the Government is subject to
|
||||
;;; restrictions as set forth in subparagraph (c)(1)(ii) of the Rights
|
||||
;;; in Technical Data and Computer Licensed Programs clause of DFARS
|
||||
;;; 52.227 7013.
|
||||
;;;
|
||||
;;; Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
;;; All rights reserved.
|
||||
;;;
|
||||
;;; *** Government Use ***
|
||||
;;;
|
||||
;;; The Licensed Programs and their documentation were developed at
|
||||
;;; private expense and no part of them is in the public domain.
|
||||
;;;
|
||||
;;; The Licensed Programs are "Restricted Computer Software" as that
|
||||
;;; term is defined in Clause 52.227-19 of the Federal Acquisition
|
||||
;;; Regulations (FAR) and are "Commercial Computer Software" as that
|
||||
;;; term is defined in Subpart 227.401 of the Department of Defense
|
||||
;;; Federal Acquisition Regulation Supplement (DFARS).
|
||||
;;;
|
||||
;;; (i) If the licensed Programs are supplied to the Department of
|
||||
;;; Defense (DoD), the Licensed Programs are classified as
|
||||
;;; "Commercial Computer Software" and the Government is acquiring
|
||||
;;; only "restricted rights" in the Licensed Programs and their
|
||||
;;; documentation as that term is defined in Clause 52.227
|
||||
;;; 7013(c)(1) of the DFARS, and
|
||||
;;;
|
||||
;;; (ii) If the Licensed Programs are supplied to any unit or agency
|
||||
;;; of the United States Government other than DoD, the
|
||||
;;; Government's rights in the Licensed Programs and their
|
||||
;;; documentation will be as defined in Clause 52.227-19(c)(2) of
|
||||
;;; the FAR.
|
||||
|
||||
;;; enabled by default, uninstall in the OEM's config file if not wanted
|
||||
install DECORUM_OVER_PNA
|
||||
;install PNA
|
||||
install DECORUM_OVER_PNA_MIB
|
||||
install DECORUM_OVER_PNA_NFS
|
||||
install DECORUM_OVER_PNA_UTILS
|
||||
|
||||
;;; three mutually exclusive options
|
||||
install DECORUM_OVER_PNA_NOFILE
|
||||
uninstall DECORUM_OVER_PNA_FILE
|
||||
uninstall DECORUM_OVER_PNA_DRDESIGN
|
||||
|
||||
;;; Build the Dr. Design HTTPD sample code
|
||||
|
||||
|
||||
;;; must be defined one way or the other, need no further attention
|
||||
requires ATTACHE
|
||||
requires DECORUM
|
||||
requires ENVOY
|
||||
requires DECORUM_OVER_OPEN_PSOS
|
||||
@@ -0,0 +1,541 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/bpf.c,v 1.3 2003/01/15 14:04:30 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: bpf.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:30 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:20 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:41 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.14 2001/01/19 22:23:38 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.13 2000/10/16 19:21:49 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 2.12 2000/03/17 00:12:36 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.11 2000/03/13 21:22:01 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 2.10 1999/02/18 04:41:32 wes
|
||||
* Sockets merge: Everything Else
|
||||
* - memory pools
|
||||
* - thread support
|
||||
* - port-specific headers
|
||||
*
|
||||
* Revision 2.9.12.1 1998/09/23 19:17:15 wes
|
||||
* Merge socket-branch-1 changes to socket-branch-2
|
||||
*
|
||||
* Revision 2.9.10.1 1998/08/19 13:26:22 wes
|
||||
* Merge sockets-pthreads work to shared branch
|
||||
*
|
||||
* Revision 2.9.4.1 1998/08/05 20:48:47 wes
|
||||
* XXX: Deal with mit-pthreads header file dane brammage
|
||||
*
|
||||
* Revision 2.9 1998/04/09 22:03:08 wes
|
||||
* Rip out ntohl/ntohs stuff since anyone still running NetBSD 0.8 gets what they deserve...
|
||||
*
|
||||
* Revision 2.8 1998/02/25 04:57:20 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.7 1998/02/17 18:28:53 sra
|
||||
* Add filter support for IPv4 multicast.
|
||||
*
|
||||
* Revision 2.6 1997/06/03 05:12:30 sra
|
||||
* Tighter BPF filter (souvenir of N+I Vegas '97).
|
||||
*
|
||||
* Revision 2.5 1997/04/25 01:02:25 sra
|
||||
* Fix code to set explicit MAC addresses for BPF, allow non-promiscuous mode.
|
||||
*
|
||||
* Revision 2.4 1997/03/20 06:52:51 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.3 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.2 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.1 1995/06/22 05:29:06 sra
|
||||
* Preliminary changes for multicast and OSPF.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.4 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.3 1994/09/02 21:15:48 sra
|
||||
* Add still more parentheses to the for() loop from hell in bpf_find().
|
||||
*
|
||||
* Revision 1.2 1993/07/29 04:30:26 sra
|
||||
* Don't use the inline versions of the byteswap routines, GCC gets
|
||||
* confused.
|
||||
*
|
||||
* Revision 1.1 1993/07/05 21:53:30 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* BPF interface to ethernet for attache testing under 386BSD/NetBSD/FreeBSD.
|
||||
*
|
||||
* All access to BPF should be through this module, the only thing we
|
||||
* expect our caller to do with our file descriptor is use it in
|
||||
* select() calls. There are enough name conflicts between the unix
|
||||
* networking code and the Attache networking code that it's probably
|
||||
* hopeless to have the two mingled in the same file.
|
||||
*
|
||||
* References: BPF sample RARP server
|
||||
* tcpdump { bpf_image.c, bpf_dump.c, pcap-bpf.c }
|
||||
* bpf(4) manual page
|
||||
* netintro(4) manual page
|
||||
* routed.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/bpf.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/if_types.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Stuff dealing with the BPF filter itself.
|
||||
*/
|
||||
|
||||
#ifndef INSTALL_SNARK_BSD_BPF_LOOSE_FILTER
|
||||
#define INSTALL_SNARK_BSD_BPF_LOOSE_FILTER 0
|
||||
#endif
|
||||
|
||||
#ifndef INSTALL_SNARK_BSD_BPF_NO_V4_MULTICAST
|
||||
#define INSTALL_SNARK_BSD_BPF_NO_V4_MULTICAST 0
|
||||
#endif
|
||||
|
||||
#if INSTALL_SNARK_BSD_BPF_LOOSE_FILTER
|
||||
|
||||
/*
|
||||
* Filter expression (see tcpdump(1) man page for translation):
|
||||
* '-s 1500 ether multicast or ether dst e1:e2:e3:e4:e5:e6'
|
||||
*/
|
||||
static struct bpf_insn instructions[] = {
|
||||
{ 0x30, 0, 0, 0x00000000 }, /* (000) ldb [0] */
|
||||
{ 0x45, 4, 0, 0x00000001 }, /* (001) jset #0x1 jt 6 jf 2 */
|
||||
{ 0x20, 0, 0, 0x00000002 }, /* (002) ld [2] */
|
||||
{ 0x15, 0, 3, 0xe3e4e5e6 }, /* (003) jeq #0xe3e4e5e6 jt 4 jf 7 */
|
||||
{ 0x28, 0, 0, 0x00000000 }, /* (004) ldh [0] */
|
||||
{ 0x15, 0, 1, 0x0000e1e2 }, /* (005) jeq #0xe1e2 jt 6 jf 7 */
|
||||
{ 0x6, 0, 0, 0x000005dc }, /* (006) ret #1500 */
|
||||
{ 0x6, 0, 0, 0x00000000 }, /* (007) ret #0 */
|
||||
};
|
||||
|
||||
#else /* INSTALL_SNARK_BSD_BPF_LOOSE_FILTER */
|
||||
|
||||
#if INSTALL_SNARK_BSD_BPF_NO_V4_MULTICAST
|
||||
|
||||
/*
|
||||
* Filter expression (see tcpdump(1) man page for translation):
|
||||
* '-s 1514 ether[0:2] = 0x3333 or ether broadcast or ether dst e1:e2:e3:d4:e5:e6'
|
||||
*/
|
||||
static struct bpf_insn instructions[] = {
|
||||
{ 0x28, 0, 0, 0x00000000 }, /* (000) ldh [0] */
|
||||
{ 0x15, 7, 0, 0x00003333 }, /* (001) jeq #0x3333 jt 9 jf 2 */
|
||||
{ 0x20, 0, 0, 0x00000002 }, /* (002) ld [2] */
|
||||
{ 0x15, 0, 2, 0xffffffff }, /* (003) jeq #0xffffffff jt 4 jf 6 */
|
||||
{ 0x28, 0, 0, 0x00000000 }, /* (004) ldh [0] */
|
||||
{ 0x15, 3, 4, 0x0000ffff }, /* (005) jeq #0xffff jt 9 jf 10 */
|
||||
{ 0x15, 0, 3, 0xe3d4e5e6 }, /* (006) jeq #0xe3d4e5e6 jt 7 jf 10 */
|
||||
{ 0x28, 0, 0, 0x00000000 }, /* (007) ldh [0] */
|
||||
{ 0x15, 0, 1, 0x0000e1e2 }, /* (008) jeq #0xe1e2 jt 9 jf 10 */
|
||||
{ 0x6, 0, 0, 0x000005ea }, /* (009) ret #1514 */
|
||||
{ 0x6, 0, 0, 0x00000000 }, /* (010) ret #0 */
|
||||
};
|
||||
|
||||
#else /* INSTALL_SNARK_BSD_BPF_NO_V4_MULTICAST */
|
||||
|
||||
/*
|
||||
* Filter expression (see tcpdump(1) man page for translation):
|
||||
* '-s 1514 ether[0:2] = 0x3333 or ( ether[0:2] = 0x0100 and ether[2:1] = 0x5e ) or ether broadcast or ether dst e1:e2:e3:d4:e5:e6'
|
||||
*/
|
||||
|
||||
static struct bpf_insn instructions[] = {
|
||||
{ 0x28, 0, 0, 0x00000000 }, /* (000) ldh [0] */
|
||||
{ 0x15, 10, 0, 0x00003333 }, /* (001) jeq #0x3333 jt 12 jf 2 */
|
||||
{ 0x15, 0, 2, 0x00000100 }, /* (002) jeq #0x100 jt 3 jf 5 */
|
||||
{ 0x30, 0, 0, 0x00000002 }, /* (003) ldb [2] */
|
||||
{ 0x15, 7, 0, 0x0000005e }, /* (004) jeq #0x5e jt 12 jf 5 */
|
||||
{ 0x20, 0, 0, 0x00000002 }, /* (005) ld [2] */
|
||||
{ 0x15, 0, 2, 0xffffffff }, /* (006) jeq #0xffffffff jt 7 jf 9 */
|
||||
{ 0x28, 0, 0, 0x00000000 }, /* (007) ldh [0] */
|
||||
{ 0x15, 3, 4, 0x0000ffff }, /* (008) jeq #0xffff jt 12 jf 13 */
|
||||
{ 0x15, 0, 3, 0xe3d4e5e6 }, /* (009) jeq #0xe3d4e5e6 jt 10 jf 13 */
|
||||
{ 0x28, 0, 0, 0x00000000 }, /* (010) ldh [0] */
|
||||
{ 0x15, 0, 1, 0x0000e1e2 }, /* (011) jeq #0xe1e2 jt 12 jf 13 */
|
||||
{ 0x6, 0, 0, 0x000005ea }, /* (012) ret #1514 */
|
||||
{ 0x6, 0, 0, 0x00000000 }, /* (013) ret #0 */
|
||||
};
|
||||
|
||||
#endif /* INSTALL_SNARK_BSD_BPF_NO_V4_MULTICAST */
|
||||
|
||||
#endif /* INSTALL_SNARK_BSD_BPF_LOOSE_FILTER */
|
||||
|
||||
struct bpf_program filter = {
|
||||
sizeof(instructions) / sizeof(*instructions),
|
||||
instructions
|
||||
};
|
||||
|
||||
/*
|
||||
* Macros to set filter componants at runtime. These macros should
|
||||
* be the only code that knows anything about the guts of the filter.
|
||||
*
|
||||
* SET_FILTER_MAC sets the filter's MAC addr (in case the board is
|
||||
* in promiscuous mode) to the value of the six-byte string given
|
||||
* as an argument. Presumably this is from the sockaddr sa_data field
|
||||
* or an explict argument given to bpf_open().
|
||||
*
|
||||
* SET_FILTER_MTU sets the filter MTU for inbound packets; this is really
|
||||
* the truncation length for the kernel, but since it should match the
|
||||
* buffer size you're using it's effectively the same thing.
|
||||
*/
|
||||
|
||||
#if INSTALL_SNARK_BSD_BPF_LOOSE_FILTER
|
||||
|
||||
#define SET_FILTER_MAC(_x_) \
|
||||
do { \
|
||||
instructions[5].k = ntohs(*(u_short *) ((_x_)+0)); \
|
||||
instructions[3].k = ntohl(*(u_long *) ((_x_)+2)); \
|
||||
} while (0)
|
||||
|
||||
#define SET_FILTER_MTU(_x_) \
|
||||
do { \
|
||||
instructions[6].k = (_x_); \
|
||||
} while (0)
|
||||
|
||||
#else /* INSTALL_SNARK_BSD_BPF_LOOSE_FILTER */
|
||||
|
||||
#if INSTALL_SNARK_BSD_BPF_NO_V4_MULTICAST
|
||||
|
||||
#define SET_FILTER_MAC(_x_) \
|
||||
do { \
|
||||
instructions[8].k = ntohs(*(u_short *) ((_x_)+0)); \
|
||||
instructions[6].k = ntohl(*(u_long *) ((_x_)+2)); \
|
||||
} while (0)
|
||||
|
||||
#define SET_FILTER_MTU(_x_) \
|
||||
do { \
|
||||
instructions[9].k = (_x_); \
|
||||
} while (0)
|
||||
|
||||
#else /* INSTALL_SNARK_BSD_BPF_NO_V4_MULTICAST */
|
||||
|
||||
#define SET_FILTER_MAC(_x_) \
|
||||
do { \
|
||||
instructions[11].k = ntohs(*(u_short *) ((_x_)+0)); \
|
||||
instructions[ 9].k = ntohl(*(u_long *) ((_x_)+2)); \
|
||||
} while (0)
|
||||
|
||||
#define SET_FILTER_MTU(_x_) \
|
||||
do { \
|
||||
instructions[12].k = (_x_); \
|
||||
} while (0)
|
||||
|
||||
#endif /* INSTALL_SNARK_BSD_BPF_NO_V4_MULTICAST */
|
||||
|
||||
#endif /* INSTALL_SNARK_BSD_BPF_LOOSE_FILTER */
|
||||
|
||||
/*
|
||||
* Macro for calculating the size of buffer to tell BPF to use, based
|
||||
* on the MTU of the interface. This would be the BPF header size
|
||||
* plus the MTU, except that BPF does some rounding for alignment. The
|
||||
* intent is that the size of buffer we use be just big enough that
|
||||
* BPF will never truncate a packet that we know how to handle.
|
||||
*/
|
||||
|
||||
#define ROUNDED_BPF_MTU(_x_) \
|
||||
(BPF_WORDALIGN((_x_)) + BPF_WORDALIGN(sizeof(struct bpf_hdr)))
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Open a BPF file and attach it to the interface named 'device'.
|
||||
* Returns BPF file descriptor, or -1 if an error occurs.
|
||||
*
|
||||
* This is cobbled together from code in rarpd and tcpdump.
|
||||
*/
|
||||
|
||||
int bpf_open(char *ifname, unsigned mtu, unsigned char *mac, int promiscuous)
|
||||
{
|
||||
struct bpf_version bv;
|
||||
struct ifreq ifr;
|
||||
int fd, i;
|
||||
u_int u;
|
||||
|
||||
/*
|
||||
* Look for a BPF device that's not in use.
|
||||
*/
|
||||
i = 0;
|
||||
do {
|
||||
char bpfname[sizeof "/dev/bpf000"];
|
||||
(void) sprintf(bpfname, "/dev/bpf%d", i++);
|
||||
fd = open(bpfname, O_RDWR);
|
||||
} while (fd < 0 && errno == EBUSY);
|
||||
if (fd < 0) {
|
||||
perror("couldn't get a BPF device");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the filter language version number.
|
||||
*/
|
||||
if (ioctl(fd, BIOCVERSION, (char *) &bv) < 0) {
|
||||
fprintf(stderr, "kernel BPF interpreter out of date");
|
||||
return -1;
|
||||
} else if (bv.bv_major != BPF_MAJOR_VERSION ||
|
||||
bv.bv_minor < BPF_MINOR_VERSION) {
|
||||
fprintf(stderr, "requires BPF language %d.%d or higher; kernel is %d.%d",
|
||||
BPF_MAJOR_VERSION, BPF_MINOR_VERSION, bv.bv_major, bv.bv_minor);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set immediate mode so packets are processed as they arrive.
|
||||
*/
|
||||
i = 1;
|
||||
if (ioctl(fd, BIOCIMMEDIATE, (char *) &i) < 0) {
|
||||
perror("BIOCIMMEDIATE");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the read() buffer size.
|
||||
*/
|
||||
u = ROUNDED_BPF_MTU(mtu);
|
||||
if (ioctl(fd, BIOCSBLEN, (char *) &u) < 0) {
|
||||
perror("BIOCSBLEN");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Attach the BPF device to the interface.
|
||||
*/
|
||||
(void) strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||
if (ioctl(fd, BIOCSETIF, (char *) &ifr) < 0) {
|
||||
perror("BIOCSETIF");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that the data link layer is an Ethernet; this code won't
|
||||
* work with anything else.
|
||||
*/
|
||||
if (ioctl(fd, BIOCGDLT, (char *) &u) < 0) {
|
||||
perror("BIOCGDLT");
|
||||
return -1;
|
||||
}
|
||||
if (u != DLT_EN10MB) {
|
||||
fprintf(stderr, "%s is not an ethernet", ifname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Put the interface in promiscuous mode so we'll see packets
|
||||
* to our faked MAC address.
|
||||
*/
|
||||
if (promiscuous && ioctl(fd, BIOCPROMISC, 0) < 0) {
|
||||
perror("BIOCPROMISC");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we were given a MAC address, use it to set up a filter.
|
||||
* Otherwise, assume we're happy being in promiscuous mode.
|
||||
*/
|
||||
if (mac) {
|
||||
SET_FILTER_MAC(mac);
|
||||
SET_FILTER_MTU(mtu);
|
||||
if (ioctl(fd, BIOCSETF, (char *) &filter) < 0) {
|
||||
perror("BIOCSETF");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Read a BPF buffer and hand its contents off to Attache as packets.
|
||||
* This is based on the readloop() function in tcpdump's BPF code.
|
||||
*
|
||||
* The handler routine supplied by the Attache-side code gets three
|
||||
* arguments: a pointer to the packet data, the length of the packet
|
||||
* data, and the length that the real packet was on the wire.
|
||||
*
|
||||
* There's probably nothing useful that Attache can do with a truncated
|
||||
* packet, but the info is there, so we may as well pass it along.
|
||||
*/
|
||||
|
||||
#define bhp ((struct bpf_hdr *) bp)
|
||||
|
||||
#if defined(__NetBSD__) && defined(INSTALL_SNARK_THREADS)
|
||||
/* mit_pthreads has broken stdlib.h !!! */
|
||||
#if !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
|
||||
#if defined(alloca) && (alloca == __builtin_alloca) && (__GNUC__ < 2)
|
||||
void *alloca __P((int)); /* built-in for gcc */
|
||||
#else
|
||||
void *alloca __P((size_t));
|
||||
#endif /* __GNUC__ */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int bpf_read
|
||||
(int fd,
|
||||
unsigned mtu,
|
||||
void (*handler)(unsigned char *, unsigned, unsigned, void *),
|
||||
void *cookie)
|
||||
{
|
||||
unsigned char *buf, *bp, *ep;
|
||||
int i;
|
||||
|
||||
mtu = ROUNDED_BPF_MTU(mtu);
|
||||
|
||||
if ((buf = (unsigned char *) alloca(mtu)) == 0) {
|
||||
fprintf(stderr, "alloca(%d) failed\n", mtu);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to read a packet, restart if we get screwed by the debugger.
|
||||
* Return on other error or on EOF.
|
||||
*/
|
||||
do {
|
||||
i = read(fd, buf, mtu);
|
||||
} while (i < 0 && errno == EINTR);
|
||||
if (i <= 0)
|
||||
return i;
|
||||
|
||||
/*
|
||||
* Got a buffer full of data, chop it into packets and hand it off.
|
||||
*/
|
||||
bp = buf;
|
||||
ep = bp + i;
|
||||
for (i = 0; bp < ep; ++i) {
|
||||
handler(bp + bhp->bh_hdrlen, bhp->bh_caplen, bhp->bh_datalen, cookie);
|
||||
bp += BPF_WORDALIGN(bhp->bh_caplen + bhp->bh_hdrlen);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the number of packets we got.
|
||||
*/
|
||||
return i;
|
||||
}
|
||||
|
||||
#undef bhp
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Write a packet to the BPF file. Per BPF manual page, we can only
|
||||
* write one packet at a time. This shouldn't be a problem.
|
||||
*/
|
||||
|
||||
int bpf_write(int fd, unsigned char *data, unsigned datalen)
|
||||
{
|
||||
return write(fd, data, datalen);
|
||||
}
|
||||
|
||||
/*
|
||||
* Close a BPF interface.
|
||||
*/
|
||||
|
||||
void bpf_close(int fd)
|
||||
{
|
||||
(void) close(fd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined(SIOCGIFCONF)
|
||||
|
||||
/*
|
||||
* Find all ethernet interfaces. Works on NetBSD, your milage may vary.
|
||||
* The "array" returned by SIOCGIFCONF is kinda bizzare....
|
||||
*/
|
||||
|
||||
void bpf_find(void (*handler)(char *, void *), void *cookie)
|
||||
{
|
||||
char buffer[5000];
|
||||
struct ifconf ifc;
|
||||
struct ifreq *ifr;
|
||||
int s;
|
||||
|
||||
if (!handler)
|
||||
return;
|
||||
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("socket");
|
||||
return;
|
||||
}
|
||||
ifc.ifc_len = sizeof(buffer);
|
||||
ifc.ifc_buf = buffer;
|
||||
if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0) {
|
||||
perror("ioctl");
|
||||
(void) close(s);
|
||||
return;
|
||||
}
|
||||
for (ifr = ifc.ifc_req;
|
||||
((char *) ifr) < ifc.ifc_buf + ifc.ifc_len;
|
||||
ifr = ((struct ifreq *)
|
||||
(((char *) ifr) + sizeof(ifr->ifr_name) + ifr->ifr_addr.sa_len)))
|
||||
if (ifr->ifr_addr.sa_family == AF_LINK &&
|
||||
((struct sockaddr_dl *) &ifr->ifr_addr)->sdl_type == IFT_ETHER)
|
||||
handler(ifr->ifr_name, cookie);
|
||||
(void) close(s);
|
||||
}
|
||||
|
||||
#endif /* defined(SIOCGIFCONF) */
|
||||
@@ -0,0 +1,424 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/bpfdrive.c,v 1.4 2003/01/15 14:04:30 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: bpfdrive.c,v $
|
||||
* Revision 1.4 2003/01/15 14:04:30 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.3 2001/11/08 15:56:20 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.2 2001/11/06 20:11:11 josh
|
||||
* updating include paths to include proper path to layout directory
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:41 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.28 2001/01/19 22:23:39 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.27 2000/12/02 20:27:16 sar
|
||||
* Set pkt_datalen before call et_rcv so that we know how many bytes
|
||||
* we actually received in upper layers
|
||||
*
|
||||
* Revision 2.26 2000/10/16 19:21:49 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 2.25 2000/03/17 00:12:36 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.24 2000/03/13 21:22:02 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 2.23 1999/11/05 22:29:04 paul
|
||||
* Updated driver structs to reflect conditional backwards-compatibility
|
||||
* fields and new fields.
|
||||
*
|
||||
* Revision 2.22 1999/10/19 23:07:54 sar
|
||||
* Add et_ipv6_send_pkt as the ipv6 send routine
|
||||
*
|
||||
* Revision 2.21 1999/03/25 20:25:09 wes
|
||||
* provide install option for subinstances (on by default)
|
||||
*
|
||||
* Revision 2.20 1998/10/28 18:50:54 josh
|
||||
* marging in courier-sep98 branch
|
||||
*
|
||||
* Revision 2.19.8.1 1998/09/11 05:50:22 sra
|
||||
* Initial commit on courier-sep98 branch.
|
||||
*
|
||||
* Revision 2.19 1998/02/25 15:21:46 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 2.18 1998/02/25 04:57:21 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.17 1997/06/06 17:39:15 sra
|
||||
* Get rid of unused variable warning in bpf_driver_send().
|
||||
*
|
||||
* Revision 2.16 1997/05/22 18:51:47 mrf
|
||||
* add ipv4_send routine to driver structure
|
||||
*
|
||||
* Revision 2.15 1997/05/20 20:41:00 mrf
|
||||
* remove reference to 'struct bb_ether' (now departed)
|
||||
*
|
||||
* Revision 2.14 1997/05/20 02:08:03 mrf
|
||||
* ipaddr_t, ldb macro and routing api conversion of media layer and arp code
|
||||
*
|
||||
* Revision 2.13 1997/05/07 17:23:34 mrf
|
||||
* move ipv6_send function to end of net_if structure
|
||||
*
|
||||
* Revision 2.11 1997/04/25 01:02:24 sra
|
||||
* Fix code to set explicit MAC addresses for BPF, allow non-promiscuous mode.
|
||||
*
|
||||
* Revision 2.10 1997/04/19 02:47:58 mrf
|
||||
* added basic ipv6 code, config ipv6 addresses, added new ipv6_send handler
|
||||
* to snoop and bpf driver structures, added configurable maxlnt and cleaned
|
||||
* up makefile.cfg formatting error
|
||||
*
|
||||
* Revision 2.9 1997/03/20 06:52:52 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.8 1997/02/27 21:34:23 josh
|
||||
* changed (cookie *) to (void *) in bpf_driver_read()
|
||||
*
|
||||
* Revision 2.7 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.6 1997/02/19 08:10:29 sra
|
||||
* More fun merging snmptalk into snark, general snark cleanup.
|
||||
*
|
||||
* Revision 2.5 1997/01/28 18:43:33 lowell
|
||||
* support for having a hardware address *before* an IP address
|
||||
* (what a concept)
|
||||
*
|
||||
* Revision 2.4 1996/07/09 18:54:14 lowell
|
||||
* go back to using IP address for part of ethernet address;
|
||||
* but only if if there *is* an IP address
|
||||
*
|
||||
* Revision 2.3 1996/04/23 22:05:58 lowell
|
||||
* added ARP-for-my-own-address on startup
|
||||
* (to solve problems associated with making up ethernet addresses
|
||||
* out of thin air)
|
||||
*
|
||||
* Revision 2.2 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.1 1995/10/04 23:49:53 lowell
|
||||
* added media control routine and changed the generation of ethernet
|
||||
* addresses so they don't depend on already having an IP address
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.6 1995/03/03 21:02:32 sra
|
||||
* Add installation option for workaround for erroneous BPF byteswap of
|
||||
* ethernet type field on output, since this kernel bug seems to have
|
||||
* resurfaced in FreeBSD 2.0.
|
||||
*
|
||||
* Revision 1.5 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.4 1994/09/04 06:13:38 sra
|
||||
* Clean up antique type names and install macros.
|
||||
*
|
||||
* Revision 1.3 1994/08/08 08:30:47 sra
|
||||
* Turn off byteswap kludge, now that FreeBSD has fixed the BPF bug.
|
||||
*
|
||||
* Revision 1.2 1994/01/09 23:57:29 sra
|
||||
* Add support for NIT under SunOS 4.1.2.
|
||||
*
|
||||
* Revision 1.1 1993/07/05 21:53:30 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Berkeley Packet Filter (BPF) network interface for snark package.
|
||||
*
|
||||
* This has only been tested on NetBSD 0.8, it will probably work on other
|
||||
* BSD-Net2-derived systems, and may work with minor modifications on other
|
||||
* BSD-related systems with BPF (eg, SunOS with the BPF additions supplied
|
||||
* with the tcpdump program distributed by LBL).
|
||||
*
|
||||
* This file contains the Attache driver code for BPF.
|
||||
*
|
||||
* There are a couple of slightly strange things about this code.
|
||||
*
|
||||
* 1) We need a fake MAC address for each interface, not because Attache
|
||||
* cares but because it's the easiest way to get BPF to do the right
|
||||
* thing without all kinds of bizzare interactions with the unix
|
||||
* routing code. We cons up addresses by borrowing a disused vendor
|
||||
* componant (listed as "obsolete") and using pieces of snark's
|
||||
* process ID and the UNIX machine's host ID for the remaining
|
||||
* octets of the MAC address. This should generate locally unique
|
||||
* MAC addresses on (almost) any IP network.
|
||||
*
|
||||
* We used to use snark's IP address, but that won't work when we
|
||||
* don't have an IP address (as I realized when trying to test
|
||||
* DHCP). This approach does result in a different MAC address
|
||||
* every time (necessary to run multiple snark instances in
|
||||
* parallel), so the net-configuring code has to ARP for its own
|
||||
* address after installing an address.
|
||||
*
|
||||
* 2) The current BPF implementation (on NetBSD 0.8, anyway) barfs
|
||||
* when I attempt to write() a packet longer than 1024 octets, so
|
||||
* the IP MTU for this interface is 1010 octets (1024 - lnh - lnt)
|
||||
* rather than 1500.
|
||||
* */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/ether.h>
|
||||
#include <wrn/wm/attache/arp.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include <wrn/wm/util/layout/ldbglue.h>
|
||||
#include <wrn/wm/util/layout/ethernet.h>
|
||||
#include <wrn/wm/util/layout/arp.h>
|
||||
#include <wrn/wm/demo/bpf.h>
|
||||
#include <wrn/wm/demo/bsdif.h>
|
||||
#include <wrn/wm/demo/bpfdrive.h>
|
||||
|
||||
struct bpf_driver_private {
|
||||
bits8_t mac[6]; /* MAC address for this interface */
|
||||
};
|
||||
|
||||
#define TEN_MEGABITS 10000000
|
||||
|
||||
#ifndef IFNAMELEN
|
||||
#define IFNAMELEN 20
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Routines to read (struct bsdif) generic network interface.
|
||||
*/
|
||||
|
||||
static void bpf_driver_rcv
|
||||
(unsigned char *buffer,
|
||||
unsigned buffer_length,
|
||||
unsigned network_length,
|
||||
void *cookie)
|
||||
{
|
||||
packet *p;
|
||||
|
||||
if (buffer_length != network_length || (p = pkt_alloc(buffer_length)) == 0)
|
||||
return;
|
||||
MEMCPY(p->pkt_buffer, buffer, buffer_length);
|
||||
p->pkt_datalen = buffer_length;
|
||||
p->pkt_n = cookie;
|
||||
et_rcv(p);
|
||||
}
|
||||
|
||||
static void bpf_driver_read (int fd, void *cookie, unsigned flags)
|
||||
{
|
||||
struct net *net = cookie;
|
||||
if ((net->flags & NF_DRIVER_DOWN) == 0 && (flags & BSDIF_READ) != 0)
|
||||
(void) bpf_read(fd, net->driver->maxlen, bpf_driver_rcv, net);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Attache device driver routines for BPF.
|
||||
*/
|
||||
|
||||
/*
|
||||
#include <wrn/wm/demo/read_ini.h>
|
||||
*/
|
||||
static void bpf_driver_init (struct net *net)
|
||||
{
|
||||
/* This prefix is from "obsolete" portion of DEC's space (see RFC-1340). */
|
||||
static bits8_t bpf_driver_mac_prefix[3] = { 0xAA, 0x00, 0x00 };
|
||||
struct bsdif *bif = net->specific;
|
||||
struct bpf_driver_private *private;
|
||||
char name[IFNAMELEN];
|
||||
|
||||
STRCPY(name, net->s_name + STRLEN(net->driver->prefix));
|
||||
if (isalpha(name[STRLEN(name) - 1]))
|
||||
name[STRLEN(name) - 1] = '\0';
|
||||
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
net->speed = TEN_MEGABITS;
|
||||
|
||||
/*
|
||||
* Pick a MAC address to use. If there's already one specified,
|
||||
* use it. Otherwise, if we're in 2.x backwards compatability mode and have
|
||||
* an IP address, use it, otherwise try to generate something unique.
|
||||
*/
|
||||
if (!net->h_address) {
|
||||
if ((bif->private = private = GLUE_ALLOC(sizeof(*private))) == 0)
|
||||
return;
|
||||
net->ha_len = sizeof(private->mac);
|
||||
net->h_address = private->mac;
|
||||
MEMCPY(private->mac+0, bpf_driver_mac_prefix, 3);
|
||||
if (net->ip_addr) {
|
||||
MEMCPY(private->mac + 3, ((bits8_t *) &net->ip_addr) + 1, 3);
|
||||
} else {
|
||||
pid_t proc = getpid();
|
||||
bits32_t hostid = gethostid();
|
||||
private->mac[3] ^= (bits8_t) (proc & 0xff);
|
||||
private->mac[4] ^= (bits8_t) (proc >> 8 & 0xff);
|
||||
private->mac[5] ^= (bits8_t) (hostid & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
if ((bif->fd = bpf_open(name, net->driver->maxlen, net->h_address,
|
||||
INSTALL_SNARK_BSD_BPF_PROMISCUOUS)) < 0)
|
||||
return;
|
||||
|
||||
bif->handler = bpf_driver_read;
|
||||
bif->flags |= BSDIF_READ;
|
||||
net->flags &= ~NF_DRIVER_DOWN;
|
||||
}
|
||||
|
||||
static void bpf_driver_send (struct packet *p)
|
||||
{
|
||||
struct bsdif *bif = p->pkt_n->specific;
|
||||
|
||||
#if INSTALL_SNARK_BSD_BPF_SWAP_OUTPUT_ETHERTYPE
|
||||
/*
|
||||
* Some versions of BPF code byte swap the ethernet type field.
|
||||
* Enable the following two lines to kludge around this.
|
||||
*/
|
||||
{
|
||||
bits16_t type = SWAP16(GET_ETHERNET_HEADER_TYPE(p->pkt_data));
|
||||
SET_ETHERNET_HEADER_TYPE(p->pkt_data, type);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Send the packet, logging any error that might occur.
|
||||
* If the driver is down, just drop the packet.
|
||||
*/
|
||||
if ((p->pkt_n->flags & NF_DRIVER_DOWN) == 0 &&
|
||||
bpf_write(bif->fd, p->pkt_data, p->pkt_datalen) < 0)
|
||||
perror("BPF write() failure");
|
||||
pkt_free(p);
|
||||
}
|
||||
|
||||
static void bpf_driver_close (struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
|
||||
if ((net->flags & NF_DRIVER_DOWN) == 0) {
|
||||
bpf_close(bif->fd);
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
}
|
||||
if (bif->private) {
|
||||
GLUE_FREE(bif->private);
|
||||
bif->private = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static struct driver bpf_driver = {
|
||||
bpf_driver_init, /* Interface initialization routine */
|
||||
bpf_driver_send, /* Raw packet send routine */
|
||||
0, /* IP packet send back compat routine */
|
||||
et_arp_send, /* ARP packet send encapsulation routine */
|
||||
0, /* Test routine (unused) */
|
||||
bpf_driver_close, /* Interface close routine */
|
||||
"bpf", /* Driver short name */
|
||||
"Berkeley Packet Filter Ethernet", /* Driver long name */
|
||||
14, /* Local net header length */
|
||||
0, /* Local net trailer length */
|
||||
#if 0
|
||||
1514, /* Real Ethernet frame size is this... */
|
||||
#else
|
||||
1024, /* ...but this is the most BPF can handle */
|
||||
#endif
|
||||
IF_ETHERNET, /* MIB type of interfaces using this driver */
|
||||
ARP_HEADER_HARDWARE_TYPE_is_ETHERNET,
|
||||
#if !INSTALL_ATTACHE_ETHERNET_NO_MEDIA_CTL
|
||||
et_media_ctl, /* Media control routine, if installed */
|
||||
#else
|
||||
0,
|
||||
#endif /* !INSTALL_ATTACHE_ETHERNET_NO_MEDIA_CTL */
|
||||
#if INSTALL_ATTACHE_IPV6
|
||||
et_ipv6_send, /* IPv6 send routine, if installed */
|
||||
#else
|
||||
0,
|
||||
#endif /* INSTALL_ATTACHE_IPV6 */
|
||||
#if INSTALL_ATTACHE_IPV4
|
||||
et_ipv4_send /* IPv4 send routine, if installed */
|
||||
#else
|
||||
0
|
||||
#endif /* INSTALL_ATTACHE_IPV4 */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Routines for finding BPF interface devices.
|
||||
* This is just a wrapper to add the Attache-specific things onto bpf_find().
|
||||
*/
|
||||
|
||||
struct bpf_driver_find_state {
|
||||
void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t);
|
||||
int instance;
|
||||
};
|
||||
|
||||
static void bpf_driver_find_one(char *name, void *cookie)
|
||||
{
|
||||
struct bpf_driver_find_state *state = cookie;
|
||||
|
||||
state->config(name, &bpf_driver, state->instance++, NF_ARP,
|
||||
bpf_driver.maxlen - bpf_driver.lnh - bpf_driver.lnt,
|
||||
TEN_MEGABITS);
|
||||
|
||||
#if INSTALL_SNARK_BSD_BPF_SUBINSTANCES
|
||||
{
|
||||
char c;
|
||||
for (c = 'a'; c <= 'z'; c++)
|
||||
{
|
||||
char name_[IFNAMELEN];
|
||||
sprintf(name_, "%s%c", name, c);
|
||||
state->config(name_, &bpf_driver, state->instance++, NF_ARP,
|
||||
bpf_driver.maxlen - bpf_driver.lnh - bpf_driver.lnt,
|
||||
TEN_MEGABITS);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void bpf_driver_find
|
||||
(void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t))
|
||||
{
|
||||
struct bpf_driver_find_state state;
|
||||
state.config = config;
|
||||
state.instance = 0;
|
||||
bpf_find(bpf_driver_find_one, &state);
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/bug_conf.c,v 1.3 2003/01/15 14:04:30 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/* Run-time configuration of the BUG() macro and friends. */
|
||||
|
||||
/*
|
||||
* $Log: bug_conf.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:30 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:20 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:41 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.21 2001/01/19 22:23:39 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.20 2000/10/16 19:21:49 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 1.19 2000/03/17 00:12:37 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.18 2000/03/13 21:22:04 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 1.17 1999/04/26 19:04:59 sra
|
||||
* Fix a few minor warnings, fix a few Solaris-specific problems in the
|
||||
* demo code.
|
||||
*
|
||||
* Revision 1.16 1999/02/19 22:16:52 wes
|
||||
* Silence a format warning
|
||||
*
|
||||
* Revision 1.15 1999/02/18 04:41:32 wes
|
||||
* Sockets merge: Everything Else
|
||||
* - memory pools
|
||||
* - thread support
|
||||
* - port-specific headers
|
||||
*
|
||||
* Revision 1.14.8.4 1999/01/04 20:54:32 wes
|
||||
* Use reentrant localtime_r if threaded on UNIX
|
||||
*
|
||||
* Revision 1.14.8.3 1998/11/13 18:17:23 wes
|
||||
* Make SNARK_*LOCK*() calls into the "real" attache global lock
|
||||
* ATTACHE_*LOCK*() and make it live in attache-land, not snark-land.
|
||||
*
|
||||
* Revision 1.14.8.2 1998/10/01 21:45:22 wes
|
||||
* sockets port: add new configurable bug action: yield the processor
|
||||
*
|
||||
* Revision 1.14.8.1 1998/09/23 19:17:17 wes
|
||||
* Merge socket-branch-1 changes to socket-branch-2
|
||||
*
|
||||
* Revision 1.14.6.1 1998/08/19 13:26:25 wes
|
||||
* Merge sockets-pthreads work to shared branch
|
||||
*
|
||||
* Revision 1.14.2.1 1998/08/05 20:48:49 wes
|
||||
* XXX: Deal with mit-pthreads header file dane brammage
|
||||
*
|
||||
* Revision 1.14 1998/07/02 06:55:35 sra
|
||||
* Make Snark restartable under pSOS, and other minor cleanups.
|
||||
*
|
||||
* Revision 1.13 1998/02/25 15:21:47 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 1.12 1998/02/25 04:57:23 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.11 1997/05/15 07:54:06 sra
|
||||
* Add IDENT option.
|
||||
*
|
||||
* Revision 1.10 1997/04/15 06:05:31 sra
|
||||
* Fix bug_timestamp().
|
||||
*
|
||||
* Revision 1.9 1997/03/20 06:52:50 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 1.8 1997/03/19 22:05:28 sra
|
||||
* Perhaps we should include install.h before testing install options?
|
||||
*
|
||||
* Revision 1.7 1997/03/19 20:20:06 sra
|
||||
* Remove gratuitous Attache dependencies.
|
||||
*
|
||||
* Revision 1.6 1997/03/19 04:47:35 sra
|
||||
* Get rid of some gratuitous historical dependencies on Attache.
|
||||
*
|
||||
* Revision 1.5 1997/03/19 04:11:35 sra
|
||||
* BUG() now common to all products, so move the associated .h files.
|
||||
*
|
||||
* Revision 1.4 1997/03/09 18:38:00 sra
|
||||
* Track changes in keyword module.
|
||||
*
|
||||
* Revision 1.3 1997/02/25 08:14:25 sra
|
||||
* Fiddle bug_timestamp().
|
||||
*
|
||||
* Revision 1.2 1997/02/24 00:56:59 sra
|
||||
* Support for run-time configuration of BUG() macros.
|
||||
*
|
||||
* Revision 1.1 1997/02/23 21:56:22 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#if INSTALL_ATTACHE_THREADS
|
||||
#include <wrn/wm/attache/attthd.h>
|
||||
#endif
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
#include <wrn/wm/demo/read_ini.h>
|
||||
|
||||
|
||||
static struct bug_table {
|
||||
char *name;
|
||||
enum bug_codes code;
|
||||
} bugtab[] = {
|
||||
#define BUGDEF(x) { #x , x },
|
||||
#include <wrn/wm/common/bugdef.h>
|
||||
#undef BUGDEF
|
||||
};
|
||||
|
||||
static struct keyword_table bug_keywords;
|
||||
|
||||
unsigned bug_flags[sizeof(bugtab)/sizeof(*bugtab)];
|
||||
|
||||
int
|
||||
bug_breakpoint(enum bug_codes code, void *cookie, int fatal)
|
||||
{
|
||||
return fatal;
|
||||
}
|
||||
|
||||
/*
|
||||
* This really ought to use the Attache time service
|
||||
* and POSIX functions, but it's a pain to do right
|
||||
* and this is just noncritical debugging code anyway.
|
||||
* Fix later.
|
||||
*/
|
||||
|
||||
#ifdef INSTALL_on_unix
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#if defined(__NetBSD__) && defined(INSTALL_ATTACHE_THREADS)
|
||||
/* !!! mit_pthreads strftime() prototype is inexplicably commented out */
|
||||
size_t strftime __P((char *, size_t, const char *, const struct tm *));
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
bug_timestamp(struct sty *sty)
|
||||
{
|
||||
char ts[30];
|
||||
struct timeval tv;
|
||||
struct tm *tm;
|
||||
#if INSTALL_ATTACHE_THREADS
|
||||
struct tm tms;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* time-related functions appear to have races on Solaris.
|
||||
*/
|
||||
gettimeofday(&tv, 0);
|
||||
#if INSTALL_ATTACHE_THREADS
|
||||
tm = localtime_r(&tv.tv_sec, &tms);
|
||||
#else
|
||||
tm = localtime(&tv.tv_sec);
|
||||
#endif
|
||||
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
|
||||
|
||||
|
||||
sty_printf(sty, "%s.%06lu: ", ts, (unsigned long)tv.tv_usec);
|
||||
}
|
||||
|
||||
#else /* INSTALL_on_unix */
|
||||
|
||||
void
|
||||
bug_timestamp(struct sty *sty)
|
||||
{
|
||||
unsigned long now = GLUE_NOW(); /* sic */
|
||||
sty_printf(sty, "%lu.%03lu: ", now / 1000, now % 1000);
|
||||
}
|
||||
|
||||
#endif /* INSTALL_on_unix */
|
||||
|
||||
void bug_yield(enum bug_codes code, char *file, int line)
|
||||
{
|
||||
#if INSTALL_ATTACHE_THREADS
|
||||
ETC_THD_YIELD();
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
bug_config_1(struct ini_handle *ini_handle, char *name, unsigned flag)
|
||||
{
|
||||
static char snark_section[] = "etc snark bug";
|
||||
struct bug_table *t;
|
||||
char *s;
|
||||
int i;
|
||||
|
||||
for (s = ini_iter_start(ini_handle, snark_section, name); s;
|
||||
s = ini_iter_next(ini_handle))
|
||||
if (s[0] == '*' && s[1] == '\0')
|
||||
for (i = 0; i < sizeof(bugtab)/sizeof(*bugtab); i++)
|
||||
bug_flags[i] ^= flag;
|
||||
else if ((t = keyword_find(&bug_keywords, s)) != 0)
|
||||
bug_flags[(int) (t->code)] ^= flag;
|
||||
else
|
||||
fprintf(stderr, "%% [%s] %s: Unknown bug name \"%s\"\n",
|
||||
snark_section, name, s);
|
||||
}
|
||||
|
||||
void
|
||||
bug_config(void)
|
||||
{
|
||||
struct ini_handle *ini_handle = ini_open(256);
|
||||
KEYWORD_INIT(&bug_keywords, bugtab);
|
||||
bug_config_1(ini_handle, "print", BUG_FLAG_PRINT);
|
||||
bug_config_1(ini_handle, "break", BUG_FLAG_BREAK);
|
||||
bug_config_1(ini_handle, "fatal", BUG_FLAG_FATAL);
|
||||
bug_config_1(ini_handle, "ident", BUG_FLAG_IDENT);
|
||||
bug_config_1(ini_handle, "yield", BUG_FLAG_YIELD);
|
||||
ini_close(ini_handle);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/cksum.c,v 1.3 2003/01/15 14:04:31 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: cksum.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:31 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:20 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:41 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.3 2001/01/19 22:23:40 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.2 2000/03/17 00:12:37 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.1 1998/07/15 20:58:21 sra
|
||||
* Initial version.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Checksum routine for Snark demos.
|
||||
* You can almost certainly do better than this in assembly language.
|
||||
*/
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
#ifndef INSTALL_SNARK_GLUE_CKSUM_ALIGNMENT_KLUDGE
|
||||
#define INSTALL_SNARK_GLUE_CKSUM_ALIGNMENT_KLUDGE defined(__sparc__)
|
||||
#endif
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
|
||||
/*
|
||||
* This code is borrowed from RFC 1071. Note that our checksum function
|
||||
* takes the number of words as an argument, rather than the number of
|
||||
* bytes. Also, we let the caller perform the one's complement change.
|
||||
*/
|
||||
bits16_t glue_cksum(bits16_t *addr, unsigned count)
|
||||
{
|
||||
register bits32_t sum = 0;
|
||||
|
||||
#if INSTALL_SNARK_GLUE_CKSUM_ALIGNMENT_KLUDGE
|
||||
/*
|
||||
* Kludge around alignment restrictions.
|
||||
*/
|
||||
if (count > 0 && (((unsigned long) addr) & 1) != 0) {
|
||||
bits8_t *a = (bits8_t *) addr;
|
||||
sum = glue_cksum((bits16_t *) (a+1), count - 1);
|
||||
sum = ((sum << 8) & 0xFF00) | ((sum >> 8) & 0x00FF);
|
||||
sum += ((a[0] << 8) + a[count * 2 - 1]);
|
||||
count = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
while (count-- > 0)
|
||||
sum += *addr++;
|
||||
sum = (sum >> 16) + (sum & 0xFFFF); /* This can only wrap twice */
|
||||
return (sum >> 16) + (sum & 0xFFFF);
|
||||
}
|
||||
|
||||
#endif /* INSTALL_ATTACHE */
|
||||
@@ -0,0 +1,125 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/collect.c,v 1.2 2001/11/08 15:56:21 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1996-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: collect.c,v $
|
||||
* Revision 1.2 2001/11/08 15:56:21 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:41 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.5 2001/01/19 22:23:40 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.4 2000/03/17 00:12:37 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.3 1998/02/25 04:57:23 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.2 1997/11/21 00:06:23 josh
|
||||
* updating files for Liaison support for NIT
|
||||
*
|
||||
* Revision 2.1 1997/11/04 16:11:30 josh
|
||||
* Adding Liaison support files
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/udp.h>
|
||||
#include <wrn/wm/attache/dns.h>
|
||||
#include <wrn/wm/attache/loop.h>
|
||||
|
||||
#include <liaison/hrmon/rmonapi.h>
|
||||
|
||||
#include <wrn/wm/demo/read_ini.h>
|
||||
#include <wrn/wm/demo/parse.h>
|
||||
|
||||
#include <snark/lib/netconf.h>
|
||||
|
||||
#if INSTALL_SNARK_BSD_BPF
|
||||
#include <snark/lib/bpf.h>
|
||||
#elif INSTALL_SNARK_BSD_NIT
|
||||
#include <snark/lib/nit.h>
|
||||
#endif
|
||||
|
||||
/* This file contains routines to run the packet collector for Liaison
|
||||
* RMON.
|
||||
*/
|
||||
|
||||
extern int liaison_collectors[];
|
||||
|
||||
void snark_process_collected_pkt(unsigned char *pktp,
|
||||
unsigned caplen,
|
||||
unsigned datalen,
|
||||
void *cookie)
|
||||
{
|
||||
int i;
|
||||
int bpfdev = *((int *)cookie);
|
||||
|
||||
/* Quick sanity check */
|
||||
if (!(caplen == datalen))
|
||||
return;
|
||||
|
||||
/* Figure out the interface number and then call Liaison
|
||||
* to process the packet.
|
||||
*/
|
||||
|
||||
for (i = 1; i < 17; i++)
|
||||
{
|
||||
if (liaison_collectors[i] == bpfdev)
|
||||
{
|
||||
rmon_process_packet(pktp, i, datalen, datalen,
|
||||
XMIB_IF_TYPE_ET, FALSE, FALSE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void snark_liaison_collect(int bpfdev, void *cookie)
|
||||
{
|
||||
int errno;
|
||||
|
||||
#if INSTALL_SNARK_BSD_BPF
|
||||
errno = bpf_read(bpfdev, 1514, snark_process_collected_pkt, cookie);
|
||||
#elif INSTALL_SNARK_BSD_NIT
|
||||
errno = nit_read(bpfdev, 1514, snark_process_collected_pkt, cookie);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,497 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/dlpi.c,v 1.2 2001/11/08 15:56:21 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: dlpi.c,v $
|
||||
* Revision 1.2 2001/11/08 15:56:21 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:41 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.3 2001/01/19 22:23:40 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.2 2000/03/17 00:12:37 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.1 1998/07/29 20:54:51 wes
|
||||
* First cut of the Solaris port.
|
||||
* (DLPI support, termios, minor tweaks to libraries and port header files)
|
||||
*
|
||||
* Revision 1.1.2.1 1998/07/24 21:45:41 wes
|
||||
* Initial implementation
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* DLPI interface to ethernet for Attache testing under Solaris 2.x
|
||||
*
|
||||
* All access to DLPI should be through this module, the only thing we
|
||||
* expect our caller to do with our file descriptor is use it in
|
||||
* select() calls. There are enough name conflicts between the unix
|
||||
* networking code and the Attache networking code that it's probably
|
||||
* hopeless to have the two mingled in the same file.
|
||||
*
|
||||
* This was brutally converted from nit.c in a fit of madness.
|
||||
*
|
||||
* References: NIT manual pages
|
||||
* tcpdump source
|
||||
* CAP ethertalk source
|
||||
* netintro(4) manual page
|
||||
* NET-2 routed source
|
||||
* "How to use DLPI" document from Sun Internet Engineering, dated 30 Jun 1992
|
||||
* DLPI specification.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <stropts.h>
|
||||
#include <sys/dlpi.h>
|
||||
#include <sys/pfmod.h>
|
||||
#include <sys/sockio.h>
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#define __(x) x
|
||||
#include <wrn/wm/demo/dlpi.h>
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define alloca __builtin_alloca
|
||||
#endif
|
||||
|
||||
|
||||
#define MAXDLBUF 8192
|
||||
#define OFFADDR(s, n) (u_char*)((char*)(s) + (int)(n))
|
||||
|
||||
|
||||
/*
|
||||
* DLPI client stubs.
|
||||
*/
|
||||
|
||||
int dlreqspew (int fd, void *buf, size_t size)
|
||||
{
|
||||
struct strbuf ctl;
|
||||
|
||||
ctl.maxlen = 0;
|
||||
ctl.len = size;
|
||||
ctl.buf = buf;
|
||||
|
||||
return putmsg(fd, &ctl, NULL, 0);
|
||||
}
|
||||
|
||||
int dlgetack (int fd, int exp_prim, int exp_flags, char *respbuf, int exp_size)
|
||||
{
|
||||
union DL_primitives *dlp;
|
||||
struct strbuf ctl;
|
||||
char tmpbuf[MAXDLBUF];
|
||||
int flags = 0;
|
||||
|
||||
if (!respbuf)
|
||||
respbuf = tmpbuf;
|
||||
|
||||
/* XXX do a poll() here to wait for the response.. */
|
||||
|
||||
ctl.maxlen = exp_size;
|
||||
ctl.len = 0;
|
||||
ctl.buf = respbuf;
|
||||
|
||||
if (getmsg(fd, &ctl, NULL, &flags) < 0)
|
||||
return -4;
|
||||
dlp = (union DL_primitives *)ctl.buf;
|
||||
|
||||
if (dlp->dl_primitive != exp_prim)
|
||||
return -1;
|
||||
|
||||
if (flags != exp_flags)
|
||||
return -2;
|
||||
|
||||
if (ctl.len < exp_size)
|
||||
return -3;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int dlsar (int fd, void *reqbuf, size_t size,
|
||||
int exp_prim, int exp_flags, void *respbuf, int exp_size)
|
||||
{
|
||||
/* Flush the read queue, don't worry about it if we can't. */
|
||||
(void) ioctl(fd, I_FLUSH, (char *) FLUSHR);
|
||||
|
||||
if (dlreqspew(fd, reqbuf, size) < 0)
|
||||
return -1;
|
||||
|
||||
return dlgetack(fd, exp_prim, exp_flags, respbuf, exp_size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int dlattach(int fd, u_long ppa)
|
||||
{
|
||||
dl_attach_req_t attach_req;
|
||||
|
||||
attach_req.dl_primitive = DL_ATTACH_REQ;
|
||||
attach_req.dl_ppa = ppa;
|
||||
|
||||
return dlsar(fd, &attach_req, sizeof(attach_req),
|
||||
DL_OK_ACK, RS_HIPRI, NULL, sizeof(dl_ok_ack_t));
|
||||
}
|
||||
|
||||
int dlbind(int fd, u_long sap, u_long max_conind, u_long service_mode, u_long conn_mgmt, u_long xidtest)
|
||||
{
|
||||
dl_bind_req_t bind_req;
|
||||
|
||||
bind_req.dl_primitive = DL_BIND_REQ;
|
||||
bind_req.dl_sap = sap;
|
||||
bind_req.dl_max_conind = max_conind;
|
||||
bind_req.dl_service_mode = service_mode;
|
||||
bind_req.dl_conn_mgmt = conn_mgmt;
|
||||
bind_req.dl_xidtest_flg = xidtest;
|
||||
|
||||
return dlsar(fd, &bind_req, sizeof(bind_req),
|
||||
DL_BIND_ACK, RS_HIPRI, NULL, sizeof(dl_bind_ack_t));
|
||||
}
|
||||
|
||||
int dlpromiscon(int fd, int level)
|
||||
{
|
||||
dl_promiscon_req_t promiscon_req;
|
||||
promiscon_req.dl_primitive = DL_PROMISCON_REQ;
|
||||
promiscon_req.dl_level = level;
|
||||
|
||||
return dlsar (fd, &promiscon_req, sizeof(promiscon_req),
|
||||
DL_OK_ACK, RS_HIPRI, NULL, sizeof(dl_ok_ack_t));
|
||||
}
|
||||
|
||||
int dlphysaddr(int fd, int which, char *phy, int len)
|
||||
{
|
||||
dl_phys_addr_req_t phys_addr_req;
|
||||
dl_phys_addr_ack_t phys_addr_ack;
|
||||
int tmp;
|
||||
union DL_primitives *dlp;
|
||||
|
||||
phys_addr_req.dl_primitive = DL_PHYS_ADDR_REQ;
|
||||
phys_addr_req.dl_addr_type = which;
|
||||
|
||||
tmp = dlsar (fd, &phys_addr_req, sizeof(phys_addr_req),
|
||||
DL_PHYS_ADDR_ACK, RS_HIPRI, &phys_addr_ack, sizeof(phys_addr_ack));
|
||||
|
||||
if (tmp < 0)
|
||||
return tmp;
|
||||
|
||||
dlp=(union DL_primitives *)&phys_addr_ack;
|
||||
|
||||
memcpy(phy, OFFADDR(dlp, dlp->physaddr_ack.dl_addr_offset), len);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Open a STREAMS driver for the interface and attach it to the interface named 'device'.
|
||||
* Returns DLPI file descriptor, or -1 if an error occurs.
|
||||
*
|
||||
* Since this implementation uses the same ethernet address as the host
|
||||
* on which it's running, fill in Attache's idea of the MAC address.
|
||||
*
|
||||
* N.B. the order of calls of the STREAMS primitives here is
|
||||
* evidently fairly subtle and is not covered by existing documentation.
|
||||
*
|
||||
* Looking at known working code (e.g., LBL libpcap) finally allowed
|
||||
* me to get things to work right; based on reading that other code,
|
||||
* it appears that this will require some work on systems other than
|
||||
* Solaris.
|
||||
*/
|
||||
|
||||
int dlpi_open(char *ifname, unsigned mtu, unsigned char *mac)
|
||||
{
|
||||
struct strioctl sioc;
|
||||
|
||||
char driver[16];
|
||||
int fd;
|
||||
|
||||
u_long unit;
|
||||
char *cp;
|
||||
|
||||
/*
|
||||
* parse the unit number out of the ifname..
|
||||
*/
|
||||
sprintf(driver, "/dev/%s", ifname);
|
||||
cp = &driver[strlen(driver)];
|
||||
while(isdigit((int)cp[-1])) /* XXX int cast to quiet gcc */
|
||||
--cp;
|
||||
unit = atoi(cp);
|
||||
*cp = '\0';
|
||||
|
||||
/*
|
||||
* Look for cloned link-layer driver..
|
||||
*/
|
||||
if ((fd = open(driver, O_RDWR)) < 0) {
|
||||
perror("couldn't clone DLPI device");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dlattach(fd, unit) < 0) {
|
||||
perror("couldn't attach dlpi unit\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable discrete messages.
|
||||
*/
|
||||
if (ioctl(fd, I_SRDOPT, (char *) RMSGD) < 0) {
|
||||
perror("couldn't enable discrete DLPI messages");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't bother with buffering, or truncation for now.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Put the interface into promiscuous mode so that we'll see packets
|
||||
* to our faked MAC address..
|
||||
*/
|
||||
|
||||
if (dlpromiscon(fd, DL_PROMISC_PHYS) < 0) {
|
||||
perror("dlpi: failed to set promisc PHYS mode\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Get all SAP's (this apparently needs to happen *after* setting
|
||||
* the lower-level promiscuous mode
|
||||
*/
|
||||
if (dlpromiscon(fd, DL_PROMISC_SAP) < 0)
|
||||
perror("dlpi: failed to set promisc SAP mode");
|
||||
|
||||
/*
|
||||
* We bind last since comments in libpcap suggest that this is most portable.
|
||||
*/
|
||||
|
||||
if (dlbind(fd, 0, 0, DL_CLDLS, 0, 0) < 0) {
|
||||
perror("couldn't dlbind\n");
|
||||
}
|
||||
|
||||
/* Set raw mode. if this fails, we *should* blow up since the protocol's different.. */
|
||||
sioc.ic_cmd = DLIOCRAW;
|
||||
sioc.ic_timout = -1;
|
||||
sioc.ic_len = 0;
|
||||
sioc.ic_dp = 0;
|
||||
if (ioctl(fd, I_STR, &sioc) < 0) {
|
||||
perror("couldn't set RAW mode, continuing..\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Push packet filter module.
|
||||
*/
|
||||
|
||||
if (ioctl(fd, I_PUSH, "pfmod") < 0) {
|
||||
perror("couldn't push packet filter STREAMS module, continuing..");
|
||||
} else {
|
||||
struct packetfilt pfil;
|
||||
|
||||
u_short *pfp = &pfil.Pf_Filter[0];
|
||||
|
||||
/*
|
||||
* Yum. Interpreted LIW code, the result of several hours of mental pain.
|
||||
* This *might* be an optimal instruction schedule.
|
||||
*
|
||||
* Whoever named the ENF_C{N,}{AND,OR} ops was.. confused...
|
||||
* But, well...
|
||||
*/
|
||||
|
||||
*pfp++ = ENF_PUSHLIT;
|
||||
*pfp++ = 0x0100; /* multicast bit */
|
||||
*pfp++ = (ENF_PUSHWORD+0) | ENF_AND; /* mask with first word of mac */
|
||||
*pfp++ = ENF_PUSHZERO | ENF_CNAND; /* succeed if nonzero */
|
||||
|
||||
*pfp++ = ENF_PUSHLIT;
|
||||
*pfp++ = ntohs(*(u_short *)mac); /* first word of mac */
|
||||
*pfp++ = (ENF_PUSHWORD+0) | ENF_CAND; /* fail if not equal */
|
||||
|
||||
*pfp++ = ENF_PUSHLIT;
|
||||
*pfp++ = ntohs(*(u_short *)(mac+2)); /* second word of mac */
|
||||
*pfp++ = (ENF_PUSHWORD+1) | ENF_CAND; /* fail if not equal */
|
||||
|
||||
*pfp++ = ENF_PUSHLIT;
|
||||
*pfp++ = ntohs(*(u_short *)(mac+4)); /* third word of mac */
|
||||
*pfp++ = (ENF_PUSHWORD+2) | ENF_EQ; /* succeed if equal.. */
|
||||
|
||||
pfil.Pf_Priority = 0;
|
||||
pfil.Pf_FilterLen = pfp - &pfil.Pf_Filter[0];
|
||||
|
||||
sioc.ic_cmd = PFIOCSETF;
|
||||
sioc.ic_timout = -1;
|
||||
sioc.ic_len = sizeof(pfil);
|
||||
sioc.ic_dp = (void *)&pfil;
|
||||
if (ioctl(fd, I_STR, &sioc) < 0) {
|
||||
perror("couldn't set packet filter, continuing..");
|
||||
}
|
||||
}
|
||||
|
||||
/* As last action, flush the read queue.. */
|
||||
(void) ioctl(fd, I_FLUSH, (char *) FLUSHR);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Read a DLPI buffer and hand its contents off to Attache as packets.
|
||||
* This is based on the readloop() function in tcpdump's BPF code and
|
||||
* on the dlpi(4) manual page.
|
||||
*
|
||||
* The handler routine supplied by the Attache-side code gets three
|
||||
* arguments: a pointer to the packet data, the length of the packet
|
||||
* data, and the length that the real packet was on the wire.
|
||||
*
|
||||
* There's probably nothing useful that Attache can do with a truncated
|
||||
* packet, but the info is there, so we may as well pass it along.
|
||||
*/
|
||||
|
||||
int dlpi_read
|
||||
(int fd,
|
||||
unsigned mtu,
|
||||
void (*handler)(unsigned char *, unsigned, unsigned, void *),
|
||||
void *cookie)
|
||||
{
|
||||
unsigned char *buf;
|
||||
int i, flags;
|
||||
struct strbuf data;
|
||||
|
||||
|
||||
if ((buf = (unsigned char *) alloca(mtu)) == 0) {
|
||||
fprintf(stderr, "alloca(%d) failed\n", mtu);
|
||||
return -1;
|
||||
}
|
||||
|
||||
data.buf = buf;
|
||||
data.maxlen = mtu;
|
||||
data.len = 0;
|
||||
|
||||
/*
|
||||
* Try to read a packet, restart if we get screwed by the debugger.
|
||||
* Return on other error or on EOF.
|
||||
*/
|
||||
flags = 0;
|
||||
do {
|
||||
i = getmsg(fd, NULL, &data, &flags);
|
||||
} while (i < 0 && errno == EINTR);
|
||||
if (i>=0)
|
||||
i=data.len;
|
||||
|
||||
if (i <= 0)
|
||||
return i;
|
||||
|
||||
/*
|
||||
* In theory, since we've got the stream in discrete message mode,
|
||||
* we can just assume that we got one packet.
|
||||
*/
|
||||
handler(buf, i, i, cookie);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Write a packet to the DLPI stream.
|
||||
*/
|
||||
|
||||
int dlpi_write(int fd, unsigned char *data, unsigned datalen)
|
||||
{
|
||||
struct strbuf dbuf;
|
||||
dbuf.buf = data;
|
||||
dbuf.len = datalen;
|
||||
dbuf.maxlen = 0;
|
||||
|
||||
return putmsg(fd, 0, &dbuf, 0) < 0 ? -1 : datalen;
|
||||
}
|
||||
|
||||
/*
|
||||
* Close a DLPI interface.
|
||||
*/
|
||||
|
||||
void dlpi_close(int fd)
|
||||
{
|
||||
(void) close(fd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined(SIOCGIFCONF)
|
||||
|
||||
/*
|
||||
* Find all ethernet interfaces. This is a simplified version of the
|
||||
* code that works on NetBSD, I dunno yet whether this will work on SunOS.
|
||||
*/
|
||||
|
||||
void dlpi_find(void (*handler)(char *, void *), void *cookie)
|
||||
{
|
||||
char buffer[5000];
|
||||
struct ifconf ifc;
|
||||
struct ifreq *ifr;
|
||||
int s;
|
||||
|
||||
if (!handler)
|
||||
return;
|
||||
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("socket");
|
||||
return;
|
||||
}
|
||||
/* shut up purify whining about uninit memory.. */
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
ifc.ifc_len = sizeof(buffer);
|
||||
ifc.ifc_buf = buffer;
|
||||
if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0) {
|
||||
perror("ioctl");
|
||||
(void) close(s);
|
||||
return;
|
||||
}
|
||||
for (ifr = ifc.ifc_req; ((char *) ifr) < ifc.ifc_buf + ifc.ifc_len; ++ifr) {
|
||||
handler(ifr->ifr_name, cookie);
|
||||
}
|
||||
|
||||
(void) close(s);
|
||||
}
|
||||
|
||||
#endif /* defined(SIOCGIFCONF) */
|
||||
@@ -0,0 +1,276 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/dlpidrv.c,v 1.4 2003/01/15 14:04:31 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: dlpidrv.c,v $
|
||||
* Revision 1.4 2003/01/15 14:04:31 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.3 2001/11/08 15:56:21 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.2 2001/11/06 20:11:11 josh
|
||||
* updating include paths to include proper path to layout directory
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:41 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.8 2001/01/19 22:23:41 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.7 2000/10/20 18:32:25 paul
|
||||
* Properly conditionalized driver.ip_send
|
||||
*
|
||||
* Revision 2.6 2000/10/16 19:21:53 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 2.5 2000/03/17 00:12:38 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.4 2000/03/13 21:22:04 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 2.3 1999/11/05 22:29:05 paul
|
||||
* Updated driver structs to reflect conditional backwards-compatibility
|
||||
* fields and new fields.
|
||||
*
|
||||
* Revision 2.2 1998/09/14 20:13:43 wes
|
||||
* make DLPI driver filenames 8.3 safe..
|
||||
*
|
||||
* Revision 2.1 1998/07/29 20:54:52 wes
|
||||
* First cut of the Solaris port.
|
||||
* (DLPI support, termios, minor tweaks to libraries and port header files)
|
||||
*
|
||||
* Revision 1.1.2.1 1998/07/24 21:45:44 wes
|
||||
* Initial implementation
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Attache code for interfacing to ethernet via the Data Link Provider Interface
|
||||
* on Solaris. Some modification will likely be necessary for use on other
|
||||
* platforms..
|
||||
*
|
||||
* This file contains the Attache driver code for DLPI.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/ether.h>
|
||||
#include <wrn/wm/attache/arp.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include <wrn/wm/util/layout/ldbglue.h>
|
||||
#include <wrn/wm/util/layout/arp.h>
|
||||
|
||||
#include <wrn/wm/demo/dlpi.h>
|
||||
#include <wrn/wm/demo/bsdif.h>
|
||||
#include <wrn/wm/demo/dlpidrv.h>
|
||||
|
||||
struct dlpi_driver_private {
|
||||
bits8_t mac[6]; /* MAC address for this interface */
|
||||
};
|
||||
|
||||
#define TEN_MEGABITS 10000000
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Routines to read (struct bsdif) generic network interface.
|
||||
*/
|
||||
|
||||
static void dlpi_driver_rcv
|
||||
(unsigned char *buffer,
|
||||
unsigned buflen,
|
||||
unsigned netlen,
|
||||
void *cookie)
|
||||
{
|
||||
packet *p;
|
||||
|
||||
if (buflen != netlen || (p = pkt_alloc(buflen + 2)) == 0)
|
||||
return;
|
||||
MEMCPY((p->pkt_data += 2), buffer, (p->pkt_datalen = buflen));
|
||||
p->pkt_n = cookie;
|
||||
et_rcv(p);
|
||||
}
|
||||
|
||||
static void dlpi_driver_read (int fd, void *cookie, unsigned flags)
|
||||
{
|
||||
struct net *net = cookie;
|
||||
if ((net->flags & NF_DRIVER_DOWN) == 0 && (flags & BSDIF_READ) != 0)
|
||||
(void) dlpi_read(fd, net->driver->maxlen, dlpi_driver_rcv, net);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Attache device driver routines for DLPI.
|
||||
*/
|
||||
|
||||
static void dlpi_driver_init (struct net *net)
|
||||
{
|
||||
/* This prefix is from "obsolete" portion of DEC's space (see RFC-1340). */
|
||||
static bits8_t bpf_driver_mac_prefix[3] = { 0xAA, 0x00, 0x00 };
|
||||
struct bsdif *bif = net->specific;
|
||||
struct dlpi_driver_private *private;
|
||||
char *name = net->s_name + STRLEN(net->driver->prefix);
|
||||
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
net->speed = TEN_MEGABITS;
|
||||
|
||||
if ((bif->private = private = GLUE_ALLOC(sizeof(*private))) == 0)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Pick a MAC address to use. If there's already one specified,
|
||||
* use it. Otherwise, if we're in 2.x backwards compatability mode and have
|
||||
* an IP address, use it, otherwise try to generate something unique.
|
||||
*/
|
||||
if (!net->h_address) {
|
||||
net->ha_len = sizeof(private->mac);
|
||||
net->h_address = private->mac;
|
||||
MEMCPY(private->mac+0, bpf_driver_mac_prefix, 3);
|
||||
if (net->ip_addr) {
|
||||
MEMCPY(private->mac + 3, ((bits8_t *) &net->ip_addr) + 1, 3);
|
||||
} else {
|
||||
pid_t proc = getpid();
|
||||
bits32_t hostid = gethostid();
|
||||
private->mac[3] ^= (bits8_t) (proc & 0xff);
|
||||
private->mac[4] ^= (bits8_t) (proc >> 8 & 0xff);
|
||||
private->mac[5] ^= (bits8_t) (hostid & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
if ((bif->fd = dlpi_open(name, net->driver->maxlen, private->mac)) < 0)
|
||||
return;
|
||||
|
||||
bif->handler = dlpi_driver_read;
|
||||
bif->flags |= BSDIF_READ;
|
||||
net->flags &= ~NF_DRIVER_DOWN;
|
||||
}
|
||||
|
||||
static void dlpi_driver_send (struct packet *p)
|
||||
{
|
||||
struct bsdif *bif = p->pkt_n->specific;
|
||||
|
||||
/*
|
||||
* Send the packet, logging any error that might occur.
|
||||
* If the driver is down, just drop the packet.
|
||||
*/
|
||||
if ((p->pkt_n->flags & NF_DRIVER_DOWN) == 0 &&
|
||||
dlpi_write(bif->fd, p->pkt_data, p->pkt_datalen) < 0)
|
||||
perror("DLPI write() failure");
|
||||
pkt_free(p);
|
||||
}
|
||||
|
||||
static void dlpi_driver_close (struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
|
||||
if ((net->flags & NF_DRIVER_DOWN) == 0) {
|
||||
dlpi_close(bif->fd);
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
}
|
||||
if (bif->private) {
|
||||
GLUE_FREE(bif->private);
|
||||
bif->private = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This could be static now, but it might be useful to leave it visible.
|
||||
*/
|
||||
|
||||
struct driver dlpi_driver = {
|
||||
dlpi_driver_init, /* Interface initialization routine */
|
||||
dlpi_driver_send, /* Raw packet send routine */
|
||||
#if INSTALL_ATTACHE_34_IPV4_API_COMPAT
|
||||
et_ip_send, /* IP packet send encapsulation routine */
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
et_arp_send, /* ARP packet send encapsulation routine */
|
||||
0, /* Test routine (unused) */
|
||||
dlpi_driver_close, /* Interface close routine */
|
||||
"dlpi", /* Driver short name */
|
||||
"DLPI Ethernet", /* Driver long name */
|
||||
14, /* Local net header length */
|
||||
0, /* Local net trailer length */
|
||||
1514, /* Ethernet frame size */
|
||||
IF_ETHERNET, /* MIB type of interfaces using this driver */
|
||||
ARP_HEADER_HARDWARE_TYPE_is_ETHERNET,
|
||||
#if !INSTALL_ATTACHE_ETHERNET_NO_MEDIA_CTL
|
||||
et_media_ctl, /* Media control routine, if installed */
|
||||
#else
|
||||
0, /* No media_ctl routine */
|
||||
#endif /* !INSTALL_ATTACHE_ETHERNET_NO_MEDIA_CTL */
|
||||
#if INSTALL_ATTACHE_IPV6
|
||||
et_ipv6_send, /* IPv6 send routine, if installed */
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
#if INSTALL_ATTACHE_IPV4
|
||||
et_ipv4_send /* IPv4 send routine, if installed */
|
||||
#else
|
||||
0
|
||||
#endif /* INSTALL_ATTACHE_IPV4 */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Routines for finding DLPI interface devices.
|
||||
* This is just a wrapper to add the Attache-specific things onto dlpi_find().
|
||||
*/
|
||||
|
||||
struct dlpi_driver_find_state {
|
||||
void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t);
|
||||
int instance;
|
||||
};
|
||||
|
||||
static void dlpi_driver_find_one(char *name, void *cookie)
|
||||
{
|
||||
struct dlpi_driver_find_state *state = cookie;
|
||||
state->config(name, &dlpi_driver, state->instance++, NF_ARP,
|
||||
dlpi_driver.maxlen - dlpi_driver.lnh - dlpi_driver.lnt,
|
||||
TEN_MEGABITS);
|
||||
}
|
||||
|
||||
void dlpi_driver_find
|
||||
(void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t))
|
||||
{
|
||||
struct dlpi_driver_find_state state;
|
||||
state.config = config;
|
||||
state.instance = 0;
|
||||
dlpi_find(dlpi_driver_find_one, &state);
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/filefunc.c,v 1.3 2003/01/15 14:04:31 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1996-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: filefunc.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:31 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:21 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:41 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.6 2001/01/19 22:23:41 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.5 2000/03/17 00:12:38 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.4 1998/09/04 04:00:09 sar
|
||||
* modified some #if statements to use #ifdef as they were testing
|
||||
* items that might not be defined - INSTALL_on_* options.
|
||||
*
|
||||
* Revision 1.3 1998/02/25 15:21:47 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 1.2 1998/02/25 04:57:24 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.1 1997/08/12 22:31:18 lowell
|
||||
* kick release numbers to avoid the "0.*" special case
|
||||
*
|
||||
* Revision 0.8 1997/07/23 07:08:01 alan
|
||||
* New: file_last_modified_time()
|
||||
*
|
||||
* Revision 0.7 1997/03/20 06:52:54 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 0.6 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 0.5 1997/02/19 08:10:29 sra
|
||||
* More fun merging snmptalk into snark, general snark cleanup.
|
||||
*
|
||||
* Revision 0.4 1996/11/13 15:09:16 mrf
|
||||
* Changes necessary to make snoop support work on Irix 5.x include
|
||||
* addition of snoop driver code and port to somewhat wacky Irix
|
||||
* curses implementation.
|
||||
*
|
||||
* Revision 0.3 1996/10/29 00:50:22 sar
|
||||
* made filptr a pointer
|
||||
*
|
||||
* Revision 0.2 1996/10/28 21:29:24 lowell
|
||||
* include dconfig.h instead of decorum.h
|
||||
*
|
||||
* Revision 0.1 1996/10/27 16:59:26 lowell
|
||||
* initial revision
|
||||
* file-size for ETC_STDIO_SIZE
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/* Get the standard epilogue types */
|
||||
#include <wrn/wm/common/types.h>
|
||||
/* and specific info for decorum */
|
||||
#include <decorum/h/dconfig.h>
|
||||
#include <decorum/h/date.h>
|
||||
|
||||
/*
|
||||
* A function for our pseudo-stdio to find file sizes with.
|
||||
*/
|
||||
|
||||
#ifdef INSTALL_on_unix
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
bits32_t file_size_32(char * filename)
|
||||
{
|
||||
struct stat buf;
|
||||
int errval;
|
||||
|
||||
errval = stat(filename, &buf);
|
||||
if (errval != 0)
|
||||
return 0;
|
||||
|
||||
return ((bits32_t)(buf.st_size));
|
||||
}
|
||||
|
||||
void
|
||||
file_last_modified_time(char *filename, struct decorum_rawtime *tv)
|
||||
{
|
||||
struct stat buf;
|
||||
|
||||
if (stat(filename, &buf)) {
|
||||
tv->type = T0_NONE;
|
||||
} else {
|
||||
tv->type = T0_UNIX;
|
||||
tv->time = buf.st_ctime;
|
||||
}
|
||||
}
|
||||
|
||||
#else /* not BSD */
|
||||
|
||||
/* brute force, ugly, but will work anywhere ETC_STDIO does. */
|
||||
#ifndef filesize_buf_size
|
||||
#define filesize_buf_size 1024
|
||||
#endif /* ifndef filesize_buf_size */
|
||||
bits32_t file_size_32(char * filename)
|
||||
{
|
||||
etc_stdio_t *filptr;
|
||||
char buffer[filesize_buf_size];
|
||||
bits32_t len=0;
|
||||
int thistime;
|
||||
|
||||
filptr = ETC_STDIO_OPEN(filename, ETC_STDIO_MODE_READ);
|
||||
if (!filptr) return 0;
|
||||
|
||||
do
|
||||
{
|
||||
thistime = ETC_STDIO_READ(filptr, filesize_buf_size, buffer);
|
||||
len += (bits32_t)thistime;
|
||||
} while (filesize_buf_size == thistime);
|
||||
|
||||
ETC_STDIO_CLOSE(filptr);
|
||||
|
||||
return len;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,575 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/firewall.c,v 1.4 2003/01/15 14:04:31 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* Rudimentary firewall built on top of Attache.
|
||||
* This is a work in progress, I need the basic functionality to solve
|
||||
* a short term problem but the code will need more work to make
|
||||
* it as general as it should be.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: firewall.c,v $
|
||||
* Revision 1.4 2003/01/15 14:04:31 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.3 2001/11/08 15:56:21 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.2 2001/11/06 20:11:11 josh
|
||||
* updating include paths to include proper path to layout directory
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:41 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.4 2001/01/19 22:23:41 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.3 2000/03/17 00:12:38 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.2 1998/09/08 05:21:46 sra
|
||||
* Compiler warnings.
|
||||
*
|
||||
* Revision 2.1 1998/09/06 08:11:08 sra
|
||||
* Packet filtering hooks in Attache, rudimentary firewall
|
||||
* implementation in Snark.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/udp.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
|
||||
#include <wrn/wm/util/layout/ip.h>
|
||||
|
||||
#if INSTALL_ATTACHE_IPV6
|
||||
#include <wrn/wm/util/layout/ip6.h>
|
||||
#endif
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
#include <wrn/wm/demo/read_ini.h>
|
||||
#include <wrn/wm/demo/parse.h>
|
||||
|
||||
enum fw_action {
|
||||
FW_ALLOW = 0,
|
||||
FW_DROP = 1,
|
||||
FW_RESET = 2
|
||||
};
|
||||
|
||||
struct filter {
|
||||
struct filter *next;
|
||||
enum fw_action action;
|
||||
bits8_t proto, src_prefix, dst_prefix;
|
||||
bits16_t src_low_port, src_high_port, dst_low_port, dst_high_port;
|
||||
ipaddr_t src_addr, dst_addr;
|
||||
char ifname[20];
|
||||
unsigned negate_proto : 1;
|
||||
unsigned negate_src_addr : 1;
|
||||
unsigned negate_dst_addr : 1;
|
||||
unsigned negate_src_port : 1;
|
||||
unsigned negate_dst_port : 1;
|
||||
unsigned negate_ifname : 1;
|
||||
unsigned tcp_established : 1;
|
||||
unsigned tcp_setup : 1;
|
||||
};
|
||||
|
||||
enum filter_argv {
|
||||
ARGV_ACTION,
|
||||
ARGV_PROTO,
|
||||
ARGV_SRC_ADDR,
|
||||
ARGV_SRC_PORT,
|
||||
ARGV_DST_ADDR,
|
||||
ARGV_DST_PORT,
|
||||
ARGV_IFNAME,
|
||||
ARGV_MINLENGTH
|
||||
};
|
||||
|
||||
enum fw_tcpflag {
|
||||
TCPFLAG_ESTABLISHED,
|
||||
TCPFLAG_SETUP,
|
||||
};
|
||||
|
||||
static struct action_table {
|
||||
char *name;
|
||||
enum fw_action action;
|
||||
} action_table[] = {
|
||||
{ "allow", FW_ALLOW },
|
||||
{ "drop", FW_DROP },
|
||||
{ "reset", FW_RESET },
|
||||
};
|
||||
|
||||
static struct tcpflag_table {
|
||||
char *name;
|
||||
enum fw_tcpflag flag;
|
||||
} tcpflag_table[] = {
|
||||
{ "established", TCPFLAG_ESTABLISHED },
|
||||
{ "setup", TCPFLAG_SETUP },
|
||||
};
|
||||
|
||||
static struct proto_table {
|
||||
char *name;
|
||||
bits8_t proto;
|
||||
} proto_table[] = {
|
||||
{ "*", 0 },
|
||||
{ "icmp", IP_PROTOCOL_is_ICMP },
|
||||
{ "tcp", IP_PROTOCOL_is_TCP },
|
||||
{ "udp", IP_PROTOCOL_is_UDP },
|
||||
};
|
||||
|
||||
static struct filter *ifilter = 0;
|
||||
static struct filter *ofilter = 0;
|
||||
static struct filter *ffilter = 0;
|
||||
|
||||
static struct keyword_table action_keywords, proto_keywords, tcpflag_keywords;
|
||||
|
||||
#ifndef GET_TCP_HEADER_DESTINATION_PORT
|
||||
#define GET_TCP_HEADER_DESTINATION_PORT(_P_) \
|
||||
GET_IP_PORT_NUMBER(PTR_TCP_HEADER_DESTINATION_PORT(_P_))
|
||||
#endif
|
||||
|
||||
#ifndef GET_TCP_HEADER_SOURCE_PORT
|
||||
#define GET_TCP_HEADER_SOURCE_PORT(_P_) \
|
||||
GET_IP_PORT_NUMBER(PTR_TCP_HEADER_SOURCE_PORT(_P_))
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Compare the first len bits of two ipaddr_ts, return nonzero if they match.
|
||||
*/
|
||||
static int ipaddr_match (ipaddr_t *a1, ipaddr_t *a2, bits8_t len)
|
||||
{
|
||||
ipaddr_bits_t *b1, *b2;
|
||||
|
||||
BUG_ASSERT(a1 && a2 && len <= MAX_IP_ADDR_LEN * 8);
|
||||
|
||||
if (!len)
|
||||
return 1;
|
||||
|
||||
if (GET_IPADDR_TYPE(a1) != GET_IPADDR_TYPE(a2))
|
||||
return 0;
|
||||
|
||||
for (b1 = PTR_IPADDR_BITS(a1), b2 = PTR_IPADDR_BITS(a2);
|
||||
len >= 8;
|
||||
b1++, b2++, len -= 8)
|
||||
if (*b1 != *b2)
|
||||
return 0;
|
||||
|
||||
return !((*b1 ^ *b2) >> (8 - len));
|
||||
}
|
||||
|
||||
#define FILTER_ALLOW() \
|
||||
do { \
|
||||
BUG_SUPPORT(ipaddr_to_string(&src_addr, src_host, sizeof(src_host))); \
|
||||
BUG_SUPPORT(ipaddr_to_string(&dst_addr, dst_host, sizeof(dst_host))); \
|
||||
BUG(BUG_SNARK_FIREWALL_ALLOW_PKT, BUG_CONTINUABLE, p, \
|
||||
(BUG_OUT, "FW: Allow: %u %s %u %s %u %s", \
|
||||
proto, src_host, src_port, dst_host, dst_port, ifname)); \
|
||||
return (int) FW_ALLOW; \
|
||||
} while (0)
|
||||
|
||||
#define FILTER_DROP() \
|
||||
do { \
|
||||
BUG_SUPPORT(ipaddr_to_string(&src_addr, src_host, sizeof(src_host))); \
|
||||
BUG_SUPPORT(ipaddr_to_string(&dst_addr, dst_host, sizeof(dst_host))); \
|
||||
BUG(BUG_SNARK_FIREWALL_DROP_PKT, BUG_CONTINUABLE, p, \
|
||||
(BUG_OUT, "FW: Drop: %u %s %u %s %u %s", \
|
||||
proto, src_host, src_port, dst_host, dst_port, ifname)); \
|
||||
return (int) FW_DROP; \
|
||||
} while (0)
|
||||
|
||||
#define FILTER_RESET() \
|
||||
do { \
|
||||
BUG_SUPPORT(ipaddr_to_string(&src_addr, src_host, sizeof(src_host))); \
|
||||
BUG_SUPPORT(ipaddr_to_string(&dst_addr, dst_host, sizeof(dst_host))); \
|
||||
BUG(BUG_SNARK_FIREWALL_RESET_PKT, BUG_CONTINUABLE, p, \
|
||||
(BUG_OUT, "FW: Reset: %u %s %u %s %u %s", \
|
||||
proto, src_host, src_port, dst_host, dst_port, ifname)); \
|
||||
return (int) FW_RESET; \
|
||||
} while (0)
|
||||
|
||||
static int filter(packet *p, struct filter *f, bits8_t *ip_hdr)
|
||||
{
|
||||
bits8_t proto = 0;
|
||||
bits16_t src_port = 0, dst_port = 0;
|
||||
ipaddr_t src_addr, dst_addr;
|
||||
char *ifname = "";
|
||||
bits8_t *tp_hdr = 0;
|
||||
int tcp_established = 0, tcp_setup = 0;
|
||||
size_t optlen;
|
||||
|
||||
BUG_SUPPORT(char src_host[MAX_IPADDR_STRING_LEN]);
|
||||
BUG_SUPPORT(char dst_host[MAX_IPADDR_STRING_LEN]);
|
||||
|
||||
BUG_ASSERT(p && ip_hdr);
|
||||
|
||||
/*
|
||||
* Extract relevant fields from the packet.
|
||||
*/
|
||||
|
||||
switch (GET_IP_HEADER_VERSION(ip_hdr)) {
|
||||
|
||||
#if INSTALL_ATTACHE_IPV4
|
||||
case IP_HEADER_VERSION_is_IPV4:
|
||||
optlen = GET_IP_HEADER_HEADER_LENGTH(ip_hdr) * 4 - SIZEOF_IP_HEADER;
|
||||
tp_hdr = ip_hdr + SIZEOF_IP_HEADER + optlen;
|
||||
break;
|
||||
#endif /* INSTALL_ATTACHE_IPV4 */
|
||||
|
||||
#if INSTALL_ATTACHE_IPV6
|
||||
case IP_HEADER_VERSION_is_IPV6:
|
||||
/* This isn't right. */
|
||||
optlen = 0;
|
||||
tp_hdr = ip_hdr + SIZEOF_IP6_HEADER + optlen;
|
||||
break;
|
||||
#endif /* INSTALL_ATTACHE_IPV6 */
|
||||
|
||||
default:
|
||||
FILTER_DROP();
|
||||
}
|
||||
|
||||
/* For the moment, just drop any packets containing IP options. */
|
||||
if (optlen)
|
||||
FILTER_DROP();
|
||||
|
||||
proto = GET_IP_HEADER_PROTOCOL(ip_hdr);
|
||||
GET_IP_SRC_ADDR(ip_hdr, &src_addr);
|
||||
GET_IP_DST_ADDR(ip_hdr, &dst_addr);
|
||||
|
||||
switch (proto) {
|
||||
case IP_PROTOCOL_is_TCP:
|
||||
if (p->pkt_data + p->pkt_datalen < tp_hdr + SIZEOF_TCP_HEADER)
|
||||
FILTER_DROP();
|
||||
src_port = GET_TCP_HEADER_SOURCE_PORT(tp_hdr);
|
||||
dst_port = GET_TCP_HEADER_DESTINATION_PORT(tp_hdr);
|
||||
tcp_established = GET_TCP_HEADER_ACK(tp_hdr) || GET_TCP_HEADER_RST(tp_hdr);
|
||||
tcp_setup = GET_TCP_HEADER_SYN(tp_hdr) && !GET_TCP_HEADER_ACK(tp_hdr);
|
||||
break;
|
||||
case IP_PROTOCOL_is_UDP:
|
||||
if (p->pkt_data + p->pkt_datalen < tp_hdr + SIZEOF_UDP_HEADER)
|
||||
FILTER_DROP();
|
||||
src_port = GET_UDP_HEADER_SOURCE_PORT(tp_hdr);
|
||||
dst_port = GET_UDP_HEADER_DESTINATION_PORT(tp_hdr);
|
||||
break;
|
||||
default:
|
||||
src_port = dst_port = 0;
|
||||
}
|
||||
|
||||
ifname = (p->pkt_n && p->pkt_n->s_name) ? p->pkt_n->s_name : "";
|
||||
|
||||
/*
|
||||
* Look for a matching rule.
|
||||
*/
|
||||
while (f &&
|
||||
((f->proto && (f->negate_proto ^ (proto != f->proto))) ||
|
||||
(proto == IP_PROTOCOL_is_TCP && ((f->tcp_setup && !tcp_setup) || (f->tcp_established && !tcp_established))) ||
|
||||
(f->negate_src_port ^ (src_port < f->src_low_port || src_port > f->src_high_port)) ||
|
||||
(f->negate_dst_port ^ (dst_port < f->dst_low_port || dst_port > f->dst_high_port)) ||
|
||||
(f->negate_src_addr ^ !ipaddr_match(&src_addr, &f->src_addr, f->src_prefix)) ||
|
||||
(f->negate_dst_addr ^ !ipaddr_match(&dst_addr, &f->dst_addr, f->dst_prefix)) ||
|
||||
(*f->ifname && (f->negate_ifname ^ (STRCMP(ifname, f->ifname) != 0)))))
|
||||
f = f->next;
|
||||
|
||||
/*
|
||||
* If we found a rule, apply it.
|
||||
*/
|
||||
if (f) {
|
||||
switch (f->action) {
|
||||
case FW_ALLOW:
|
||||
FILTER_ALLOW();
|
||||
case FW_RESET:
|
||||
#if 0
|
||||
/*
|
||||
* p->pkt_data would need adjustment here
|
||||
*/
|
||||
tcp_clrs(p);
|
||||
#endif
|
||||
FILTER_RESET();
|
||||
case FW_DROP:
|
||||
FILTER_DROP();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* For now, if we didn't find a matching rule, silently drop the packet.
|
||||
*/
|
||||
FILTER_DROP();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int snark_firewall_inbound_filter(packet *p)
|
||||
{
|
||||
return filter(p, ifilter, PKT_GET_IP_HEADER(p));
|
||||
}
|
||||
|
||||
int snark_firewall_outbound_filter(packet *p)
|
||||
{
|
||||
return filter(p, ofilter, p->pkt_data);
|
||||
}
|
||||
|
||||
int snark_firewall_forward_filter(packet *p)
|
||||
{
|
||||
return filter(p, ffilter, p->pkt_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int parse_action(struct filter *rule, char **av)
|
||||
{
|
||||
struct action_table *entry;
|
||||
|
||||
if (!(entry = keyword_find(&action_keywords, av[ARGV_ACTION])))
|
||||
return 0;
|
||||
|
||||
rule->action = entry->action;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int parse_proto(struct filter *rule, char **av)
|
||||
{
|
||||
struct proto_table *entry;
|
||||
char *sep;
|
||||
|
||||
if (*av[ARGV_PROTO] == '!') {
|
||||
rule->negate_proto = 1;
|
||||
av[ARGV_PROTO]++;
|
||||
}
|
||||
|
||||
if ((entry = keyword_find(&proto_keywords, av[ARGV_PROTO])) != 0) {
|
||||
rule->proto = entry->proto;
|
||||
return 1;
|
||||
}
|
||||
|
||||
rule->proto = STRTOUL(av[ARGV_PROTO], &sep, 10);
|
||||
return av[ARGV_PROTO] != '\0' && *sep == '\0';
|
||||
}
|
||||
|
||||
static int parse_ipaddr(struct filter *rule, char **av, int ai)
|
||||
{
|
||||
ipaddr_t *addr;
|
||||
bits8_t *prefix;
|
||||
unsigned negate = 0;
|
||||
char *pfx;
|
||||
|
||||
if (*av[ai] == '!') {
|
||||
negate = 1;
|
||||
av[ai]++;
|
||||
}
|
||||
|
||||
switch (ai) {
|
||||
case ARGV_SRC_ADDR:
|
||||
rule->negate_src_addr = negate;
|
||||
addr = &rule->src_addr;
|
||||
prefix = &rule->src_prefix;
|
||||
break;
|
||||
case ARGV_DST_ADDR:
|
||||
rule->negate_dst_addr = negate;
|
||||
addr = &rule->dst_addr;
|
||||
prefix = &rule->dst_prefix;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (av[ai][0] == '*' && av[ai][1] == '\0') {
|
||||
*prefix = 0;
|
||||
SET_IPADDR_TYPE(addr, IPNONE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (pfx = av[ai]; *pfx != '\0'; ++pfx) {
|
||||
if (*pfx == '/') {
|
||||
*pfx++ = '\0';
|
||||
if (*pfx == '\0')
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string_to_ipaddr(av[ai], addr);
|
||||
if (GET_IPADDR_TYPE(addr) == IPNONE)
|
||||
return 0;
|
||||
|
||||
if (*pfx == '\0') {
|
||||
*prefix = IPADDR_LENGTH(addr) * 8;
|
||||
return 1;
|
||||
} else {
|
||||
*prefix = STRTOUL(pfx, &pfx, 10);
|
||||
return *pfx == '\0' && *prefix <= IPADDR_LENGTH(addr) * 8;
|
||||
}
|
||||
}
|
||||
|
||||
static int parse_port(struct filter *rule, char **av, int ai)
|
||||
{
|
||||
bits16_t *lowport, *highport;
|
||||
unsigned negate = 0;
|
||||
char *sep;
|
||||
|
||||
if (*av[ai] == '!') {
|
||||
negate = 1;
|
||||
av[ai]++;
|
||||
}
|
||||
|
||||
switch (ai) {
|
||||
case ARGV_SRC_PORT:
|
||||
rule->negate_src_port = negate;
|
||||
lowport = &rule->src_low_port;
|
||||
highport = &rule->src_high_port;
|
||||
break;
|
||||
case ARGV_DST_PORT:
|
||||
rule->negate_dst_port = negate;
|
||||
lowport = &rule->dst_low_port;
|
||||
highport = &rule->dst_high_port;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (av[ai][0]) {
|
||||
case '\0':
|
||||
return 0;
|
||||
case '*':
|
||||
if (av[ai][1] != '\0')
|
||||
return 0;
|
||||
*lowport = 0;
|
||||
*highport = 0xFFFF;
|
||||
return 1;
|
||||
}
|
||||
|
||||
*lowport = STRTOUL(av[ai], &sep, 10);
|
||||
|
||||
switch (*sep) {
|
||||
case '\0':
|
||||
*highport = *lowport;
|
||||
return 1;
|
||||
case '-':
|
||||
if (*++sep == '\0')
|
||||
return 0;
|
||||
*highport = STRTOUL(sep, &sep, 10);
|
||||
return *sep == '\0';
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int parse_ifname(struct filter *rule, char **av)
|
||||
{
|
||||
if (*av[ARGV_IFNAME] == '!') {
|
||||
rule->negate_ifname = 1;
|
||||
av[ARGV_IFNAME]++;
|
||||
}
|
||||
|
||||
if (*av[ARGV_IFNAME] == '*' && *++av[ARGV_IFNAME] != '\0')
|
||||
return 0;
|
||||
|
||||
strncpy(rule->ifname, av[ARGV_IFNAME], sizeof(rule->ifname) - 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int parse_tcpflag(struct filter *rule, char **av, int ac)
|
||||
{
|
||||
struct tcpflag_table *entry;
|
||||
|
||||
if (rule->proto != IP_PROTOCOL_is_TCP || ac == ARGV_MINLENGTH)
|
||||
return 1;
|
||||
|
||||
if (ac > ARGV_MINLENGTH + 1 || (entry = keyword_find(&tcpflag_keywords, av[ARGV_MINLENGTH])) == 0)
|
||||
return 0;
|
||||
|
||||
switch (entry->flag) {
|
||||
case TCPFLAG_ESTABLISHED:
|
||||
rule->tcp_established = 1;
|
||||
return 1;
|
||||
case TCPFLAG_SETUP:
|
||||
rule->tcp_setup = 1;
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void config_1 (struct ini_handle *ini_handle, char *name, struct filter **tail)
|
||||
{
|
||||
static char snark_section[] = "etc snark firewall";
|
||||
struct filter *rule = 0;
|
||||
char *s, buf[256], *av[20];
|
||||
int ac;
|
||||
|
||||
BUG_ASSERT(sizeof(buf) >= ini_handle->buflen);
|
||||
|
||||
*tail = 0;
|
||||
|
||||
for (s = ini_iter_start(ini_handle, snark_section, name); s;
|
||||
s = ini_iter_next(ini_handle)) {
|
||||
if (!rule && !(rule = GLUE_ALLOC(sizeof(*rule)))) {
|
||||
BUG(BUG_SNARK_FIREWALL_CONFIG_ALLOC_FAILED, BUG_FATAL, s,
|
||||
(BUG_OUT, "fw_config_1(): allocation failed for rule: %s", s));
|
||||
return;
|
||||
}
|
||||
MEMSET(rule, 0, sizeof(*rule));
|
||||
|
||||
STRCPY(buf, s);
|
||||
if ((ac = parse_line(buf, av, sizeof(av)/sizeof(*av))) < ARGV_MINLENGTH ||
|
||||
!parse_action(rule, av) ||
|
||||
!parse_proto(rule, av) ||
|
||||
!parse_ipaddr(rule, av, ARGV_SRC_ADDR) ||
|
||||
!parse_ipaddr(rule, av, ARGV_DST_ADDR) ||
|
||||
!parse_port(rule, av, ARGV_SRC_PORT) ||
|
||||
!parse_port(rule, av, ARGV_DST_PORT) ||
|
||||
!parse_ifname(rule, av) ||
|
||||
!parse_tcpflag(rule, av, ac)) {
|
||||
BUG(BUG_SNARK_FIREWALL_CONFIG_PARSE_ERROR, BUG_FATAL, s,
|
||||
(BUG_OUT, "fw_config_1(): couldn't parse rule: %s", s));
|
||||
GLUE_FREE(rule);
|
||||
return;
|
||||
}
|
||||
|
||||
*tail = rule;
|
||||
tail = &rule->next;
|
||||
rule = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void snark_firewall_init (void)
|
||||
{
|
||||
struct ini_handle *ini_handle = ini_open(256);
|
||||
KEYWORD_INIT(&action_keywords, action_table);
|
||||
KEYWORD_INIT(&proto_keywords, proto_table);
|
||||
KEYWORD_INIT(&tcpflag_keywords, tcpflag_table);
|
||||
config_1(ini_handle, "inbound-filter", &ifilter);
|
||||
config_1(ini_handle, "outbound-filter", &ofilter);
|
||||
config_1(ini_handle, "forward-filter", &ffilter);
|
||||
ini_close(ini_handle);
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/keyword.c,v 1.3 2003/01/15 14:04:31 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: keyword.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:31 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:22 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:41 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.11 2001/01/19 22:23:42 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.10 2000/03/17 00:12:39 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.9 1998/07/02 06:55:35 sra
|
||||
* Make Snark restartable under pSOS, and other minor cleanups.
|
||||
*
|
||||
* Revision 1.8 1998/02/25 15:21:47 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 1.7 1998/02/25 04:57:24 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.6 1997/03/20 06:52:54 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 1.5 1997/03/19 22:05:35 sra
|
||||
* Perhaps we should include install.h before testing install options?
|
||||
*
|
||||
* Revision 1.4 1997/03/19 20:17:56 sra
|
||||
* Fun with "const" attributes. Remove gratuitous Attache dependencies.
|
||||
*
|
||||
* Revision 1.3 1997/03/19 04:47:35 sra
|
||||
* Get rid of some gratuitous historical dependencies on Attache.
|
||||
*
|
||||
* Revision 1.2 1997/03/09 18:39:33 sra
|
||||
* Fix some compiler warnings, change from compile-time to run-time init
|
||||
* macros for keyword tables.
|
||||
*
|
||||
* Revision 1.1 1997/02/19 08:13:05 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
#include <wrn/wm/common/bug.h>
|
||||
|
||||
/*
|
||||
* This business with (const char * const *) is pretty grotty,
|
||||
* but the idea is that we're converting a pointer to constant data
|
||||
* into a pointer to a constant pointer to constant data.
|
||||
* The syntax is awful, but without the second const token in the cast,
|
||||
* gcc correctly objects to the cast as throwing away the constraint
|
||||
* that came with the original (const void *) argument.
|
||||
*/
|
||||
|
||||
static int q_compare(const void *thing1, const void *thing2)
|
||||
{
|
||||
return STRICMP(*(const char * const *) thing1,
|
||||
*(const char * const *) thing2);
|
||||
}
|
||||
|
||||
static int b_compare(const void *key, const void *thing)
|
||||
{
|
||||
return STRNICMP((const char *) key,
|
||||
*(const char * const *) thing,
|
||||
STRLEN((const char *) key));
|
||||
}
|
||||
|
||||
/* ref(a,i) :=: &a[i] */
|
||||
#define ref(_a_,_i_) (((char *) (_a_)) + ((_i_) * s))
|
||||
|
||||
void *keyword_find(struct keyword_table *table, const char *name)
|
||||
{
|
||||
void *r, *t = table->table;
|
||||
size_t n = table->table_length, s = table->entry_size;
|
||||
|
||||
BUG_ASSERT(table && table->table && name);
|
||||
|
||||
r = table->result = bsearch(name, t, n, s, b_compare);
|
||||
if (!r)
|
||||
table->error = KEYWORD_ERROR_NOT_FOUND;
|
||||
else if ((ref(r, 0) > ref(t, 0) && !b_compare(name, ref(r, -1))) ||
|
||||
(ref(r, 0) < ref(t, n - 1) && !b_compare(name, ref(r, +1))))
|
||||
table->error = KEYWORD_ERROR_AMBIGUOUS;
|
||||
else
|
||||
table->error = KEYWORD_ERROR_OK;
|
||||
|
||||
return table->error == KEYWORD_ERROR_OK ? r : 0;
|
||||
}
|
||||
|
||||
void
|
||||
keyword_init(struct keyword_table *table,
|
||||
void * array,
|
||||
size_t array_length,
|
||||
size_t entry_size)
|
||||
{
|
||||
BUG_ASSERT(table && array && array_length && entry_size);
|
||||
|
||||
MEMSET(table, 0, sizeof(*table));
|
||||
table->table = array;
|
||||
table->table_length = array_length;
|
||||
table->entry_size = entry_size;
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* If we were worried about loading the keyword table from
|
||||
* read-only memory, we'd do this here.
|
||||
*/
|
||||
table->table = GLUE_ALLOC(array_length);
|
||||
BUG_ASSERT(table->table);
|
||||
MEMCPY(table->table, array, array_length);
|
||||
#endif /* 0 */
|
||||
|
||||
qsort(table->table, array_length, entry_size, q_compare);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/loopglue.c,v 1.2 2001/11/08 15:56:22 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* This code is cursed and should not be used as an example. It
|
||||
* exists for historical reasons only.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: loopglue.c,v $
|
||||
* Revision 1.2 2001/11/08 15:56:22 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:41 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.8 2001/01/19 22:23:42 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.7 2000/03/17 00:12:39 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.6 1998/02/25 04:57:24 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.5 1998/02/18 22:34:54 sra
|
||||
* Add ip_loopback(), eradicate glue_pkt_handle().
|
||||
*
|
||||
* Revision 1.4 1997/03/20 06:52:56 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 1.3 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 1.2 1997/01/15 01:24:09 sra
|
||||
* Fix a packet leak.
|
||||
*
|
||||
* Revision 1.1 1997/01/08 01:20:46 sar
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
|
||||
/*
|
||||
* Nothing should ever call this function anymore. On the off-chance
|
||||
* that a customer has code that still invokes the ancient and
|
||||
* undocumented glue_pkt_handle() function, here's a definition that
|
||||
* should be relatively harmless. If you're reading this comment
|
||||
* because your application blew out its stack with nested invocations
|
||||
* of glue_pkt_handle(), please contact support@epilogue.com and
|
||||
* describe your application to us so that we can help you fix this.
|
||||
*/
|
||||
|
||||
void glue_pkt_handle(packet *p, void (*handler)(packet *))
|
||||
{
|
||||
handler(p);
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/main.c,v 1.2 2001/11/08 15:56:22 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: main.c,v $
|
||||
* Revision 1.2 2001/11/08 15:56:22 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:41 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.11 2001/01/19 22:23:45 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.10 2000/10/16 19:21:53 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 1.9 2000/03/17 00:12:39 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.8 2000/03/13 21:22:05 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 1.7 1999/02/18 04:41:33 wes
|
||||
* Sockets merge: Everything Else
|
||||
* - memory pools
|
||||
* - thread support
|
||||
* - port-specific headers
|
||||
*
|
||||
* Revision 1.6.10.3 1998/11/13 18:17:25 wes
|
||||
* Make SNARK_*LOCK*() calls into the "real" attache global lock
|
||||
* ATTACHE_*LOCK*() and make it live in attache-land, not snark-land.
|
||||
*
|
||||
* Revision 1.6.10.2 1998/10/22 20:29:34 wes
|
||||
* add a `name' field to the debugging version of the mutex for added
|
||||
* ease of interpreting mutex assertion problems.
|
||||
*
|
||||
* Revision 1.6.10.1 1998/09/23 19:17:18 wes
|
||||
* Merge socket-branch-1 changes to socket-branch-2
|
||||
*
|
||||
* Revision 1.6.8.2 1998/09/11 21:32:03 wes
|
||||
* Rename EPI_ prefix thread primitives to ETC_ prefix
|
||||
*
|
||||
* Revision 1.6.8.1 1998/08/19 13:26:28 wes
|
||||
* Merge sockets-pthreads work to shared branch
|
||||
*
|
||||
* Revision 1.6.2.1 1998/07/28 18:14:52 wes
|
||||
* pthread hacks
|
||||
*
|
||||
* Revision 1.6 1998/06/04 18:06:32 sra
|
||||
* Do psos_main() definition a slightly different way.
|
||||
*
|
||||
* Revision 1.5 1998/04/29 23:16:07 meister
|
||||
* SNARK_OVER_PSOS install #define
|
||||
*
|
||||
* Revision 1.4 1998/04/24 21:58:10 meister
|
||||
* Initial rev of pSOS snark port.
|
||||
*
|
||||
* Revision 1.3 1998/02/25 04:57:25 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.2 1997/03/20 06:52:56 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 1.1 1997/02/19 08:13:05 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
#if INSTALL_ATTACHE_THREADS
|
||||
#include <wrn/wm/attache/attthd.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* snark_exit() is like exit() but it first does a clean shutdown
|
||||
* of all the snark stuff, which might matter if you're running under purify
|
||||
* and care about memory leaks, or if you're running under DOS and ever want
|
||||
* to use your machine again without rebooting it first.
|
||||
*/
|
||||
|
||||
void snark_exit(int value)
|
||||
{
|
||||
#if INSTALL_SNARK_EXIT_UNWIND
|
||||
snark_exit_flag = 1;
|
||||
snark_exit_value = value;
|
||||
#else
|
||||
snark_shutdown();
|
||||
exit(value);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* This is gross, but it's better than having two parameter lists to
|
||||
* the same function.
|
||||
*/
|
||||
#if INSTALL_SNARK_OVER_PSOS
|
||||
#define main psos_main
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct snark_main_args main_args;
|
||||
struct task initial_task;
|
||||
void *initial_task_cookie;
|
||||
|
||||
#if INSTALL_ATTACHE_THREADS
|
||||
ATTACHE_THREAD_INIT();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Set up argument block we pass to application's snark_main() function.
|
||||
* Use an explicit cookie variable so that the user-exits can muck with
|
||||
* it if they feel a need to do so.
|
||||
*/
|
||||
main_args.argc = argc;
|
||||
main_args.argv = argv;
|
||||
initial_task_cookie = &main_args;
|
||||
|
||||
snark_exit_flag = snark_exit_value = 0;
|
||||
|
||||
/*
|
||||
* User-exit to let application interfere before snark is running.
|
||||
*/
|
||||
#ifdef SNARK_PRE_INIT_HOOK
|
||||
SNARK_PRE_INIT_HOOK(initial_task_cookie);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Initialize the core of snark itself.
|
||||
*/
|
||||
snark_init();
|
||||
|
||||
/*
|
||||
* Set up the cty. Note that since we're doing this without
|
||||
* issuing any banner, snark_main() (or something it calls)
|
||||
* will have to do that "manually" later. Sorry, but we need
|
||||
* to set up the cty ASAP for logging, init output, etc.
|
||||
*/
|
||||
sty_listen(cty_set);
|
||||
CTY_SETUP();
|
||||
sty_listen(0);
|
||||
|
||||
/*
|
||||
* User-exit to let application interfere after snark is running.
|
||||
*/
|
||||
#ifdef SNARK_POST_INIT_HOOK
|
||||
SNARK_POST_INIT_HOOK(initial_task_cookie);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Set up the initial task to call the application's snark_main() function.
|
||||
*/
|
||||
task_ini(&initial_task);
|
||||
task_add(&initial_task, "Snark initial task",
|
||||
snark_main, initial_task_cookie);
|
||||
|
||||
/*
|
||||
* Start running the tasking I/O system. If this ever returns, its
|
||||
* value is what we should use for our exit value.
|
||||
*/
|
||||
return tasks_run();
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
|
||||
#
|
||||
# snark/lib
|
||||
#
|
||||
|
||||
$#equate(PRODUCTH $#filepath($(SRCDIR) target h wrn wm demo))
|
||||
|
||||
$#makefile-init()
|
||||
|
||||
##############################################################################
|
||||
# OBJECT FILE DEFINITION SECTION
|
||||
|
||||
$#equate(OBJS
|
||||
$#objs(sty tasks parse read_ini sty_kb main keyword strdup)
|
||||
$#if-installed(on_unix $#objs(snarkbsd))
|
||||
$#if-installed(on_msdos $#objs(snarkdos))
|
||||
$#if-installed(SNARK_OVER_PSOS $#objs(snrkpsos psostty))
|
||||
$#if-installed(DECORUM $#objs(put_str filefunc tad))
|
||||
$#if-installed(LIAISON $#objs(collect))
|
||||
$#if-installed(SNARK_BUG_CONF $#objs(bug_conf))
|
||||
$#if-installed(ATTACHE $#objs(netconf loopglue
|
||||
swap cksum))
|
||||
$#if-installed(SNARK_BSD_BPF $#objs(bpfdrive bpf))
|
||||
$#if-installed(SNARK_BSD_NIT $#objs(nitdrive nit))
|
||||
$#if-installed(SNARK_BSD_SLIP $#objs(slipbsd))
|
||||
$#if-installed(SNARK_BSD_PPP $#objs(pppbsd))
|
||||
$#if-installed(SNARK_BSD_TUN $#objs(tun))
|
||||
$#if-installed(SNARK_DLPI $#objs(dlpidrv dlpi))
|
||||
$#if-installed(SNARK_BSD_VAPORNET $#objs(vapornet))
|
||||
$#if-installed(SNARK_BSD_SNOOP $#objs(snoopdrv snoop))
|
||||
$#if-installed(SNARK_DOS_PKTDRV $#objs(pktdrive pktd))
|
||||
$#if-installed(SNARK_POOL_TEST $#objs(pool))
|
||||
$#if-installed(ATTACHE_TELNET $#objs(sty_tn))
|
||||
$#if-installed(SNARK_RELAY_PCL725 $#objs(relay))
|
||||
$#if-installed(ENVOY $#objs(snmpfunc snmp_att
|
||||
snmpconf nvutils
|
||||
nvviews))
|
||||
$#if-installed(SNARK_FIREWALL $#objs(firewall))
|
||||
)
|
||||
|
||||
all: $#libs(snark) $#dummy()
|
||||
|
||||
##############################################################################
|
||||
# Make the library itself
|
||||
|
||||
$#makelib(snark $#(OBJS) $(MAKEFILENAME))
|
||||
|
||||
# commands to figure out how big this all compiles to
|
||||
sizes: $#dummy()
|
||||
$#makesizehdr(Snark)
|
||||
$#makesize(library $(OBJS))
|
||||
|
||||
clean: $#dummy()
|
||||
-$(RM) $#objs(*)
|
||||
-$(RM) $#libs(snark)
|
||||
$#clean()
|
||||
|
||||
##############################################################################
|
||||
# file dependencies
|
||||
|
||||
$#objs(sty) : sty.c \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/install.h $#port-hdr(snark.h) \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/sty.h
|
||||
$#objs(sty_tn) : sty_tn.c $(SRCDIR)/target/h/wrn/wm/attache/config.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/install.h $#port-hdr(attache.h) \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/tn.h $(SRCDIR)/target/h/wrn/wm/demo/sty.h
|
||||
$#objs(tasks) : tasks.c \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/install.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/tasks.h
|
||||
$#objs(parse) : parse.c $(SRCDIR)/target/h/wrn/wm/demo/parse.h
|
||||
$#objs(netconf) : netconf.c $(SRCDIR)/target/h/wrn/wm/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/config.h $(SRCDIR)/target/h/wrn/wm/common/install.h \
|
||||
$#port-hdr(attache.h) $(SRCDIR)/target/h/wrn/wm/attache/mib.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/timer.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/packet.h $(SRCDIR)/target/h/wrn/wm/attache/net.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/glue.h $(SRCDIR)/target/h/wrn/wm/attache/route.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/ip.h $(SRCDIR)/target/h/wrn/wm/attache/udp.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/dns.h $(SRCDIR)/target/h/wrn/wm/attache/loop.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/dhcp.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/read_ini.h $(SRCDIR)/target/h/wrn/wm/demo/parse.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/netconf.h
|
||||
$#objs(read_ini) : read_ini.c \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/install.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/read_ini.h
|
||||
$#objs(sty_kb) : sty_kb.c \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/install.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/sty.h $(SRCDIR)/target/h/wrn/wm/demo/keyboard.h $#port-hdr(snark.h)
|
||||
$#objs(snarkbsd) : snarkbsd.c \
|
||||
$#if-installed(ATTACHE
|
||||
$#progn($(SRCDIR)/target/h/wrn/wm/attache/config.h $#port-hdr(attache.h)
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/bsdif.h $(SRCDIR)/target/h/wrn/wm/demo/netconf.h
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/bpfdrive.h $(SRCDIR)/target/h/wrn/wm/demo/slipbsd.h
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/nitdrive.h $(SRCDIR)/target/h/wrn/wm/demo/vapornet.h
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/packet.h $(SRCDIR)/target/h/wrn/wm/attache/net.h
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/glue.h $(SRCDIR)/target/h/wrn/wm/attache/route.h
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/ip.h $(SRCDIR)/target/h/wrn/wm/attache/loop.h)) \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/tasks.h $(SRCDIR)/target/h/wrn/wm/demo/sty.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/keyboard.h $#port-hdr(snark.h) \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/install.h
|
||||
$#objs(slipbsd) : slipbsd.c $(SRCDIR)/target/h/wrn/wm/attache/config.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/bsdif.h $(SRCDIR)/target/h/wrn/wm/demo/slipbsd.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/mib.h $(SRCDIR)/target/h/wrn/wm/attache/timer.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/packet.h $(SRCDIR)/target/h/wrn/wm/attache/net.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/glue.h $(SRCDIR)/target/h/wrn/wm/attache/route.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/ip.h $(SRCDIR)/target/h/wrn/wm/attache/loop.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/types.h $(SRCDIR)/target/h/wrn/wm/common/install.h
|
||||
$#objs(bpfdrive) : bpfdrive.c $(SRCDIR)/target/h/wrn/wm/attache/config.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/bsdif.h $(SRCDIR)/target/h/wrn/wm/demo/bpf.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/bpfdrive.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/mib.h $(SRCDIR)/target/h/wrn/wm/attache/timer.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/packet.h $(SRCDIR)/target/h/wrn/wm/attache/net.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/ether.h $(SRCDIR)/target/h/wrn/wm/attache/arp.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/glue.h $(SRCDIR)/target/h/wrn/wm/attache/route.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/types.h $(SRCDIR)/target/h/wrn/wm/common/install.h
|
||||
$#objs(vapornet) : vapornet.c \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/bsdif.h $(SRCDIR)/target/h/wrn/wm/demo/vapornet.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/read_ini.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/config.h $(SRCDIR)/target/h/wrn/wm/common/types.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/install.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/mib.h $(SRCDIR)/target/h/wrn/wm/attache/timer.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/packet.h $(SRCDIR)/target/h/wrn/wm/attache/net.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/glue.h $(SRCDIR)/target/h/wrn/wm/attache/route.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/ip.h
|
||||
$#objs(nit) : nit.c $(SRCDIR)/target/h/wrn/wm/demo/nit.h
|
||||
$#objs(nitdrive) : nitdrive.c $(SRCDIR)/target/h/wrn/wm/demo/nitdrive.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/nit.h $(SRCDIR)/target/h/wrn/wm/demo/bsdif.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/config.h $(SRCDIR)/target/h/wrn/wm/common/types.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/install.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/mib.h $(SRCDIR)/target/h/wrn/wm/attache/timer.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/packet.h $(SRCDIR)/target/h/wrn/wm/attache/net.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/ether.h $(SRCDIR)/target/h/wrn/wm/attache/arp.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/glue.h $(SRCDIR)/target/h/wrn/wm/attache/route.h
|
||||
$#objs(snarkdos) : snarkdos.c $(SRCDIR)/target/h/wrn/wm/common/install.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/types.h \
|
||||
$#if-installed(ATTACHE
|
||||
$#progn($(SRCDIR)/target/h/wrn/wm/demo/netconf.h $(SRCDIR)/target/h/wrn/wm/demo/pktdrive.h
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/config.h
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/mib.h $(SRCDIR)/target/h/wrn/wm/attache/timer.h
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/packet.h $(SRCDIR)/target/h/wrn/wm/attache/net.h
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/ip.h $(SRCDIR)/target/h/wrn/wm/attache/loop.h
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/glue.h $(SRCDIR)/target/h/wrn/wm/attache/route.h)) \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/tasks.h $(SRCDIR)/target/h/wrn/wm/demo/sty.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/keyboard.h
|
||||
$#objs(pktdrive) : pktdrive.c $(SRCDIR)/target/h/wrn/wm/demo/pktd_msc.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/pktd_bcc.h $(SRCDIR)/target/h/wrn/wm/demo/pktd.h\
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/config.h $(SRCDIR)/target/h/wrn/wm/common/types.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/install.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/mib.h $(SRCDIR)/target/h/wrn/wm/attache/timer.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/packet.h $(SRCDIR)/target/h/wrn/wm/attache/net.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/arp.h $(SRCDIR)/target/h/wrn/wm/attache/ether.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/ip.h $(SRCDIR)/target/h/wrn/wm/attache/ppp.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/attache/glue.h $(SRCDIR)/target/h/wrn/wm/attache/route.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/tasks.h
|
||||
$#objs(pktd) : pktd.c $(SRCDIR)/target/h/wrn/wm/demo/pktd_msc.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/pktd_bcc.h $(SRCDIR)/target/h/wrn/wm/demo/pktd.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/common/install.h
|
||||
$#objs(put_str) : put_str.c $(SRCDIR)/target/h/wrn/wm/common/types.h $#port-hdr(oemtypes.h) \
|
||||
$#port-hdr(decorum.h) $(SRCDIR)/envoy/h/asn1conf.h
|
||||
$#objs(filefunc) : filefunc.c $(SRCDIR)/target/h/wrn/wm/common/types.h \
|
||||
$#port-hdr(oemtypes.h) \
|
||||
$#port-hdr(decorum.h)
|
||||
$#objs(bug_conf) : bug_conf.c $(SRCDIR)/target/h/wrn/wm/common/bugdef.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/snarklib.h \
|
||||
$(SRCDIR)/target/h/wrn/wm/demo/read_ini.h
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,373 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/nit.c,v 1.2 2001/11/08 15:56:23 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1994-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: nit.c,v $
|
||||
* Revision 1.2 2001/11/08 15:56:23 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:42 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.10 2001/01/19 22:23:46 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.9 2000/03/17 00:12:40 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.8 1998/07/31 19:45:45 wes
|
||||
* Put packet filtering into NIT driver...
|
||||
*
|
||||
* Revision 2.7 1998/02/25 04:57:27 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.6 1997/11/21 00:06:24 josh
|
||||
* updating files for Liaison support for NIT
|
||||
*
|
||||
* Revision 2.5 1997/05/17 23:08:55 sra
|
||||
* Clean up some SunOS/gcc warnings.
|
||||
*
|
||||
* Revision 2.4 1997/05/02 02:45:49 sra
|
||||
* Support NIT in promiscuous mode, for IPv6 multicast.
|
||||
*
|
||||
* Revision 2.3 1997/03/20 06:52:59 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.2 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.2 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.1 1994/01/09 23:57:29 sra
|
||||
* Add support for NIT under SunOS 4.1.2.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* NIT interface to ethernet for Attache testing under SunOS 4.1.2.
|
||||
*
|
||||
* All access to NIT should be through this module, the only thing we
|
||||
* expect our caller to do with our file descriptor is use it in
|
||||
* select() calls. There are enough name conflicts between the unix
|
||||
* networking code and the Attache networking code that it's probably
|
||||
* hopeless to have the two mingled in the same file.
|
||||
*
|
||||
* References: NIT manual pages
|
||||
* tcpdump source
|
||||
* CAP ethertalk source
|
||||
* netintro(4) manual page
|
||||
* NET-2 routed source
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <net/nit.h>
|
||||
#include <net/nit_if.h>
|
||||
#include <net/nit_pf.h>
|
||||
#include <net/nit_buf.h>
|
||||
#include <net/packetfilt.h>
|
||||
#include <stropts.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
||||
#define __(x) x
|
||||
#include <wrn/wm/demo/nit.h>
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define alloca __builtin_alloca
|
||||
#endif
|
||||
|
||||
/* 1997 and they still can't prototype the system functions. */
|
||||
extern int ioctl(), putmsg(), socket();
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Open a NIT file and attach it to the interface named 'device'.
|
||||
* Returns NIT file descriptor, or -1 if an error occurs.
|
||||
*
|
||||
* Since this implementation uses the same ethernet address as the host
|
||||
* on which it's running, fill in Attache's idea of the MAC address.
|
||||
*/
|
||||
|
||||
int nit_open(char *ifname, unsigned mtu, unsigned char *mac)
|
||||
{
|
||||
struct strioctl si;
|
||||
struct ifreq ifr;
|
||||
int fd;
|
||||
int promiscuous = 1;
|
||||
|
||||
/*
|
||||
* Look for cloned NIT device.
|
||||
*/
|
||||
if ((fd = open("/dev/nit", O_RDWR)) < 0) {
|
||||
perror("couldn't clone NIT device");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable discrete messages.
|
||||
*/
|
||||
if (ioctl(fd, I_SRDOPT, (char *) RMSGD) < 0) {
|
||||
perror("couldn't enable discrete NIT messages");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Attach the NIT device to the interface.
|
||||
*/
|
||||
(void) strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||
si.ic_cmd = NIOCBIND;
|
||||
si.ic_timout = INFTIM;
|
||||
si.ic_len = sizeof(ifr);
|
||||
si.ic_dp = (char *) 𝔦
|
||||
if (ioctl(fd, I_STR, (char *) &si) < 0) {
|
||||
perror("couldn't bind NIT to interface");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Turn on promiscuous mode for multicast, etc.
|
||||
* Only root can do this, so just continue if this fails.
|
||||
*/
|
||||
{
|
||||
unsigned long flags = NI_PROMISC;
|
||||
si.ic_cmd = NIOCSFLAGS;
|
||||
si.ic_len = sizeof(flags);
|
||||
si.ic_dp = (char *) &flags;
|
||||
if (ioctl(fd, I_STR, (char *) &si) < 0) {
|
||||
perror("Couldn't set promiscuous mode, continuing");
|
||||
promiscuous = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Flush the read queue, don't worry about it if we can't.
|
||||
*/
|
||||
(void) ioctl(fd, I_FLUSH, (char *) FLUSHR);
|
||||
|
||||
/*
|
||||
* Get local MAC address for Attache to use, if we were given one
|
||||
*/
|
||||
if (mac && !promiscuous) {
|
||||
if (ioctl(fd, SIOCGIFADDR, &ifr) < 0) {
|
||||
perror("couldn't get local MAC address");
|
||||
} else {
|
||||
memcpy(mac, ((struct sockaddr *) &ifr.ifr_data)->sa_data, 6);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Push packet filter module.
|
||||
*/
|
||||
|
||||
if (ioctl(fd, I_PUSH, "pf") < 0) {
|
||||
perror("couldn't push packet filter STREAMS module, continuing..");
|
||||
} else {
|
||||
struct packetfilt pfil;
|
||||
|
||||
u_short *pfp = &pfil.Pf_Filter[0];
|
||||
|
||||
/*
|
||||
* Yum. Interpreted LIW code, the result of several hours of mental pain.
|
||||
* This *might* be an optimal instruction schedule.
|
||||
*
|
||||
* Whoever named the ENF_C{N,}{AND,OR} ops was.. confused...
|
||||
* But, well...
|
||||
*/
|
||||
|
||||
*pfp++ = ENF_PUSHLIT;
|
||||
*pfp++ = 0x0100; /* multicast bit */
|
||||
*pfp++ = (ENF_PUSHWORD+0) | ENF_AND; /* mask with first word of mac */
|
||||
*pfp++ = ENF_PUSHZERO | ENF_CNAND; /* succeed if nonzero */
|
||||
|
||||
*pfp++ = ENF_PUSHLIT;
|
||||
*pfp++ = ntohs(*(u_short *)mac); /* first word of mac */
|
||||
*pfp++ = (ENF_PUSHWORD+0) | ENF_CAND; /* fail if not equal */
|
||||
|
||||
*pfp++ = ENF_PUSHLIT;
|
||||
*pfp++ = ntohs(*(u_short *)(mac+2)); /* second word of mac */
|
||||
*pfp++ = (ENF_PUSHWORD+1) | ENF_CAND; /* fail if not equal */
|
||||
|
||||
*pfp++ = ENF_PUSHLIT;
|
||||
*pfp++ = ntohs(*(u_short *)(mac+4)); /* third word of mac */
|
||||
*pfp++ = (ENF_PUSHWORD+2) | ENF_EQ; /* succeed if equal.. */
|
||||
|
||||
pfil.Pf_Priority = 0;
|
||||
pfil.Pf_FilterLen = pfp - &pfil.Pf_Filter[0];
|
||||
|
||||
si.ic_cmd = NIOCSETF;
|
||||
si.ic_timout = -1;
|
||||
si.ic_len = sizeof(pfil);
|
||||
si.ic_dp = (void *)&pfil;
|
||||
if (ioctl(fd, I_STR, &si) < 0) {
|
||||
perror("couldn't set packet filter, continuing..");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't bother with buffering or truncation for now.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Flush the read queue, don't worry about it if we can't.
|
||||
*/
|
||||
(void) ioctl(fd, I_FLUSH, (char *) FLUSHR);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Read a NIT buffer and hand its contents off to Attache as packets.
|
||||
* This is based on the readloop() function in tcpdump's BPF code and
|
||||
* on the nit(4) manual page.
|
||||
*
|
||||
* The handler routine supplied by the Attache-side code gets three
|
||||
* arguments: a pointer to the packet data, the length of the packet
|
||||
* data, and the length that the real packet was on the wire.
|
||||
*
|
||||
* There's probably nothing useful that Attache can do with a truncated
|
||||
* packet, but the info is there, so we may as well pass it along.
|
||||
*/
|
||||
|
||||
int nit_read
|
||||
(int fd,
|
||||
unsigned mtu,
|
||||
void (*handler)(unsigned char *, unsigned, unsigned, void *),
|
||||
void *cookie)
|
||||
{
|
||||
unsigned char *buf;
|
||||
int i;
|
||||
|
||||
if ((buf = (unsigned char *) alloca(mtu)) == 0) {
|
||||
fprintf(stderr, "alloca(%d) failed\n", mtu);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to read a packet, restart if we get screwed by the debugger.
|
||||
* Return on other error or on EOF.
|
||||
*/
|
||||
do {
|
||||
i = read(fd, buf, mtu);
|
||||
} while (i < 0 && errno == EINTR);
|
||||
if (i <= 0)
|
||||
return i;
|
||||
|
||||
/*
|
||||
* In theory, since we've got the stream in discrete message mode,
|
||||
* we can just assume that we got one packet.
|
||||
*/
|
||||
handler(buf, i, i, cookie);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Write a packet to the NIT stream.
|
||||
*/
|
||||
|
||||
int nit_write(int fd, unsigned char *data, unsigned datalen)
|
||||
{
|
||||
struct strbuf pbuf, dbuf;
|
||||
struct sockaddr sa;
|
||||
|
||||
sa.sa_family = AF_UNSPEC;
|
||||
memcpy(sa.sa_data, data, sizeof(struct ether_header));
|
||||
|
||||
pbuf.len = sizeof(sa);
|
||||
pbuf.buf = (char *) &sa;
|
||||
dbuf.len = datalen - sizeof(struct ether_header);
|
||||
dbuf.buf = (char *) data + sizeof(struct ether_header);
|
||||
|
||||
return putmsg(fd, &pbuf, &dbuf, 0) < 0 ? -1 : datalen;
|
||||
}
|
||||
|
||||
/*
|
||||
* Close a NIT interface.
|
||||
*/
|
||||
|
||||
void nit_close(int fd)
|
||||
{
|
||||
(void) close(fd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined(SIOCGIFCONF)
|
||||
|
||||
/*
|
||||
* Find all ethernet interfaces. This is a simplified version of the
|
||||
* code that works on NetBSD, I dunno yet whether this will work on SunOS.
|
||||
*/
|
||||
|
||||
void nit_find(void (*handler)(char *, void *), void *cookie)
|
||||
{
|
||||
char buffer[5000];
|
||||
struct ifconf ifc;
|
||||
struct ifreq *ifr;
|
||||
int s;
|
||||
|
||||
if (!handler)
|
||||
return;
|
||||
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("socket");
|
||||
return;
|
||||
}
|
||||
ifc.ifc_len = sizeof(buffer);
|
||||
ifc.ifc_buf = buffer;
|
||||
if (ioctl(s, SIOCGIFCONF, (char *) &ifc) < 0) {
|
||||
perror("ioctl");
|
||||
(void) close(s);
|
||||
return;
|
||||
}
|
||||
for (ifr = ifc.ifc_req; ((char *) ifr) < ifc.ifc_buf + ifc.ifc_len; ++ifr)
|
||||
handler(ifr->ifr_name, cookie);
|
||||
(void) close(s);
|
||||
}
|
||||
|
||||
#endif /* defined(SIOCGIFCONF) */
|
||||
@@ -0,0 +1,315 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/nitdrive.c,v 1.4 2003/01/15 14:04:32 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1994-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: nitdrive.c,v $
|
||||
* Revision 1.4 2003/01/15 14:04:32 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.3 2001/11/08 15:56:23 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.2 2001/11/06 20:11:12 josh
|
||||
* updating include paths to include proper path to layout directory
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:42 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.19 2001/01/19 22:23:47 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.18 2000/10/20 18:32:25 paul
|
||||
* Properly conditionalized driver.ip_send
|
||||
*
|
||||
* Revision 2.17 2000/10/16 19:21:54 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 2.16 2000/03/17 00:12:40 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.15 2000/03/13 21:22:06 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 2.14 1999/11/05 22:29:05 paul
|
||||
* Updated driver structs to reflect conditional backwards-compatibility
|
||||
* fields and new fields.
|
||||
*
|
||||
* Revision 2.13 1998/08/17 22:46:40 wes
|
||||
* Silence purify warning
|
||||
*
|
||||
* Revision 2.12 1998/07/31 19:45:48 wes
|
||||
* Put packet filtering into NIT driver...
|
||||
*
|
||||
* Revision 2.11 1998/04/16 17:29:56 wes
|
||||
* Enable use of ethernet media control
|
||||
*
|
||||
* Revision 2.10 1998/02/25 15:21:48 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 2.9 1998/02/25 04:57:28 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.8 1997/05/20 02:21:46 mrf
|
||||
* make snark lib driver code use new ldb arp definitions
|
||||
*
|
||||
* Revision 2.7 1997/05/07 17:23:35 mrf
|
||||
* move ipv6_send function to end of net_if structure
|
||||
*
|
||||
* Revision 2.5 1997/05/02 02:45:51 sra
|
||||
* Support NIT in promiscuous mode, for IPv6 multicast.
|
||||
*
|
||||
* Revision 2.4 1997/03/20 06:53:00 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.3 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.2 1997/02/19 08:10:29 sra
|
||||
* More fun merging snmptalk into snark, general snark cleanup.
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.3 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.2 1994/09/04 06:13:38 sra
|
||||
* Clean up antique type names and install macros.
|
||||
*
|
||||
* Revision 1.1 1994/01/09 23:57:29 sra
|
||||
* Add support for NIT under SunOS 4.1.2.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Attache code for interfacing to ethernet via the Network Interface Tap
|
||||
* on SunOS 4.1.2.
|
||||
*
|
||||
* This file contains the Attache driver code for NIT.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/ether.h>
|
||||
#include <wrn/wm/attache/arp.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include <wrn/wm/util/layout/ldbglue.h>
|
||||
#include <wrn/wm/util/layout/arp.h>
|
||||
|
||||
#include <wrn/wm/demo/nit.h>
|
||||
#include <wrn/wm/demo/bsdif.h>
|
||||
#include <wrn/wm/demo/nitdrive.h>
|
||||
|
||||
struct nit_driver_private {
|
||||
bits8_t mac[6]; /* MAC address for this interface */
|
||||
};
|
||||
|
||||
#define TEN_MEGABITS 10000000
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Routines to read (struct bsdif) generic network interface.
|
||||
*/
|
||||
|
||||
static void nit_driver_rcv
|
||||
(unsigned char *buffer,
|
||||
unsigned buflen,
|
||||
unsigned netlen,
|
||||
void *cookie)
|
||||
{
|
||||
packet *p;
|
||||
|
||||
if (buflen != netlen || (p = pkt_alloc(buflen + 2)) == 0)
|
||||
return;
|
||||
MEMCPY((p->pkt_data += 2), buffer, (p->pkt_datalen = buflen));
|
||||
p->pkt_n = cookie;
|
||||
et_rcv(p);
|
||||
}
|
||||
|
||||
static void nit_driver_read (int fd, void *cookie, unsigned flags)
|
||||
{
|
||||
struct net *net = cookie;
|
||||
if ((net->flags & NF_DRIVER_DOWN) == 0 && (flags & BSDIF_READ) != 0)
|
||||
(void) nit_read(fd, net->driver->maxlen, nit_driver_rcv, net);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Attache device driver routines for NIT.
|
||||
*/
|
||||
|
||||
static void nit_driver_init (struct net *net)
|
||||
{
|
||||
/* This prefix is from "obsolete" portion of DEC's space (see RFC-1340). */
|
||||
static bits8_t nit_driver_mac_prefix[3] = { 0xAA, 0x00, 0x00 };
|
||||
struct bsdif *bif = net->specific;
|
||||
struct nit_driver_private *private;
|
||||
char *name = net->s_name + STRLEN(net->driver->prefix);
|
||||
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
net->speed = TEN_MEGABITS;
|
||||
|
||||
if ((bif->private = private = GLUE_ALLOC(sizeof(*private))) == 0)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Pick a MAC address to use. If there's already one specified,
|
||||
* use it. Otherwise, if we're in 2.x backwards compatability mode and have
|
||||
* an IP address, use it, otherwise try to generate something unique.
|
||||
*/
|
||||
if (!net->h_address) {
|
||||
net->ha_len = sizeof(private->mac);
|
||||
net->h_address = private->mac;
|
||||
MEMCPY(private->mac+0, nit_driver_mac_prefix, 3);
|
||||
if (net->ip_addr) {
|
||||
MEMCPY(private->mac + 3, ((bits8_t *) &net->ip_addr) + 1, 3);
|
||||
} else {
|
||||
extern int gethostid(void);
|
||||
|
||||
pid_t proc = getpid();
|
||||
bits32_t hostid = gethostid();
|
||||
private->mac[3] = (bits8_t) (proc & 0xff);
|
||||
private->mac[4] = (bits8_t) (proc >> 8 & 0xff);
|
||||
private->mac[5] = (bits8_t) (hostid & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
if ((bif->fd = nit_open(name, net->driver->maxlen, private->mac)) < 0)
|
||||
return;
|
||||
|
||||
bif->handler = nit_driver_read;
|
||||
bif->flags |= BSDIF_READ;
|
||||
net->flags &= ~NF_DRIVER_DOWN;
|
||||
}
|
||||
|
||||
static void nit_driver_send (struct packet *p)
|
||||
{
|
||||
struct bsdif *bif = p->pkt_n->specific;
|
||||
|
||||
/*
|
||||
* Send the packet, logging any error that might occur.
|
||||
* If the driver is down, just drop the packet.
|
||||
*/
|
||||
if ((p->pkt_n->flags & NF_DRIVER_DOWN) == 0 &&
|
||||
nit_write(bif->fd, p->pkt_data, p->pkt_datalen) < 0)
|
||||
perror("NIT write() failure");
|
||||
pkt_free(p);
|
||||
}
|
||||
|
||||
static void nit_driver_close (struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
|
||||
if ((net->flags & NF_DRIVER_DOWN) == 0) {
|
||||
nit_close(bif->fd);
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
}
|
||||
if (bif->private) {
|
||||
GLUE_FREE(bif->private);
|
||||
bif->private = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This could be static now, but it might be useful to leave it visible.
|
||||
*/
|
||||
|
||||
struct driver nit_driver = {
|
||||
nit_driver_init, /* Interface initialization routine */
|
||||
nit_driver_send, /* Raw packet send routine */
|
||||
#if INSTALL_ATTACHE_34_IPV4_API_COMPAT
|
||||
et_ip_send, /* IP packet send encapsulation routine */
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
et_arp_send, /* ARP packet send encapsulation routine */
|
||||
0, /* Test routine (unused) */
|
||||
nit_driver_close, /* Interface close routine */
|
||||
"nit", /* Driver short name */
|
||||
"Network Interface Tap Ethernet", /* Driver long name */
|
||||
14, /* Local net header length */
|
||||
0, /* Local net trailer length */
|
||||
1514, /* Ethernet frame size */
|
||||
IF_ETHERNET, /* MIB type of interfaces using this driver */
|
||||
ARP_HEADER_HARDWARE_TYPE_is_ETHERNET,
|
||||
#if !INSTALL_ATTACHE_ETHERNET_NO_MEDIA_CTL
|
||||
et_media_ctl, /* Media control routine, if installed */
|
||||
#else
|
||||
0, /* No media_ctl routine */
|
||||
#endif /* !INSTALL_ATTACHE_ETHERNET_NO_MEDIA_CTL */
|
||||
#if INSTALL_ATTACHE_IPV6
|
||||
et_ipv6_send, /* IPv6 send routine, if installed */
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
#if INSTALL_ATTACHE_IPV4
|
||||
et_ipv4_send /* IPv4 send routine, if installed */
|
||||
#else
|
||||
0
|
||||
#endif /* INSTALL_ATTACHE_IPV4 */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Routines for finding NIT interface devices.
|
||||
* This is just a wrapper to add the Attache-specific things onto nit_find().
|
||||
*/
|
||||
|
||||
struct nit_driver_find_state {
|
||||
void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t);
|
||||
int instance;
|
||||
};
|
||||
|
||||
static void nit_driver_find_one(char *name, void *cookie)
|
||||
{
|
||||
struct nit_driver_find_state *state = cookie;
|
||||
state->config(name, &nit_driver, state->instance++, NF_ARP,
|
||||
nit_driver.maxlen - nit_driver.lnh - nit_driver.lnt,
|
||||
TEN_MEGABITS);
|
||||
}
|
||||
|
||||
void nit_driver_find
|
||||
(void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t))
|
||||
{
|
||||
struct nit_driver_find_state state;
|
||||
state.config = config;
|
||||
state.instance = 0;
|
||||
nit_find(nit_driver_find_one, &state);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,109 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/nvviews.c,v 1.3 2003/01/15 14:04:33 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1995-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: nvviews.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:33 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:24 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:42 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 7.9 2001/01/19 22:23:47 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 7.8 2000/03/17 00:12:42 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 7.7 1998/06/18 04:18:37 sar
|
||||
* Update the view indexes to match the new structure
|
||||
*
|
||||
* Revision 7.6 1998/05/23 18:35:23 sar
|
||||
* Added an installation for rfc2275 as well as rfc1445
|
||||
*
|
||||
* Revision 7.5 1998/02/25 04:58:00 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 7.4 1997/03/20 06:53:52 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 7.3 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 7.2 1997/01/08 23:26:53 sar
|
||||
* Updated include files to use envoy/h as appropriate after
|
||||
* move from envoy/utils to snark/snmptalk
|
||||
*
|
||||
* Revision 7.1 1997/01/08 01:58:11 sar
|
||||
* Removed no_pp stuff and updated copyrights
|
||||
*
|
||||
* Revision 7.0 1996/03/18 20:19:20 sar
|
||||
* Updated rev to 7.0 and copyright to 96
|
||||
*
|
||||
* Revision 1.1 1995/11/11 00:09:41 sar
|
||||
* Initial revision
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/snmp/engine/asn1conf.h>
|
||||
|
||||
#if INSTALL_ENVOY_SNMP_DYNAMIC_VIEWS
|
||||
#include <wrn/wm/snmp/engine/view.h>
|
||||
|
||||
extern VIEWINDEX_T vindex1;
|
||||
extern VIEWINDEX_T vindex2;
|
||||
|
||||
/* viewleaf_t = index, subtree, mask, type, status, storage,
|
||||
lexinext, masknext */
|
||||
static OIDC_T oid_1_1[] = {1, 3, 6};
|
||||
static OIDC_T oid_2_1[] = {1, 3, 6, 1, 2, 1, 1};
|
||||
|
||||
static VIEWLEAF_T vleaf1_1 = {&vindex1, 1, {3, oid_1_1}, {0, 0, 0, 0}, 1, 1, 3, 0, 0};
|
||||
static VIEWLEAF_T vleaf2_1 = {&vindex2, 2, {7, oid_2_1}, {0, 0, 0, 0}, 1, 1, 3, 0, 0};
|
||||
|
||||
#if (INSTALL_ENVOY_SNMP_RFC1445_VIEWS)
|
||||
/* viewindex_t = index, next viewindex, lexi leaves, mask leaves, quickmask */
|
||||
static VIEWINDEX_T vindex2 = {2, 0, &vleaf2_1, &vleaf2_1};
|
||||
static VIEWINDEX_T vindex1 = {1, &vindex2, &vleaf1_1, &vleaf1_1};
|
||||
#endif
|
||||
|
||||
#if (INSTALL_ENVOY_SNMP_RFC2275_VIEWS)
|
||||
/* viewindex_t = name, next viewindex, lexi leaves, mask leaves, quickmask */
|
||||
static bits8_t vone[] = "one";
|
||||
static bits8_t vtwo[] = "two";
|
||||
|
||||
static VIEWINDEX_T vindex2 = {vtwo, 3, 0, &vleaf2_1, &vleaf2_1};
|
||||
static VIEWINDEX_T vindex1 = {vone, 3, &vindex2, &vleaf1_1, &vleaf1_1};
|
||||
|
||||
#endif
|
||||
|
||||
VIEWINDEX_T *precomp_viewroot = &vindex1;
|
||||
#endif
|
||||
@@ -0,0 +1,128 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/parse.c,v 1.2 2001/11/08 15:56:24 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: parse.c,v $
|
||||
* Revision 1.2 2001/11/08 15:56:24 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:42 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.7 2001/01/19 22:23:48 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.6 2000/03/17 00:12:42 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.5 1999/04/26 19:05:01 sra
|
||||
* Fix a few minor warnings, fix a few Solaris-specific problems in the
|
||||
* demo code.
|
||||
*
|
||||
* Revision 2.4 1998/02/25 04:57:29 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.3 1997/03/20 06:53:02 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.2 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.3 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.2 1993/07/29 04:28:22 sra
|
||||
* Add copyright notice.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* This is a hacked up version of Bridgham's parse_line() function.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <wrn/wm/demo/parse.h>
|
||||
|
||||
/*
|
||||
* Backslash handling. Generates one character, shuffles
|
||||
* remaining string down appropriately to close up.
|
||||
*/
|
||||
|
||||
static void backslash(register char *p1)
|
||||
{
|
||||
register char *p2 = p1 + 1;
|
||||
if (*p2 >= '0' && *p2 <= '9') { /* octal digits */
|
||||
*p1 = (char) (*p2++ - '0');
|
||||
while (p2 <= p1 + 3 && *p2 >= '0' && *p2 <= '9')
|
||||
*p1 = (char) ((*p1 * 8) + (*p2++ - '0'));
|
||||
p1++;
|
||||
} else switch (*p2) {
|
||||
case 'a': *p2 = '\007'; break; /* bell */
|
||||
case 'b': *p2 = '\010'; break; /* backspace */
|
||||
case 'e': *p2 = '\033'; break; /* escape */
|
||||
case 'f': *p2 = '\014'; break; /* formfeed */
|
||||
case 'n': *p2 = '\012'; break; /* linefeed */
|
||||
case 'r': *p2 = '\015'; break; /* carriage return */
|
||||
case 't': *p2 = '\011'; break; /* tab */
|
||||
}
|
||||
while ((*p1++ = *p2++) != '\0'); /* and copy the line down */
|
||||
}
|
||||
|
||||
/*
|
||||
* Parses a line into argc and argv, returns argc.
|
||||
* Doublequote and backslash do the obvious quoting things.
|
||||
*/
|
||||
|
||||
int parse_line(char *line, char *argv[], int max_args)
|
||||
{
|
||||
int argc = 0, quoting = 0;
|
||||
for (;;) {
|
||||
while (isspace((int) *line))
|
||||
line++;
|
||||
switch (*line) {
|
||||
case '\0': return argc;
|
||||
case '\"': quoting = 1; line++; break;
|
||||
}
|
||||
if (argc >= max_args)
|
||||
return -1;
|
||||
argv[argc++] = line;
|
||||
while (quoting || !isspace((int) *line))
|
||||
switch (*line) {
|
||||
case '\0': return (quoting ? -1 : argc);
|
||||
case '\"': quoting = 0; *line = ' '; continue;
|
||||
case '\\': backslash(line); line++; continue;
|
||||
default: line++; continue;
|
||||
}
|
||||
*line++ = '\0';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/pktd.c,v 1.3 2003/01/15 14:04:33 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1992-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
*****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: pktd.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:33 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:24 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:42 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.10 2001/01/19 22:23:48 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.9 2000/03/17 00:12:42 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.8 1998/09/04 04:00:09 sar
|
||||
* modified some #if statements to use #ifdef as they were testing
|
||||
* items that might not be defined - INSTALL_on_* options.
|
||||
*
|
||||
* Revision 2.7 1998/02/25 04:57:30 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.6 1998/02/20 23:07:23 sra
|
||||
* Add multicast and IPv6 support.
|
||||
*
|
||||
* Revision 2.5 1998/02/19 07:46:08 sra
|
||||
* Preliminary multicast support.
|
||||
*
|
||||
* Revision 2.4 1997/03/20 06:53:02 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.3 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.2 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.1 1996/03/14 16:34:57 dab
|
||||
* Workaround for bug in Xircom packet drivers.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.6 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.5 1993/08/03 01:28:42 sra
|
||||
* Different install option for MSC.
|
||||
*
|
||||
* Revision 1.4 1993/07/31 02:01:16 sra
|
||||
* Flush boolean_t from this file.
|
||||
*
|
||||
* Revision 1.3 1993/07/31 01:28:33 sra
|
||||
* Get automatic compiler configuration stuff right this time.
|
||||
*
|
||||
* Revision 1.2 1993/07/31 00:53:55 sra
|
||||
* Changes for Borland C++ 3.1.
|
||||
*
|
||||
* Revision 1.1 1993/07/30 02:41:24 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Low-level interface routines to FTP Software spec packet driver.
|
||||
* This is DAB's pkt.c with very minor cosmetic changes.
|
||||
*
|
||||
* The modularity here is not yet quite what I had in mind, I'd prefer
|
||||
* to move all knowledge of Attache and Snark out of this file, leaving
|
||||
* nothing but packet driver stuff; the Attache/Snark stuff should all be
|
||||
* in pktdrive.c. But we've got a deadline to make, and it's not too bad
|
||||
* as it stands, so this will be left for a future version of this code.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Stuff to configure us for a particular DOS compiler (BCC, MSC, whatever).
|
||||
*/
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
|
||||
#ifdef INSTALL_on_microsoft
|
||||
#include <wrn/wm/demo/pktd_msc.h>
|
||||
#endif
|
||||
|
||||
#ifdef INSTALL_on_bcc
|
||||
#include <wrn/wm/demo/pktd_bcc.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Definitions for this module.
|
||||
*/
|
||||
|
||||
#include <wrn/wm/demo/pktd.h>
|
||||
|
||||
/*
|
||||
* Error codes from packet drivers.
|
||||
*/
|
||||
static char *pd_error_strings[] = {
|
||||
"no error",
|
||||
"bad handle",
|
||||
"no class",
|
||||
"no type",
|
||||
"no number",
|
||||
"bad type",
|
||||
"no multicast",
|
||||
"can't terminate",
|
||||
"bad mode",
|
||||
"no space",
|
||||
"type in use",
|
||||
"bad command",
|
||||
"can't send",
|
||||
};
|
||||
|
||||
char *pd_perror(int err)
|
||||
{
|
||||
if (err >= 0 && err < sizeof(pd_error_strings)/sizeof(*pd_error_strings))
|
||||
return pd_error_strings[err];
|
||||
else if (err == PDE_NO_PKT_DRVR)
|
||||
return "no packet driver";
|
||||
else
|
||||
return "unknown error";
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns non-zero if pd_int looks like a packet driver interrupt.
|
||||
*/
|
||||
#define DOSGETVECTOR 0x35
|
||||
|
||||
int pd_check_int(int pd_int)
|
||||
{
|
||||
union REGS r;
|
||||
struct SREGS sr;
|
||||
unsigned char far *fcp;
|
||||
static char word_pkt[] = "PKT ", word_drvr[] = "DRVR";
|
||||
unsigned long *wordp;
|
||||
unsigned long far *wordfp;
|
||||
|
||||
if (pd_int < PKTDRVR_MIN_INT || pd_int > PKTDRVR_MAX_INT)
|
||||
return 0;
|
||||
|
||||
r.h.ah = DOSGETVECTOR;
|
||||
r.h.al = (unsigned char) pd_int;
|
||||
intdosx(&r, &r, &sr);
|
||||
|
||||
if ((fcp = MK_FP(sr.es, r.x.bx)) == 0 || (*fcp != 0xe9 && *fcp != 0xeb))
|
||||
return 0;
|
||||
|
||||
wordfp = (unsigned long far *) (fcp + 3);
|
||||
wordp = (unsigned long *) word_pkt;
|
||||
if (*wordfp != *wordp)
|
||||
return 0;
|
||||
|
||||
wordfp = (unsigned long far *) (fcp + 7);
|
||||
wordp = (unsigned long *) word_drvr;
|
||||
if (*wordfp != *wordp)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the packet driver information, fills in driver information in pd_net.
|
||||
* Returns PDE_NO_ERROR if successful, otherwise a packet driver error code.
|
||||
*/
|
||||
int pd_driver_info(int handle, struct pd_net *pdn)
|
||||
{
|
||||
union REGS r;
|
||||
struct SREGS sr;
|
||||
|
||||
r.h.ah = PF_DRIVER_INFO;
|
||||
r.h.al = 255;
|
||||
int86x(pdn->pd_int, &r, &r, &sr);
|
||||
if (r.x.cflag) /* if error return */
|
||||
return r.h.dh;
|
||||
|
||||
#if 0
|
||||
/* the Xircom packet driver doesn't do this right. */
|
||||
if (r.h.ah == 255) /* if no packet driver loaded */
|
||||
return PDE_NO_PKT_DRVR;
|
||||
#endif
|
||||
|
||||
pdn->drvr_info.version = r.x.bx;
|
||||
pdn->drvr_info.pdtype = r.x.dx;
|
||||
pdn->drvr_info.class = r.h.ch;
|
||||
pdn->drvr_info.number = r.h.cl;
|
||||
pdn->drvr_info.name = MK_FP(sr.ds, r.x.si);
|
||||
pdn->drvr_info.basic_flag = r.h.al;
|
||||
|
||||
return PDE_NO_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calls the packet driver to pick up packets of type type. Returns a
|
||||
* packet driver error code. The handle is stored in *handle if no error.
|
||||
*/
|
||||
int pd_access_type
|
||||
(struct pd_net *pdn,
|
||||
int *handle,
|
||||
unsigned char far *type_field,
|
||||
int type_len)
|
||||
{
|
||||
union REGS r;
|
||||
struct SREGS sr;
|
||||
|
||||
r.h.ah = PF_ACCESS_TYPE;
|
||||
r.h.al = pdn->drvr_info.class;
|
||||
r.x.bx = pdn->drvr_info.pdtype;
|
||||
r.h.dl = pdn->drvr_info.number;
|
||||
sr.ds = FP_SEG(type_field);
|
||||
r.x.si = FP_OFF(type_field);
|
||||
r.x.cx = type_len;
|
||||
sr.es = FP_SEG(pdn->device_receive_rtn);
|
||||
r.x.di = FP_OFF(pdn->device_receive_rtn);
|
||||
int86x(pdn->pd_int, &r, &r, &sr);
|
||||
|
||||
if (r.x.cflag)
|
||||
return r.h.dh; /* error code */
|
||||
|
||||
*handle = r.x.ax;
|
||||
return PDE_NO_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calls the packet driver to stop getting packets of type type. Returns a
|
||||
* packet driver error code.
|
||||
*/
|
||||
int pd_release_type(struct pd_net *pdn, int handle)
|
||||
{
|
||||
union REGS r;
|
||||
struct SREGS sr;
|
||||
|
||||
r.h.ah = PF_RELEASE_TYPE;
|
||||
r.x.bx = handle;
|
||||
int86x(pdn->pd_int, &r, &r, &sr);
|
||||
|
||||
if (r.x.cflag)
|
||||
return r.h.dh; /* error code */
|
||||
return PDE_NO_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calls the packet driver to get the mac addrss of this interface.
|
||||
* Returns a packet driver error code.
|
||||
*/
|
||||
int pd_get_address
|
||||
(struct pd_net *pdn,
|
||||
unsigned char far *address_buffer,
|
||||
int buffer_length)
|
||||
{
|
||||
union REGS r;
|
||||
struct SREGS sr;
|
||||
|
||||
r.h.ah = PF_GET_ADDRESS;
|
||||
r.x.bx = pdn->handle;
|
||||
r.x.cx = buffer_length;
|
||||
sr.es = FP_SEG(address_buffer);
|
||||
r.x.di = FP_OFF(address_buffer);
|
||||
int86x(pdn->pd_int, &r, &r, &sr);
|
||||
|
||||
if (r.x.cflag)
|
||||
return r.h.dh; /* error code */
|
||||
|
||||
return PDE_NO_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calls the packet driver to send a packet.
|
||||
* Returns a packet driver error code.
|
||||
*/
|
||||
int pd_send_pkt
|
||||
(struct pd_net *pdn,
|
||||
unsigned char far *address_buffer,
|
||||
unsigned int buffer_length)
|
||||
{
|
||||
union REGS r;
|
||||
struct SREGS sr;
|
||||
|
||||
r.h.ah = PF_SEND_PKT;
|
||||
r.x.cx = buffer_length;
|
||||
sr.ds = FP_SEG(address_buffer);
|
||||
r.x.si = FP_OFF(address_buffer);
|
||||
int86x(pdn->pd_int, &r, &r, &sr);
|
||||
|
||||
if (r.x.cflag)
|
||||
return r.h.dh; /* error code */
|
||||
|
||||
return PDE_NO_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* Calls the packet driver to get the current receive mode, stores that
|
||||
* in *mode on success. Returns a packet driver error code.
|
||||
*/
|
||||
int pd_get_rcv_mode(struct pd_net *pdn, int *mode)
|
||||
{
|
||||
union REGS r;
|
||||
struct SREGS sr;
|
||||
|
||||
r.h.ah = PF_GET_RCV_MODE;
|
||||
r.x.bx = pdn->handle;
|
||||
int86x(pdn->pd_int, &r, &r, &sr);
|
||||
|
||||
if (r.x.cflag)
|
||||
return r.h.dh; /* error code */
|
||||
|
||||
*mode = r.x.ax;
|
||||
return PDE_NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Calls the packet driver to set the current mode.
|
||||
* Returns a packet driver error code.
|
||||
*/
|
||||
int pd_set_rcv_mode(struct pd_net *pdn, int mode)
|
||||
{
|
||||
union REGS r;
|
||||
struct SREGS sr;
|
||||
|
||||
r.h.ah = PF_SET_RCV_MODE;
|
||||
r.x.bx = pdn->handle;
|
||||
r.x.cx = mode;
|
||||
int86x(pdn->pd_int, &r, &r, &sr);
|
||||
|
||||
if (r.x.cflag)
|
||||
return r.h.dh; /* error code */
|
||||
|
||||
return PDE_NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,909 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/pktdrive.c,v 1.4 2003/01/15 14:04:33 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
*****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: pktdrive.c,v $
|
||||
* Revision 1.4 2003/01/15 14:04:33 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.3 2001/11/08 15:56:24 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.2 2001/11/06 20:11:12 josh
|
||||
* updating include paths to include proper path to layout directory
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:42 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.22 2001/01/19 22:23:49 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.21 2000/10/20 18:32:25 paul
|
||||
* Properly conditionalized driver.ip_send
|
||||
*
|
||||
* Revision 2.20 2000/10/16 19:21:54 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 2.19 2000/03/17 00:12:43 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.18 2000/03/13 21:22:07 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 2.17 1999/11/05 22:29:06 paul
|
||||
* Updated driver structs to reflect conditional backwards-compatibility
|
||||
* fields and new fields.
|
||||
*
|
||||
* Revision 2.16 1998/09/04 04:00:10 sar
|
||||
* modified some #if statements to use #ifdef as they were testing
|
||||
* items that might not be defined - INSTALL_on_* options.
|
||||
*
|
||||
* Revision 2.15 1998/06/11 17:35:49 sra
|
||||
* Use et_media_ctl() if it's installed.
|
||||
*
|
||||
* Revision 2.14 1998/02/25 15:21:48 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 2.13 1998/02/25 04:57:32 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.12 1998/02/20 23:07:24 sra
|
||||
* Add multicast and IPv6 support.
|
||||
*
|
||||
* Revision 2.11 1998/02/19 07:46:10 sra
|
||||
* Preliminary multicast support.
|
||||
*
|
||||
* Revision 2.10 1997/07/01 02:23:00 mrf
|
||||
* packet drivers still need packet types byteswapped.
|
||||
*
|
||||
* Revision 2.9 1997/05/22 03:39:16 sra
|
||||
* Don't depend on ancient NF_DOWN kludge in if_attach().
|
||||
*
|
||||
* Revision 2.8 1997/05/20 02:21:47 mrf
|
||||
* make snark lib driver code use new ldb arp definitions
|
||||
*
|
||||
* Revision 2.7 1997/05/07 17:23:36 mrf
|
||||
* move ipv6_send function to end of net_if structure
|
||||
*
|
||||
* Revision 2.6 1997/03/20 06:53:07 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.5 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.4 1996/10/28 03:31:26 sra
|
||||
* More BCC warnings.
|
||||
*
|
||||
* Revision 2.3 1996/10/26 17:50:18 sra
|
||||
* More silliness to silence compiler warnings.
|
||||
*
|
||||
* Revision 2.2 1996/10/26 17:43:19 sra
|
||||
* Get rid of some compiler warnings caused by Dave's
|
||||
* PPP-over-SLIP-pktdrv testing hack.
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.10 1995/04/14 21:01:18 sra
|
||||
* Different fix for interface name problem.
|
||||
*
|
||||
* Revision 1.9 1995/04/14 20:21:32 dab
|
||||
* Malloc the right amount of space for net.s_name. This isn't right
|
||||
* with respect to the rest of the packet driver code but it fixes
|
||||
* the bug for now.
|
||||
*
|
||||
* Revision 1.8 1995/03/14 17:57:29 dab
|
||||
* Set the speed in network interface structures.
|
||||
*
|
||||
* Revision 1.7 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.6 1994/12/20 22:40:36 dab
|
||||
* Added code to run the PPP media layer over a SLIP packet driver.
|
||||
*
|
||||
* Revision 1.5 1994/09/04 06:13:38 sra
|
||||
* Clean up antique type names and install macros.
|
||||
*
|
||||
* Revision 1.4 1993/08/03 01:28:51 sra
|
||||
* Different install option for MSC.
|
||||
*
|
||||
* Revision 1.3 1993/07/31 01:43:11 sra
|
||||
* Include appropriate pktd_xxx.h file for current install.h settings.
|
||||
*
|
||||
* Revision 1.2 1993/07/30 22:25:35 sra
|
||||
* Initial working version.
|
||||
*
|
||||
* Revision 1.1 1993/07/30 02:41:24 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Packet driver code for snark under DOS.
|
||||
*
|
||||
* This started life as the attache/pc/pd2/pktdrv.lib library, but it's
|
||||
* been mangled somewhat to make it fit the snark architecture.
|
||||
*/
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/ether.h>
|
||||
#include <wrn/wm/attache/arp.h>
|
||||
#include <wrn/wm/attache/ppp.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include <wrn/wm/util/layout/ldbglue.h>
|
||||
#include <wrn/wm/util/layout/arp.h>
|
||||
#include <wrn/wm/demo/tasks.h>
|
||||
|
||||
#ifdef INSTALL_on_microsoft
|
||||
#include <wrn/wm/demo/pktd_msc.h>
|
||||
#endif
|
||||
|
||||
#ifdef INSTALL_on_bcc
|
||||
#include <wrn/wm/demo/pktd_bcc.h>
|
||||
#endif
|
||||
|
||||
#include <wrn/wm/demo/pktd.h>
|
||||
|
||||
/*
|
||||
* All the packet drivers I tested did ok with their receive modes set to
|
||||
* either 5 (all multicast) or 6 (all packets). For most uses, we want
|
||||
* mode 5, but you might need to override this to mode 6 or mode 3 (normal)
|
||||
* for certain applications.
|
||||
*/
|
||||
|
||||
#ifndef SNARK_PKTD_RCV_MODE
|
||||
#define SNARK_PKTD_RCV_MODE PKT_RCVR_ALL_MCAST
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Monolithic structure to hold everything that we know about a particular
|
||||
* interface. Routines outside this module just deal with sub-structures.
|
||||
*
|
||||
* The pd_net should be the first field, so that we can cast pointers to
|
||||
* it to pointers to the outer structure.
|
||||
*/
|
||||
|
||||
struct pktdif {
|
||||
struct pd_net pdn; /* Interface to packet driver library */
|
||||
struct net net; /* Interface to Attache */
|
||||
struct task task; /* Interface to Snark tasking routines */
|
||||
packet *pkt; /* Packet under construction */
|
||||
packet *pkt_q_head; /* Head of input packet queue */
|
||||
packet **pkt_q_tail; /* Tail of input packet queue */
|
||||
void (*receiver)(packet *); /* Media receive routine */
|
||||
char name[20]; /* Space for short name for interface */
|
||||
bits8_t mac[6]; /* Space for MAC address */
|
||||
int saved_rcv_mode; /* Saved driver receive mode */
|
||||
};
|
||||
|
||||
/*
|
||||
* A pointer for each possible packet driver.
|
||||
*/
|
||||
static struct pd_net *pd_nets[PKTDRVR_MAX_INT - PKTDRVR_MIN_INT + 1];
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Common driver routines for all Attache interfaces using packet drivers.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Initializes an Attache network interface using a packet driver.
|
||||
*/
|
||||
static void pktd_init(struct net *net)
|
||||
{
|
||||
struct pktdif *pif = net->specific;
|
||||
bits16_t type_field;
|
||||
int err;
|
||||
|
||||
if (!net || !pif)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Do class specific initialization
|
||||
*/
|
||||
switch (pif->pdn.drvr_info.class) {
|
||||
|
||||
case IC_ETHERNET:
|
||||
|
||||
/*
|
||||
* Get one handle that will receive any incoming packet type.
|
||||
* We used to use separate handles for IPv4 and ARP, but that
|
||||
* turned out not to work with a lot of packet drivers when we
|
||||
* tried to extend it for IPv6 and multicast. Don't really know
|
||||
* why it failed, but this single-handle-with-null-type is
|
||||
* supported by most drivers because network analyzers use it.
|
||||
* So we go with what works.
|
||||
*/
|
||||
|
||||
if ((err = pd_access_type(&pif->pdn, &pif->pdn.handle,
|
||||
(unsigned char *) 0, 0)) != PDE_NO_ERROR) {
|
||||
printf("Can't set up access via ethernet packet driver %s: %s\n",
|
||||
net->s_name, pd_perror(err));
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Save the current receive mode and put the packet driver into
|
||||
* the mode we want. In most cases, we want mode 5 (unicast to
|
||||
* our MAC address plus all broadcast and all multicast), but you
|
||||
* can change this by redefining SNARK_PKTD_RCV_MODE if necessary.
|
||||
*/
|
||||
if (pif->saved_rcv_mode == -1 &&
|
||||
(err = pd_get_rcv_mode(&pif->pdn,
|
||||
&pif->saved_rcv_mode)) != PDE_NO_ERROR) {
|
||||
printf ("Can't get get receive mode of ethernet packet driver %s: %s\n",
|
||||
net->s_name, pd_perror(err));
|
||||
}
|
||||
else if ((err = pd_set_rcv_mode(&pif->pdn,
|
||||
SNARK_PKTD_RCV_MODE)) != PDE_NO_ERROR) {
|
||||
printf ("Can't set receive mode of ethernet packet driver %s: %s\n",
|
||||
net->s_name, pd_perror(err));
|
||||
}
|
||||
|
||||
/*
|
||||
* Find out our ethernet address, for ARP's benefit.
|
||||
*/
|
||||
net->ha_len = 6;
|
||||
net->h_address = pif->mac;
|
||||
pd_get_address(&pif->pdn, net->h_address, 6);
|
||||
|
||||
break;
|
||||
|
||||
case IC_SERIAL_LINE:
|
||||
|
||||
if ((err = pd_access_type(&pif->pdn, &pif->pdn.handle,
|
||||
0, 0)) != PDE_NO_ERROR) {
|
||||
printf("Can't access IP protocol via serial line packet driver %s: %s\n",
|
||||
net->s_name, pd_perror(err));
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case IC_FPPP:
|
||||
|
||||
type_field = 0x2100;
|
||||
if ((err = pd_access_type(&pif->pdn, &pif->pdn.handle,
|
||||
(unsigned char *) &type_field,
|
||||
sizeof(type_field))) != PDE_NO_ERROR) {
|
||||
printf("Can't access IP protocol via FPPP packet driver %s: %s\n",
|
||||
net->s_name, pd_perror(err));
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Don't know packet driver class %d for packet driver %s\n",
|
||||
pif->pdn.drvr_info.class, net->s_name);
|
||||
return;
|
||||
}
|
||||
|
||||
/* mark this interface as up
|
||||
*/
|
||||
net->flags &= ~NF_DRIVER_DOWN;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Shutdown the packet driver interface
|
||||
*/
|
||||
static void pktd_close(struct net *net)
|
||||
{
|
||||
int err;
|
||||
|
||||
if ((net->flags & NF_DRIVER_DOWN) == 0) {
|
||||
struct pktdif *pif = net->specific;
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
if (pif->pdn.drvr_info.class == IC_ETHERNET &&
|
||||
pif->saved_rcv_mode != -1 &&
|
||||
(err = pd_set_rcv_mode(&pif->pdn,
|
||||
pif->saved_rcv_mode)) != PDE_NO_ERROR) {
|
||||
printf ("Can't restore receive mode of ethernet packet driver %s: %s\n",
|
||||
net->s_name, pd_perror(err));
|
||||
}
|
||||
pd_release_type(&pif->pdn, pif->pdn.handle);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a packet, just hand it off to the packet driver.
|
||||
*/
|
||||
static void pktd_send(packet *p)
|
||||
{
|
||||
struct pktdif *pif = p->pkt_n->specific;
|
||||
pd_send_pkt(&pif->pdn, p->pkt_data, p->pkt_datalen);
|
||||
pkt_free(p);
|
||||
}
|
||||
|
||||
/*
|
||||
* Take a packet off an interface's input queue, pass it along
|
||||
* to the appropriate routine. Arrange for this to happen again
|
||||
* if there are more packets queued.
|
||||
*
|
||||
* This is the main-program-level part of the packet receive logic.
|
||||
*/
|
||||
static void pktd_handler(struct task *task, void *cookie)
|
||||
{
|
||||
struct pktdif *pif = cookie;
|
||||
packet *pkt = 0;
|
||||
int lock;
|
||||
|
||||
/*
|
||||
* Pull off the next packet on the queue. We have to lock out interrupts
|
||||
* while we're doing this to avoid trashing the queue, so keep this short.
|
||||
*/
|
||||
lock = glue_intlock(0);
|
||||
if ((pkt = pif->pkt_q_head) != 0 && (pif->pkt_q_head = pkt->pkt_link) == 0)
|
||||
pif->pkt_q_tail = &pif->pkt_q_head;
|
||||
glue_intlock(lock);
|
||||
|
||||
/*
|
||||
* If we didn't get a packet, we're done.
|
||||
*/
|
||||
if (!pkt)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Got a packet. If there's a receiver, hand it up, otherwise punt it.
|
||||
*/
|
||||
if (pif->receiver)
|
||||
(*pif->receiver)(pkt);
|
||||
else
|
||||
pkt_free(pkt);
|
||||
|
||||
/*
|
||||
* Run self again to check for another packet.
|
||||
*/
|
||||
task_enq(task);
|
||||
}
|
||||
|
||||
/*
|
||||
* Packet driver receive upcalls come together here. Each received packet
|
||||
* gets two upcalls, the first one gets the packet and the second delivers
|
||||
* the data. Since we're running at interrupt level, we don't try to give
|
||||
* the packet to Attache; instead we schedule a task to run at main program
|
||||
* level which will do it for us.
|
||||
*/
|
||||
static unsigned char far *pktd_receive
|
||||
(struct saveregs far *r,
|
||||
struct pd_net *pd_net)
|
||||
{
|
||||
struct pktdif *pif = (struct pktdif *) pd_net;
|
||||
int extra;
|
||||
|
||||
if (r->ax != 0) {
|
||||
|
||||
/*
|
||||
* Second upcall we queue the packet buffer.
|
||||
* Schedule our task to run at main program level to handle the packet(s).
|
||||
*/
|
||||
pif->pkt->pkt_link = 0;
|
||||
*pif->pkt_q_tail = pif->pkt;
|
||||
pif->pkt_q_tail = &pif->pkt->pkt_link;
|
||||
pif->pkt = 0;
|
||||
task_enq(&pif->task);
|
||||
|
||||
} else {
|
||||
|
||||
/*
|
||||
* First upcall we allocate and return the packet buffer
|
||||
*/
|
||||
|
||||
/*
|
||||
* Sanity check the requested length
|
||||
*/
|
||||
if (r->cx != 0) {
|
||||
|
||||
/*
|
||||
* Leave space at the front of the packet in case this packet
|
||||
* is forwarded out any networks with larger headers than this one
|
||||
*/
|
||||
extra = MaxLnh - pif->net.driver->lnh;
|
||||
|
||||
/*
|
||||
* Get the packet buffer
|
||||
*/
|
||||
pif->pkt = pkt_alloc(r->cx + extra);
|
||||
if (pif->pkt != 0) {
|
||||
|
||||
/*
|
||||
* Initialize packet buffer
|
||||
*/
|
||||
pif->pkt->pkt_datalen = r->cx;
|
||||
pif->pkt->pkt_data = pif->pkt->pkt_buffer + extra;
|
||||
pif->pkt->pkt_n = &pif->net;
|
||||
|
||||
return (unsigned char far *) (pif->pkt->pkt_data);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Routines specific to the fake PPP layer used by the Niwot packet driver.
|
||||
* Does nothing but add two bytes of type field at the front of the packet.
|
||||
*
|
||||
* The magic type code is byte[0] = 0x00, byte[1] = 0x21.
|
||||
* This was determined empirically.
|
||||
*
|
||||
* We don't know (or really care) who came up with this silliness, it's not
|
||||
* a particularly bad idea, it's just not PPP and shouldn't be called that.
|
||||
*/
|
||||
|
||||
/* Receive a fake PPP packet; update the MIB counters and hand it up to IP. */
|
||||
static void fppp_rcv(struct packet *p)
|
||||
{
|
||||
bits16_t pkt_type;
|
||||
|
||||
#if INSTALL_ATTACHE_MIB
|
||||
p->pkt_n->ifInOctets += p->pkt_datalen;
|
||||
#endif
|
||||
MIB_COUNTER_INC(p->pkt_n->ifInUcastPkts);
|
||||
|
||||
/* pull out the type field */
|
||||
if (p->pkt_datalen < 2) {
|
||||
MIB_COUNTER_INC(p->pkt_n->ifInErrors);
|
||||
pkt_free(p);
|
||||
return;
|
||||
}
|
||||
pkt_type = p->pkt_data[0] << 8;
|
||||
pkt_type |= p->pkt_data[1];
|
||||
p->pkt_data += 2;
|
||||
p->pkt_datalen -= 2;
|
||||
|
||||
/* hand the packet up to the next layer */
|
||||
if (pkt_type == 0x0021) {
|
||||
ip_rcv(p);
|
||||
} else {
|
||||
MIB_COUNTER_INC(p->pkt_n->ifInUnknownProtos);
|
||||
pkt_free(p);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Send an IP packet; put in the type field, update the MIB counters
|
||||
* and hand it off to the packet driver as a fake PPP packet.
|
||||
*/
|
||||
static void fppp_ip_send(struct net *net, struct packet *p, inaddr_t dest)
|
||||
{
|
||||
p->pkt_n = net;
|
||||
|
||||
/* make space for the type field */
|
||||
p->pkt_data -= 2;
|
||||
if (p->pkt_data < p->pkt_buffer) {
|
||||
/* If this happens then things are bad */
|
||||
pkt_free(p);
|
||||
return;
|
||||
}
|
||||
p->pkt_datalen += 2;
|
||||
|
||||
/* Type PPP_IP */
|
||||
p->pkt_data[0] = 0;
|
||||
p->pkt_data[1] = 0x21;
|
||||
|
||||
#if INSTALL_ATTACHE_MIB
|
||||
net->ifOutOctets += p->pkt_datalen;
|
||||
#endif
|
||||
MIB_COUNTER_INC(net->ifOutUcastPkts);
|
||||
|
||||
pktd_send(p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if !INSTALL_ATTACHE_PPP || !SNARK_PKTDRV_PPP_OVER_SLIP
|
||||
|
||||
/*
|
||||
* Slip packet driver routines.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Receive a SLIP packet; update the MIB counters and hand it up to IP.
|
||||
*/
|
||||
static void slip_rcv(struct packet *p)
|
||||
{
|
||||
#if INSTALL_ATTACHE_MIB
|
||||
p->pkt_n->ifInOctets += p->pkt_datalen;
|
||||
#endif
|
||||
MIB_COUNTER_INC(p->pkt_n->ifInUcastPkts);
|
||||
|
||||
ip_rcv(p);
|
||||
}
|
||||
|
||||
/*
|
||||
* Send an IP packet; update MIB counters and hand off to packet driver.
|
||||
*/
|
||||
static void slip_ip_send(struct net *net, struct packet *p, inaddr_t dest)
|
||||
{
|
||||
p->pkt_n = net;
|
||||
#if INSTALL_ATTACHE_MIB
|
||||
net->ifOutOctets += p->pkt_datalen;
|
||||
#endif
|
||||
MIB_COUNTER_INC(net->ifOutUcastPkts);
|
||||
|
||||
pktd_send(p);
|
||||
}
|
||||
|
||||
#endif /* !INSTALL_ATTACHE_PPP || !SNARK_PKTDRV_PPP_OVER_SLIP */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Driver interface structures for the various media types we understand
|
||||
* via packet drivers.
|
||||
*/
|
||||
|
||||
/* The ethernet packet driver interface structure */
|
||||
static struct driver pd_ether_driver = {
|
||||
pktd_init,
|
||||
pktd_send,
|
||||
#if INSTALL_ATTACHE_34_IPV4_API_COMPAT
|
||||
et_ip_send,
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
et_arp_send,
|
||||
0, /* test routine */
|
||||
pktd_close,
|
||||
"ether", /* short name */
|
||||
"FTP Software Packet Driver", /* long name */
|
||||
14, /* local net header */
|
||||
0, /* local net trailer */
|
||||
1514, /* MTU */
|
||||
IF_ETHERNET,
|
||||
ARP_HEADER_HARDWARE_TYPE_is_ETHERNET,
|
||||
#if !INSTALL_ATTACHE_ETHERNET_NO_MEDIA_CTL
|
||||
et_media_ctl, /* Media control routine, if installed */
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
#if INSTALL_ATTACHE_IPV6
|
||||
et_ipv6_send, /* IPv6 send routine, if installed */
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
#if INSTALL_ATTACHE_IPV4
|
||||
et_ipv4_send, /* IPv4 send routine, if installed */
|
||||
#else
|
||||
0,
|
||||
#endif /* INSTALL_ATTACHE_IPV4 */
|
||||
};
|
||||
|
||||
/*
|
||||
* The serial line (SLIP) packet driver interface structure.
|
||||
*/
|
||||
#if !INSTALL_ATTACHE_PPP || !SNARK_PKTDRV_PPP_OVER_SLIP
|
||||
static struct driver pd_serial_driver = {
|
||||
pktd_init,
|
||||
pktd_send,
|
||||
slip_ip_send,
|
||||
0, /* arp send */
|
||||
0, /* test routine */
|
||||
pktd_close,
|
||||
"slip", /* short name */
|
||||
"FTP Software Packet Driver", /* long name */
|
||||
0, /* local net header */
|
||||
0, /* local net trailer */
|
||||
1514, /* MTU */
|
||||
IF_SLIP,
|
||||
0, /* arp hardware type */
|
||||
0, /* media control */
|
||||
0, /* IPv6 send */
|
||||
0 /* IPv4 send */
|
||||
};
|
||||
#endif /* !INSTALL_ATTACHE_PPP || !SNARK_PKTDRV_PPP_OVER_SLIP */
|
||||
|
||||
/*
|
||||
* The Point to Point Protocol (PPP) packet driver interface structure.
|
||||
*/
|
||||
#if INSTALL_ATTACHE_PPP && SNARK_PKTDRV_PPP_OVER_SLIP
|
||||
static struct driver pd_ppp_driver = {
|
||||
pktd_init,
|
||||
pktd_send,
|
||||
ppp_ip_send,
|
||||
0, /* arp send */
|
||||
0, /* test routine */
|
||||
pktd_close,
|
||||
"ppp", /* short name */
|
||||
"FTP Software Packet Driver", /* long name */
|
||||
4, /* local net header */
|
||||
0, /* local net trailer */
|
||||
1514, /* MTU */
|
||||
IF_PPP,
|
||||
0, /* arp hardware type */
|
||||
ppp_control, /* media control */
|
||||
0, /* IPv6 send */
|
||||
0 /* IPv4 send */
|
||||
};
|
||||
#endif /* INSTALL_ATTACHE_PPP && SNARK_PKTDRV_PPP_OVER_SLIP */
|
||||
|
||||
/*
|
||||
* The "fake PPP" packet driver interface structure.
|
||||
*/
|
||||
static struct driver pd_fppp_driver = {
|
||||
pktd_init,
|
||||
pktd_send,
|
||||
fppp_ip_send,
|
||||
0, /* arp send */
|
||||
0, /* test routine */
|
||||
pktd_close,
|
||||
"fppp", /* short name */
|
||||
"FTP Software Packet Driver", /* long name */
|
||||
0, /* local net header */
|
||||
0, /* local net trailer */
|
||||
1514, /* MTU */
|
||||
IF_PPP,
|
||||
0, /* arp hardware type */
|
||||
0, /* media control */
|
||||
0, /* IPv6 send */
|
||||
0 /* IPv4 send */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* The packet receive routines. We have several instances of essentially the
|
||||
* same routine because the only information we have about which packet driver
|
||||
* is calling us is given by which routine is called. Closures would be nice.
|
||||
* The macro that produces this routine is defined in system.h. I'll have to
|
||||
* come up with something else for those C compilers which can't generate such
|
||||
* a routine from C source and needs assembly language instead.
|
||||
*/
|
||||
|
||||
PD_UPCALL(pktd_receive60, pd_nets[0x00], pktd_receive)
|
||||
PD_UPCALL(pktd_receive61, pd_nets[0x01], pktd_receive)
|
||||
PD_UPCALL(pktd_receive62, pd_nets[0x02], pktd_receive)
|
||||
PD_UPCALL(pktd_receive63, pd_nets[0x03], pktd_receive)
|
||||
PD_UPCALL(pktd_receive64, pd_nets[0x04], pktd_receive)
|
||||
PD_UPCALL(pktd_receive65, pd_nets[0x05], pktd_receive)
|
||||
PD_UPCALL(pktd_receive66, pd_nets[0x06], pktd_receive)
|
||||
PD_UPCALL(pktd_receive67, pd_nets[0x07], pktd_receive)
|
||||
PD_UPCALL(pktd_receive68, pd_nets[0x08], pktd_receive)
|
||||
PD_UPCALL(pktd_receive69, pd_nets[0x09], pktd_receive)
|
||||
PD_UPCALL(pktd_receive6a, pd_nets[0x0a], pktd_receive)
|
||||
PD_UPCALL(pktd_receive6b, pd_nets[0x0b], pktd_receive)
|
||||
PD_UPCALL(pktd_receive6c, pd_nets[0x0c], pktd_receive)
|
||||
PD_UPCALL(pktd_receive6d, pd_nets[0x0d], pktd_receive)
|
||||
PD_UPCALL(pktd_receive6e, pd_nets[0x0e], pktd_receive)
|
||||
PD_UPCALL(pktd_receive6f, pd_nets[0x0f], pktd_receive)
|
||||
PD_UPCALL(pktd_receive70, pd_nets[0x10], pktd_receive)
|
||||
PD_UPCALL(pktd_receive71, pd_nets[0x11], pktd_receive)
|
||||
PD_UPCALL(pktd_receive72, pd_nets[0x12], pktd_receive)
|
||||
PD_UPCALL(pktd_receive73, pd_nets[0x13], pktd_receive)
|
||||
PD_UPCALL(pktd_receive74, pd_nets[0x14], pktd_receive)
|
||||
PD_UPCALL(pktd_receive75, pd_nets[0x15], pktd_receive)
|
||||
PD_UPCALL(pktd_receive76, pd_nets[0x16], pktd_receive)
|
||||
PD_UPCALL(pktd_receive77, pd_nets[0x17], pktd_receive)
|
||||
PD_UPCALL(pktd_receive78, pd_nets[0x18], pktd_receive)
|
||||
PD_UPCALL(pktd_receive79, pd_nets[0x19], pktd_receive)
|
||||
PD_UPCALL(pktd_receive7a, pd_nets[0x1a], pktd_receive)
|
||||
PD_UPCALL(pktd_receive7b, pd_nets[0x1b], pktd_receive)
|
||||
PD_UPCALL(pktd_receive7c, pd_nets[0x1c], pktd_receive)
|
||||
PD_UPCALL(pktd_receive7d, pd_nets[0x1d], pktd_receive)
|
||||
PD_UPCALL(pktd_receive7e, pd_nets[0x1e], pktd_receive)
|
||||
PD_UPCALL(pktd_receive7f, pd_nets[0x1f], pktd_receive)
|
||||
|
||||
/*
|
||||
* Indexed by packet driver interrupt (0 index = PKTDRVR_MIN_INT).
|
||||
*/
|
||||
|
||||
static PD_UPCALL_RTN_T *pd_upcalls[PKTDRVR_MAX_INT - PKTDRVR_MIN_INT + 1] = {
|
||||
pktd_receive60, pktd_receive61, pktd_receive62, pktd_receive63,
|
||||
pktd_receive64, pktd_receive65, pktd_receive66, pktd_receive67,
|
||||
pktd_receive68, pktd_receive69, pktd_receive6a, pktd_receive6b,
|
||||
pktd_receive6c, pktd_receive6d, pktd_receive6e, pktd_receive6f,
|
||||
pktd_receive70, pktd_receive71, pktd_receive72, pktd_receive73,
|
||||
pktd_receive74, pktd_receive75, pktd_receive76, pktd_receive77,
|
||||
pktd_receive78, pktd_receive79, pktd_receive7a, pktd_receive7b,
|
||||
pktd_receive7c, pktd_receive7d, pktd_receive7e, pktd_receive7f,
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Allocates, initializes, and returns an Attache network interface for a
|
||||
* packet driver. The network is configured with IP addresses and is marked
|
||||
* as down (the packet driver init routine marks it up).
|
||||
*/
|
||||
|
||||
static struct net *pktd_create_net(int pd_int)
|
||||
{
|
||||
struct pktdif *pif;
|
||||
#if INSTALL_ATTACHE_PPP && SNARK_PKTDRV_PPP_OVER_SLIP
|
||||
struct pppctl *pc;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Allocate a block of memory for our combined interface information.
|
||||
*/
|
||||
if ((pif = (struct pktdif *) GLUE_ALLOC(sizeof(*pif))) == 0)
|
||||
return 0;
|
||||
MEMSET(pif, 0, sizeof(*pif));
|
||||
|
||||
/*
|
||||
* Set up all the internal pointers between the various chunks of data.
|
||||
*/
|
||||
pif->net.s_name = pif->name;
|
||||
pif->net.specific = pif;
|
||||
pif->net.instance = pd_int;
|
||||
pif->net.flags = NF_DRIVER_DOWN;
|
||||
pif->net.ip_bcast = 0xFFFFFFFFL;
|
||||
pif->pdn.pd_int = pd_int;
|
||||
pif->pkt_q_tail = &pif->pkt_q_head;
|
||||
task_ini(&pif->task);
|
||||
pif->task.name = pif->name;
|
||||
pif->task.func = pktd_handler;
|
||||
pif->task.cookie = pif;
|
||||
pif->saved_rcv_mode = -1;
|
||||
|
||||
/*
|
||||
* Get the driver info.
|
||||
*/
|
||||
switch (pd_driver_info(0, &pif->pdn)) {
|
||||
|
||||
case PDE_BAD_HANDLE:
|
||||
/*
|
||||
* Older packet drivers might do this. Just assume it's an
|
||||
* ethernet and get the rest of the information later.
|
||||
*/
|
||||
pif->pdn.drvr_info.version = 0;
|
||||
pif->pdn.drvr_info.class = IC_ETHERNET;
|
||||
pif->pdn.drvr_info.pdtype = IT_ANY;
|
||||
pif->pdn.drvr_info.number = 0;
|
||||
pif->pdn.drvr_info.name = "unknown packet driver";
|
||||
pif->pdn.drvr_info.basic_flag = PDFC_BASIC;
|
||||
break;
|
||||
|
||||
case PDE_NO_ERROR:
|
||||
/*
|
||||
* We got the information, so continue processing.
|
||||
*/
|
||||
break;
|
||||
|
||||
default:
|
||||
/*
|
||||
* Any other error is bad, can't use this interface.
|
||||
*/
|
||||
GLUE_FREE(pif);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Pick the right Attache driver for this packet driver, set it up.
|
||||
*/
|
||||
switch (pif->pdn.drvr_info.class) {
|
||||
|
||||
case IC_ETHERNET:
|
||||
pif->net.driver = &pd_ether_driver;
|
||||
pif->net.flags |= NF_ARP;
|
||||
pif->net.speed = 10000000L;
|
||||
pif->receiver = et_rcv;
|
||||
break;
|
||||
|
||||
case IC_SERIAL_LINE:
|
||||
#if INSTALL_ATTACHE_PPP && SNARK_PKTDRV_PPP_OVER_SLIP
|
||||
/*
|
||||
* This is a hack for testing PPP. I use a SLIP packet driver for
|
||||
* the driver and framing. This loses some of the capabilities of
|
||||
* PPP, no async control map, but it lets me test the main parts
|
||||
* of the PPP protocol.
|
||||
*/
|
||||
pif->net.driver = &pd_ppp_driver;
|
||||
pif->net.speed = 9600; /* should get this from the packet driver */
|
||||
pif->receiver = ppp_rcv;
|
||||
pif->pdn.drvr_info.pdtype = -1;
|
||||
|
||||
if ((pc = GLUE_ALLOC(sizeof(struct pppctl))) == 0) {
|
||||
printf("Couldn't allocate storage for PPP control block\n");
|
||||
GLUE_FREE(pif);
|
||||
return 0;
|
||||
}
|
||||
MEMSET(pc, 0, sizeof(struct pppctl));
|
||||
pc->max_terminate = 5;
|
||||
pc->max_configure = 5;
|
||||
/* pc->ctl_flags = PPPC_FCS; */
|
||||
pc->ctl_flags = 0;
|
||||
pc->restart_timeout = 5000L; /* 5 seconds */
|
||||
pif->net.media_cookie = pc;
|
||||
#else /* INSTALL_ATTACHE_PPP && SNARK_PKTDRV_PPP_OVER_SLIP */
|
||||
pif->net.driver = &pd_serial_driver;
|
||||
pif->net.speed = 9600L; /* should get this from the packet driver */
|
||||
pif->receiver = slip_rcv;
|
||||
pif->pdn.drvr_info.pdtype = -1;
|
||||
#endif /* INSTALL_ATTACHE_PPP && SNARK_PKTDRV_PPP_OVER_SLIP */
|
||||
break;
|
||||
|
||||
case IC_FPPP:
|
||||
pif->net.driver = &pd_fppp_driver;
|
||||
pif->net.speed = 56000L; /* does the packet driver know? */
|
||||
pif->receiver = fppp_rcv;
|
||||
pif->pdn.drvr_info.pdtype = -1;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("Don't know class %d for packet driver %02x\n",
|
||||
pif->pdn.drvr_info.class, pd_int);
|
||||
GLUE_FREE(pif);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Finally, set up the common stuff. */
|
||||
pif->net.mtu
|
||||
= pif->net.driver->maxlen - pif->net.driver->lnh + pif->net.driver->lnt;
|
||||
sprintf(pif->name, "%.*s%02x", sizeof(pif->name) - 3,
|
||||
pif->net.driver->prefix, pif->net.instance);
|
||||
pif->pdn.device_receive_rtn = pd_upcalls[pd_int - PKTDRVR_MIN_INT];
|
||||
pd_nets[pd_int - PKTDRVR_MIN_INT] = &pif->pdn;
|
||||
|
||||
/* pif->net.driver->name = far_strdup(pif->pdn.drvr_info.name); */
|
||||
|
||||
/*
|
||||
* Done, return the new interface.
|
||||
*/
|
||||
return &pif->net;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Find all the packet drivers, build net structures for them, and call the
|
||||
* configuration routine for each of them. If the configuration routine
|
||||
* returns success, attach the interface.
|
||||
*/
|
||||
void pktd_driver_find(boolean_t (*config)(struct net *))
|
||||
{
|
||||
struct net *net;
|
||||
int pd_int;
|
||||
|
||||
for (pd_int = PKTDRVR_MIN_INT; pd_int <= PKTDRVR_MAX_INT; pd_int++) {
|
||||
if (pd_check_int(pd_int) && (net = pktd_create_net(pd_int)) != 0) {
|
||||
if ((*config)(net)) {
|
||||
net->flags |= NF_DOWN;
|
||||
if_attach(net);
|
||||
if_up(net);
|
||||
} else {
|
||||
GLUE_FREE(net->specific);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/pool.c,v 1.3 2003/01/15 14:04:33 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1999 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
struct pool_shim
|
||||
{
|
||||
pool_id_t pool_id;
|
||||
int block_id;
|
||||
};
|
||||
|
||||
struct pool_log_s {
|
||||
#if INSTALL_SNARK_POOL_TEST_METRICS
|
||||
int current;
|
||||
int hiwat;
|
||||
#endif
|
||||
int total;
|
||||
} pool_log[MEMPOOL_MAX_POOL_ID];
|
||||
|
||||
void *glue_alloc_pool (size_t size, pool_id_t id)
|
||||
{
|
||||
void *tp;
|
||||
struct pool_shim *ps;
|
||||
|
||||
if (size == 0)
|
||||
return 0;
|
||||
|
||||
tp = malloc (size + sizeof(*ps));
|
||||
|
||||
if (tp == 0)
|
||||
return 0;
|
||||
|
||||
ps = (struct pool_shim*)tp;
|
||||
ps->pool_id = id;
|
||||
|
||||
ps->block_id = ++pool_log[id].total;
|
||||
BUG(BUG_MEMPOOL_TRACE, BUG_TRACE, (void *)ps,
|
||||
(BUG_OUT, "glue_alloc_pool: pool %u, block %d", id, ps->block_id));
|
||||
|
||||
#if INSTALL_SNARK_POOL_TEST_METRICS
|
||||
++pool_log[id].current;
|
||||
if (pool_log[id].hiwat < pool_log[id].current)
|
||||
pool_log[id].hiwat = pool_log[id].current;
|
||||
#endif
|
||||
|
||||
return ((void *)&ps[1]);
|
||||
}
|
||||
|
||||
void glue_free_pool (void *p, pool_id_t id)
|
||||
{
|
||||
struct pool_shim *ps = p;
|
||||
|
||||
--ps;
|
||||
|
||||
BUG(BUG_MEMPOOL_TRACE, BUG_TRACE, (void *)ps,
|
||||
(BUG_OUT, "glue_free_pool: pool %u, block %d", id, ps->block_id));
|
||||
|
||||
BUG_ASSERT(ps->pool_id == id);
|
||||
|
||||
#if INSTALL_SNARK_POOL_TEST_METRICS
|
||||
--pool_log[id].current;
|
||||
BUG_ASSERT(pool_log[id].current >= 0);
|
||||
#endif
|
||||
|
||||
free(ps);
|
||||
}
|
||||
|
||||
#if INSTALL_SNARK_POOL_TEST_METRICS
|
||||
void pool_report(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("memory pool report:\n"
|
||||
"id\tcurrent\thiwat\ttotal\n");
|
||||
for (i = 0; i < MEMPOOL_MAX_POOL_ID; ++i) {
|
||||
if (pool_log[i].total > 0) {
|
||||
printf("%d\t%d\t%d\t%d\n", i, pool_log[i].current,
|
||||
pool_log[i].hiwat, pool_log[i].total);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,708 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/pppbsd.c,v 1.3 2003/01/15 14:04:33 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: pppbsd.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:33 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:25 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:42 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.10 2001/01/19 22:23:49 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.9 2000/10/16 19:21:54 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 2.8 2000/03/17 00:12:43 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.7 2000/03/13 21:22:08 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 2.6 1999/11/05 22:29:06 paul
|
||||
* Updated driver structs to reflect conditional backwards-compatibility
|
||||
* fields and new fields.
|
||||
*
|
||||
* Revision 2.5 1999/03/01 22:05:26 wes
|
||||
* Add Yet Another Way to connect attache ppp to a unix ppp: attach
|
||||
* ourselves to the master side of a pty; run pppd attached to the slave
|
||||
* side.
|
||||
* configured via INSTALL_SNARK_BSD_PPP_OVER_PTY
|
||||
*
|
||||
* Revision 2.4 1998/02/25 15:21:49 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 2.3 1998/02/25 04:57:35 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.2 1997/11/18 18:05:19 sra
|
||||
* Make PPP work on Purify/SunOS testbed.
|
||||
*
|
||||
* Revision 2.1 1997/10/28 00:51:55 sra
|
||||
* Convert PPP code to use BUG() macro.
|
||||
* Bang on CHAP and PAP code some more.
|
||||
* Create test driver for PPP under Snark/BSD.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Point-to-Point Protocol (PPP) interface for snark under BSD-derived systems.
|
||||
*
|
||||
* This code has only been tested under FreeBSD 2.x. It should work on
|
||||
* any BSD-derived system with minor modifications.
|
||||
*
|
||||
* We depend on the PPP media layer code to handle the FCS, address, and
|
||||
* control fields in the framing (PPPC_FCS must be enabled). So all we
|
||||
* have to worry about is the byte stuffing and the framing "flag" byte.
|
||||
*/
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/ppp.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if INSTALL_SNARK_BSD_PPP_OVER_TCP
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#if INSTALL_SNARK_BSD_PPP_OVER_PTY
|
||||
#include <util.h>
|
||||
#include <termios.h>
|
||||
#endif
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
#include <wrn/wm/demo/bsdif.h>
|
||||
#include <wrn/wm/demo/pppbsd.h>
|
||||
|
||||
#define PF_PPP_BOP 0x1000
|
||||
|
||||
#ifndef BSDPPP_COMPORT_NAME
|
||||
#if INSTALL_SNARK_BSD_PPP_OVER_PTY
|
||||
#define BSDPPP_COMPORT_NAME "pty"
|
||||
#elif INSTALL_SNARK_BSD_PPP_OVER_TCP
|
||||
#define BSDPPP_COMPORT_NAME "tcp"
|
||||
#else
|
||||
#define BSDPPP_COMPORT_NAME "cuaa"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* PPP control structure, hangs off net->specific->private.
|
||||
*/
|
||||
|
||||
#ifndef SNARKBSD_PPP_IBUFLEN
|
||||
#define SNARKBSD_PPP_IBUFLEN 6000
|
||||
#endif
|
||||
|
||||
#ifndef SNARKBSD_PPP_OBUFLEN
|
||||
#define SNARKBSD_PPP_OBUFLEN 6000
|
||||
#endif
|
||||
|
||||
struct ppp_driver_ctl {
|
||||
struct net *net;
|
||||
bits32_t snd_asynch_mask;
|
||||
packet *ipkt, *opkt_head, **opkt_tail;
|
||||
int ilen, olen;
|
||||
unsigned char *ibp, *obp;
|
||||
unsigned char ibuf[SNARKBSD_PPP_IBUFLEN], obuf[SNARKBSD_PPP_OBUFLEN];
|
||||
unsigned iescaped : 1;
|
||||
unsigned idiscard : 1;
|
||||
unsigned oescaped : 1;
|
||||
};
|
||||
|
||||
/*
|
||||
* PPP framing and byte stuffing magic
|
||||
*/
|
||||
#define PPP_FLAG 0x7e
|
||||
#define PPP_ESCAPE 0x7d
|
||||
#define PPP_XOR 0x20
|
||||
|
||||
#define PPP_MASKED(_c_, _m_) ((_c_) < 32 && ((_m_) & (1 << (_c_))))
|
||||
|
||||
#ifndef PPP_DRIVER_RCV_ASYNCH_MASK
|
||||
#define PPP_DRIVER_RCV_ASYNCH_MASK 0
|
||||
#endif
|
||||
|
||||
static void hexdump (char *flag, unsigned char *cp, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
fprintf(stderr, "%s:", flag);
|
||||
for (i=0; i<len; i++) {
|
||||
fprintf(stderr, " %02x", cp[i]);
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Decode a buffer of data into zero or more Attache packet buffers.
|
||||
* Most of the hair is just checking for weird boundary conditions.
|
||||
*/
|
||||
|
||||
#define DOCHAR(x) \
|
||||
do { \
|
||||
if (pdc->idiscard) { \
|
||||
continue; \
|
||||
} else if (p->pkt_data < p->pkt_buffer + p->pkt_buflen) { \
|
||||
*p->pkt_data++ = (x); \
|
||||
} else { \
|
||||
pdc->idiscard = 1; \
|
||||
continue; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static packet *ppp_driver_decode
|
||||
(struct net *net, unsigned char *buf, int len, int *used)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
struct ppp_driver_ctl *pdc = bif->private;
|
||||
unsigned char *bob = buf, *eob = buf + len;
|
||||
packet *p;
|
||||
|
||||
while (buf < eob) {
|
||||
if (pdc->ipkt == 0 && (pdc->ipkt = pkt_alloc(net->driver->maxlen)) == 0)
|
||||
break; /* Oops, no packet buffers */
|
||||
p = pdc->ipkt;
|
||||
|
||||
if (PPP_MASKED(*buf, PPP_DRIVER_RCV_ASYNCH_MASK)) {
|
||||
++buf; /* Noise byte, just ignore it */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pdc->iescaped) { /* Was escaped? */
|
||||
pdc->iescaped = 0; /* ain't no more */
|
||||
if (*buf == PPP_FLAG) /* End of frame in escape sequence? */
|
||||
pdc->idiscard = 1; /* yeah, abort this packet */
|
||||
DOCHAR(*buf++ ^ PPP_XOR); /* Save unescaped byte */
|
||||
} else { /* Not escaped */
|
||||
switch (*buf++) {
|
||||
case PPP_FLAG:
|
||||
if (!pdc->idiscard && p->pkt_data > p->pkt_buffer) {
|
||||
pdc->ipkt = 0;
|
||||
p->pkt_datalen = p->pkt_data - p->pkt_buffer;
|
||||
p->pkt_data = p->pkt_buffer;
|
||||
if (used)
|
||||
*used = buf - bob;
|
||||
return p; /* Happy packet */
|
||||
}
|
||||
pdc->idiscard = 0; /* Bogus packet now history */
|
||||
p->pkt_data = p->pkt_buffer;
|
||||
continue;
|
||||
case PPP_ESCAPE:
|
||||
pdc->iescaped = 1; /* An escaping byte! */
|
||||
continue;
|
||||
default:
|
||||
DOCHAR(*(buf-1)); /* A normal boring byte */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (used)
|
||||
*used = buf - bob;
|
||||
return 0; /* Yes, we have no packet today */
|
||||
}
|
||||
|
||||
#undef DOCHAR
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Encode zero or more Attache packet buffers into a data buffer.
|
||||
* Packets will have been queued for us by ppp_driver_send().
|
||||
*/
|
||||
|
||||
#define DOCHAR(x) \
|
||||
do { *buf++ = (x); if (buf == eob) return (buf - bob); } while (0)
|
||||
|
||||
static int ppp_driver_encode(struct net *net, unsigned char *buf, int len)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
struct ppp_driver_ctl *pdc = bif->private;
|
||||
unsigned char *bob = buf, *eob = buf + len;
|
||||
packet *p;
|
||||
|
||||
if (buf >= eob)
|
||||
return 0;
|
||||
|
||||
while ((p = pdc->opkt_head) != 0) {
|
||||
|
||||
/*
|
||||
* Send framing sequence before a new packet, to flush line noise.
|
||||
*/
|
||||
if ((p->pkt_flags & PF_PPP_BOP) != 0) {
|
||||
p->pkt_flags &= ~PF_PPP_BOP;
|
||||
DOCHAR(PPP_FLAG);
|
||||
}
|
||||
|
||||
/*
|
||||
* Process data in this packet.
|
||||
*/
|
||||
while (p->pkt_datalen > 0) {
|
||||
if (pdc->oescaped) {
|
||||
pdc->oescaped = 0; /* Was escaped, ain't no more */
|
||||
DOCHAR((*p->pkt_data++) ^ PPP_XOR);
|
||||
} else {
|
||||
switch (*p->pkt_data) {
|
||||
default:
|
||||
if (!PPP_MASKED(*p->pkt_data, pdc->snd_asynch_mask)) {
|
||||
DOCHAR(*p->pkt_data++);
|
||||
break; /* Ordinary char, just send it */
|
||||
}
|
||||
case PPP_FLAG: /* I need an escape */
|
||||
case PPP_ESCAPE:
|
||||
pdc->oescaped = 1;
|
||||
DOCHAR(PPP_ESCAPE);
|
||||
continue; /* Doesn't count as sent yet */
|
||||
}
|
||||
}
|
||||
p->pkt_datalen--; /* One less octet to feed */
|
||||
}
|
||||
|
||||
/*
|
||||
* No more data in current packet, so send framing sequence
|
||||
* and proceed with next packet in the output queue.
|
||||
*/
|
||||
DOCHAR(PPP_FLAG);
|
||||
if ((pdc->opkt_head = p->pkt_link) == 0)
|
||||
pdc->opkt_tail = &pdc->opkt_head;
|
||||
pkt_free(p);
|
||||
}
|
||||
|
||||
return buf - bob;
|
||||
}
|
||||
|
||||
#undef DOCHAR
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Process whatever incoming PPP data we can without blocking,
|
||||
* passing zero or more Attache packets to ppp_rcv().
|
||||
*/
|
||||
|
||||
static void ppp_driver_input(struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
struct ppp_driver_ctl *pdc = bif->private;
|
||||
packet *p;
|
||||
int n;
|
||||
|
||||
if (pdc->ilen <= 0) {
|
||||
do {
|
||||
n = read(bif->fd, (char *) pdc->ibuf, sizeof(pdc->ibuf));
|
||||
} while (n < 0 && errno == EINTR);
|
||||
if (n == 0 || (n < 0 && errno != EWOULDBLOCK)) {
|
||||
bif->flags &= ~BSDIF_READ;
|
||||
return;
|
||||
}
|
||||
pdc->ilen = n;
|
||||
pdc->ibp = pdc->ibuf;
|
||||
}
|
||||
|
||||
while (pdc->ilen > 0) {
|
||||
if ((p = ppp_driver_decode(net, pdc->ibp, pdc->ilen, &n)) != 0) {
|
||||
p->pkt_n = net;
|
||||
hexdump("RX", p->pkt_data, p->pkt_datalen);
|
||||
ppp_rcv(p);
|
||||
}
|
||||
if (n == 0) /* out of packet buffers, try again later */
|
||||
break;
|
||||
pdc->ibp += n; /* count what we consumed */
|
||||
pdc->ilen -= n;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Process whatever outgoing Attache packets we can without blocking.
|
||||
* Generates zero or more writes of encoded PPP data.
|
||||
*/
|
||||
|
||||
static void ppp_driver_output(struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
struct ppp_driver_ctl *pdc = bif->private;
|
||||
int n;
|
||||
|
||||
for (;;) {
|
||||
if (pdc->olen == 0) {
|
||||
if ((n = ppp_driver_encode(net, pdc->obuf, sizeof(pdc->obuf))) == 0)
|
||||
break;
|
||||
pdc->olen = n;
|
||||
pdc->obp = pdc->obuf;
|
||||
}
|
||||
do {
|
||||
n = write(bif->fd, pdc->obp, pdc->olen);
|
||||
} while (n < 0 && errno == EINTR);
|
||||
if (n <= 0)
|
||||
break;
|
||||
pdc->obp += n;
|
||||
pdc->olen -= n;
|
||||
}
|
||||
if (n == 0 || (n < 0 && errno != EWOULDBLOCK))
|
||||
bif->flags &= ~BSDIF_WRITE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle events detected by generic NetBSD I/O loop.
|
||||
* The flags tell us what kind of event happened, we call the
|
||||
* non-blocking I/O routines to do the real work.
|
||||
*/
|
||||
|
||||
static void ppp_driver_handler(int fd, void *net, unsigned flags)
|
||||
{
|
||||
if ((flags & BSDIF_WRITE) != 0)
|
||||
ppp_driver_output(net);
|
||||
if ((flags & BSDIF_READ) != 0)
|
||||
ppp_driver_input(net);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Attache device driver routines.
|
||||
*/
|
||||
|
||||
static void ppp_driver_send(packet *p)
|
||||
{
|
||||
struct net *net = p->pkt_n;
|
||||
struct bsdif *bif = net->specific;
|
||||
struct ppp_driver_ctl *pdc = bif->private;
|
||||
|
||||
hexdump("TX", p->pkt_data, p->pkt_datalen);
|
||||
|
||||
p->pkt_flags |= PF_PPP_BOP; /* Flag that this is a new packet */
|
||||
|
||||
p->pkt_link = 0; /* Stuff this packet into the */
|
||||
*pdc->opkt_tail = p; /* output queue */
|
||||
pdc->opkt_tail = &p->pkt_link;
|
||||
|
||||
bif->flags |= BSDIF_WRITE; /* Now interested in output events */
|
||||
ppp_driver_output(net); /* Send what we can right away */
|
||||
}
|
||||
|
||||
static void ppp_driver_close(struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
bif->flags &= ~(BSDIF_READ | BSDIF_WRITE);
|
||||
|
||||
if (bif->fd >= 0) {
|
||||
(void) close(bif->fd); /* Clean up our file if we had one */
|
||||
bif->fd = -1;
|
||||
}
|
||||
if (bif->private) {
|
||||
GLUE_FREE(bif->private); /* Release our memory if we had any */
|
||||
bif->private = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void ppp_driver_init(struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
struct ppp_driver_ctl *pdc;
|
||||
char name[64];
|
||||
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
|
||||
if (!net->speed)
|
||||
net->speed = 115200;
|
||||
|
||||
if ((bif->private = pdc = GLUE_ALLOC(sizeof(*pdc))) == 0) {
|
||||
fprintf(stderr, "couldn't allocate ppp control structure\n");
|
||||
return;
|
||||
}
|
||||
MEMSET(pdc, 0, sizeof(*pdc));
|
||||
pdc->opkt_tail = &pdc->opkt_head;
|
||||
pdc->net = net;
|
||||
|
||||
#if INSTALL_SNARK_BSD_PPP_OVER_PTY
|
||||
{
|
||||
int pty, tty;
|
||||
int subpid;
|
||||
char *pppd_path;
|
||||
struct termios t;
|
||||
int nsleep = 10;
|
||||
|
||||
sprintf(name, "SNARKBSDPPP_PTY%d", net->instance);
|
||||
pppd_path = getenv(name);
|
||||
|
||||
if (!pppd_path)
|
||||
return;
|
||||
|
||||
if (openpty(&pty, &tty, name, NULL, NULL) < 0) {
|
||||
perror("can't open pty");
|
||||
return;
|
||||
}
|
||||
|
||||
tcgetattr(tty, &t);
|
||||
cfmakeraw(&t);
|
||||
tcsetattr(tty, TCSAFLUSH, &t);
|
||||
|
||||
fflush(NULL);
|
||||
subpid = fork();
|
||||
if (subpid < 0) {
|
||||
perror("fork");
|
||||
return; /* !!! cleanup? */
|
||||
}
|
||||
|
||||
if (subpid == 0) {
|
||||
|
||||
/* in the child; start pppd... */
|
||||
|
||||
dup2(tty, 0);
|
||||
dup2(tty, 1);
|
||||
close(pty);
|
||||
close(tty);
|
||||
fprintf(stderr, "execing %s in pid %d on %s in %d seconds...\n", pppd_path, getpid(), name, nsleep);
|
||||
sleep(nsleep);
|
||||
fprintf(stderr, "execing now\n");
|
||||
execlp(pppd_path, "pppd", name,
|
||||
"file", "snark.ppprc", NULL);
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
/* now in the parent.. */
|
||||
close(tty);
|
||||
bif->fd = pty;
|
||||
sleep(nsleep+1);
|
||||
}
|
||||
#elif !INSTALL_SNARK_BSD_PPP_OVER_TCP
|
||||
|
||||
/*
|
||||
* Normal /dev/ttyxxx-based PPP. This code was written for FreeBSD 2.2.1,
|
||||
* it should be pretty easy to make it work on other Unix-like systems.
|
||||
*/
|
||||
{
|
||||
struct termios termios;
|
||||
|
||||
sprintf(name, "/dev/%s", net->s_name + 3);
|
||||
if ((bif->fd = open(name, O_RDWR, 0660)) < 0) { /* |O_NONBLOCK */
|
||||
perror("couldn't open ppp device");
|
||||
goto lose;
|
||||
}
|
||||
if (tcgetattr(bif->fd, &termios) < 0) {
|
||||
perror("couldn't get ppp line state");
|
||||
goto lose;
|
||||
}
|
||||
if (cfmakeraw(&termios), cfsetspeed(&termios, net->speed) < 0) {
|
||||
perror("couldn't fiddle ppp state");
|
||||
goto lose;
|
||||
}
|
||||
if (tcsetattr(bif->fd, TCSANOW, &termios) < 0) {
|
||||
perror("couldn't set ppp line flags and speed");
|
||||
goto lose;
|
||||
}
|
||||
}
|
||||
#elif 0
|
||||
/*
|
||||
* PPP over TCP. This version does an active connect. In theory,
|
||||
* it should work nicely with IIJ-PPP in -direct mode running under
|
||||
* Juergen Nickelsen's "socket" program, but in practice the connection
|
||||
* keeps getting closed before LCP ever really gets going. Sigh.
|
||||
*/
|
||||
{
|
||||
struct sockaddr_in sin;
|
||||
char host[20];
|
||||
unsigned short port;
|
||||
|
||||
sprintf(name, "SNARKBSDPPP_%s", net->s_name + 3);
|
||||
if (sscanf(getenv(name), "%16[0-9.]:%hu", host, &port) != 2) {
|
||||
fprintf(stderr, "couldn't line information for PPP/TCP link\n");
|
||||
goto lose;
|
||||
}
|
||||
MEMSET(&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = htons(port);
|
||||
sin.sin_addr.s_addr = inet_addr(host);
|
||||
if ((bif->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
perror("couldn't get socket for PPP/TCP link");
|
||||
goto lose;
|
||||
}
|
||||
if (connect(bif->fd, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
|
||||
perror("couldn't connect PPP/TCP link");
|
||||
goto lose;
|
||||
}
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* PPP over TCP. This version does a passive listen, which, in theory,
|
||||
* should allow IIJ-PPP to connect to it directly.
|
||||
*/
|
||||
{
|
||||
struct sockaddr_in sin;
|
||||
unsigned short port;
|
||||
int s, n;
|
||||
|
||||
sprintf(name, "SNARKBSDPPP_%s", net->s_name + 3);
|
||||
if (sscanf(getenv(name), "%hu", &port) != 1) {
|
||||
fprintf(stderr, "couldn't parse line information for PPP/TCP link %s: %s\n",
|
||||
name, getenv(name));
|
||||
goto lose;
|
||||
}
|
||||
MEMSET(&sin, 0, sizeof(sin));
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = htons(port);
|
||||
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||
perror("couldn't get socket for PPP/TCP listener");
|
||||
goto lose;
|
||||
}
|
||||
if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
|
||||
perror("couldn't bind socket for PPP/TCP listener");
|
||||
goto lose;
|
||||
}
|
||||
if (listen(s, 1) < 0) {
|
||||
perror("couldn't listen for for PPP/TCP connection");
|
||||
goto lose;
|
||||
}
|
||||
fprintf(stderr, "[Listening for PPP/TCP connection on port %u]\n", port);
|
||||
n = sizeof(sin);
|
||||
if ((bif->fd = accept(s, (struct sockaddr *) &sin, &n)) < 0) {
|
||||
perror("couldn't accept PPP/TCP connection");
|
||||
goto lose;
|
||||
}
|
||||
close(s);
|
||||
fprintf(stderr, "[Got PPP/TCP connection from %s:%u]\n",
|
||||
inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
|
||||
}
|
||||
#endif
|
||||
|
||||
if (fcntl(bif->fd, F_SETFL, FNDELAY) < 0) {
|
||||
perror("unable to set ppp line non-blocking");
|
||||
goto lose;
|
||||
}
|
||||
|
||||
bif->handler = ppp_driver_handler;
|
||||
bif->flags |= BSDIF_READ;
|
||||
net->flags &= ~NF_DRIVER_DOWN;
|
||||
return; /* success */
|
||||
|
||||
lose:
|
||||
ppp_driver_close(net); /* failure */
|
||||
}
|
||||
|
||||
static int ppp_driver_device_ctl(struct net *net, int code, ptr_t cookie)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
struct ppp_driver_ctl *pdc = bif->private;
|
||||
|
||||
switch (code) {
|
||||
case DEVICE_CTL_SET_PPP_ASYNC_CTL_MAP:
|
||||
BUG_ASSERT(cookie && bif && pdc);
|
||||
pdc->snd_asynch_mask = *(bits32_t *)cookie;
|
||||
return DEVICE_CTL_GOOD;
|
||||
case DEVICE_CTL_GET_PPP_RCV_ASYNC_CTL_MAP:
|
||||
BUG_ASSERT(cookie);
|
||||
*(bits32_t *)cookie = PPP_DRIVER_RCV_ASYNCH_MASK;
|
||||
return DEVICE_CTL_GOOD;
|
||||
default:
|
||||
return DEVICE_CTL_UNKNOWN_CODE;
|
||||
}
|
||||
}
|
||||
|
||||
static struct driver ppp_driver = {
|
||||
ppp_driver_init, /* Init routine */
|
||||
ppp_driver_send, /* Raw send routine */
|
||||
ppp_ip_send, /* IP packet send routine */
|
||||
0, /* ARP routine */
|
||||
ppp_driver_device_ctl, /* Device control routine */
|
||||
ppp_driver_close, /* Close routine */
|
||||
"ppp", /* Driver name prefix */
|
||||
"Point-to-Point Protocol", /* Driver name */
|
||||
4, /* Header length (adr, ctl, prot) */
|
||||
2, /* Trailer length (FCS) */
|
||||
1506, /* Max packet size */
|
||||
IF_PPP, /* MIB interface type */
|
||||
0, /* ARP hardware type */
|
||||
ppp_control, /* Media control routine */
|
||||
0, /* IPv6 send */
|
||||
0 /* IPv4 send */
|
||||
};
|
||||
|
||||
void ppp_driver_find
|
||||
(void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t))
|
||||
{
|
||||
char name[64];
|
||||
int speed, instance;
|
||||
|
||||
for (instance = 0; ; instance++) {
|
||||
#if INSTALL_SNARK_BSD_PPP_OVER_PTY
|
||||
sprintf(name, "SNARKBSDPPP_PTY%d", instance);
|
||||
if (!getenv(name))
|
||||
return;
|
||||
speed = 115200;
|
||||
#elif INSTALL_SNARK_BSD_PPP_OVER_TCP
|
||||
sprintf(name, "SNARKBSDPPP_%s%d", BSDPPP_COMPORT_NAME, instance);
|
||||
if (!getenv(name))
|
||||
return;
|
||||
speed = 115200;
|
||||
#else
|
||||
struct termios termios;
|
||||
int fd;
|
||||
sprintf(name, "/dev/%s%d", BSDPPP_COMPORT_NAME, instance);
|
||||
if ((fd = open(name, O_RDONLY | O_NONBLOCK)) < 0) {
|
||||
if (errno == ENOENT)
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
speed = (tcgetattr(fd, &termios) < 0 ? 0 : cfgetispeed(&termios));
|
||||
(void) close(fd);
|
||||
if (speed == 0)
|
||||
continue;
|
||||
#endif
|
||||
sprintf(name, "%s%d", BSDPPP_COMPORT_NAME, instance);
|
||||
config(name, &ppp_driver, instance, 0,
|
||||
ppp_driver.maxlen - ppp_driver.lnh - ppp_driver.lnt, speed);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/psostty.c,v 1.3 2003/01/15 14:04:34 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: psostty.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:34 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:25 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:42 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.14 2001/01/19 22:23:50 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.13 2000/03/17 00:12:43 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.12 1999/04/15 21:38:25 wes
|
||||
* Use symbolic values for flag bits
|
||||
*
|
||||
* Revision 2.11 1999/04/13 20:40:30 wes
|
||||
* Support psossim console
|
||||
*
|
||||
* Revision 2.10 1999/04/09 20:55:22 wes
|
||||
* fix a bunch of gcc warnings.
|
||||
* include new psosinit.h (also included by root.c) for prototypes
|
||||
* of functions exported by this file.
|
||||
*
|
||||
* Revision 2.9 1998/12/15 05:47:18 sra
|
||||
* Get pSOS/X86 serial console working.
|
||||
*
|
||||
* Revision 2.8 1998/12/12 18:53:39 sra
|
||||
* Changes to pSOS port of Attache: support non-Ethernet NI drivers,
|
||||
* simplify packet buffer implementation, general cleanup.
|
||||
*
|
||||
* Revision 2.7 1998/09/22 19:46:25 wes
|
||||
* Use VMIN=1 instead of VMIN=0 (to work around apparent driver bug)
|
||||
* Do blocking read of serial console just like PC keyboard console.
|
||||
* Simplify extensively.
|
||||
*
|
||||
* Revision 2.6 1998/08/13 22:56:20 meister
|
||||
* conditionalize PC console include file
|
||||
*
|
||||
* Revision 2.5 1998/08/05 23:11:14 meister
|
||||
* added code to turn off echo on the PC console device
|
||||
*
|
||||
* Revision 2.4 1998/08/04 22:54:15 meister
|
||||
* Changed PEV_QEVENT, MSG_KBDCHAR, etc to have more attache-specific names
|
||||
*
|
||||
* Revision 2.3 1998/07/31 21:37:50 meister
|
||||
* Merge x86 pc console rotines back in
|
||||
*
|
||||
* Revision 2.2 1998/07/30 22:16:21 meister
|
||||
* get rid of printf, use BUG
|
||||
*
|
||||
* Revision 2.1 1998/07/24 21:04:01 meister
|
||||
* Added psostty.c
|
||||
* moved nidrive.c to attache/psos
|
||||
*
|
||||
* Revision 1.7 1998/07/24 17:03:15 meister
|
||||
* moved att_cfg.c, niatt.c, nimux.c to attache/psos
|
||||
* moved kbd_read_task to psostty.c
|
||||
*
|
||||
* Revision 1.6 1998/07/20 21:24:26 sra
|
||||
* Cleanup.
|
||||
*
|
||||
* Revision 1.5 1998/07/17 21:47:58 meister
|
||||
* minor code shufflage
|
||||
*
|
||||
* Revision 1.4 1998/07/17 06:37:24 sra
|
||||
* Add some casts to make CAD-UL happy.
|
||||
*
|
||||
* Revision 1.3 1998/06/24 18:46:48 meister
|
||||
* More cosmetics
|
||||
*
|
||||
* Revision 1.2 1998/06/24 17:38:54 meister
|
||||
* Legal boilerplate.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
#include <types.h>
|
||||
#include <psos.h>
|
||||
#include <prepc.h>
|
||||
#include <gsblk.h>
|
||||
#include <disi.h>
|
||||
#include <diti.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/demo/bug_conf.h>
|
||||
#include <wrn/wm/common/bug.h>
|
||||
#include <wrn/wm/attache/psos/nidrv.h>
|
||||
#include <sys_conf.h>
|
||||
#include <wrn/wm/demo/psosinit.h>
|
||||
|
||||
|
||||
#ifndef INSTALL_SNARK_PSOSTTY_PC_CONSOLE
|
||||
#define INSTALL_SNARK_PSOSTTY_PC_CONSOLE \
|
||||
(defined(BSP_CPUFAMILY) && defined(FAMILY_X86) && \
|
||||
defined(SC_APP_CONSOLE) && defined(PCCON) && \
|
||||
(BSP_CPUFAMILY == FAMILY_X86) && (SC_APP_CONSOLE == PCCON))
|
||||
#endif
|
||||
|
||||
#ifndef INSTALL_SNARK_PSOSTTY_SIM_CONSOLE
|
||||
#define INSTALL_SNARK_PSOSTTY_SIM_CONSOLE \
|
||||
(defined(BSP_CPUFAMILY) && defined(FAMILY_PSOSIM) && \
|
||||
(BSP_CPUFAMILY == FAMILY_PSOSIM))
|
||||
#endif
|
||||
|
||||
#if INSTALL_SNARK_PSOSTTY_PC_CONSOLE
|
||||
#include <../devices/common/pcconsol.h>
|
||||
#endif
|
||||
|
||||
extern void (*kbd_handler)(unsigned char *, size_t);
|
||||
|
||||
static void kbd_read_task (void);
|
||||
|
||||
#define CLIENT_USRSTACK 1024 /* User stack size of client task */
|
||||
#define CLIENT_SYSSTACK 4096 /* Supervisor stack size */
|
||||
#define CLIENT_FLAGS 0x00 /* Flags for client task */
|
||||
#define CLIENT_INITMODE T_SUPV /* Initial mode of the client task */
|
||||
|
||||
/*
|
||||
* put console in non-echo, non blocking mode.
|
||||
* The PC console code is somewhat black magic, depending on calls in the
|
||||
* the pc console device driver module that aren't documented in the pSOS
|
||||
* documentation. set INSTALL_SNARK_PSOS_NO_PC_CONSOLE_ECHO_MAGIC in your
|
||||
* config file to turn it off.
|
||||
*/
|
||||
|
||||
void term_setup (void)
|
||||
{
|
||||
#if !INSTALL_SNARK_PSOSTTY_PC_CONSOLE && !INSTALL_SNARK_PSOSTTY_SIM_CONSOLE
|
||||
struct ioparms parms;
|
||||
ULONG iopb [4];
|
||||
|
||||
TermCtl tctl;
|
||||
struct termio tio;
|
||||
|
||||
parms.in_iopb = iopb;
|
||||
parms.in_dev = CONSOLE;
|
||||
parms.tid = 0L;
|
||||
|
||||
TermInit (&parms);
|
||||
|
||||
BUG(BUG_SNARK_PSOSTTY_INFO, BUG_CONTINUABLE, (void *) 0,
|
||||
(BUG_OUT, "term_init returned %ld for err, %ld for retval",
|
||||
parms.err, parms.out_retval));
|
||||
|
||||
parms.in_iopb = (ULONG *) &tctl;
|
||||
tctl.function = TCGETS;
|
||||
tctl.arg = &tio;
|
||||
|
||||
TermIoctl (&parms);
|
||||
|
||||
BUG(BUG_SNARK_PSOSTTY_INFO, BUG_CONTINUABLE, (void *) 0,
|
||||
(BUG_OUT, "TermIoctl returned %ld for err, %ld for retval",
|
||||
parms.err, parms.out_retval));
|
||||
|
||||
tio.c_lflag &= ~(ICANON|ECHO);
|
||||
tio.c_cc[VMIN] = 1;
|
||||
tio.c_cc[VTIME] = 0;
|
||||
|
||||
tctl.function = TCSETS;
|
||||
|
||||
TermIoctl (&parms);
|
||||
|
||||
BUG(BUG_SNARK_PSOSTTY_INFO, BUG_CONTINUABLE, (void *) 0,
|
||||
(BUG_OUT, "TermIoctl returned %ld for err, %ld for retval",
|
||||
parms.err, parms.out_retval));
|
||||
#elif INSTALL_SNARK_PSOSTTY_PSOS_CONSOLE && !INSTALL_SNARK_PSOS_NO_PC_CONSOLE_ECHO_MAGIC
|
||||
struct ioparms parms;
|
||||
struct pccnsl_ctl_iopb cons_iopb;
|
||||
|
||||
cons_iopb.function = PCCNSL_GET_PARMS;
|
||||
parms.in_iopb = (ULONG *) &cons_iopb;
|
||||
|
||||
PcCnslCntrl (&parms);
|
||||
|
||||
if (cons_iopb.parms.echo == TRUE)
|
||||
{
|
||||
BUG(BUG_SNARK_PSOSTTY_INFO, BUG_CONTINUABLE, (void *) 0,
|
||||
(BUG_OUT, "pc console ECHO mode starts out ON"));
|
||||
}
|
||||
else
|
||||
{
|
||||
BUG(BUG_SNARK_PSOSTTY_INFO, BUG_CONTINUABLE, (void *) 0,
|
||||
(BUG_OUT, "pc console ECHO mode starts out OFF"));
|
||||
}
|
||||
|
||||
cons_iopb.parms.echo = 0;
|
||||
|
||||
cons_iopb.function = PCCNSL_SET_PARMS;
|
||||
PcCnslCntrl (&parms);
|
||||
|
||||
cons_iopb.function = PCCNSL_GET_PARMS;
|
||||
PcCnslCntrl (&parms);
|
||||
|
||||
if (cons_iopb.parms.echo == TRUE)
|
||||
{
|
||||
BUG(BUG_SNARK_PSOSTTY_INFO, BUG_CONTINUABLE, (void *) 0,
|
||||
(BUG_OUT, "pc console ECHO mode ends up ON"));
|
||||
}
|
||||
else
|
||||
{
|
||||
BUG(BUG_SNARK_PSOSTTY_INFO, BUG_CONTINUABLE, (void *) 0,
|
||||
(BUG_OUT, "pc console ECHO mode ends up OFF"));
|
||||
}
|
||||
#endif /* !INSTALL_SNARK_PSOSTTY_PC_CONSOLE */
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* write a character string to the serial console
|
||||
*/
|
||||
|
||||
static int psos_console_write (char *txt, int len)
|
||||
{
|
||||
#if INSTALL_SNARK_PSOSTTY_PC_CONSOLE || INSTALL_SNARK_PSOSTTY_SIM_CONSOLE
|
||||
|
||||
ULONG ioretval, iopb[4], rc;
|
||||
|
||||
iopb[0] = len;
|
||||
iopb[1] = (ULONG) txt;
|
||||
rc = de_write(CONSOLE, iopb, &ioretval);
|
||||
|
||||
return (int) rc;
|
||||
|
||||
#else /* INSTALL_SNARK_PSOSTTY_PC_CONSOLE */
|
||||
struct ioparms parms;
|
||||
|
||||
TermIO tioblk;
|
||||
|
||||
parms.in_dev = CONSOLE;
|
||||
parms.tid = 0L;
|
||||
|
||||
tioblk.length = len;
|
||||
tioblk.buffp = txt;
|
||||
parms.in_iopb = (ULONG *) &tioblk;
|
||||
|
||||
TermWrite (&parms);
|
||||
|
||||
return parms.out_retval;
|
||||
|
||||
#endif /* INSTALL_SNARK_PSOSTTY_PC_CONSOLE */
|
||||
}
|
||||
|
||||
|
||||
void keyboard_write(unsigned char *text, size_t length)
|
||||
{
|
||||
(void) psos_console_write ((char *) text, (int) length);
|
||||
}
|
||||
|
||||
static unsigned long kbd_send_queue = 0L;
|
||||
static unsigned long kbd_send_task = 0L;
|
||||
static unsigned long AttKbdTaskId = 0L;
|
||||
|
||||
unsigned long CreateKbdTask (unsigned long priority,
|
||||
unsigned long kbd_queue_id,
|
||||
unsigned long attache_task_id)
|
||||
{
|
||||
if (t_create("AKBD", priority, CLIENT_SYSSTACK, CLIENT_USRSTACK,
|
||||
CLIENT_FLAGS, &AttKbdTaskId) != 0)
|
||||
{
|
||||
BUG(BUG_SNARK_PSOSTTY_INFO, BUG_CONTINUABLE, (void *) 0,
|
||||
(BUG_OUT, "Task creation error (AKBD)"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
kbd_send_queue = kbd_queue_id;
|
||||
kbd_send_task = attache_task_id;
|
||||
return AttKbdTaskId;
|
||||
}
|
||||
|
||||
int StartKbdTask ()
|
||||
{ unsigned long i;
|
||||
if (t_start(AttKbdTaskId, CLIENT_INITMODE, kbd_read_task, &i) != 0)
|
||||
{
|
||||
BUG(BUG_SNARK_PSOSTTY_INFO, BUG_CONTINUABLE, (void *) 0,
|
||||
(BUG_OUT, "AKBD task start error"));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void kbd_read_task (void)
|
||||
{
|
||||
unsigned long msg[4];
|
||||
unsigned char c;
|
||||
|
||||
while (1)
|
||||
{
|
||||
#if INSTALL_SNARK_PSOSTTY_PC_CONSOLE || INSTALL_SNARK_PSOSTTY_SIM_CONSOLE
|
||||
ULONG ioretval, iopb[4];
|
||||
|
||||
iopb[0] = 1;
|
||||
iopb[1] = (ULONG) &c;
|
||||
de_read (CONSOLE, iopb, &ioretval);
|
||||
#else
|
||||
struct ioparms parms;
|
||||
TermIO tioblk;
|
||||
tioblk.length = 1;
|
||||
tioblk.buffp = &c;
|
||||
parms.in_iopb = (ULONG *)&tioblk;
|
||||
parms.in_dev = CONSOLE;
|
||||
TermRead(&parms);
|
||||
if (parms.err)
|
||||
{
|
||||
BUG(BUG_SNARK_PSOSTTY_INFO, BUG_CONTINUABLE, (void *) 0,
|
||||
(BUG_OUT, "kbd_task TermRead failed, code %lx",
|
||||
parms.err));
|
||||
continue;
|
||||
}
|
||||
|
||||
#endif
|
||||
/* If no receiver yet, drop char into bit bucket.. */
|
||||
if (kbd_send_task)
|
||||
{
|
||||
MEMSET(msg, 0, sizeof(msg));
|
||||
SET_ATTACHE_PSOS_MSG_OPCODE(msg, ATTACHE_PSOS_MSG_KBDCHAR);
|
||||
SET_ATTACHE_PSOS_MSG_CHAR(msg, c);
|
||||
q_send(kbd_send_queue, msg);
|
||||
ev_send(kbd_send_task, ATTACHE_PSOS_QEVENT);
|
||||
}
|
||||
}
|
||||
|
||||
/* NOTREACHED */
|
||||
t_suspend (0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/put_str.c,v 1.1.1.1 2001/11/05 17:48:42 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1996-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: put_str.c,v $
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:42 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.5 2001/01/19 22:23:50 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.4 2000/03/17 00:12:44 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.3 1998/02/25 04:57:36 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.2 1998/02/18 18:49:45 josh
|
||||
* making prototypes more consistent with new data type epilogue_char_t
|
||||
*
|
||||
* Revision 1.1 1997/08/12 22:31:19 lowell
|
||||
* kick release numbers to avoid the "0.*" special case
|
||||
*
|
||||
* Revision 0.8 1997/03/20 06:53:08 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 0.7 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 0.6 1996/11/13 17:24:01 sra
|
||||
* Use putc() instead of fputc(), should be identical everywhere but
|
||||
* faster.
|
||||
*
|
||||
* Revision 0.5 1996/11/13 17:22:44 sra
|
||||
* Rewrite decorum_put_string() to get rid of all the crazy OS
|
||||
* dependencies.
|
||||
*
|
||||
* Revision 0.4 1996/11/13 15:09:16 mrf
|
||||
* Changes necessary to make snoop support work on Irix 5.x include
|
||||
* addition of snoop driver code and port to somewhat wacky Irix
|
||||
* curses implementation.
|
||||
*
|
||||
* Revision 0.3 1996/10/30 20:39:43 sar
|
||||
* Corrected test of fputs for msdos
|
||||
*
|
||||
* Revision 0.2 1996/10/28 17:49:57 sar
|
||||
* use decorum/h/dconfig.h instead of decorum.h directly
|
||||
*
|
||||
* Revision 0.1 1996/10/15 17:13:40 sar
|
||||
* initial vesion
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/* get the decorum configuration */
|
||||
#ifndef decorum_config_inc
|
||||
#include <decorum/h/dconfig.h>
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
NAME: decorum_put_string
|
||||
decorum_put_sbits32
|
||||
decorum_put_bits32
|
||||
decorum_put_hex_string
|
||||
|
||||
PURPOSE: output strings or numbers to the given output stream
|
||||
these exist to isolate all of the html routines from
|
||||
a particular file or memory implementation.
|
||||
|
||||
PARAMETERS:
|
||||
etc_stdio_t * The stream to write the header to.
|
||||
|
||||
put_string and put_hex_string also have
|
||||
sbits8_t * The string to use for the title and header
|
||||
decorum_size_t The number of characters to output,
|
||||
if -1 then the string is null terminated
|
||||
note that hex strings can't use the null termination.
|
||||
put_sbits32
|
||||
sbits32_t The value (signed 32 bit) to output
|
||||
|
||||
put_bits32
|
||||
bits32_t The value (unsigned 32 bit) to output
|
||||
|
||||
RETURNS: int 0 = success, otherwise failure
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
sbits16_t
|
||||
decorum_put_string(etc_stdio_t *outstream,
|
||||
epilogue_char_t *bufp,
|
||||
decorum_size_t bufl)
|
||||
{
|
||||
if (bufl == -1) {
|
||||
for (; *bufp; bufp++)
|
||||
if (putc((int)(*bufp), outstream) == EOF)
|
||||
return(1);
|
||||
} else {
|
||||
for(; bufl; bufl--, bufp++)
|
||||
if (putc((int)(*bufp), outstream) == EOF)
|
||||
return(1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
sbits16_t
|
||||
decorum_put_sbits32(etc_stdio_t *outstream,
|
||||
sbits32_t value)
|
||||
{
|
||||
if (fprintf(outstream, "%ld", value) == 0)
|
||||
return(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
sbits16_t
|
||||
decorum_put_bits32(etc_stdio_t *outstream,
|
||||
bits32_t value)
|
||||
{
|
||||
if (fprintf(outstream, "%lu", value) == 0)
|
||||
return(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
sbits16_t
|
||||
decorum_put_hex_string(etc_stdio_t *outstream,
|
||||
bits8_t *bufp,
|
||||
decorum_size_t bufl)
|
||||
{
|
||||
if (bufl < 0)
|
||||
return(1);
|
||||
|
||||
for(; bufl; bufl--, bufp++)
|
||||
if (fprintf(outstream, "%02x", (*bufp) & 0xFF) == 0)
|
||||
return(1);
|
||||
return(0);
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
# $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/read_ini.awk,v 1.1.1.1 2001/11/05 17:48:41 tneale Exp $
|
||||
|
||||
################################################################################
|
||||
# *** Restricted Rights Legend ***
|
||||
#
|
||||
# The programs and information contained herein are licensed only
|
||||
# pursuant to a license agreement that contains use, reverse
|
||||
# engineering, disclosure, and other restrictions; accordingly, it
|
||||
# is "Unpublished--all rights reserved under the applicable
|
||||
# copyright laws".
|
||||
#
|
||||
# Use duplication, or disclosure by the Government is subject to
|
||||
# restrictions as set forth in subparagraph (c)(1)(ii) of the Rights
|
||||
# in Technical Data and Computer Licensed Programs clause of DFARS
|
||||
# 52.227 7013.
|
||||
#
|
||||
# Copyright 2000-2001 Wind River Systems, Inc.
|
||||
# Copyright 1998 Integrated Systems, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# *** Government Use ***
|
||||
#
|
||||
# The Licensed Programs and their documentation were developed at
|
||||
# private expense and no part of them is in the public domain.
|
||||
#
|
||||
# The Licensed Programs are "Restricted Computer Software" as that
|
||||
# term is defined in Clause 52.227-19 of the Federal Acquisition
|
||||
# Regulations (FAR) and are "Commercial Computer Software" as that
|
||||
# term is defined in Subpart 227.401 of the Department of Defense
|
||||
# Federal Acquisition Regulation Supplement (DFARS).
|
||||
#
|
||||
# (i) If the licensed Programs are supplied to the Department of
|
||||
# Defense (DoD), the Licensed Programs are classified as
|
||||
# "Commercial Computer Software" and the Government is acquiring
|
||||
# only "restricted rights" in the Licensed Programs and their
|
||||
# documentation as that term is defined in Clause 52.227
|
||||
# 7013(c)(1) of the DFARS, and
|
||||
#
|
||||
# (ii) If the Licensed Programs are supplied to any unit or agency
|
||||
# of the United States Government other than DoD, the
|
||||
# Government's rights in the Licensed Programs and their
|
||||
# documentation will be as defined in Clause 52.227-19(c)(2) of
|
||||
# the FAR.
|
||||
################################################################################
|
||||
|
||||
# AWK script to convert from one of the two formats that snark/lib/read_ini.c
|
||||
# knows how to read to the other format.
|
||||
#
|
||||
# Ordinarily, the demo configuration routines in read_ini load configuration
|
||||
# data from a file called etc.ini. However, this does not make a very good
|
||||
# demo on embedded systems where there is no filesystem, so these routines
|
||||
# can also be configured to load configuration information from a static array.
|
||||
# This is still not particularly efficient (if you want efficency, use the
|
||||
# real configuration APIs for the various Epilogue products), but it is fairly
|
||||
# to use and thus makes a reasonable demo.
|
||||
#
|
||||
# Rather than having to maintain two sets of configuration files, you can write
|
||||
# configuration files in the normal etc.ini format and use this script to
|
||||
# convert them to the static array format that the snark demo package uses when
|
||||
# you've installed the SNARK_READ_INI_FROM_MEMORY configuration option.
|
||||
#
|
||||
# This script is intended to be used only on well-formed etc.ini files.
|
||||
# It does not attempt to detect every possible format violation, and it
|
||||
# transcribes etc.ini comments to C comments without checking them for
|
||||
# possible nested C comments. We do try to do appropriate quoting for
|
||||
# doublequote and backslash as supported by snark/lib/parse.c.
|
||||
|
||||
BEGIN {
|
||||
print "/*";
|
||||
print " * Automatically generated file. You may choose to modify this file";
|
||||
print " * by hand, but beware of accidently overwriting it.";
|
||||
print " */";
|
||||
print "";
|
||||
print "#include <common/h/config.h>";
|
||||
print "#include <common/h/glue.h>";
|
||||
print "#include <snark/h/read_ini.h>";
|
||||
print "";
|
||||
print "struct ini_table etc_ini_table[] = {";
|
||||
print "";
|
||||
}
|
||||
|
||||
END {
|
||||
print "";
|
||||
print " { 0, 0 }";
|
||||
print "};";
|
||||
}
|
||||
|
||||
NF == 0 { # blank line?
|
||||
print "";
|
||||
next;
|
||||
}
|
||||
|
||||
$1 ~ /^;/ { # comment?
|
||||
printf " /* %s */\n", $0;
|
||||
next;
|
||||
}
|
||||
|
||||
$1 ~ /^\[/ { # section label?
|
||||
sub(/^[ \t]*\[/, ""); # delete leading cruft
|
||||
sub(/\][ \t]*$/, ""); # delete trailing cruft
|
||||
printf " { \"%s\", 0 },\n", $0;
|
||||
next;
|
||||
}
|
||||
|
||||
/=/ { # variable?
|
||||
eq_pos = match($0, "="); # find delimiter
|
||||
key = substr($0, 1, eq_pos - 1);
|
||||
val = substr($0, eq_pos + 1);
|
||||
sub(/^[ \t]+/, "", key); # delete leading whitespace from key
|
||||
sub(/[ \t]+$/, "", key); # delete trailing whitespace from key
|
||||
sub(/^[ \t]+/, "", val); # delete leading whitespace from val
|
||||
sub(/[ \t]+$/, "", val); # delete trailing whitespace from val
|
||||
gsub(/\\/, "\\\\", val); # quote backslashes in val
|
||||
gsub(/"/, "\\\"", val); # quote doublequotes in val
|
||||
printf " { \"%s\", \"%s\" },\n", key, val;
|
||||
next;
|
||||
}
|
||||
|
||||
{ # ???
|
||||
printf "/* ???: %s */\n", $0;
|
||||
next;
|
||||
}
|
||||
@@ -0,0 +1,404 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/read_ini.c,v 1.3 2003/01/15 14:04:34 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: read_ini.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:34 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:25 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:42 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.15 2001/01/19 22:23:50 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.14 2000/03/17 00:12:44 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.13 1999/04/26 19:05:01 sra
|
||||
* Fix a few minor warnings, fix a few Solaris-specific problems in the
|
||||
* demo code.
|
||||
*
|
||||
* Revision 2.12 1998/07/15 17:49:28 meister
|
||||
* added nidrive.c and nidrv.h.
|
||||
*
|
||||
* Revision 2.11 1998/07/02 21:23:49 sra
|
||||
* Rearrange #include files to fix stdio dependency.
|
||||
*
|
||||
* Revision 2.10 1998/06/28 20:09:38 sra
|
||||
* Add support for SNARK_READ_INI_FROM_MEMORY.
|
||||
*
|
||||
* Revision 2.9 1998/05/13 21:16:13 meister
|
||||
* only compile this if SNARK_PSOS_NO_PHILE is not installed
|
||||
*
|
||||
* Revision 2.8 1998/02/25 04:57:36 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.7 1997/03/20 06:53:09 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.6 1997/03/19 20:20:40 sra
|
||||
* Remove gratuitous Attache dependencies.
|
||||
*
|
||||
* Revision 2.5 1997/03/19 04:47:35 sra
|
||||
* Get rid of some gratuitous historical dependencies on Attache.
|
||||
*
|
||||
* Revision 2.4 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.3 1996/10/25 16:01:00 sar
|
||||
* Added some include files to get the configuration stuff correct.
|
||||
*
|
||||
* Revision 2.2 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.1 1995/07/31 13:54:55 sra
|
||||
* OSPF now working well enough to let somebody else test it.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.3 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.2 1993/08/14 05:04:29 sra
|
||||
* Don't invalidate handle->iter_variable in ini_scan_for_section(),
|
||||
* Shawn's SNMPv2 configuration code wants it to stay valid.
|
||||
*
|
||||
* Revision 1.1 1993/07/05 21:53:30 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#if !INSTALL_SNARK_READ_INI_FROM_MEMORY
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
#include <wrn/wm/demo/read_ini.h>
|
||||
|
||||
#if !INSTALL_SNARK_READ_INI_FROM_MEMORY
|
||||
|
||||
#define DOWNCASE(c) (isupper((int) c) ? tolower((int) c) : (int) c)
|
||||
|
||||
#define LINE_SKIP() \
|
||||
do { \
|
||||
while (c != '\n') \
|
||||
if ((c = fgetc(handle->file)) == EOF) \
|
||||
return 0; \
|
||||
} while (0)
|
||||
|
||||
#define SKIP_WHITE() \
|
||||
do { \
|
||||
while ((c == ' ') || (c == '\t')) \
|
||||
if ((c = fgetc(handle->file)) == EOF) \
|
||||
return 0; \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_TOKEN() \
|
||||
do { \
|
||||
while (*cp && DOWNCASE(c) == DOWNCASE(*cp)) { \
|
||||
if ((c = fgetc(handle->file)) == EOF) \
|
||||
return 0; \
|
||||
cp++; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif /* INSTALL_SNARK_READ_INI_FROM_MEMORY */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* If the enviroment variable is set then use it to find the .ini file.
|
||||
* If no environment variable or file not found look in the current directory.
|
||||
* If no local file then look for the global default file.
|
||||
*/
|
||||
struct ini_handle *ini_open(size_t buflen)
|
||||
{
|
||||
struct ini_handle *handle = GLUE_ALLOC(sizeof(*handle) + buflen);
|
||||
|
||||
if (!handle) {
|
||||
fprintf(stderr, "Can't allocate handle for ini file\n");
|
||||
return 0;
|
||||
}
|
||||
MEMSET(handle, 0, sizeof(*handle));
|
||||
if ((handle->buflen = buflen) != 0)
|
||||
handle->buffer = (char *) (handle + 1);
|
||||
|
||||
#if !INSTALL_SNARK_READ_INI_FROM_MEMORY
|
||||
|
||||
{
|
||||
static char env_ini[] = "ETC_INI";
|
||||
static char local_file[] = "etc.ini";
|
||||
static char global_file[] = "/etc/etc.ini";
|
||||
char *env = getenv(env_ini);
|
||||
|
||||
if ((!env || (handle->file = fopen(env, "r")) == 0) &&
|
||||
(handle->file = fopen(local_file, "r")) == 0 &&
|
||||
(handle->file = fopen(global_file, "r")) == 0) {
|
||||
fprintf(stderr, "Can't find init file %s\n", (env ? env : local_file));
|
||||
GLUE_FREE(handle);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* INSTALL_SNARK_READ_INI_FROM_MEMORY */
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void ini_close(struct ini_handle *handle)
|
||||
{
|
||||
if (!handle)
|
||||
return;
|
||||
|
||||
#if !INSTALL_SNARK_READ_INI_FROM_MEMORY
|
||||
|
||||
if (handle->file)
|
||||
fclose(handle->file);
|
||||
|
||||
#endif /* INSTALL_SNARK_READ_INI_FROM_MEMORY */
|
||||
|
||||
GLUE_FREE(handle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if INSTALL_SNARK_READ_INI_FROM_MEMORY
|
||||
|
||||
static unsigned long ini_get_pos(struct ini_handle *handle)
|
||||
{
|
||||
return handle->current_pos;
|
||||
}
|
||||
|
||||
static void ini_set_pos(struct ini_handle *handle, unsigned long new_pos)
|
||||
{
|
||||
handle->current_pos = new_pos;
|
||||
}
|
||||
|
||||
#else /* INSTALL_SNARK_READ_INI_FROM_MEMORY */
|
||||
|
||||
static unsigned long ini_get_pos(struct ini_handle *handle)
|
||||
{
|
||||
return (unsigned long) ftell(handle->file);
|
||||
}
|
||||
|
||||
static void ini_set_pos(struct ini_handle *handle, unsigned long new_pos)
|
||||
{
|
||||
fseek(handle->file, (long) new_pos, 0);
|
||||
}
|
||||
|
||||
#endif /* INSTALL_SNARK_READ_INI_FROM_MEMORY */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Scans for a section with the right name.
|
||||
*/
|
||||
static boolean_t ini_scan_for_section
|
||||
(struct ini_handle *handle, char *section)
|
||||
{
|
||||
if (!handle || !section)
|
||||
return 0; /* bad arguments, lose */
|
||||
|
||||
if (section == handle->section_name) {
|
||||
ini_set_pos(handle, handle->section_start);
|
||||
return 1; /* section was cached, win */
|
||||
}
|
||||
|
||||
if (handle->section_name) /* has file been used? */
|
||||
ini_set_pos(handle, 0); /* yeah, rewind it */
|
||||
|
||||
#if INSTALL_SNARK_READ_INI_FROM_MEMORY
|
||||
|
||||
{
|
||||
for (;;) {
|
||||
if (!etc_ini_table[handle->current_pos].tag)
|
||||
return 0; /* "EOF", lose */
|
||||
if (!etc_ini_table[handle->current_pos].value &&
|
||||
!STRICMP(section, etc_ini_table[handle->current_pos].tag))
|
||||
break; /* matching section tag, won */
|
||||
handle->current_pos++; /* otherwise, keep looking */
|
||||
}
|
||||
|
||||
handle->current_pos++; /* won, skip to first variable */
|
||||
}
|
||||
|
||||
#else /* INSTALL_SNARK_READ_INI_FROM_MEMORY */
|
||||
|
||||
{
|
||||
char *cp;
|
||||
int c;
|
||||
|
||||
if (!handle->file)
|
||||
return 0; /* bad arguments, lose */
|
||||
|
||||
for (;;) {
|
||||
if ((c = fgetc(handle->file)) == EOF)
|
||||
return 0;
|
||||
if (c != '[') { /* not at a section name */
|
||||
LINE_SKIP(); /* so skip the line and try again */
|
||||
continue;
|
||||
}
|
||||
if ((c = getc(handle->file)) == EOF)
|
||||
return 0;
|
||||
cp = section; /* check the section name */
|
||||
CHECK_TOKEN();
|
||||
if (*cp == '\0' && c == ']') /* matched exactly? */
|
||||
break; /* win */
|
||||
LINE_SKIP();
|
||||
}
|
||||
|
||||
LINE_SKIP(); /* won, skip to first variable */
|
||||
}
|
||||
|
||||
#endif /* INSTALL_SNARK_READ_INI_FROM_MEMORY */
|
||||
|
||||
/*
|
||||
* Found the desired section. Cache it and return win.
|
||||
*/
|
||||
handle->section_name = section;
|
||||
handle->section_start = ini_get_pos(handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Scan the current section for the right variable.
|
||||
*/
|
||||
static char *ini_scan_for_variable
|
||||
(struct ini_handle *handle, char *variable)
|
||||
{
|
||||
if (!handle || !variable || !handle->buffer || handle->buflen <= 0)
|
||||
return 0;
|
||||
|
||||
#if INSTALL_SNARK_READ_INI_FROM_MEMORY
|
||||
|
||||
{
|
||||
for (;;) {
|
||||
if (!etc_ini_table[handle->current_pos].tag ||
|
||||
!etc_ini_table[handle->current_pos].value)
|
||||
return 0; /* end of section, lose */
|
||||
if (!STRICMP(variable, etc_ini_table[handle->current_pos].tag))
|
||||
break; /* matching variable tag, won */
|
||||
handle->current_pos++; /* otherwise, keep looking */
|
||||
}
|
||||
|
||||
if (STRLEN(etc_ini_table[handle->current_pos].value) >= handle->buflen)
|
||||
return 0; /* buffer too small, lose */
|
||||
|
||||
STRCPY(handle->buffer, etc_ini_table[handle->current_pos].value);
|
||||
handle->current_pos++; /* won, skip over line we just read */
|
||||
}
|
||||
|
||||
#else /* INSTALL_SNARK_READ_INI_FROM_MEMORY */
|
||||
|
||||
{
|
||||
char *cp;
|
||||
int c;
|
||||
|
||||
if (!handle->file)
|
||||
return 0;
|
||||
|
||||
for (;;) {
|
||||
if ((c = fgetc(handle->file)) == EOF || c == '[')
|
||||
return 0;
|
||||
cp = variable; /* check the variable name */
|
||||
CHECK_TOKEN();
|
||||
if (*cp == '\0') {
|
||||
SKIP_WHITE();
|
||||
if (c == '=') /* and found right delimiter? */
|
||||
break; /* win */
|
||||
}
|
||||
LINE_SKIP(); /* didn't match, keep looking */
|
||||
}
|
||||
|
||||
if ((c = fgetc(handle->file)) == EOF)
|
||||
return 0;
|
||||
SKIP_WHITE();
|
||||
cp = handle->buffer; /* now copy the data */
|
||||
while (c != '\n') {
|
||||
*cp++ = c;
|
||||
if (cp >= handle->buffer + handle->buflen ||
|
||||
(c = fgetc(handle->file)) == EOF)
|
||||
return 0;
|
||||
}
|
||||
*cp = '\0';
|
||||
}
|
||||
|
||||
#endif /* INSTALL_SNARK_READ_INI_FROM_MEMORY */
|
||||
|
||||
return handle->buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *ini_lookup(struct ini_handle *handle, char *section, char *variable)
|
||||
{
|
||||
if (!handle || !ini_scan_for_section(handle, section))
|
||||
return 0;
|
||||
return ini_scan_for_variable(handle, variable);
|
||||
}
|
||||
|
||||
char *ini_iter_start(struct ini_handle *handle, char *section, char *variable)
|
||||
{
|
||||
if (!handle || !ini_scan_for_section(handle, section))
|
||||
return 0;
|
||||
return ini_scan_for_variable(handle, (handle->iter_variable = variable));
|
||||
}
|
||||
|
||||
char *ini_iter_next(struct ini_handle *handle)
|
||||
{
|
||||
if (!handle)
|
||||
return 0;
|
||||
return ini_scan_for_variable(handle, handle->iter_variable);
|
||||
}
|
||||
|
||||
void ini_save (struct ini_handle *handle, struct ini_handle_saved *save)
|
||||
{
|
||||
save->section_name = handle->section_name;
|
||||
save->section_start = handle->section_start;
|
||||
save->iter_variable = handle->iter_variable;
|
||||
save->current_pos = ini_get_pos(handle);
|
||||
}
|
||||
|
||||
void ini_restore (struct ini_handle *handle, struct ini_handle_saved *save)
|
||||
{
|
||||
handle->section_name = save->section_name;
|
||||
handle->section_start = save->section_start;
|
||||
handle->iter_variable = save->iter_variable;
|
||||
ini_set_pos(handle, save->current_pos);
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
# $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/read_ini.sed,v 1.1.1.1 2001/11/05 17:48:42 tneale Exp $
|
||||
|
||||
################################################################################
|
||||
# *** Restricted Rights Legend ***
|
||||
#
|
||||
# The programs and information contained herein are licensed only
|
||||
# pursuant to a license agreement that contains use, reverse
|
||||
# engineering, disclosure, and other restrictions; accordingly, it
|
||||
# is "Unpublished--all rights reserved under the applicable
|
||||
# copyright laws".
|
||||
#
|
||||
# Use duplication, or disclosure by the Government is subject to
|
||||
# restrictions as set forth in subparagraph (c)(1)(ii) of the Rights
|
||||
# in Technical Data and Computer Licensed Programs clause of DFARS
|
||||
# 52.227 7013.
|
||||
#
|
||||
# Copyright 2000-2001 Wind River Systems, Inc.
|
||||
# Copyright 1998 Integrated Systems, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# *** Government Use ***
|
||||
#
|
||||
# The Licensed Programs and their documentation were developed at
|
||||
# private expense and no part of them is in the public domain.
|
||||
#
|
||||
# The Licensed Programs are "Restricted Computer Software" as that
|
||||
# term is defined in Clause 52.227-19 of the Federal Acquisition
|
||||
# Regulations (FAR) and are "Commercial Computer Software" as that
|
||||
# term is defined in Subpart 227.401 of the Department of Defense
|
||||
# Federal Acquisition Regulation Supplement (DFARS).
|
||||
#
|
||||
# (i) If the licensed Programs are supplied to the Department of
|
||||
# Defense (DoD), the Licensed Programs are classified as
|
||||
# "Commercial Computer Software" and the Government is acquiring
|
||||
# only "restricted rights" in the Licensed Programs and their
|
||||
# documentation as that term is defined in Clause 52.227
|
||||
# 7013(c)(1) of the DFARS, and
|
||||
#
|
||||
# (ii) If the Licensed Programs are supplied to any unit or agency
|
||||
# of the United States Government other than DoD, the
|
||||
# Government's rights in the Licensed Programs and their
|
||||
# documentation will be as defined in Clause 52.227-19(c)(2) of
|
||||
# the FAR.
|
||||
################################################################################
|
||||
|
||||
# sed script to convert from one of the two formats that snark/lib/read_ini.c
|
||||
# knows how to read to the other format.
|
||||
#
|
||||
# Ordinarily, the demo configuration routines in read_ini load configuration
|
||||
# data from a file called etc.ini. However, this does not make a very good
|
||||
# demo on embedded systems where there is no filesystem, so these routines
|
||||
# can also be configured to load configuration information from a static array.
|
||||
# This is still not particularly efficient (if you want efficency, use the
|
||||
# real configuration APIs for the various Epilogue products), but it is fairly
|
||||
# to use and thus makes a reasonable demo.
|
||||
#
|
||||
# Rather than having to maintain two sets of configuration files, you can write
|
||||
# configuration files in the normal etc.ini format and use this script to
|
||||
# convert them to the static array format that the snark demo package uses when
|
||||
# you've installed the SNARK_READ_INI_FROM_MEMORY configuration option.
|
||||
#
|
||||
# This script is intended to be used only on well-formed etc.ini files.
|
||||
# It does not attempt to detect every possible format violation, and it
|
||||
# transcribes etc.ini comments to C comments without checking them for
|
||||
# possible nested C comments. We do try to do appropriate quoting for
|
||||
# doublequote and backslash as supported by snark/lib/parse.c.
|
||||
#
|
||||
# This script works on all the versions of sed where we've tried it.
|
||||
# Rumor has it that some versions of sed are so abysmally stupid that
|
||||
# they will only tolerate a single comment on the first line of a script.
|
||||
# If you get weird errors trying to use this script, try deleting all the
|
||||
# comments to see if that helps....
|
||||
|
||||
# Header boilerplate
|
||||
#
|
||||
1i\
|
||||
/*\
|
||||
\ * Automatically generated file. You may choose to modify this file\
|
||||
\ * by hand, but beware of accidently overwriting it.\
|
||||
\ */\
|
||||
\
|
||||
#include <common/h/config.h>\
|
||||
#include <common/h/glue.h>\
|
||||
#include <snark/h/read_ini.h>\
|
||||
\
|
||||
struct ini_table etc_ini_table[] = {
|
||||
|
||||
# Trailer boilerplate
|
||||
#
|
||||
$a\
|
||||
\ \ { 0, 0 }\
|
||||
};
|
||||
|
||||
# Delete comments and blank lines
|
||||
#
|
||||
/^[ ]*$/D
|
||||
/^[ ]*;/D
|
||||
|
||||
# Handle section headers
|
||||
#
|
||||
/^[ ]*\[/ {
|
||||
s|^[ ]*\[| { "|
|
||||
s|\][ ]*$|", 0 },|
|
||||
b
|
||||
}
|
||||
|
||||
# Handle variable assignments
|
||||
/=/ {
|
||||
s|\\|\\\\|g
|
||||
s|"|\\"|g
|
||||
s|^[ ]*| { "|
|
||||
s|[ ]*=[ ]*|", "|
|
||||
s|[ ]*$|" },|
|
||||
b
|
||||
}
|
||||
|
||||
# Delete anything else
|
||||
#
|
||||
D
|
||||
@@ -0,0 +1,199 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/relay.c,v 1.3 2003/01/15 14:04:34 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1990-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: relay.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:34 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:26 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:42 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.7 2001/01/19 22:23:51 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.6 2000/03/17 00:12:44 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.5 1998/09/18 19:56:24 meister
|
||||
* timer call renaming tm_ --> etc_tm_
|
||||
*
|
||||
* Revision 2.4 1998/06/03 21:24:47 sar
|
||||
* Updated code to use common string macros
|
||||
*
|
||||
* Revision 2.3 1998/02/25 15:21:49 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 2.2 1998/02/25 04:57:37 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.1 1997/04/25 05:43:23 sra
|
||||
* Still hacking PCL-725 relay boards after all these years.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Control code for PCL-725 relay board (of "Internet Toaster" fame).
|
||||
*
|
||||
* To build a standalone control program for the relay board,
|
||||
* compile with -DRELAY_STANDALONE
|
||||
*
|
||||
* Yes, the conditional compilation in this file is ugly. This is
|
||||
* code that we use at trade shows, we don't really expect our
|
||||
* customers to ever try to turn this on.
|
||||
*/
|
||||
|
||||
#ifndef RELAY_PORT
|
||||
#define RELAY_PORT 0x2a8
|
||||
#endif
|
||||
|
||||
#if defined(RELAY_STANDALONE)
|
||||
|
||||
typedef unsigned char bits8_t;
|
||||
|
||||
#else /* RELAY_STANDALONE */
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
#include <wrn/wm/demo/relay.h>
|
||||
|
||||
#endif /* RELAY_STANDALONE */
|
||||
|
||||
#if defined(INSTALL_on_msdos) || defined(MSDOS)
|
||||
|
||||
/*
|
||||
* DOS, I forget which compiler, probably BCC.
|
||||
*/
|
||||
|
||||
#include <dos.h>
|
||||
|
||||
#define PORT_READ __inportb__
|
||||
#define PORT_WRITE __outportb__
|
||||
#define PORT_INIT()
|
||||
|
||||
#elif defined(__FreeBSD__)
|
||||
|
||||
/*
|
||||
* FreeBSD. Yes, this really does open a file descriptor which is
|
||||
* never used again, that's how raw hardware I/O works on FreeBSD.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/file.h>
|
||||
#include <machine/pio.h>
|
||||
|
||||
static int relay_fd = -1;
|
||||
|
||||
#define PORT_READ inb
|
||||
#define PORT_WRITE outb
|
||||
#define PORT_INIT() \
|
||||
do { \
|
||||
if (relay_fd < 0 && (relay_fd = open("/dev/io", O_RDONLY, 0666)) < 0) \
|
||||
abort(); \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
|
||||
#error Sorry, no PCL-725 support for this platform yet.
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Read relay state, one bit per relay.
|
||||
*/
|
||||
bits8_t relay_read(void)
|
||||
{
|
||||
PORT_INIT();
|
||||
return PORT_READ(RELAY_PORT);
|
||||
}
|
||||
|
||||
/*
|
||||
* Write relay state, one bit per relay.
|
||||
*/
|
||||
void relay_write(bits8_t bits)
|
||||
{
|
||||
PORT_INIT();
|
||||
PORT_WRITE(RELAY_PORT, bits);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined(RELAY_STANDALONE)
|
||||
|
||||
/*
|
||||
* Standalone program to twiddle the relays.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
if (argc > 1)
|
||||
relay_write(STRTOUL(argv[1], 0, 16));
|
||||
else
|
||||
printf("Relay state %02x\n", relay_read());
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* RELAY_STANDALONE */
|
||||
|
||||
/*
|
||||
* Attache timer based routines for demos.
|
||||
* Could trivially add Envoy timers here if we ever need that.
|
||||
*/
|
||||
|
||||
#if defined(INSTALL_ATTACHE) && INSTALL_ATTACHE
|
||||
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
|
||||
static struct timer relay_timer;
|
||||
static bits8_t relay_reset_state;
|
||||
|
||||
static void relay_handler(struct timer *tm, void *cookie)
|
||||
{
|
||||
relay_write(relay_reset_state);
|
||||
}
|
||||
|
||||
void relay_start(bits8_t state1, bits32_t delay, bits8_t state2)
|
||||
{
|
||||
if (!relay_timer.handler) {
|
||||
etc_tm_init(&relay_timer);
|
||||
relay_timer.handler = relay_handler;
|
||||
}
|
||||
relay_reset_state = state2;
|
||||
relay_write(state1);
|
||||
etc_tm_set(&relay_timer, delay);
|
||||
}
|
||||
|
||||
#endif /* INSTALL_ATTACHE */
|
||||
|
||||
#endif /* RELAY_STANDALONE */
|
||||
@@ -0,0 +1,548 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/slipbsd.c,v 1.3 2003/01/15 14:04:34 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: slipbsd.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:34 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:26 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.14 2001/01/19 22:23:51 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.13 2000/10/16 19:21:54 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 2.12 2000/03/17 00:12:44 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.11 2000/03/13 21:22:08 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 2.10 1999/11/05 22:29:07 paul
|
||||
* Updated driver structs to reflect conditional backwards-compatibility
|
||||
* fields and new fields.
|
||||
*
|
||||
* Revision 2.9 1999/04/07 14:57:00 sra
|
||||
* Update COM_DEV_NAME to something sane.
|
||||
*
|
||||
* Revision 2.8 1998/02/25 15:21:50 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 2.7 1998/02/25 04:57:37 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.6 1997/03/20 06:53:10 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.5 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.4 1997/02/19 08:10:29 sra
|
||||
* More fun merging snmptalk into snark, general snark cleanup.
|
||||
*
|
||||
* Revision 2.3 1996/11/13 15:09:16 mrf
|
||||
* Changes necessary to make snoop support work on Irix 5.x include
|
||||
* addition of snoop driver code and port to somewhat wacky Irix
|
||||
* curses implementation.
|
||||
*
|
||||
* Revision 2.2 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.1 1995/11/16 00:33:13 sra
|
||||
* Fix a format string to make gcc -paranoid happier.
|
||||
* Rearrange file header per current conventions.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.4 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.3 1994/09/04 06:13:38 sra
|
||||
* Clean up antique type names and install macros.
|
||||
*
|
||||
* Revision 1.2 1994/01/09 23:57:29 sra
|
||||
* Add support for NIT under SunOS 4.1.2.
|
||||
*
|
||||
* Revision 1.1 1993/07/05 21:53:30 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Serial Line IP (SLIP) interface for snark under BSD-derived systems.
|
||||
*
|
||||
* This code has only been tested under NetBSD 0.8. It should work on
|
||||
* any BSD-derived system with minor modifications.
|
||||
*/
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/loop.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sgtty.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <wrn/wm/demo/bsdif.h>
|
||||
#include <wrn/wm/demo/slipbsd.h>
|
||||
|
||||
#define PF_SLIP_BOP 0x1000
|
||||
|
||||
#ifndef COM_DEV_NAME
|
||||
#define COM_DEV_NAME "/dev/cuaa"
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* SLIP control structure, hangs off net->specific->private.
|
||||
*/
|
||||
|
||||
#ifndef SNARKBSD_SLIP_IBUFLEN
|
||||
#define SNARKBSD_SLIP_IBUFLEN 1000
|
||||
#endif
|
||||
|
||||
#ifndef SNARKBSD_SLIP_OBUFLEN
|
||||
#define SNARKBSD_SLIP_OBUFLEN 6000
|
||||
#endif
|
||||
|
||||
struct slipctl {
|
||||
struct net *net;
|
||||
unsigned iescaped : 1;
|
||||
unsigned idiscard : 1;
|
||||
unsigned oescaped : 1;
|
||||
packet *ipkt, *opkt_head, **opkt_tail;
|
||||
int ilen, olen;
|
||||
unsigned char *ibp, *obp;
|
||||
unsigned char ibuf[SNARKBSD_SLIP_IBUFLEN], obuf[SNARKBSD_SLIP_OBUFLEN];
|
||||
};
|
||||
|
||||
/*
|
||||
* SLIP framing characters
|
||||
*/
|
||||
#define SLIP_END 0300
|
||||
#define SLIP_ESC 0333
|
||||
#define SLIP_ENC_END 0334
|
||||
#define SLIP_ENC_ESC 0335
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Decode a buffer of data into zero or more Attache packet buffers.
|
||||
* Most of the hair is just checking for weird boundary conditions.
|
||||
*/
|
||||
|
||||
#define DOCHAR(x) \
|
||||
if (sp->idiscard) { \
|
||||
continue; \
|
||||
} else if (p->pkt_data < p->pkt_buffer + p->pkt_buflen) { \
|
||||
*p->pkt_data++ = (x); \
|
||||
} else { \
|
||||
sp->idiscard = 1; \
|
||||
continue; \
|
||||
}
|
||||
|
||||
static packet *slip_decode
|
||||
(struct net *net, unsigned char *buf, int len, int *used)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
struct slipctl *sp = bif->private;
|
||||
unsigned char *bob = buf, *eob = buf + len;
|
||||
packet *p;
|
||||
|
||||
while (buf < eob) {
|
||||
if (sp->ipkt == 0 && (sp->ipkt = pkt_alloc(net->driver->maxlen)) == 0)
|
||||
break; /* Oops, no packet buffers */
|
||||
p = sp->ipkt;
|
||||
if (sp->iescaped) { /* Was escaped */
|
||||
sp->iescaped = 0; /* ain't no more */
|
||||
switch (*buf++) {
|
||||
case SLIP_ENC_END:
|
||||
DOCHAR(SLIP_END); /* Escaped END character */
|
||||
continue;
|
||||
case SLIP_ENC_ESC:
|
||||
DOCHAR(SLIP_ESC); /* Escaped ESC character */
|
||||
continue;
|
||||
default:
|
||||
sp->idiscard = 1; /* Escaped garbage, packet be bogus */
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
switch (*buf++) {
|
||||
case SLIP_END:
|
||||
if (!sp->idiscard && p->pkt_data > p->pkt_buffer) {
|
||||
sp->ipkt = 0;
|
||||
p->pkt_datalen = p->pkt_data - p->pkt_buffer;
|
||||
p->pkt_data = p->pkt_buffer;
|
||||
if (used)
|
||||
*used = buf - bob;
|
||||
return p; /* Happy packet */
|
||||
}
|
||||
sp->idiscard = 0; /* Bogus packet now history */
|
||||
p->pkt_data = p->pkt_buffer;
|
||||
continue;
|
||||
case SLIP_ESC:
|
||||
sp->iescaped = 1; /* An escaping byte! */
|
||||
continue;
|
||||
default:
|
||||
DOCHAR(*(buf-1)); /* A normal boring byte */
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (used)
|
||||
*used = buf - bob;
|
||||
return 0; /* Yes, we have no packet today */
|
||||
}
|
||||
|
||||
#undef DOCHAR
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Encode zero or more Attache packet buffers into a data buffer.
|
||||
* Packets will have been queued for us by slip_send().
|
||||
*/
|
||||
|
||||
#define DOCHAR(x) \
|
||||
do { *buf++ = (x); if (buf == eob) return (buf - bob); } while (0)
|
||||
|
||||
static int slip_encode(struct net *net, unsigned char *buf, int len)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
struct slipctl *sp = bif->private;
|
||||
unsigned char *bob = buf, *eob = buf + len;
|
||||
packet *p;
|
||||
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
while ((p = sp->opkt_head) != 0) {
|
||||
|
||||
/*
|
||||
* Send framing sequence before a new packet, to flush line noise.
|
||||
*/
|
||||
if ((p->pkt_flags & PF_SLIP_BOP) != 0) {
|
||||
p->pkt_flags &= ~PF_SLIP_BOP;
|
||||
DOCHAR(SLIP_END);
|
||||
}
|
||||
|
||||
/*
|
||||
* Process data in this packet.
|
||||
*/
|
||||
while (p->pkt_datalen > 0) {
|
||||
if (sp->oescaped) {
|
||||
sp->oescaped = 0; /* Was escaped, ain't no more */
|
||||
switch (*p->pkt_data++) {
|
||||
case SLIP_END: /* Encoding an END octet */
|
||||
DOCHAR(SLIP_ENC_END);
|
||||
break;
|
||||
case SLIP_ESC: /* Encoding an ESC octet */
|
||||
DOCHAR(SLIP_ENC_ESC);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (*p->pkt_data) {
|
||||
case SLIP_END: /* I need an escape */
|
||||
case SLIP_ESC:
|
||||
sp->oescaped = 1;
|
||||
DOCHAR(SLIP_ESC);
|
||||
continue; /* Doesn't count as sent yet */
|
||||
default:
|
||||
DOCHAR(*p->pkt_data++); /* Normal octet, send it */
|
||||
}
|
||||
}
|
||||
p->pkt_datalen--; /* One less octet to feed */
|
||||
}
|
||||
|
||||
/*
|
||||
* No more data in current packet, so send framing sequence
|
||||
* and proceed with next packet in the output queue.
|
||||
*/
|
||||
DOCHAR(SLIP_END);
|
||||
if ((sp->opkt_head = p->pkt_link) == 0)
|
||||
sp->opkt_tail = &sp->opkt_head;
|
||||
pkt_free(p);
|
||||
}
|
||||
|
||||
return buf - bob;
|
||||
}
|
||||
|
||||
#undef DOCHAR
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Process whatever incoming SLIP data we can without blocking,
|
||||
* passing zero or more Attache packets to ip_rcv().
|
||||
*/
|
||||
|
||||
static void slip_rcv(struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
struct slipctl *sp = bif->private;
|
||||
packet *p;
|
||||
int n;
|
||||
|
||||
if (sp->ilen <= 0) {
|
||||
do {
|
||||
n = read(bif->fd, (char *) sp->ibuf, sizeof(sp->ibuf));
|
||||
} while (n < 0 && errno == EINTR);
|
||||
if (n == 0 || (n < 0 && errno != EWOULDBLOCK)) {
|
||||
bif->flags &= ~BSDIF_READ;
|
||||
return;
|
||||
}
|
||||
sp->ilen = n;
|
||||
sp->ibp = sp->ibuf;
|
||||
}
|
||||
|
||||
while (sp->ilen > 0) {
|
||||
if ((p = slip_decode(net, sp->ibp, sp->ilen, &n)) != 0) {
|
||||
p->pkt_n = net;
|
||||
ip_rcv(p);
|
||||
}
|
||||
if (n == 0) /* out of packet buffers, try again later */
|
||||
break;
|
||||
sp->ibp += n; /* count what we consumed */
|
||||
sp->ilen -= n;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Process whatever outgoing Attache packets we can without blocking.
|
||||
* Generates zero or more writes of encoded SLIP data.
|
||||
*/
|
||||
|
||||
static void slip_snd(struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
struct slipctl *sp = bif->private;
|
||||
int n;
|
||||
|
||||
for (;;) {
|
||||
if (sp->olen == 0) {
|
||||
if ((n = slip_encode(net, sp->obuf, sizeof(sp->obuf))) == 0)
|
||||
break;
|
||||
sp->olen = n;
|
||||
sp->obp = sp->obuf;
|
||||
}
|
||||
do {
|
||||
n = write(bif->fd, sp->obp, sp->olen);
|
||||
} while (n < 0 && errno == EINTR);
|
||||
if (n <= 0)
|
||||
break;
|
||||
sp->obp += n;
|
||||
sp->olen -= n;
|
||||
}
|
||||
if (n == 0 || (n < 0 && errno != EWOULDBLOCK))
|
||||
bif->flags &= ~BSDIF_WRITE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle events detected by generic NetBSD I/O loop.
|
||||
* The flags tell us what kind of event happened, we call the
|
||||
* non-blocking I/O routines to do the real work.
|
||||
*/
|
||||
|
||||
static void slip_handler(int fd, void *net, unsigned flags)
|
||||
{
|
||||
if ((flags & BSDIF_WRITE) != 0)
|
||||
slip_snd(net);
|
||||
if ((flags & BSDIF_READ) != 0)
|
||||
slip_rcv(net);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Convert between raw line speed numbers and NetBSD line speed codes.
|
||||
* The second argument names the thing you want as the return value.
|
||||
*/
|
||||
|
||||
enum speed_index { slip_speed_number, slip_speed_symbol };
|
||||
|
||||
static int slip_speed(int speed, enum speed_index speed_index)
|
||||
{
|
||||
int i;
|
||||
static int table[][2] = {
|
||||
{ 1200, B1200 }, { 2400, B2400 }, { 4800, B4800 },
|
||||
{ 9600, B9600 }, { 19200, EXTA }, { 38400, EXTB }
|
||||
};
|
||||
|
||||
for (i = 0; i < sizeof(table)/sizeof(*table); ++i)
|
||||
if (table[i][!speed_index] == speed)
|
||||
return table[i][speed_index];
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Attache device driver routines.
|
||||
*/
|
||||
|
||||
static void slip_ip_send(struct net *net, packet *p, inaddr_t host)
|
||||
{
|
||||
p->pkt_n = net;
|
||||
(*net->driver->send)(p); /* Not much to do here, huh? */
|
||||
}
|
||||
|
||||
static void slip_send(packet *p)
|
||||
{
|
||||
struct net *net = p->pkt_n;
|
||||
struct bsdif *bif = net->specific;
|
||||
struct slipctl *sp = bif->private;
|
||||
|
||||
p->pkt_flags |= PF_SLIP_BOP; /* Flag that this is a new packet */
|
||||
|
||||
p->pkt_link = 0; /* Stuff this packet into the */
|
||||
*sp->opkt_tail = p; /* output queue */
|
||||
sp->opkt_tail = &p->pkt_link;
|
||||
|
||||
bif->flags |= BSDIF_WRITE; /* Now interested in output events */
|
||||
slip_snd(net); /* Send what we can right away */
|
||||
}
|
||||
|
||||
static void slip_close(struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
bif->flags &= ~(BSDIF_READ | BSDIF_WRITE);
|
||||
|
||||
if (bif->fd >= 0) {
|
||||
(void) close(bif->fd); /* Clean up our file if we had one */
|
||||
bif->fd = -1;
|
||||
}
|
||||
if (bif->private) {
|
||||
GLUE_FREE(bif->private); /* Release our memory if we had any */
|
||||
bif->private = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void slip_init(struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
struct slipctl *sp;
|
||||
struct sgttyb sgtty;
|
||||
char name[sizeof(COM_DEV_NAME)+4];
|
||||
int speed = slip_speed(net->speed, slip_speed_symbol);
|
||||
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
|
||||
sprintf(name, "%s%d", COM_DEV_NAME, net->instance);
|
||||
|
||||
if (!speed) {
|
||||
fprintf(stderr, "line speed %lu not supported\n", net->speed);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((bif->private = sp = GLUE_ALLOC(sizeof(*sp))) == 0) {
|
||||
fprintf(stderr, "couldn't allocate slip control structure\n");
|
||||
return;
|
||||
}
|
||||
MEMSET(sp, 0, sizeof(*sp));
|
||||
sp->opkt_tail = &sp->opkt_head;
|
||||
sp->net = net;
|
||||
|
||||
sgtty.sg_flags = RAW | ANYP;
|
||||
sgtty.sg_ispeed = sgtty.sg_ospeed = speed;
|
||||
|
||||
if ((bif->fd = open(name, O_RDWR, 0660)) < 0) { /* |O_NONBLOCK */
|
||||
perror("couldn't open slip device");
|
||||
} else if (ioctl(bif->fd, TIOCSETP, &sgtty) < 0) {
|
||||
perror("couldn't set slip line flags and speed");
|
||||
} else if (fcntl(bif->fd, F_SETFL, FNDELAY) < 0) {
|
||||
perror("unable to set slip pty non-blocking");
|
||||
} else {
|
||||
bif->handler = slip_handler;
|
||||
bif->flags |= BSDIF_READ;
|
||||
net->flags &= ~NF_DRIVER_DOWN;
|
||||
return; /* success */
|
||||
}
|
||||
slip_close(net); /* failure */
|
||||
}
|
||||
|
||||
static struct driver slip_driver = {
|
||||
slip_init, /* Init routine */
|
||||
slip_send, /* Raw send routine */
|
||||
slip_ip_send, /* IP packet send routine */
|
||||
0, 0, /* ARP and test close routines */
|
||||
slip_close, /* Close routine */
|
||||
"sl", /* Driver name prefix */
|
||||
"Serial Line IP", /* Driver name */
|
||||
0, 0, /* Net header and trailer lengths */
|
||||
296, /* Max packet size */
|
||||
IF_SLIP, /* MIB interface type */
|
||||
0, /* ARP hardware type (none) */
|
||||
0, /* media control */
|
||||
0, /* IPv6 send */
|
||||
0 /* IPv4 send */
|
||||
};
|
||||
|
||||
void slip_driver_find
|
||||
(void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t))
|
||||
{
|
||||
char name[sizeof(COM_DEV_NAME)+4];
|
||||
struct sgttyb sgtty;
|
||||
int fd, speed, instance;
|
||||
|
||||
for (instance = 0; ; instance++) {
|
||||
sprintf(name, "%s%d", COM_DEV_NAME, instance);
|
||||
if ((fd = open(name, O_RDONLY | O_NONBLOCK)) < 0) {
|
||||
if (errno == ENOENT)
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
speed = ((ioctl(fd, TIOCGETP, &sgtty) < 0)
|
||||
? 0 : slip_speed(sgtty.sg_ispeed, slip_speed_number));
|
||||
(void) close(fd);
|
||||
if (speed == 0)
|
||||
continue;
|
||||
sprintf(name, "%d", instance);
|
||||
config(name, &slip_driver, instance, 0,
|
||||
slip_driver.maxlen - slip_driver.lnh - slip_driver.lnt, speed);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,428 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/snarkdos.c,v 1.3 2003/01/15 14:04:35 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: snarkdos.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:35 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:26 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.18 2001/01/19 22:23:52 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.17 2000/03/17 00:12:45 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.16 1998/09/04 04:00:08 sar
|
||||
* modified some #if statements to use #ifdef as they were testing
|
||||
* items that might not be defined - INSTALL_on_* options.
|
||||
*
|
||||
* Revision 2.15 1998/07/17 18:58:43 sra
|
||||
* Swap and checksum routines moved to separate files.
|
||||
*
|
||||
* Revision 2.14 1998/07/02 06:55:39 sra
|
||||
* Make Snark restartable under pSOS, and other minor cleanups.
|
||||
*
|
||||
* Revision 2.13 1998/02/25 15:21:51 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 2.12 1998/02/25 04:57:39 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.11 1997/10/29 22:23:20 sar
|
||||
* moved the call to envoy_init() from snmp_init() in snmpfunc.c to
|
||||
* snark_init() in snarkbsd.c & snarkdos.c
|
||||
*
|
||||
* Revision 2.10 1997/03/20 06:53:11 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.9 1997/03/19 22:05:52 sra
|
||||
* Perhaps we should include install.h before testing install options?
|
||||
*
|
||||
* Revision 2.8 1997/03/19 04:47:35 sra
|
||||
* Get rid of some gratuitous historical dependencies on Attache.
|
||||
*
|
||||
* Revision 2.7 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.6 1997/02/24 00:56:59 sra
|
||||
* Support for run-time configuration of BUG() macros.
|
||||
*
|
||||
* Revision 2.5 1997/02/19 08:10:29 sra
|
||||
* More fun merging snmptalk into snark, general snark cleanup.
|
||||
*
|
||||
* Revision 2.4 1997/01/08 01:20:46 sar
|
||||
* Moved the glue_pkt_handle routine from snark*.c to loopglue.c
|
||||
* and added loopglue.c to the base object list.
|
||||
*
|
||||
* Revision 2.3 1996/10/31 01:16:15 sra
|
||||
* Why are we getting warnings from magic DOS incantations that have been
|
||||
* stable for years?
|
||||
*
|
||||
* Revision 2.2 1996/10/26 17:30:30 sra
|
||||
* BCC 4.0 sure is fussy about parameter lists.
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.11 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.10 1994/12/20 23:10:56 sra
|
||||
* Twiddle type signature of a pointer to function to make MSC 7.0 happy.
|
||||
* Fix sense of interrupt flag test.
|
||||
*
|
||||
* Revision 1.9 1994/09/04 06:13:38 sra
|
||||
* Clean up antique type names and install macros.
|
||||
*
|
||||
* Revision 1.8 1993/08/03 01:29:13 sra
|
||||
* Add a cast to glue_cksum() for MSC 7.0.
|
||||
*
|
||||
* Revision 1.7 1993/08/01 23:57:40 sra
|
||||
* Add in Dave's changes to make this work with Microsoft C.
|
||||
*
|
||||
* Revision 1.6 1993/08/01 21:31:01 sra
|
||||
* Fiddle byte-swap routines a little. Fix DOS keyboard/screen I/O to
|
||||
* work aproximately as we'd like: it's still not perfect, but it's now
|
||||
* close enough to be useful as a telnet client.
|
||||
*
|
||||
* Revision 1.5 1993/08/01 07:11:38 sra
|
||||
* Minor cleanup. DOS keyboard/screen interface not quite right yet, but
|
||||
* this is just demo code, I never claimed to be a DOS programmer....
|
||||
*
|
||||
* Revision 1.4 1993/07/31 23:26:33 sra
|
||||
* Add keyboard_write().
|
||||
*
|
||||
* Revision 1.3 1993/07/30 23:44:56 sra
|
||||
* Cosmetic changes to make Borland C++ 3.1 happy.
|
||||
*
|
||||
* Revision 1.2 1993/07/30 22:26:03 sra
|
||||
* Initial working version.
|
||||
*
|
||||
* Revision 1.1 1993/07/30 02:41:24 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Implementation of snark for MS-DOS with FTP Software spec packet drivers.
|
||||
* You should probably have ANSI.SYS (or replacement) loaded too.
|
||||
*/
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/loop.h>
|
||||
#endif
|
||||
|
||||
#if INSTALL_ENVOY
|
||||
#include <wrn/wm/snmp/engine/snmpdefs.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <dos.h>
|
||||
#include <conio.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
#include <wrn/wm/demo/netconf.h>
|
||||
#include <wrn/wm/demo/pktdrive.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* These are defined here rather than in snark/lib/main.c so that this
|
||||
* code can be used without that module if the customer so desires.
|
||||
*/
|
||||
int snark_exit_flag, snark_exit_value;
|
||||
|
||||
/*
|
||||
* These suppress spurious warnings from Borland C++ 3.1.
|
||||
*/
|
||||
static void clock_init(void), clock_shutdown(void);
|
||||
static unsigned char kbd_getch(void);
|
||||
static int kbd_kbhit(void);
|
||||
|
||||
/*
|
||||
* Some macros to make MSC-style code work with BCC.
|
||||
*/
|
||||
#ifdef INSTALL_on_bcc
|
||||
#define _asm asm
|
||||
#define _interrupt interrupt
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Timer interrupt routines. This is all PC-hardware specific.
|
||||
*/
|
||||
|
||||
#define CLOCK_INT 0x1c
|
||||
#define CLOCK_MS_PER_TICK 54
|
||||
|
||||
#ifdef INSTALL_on_bcc
|
||||
typedef void interrupt (*old_clock_int_t)(void);
|
||||
#endif
|
||||
|
||||
#ifdef INSTALL_on_microsoft
|
||||
typedef void (__cdecl __interrupt __far *old_clock_int_t)(void);
|
||||
#endif
|
||||
|
||||
static old_clock_int_t old_clock_int = 0;
|
||||
|
||||
static bits32_t cticks;
|
||||
|
||||
/* The clock tick handler */
|
||||
static void _interrupt clock_tick()
|
||||
{
|
||||
cticks++;
|
||||
old_clock_int();
|
||||
}
|
||||
|
||||
/* Set up the clock so we start seeing ticks. */
|
||||
static void clock_init()
|
||||
{
|
||||
if (!old_clock_int) {
|
||||
old_clock_int = (old_clock_int_t) _dos_getvect(CLOCK_INT);
|
||||
_dos_setvect(CLOCK_INT, clock_tick);
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up the clock so we can exit. */
|
||||
static void clock_shutdown()
|
||||
{
|
||||
if (old_clock_int)
|
||||
_dos_setvect(CLOCK_INT, old_clock_int);
|
||||
}
|
||||
|
||||
/* This routine implements Attache's GLUE_NOW() function. */
|
||||
bits32_t glue_now()
|
||||
{
|
||||
return cticks * CLOCK_MS_PER_TICK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Disable interrupts if argument is 0, otherwise enables interrupts.
|
||||
* Returns previous interrupt state.
|
||||
*/
|
||||
int glue_intlock(int x)
|
||||
{
|
||||
unsigned int interrupt_flag;
|
||||
|
||||
/*
|
||||
* interrupt_flag = _FLAGS;
|
||||
*/
|
||||
_asm pushf
|
||||
_asm pop ax
|
||||
_asm mov interrupt_flag, ax
|
||||
|
||||
if (x)
|
||||
_enable();
|
||||
else
|
||||
_disable();
|
||||
return (interrupt_flag & 0x200) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Low-level keyboard handler stuff. */
|
||||
|
||||
static void (*kbd_handler)(unsigned char *, size_t);
|
||||
|
||||
void keyboard_handler(void (*handler)(unsigned char *, size_t))
|
||||
{
|
||||
kbd_handler = handler;
|
||||
}
|
||||
|
||||
/*
|
||||
* Low-level DOS I/O routines. We don't use library functions
|
||||
* because they don't do what we want for ANSI.SYS escape sequences
|
||||
* and Control-C handling on input.
|
||||
*/
|
||||
|
||||
static unsigned char kbd_getch()
|
||||
{
|
||||
union REGS i, o;
|
||||
|
||||
i.h.ah = 0x07; /* Direct console input without echo */
|
||||
intdos(&i, &o);
|
||||
return o.h.al; /* Return character we got */
|
||||
}
|
||||
|
||||
static int kbd_kbhit()
|
||||
{
|
||||
union REGS i, o;
|
||||
|
||||
i.x.ax = 0x4406; /* IOCTL get input status */
|
||||
i.x.bx = 0x0000; /* 0 = stdin */
|
||||
intdos(&i, &o);
|
||||
return (int) o.h.al; /* Return non-zero if device ready */
|
||||
}
|
||||
|
||||
/*
|
||||
* Send a string to the local screen.
|
||||
*/
|
||||
void keyboard_write(unsigned char *text, size_t length)
|
||||
{
|
||||
union REGS i, o;
|
||||
|
||||
if (!text)
|
||||
return;
|
||||
|
||||
i.h.ah = 0x06; /* Direct console output */
|
||||
|
||||
while (length-- > 0) {
|
||||
switch (*text) {
|
||||
case 0xFF: /* We can't output this character, sorry */
|
||||
text++; /* (DOS thinks it means do input instead) */
|
||||
continue;
|
||||
case '\n': /* NL -> CRLF */
|
||||
i.h.dl = '\r'; /* Write the CR */
|
||||
intdos(&i, &o); /* (fall through...) */
|
||||
default:
|
||||
i.h.dl = *text++;
|
||||
intdos(&i, &o);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* tasks_run() function, using system-independent tasking queue.
|
||||
*/
|
||||
|
||||
static bits32_t glue_callin_when;
|
||||
static void (*glue_callin_who)(void);
|
||||
|
||||
/* This is the function we use to provide GLUE_CALLIN(). */
|
||||
void glue_callin(bits32_t when, void (*who)(void))
|
||||
{
|
||||
glue_callin_when = when + glue_now();
|
||||
glue_callin_who = who;
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the main body of the task dispatcher.
|
||||
* If it ever returns, main() should exit immediately with the same value.
|
||||
*/
|
||||
int tasks_run()
|
||||
{
|
||||
struct task *task;
|
||||
|
||||
for (;;) {
|
||||
if (kbd_handler && kbd_kbhit()) {
|
||||
unsigned char c = kbd_getch();
|
||||
(*kbd_handler)(&c, 1);
|
||||
if (snark_exit_flag)
|
||||
break;
|
||||
}
|
||||
if ((task = task_deq()) != 0 && task->func != 0) {
|
||||
task->func(task, task->cookie);
|
||||
if (snark_exit_flag)
|
||||
break;
|
||||
}
|
||||
if (glue_callin_who &&
|
||||
((sbits32_t) (glue_callin_when - glue_now())) <= 0) {
|
||||
void (*who)(void) = glue_callin_who;
|
||||
glue_callin_who = 0;
|
||||
who();
|
||||
if (snark_exit_flag)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
snark_shutdown();
|
||||
return snark_exit_value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
|
||||
/*
|
||||
* Network configuration.
|
||||
*/
|
||||
|
||||
void netconfig_find()
|
||||
{
|
||||
pktd_driver_find(netconfig_if);
|
||||
}
|
||||
|
||||
#endif /* INSTALL_ATTACHE */
|
||||
|
||||
|
||||
|
||||
/* Initialization and shutdown. */
|
||||
|
||||
void snark_init()
|
||||
{
|
||||
clock_init();
|
||||
tasks_init();
|
||||
#if INSTALL_ATTACHE
|
||||
attache_init();
|
||||
#endif
|
||||
#if INSTALL_ENVOY
|
||||
envoy_init();
|
||||
#endif
|
||||
sty_init();
|
||||
#if INSTALL_ATTACHE
|
||||
netconfig();
|
||||
#endif
|
||||
#if INSTALL_SNARK_BUG_CONF
|
||||
bug_config();
|
||||
#endif
|
||||
}
|
||||
|
||||
void snark_shutdown()
|
||||
{
|
||||
#if INSTALL_ATTACHE && INSTALL_ATTACHE_SHUTDOWN
|
||||
attache_shutdown();
|
||||
#endif
|
||||
clock_shutdown();
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/snmp_att.c,v 1.3 2003/01/15 14:04:35 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: snmp_att.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:35 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:26 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.4 2001/01/19 22:23:52 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.3 2000/03/17 00:12:45 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.2 1998/07/06 01:04:56 sar
|
||||
* Add some casts and change atoi to strtol to make compilers happy
|
||||
*
|
||||
* Revision 1.1 1998/06/07 02:40:06 sar
|
||||
* Move the validate and timing routines to the snark library
|
||||
* so they can be used by multiple demos
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
|
||||
#include <wrn/wm/demo/snmpfunc.h>
|
||||
|
||||
#include <wrn/wm/snmp/engine/asn1conf.h>
|
||||
#include <wrn/wm/snmp/engine/snmpdefs.h>
|
||||
#include <wrn/wm/snmp/engine/buffer.h>
|
||||
#include <wrn/wm/snmp/engine/proxy_tr.h>
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
#include <wrn/wm/attache/udp.h>
|
||||
|
||||
#if INSTALL_ATTACHE_DNS
|
||||
#include <wrn/wm/attache/dns.h>
|
||||
extern struct dns_config domain_config;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#if INSTALL_ENVOY_SNMP_PROXY
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
|
||||
/****************************************************************************
|
||||
NAME: proxy_dns_won
|
||||
|
||||
PURPOSE: Routine to send a packet after a dns lookup for a proxy
|
||||
|
||||
PARAMETERS:
|
||||
|
||||
RETURNS: void
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
void
|
||||
proxy_dns_won(struct dns_query *query,
|
||||
char *dname,
|
||||
int n,
|
||||
inaddr_t addrs[],
|
||||
void *cookie)
|
||||
{
|
||||
TRANS_STUFF_T *trans_stuff = cookie;
|
||||
|
||||
/* send the packet */
|
||||
if (n)
|
||||
udp_send_to((packet *)trans_stuff->pkt, addrs[0], trans_stuff->port, 161);
|
||||
|
||||
SNMP_memory_free(trans_stuff);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
NAME: proxy_dns_err
|
||||
|
||||
PURPOSE: Routine to cleanup after a filed dns lookup for a proxy
|
||||
|
||||
PARAMETERS:
|
||||
|
||||
RETURNS: void
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
void
|
||||
proxy_dns_err(struct dns_query *query,
|
||||
enum dns_error error,
|
||||
void *cookie)
|
||||
{
|
||||
TRANS_STUFF_T *trans_stuff = cookie;
|
||||
|
||||
/* just cleanup everything */
|
||||
udp_free((packet *)trans_stuff->pkt);
|
||||
SNMP_memory_free(trans_stuff);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
NAME: attache_proxy_send_rtn
|
||||
|
||||
PURPOSE: Routine to attempt to transmit a byte string for proxies
|
||||
|
||||
PARAMETERS:
|
||||
EBUFFER_T * The buffer to send
|
||||
PTR_T Information as to where to send the buffer.
|
||||
|
||||
RETURNS: INT_32_T A reasonable timeout period for this transport
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
INT_32_T
|
||||
attache_proxy_send_rtn(EBUFFER_T *ebuf,
|
||||
PTR_T cookie)
|
||||
{
|
||||
packet *pkt;
|
||||
TRANS_STUFF_T *tstuff_cp, *tstuff = (TRANS_STUFF_T *)cookie;
|
||||
|
||||
/* create a new trans stuff block to pass through the dns query */
|
||||
tstuff_cp =
|
||||
(TRANS_STUFF_T *)SNMP_memory_alloc(sizeof(TRANS_STUFF_T) +
|
||||
STRLEN((char *)(tstuff->addr_str)) + 1);
|
||||
if (tstuff_cp == 0)
|
||||
return(0);
|
||||
|
||||
/* fill it in, we zero the proxy block stuff as we aren't using it here */
|
||||
MEMSET(&tstuff_cp->pblockp, 0, sizeof(PROXY_BLOCK_T));
|
||||
tstuff_cp->addr_str = ((bits8_t *)tstuff) + sizeof(TRANS_STUFF_T);
|
||||
(void) STRCPY((char *)(tstuff_cp->addr_str), (char *)(tstuff->addr_str));
|
||||
tstuff_cp->port = tstuff->port;
|
||||
|
||||
/* create the udp packet to send and attach it to the trans stuff struct */
|
||||
if ((pkt = udp_alloc(EBufferUsed(ebuf), 0)) == 0) {
|
||||
SNMP_memory_free(tstuff_cp);
|
||||
return(0);
|
||||
}
|
||||
|
||||
MEMCPY(pkt->pkt_data, EBufferStart(ebuf), EBufferUsed(ebuf));
|
||||
tstuff_cp->pkt = (ptr_t)pkt;
|
||||
|
||||
/* send the name to the dns to be resolved, the won option
|
||||
will send the packet, the err option will clean up the packet */
|
||||
|
||||
dns_name_to_address((char *)(tstuff_cp->addr_str), proxy_dns_won,
|
||||
proxy_dns_err, &domain_config, 0, tstuff_cp);
|
||||
|
||||
return(1000);
|
||||
}
|
||||
|
||||
#endif /* INSTALL_ATTACHE */
|
||||
|
||||
#endif /* (INSTALL_ENVOY_SNMP_PROXY) */
|
||||
|
||||
@@ -0,0 +1,556 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/snmpconf.c,v 1.4 2003/01/15 14:04:35 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1991-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
Routines for parsing the snmp configuration information as well
|
||||
as a bunch of standard variable space, moved here from snmptalk/parse.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Log: snmpconf.c,v $
|
||||
* Revision 1.4 2003/01/15 14:04:35 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.3 2002/03/11 19:13:57 josh
|
||||
* dest_addr is now an ipaddr_t, and added a v6_scope for IPv6 support
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:27 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.6 2001/01/19 22:23:52 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.5 2000/03/17 00:12:45 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.4 1998/11/25 03:38:18 sra
|
||||
* "timeout" => "snmp_timeout" to fix OpEN symbol conflict.
|
||||
*
|
||||
* Revision 1.3 1998/10/28 18:51:01 josh
|
||||
* marging in courier-sep98 branch
|
||||
*
|
||||
* Revision 1.2.4.1 1998/09/12 19:27:33 sra
|
||||
* Minor kludges to make this development snapshot of snark compile with
|
||||
* the released versions of the Attache, Envoy, and Emissary products.
|
||||
* These changes will need to be un-done when this branch is merged back
|
||||
* into the main code base.
|
||||
*
|
||||
* Revision 1.2 1998/07/06 01:04:56 sar
|
||||
* Add some casts and change atoi to strtol to make compilers happy
|
||||
*
|
||||
* Revision 1.1 1998/06/23 20:40:57 sar
|
||||
* Moved the general snmp configuration code here from snmptalk/parse.c.
|
||||
* Also arranged for the snmp config routine to call the nv config routine
|
||||
* if necessary.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01b,19apr05,job update copyright notices
|
||||
01a,25mar05,job add an option handler for -a
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Revision history from when this was snmptalk/parse.c
|
||||
*
|
||||
*
|
||||
* Revision 7.13 1998/06/07 02:52:56 sar
|
||||
* Move the global configuration arguments to snark library
|
||||
*
|
||||
* Revision 7.12 1998/06/04 15:13:51 sar
|
||||
* Cleaned up some installation options to allow v3 to work if v2 isn't
|
||||
* installed
|
||||
*
|
||||
* Revision 7.11 1998/06/03 21:50:28 sar
|
||||
* Moved nvutils and nvviews to snark/lib so we can have one copy shared
|
||||
* amongst the demos
|
||||
* Moved the common string functions from stdf to common/lib and created
|
||||
* a series of macros for this code to use
|
||||
* Moved strdup to snark/lib and renamed it to etc_strdup to avoid
|
||||
* needing one from the system libraries
|
||||
*
|
||||
* Revision 7.10 1998/05/23 18:19:25 sar
|
||||
* Added global arguments for v3 along with their defaults
|
||||
*
|
||||
* Revision 7.9 1998/02/25 15:21:58 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 7.8 1998/02/25 04:58:00 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 7.7 1997/05/17 23:08:59 sra
|
||||
* Clean up some SunOS/gcc warnings.
|
||||
*
|
||||
* Revision 7.6 1997/03/20 06:53:53 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 7.5 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 7.4 1997/02/19 08:10:29 sra
|
||||
* More fun merging snmptalk into snark, general snark cleanup.
|
||||
*
|
||||
* Revision 7.3 1997/01/10 20:32:39 sra
|
||||
* Punt this copy of parse_line(), since there's a better one snark/lib.
|
||||
*
|
||||
* Revision 7.2 1997/01/08 23:26:53 sar
|
||||
* Updated include files to use envoy/h as appropriate after
|
||||
* move from envoy/utils to snark/snmptalk
|
||||
*
|
||||
* Revision 7.1 1997/01/08 02:00:21 sar
|
||||
* updated config_defaults to use snark read_ini code and removed outfile
|
||||
*
|
||||
* Revision 7.0 1996/03/18 20:19:20 sar
|
||||
* Updated rev to 7.0 and copyright to 96
|
||||
*
|
||||
* Revision 6.4 1996/01/26 22:05:01 sar
|
||||
* added a check to see if usec is installed when deciding what
|
||||
* to do about nv config files.
|
||||
*
|
||||
* Revision 6.3 1996/01/10 16:41:40 sar
|
||||
* Usec updates
|
||||
*
|
||||
* Revision 6.2 1995/11/11 00:09:41 sar
|
||||
* Added a new command option to decide where the rfc1445 viewtree
|
||||
* comes from - the config.txt file or nvviews.c
|
||||
*
|
||||
* Revision 6.1 1995/10/20 22:39:59 sar
|
||||
* remvoed dparty, sparty and context info
|
||||
*
|
||||
* Revision 6.0 1995/05/31 21:50:19 sra
|
||||
* Release 6.0.
|
||||
*
|
||||
* Revision 5.4 1995/03/21 00:50:48 sar
|
||||
* Added a packet_dump option to snmptalk, this allows the user to trun
|
||||
* packet dumping on & off while snmptalk is running.
|
||||
*
|
||||
* Revision 5.3 1994/11/09 01:43:52 sar
|
||||
* Read the nv config file if/when we need to. If the master_agent or
|
||||
* v2_view options are installed we always read it, if they aren't vut
|
||||
* v2 is installed we check the snmptalk_version flag if it is 2 we read
|
||||
* the file if it is 1 we don't. The first time we switch to v2 we
|
||||
* try and read the file and complain if one doesn't exist. If we only
|
||||
* have v1 installed we never read the config file.
|
||||
*
|
||||
* Revision 5.2 1994/09/23 19:29:50 sar
|
||||
* Removed the old non volatile scheme and added a new one that is hopefully
|
||||
* easier to use and allows for some new options such as a read only
|
||||
* flag to prohibit creating a new config file. The config stuff will
|
||||
* only be included if needed.
|
||||
* In snmptalk and snmpint added a next function.
|
||||
*
|
||||
* Revision 5.1 1994/07/24 15:41:03 dab
|
||||
* Added ability to set UDP port used by manager and the set command can
|
||||
* now specify enumerated integer values by symbolic name.
|
||||
*
|
||||
* Revision 5.0 1994/05/16 15:57:40 sar
|
||||
* Updated revision to 5.0 and copyright to include 1994
|
||||
*
|
||||
* Revision 4.2 1994/03/22 10:07:20 sra
|
||||
* Add "snmp-version" keyword to config file.
|
||||
*
|
||||
* Revision 4.1 1993/11/30 19:52:15 sar
|
||||
* Changed the initial source and destination parties and context to use
|
||||
* an ip address of 127.0.0.1.
|
||||
*
|
||||
* Revision 4.0 1993/06/24 17:14:56 sar
|
||||
* Updated rev to 4.0 and copyright to 93
|
||||
*
|
||||
* Revision 3.11 1993/06/13 02:48:16 sar
|
||||
* moved inclusion of stdf.h to be after asn1.h so that NO_PP will be defined
|
||||
* if desired.
|
||||
*
|
||||
* Revision 3.10 1993/06/09 20:00:50 dab
|
||||
* need <types.h> to get NO_PP
|
||||
*
|
||||
* Revision 3.9 1993/05/19 20:38:22 sar
|
||||
* Added procedure prototypes to some of the routines. (#if !defined(NO_PP)...)
|
||||
*
|
||||
* Revision 3.8 1993/05/17 20:36:13 sar
|
||||
* added <install.h> and "stdf.h" to include string routines that zortech
|
||||
* didn't have.
|
||||
*
|
||||
* Revision 3.7 1993/05/13 19:08:06 sar
|
||||
* Added code to use a file implementation of nv memory
|
||||
*
|
||||
* Revision 3.6 1993/03/03 20:04:39 dab
|
||||
* The routine ini_lookup() returns a malloc'd string, free it.
|
||||
* Added new routine parse_hex_octet_string.
|
||||
*
|
||||
* Revision 3.5 1993/03/02 18:18:33 dab
|
||||
* Added read_config_defaults()
|
||||
*
|
||||
* Revision 3.4 1993/02/19 19:29:35 dab
|
||||
* Added the -m switch to set the name of the mib file.
|
||||
*
|
||||
* Revision 3.3 1993/02/17 21:19:41 sar
|
||||
* Added declarations for spoid, dpoid and cpoid (source and dest parties and
|
||||
* context oids) and their lengths (spoidlen, dpoidlen and cpoidlen).
|
||||
* These are used to determine what parties to use for a v2 packet.
|
||||
*
|
||||
* Revision 3.1 92/06/16 16:05:40 dab
|
||||
* Added batch mode
|
||||
*
|
||||
* Revision 3.0 92/04/03 19:53:14 dab
|
||||
* Release 3.0
|
||||
*
|
||||
* Revision 2.102 91/11/03 10:04:49 dab
|
||||
* Don't include <strings.h>, let system.h do it instead.
|
||||
*
|
||||
* Revision 2.101 91/10/30 09:21:25 dab
|
||||
* Include system.h instead of trying to declare strdup or not
|
||||
* in here.
|
||||
*
|
||||
* Revision 2.100 91/08/09 14:05:21 dab
|
||||
* Update version number. This is just before the work to upgrade to
|
||||
* release 3.0.
|
||||
*
|
||||
* Revision 1.1 91/07/11 18:13:29 romkey
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
#include <wrn/wm/common/config.h>
|
||||
|
||||
#include <wrn/wm/snmp/engine/asn1.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
#include <snark.h>
|
||||
#include <wrn/wm/demo/snmpconf.h>
|
||||
#include <wrn/wm/demo/read_ini.h>
|
||||
#include <wrn/wm/demo/parse.h>
|
||||
#include <wrn/wm/demo/strdup.h>
|
||||
#include <wrn/wm/demo/nvutils.h>
|
||||
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#if INSTALL_ENVOY_SNMP_VERSION_2
|
||||
int SNMPTalk_SNMP_Version = 2;
|
||||
#elif INSTALL_ENVOY_SNMP_VERSION_1
|
||||
int SNMPTalk_SNMP_Version = 1;
|
||||
#else
|
||||
int SNMPTalk_SNMP_Version = 3;
|
||||
#endif
|
||||
|
||||
char *read_community = "public";
|
||||
char *write_community = "public";
|
||||
char *mib_filename = "mib.rt";
|
||||
char *destination = 0;
|
||||
unsigned udp_port = 161;
|
||||
ipaddr_t dest_addr = { IPNONE, { 0 } };
|
||||
#if INSTALL_SNMP_DEMO_AGENT_IPV6
|
||||
int v6_scope = 0;
|
||||
#endif
|
||||
int snmp_timeout = 4;
|
||||
int retry_count = 2;
|
||||
int batch_mode = 0;
|
||||
int packet_dump = 0;
|
||||
/* Use alternate display mechanism */
|
||||
int alt_display = 0;
|
||||
|
||||
/* defaults for version 3 stuff */
|
||||
#if INSTALL_ENVOY_SNMP_VERSION_3
|
||||
char v3_tos_flags = 0;
|
||||
char *v3_con_name = "";
|
||||
bits8_t v3_con_id[32];
|
||||
ALENGTH_T v3_con_id_len = 0;
|
||||
char *v3_sec_name = "shawn";
|
||||
bits8_t v3_sec_id[32];
|
||||
ALENGTH_T v3_sec_id_len = 0;
|
||||
#endif
|
||||
|
||||
/* defaults for usec */
|
||||
#if INSTALL_ENVOY_SNMP_VERSION_USEC
|
||||
/*char *usec_agentid = "\0\0\0\43\200\340\01\225\0\0\0\0";*/
|
||||
/*OCTET_T *usec_agentid = "\0\0\0\2\0\0\0\0\21\42\210\75";*/
|
||||
OCTET_T *usec_agentid = "\0\0\0\0\0\0\0\0\0\0\0\2";
|
||||
OCTET_T *usec_context = "\0";
|
||||
OCTET_T usec_qos = 0;
|
||||
#endif
|
||||
|
||||
|
||||
/* flag to tell us if the nv config file has been read (1) or not (0) */
|
||||
int SNMPTalk_NV_Read = 0;
|
||||
|
||||
/* Parses a string of colon separated hex numbers into a byte array */
|
||||
int
|
||||
parse_hex_octet_string_colon(char *string,
|
||||
int buflen,
|
||||
bits8_t *buf)
|
||||
{
|
||||
unsigned long value;
|
||||
int count;
|
||||
char *newstring;
|
||||
|
||||
count = 0;
|
||||
while (*string) {
|
||||
value = STRTOUL(string, &newstring, 16);
|
||||
if (string == newstring)
|
||||
break; /* we didn't make any progress */
|
||||
else
|
||||
string = newstring;
|
||||
|
||||
buf[count++] = (unsigned char)(value & 0xFF);
|
||||
if ((count >= buflen) || (*string != ':'))
|
||||
break;
|
||||
string++;
|
||||
}
|
||||
|
||||
return (count);
|
||||
}
|
||||
|
||||
/* parse a string of unseperated hex numbers into a byte array */
|
||||
int
|
||||
parse_hex_octet_string(char *string,
|
||||
int buflen,
|
||||
bits8_t *buf)
|
||||
{
|
||||
unsigned long value;
|
||||
int count;
|
||||
char nibble[3], *newstring;
|
||||
|
||||
/* set up the end for strtoul */
|
||||
nibble[2] = 0;
|
||||
|
||||
for (count = 0; *string && (count < buflen); count++) {
|
||||
if (*(string+1) == 0)
|
||||
return(0);
|
||||
|
||||
nibble[0] = *string++;
|
||||
nibble[1] = *string++;
|
||||
value = STRTOUL(nibble, &newstring, 16);
|
||||
if (newstring == nibble)
|
||||
break;
|
||||
buf[count] = (unsigned char)(value & 0xFF);
|
||||
}
|
||||
|
||||
return(count);
|
||||
}
|
||||
|
||||
/* Execute options out of a parsed command line. Returns the number of
|
||||
* arguments used up as options. */
|
||||
int
|
||||
SNMP_Parse_Opts(int argc,
|
||||
char *argv[],
|
||||
char *where)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
while ((argc != 0) && (*argv[0] == '-')) {
|
||||
if (STRICMP(argv[0], "-batch") == 0) {
|
||||
batch_mode = 1;
|
||||
argv += 1;
|
||||
argc -= 1;
|
||||
count += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Since all options (except -batch) take exactly one argument,
|
||||
* check here. */
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "no argument for option '%s' in %s\n", argv[0], where);
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (argv[0][1]) {
|
||||
case 'm': /* set the mib file name */
|
||||
mib_filename = etc_strdup(argv[1]);
|
||||
break;
|
||||
case 'd': /* set the remote host to talk to */
|
||||
if (destination)
|
||||
etc_strdup_free(destination);
|
||||
destination = etc_strdup(argv[1]);
|
||||
break;
|
||||
case 'p': /* set the destination UDP port */
|
||||
udp_port = (unsigned)atoi(argv[1]);
|
||||
break;
|
||||
case 'r': /* set the community string to use for reads */
|
||||
read_community = etc_strdup(argv[1]);
|
||||
break;
|
||||
case 'w': /* set the community string used for writes */
|
||||
write_community = etc_strdup(argv[1]);
|
||||
break;
|
||||
case 't': /* set the retransmission timeout */
|
||||
snmp_timeout = atoi(argv[1]);
|
||||
break;
|
||||
case 'c': /* set the retransmission count */
|
||||
retry_count = atoi(argv[1]);
|
||||
break;
|
||||
case 'a': /* set the retransmission count */
|
||||
alt_display = atoi(argv[1]);
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "Unknown option `%s'\n", argv[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Here because all options take exactly one agrument */
|
||||
argv += 2;
|
||||
argc -= 2;
|
||||
count += 2;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/* Reads the config file (generally etc.ini) to set defaults
|
||||
for the snmp engine. Then, if necessary, reads the nv configuration
|
||||
file to populate the engines database. */
|
||||
int
|
||||
SNMP_Config()
|
||||
{
|
||||
static char *etc_section = "etc envoy";
|
||||
char *value;
|
||||
long tmp_l;
|
||||
struct ini_handle *i_hand;
|
||||
|
||||
i_hand = ini_open(256);
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "mibfile")) != 0)
|
||||
if ((mib_filename = etc_strdup(value)) == 0)
|
||||
return(1);
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "read-community")) != 0)
|
||||
if ((read_community = etc_strdup(value)) == 0)
|
||||
return(1);
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "write-community")) != 0)
|
||||
if ((write_community = etc_strdup(value)) == 0)
|
||||
return(1);
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "timeout")) != 0) {
|
||||
if ((tmp_l = STRTOL(value, 0, 0)) != 0)
|
||||
snmp_timeout = (int)tmp_l;
|
||||
}
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "retry-count")) != 0) {
|
||||
if ((tmp_l = STRTOL(value, 0, 0)) != 0)
|
||||
retry_count = (int)tmp_l;
|
||||
}
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "udp-port")) != 0) {
|
||||
if ((tmp_l = STRTOL(value, 0, 0)) != 0)
|
||||
udp_port = (unsigned)tmp_l;
|
||||
}
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "snmp-version")) != 0) {
|
||||
switch (atoi(value)) {
|
||||
#if INSTALL_ENVOY_SNMP_VERSION_1
|
||||
case 1: SNMPTalk_SNMP_Version = 1; break;
|
||||
#endif /* INSTALL_ENVOY_SNMP_VERSION_1 */
|
||||
#if INSTALL_ENVOY_SNMP_VERSION_2
|
||||
case 2: SNMPTalk_SNMP_Version = 2; break;
|
||||
#endif /* INSTALL_ENVOY_SNMP_VERSION_2 */
|
||||
#if INSTALL_ENVOY_SNMP_VERSION_3
|
||||
case 3: SNMPTalk_SNMP_Version = 3; break;
|
||||
#endif /* INSTALL_ENVOY_SNMP_VERSION_3 */
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
/* if v3 is installed see what we have for defualts for it.
|
||||
we have the context name and engine id, and the security
|
||||
name and engine id */
|
||||
#if INSTALL_ENVOY_SNMP_VERSION_3
|
||||
if ((value = ini_lookup(i_hand, etc_section, "v3_context_name")) != 0)
|
||||
if ((v3_con_name = etc_strdup(value)) == 0)
|
||||
return(1);
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "v3_context_id")) != 0)
|
||||
if ((v3_con_id_len = parse_hex_octet_string(value, 32, v3_con_id)) == 0)
|
||||
return(1);
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "v3_security_name")) != 0)
|
||||
if ((v3_sec_name = etc_strdup(value)) == 0)
|
||||
return(1);
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "v3_security_id")) != 0)
|
||||
if ((v3_sec_id_len = parse_hex_octet_string(value, 32, v3_sec_id)) == 0)
|
||||
return(1);
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "v3_tos_flags")) != 0) {
|
||||
switch (atoi(value)) {
|
||||
case 0: v3_tos_flags = 0; break;
|
||||
case 1: v3_tos_flags = 1; break;
|
||||
case 3: v3_tos_flags = 3; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
#endif /* INSTALL_ENVOY_SNMP_VERSION_3 */
|
||||
|
||||
/* See if the configuration file wants to alter the non volatile
|
||||
configuration file defaults, but only if we are compiled for
|
||||
dynamic views or have a version that requires it.
|
||||
After we get the file info from etc.ini we read non volatile
|
||||
configuration into the dabase */
|
||||
#if (INSTALL_ENVOY_SNMP_VERSION_3 || INSTALL_ENVOY_SNMP_DYNAMIC_VIEWS || \
|
||||
INSTALL_ENVOY_SNMP_VERSION_USEC)
|
||||
if ((value = ini_lookup(i_hand, etc_section, "nv-config-file")) != 0)
|
||||
if ((NV_Config_File = etc_strdup(value)) == 0)
|
||||
return(1);
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "nv-config-file-old")) != 0)
|
||||
if ((NV_Old_Config_File = etc_strdup(value)) == 0)
|
||||
return(1);
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "nv-config-file-temp")) != 0)
|
||||
if ((NV_Temp_Config_File = etc_strdup(value)) == 0)
|
||||
return(1);
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "nv-views-from-config")) != 0) {
|
||||
switch (atoi(value)) {
|
||||
case 0: NV_Views_From_Config = 0; break;
|
||||
case 1: NV_Views_From_Config = 1; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((value = ini_lookup(i_hand, etc_section, "nv-read-only")) != 0) {
|
||||
switch (atoi(value)) {
|
||||
case 0: NV_Read_Only = 0; break;
|
||||
case 1: NV_Read_Only = 1; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
value = ini_lookup(i_hand, etc_section, "v3_engine_id");
|
||||
SNMPTalk_NV_Read = 1;
|
||||
if (SNMP_NV_Config(value)) {
|
||||
return(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
ini_close(i_hand);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,386 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/snmpfunc.c,v 1.3 2003/01/15 14:04:35 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: snmpfunc.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:35 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:27 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.9 2001/05/07 14:39:22 markadam
|
||||
* Changed the default view for "public" access to be the same as for "private"
|
||||
* access. Note, this only affects GETs.
|
||||
*
|
||||
* Revision 1.8 2001/01/19 22:23:52 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.7 2000/03/17 00:12:45 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.6 1998/09/28 21:12:28 josh
|
||||
* just to make RFC2275 views alittle more useful if you're not using
|
||||
* SNMPv3...
|
||||
*
|
||||
* Revision 1.5 1998/07/06 01:04:55 sar
|
||||
* Add some casts and change atoi to strtol to make compilers happy
|
||||
*
|
||||
* Revision 1.4 1998/06/16 05:36:37 sar
|
||||
* clean up some type info, cast some strings
|
||||
*
|
||||
* Revision 1.3 1998/06/09 22:02:11 sar
|
||||
* Only define proxy_release_private if proxy is installed
|
||||
*
|
||||
* Revision 1.2 1998/06/08 19:47:44 sar
|
||||
* Added rmon start call if liaison is installed
|
||||
*
|
||||
* Revision 1.1 1998/06/07 02:40:06 sar
|
||||
* Move the validate and timing routines to the snark library
|
||||
* so they can be used by multiple demos
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
|
||||
#include <snark.h>
|
||||
|
||||
#include <wrn/wm/demo/snmpfunc.h>
|
||||
|
||||
#include <wrn/wm/snmp/engine/asn1conf.h>
|
||||
#include <wrn/wm/snmp/engine/snmpdefs.h>
|
||||
#include <wrn/wm/snmp/engine/buffer.h>
|
||||
#include <wrn/wm/snmp/engine/proxy_tr.h>
|
||||
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#if INSTALL_ENVOY_SNMP_RFC2275_VIEWS
|
||||
static bits8_t *one = (bits8_t *)("one");
|
||||
static bits8_t *two = (bits8_t *)("two");
|
||||
#endif
|
||||
|
||||
char snmp_get_request_community[SNMP_COMM_MAX] = "public";
|
||||
char snmp_set_request_community[SNMP_COMM_MAX] = "private";
|
||||
char snmp_trap_community[SNMP_COMM_MAX] = "SNMP_trap";
|
||||
|
||||
#if INSTALL_LIAISON
|
||||
extern void rmon_new_snmp_command(void);
|
||||
#endif
|
||||
|
||||
#if INSTALL_ENVOY_SNMP_PROXY
|
||||
extern sbits32_t proxy_send_rtn(EBUFFER_T *, ptr_t);
|
||||
#endif
|
||||
|
||||
#if INSTALL_ENVOY_SNMP_PROXY
|
||||
/****************************************************************************
|
||||
NAME: proxy_release_private
|
||||
|
||||
PURPOSE: Routine to release any resources that the validate routine
|
||||
attached to the user_private pointer for proxies.
|
||||
|
||||
PARAMETERS:
|
||||
SNMP_PKT_T * Packet we're working on
|
||||
|
||||
RETURNS: void
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
void
|
||||
proxy_release_private(SNMP_PKT_T *rp)
|
||||
{
|
||||
if (rp->proxy_routine && rp->user_private) {
|
||||
SNMP_memory_free(rp->user_private);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
validate_SNMP_community -- Check an operation against the community name.
|
||||
Get class operations can use either the set or get community.
|
||||
Set operations may use only the set community.
|
||||
|
||||
The parameters to this procedure are:
|
||||
SNMP_PKT_T * The received packet (decoded format)
|
||||
SNMPADDR_T * Source of the packet
|
||||
SNMPADDR_T * Destination of the packet (most likely
|
||||
the address of the machine on which this
|
||||
code is running.)
|
||||
|
||||
This procedure should return 0 if happy with the sommunity string
|
||||
and 1 if not.
|
||||
|
||||
This routine may hang additional data onto the "private" field of
|
||||
the packet structure.
|
||||
The user will be given the opportinity to release that memory via
|
||||
release_private().
|
||||
|
||||
**********************************************************************/
|
||||
/*ARGSUSED*/
|
||||
/*lint -e715 */
|
||||
int
|
||||
validate_SNMP_community(SNMP_PKT_T *rp,
|
||||
SNMPADDR_T *pktsrc,
|
||||
SNMPADDR_T *pktdst)
|
||||
{
|
||||
static bits16_t lcl_ident_source = 0;
|
||||
bits8_t *com_str;
|
||||
ALENGTH_T com_len;
|
||||
int match_get, match_set;
|
||||
|
||||
#if INSTALL_LIAISON
|
||||
rmon_new_snmp_command();
|
||||
#endif
|
||||
|
||||
MEMCPY(&(rp->pkt_src), pktsrc, sizeof(SNMPADDR_T));
|
||||
MEMCPY(&(rp->pkt_dst), pktdst, sizeof(SNMPADDR_T));
|
||||
|
||||
rp->lcl_ident = lcl_ident_source++;
|
||||
rp->user_private = 0;
|
||||
|
||||
com_str = EBufferStart(&(rp->community));
|
||||
com_len = EBufferUsed(&(rp->community));
|
||||
|
||||
#if (INSTALL_ENVOY_SNMP_PROXY)
|
||||
/* Test to see if this is a proxy request, the community
|
||||
string will be of the form "proxy@vx@cstring@addr@port"
|
||||
with vx beign v1 or v2 to select the next hop version,
|
||||
port is optional (default = 161) so we require a minimum
|
||||
of 10 characters */
|
||||
if ((com_len >= 10) && (MEMCMP("proxy@", com_str, 6) == 0)) {
|
||||
bits8_t *vstr, *cstr, *astr, *pstr, addrstr[128];
|
||||
ALENGTH_T vlen, clen, alen;
|
||||
TRANS_STUFF_T *trans_stuff;
|
||||
int port = 161;
|
||||
|
||||
/* dig out the version string */
|
||||
vstr = com_str + 6;
|
||||
com_len -= 6;
|
||||
/* figure out how long the version string is */
|
||||
for (cstr = vstr, vlen = 0; *cstr != '@'; cstr++, vlen++, com_len--) {
|
||||
/* a properly formatted string must have at least 5 characters
|
||||
left (the current character 2 '@' and one character each for
|
||||
the community string and the addr */
|
||||
if (com_len <= 5)
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* we must have only two characters for the version string and the
|
||||
first must be 'v' */
|
||||
if ((vlen != 2) || (*vstr != 'v'))
|
||||
return(1);
|
||||
|
||||
/* dig out the proxy community string, remove the '@' */
|
||||
cstr++;
|
||||
com_len--;
|
||||
/* figure out how long the community string is */
|
||||
for (astr = cstr, clen = 0;
|
||||
*astr != '@';
|
||||
astr++, clen++, com_len--) {
|
||||
/* a properly formatted cstring must have at least
|
||||
3 characters left (the current character the '@'
|
||||
and the first character of the addr */
|
||||
if (com_len <= 3)
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* remove the '@' */
|
||||
astr++;
|
||||
com_len--;
|
||||
/* figure out how long the addr string is */
|
||||
for (pstr = astr, alen = 0;
|
||||
(com_len) && (*pstr != '@');
|
||||
pstr++, alen++, com_len--)
|
||||
/* empty for loop */
|
||||
;
|
||||
/* if we don't have a name we bail out */
|
||||
if (alen == 0)
|
||||
return(1);
|
||||
|
||||
/* remove the '@' */
|
||||
pstr++;
|
||||
com_len--;
|
||||
|
||||
/* if we have characters left after the '@' they belong to the
|
||||
port string, we reject any ports that would be too long
|
||||
more than 5 characters (16 bit numbes) otherwise we copy
|
||||
0 terminate the string then convert to an integer */
|
||||
if (com_len > 5)
|
||||
return(1);
|
||||
if (com_len > 0) {
|
||||
MEMCPY(addrstr, pstr, com_len);
|
||||
addrstr[com_len] = 0;
|
||||
port = (int)STRTOL((char *)addrstr, 0, 0);
|
||||
if (port == 0)
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* having made it here we have a community string, address
|
||||
and port for use with the proxy stuff we allocate space
|
||||
for the transport block (which includes the proxy block)
|
||||
and the name, then fill them in */
|
||||
trans_stuff = (TRANS_STUFF_T *)SNMP_memory_alloc(sizeof(TRANS_STUFF_T) +
|
||||
alen + 1);
|
||||
if (trans_stuff == 0)
|
||||
return(1);
|
||||
|
||||
trans_stuff->addr_str = ((bits8_t *)trans_stuff) + sizeof(TRANS_STUFF_T);
|
||||
|
||||
/* save the address string */
|
||||
MEMCPY(trans_stuff->addr_str, astr, alen);
|
||||
/* add the 0 */
|
||||
trans_stuff->addr_str[alen] = 0;
|
||||
|
||||
/* and the rest of the information */
|
||||
EBufferPreLoad(BFL_IS_STATIC, &(trans_stuff->pblockp.community),
|
||||
cstr, clen);
|
||||
trans_stuff->port = port;
|
||||
trans_stuff->pkt = 0;
|
||||
trans_stuff->pblockp.transport_routine = proxy_send_rtn;
|
||||
trans_stuff->pblockp.transport_block = (ptr_t)trans_stuff;
|
||||
|
||||
rp->user_private = (ptr_t)trans_stuff;
|
||||
|
||||
switch(*(vstr+1)) {
|
||||
#if (INSTALL_ENVOY_SNMP_VERSION_1)
|
||||
case '1':
|
||||
/* rp->proxy_routine = SNMP_Proxy_V1_Translation;*/
|
||||
rp->proxy_routine = 0;
|
||||
break;
|
||||
#endif
|
||||
#if (INSTALL_ENVOY_SNMP_VERSION_2)
|
||||
case '2':
|
||||
/* rp->proxy_routine = SNMP_Proxy_V2_Translation;*/
|
||||
rp->proxy_routine = 0;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return(1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
#endif /* (INSTALL_ENVOY_SNMP_PROXY) */
|
||||
|
||||
match_get = (STRLEN(snmp_get_request_community) == com_len &&
|
||||
(MEMCMP(snmp_get_request_community, com_str, com_len) == 0));
|
||||
match_set = (STRLEN(snmp_set_request_community) == com_len &&
|
||||
(MEMCMP(snmp_set_request_community, com_str, com_len) == 0));
|
||||
|
||||
switch(rp->pdu_type) {
|
||||
case SET_REQUEST_PDU:
|
||||
if (match_set) {
|
||||
/* good set community name */
|
||||
rp->mib_view = 0xffffffffL;
|
||||
#if (INSTALL_ENVOY_SNMP_RFC1445_VIEWS)
|
||||
rp->view_index = 2;
|
||||
#elif (INSTALL_ENVOY_SNMP_RFC2275_VIEWS)
|
||||
EBufferPreLoad(BFL_IS_STATIC, &rp->view_name, two, 3);
|
||||
#endif
|
||||
return(0);
|
||||
}
|
||||
if (match_get)
|
||||
return(3);
|
||||
return(2);
|
||||
|
||||
case GET_REQUEST_PDU:
|
||||
case GET_NEXT_REQUEST_PDU:
|
||||
case GET_BULK_REQUEST_PDU:
|
||||
if (match_get || match_set) {
|
||||
/* allow access if either get or set name matched */
|
||||
rp->mib_view = 0xffffffffL;
|
||||
#if (INSTALL_ENVOY_SNMP_RFC1445_VIEWS)
|
||||
rp->view_index = 2;
|
||||
#elif (INSTALL_ENVOY_SNMP_RFC2275_VIEWS)
|
||||
EBufferPreLoad(BFL_IS_STATIC, &rp->view_name, two, 3);
|
||||
#endif
|
||||
return(0);
|
||||
}
|
||||
return(2);
|
||||
|
||||
default:
|
||||
/* allow other pdu types through without checking */
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
/*lint -e715 */
|
||||
|
||||
/**********************************************************************
|
||||
This is a placeholder routine
|
||||
**********************************************************************/
|
||||
int validate_SNMP_address(SNMP_PKT_T *rp,
|
||||
SNMPADDR_T *src,
|
||||
SNMPADDR_T *dst)
|
||||
{
|
||||
MEMCPY(&rp->pkt_src, src, sizeof(SNMPADDR_T));
|
||||
MEMCPY(&rp->pkt_dst, dst, sizeof(SNMPADDR_T));
|
||||
return(0);
|
||||
}
|
||||
|
||||
#if INSTALL_ENVOY_SNMP_VERSION_3
|
||||
|
||||
/**********************************************************************
|
||||
validate_SNMP_V3_address -- Check an operation against the address.
|
||||
Primarily this function is for copying the addressing info
|
||||
into the packet structure, but the user may also choose to
|
||||
deny access based on address or use a different mib tree
|
||||
based on address or context information.
|
||||
|
||||
The parameters to this procedure are:
|
||||
SNMP_PKT_T * The received packet (decoded format)
|
||||
SNMPADDR_T * Source of the packet
|
||||
SNMPADDR_T * Destination of the packet (most likely
|
||||
the address of the machine on which this
|
||||
code is running.)
|
||||
|
||||
This procedure should return 0 if happy and 1 if not
|
||||
|
||||
This routine may hang additional data onto the "private" field of
|
||||
the packet structure.
|
||||
The user will be given the opportinity to release that memory via
|
||||
release_private().
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
int
|
||||
validate_SNMP_V3_address(SNMP_PKT_T *rp,
|
||||
SNMPADDR_T *pktsrc,
|
||||
SNMPADDR_T *pktdst)
|
||||
{
|
||||
rp->user_private = 0;
|
||||
|
||||
MEMCPY(&(rp->pkt_src), pktsrc, sizeof(SNMPADDR_T));
|
||||
MEMCPY(&(rp->pkt_dst), pktdst, sizeof(SNMPADDR_T));
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
#endif /* #if INSTALL_ENVOY_SNMP_VERSION_3 */
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/snoop.c,v 1.1.1.1 2001/11/05 17:48:43 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: snoop.c,v $
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.7 2001/01/19 22:23:53 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.6 2000/03/17 00:12:46 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.5 1998/02/25 04:57:40 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.4 1997/03/20 06:53:12 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 1.3 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 1.2 1997/02/19 08:10:29 sra
|
||||
* More fun merging snmptalk into snark, general snark cleanup.
|
||||
*
|
||||
* Revision 1.1 1996/11/13 15:06:46 mrf
|
||||
* Initial revision
|
||||
*
|
||||
* Revision 2.2 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.1 1995/06/22 05:29:06 sra
|
||||
* Preliminary changes for multicast and OSPF.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.4 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.3 1994/09/02 21:15:48 sra
|
||||
* Add still more parentheses to the for() loop from hell in bpf_find().
|
||||
*
|
||||
* Revision 1.2 1993/07/29 04:30:26 sra
|
||||
* Don't use the inline versions of the byteswap routines, GCC gets
|
||||
* confused.
|
||||
*
|
||||
* Revision 1.1 1993/07/05 21:53:30 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* SNOOP interface to ethernet for Attache testing under Irix.
|
||||
*
|
||||
* All access to SNOOP should be through this module, the only thing we
|
||||
* expect our caller to do with our file descriptor is use it in
|
||||
* select() calls. There are enough name conflicts between the unix
|
||||
* networking code and the Attache networking code that it's probably
|
||||
* hopeless to have the two mingled in the same file.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <net/raw.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/if_ether.h>
|
||||
|
||||
int snoop_open(char *ifname, unsigned mtu, unsigned char *mac)
|
||||
{
|
||||
int fd;
|
||||
struct sockaddr_raw sr;
|
||||
struct snoopfilter sf;
|
||||
u_int cc, on;
|
||||
|
||||
/* get a snoop socket */
|
||||
fd = socket(PF_RAW, SOCK_RAW, RAWPROTO_SNOOP);
|
||||
if (fd < 0) {
|
||||
perror("Couldn't open SNOOP socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* bind the socket */
|
||||
bzero((char *)&sr, sizeof(sr));
|
||||
sr.sr_family = AF_RAW;
|
||||
sr.sr_port = 0;
|
||||
(void)strncpy(sr.sr_ifname, ifname, sizeof(sr.sr_ifname));
|
||||
if (bind(fd, (struct sockaddr *)&sr, sizeof(sr))) {
|
||||
(void)close(fd);
|
||||
perror("Couldn't bind SNOOP socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* set snoop filter */
|
||||
bzero((char *)&sf, sizeof(sf));
|
||||
if (ioctl(fd, SIOCADDSNOOP, &sf) < 0) {
|
||||
perror("Couldn't set SNOOP filter");
|
||||
(void)close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* set receive length for packets and start snooping.*/
|
||||
cc = 64 * 1024; /* largest packet is 64K */
|
||||
(void)setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&cc, sizeof(cc));
|
||||
if (ioctl(fd, SIOCSNOOPING, &on) < 0) {
|
||||
perror ("Couldn't start SNOOPing");
|
||||
(void)close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
#define ETHERHDRPAD RAW_HDRPAD(sizeof(struct ether_header))
|
||||
|
||||
struct etherpacket {
|
||||
struct snoopheader snoop;
|
||||
char pad[ETHERHDRPAD];
|
||||
struct ether_header ether;
|
||||
char data[ETHERMTU];
|
||||
};
|
||||
|
||||
int snoop_read
|
||||
(int fd,
|
||||
unsigned mtu,
|
||||
void (*handler)(unsigned char *, unsigned, unsigned, void *),
|
||||
void *cookie)
|
||||
{
|
||||
struct etherpacket *ep;
|
||||
struct snoopheader *sh;
|
||||
int datalen, caplen;
|
||||
|
||||
if ((ep = (struct etherpacket *) malloc(sizeof(struct etherpacket))) == 0) {
|
||||
fprintf(stderr, "malloc(%d) failed\n", mtu);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to read a packet, restart if we get screwed by the debugger.
|
||||
* Return on other error or on EOF.
|
||||
*/
|
||||
do {
|
||||
caplen = read(fd, ep, mtu);
|
||||
} while (caplen < 0 && errno == EINTR);
|
||||
if (caplen <= 0) {
|
||||
perror ("Read from SNOOP socket failed");
|
||||
return caplen;
|
||||
}
|
||||
|
||||
sh = (struct snoopheader *)ep;
|
||||
datalen = sh->snoop_packetlen;
|
||||
handler((char *)&(ep->ether), datalen, datalen, cookie);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int snoop_write(int fd, unsigned char *data, unsigned datalen)
|
||||
{
|
||||
return write(fd, data, datalen);
|
||||
}
|
||||
|
||||
void snoop_close(int fd)
|
||||
{
|
||||
(void) close(fd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Find "all" ethernet interfaces.
|
||||
* Apparently doing this is hard on Irix, so just hardwire it for now.
|
||||
*/
|
||||
|
||||
void snoop_find(void (*handler)(char *, void *), void *cookie)
|
||||
{
|
||||
handler("ec0", cookie);
|
||||
}
|
||||
@@ -0,0 +1,310 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/snoopdrv.c,v 1.4 2003/01/15 14:04:36 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1994-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: snoopdrv.c,v $
|
||||
* Revision 1.4 2003/01/15 14:04:36 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.3 2001/11/08 15:56:27 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.2 2001/11/06 20:11:12 josh
|
||||
* updating include paths to include proper path to layout directory
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.18 2001/01/19 22:23:53 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.17 2000/10/20 18:32:25 paul
|
||||
* Properly conditionalized driver.ip_send
|
||||
*
|
||||
* Revision 1.16 2000/10/16 19:21:55 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 1.15 2000/03/17 00:12:46 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.14 2000/03/13 21:22:10 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 1.13 1999/11/05 22:29:07 paul
|
||||
* Updated driver structs to reflect conditional backwards-compatibility
|
||||
* fields and new fields.
|
||||
*
|
||||
* Revision 1.12 1999/04/28 23:53:26 sra
|
||||
* Clean up various minor installation option glitches.
|
||||
*
|
||||
* Revision 1.11 1998/02/25 15:21:51 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 1.10 1998/02/25 04:57:41 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.9 1997/05/20 02:21:50 mrf
|
||||
* make snark lib driver code use new ldb arp definitions
|
||||
*
|
||||
* Revision 1.8 1997/05/07 17:23:38 mrf
|
||||
* move ipv6_send function to end of net_if structure
|
||||
*
|
||||
* Revision 1.6 1997/04/19 02:48:03 mrf
|
||||
* added basic ipv6 code, config ipv6 addresses, added new ipv6_send handler
|
||||
* to snoop and bpf driver structures, added configurable maxlnt and cleaned
|
||||
* up makefile.cfg formatting error
|
||||
*
|
||||
* Revision 1.4 1997/03/20 06:53:13 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 1.3 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 1.2 1997/02/19 08:10:29 sra
|
||||
* More fun merging snmptalk into snark, general snark cleanup.
|
||||
*
|
||||
* Revision 1.1 1996/11/13 15:06:46 mrf
|
||||
* Initial revision
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.3 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.2 1994/09/04 06:13:38 sra
|
||||
* Clean up antique type names and install macros.
|
||||
*
|
||||
* Revision 1.1 1994/01/09 23:57:29 sra
|
||||
* Add support for NIT under SunOS 4.1.2.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* This file contains the Attache driver code for SNOOP.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/ether.h>
|
||||
#include <wrn/wm/attache/arp.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include <wrn/wm/util/layout/ldbglue.h>
|
||||
#inlcude <layout/arp.h>
|
||||
|
||||
#include <wrn/wm/demo/snoop.h>
|
||||
#include <wrn/wm/demo/bsdif.h>
|
||||
#include <wrn/wm/demo/snoopdrv.h>
|
||||
|
||||
struct snoop_driver_private {
|
||||
bits8_t mac[6]; /* MAC address for this interface */
|
||||
};
|
||||
|
||||
#define TEN_MEGABITS 10000000
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Routines to read (struct bsdif) generic network interface.
|
||||
*/
|
||||
|
||||
static void snoop_driver_rcv
|
||||
(unsigned char *buffer,
|
||||
unsigned buflen,
|
||||
unsigned netlen,
|
||||
void *cookie)
|
||||
{
|
||||
packet *p;
|
||||
|
||||
if (buflen != netlen || (p = pkt_alloc(buflen + 2)) == 0)
|
||||
return;
|
||||
|
||||
MEMCPY(p->pkt_data += 2, buffer, buflen);
|
||||
p->pkt_datalen = buflen;
|
||||
p->pkt_n = cookie;
|
||||
et_rcv(p);
|
||||
}
|
||||
|
||||
static void snoop_driver_read (int fd, void *cookie, unsigned flags)
|
||||
{
|
||||
struct net *net = cookie;
|
||||
if ((net->flags & NF_DRIVER_DOWN) == 0 && (flags & BSDIF_READ) != 0)
|
||||
(void) snoop_read(fd, net->driver->maxlen, snoop_driver_rcv, (void *)net);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Attache device driver routines for SNOOP.
|
||||
*/
|
||||
|
||||
static void snoop_driver_init (struct net *net)
|
||||
{
|
||||
/* prefix from "obsolete" portion of dec's space (see rfc1340) */
|
||||
static bits8_t snp_driver_mac_prefix[3] = { 0xAA, 0x00, 0x00 };
|
||||
struct bsdif *bif = net->specific;
|
||||
struct snoop_driver_private *private;
|
||||
char *name = net->s_name + STRLEN(net->driver->prefix);
|
||||
pid_t proc = getpid();
|
||||
bits32_t hostid = gethostid();
|
||||
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
net->speed = TEN_MEGABITS;
|
||||
|
||||
if (net->h_address == 0)
|
||||
{
|
||||
if ((bif->private = private = GLUE_ALLOC(sizeof(*private))) == 0)
|
||||
return;
|
||||
net->ha_len = sizeof(private->mac);
|
||||
net->h_address = private->mac;
|
||||
MEMCPY(private->mac+0, snp_driver_mac_prefix, 3);
|
||||
/* use the IP address if we've already got one (this depends on the
|
||||
* backward compatibility mode sticking the address in the net_if) */
|
||||
if (net->ip_addr != 0L)
|
||||
MEMCPY(private->mac+3, ((bits8_t *) &net->ip_addr) + 1, 3);
|
||||
else {
|
||||
/* if not, cons up something unique */
|
||||
*(private->mac+3) |= (bits8_t)(proc & 0xff);
|
||||
*(private->mac+4) |= (bits8_t)(proc>>8 & 0xff);
|
||||
if (hostid & 0xff)
|
||||
*(private->mac+5) |= (bits8_t)(hostid & 0xff);
|
||||
}
|
||||
}
|
||||
else
|
||||
private = (struct snoop_driver_private *) net->h_address;
|
||||
|
||||
|
||||
if ((bif->fd = snoop_open(name, net->driver->maxlen, private->mac)) < 0)
|
||||
return;
|
||||
|
||||
bif->handler = snoop_driver_read;
|
||||
bif->flags |= BSDIF_READ;
|
||||
net->flags &= ~NF_DRIVER_DOWN;
|
||||
}
|
||||
|
||||
static void snoop_driver_send (struct packet *p)
|
||||
{
|
||||
struct bsdif *bif = p->pkt_n->specific;
|
||||
|
||||
/*
|
||||
* Send the packet, logging any error that might occur.
|
||||
* If the driver is down, just drop the packet.
|
||||
*/
|
||||
if ((p->pkt_n->flags & NF_DRIVER_DOWN) == 0 &&
|
||||
snoop_write(bif->fd, p->pkt_data, p->pkt_datalen) < 0)
|
||||
perror("SNOOP write() failure");
|
||||
pkt_free(p);
|
||||
}
|
||||
|
||||
static void snoop_driver_close (struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
|
||||
if ((net->flags & NF_DRIVER_DOWN) == 0) {
|
||||
snoop_close(bif->fd);
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
}
|
||||
if (bif->private) {
|
||||
GLUE_FREE(bif->private);
|
||||
bif->private = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This could be static now, but it might be useful to leave it visible.
|
||||
*/
|
||||
|
||||
struct driver snoop_driver = {
|
||||
snoop_driver_init, /* Interface initialization routine */
|
||||
snoop_driver_send, /* Raw packet send routine */
|
||||
#if INSTALL_ATTACHE_34_IPV4_API_COMPAT
|
||||
et_ip_send, /* IP packet send encapsulation routine */
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
et_arp_send, /* ARP packet send encapsulation routine */
|
||||
0, /* Test routine (unused) */
|
||||
snoop_driver_close, /* Interface close routine */
|
||||
"snp", /* Driver short name */
|
||||
"SNOOP Ethernet", /* Driver long name */
|
||||
14, /* Local net header length */
|
||||
0, /* Local net trailer length */
|
||||
1514, /* Ethernet frame size */
|
||||
IF_ETHERNET, /* MIB type of interfaces using this driver */
|
||||
ARP_HEADER_HARDWARE_TYPE_is_ETHERNET,
|
||||
0, /* No media control routine */
|
||||
#if INSTALL_ATTACHE_IPV6
|
||||
et_ipv6_send, /* IPv6 packet send routine, if installed */
|
||||
#else
|
||||
0,
|
||||
#endif
|
||||
#if INSTALL_ATTACHE_IPV4
|
||||
et_ipv4_send /* IPv4 send routine, if installed */
|
||||
#else
|
||||
0
|
||||
#endif /* INSTALL_ATTACHE_IPV4 */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Routines for finding SNOOP interface devices.
|
||||
* This is just a wrapper to add the Attache-specific things onto snoop_find().
|
||||
*/
|
||||
|
||||
struct snoop_driver_find_state {
|
||||
void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t);
|
||||
int instance;
|
||||
};
|
||||
|
||||
static void snoop_driver_find_one(char *name, void *cookie)
|
||||
{
|
||||
struct snoop_driver_find_state *state = cookie;
|
||||
state->config(name, &snoop_driver, state->instance++, NF_ARP,
|
||||
snoop_driver.maxlen - snoop_driver.lnh - snoop_driver.lnt,
|
||||
TEN_MEGABITS);
|
||||
}
|
||||
|
||||
void snoop_driver_find
|
||||
(void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t))
|
||||
{
|
||||
struct snoop_driver_find_state state;
|
||||
|
||||
state.config = config;
|
||||
state.instance = 0;
|
||||
snoop_find(snoop_driver_find_one, &state);
|
||||
}
|
||||
@@ -0,0 +1,627 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/snrkpsos.c,v 1.3 2003/01/15 14:04:36 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: snrkpsos.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:36 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:27 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.41 2001/06/12 15:57:53 paul
|
||||
* Removed some private debugging code that crept in.
|
||||
*
|
||||
* Revision 1.40 2001/06/12 08:06:26 paul
|
||||
* Seize the Attache lock before calling attache_init().
|
||||
* Init the debug stuff first, so we can debug subsequent init code.
|
||||
* Be more careful with condition variables.
|
||||
*
|
||||
* Revision 1.39 2001/02/09 20:14:05 paul
|
||||
* Trivial cleanup.
|
||||
*
|
||||
* Revision 1.38 2001/01/19 22:23:54 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.37 2000/10/16 19:21:55 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 1.36 2000/03/17 00:12:46 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.35 2000/03/13 21:22:10 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 1.34 1999/04/15 21:38:25 wes
|
||||
* Use symbolic values for flag bits
|
||||
*
|
||||
* Revision 1.33 1999/04/15 17:48:39 wes
|
||||
* Pick up task loop changes similar to recent ones to snarkbsd.c in the
|
||||
* ATTACHE_THREADS case (neatening it up before burial).
|
||||
*
|
||||
* Revision 1.32 1999/04/15 15:45:31 wes
|
||||
* Catch null function pointers with a BUG_ASSERT instead of blithely
|
||||
* leaping into the void.
|
||||
*
|
||||
* Revision 1.31 1999/04/09 21:28:57 wes
|
||||
* clean up isascii prototype and definition.
|
||||
*
|
||||
* Revision 1.30 1999/02/22 21:31:56 wes
|
||||
* let the ATTACHE_THREADS case work again.
|
||||
*
|
||||
* Revision 1.29 1999/02/18 04:41:36 wes
|
||||
* Sockets merge: Everything Else
|
||||
* - memory pools
|
||||
* - thread support
|
||||
* - port-specific headers
|
||||
*
|
||||
* Revision 1.28 1998/12/16 09:09:07 sra
|
||||
* Add magic multicast support for Courier. Change opcode for packet receive
|
||||
* events to avoid customers handing unencapsulated IP packets to et_rcv().
|
||||
*
|
||||
* Revision 1.27 1998/12/12 18:53:40 sra
|
||||
* Changes to pSOS port of Attache: support non-Ethernet NI drivers,
|
||||
* simplify packet buffer implementation, general cleanup.
|
||||
*
|
||||
* Revision 1.26 1998/09/29 20:10:13 meister
|
||||
* delete unused glue_free() code
|
||||
*
|
||||
* Revision 1.25 1998/09/25 21:23:26 meister
|
||||
* queue attache callbacks onto the attache queue such that they are invoked by
|
||||
* same task as is usually calling attache. Fixes re-entrancy bug which crept
|
||||
* in when MUXD task went away and i consolidated timers.
|
||||
*
|
||||
* Revision 1.24 1998/09/22 21:57:53 meister
|
||||
* glue_pktalloc, glue_pktfree, glue_intlock really belong in attache/psos,
|
||||
* not snark/lib for this port.
|
||||
*
|
||||
* Revision 1.23 1998/09/22 19:39:26 wes
|
||||
* Since, at startup, there's a task already queued for us, check the task
|
||||
* queue at the top of the loop instead of the bottom..
|
||||
*
|
||||
* Revision 1.22 1998/09/18 18:52:05 meister
|
||||
* consolidation based on Qing code review
|
||||
*
|
||||
* Revision 1.21 1998/09/15 20:40:20 meister
|
||||
* attache timer is NIDD task's responsibility now
|
||||
*
|
||||
* Revision 1.20 1998/09/15 19:49:55 meister
|
||||
* tweaks to allow single callback function for all pSOS NI's
|
||||
*
|
||||
* Revision 1.19 1998/09/11 19:16:31 meister
|
||||
* handle non-zero-copy NI drivers; pass NI flags into add_psos_nidrv_iface
|
||||
*
|
||||
* Revision 1.18 1998/09/09 16:35:02 meister
|
||||
* changes for multiple NI drivers
|
||||
*
|
||||
* Revision 1.17 1998/09/03 22:19:31 meister
|
||||
* tweaks to populate_attache_ni_table ()
|
||||
*
|
||||
* Revision 1.16 1998/08/07 18:50:17 meister
|
||||
* no more esysconf.h
|
||||
*
|
||||
* Revision 1.15 1998/08/04 22:53:03 meister
|
||||
* changed PEV_QEVENT, MSG_KBDCHAR, etc to have better attache_specific names
|
||||
*
|
||||
* Revision 1.14 1998/08/03 20:46:39 meister
|
||||
* changed declaration for NiLan to BSP_LAN1_ENTRY
|
||||
*
|
||||
* Revision 1.13 1998/08/01 19:44:54 sra
|
||||
* Swap routines live in their own file now.
|
||||
*
|
||||
* Revision 1.12 1998/07/30 22:17:25 meister
|
||||
* simplified add_psos_nidrv_interface(), moved to attache/psos directory
|
||||
*
|
||||
* Revision 1.11 1998/07/24 21:04:02 meister
|
||||
* Added psostty.c
|
||||
* moved nidrive.c to attache/psos
|
||||
*
|
||||
* Revision 1.10 1998/07/17 18:58:43 sra
|
||||
* Swap and checksum routines moved to separate files.
|
||||
*
|
||||
* Revision 1.9 1998/07/14 00:16:19 sra
|
||||
* Use <common/h/config.h>.
|
||||
*
|
||||
* Revision 1.8 1998/07/10 21:52:52 meister
|
||||
* netconfig_find searches through a constructed-at-run-time attache NI table
|
||||
*
|
||||
* Revision 1.7 1998/07/02 06:55:39 sra
|
||||
* Make Snark restartable under pSOS, and other minor cleanups.
|
||||
*
|
||||
* Revision 1.6 1998/06/23 17:51:30 meister
|
||||
* deleted unneeded attache/h/ip.h
|
||||
*
|
||||
* Revision 1.5 1998/06/08 22:05:46 meister
|
||||
* added "unlink" wrapper [calls pHILE remove_f () call]
|
||||
*
|
||||
* Revision 1.4 1998/06/04 23:04:44 meister
|
||||
* strncasecmp shim
|
||||
*
|
||||
* Revision 1.3 1998/05/13 21:18:33 meister
|
||||
* removed some debug code
|
||||
*
|
||||
* Revision 1.2 1998/04/29 23:15:11 meister
|
||||
* Configuration via etc.ini added (over pHILE ramdisk)
|
||||
*
|
||||
* Revision 1.1 1998/04/24 22:04:19 meister
|
||||
* Initial checkin of snark pSOS port
|
||||
*
|
||||
* Initial revision meister
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Implementation of snark for pSOS with Bala's NI shim
|
||||
*/
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
/*
|
||||
* the following are pSOS specific include files, which should be found by the
|
||||
* Diab or other pSOS cross-compiler being used.
|
||||
*/
|
||||
|
||||
#include <psos.h>
|
||||
#include <prepc.h>
|
||||
#if INSTALL_SNARK_PSOS_NEEDS_UNLINK
|
||||
#include <phile.h>
|
||||
#endif
|
||||
#include <gsblk.h>
|
||||
|
||||
#include <sys_conf.h>
|
||||
|
||||
/*
|
||||
* end of pSOS specific includes
|
||||
*/
|
||||
|
||||
#include <wrn/wm/demo/bug_conf.h>
|
||||
#include <wrn/wm/demo/psosinit.h>
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include <wrn/wm/attache/loop.h>
|
||||
#include <wrn/wm/attache/ether.h>
|
||||
#include <wrn/wm/attache/arp.h>
|
||||
#include <wrn/wm/attache/attthd.h>
|
||||
#endif
|
||||
|
||||
#if INSTALL_ENVOY
|
||||
#include <wrn/wm/snmp/engine/snmpdefs.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
#include <wrn/wm/attache/psos/nidrv.h>
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
#include <wrn/wm/demo/netconf.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* These are defined here rather than in snark/lib/main.c so that this
|
||||
* code can be used without that module if the customer so desires.
|
||||
*/
|
||||
int snark_exit_flag, snark_exit_value;
|
||||
|
||||
extern int psos_kbd_getch (void);
|
||||
extern int psos_kbhit (void);
|
||||
|
||||
/*
|
||||
* This function processes a system time received from SNTP. Because we
|
||||
* are in a simulator, we don't want to set the real system time. The
|
||||
* time is represented as seconds (secs) and fractions of a second
|
||||
* (fracs) since 00:00:00 1/1/1900. This is the standard NTP time
|
||||
* representation described in RFC 2030 and others.
|
||||
*
|
||||
* This function is handed the entire SNTP packet, because it is
|
||||
* likely that a real SNTP client would want to enforce some sort
|
||||
* of policy regarding what time sources to believe.
|
||||
*/
|
||||
void glue_set_time(packet *p, bits32_t secs, bits32_t fracs)
|
||||
{
|
||||
/* adjust NTP time representation to Unix time representation. This
|
||||
* method is good enough for most purposes, but not perfect.
|
||||
*/
|
||||
secs -= (bits32_t)2208988800UL;
|
||||
|
||||
printf("\nThe time is: %lu (in UNIX time seconds)\n", secs);
|
||||
}
|
||||
|
||||
/* Low-level keyboard handler stuff. */
|
||||
|
||||
void (*kbd_handler)(unsigned char *, size_t);
|
||||
|
||||
void keyboard_handler(void (*handler)(unsigned char *, size_t))
|
||||
{
|
||||
kbd_handler = handler;
|
||||
}
|
||||
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
|
||||
/*
|
||||
* Network configuration.
|
||||
*/
|
||||
|
||||
extern long BSP_LAN1_ENTRY(unsigned long, void *);
|
||||
extern long BSP_LAN2_ENTRY(unsigned long, void *);
|
||||
extern long NiSlip(unsigned long, void *);
|
||||
extern long NiPPP(unsigned long, void *);
|
||||
|
||||
static void netconfig_find_one(bits16_t flags,
|
||||
int ha_len,
|
||||
bits32_t speed,
|
||||
long (*nidriver)(unsigned long, void *),
|
||||
int nidrv_flags,
|
||||
int nidrv_instance)
|
||||
{
|
||||
net_if *interface;
|
||||
int err;
|
||||
|
||||
interface = add_psos_nidrv_interface (flags, ha_len, speed, nidriver,
|
||||
nidrv_flags, nidrv_instance, &err);
|
||||
|
||||
if (!interface) {
|
||||
/* This should use BUG() */
|
||||
printf ("Error %d configuring pSOS NI driver interface %d\n", err,
|
||||
nidrv_instance);
|
||||
return;
|
||||
}
|
||||
|
||||
if (netconfig_if (interface)) {
|
||||
if_attach(interface);
|
||||
if_up(interface);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void netconfig_find()
|
||||
{
|
||||
int instance = 0;
|
||||
|
||||
#if SC_PNET || SC_PNA
|
||||
netconfig_find_one(NF_DOWN | NF_DRIVER_DOWN | NF_ARP, 6, 10000000L,
|
||||
(long (*)(unsigned long, void *)) MuxLan,
|
||||
BSP_LAN1_FLAGS, ++instance);
|
||||
#else
|
||||
netconfig_find_one(NF_DOWN | NF_DRIVER_DOWN | NF_ARP, 6, 10000000L,
|
||||
BSP_LAN1_ENTRY, BSP_LAN1_FLAGS, ++instance);
|
||||
#endif
|
||||
|
||||
#if INSTALL_SNARK_PSOS_BSP_LAN2
|
||||
netconfig_find_one(NF_DOWN | NF_DRIVER_DOWN | NF_ARP, 6, 10000000L,
|
||||
BSP_LAN2_ENTRY, BSP_LAN2_FLAGS, ++instance);
|
||||
#endif
|
||||
|
||||
#if INSTALL_SNARK_PSOS_SLIP
|
||||
|
||||
/*
|
||||
* This must happen before the NI_INIT call to NiSlip.
|
||||
* May as well do it here.
|
||||
*/
|
||||
NiSlipSetup(9600L);
|
||||
|
||||
netconfig_find_one(NF_DOWN | NF_DRIVER_DOWN, 6, 9600L, NiSlip,
|
||||
IFF_NOARP|IFF_POINTTOPOINT|IFF_RAWMEM|IFF_POLL,
|
||||
++instance);
|
||||
|
||||
#endif /* INSTALL_SNARK_PSOS_SLIP */
|
||||
}
|
||||
|
||||
#endif /* INSTALL_ATTACHE */
|
||||
|
||||
|
||||
|
||||
/* Initialization and shutdown. */
|
||||
|
||||
void snark_init()
|
||||
{
|
||||
sty_init();
|
||||
|
||||
#if INSTALL_SNARK_BUG_CONF
|
||||
bug_config();
|
||||
#endif
|
||||
|
||||
tasks_init();
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
ATTACHE_LOCK();
|
||||
attache_init();
|
||||
ATTACHE_UNLOCK();
|
||||
#endif
|
||||
|
||||
#if INSTALL_ENVOY
|
||||
envoy_init();
|
||||
#endif
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
netconfig ();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void snark_shutdown()
|
||||
{
|
||||
#if INSTALL_ATTACHE && INSTALL_ATTACHE_SHUTDOWN
|
||||
attache_shutdown();
|
||||
#endif
|
||||
#if INSTALL_ATTACHE_THREADS
|
||||
ATTACHE_UNLOCK();
|
||||
task_kick();
|
||||
ETC_THD_YIELD();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if INSTALL_ATTACHE_SOCKETS
|
||||
static void (*deferred_io_handler)(void);
|
||||
static void (*deferred_io_first)(void);
|
||||
|
||||
void glue_set_deferred_io_handler (void (*first)(void), void (*handler)(void))
|
||||
{
|
||||
deferred_io_first = first;
|
||||
deferred_io_handler = handler;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if INSTALL_ATTACHE_THREADS
|
||||
|
||||
static ULONG TKRDTid;
|
||||
|
||||
etc_cond_t task_cond;
|
||||
|
||||
#define CLIENT_USRSTACK 16384 /* User stack size of client task */
|
||||
#define CLIENT_SYSSTACK 4096 /* Supervisor stack size */
|
||||
#define CLIENT_FLAGS 0x00 /* Flags for client task */
|
||||
#define CLIENT_INITMODE T_SUPV /* Initial mode of the client task */
|
||||
|
||||
void tasks_run_guts(void)
|
||||
{
|
||||
struct task *task;
|
||||
|
||||
ATTACHE_LOCK();
|
||||
while (!snark_exit_flag) {
|
||||
while ((task = task_deq()) != 0 && task->func != 0)
|
||||
{
|
||||
task->func(task, task->cookie);
|
||||
if (snark_exit_flag)
|
||||
break;
|
||||
}
|
||||
if (snark_exit_flag)
|
||||
break;
|
||||
ETC_COND_WAIT(&task_cond, &attache_lock);
|
||||
}
|
||||
ATTACHE_UNLOCK();
|
||||
t_suspend(0);
|
||||
}
|
||||
|
||||
void task_kick(void)
|
||||
{
|
||||
/* this gets called from task_enq from task_add, before tasks_run,
|
||||
* where the condition variable is actually initialized
|
||||
*/
|
||||
if (TKRDTid != 0)
|
||||
ETC_COND_BROADCAST(&task_cond, &attache_lock);
|
||||
}
|
||||
|
||||
#endif /* INSTALL_ATTACHE_THREADS */
|
||||
|
||||
/*
|
||||
* tasks_run() function, using system-independent tasking queue.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the main body of the task dispatcher.
|
||||
* If it ever returns, main() should exit immediately with the same value.
|
||||
*/
|
||||
|
||||
extern int snark_exit_flag;
|
||||
extern int snark_exit_value;
|
||||
|
||||
int tasks_run()
|
||||
{
|
||||
#if !INSTALL_ATTACHE_THREADS
|
||||
struct task *task;
|
||||
#endif
|
||||
unsigned long rc, events, msg[4], PacketQueue;
|
||||
|
||||
ATTACHE_LOCK();
|
||||
|
||||
/*
|
||||
* Find out where to get Attache packets from.
|
||||
*/
|
||||
|
||||
PacketQueue = GetAttacheQueueId ();
|
||||
|
||||
/*
|
||||
* Register my task ID so I get ATTACHE_PSOS_QEVENT notifications from the
|
||||
* NIDD task.
|
||||
*/
|
||||
|
||||
RegisterAttacheReceiver (0L, ATTACHE_NIDRV_SEND_PKTEVENTS);
|
||||
|
||||
#if INSTALL_ATTACHE_THREADS
|
||||
{
|
||||
ULONG parms[4];
|
||||
|
||||
if ((rc = ETC_COND_INIT(&task_cond, &attache_lock)) != 0) {
|
||||
printf("tasks_run: ETC_COND_INIT failed!\n");
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* !!! priority?? */
|
||||
rc = t_create("TKRD", 190, CLIENT_SYSSTACK, CLIENT_USRSTACK,
|
||||
CLIENT_FLAGS, &TKRDTid);
|
||||
if (rc != 0)
|
||||
{
|
||||
BUG(BUG_ATTACHE_PSOS_NIDRV_INFO, BUG_CONTINUABLE, (void *) 0,
|
||||
(BUG_OUT, "Task creation error %lx (TKRD)\n", rc));
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = t_start(TKRDTid, CLIENT_INITMODE, tasks_run_guts, parms);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
BUG(BUG_ATTACHE_PSOS_NIDRV_INFO, BUG_CONTINUABLE, (void *) 0,
|
||||
(BUG_OUT, "Task start error %lx (TKRD)\n", rc));
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
#endif /* INSTALL_ATTACHE_THREADS */
|
||||
|
||||
|
||||
/*
|
||||
* Wait on events. The daemon task waits "forever" processing various
|
||||
* events (packet receive, timer, and keystroke).
|
||||
*/
|
||||
|
||||
while (!snark_exit_flag) {
|
||||
|
||||
/*
|
||||
* First look for a received packet, callback, or keystroke.
|
||||
*/
|
||||
while ((rc = q_receive(PacketQueue, Q_NOWAIT, 0, msg)) == 0) {
|
||||
|
||||
switch (GET_ATTACHE_PSOS_MSG_OPCODE(msg)) {
|
||||
|
||||
case ATTACHE_PSOS_MSG_CALLBACK:
|
||||
/*
|
||||
* This is an Attache callback function; call it
|
||||
*/
|
||||
{
|
||||
void (*callback)(void) = GET_ATTACHE_PSOS_MSG_CBFUNC(msg);
|
||||
BUG_ASSERT(callback != NULL);
|
||||
(*callback)();
|
||||
continue;
|
||||
}
|
||||
|
||||
case ATTACHE_PSOS_MSG_PKTFUNC:
|
||||
/*
|
||||
* This is a packet for Attache
|
||||
*/
|
||||
{
|
||||
packet *p = GET_ATTACHE_PSOS_MSG_PKTBUF(msg);
|
||||
void (*receiver)(packet *) = GET_ATTACHE_PSOS_MSG_PKTRCV(msg);
|
||||
BUG_ASSERT(receiver != NULL);
|
||||
(*receiver)(p);
|
||||
continue;
|
||||
}
|
||||
|
||||
case ATTACHE_PSOS_MSG_KBDCHAR:
|
||||
/*
|
||||
* This is a snark keyboard event.
|
||||
*/
|
||||
if (kbd_handler) {
|
||||
unsigned char ch = GET_ATTACHE_PSOS_MSG_CHAR(msg);
|
||||
(*kbd_handler) (&ch, 1);
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
printf("ATTD: unexpected queue message\n");
|
||||
}
|
||||
|
||||
if (rc != ERR_NOMSG) {
|
||||
printf("ATTD: q_receive failed\n");
|
||||
break;
|
||||
}
|
||||
|
||||
#if !INSTALL_ATTACHE_THREADS
|
||||
/*
|
||||
* Next, look for a snark "task" to run.
|
||||
*/
|
||||
if ((task = task_deq()) != 0 && task->func != 0) {
|
||||
task->func(task, task->cookie);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
ATTACHE_UNLOCK();
|
||||
|
||||
#if INSTALL_ATTACHE_SOCKETS
|
||||
if (deferred_io_handler) {
|
||||
if (deferred_io_first) {
|
||||
(*deferred_io_first)();
|
||||
deferred_io_first = NULL;
|
||||
}
|
||||
(*deferred_io_handler)();
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* When we get here, we've run out of things to do, so go to sleep.
|
||||
*/
|
||||
if (ev_receive(ATTACHE_PSOS_QEVENT, EV_ANY, 0, &events)) {
|
||||
printf("ATTD: ev_receive() failed\n");
|
||||
break;
|
||||
}
|
||||
|
||||
ATTACHE_LOCK();
|
||||
|
||||
/*
|
||||
* This is the only event we expect to receive.
|
||||
*/
|
||||
BUG_ASSERT(events == ATTACHE_PSOS_QEVENT);
|
||||
|
||||
}
|
||||
|
||||
snark_shutdown();
|
||||
#if INSTALL_SNARK_POOL_TEST_METRICS
|
||||
{
|
||||
void pool_report(void);
|
||||
pool_report();
|
||||
}
|
||||
#endif
|
||||
t_suspend(0);
|
||||
return snark_exit_value;
|
||||
}
|
||||
|
||||
int etc_isascii (char c)
|
||||
{
|
||||
return !(c & ~0x7f);
|
||||
}
|
||||
|
||||
|
||||
#if INSTALL_SNARK_PSOS_NEEDS_UNLINK
|
||||
int unlink (char *f)
|
||||
{
|
||||
return (int) remove_f (f);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/strdup.c,v 1.3 2003/01/15 14:04:36 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: strdup.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:36 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:28 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.3 2001/01/19 22:23:54 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.2 2000/03/17 00:12:47 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.1 1998/06/03 21:16:35 sar
|
||||
* A local version of the strdup function so that the demo code
|
||||
* can use it without worring about its existence
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/* This used to be part of snmptalk/stdf.h it has been moved to
|
||||
the snark library so other demo code can use it. The other
|
||||
stdf functions were moved to the common library. */
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <wrn/wm/common/config.h>
|
||||
|
||||
#include <snark.h>
|
||||
#include <wrn/wm/demo/strdup.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
char *
|
||||
etc_strdup(char *str)
|
||||
{
|
||||
char *ans;
|
||||
|
||||
ans = (char *)GLUE_ALLOC(STRLEN(str) + 1);
|
||||
if (ans)
|
||||
STRCPY(ans, str);
|
||||
return ans;
|
||||
}
|
||||
|
||||
void
|
||||
etc_strdup_free(char *str)
|
||||
{
|
||||
GLUE_FREE(str);
|
||||
}
|
||||
@@ -0,0 +1,436 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/sty.c,v 1.3 2003/01/15 14:04:36 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: sty.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:36 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:28 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.14 2001/01/19 22:23:54 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.13 2000/03/17 00:12:47 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.12 1999/05/21 16:45:22 sra
|
||||
* vsnprintf() => VSNPRINTF().
|
||||
*
|
||||
* Revision 2.11 1998/07/02 06:55:39 sra
|
||||
* Make Snark restartable under pSOS, and other minor cleanups.
|
||||
*
|
||||
* Revision 2.10 1998/06/03 21:22:15 sar
|
||||
* Updated code to use the common string macros
|
||||
*
|
||||
* Revision 2.9 1998/02/25 04:57:42 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.8 1997/03/20 06:53:14 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.7 1997/03/19 22:06:00 sra
|
||||
* Perhaps we should include install.h before testing install options?
|
||||
*
|
||||
* Revision 2.6 1997/03/19 20:19:50 sra
|
||||
* Remove gratuitous Attache dependencies.
|
||||
*
|
||||
* Revision 2.5 1997/03/19 04:47:35 sra
|
||||
* Get rid of some gratuitous historical dependencies on Attache.
|
||||
*
|
||||
* Revision 2.4 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.3 1997/02/19 08:10:29 sra
|
||||
* More fun merging snmptalk into snark, general snark cleanup.
|
||||
*
|
||||
* Revision 2.2 1996/10/29 03:02:38 sra
|
||||
* Duh, maybe we should free the history list when we close the sty?
|
||||
* Another ancient bug nailed thanks to Purify....
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.5 1995/04/28 03:44:03 sra
|
||||
* Check for null pointer properly in sty_yank().
|
||||
*
|
||||
* Revision 1.4 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.3 1993/07/31 01:25:44 sra
|
||||
* Include <snark.h> when building, for vsnprintf().
|
||||
*
|
||||
* Revision 1.2 1993/07/30 23:45:30 sra
|
||||
* Cosmetic changes to make Borland C++ 3.1 happy.
|
||||
*
|
||||
* Revision 1.1 1993/07/05 21:53:30 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Software terminal support for snark.
|
||||
*
|
||||
* As much of this code as possible was taken from Bridgham's
|
||||
* doskbd.c package.
|
||||
*/
|
||||
|
||||
/* ANSI C files. */
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
|
||||
/* Local files. */
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
/* The console -- see usage note in snark/h/sty.h. */
|
||||
struct sty *cty;
|
||||
|
||||
/* Internal cruft. */
|
||||
static sty_listener_t sty_listener;
|
||||
static void sty_read_loop(struct sty *);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* low level ring buffer routines
|
||||
*/
|
||||
|
||||
/* private */
|
||||
|
||||
#define sty_ring_empty(_sty_) \
|
||||
((_sty_)->ring_start == (_sty_)->ring_end)
|
||||
|
||||
#define sty_ring_full(_sty_) \
|
||||
((_sty_)->ring_end - (_sty_)->ring_start + 1 == 0)
|
||||
|
||||
static int sty_getch(struct sty *sty)
|
||||
{
|
||||
if (!sty_ring_empty(sty)) {
|
||||
int c = sty->ring_buf[sty->ring_start++];
|
||||
if (sty->ring_start >= sizeof(sty->ring_buf))
|
||||
sty->ring_start = 0;
|
||||
return c;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* public */
|
||||
|
||||
unsigned sty_window(struct sty *sty)
|
||||
{
|
||||
if (!sty)
|
||||
return 0;
|
||||
return sizeof(sty->ring_buf) + sty->ring_start - sty->ring_end;
|
||||
}
|
||||
|
||||
void sty_receive(struct sty *sty, unsigned char *text, unsigned length)
|
||||
{
|
||||
if (!sty || !text)
|
||||
return;
|
||||
|
||||
do {
|
||||
for ( ; length > 0 && !sty_ring_full(sty); length--) {
|
||||
sty->ring_buf[sty->ring_end++] = *text++;
|
||||
if (sty->ring_end >= sizeof(sty->ring_buf))
|
||||
sty->ring_end = 0;
|
||||
}
|
||||
if (sty->app_receiver)
|
||||
sty_read_loop(sty);
|
||||
} while (length > 0 && !sty_ring_full(sty));
|
||||
|
||||
while (length-- > 0)
|
||||
sty_puts(sty, "\007");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* command line editing level routines
|
||||
*/
|
||||
|
||||
static void sty_erase_char(struct sty *sty)
|
||||
{
|
||||
if (sty->line_len > 0) {
|
||||
sty->line_len--;
|
||||
if (sty->flags & STY_FLAG_ECHOING)
|
||||
sty_puts(sty, "\010 \010");
|
||||
}
|
||||
}
|
||||
|
||||
static void sty_erase_line(struct sty *sty)
|
||||
{
|
||||
if (sty->flags & STY_FLAG_ECHOING)
|
||||
while (sty->line_len-- > 0)
|
||||
sty_puts(sty, "\010 \010");
|
||||
sty->line_len = 0;
|
||||
}
|
||||
|
||||
static void sty_yank(register struct sty *sty)
|
||||
{
|
||||
if (sty->history[sty->history_ptr] == 0)
|
||||
return;
|
||||
for ( ; sty->line_len > 0; sty->line_len--)
|
||||
sty_puts(sty, "\010 \010");
|
||||
while ((sty->line_buf[sty->line_len]
|
||||
= sty->history[sty->history_ptr][sty->line_len]) != '\0')
|
||||
sty->line_len++;
|
||||
sty_puts(sty, (char *) sty->line_buf);
|
||||
}
|
||||
|
||||
#define sty_historical_interest(_sty_) \
|
||||
((_sty_)->line_len != 0 && \
|
||||
(!(_sty_)->history[STY_HISTORY_SIZE - 1] || \
|
||||
STRCMP((_sty_)->line_buf, (_sty_)->history[STY_HISTORY_SIZE - 1]) != 0))
|
||||
|
||||
/* implements the main editing loop */
|
||||
static void sty_read_loop(struct sty *sty)
|
||||
{
|
||||
void (*receiver)(struct sty *, char *, void *);
|
||||
int c, i;
|
||||
|
||||
while ((c = sty_getch(sty)) != -1) {
|
||||
|
||||
if (sty->flags & STY_FLAG_RAWMODE) {
|
||||
if (sty->flags & STY_FLAG_ECHOING)
|
||||
sty_putc(sty, c);
|
||||
sty->line_buf[0] = (char) c;
|
||||
receiver = sty->app_receiver;
|
||||
sty->app_receiver = 0;
|
||||
receiver(sty, sty->line_buf, sty->app_cookie);
|
||||
return;
|
||||
} else {
|
||||
switch (c) {
|
||||
case '\n':
|
||||
case '\r': /* send the line on */
|
||||
if (sty->flags & STY_FLAG_ECHOING)
|
||||
sty_puts(sty, "\n");
|
||||
sty->line_buf[sty->line_len] = '\0';
|
||||
if (sty_historical_interest(sty)) {
|
||||
if (sty->history[0])
|
||||
GLUE_FREE(sty->history[0]);
|
||||
for (i = 0; i < STY_HISTORY_SIZE - 1; i++)
|
||||
sty->history[i] = sty->history[i+1];
|
||||
sty->history[STY_HISTORY_SIZE - 1]
|
||||
= GLUE_ALLOC(STRLEN(sty->line_buf)+1);
|
||||
if (sty->history[STY_HISTORY_SIZE - 1])
|
||||
STRCPY(sty->history[STY_HISTORY_SIZE - 1], sty->line_buf);
|
||||
}
|
||||
sty->history_ptr = 0;
|
||||
sty->line_len = 0;
|
||||
receiver = sty->app_receiver;
|
||||
sty->app_receiver = 0;
|
||||
receiver(sty, sty->line_buf, sty->app_cookie);
|
||||
return;
|
||||
case '\177': /* delete */
|
||||
case 'H' & 077: /* backspace (C-H) */
|
||||
sty_erase_char(sty);
|
||||
continue;
|
||||
case 'U' & 077: /* C-U */
|
||||
sty_erase_line(sty);
|
||||
continue;
|
||||
case 'P' & 077: /* control-p */
|
||||
sty->history_ptr--;
|
||||
if ((sty->history_ptr < 0) || (sty->history[sty->history_ptr] == 0))
|
||||
sty->history_ptr = STY_HISTORY_SIZE - 1;
|
||||
sty_yank(sty);
|
||||
continue;
|
||||
case 'N' & 077: /* control-n */
|
||||
sty->history_ptr++;
|
||||
if (sty->history_ptr >= STY_HISTORY_SIZE - 1) {
|
||||
if (sty->history[STY_HISTORY_SIZE - 1] == 0) {
|
||||
sty->history_ptr = STY_HISTORY_SIZE - 1;
|
||||
continue;
|
||||
}
|
||||
for (sty->history_ptr = 0;
|
||||
sty->history[sty->history_ptr] == 0;
|
||||
sty->history_ptr++)
|
||||
; /* find the oldest */
|
||||
}
|
||||
sty_yank(sty);
|
||||
continue;
|
||||
case 'Y' & 077: /* control-y */
|
||||
sty->history_ptr = STY_HISTORY_SIZE - 1;
|
||||
sty_yank(sty);
|
||||
continue;
|
||||
case '\f': /* control-l */
|
||||
sty_puts(sty, "\033[;H\033[2J");
|
||||
if (sty->prompt)
|
||||
sty_puts(sty, sty->prompt);
|
||||
sty_write(sty, sty->line_buf, sty->line_len);
|
||||
continue;
|
||||
default:
|
||||
if (isascii(c) && isprint(c) &&
|
||||
sty->line_len < sizeof(sty->line_buf)-1) {
|
||||
sty->line_buf[sty->line_len++] = (char) c;
|
||||
if (sty->flags & STY_FLAG_ECHOING)
|
||||
sty_putc(sty, c);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If we get here, the keyboard buffer is empty. If the driver is
|
||||
* null, we've hit EOF, otherwise we need to wait for more input.
|
||||
*/
|
||||
if (!sty->driver) {
|
||||
sty->line_len = 0;
|
||||
receiver = sty->app_receiver;
|
||||
sty->app_receiver = 0;
|
||||
receiver(sty, 0, sty->app_cookie);
|
||||
}
|
||||
}
|
||||
|
||||
void sty_read
|
||||
(struct sty *sty,
|
||||
void (*receiver)(struct sty *, char *, void *),
|
||||
char *prompt,
|
||||
void *cookie)
|
||||
{
|
||||
sty->app_receiver = receiver;
|
||||
sty->app_cookie = cookie;
|
||||
sty->prompt = prompt;
|
||||
if (prompt)
|
||||
sty_puts(sty, prompt);
|
||||
sty_read_loop(sty);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Output routines.
|
||||
*/
|
||||
|
||||
void sty_write(struct sty *sty, char *text, size_t len)
|
||||
{
|
||||
if (sty && sty->driver && text && len)
|
||||
sty->driver->write(sty, (unsigned char *) text, len, sty->driver_cookie);
|
||||
}
|
||||
|
||||
void sty_putc(struct sty *sty, int c)
|
||||
{
|
||||
char text[1];
|
||||
text[0] = (char) c;
|
||||
sty_write(sty, text, 1);
|
||||
}
|
||||
|
||||
void sty_puts(struct sty *sty, char *text)
|
||||
{
|
||||
sty_write(sty, text, STRLEN(text));
|
||||
}
|
||||
|
||||
int sty_printf(struct sty *sty, char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int val;
|
||||
char buffer[2000];
|
||||
|
||||
va_start(ap, fmt);
|
||||
val = VSNPRINTF(buffer, sizeof(buffer), fmt, ap);
|
||||
va_end(ap);
|
||||
sty_puts(sty, buffer);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void sty_discard(struct sty *sty)
|
||||
{
|
||||
sty->ring_start = sty->ring_end = 0;
|
||||
sty_erase_line(sty);
|
||||
}
|
||||
|
||||
|
||||
|
||||
sty_listener_t sty_listen(sty_listener_t new_listener)
|
||||
{
|
||||
sty_listener_t old_listener = sty_listener;
|
||||
sty_listener = new_listener;
|
||||
return old_listener;
|
||||
}
|
||||
|
||||
void sty_open
|
||||
(struct sty *sty,
|
||||
struct sty_driver *driver,
|
||||
unsigned flags,
|
||||
void *cookie)
|
||||
{
|
||||
if (!sty)
|
||||
return;
|
||||
MEMSET((void *) sty, 0, sizeof(*sty));
|
||||
sty->driver = driver;
|
||||
sty->flags = flags;
|
||||
sty->driver_cookie = cookie;
|
||||
if (sty_listener)
|
||||
sty_listener(sty);
|
||||
}
|
||||
|
||||
void sty_init()
|
||||
{
|
||||
sty_listener = 0;
|
||||
cty = 0;
|
||||
}
|
||||
|
||||
void sty_close(struct sty *sty)
|
||||
{
|
||||
struct sty_driver *driver;
|
||||
int i;
|
||||
|
||||
if (sty) {
|
||||
for (i = 0; i < STY_HISTORY_SIZE; i++) {
|
||||
if (sty->history[i]) {
|
||||
GLUE_FREE(sty->history[i]);
|
||||
sty->history[i] = 0;
|
||||
}
|
||||
}
|
||||
driver = sty->driver;
|
||||
sty->driver = 0;
|
||||
if (driver && driver->close)
|
||||
driver->close(sty, sty->driver_cookie);
|
||||
}
|
||||
}
|
||||
|
||||
void cty_set(struct sty *sty)
|
||||
{
|
||||
cty = sty;
|
||||
|
||||
#if 0
|
||||
sty_puts(cty, "XX ITS 2268 SYSTEM JOB USING THIS CONSOLE.\n");
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/sty_kb.c,v 1.3 2003/01/15 14:04:37 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: sty_kb.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:37 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:28 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.12 2001/01/19 22:23:54 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.11 2000/03/17 00:12:47 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.10 1998/07/04 00:43:25 sra
|
||||
* Allow configuration of initial sty flags.
|
||||
*
|
||||
* Revision 2.9 1998/07/02 06:55:40 sra
|
||||
* Make Snark restartable under pSOS, and other minor cleanups.
|
||||
*
|
||||
* Revision 2.8 1998/02/25 04:57:42 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.7 1997/03/20 06:53:15 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.6 1997/03/19 22:06:08 sra
|
||||
* Perhaps we should include install.h before testing install options?
|
||||
*
|
||||
* Revision 2.5 1997/03/19 20:19:37 sra
|
||||
* Remove gratuitous Attache dependencies.
|
||||
*
|
||||
* Revision 2.4 1997/03/19 04:47:35 sra
|
||||
* Get rid of some gratuitous historical dependencies on Attache.
|
||||
*
|
||||
* Revision 2.3 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.2 1997/02/19 08:10:29 sra
|
||||
* More fun merging snmptalk into snark, general snark cleanup.
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.4 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.3 1993/07/31 23:27:08 sra
|
||||
* Change stykb_driver_write() to use keyboard_write().
|
||||
*
|
||||
* Revision 1.2 1993/07/30 23:44:24 sra
|
||||
* Cosmetic changes to make Borland C++ 3.1 happy.
|
||||
*
|
||||
* Revision 1.1 1993/07/05 21:53:30 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Sty driver code for low-level virtual snark keyboard.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
#ifndef SNARK_STYKB_INITIAL_FLAGS
|
||||
#define SNARK_STYKB_INITIAL_FLAGS STY_FLAG_ECHOING
|
||||
#endif
|
||||
|
||||
static struct sty stykb_sty;
|
||||
|
||||
static void stykb_driver_write
|
||||
(struct sty *sty, unsigned char *text, size_t length, void *cookie)
|
||||
{
|
||||
keyboard_write(text, length);
|
||||
}
|
||||
|
||||
static void stykb_driver_close(struct sty *sty, void *cookie)
|
||||
{
|
||||
keyboard_handler(0);
|
||||
}
|
||||
|
||||
static struct sty_driver stykb_driver = {
|
||||
stykb_driver_write,
|
||||
stykb_driver_close
|
||||
};
|
||||
|
||||
static void stykb_handler(unsigned char *text, size_t length)
|
||||
{
|
||||
sty_receive(&stykb_sty, text, length);
|
||||
}
|
||||
|
||||
void stykb_open(void)
|
||||
{
|
||||
sty_open(&stykb_sty, &stykb_driver, SNARK_STYKB_INITIAL_FLAGS, 0);
|
||||
keyboard_handler(stykb_handler);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/sty_log.c,v 1.3 2003/01/15 14:04:37 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: sty_log.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:37 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:28 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.11 2001/01/19 22:23:54 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.10 2000/03/17 00:12:47 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.9 1999/05/21 16:45:21 sra
|
||||
* vsnprintf() => VSNPRINTF().
|
||||
*
|
||||
* Revision 2.8 1998/07/02 06:55:40 sra
|
||||
* Make Snark restartable under pSOS, and other minor cleanups.
|
||||
*
|
||||
* Revision 2.7 1998/02/25 04:57:43 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.6 1997/03/20 06:53:15 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.5 1997/03/19 22:05:19 sra
|
||||
* Perhaps we should include install.h before testing install options?
|
||||
*
|
||||
* Revision 2.4 1997/03/19 20:19:26 sra
|
||||
* Remove gratuitous Attache dependencies.
|
||||
*
|
||||
* Revision 2.3 1997/03/19 04:47:35 sra
|
||||
* Get rid of some gratuitous historical dependencies on Attache.
|
||||
*
|
||||
* Revision 2.2 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.2 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.1 1993/07/05 21:53:30 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Software terminal support for snark.
|
||||
*
|
||||
* This module implements the PRINTF() function used in Attache.
|
||||
* To avoid possible confusion by case-insensitive linkers, the function
|
||||
* we define here is called sty_log(). A #define of PRINTF to sty_log()
|
||||
* should be added to attache.h to use this feature.
|
||||
*/
|
||||
|
||||
/* ANSI C files. */
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <wrn/wm/common/install.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
static struct sty *log_sty;
|
||||
|
||||
struct sty *sty_setlog(struct sty *newsty)
|
||||
{
|
||||
struct sty *oldsty = log_sty;
|
||||
log_sty = newsty;
|
||||
return oldsty;
|
||||
}
|
||||
|
||||
void sty_log(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int val;
|
||||
char buffer[2000];
|
||||
|
||||
va_start(ap, fmt);
|
||||
if (log_sty) {
|
||||
VSNPRINTF(buffer, sizeof(buffer), fmt, ap);
|
||||
sty_puts(log_sty, buffer);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,304 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/sty_tn.c,v 1.2 2001/11/08 15:56:30 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: sty_tn.c,v $
|
||||
* Revision 1.2 2001/11/08 15:56:30 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.11 2001/01/19 22:23:55 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.10 2000/03/17 00:12:48 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.9 2000/03/13 21:22:11 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 2.8 1999/02/18 04:41:36 wes
|
||||
* fixed printf format problem
|
||||
*
|
||||
* Revision 2.7 1998/07/02 06:55:40 sra
|
||||
* Make Snark restartable under pSOS, and other minor cleanups.
|
||||
*
|
||||
* Revision 2.6 1998/02/25 04:57:43 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.5 1997/03/20 06:53:16 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.4 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.3 1996/10/29 03:03:14 sra
|
||||
* Duh, maybe we should free the sty when we close the connection?
|
||||
* Another ancient bug nailed thanks to Purify....
|
||||
*
|
||||
* Revision 2.2 1996/10/26 08:03:42 sra
|
||||
* Fiddle things so that we always include attache/h/glue.h.
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.5 1995/04/23 01:10:39 sra
|
||||
* More header files.
|
||||
*
|
||||
* Revision 1.4 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.3 1994/09/04 06:13:38 sra
|
||||
* Clean up antique type names and install macros.
|
||||
*
|
||||
* Revision 1.2 1993/07/30 23:45:23 sra
|
||||
* Cosmetic changes to make Borland C++ 3.1 happy.
|
||||
*
|
||||
* Revision 1.1 1993/07/05 21:53:30 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Sty driver code for Attache telnet.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
|
||||
#if INSTALL_ATTACHE_TCP
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/tcp.h>
|
||||
#endif
|
||||
|
||||
#include <wrn/wm/attache/tn.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
|
||||
#include <wrn/wm/demo/sty.h>
|
||||
|
||||
/* Debugging frob */
|
||||
#ifndef TNSTY_COUNT_BLOCKAGES
|
||||
#define TNSTY_COUNT_BLOCKAGES 0
|
||||
#endif
|
||||
|
||||
static void stytn_driver_write
|
||||
(struct sty *sty,
|
||||
unsigned char *text,
|
||||
size_t length,
|
||||
void *tn)
|
||||
{
|
||||
if (tn && text && length)
|
||||
(void) tn_send_text(tn, text, length);
|
||||
}
|
||||
|
||||
static void stytn_driver_close(struct sty *sty, void *tn)
|
||||
{
|
||||
if (tn)
|
||||
(void) tn_send_close(tn);
|
||||
}
|
||||
|
||||
static struct sty_driver stytn_driver = {
|
||||
stytn_driver_write,
|
||||
stytn_driver_close
|
||||
};
|
||||
|
||||
/* Just collect characters from the keyboard. */
|
||||
static void stytn_text
|
||||
(struct tn_connection *tn, unsigned char text[], unsigned length)
|
||||
{
|
||||
sty_receive(tn_get_cookie(tn), text, length);
|
||||
}
|
||||
|
||||
/* Window control stuff for TELNET. */
|
||||
|
||||
unsigned stytn_space_initial = STY_RING_SIZE;
|
||||
|
||||
unsigned stytn_space_left(struct tn_connection *tn)
|
||||
{
|
||||
return sty_window(tn_get_cookie(tn));
|
||||
}
|
||||
|
||||
static void stytn_open(struct tn_connection *tn)
|
||||
{
|
||||
struct sty *sty = (struct sty *) GLUE_ALLOC(sizeof(*sty));
|
||||
if (!sty) {
|
||||
tn_abort(tn);
|
||||
} else {
|
||||
tn_set_cookie(tn, sty);
|
||||
sty_open(sty, &stytn_driver, 0, tn);
|
||||
(void) tn_send_negotiation(tn, TN_OPT_ECHO, 0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void stytn_ip(struct tn_connection *tn)
|
||||
{
|
||||
struct sty *sty = tn_get_cookie(tn);
|
||||
if (sty)
|
||||
sty->flags |= STY_FLAG_INTERRUPTED;
|
||||
}
|
||||
|
||||
static void stytn_ao(struct tn_connection *tn)
|
||||
{
|
||||
struct sty *sty = tn_get_cookie(tn);
|
||||
if (sty)
|
||||
sty->flags |= STY_FLAG_ABORTED;
|
||||
}
|
||||
|
||||
static void stytn_ayt(struct tn_connection *tn)
|
||||
{
|
||||
struct sty *sty = tn_get_cookie(tn);
|
||||
if (sty) {
|
||||
bits32_t now = GLUE_NOW();
|
||||
sty_printf(sty, "[It's now %lu:%02lu:%02lu.%03lu Beandorfian Standard Time]\n",
|
||||
(now/3600000L), (now/60000L)%60, (now/1000L)%60, now%1000L);
|
||||
}
|
||||
}
|
||||
|
||||
static void stytn_close(struct tn_connection *tn)
|
||||
{
|
||||
struct sty *sty = tn_get_cookie(tn);
|
||||
if (sty) {
|
||||
sty_close(sty);
|
||||
GLUE_FREE(sty);
|
||||
tn_set_cookie(tn, 0);
|
||||
}
|
||||
}
|
||||
|
||||
#if TNSTY_COUNT_BLOCKAGES
|
||||
long stytn_blockages = 0;
|
||||
#endif
|
||||
|
||||
static void stytn_error(struct tn_connection *tn, enum tn_error code)
|
||||
{
|
||||
struct sty *sty = tn_get_cookie(tn);
|
||||
|
||||
switch (code) {
|
||||
case TN_ERROR_WINDOW_CLOSED:
|
||||
sty->flags |= STY_FLAG_BLOCKED;
|
||||
#if STYTN_COUNT_BLOCKAGES
|
||||
stytn_blockages++;
|
||||
#endif
|
||||
return;
|
||||
case TN_ERROR_WINDOW_OPENED:
|
||||
sty->flags &= ~STY_FLAG_BLOCKED;
|
||||
#if STYTN_COUNT_BLOCKAGES
|
||||
stytn_blockages--;
|
||||
#endif
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static int stytn_echo
|
||||
(struct tn_connection *tn,
|
||||
enum tn_ctl control,
|
||||
enum tn_opt option,
|
||||
unsigned char *text,
|
||||
unsigned text_length,
|
||||
int entire)
|
||||
{
|
||||
struct sty *sty = tn_get_cookie(tn);
|
||||
|
||||
if (sty) {
|
||||
switch (control) {
|
||||
case TN_CTL_DO:
|
||||
sty->flags |= STY_FLAG_ECHOING;
|
||||
return 1;
|
||||
case TN_CTL_DONT:
|
||||
sty->flags &= ~STY_FLAG_ECHOING;
|
||||
return 0;
|
||||
default: /* Make GCC -Wall happy */
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static tn_option_dispatch_vector stytn_options = {
|
||||
tn_handle_transmit_binary, /* TN_OPT_TRANSMIT_BINARY */
|
||||
stytn_echo, /* TN_OPT_ECHO */
|
||||
0, /* TN_OPT_RCP */
|
||||
tn_handle_suppress_go_ahead, /* TN_OPT_SUPPRESS_GO_AHEAD */
|
||||
0, /* TN_OPT_NAMS */
|
||||
tn_handle_status, /* TN_OPT_STATUS */
|
||||
0, /* TN_OPT_TIMING_MARK */
|
||||
0, /* TN_OPT_RCTE */
|
||||
0, /* TN_OPT_NAOL */
|
||||
0, /* TN_OPT_NAOP */
|
||||
0, /* TN_OPT_NAOCRD */
|
||||
0, /* TN_OPT_NAOHTS */
|
||||
0, /* TN_OPT_HAOHTD */
|
||||
0, /* TN_OPT_NAOFFD */
|
||||
0, /* TN_OPT_NAOVTS */
|
||||
0, /* TN_OPT_NAOVTD */
|
||||
0, /* TN_OPT_NAOLFD */
|
||||
0, /* TN_OPT_EXTEND_ASCII */
|
||||
0, /* TN_OPT_LOGOUT */
|
||||
0, /* TN_OPT_BM */
|
||||
0, /* TN_OPT_DET */
|
||||
0, /* TN_OPT_SUPDUP */
|
||||
0, /* TN_OPT_SUPDUP_OUTPUT */
|
||||
0, /* TN_OPT_SEND_LOCATION */
|
||||
0, /* TN_OPT_TERMINAL_TYPE */
|
||||
tn_handle_end_of_record, /* TN_OPT_END_OF_RECORD */
|
||||
0, /* TN_OPT_TUID */
|
||||
0, /* TN_OPT_OUTMRK */
|
||||
0, /* TN_OPT_TTYLOC */
|
||||
0, /* TN_OPT_3270_REGIME */
|
||||
0, /* TN_OPT_X3_PAD */
|
||||
0, /* TN_OPT_NAWS */
|
||||
0, /* TN_OPT_TERMINAL_SPEED */
|
||||
0, /* TN_OPT_TOGGLE_FLOW_CONTROL */
|
||||
0, /* TN_OPT_LINEMODE */
|
||||
0 /* TN_OPT_XDISPLOC */
|
||||
};
|
||||
|
||||
struct tn_dispatch stytn_dispatch = {
|
||||
stytn_text, /* Text */
|
||||
stytn_ip, /* IP */
|
||||
stytn_ao, /* AO */
|
||||
stytn_ayt, /* AYT */
|
||||
0, /* EL */
|
||||
0, /* EC */
|
||||
0, /* EOR */
|
||||
0, /* BRK */
|
||||
0, /* GA */
|
||||
stytn_open, /* Open */
|
||||
stytn_close, /* Close */
|
||||
stytn_error, /* Error */
|
||||
stytn_options /* Option dispatch vector */
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/swap.c,v 1.3 2003/01/15 14:04:37 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: swap.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:37 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:30 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:43 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.3 2001/01/19 22:23:55 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.2 2000/03/17 00:12:48 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.1 1998/07/15 20:58:21 sra
|
||||
* Initial version.
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Swap routines for Snark. You can almost certainly do better than
|
||||
* this in assembly language.
|
||||
*/
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
|
||||
bits16_t glue_swap16(bits16_t goes_inta)
|
||||
{
|
||||
bits16_t goes_outa = (goes_inta & 0xFF);
|
||||
goes_inta >>= 8; goes_outa <<= 8;
|
||||
return goes_outa | (goes_inta & 0xFF);
|
||||
}
|
||||
|
||||
bits32_t glue_swap32(bits32_t goes_inta)
|
||||
{
|
||||
bits32_t goes_outa = (goes_inta & 0xFF);
|
||||
goes_inta >>= 8; goes_outa <<= 8;
|
||||
goes_outa |= (goes_inta & 0xFF);
|
||||
goes_inta >>= 8; goes_outa <<= 8;
|
||||
goes_outa |= (goes_inta & 0xFF);
|
||||
goes_inta >>= 8; goes_outa <<= 8;
|
||||
return goes_outa | (goes_inta & 0xFF);
|
||||
}
|
||||
|
||||
#endif /* INSTALL_ATTACHE */
|
||||
@@ -0,0 +1,117 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/tad.c,v 1.3 2003/01/15 14:04:37 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: tad.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:37 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:30 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:44 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.5 2001/01/19 22:23:55 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.4 2000/03/17 00:12:48 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.3 1998/02/25 15:21:52 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 1.2 1998/02/25 04:57:43 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 1.1 1997/08/12 22:31:18 lowell
|
||||
* kick release numbers to avoid the "0.*" special case
|
||||
*
|
||||
* Revision 0.2 1997/03/20 06:53:17 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 0.1 1997/02/12 19:40:01 lowell
|
||||
* I think this is okay.
|
||||
* But I'm not positive yet -- I just wanted to check it in quick
|
||||
* so the autotester wouldn't choke on its absence.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Time and Date code, really just for Decorum's use so far.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef EPILOGUE_TYPES_H
|
||||
#include <wrn/wm/common/types.h>
|
||||
#endif
|
||||
#ifndef EPILOGUE_INSTALL_H
|
||||
#include <wrn/wm/common/install.h>
|
||||
#endif
|
||||
#ifndef ATTACHE_CONFIG_H
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#endif
|
||||
#ifndef ATTACHE_PACKET_H
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#endif
|
||||
#ifndef ATTACHE_GLUE_H
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#endif
|
||||
#ifndef ATTACHE_TIMER_H
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#endif
|
||||
|
||||
#include <decorum/h/date.h>
|
||||
|
||||
|
||||
/* Glue code for different sources of time. */
|
||||
#if INSTALL_ATTACHE_NETIME_SERVER
|
||||
#include <wrn/wm/attache/netime.h>
|
||||
void att_glue_getime(struct decorum_rawtime * now)
|
||||
{
|
||||
now->time = netime_now();
|
||||
if (now->time)
|
||||
now->type = T0_RFC868;
|
||||
else
|
||||
now->type = T0_NONE;
|
||||
}
|
||||
#endif /* INSTALL_ATTACHE_NETIME_SERVER */
|
||||
|
||||
#ifdef INSTALL_on_unix
|
||||
/* An example for using the UNIX idea of the time.
|
||||
* Uses standard C library calls, so it should work on any UNIX.
|
||||
* It assumes that time(3) gives a 32-bit number of seconds since
|
||||
* 1 January, 1970, as is standard on UNIX. Last I checked, anyway.
|
||||
* Known to work on 4.4BSD and SunOS 4.1.4.
|
||||
*/
|
||||
#include <sys/time.h>
|
||||
void unix_glue_getime(struct decorum_rawtime * now)
|
||||
{
|
||||
now->time = (bits32_t)time(0);
|
||||
now->type = T0_UNIX;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,240 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/tasks.c,v 1.3 2003/01/15 14:04:37 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1993-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: tasks.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:37 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/08 15:56:30 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:44 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.14 2001/01/19 22:23:55 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.13 2000/10/16 19:21:55 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 2.12 2000/03/17 00:12:48 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.11 2000/03/13 21:22:12 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 2.10 1999/02/18 04:41:41 wes
|
||||
* Sockets merge: Everything Else
|
||||
* - memory pools
|
||||
* - thread support
|
||||
* - port-specific headers
|
||||
*
|
||||
* Revision 2.9.8.1 1998/09/23 19:17:24 wes
|
||||
* Merge socket-branch-1 changes to socket-branch-2
|
||||
*
|
||||
* Revision 2.9.6.1 1998/08/19 13:26:36 wes
|
||||
* Merge sockets-pthreads work to shared branch
|
||||
*
|
||||
* Revision 2.9.2.1 1998/07/28 18:14:59 wes
|
||||
* pthread hacks
|
||||
*
|
||||
* Revision 2.9 1998/07/02 06:55:41 sra
|
||||
* Make Snark restartable under pSOS, and other minor cleanups.
|
||||
*
|
||||
* Revision 2.8 1998/06/23 17:52:33 meister
|
||||
* move snarklib.h to after attache/h/glue.h if attache is defined
|
||||
*
|
||||
* Revision 2.7 1998/02/25 04:57:44 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.6 1997/03/20 06:53:17 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.5 1997/03/19 20:19:01 sra
|
||||
* Put glue_intlock() calls under INSTALL_ATTACHE conditionals. This
|
||||
* isn't the right long-term solution, but it'll do for now.
|
||||
*
|
||||
* Revision 2.4 1997/03/19 04:47:35 sra
|
||||
* Get rid of some gratuitous historical dependencies on Attache.
|
||||
*
|
||||
* Revision 2.3 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.2 1996/10/25 16:01:00 sar
|
||||
* Added some include files to get the configuration stuff correct.
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.2 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.1 1993/07/05 21:53:30 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Common code (all ports) for snark's tasking package.
|
||||
*
|
||||
* This is based in large part on Romkey's simtask package, with
|
||||
* some changes suggested by Bridgham and different modularization
|
||||
* to fit into snark properly.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This business with glue_intlock() is a mess that should be sorted
|
||||
* out someday, but today I've got to get this puppy to build cleanly
|
||||
* without Attache, so just conditionalize the references for now.
|
||||
*/
|
||||
|
||||
#include <wrn/wm/common/config.h>
|
||||
#include <wrn/wm/common/glue.h>
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#endif
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
static struct task *task_head, **task_tail;
|
||||
|
||||
void task_ini(struct task *task)
|
||||
{
|
||||
if (task)
|
||||
MEMSET((void *) task, 0, sizeof(*task));
|
||||
}
|
||||
|
||||
void task_enq(struct task *task)
|
||||
{
|
||||
#if INSTALL_ATTACHE
|
||||
int lock = glue_intlock(0);
|
||||
#endif
|
||||
|
||||
if (task && !task->next) {
|
||||
*task_tail = task;
|
||||
task_tail = &task->next;
|
||||
}
|
||||
#if INSTALL_ATTACHE
|
||||
glue_intlock(lock);
|
||||
#endif
|
||||
|
||||
#if INSTALL_ATTACHE_THREADS
|
||||
task_kick();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
struct task *task_deq()
|
||||
{
|
||||
#if INSTALL_ATTACHE
|
||||
int lock = glue_intlock(0);
|
||||
#endif
|
||||
struct task *task = task_head;
|
||||
|
||||
if (task) {
|
||||
task_head = task->next;
|
||||
if (task_head)
|
||||
task->next = 0;
|
||||
else
|
||||
task_tail = &task_head;
|
||||
}
|
||||
|
||||
#if INSTALL_ATTACHE
|
||||
glue_intlock(lock);
|
||||
#endif
|
||||
return task;
|
||||
}
|
||||
|
||||
void task_add
|
||||
(struct task *task,
|
||||
char *name,
|
||||
void (*func)(struct task *, void *),
|
||||
void *cookie)
|
||||
{
|
||||
if (!task)
|
||||
return;
|
||||
task->name = name;
|
||||
task->func = func;
|
||||
task->cookie = cookie;
|
||||
task_enq(task);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is messy. We don't want to disable interrupts while we search
|
||||
* the task queue, because that could take a long time. We must disable
|
||||
* interrupts while we're modifying the queue. So we check for timing
|
||||
* screws between locating the block and disabling interrupts, and loop
|
||||
* if we determine that such a timing screw has occured.
|
||||
*
|
||||
* I'm not sure it's worth going to all this trouble, it might be simpler
|
||||
* to say that dequeuing a task just means zeroing its function pointer.
|
||||
*/
|
||||
|
||||
void task_delq(struct task *task)
|
||||
{
|
||||
struct task **t = &task_head;
|
||||
#if INSTALL_ATTACHE
|
||||
int lock;
|
||||
#endif
|
||||
|
||||
while (*t) {
|
||||
if (*t != task) {
|
||||
t = &(*t)->next; /* Haven't found our task yet */
|
||||
continue;
|
||||
}
|
||||
#if INSTALL_ATTACHE
|
||||
lock = glue_intlock(0);
|
||||
#endif
|
||||
if (*t != task || (!task->next && &task->next != task_tail)) {
|
||||
t = &task_head; /* Oops, timing screw, restart search */
|
||||
} else {
|
||||
*t = task->next; /* No timing screw, unlink our task */
|
||||
task->next = 0;
|
||||
t = &task->next; /* Remember that we're done searching */
|
||||
}
|
||||
#if INSTALL_ATTACHE
|
||||
glue_intlock(lock);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int task_idle()
|
||||
{
|
||||
return !task_head;
|
||||
}
|
||||
|
||||
void tasks_init(void)
|
||||
{
|
||||
task_head = 0;
|
||||
task_tail = &task_head;
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/tun.c,v 1.2 2001/11/08 15:56:30 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: tun.c,v $
|
||||
* Revision 1.2 2001/11/08 15:56:30 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:44 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.7 2001/01/19 22:23:56 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.6 2000/10/16 19:21:55 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 1.5 2000/03/17 00:12:48 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.4 2000/03/13 21:22:13 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 1.3 1999/11/05 22:29:07 paul
|
||||
* Updated driver structs to reflect conditional backwards-compatibility
|
||||
* fields and new fields.
|
||||
*
|
||||
* Revision 1.2 1998/11/23 20:52:59 wes
|
||||
* Make MEDIA_CTL_CHECK_ADDRESS succeed rather than die.
|
||||
* Die using BUG instead of abort() for unknown media_ctl ops.
|
||||
*
|
||||
* Revision 1.1 1998/06/11 20:01:58 wes
|
||||
* Snark driver to talk to BSD tunnel driver..
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Use the *BSD tun0 / /dev/tun interface to glue snark into the real world.
|
||||
* This is a work in progress; ifconfig'ing the host side of the interface
|
||||
* and adding appropriate routes on the other side is currently left as
|
||||
* a exercise for the user of this driver.
|
||||
*/
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/slowtime.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <assert.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
#include <wrn/wm/demo/read_ini.h>
|
||||
|
||||
#define TEN_MEGABITS 10000000
|
||||
|
||||
#include <wrn/wm/demo/bsdif.h>
|
||||
|
||||
static void tun_driver_read (int fd, void *cookie, unsigned flags)
|
||||
{
|
||||
char buf[2048];
|
||||
struct net *net = cookie;
|
||||
struct packet *p;
|
||||
|
||||
if ((net->flags & NF_DRIVER_DOWN) == 0 && (flags & BSDIF_READ) != 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
do
|
||||
{
|
||||
i = read(fd, buf, sizeof(buf));
|
||||
} while ((i<0) && (errno == EINTR));
|
||||
if (i <= 0)
|
||||
return;
|
||||
p = pkt_alloc(i+MaxLnh);
|
||||
if (p == NULL)
|
||||
return;
|
||||
p->pkt_data += MaxLnh;
|
||||
p->pkt_datalen -= MaxLnh;
|
||||
p->pkt_n = net;
|
||||
MEMCPY(p->pkt_data, buf, i);
|
||||
ip_rcv(p);
|
||||
}
|
||||
}
|
||||
|
||||
static void tun_driver_init(struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
char *name = net->s_name;
|
||||
char namebuf[256];
|
||||
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
net->speed = TEN_MEGABITS;
|
||||
|
||||
sprintf(namebuf, "/dev/%s", name);
|
||||
if ((bif->fd = open(namebuf, O_RDWR, 0)) < 0)
|
||||
return;
|
||||
|
||||
bif->handler = tun_driver_read;
|
||||
bif->flags = BSDIF_READ;
|
||||
net->flags &= ~NF_DRIVER_DOWN;
|
||||
}
|
||||
|
||||
static void tun_driver_send (struct packet *p)
|
||||
{
|
||||
struct bsdif *bif = p->pkt_n->specific;
|
||||
|
||||
if (write(bif->fd, p->pkt_data, p->pkt_datalen) < 0)
|
||||
{
|
||||
fputs(p->pkt_n->s_name, stderr);
|
||||
perror(": write() failure");
|
||||
}
|
||||
pkt_free(p);
|
||||
}
|
||||
|
||||
static void tun_ip_send (struct net *net, packet *p, inaddr_t host)
|
||||
{
|
||||
p->pkt_n = net;
|
||||
tun_driver_send(p);
|
||||
}
|
||||
|
||||
static void tun_driver_close (struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
if ((net->flags & NF_DRIVER_DOWN) == 0) {
|
||||
close(bif->fd);
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
static int tun_media_ctl (struct net *net, int code, void *cookie)
|
||||
{
|
||||
switch (code)
|
||||
{
|
||||
case MEDIA_CTL_INIT:
|
||||
tun_driver_init(net);
|
||||
return MEDIA_CTL_GOOD;
|
||||
case MEDIA_CTL_CLOSE:
|
||||
tun_driver_close(net);
|
||||
return MEDIA_CTL_GOOD;
|
||||
case MEDIA_CTL_IP_UP:
|
||||
net->flags &= ~NF_DOWN;
|
||||
net->status_tstamp = GLUE_NOW();
|
||||
#if INSTALL_ATTACHE_MIB
|
||||
net->ifLastChange = centiseconds_since_attache_boot();
|
||||
#endif
|
||||
ip_advise_if_up(net);
|
||||
return MEDIA_CTL_GOOD;
|
||||
|
||||
case MEDIA_CTL_IP_DOWN:
|
||||
net->flags |= NF_DOWN;
|
||||
net->status_tstamp = GLUE_NOW();
|
||||
#if INSTALL_ATTACHE_MIB
|
||||
net->ifLastChange = centiseconds_since_attache_boot();
|
||||
#endif
|
||||
ip_advise_if_down(net);
|
||||
return MEDIA_CTL_GOOD;
|
||||
|
||||
case MEDIA_CTL_ADD_IPV4_ADDRESS:
|
||||
return MEDIA_CTL_GOOD;
|
||||
|
||||
|
||||
case MEDIA_CTL_DELETE_IPV4_ADDRESS:
|
||||
return MEDIA_CTL_GOOD;
|
||||
|
||||
case MEDIA_CTL_CHECK_ADDRESS:
|
||||
return MEDIA_CTL_GOOD;
|
||||
|
||||
default:
|
||||
BUG (BUG_SNARK_TUN_ERROR, BUG_FATAL, net,
|
||||
(BUG_OUT, "%s: unknown media_ctl opcode %d", net->s_name, code));
|
||||
return MEDIA_CTL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static struct driver tun_driver = {
|
||||
tun_driver_init, /* Interface initialization routine */
|
||||
tun_driver_send, /* Raw packet send routine */
|
||||
tun_ip_send, /* IP packet send back compat routine */
|
||||
0, /* ARP packet send encapsulation routine */
|
||||
0, /* Test routine (unused) */
|
||||
tun_driver_close, /* Interface close routine */
|
||||
"tun", /* Driver short name */
|
||||
"Berkeley Packet Filter Ethernet", /* Driver long name */
|
||||
14, /* Local net header length */
|
||||
0, /* Local net trailer length */
|
||||
1500, /* Real Ethernet frame size is this... */
|
||||
IF_PROP_SERIAL, /* MIB type of interfaces using this driver */
|
||||
0, /* arp hardware type (none) */
|
||||
tun_media_ctl, /* Media control routine */
|
||||
0, /* ipv6 send.. */
|
||||
0 /* ipv4 send.. */
|
||||
};
|
||||
|
||||
void tun_driver_find (void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t))
|
||||
{
|
||||
int instance;
|
||||
char name[10];
|
||||
|
||||
for (instance = 0; instance < 2; instance++)
|
||||
{
|
||||
sprintf(name, "%d", instance);
|
||||
config (name, &tun_driver, instance, 0,
|
||||
tun_driver.maxlen - tun_driver.lnh - tun_driver.lnt, TEN_MEGABITS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,932 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/lib/vapornet.c,v 1.2 2001/11/08 15:56:31 tneale Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1995-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: vapornet.c,v $
|
||||
* Revision 1.2 2001/11/08 15:56:31 tneale
|
||||
* Updated for newest file layout
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:48:44 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.28 2001/04/24 14:40:26 josh
|
||||
* remove an extra character
|
||||
*
|
||||
* Revision 2.27 2001/01/19 22:23:56 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.26 2000/10/16 19:21:56 paul
|
||||
* Restore sockets and mempool code.
|
||||
*
|
||||
* Revision 2.25 2000/03/17 00:12:49 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.24 2000/03/13 21:22:16 paul
|
||||
* Removed some code that we are no longer working on.
|
||||
*
|
||||
* Revision 2.23 1999/11/05 22:29:08 paul
|
||||
* Updated driver structs to reflect conditional backwards-compatibility
|
||||
* fields and new fields.
|
||||
*
|
||||
* Revision 2.22 1999/04/28 23:53:26 sra
|
||||
* Clean up various minor installation option glitches.
|
||||
*
|
||||
* Revision 2.21 1999/04/26 19:04:58 sra
|
||||
* Fix a few minor warnings, fix a few Solaris-specific problems in the
|
||||
* demo code.
|
||||
*
|
||||
* Revision 2.20 1998/12/07 19:49:37 josh
|
||||
* making vapornet support unnumbered links
|
||||
*
|
||||
* Revision 2.19 1998/09/18 19:56:24 meister
|
||||
* timer call renaming tm_ --> etc_tm_
|
||||
*
|
||||
* Revision 2.18 1998/06/03 21:23:07 sar
|
||||
* Updated code to use common string macros
|
||||
*
|
||||
* Revision 2.17 1998/05/18 17:21:22 meister
|
||||
* "struct route *" --> "route_entry_t *"
|
||||
*
|
||||
* Revision 2.16 1998/02/25 04:57:45 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.15 1997/05/17 23:08:56 sra
|
||||
* Clean up some SunOS/gcc warnings.
|
||||
*
|
||||
* Revision 2.14 1997/03/20 06:53:18 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.13 1997/03/19 22:38:29 sra
|
||||
* Silence a gcc warning.
|
||||
*
|
||||
* Revision 2.12 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.11 1997/02/19 08:10:29 sra
|
||||
* More fun merging snmptalk into snark, general snark cleanup.
|
||||
*
|
||||
* Revision 2.10 1997/01/29 06:53:58 sra
|
||||
* Switch vapornet to use a media_ctl() function.
|
||||
*
|
||||
* Revision 2.9 1997/01/17 23:15:10 sra
|
||||
* Remove last vestiges of Attache 2.x compatability mode.
|
||||
*
|
||||
* Revision 2.8 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.7 1996/03/08 21:54:58 sra
|
||||
* Add code for dropping/delaying packets to simulate bad networks.
|
||||
* Add timer-based checkpointing of pktlog files.
|
||||
*
|
||||
* Revision 2.6 1995/10/09 22:54:32 sra
|
||||
* Fun with copyright notices.
|
||||
*
|
||||
* Revision 2.5 1995/09/08 20:00:31 sra
|
||||
* Duh, need to call vp_broadcast() even for broadcast on ptop links,
|
||||
* since otherwise we drop the packet when we can't find the socket.
|
||||
*
|
||||
* Revision 2.4 1995/09/08 19:58:35 sra
|
||||
* Add WetStringNet, for testing OSPF over point-to-point links.
|
||||
*
|
||||
* Revision 2.3 1995/07/31 13:54:55 sra
|
||||
* OSPF now working well enough to let somebody else test it.
|
||||
*
|
||||
* Revision 2.2 1995/06/27 06:23:28 sra
|
||||
* Add multicast support. Claim to be 3MB-Ether so that RCI
|
||||
* code will believe this is a broadcast-capable medium.
|
||||
*
|
||||
* Revision 2.1 1995/05/13 04:22:24 sra
|
||||
* Get installation conditional right.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.2 1995/05/06 00:41:42 sra
|
||||
* Put under installation conditional.
|
||||
*
|
||||
* Revision 1.1 1995/03/26 02:29:19 sra
|
||||
* Initial revision
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Fake network built on BSD "unix domain" sockets. Intended primarily
|
||||
* to allow building a complex enough network to do some testing of router
|
||||
* code in a relatively sane debugging environment.
|
||||
*
|
||||
* None of the code in this module is likely to be at all suitable for
|
||||
* use in a real product, it's just a debugging tool that Epilogue's
|
||||
* engineers use internally and that we're providing to our customers
|
||||
* as a courtesy.
|
||||
*/
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/slowtime.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
|
||||
#if INSTALL_SNARK_BSD_VAPORNET
|
||||
|
||||
/* Dunno what system include files we want yet */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <assert.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
#include <wrn/wm/demo/read_ini.h>
|
||||
|
||||
#include <wrn/wm/demo/bsdif.h>
|
||||
#include <wrn/wm/demo/vapornet.h>
|
||||
|
||||
/*
|
||||
* Maximum number of addresses we can handle for broadcast.
|
||||
*/
|
||||
#ifndef VP_MAX_BROADCAST
|
||||
#define VP_MAX_BROADCAST 256
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Maximum number of interfaces we probe for.
|
||||
*/
|
||||
#ifndef VP_MAX_INTERFACES
|
||||
#define VP_MAX_INTERFACES 10
|
||||
#endif
|
||||
#ifndef WS_MAX_INTERFACES
|
||||
#define WS_MAX_INTERFACES VP_MAX_INTERFACES
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Directory where vapornet socket inodes live.
|
||||
*/
|
||||
#ifndef VP_SOCKET_DIR
|
||||
#define VP_SOCKET_DIR "/tmp/vapornet"
|
||||
#endif
|
||||
|
||||
static char vp_socket_dir[] = VP_SOCKET_DIR;
|
||||
|
||||
/*
|
||||
* Cycle time for synchronizing packet log to disk.
|
||||
*/
|
||||
#ifndef VP_PKTLOG_SYNC_INTERVAL
|
||||
#define VP_PKTLOG_SYNC_INTERVAL 30000
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Section name for our configuration data.
|
||||
*/
|
||||
static char attache_section[] = "etc attache";
|
||||
|
||||
/*
|
||||
* Interface speed and MTU parameters.
|
||||
*/
|
||||
#define VP_MTU 1500
|
||||
#define VP_SPEED 0x7FFFFFFF
|
||||
#define WS_MTU VP_MTU
|
||||
#define WS_SPEED VP_SPEED
|
||||
|
||||
#define VP_MAX_TAG 20
|
||||
|
||||
/*
|
||||
* Driver private data, hangs off net->specific->private.
|
||||
*/
|
||||
struct vp_ctl {
|
||||
struct net *net; /* associated Attache network interface */
|
||||
packet *ipkt; /* receive buffer (to avoid extra copy step) */
|
||||
time_t bcast_mtime; /* last mod time for broadcast cache */
|
||||
inaddr_t bcasts[VP_MAX_BROADCAST];
|
||||
int nbcasts; /* broadcast address list for our subnet */
|
||||
FILE *pktlog; /* packet log file, if non-null */
|
||||
bits32_t delay, jitter; /* for simulating low-quality links */
|
||||
bits32_t drop_p1, drop_p2, drop_p3, drop_count;
|
||||
packet *opkts; /* keep track of our garbage... */
|
||||
struct timer pktlog_sync; /* for synching packet log file */
|
||||
bits8_t local_tag[VP_MAX_TAG+1];
|
||||
bits8_t remote_tag[VP_MAX_TAG+1];
|
||||
bits8_t local_exists;
|
||||
bits8_t remote_exists;
|
||||
};
|
||||
|
||||
/*
|
||||
* Junk that we want to keep around when delaying packet transmission
|
||||
* to simulate a bad link. By craming this stuff into the head of
|
||||
* the packet buffer, we avoid having to worry about storage issues.
|
||||
*/
|
||||
struct vp_lnh {
|
||||
inaddr_t host; /* next hop */
|
||||
struct timer tm; /* delay timer */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Logging routines. We log packets in the same binary file format
|
||||
* as the excellent tcpdump program, so that we can use tcpdump itself
|
||||
* as the analysis tool. Thanks, Van!
|
||||
*
|
||||
* Some of the code in vp_open_log() and vp_log() comes from the tcpdump
|
||||
* program (because there's no other documentation for the dump file
|
||||
* format) and thus is subject to the following copyright:
|
||||
*
|
||||
* Copyright (c) 1990,1991 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or
|
||||
* without modification, are permitted provided that: (1) source
|
||||
* code distributions retain the above copyright notice and this
|
||||
* paragraph in its entirety, (2) distributions including binary
|
||||
* code include the above copyright notice and this paragraph in its
|
||||
* entirety in the documentation or other materials provided with
|
||||
* the distribution, and (3) all advertising materials mentioning
|
||||
* features or use of this software display the following
|
||||
* acknowledgement: ``This product includes software developed by
|
||||
* the University of California, Lawrence Berkeley Laboratory and
|
||||
* its contributors.'' Neither the name of the University nor the
|
||||
* names of its contributors may be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND
|
||||
* WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
|
||||
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* Please note that since Epilogue distributes this module solely as
|
||||
* sample source code on an "as-is" basis and does not advertise or
|
||||
* even document the features provided by these logging routines, we
|
||||
* believe that inclusion of the above notice constitutes compliance
|
||||
* with the copyright conditions.
|
||||
*/
|
||||
|
||||
#define TCPDUMP_MAGIC 0xa1b2c3d4
|
||||
#define TCPDUMP_VERSION_MAJOR 2
|
||||
#define TCPDUMP_VERSION_MINOR 2
|
||||
|
||||
struct tcpdump_file_header {
|
||||
u_long magic;
|
||||
u_short version_major;
|
||||
u_short version_minor;
|
||||
long thiszone;
|
||||
u_long sigfigs;
|
||||
u_long snaplen;
|
||||
u_long linktype;
|
||||
};
|
||||
|
||||
static void vp_pklog_sync_handler(struct timer *tm, void *cookie)
|
||||
{
|
||||
struct vp_ctl *ctl = cookie;
|
||||
if (ctl && ctl->pktlog)
|
||||
fflush(ctl->pktlog);
|
||||
etc_tm_set(tm, VP_PKTLOG_SYNC_INTERVAL);
|
||||
}
|
||||
|
||||
static void vp_close_log(struct vp_ctl *ctl)
|
||||
{
|
||||
if (ctl->pktlog) {
|
||||
fclose(ctl->pktlog);
|
||||
ctl->pktlog = 0;
|
||||
}
|
||||
etc_tm_cancel(&ctl->pktlog_sync);
|
||||
}
|
||||
|
||||
static void vp_open_log(struct vp_ctl *ctl, struct ini_handle *ini_handle)
|
||||
{
|
||||
char *filename, varname[20];
|
||||
struct tcpdump_file_header hdr;
|
||||
#if !defined(INSTALL_on_solaris) || !INSTALL_on_solaris
|
||||
time_t t = time(0);
|
||||
struct tm *tm = localtime(&t);
|
||||
#endif
|
||||
|
||||
sprintf(varname, "%s-pktfile", ctl->net->s_name);
|
||||
if ((filename = ini_lookup(ini_handle, attache_section, varname)) == 0 ||
|
||||
(ctl->pktlog = fopen(filename, "w")) == 0)
|
||||
return;
|
||||
|
||||
hdr.magic = TCPDUMP_MAGIC;
|
||||
hdr.version_major = TCPDUMP_VERSION_MAJOR;
|
||||
hdr.version_minor = TCPDUMP_VERSION_MINOR;
|
||||
hdr.snaplen = VP_MTU;
|
||||
hdr.sigfigs = 2;
|
||||
hdr.linktype = 0;
|
||||
#if !defined(INSTALL_on_solaris) || !INSTALL_on_solaris
|
||||
hdr.thiszone = tm ? tm->tm_gmtoff : 0;
|
||||
#else
|
||||
hdr.thiszone = 0;
|
||||
#endif
|
||||
|
||||
if (fwrite(&hdr, sizeof(hdr), 1, ctl->pktlog) != 1) {
|
||||
vp_close_log(ctl);
|
||||
return;
|
||||
}
|
||||
|
||||
ctl->pktlog_sync.handler = vp_pklog_sync_handler;
|
||||
ctl->pktlog_sync.cookie = ctl;
|
||||
etc_tm_set(&ctl->pktlog_sync, VP_PKTLOG_SYNC_INTERVAL);
|
||||
}
|
||||
|
||||
struct tcpdump_packet_header {
|
||||
struct timeval ts;
|
||||
u_long len;
|
||||
u_long caplen;
|
||||
u_int af;
|
||||
};
|
||||
|
||||
static void vp_log_packet(FILE *f, packet *p)
|
||||
{
|
||||
struct tcpdump_packet_header h;
|
||||
|
||||
gettimeofday(&h.ts, 0);
|
||||
h.af = AF_INET;
|
||||
h.len = h.caplen = p->pkt_datalen + sizeof(h.af);
|
||||
fwrite(&h, sizeof(h), 1, f);
|
||||
fwrite(p->pkt_data, p->pkt_datalen, 1, f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Output routines.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Send packet at head of output queue to a single recipient.
|
||||
* Just drops packets that can't be sent immediately.
|
||||
*/
|
||||
|
||||
static void vp_unicast(struct vp_ctl *ctl, packet *p, inaddr_t dest)
|
||||
{
|
||||
struct net *net = ctl->net;
|
||||
struct bsdif *bif = net->specific;
|
||||
struct sockaddr_un sa;
|
||||
|
||||
sprintf(sa.sun_path, "%s/%s", vp_socket_dir, inettoa(dest));
|
||||
sa.sun_family = AF_UNIX;
|
||||
|
||||
sendto(bif->fd, (p->pkt_data), p->pkt_datalen, 0,
|
||||
(struct sockaddr *) &sa,
|
||||
sizeof(sa) - sizeof(sa.sun_path) + STRLEN(sa.sun_path));
|
||||
}
|
||||
|
||||
/*
|
||||
* Send packet at head of output queue to a single recipient as
|
||||
* specified by the 'dest' identifier.
|
||||
*/
|
||||
|
||||
static void vp_link_send(struct vp_ctl *ctl, packet *p)
|
||||
{
|
||||
struct net *net = ctl->net;
|
||||
struct bsdif *bif = net->specific;
|
||||
struct sockaddr_un sa;
|
||||
|
||||
sprintf(sa.sun_path, "%s/%s", vp_socket_dir, ctl->remote_tag);
|
||||
sa.sun_family = AF_UNIX;
|
||||
|
||||
sendto(bif->fd, (p->pkt_data), p->pkt_datalen, 0,
|
||||
(struct sockaddr *) &sa,
|
||||
sizeof(sa) - sizeof(sa.sun_path) + STRLEN(sa.sun_path));
|
||||
}
|
||||
|
||||
/*
|
||||
* Simulate broadcast by iterative unicast in pseudo-random order.
|
||||
* We construct the broadcast list by looking for addresses that
|
||||
* are on a subnet attached to this interface but which are not
|
||||
* any of our own addresses. This is a little painful, but we
|
||||
* only have to do it when the socket directory changes.
|
||||
*/
|
||||
|
||||
void vp_broadcast(struct vp_ctl *ctl, packet *p)
|
||||
{
|
||||
struct net *net = ctl->net;
|
||||
int idx[VP_MAX_BROADCAST], i, n;
|
||||
route_entry_t *r;
|
||||
inaddr_t addr;
|
||||
struct dirent *dp;
|
||||
struct stat st;
|
||||
DIR *dd;
|
||||
|
||||
if (stat(vp_socket_dir, &st) >= 0 && st.st_mtime > ctl->bcast_mtime &&
|
||||
(dd = opendir(vp_socket_dir)) != 0) {
|
||||
n = 0;
|
||||
ctl->remote_exists = 0;
|
||||
while (n < VP_MAX_BROADCAST && (dp = readdir(dd)) != 0) {
|
||||
addr = atoinet(dp->d_name);
|
||||
if (addr) {
|
||||
/* Punt if we don't share a subnet with this address. */
|
||||
r = owner_routes_first(&direct_routes_owner);
|
||||
while (r && (net != r->net || (addr & r->mask) != r->dest))
|
||||
r = owner_routes_next(&direct_routes_owner, r);
|
||||
if (!r)
|
||||
continue;
|
||||
/* Punt if this is one of our own addresses. */
|
||||
r = owner_routes_first(&address_routes_owner);
|
||||
while (r && addr != r->dest)
|
||||
r = owner_routes_next(&address_routes_owner, r);
|
||||
if (r)
|
||||
continue;
|
||||
/* An address on our subnet that's not us, save it. */
|
||||
ctl->bcasts[n++] = addr;
|
||||
}
|
||||
else {
|
||||
/* could it be the other end of an unnumbered link? */
|
||||
if ((ctl->remote_tag[0]) && !STRCMP(ctl->remote_tag, dp->d_name))
|
||||
ctl->remote_exists = 1;
|
||||
}
|
||||
}
|
||||
closedir(dd);
|
||||
ctl->bcast_mtime = st.st_mtime;
|
||||
ctl->nbcasts = n;
|
||||
} else {
|
||||
n = ctl->nbcasts;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
idx[i] = i;
|
||||
|
||||
if (n) {
|
||||
while (n > 0) {
|
||||
i = random() % n;
|
||||
vp_unicast(ctl, p, ctl->bcasts[idx[i]]);
|
||||
idx[i] = idx[--n];
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* We might have an unnumbered link to send to */
|
||||
if (ctl->remote_exists)
|
||||
vp_link_send(ctl, p);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Process an outgoing Attache IP packet. Since we just drop packets
|
||||
* that we can't send right away, we may as well do this directly
|
||||
* from the driver rather than maintaining an output queue.
|
||||
*
|
||||
* Except that sometimes it's weirder when we're simulating a bad link.
|
||||
*/
|
||||
|
||||
static void vp_ip_send_handler(struct timer *tm, void *cookie)
|
||||
{
|
||||
packet *p = cookie, **pp;
|
||||
struct net *net = p->pkt_n;
|
||||
struct bsdif *bif = net->specific;
|
||||
struct vp_ctl *ctl = bif->private;
|
||||
struct vp_lnh *lh = (struct vp_lnh *) (p->pkt_buffer);
|
||||
inaddr_t host = lh->host;
|
||||
int drop = 0;
|
||||
|
||||
if (ctl) {
|
||||
|
||||
/*
|
||||
* Packet dropping to simulate bad networks.
|
||||
* Yes, thank you, I am making this up as I go along.
|
||||
*/
|
||||
ctl->drop_count++;
|
||||
switch (ctl->drop_p1) {
|
||||
|
||||
case 1:
|
||||
/*
|
||||
* Drop nth packet. p2 specifies n, p2 specifies whether
|
||||
* we're dropping every-nth or just first-nth.
|
||||
*/
|
||||
if (ctl->drop_count % ctl->drop_p2 == 0) {
|
||||
drop = 1;
|
||||
if (!ctl->drop_p3)
|
||||
ctl->drop_p1 = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
/*
|
||||
* Drop p2/p3 of the packets, pseudo-randomly.
|
||||
*/
|
||||
if (random() % ctl->drop_p3 < ctl->drop_p2)
|
||||
drop = 1;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Send the packet in the right way, unless we're dropping it.
|
||||
*/
|
||||
if (!drop) {
|
||||
if (ctl->pktlog)
|
||||
vp_log_packet(ctl->pktlog, p);
|
||||
if ((p->pkt_flags & (PF_TX_BROADCAST | PF_TX_MULTICAST)) != 0)
|
||||
vp_broadcast(ctl, p);
|
||||
else if (ctl->remote_exists && ctl->local_exists)
|
||||
vp_link_send(ctl, p);
|
||||
else
|
||||
vp_unicast(ctl, p, host);
|
||||
}
|
||||
#if 0
|
||||
else {
|
||||
printf("[Dropping packet #%lu (%s)]\n", ctl->drop_count, net->s_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Unlink packet from the gc chain.
|
||||
*/
|
||||
for (pp = &ctl->opkts; *pp; pp = &(*pp)->pkt_link) {
|
||||
if (*pp == p) {
|
||||
*pp = p->pkt_link;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Free the packet no matter what else we do.
|
||||
*/
|
||||
pkt_free(p);
|
||||
}
|
||||
|
||||
static void vp_ip_send(struct net *net, packet *p, inaddr_t host)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
struct vp_ctl *ctl = bif->private;
|
||||
struct vp_lnh *lh = (struct vp_lnh *) (p->pkt_buffer);
|
||||
|
||||
if (!ctl) {
|
||||
pkt_free(p);
|
||||
return;
|
||||
}
|
||||
|
||||
etc_tm_init(&lh->tm);
|
||||
lh->tm.handler = vp_ip_send_handler;
|
||||
lh->tm.cookie = p;
|
||||
lh->host = host;
|
||||
|
||||
p->pkt_n = net;
|
||||
p->pkt_link = ctl->opkts;
|
||||
ctl->opkts = p;
|
||||
|
||||
if (ctl->jitter)
|
||||
etc_tm_set(&lh->tm, ctl->delay + random() % ctl->jitter);
|
||||
else if (ctl->delay)
|
||||
etc_tm_set(&lh->tm, ctl->delay);
|
||||
else
|
||||
lh->tm.handler(&lh->tm, lh->tm.cookie);
|
||||
}
|
||||
|
||||
/*
|
||||
* The parameters set in this function all degrade the virtual network
|
||||
* simulated by this code in various ways that may be useful when
|
||||
* testing/debugging. Leaving all of these parameters in their default
|
||||
* (zero) state yields the best network we can simulate (no delays,
|
||||
* packets dropped only when the underlying IPC decides to drop them).
|
||||
*/
|
||||
static void vp_ip_send_config
|
||||
(struct vp_ctl *ctl, struct ini_handle *ini_handle)
|
||||
{
|
||||
char *s, varname[20];
|
||||
|
||||
/*
|
||||
* Delay each outbound packet by a fixed number of milliseconds.
|
||||
* This and "jitter" are additive.
|
||||
*/
|
||||
sprintf(varname, "%s-delay", ctl->net->s_name);
|
||||
if ((s = ini_lookup(ini_handle, attache_section, varname)) != 0)
|
||||
sscanf(s, "%lu", &ctl->delay);
|
||||
|
||||
/*
|
||||
* Delay each outbound packet by a pseudorandom number of milliseconds
|
||||
* in the range from zero to (n - 1). This and "delay" are additive.
|
||||
*/
|
||||
sprintf(varname, "%s-jitter", ctl->net->s_name);
|
||||
if ((s = ini_lookup(ini_handle, attache_section, varname)) != 0)
|
||||
sscanf(s, "%lu", &ctl->jitter);
|
||||
|
||||
/*
|
||||
* Drop packets according to one of the algorithms in vp_ip_send_handler().
|
||||
* See that function for details.
|
||||
*/
|
||||
sprintf(varname, "%s-drop", ctl->net->s_name);
|
||||
if ((s = ini_lookup(ini_handle, attache_section, varname)) != 0)
|
||||
sscanf(s, "%lu %lu %lu", &ctl->drop_p1, &ctl->drop_p2, &ctl->drop_p3);
|
||||
}
|
||||
|
||||
static void vp_link_config(struct vp_ctl *ctl, struct ini_handle *ini_handle)
|
||||
{
|
||||
char *s;
|
||||
char *av[20];
|
||||
int ac, i = 0;
|
||||
|
||||
for (s = ini_iter_start(ini_handle, attache_section, "unnumbered-link"); s;
|
||||
s = ini_iter_next(ini_handle)) {
|
||||
ac = parse_line(s, av, sizeof(av)/sizeof(*av));
|
||||
if (ac < 3)
|
||||
continue;
|
||||
if (STRCMP(av[i++], ctl->net->s_name) != 0)
|
||||
continue;
|
||||
if (STRLEN(av[i]) > VP_MAX_TAG)
|
||||
av[i][VP_MAX_TAG+1] = '\0';
|
||||
STRCPY(ctl->local_tag, av[i++]);
|
||||
if (STRLEN(av[i]) > VP_MAX_TAG)
|
||||
av[i][VP_MAX_TAG+1] = '\0';
|
||||
STRCPY(ctl->remote_tag, av[i]);
|
||||
printf(" -- Configuring %s with local tag %s, remote link to tag %s\n",
|
||||
ctl->net->s_name, ctl->local_tag, ctl->remote_tag);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Process whatever incoming packets we can without blocking.
|
||||
* Passes zero or more Attache packets to ip_rcv().
|
||||
*/
|
||||
|
||||
static void vp_rcv(struct net *net)
|
||||
{
|
||||
struct bsdif *bif = net->specific;
|
||||
struct vp_ctl *ctl = bif->private;
|
||||
packet *p = ctl->ipkt;
|
||||
size_t len = net->driver->maxlen + MaxLnh;
|
||||
int n;
|
||||
|
||||
for (;;) {
|
||||
if (p == 0) {
|
||||
if ((p = pkt_alloc(len)) == 0)
|
||||
break;
|
||||
p->pkt_data += MaxLnh;
|
||||
p->pkt_datalen -= MaxLnh;
|
||||
}
|
||||
do {
|
||||
n = recv(bif->fd, p->pkt_data, p->pkt_datalen, 0);
|
||||
} while (n < 0 && errno == EINTR);
|
||||
if (n <= 0) {
|
||||
if (errno != EWOULDBLOCK)
|
||||
bif->flags &= ~BSDIF_READ;
|
||||
break;
|
||||
}
|
||||
p->pkt_datalen = n;
|
||||
p->pkt_n = net;
|
||||
ip_rcv(p);
|
||||
p = 0;
|
||||
}
|
||||
|
||||
ctl->ipkt = p;
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle events detected by generic BSD I/O loop.
|
||||
* This particular driver should never get anything but read events.
|
||||
*/
|
||||
|
||||
static void vp_handler(int fd, void *net, unsigned flags)
|
||||
{
|
||||
assert((flags & ~BSDIF_READ) == 0);
|
||||
vp_rcv(net);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Media control routine. In this particular driver, this takes
|
||||
* the place of the driver init and close routines as well, since
|
||||
* there's no real need to separate out those functions.
|
||||
*/
|
||||
|
||||
static int vp_media_ctl(struct net *net, int code, void *cookie)
|
||||
{
|
||||
char sockname[sizeof(vp_socket_dir) + 16];
|
||||
struct bsdif *bif = net->specific;
|
||||
struct sockaddr_un sa;
|
||||
struct vp_ctl *ctl;
|
||||
|
||||
sprintf(sa.sun_path, "%s/i%d-%s",
|
||||
vp_socket_dir, (int) getpid(), net->s_name);
|
||||
sa.sun_family = AF_UNIX;
|
||||
|
||||
switch (code) {
|
||||
|
||||
case MEDIA_CTL_INIT:
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
if ((bif->private = ctl = GLUE_ALLOC(sizeof(*ctl))) == 0) {
|
||||
fprintf(stderr, "couldn't allocate vp control structure\n");
|
||||
return MEDIA_CTL_ERROR;
|
||||
}
|
||||
MEMSET(ctl, 0, sizeof(*ctl));
|
||||
etc_tm_init(&ctl->pktlog_sync);
|
||||
ctl->net = net;
|
||||
if ((bif->fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) {
|
||||
perror("couldn't create vp socket");
|
||||
} else if (mkdir(vp_socket_dir, 0777) < 0 && errno != EEXIST) {
|
||||
perror("couldn't create vp socket inode directory");
|
||||
} else if (unlink(sa.sun_path) < 0 && errno != ENOENT) {
|
||||
perror("couldn't unlink old vp socket inode");
|
||||
} else if (bind(bif->fd, (struct sockaddr *) &sa,
|
||||
(sizeof(sa) - sizeof(sa.sun_path) +
|
||||
STRLEN(sa.sun_path))) < 0) {
|
||||
perror("couldn't bind vp socket address");
|
||||
} else if (fcntl(bif->fd, F_SETFL, FNDELAY) < 0) {
|
||||
perror("couldn't set vp socket non-blocking");
|
||||
} else {
|
||||
struct ini_handle *ini_handle = ini_open(256);
|
||||
vp_open_log(ctl, ini_handle);
|
||||
vp_ip_send_config(ctl, ini_handle);
|
||||
/* This is where we configure point-to-point names */
|
||||
vp_link_config(ctl, ini_handle);
|
||||
ini_close(ini_handle);
|
||||
bif->handler = vp_handler;
|
||||
bif->flags |= BSDIF_READ;
|
||||
net->flags &= ~NF_DRIVER_DOWN;
|
||||
return MEDIA_CTL_GOOD;
|
||||
}
|
||||
/* aieeeee.... */
|
||||
|
||||
case MEDIA_CTL_CLOSE:
|
||||
ctl = bif->private;
|
||||
net->flags |= NF_DRIVER_DOWN;
|
||||
bif->flags &= ~(BSDIF_READ | BSDIF_WRITE);
|
||||
unlink(sa.sun_path);
|
||||
if (bif->fd >= 0) {
|
||||
close(bif->fd);
|
||||
bif->fd = -1;
|
||||
}
|
||||
if (ctl) {
|
||||
if (ctl->ipkt)
|
||||
pkt_free(ctl->ipkt);
|
||||
while (ctl->opkts) {
|
||||
packet *p = ctl->opkts;
|
||||
struct vp_lnh *lh = (struct vp_lnh *) (p->pkt_buffer);
|
||||
etc_tm_cancel(&lh->tm);
|
||||
ctl->opkts = p->pkt_link;
|
||||
pkt_free(p);
|
||||
}
|
||||
if (ctl->pktlog)
|
||||
vp_close_log(ctl);
|
||||
GLUE_FREE(ctl);
|
||||
bif->private = 0;
|
||||
}
|
||||
return code == MEDIA_CTL_CLOSE ? MEDIA_CTL_GOOD : MEDIA_CTL_ERROR;
|
||||
|
||||
case MEDIA_CTL_IP_UP:
|
||||
ctl = bif->private;
|
||||
net->flags &= ~NF_DOWN;
|
||||
net->status_tstamp = GLUE_NOW();
|
||||
#if INSTALL_ATTACHE_MIB
|
||||
net->ifLastChange = centiseconds_since_attache_boot();
|
||||
#endif
|
||||
if (!route_address_count(net, 0) && (ctl->local_tag[0])) {
|
||||
sprintf(sockname, "%s/%s", vp_socket_dir, ctl->local_tag);
|
||||
if (unlink(sockname) < 0 && errno != ENOENT)
|
||||
perror("couldn't unlink vp unnumbered link");
|
||||
else if (link(sa.sun_path, sockname) < 0)
|
||||
perror("couldn't link vp unnumbered link");
|
||||
else {
|
||||
ctl->local_exists = 1;
|
||||
ip_advise_if_up(net);
|
||||
return MEDIA_CTL_GOOD;
|
||||
}
|
||||
return MEDIA_CTL_ERROR;
|
||||
}
|
||||
ip_advise_if_up(net);
|
||||
return MEDIA_CTL_GOOD;
|
||||
|
||||
case MEDIA_CTL_IP_DOWN:
|
||||
ctl = bif->private;
|
||||
net->flags |= NF_DOWN;
|
||||
net->status_tstamp = GLUE_NOW();
|
||||
#if INSTALL_ATTACHE_MIB
|
||||
net->ifLastChange = centiseconds_since_attache_boot();
|
||||
#endif
|
||||
ip_advise_if_down(net);
|
||||
if (STRLEN(ctl->local_tag)) {
|
||||
sprintf(sockname, "%s/%s", vp_socket_dir, ctl->local_tag);
|
||||
unlink(sockname);
|
||||
ctl->local_exists = 0;
|
||||
}
|
||||
return MEDIA_CTL_GOOD;
|
||||
|
||||
case MEDIA_CTL_ADD_ADDRESS:
|
||||
ctl = bif->private;
|
||||
sprintf(sockname, "%s/%s", vp_socket_dir, inettoa(* (inaddr_t *) cookie));
|
||||
if (unlink(sockname) < 0 && errno != ENOENT)
|
||||
perror("couldn't unlink vp IP address");
|
||||
else if (link(sa.sun_path, sockname) < 0)
|
||||
perror("couldn't link secondary vp IP address");
|
||||
else {
|
||||
if (ctl->local_exists) {
|
||||
sprintf(sockname, "%s/%s", vp_socket_dir, ctl->local_tag);
|
||||
unlink(sockname);
|
||||
ctl->local_exists = 0;
|
||||
}
|
||||
return MEDIA_CTL_GOOD;
|
||||
}
|
||||
return MEDIA_CTL_ERROR;
|
||||
|
||||
case MEDIA_CTL_DELETE_ADDRESS:
|
||||
sprintf(sockname, "%s/%s", vp_socket_dir, inettoa(* (inaddr_t *) cookie));
|
||||
unlink(sockname);
|
||||
return MEDIA_CTL_ERROR;
|
||||
|
||||
default:
|
||||
return MEDIA_CTL_UNKNOWN_CODE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static struct driver vp_driver = {
|
||||
0, /* Init routine */
|
||||
0, /* Raw send routine */
|
||||
vp_ip_send, /* IP packet send routine */
|
||||
0, /* ARP routine */
|
||||
0, /* Device control routine */
|
||||
0, /* Close routine */
|
||||
"vp", /* Driver name prefix */
|
||||
"BSD Socket VaporNet", /* Driver name */
|
||||
sizeof(struct vp_lnh), /* Net header length */
|
||||
0, /* Net trailer length */
|
||||
VP_MTU, /* Max packet size */
|
||||
IF_ETHER_3MB, /* MIB interface type (fake broadcast) */
|
||||
0, /* ARP hardware type (none) */
|
||||
vp_media_ctl /* Media layer control routine */
|
||||
};
|
||||
|
||||
static struct driver ws_driver = {
|
||||
0, /* Init routine */
|
||||
0, /* Raw send routine */
|
||||
vp_ip_send, /* IP packet send routine */
|
||||
0, /* ARP routine */
|
||||
0, /* Device control routine */
|
||||
0, /* Close routine */
|
||||
"ws", /* Driver name prefix */
|
||||
"BSD Socket WetStringNet", /* Driver name */
|
||||
sizeof(struct vp_lnh), /* Net header length */
|
||||
0, /* Net trailer length */
|
||||
VP_MTU, /* Max packet size */
|
||||
IF_PROP_SERIAL, /* MIB interface type (fake point-to-point) */
|
||||
0, /* ARP hardware type (none) */
|
||||
vp_media_ctl, /* Media layer control routine */
|
||||
0, /* IPv6 send */
|
||||
0 /* IPv4 send */
|
||||
};
|
||||
|
||||
/*
|
||||
* Standard snark interface find routine.
|
||||
* Since there's no real device in back of a vapornet interface,
|
||||
* we just generate a specified number of interface names, then exit.
|
||||
*/
|
||||
|
||||
void vp_driver_find
|
||||
(void (*config)(char *, struct driver *, int, bits16_t, unsigned, bits32_t))
|
||||
{
|
||||
char name[10];
|
||||
int instance;
|
||||
|
||||
for (instance = 0; instance < VP_MAX_INTERFACES; instance++) {
|
||||
sprintf(name, "%d", instance);
|
||||
config(name, &vp_driver, instance, 0,
|
||||
vp_driver.maxlen - vp_driver.lnh - vp_driver.lnt, VP_SPEED);
|
||||
}
|
||||
|
||||
for (instance = 0; instance < WS_MAX_INTERFACES; instance++) {
|
||||
sprintf(name, "%d", instance);
|
||||
config(name, &ws_driver, instance, 0,
|
||||
ws_driver.maxlen - ws_driver.lnh - ws_driver.lnt, WS_SPEED);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* INSTALL_SNARK_BSD_VAPORNET */
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
#
|
||||
# Top-level makefile for snark.
|
||||
#
|
||||
|
||||
$#equate(SNARK_DIRECTORIES
|
||||
$#if-installed(SNARK_LIB lib)
|
||||
$#if-installed(SNARK_ROUTER router)
|
||||
$#if-installed(ENVOY_SNMPTALK snmptalk)
|
||||
$#if-installed(ENVOY_SUN_AGENT
|
||||
$#if-installed(ATTACHE $#nil() unxagent))
|
||||
$#if-installed(ENVOY_WINSOCK_AGENT winagent)
|
||||
$#if-installed(SNARK_HTTPSERV httpserv)
|
||||
$#if-installed(SNARK_OVER_PSOS psos)
|
||||
$#if-installed(DECORUM_OVER_PNA deconpna)
|
||||
$#if-installed(SNARK_SOCKTEST socktest))
|
||||
|
||||
$#makefile-init()
|
||||
|
||||
$##make-makefiles($#@($#(SNARK_DIRECTORIES)))
|
||||
|
||||
all: $#dummy()
|
||||
$##make-all($#@($#(SNARK_DIRECTORIES)))
|
||||
|
||||
sizes: $#dummy()
|
||||
$##make-sizes($#@($#(SNARK_DIRECTORIES)))
|
||||
|
||||
clean: $#dummy()
|
||||
$##make-clean($#@($#(SNARK_DIRECTORIES)))
|
||||
@@ -0,0 +1,139 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/router/cmds.h,v 1.2 2001/11/09 21:06:48 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1994-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: cmds.h,v $
|
||||
* Revision 1.2 2001/11/09 21:06:48 josh
|
||||
* demo router path modification
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:49:09 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.10 2001/05/10 15:45:51 paul
|
||||
* Removed tcptest.
|
||||
*
|
||||
* Revision 2.9 2001/01/19 22:24:36 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.8 2000/03/17 00:14:17 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.7 1999/04/29 22:31:22 wes
|
||||
* Beginnings of a test to exercise random dark corners/error cases in
|
||||
* the tcp API.
|
||||
*
|
||||
* Revision 2.6 1999/04/15 21:43:39 wes
|
||||
* Fix SNARK_ATTACHE_34_DNS_COMPAT to continue working..
|
||||
*
|
||||
* Revision 2.5 1998/12/02 18:07:17 josh
|
||||
* additions to allow dynamic adding/deleting of IP addresses
|
||||
*
|
||||
* Revision 2.4 1998/10/28 18:51:04 josh
|
||||
* marging in courier-sep98 branch
|
||||
*
|
||||
* Revision 2.3.4.2 1998/09/11 18:53:49 sra
|
||||
* Second batch of updates from Josh and Shukri.
|
||||
*
|
||||
* Revision 2.3.4.1 1998/09/11 05:50:30 sra
|
||||
* Initial commit on courier-sep98 branch.
|
||||
*
|
||||
* Revision 2.3 1998/06/25 21:31:12 wes
|
||||
* Add command to start/stop/abort DHCP from the command line
|
||||
*
|
||||
* Revision 2.2 1998/06/22 22:17:11 meister
|
||||
* include sty.h
|
||||
*
|
||||
* Revision 2.1 1998/04/09 22:00:23 wes
|
||||
* Start splitting main.c into app-specific files; add netime client
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
#if INSTALL_ATTACHE_DNS
|
||||
#include <wrn/wm/attache/dns.h>
|
||||
#include <wrn/wm/demo/sty.h>
|
||||
|
||||
/* Print DNS error to `sty'.. */
|
||||
void display_dns_error(struct sty *, struct dns_query *, enum dns_error);
|
||||
|
||||
#if INSTALL_SNARK_ATTACHE_34_DNS_COMPAT
|
||||
|
||||
extern void snark_attache_dns_34_compat
|
||||
(void (*handler)(struct dns_query *, char *, int, ipaddr_t [], void *),
|
||||
struct dns_query *query,
|
||||
char *dname,
|
||||
int n,
|
||||
inaddr_t addrs[],
|
||||
void *cookie);
|
||||
|
||||
#define DNS_NAME_TO_IPADDR(x1, x2, x3, x4, x5, x6) \
|
||||
dns_name_to_address(x1, x2 ## _compat , x3, x4, x5, x6)
|
||||
#else /* INSTALL_SNARK_ATTACHE_34_DNS_COMPAT */
|
||||
|
||||
#define DNS_NAME_TO_IPADDR dns_name_to_ipaddr
|
||||
|
||||
#endif /* INSTALL_SNARK_ATTACHE_34_DNS_COMPAT */
|
||||
|
||||
#endif /* INSTALL_ATTACHE_DNS */
|
||||
|
||||
enum help_level { help_none, help_short, help_long };
|
||||
|
||||
extern char *prompt;
|
||||
|
||||
void do_cmd(struct sty *, char *, void *);
|
||||
|
||||
/* command-related prototypes */
|
||||
boolean_t cmd_tftp (struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_netime (struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_dhcp (struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_add_address (struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_delete_address(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
|
||||
|
||||
|
||||
#if INSTALL_COURIER
|
||||
#if INSTALL_COURIER_RIP
|
||||
boolean_t cmd_rip_get_export_template (struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_rip_get_import_template (struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_rip_add_export_filter(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_rip_add_export_template(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_rip_add_import_filter(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_rip_add_import_template(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_rip_delete_export_filter(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_rip_delete_export_template(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_rip_delete_import_filter(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_rip_delete_import_template(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
#endif
|
||||
#if INSTALL_COURIER_OSPF
|
||||
boolean_t cmd_ospf_add_export_filter(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_ospf_add_export_template(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_ospf_add_import_filter(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_ospf_add_import_template(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_ospf_delete_export_filter(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_ospf_delete_export_template(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_ospf_delete_import_filter(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
boolean_t cmd_ospf_delete_import_template(struct sty *sty, enum help_level help, int argc, char **argv);
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,342 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/router/dhcpcmd.c,v 1.2 2001/11/09 21:06:49 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1994-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: dhcpcmd.c,v $
|
||||
* Revision 1.2 2001/11/09 21:06:49 josh
|
||||
* demo router path modification
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:49:09 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.4 2001/01/19 22:24:37 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.3 2000/03/17 00:14:17 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.2 1998/08/17 22:47:21 wes
|
||||
* Modify 'dhcp punt' command slightly
|
||||
*
|
||||
* Revision 2.1 1998/06/25 21:31:12 wes
|
||||
* Add command to start/stop/abort DHCP from the command line
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/ipaddr.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include "cmds.h"
|
||||
|
||||
#if INSTALL_ATTACHE_DHCP
|
||||
#include <wrn/wm/attache/dhcp.h>
|
||||
#endif
|
||||
|
||||
#include <wrn/wm/attache/route.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
#include <wrn/wm/demo/read_ini.h>
|
||||
|
||||
#if INSTALL_ATTACHE_DHCP
|
||||
|
||||
|
||||
/* string for DHCP second-level commands */
|
||||
static char * dhcp_cmds[] = { "start", "stop", "status", "punt" };
|
||||
#define DHCP_CMDS (sizeof(dhcp_cmds)/sizeof(*dhcp_cmds))
|
||||
|
||||
/* dhcp_parse_parm()
|
||||
*
|
||||
* Parse a parameter to a command.
|
||||
*
|
||||
* Takes a string containing the parameter entered,
|
||||
* a list of possible parameter values to match it against,
|
||||
* and a count of the number of values in that list.
|
||||
* Returns the 1-based offset of the matched value,
|
||||
* or 0 if not found.
|
||||
*/
|
||||
static int dhcp_parse_parm(char * cmd, char * cmd_list[], int num_choices)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<num_choices; i++)
|
||||
if (STRNICMP(cmd, cmd_list[i], strlen(cmd)) == 0)
|
||||
return (i+1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dhcp_cmd_cb_func(void * mycookie,
|
||||
dhcp_hdr_t * msg,
|
||||
dhcp_stateblk_t * state_block,
|
||||
dhcp_event_t event)
|
||||
{
|
||||
#if 0
|
||||
char buf[80];
|
||||
char *s;
|
||||
struct ini_handle *oldhandle = ini_handle;
|
||||
#endif
|
||||
int p;
|
||||
#if SNARK_GRATUITOUS_ARP
|
||||
ipaddr_t myaddr_ip;
|
||||
#endif
|
||||
|
||||
p = snark_dhcp_get_punt(state_block);
|
||||
|
||||
if (p != 0) {
|
||||
p--;
|
||||
if (p == 0)
|
||||
dhcp_stop(state_block);
|
||||
printf("dhcp: stop in %d callbacks\n", p);
|
||||
snark_dhcp_set_punt(state_block, p);
|
||||
return;
|
||||
}
|
||||
switch (event) {
|
||||
case DHCP_EVT_GOT_RESPONSE:
|
||||
if (DHCP_INVC_STATE(state_block) == DHCP_ST_SELECTING)
|
||||
dhcp_request(state_block, msg);
|
||||
break;
|
||||
|
||||
case DHCP_EVT_TIMEOUT_CHOOSE_OFFER:
|
||||
fprintf(stderr,"\"Shouldn't happen\" DHCP event!\n");
|
||||
dhcp_stop(state_block);
|
||||
break;
|
||||
|
||||
case DHCP_EVT_MSG_TO_GO:
|
||||
#if 0
|
||||
if (oldhandle == 0)
|
||||
ini_handle = ini_open(256); /* Open the ini file */
|
||||
sprintf(buf,"%s-dhcp-clientid",state_block->net->s_name);
|
||||
if ((s = INI_LOOKUP(attache_section, buf)) != 0 &&
|
||||
(STRLEN(s) >0))
|
||||
dhcp_add_option(msg, DHCP_TAG_CLIENT_ID,
|
||||
(bits8_t) STRLEN(s), (bits8_t *) s);
|
||||
if (oldhandle == 0)
|
||||
ini_close(ini_handle); /* Close the ini file */
|
||||
ini_handle = oldhandle;
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DHCP_EVT_CANT_ADD_ADDR_MASK:
|
||||
case DHCP_EVT_CANT_ADD_ADDR_BRD:
|
||||
case DHCP_EVT_CANT_ADD_ADDR_MEM:
|
||||
case DHCP_EVT_CANT_ADD_ADDR_UNK:
|
||||
fprintf(stderr,"DHCP problem adding address!\n");
|
||||
dhcp_stop(state_block);
|
||||
break;
|
||||
|
||||
case DHCP_EVT_BOUND:
|
||||
{
|
||||
int optionlen = 0;
|
||||
unsigned char *buf = 0;
|
||||
dhcp_err_t code = dhcp_get_option(msg, DHCP_TAG_X_FS, &optionlen, 0);
|
||||
printf("get_option returns code %d, optlen %d\n",
|
||||
code, optionlen);
|
||||
|
||||
code = dhcp_get_option(msg, DHCP_TAG_ROUTER, &optionlen, 0);
|
||||
printf("get_option returns code %d, optlen %d\n",
|
||||
code, optionlen);
|
||||
if (code == 0) {
|
||||
int i;
|
||||
buf = GLUE_ALLOC(optionlen);
|
||||
code = dhcp_get_option(msg, DHCP_TAG_ROUTER, &optionlen, buf);
|
||||
printf("Value:");
|
||||
for (i=0; i<optionlen; i++) {
|
||||
printf(" %02x", buf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
#if INSTALL_SNARK_DHCP_CONSOLE_MSGS
|
||||
printf(" -- Interface %s has address %s; DHCP running --\n",
|
||||
state_block->net->s_name,
|
||||
inettoa(state_block->myaddr));
|
||||
#endif /* INSTALL_SNARK_DHCP_CONSOLE_MSGS */
|
||||
#if SNARK_GRATUITOUS_ARP
|
||||
/* it'll end up doing this on every lease renewal as well as
|
||||
* when it first starts, but that's okay for demo code;
|
||||
* production code shouldn't be doing this in the first place
|
||||
* (because it should have a permanent hardware address)
|
||||
*/
|
||||
SET_IPADDR_TYPE(&myaddr_ip, IPV4);
|
||||
MEMCPY(PTR_IPADDR_BITS(&myaddr_ip), &state_block->myaddr, IPV4_ADDR_LEN);
|
||||
snark_gratuitous_arp(state_block->net, &myaddr_ip);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case DHCP_EVT_BOOTP_MSG:
|
||||
fprintf(stderr, "DHCP -- Server error!\n");
|
||||
break;
|
||||
|
||||
case DHCP_EVT_LEASE_RENEWING:
|
||||
case DHCP_EVT_LEASE_REBINDING:
|
||||
case DHCP_EVT_ADDRESS_LOST:
|
||||
#if INSTALL_SNARK_DHCP_CONSOLE_MSGS
|
||||
printf(" -- DHCP address renegotiation... --\n");
|
||||
#endif /* INSTALL_SNARK_DHCP_CONSOLE_MSGS */
|
||||
break;
|
||||
|
||||
case DHCP_EVT_QUITTING:
|
||||
#if INSTALL_SNARK_DHCP_CONSOLE_MSGS
|
||||
printf(" -- DHCP quit. --\n");
|
||||
#endif /* INSTALL_SNARK_DHCP_CONSOLE_MSGS */
|
||||
snark_dhcp_remove(state_block);
|
||||
break;
|
||||
|
||||
case DHCP_EVT_DECLINE:
|
||||
case DHCP_EVT_TIMEOUT_NO_RESPONSE:
|
||||
default:
|
||||
/* If we don't know about this particular event, just ignore it. */
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
int dump_status (void *cookie, dhcp_stateblk_t *dhcp, net_if *net)
|
||||
{
|
||||
struct sty *sty = cookie;
|
||||
static char *state_name[] = {
|
||||
"REBOOT",
|
||||
"INIT",
|
||||
"SELECTING",
|
||||
"REQUESTING",
|
||||
"BOUND",
|
||||
"RENEWING",
|
||||
"REBINDING",
|
||||
"ADDRESSCHECK"
|
||||
};
|
||||
|
||||
sty_printf(sty,
|
||||
"%s: %s\n",
|
||||
net->s_name? net->s_name : "???",
|
||||
state_name[dhcp->state]);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* commands:
|
||||
* dhcp start <if>
|
||||
* dhcp stop <if>
|
||||
* dhcp punt <if>
|
||||
* dhcp status <if>
|
||||
*/
|
||||
|
||||
boolean_t dhcp_do_cmd (int argc, char **argv, struct sty *sty)
|
||||
{
|
||||
dhcp_err_t code;
|
||||
dhcp_stateblk_t *dhcphandle;
|
||||
int p;
|
||||
|
||||
char *ifname = argv[2];
|
||||
net_if *n = if_lookup(ifname);
|
||||
|
||||
if (n == NULL) {
|
||||
sty_printf(sty, "Unknown interface %s\n", ifname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (dhcp_parse_parm(argv[1], dhcp_cmds, DHCP_CMDS)) {
|
||||
case 1:
|
||||
code = dhcp_coldstart (n, 0, dhcp_cmd_cb_func, &dhcphandle, 0);
|
||||
sty_printf(sty, "Coldstart returned %d\n", code);
|
||||
if (code == 0) {
|
||||
snark_dhcp_add (n, dhcphandle);
|
||||
}
|
||||
/* start */
|
||||
break;
|
||||
|
||||
case 2:
|
||||
dhcphandle = snark_dhcp_find (n);
|
||||
if (dhcphandle == NULL) {
|
||||
sty_printf(sty, "No DHCP invocation on %s found!\n", ifname);
|
||||
} else {
|
||||
dhcp_stop(dhcphandle);
|
||||
}
|
||||
/* stop */
|
||||
break;
|
||||
|
||||
case 3:
|
||||
snark_dhcp_walk (dump_status, sty);
|
||||
/* status */
|
||||
break;
|
||||
|
||||
case 4:
|
||||
p = 1;
|
||||
if (argc > 3)
|
||||
p = atoi(argv[3]);
|
||||
|
||||
dhcphandle = snark_dhcp_find (n);
|
||||
if (dhcphandle == NULL) {
|
||||
sty_printf(sty, "No DHCP invocation on %s found!\n", ifname);
|
||||
} else {
|
||||
snark_dhcp_set_punt(dhcphandle, p);
|
||||
printf("dhcp will punt after %d callbacks\n", p);
|
||||
}
|
||||
/* punt */
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
boolean_t cmd_dhcp (struct sty *sty, enum help_level help,
|
||||
int argc, char **argv)
|
||||
{
|
||||
if (argc < 3)
|
||||
help=help_short;
|
||||
|
||||
switch(help) {
|
||||
case help_none:
|
||||
return dhcp_do_cmd(argc, argv, sty);
|
||||
break;
|
||||
case help_short:
|
||||
sty_puts(sty, "dhcp dhcp start/stop/status/punt interface\n");
|
||||
break;
|
||||
case help_long:
|
||||
sty_puts(sty, "\
|
||||
The \"dhcp\" command allows for automatic configuration of addresses on\n\
|
||||
interfaces via the DHCP protocol.\n");
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/router/drv_conf.c,v 1.3 2003/01/15 14:04:49 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: drv_conf.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:49 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/09 21:06:49 josh
|
||||
* demo router path modification
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:49:09 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.7 2001/01/19 22:24:37 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.6 2000/03/17 00:14:18 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.5 1998/09/30 18:41:51 meister
|
||||
* drv_conf.c needs install.h now
|
||||
*
|
||||
* Revision 1.4 1998/09/28 23:19:03 meister
|
||||
* *** empty log message ***
|
||||
*
|
||||
* Revision 1.1 1998/08/19 21:02:11 meister
|
||||
* drv_conf.c --> drv.c, now just a pointer to the REAL drv_conf in a port dir
|
||||
*
|
||||
* Revision 1.2 1998/08/03 21:35:46 meister
|
||||
* added old revision histories comment
|
||||
*
|
||||
* Revision 1.1 1998/08/03 21:33:58 meister
|
||||
* added root.c and drv_conf.c to snark/router
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* old revision history from snark/psos/router
|
||||
*
|
||||
* Revision 1.3 1998/06/24 18:46:44 meister
|
||||
* More cosmetics
|
||||
*
|
||||
* Revision 1.2 1998/06/24 17:38:53 meister
|
||||
* Legal boilerplate.
|
||||
*
|
||||
*/
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <drv_conf.h>
|
||||
@@ -0,0 +1,168 @@
|
||||
[etc attache]
|
||||
|
||||
;; $Header: /usr/cvsroot/target/src/wrn/wm/demo/router/etc.ini,v 1.1.1.1 2001/11/05 17:49:09 tneale Exp $
|
||||
|
||||
;; This is a sample configuration file for the Snark port of Attache.
|
||||
;; All the lines beginning with ";" characters are comments.
|
||||
;;
|
||||
;; The lines beginning with ";;" are comments meant for humans.
|
||||
;;
|
||||
;; The lines beginning with a single ";" are commented-out commands.
|
||||
;; Uncomment the commands you need, filling in the addresses, masks, and
|
||||
;; DNS names as appropriate for your site.
|
||||
|
||||
;; Part one: interface definitions.
|
||||
;;
|
||||
;; For each interface, there are several values that you can configure.
|
||||
;; See the function netconfig_if() in snark/lib/netconf.c for details.
|
||||
;; The most useful parameters are the IP address ("xxx-address = a.b.c.d"),
|
||||
;; the netmask ("xxx-netmask = a.b.c.d"), and, for a serial line, the line
|
||||
;; speed ("xxx-speed = nnnnn"). In all of these, "xxx" is the interface name.
|
||||
;;
|
||||
;; How interfaces are named varies depending on the environment in which
|
||||
;; snark is running. Currently, the NetBSD port of snark supports two kinds
|
||||
;; of interfaces: BPF interfaces have names like "bpfxxx" where "xxx" is the
|
||||
;; name of the NetBSD interface device; serial interfaces have names like
|
||||
;; "sln" where "n" is the unit number of the serial device. The SunOS 4.1.2
|
||||
;; port of snark supports the NIT streams interface. For either NetBSD or
|
||||
;; SunOS, be sure you have access to the network device special file
|
||||
;; (/dev/bpfnnn or /dev/nit). Under MS-DOS, the only kind of interface
|
||||
;; currently supported is the FTP Software packet driver spec (aka
|
||||
;; "Clarkson" or "Crynwr" packet driver); interfaces have names of the form
|
||||
;; "xxxxnnn" where "xxxx" is the short name by which the packet driver
|
||||
;; identifies itself, and "nnn" is the hex interrupt number. Last, all
|
||||
;; ports of snark support the Attache loopback device, "lp0".
|
||||
|
||||
;; This is a host running over BPF over interface we0 on NetBSD 0.8.
|
||||
;bpfed0-address = a.b.c.d
|
||||
;bpfed0-netmask = 255.255.255.0
|
||||
|
||||
;; This is a host running over NIT over interface le0 on SunOS 4.1.2.
|
||||
;nitle0-address = a.b.c.d
|
||||
;nitle0-netmask = 255.255.255.0
|
||||
|
||||
;; This is a host running over SLIP over interface /dev/com0 on NetBSD 0.8.
|
||||
;sl1-address = a.b.c.d
|
||||
;sl1-netmask = 255.255.255.0
|
||||
;sl1-speed = 38400
|
||||
|
||||
;; This is an ethernet packet driver on interrupt 0x60 on MS-DOS.
|
||||
;ether60-address = a.b.c.d
|
||||
;ether60-netmask = 255.255.255.0
|
||||
|
||||
;; Attache loopback interface, any port of Snark.
|
||||
;; Don't change the IP address, it's the one Berkeley seized for this purpose
|
||||
;; and it's been retroactively blessed by the Number Czar.
|
||||
;; Don't try to change the netmask either.
|
||||
lp0-address = 127.0.0.1
|
||||
lp0-netmask = 255.255.255.255
|
||||
|
||||
;; Part two: routing setup.
|
||||
;;
|
||||
;; There are a couple of commands you can use to configure routes
|
||||
;; at boot time. See netconfig_route() in snark/lib/netconf.c for details.
|
||||
;;
|
||||
;; You almost certainly want to configure a default route: this simply
|
||||
;; names the router to which we should send packets that would
|
||||
;; otherwise be dropped for lack of better information. This command
|
||||
;; takes one argument, the IP address of the default router.
|
||||
;;
|
||||
;; For more complicated static routing, you can use the route-gw
|
||||
;; command. This establishes a route to a particular network via
|
||||
;; a specified router. This command takes three arguments: the
|
||||
;; destination network, the netmask for the destination network, and
|
||||
;; the first-hop router to get to the destination network. There's an
|
||||
;; optional fourth argument which sets the route's priority.
|
||||
|
||||
;; Static route to network p.q.r.s via router w.x.y.z.
|
||||
;route-gw = p.q.r.s 255.255.255.0 w.x.y.z
|
||||
|
||||
;; Default router, gets all traffic with no better destination. The
|
||||
;; preference value is only significant if Router Discovery is installed.
|
||||
;; Format route-default = <nh_address> [preference]
|
||||
;route-default = a.b.c.d 0
|
||||
|
||||
;; Router addresses to Advertise (only if IPv4 Router Discovery and
|
||||
;; IP Forwarding are enabled).
|
||||
;; Format: router-advert = <interface> <router address> <preference>
|
||||
;router-advert = bpfde0 w.x.y.z 0
|
||||
;router-advert = bpfde0 a.b.c.d 10
|
||||
|
||||
;; Part three: Domain Name System configuration
|
||||
;;
|
||||
;; If you're going to use the DNS code to translate between hostnames
|
||||
;; and IP addresses, you need to configure at least snark to know
|
||||
;; about at least one DNS nameserver that offers recursive DNS
|
||||
;; service. You should really configure at least two for any serious
|
||||
;; use. You may also want to configure a search path, to allow you to
|
||||
;; specify just the prefix portion of a hostname and have the DNS code
|
||||
;; know what you mean. See netconfig_dns() in snark/lib/netconf.c for
|
||||
;; the details of how this all works.
|
||||
;;
|
||||
;; To configure a name server, use the nameserver command. At present
|
||||
;; it takes one argument, the IP address of the nameserver. This may
|
||||
;; be expanded in a future version of this code.
|
||||
;;
|
||||
;; To configure a DNS search path, use the dns-suffix command. It
|
||||
;; takes one argument, the "printed" (human-readable) form of a DNS
|
||||
;; name which will be used as a suffix. If you use this command more
|
||||
;; than once, it establishes a list of suffixes, in the specified
|
||||
;; order. WARNING: if you use this command, be sure to put the null
|
||||
;; suffix (written as ".") in your search path. If you don't,
|
||||
;; fully-qualified DNS names will mysteriously fail to work.
|
||||
|
||||
;; DNS name servers
|
||||
;nameserver = a.b.c.d
|
||||
;nameserver = u.v.w.x
|
||||
|
||||
;; DNS search path
|
||||
;dns-suffix = mydomain.com
|
||||
;dns-suffix = .
|
||||
|
||||
[etc envoy]
|
||||
; the file from which to get the manager's mib
|
||||
mibfile=mib.rt
|
||||
|
||||
; community string to use on gets
|
||||
read-community=public
|
||||
|
||||
; community string to use on sets
|
||||
write-community=private
|
||||
|
||||
; seconds to wait before retrying request
|
||||
timeout=3
|
||||
|
||||
; number of times to try before giving up
|
||||
retry-count=2
|
||||
|
||||
;;; the non volatile group, with their defaults
|
||||
;; the configuration file for non volatile info
|
||||
; nv-config-file = snmp_nv.txt
|
||||
|
||||
;; the old configuration file
|
||||
; nv-config-file-old = snmp_nv.old
|
||||
|
||||
;; the temporary configurationfile
|
||||
; nv-config-file-temp = snmp_nv.tmp
|
||||
|
||||
;; the read only flag, 1 = config file is read only, 0 = file is writeable
|
||||
; nv-read-only = 0
|
||||
|
||||
;;; configuration information for SNMPv3 and defaults
|
||||
;; engined id of this engine, unseparated hex string
|
||||
;; if this field is filled in it is used as the engine id,
|
||||
;; if it is empty the engine id should come from the nv config file
|
||||
;v3_engine_id = 0000000c000000007f000001
|
||||
|
||||
;; the security engine id, unseparated hex string
|
||||
v3_security_id = 0000000c000000007f000001
|
||||
|
||||
;;; the security name
|
||||
v3_security_name = initialmd5
|
||||
|
||||
;; the context engine id, unseparated hex string
|
||||
;v3_context_id =
|
||||
|
||||
;; the context name
|
||||
;v3_context_name =
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/router/if_ctl.c,v 1.2 2001/11/09 21:06:49 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1994-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: if_ctl.c,v $
|
||||
* Revision 1.2 2001/11/09 21:06:49 josh
|
||||
* demo router path modification
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:49:09 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.7 2001/01/19 22:24:37 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.6 2000/03/17 00:14:18 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.5 1998/03/03 15:24:31 mrf
|
||||
* Clean up short help and add new features to compile-options command.
|
||||
*
|
||||
* Revision 2.4 1998/02/25 04:57:46 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.3 1997/03/20 06:53:27 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.2 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.2 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.1 1994/12/20 22:42:45 dab
|
||||
* Initial revision
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Commands for poking around the interface list.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
enum help_level { help_none, help_short, help_long };
|
||||
|
||||
extern net_if *If_list;
|
||||
net_if *detached_If_list = 0; /* net I detach get put here */
|
||||
|
||||
/* Print stats about each net interface. */
|
||||
boolean_t
|
||||
cmd_if_stat(struct sty *sty,
|
||||
enum help_level help,
|
||||
int argc,
|
||||
char **argv)
|
||||
{
|
||||
net_if *n;
|
||||
char buf[80];
|
||||
int ifIndex;
|
||||
|
||||
switch (help) {
|
||||
case help_short:
|
||||
sty_puts(sty, "ifstat print interface statistics\n");
|
||||
break;
|
||||
|
||||
case help_long:
|
||||
sty_puts(sty, "\
|
||||
Print the status and statistics for each interface in the\n\
|
||||
interface list.\n");
|
||||
break;
|
||||
|
||||
case help_none:
|
||||
ifIndex = 1;
|
||||
if (If_list == 0)
|
||||
sty_puts(sty, "Interface list is empty\n");
|
||||
else {
|
||||
for (n = If_list; n; n = n->link) {
|
||||
/* only prints up/down status right now */
|
||||
sprintf(buf, "%2d: %10s %4s %10s\n",
|
||||
ifIndex, n->s_name,
|
||||
n->flags & NF_DOWN ? "Down" : "Up",
|
||||
n->flags & NF_DRIVER_DOWN ? "DriverDown" : "DriverUp");
|
||||
sty_puts(sty, buf);
|
||||
ifIndex++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 1; /* restart command scanner */
|
||||
}
|
||||
|
||||
/* look up an interface by its name and return a pointer to the
|
||||
* structure or 0 if none is found. List is the start of the
|
||||
* interface list, usually If_list if we want Attache's interfaces or
|
||||
* detached_If_list if it's an interface we've removed. */
|
||||
static net_if *
|
||||
if_lookup_by_name(char *name, net_if *if_list)
|
||||
{
|
||||
net_if *n;
|
||||
|
||||
for (n = if_list; n; n = n->link)
|
||||
if (STRCMP(n->s_name, name) == 0)
|
||||
return n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* mark an interface down */
|
||||
boolean_t
|
||||
cmd_if_down(struct sty *sty,
|
||||
enum help_level help,
|
||||
int argc,
|
||||
char **argv)
|
||||
{
|
||||
net_if *n;
|
||||
|
||||
switch (help) {
|
||||
case help_short:
|
||||
sty_puts(sty, "down down interface-name\n");
|
||||
break;
|
||||
|
||||
case help_long:
|
||||
sty_puts(sty, "Mark an interface as down.\n");
|
||||
break;
|
||||
|
||||
case help_none:
|
||||
if (argc != 2) {
|
||||
sty_puts(sty, "usage: down interface-name\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if ((n = if_lookup_by_name(argv[1], If_list)) != 0)
|
||||
if_down(n);
|
||||
else {
|
||||
sty_puts(sty, "No interface called '");
|
||||
sty_puts(sty, argv[1]);
|
||||
sty_puts(sty, "'\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 1; /* restart command scanner */
|
||||
}
|
||||
|
||||
/* mark an interface up */
|
||||
boolean_t
|
||||
cmd_if_up(struct sty *sty,
|
||||
enum help_level help,
|
||||
int argc,
|
||||
char **argv)
|
||||
{
|
||||
net_if *n;
|
||||
|
||||
switch (help) {
|
||||
case help_short:
|
||||
sty_puts(sty, "up up interface-name\n");
|
||||
break;
|
||||
|
||||
case help_long:
|
||||
sty_puts(sty, "Mark an interface as up.\n");
|
||||
break;
|
||||
|
||||
case help_none:
|
||||
if (argc != 2) {
|
||||
sty_puts(sty, "usage: up interface-name\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if ((n = if_lookup_by_name(argv[1], If_list)) != 0)
|
||||
if_up(n);
|
||||
else {
|
||||
sty_puts(sty, "No interface called '");
|
||||
sty_puts(sty, argv[1]);
|
||||
sty_puts(sty, "'\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 1; /* restart command scanner */
|
||||
}
|
||||
|
||||
/* Detach this interface. The interface is placed on a detached list
|
||||
* so it can be re-attached later. */
|
||||
boolean_t
|
||||
cmd_if_detach(struct sty *sty,
|
||||
enum help_level help,
|
||||
int argc,
|
||||
char **argv)
|
||||
{
|
||||
net_if *n;
|
||||
|
||||
switch (help) {
|
||||
case help_short:
|
||||
sty_puts(sty, "detach detach interface-name\n");
|
||||
break;
|
||||
|
||||
case help_long:
|
||||
sty_puts(sty, "\
|
||||
Remove an interface from Attache's knowledge. It is\n\
|
||||
placed on a detached list so it can be reattached later.\n");
|
||||
break;
|
||||
|
||||
case help_none:
|
||||
if (argc != 2) {
|
||||
sty_puts(sty, "usage: detach interface-name\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if ((n = if_lookup_by_name(argv[1], If_list)) != 0) {
|
||||
/* remove the interface from Attache */
|
||||
if_detach(n);
|
||||
/* thread the interface onto here so we can reattach it later */
|
||||
n->link = detached_If_list;
|
||||
detached_If_list = n;
|
||||
}
|
||||
else {
|
||||
sty_puts(sty, "No interface called '");
|
||||
sty_puts(sty, argv[1]);
|
||||
sty_puts(sty, "'\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 1; /* restart command scanner */
|
||||
}
|
||||
|
||||
/* Interfaces that have been detached with the `detach' command can be
|
||||
reattached with this command. */
|
||||
boolean_t
|
||||
cmd_if_attach(struct sty *sty,
|
||||
enum help_level help,
|
||||
int argc,
|
||||
char **argv)
|
||||
{
|
||||
net_if *n;
|
||||
net_if **np;
|
||||
|
||||
switch (help) {
|
||||
case help_short:
|
||||
sty_puts(sty, "attach attach interface-name\n");
|
||||
break;
|
||||
|
||||
case help_long:
|
||||
sty_puts(sty, "\
|
||||
Reattach an interface that was removed with the `detach' command.\n");
|
||||
break;
|
||||
|
||||
case help_none:
|
||||
if (argc != 2) {
|
||||
sty_puts(sty, "usage: attach interface-name\n");
|
||||
if (detached_If_list == 0)
|
||||
sty_puts(sty, " No interfaces on detached list\n");
|
||||
else {
|
||||
sty_puts(sty, " One of:");
|
||||
for (n = detached_If_list; n; n = n->link) {
|
||||
sty_puts(sty, "\n ");
|
||||
sty_puts(sty, n->s_name);
|
||||
}
|
||||
sty_puts(sty, "\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ((n = if_lookup_by_name(argv[1], detached_If_list)) != 0) {
|
||||
/* remove the interface from the detached list */
|
||||
for (np = &detached_If_list; *np; np = &((*np)->link)) {
|
||||
if ((*np) == n) {
|
||||
*np = (*np)->link;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* tell Attache about it */
|
||||
if_attach(n);
|
||||
}
|
||||
else {
|
||||
sty_puts(sty, "No detached interface called '");
|
||||
sty_puts(sty, argv[1]);
|
||||
sty_puts(sty, "'\n");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 1; /* restart command scanner */
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/router/ip_ctl.c,v 1.2 2001/11/09 21:06:50 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1994-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998-1999 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: ip_ctl.c,v $
|
||||
* Revision 1.2 2001/11/09 21:06:50 josh
|
||||
* demo router path modification
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:49:09 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.4 2001/01/19 22:24:37 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.3 2000/03/17 00:14:18 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.2 1999/11/05 22:24:01 paul
|
||||
* Eliminate dependence on ancient backward-compatibility code.
|
||||
*
|
||||
* Revision 2.1 1998/12/02 18:07:17 josh
|
||||
* additions to allow dynamic adding/deleting of IP addresses
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Commands for adding/deleting IP addresses.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
|
||||
enum help_level { help_none, help_short, help_long };
|
||||
|
||||
/* add an ip address to a net interface. */
|
||||
boolean_t cmd_add_address(struct sty *sty,
|
||||
enum help_level help,
|
||||
int argc,
|
||||
char **argv)
|
||||
{
|
||||
ipaddr_t addr, brd, mask;
|
||||
net_if *n;
|
||||
int err;
|
||||
|
||||
switch (help) {
|
||||
case help_short:
|
||||
sty_puts(sty, "add-address add an IP address\n");
|
||||
break;
|
||||
|
||||
case help_long:
|
||||
sty_puts(sty, "\
|
||||
Add an IP address to Attache using the given net_if.\n");
|
||||
break;
|
||||
|
||||
case help_none:
|
||||
if (argc < 4)
|
||||
{
|
||||
sty_puts(sty, "usage: add-address <ip-address> <netmask> <net> [brd]\n");
|
||||
break;
|
||||
}
|
||||
string_to_ipaddr(argv[1], &addr);
|
||||
if (argc > 4)
|
||||
string_to_ipaddr(argv[4], &brd);
|
||||
else
|
||||
{
|
||||
IPADDR_ALL_ONES(&brd);
|
||||
SET_IPADDR_TYPE(&brd, GET_IPADDR_TYPE(&addr));
|
||||
}
|
||||
if (!(n=if_lookup(argv[3])))
|
||||
{
|
||||
sty_puts(sty, "No interface called ");
|
||||
sty_puts(sty, argv[3]);
|
||||
sty_puts(sty, ".\n");
|
||||
break;
|
||||
}
|
||||
string_to_ipaddr(argv[2], &mask);
|
||||
err = route_add_address(&addr,
|
||||
ipv4_mask_to_pfxlen(&mask),
|
||||
&brd,
|
||||
n);
|
||||
switch (err) {
|
||||
case RCERR_NONE:
|
||||
sty_puts(sty, "IP address ");
|
||||
sty_puts(sty, argv[1]);
|
||||
sty_puts(sty, " successfully added to ");
|
||||
sty_puts(sty, argv[3]);
|
||||
sty_puts(sty, ".\n");
|
||||
break;
|
||||
case RCERR_BADMASK:
|
||||
sty_puts(sty, "Invalid mask.\n");
|
||||
break;
|
||||
case RCERR_BADBRD:
|
||||
sty_puts(sty, "Invalid broadcast address.\n");
|
||||
break;
|
||||
default:
|
||||
sty_puts(sty, "address create error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
boolean_t cmd_delete_address(struct sty *sty,
|
||||
enum help_level help,
|
||||
int argc,
|
||||
char **argv)
|
||||
{
|
||||
ipaddr_t addr;
|
||||
int err;
|
||||
|
||||
switch (help) {
|
||||
case help_short:
|
||||
sty_puts(sty, "delete-address remove an IP address\n");
|
||||
break;
|
||||
|
||||
case help_long:
|
||||
sty_puts(sty, "\
|
||||
Removes an IP address from Attache.\n");
|
||||
break;
|
||||
|
||||
case help_none:
|
||||
if (argc < 2)
|
||||
{
|
||||
sty_puts(sty, "usage: delete-address <ip-address>\n");
|
||||
break;
|
||||
}
|
||||
string_to_ipaddr(argv[1], &addr);
|
||||
err = route_delete_address(&addr);
|
||||
|
||||
switch (err) {
|
||||
case RTE_ERR_NONE:
|
||||
sty_puts(sty, "IP address ");
|
||||
sty_puts(sty, argv[1]);
|
||||
sty_puts(sty, " successfully removed.\n");
|
||||
break;
|
||||
case RTE_ERR_NOENTRY:
|
||||
sty_puts(sty, "IP address ");
|
||||
sty_puts(sty, argv[1]);
|
||||
sty_puts(sty, " does not exist.\n");
|
||||
break;
|
||||
default:
|
||||
sty_puts(sty, "address deletion error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/router/ips_glue.c,v 1.2 2001/11/09 21:06:50 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
/*
|
||||
* $Log: ips_glue.c,v $
|
||||
* Revision 1.2 2001/11/09 21:06:50 josh
|
||||
* demo router path modification
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:49:09 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.8 2001/01/19 22:24:37 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.7 2000/10/26 17:06:47 paul
|
||||
* Added $Header
|
||||
*
|
||||
* Revision 1.5 2000/03/17 00:14:18 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.4 1998/03/12 19:15:47 meister
|
||||
* added GLUE_IPSEC_RCV_SA_NOTUNNEL()
|
||||
*
|
||||
* Revision 1.3 1998/03/10 00:29:11 meister
|
||||
* corrected some inconsistencies in the glue functions.
|
||||
*
|
||||
* Revision 1.2 1998/03/03 15:25:16 mrf
|
||||
* Don't call PRINTF if it isn't defined.
|
||||
*
|
||||
* Revision 1.1 1998/02/27 22:16:34 meister
|
||||
* Initial checkin; snark ipsec glue routines
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* This file defines some basic IPsec glue functions.
|
||||
*/
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/ipaddr.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/ipsec.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
|
||||
/*
|
||||
* if GLUE_IPSEC_SA_EXPIRED is defined, set, this function gets called
|
||||
* when an SA expires. The SA direction, host addr, SPI, and type of SA
|
||||
* is passed up.
|
||||
*/
|
||||
|
||||
|
||||
/* keep it simple; when an SA expires, we just delete it. */
|
||||
void glue_ipsec_sa_expired (ipsec_sa_dir_t dir, ipaddr_t *dst,
|
||||
bits32_t spi, bits8_t satype)
|
||||
{
|
||||
#ifdef PRINTF
|
||||
PRINTF("SA expire notice: %s, %s, spi %lu, %s\n",
|
||||
ipaddr_to_string (dst, 0, 0),
|
||||
(dir == IPSEC_SA_SEND ? "send" : "rcv"),
|
||||
(unsigned long) spi,
|
||||
(satype == IPSEC_SATYPE_ESP ? "esp" : "ah"));
|
||||
#endif
|
||||
|
||||
ipsec_secassoc_destroy_sa (dst, spi, satype, dir);
|
||||
}
|
||||
|
||||
/*
|
||||
* if GLUE_IPSEC_SND_PKT_DENIED is defined, and we deny sending a packet
|
||||
* by policy, this gets called with the packet and the deny code.
|
||||
*/
|
||||
|
||||
void glue_ipsec_snd_pkt_denied(packet *p, ipaddr_t *src, ipaddr_t *dst,
|
||||
int code)
|
||||
{
|
||||
#ifdef PRINTF
|
||||
PRINTF("IPSEC: Packet from %s ", ipaddr_to_string (src, 0, 0));
|
||||
PRINTF("to %s denied, %s\n",
|
||||
ipaddr_to_string (dst, 0, 0),
|
||||
(code == IPSEC_DENIED_NO_SA ?
|
||||
"no sa available" : "policy explicit drop"));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
void glue_ipsec_rcv_pkt_badspi(packet *p, ipaddr_t *src, ipaddr_t *dst,
|
||||
bits32_t spi, bits8_t type)
|
||||
{
|
||||
#ifdef PRINTF
|
||||
PRINTF("IPSEC: Packet from %s ", ipaddr_to_string (src, 0, 0));
|
||||
PRINTF("to %s UNKNOWN %s SPI %lu\n",
|
||||
ipaddr_to_string (dst, 0, 0),
|
||||
(type == IPSEC_SATYPE_ESP ? "esp" : "ah"),
|
||||
(unsigned long) spi);
|
||||
#endif
|
||||
}
|
||||
|
||||
void glue_ipsec_rcv_pkt_notparty(packet *p, ipaddr_t *src, ipaddr_t *dst,
|
||||
bits32_t spi, bits8_t type)
|
||||
{
|
||||
#ifdef PRINTF
|
||||
PRINTF("IPSEC: Packet from %s ", ipaddr_to_string (src, 0, 0));
|
||||
PRINTF("to %s NOT PARTY TO %s SPI %lu\n",
|
||||
ipaddr_to_string (dst, 0, 0),
|
||||
(type == IPSEC_SATYPE_ESP ? "esp" : "ah"),
|
||||
(unsigned long) spi);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void glue_ipsec_rcv_sa_notunnel(packet *p, ipaddr_t *src, ipaddr_t *dst,
|
||||
bits32_t spi, bits8_t type)
|
||||
{
|
||||
#ifdef PRINTF
|
||||
PRINTF("IPSEC: Packet from %s ", ipaddr_to_string (src, 0, 0));
|
||||
PRINTF("to %s USE of TRANSPORT ONLY %s SPI %lu AS TUNNEL\n",
|
||||
ipaddr_to_string (dst, 0, 0),
|
||||
(type == IPSEC_SATYPE_ESP ? "esp" : "ah"),
|
||||
(unsigned long) spi);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void glue_ipsec_rcv_tunpkt_notip(packet *tun, packet *p,
|
||||
ipaddr_t *src, ipaddr_t *dst,
|
||||
bits32_t spi, bits8_t type)
|
||||
{
|
||||
#ifdef PRINTF
|
||||
PRINTF("IPSEC: tunnel from %s ", ipaddr_to_string (src, 0, 0));
|
||||
PRINTF("to %s ", ipaddr_to_string (dst, 0, 0));
|
||||
PRINTF("handed us a NOT IP packet. %s SPI %lu\n",
|
||||
(type == IPSEC_SATYPE_ESP ? "esp" : "ah"),
|
||||
(unsigned long) spi);
|
||||
#endif
|
||||
}
|
||||
|
||||
void glue_ipsec_rcv_tunpkt_notparty(packet *tun, ipaddr_t *tsrc,
|
||||
ipaddr_t *tdst,
|
||||
packet *outer, ipaddr_t *osrc,
|
||||
ipaddr_t *odst,
|
||||
bits32_t spi, bits8_t type)
|
||||
{
|
||||
#ifdef PRINTF
|
||||
PRINTF("IPSEC: tunneled packet from %s ", ipaddr_to_string (tsrc, 0, 0));
|
||||
PRINTF("to %s ", ipaddr_to_string (tdst, 0, 0));
|
||||
PRINTF("NOT PARTY TO %s SPI %lu\n",
|
||||
(type == IPSEC_SATYPE_ESP ? "esp" : "ah"),
|
||||
(unsigned long) spi);
|
||||
PRINTF("\t encapsulating packet was from %s ",
|
||||
ipaddr_to_string (osrc, 0, 0));
|
||||
PRINTF("to %s ", ipaddr_to_string (odst, 0, 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void glue_ipsec_rcv_pkt_badah(packet *p, ipaddr_t *src,
|
||||
ipaddr_t *dst, bits32_t spi)
|
||||
{
|
||||
#ifdef PRINTF
|
||||
PRINTF("IPSEC: Packet from %s ", ipaddr_to_string (src, 0, 0));
|
||||
PRINTF("to %s FAILS AH VERIFICATION SPI %lu\n",
|
||||
ipaddr_to_string (dst, 0, 0),
|
||||
(unsigned long) spi);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void glue_ipsec_rcv_pkt_denied(packet *p, ipaddr_t *src, ipaddr_t *dst,
|
||||
ipsec_policy_flags_t polflags,
|
||||
bits16_t pktflags)
|
||||
{
|
||||
#ifdef PRINTF
|
||||
PRINTF("IPSEC: Packet from %s ", ipaddr_to_string (src, 0, 0));
|
||||
PRINTF("to %s Fails Recieve Policy. \n",
|
||||
ipaddr_to_string (dst, 0, 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,119 @@
|
||||
|
||||
#
|
||||
# Makefile for snark/router
|
||||
#
|
||||
|
||||
# It should be possible to override these somehow.
|
||||
$#equate(SNARK_TEST_MIBS
|
||||
$#if-installed(ATTACHE_MIB rfc1213.mib)
|
||||
$#if-installed(ATTACHE_CIDR_MIB rfc2096.mib)
|
||||
$#if-installed(ENVOY_SNMP_RFC2275_VIEWS $#progn(rfc2571.mib rfc2575.mib))
|
||||
$#if-installed(ENVOY_SNMP_VERSION_3 $#progn(rfc2572.mib rfc2573.mib
|
||||
rfc2574.mib rfc2576.mib))
|
||||
$#if-installed(ENVOY_ENTITY_MIB rfc2737.mib))
|
||||
|
||||
$#equate(SNARK_TEST_CTLS
|
||||
$#if-installed(ATTACHE_TCP
|
||||
$#nil() $#progn(-exclude tcp))
|
||||
$#if-installed(ENVOY_SNMP_GROUP_V1
|
||||
$#nil()
|
||||
$#if-installed(ENVOY_SNMP_GROUP_V2
|
||||
$#filepath($(SRCDIR) target src wrn wm demo snmpctls v1_exc.mib)
|
||||
$#progn(-exclude snmp)))
|
||||
$#if-installed(ATTACHE_MIB
|
||||
$#filepath($(SRCDIR) target src wrn wm attache net attache.mib))
|
||||
$#if-installed(ENVOY_SNMP_RFC2275_VIEWS
|
||||
$#if-installed(ENVOY_SNMP_VERSION_3
|
||||
$#filepath($(SRCDIR) target src wrn wm demo snmpctls v3mib.ctl)
|
||||
$#filepath($(SRCDIR) target src wrn wm demo snmpctls view2275.ctl)))
|
||||
$#if-installed(ENVOY_ENTITY_MIB
|
||||
$#filepath($(SRCDIR) target src wrn wm demo snmpctls entity.mib)))
|
||||
|
||||
$#if-installed(ENVOY_SNMP_VERSION_3
|
||||
$#equate(SNMPTALK_MIB_V3_EXCLUDES
|
||||
$#progn(
|
||||
$#if-installed(ENVOY_SNMP_V3_TARGET
|
||||
$#nil()
|
||||
$#filepath($(SRCDIR) target src wrn wm demo snmpctls v3trgtex.mib))
|
||||
$#if-installed(ENVOY_SNMP_V3_NOTIFY
|
||||
$#nil()
|
||||
$#filepath($(SRCDIR) target src wrn wm demo snmpctls v3ntfyex.mib))
|
||||
$#if-installed(ENVOY_SNMP_V3_PROXY
|
||||
$#nil()
|
||||
$#filepath($(SRCDIR) target src wrn wm demo snmpctls v3pxyex.mib))
|
||||
$#if-installed(ENVOY_SNMP_COEXISTENCE
|
||||
$#nil()
|
||||
$#filepath($(SRCDIR) target src wrn wm demo snmpctls v3commex.mib)))))
|
||||
|
||||
$#makefile-init()
|
||||
|
||||
$#equate(OBJS
|
||||
$#objs(main if_ctl ip_ctl tftp netime)
|
||||
$#if-installed(ATTACHE_DHCP $#objs(dhcpcmd))
|
||||
$#if-installed(ENVOY $#objs(snmpvars mib))
|
||||
$#if-installed(ATTACHE_IPSEC $#objs(ips_glue))
|
||||
$#if-installed(SNARK_OVER_PSOS $#objs(root drv_conf etc_ini)))
|
||||
|
||||
$#if-installed(ENVOY
|
||||
$#equate(SNMP_LIBS
|
||||
$#filepath($(SRCDIR) target src wrn wm snmp engine $#libs(snmp)))
|
||||
$#equate(SNMP_LIBS))
|
||||
|
||||
$#equate(PSOS_LIBS
|
||||
$#if-installed(ATTACHE_OVER_PSOS
|
||||
$#filepath($(SRCDIR) target src wrn wm attache psos $#libs(attpsos)))
|
||||
$#if-installed(ATTACHE_PSOS_PNET
|
||||
$#filepath($(PSS_ROOT) sys libc $#libs(pnet))))
|
||||
|
||||
$#equate(ATTACHE_LIBS
|
||||
$#filepath($(SRCDIR) target src wrn wm attache net $#libs(net))
|
||||
$#if-installed(ATTACHE_SOCKETS
|
||||
$#filepath($(SRCDIR) target src wrn wm attache sockets $#libs(sockets)))
|
||||
$#if-installed(ATTACHE_PPP
|
||||
$#filepath($(SRCDIR) target src wrn wm attache ppp $#libs(ppp)))
|
||||
$#filepath($(SRCDIR) target src wrn wm attache net $#libs(net))
|
||||
$#if-installed(SNARK_OVER_PSOS $#(PSOS_LIBS))
|
||||
$#filepath($(SRCDIR) target src wrn wm attache net $#libs(net)))
|
||||
|
||||
$#if-installed(ATTACHE_TELNET
|
||||
$#equate(TN_LIBS
|
||||
$#filepath($(SRCDIR) target src wrn wm attache telnet $#libs(tn)))
|
||||
$#equate(TN_LIBS))
|
||||
|
||||
$#equate(SNARK_LIBS
|
||||
$#filepath($(SRCDIR) target src wrn wm demo lib $#libs(snark)))
|
||||
|
||||
$#equate(COMMON_LIBS
|
||||
$#if-installed(COMMON_DES
|
||||
$#filepath($(SRCDIR) target src wrn wm common lib $#libs(epdes)))
|
||||
$#if-installed(COMMON_DES_FAKE
|
||||
$#filepath($(SRCDIR) target src wrn wm common lib $#libs(epdes)))
|
||||
$#filepath($(SRCDIR) target src wrn wm common lib $#libs(epcommon)))
|
||||
|
||||
$#equate(LIBS $#(SNARK_LIBS) $#(TN_LIBS) $#(ATTACHE_LIBS)
|
||||
$#(SNMP_LIBS) $#(SNARK_LIBS) $#(COMMON_LIBS))
|
||||
|
||||
all: $#exes(router) $#dummy()
|
||||
|
||||
$#makeexe(router $#progn($#(OBJS)) $#progn($#(LIBS)) makefile)
|
||||
|
||||
$#makemib(mib.c $#nil() $(SNMPTALK_MIB_V3_EXCLUDES) $(SNARK_TEST_MIBS) $(SNARK_TEST_CTLS) $#nil())
|
||||
|
||||
$#makelib(snarkmn $#(OBJS) makefile)
|
||||
|
||||
sans-mibcompiler: mib.c
|
||||
|
||||
cleanobj: $#dummy()
|
||||
-$(RM) $#objs(*)
|
||||
|
||||
clean: $#dummy()
|
||||
-$(RM) mib.c
|
||||
-$(RM) $#objs(*)
|
||||
-$(RM) $#exes(router)
|
||||
-$(RM) etc_ini.c
|
||||
$#clean()
|
||||
|
||||
sizes: $#dummy()
|
||||
$#makesize(router $(OBJS))
|
||||
|
||||
$#makeetcini(etc_ini.c $(ETC_INI_FILES))
|
||||
@@ -0,0 +1,259 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/router/netime.c,v 1.2 2001/11/09 21:06:51 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1994-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: netime.c,v $
|
||||
* Revision 1.2 2001/11/09 21:06:51 josh
|
||||
* demo router path modification
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:49:09 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.5 2001/01/19 22:24:38 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.4 2000/03/17 00:14:19 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.3 1999/04/15 21:43:40 wes
|
||||
* Fix SNARK_ATTACHE_34_DNS_COMPAT to continue working..
|
||||
*
|
||||
* Revision 2.2 1999/04/09 20:48:46 wes
|
||||
* let it build without ATTACHE_DNS or ATTACHE_TCP
|
||||
*
|
||||
* Revision 2.1 1998/04/09 22:00:25 wes
|
||||
* Start splitting main.c into app-specific files; add netime client
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
|
||||
#include "cmds.h"
|
||||
|
||||
#if INSTALL_ATTACHE_NETIME_CLIENT
|
||||
#include <wrn/wm/attache/netime.h>
|
||||
#endif
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
#include <wrn/wm/demo/read_ini.h>
|
||||
|
||||
|
||||
#if INSTALL_ATTACHE_NETIME_CLIENT && INSTALL_ATTACHE_DNS
|
||||
|
||||
struct netime_state
|
||||
{
|
||||
struct sty *sty;
|
||||
ipaddr_t *addresses; /* array of addresses to fill in */
|
||||
int naddr; /* max addresses we have room for.. */
|
||||
int vaddr; /* number of valid addresses so far.. */
|
||||
int nnames; /* number of names left to resolve */
|
||||
char **names; /* pointer to tail of argv */
|
||||
netime_query_t *query; /* the netime query.. */
|
||||
};
|
||||
|
||||
static void netime_dns_won(struct dns_query *query,
|
||||
char *dname,
|
||||
int n,
|
||||
ipaddr_t addrs[],
|
||||
void *cookie);
|
||||
|
||||
#if INSTALL_SNARK_ATTACHE_34_DNS_COMPAT
|
||||
|
||||
static void netime_dns_won_compat
|
||||
(struct dns_query *query, char *dname, int n, inaddr_t addrs[], void *cookie)
|
||||
{
|
||||
snark_attache_dns_34_compat(netime_dns_won, query, dname, n, addrs, cookie);
|
||||
}
|
||||
|
||||
#endif /* INSTALL_SNARK_ATTACHE_34_DNS_COMPAT */
|
||||
|
||||
|
||||
/* netime_dns_err()
|
||||
*
|
||||
* DNS callback if it didn't get an IP address
|
||||
*
|
||||
* prints an error and kills the "session" state block
|
||||
*/
|
||||
static void netime_dns_err(struct dns_query *query,
|
||||
enum dns_error error,
|
||||
void *cookie)
|
||||
{
|
||||
struct netime_state * session = cookie;
|
||||
|
||||
display_dns_error(session->sty, query, error);
|
||||
|
||||
/* Give the terminal back. */
|
||||
sty_read(session->sty, do_cmd, prompt, 0);
|
||||
|
||||
GLUE_FREE(session->addresses); /* !!! */
|
||||
GLUE_FREE(session); /* !!! */
|
||||
}
|
||||
|
||||
void do_netime_callback (netime_query_t *query,
|
||||
bits32_t timestamp,
|
||||
void *cookie)
|
||||
{
|
||||
struct netime_state *session = cookie;
|
||||
printf("Got back answer: %x\n", (unsigned)timestamp);
|
||||
|
||||
/* Give the terminal back. */
|
||||
sty_read(session->sty, do_cmd, prompt, 0);
|
||||
|
||||
GLUE_FREE(session->addresses); /* !!! */
|
||||
GLUE_FREE(session); /* !!! */
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* netime_dns_won()
|
||||
*
|
||||
* DNS callback if it got an IP address
|
||||
*
|
||||
* Starts resolution of the next name in the list, or starts the time
|
||||
* query if we run out of names..
|
||||
*/
|
||||
|
||||
static void netime_dns_won(struct dns_query *query,
|
||||
char *dname,
|
||||
int n,
|
||||
ipaddr_t addrs[],
|
||||
void *cookie)
|
||||
{
|
||||
struct netime_state *session = cookie;
|
||||
int v, m;
|
||||
|
||||
v = session->vaddr;
|
||||
m = session->naddr;
|
||||
|
||||
if (v+n > m)
|
||||
{
|
||||
ipaddr_t *taddrs;
|
||||
int nm = m+m;
|
||||
while (v+n > nm)
|
||||
nm = nm+nm;
|
||||
|
||||
/* oops. too many addresses.. */
|
||||
taddrs = GLUE_ALLOC (nm * sizeof (ipaddr_t));
|
||||
if (taddrs == NULL)
|
||||
{
|
||||
abort(); /* !!! */
|
||||
}
|
||||
MEMCPY(taddrs, session->addresses, m*sizeof(ipaddr_t));
|
||||
m = nm;
|
||||
}
|
||||
|
||||
MEMCPY(&session->addresses[v], addrs, n*sizeof(ipaddr_t));
|
||||
v += n;
|
||||
|
||||
session->vaddr = v;
|
||||
session->naddr = m;
|
||||
|
||||
if (session->nnames > 0)
|
||||
{
|
||||
char *name = session->names[0];
|
||||
session->names++;
|
||||
session->nnames--;
|
||||
/* Go to the DNS for the next ip address */
|
||||
DNS_NAME_TO_IPADDR(name, netime_dns_won, netime_dns_err,
|
||||
&domain_config, 0, session);
|
||||
} else {
|
||||
session->query = netime_query (session->addresses, session->vaddr, 1, do_netime_callback, session);
|
||||
if (session->query == NULL)
|
||||
{
|
||||
printf("Bogon!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean_t do_netime(struct sty *sty, int argc, char **argv)
|
||||
{
|
||||
struct netime_state *session;
|
||||
|
||||
session = (struct netime_state *)GLUE_ALLOC(sizeof(*session));
|
||||
if (session == NULL)
|
||||
{
|
||||
sty_puts(sty, "%% Couldn't allocate state block\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
session->addresses = (ipaddr_t *)GLUE_ALLOC(argc * sizeof(ipaddr_t));
|
||||
|
||||
if (session->addresses == NULL)
|
||||
{
|
||||
sty_puts(sty, "%% Couldn't allocate state block\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
session->sty = sty;
|
||||
session->naddr = argc;
|
||||
session->vaddr = 0;
|
||||
session->names = &argv[2];
|
||||
session->nnames = argc-2;
|
||||
|
||||
/* Go to the DNS for the first ip address */
|
||||
DNS_NAME_TO_IPADDR(argv[1], netime_dns_won, netime_dns_err,
|
||||
&domain_config, 0, session);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
boolean_t cmd_netime (struct sty *sty, enum help_level help,
|
||||
int argc, char **argv)
|
||||
{
|
||||
switch (help) {
|
||||
case help_none:
|
||||
if (argc < 2) {
|
||||
sty_puts(sty, "insufficient arguments\n");
|
||||
sty_puts(sty, "usage: netime host [host ...]\n");
|
||||
break;
|
||||
}
|
||||
return do_netime(sty, argc, argv);
|
||||
case help_short:
|
||||
sty_puts(sty, "netime netime host [host ...]\n");
|
||||
break;
|
||||
case help_long:
|
||||
sty_puts(sty, "\
|
||||
The \"netime\" command attempts to retrieve the time \
|
||||
via the NETIME protocol.\n \
|
||||
It queries each host in turn until it gets a response\n");
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/***********************************************************************/
|
||||
/* */
|
||||
/* MODULE: root.c */
|
||||
/* DATE: 98/6/23 */
|
||||
/* PURPOSE: Code for sample application 'ROOT' task */
|
||||
/* */
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* */
|
||||
/* Copyright 1991 - 1998 Integrated Systems, Inc. */
|
||||
/* ALL RIGHTS RESERVED */
|
||||
/* */
|
||||
/* Permission is hereby granted to licensees of Integrated Systems, */
|
||||
/* Inc. products to use or abstract this computer program for the */
|
||||
/* sole purpose of implementing a product based on Integrated */
|
||||
/* Systems, Inc. products. No other rights to reproduce, use, */
|
||||
/* or disseminate this computer program, whether in part or in */
|
||||
/* whole, are granted. */
|
||||
/* */
|
||||
/* Integrated Systems, Inc. makes no representation or warranties */
|
||||
/* with respect to the performance of this computer program, and */
|
||||
/* specifically disclaims any responsibility for any damages, */
|
||||
/* special or consequential, connected with the use of this program. */
|
||||
/* */
|
||||
/***********************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: root.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:50 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/09 21:06:51 josh
|
||||
* demo router path modification
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:49:09 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 1.12 2001/01/19 22:24:38 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 1.11 2000/03/17 00:14:19 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 1.10 1999/04/15 21:40:36 wes
|
||||
* Use symbolic values for flag bits
|
||||
*
|
||||
* Revision 1.9 1999/04/15 17:46:01 wes
|
||||
* things seem to be happier when NIDD has higher priority..
|
||||
*
|
||||
* Revision 1.8 1999/04/09 20:48:48 wes
|
||||
* let it build without ATTACHE_DNS or ATTACHE_TCP
|
||||
*
|
||||
* Revision 1.7 1998/12/12 18:53:40 sra
|
||||
* Changes to pSOS port of Attache: support non-Ethernet NI drivers,
|
||||
* simplify packet buffer implementation, general cleanup.
|
||||
*
|
||||
* Revision 1.6 1998/09/18 18:52:47 meister
|
||||
* consolidation based on Qing code review
|
||||
*
|
||||
* Revision 1.5 1998/09/17 23:05:10 meister
|
||||
* Per Qing: MUXD task can be eliminated
|
||||
*
|
||||
* Revision 1.4 1998/08/19 19:52:58 meister
|
||||
* renamed CLIENT_<xxx> flags to SNARK_CLIENT_<xxx>
|
||||
*
|
||||
* Revision 1.3 1998/08/05 18:53:29 meister
|
||||
* attache_task () --> snark_task (), moved to this file
|
||||
*
|
||||
* Revision 1.2 1998/08/03 21:35:47 meister
|
||||
* added old revision histories comment
|
||||
*
|
||||
* Revision 1.1 1998/08/03 21:33:59 meister
|
||||
* added root.c and drv_conf.c to snark/router
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/router/root.c,v 1.3 2003/01/15 14:04:50 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Old revision history from snark/psos/router
|
||||
*
|
||||
* Revision 1.8 1998/07/27 20:27:41 meister
|
||||
* Create NIDD and AKBD tasks using routines now provided in libattpsos.a
|
||||
*
|
||||
* Revision 1.7 1998/07/20 21:24:26 sra
|
||||
* Cleanup.
|
||||
*
|
||||
* Revision 1.6 1998/07/17 21:50:05 meister
|
||||
* get rid of vestigial KBDQUEUE #ifdef
|
||||
*
|
||||
* Revision 1.5 1998/07/15 17:47:18 meister
|
||||
* Code shuffling to allow nidrive.c to be moved into snark/lib,
|
||||
* and remove dependencies on sys_conf.h from Snark portions of this
|
||||
* application.
|
||||
*
|
||||
* Revision 1.4 1998/07/10 21:58:30 meister
|
||||
* added populate_attache_ni_table() call
|
||||
*
|
||||
* Revision 1.3 1998/06/24 18:46:50 meister
|
||||
* More cosmetics
|
||||
*
|
||||
* Revision 1.2 1998/06/24 17:38:54 meister
|
||||
* Legal boilerplate.
|
||||
*
|
||||
* Revision 1.1 1998/06/04 21:31:51 meister
|
||||
* moved these files to their proper place.
|
||||
* This is the pSOS "router" application
|
||||
*
|
||||
* Revision 1.7 1998/06/03 21:40:38 meister
|
||||
* modified for use with ni-to-ni mux.
|
||||
*
|
||||
* Revision 1.6 1998/05/13 21:13:29 meister
|
||||
* memory based Snark initialization for pHILEless intalls.
|
||||
* Conditionalize ramdisk and saci initialization based on whether ths pSOS
|
||||
* anchor indicates that we have pHILE installed.
|
||||
*
|
||||
* Revision 1.5 1998/05/06 23:38:08 meister
|
||||
* some attempts at determining pSOS system config
|
||||
*
|
||||
* Revision 1.4 1998/04/29 23:13:38 meister
|
||||
* Configuration via etc,ini (written into pHILE ramdisk) added.
|
||||
*
|
||||
*/
|
||||
#include <wrn/wm/common/install.h>
|
||||
#include <sys_conf.h>
|
||||
#include <psos.h>
|
||||
#include <configs.h>
|
||||
#include <drv_intf.h>
|
||||
#include <probe.h>
|
||||
#include <prepc.h>
|
||||
#include <phile.h>
|
||||
#include <wrn/wm/demo/read_ini.h>
|
||||
#include <wrn/wm/demo/psosinit.h>
|
||||
#include <gsblk.h>
|
||||
#include <attache/psos/h/nidrv.h>
|
||||
|
||||
#define SNARK_CLIENT_PRIO 190 /* Priority of the client task */
|
||||
#define SNARK_CLIENT_USRSTACK 1024 /* User stack size of client task */
|
||||
#define SNARK_CLIENT_SYSSTACK 4096 /* Supervisor stack size */
|
||||
#define SNARK_CLIENT_FLAGS 0x00 /* Flags for client task */
|
||||
#define SNARK_CLIENT_INITMODE T_SUPV /* Initial mode of the client task */
|
||||
|
||||
#define NIDD_TASK_PRIORITY 191
|
||||
|
||||
#if 0
|
||||
static void error(char *str);
|
||||
#endif
|
||||
unsigned long AttTid;
|
||||
unsigned long AttKbdTid;
|
||||
|
||||
extern NODE_CT *anchor;
|
||||
|
||||
/***********************************************************************/
|
||||
/* root: Code for the ROOT task */
|
||||
/* */
|
||||
/* NOTE: This executes as the 'ROOT' task. It suspends itself */
|
||||
/* when finished. */
|
||||
/* */
|
||||
/***********************************************************************/
|
||||
|
||||
extern void psos_main (int, char **);
|
||||
|
||||
void snark_task ()
|
||||
{
|
||||
char * main_argv[] = { "psos_main", (char *) 0 };
|
||||
|
||||
term_setup ();
|
||||
psos_main (1, main_argv);
|
||||
}
|
||||
|
||||
void root(void)
|
||||
{
|
||||
ULONG i;
|
||||
|
||||
printf ("System contains: ");
|
||||
if (anchor->pnact)
|
||||
printf ("pNA ");
|
||||
if (anchor->psosct)
|
||||
printf ("pSOS ");
|
||||
if (anchor->probect)
|
||||
printf ("pROBE ");
|
||||
if (anchor->philect)
|
||||
printf ("pHILE ");
|
||||
if (anchor->psect)
|
||||
printf ("pSE ");
|
||||
if (anchor->pmct)
|
||||
printf ("pMONT ");
|
||||
if (anchor->prepct)
|
||||
printf ("pREPC ");
|
||||
printf ("\n");
|
||||
|
||||
CreateNiDrvTask (NIDD_TASK_PRIORITY);
|
||||
|
||||
if (t_create("ATTD", SNARK_CLIENT_PRIO, SNARK_CLIENT_SYSSTACK,
|
||||
SNARK_CLIENT_USRSTACK, SNARK_CLIENT_FLAGS, &AttTid) != 0)
|
||||
{
|
||||
printf("Task creation error (ATTD). Suspending root task.\n");
|
||||
t_suspend (0L);
|
||||
}
|
||||
|
||||
CreateKbdTask (100, GetAttacheQueueId (), AttTid);
|
||||
|
||||
StartNiDrvTask ();
|
||||
|
||||
if (t_start(AttTid, SNARK_CLIENT_INITMODE, snark_task, &i) != 0)
|
||||
{
|
||||
printf ("Task start error");
|
||||
}
|
||||
|
||||
StartKbdTask ();
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* That's the end of the 'ROOT' task, and the end of this application. */
|
||||
/* Now suspend the 'ROOT' task. */
|
||||
/*---------------------------------------------------------------------*/
|
||||
|
||||
printf("suspending root task\n");
|
||||
t_suspend(0L);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/***********************************************************************/
|
||||
/* error: Error handling routine */
|
||||
/* */
|
||||
/* INPUT: pointer to character string. */
|
||||
/***********************************************************************/
|
||||
static void error(char *str)
|
||||
{
|
||||
printf("%s %x\n", str, errno);
|
||||
t_suspend(0L);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,250 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/router/snmpvars.c,v 1.3 2003/01/15 14:04:50 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1994-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: snmpvars.c,v $
|
||||
* Revision 1.3 2003/01/15 14:04:50 josh
|
||||
* directory structure shifting
|
||||
*
|
||||
* Revision 1.2 2001/11/09 21:06:51 josh
|
||||
* demo router path modification
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:49:10 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.14 2001/01/19 22:24:38 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.13 2000/03/17 00:14:19 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.12 1998/10/28 18:51:12 josh
|
||||
* marging in courier-sep98 branch
|
||||
*
|
||||
* Revision 2.11 1998/09/18 19:55:13 meister
|
||||
* timer call renaming; tm_ --> etc_tm_
|
||||
*
|
||||
* Revision 2.10.6.1 1998/09/12 19:27:36 sra
|
||||
* Minor kludges to make this development snapshot of snark compile with
|
||||
* the released versions of the Attache, Envoy, and Emissary products.
|
||||
* These changes will need to be un-done when this branch is merged back
|
||||
* into the main code base.
|
||||
*
|
||||
* Revision 2.10 1998/06/08 19:53:49 sar
|
||||
* Moved the validate and proxy code to the snark library this also
|
||||
* required adding the snark/lib into the library path for a second time
|
||||
* after the envoy libraries
|
||||
*
|
||||
* Revision 2.9 1998/02/25 15:21:52 sra
|
||||
* Finish moving types.h, bug.h, and bugdef.h to common/h/.
|
||||
*
|
||||
* Revision 2.8 1998/02/25 04:57:47 sra
|
||||
* Update copyrights.
|
||||
*
|
||||
* Revision 2.7 1997/11/13 18:50:57 josh
|
||||
* adding Liaison call to rmon_new_snmp_command() to the
|
||||
* validate_community() function for now
|
||||
*
|
||||
* Revision 2.6 1997/03/20 06:53:27 sra
|
||||
* DFARS-safe copyright text. Zap!
|
||||
*
|
||||
* Revision 2.5 1997/02/25 10:58:16 sra
|
||||
* Update copyright notice, dust under the bed.
|
||||
*
|
||||
* Revision 2.4 1996/10/30 16:25:57 sra
|
||||
* Fix pktcom_xxx warnings again, in yet another copy of this file.
|
||||
* Sigh.
|
||||
*
|
||||
* Revision 2.3 1996/10/16 20:20:31 sar
|
||||
* Declare all response pdus as valid.
|
||||
*
|
||||
* Revision 2.2 1996/10/16 16:40:35 sar
|
||||
* Added proxy and timer code.
|
||||
*
|
||||
* Revision 2.1 1996/03/22 10:05:39 sra
|
||||
* Update copyrights prior to Attache 3.2 release.
|
||||
*
|
||||
* Revision 2.0 1995/05/10 22:38:15 sra
|
||||
* Attache release 3.0.
|
||||
*
|
||||
* Revision 1.3 1995/01/06 00:52:48 sra
|
||||
* Update copyright notice for 2.1 release.
|
||||
*
|
||||
* Revision 1.2 1994/12/20 22:41:54 dab
|
||||
* Changed sysObjectId to identify the router.
|
||||
*
|
||||
* Revision 1.1 1994/11/23 18:31:00 dab
|
||||
* Initial revision
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* SNMP variables and routines for snark.
|
||||
*/
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/common/types.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
#include <wrn/wm/attache/arp.h>
|
||||
#include <wrn/wm/attache/udp.h>
|
||||
|
||||
#if INSTALL_ATTACHE_DNS
|
||||
#include <wrn/wm/attache/dns.h>
|
||||
extern struct dns_config domain_config;
|
||||
#endif
|
||||
|
||||
#include <wrn/wm/snmp/engine/asn1conf.h>
|
||||
#include <wrn/wm/snmp/engine/asn1.h>
|
||||
#include <wrn/wm/snmp/engine/buffer.h>
|
||||
#include <wrn/wm/snmp/engine/mib.h>
|
||||
#include <wrn/wm/snmp/engine/localio.h>
|
||||
#include <wrn/wm/snmp/engine/snmpdefs.h>
|
||||
#include <wrn/wm/snmp/engine/snmp.h>
|
||||
#include <wrn/wm/snmp/engine/snmpstat.h>
|
||||
#include <wrn/wm/snmp/engine/proxy_tr.h>
|
||||
|
||||
#include <wrn/wm/attache/snmpvars.h>
|
||||
|
||||
#include <wrn/wm/demo/snmpfunc.h>
|
||||
|
||||
#if (ENVOY_NEED_STATS)
|
||||
SNMP_STATS_T snmp_stats;
|
||||
#endif
|
||||
|
||||
OIDC_T snmp_product_id[] = {
|
||||
1, /* ( 0) iso */
|
||||
3, /* ( 1) org */
|
||||
6, /* ( 2) dod */
|
||||
1, /* ( 3) internet */
|
||||
4, /* ( 4) private */
|
||||
1, /* ( 5) enterprises */
|
||||
12, /* ( 6) Epilogue Technology */
|
||||
7, /* ( 7) products */
|
||||
6, /* ( 8) router package (may be changed at runtime) */
|
||||
1, /* ( 9) major version (may be changed at runtime) */
|
||||
0, /* (10) minor version (may be changed at runtime) */
|
||||
};
|
||||
|
||||
void set_snmp_product_id(OIDC_T product, OIDC_T major, OIDC_T minor)
|
||||
{
|
||||
snmp_product_id[ 8] = product;
|
||||
snmp_product_id[ 9] = major;
|
||||
snmp_product_id[10] = minor;
|
||||
}
|
||||
|
||||
OBJ_ID_T var_sysObjectID = {
|
||||
sizeof(snmp_product_id)/sizeof(*snmp_product_id),
|
||||
snmp_product_id
|
||||
};
|
||||
|
||||
|
||||
|
||||
char snmp_auth_traps = 1;
|
||||
long var_sysServices = 4;
|
||||
|
||||
#define DEFVAR(name, maxlen, value) \
|
||||
static char name##_data[maxlen] = value; \
|
||||
struct string_wlen name = { maxlen, sizeof(value) - 1, name##_data };
|
||||
|
||||
DEFVAR(var_sysDescr, MAX_SYSDESCR, "Epilogue Technology demo Router");
|
||||
DEFVAR(var_sysContact, MAX_SYSCONTACT, "sysContact not set");
|
||||
DEFVAR(var_sysLocation, MAX_SYSLOCATION, "sysLocation not set");
|
||||
DEFVAR(var_sysName, MAX_SYSNAME, "sysName not set");
|
||||
|
||||
#undef DEFVAR
|
||||
|
||||
#if 0
|
||||
void snmpvars_init()
|
||||
{
|
||||
MEMSET(&snmp_stats, 0, sizeof(snmp_stats));
|
||||
/* Might do run-time config of system crufties here. */
|
||||
}
|
||||
#endif
|
||||
|
||||
struct timer main_envoy_tm;
|
||||
int first = 1;
|
||||
|
||||
void
|
||||
envoy_glue_handler(struct timer *tm,
|
||||
void *cookiep)
|
||||
{
|
||||
(*((void (*) (void)) cookiep))();
|
||||
}
|
||||
|
||||
void
|
||||
envoy_call_timer(bits32_t when,
|
||||
void (*what)(void))
|
||||
{
|
||||
if (first) {
|
||||
etc_tm_init(&main_envoy_tm);
|
||||
first = 0;
|
||||
}
|
||||
main_envoy_tm.handler = envoy_glue_handler;
|
||||
main_envoy_tm.cookie =(void *)what;
|
||||
etc_tm_set(&main_envoy_tm, when);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* Glue routine to connect up to the attache now routine elsewhere in
|
||||
snark/lib. We use this mechanism instead of envoy.h so we can compile
|
||||
most of the code without knowing what we are running on the top of */
|
||||
bits32_t
|
||||
envoy_now(void)
|
||||
{
|
||||
return(glue_now());
|
||||
}
|
||||
|
||||
#if (INSTALL_ENVOY_SNMP_PROXY)
|
||||
/****************************************************************************
|
||||
NAME: proxy_send_rtn
|
||||
|
||||
PURPOSE: glue routine to connect up to the real send rtn in snark/lib
|
||||
|
||||
PARAMETERS:
|
||||
EBUFFER_T * The buffer to send
|
||||
ptr_t Information as to where to send the buffer.
|
||||
|
||||
RETURNS: sbits32_t A reasonable timeout period for this transport
|
||||
|
||||
****************************************************************************/
|
||||
|
||||
sbits32_t
|
||||
proxy_send_rtn(EBUFFER_T *ebuf,
|
||||
ptr_t cookie)
|
||||
{
|
||||
return(attache_proxy_send_rtn(ebuf, cookie));
|
||||
}
|
||||
#endif /* #if (INSTALL_ENVOY_SNMP_PROXY) */
|
||||
|
||||
@@ -0,0 +1,651 @@
|
||||
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/router/tftp.c,v 1.2 2001/11/09 21:06:51 josh Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 1999-2005 Wind River Systems, Inc.
|
||||
* All rights reserved. Provided under license only.
|
||||
* Distribution or other use of this software is only
|
||||
* permitted pursuant to the terms of a license agreement
|
||||
* from Wind River Systems (and is otherwise prohibited).
|
||||
* Refer to that license agreement for terms of use.
|
||||
*/
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Copyright 1994-1997 Epilogue Technology Corporation.
|
||||
* Copyright 1998 Integrated Systems, Inc.
|
||||
* All rights reserved.
|
||||
****************************************************************************/
|
||||
|
||||
/*
|
||||
* $Log: tftp.c,v $
|
||||
* Revision 1.2 2001/11/09 21:06:51 josh
|
||||
* demo router path modification
|
||||
*
|
||||
* Revision 1.1.1.1 2001/11/05 17:49:10 tneale
|
||||
* Tornado shuffle
|
||||
*
|
||||
* Revision 2.10 2001/01/19 22:24:39 paul
|
||||
* Update copyright.
|
||||
*
|
||||
* Revision 2.9 2000/03/17 00:14:19 meister
|
||||
* Update copyright message
|
||||
*
|
||||
* Revision 2.8 1999/04/15 21:43:41 wes
|
||||
* Fix SNARK_ATTACHE_34_DNS_COMPAT to continue working..
|
||||
*
|
||||
* Revision 2.7 1998/10/28 18:51:16 josh
|
||||
* marging in courier-sep98 branch
|
||||
*
|
||||
* Revision 2.6 1998/10/16 20:50:40 wes
|
||||
* Clean up namespace of of TFTP error symbols; s/ERR_/TFTP_ERR_/
|
||||
*
|
||||
* Revision 2.5 1998/09/25 16:56:57 wes
|
||||
* Include udp.h so previous change will work..
|
||||
*
|
||||
* Revision 2.4 1998/09/25 16:55:54 wes
|
||||
* Consistently use udp_free instead of pkt_free
|
||||
*
|
||||
* Revision 2.3 1998/09/18 19:55:14 meister
|
||||
* timer call renaming; tm_ --> etc_tm_
|
||||
*
|
||||
* Revision 2.2.8.1 1998/09/12 19:27:36 sra
|
||||
* Minor kludges to make this development snapshot of snark compile with
|
||||
* the released versions of the Attache, Envoy, and Emissary products.
|
||||
* These changes will need to be un-done when this branch is merged back
|
||||
* into the main code base.
|
||||
*
|
||||
* Revision 2.2 1998/04/13 21:32:48 wes
|
||||
* Actually implement 'tftp mode oldapi' ...
|
||||
*
|
||||
* Revision 2.1 1998/04/09 22:00:25 wes
|
||||
* Start splitting main.c into app-specific files; add netime client
|
||||
*
|
||||
*/
|
||||
|
||||
/* [clearcase]
|
||||
modification history
|
||||
-------------------
|
||||
01a,19apr05,job update copyright notices
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <wrn/wm/attache/config.h>
|
||||
#include <wrn/wm/attache/mib.h>
|
||||
#include <wrn/wm/attache/timer.h>
|
||||
#include <wrn/wm/attache/packet.h>
|
||||
#include <wrn/wm/attache/net.h>
|
||||
#include <wrn/wm/attache/route.h>
|
||||
#include <wrn/wm/attache/ip.h>
|
||||
#include <wrn/wm/attache/udp.h>
|
||||
#include <wrn/wm/attache/glue.h>
|
||||
|
||||
#include "cmds.h"
|
||||
|
||||
#if INSTALL_ATTACHE_TFTP
|
||||
#include <wrn/wm/attache/tftpc.h>
|
||||
#endif
|
||||
|
||||
#if INSTALL_ATTACHE_DNS
|
||||
#include <wrn/wm/attache/dns.h>
|
||||
#endif
|
||||
|
||||
#include <wrn/wm/demo/snarklib.h>
|
||||
#include <wrn/wm/demo/read_ini.h>
|
||||
|
||||
#if INSTALL_ATTACHE_DNS && INSTALL_ATTACHE_TFTP
|
||||
|
||||
/* structure to hold error strings for tftp_error_print() */
|
||||
struct tftp_err_lookup { int err_code; char * err_string; };
|
||||
|
||||
/* error strings for TFTP */
|
||||
struct tftp_err_lookup tftp_err_strings[] =
|
||||
{
|
||||
{ TFTP_ERR_NOFILE, "TFTP error: File not found."},
|
||||
{ TFTP_ERR_ACCESS, "TFTP error: Access violation."},
|
||||
{ TFTP_ERR_DISKFULL, "TFTP error: Disk full or allocation exceeded."},
|
||||
{ TFTP_ERR_ILLEGALOP, "TFTP error: Illegal TFTP operation."},
|
||||
{ TFTP_ERR_BADTID, "TFTP error: Unknown transfer ID."},
|
||||
{ TFTP_ERR_EXISTS, "TFTP error: File already exists."},
|
||||
{ TFTP_ERR_NOUSER, "TFTP error: No such user."},
|
||||
{ TFTP_ERR_RESOURCES, "TFTP error: Resources not available."},
|
||||
{ TFTP_ERR_USEMSG, "TFTP error: Aborted by client request."},
|
||||
{ TFTP_ERR_TIMEOUT, "TFTP error: Timed out."}
|
||||
};
|
||||
#define TFTP_ERR_STRINGS (sizeof(tftp_err_strings)/sizeof(*tftp_err_strings))
|
||||
|
||||
|
||||
/* structure to keep track of current tftp "connections" */
|
||||
struct tftp_state
|
||||
{
|
||||
ipaddr_t host;
|
||||
char * file_name_ptr;
|
||||
int direction;
|
||||
FILE * fp;
|
||||
struct sty *sty;
|
||||
struct tftp_state * next;
|
||||
|
||||
tftp_cnxn_t *cnxn;
|
||||
packet *delay_pkt;
|
||||
struct timer delack_tm;
|
||||
int delay_block;
|
||||
int defer_exit;
|
||||
};
|
||||
static struct tftp_state * tftp_state_head = 0;
|
||||
|
||||
|
||||
static int tftp_start_xfer (int argc, char ** argv, struct sty * sty);
|
||||
static void tftp_dns_err(struct dns_query *query,
|
||||
enum dns_error error,
|
||||
void *cookie);
|
||||
static void tftp_dns_won(struct dns_query *query,
|
||||
char *dname, int n,
|
||||
ipaddr_t addrs[], void *cookie);
|
||||
static boolean_t tftp_error_print (struct sty * sty,
|
||||
struct tftp_err_lookup table[],
|
||||
int table_size, int err_val);
|
||||
static int tftp_read_handler (tftp_rval_t code, packet *pkt, void *cookie,
|
||||
tftp_error_t errnum, tftp_cnxn_t * tftp_cnxn);
|
||||
static void tftp_read_delack_handler(struct timer *tm, void *cookie);
|
||||
#if INSTALL_ATTACHE_TFTP_SENDFILE
|
||||
static int tftp_write_handler (tftp_rval_t code, packet *pkt, void *cookie,
|
||||
tftp_error_t errnum, tftp_cnxn_t * tftp_cnxn);
|
||||
#endif
|
||||
static int tftp_parse_parm(char * cmd, char * cmd_list[], int num_choices);
|
||||
static boolean_t tftp_exit(struct tftp_state * );
|
||||
|
||||
/* string for TFTP second-level commands */
|
||||
static char * tftp_cmds[] = { "get", "send", "mode" };
|
||||
#define TFTP_CMDS (sizeof(tftp_cmds)/sizeof(*tftp_cmds))
|
||||
|
||||
/* string for TFTP mode third-level commands */
|
||||
static char * tftp_modes[] = { "delack", "nodelack", "oldapi", "newapi"};
|
||||
#define TFTP_MODES (sizeof(tftp_modes)/sizeof(*tftp_modes))
|
||||
|
||||
int newapi = 1;
|
||||
int delack = 0;
|
||||
|
||||
/* cmd_tftp()
|
||||
*
|
||||
* function that gets called when a "tftp" command is typed at the command line
|
||||
*/
|
||||
|
||||
boolean_t cmd_tftp (struct sty *sty, enum help_level help,
|
||||
int argc, char **argv)
|
||||
{
|
||||
switch (help) {
|
||||
case help_none:
|
||||
if (tftp_start_xfer(argc,argv,sty) == 1)
|
||||
return 0;
|
||||
break;
|
||||
case help_short:
|
||||
sty_puts(sty, "tftp tftp get/send host filename\n");
|
||||
break;
|
||||
case help_long:
|
||||
sty_puts(sty, "\
|
||||
The \"tftp\" command attempts to send or retrieve a file \
|
||||
via the TFTP protocol.\n \
|
||||
The filename is the full path of the remote file; \n \
|
||||
the local file will always be assumed to be in the current directory.\n");
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#if INSTALL_SNARK_ATTACHE_34_DNS_COMPAT
|
||||
|
||||
static void tftp_dns_won_compat
|
||||
(struct dns_query *query, char *dname, int n, inaddr_t addrs[], void *cookie)
|
||||
{
|
||||
snark_attache_dns_34_compat(tftp_dns_won, query, dname, n, addrs, cookie);
|
||||
}
|
||||
|
||||
#endif /* INSTALL_SNARK_ATTACHE_34_DNS_COMPAT */
|
||||
|
||||
|
||||
|
||||
/* tftp_start_xfer()
|
||||
*
|
||||
* Begin a TFTP operation: passed a set of parameters where:
|
||||
* it is known there are exactly four,
|
||||
* the first is known to be "tftp",
|
||||
* the second presumably "get" or "send",
|
||||
* the third a host to get the file from,
|
||||
* and the fourth is a filename to get.
|
||||
*
|
||||
* Returns 0 on error, 1 otherwise.
|
||||
*/
|
||||
static int tftp_start_xfer(int argc, char ** argv, struct sty * sty)
|
||||
{
|
||||
int mode;
|
||||
struct tftp_state * session;
|
||||
|
||||
/* get a session block */
|
||||
if ((session = (struct tftp_state *) GLUE_ALLOC(sizeof(*session))) == 0) {
|
||||
sty_puts(sty, "%% Couldn't allocate state block\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
session->direction = tftp_parse_parm(argv[1], tftp_cmds, TFTP_CMDS);
|
||||
switch (session->direction)
|
||||
{
|
||||
case 1: /* get */
|
||||
if (argc < 4) {
|
||||
sty_puts(sty, "insufficient arguments\n");
|
||||
sty_puts(sty, "usage: tftp get/send host filename\n");
|
||||
GLUE_FREE(session);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case 2: /* send */
|
||||
#if INSTALL_ATTACHE_TFTP_SENDFILE
|
||||
if (argc < 4) {
|
||||
sty_puts(sty, "insufficient arguments\n");
|
||||
sty_puts(sty, "usage: tftp get/send host filename\n");
|
||||
GLUE_FREE(session);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
#else
|
||||
sty_puts(sty, "tftp send not installed\n");
|
||||
GLUE_FREE(session);
|
||||
return 0;
|
||||
#endif
|
||||
case 3:
|
||||
mode = tftp_parse_parm(argv[2], tftp_modes, TFTP_MODES);
|
||||
switch(mode)
|
||||
{
|
||||
case 1:
|
||||
delack = 1;
|
||||
break;
|
||||
case 2:
|
||||
delack = 0;
|
||||
break;
|
||||
case 3:
|
||||
#if INSTALL_SNARK_ATTACHE_34_TFTP_COMPAT
|
||||
newapi = 0;
|
||||
#else
|
||||
sty_puts(sty, "tftp old api support not included\n");
|
||||
#endif
|
||||
break;
|
||||
case 4:
|
||||
newapi = 1;
|
||||
break;
|
||||
default:
|
||||
sty_puts(sty, "tftp mode delack/nodelack/oldapi/newapi\n");
|
||||
}
|
||||
GLUE_FREE(session);
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
sty_puts(sty, "tftp tftp get/send host filename\n");
|
||||
GLUE_FREE(session);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get some memory to stash the filename */
|
||||
if ((session->file_name_ptr = GLUE_ALLOC(strlen(argv[3]) + 1)) == 0) {
|
||||
sty_puts(sty, "%% Couldn't allocate scratch space for filename\n");
|
||||
GLUE_FREE(session);
|
||||
return 0;
|
||||
}
|
||||
strcpy(session->file_name_ptr, argv[3]);
|
||||
|
||||
/* Fill the state block with whatever we need now. */
|
||||
session->sty = sty;
|
||||
session->fp = NULL; /* and friends, Obie was making sure ... */
|
||||
session->delay_pkt = NULL;
|
||||
session->delay_block = 0;
|
||||
session->defer_exit = 0;
|
||||
etc_tm_init(&session->delack_tm);
|
||||
session->delack_tm.handler = tftp_read_delack_handler;
|
||||
session->delack_tm.cookie = session;
|
||||
|
||||
/* Go to the DNS for the IP address of our target */
|
||||
DNS_NAME_TO_IPADDR(argv[2], tftp_dns_won, tftp_dns_err,
|
||||
&domain_config, 0, session);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* tftp_dns_err()
|
||||
*
|
||||
* DNS callback if it didn't get an IP address
|
||||
*
|
||||
* prints an error and kills the "session" state block
|
||||
*/
|
||||
static void tftp_dns_err(struct dns_query *query,
|
||||
enum dns_error error,
|
||||
void *cookie)
|
||||
{
|
||||
struct tftp_state * session = cookie;
|
||||
|
||||
display_dns_error(session->sty, query, error);
|
||||
|
||||
/* Give the terminal back. */
|
||||
sty_read(session->sty, do_cmd, prompt, 0);
|
||||
|
||||
tftp_exit(session);
|
||||
}
|
||||
|
||||
/* tftp_dns_won()
|
||||
*
|
||||
* DNS callback if it got an IP address
|
||||
*
|
||||
* goes ahead and starts up the TFTP transfer
|
||||
*/
|
||||
static void tftp_dns_won(struct dns_query *query,
|
||||
char *dname,
|
||||
int n,
|
||||
ipaddr_t addrs[],
|
||||
void *cookie)
|
||||
{
|
||||
struct tftp_state * session = (struct tftp_state *) cookie;
|
||||
char * filename_bare;
|
||||
char * filename_index;
|
||||
char * mode;
|
||||
#if INSTALL_SNARK_ATTACHE_34_TFTP_COMPAT
|
||||
inaddr_t oldaddr;
|
||||
#endif
|
||||
|
||||
|
||||
/* stick the IP address into our state block */
|
||||
IPADDR_COPY(&session->host, &addrs[0]);
|
||||
|
||||
/* strip down the filename so we open it in the current directory */
|
||||
for (filename_bare = filename_index = session->file_name_ptr;
|
||||
*filename_index;
|
||||
filename_index++) {
|
||||
if (*filename_index == '/')
|
||||
filename_bare = filename_index+1;
|
||||
#if INSTALL_on_msdos
|
||||
else if (*filename_index == '\\')
|
||||
filename_bare = filename_index+1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* open up the local file */
|
||||
if (session->direction == 1)
|
||||
mode = "wb";
|
||||
else
|
||||
mode = "rb";
|
||||
session->fp = fopen(filename_bare, mode);
|
||||
if (session->fp == 0) {
|
||||
sty_printf(session->sty,
|
||||
"%% Couldn't open %s for writing\n", filename_bare);
|
||||
tftp_exit(session);
|
||||
/* Give the terminal back.
|
||||
* Makes ownership fuzzy, but that's the way to do parallel transfers.
|
||||
*/
|
||||
sty_read(session->sty, do_cmd, prompt, 0);
|
||||
return;
|
||||
}
|
||||
/* We have a valid state block. Link it in. */
|
||||
session->next = tftp_state_head;
|
||||
tftp_state_head = session;
|
||||
|
||||
#if INSTALL_SNARK_ATTACHE_34_TFTP_COMPAT
|
||||
if (!newapi) {
|
||||
if (GET_IPADDR_TYPE(&session->host) != IPV4) {
|
||||
sty_printf(session->sty,
|
||||
"%% Can't do non-IPV4 TFTP through old API; try reconfiguring ..");
|
||||
tftp_exit(session);
|
||||
/* Give the terminal back.
|
||||
* Makes ownership fuzzy, but that's the way to do parallel transfers.
|
||||
*/
|
||||
sty_read(session->sty, do_cmd, prompt, 0);
|
||||
return;
|
||||
}
|
||||
MEMCPY(&oldaddr, PTR_IPADDR_BITS(&session->host), IPV4_ADDR_LEN);
|
||||
if (session->direction == 1)
|
||||
session->cnxn = tftpc_getfile(oldaddr, session->file_name_ptr, MODE_OCTET,
|
||||
tftp_read_handler, (void *) session);
|
||||
#if INSTALL_ATTACHE_TFTP_SENDFILE
|
||||
else
|
||||
session->cnxn = tftpc_sendfile(oldaddr, session->file_name_ptr, MODE_OCTET,
|
||||
tftp_write_handler, (void *) session);
|
||||
#endif /* TFTP_SENDFILE */
|
||||
} else
|
||||
#endif /* TFTP_COMPAT */
|
||||
{
|
||||
if (session->direction == 1)
|
||||
session->cnxn = tftpc_fetchfile(&session->host, session->file_name_ptr, MODE_OCTET,
|
||||
tftp_read_handler, (void *) session);
|
||||
#if INSTALL_ATTACHE_TFTP_SENDFILE
|
||||
else
|
||||
session->cnxn = tftpc_putfile(&session->host, session->file_name_ptr, MODE_OCTET,
|
||||
tftp_write_handler, (void *) session);
|
||||
#endif /* TFTP_SENDFILE */
|
||||
}
|
||||
|
||||
sty_printf(session->sty, "tftp %s of %s %s host %s (%s) started\n",
|
||||
session->direction?"fetch":"store",
|
||||
session->file_name_ptr,
|
||||
session->direction?"from":"to",
|
||||
dname, ipaddr_to_string(&addrs[0], 0, 0));
|
||||
|
||||
/* Give the terminal back.
|
||||
* Makes ownership fuzzy, but that's the way to do parallel transfers.
|
||||
*/
|
||||
sty_read(session->sty, do_cmd, prompt, 0);
|
||||
}
|
||||
|
||||
/* tftp_exit()
|
||||
*
|
||||
* call this to delete the session structure and generally clean
|
||||
* up when you're done with tftp
|
||||
*
|
||||
* returns TRUE if it finds a problem, FALSE otherwise
|
||||
*/
|
||||
static boolean_t tftp_exit(struct tftp_state * session)
|
||||
{
|
||||
struct tftp_state **p = &tftp_state_head;
|
||||
|
||||
while (*p && *p != session)
|
||||
p = &(*p)->next;
|
||||
if (*p == 0)
|
||||
return TRUE;
|
||||
*p = session->next;
|
||||
|
||||
if (session->fp)
|
||||
fclose(session->fp);
|
||||
|
||||
if (session->file_name_ptr) {
|
||||
sty_printf(session->sty, "\nDone with tftp %s of %s\n",
|
||||
((session->direction == 2) ? "send" : "get"),
|
||||
session->file_name_ptr);
|
||||
GLUE_FREE(session->file_name_ptr);
|
||||
}
|
||||
|
||||
GLUE_FREE(session);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* tftp_error_print()
|
||||
*
|
||||
* print out the appropriate error message; give it a table of tftp_err_lookup
|
||||
* structures and the error value to match for, and it will find the
|
||||
* appropriate string from the table and print it out.
|
||||
*/
|
||||
static boolean_t tftp_error_print(struct sty * sty,
|
||||
struct tftp_err_lookup table[],
|
||||
int table_size,
|
||||
int err_val)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i< table_size; i++) {
|
||||
if (table[i].err_code == err_val) {
|
||||
sty_printf(sty, "%s\n", table[i].err_string);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
sty_puts(sty, "unknown error\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void tftp_read_delack_handler(struct timer *tm, void *cookie)
|
||||
{
|
||||
struct tftp_state *xfer = cookie;
|
||||
packet *pkt = xfer->delay_pkt;
|
||||
xfer->delay_pkt = NULL;
|
||||
|
||||
if (fwrite(pkt->pkt_data, 1, pkt->pkt_datalen, xfer->fp)
|
||||
== pkt->pkt_datalen) {
|
||||
udp_free(pkt);
|
||||
}
|
||||
#ifdef TFTP_DEBUG
|
||||
sty_printf(xfer->sty, "delack %d\n", xfer->delay_block);
|
||||
#endif
|
||||
tftpc_sendack(xfer->cnxn, xfer->delay_block);
|
||||
if (xfer->defer_exit)
|
||||
tftp_exit(xfer);
|
||||
}
|
||||
|
||||
/* tftp_read_handler()
|
||||
*
|
||||
* callback function for tftp reads
|
||||
*/
|
||||
static int tftp_read_handler (tftp_rval_t code,
|
||||
packet *pkt,
|
||||
void *cookie,
|
||||
tftp_error_t errnum,
|
||||
tftp_cnxn_t * tftp_cnxn)
|
||||
{
|
||||
struct tftp_state * xfer = (struct tftp_state *) cookie;
|
||||
int retval = TFTP_ERROR;
|
||||
|
||||
switch (code) {
|
||||
case HND_ERROR:
|
||||
tftp_error_print(xfer->sty, tftp_err_strings, TFTP_ERR_STRINGS, errnum);
|
||||
if (pkt && pkt->pkt_data)
|
||||
/* RFC-1350 says the error string is null-terminated. */
|
||||
sty_puts(xfer->sty, (char *) (pkt->pkt_data));
|
||||
break;
|
||||
|
||||
case HND_DONE:
|
||||
if (xfer->delay_pkt)
|
||||
{
|
||||
xfer->defer_exit = 1;
|
||||
return TFTP_GOOD;
|
||||
} else {
|
||||
fclose(xfer->fp);
|
||||
}
|
||||
retval = TFTP_GOOD;
|
||||
break;
|
||||
|
||||
case HND_DATA:
|
||||
if (!delack)
|
||||
{
|
||||
if (fwrite(pkt->pkt_data, 1, pkt->pkt_datalen, xfer->fp)
|
||||
== pkt->pkt_datalen) {
|
||||
udp_free(pkt);
|
||||
return TFTP_GOOD; /* The write was OK. */
|
||||
}
|
||||
} else {
|
||||
if (xfer->delay_pkt)
|
||||
{
|
||||
sty_printf(xfer->sty, "We already have a delayed packet.. oops, blowing up connection\n");
|
||||
return TFTP_ERROR;
|
||||
}
|
||||
xfer->delay_pkt = pkt;
|
||||
xfer->delay_block = tftp_cnxn_get_blocknum(tftp_cnxn);
|
||||
etc_tm_set(&xfer->delack_tm, 100); /* 100ms */
|
||||
return TFTP_WAIT;
|
||||
}
|
||||
|
||||
/* If we got here, there were problems with the write. */
|
||||
sty_puts(xfer->sty, "Problem writing to file.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if (tftp_exit(xfer))
|
||||
retval = TFTP_ERROR;
|
||||
|
||||
/* TFTP module thinks we're responsible for freeing the packet... */
|
||||
if (pkt != 0)
|
||||
udp_free(pkt);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#if INSTALL_ATTACHE_TFTP_SENDFILE
|
||||
|
||||
/* tftp_write_handler()
|
||||
*
|
||||
* callback function for tftp write
|
||||
*/
|
||||
static int tftp_write_handler (tftp_rval_t code,
|
||||
packet *pkt,
|
||||
void *cookie,
|
||||
tftp_error_t errnum,
|
||||
tftp_cnxn_t * tftp_cnxn)
|
||||
{
|
||||
struct tftp_state * xfer = (struct tftp_state *) cookie;
|
||||
int retval = -1;
|
||||
int bytes_read;
|
||||
|
||||
switch (code) {
|
||||
case HND_ERROR:
|
||||
tftp_error_print(xfer->sty, tftp_err_strings, TFTP_ERR_STRINGS, errnum);
|
||||
if (pkt && pkt->pkt_data)
|
||||
/* RFC-1350 says the error string is null-terminated. */
|
||||
sty_puts(xfer->sty, (char *) (pkt->pkt_data));
|
||||
break;
|
||||
|
||||
case HND_DONE:
|
||||
fclose(xfer->fp);
|
||||
retval = 0;
|
||||
break;
|
||||
|
||||
case HND_DATA:
|
||||
bytes_read = fread(pkt->pkt_data, 1, pkt->pkt_datalen, xfer->fp);
|
||||
if ((bytes_read != pkt->pkt_datalen) &&
|
||||
(!feof(xfer->fp)) )
|
||||
return -1;
|
||||
else
|
||||
{
|
||||
pkt->pkt_datalen = bytes_read;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (tftp_exit(xfer))
|
||||
retval = -1;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* tftp_parse_parm()
|
||||
*
|
||||
* Parse a parameter to a command.
|
||||
*
|
||||
* Takes a string containing the parameter entered,
|
||||
* a list of possible parameter values to match it against,
|
||||
* and a count of the number of values in that list.
|
||||
* Returns the 1-based offset of the matched value,
|
||||
* or 0 if not found.
|
||||
*/
|
||||
static int tftp_parse_parm(char * cmd, char * cmd_list[], int num_choices)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (cmd == NULL)
|
||||
return 0;
|
||||
|
||||
for (i=0; i<num_choices; i++)
|
||||
if (STRNICMP(cmd, cmd_list[i], strlen(cmd)) == 0)
|
||||
return (i+1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* INSTALL_ATTACHE_DNS && INSTALL_ATTACHE_TFTP */
|
||||
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user