original files of m241
This commit is contained in:
@@ -0,0 +1,308 @@
|
||||
/* 02comp_ipnet_dhcp.cdf - IPNet DHCP configuration file */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006-2009 Wind River Systems, Inc.
|
||||
*
|
||||
* The right to copy, distribute or otherwise make use of this software
|
||||
* may be licensed only pursuant to the terms of an applicable Wind River
|
||||
* license agreement. No license to Wind River intellectual property rights
|
||||
* is granted herein. All rights not licensed by Wind River are reserved
|
||||
* by Wind River.
|
||||
*/
|
||||
|
||||
/*
|
||||
modification history
|
||||
--------------------
|
||||
01v,02aug10,fei move from osconfig and spilt from 02comp_ipnet_dhcp.cdf
|
||||
01u,05jul10,lzq Added INCLUDE_IPDHCPC6_CMD component
|
||||
01t,04sep09,h_s Modify the DHCPC,DHCPR,DHCPS related callback function to 0 instead of NULL
|
||||
to make gnu compile correct.
|
||||
01s,04jun09,ggz Added DHCPC ip address lease time
|
||||
01r,29may09,spw Add DHCPS_NO_STRICT_SUBNET_MATCH param
|
||||
01q,11feb08,spw Add support for user defined client options
|
||||
01p,10oct08,spw Add max message size, ttl, auto enable interface configs
|
||||
01o,27aug08,spw Add option to remove existing addresses from interface
|
||||
when starting negotiation
|
||||
01n,27aug08,spw Modify option callback param name, add netmask option
|
||||
01m,30may08,spw Add bootp mode and some more options
|
||||
01l,23sep08,rme Misspelled words corrected
|
||||
01k,19sep07,rme Added missing backslash
|
||||
01n,07sep07,rme Replaced SELECTION_IPCOM_FS with SELECT_IPCOM_FS in INCLUDE_IPDHCPC6
|
||||
|
||||
01m,07sep07,rme Replaced SELECTION_IPCOM_FS with SELECT_IPCOM_FS in INCLUDE_IPDHCPS
|
||||
|
||||
01l,10sep07,mze INCLUDE_IPCOM_FS_SELECTION changed to SELECT_IPCOM_FS
|
||||
01k,21aug07,mze fixed mistake in INCLUDE_IPDHCPS MODULES line continued without "\"
|
||||
01j,28aug07,ps Add DHCPc6 authentication parameters
|
||||
01i,07feb07,tkf Add IPDHCPS dependency on SELECT_IPCOM_FS.
|
||||
01h,22jan07,kch Added DHCPC_RFC2131_INIT_DELAY, DHCPC_RFC2131_EXP_BACKOFF,
|
||||
DHCPC_DISCOVER_RETRIES and DHCPC_OFFER_TIMEOUT configuration
|
||||
macros (WIND00086146).
|
||||
01g,03jan07,kch Changed DHCPC_SERVER_PORT default value from 68 to 67.
|
||||
Renamed DHCPC_IFLIST_REQ_OPTS and DHCPC_IFLIST_CLIENT_ID
|
||||
macros to DHCPC_IF_REQ_OPTS_LIST and DHCPC_IF_CLIENT_ID_LIST.
|
||||
01f,19dec06,mwv Correct typos throughout (WIND00083100)
|
||||
01e,15dec06,kch Corrected typo for DHCPC6_IF_IA_NA_DEFAULT_LIST description.
|
||||
01d,11dec06,kch Added configuration parameters for DHCP client, relay
|
||||
and server callback hooks. Also added DHCPS_NETCONF_SYSVAR
|
||||
and DHCPR_NETCONF_SYSVAR. Added ipnet/ipDHCPc_example.c
|
||||
configlette to INCLUDE_IPDHCPC as well.
|
||||
01c,01dec06,kch Added additional configuration parameters for DHCP6 Client.
|
||||
01b,23sep06.kch Added INCLUDE_IPDHCPS6_CMD.
|
||||
01a,14sep06,tkf Written
|
||||
*/
|
||||
#ifdef _WRS_CONFIG_COMPONENT_IPDHCPS
|
||||
|
||||
Component INCLUDE_IPDHCPS {
|
||||
NAME DHCP Server
|
||||
SYNOPSIS DHCP Server
|
||||
MODULES ipdhcps.o ipdhcps_cmd_dhcps.o ipdhcps_db.o \
|
||||
ipdhcps_leasedump.o ipdhcps_options.o ipdhcps_packet.o
|
||||
REQUIRES INCLUDE_IPCOM SELECT_IPCOM_FS
|
||||
CONFIGLETTES ipdhcps_config.c
|
||||
CFG_PARAMS DHCPS_SERVER_PORT DHCPS_CLIENT_PORT \
|
||||
DHCPS_DEFAULT_LEASE_TIME DHCPS_MAX_LEASE_TIME \
|
||||
DHCPS_MIN_LEASE_TIME DHCPS_RENEWAL_TIME \
|
||||
DHCPS_REBINDING_TIME DHCPS_ABANDONED_STATE_MAX_TIME \
|
||||
DHCPS_EXPIRED_STATE_MAX_TIME \
|
||||
DHCPS_RELEASED_STATE_MAX_TIME \
|
||||
DHCPS_OFFERED_STATE_MAX_TIME \
|
||||
DHCPS_LEASE_BOOTPC_MAX_TIME DHCPS_ALLOW_DECLINE \
|
||||
DHCPS_PKT_SIZE DHCPS_ALLOW_BOOTP \
|
||||
DHCPS_ALLOW_DYNAMIC_BOOTP DHCPS_DO_ICMP_ADDRESS_CHECK \
|
||||
DHCPS_AUTHORIZED_AGENTS DHCPS_NETCONF_SYSVAR \
|
||||
DHCPS_INSTALL_CALLBACK_HOOK DHCPS_START_CALLBACK_HOOK \
|
||||
DHCPS_STOP_CALLBACK_HOOK \
|
||||
DHCPS_AUTO_ENABLE_INTERFACES \
|
||||
DHCPS_NO_STRICT_SUBNET_MATCH
|
||||
_CHILDREN FOLDER_DHCP
|
||||
}
|
||||
|
||||
/* INCLUDE_IPDHCPS configuration parameters */
|
||||
Parameter DHCPS_SERVER_PORT {
|
||||
NAME UDP port used by the DHCP server
|
||||
SYNOPSIS Defines the UDP port used by IPDHCPS for receiving.
|
||||
TYPE char *
|
||||
DEFAULT "67"
|
||||
}
|
||||
|
||||
Parameter DHCPS_CLIENT_PORT {
|
||||
NAME UDP port used by the DHCP/bootp clients
|
||||
SYNOPSIS Defines the UDP port used for reception by DHCP/bootp \
|
||||
clients handled by DHCP server.
|
||||
TYPE char *
|
||||
DEFAULT "68"
|
||||
}
|
||||
|
||||
Parameter DHCPS_DEFAULT_LEASE_TIME {
|
||||
NAME Default lease time
|
||||
SYNOPSIS The default time in seconds a client can hold a dynamic \
|
||||
lease before it expires.
|
||||
TYPE char *
|
||||
DEFAULT "864000"
|
||||
}
|
||||
|
||||
Parameter DHCPS_MAX_LEASE_TIME {
|
||||
NAME Maximum lease time
|
||||
SYNOPSIS The maximum time in seconds a client can hold a dynamic \
|
||||
lease before it expires.
|
||||
TYPE char *
|
||||
DEFAULT "8640000"
|
||||
}
|
||||
|
||||
Parameter DHCPS_MIN_LEASE_TIME {
|
||||
NAME Minimum lease time
|
||||
SYNOPSIS The minimum time in seconds a client can hold a dynamic \
|
||||
lease before it expires.
|
||||
TYPE char *
|
||||
DEFAULT "60"
|
||||
}
|
||||
|
||||
Parameter DHCPS_RENEWAL_TIME {
|
||||
NAME Lease renewal time
|
||||
SYNOPSIS The time in seconds when the client must start asking to \
|
||||
extend the lease. If set to "disabled", the server will not \
|
||||
transmit its value to its clients. Clients will then use a \
|
||||
local default value for this parameter, typically one-half \
|
||||
of the lease time.
|
||||
TYPE char *
|
||||
DEFAULT "disabled"
|
||||
}
|
||||
|
||||
Parameter DHCPS_REBINDING_TIME {
|
||||
NAME Lease rebinding time
|
||||
SYNOPSIS The time in seconds when the client must start rebinding \
|
||||
the lease if it has failed to renew it. If set to "disabled", \
|
||||
the server will not transmit its value to its clients. Clients \
|
||||
will then use a local default value for this parameter.
|
||||
TYPE char *
|
||||
DEFAULT "disabled"
|
||||
}
|
||||
|
||||
Parameter DHCPS_ABANDONED_STATE_MAX_TIME {
|
||||
NAME Abandoned state max time
|
||||
SYNOPSIS The time in seconds that must pass before an abandoned lease \
|
||||
is allowed to be released and set to state free.
|
||||
TYPE char *
|
||||
DEFAULT "8640000"
|
||||
}
|
||||
|
||||
Parameter DHCPS_EXPIRED_STATE_MAX_TIME {
|
||||
NAME Expired state max time
|
||||
SYNOPSIS The time in seconds that must pass before an expired lease \
|
||||
will be set to state free to be reused. If set to "forever", \
|
||||
the server will never flush expired leases automatically.
|
||||
TYPE char *
|
||||
DEFAULT "forever"
|
||||
}
|
||||
|
||||
Parameter DHCPS_RELEASED_STATE_MAX_TIME {
|
||||
NAME Released state max time
|
||||
SYNOPSIS The time in seconds that must pass before a released lease \
|
||||
can be set to state free to be reused. If set to "forever", \
|
||||
the server will never flush released leases automatically.
|
||||
TYPE char *
|
||||
DEFAULT "forever"
|
||||
}
|
||||
|
||||
Parameter DHCPS_OFFERED_STATE_MAX_TIME {
|
||||
NAME Offered state max time
|
||||
SYNOPSIS The time in seconds that must pass before an offered lease \
|
||||
can be set to state free to be reused.
|
||||
TYPE char *
|
||||
DEFAULT "10"
|
||||
}
|
||||
|
||||
Parameter DHCPS_LEASE_BOOTPC_MAX_TIME {
|
||||
NAME Lease for bootp client max time
|
||||
SYNOPSIS The time in seconds that must pass before a lease held by a \
|
||||
bootp client can be set to state free to be reused. If set \
|
||||
to "forever", the server will never flush bootp leases \
|
||||
automatically.
|
||||
TYPE char *
|
||||
DEFAULT "forever"
|
||||
}
|
||||
|
||||
Parameter DHCPS_ALLOW_DECLINE {
|
||||
NAME Allow decline
|
||||
SYNOPSIS Whether DHCP server shall ignore DHCP DECLINE messages \
|
||||
or if it shall honor them in an appropriate way.
|
||||
TYPE char *
|
||||
DEFAULT "true"
|
||||
}
|
||||
|
||||
Parameter DHCPS_PKT_SIZE {
|
||||
NAME Packet size
|
||||
SYNOPSIS The size in bytes of a DHCP packet used by IPDHCPS. It must \
|
||||
never be less than 576 bytes.
|
||||
TYPE char *
|
||||
DEFAULT "576"
|
||||
}
|
||||
|
||||
Parameter DHCPS_ALLOW_BOOTP {
|
||||
NAME Allow bootp
|
||||
SYNOPSIS Whether DHCP server shall accept requests from bootp \
|
||||
clients or not.
|
||||
TYPE char *
|
||||
DEFAULT "true"
|
||||
}
|
||||
|
||||
Parameter DHCPS_ALLOW_DYNAMIC_BOOTP {
|
||||
NAME Allow dynamic bootp
|
||||
SYNOPSIS Whether DHCP server shall accept allocating dynamic leases \
|
||||
to bootp clients or not. If set to "false", the server will \
|
||||
only use static leases for bootp clients.
|
||||
TYPE char *
|
||||
DEFAULT "false"
|
||||
}
|
||||
|
||||
Parameter DHCPS_DO_ICMP_ADDRESS_CHECK {
|
||||
NAME Check address
|
||||
SYNOPSIS Specifies if DHCP server should perform an ICMP ping to \
|
||||
check on each address before it is offered to a DHCP client.
|
||||
TYPE char *
|
||||
DEFAULT "false"
|
||||
}
|
||||
|
||||
Parameter DHCPS_AUTHORIZED_AGENTS {
|
||||
NAME Authorized DHCP relay agent
|
||||
SYNOPSIS Set to "any" or specifies a list of space-separated IP \
|
||||
addresses to DHCP relay agents that are authorized to \
|
||||
access this DHCP server.
|
||||
TYPE char *
|
||||
DEFAULT "any"
|
||||
}
|
||||
|
||||
Parameter DHCPS_NETCONF_SYSVAR {
|
||||
NAME DHCP server network pre-configuration
|
||||
SYNOPSIS DHCP server network pre-configuration array is used to \
|
||||
statically configure the DHCP server with a pre-configured \
|
||||
setup of networks and hosts when initiated. Each system \
|
||||
variable in this array must be named according to the syntax \
|
||||
ipdhcps.netconf.<index>, where <index> is a unique line \
|
||||
indicator. The value of each system variable must consist \
|
||||
of a IPDHCPS shell command (without the preceding dhcps \
|
||||
that is used only when executing from a shell). The commands \
|
||||
are executed in the order they are defined. See \
|
||||
ipdhcps_netconf_sysvar Ipcom_sysvar array in ipdhcps_config.c \
|
||||
configlette for the example usage.
|
||||
TYPE void *
|
||||
DEFAULT NULL
|
||||
}
|
||||
|
||||
Parameter DHCPS_INSTALL_CALLBACK_HOOK {
|
||||
NAME Install dhcp server callback routines
|
||||
SYNOPSIS Determine if the user-defined DHCP server callback routines \
|
||||
as specified by the macro DHCPS_START_CALLBACK_HOOK and \
|
||||
DHCPS_STOP_CALLBACK_HOOK should be installed. If FALSE, the \
|
||||
DHCPS_START_CALLBACK_HOOK and DHCPS_STOP_CALLBACK_HOOK \
|
||||
configurations are not applicable.
|
||||
TYPE BOOL
|
||||
DEFAULT FALSE
|
||||
}
|
||||
|
||||
Parameter DHCPS_START_CALLBACK_HOOK {
|
||||
NAME DHCP server startup callback routine
|
||||
SYNOPSIS DHCP server startup callback routine. This routine, if \
|
||||
provided, will be called by dhcp server at startup. It is \
|
||||
intended to be used for static configuration of DHCP server, \
|
||||
i.e. to install a lease 'dump to file' routine and/or to \
|
||||
restore a lease database from a file. The \
|
||||
DHCPS_INSTALL_CALLBACK_HOOK must also be set to TRUE in \
|
||||
order to install this callback hook.
|
||||
TYPE FUNCPTR
|
||||
DEFAULT 0
|
||||
}
|
||||
|
||||
Parameter DHCPS_STOP_CALLBACK_HOOK {
|
||||
NAME DHCP server termination callback routine
|
||||
SYNOPSIS DHCP server termination callback routine. This callback \
|
||||
will be called by DHCP server upon termination of the DHCP \
|
||||
server. It is intended to be used for static configuration \
|
||||
of IPDHCPS, for instance to save the lease database at \
|
||||
shutdown so that the lease can later be restored. The \
|
||||
DHCPS_INSTALL_CALLBACK_HOOK must also be set to TRUE in \
|
||||
order to install this callback hook.
|
||||
TYPE FUNCPTR
|
||||
DEFAULT 0
|
||||
}
|
||||
|
||||
Parameter DHCPS_AUTO_ENABLE_INTERFACES {
|
||||
NAME Enable Interfaces Automatically
|
||||
SYNOPSIS Whether DHCP server should automatically start the server on \
|
||||
interfaces when they are found. If set to "false", the server \
|
||||
will have to be enabled on interfaces manually.
|
||||
TYPE char *
|
||||
DEFAULT "true"
|
||||
}
|
||||
|
||||
Parameter DHCPS_NO_STRICT_SUBNET_MATCH {
|
||||
NAME Disable Strict Subnet Matching
|
||||
SYNOPSIS Whether DHCP server should _not_ prefer to issue a lease from \
|
||||
a pool with the same subnet that is present on the enabled dhcps interface. \
|
||||
Default is "false". ie. strict subnet matching is enabled.
|
||||
TYPE char *
|
||||
DEFAULT "false"
|
||||
}
|
||||
|
||||
#endif /* _WRS_CONFIG_COMPONENT_IPDHCPS */
|
||||
@@ -0,0 +1,12 @@
|
||||
# Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: common.vxconfig,v $ $Revision: 1.7 $
|
||||
# $Source: /home/interpeak/CVSRoot/ipdhcps/config/common.vxconfig,v $
|
||||
# $Author: myakan $
|
||||
# $State: Exp $ $Locker: $
|
||||
#
|
||||
# INTERPEAK_COPYRIGHT_STRING
|
||||
|
||||
#hidden option that enables IPDHCPS
|
||||
config SUPPORTS_DHCPS
|
||||
bool
|
||||
default y
|
||||
|
||||
@@ -0,0 +1,724 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* IPCOM CONFIGURATION SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipdhcps_config.c,v $ $Revision: 1.24.10.8 $
|
||||
* $Source: /home/interpeak/CVSRoot/ipdhcps/config/ipdhcps_config.c,v $
|
||||
* $Author: jren $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
*
|
||||
* Design and implementation by Jonas Rendel <jonas@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
modification history
|
||||
--------------------
|
||||
01h,04sep09,h_s Fix defect WIND00184353.
|
||||
01g,02jun09,spw Add no strict subnet match sysvar
|
||||
01f,03jan07,kch Updated CVS revision log entry for Jan 03 code drop.
|
||||
01e,11dec06,kch Modified ipdhcps_start_hook() and ipdhcps_stop_hook()
|
||||
to allow for user configurable callback hooks. Also
|
||||
added DHCPS_NETCONF_SYSVAR to allow preconfigure network
|
||||
configurations.
|
||||
01d,01dec06,kch Updated CVS revision log entry.
|
||||
01c,13sep06,kch Refresh with Sept 08, 2006 code drop
|
||||
01b,04sep06,kch Include only minimum set of header files to workaround
|
||||
symbol redeclaration errors.
|
||||
01a,28aug06,kch Update based on Aug 22, 2006 code drop.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
#include "ipcom_config.h"
|
||||
#include "ipcom_err.h"
|
||||
|
||||
/* ?? maybe should be IP_PORT_VXWORKS or PRJ_BUILD */
|
||||
#ifndef IP_WB_BUILD
|
||||
#include "ipcom_clib.h"
|
||||
#include "ipcom_sock.h"
|
||||
#include "ipcom_inet.h"
|
||||
#include "ipcom_type.h"
|
||||
#include "ipcom_tmo.h"
|
||||
#include "ipcom_cstyle.h"
|
||||
#endif
|
||||
|
||||
#include "ipcom_sysvar.h"
|
||||
#include "ipcom_shell.h"
|
||||
#ifdef IP_WB_BUILD
|
||||
#include "ipdhcps_config.h"
|
||||
#endif
|
||||
|
||||
#ifndef IP_WB_BUILD
|
||||
#include "ipdhcps.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 GENERAL
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IP_WB_BUILD
|
||||
/* typedef to make compiler happy... */
|
||||
typedef int (*ipdhcps_start_cb)(void);
|
||||
typedef int (*ipdhcps_stop_cb)(void);
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#if defined(IPDHCPS_INCLUDE_CMD) || !defined(IP_WB_BUILD)
|
||||
IP_EXTERN int ipdhcps_cmd_dhcps(int argc, char **argv);
|
||||
#endif
|
||||
|
||||
IP_EXTERN int ipdhcps_start_hook (void);
|
||||
IP_EXTERN int ipdhcps_stop_hook (void);
|
||||
|
||||
#ifdef IPDHCPS_USE_EXAMPLE
|
||||
/*
|
||||
*===========================================================================
|
||||
* example_dump_lease_db(void);
|
||||
*===========================================================================
|
||||
* Description: Lease DB dump routine used in the configuration example
|
||||
* below.
|
||||
*
|
||||
*/
|
||||
IP_EXTERN Ip_s32 example_lease_dump_tmo_func(struct Ipcom_tmo_struct *tmo,
|
||||
void *cookie);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* example_restore_lease_db(void)
|
||||
*===========================================================================
|
||||
* Description: Lease DB restore routine used in the configuration example
|
||||
* below.
|
||||
*
|
||||
*/
|
||||
IP_EXTERN int example_restore_lease_db(void);
|
||||
#endif
|
||||
|
||||
#if defined (IPDHCPS_INCLUDE_CMD) && defined (IPDHCPS_INCLUDE_ISC_EXAMPLE)
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* example_isc_config
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL Ip_s32 example_isc_config(const char *cfgfile);
|
||||
#endif
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPDHCPS_USE_EXAMPLE
|
||||
/*
|
||||
*===========================================================================
|
||||
* lease_dump_tmo
|
||||
*===========================================================================
|
||||
* Description: IPCOM timeout handler used in the configuration example
|
||||
* below.
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ipcom_tmo lease_dump_tmo;
|
||||
#endif
|
||||
|
||||
/* if needed, use VIP control this value */
|
||||
#define DHCPS_USE_REMOTE_AGENT_CLASS_ID "true"
|
||||
#define DHCPS_STRICT_VENDER_CLASS_ID_MATCH "true"
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_conf_sysvar
|
||||
*===========================================================================
|
||||
* Description: Initiates mandatory system configuration variables specific
|
||||
* for IPDHCPS.
|
||||
*
|
||||
*/
|
||||
IP_STATIC IP_CONST Ipcom_sysvar ipdhcps_conf_sysvar[] =
|
||||
{
|
||||
/*
|
||||
* server_port
|
||||
*
|
||||
* UDP port used by the IPDHCPS server.
|
||||
*
|
||||
* Default: 67
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.server_port", "67", DHCPS_SERVER_PORT),
|
||||
|
||||
/*
|
||||
* client_port
|
||||
*
|
||||
* UDP port used by the dhcp/bootp clients.
|
||||
*
|
||||
* Default: 68
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.client_port", "68", DHCPS_CLIENT_PORT),
|
||||
|
||||
/*
|
||||
* default_lease_time
|
||||
*
|
||||
* The default time a client can hold a dynamic lease before
|
||||
* it expires.
|
||||
*
|
||||
* Default: 864000 seconds (10 days).
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.default_lease_time", "864000", DHCPS_DEFAULT_LEASE_TIME),
|
||||
|
||||
/*
|
||||
* max_lease_time
|
||||
*
|
||||
* The maximum time a client can hold a dynamic lease before
|
||||
* it expires.
|
||||
*
|
||||
* Default: 8640000 seconds (100 days).
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.max_lease_time", "864000", DHCPS_MAX_LEASE_TIME),
|
||||
|
||||
|
||||
/*
|
||||
* min_lease_time
|
||||
*
|
||||
* The minimimum time a client can hold a dynamic lease before
|
||||
* it expires.
|
||||
*
|
||||
* Default: 60 seconds
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.min_lease_time", "60", DHCPS_MIN_LEASE_TIME),
|
||||
|
||||
/*
|
||||
* renewal_time
|
||||
*
|
||||
* The time in seconds when the client must start asking to extend
|
||||
* the lease. This is known as T1 or the renewal time.
|
||||
* If this constant is set to zero the server will not give
|
||||
* the client a value for T1. The client then typically
|
||||
* defaults this value to one-half of its lease time.
|
||||
*
|
||||
* Default: disabled
|
||||
*
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.renewal_time", "disabled", DHCPS_RENEWAL_TIME),
|
||||
|
||||
/*
|
||||
* rebinding_time
|
||||
*
|
||||
* The time in seconds when the client must start rebinding
|
||||
* the lease if it has failed to renew it. This is known as T2
|
||||
* or the rebinding time.
|
||||
* If this constant is set to zero the server will not give
|
||||
* the client a value for T2. The client then typically defaults
|
||||
* value for this parameter.
|
||||
*
|
||||
* Default: disabled
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.rebinding_time", "disabled", DHCPS_REBINDING_TIME),
|
||||
|
||||
/*
|
||||
* in_abandoned_state_max_time
|
||||
*
|
||||
* The time that must pass before an abandoned lease is allowed
|
||||
* to be released and set to state free.
|
||||
*
|
||||
* Default: 8640000 seconds (100 days)
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.in_abandoned_state_max_time", "8640000", DHCPS_ABANDONED_STATE_MAX_TIME),
|
||||
|
||||
/*
|
||||
* in_expired_state_max_time
|
||||
*
|
||||
* The time in seconds that must pass before an expired lease will
|
||||
* be set to state free to be reused.
|
||||
*
|
||||
* Default: "forever"
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.in_expired_state_max_time", "forever", DHCPS_EXPIRED_STATE_MAX_TIME),
|
||||
|
||||
/*
|
||||
* in_released_state_max_time
|
||||
*
|
||||
* The time in seconds that must pass before a released lease can
|
||||
* be set to state free to be reused.
|
||||
*
|
||||
* Default: "forever"
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.in_released_state_max_time", "forever", DHCPS_RELEASED_STATE_MAX_TIME),
|
||||
|
||||
/*
|
||||
* in_offered_state_max_time
|
||||
*
|
||||
* The time in seconds that must pass before an offered lease can
|
||||
* be set to state free to be reused.
|
||||
*
|
||||
* Default: 10 seconds
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.in_offered_state_max_time", "10", DHCPS_OFFERED_STATE_MAX_TIME),
|
||||
|
||||
/*
|
||||
* lease_for_bootp_client_max_time
|
||||
*
|
||||
* The time in seconds that must pass before a lease held by a
|
||||
* bootp client can be set to state free to be reused.
|
||||
*
|
||||
* Default: "forever"
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.lease_for_bootp_client_max_time", "forever", DHCPS_LEASE_BOOTPC_MAX_TIME),
|
||||
|
||||
/*
|
||||
* allow_decline
|
||||
*
|
||||
* This boolean tells if IPDHCPS shall ignore DHCP DECLINE messages
|
||||
* or if it shall honor them in an appropriate way.
|
||||
* If set to "true" the IPDHCPS lease database can in worst case be
|
||||
* exhausted by a malfunctioning DHCP client or a denial of service
|
||||
* attack.
|
||||
*
|
||||
* Default: "true"
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.allow_decline", "true", DHCPS_ALLOW_DECLINE),
|
||||
|
||||
/*
|
||||
* enable_new_interface_when_found
|
||||
*
|
||||
* This boolean tells if IPDHCPS shall treat newly found interfaces
|
||||
* as 'enabled' directly when they have been found and attached to
|
||||
* the IPDHCPS.
|
||||
*
|
||||
* If this variable is set to 'false' it is necessary to explicitly
|
||||
* instruct the IPDHCPS which interface(s) it shall use.
|
||||
* This can be done from the shell by issuing the command:
|
||||
* 'dhcps interface enable <ifname>'
|
||||
* The same command can also be issued from the netconf sysvar list
|
||||
* upon startup.
|
||||
*
|
||||
* Default: "true"
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.enable_new_interface_when_found", "true", DHCPS_AUTO_ENABLE_INTERFACES),
|
||||
|
||||
/*
|
||||
* packet_size
|
||||
*
|
||||
* The size in bytes of a DHCP packet rx/tx buffer used by IPDHCPS. It must never
|
||||
* be less than 576 bytes.
|
||||
*
|
||||
* Default: 576 bytes
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.packet_size", "576", DHCPS_PKT_SIZE),
|
||||
|
||||
/*
|
||||
* allow_bootp
|
||||
*
|
||||
* This boolean tells if IPDHCPS shall accept requests from bootp
|
||||
* clients or not.
|
||||
*
|
||||
* Default: "true"
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.allow_bootp", "true", DHCPS_ALLOW_BOOTP),
|
||||
|
||||
/*
|
||||
* allow_dynamic_bootp
|
||||
*
|
||||
* This boolean tells if IPDHCPS shall accept allocating dynamic leases
|
||||
* to bootp clients or not.
|
||||
* Becasue of limitations in the bootp protocol, this type of clients
|
||||
* can not release allocated addresses. Hence it is not recommended to
|
||||
* allow them to have dynamic leases.
|
||||
*
|
||||
* Default : "false" (do not accept)
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.allow_dynamic_bootp", "false", DHCPS_ALLOW_DYNAMIC_BOOTP),
|
||||
|
||||
/*
|
||||
* do_icmp_address_check
|
||||
*
|
||||
* This boolean tells if IPDHCPS shall perfom a icmp ping check on
|
||||
* each address before it is offered to a DHCP client.
|
||||
*
|
||||
* Default : "false"
|
||||
*/
|
||||
|
||||
IP_SYSVAR("ipdhcps.do_icmp_address_check", "false", DHCPS_DO_ICMP_ADDRESS_CHECK),
|
||||
|
||||
|
||||
/*
|
||||
* authorized_agents
|
||||
*
|
||||
* This parameter is either set to "any" or is a list of IP
|
||||
* addresses to dhcp relay agents that are authorized to
|
||||
* access this dhcp server.
|
||||
*
|
||||
* Default : "any"
|
||||
*/
|
||||
IP_SYSVAR("ipdhcps.authorized_agents", "any", DHCPS_AUTHORIZED_AGENTS),
|
||||
|
||||
/*
|
||||
* no_strict_subnet_match
|
||||
*
|
||||
* This boolean determines whether IPDHCPS should _not_ prefer to issue a lease from
|
||||
* a pool with the same subnet that is present on the enabled dhcps interface.
|
||||
*
|
||||
* Default: "false"
|
||||
*/
|
||||
IP_SYSVAR("ipdhcps.no_strict_subnet_match", "false", DHCPS_NO_STRICT_SUBNET_MATCH),
|
||||
|
||||
/*
|
||||
* use_remote_agent_class_id
|
||||
*
|
||||
* This boolean determines whether IPDHCPS check class ID or not.
|
||||
*
|
||||
* Default: "true"
|
||||
*/
|
||||
IP_SYSVAR("ipdhcps.use_remote_agent_class_id", "true", DHCPS_USE_REMOTE_AGENT_CLASS_ID),
|
||||
IP_SYSVAR("ipdhcps.strict_vender_class_id_match", "true", DHCPS_STRICT_VENDER_CLASS_ID_MATCH),
|
||||
|
||||
{ IP_NULL, IP_NULL }
|
||||
};
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_netconf_sysvar
|
||||
*===========================================================================
|
||||
* Description: Initiates optional network configuration variables used
|
||||
* for IPDHCPS. The intention of this variable set is to initiate
|
||||
* the dhcp server with a preconfigured setup of networks and hosts
|
||||
* to handle.
|
||||
* Each of these system variables must have a name as below:
|
||||
* ipdhcps.netconf.<index>
|
||||
* The value of the system variable must be a IPDHCPS specific
|
||||
* shell command (without the preceding 'dhcps').
|
||||
*
|
||||
* Below is an example on how to use it.
|
||||
*
|
||||
*/
|
||||
#ifdef IPDHCPS_INCLUDE_CMD
|
||||
IP_STATIC IP_CONST Ipcom_sysvar ipdhcps_netconf_sysvar[] =
|
||||
{
|
||||
#if defined(IPDHCPS_USE_EXAMPLE) || defined(INCLUDE_IPDHCPS_USE_EXAMPLE)
|
||||
/* Add a subnet 10.1.0.0 with subnet mask 255.255.0.0 */
|
||||
{"ipdhcps.netconf.00", "subnet add 10.1.0.0 255.255.0.0"},
|
||||
|
||||
/* Add an address pool to this subnet */
|
||||
{"ipdhcps.netconf.01", "pool add 10.1.0.0 10.1.0.5 10.1.0.99"},
|
||||
|
||||
/* Add another address pool to this subnet */
|
||||
{"ipdhcps.netconf.02", "pool add 10.1.0.0 10.1.0.199 10.1.0.249"},
|
||||
|
||||
/* Add a domain name (dhcp option 15) to this subnet */
|
||||
{"ipdhcps.netconf.03", "option add 10.1.0.0 15 green.net"},
|
||||
|
||||
/* Add a router (dhcp option 3) to this subnet */
|
||||
{"ipdhcps.netconf.04", "option add 10.1.0.0 3 10.1.0.1"},
|
||||
|
||||
/* Add a name server (dhcp option 5) to this subnet */
|
||||
{"ipdhcps.netconf.05", "option add 10.1.0.0 5 10.1.0.2"},
|
||||
|
||||
/* A another subnet 192.168.2.0 with netmask 255.255.255.0 */
|
||||
{"ipdhcps.netconf.06", "subnet add 192.168.2.0 255.255.255.0"},
|
||||
|
||||
/* Add an address pool to this subnet*/
|
||||
{"ipdhcps.netconf.07", "pool add 192.168.2.0 192.168.2.10 192.168.2.50"},
|
||||
|
||||
/* Add a domain name (dhcp option 15) to this subnet */
|
||||
{"ipdhcps.netconf.08", "option add 192.168.2.0 15 blue.net"},
|
||||
|
||||
/* Add two routers (dhcp option 3) to this subnet */
|
||||
{"ipdhcps.netconf.09", "option add 192.168.2.0 3 192.168.2.1 192.168.2.2"},
|
||||
|
||||
/* Add a static route (dhcp option 33) on this subnet (10.1.0.0->192.168.2.2 */
|
||||
{"ipdhcps.netconf.10", "option add 192.168.2.0 33 10.1.0.0 192.168.2.2"},
|
||||
|
||||
/* Set max lease time to 120 seconds on this subnet */
|
||||
{"ipdhcps.netconf.11", "config set 192.168.2.0 max-lease-time 120"},
|
||||
|
||||
/* Set default lease time to 60 seconds on this subnet */
|
||||
{"ipdhcps.netconf.12", "config set 192.168.2.0 default-lease-time 60"},
|
||||
|
||||
/* Add a host with the client identifier 'Jack's lap top' */
|
||||
{"ipdhcps.netconf.13", "host add 10.1.0.142 -i \"\\0Jack's lap top\""},
|
||||
|
||||
/* Add a host name (dhcp option 12) for this host */
|
||||
{"ipdhcps.netconf.14", "option add 10.1.0.142 12 blue-host"},
|
||||
|
||||
/* Add a router (dhcp option 3) to this host */
|
||||
{"ipdhcps.netconf.15", "option add 10.1.0.142 3 10.1.0.1"},
|
||||
|
||||
/* Add a host with a standard ethernet MAC address */
|
||||
{"ipdhcps.netconf.16", "host add 10.1.0.141 -h BE:60:13:F7:F8:0F"},
|
||||
|
||||
/* Add a host name (dhcp option 12) for this host */
|
||||
{"ipdhcps.netconf.17", "option add 10.1.0.141 12 yellow-host"},
|
||||
|
||||
/* Setup a boot file for this host */
|
||||
{"ipdhcps.netconf.18", "config set 10.1.0.141 boot-file /boot/yellow-host.boot"},
|
||||
|
||||
/* Setup a boot server for this host to boot from */
|
||||
{"ipdhcps.netconf.19", "config set 10.1.0.141 next-server-name black-server"},
|
||||
|
||||
/* Setup the default lease time to 600 seconds on the default net */
|
||||
{"ipdhcps.netconf.20", "config set default default-lease-time 600"},
|
||||
|
||||
/* Setup bootp allowance on the default net */
|
||||
{"ipdhcps.netconf.21", "config set default allow-bootp false"},
|
||||
|
||||
/* Enable ICMP ping checking on subnet 10.1.0.0 */
|
||||
{"ipdhcps.netconf.22", "config set 10.1.0.0 do-icmp-address-check true"},
|
||||
|
||||
/* Add vendor class identifer on subnet 10.1.0.0 */
|
||||
{"ipdhcps.netconf.23", "class add 10.1.0.0 first-class vendor first"},
|
||||
|
||||
/* Add vendor class on default */
|
||||
{"ipdhcps.netconf.24", "class add default second-class vendor second"},
|
||||
|
||||
/* Setup ARP cache timeout on subnet 10.1.0.0 */
|
||||
{"ipdhcps.netconf.25", "option add 10.1.0.0 35 10"},
|
||||
|
||||
/* Setup ARP cache timeout for vendor class on subnet 10.1.0.0 */
|
||||
{"ipdhcps.netconf.26", "option add 10.1.0.0 -c first-class 35 20"},
|
||||
|
||||
/* Setup ARP cache on default */
|
||||
{"ipdhcps.netconf.27", "option add default 35 60"},
|
||||
|
||||
/* Setup ARP cache on vendor class on default */
|
||||
{"ipdhcps.netconf.28", "option add default -c second-class 35 40"},
|
||||
|
||||
/* Setup authorized relay agents on subnet 10.1.0.0 */
|
||||
{"ipdhcps.netconf.29", "config set 10.1.0.0 authorized-agents 10.1.0.2 10.1.0.3"},
|
||||
|
||||
#endif /* IPDHCPS_USE_EXAMPLE || INCLUDE_IPDHCPS_USE_EXAMPLE */
|
||||
|
||||
{ IP_NULL, IP_NULL}
|
||||
};
|
||||
#endif /* IPDHCPS_INCLUDE_CMD */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
#ifdef IP_WB_BUILD
|
||||
#if DHCPS_INSTALL_CALLBACK_HOOK == TRUE
|
||||
|
||||
/*
|
||||
* forward declarations for the user-defined dhcp server callback hooks
|
||||
* to satisfy the compiler.
|
||||
*/
|
||||
#if defined(DHCPS_START_CALLBACK_HOOK)&& defined(DHCPS_STOP_CALLBACK_HOOK)
|
||||
int DHCPS_START_CALLBACK_HOOK (void);
|
||||
int DHCPS_STOP_CALLBACK_HOOK (void);
|
||||
#endif
|
||||
#else
|
||||
|
||||
/*
|
||||
* DHCPS_START_CALLBACK_HOOK and DHCPS_STOP_CALLBACK_HOOK are applicable
|
||||
* only if DHCPS_INSTALL_CALLBACK_HOOK is set to TRUE. Explicitly re-define
|
||||
* these hooks to NULL so that we don't get compiler errors
|
||||
*/
|
||||
#undef DHCPS_START_CALLBACK_HOOK
|
||||
#define DHCPS_START_CALLBACK_HOOK NULL
|
||||
|
||||
#undef DHCPS_STOP_CALLBACK_HOOK
|
||||
#define DHCPS_STOP_CALLBACK_HOOK NULL
|
||||
|
||||
#endif /* DHCPS_INSTALL_CALLBACK_HOOK */
|
||||
#endif /* IP_WB_BUILD */
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_start_hook
|
||||
*===========================================================================
|
||||
* Description: This routine is called by IPDHCPS at start-up. It is
|
||||
* intended to be used for static configuration of IPDHCPS,
|
||||
* for instance to install a lease 'dump to file' routine and/or
|
||||
* to restore a IPDHCPS database from a lease dump.
|
||||
*
|
||||
*
|
||||
* Parameters: -
|
||||
* Returns: 0 - success
|
||||
* -1 - failure
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
ipdhcps_start_hook (void)
|
||||
{
|
||||
#ifdef IP_WB_BUILD
|
||||
ipdhcps_start_cb dhcps_cb;
|
||||
|
||||
dhcps_cb = (DHCPS_START_CALLBACK_HOOK != NULL) ?
|
||||
DHCPS_START_CALLBACK_HOOK : NULL;
|
||||
|
||||
/*
|
||||
* call the user callback routine if provided. Otherwise, simply return 0.
|
||||
*/
|
||||
return (dhcps_cb != NULL) ? dhcps_cb() : 0;
|
||||
#else /* IP_WB_BUILD */
|
||||
int ret = 0;
|
||||
#ifdef IPDHCPS_USE_EXAMPLE
|
||||
/* Restore lease database */
|
||||
example_restore_lease_db ();
|
||||
|
||||
ipcom_tmo_request (&lease_dump_tmo,
|
||||
example_lease_dump_tmo_func,
|
||||
&lease_dump_tmo,
|
||||
10*60*60*1000);
|
||||
#endif /* IPDHCPS_USE_EXAMPLE */
|
||||
#if defined (IPDHCPS_INCLUDE_CMD) && defined (IPDHCPS_INCLUDE_ISC_EXAMPLE)
|
||||
{
|
||||
char *cfgfile = ipcom_sysvar_get("ipdhcps.iscfile", IP_NULL, IP_NULL);
|
||||
if (cfgfile)
|
||||
{
|
||||
ret = example_isc_config(cfgfile);
|
||||
ipcom_free(cfgfile);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
#endif /* IP_WB_BUILD */
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_stop_hook
|
||||
*===========================================================================
|
||||
* Description: Shows how to save the lease database at shutdown.
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
ipdhcps_stop_hook (void)
|
||||
{
|
||||
#ifdef IP_WB_BUILD
|
||||
ipdhcps_stop_cb dhcps_cb;
|
||||
|
||||
dhcps_cb = (DHCPS_STOP_CALLBACK_HOOK != NULL) ?
|
||||
DHCPS_STOP_CALLBACK_HOOK : NULL;
|
||||
|
||||
/*
|
||||
* call the user callback routine if provided. Otherwise, simply return 0.
|
||||
*/
|
||||
return (dhcps_cb != NULL) ? dhcps_cb() : 0;
|
||||
#else /* IP_WB_BUILD */
|
||||
#ifdef IPDHCPS_USE_EXAMPLE
|
||||
(void)ipcom_tmo_cancel (&lease_dump_tmo);
|
||||
example_dump_lease_db ();
|
||||
#endif
|
||||
return 0;
|
||||
#endif /* IP_WB_BUILD */
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_configure
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
ipdhcps_configure(void)
|
||||
{
|
||||
Ip_err ret;
|
||||
|
||||
/* Initialize IPDHCPS system configuration. */
|
||||
(void)ipcom_sysvar_setv(ipdhcps_conf_sysvar, 0);
|
||||
|
||||
#if defined (IPDHCPS_INCLUDE_CMD)
|
||||
{
|
||||
#ifdef IP_WB_BUILD
|
||||
Ipcom_sysvar *entries;
|
||||
|
||||
if ((entries = (Ipcom_sysvar *)DHCPS_NETCONF_SYSVAR) != NULL)
|
||||
{
|
||||
/* Initialize IPDHCPS network preconfiguration */
|
||||
(void)ipcom_sysvar_setv(entries, 0);
|
||||
}
|
||||
#else /* IP_WB_BUILD */
|
||||
/* Initialize IPDHCPS network preconfiguration */
|
||||
(void)ipcom_sysvar_setv(ipdhcps_netconf_sysvar, 0);
|
||||
#endif /* IP_WB_BUILD */
|
||||
#endif
|
||||
#if defined(IPDHCPS_INCLUDE_CMD) || !defined(IP_WB_BUILD)
|
||||
ret = ipcom_shell_add_cmd("dhcps",
|
||||
"dhcps ...",
|
||||
"DHCP server shell tool",
|
||||
(Ipcom_shell_cmd_type) ipdhcps_cmd_dhcps,
|
||||
IPCOM_SHELL_PRIO_SAME,
|
||||
IPCOM_PROC_STACK_DEFAULT);
|
||||
|
||||
if(ret != IPCOM_SUCCESS)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return IPCOM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* IPNET_CONFIG.H
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipdhcps_config.h,v $ $Revision: 1.12 $
|
||||
* $Source: /home/interpeak/CVSRoot/ipdhcps/config/ipdhcps_config.h,v $
|
||||
* $Author: kenneth $ $Date: 2010-10-04 19:33:58 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
*
|
||||
* Design and implementation by Jonas Rendel <jonas@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPDHCPS_CONFIG_H
|
||||
#define IPDHCPS_CONFIG_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*
|
||||
* Configuration for IPDHCPS. Parameters that are macros can only be changed
|
||||
* before compiling, variables can be changed before compiling and linking.
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_config.h>
|
||||
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
|
||||
#include "ipdhcps.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 DEFINE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_SYSLOG_PRIORITY
|
||||
#undef IPCOM_SYSLOG_PRIORITY
|
||||
#endif
|
||||
|
||||
#if defined(_WRS_CONFIG_IPDHCPS_SYSLOG_PRIORITY)
|
||||
#define IPCOM_SYSLOG_PRIORITY _WRS_CONFIG_IPDHCPS_SYSLOG_PRIORITY
|
||||
#else
|
||||
#define IPCOM_SYSLOG_PRIORITY IPCOM_LOG_WARNING
|
||||
#endif
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPDHCPS_INCLUDE_CMD
|
||||
*===========================================================================
|
||||
* Define to include DHCP Server shell command 'dhcps'.
|
||||
*/
|
||||
#define IPDHCPS_INCLUDE_CMD
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPDHCPS_USE_EXAMPLE
|
||||
*===========================================================================
|
||||
* Use Interpeak example in example/ipdhcps_userhooks.c.
|
||||
*
|
||||
#define IPDHCPS_USE_EXAMPLE
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 CVS REVISION HISTORY
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,853 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipdhcps_example.c,v $ $Revision $
|
||||
* $Source: /home/interpeak/CVSRoot/ipdhcps/config/ipdhcps_example.c,v $
|
||||
* $Author: kenneth $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
*
|
||||
* Design and implementation by Jonas Rendel <jonas@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
* Example file on :
|
||||
* 1. How to save lease database at shutdown.
|
||||
* 2. How to restore lease database at startup
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_config.h>
|
||||
|
||||
#if defined(IP_WB_BUILD) && defined(IPCOM_USE_CLIB_PROTO)
|
||||
#undef IPCOM_USE_CLIB_PROTO
|
||||
#endif
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_clib2.h>
|
||||
#include <ipcom_strlib.h>
|
||||
#include <ipcom_os.h>
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_tmo.h>
|
||||
#include <ipcom_shell.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_file.h>
|
||||
|
||||
#include "ipdhcps.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC int example_restore_lease_db(void);
|
||||
IP_STATIC int example_dump_lease_db(void);
|
||||
IP_STATIC Ip_s32 example_lease_dump_tmo_func(struct Ipcom_tmo_struct *tmo,
|
||||
void *cookie);
|
||||
|
||||
|
||||
/* IPCOM timeout handler used in the configuration example below. */
|
||||
IP_STATIC Ipcom_tmo lease_dump_tmo;
|
||||
|
||||
#if (defined(IP_WB_BUILD) && defined(IPDHCPS_UNSUPPORTED_EXAMPLE)) || !defined(IP_WB_BUILD)
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 LOCAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPDHCPS_USE_EXAMPLE
|
||||
/*
|
||||
*===========================================================================
|
||||
* restore_lease_db
|
||||
*===========================================================================
|
||||
* Description: This is an example on how the contents of the IPDHCPS
|
||||
* lease database can be restored by initializing it with
|
||||
* data stored in a file system.
|
||||
*
|
||||
* Parameters: -
|
||||
* Returns: 0 - success
|
||||
* -1 - failure
|
||||
*
|
||||
*/
|
||||
IP_STATIC int
|
||||
example_restore_lease_db(void)
|
||||
{
|
||||
int retval = -1;
|
||||
IP_FILE *fd = IP_NULL;
|
||||
struct Ip_stat statbuf;
|
||||
void *buf = IP_NULL;
|
||||
|
||||
if(ipcom_stat("/home/jonas/dumpfile", &statbuf) == -1)
|
||||
goto leave;
|
||||
|
||||
if((fd = ipcom_fopen("/home/jonas/dumpfile", "r")) == 0)
|
||||
goto leave;
|
||||
|
||||
if((buf = ipcom_malloc(statbuf.st_size)) == IP_NULL)
|
||||
goto leave;
|
||||
|
||||
if(ipcom_fread(buf, statbuf.st_size, 1, fd) <= 0)
|
||||
goto leave;
|
||||
|
||||
ipdhcps_lease_db_restore(buf);
|
||||
|
||||
retval = 0;
|
||||
|
||||
leave:
|
||||
|
||||
if(fd)
|
||||
ipcom_fclose(fd);
|
||||
|
||||
if(buf != IP_NULL)
|
||||
ipcom_free(buf);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* dump_lease_db
|
||||
*===========================================================================
|
||||
* Description: This is an example on how to save the current contents
|
||||
* of the IPDHCPS lease database to a file system.
|
||||
* The routine is adapted for a UNIX file system.
|
||||
*
|
||||
* Parameters: -
|
||||
* Returns: 0 - success
|
||||
* -1 - failure
|
||||
*/
|
||||
IP_STATIC int
|
||||
example_dump_lease_db(void)
|
||||
{
|
||||
int retval = -1;
|
||||
void *buf = IP_NULL;
|
||||
IP_FILE *fd = IP_NULL;
|
||||
int n;
|
||||
|
||||
if((n = ipdhcps_lease_db_dump(&buf)) < 0)
|
||||
goto leave;
|
||||
|
||||
if((fd = ipcom_fopen("/home/jonas/dumpfile","w+")) == 0)
|
||||
goto leave;
|
||||
|
||||
if((ipcom_fwrite(buf, n, 1, fd)) <= 0)
|
||||
goto leave;
|
||||
|
||||
retval = 0;
|
||||
|
||||
leave:
|
||||
if(fd)
|
||||
ipcom_fclose(fd);
|
||||
if(buf != IP_NULL)
|
||||
ipcom_free(buf);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* lease_dump_tmo_func
|
||||
*===========================================================================
|
||||
* Description: This is an example on how the contents of the lease
|
||||
* database can be dumped periodically to a file during
|
||||
* execution of IPDHCPS.
|
||||
*
|
||||
* Parameters: -
|
||||
* Returns: 0 - success
|
||||
* -1 - failure
|
||||
*/
|
||||
|
||||
IP_STATIC Ip_s32
|
||||
example_lease_dump_tmo_func(struct Ipcom_tmo_struct *tmo, void *cookie)
|
||||
{
|
||||
if(example_dump_lease_db() == 0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* IPDHCPS_USE_EXAMPLE */
|
||||
|
||||
|
||||
#if defined (IPDHCPS_INCLUDE_CMD) && defined (IPDHCPS_INCLUDE_ISC_EXAMPLE)
|
||||
|
||||
IP_GLOBAL int ipdhcps_cmd_dhcps(int argc, char **argv);
|
||||
|
||||
typedef struct _example_token_buffer
|
||||
{
|
||||
char *llines;
|
||||
char *lines;
|
||||
char *ltokens;
|
||||
char *tokens;
|
||||
|
||||
/**/
|
||||
char *spec;
|
||||
|
||||
/**/
|
||||
Ip_bool eof;
|
||||
int curline;
|
||||
} example_token_buffer_t;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* example_do_command
|
||||
*===========================================================================
|
||||
* Description: Execute a DHCPS command containing the parameters we're
|
||||
* interested in adding to the configuration.
|
||||
* Parameters: format - The format string
|
||||
* ... - The arguments for the format string
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
example_do_command(const char *format, ...)
|
||||
{
|
||||
va_list vargs;
|
||||
char *cmd;
|
||||
int argc;
|
||||
char **argv = IP_NULL;
|
||||
|
||||
if ((cmd = ipcom_malloc(256)) != IP_NULL)
|
||||
{
|
||||
va_start(vargs, format);
|
||||
ipcom_vsnprintf(cmd, 256, format, vargs);
|
||||
va_end(vargs);
|
||||
|
||||
|
||||
IPCOM_LOG1(INFO,"DHCP Executing '%s'", cmd);
|
||||
if(ipcom_parse_argstr(cmd, (int*)&argc, &argv) != IPCOM_SUCCESS)
|
||||
{
|
||||
IPCOM_LOG1(ERR,"failed to parse command '%s'", cmd);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if(ipdhcps_cmd_dhcps(argc, argv) != IPCOM_SUCCESS)
|
||||
{
|
||||
IPCOM_LOG1(ERR,"failed to execute command '%s'", cmd);
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
if (argv != IP_NULL)
|
||||
ipcom_free(argv);
|
||||
if (cmd)
|
||||
ipcom_free(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* example_get_line
|
||||
*===========================================================================
|
||||
* Description: Fetch the next available line into the tokenizer buffer
|
||||
* Parameters: tok - The tokenizer buffer
|
||||
* Returns: IP_TRUE on success, IP_FALSE if we're at EOF.
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_bool
|
||||
example_get_line(example_token_buffer_t *tok)
|
||||
{
|
||||
char *line;
|
||||
char *t;
|
||||
|
||||
restart:
|
||||
/* Already EOF */
|
||||
if (tok->eof)
|
||||
return IP_FALSE;
|
||||
|
||||
/* Get next */
|
||||
line = ipcom_strtok_r(tok->lines, "\r\n", &tok->llines);
|
||||
tok->curline++;
|
||||
tok->lines = IP_NULL;
|
||||
|
||||
/* No more lines? */
|
||||
if (line == IP_NULL)
|
||||
{
|
||||
tok->eof = IP_TRUE;
|
||||
return IP_FALSE;
|
||||
}
|
||||
|
||||
/* Discard comments */
|
||||
t = ipcom_strchr(line, '#');
|
||||
if (t)
|
||||
*t = '\0';
|
||||
|
||||
/* Empty line; restart */
|
||||
if (ipcom_strlen(line) == 0)
|
||||
goto restart;
|
||||
|
||||
/* Set the tokens; discard any stored values */
|
||||
tok->tokens = line;
|
||||
tok->spec = IP_NULL;
|
||||
|
||||
return IP_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* example_get_token
|
||||
*===========================================================================
|
||||
* Description: Get the next token from the tokenizer
|
||||
* Parameters: tok - The tokenizer buffer
|
||||
* nl - IP_TRUE if we're allowed to consume newlines
|
||||
* Returns: A token if one is available, IP_NULL otherwise.
|
||||
*
|
||||
*/
|
||||
IP_STATIC char *
|
||||
example_get_token(example_token_buffer_t *tok, Ip_bool nl)
|
||||
{
|
||||
char *token;
|
||||
|
||||
if (tok->eof)
|
||||
{
|
||||
/* We're out of tokens */
|
||||
return IP_FALSE;
|
||||
}
|
||||
else if (tok->spec)
|
||||
{
|
||||
/* There's a special token stored. ';' */
|
||||
token = tok->spec;
|
||||
tok->spec = IP_NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *t;
|
||||
while ((token = ipcom_strtok_r(tok->tokens, ",\t ", &tok->ltokens)) == IP_NULL)
|
||||
{
|
||||
if (nl && example_get_line(tok))
|
||||
continue;
|
||||
return IP_NULL;
|
||||
}
|
||||
|
||||
/* Clear the tokens buffer */
|
||||
tok->tokens = IP_NULL;
|
||||
|
||||
/* Need to separate semicolons; they're used as 'eol' */
|
||||
if (ipcom_strchr(token, ';') != IP_NULL)
|
||||
tok->spec = ";";
|
||||
|
||||
token = ipcom_strtok_r(token, ";", &t);
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* example_check_token
|
||||
*===========================================================================
|
||||
* Description: Check that the next token matches what is required.
|
||||
* Parameters: tok - The tokenizer buffer
|
||||
* req - The required token
|
||||
* nl - IP_TRUE if we're allowed to consume newlines
|
||||
* Returns: IP_TRUE on success, IP_FALSE otherwise
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_bool
|
||||
example_check_token(example_token_buffer_t *tok, const char *req, Ip_bool nl)
|
||||
{
|
||||
char *token = example_get_token(tok, nl);
|
||||
if (token)
|
||||
{
|
||||
if (req && ipcom_strcasecmp(token, req) == 0)
|
||||
return IP_TRUE;
|
||||
return IP_FALSE;
|
||||
}
|
||||
|
||||
return req? IP_FALSE : IP_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* example_concatenate_tokens
|
||||
*===========================================================================
|
||||
* Description: Concatenate all options on this line
|
||||
* Parameters: tok - The tokenizer buffer
|
||||
* Returns: A dynamically allocated memory buffer containing all the
|
||||
* tokenized options on success, IP_NULL otherwise.
|
||||
*
|
||||
*/
|
||||
IP_STATIC char *
|
||||
example_concatenate_tokens(example_token_buffer_t *tok)
|
||||
{
|
||||
char *value;
|
||||
char *conc = ipcom_malloc(256);
|
||||
|
||||
if (conc != IP_NULL)
|
||||
{
|
||||
int no_values = 0;
|
||||
|
||||
conc[0] = '\0';
|
||||
while ((value = example_get_token(tok, IP_FALSE)) != IP_NULL)
|
||||
{
|
||||
if (ipcom_strcasecmp(value, ";") == 0)
|
||||
break;
|
||||
|
||||
no_values++;
|
||||
ipcom_strncat(conc, value, 256);
|
||||
ipcom_strncat(conc, " ", 256);
|
||||
}
|
||||
|
||||
/* No semicolon or no values */
|
||||
if (no_values == 0 || value == IP_NULL)
|
||||
{
|
||||
ipcom_free(conc);
|
||||
return IP_NULL;
|
||||
}
|
||||
|
||||
return conc;
|
||||
}
|
||||
return IP_NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* example_parse_option
|
||||
*===========================================================================
|
||||
* Description: Parse a ISC option string
|
||||
* Parameters: tok - The tokenizer buffer
|
||||
* context - The context the option resides in
|
||||
* Returns: 0 on success.
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_s32
|
||||
example_parse_option(example_token_buffer_t *tok, const char *context)
|
||||
{
|
||||
/* Retrieve the option name */
|
||||
char *option = example_get_token(tok, IP_FALSE);
|
||||
if (option == IP_NULL)
|
||||
{
|
||||
IPCOM_LOG1(ERR,
|
||||
"DHCPS(%d): no option name specified",
|
||||
tok->curline);
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
if (ipcom_strcasecmp(option, "domain-name-servers") == 0)
|
||||
{
|
||||
/* DNS servers option; retrieve the list of servers and pass it
|
||||
* to our dhcps command */
|
||||
char *value = example_concatenate_tokens(tok);
|
||||
|
||||
if (value == IP_NULL)
|
||||
{
|
||||
IPCOM_LOG1(ERR,
|
||||
"DHCPS(%d): No servers specified or lacking ';' in domain-name-servers option",
|
||||
tok->curline);
|
||||
return -1;
|
||||
}
|
||||
|
||||
example_do_command("dhcps option add %s 5 %s", context, value);
|
||||
ipcom_free(value);
|
||||
}
|
||||
else if (ipcom_strcasecmp(option, "domain-name") == 0)
|
||||
{
|
||||
/* A domain name */
|
||||
char *value = example_get_token(tok, IP_FALSE);
|
||||
if (!example_check_token(tok, ";", IP_FALSE))
|
||||
{
|
||||
IPCOM_LOG1(ERR,
|
||||
"DHCPS(%d): No domain name specified or lacking ';' in domain-name option",
|
||||
tok->curline);
|
||||
return -1;
|
||||
}
|
||||
|
||||
example_do_command("dhcps option add %s 15 %s", context, value);
|
||||
}
|
||||
else if (ipcom_strcasecmp(option, "routers") == 0)
|
||||
{
|
||||
/* One or many routers */
|
||||
char *value = example_concatenate_tokens(tok);
|
||||
if (value == IP_NULL)
|
||||
{
|
||||
IPCOM_LOG1(ERR,
|
||||
"DHCPS(%d): No servers specified or lacking ';' in routers option",
|
||||
tok->curline);
|
||||
return -1;
|
||||
}
|
||||
|
||||
example_do_command("dhcps option add %s 3 %s", context, value);
|
||||
ipcom_free(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Unknown or unhandled option */
|
||||
IPCOM_LOG2(WARNING,
|
||||
"DHCPS(%d): Unknown option %s",
|
||||
tok->curline,
|
||||
option);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* example_parse_subnet
|
||||
*===========================================================================
|
||||
* Description: Parse an ISC subnet directive
|
||||
* Parameters: tok - The tokenizer buffer.
|
||||
* Returns: 0 on success
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_s32
|
||||
example_parse_subnet(example_token_buffer_t *tok)
|
||||
{
|
||||
/* address NETMASK netmask { */
|
||||
char *address, *netmask;
|
||||
char *token;
|
||||
|
||||
/* We need to retrieve the address, the NETMASK keyword and the
|
||||
* netmask value */
|
||||
address = example_get_token(tok, IP_FALSE);
|
||||
if (!example_check_token(tok, "netmask", IP_FALSE))
|
||||
return -1;
|
||||
netmask = example_get_token(tok, IP_FALSE);
|
||||
|
||||
/**/
|
||||
if (address == IP_NULL || netmask == IP_NULL)
|
||||
return -1;
|
||||
|
||||
/* The subnet block starts with a left bracer */
|
||||
if (!example_check_token(tok, "{", IP_TRUE))
|
||||
return -1;
|
||||
|
||||
/* Add the subnet command */
|
||||
example_do_command("dhcps subnet add %s %s", address, netmask);
|
||||
|
||||
/* Go through the subnet */
|
||||
while ((token = example_get_token(tok, IP_TRUE)) != IP_NULL)
|
||||
{
|
||||
int retval;
|
||||
|
||||
/* End of subnet is a right bracer, exit successfully if found */
|
||||
if (ipcom_strcasecmp(token, "}") == 0)
|
||||
return 0;
|
||||
else if (ipcom_strcasecmp(token, "option") == 0)
|
||||
{
|
||||
/* Parse a subnet specific option */
|
||||
if ((retval = example_parse_option(tok, address)) != 0)
|
||||
return retval;
|
||||
}
|
||||
else if (ipcom_strcasecmp(token, "range") == 0)
|
||||
{
|
||||
/* Parse a pool range */
|
||||
char *start, *end;
|
||||
start = example_get_token(tok, IP_FALSE);
|
||||
end = example_get_token(tok, IP_FALSE);
|
||||
if (!example_check_token(tok, ";", IP_FALSE))
|
||||
{
|
||||
IPCOM_LOG1(ERR,
|
||||
"DHCPS(%d): Missing range start, end or ';' in range directive",
|
||||
tok->curline);
|
||||
return -1;
|
||||
}
|
||||
|
||||
example_do_command("dhcps pool add %s %s %s", address, start, end);
|
||||
}
|
||||
else if (ipcom_strcasecmp(token, "default-lease-time") == 0)
|
||||
{
|
||||
char *lease;
|
||||
lease = example_get_token(tok, IP_FALSE);
|
||||
if (!example_check_token(tok, ";", IP_FALSE))
|
||||
{
|
||||
IPCOM_LOG1(ERR,
|
||||
"DHCPS(%d): lease time specified or ';' missing in default-lease-time directive",
|
||||
tok->curline);
|
||||
return -1;
|
||||
}
|
||||
|
||||
example_do_command("dhcps config set %s default-lease-time %s", address, lease);
|
||||
}
|
||||
else if (ipcom_strcasecmp(token, "max-lease-time") == 0)
|
||||
{
|
||||
char *lease;
|
||||
lease = example_get_token(tok, IP_FALSE);
|
||||
if (!example_check_token(tok, ";", IP_FALSE))
|
||||
{
|
||||
IPCOM_LOG1(ERR,
|
||||
"DHCPS(%d): lease time specified or ';' missing in max-lease-time directive",
|
||||
tok->curline);
|
||||
return -1;
|
||||
}
|
||||
|
||||
example_do_command("dhcps config set %s max-lease-time %s", address, lease);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* example_parse_base
|
||||
*===========================================================================
|
||||
* Description: Parse top-level ISC configuration items
|
||||
* Parameters: tok - The tokenizer buffer
|
||||
* Returns: 0 on success
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_s32
|
||||
example_parse_base(example_token_buffer_t *tok)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
char *token = example_get_token(tok, IP_TRUE);
|
||||
char *value;
|
||||
int ret;
|
||||
|
||||
/* EOF; We've read the entire file - exit */
|
||||
if (token == IP_NULL)
|
||||
return 0;
|
||||
|
||||
/* Check the token and see if we know it */
|
||||
if (ipcom_strcasecmp(token, "subnet") == 0)
|
||||
{
|
||||
ret = example_parse_subnet(tok);
|
||||
}
|
||||
else if (ipcom_strcasecmp(token, "option") == 0)
|
||||
{
|
||||
ret = example_parse_option(tok, "default");
|
||||
}
|
||||
else if (ipcom_strcasecmp(token, "default-lease-time") == 0)
|
||||
{
|
||||
value = example_get_token(tok, IP_FALSE);
|
||||
if (!example_check_token(tok, ";", IP_FALSE))
|
||||
{
|
||||
IPCOM_LOG1(ERR,
|
||||
"DHCPS(%d): lease time specified or ';' missing in default-lease-time directive",
|
||||
tok->curline);
|
||||
return -1;
|
||||
}
|
||||
|
||||
example_do_command("dhcps config set default default-lease-time %s", value);
|
||||
}
|
||||
else if (ipcom_strcasecmp(token, "max-lease-time") == 0)
|
||||
{
|
||||
value = example_get_token(tok, IP_FALSE);
|
||||
if (!example_check_token(tok, ";", IP_FALSE))
|
||||
{
|
||||
IPCOM_LOG1(ERR,
|
||||
"DHCPS(%d): lease time specified or ';' missing in max-lease-time directive",
|
||||
tok->curline);
|
||||
return -1;
|
||||
}
|
||||
|
||||
example_do_command("dhcps config set default max-lease-time %s", value);
|
||||
}
|
||||
else if (ipcom_strcasecmp(token, "authoritative") == 0 ||
|
||||
ipcom_strcasecmp(token, "ddns-update-style") == 0 ||
|
||||
ipcom_strcasecmp(token, "log-facility") == 0)
|
||||
{
|
||||
/* Unsupported ISC directives
|
||||
* Consume this line
|
||||
*/
|
||||
IPCOM_LOG2(WARNING,
|
||||
"DHCPS(%d): Unhandled directive %s specified",
|
||||
tok->curline,
|
||||
token);
|
||||
example_get_line(tok);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* example_cfgfile
|
||||
*===========================================================================
|
||||
* Description: Read an ISC DHCP configuration file
|
||||
* Parameters: cfgfile - The configuration file
|
||||
* Returns: 0 on success, -1 or errorcode otherwise.
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL Ip_s32
|
||||
example_isc_config(const char *cfgfile)
|
||||
{
|
||||
int retval = -1;
|
||||
char *buf = IP_NULL;
|
||||
IP_FILE *fd = IP_NULL;
|
||||
struct Ip_stat st;
|
||||
example_token_buffer_t tbuf;
|
||||
|
||||
/* Failed to read */
|
||||
if (ipcom_stat(cfgfile, &st) != 0)
|
||||
{
|
||||
IPCOM_LOG1(ERR,
|
||||
"DHCPS: Failed to stat configuration file %s",
|
||||
cfgfile);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* Failed to open */
|
||||
if((fd = ipcom_fopen(cfgfile,"r")) == 0)
|
||||
{
|
||||
IPCOM_LOG1(ERR,
|
||||
"DHCPS: Failed to open configuration file %s",
|
||||
cfgfile);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* Allocate buffer */
|
||||
if ((buf = ipcom_malloc(st.st_size + 1)) == IP_NULL)
|
||||
{
|
||||
IPCOM_LOG1(ERR,
|
||||
"DHCPS: Failed to allocate memory for configuration file %s",
|
||||
cfgfile);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* Read entire file */
|
||||
if((ipcom_fread(buf, 1, st.st_size, fd)) != st.st_size)
|
||||
{
|
||||
IPCOM_LOG1(ERR,
|
||||
"DHCPS: Failed to read configuration file %s",
|
||||
cfgfile);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* Zero terminate; */
|
||||
buf[st.st_size] = '\0';
|
||||
|
||||
/* Do parse the configuration file */
|
||||
ipcom_memset(&tbuf, 0, sizeof(tbuf));
|
||||
tbuf.lines = buf;
|
||||
example_get_line(&tbuf);
|
||||
|
||||
/* Parse the file */
|
||||
retval = example_parse_base(&tbuf);
|
||||
|
||||
leave:
|
||||
if (fd)
|
||||
ipcom_fclose(fd);
|
||||
if(buf != IP_NULL)
|
||||
ipcom_free(buf);
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* defined (IPDHCPS_INCLUDE_CMD) && defined (IPDHCPS_INCLUDE_ISC_EXAMPLE) */
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* ipdhcps_example_start_hook - example dhcps startup callback routine
|
||||
*
|
||||
* This is an example implementation of the callback routine that is called
|
||||
* by the DHCP server startup.
|
||||
*
|
||||
* RETURNS:
|
||||
* 0 if success or -1 if failure
|
||||
*
|
||||
* NOMANUAL
|
||||
*/
|
||||
IP_GLOBAL int ipdhcps_example_start_hook (void)
|
||||
{
|
||||
#ifdef IPDHCPS_USE_EXAMPLE
|
||||
/* Restore lease database */
|
||||
example_restore_lease_db ();
|
||||
|
||||
ipcom_tmo_request (&lease_dump_tmo,
|
||||
example_lease_dump_tmo_func,
|
||||
&lease_dump_tmo,
|
||||
10*60*60*1000);
|
||||
#endif /* IPDHCPS_USE_EXAMPLE */
|
||||
|
||||
#if defined (IPDHCPS_INCLUDE_CMD) && defined (IPDHCPS_INCLUDE_ISC_EXAMPLE)
|
||||
{
|
||||
char *cfgfile = ipcom_sysvar_get("ipdhcps.iscfile", IP_NULL, IP_NULL);
|
||||
if (cfgfile)
|
||||
{
|
||||
ret = example_isc_config(cfgfile);
|
||||
ipcom_free(cfgfile);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* ipdhcps_example_stop_hook - example dhcp server terminate callback routine
|
||||
*
|
||||
* This is an example implementation of the callback routine that is called
|
||||
* by the DHCP server upon termination.
|
||||
*
|
||||
* RETURNS:
|
||||
* 0 if success or -1 if failure
|
||||
*
|
||||
* NOMANUAL
|
||||
*/
|
||||
IP_GLOBAL int ipdhcps_example_stop_hook (void)
|
||||
{
|
||||
(void)ipcom_tmo_cancel (&lease_dump_tmo);
|
||||
example_dump_lease_db ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* IPDHCPS_UNSUPPORTED_EXAMPLE */
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
IPTARGETS := lib
|
||||
|
||||
ifneq ($(IPMAKEFILE),)
|
||||
include $(IPMAKEFILE)
|
||||
else
|
||||
include $(IPCOM_ROOT)/Makefile
|
||||
endif
|
||||
|
||||
ifneq ($(IPTEMPLATE),)
|
||||
include $(IPTEMPLATE)
|
||||
else
|
||||
include ipdhcps.mk
|
||||
endif
|
||||
|
||||
include $(IPCOM_ROOT)/gmake/ipcom_make.mk
|
||||
ifeq ($(IPPORT),las)
|
||||
lib:: dirs $(IPLIBFILE)
|
||||
else
|
||||
lib::
|
||||
$(IPMAKE) IPTEMPLATE=ipdhcps.mk lib2
|
||||
|
||||
lib2: dirs $(IPLIBFILE)
|
||||
endif
|
||||
@@ -0,0 +1,134 @@
|
||||
#############################################################################
|
||||
# IPDHCPS.MK
|
||||
#
|
||||
# Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipdhcps.mk,v $ $Revision: 1.5 $
|
||||
# $Source: /home/interpeak/CVSRoot/ipdhcps/gmake/ipdhcps.mk,v $
|
||||
# $Author: joel $ $Date: 2006-12-19 08:43:03 $
|
||||
# $State: Exp $ $Locker: $
|
||||
#
|
||||
# Copyright 2000-2006 Interpeak AB (http://www.interpeak.se). All rights reserved.
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
#
|
||||
# modification history
|
||||
# --------------------
|
||||
# 01a,11dec06,kch Build ipdhcps_example.o only if $(SKIP_CONFIG) is not
|
||||
# set to true.
|
||||
#
|
||||
|
||||
#############################################################################
|
||||
# PRODUCT
|
||||
###########################################################################
|
||||
|
||||
IPPROD ?= ipdhcps
|
||||
|
||||
|
||||
#############################################################################
|
||||
# DEFINE
|
||||
###########################################################################
|
||||
|
||||
IPDEFINE += -DIPDHCPS
|
||||
|
||||
|
||||
#############################################################################
|
||||
# INCLUDE
|
||||
###########################################################################
|
||||
|
||||
IPINCLUDE += -I$(IPDHCPS_ROOT)/config
|
||||
IPINCLUDE += -I$(IPDHCPS_ROOT)/include
|
||||
|
||||
IPLIBINCLUDE += -I$(IPDHCPS_ROOT)/src
|
||||
|
||||
|
||||
#############################################################################
|
||||
# OBJECTS
|
||||
###########################################################################
|
||||
|
||||
ifneq ($(IPPORT),las)
|
||||
# Configuration
|
||||
IPLIBOBJECTS_C += ipdhcps_config.o
|
||||
IPLIBOBJECTS_C += ipdhcps_example.o
|
||||
|
||||
# Shell command
|
||||
IPLIBOBJECTS += ipdhcps_cmd_dhcps.o
|
||||
endif
|
||||
|
||||
# Core
|
||||
IPLIBOBJECTS += ipdhcps.o
|
||||
IPLIBOBJECTS += ipdhcps_options.o
|
||||
IPLIBOBJECTS += ipdhcps_leasedump.o
|
||||
IPLIBOBJECTS += ipdhcps_db.o
|
||||
IPLIBOBJECTS += ipdhcps_packet.o
|
||||
|
||||
# Compiles the xxx_config.o if the $SKIP_CONFIG macro is either not defined
|
||||
# or set to anything other than true.
|
||||
ifneq ($(SKIP_CONFIG),true)
|
||||
IPLIBOBJECTS += $(IPLIBOBJECTS_C)
|
||||
endif
|
||||
|
||||
# Compiles the xxx_config.o if the $SKIP_CONFIG macro is either not defined
|
||||
# or set to anything other than true.
|
||||
ifneq ($(SKIP_CONFIG),true)
|
||||
IPLIBOBJECTS += $(IPLIBOBJECTS_C)
|
||||
endif
|
||||
|
||||
|
||||
#############################################################################
|
||||
# VPATH
|
||||
###########################################################################
|
||||
|
||||
IPSRCDIRS += $(IPDHCPS_ROOT)/src $(IPDHCPS_ROOT)/config
|
||||
|
||||
|
||||
#############################################################################
|
||||
# LIB
|
||||
###########################################################################
|
||||
|
||||
IPLIBS += $(IPLIBROOT)/libipdhcps.a
|
||||
|
||||
|
||||
#############################################################################
|
||||
# BINARIES
|
||||
#############################################################################
|
||||
|
||||
ifeq ($(IPPORT),las)
|
||||
# Path to binaries
|
||||
IPCMDDIR := $(IPOBJDIR)/bin
|
||||
IPDAEMONDIR := $(IPOBJDIR)/sbin
|
||||
|
||||
# List of shell commands to build
|
||||
IPDHCPSSHELLCMDS =
|
||||
_IPIPDHCPSSHELLCMDS = $(addprefix $(IPCMDDIR)/,$(IPDHCPSSHELLCMDS))
|
||||
|
||||
# List of daemons to build
|
||||
IPDHCPSDAEMONS = dhcpd
|
||||
_IPDHCPSDAEMONS = $(addprefix $(IPDAEMONDIR)/,$(IPDHCPSDAEMONS))
|
||||
|
||||
bin:: $(_IPDHCPSSHELLCMDS) $(_IPDHCPSDAEMONS)
|
||||
|
||||
$(IPOBJDIR)/ipdhcps_cmd_%.o: $(IPDHCPS_ROOT)/src/ipdhcps_cmd_%.c
|
||||
@$(IPECHO) "+++ Compiling IPDHCPS shell command $<"
|
||||
$(IPVERB)$(IPCC) -Dipdhcps_cmd_$*=ipcom_cmd_entry_point $(IPCFLAGS) -o $@ $<
|
||||
|
||||
$(IPCMDDIR)/%: $(IPOBJDIR)/ipdhcps_cmd_%.o $(IPOBJDIR)/ipcom_shell_cmd_stub.o
|
||||
@$(IPECHO) "+++ Linking IPDHCPS shell command $@"
|
||||
$(IPVERB)$(IPLD) -o $@ $(IPLDFLAGS) $^ $(IPLIBS) $(IPLIBS) $(IPLIBS) $(IPLASTLIBS)
|
||||
|
||||
$(IPOBJDIR)/ipdhcps_%.o: $(IPDHCPS_ROOT)/src/ipdhcps_%.c
|
||||
@$(IPECHO) "+++ Compiling IPDHCPS deamon $<"
|
||||
$(IPVERB)$(IPCC) -Dipdhcps_$*_proc=ipcom_daemon_entry_point -Dipdhcps_$*_create=ipcom_daemon_create $(IPCFLAGS) -o $@ $<
|
||||
|
||||
$(IPOBJDIR)/ipdhcps_config.o: $(IPDHCPS_ROOT)/config/ipdhcps_config.c
|
||||
@$(IPECHO) "+++ Compiling IPDHCPS deamon $<"
|
||||
$(IPVERB)$(IPCC) -Dipdhcps_$*_configure=ipcom_daemon_configure $(IPCFLAGS) -o $@ $<
|
||||
|
||||
$(IPDAEMONDIR)/%: $(IPOBJDIR)/ipdhcps_%.o $(IPOBJDIR)/ipdhcps_config.o $(IPOBJDIR)/ipcom_daemon_stub.o
|
||||
@$(IPECHO) "+++ Linking IPDHCPS daemon $@"
|
||||
$(IPVERB)$(IPLD) -o $@ $(IPLDFLAGS) $^ $(IPLIBS) $(IPLIBS) $(IPLIBS) $(IPLASTLIBS)
|
||||
|
||||
endif
|
||||
|
||||
###########################################################################
|
||||
# END OF IPDHCPS.MK
|
||||
###########################################################################
|
||||
@@ -0,0 +1,839 @@
|
||||
/* ipdhcps.h - API of DHCP Server */
|
||||
|
||||
/*
|
||||
******************************************************************************
|
||||
* HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipdhcps.h,v $ $Revision: 1.40.10.1 $
|
||||
* $Source: /home/interpeak/CVSRoot/ipdhcps/include/ipdhcps.h,v $
|
||||
* $Author: zluo0 $ $Date: 2012-12-13 06:10:11 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
*
|
||||
* Design and implementation by Jonas Rendel <jonas@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPDHCPS_H
|
||||
#define IPDHCPS_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
This library contains the API for the DHCP Server
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "ipdhcps_config.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_cstyle.h>
|
||||
/* #include <ipcom_tmo2.h> for 64-bit compile warning */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
/*
|
||||
*===========================================================================
|
||||
* IPDHCPS_RELEASE
|
||||
*===========================================================================
|
||||
* IPDHCPS release version.
|
||||
*/
|
||||
#define IPDHCPS_RELEASE 60600
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* DHCPS Eternity constant
|
||||
*===========================================================================
|
||||
* To be used for setting certain timer constanst in ipdhcps_config.h
|
||||
*/
|
||||
#define IPDHCPS_ETERNITY (Ip_time_t)0xffffffff
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* DHCP hardware types
|
||||
*===========================================================================
|
||||
* Hardware types handled by the IPDHCPS.
|
||||
*/
|
||||
#define IPDHCPS_HWTYPE_ETHERNET 1
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* DHCP option codes
|
||||
*===========================================================================
|
||||
* DHCP option codes accepted by DHCPS for client configurations
|
||||
*/
|
||||
#define IPDHCPS_OPTCODE_SUBNET_MASK 1
|
||||
#define IPDHCPS_OPTCODE_TIME_OFFSET 2
|
||||
#define IPDHCPS_OPTCODE_ROUTERS 3
|
||||
#define IPDHCPS_OPTCODE_TIME_SERVERS 4
|
||||
#define IPDHCPS_OPTCODE_NAME_SERVERS 5
|
||||
#define IPDHCPS_OPTCODE_DOMAIN_NAME_SERVERS 6
|
||||
#define IPDHCPS_OPTCODE_LOG_SERVERS 7
|
||||
#define IPDHCPS_OPTCODE_COOKIE_SERVERS 8
|
||||
#define IPDHCPS_OPTCODE_LPR_SERVERS 9
|
||||
#define IPDHCPS_OPTCODE_IMPRESS_SERVERS 10
|
||||
#define IPDHCPS_OPTCODE_RESOURCE_LOCATION_SERVERS 11
|
||||
#define IPDHCPS_OPTCODE_HOST_NAME 12
|
||||
#define IPDHCPS_OPTCODE_BOOT_SIZE 13
|
||||
#define IPDHCPS_OPTCODE_MERIT_DUMP 14
|
||||
#define IPDHCPS_OPTCODE_DOMAIN_NAME 15
|
||||
#define IPDHCPS_OPTCODE_SWAP_SERVER 16
|
||||
#define IPDHCPS_OPTCODE_ROOT_PATH 17
|
||||
#define IPDHCPS_OPTCODE_EXTENSIONS_PATH 18
|
||||
#define IPDHCPS_OPTCODE_IP_FORWARDING 19
|
||||
#define IPDHCPS_OPTCODE_NON_LOCAL_SOURCE_ROUTING 20
|
||||
#define IPDHCPS_OPTCODE_POLICY_FILTER 21
|
||||
#define IPDHCPS_OPTCODE_MAX_DGRAM_REASSEMBLY 22
|
||||
#define IPDHCPS_OPTCODE_DEFAULT_IP_TTL 23
|
||||
#define IPDHCPS_OPTCODE_PATH_MTU_AGING_TIMEOUT 24
|
||||
#define IPDHCPS_OPTCODE_PATH_MTU_PLATEAU_TABLE 25
|
||||
#define IPDHCPS_OPTCODE_INTERFACE_MTU 26
|
||||
#define IPDHCPS_OPTCODE_ALL_SUBNETS_LOCAL 27
|
||||
#define IPDHCPS_OPTCODE_BROADCAST_ADDRESS 28
|
||||
#define IPDHCPS_OPTCODE_PERFORM_MASK_DISCOVERY 29
|
||||
#define IPDHCPS_OPTCODE_MASK_SUPPLIER 30
|
||||
#define IPDHCPS_OPTCODE_ROUTER_DISCOVERY 31
|
||||
#define IPDHCPS_OPTCODE_ROUTER_SOLICITATION_ADDRESS 32
|
||||
#define IPDHCPS_OPTCODE_STATIC_ROUTES 33
|
||||
#define IPDHCPS_OPTCODE_TRAILER_ENCAPSULATION 34
|
||||
#define IPDHCPS_OPTCODE_ARP_CACHE_TIMEOUT 35
|
||||
#define IPDHCPS_OPTCODE_IEEE802_3_ENCAPSULATION 36
|
||||
#define IPDHCPS_OPTCODE_DEFAULT_TCP_TTL 37
|
||||
#define IPDHCPS_OPTCODE_TCP_KEEPALIVE_INTERVAL 38
|
||||
#define IPDHCPS_OPTCODE_TCP_KEEPALIVE_GARBAGE 39
|
||||
#define IPDHCPS_OPTCODE_NIS_DOMAIN 40
|
||||
#define IPDHCPS_OPTCODE_NIS_SERVERS 41
|
||||
#define IPDHCPS_OPTCODE_NTP_SERVERS 42
|
||||
#define IPDHCPS_OPTCODE_VENDOR_ENCAPSULATED_OPTIONS 43
|
||||
#define IPDHCPS_OPTCODE_NETBIOS_NAME_SERVERS 44
|
||||
#define IPDHCPS_OPTCODE_NETBIOS_DD_SERVER 45
|
||||
#define IPDHCPS_OPTCODE_NETBIOS_NODE_TYPE 46
|
||||
#define IPDHCPS_OPTCODE_NETBIOS_SCOPE 47
|
||||
#define IPDHCPS_OPTCODE_FONT_SERVERS 48
|
||||
#define IPDHCPS_OPTCODE_X_DISPLAY_MANAGER 49
|
||||
#define IPDHCPS_OPTCODE_VENDOR_CLASS 60
|
||||
#define IPDHCPS_OPTCODE_CLIENT_IDENTIFIER 61
|
||||
#define IPDHCPS_OPTCODE_NWIP_DOMAIN 62
|
||||
#define IPDHCPS_OPTCODE_NWIP_SUBOPTIONS 63
|
||||
#define IPDHCPS_OPTCODE_NISPLUS_DOMAIN 64
|
||||
#define IPDHCPS_OPTCODE_NISPLUS_SERVERS 65
|
||||
#define IPDHCPS_OPTCODE_HOME_AGENTS 68
|
||||
#define IPDHCPS_OPTCODE_SMTP_SERVERS 69
|
||||
#define IPDHCPS_OPTCODE_POP3_SERVERS 70
|
||||
#define IPDHCPS_OPTCODE_NNTP_SERVERS 71
|
||||
#define IPDHCPS_OPTCODE_WWW_SERVERS 72
|
||||
#define IPDHCPS_OPTCODE_FINGER_SERVERS 73
|
||||
#define IPDHCPS_OPTCODE_IRC_SERVERS 74
|
||||
#define IPDHCPS_OPTCODE_STREETTALK_SERVERS 75
|
||||
#define IPDHCPS_OPTCODE_STDA_SERVERS 76
|
||||
#define IPDHCPS_OPTCODE_USER_CLASS 77
|
||||
#define IPDHCPS_OPTCODE_RELAY_AGENT_INFO 82
|
||||
|
||||
#define IPDHCPS_OPTCODE_LIMIT 82
|
||||
|
||||
#define IPDHCPS_OPTCODE_UNUSED 254
|
||||
#define IPDHCPS_OPTCODE_END 255
|
||||
|
||||
#define IPDHCPS_OPT_DHCP 0
|
||||
/*
|
||||
*===========================================================================
|
||||
* DHCP RELAY AGENT IFNO SUBOPTIONS
|
||||
*===========================================================================
|
||||
* DHCP sub options used with IPDHCPS_OPTCODE_RELAY_AGENT_INFO (82)
|
||||
*/
|
||||
#define IPDHCPS_SUBOPTCODE_RA_CIRCUIT_ID 1
|
||||
#define IPDHCPS_SUBOPTCODE_RA_REMOTE_ID 2
|
||||
#define IPDHCPS_SUBOPTCODE_RA_AUTHENTICATION 8
|
||||
#define IPDHCPS_SUBOPTCODE_RA_LINK_SELECTION 5 /* RFC3527 */
|
||||
#define IPDHCPS_SUBOPTCODE_RA_SERVER_OVERRIDE 11/* RFC5107 */
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* CONFIG option codes
|
||||
*===========================================================================
|
||||
* Configuration option codes accepted by DHCPS for client and
|
||||
* server configuration.
|
||||
*/
|
||||
#define IPDHCPS_OPT_CONF 0x8000
|
||||
|
||||
#define IPDHCPS_CONFCODE_LEASE_TIME_DFLT IPDHCPS_OPT_CONF + 1 /* Host Byte Order */
|
||||
#define IPDHCPS_CONFCODE_LEASE_TIME_MAX IPDHCPS_OPT_CONF + 2 /* Host Byte Order */
|
||||
#define IPDHCPS_CONFCODE_LEASE_TIME_MIN IPDHCPS_OPT_CONF + 3 /* Host Byte Order */
|
||||
#define IPDHCPS_CONFCODE_RENEWAL_TIME IPDHCPS_OPT_CONF + 4 /* Host Byte Order */
|
||||
#define IPDHCPS_CONFCODE_REBINDING_TIME IPDHCPS_OPT_CONF + 5 /* Host Byte Order */
|
||||
#define IPDHCPS_CONFCODE_ALLOW_BOOTP IPDHCPS_OPT_CONF + 6
|
||||
#define IPDHCPS_CONFCODE_ALLOW_DYNAMIC_BOOTP IPDHCPS_OPT_CONF + 7
|
||||
#define IPDHCPS_CONFCODE_NEXT_SERVER_NAME IPDHCPS_OPT_CONF + 8
|
||||
#define IPDHCPS_CONFCODE_NEXT_SERVER_IP IPDHCPS_OPT_CONF + 9 /* Network Byte Order */
|
||||
#define IPDHCPS_CONFCODE_BOOT_FILE IPDHCPS_OPT_CONF + 10
|
||||
#define IPDHCPS_CONFCODE_DO_ICMP_ADDRESS_CHECK IPDHCPS_OPT_CONF + 11
|
||||
#define IPDHCPS_CONFCODE_AUTHORIZED_AGENTS IPDHCPS_OPT_CONF + 12
|
||||
#define IPDHCPS_CONFCODE_RA_AUTHENTICATION IPDHCPS_OPT_CONF + 13
|
||||
#define IPDHCPS_CONFCODE_RA_DROP IPDHCPS_OPT_CONF + 14
|
||||
#define IPDHCPS_CONFCODE_END IPDHCPS_OPT_CONF + IPDHCPS_OPTCODE_END
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcps_open
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef struct Ipdhcps_open_struct
|
||||
{
|
||||
Ip_u32 api_version; /* Currently version 1. Used for future compability. */
|
||||
}
|
||||
Ipdhcps_open;
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcps_poolinfo
|
||||
*===========================================================================
|
||||
* Data structure used when configuring pools on subnets
|
||||
*/
|
||||
typedef struct Ipdhcps_poolinfo_struct
|
||||
{
|
||||
Ip_u32 first_addr; /* First address in pool. Network byte order */
|
||||
Ip_u32 last_addr; /* Last address in pool. Network byte order */
|
||||
char *classname; /* Allowed classname */
|
||||
}
|
||||
Ipdhcps_poolinfo;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcps_classinfo
|
||||
*===========================================================================
|
||||
* Data structure used when configuring classes on subnets
|
||||
*/
|
||||
#define IPDHCPS_CLASSNAME_MAX 20
|
||||
|
||||
typedef struct Ipdhcps_classinfo_struct
|
||||
{
|
||||
Ip_bool data_is_string;
|
||||
char *name;
|
||||
Ip_u8 *data;
|
||||
Ip_u16 priv_data_len;
|
||||
}
|
||||
Ipdhcps_classinfo;
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcps_init
|
||||
*===========================================================================
|
||||
* Description: Initiate IPDHCPS
|
||||
* Parameters:
|
||||
* Returns: IPCOM_SUCCESS - success
|
||||
* other - failure
|
||||
*/
|
||||
IP_PUBLIC Ip_err ipdhcps_create(void);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcps_exit
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err ipdhcps_start(void);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_version
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC const char *ipdhcps_version(void);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ipdhcps_interface_status_set - set the status for an interface handled by
|
||||
* IPDHCPS
|
||||
*
|
||||
* This routine sets the status for an interface handled by IPDHCPS. The
|
||||
* interface is specified by its name.
|
||||
*
|
||||
* Parameters:
|
||||
* \is
|
||||
* \i <ifname>
|
||||
* Name of interface.
|
||||
* \i <status>
|
||||
* Enable ('IP_TRUE') or disable ('IP_FALSE') the interface.
|
||||
* \ie
|
||||
*
|
||||
* RETURNS: Either 'IPCOM_SUCCESS', on success, or the following error:
|
||||
* \is
|
||||
* \i 'IPCOM_ERR_NOT_FOUND'
|
||||
* No interface with specifie name found.
|
||||
* \ie
|
||||
*
|
||||
* ERRNO:
|
||||
*/
|
||||
IP_GLOBAL Ip_err ipdhcps_interface_status_set
|
||||
(
|
||||
char* ifname,
|
||||
Ip_bool status
|
||||
);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ipdhcps_class_add - add a new client class to a subnet
|
||||
*
|
||||
* This routine adds a new client class to an existing <subnet> specified by its
|
||||
* address.
|
||||
*
|
||||
* If the address 'IP_INADDR_ANY' is used as the subnet address, the class will be
|
||||
* configured on the defaults net.
|
||||
*
|
||||
* Parameters:
|
||||
* \is
|
||||
* \i <subnet>
|
||||
* IPv4 address of the subnet, in network byte order.
|
||||
* \i <client_class>
|
||||
* Pointer to the class descriptor.
|
||||
* \ie
|
||||
*
|
||||
* RETURNS: 'IPCOM_SUCCESS', or one of the following errors:
|
||||
* \is
|
||||
* \i 'IPCOM_ERR_NOT_OPENED'
|
||||
* IPDHCPS not started.
|
||||
* \i 'IPCOM_ERR_NOT_FOUND'
|
||||
* <Subnet> does not exist.
|
||||
* \i 'IPCOM_ERR_INVALID_ARG'
|
||||
* Invalid net address.
|
||||
* \i 'IPCOM_ERR_ALREADY_INSTALLED'
|
||||
* <class> already exists on <subnet>
|
||||
* \i 'IPCOM_ERR_NO_MEMORY'
|
||||
* Out of memory.
|
||||
* \ie
|
||||
*
|
||||
* ERRNO:
|
||||
*/
|
||||
IP_PUBLIC Ip_err ipdhcps_class_add
|
||||
(
|
||||
Ip_u32 subnet,
|
||||
Ipdhcps_classinfo *client_class
|
||||
);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ipdhcps_class_delete - delete a client class from a subnet
|
||||
*
|
||||
* This routine deletes a client class from an existing <subnet> specified by its
|
||||
* address.
|
||||
*
|
||||
* If the address 'IP_INADDR_ANY' is used as the subnet address, the class will be
|
||||
* removed from the defaults net.
|
||||
*
|
||||
* Parameters:
|
||||
* \is
|
||||
* \i <subnet>
|
||||
* IPv4 address of the subnet, in network byte order.
|
||||
* \i <classname>
|
||||
* The name of the client class
|
||||
* \ie
|
||||
*
|
||||
* RETURNS: 'IPCOM_SUCCESS', or one of the following errors:
|
||||
* \is
|
||||
* \i 'IPCOM_ERR_NOT_OPENED'
|
||||
* IPDHCPS not started.
|
||||
* \i 'IPCOM_ERR_NOT_FOUND'
|
||||
* <Subnet> or <classname> does not exist.
|
||||
* \ie
|
||||
*
|
||||
* ERRNO:
|
||||
*/
|
||||
IP_PUBLIC Ip_err ipdhcps_class_delete
|
||||
(
|
||||
Ip_u32 subnet,
|
||||
char *classname
|
||||
);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ipdhcps_subnet_add - add a new subnet descriptor to the configuration database
|
||||
*
|
||||
* This routine adds a new subnet descriptor to the IPDHCPS configuration
|
||||
* database.
|
||||
*
|
||||
* The subnet is defined by the subnet address. The net mask to be used by the
|
||||
* subnet is given in the DHCP option list (option code
|
||||
* 'IPDHCPS_OPTCODE_SUBNET_MASK').
|
||||
*
|
||||
* Parameters:
|
||||
* \is
|
||||
* \i <subnet>
|
||||
* IPv4 address of the subnet, in network byte order.
|
||||
* \i <pools>
|
||||
* Array of address pools to be mapped on the subnet.
|
||||
* \i <n_pools>
|
||||
* Number of elements in the array of address pools.
|
||||
* \i <dhcps_options>
|
||||
* Pointer to an array of DHCP options of standard DHCP format.
|
||||
* \i <conf_options>
|
||||
* Pointer to an array of config options of standard DHCP format.
|
||||
* \ie
|
||||
*
|
||||
* RETURNS: 'IPCOM_SUCCESS', or one of the following errors:
|
||||
* \is
|
||||
* \i 'IPCOM_ERR_NOT_OPENED'
|
||||
* IPDHCPS not started.
|
||||
* \i 'IPCOM_ERR_ALREADY_INSTALLED'
|
||||
* Subnet already exists.
|
||||
* \i 'IPCOM_ERR_NO_MEMORY'
|
||||
* Out of memory.
|
||||
* \ie
|
||||
*
|
||||
* ERRNO:
|
||||
*/
|
||||
IP_PUBLIC Ip_err ipdhcps_subnet_add
|
||||
(
|
||||
Ip_u32 subnet,
|
||||
Ipdhcps_poolinfo pools[],
|
||||
Ip_u32 n_pools,
|
||||
Ip_u8 *dhcp_options,
|
||||
Ip_u8 *conf_options
|
||||
);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ipdhcps_subnet_delete - delete a subnet descriptor from IPDHCPS configuration
|
||||
* database
|
||||
*
|
||||
* This routine deletes a subnet descriptor from the IPDHCPS configuration
|
||||
* database. The subnet is defined by its address.
|
||||
*
|
||||
* Parameter:
|
||||
* \is
|
||||
* \i <subnet>
|
||||
* IPv4 address of the subnet, in network byte order.
|
||||
* \ie
|
||||
*
|
||||
* RETURNS: 'IPCOM_SUCCESS', or one of the following errors:
|
||||
* \is
|
||||
* \i 'IPCOM_ERR_NOT_OPENED'
|
||||
* IPDHCPS not started.
|
||||
* \i 'IPCOM_ERR_NOT_FOUND'
|
||||
* <Subnet> does not exist.
|
||||
* \i 'IPCOM_ERR_INVALID_ARG'
|
||||
* Invalid net address.
|
||||
* \ie
|
||||
*
|
||||
* ERRNO:
|
||||
*/
|
||||
IP_PUBLIC Ip_err ipdhcps_subnet_delete
|
||||
(
|
||||
Ip_u32 subnet
|
||||
);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ipdhcps_host_add - add a new host descriptor to the IPDHCPS configuration
|
||||
*
|
||||
* This routine adds a new host descriptor to the IPDHCPS configuration.
|
||||
*
|
||||
* The host is defined by its IPv4 address and identified by either its
|
||||
* link-layer address and/or by a client-identifier. The latter has to be
|
||||
* attached to the list of DHCP options bound to the host (option code
|
||||
* 'IPDHCPS_OPTCODE_CLIENT_IDENTIFIER').
|
||||
*
|
||||
* The hosts\' link-layer address can be left out if a client identifier is
|
||||
* specified. IPDHCPS will then use this id only for client identification.
|
||||
*
|
||||
* If both link-layer address and a client identifier are specified the
|
||||
* identification will be done first by the identifier and then by the address.
|
||||
*
|
||||
* Parameters:
|
||||
* \is
|
||||
* \i <addr>
|
||||
* IPv4 address of the host (network byte order).
|
||||
* \i <hwaddr>
|
||||
* Pointer to hosts link-layer address.
|
||||
* \i <hwlen>
|
||||
* Length of link-layer address.
|
||||
* \i <dhcp_options>
|
||||
* List of hosts DHCP options of standard DHCP format.
|
||||
* \i <config_options>
|
||||
* List of hosts <config_options> of standard DHCP format.
|
||||
* \ie
|
||||
*
|
||||
* RETURNS: 'IPCOM_SUCCESS', or one of the following errors:
|
||||
* \is
|
||||
* \i 'IPCOM_ERR_NOT_OPENED'
|
||||
* IPDHCPS not started.
|
||||
* \i 'PCOM_ERR_ALREADY_INSTALLED'
|
||||
* Host already exists.
|
||||
* \i 'IPCOM_ERR_NO_MEMORY'
|
||||
* Out of memory.
|
||||
* \ie
|
||||
*
|
||||
* ERRNO:
|
||||
*/
|
||||
IP_PUBLIC Ip_err ipdhcps_host_add
|
||||
(
|
||||
Ip_u32 addr,
|
||||
Ip_u8 *hwaddr,
|
||||
Ip_u8 len,
|
||||
Ip_u8 *dhcp_options,
|
||||
Ip_u8 *conf_options
|
||||
);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ipdhcps_host_delete - delete a host descriptor from the IPDHCPS configuration
|
||||
*
|
||||
* This routine deletes a host descriptor from the IPDHCPS configuration. The
|
||||
* host is defined by its IPv4 address.
|
||||
*
|
||||
* Parameter:
|
||||
* \is
|
||||
* \i <addr>
|
||||
* IPv4 address of host.
|
||||
* \ie
|
||||
*
|
||||
* RETURNS: 'IPCOM_SUCCESS', or one of the following errors:
|
||||
* \is
|
||||
* \i 'IPCOM_ERR_NOT_OPENED'
|
||||
* IPDHCPS not started.
|
||||
* \i 'IPCOM_ERR_NOT_FOUND'
|
||||
* Host not found.
|
||||
* \i 'IPCOM_ERR_INVALID_ARG'
|
||||
* Invalid host address.
|
||||
* \ie
|
||||
*
|
||||
* ERRNO:
|
||||
*/
|
||||
IP_PUBLIC Ip_err ipdhcps_host_delete
|
||||
(
|
||||
Ip_u32 addr
|
||||
);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ipdhcps_pool_add - add a new address pool to an existing subnet
|
||||
*
|
||||
* This routine adds a new address pool to an existing <subnet> specified by its
|
||||
* address. The pool is defined by its first address and last address.
|
||||
*
|
||||
* If the address 'IP_INADDR_ANY' is used as the subnet address, the pool will be
|
||||
* configured on the defaults net.
|
||||
*
|
||||
* Parameters:
|
||||
* \is
|
||||
* \i <subnet>
|
||||
* IPv4 address of the subnet, in network byte order.
|
||||
* \i <pool>
|
||||
* Pointer to the pool descriptor.
|
||||
* \ie
|
||||
*
|
||||
* RETURNS: 'IPCOM_SUCCESS', or one of the following errors:
|
||||
* \is
|
||||
* \i 'IPCOM_ERR_NOT_OPENED'
|
||||
* IPDHCPS not started.
|
||||
* \i 'IPCOM_ERR_NOT_FOUND'
|
||||
* <Subnet> does not exist.
|
||||
* \i 'IPCOM_ERR_INVALID_ARG'
|
||||
* Invalid net address.
|
||||
* \i 'IPCOM_ERR_ALREADY_INSTALLED'
|
||||
* <Pool> already exists on <subnet> (in part or completely).
|
||||
* \ie
|
||||
*
|
||||
* ERRNO:
|
||||
*/
|
||||
IP_PUBLIC Ip_err ipdhcps_pool_add
|
||||
(
|
||||
Ip_u32 subnet,
|
||||
Ipdhcps_poolinfo *pool
|
||||
);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ipdhcps_pool_delete - delete an existing address pool on a defined subnet
|
||||
*
|
||||
* This routine deletes an existing address <pool> on a defined subnet specified
|
||||
* by its subnet address. The address <pool> is defined by its first address and
|
||||
* last address.
|
||||
*
|
||||
* If the address 'IP_INADDR_ANY' is used as subnet address the pool will be
|
||||
* deleted on the defaults net.
|
||||
*
|
||||
* Parameters:
|
||||
* \is
|
||||
* \i <subnet>
|
||||
* IPv4 address of <subnet>.
|
||||
* \i <pool>
|
||||
* Pointer to <pool> descriptor.
|
||||
* \ie
|
||||
*
|
||||
* RETURNS: 'IPCOM_SUCCESS', or one of the following errors:
|
||||
* \is
|
||||
* \i 'IPCOM_ERR_NOT_OPENED'
|
||||
* IPDHCPS not started.
|
||||
* \i 'IPCOM_ERR_NOT_FOUND'
|
||||
* <Pool> not found on specified <subnet>.
|
||||
* \ie
|
||||
*
|
||||
* ERRNO:
|
||||
*/
|
||||
IP_PUBLIC Ip_err ipdhcps_pool_delete
|
||||
(
|
||||
Ip_u32 subnet,
|
||||
Ipdhcps_poolinfo *pool
|
||||
);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ipdhcps_option_add - add a new set of DHCP/CONFIG options to a subnet or host
|
||||
*
|
||||
* This routine adds a new set of DHCP or CONFIG options to a subnet or host as
|
||||
* specified by the IPv4 address. An option with a code that already exists on
|
||||
* the subnet/host will be replaced by the new one in the set.
|
||||
*
|
||||
* Using 'IP_INADDR_ANY' as address parameter will make IPDHCPS apply the
|
||||
* operation to the system global default DHCP option list.
|
||||
*
|
||||
* Parameters:
|
||||
* \is
|
||||
* \i <addr>
|
||||
* IPv4 address of either a host or subnet in network byte order.
|
||||
* \i <classname>
|
||||
* Name of specific client class. Set to IP_NULL if no client class
|
||||
* \i <type>
|
||||
* Option type. Either IPDHCPS_OPT_DHCP or IPDHCPS_OPT_CONF
|
||||
* \i <options>
|
||||
* List of DHCP or CONFIG options.
|
||||
* \ie
|
||||
*
|
||||
* RETURNS: 'IPCOM_SUCCESS', or one of the following errors:
|
||||
* \is
|
||||
* \i 'IPCOM_ERR_NOT_OPENED'
|
||||
* IPDHCPS not started.
|
||||
* \i 'IPCOM_ERR_NOT_FOUND'
|
||||
* No host or subnet with specified address found.
|
||||
* \ie
|
||||
*
|
||||
* ERRNO:
|
||||
*/
|
||||
IP_PUBLIC Ip_err ipdhcps_option_add
|
||||
(
|
||||
Ip_u32 addr,
|
||||
char *classname,
|
||||
Ip_u16 type,
|
||||
Ip_u8 *options
|
||||
);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ipdhcps_option_delete - delete a DHCP or CONFIG option
|
||||
*
|
||||
* Delete a DHCP option specified by its code and defined on a host or subnet as
|
||||
* specified by the address.
|
||||
*
|
||||
* Using 'IP_INADDR_ANY' as address parameter will make IPDHCPS apply the
|
||||
* operation to the system global default DHCP option list.
|
||||
*
|
||||
* Parameters:
|
||||
* \is
|
||||
* \i <addr>
|
||||
* IPv4 address of host or subnet in network byte order.
|
||||
* \i <class>
|
||||
* Name of specific client class. Set to IP_NULL if no client class
|
||||
* \i <type>
|
||||
* Option type. Either IPDHCPS_OPT_DHCP or IPDHCPS_OPT_CONF
|
||||
* \i <option_code>
|
||||
* DHCP or CONFIG option code for option to be deleted.
|
||||
* \ie
|
||||
*
|
||||
* RETURNS: 'IPCOM_SUCCESS', or one of the following errors:
|
||||
* \is
|
||||
* \i 'IPCOM_ERR_NOT_OPENED'
|
||||
* PDHCPS not started.
|
||||
* \i 'IPCOM_ERR_NOT_FOUND'
|
||||
* No host or subnet with specified address found.
|
||||
* \ie
|
||||
*
|
||||
* ERRNO:
|
||||
*/
|
||||
IP_PUBLIC Ip_err ipdhcps_option_delete
|
||||
(
|
||||
Ip_u32 addr,
|
||||
char *classname,
|
||||
Ip_u16 type,
|
||||
Ip_u8 option_code
|
||||
);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ipdhcps_lease_db_dump - dump entries in the lease database to a data buffer
|
||||
*
|
||||
* This routine dumps the current entries in the lease database to a data buffer.
|
||||
*
|
||||
* This function is part of the IPDHCPS lease dump API intended to let IPDHCPS
|
||||
* utilize persistent storage of the lease database to make it survive a restart
|
||||
* of the server.
|
||||
*
|
||||
* The function can for instance be used when the server is running on systems
|
||||
* supplied with a file system or a non-volatile memory.
|
||||
*
|
||||
* Example: Call it from within the IPDHCPS stop hook, together with extra target
|
||||
* specific code to let the server save its current lease database.
|
||||
*
|
||||
* It is important to know that the contents of the data buffer are created from
|
||||
* the lease database only. It does not contain any configuration settings.
|
||||
*
|
||||
* The data buffer must be freed by the caller upon exit (using ipcom_free
|
||||
* (buffer pointer)).
|
||||
*
|
||||
* Parameter:
|
||||
* \is
|
||||
* \i <obj>
|
||||
* Reference to pointer to dump buffer.
|
||||
* \ie
|
||||
*
|
||||
* RETURNS: 'IPCOM_SUCCESS', or the following error:
|
||||
* \is
|
||||
* \i 'IPCOM_ERR_FAILED'
|
||||
* Failure.
|
||||
* \ie
|
||||
*
|
||||
* ERRNO:
|
||||
*/
|
||||
IP_PUBLIC int ipdhcps_lease_db_dump
|
||||
(
|
||||
void* obj
|
||||
);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* ipdhcps_lease_db_restore - initialize the IPDHCPS lease database
|
||||
*
|
||||
* This routine initializes the IPDHCPS lease database with data from an
|
||||
* externally provided data buffer.
|
||||
*
|
||||
* This function is part of the IPDHCPS lease dump API intended to let IPDHCPS
|
||||
* utilize persistent storage of the lease database to make it survive a restart
|
||||
* of the server.
|
||||
*
|
||||
* The function can for instance be used when the server is running on systems
|
||||
* supplied with a file system or a non-volatile memory.
|
||||
*
|
||||
* Example: Call it from the IPDHCPS start hook together with extra target
|
||||
* specific code to let the server restore its lease database from a previous
|
||||
* session.
|
||||
*
|
||||
* It is important that all configurations of subnets and address pools are done
|
||||
* before restoring the lease database. The function will drop all leases that do
|
||||
* not match the current configuration.
|
||||
*
|
||||
* Parameter:
|
||||
* \is
|
||||
* \i <obj>
|
||||
* Reference to pointer to dump buffer.
|
||||
* \ie
|
||||
*
|
||||
* RETURNS: 'IPCOM_SUCCESS,' , or the following error:
|
||||
* \is
|
||||
* \i 'IPCOM_ERR_FAILED'
|
||||
* Failure.
|
||||
* \ie
|
||||
*
|
||||
* ERRNO:
|
||||
*/
|
||||
IP_PUBLIC Ip_err ipdhcps_lease_db_restore
|
||||
(
|
||||
void *obj
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcps_cmd_dhcps
|
||||
*===========================================================================
|
||||
* Description: Install IPDHCPS shell commands
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
#ifdef IPDHCPS_INCLUDE_CMD
|
||||
IP_GLOBAL int Ipdhcps_cmd_dhcps(int argc, char **argv);
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_configure
|
||||
*===========================================================================
|
||||
* Description:
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
ipdhcps_configure(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,530 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipdhcps_leasedump.c,v $ $Revision: 1.13.16.4 $
|
||||
* $Source: /home/interpeak/CVSRoot/ipdhcps/src/ipdhcps_leasedump.c,v $
|
||||
* $Author: svc-cmnet $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
*
|
||||
* Design and implementation by Jonas Rendel <jonas@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "ipdhcps_config.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_os.h>
|
||||
#include <ipcom_sock.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_tmo2.h>
|
||||
#include <ipcom_type.h>
|
||||
|
||||
#include "ipdhcps.h"
|
||||
#include "ipdhcps_h.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Magic number used to verify a lease dump
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define IPDHCPS_DUMP_MAGIC (0x47111881)
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Version of lease dump format
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define IPDHCPS_DUMP_VERSION (1)
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Size of memory chunk allocated for lease dumping
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define IPDHCPS_LEASE_MALLOC_SZ (512)
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcps_lease_info_struct
|
||||
*===========================================================================
|
||||
* Lease descriptor data structure.
|
||||
*/
|
||||
|
||||
typedef IP_PACKED struct Ipdhcps_lease_info_struct
|
||||
{
|
||||
Ip_u32 yiaddr;
|
||||
Ip_u8 binding_state;
|
||||
Ip_time_t lease_time;
|
||||
Ip_time_t expires;
|
||||
Ip_u8 hlen;
|
||||
Ip_u8 haddr[20];
|
||||
Ip_u8 cid_len;
|
||||
Ip_u8 cid[1];
|
||||
}
|
||||
Ipdhcps_lease_info;
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcps_lease_buf_struct
|
||||
*===========================================================================
|
||||
* Data structure used when collecting lease info from the database.
|
||||
*/
|
||||
|
||||
typedef IP_PACKED struct Ipdhcps_lease_buf_struct
|
||||
{
|
||||
struct Ipdhcps_lease_buf_struct *next;
|
||||
Ip_u32 n_entries;
|
||||
Ip_u32 n_bytes;
|
||||
Ip_u8 *current;
|
||||
Ip_u8 lease_info[1];
|
||||
}
|
||||
Ipdhcps_lease_buf;
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcps_lease_dump_struct
|
||||
*===========================================================================
|
||||
* Structure describing a lease dump.
|
||||
*/
|
||||
|
||||
typedef IP_PACKED struct Ipdhcps_lease_dump_struct
|
||||
{
|
||||
Ip_u32 magic;
|
||||
Ip_u8 version;
|
||||
Ip_time_t timestamp;
|
||||
Ip_u32 checksum;
|
||||
Ip_u32 n_words;
|
||||
Ip_u32 n_entries;
|
||||
Ip_u8 lease_info[1];
|
||||
}
|
||||
Ipdhcps_lease_dump;
|
||||
|
||||
IP_STATIC char logbuf[50];
|
||||
IP_EXTERN const char *ipdhcps_binding_state_str[];
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_EXTERN Ipdhcps_data ipdhcpsc;
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC void ipdhcps_lease_dump_cb(void* obj, void* data);
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_lease_db_dump
|
||||
*===========================================================================
|
||||
* Description: Callback function applied when traversing the lease database
|
||||
*
|
||||
* Parameters: obj - Pointer to lease descriptor.
|
||||
* data - Pointer to lease buf descriptor (partial dump)
|
||||
*
|
||||
* Returns: -
|
||||
*/
|
||||
IP_STATIC void
|
||||
ipdhcps_lease_dump_cb(void* obj, void* data)
|
||||
{
|
||||
Ipdhcps_lease *l = (Ipdhcps_lease*)obj;
|
||||
Ipdhcps_lease_buf *b = (Ipdhcps_lease_buf*)data;
|
||||
Ipdhcps_lease_info *current;
|
||||
Ip_size_t len;
|
||||
|
||||
if(l->binding_state != IPDHCPS_BINDING_STATE_PERMANENT)
|
||||
{
|
||||
len = l->cid_len + sizeof(Ipdhcps_lease_info);
|
||||
|
||||
for(; b->next != IP_NULL; b = b->next);
|
||||
|
||||
if((len + b->n_bytes) > IPDHCPS_LEASE_MALLOC_SZ)
|
||||
{
|
||||
/* coverity[suspicious_sizeof] */
|
||||
b->next = (Ipdhcps_lease_buf *)ipcom_malloc(IPDHCPS_LEASE_MALLOC_SZ);
|
||||
|
||||
if(b->next == IP_NULL)
|
||||
return;
|
||||
|
||||
b = b->next;
|
||||
ipcom_memset(b, 0 , IPDHCPS_LEASE_MALLOC_SZ);
|
||||
b->current = &b->lease_info[0];
|
||||
}
|
||||
|
||||
current =(Ipdhcps_lease_info*)b->current;
|
||||
|
||||
current->yiaddr = l->yiaddr;
|
||||
current->binding_state = l->binding_state;
|
||||
current->expires = l->expires;
|
||||
current->lease_time = l->lease_time;
|
||||
current->hlen = (Ip_u8)l->chaddr.hlen;
|
||||
current->cid_len = (Ip_u8)l->cid_len;
|
||||
|
||||
ipcom_memcpy(current->haddr, l->chaddr.haddr, l->chaddr.hlen);
|
||||
ipcom_memcpy(current->cid, l->cid, l->cid_len);
|
||||
|
||||
b->n_entries++;
|
||||
b->n_bytes += (Ip_u32)len;
|
||||
b->current += len;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_lease_db_dump
|
||||
*===========================================================================
|
||||
* Description: Dumps the current entries in the lease database to a buffer
|
||||
* that can be saved to a file system or flash by user
|
||||
* supplied code;
|
||||
*
|
||||
* NOTE! The returned buffer must be freed by a calling
|
||||
* ipcom_free.
|
||||
*
|
||||
* Parameters: -
|
||||
*
|
||||
* Returns: Pointer to dump buffer - success
|
||||
* IP_NULL - failure or empry lease database.
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC int
|
||||
ipdhcps_lease_db_dump(void *obj)
|
||||
{
|
||||
int retval;
|
||||
Ipdhcps_lease_buf *head, *l;
|
||||
Ipdhcps_lease_dump **dump;
|
||||
Ip_u32 n_bytes, w;
|
||||
Ip_size_t dumpsize;
|
||||
Ip_u8 *ptr;
|
||||
|
||||
dump = obj;
|
||||
|
||||
/* coverity[suspicious_sizeof] */
|
||||
head = (Ipdhcps_lease_buf *)ipcom_malloc(IPDHCPS_LEASE_MALLOC_SZ);
|
||||
|
||||
if(head == IP_NULL)
|
||||
IPDHCPS_LEAVE(-1);
|
||||
|
||||
ipcom_memset(head, 0, IPDHCPS_LEASE_MALLOC_SZ);
|
||||
|
||||
head->current = head->lease_info;
|
||||
|
||||
(void)ipdhcps_lease_for_each(ipdhcps_lease_dump_cb, head);
|
||||
|
||||
for(l = head, n_bytes = 0; l != IP_NULL; l = l->next)
|
||||
n_bytes += l->n_bytes;
|
||||
|
||||
if(n_bytes & 0x03)
|
||||
n_bytes = (n_bytes & 0xfffffffc) + 4;
|
||||
|
||||
dumpsize = n_bytes + sizeof(Ipdhcps_lease_dump);
|
||||
*dump = ipcom_malloc(dumpsize);
|
||||
|
||||
if(*dump == IP_NULL)
|
||||
IPDHCPS_LEAVE(-1);
|
||||
|
||||
ipcom_memset(*dump, 0, dumpsize);
|
||||
|
||||
ptr = (*dump)->lease_info;
|
||||
for(l = head; l != IP_NULL; l = l->next)
|
||||
{
|
||||
ipcom_memcpy(ptr, l->lease_info, l->n_bytes);
|
||||
ptr += l->n_bytes;
|
||||
(*dump)->n_entries += l->n_entries;
|
||||
}
|
||||
|
||||
(*dump)->magic = IPDHCPS_DUMP_MAGIC;
|
||||
(*dump)->version = IPDHCPS_DUMP_VERSION;
|
||||
(*dump)->n_words = n_bytes/4;
|
||||
(*dump)->timestamp = ipcom_time(0);
|
||||
|
||||
/* Checksum 32-bitwise */
|
||||
for(w = 0; w < (*dump)->n_words; w += 4)
|
||||
(*dump)->checksum += *(Ip_u32*)&(*dump)->lease_info[w];
|
||||
|
||||
retval = (int)dumpsize;
|
||||
|
||||
leave:
|
||||
|
||||
for(; head != IP_NULL; head = l)
|
||||
{
|
||||
l = (Ipdhcps_lease_buf*)head->next;
|
||||
ipcom_free(head);
|
||||
}
|
||||
|
||||
return (retval);
|
||||
}
|
||||
|
||||
IP_STATIC Ipdhcps_lease*
|
||||
ipdhcps_host_lease_checkout_for_restore(Ipdhcps_subnet* subnet,
|
||||
Ip_u32 req_addr)
|
||||
{
|
||||
Ipdhcps_pool *p;
|
||||
Ipdhcps_lease *requested_lease = IP_NULL;
|
||||
Ipdhcps_lease *first_free_lease = IP_NULL;
|
||||
Ipdhcps_lease *first_avail_lease = IP_NULL;
|
||||
Ipdhcps_lease *returned_lease;
|
||||
Ip_u32 i;
|
||||
|
||||
|
||||
req_addr = ip_ntohl(req_addr);
|
||||
|
||||
/* Check if requested address is valid and not occupied */
|
||||
IPDHCPS_LIST_FOREACH(p, (&subnet->pools), Ipdhcps_pool*)
|
||||
{
|
||||
#if 0
|
||||
/* Do some class verifications */
|
||||
if (client_class == IP_NULL && p->class_id != IP_NULL)
|
||||
continue;
|
||||
|
||||
if (client_class != IP_NULL && p->class_id == IP_NULL)
|
||||
continue;
|
||||
|
||||
if (client_class != IP_NULL && p->class_id != IP_NULL)
|
||||
{
|
||||
if ((client_class[IPDHCPS_OPT_CODE] != p->class_id[IPDHCPS_OPT_CODE])
|
||||
|| (client_class[IPDHCPS_OPT_LEN] != p->class_id[IPDHCPS_OPT_LEN])
|
||||
|| (ipcom_memcmp(&client_class[IPDHCPS_OPT_DATA], &p->class_id[IPDHCPS_OPT_DATA], (Ip_size_t)p->class_id[IPDHCPS_OPT_LEN]) != 0))
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
if((req_addr <= p->yiaddr_max) && (req_addr >= p->yiaddr_min))
|
||||
{
|
||||
/* Found requested lease */
|
||||
if(p->leases[req_addr - p->yiaddr_min]->binding_state
|
||||
== IPDHCPS_BINDING_STATE_FREE)
|
||||
{
|
||||
/* Lease can be used by client */
|
||||
requested_lease = p->leases[req_addr - p->yiaddr_min];
|
||||
first_free_lease = requested_lease;
|
||||
break;
|
||||
}
|
||||
else if(first_free_lease != IP_NULL)
|
||||
{
|
||||
/* Requested lease can not be used, but we have found a free one */
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(first_free_lease == IP_NULL)
|
||||
{
|
||||
for(i = 0; i <= (p->yiaddr_max - p->yiaddr_min); i++)
|
||||
{
|
||||
if(p->leases[i]->binding_state == IPDHCPS_BINDING_STATE_FREE)
|
||||
{
|
||||
first_free_lease = p->leases[i];
|
||||
break;
|
||||
}
|
||||
else if((first_avail_lease == IP_NULL) &&
|
||||
((p->leases[i]->binding_state == IPDHCPS_BINDING_STATE_EXPIRED) ||
|
||||
(p->leases[i]->binding_state == IPDHCPS_BINDING_STATE_RELEASED)))
|
||||
{
|
||||
first_avail_lease = p->leases[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
returned_lease = requested_lease != IP_NULL ? requested_lease : first_free_lease;
|
||||
returned_lease = returned_lease != IP_NULL ? returned_lease : first_avail_lease;
|
||||
|
||||
if(returned_lease == IP_NULL)
|
||||
{
|
||||
/* We have no leases to offer */
|
||||
IPCOM_LOG0(DEBUG,"ipdhcps_daemon :: no leases to offer client");
|
||||
}
|
||||
else if(returned_lease == first_avail_lease)
|
||||
{
|
||||
/* This lease was not free. Print a warning */
|
||||
IPCOM_LOG2(WARNING,
|
||||
"ipdhcps_daemon :: reusing %s lease with address %s for new client",
|
||||
ipdhcps_binding_state_str[returned_lease->binding_state],
|
||||
ipcom_inet_ntop(IP_AF_INET,
|
||||
&returned_lease->yiaddr,
|
||||
logbuf,
|
||||
sizeof(logbuf)));
|
||||
|
||||
/* Delete it from lease database */
|
||||
(void)ipdhcps_lease_delete(returned_lease);
|
||||
}
|
||||
|
||||
return(returned_lease);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_lease_db_restore
|
||||
*===========================================================================
|
||||
* Description: Initiates the lease database with data from a user
|
||||
* supplied data buffer.
|
||||
*
|
||||
* NOTE! The buffer must be freed by the caller.
|
||||
*
|
||||
* Parameters: Pointer to lease dump data buffer.
|
||||
*
|
||||
* Returns: IPCOM_SUCCESS - success
|
||||
* other - failure
|
||||
*
|
||||
*/
|
||||
IP_PUBLIC Ip_err
|
||||
ipdhcps_lease_db_restore(void *obj)
|
||||
{
|
||||
Ip_err retval;
|
||||
Ipdhcps_lease_dump *dump = (Ipdhcps_lease_dump*)obj;
|
||||
Ip_u32 checksum;
|
||||
Ip_u32 i;
|
||||
Ipdhcps_lease_info *b;
|
||||
Ipdhcps_subnet *s;
|
||||
Ipdhcps_lease *l;
|
||||
char buf [20];
|
||||
|
||||
|
||||
if(dump->magic != IPDHCPS_DUMP_MAGIC)
|
||||
IPDHCPS_LEAVE(IPCOM_ERR_INVALID_CONFIG);
|
||||
|
||||
if(dump->version != IPDHCPS_DUMP_VERSION)
|
||||
IPDHCPS_LEAVE(IPCOM_ERR_INVALID_VERSION);
|
||||
|
||||
for(checksum = 0, i = 0; i < dump->n_words; i+=4)
|
||||
checksum += *(Ip_u32*)&dump->lease_info[i];
|
||||
|
||||
if(checksum != dump->checksum)
|
||||
IPDHCPS_LEAVE(IPCOM_ERR_FAILED);
|
||||
|
||||
for(i = 0;
|
||||
(i <(dump->n_words*4)) && (dump->n_entries > 0);
|
||||
i += ((Ip_u8)sizeof(Ipdhcps_lease_info) + b->cid_len))
|
||||
{
|
||||
b = (Ipdhcps_lease_info*)&dump->lease_info[i];
|
||||
dump->n_entries--;
|
||||
|
||||
s = ipdhcps_subnet_find_matching(b->yiaddr);
|
||||
s = s == IP_NULL ? ipdhcpsc.default_net : s;
|
||||
|
||||
l = ipdhcps_host_lease_checkout_for_restore(s, b->yiaddr);
|
||||
|
||||
if((l == IP_NULL) || (l->yiaddr != b->yiaddr))
|
||||
{
|
||||
(void)ipcom_inet_ntop(IP_AF_INET, &b->yiaddr, buf, sizeof(buf));
|
||||
IPCOM_LOG1(DEBUG,
|
||||
"ipdhcps lease readback :: no lease found for address %s, ignoring",
|
||||
buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(l->binding_state != IPDHCPS_BINDING_STATE_FREE)
|
||||
{
|
||||
(void)ipcom_inet_ntop(IP_AF_INET, &b->yiaddr, buf, sizeof(buf));
|
||||
IPCOM_LOG1(DEBUG,
|
||||
"ipdhcps lease readback :: lease found for address %s is not free, ignoring",
|
||||
buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(b->cid_len > 0)
|
||||
{
|
||||
l->cid = ipcom_malloc(b->cid_len);
|
||||
|
||||
if(l->cid == IP_NULL)
|
||||
IPDHCPS_LEAVE(IPCOM_ERR_NO_MEMORY);
|
||||
|
||||
ipcom_memcpy(l->cid, b->cid, b->cid_len);
|
||||
}
|
||||
|
||||
l->binding_state = b->binding_state;
|
||||
l->expires = b->expires;
|
||||
l->lease_time = b->lease_time;
|
||||
l->chaddr.hlen = b->hlen;
|
||||
l->cid_len = b->cid_len;
|
||||
|
||||
ipcom_memcpy(l->chaddr.haddr, b->haddr, b->hlen);
|
||||
|
||||
(void)ipdhcps_lease_add(l);
|
||||
}
|
||||
|
||||
retval = IPCOM_SUCCESS;
|
||||
|
||||
leave:
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,439 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipdhcps_packet.c,v $ $Revision: 1.24.10.4 $
|
||||
* $Source: /home/interpeak/CVSRoot/ipdhcps/src/ipdhcps_packet.c,v $
|
||||
* $Author: jren $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
*
|
||||
* Design and implementation by Jonas Rendel <jonas@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "ipdhcps_config.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_inet.h>
|
||||
#include <ipcom_os.h>
|
||||
#include <ipcom_shell.h>
|
||||
#include <ipcom_sock.h>
|
||||
#include <ipcom_sock.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_tmo2.h>
|
||||
#include <ipcom_type.h>
|
||||
|
||||
#include "ipdhcps.h"
|
||||
#include "ipdhcps_h.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef IP_ETH_ADDR_SIZE
|
||||
#define IP_ETH_ADDR_SIZE 6
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_EXTERN Ipdhcps_data ipdhcpsc;
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC Ip_ssize_t ipdhcps_send_to_relay_agent(Ipdhcps_handle *handle);
|
||||
IP_STATIC Ip_ssize_t ipdhcps_send_to_client (Ipdhcps_handle *handle,
|
||||
Ip_bool force_broadcast);
|
||||
IP_STATIC Ip_ssize_t ipdhcps_send_execute (Ipdhcps_handle *handle,
|
||||
Ip_u32 dst, Ip_u16 port);
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC Ip_u8 chaddr_bcast[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_send_to_client
|
||||
*===========================================================================
|
||||
* Description: DHCP send routine used when transmitting to clients that
|
||||
* can be reached directly (no relay agent inbetween).
|
||||
* Because we can not assume that the client will respond to
|
||||
* arp requests we can not use ordinary udp sockets. Instead
|
||||
* we build raw DHCP/UDP/IP packets ourselves and transmit them
|
||||
* on a packet socket using the clients link-layer address.but when
|
||||
* it comes to INFORM MESSAGE, udp socket is a better choice.
|
||||
*
|
||||
* Parameters: handle - pointer to ipdhcps handle
|
||||
* Returns: number of bytes sent. -1 if something failed.
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_ssize_t
|
||||
ipdhcps_send_to_client(Ipdhcps_handle *handle, Ip_bool force_broadcast)
|
||||
{
|
||||
Ip_ssize_t retval;
|
||||
Ip_u32 ciaddr;
|
||||
Ip_u8 *chaddr;
|
||||
int fd;
|
||||
struct Ip_sockaddr_ll dest;
|
||||
|
||||
#define IPDHCPS_MSG_INFORM 8
|
||||
|
||||
if ( handle->saved_msg_type == IPDHCPS_MSG_INFORM&&handle->packet->hdr.ciaddr)
|
||||
return ipdhcps_send_execute (handle, handle->packet->hdr.ciaddr, ipdhcpsc.config.client_port);
|
||||
|
||||
/* Get packet socket to write raw frames on */
|
||||
if((fd = ipcom_socket(IP_AF_PACKET,
|
||||
IP_SOCK_DGRAM,
|
||||
ip_htons(IP_ETH_P_IP))) == IP_INVALID_SOCKET)
|
||||
{
|
||||
IPCOM_LOG0(DEBUG, "ipdhcps_send :: failed to get packet socket.");
|
||||
IPDHCPS_LEAVE(-1);
|
||||
}
|
||||
|
||||
/* Find out destination address */
|
||||
if((force_broadcast == IP_TRUE)
|
||||
|| (ip_ntohs(handle->packet->hdr.flags) & IPDHCPS_BROADCAST_FLAG))
|
||||
{
|
||||
/* Client must be broadcasted to */
|
||||
ciaddr = IP_INADDR_BROADCAST;
|
||||
chaddr = chaddr_bcast;
|
||||
}
|
||||
else if(handle->packet->hdr.ciaddr != 0)
|
||||
{
|
||||
/* Unicast packet to clients ciaddr */
|
||||
ciaddr = handle->packet->hdr.ciaddr;
|
||||
chaddr = handle->packet->hdr.chaddr;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Unicast packet to clients yiaddr */
|
||||
ciaddr = handle->packet->hdr.yiaddr;
|
||||
chaddr = handle->packet->hdr.chaddr;
|
||||
}
|
||||
|
||||
/* Setup destination ll address */
|
||||
ipcom_memset(&dest, 0, sizeof(dest));
|
||||
|
||||
dest.sll_family = IP_AF_PACKET;
|
||||
dest.sll_protocol = ip_htons(IP_ETH_P_IP);
|
||||
dest.sll_ifindex = (Ip_u32)handle->recv_if->ifindex;
|
||||
dest.sll_halen = IP_ETH_ADDR_SIZE;
|
||||
|
||||
ipcom_memcpy(dest.sll_addr, chaddr, IP_ETH_ADDR_SIZE);
|
||||
|
||||
/* Clear IP and UDP headers */
|
||||
ipcom_memset(handle->raw_packet,
|
||||
0,
|
||||
sizeof(Ipcom_ip_header) +
|
||||
sizeof(Ipdhcps_udp_header));
|
||||
|
||||
/* Init headers */
|
||||
handle->raw_packet->ip.protocol = IP_IPPROTO_UDP;
|
||||
handle->raw_packet->ip.src.addr32 = handle->recv_if->siaddr;
|
||||
handle->raw_packet->ip.dst.addr32 = ciaddr;
|
||||
handle->raw_packet->udp.src_port = ip_htons(ipdhcpsc.config.server_port);
|
||||
handle->raw_packet->udp.dst_port = ip_htons(ipdhcpsc.config.client_port);
|
||||
handle->raw_packet->udp.length = (Ip_u16)(ip_htons(sizeof(Ipdhcps_udp_header) + handle->packet_len));
|
||||
handle->raw_packet->ip.length = handle->raw_packet->udp.length;
|
||||
|
||||
/* Calculate UDP checksum (pseudo header+header+payload) */
|
||||
handle->raw_packet->udp.checksum = ipcom_in_checksum((Ip_u16*)handle->raw_packet,
|
||||
sizeof(Ipcom_ip_header) +
|
||||
sizeof(Ipdhcps_udp_header) +
|
||||
handle->packet_len );
|
||||
|
||||
handle->raw_packet->ip.length = (Ip_u16)(ip_htons(sizeof(Ipcom_ip_header) +
|
||||
sizeof(Ipdhcps_udp_header) +
|
||||
handle->packet_len));
|
||||
|
||||
handle->raw_packet->ip.vers_len = 0x40; /* Ipv4 */
|
||||
handle->raw_packet->ip.vers_len |= sizeof(Ipcom_ip_header) / sizeof(Ip_u32);
|
||||
|
||||
handle->raw_packet->ip.ttl = 64;
|
||||
handle->raw_packet->ip.checksum = ipcom_in_checksum((Ip_u16*)&handle->raw_packet->ip,
|
||||
sizeof(Ipcom_ip_header));
|
||||
|
||||
/* Transmit packet */
|
||||
retval = ipcom_sendto(fd,
|
||||
handle->raw_packet,
|
||||
(Ip_size_t) ip_ntohs(handle->raw_packet->ip.length),
|
||||
0,
|
||||
(struct Ip_sockaddr*) &dest,
|
||||
sizeof(struct Ip_sockaddr_ll));
|
||||
leave:
|
||||
|
||||
if(fd != IP_INVALID_SOCKET)
|
||||
ipcom_socketclose(fd);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_send_execute
|
||||
*===========================================================================
|
||||
* Description: DHCP send routine used when transmitting to clients that
|
||||
* can be reached via a relay agent or the ACK is for INFORM.
|
||||
* We use a standard udp socket to send the dhcp packet
|
||||
*
|
||||
* Parameters: handle - pointer to ipdhcps handle
|
||||
* dst - destination
|
||||
* port - remote port
|
||||
* Returns: number of bytes sent. -1 if something failed.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
IP_STATIC Ip_ssize_t
|
||||
ipdhcps_send_execute (Ipdhcps_handle *handle, Ip_u32 dst, Ip_u16 port)
|
||||
{
|
||||
Ip_ssize_t retval;
|
||||
int opt;
|
||||
int fd;
|
||||
struct Ip_sockaddr_in addr;
|
||||
|
||||
if((fd = ipcom_socket(IP_AF_INET,
|
||||
IP_SOCK_DGRAM,
|
||||
IP_IPPROTO_UDP)) == IP_INVALID_SOCKET)
|
||||
{
|
||||
IPCOM_LOG0(DEBUG,"ipdhcps_send :: failed to get socket.");
|
||||
IPDHCPS_LEAVE(-1);
|
||||
}
|
||||
|
||||
opt = 1;
|
||||
if(ipcom_setsockopt(fd,
|
||||
IP_SOL_SOCKET,
|
||||
IP_SO_REUSEADDR,
|
||||
&opt,
|
||||
sizeof(opt)) == -1)
|
||||
{
|
||||
IPCOM_LOG0(DEBUG, "ipdhcps_send :: failed to set sockopt.");
|
||||
IPDHCPS_LEAVE(-1);
|
||||
}
|
||||
|
||||
/* Bind socket to receiving interface */
|
||||
memset(&addr, 0, sizeof(struct Ip_sockaddr_in));
|
||||
addr.sin_family = IP_AF_INET;
|
||||
addr.sin_port = ip_htons(ipdhcpsc.config.server_port);
|
||||
addr.sin_addr.s_addr = handle->recv_if->siaddr;
|
||||
|
||||
if(ipcom_bind(fd,
|
||||
(struct Ip_sockaddr*)&addr,
|
||||
sizeof(struct Ip_sockaddr_in)) == -1)
|
||||
{
|
||||
IPCOM_LOG0(DEBUG, "ipdhcps_send :: failed to bind socket.");
|
||||
IPDHCPS_LEAVE(-1);
|
||||
}
|
||||
|
||||
/* Send to agent */
|
||||
addr.sin_port = ip_htons(port);
|
||||
addr.sin_addr.s_addr = dst;
|
||||
|
||||
retval = ipcom_sendto(fd,
|
||||
handle->packet,
|
||||
handle->packet_len,
|
||||
0,
|
||||
(struct Ip_sockaddr*)&addr,
|
||||
sizeof(struct Ip_sockaddr_in));
|
||||
leave:
|
||||
|
||||
if(fd != IP_INVALID_SOCKET)
|
||||
ipcom_socketclose(fd);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_send_to_relay_agent
|
||||
*===========================================================================
|
||||
* Description: DHCP send routine used when transmitting to clients that
|
||||
* can only be reached via a relay agent.
|
||||
* We use a standard udp socket to send the dhcp packet to
|
||||
* the relay agent in question.
|
||||
*
|
||||
* Parameters: handle - pointer to ipdhcps handle
|
||||
* Returns: number of bytes sent. -1 if something failed.
|
||||
*
|
||||
*/
|
||||
|
||||
IP_STATIC Ip_ssize_t
|
||||
ipdhcps_send_to_relay_agent(Ipdhcps_handle *handle)
|
||||
{
|
||||
ip_assert(handle->packet != IP_NULL);
|
||||
ip_assert(handle->packet->hdr.giaddr != 0);
|
||||
return ipdhcps_send_execute (handle, handle->packet->hdr.giaddr, ipdhcpsc.config.server_port);
|
||||
}
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_send_packet
|
||||
*===========================================================================
|
||||
* Description: Wrapper function for sending dhcp packets.
|
||||
*
|
||||
* Parameters: handle - pointer to ipdhcps handle
|
||||
* Returns: number of bytes sent.
|
||||
* -1 if something failed.
|
||||
*/
|
||||
|
||||
IP_GLOBAL Ip_ssize_t
|
||||
ipdhcps_send_packet(Ipdhcps_handle *handle, Ip_bool force_broadcast)
|
||||
{
|
||||
Ip_ssize_t retval;
|
||||
|
||||
if(handle->packet->hdr.giaddr != 0)
|
||||
retval = ipdhcps_send_to_relay_agent(handle);
|
||||
else
|
||||
retval = ipdhcps_send_to_client(handle, force_broadcast);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcps_receive_packet
|
||||
*===========================================================================
|
||||
* Description: This function is used for receiving packets of type DHCP.
|
||||
* only packets of type DHCP received on interfaces define and
|
||||
* enabled for IPDHCPS are forwarded to the caller.
|
||||
*
|
||||
* Parameters: fd - receive socket descriptor
|
||||
* handle - ipdhcps handle
|
||||
*
|
||||
* Returns: number of bytes received.
|
||||
* -1 if something failed.
|
||||
*/
|
||||
|
||||
IP_GLOBAL Ip_ssize_t
|
||||
ipdhcps_receive_packet(int fd, Ipdhcps_handle *handle)
|
||||
{
|
||||
struct Ip_msghdr msg;
|
||||
struct Ip_iovec iov[1];
|
||||
struct Ip_cmsghdr *cmptr;
|
||||
struct Ip_in_pktinfo *pktinfo;
|
||||
struct Ip_sockaddr_in src_addr;
|
||||
Ip_ssize_t n;
|
||||
union {
|
||||
struct Ip_cmsghdr cm;
|
||||
char control[IP_CMSG_SPACE(sizeof(struct Ip_in_pktinfo))];
|
||||
} control_un;
|
||||
|
||||
iov[0].iov_base = handle->packet;
|
||||
iov[0].iov_len =(Ip_size_t)ipdhcpsc.config.packet_size;
|
||||
|
||||
msg.msg_name = &src_addr;
|
||||
msg.msg_namelen = sizeof(src_addr);
|
||||
msg.msg_iov = iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_control = control_un.control;
|
||||
msg.msg_controllen = sizeof(control_un.control);
|
||||
msg.msg_flags = 0;
|
||||
|
||||
ipcom_memset(&src_addr, 0, sizeof(src_addr));
|
||||
ipcom_memset(iov[0].iov_base, 0, iov[0].iov_len);
|
||||
n = ipcom_recvmsg(fd, &msg, 0);
|
||||
|
||||
if(n > 0)
|
||||
{
|
||||
/* Get info about receiving interface */
|
||||
if(((cmptr = IP_CMSG_FIRSTHDR(&msg)) != IP_NULL) &&
|
||||
cmptr->cmsg_len == IP_CMSG_LEN(sizeof(struct Ip_in_pktinfo)))
|
||||
{
|
||||
pktinfo = (struct Ip_in_pktinfo*)IP_CMSG_DATA(cmptr);
|
||||
handle->recv_if = ipdhcps_interface_find((int)pktinfo->ipi_ifindex);
|
||||
handle->dst_addr = pktinfo->ipi_addr.s_addr;
|
||||
handle->src_addr = src_addr.sin_addr.s_addr;
|
||||
|
||||
/* Drop if interface unknown */
|
||||
if(handle->recv_if == IP_NULL)
|
||||
{
|
||||
IPCOM_LOG1(INFO,
|
||||
"ipdhcps_daemon :: unable to locate interface %d",
|
||||
pktinfo->ipi_ifindex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Drop if interface disabled */
|
||||
if(handle->recv_if->enabled == IP_FALSE
|
||||
|| handle->recv_if->functional == IP_FALSE)
|
||||
return 0;
|
||||
|
||||
/* The vend data could be NULL in BOOTP */
|
||||
if (ip_ntohl(handle->packet->hdr.cookie) == 0)
|
||||
return n;
|
||||
/* Drop if packet is not DHCP */
|
||||
else if(ip_ntohl(handle->packet->hdr.cookie) != IPDHCPS_MAGIC_COOKIE)
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
IPCOM_LOG0(DEBUG, "ipdhcps_receive :: got no interface info");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
Reference in New Issue
Block a user