original files of m241
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,702 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* INTERPEAK SOURCE FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipdhcpr_cmd_dhcpr.c,v $ $Revision: 1.13.10.1 $
|
||||
* $Source: /home/interpeak/CVSRoot/ipdhcpr/src/ipdhcpr_cmd_dhcpr.c,v $
|
||||
* $Author: dgocheno $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Jonas Rendel <jonas@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include "ipdhcpr_config.h"
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#ifdef IPDHCPR_INCLUDE_CMD
|
||||
|
||||
#define IPCOM_USE_CLIB_PROTO
|
||||
#include <ipcom_type.h>
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_clib.h>
|
||||
#include <ipcom_clib2.h>
|
||||
#include <ipcom_syslog.h>
|
||||
#include <ipcom_os.h>
|
||||
#include <ipcom_sock.h>
|
||||
#include <ipcom_err.h>
|
||||
#include <ipcom_shell.h>
|
||||
#include <ipcom_tmo.h>
|
||||
#include <ipcom_sock.h>
|
||||
#include <ipcom_inet.h>
|
||||
#include <ipnet.h>
|
||||
#include <ipnet_cmd.h>
|
||||
#include <ipcom_getopt.h>
|
||||
|
||||
|
||||
#include "ipdhcpr.h"
|
||||
#include "ipdhcpr_h.h"
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#define IPDHCPR_MAX_CMD (sizeof(ipdhcpr_cmd_callback)/sizeof(Ipdhcpr_cmd_cb))
|
||||
#define IPDHCPR_MAX_SUBCMD (sizeof(ipdhcpr_subcmd)/sizeof(char*))
|
||||
|
||||
#define IPDHCPR_SUBCMD_LST (0)
|
||||
#define IPDHCPR_SUBCMD_ADD (1)
|
||||
#define IPDHCPR_SUBCMD_DEL (2)
|
||||
#define IPDHCPR_SUBCMD_ENA (3)
|
||||
#define IPDHCPR_SUBCMD_DIS (4)
|
||||
#define IPDHCPR_SUBCMD_OPT82 (5)
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
typedef struct Ipdhcpr_cmd_cb_struct
|
||||
{
|
||||
char* cmd;
|
||||
Ip_err (*cmd_cb) (int argc, char *argv[], int subcmd);
|
||||
|
||||
}
|
||||
Ipdhcpr_cmd_cb;
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 EXTERN PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_EXTERN Ipdhcpr_data ipdhcprc;
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 7 LOCAL PROTOTYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC void ipdhcpr_server_print (void *obj, void *data);
|
||||
IP_STATIC void ipdhcpr_interface_print(void *obj, void *data);
|
||||
|
||||
IP_STATIC void ipdhcpr_errmsg_print(Ip_err retval);
|
||||
|
||||
IP_STATIC Ip_err ipdhcpr_handle_cmd_server (int argc, char *argv[], int subcmd);
|
||||
IP_STATIC Ip_err ipdhcpr_handle_cmd_interface (int argc, char *argv[], int subcmd);
|
||||
IP_STATIC Ip_err ipdhcpr_handle_cmd_option82 (int argc, char *argv[], int subcmd);
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 8 DATA
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_subcmd
|
||||
*===========================================================================
|
||||
* Description: Text info representing the valid dhcpr subcommands
|
||||
*
|
||||
*/
|
||||
IP_STATIC char* ipdhcpr_subcmd[] =
|
||||
{
|
||||
"list",
|
||||
"add",
|
||||
"delete",
|
||||
"enable",
|
||||
"disable",
|
||||
"option82"
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_cmd_cb
|
||||
*===========================================================================
|
||||
* Description: Ipdhcpr command callback struct.
|
||||
*/
|
||||
IP_STATIC Ipdhcpr_cmd_cb ipdhcpr_cmd_callback[] =
|
||||
{
|
||||
{
|
||||
"server",
|
||||
ipdhcpr_handle_cmd_server
|
||||
},
|
||||
{
|
||||
"interface",
|
||||
ipdhcpr_handle_cmd_interface
|
||||
},
|
||||
{
|
||||
"option82",
|
||||
ipdhcpr_handle_cmd_option82
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 9 STATIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IP_STATIC void
|
||||
ipdhcpr_printf(const char *format, /*args*/ ...)
|
||||
{
|
||||
char *buf;
|
||||
va_list ap;
|
||||
Ip_s32 retval;
|
||||
|
||||
buf = ipcom_malloc(IPCOM_STDIO_BUFSIZE);
|
||||
ip_assert(buf);
|
||||
|
||||
va_start(ap, format);
|
||||
retval = ipcom_vsnprintf(buf, IPCOM_STDIO_BUFSIZE, format, ap);
|
||||
retval = IP_MIN(retval, (int) IPCOM_STDIO_BUFSIZE);
|
||||
va_end(ap);
|
||||
|
||||
if(retval > 0)
|
||||
{
|
||||
if(ipdhcprc.preconfiguring == IP_TRUE)
|
||||
{
|
||||
if(buf[0] != '\n')
|
||||
IPCOM_LOG0(INFO,buf);
|
||||
}
|
||||
else
|
||||
(void)ipcom_printf(buf);
|
||||
}
|
||||
|
||||
ipcom_free(buf);
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_cmd_print_usage
|
||||
*===========================================================================
|
||||
* Description: Prints the documentation for the command.
|
||||
* Parameters:
|
||||
* Returns: IPCOM_SUCCESS - the operation was successful
|
||||
* IPCOM_ERR_FAILED -
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_err
|
||||
ipdhcpr_cmd_print_usage(void)
|
||||
{
|
||||
ipdhcpr_printf(IP_LF);
|
||||
ipdhcpr_printf("NAME" IP_LF);
|
||||
ipdhcpr_printf(" dhcpr - Control Interpeak DHCP/BOOTP relay agent" IP_LF);
|
||||
ipdhcpr_printf(IP_LF);
|
||||
ipdhcpr_printf("SYNOPSIS" IP_LF);
|
||||
ipdhcpr_printf(" dhcpr server {list | add {addr} | delete {addr} |" IP_LF);
|
||||
ipdhcpr_printf(" option82 {addr} {{enable auth {in raw hex format}} |" IP_LF);
|
||||
ipdhcpr_printf(" {disable auth}}}" IP_LF);
|
||||
ipdhcpr_printf(" dhcpr interface {list | enable {name} | disable {name} |" IP_LF);
|
||||
ipdhcpr_printf(" option82 {name} {{circuit-id {in raw hex format}} |" IP_LF);
|
||||
ipdhcpr_printf(" {remote-id {in raw hex format}} |" IP_LF);
|
||||
ipdhcpr_printf(" disable}}" IP_LF);
|
||||
ipdhcpr_printf(" dhcpr option82 {list | enable {auth | drop} | disable {auth | drop}}" IP_LF);
|
||||
ipdhcpr_printf(IP_LF);
|
||||
ipdhcpr_printf("DESCRIPTION" IP_LF);
|
||||
ipdhcpr_printf(" The dhcpr program starts, stops and configures the Interpeak DHCP/BOOTP" IP_LF);
|
||||
ipdhcpr_printf(" relay agent." IP_LF);
|
||||
ipdhcpr_printf(IP_LF);
|
||||
ipdhcpr_printf(" server Show or change the configured list of servers called by" IP_LF);
|
||||
ipdhcpr_printf(" by the DHCP/BOOTP relay agent." IP_LF);
|
||||
ipdhcpr_printf(" interface List or enable/disable interfaces used by the dhcp relay agent." IP_LF);
|
||||
ipdhcpr_printf(" option82 Enable/disable DHCP relay agent Authentication and the drop" IP_LF);
|
||||
ipdhcpr_printf(" policy if incoming packet has no Authentication suboption." IP_LF);
|
||||
ipdhcpr_printf(IP_LF);
|
||||
#if 0
|
||||
ipdhcpr_printf("EXAMPLES" IP_LF);
|
||||
#endif
|
||||
|
||||
return IPCOM_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_cmd_server
|
||||
*===========================================================================
|
||||
* Description: Handles the server command.
|
||||
* Parameters: argc - number of command line arguments
|
||||
* argv - array of command line arguments
|
||||
* subcmd - sub command descriptor.
|
||||
*
|
||||
* Returns: IPCOM_SUCCESS - the operation was successful
|
||||
* IPCOM_ERR... - failed
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_err
|
||||
ipdhcpr_handle_cmd_server(int argc, char *argv[], int subcmd)
|
||||
{
|
||||
Ip_err retval;
|
||||
Ip_u32 addr;
|
||||
|
||||
switch(subcmd)
|
||||
{
|
||||
case IPDHCPR_SUBCMD_LST:
|
||||
|
||||
ipdhcpr_printf(" Registered servers"IP_LF);
|
||||
|
||||
retval = ipdhcpr_server_for_each(ipdhcpr_server_print,
|
||||
IP_NULL);
|
||||
ipdhcpr_printf(IP_LF);
|
||||
break;
|
||||
|
||||
case IPDHCPR_SUBCMD_ADD:
|
||||
|
||||
if(argc != 1)
|
||||
IPDHCPR_LEAVE(IPCOM_ERR_INVALID_ARG);
|
||||
|
||||
if(ipcom_inet_pton(IP_AF_INET, argv[0], &addr) != 1)
|
||||
IPDHCPR_LEAVE(IPCOM_ERR_INVALID_CONFIG);
|
||||
|
||||
retval = ipdhcpr_server_add(addr);
|
||||
break;
|
||||
|
||||
case IPDHCPR_SUBCMD_DEL:
|
||||
|
||||
if(argc != 1)
|
||||
IPDHCPR_LEAVE(IPCOM_ERR_INVALID_ARG);
|
||||
|
||||
if(ipcom_inet_pton(IP_AF_INET, argv[0], &addr) != 1)
|
||||
IPDHCPR_LEAVE(IPCOM_ERR_INVALID_CONFIG);
|
||||
|
||||
retval = ipdhcpr_server_delete(addr);
|
||||
break;
|
||||
|
||||
/* dhcpr server option82 {addr} {{enable auth {in raw hex format}} | {disable auth}} */
|
||||
case IPDHCPR_SUBCMD_OPT82:
|
||||
{
|
||||
Ip_bool auth_en = IP_FALSE;
|
||||
char *auth_key = IP_NULL;
|
||||
|
||||
if ((argc < 3) || (argc > 4))
|
||||
IPDHCPR_LEAVE(IPCOM_ERR_INVALID_ARG);
|
||||
|
||||
if (ipcom_inet_pton(IP_AF_INET, argv[0], &addr) != 1)
|
||||
IPDHCPR_LEAVE(IPCOM_ERR_INVALID_CONFIG);
|
||||
|
||||
if (ipcom_strcmp("enable", argv[1]) == 0)
|
||||
{
|
||||
if (4 != argc)
|
||||
IPDHCPR_LEAVE(IPCOM_ERR_INVALID_ARG);
|
||||
|
||||
auth_key = argv[3];
|
||||
auth_en = IP_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ipcom_strcmp("disable", argv[1]) != 0)
|
||||
IPDHCPR_LEAVE(IPCOM_ERR_INVALID_ARG);
|
||||
}
|
||||
|
||||
if (ipcom_strcmp("auth", argv[2]) != 0)
|
||||
IPDHCPR_LEAVE(IPCOM_ERR_INVALID_ARG);
|
||||
|
||||
retval = ipdhcpr_server_option82(addr, auth_en, auth_key);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
IPDHCPR_LEAVE(IPCOM_ERR_FAILED);
|
||||
}
|
||||
|
||||
leave:
|
||||
ipdhcpr_printf(IP_LF);
|
||||
ipdhcpr_errmsg_print(retval);
|
||||
|
||||
return(retval);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_cmd_interface
|
||||
*===========================================================================
|
||||
* Description: Handles the interface command.
|
||||
* Parameters: argc - number of command line arguments
|
||||
* argv - array of command line arguments
|
||||
* subcmd - sub command descriptor.
|
||||
*
|
||||
* Returns: IPCOM_SUCCESS - the operation was successful
|
||||
* IPCOM_ERR... - failed
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_err
|
||||
ipdhcpr_handle_cmd_interface (int argc, char *argv[], int subcmd)
|
||||
{
|
||||
Ip_err retval;
|
||||
|
||||
|
||||
switch(subcmd)
|
||||
{
|
||||
case IPDHCPR_SUBCMD_LST:
|
||||
|
||||
retval = ipdhcpr_interface_for_each(ipdhcpr_interface_print, IP_NULL);
|
||||
break;
|
||||
|
||||
case IPDHCPR_SUBCMD_ENA:
|
||||
|
||||
if (argc < 1) /* check that an interface was specified */
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
else
|
||||
retval = ipdhcpr_interface_status_set(argv[0], IP_TRUE);
|
||||
break;
|
||||
|
||||
case IPDHCPR_SUBCMD_DIS:
|
||||
|
||||
if (argc < 1) /* check that an interface was specified */
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
else
|
||||
retval = ipdhcpr_interface_status_set(argv[0], IP_FALSE);
|
||||
break;
|
||||
|
||||
/* dhcpr interface option82 {name} {{circuit-id {in raw hex format}} |
|
||||
* {remote-id {in raw hex format}}}
|
||||
* 0 */
|
||||
case IPDHCPR_SUBCMD_OPT82:
|
||||
{
|
||||
char *circuit_id = IP_NULL;
|
||||
char *remote_id = IP_NULL;
|
||||
|
||||
if ((argc < 2) || (argc > 5))
|
||||
{
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((0 != ipcom_strcmp("circuit-id", argv[1]))
|
||||
&& (0 != ipcom_strcmp("remote-id", argv[1]))
|
||||
&& (0 != ipcom_strcmp("disable", argv[1])))
|
||||
{
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
break;
|
||||
}
|
||||
|
||||
if (0 == ipcom_strcmp("circuit-id", argv[1]))
|
||||
{
|
||||
if (argc < 3) /* exclude only configure with 'circuit-id' */
|
||||
{
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
break;
|
||||
}
|
||||
circuit_id = argv[2];
|
||||
if (argc == 5)
|
||||
{
|
||||
if (0 == ipcom_strcmp("remote-id", argv[3]))
|
||||
{
|
||||
remote_id = argv[4];
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* remote-id */
|
||||
{
|
||||
if (0 == ipcom_strcmp("remote-id", argv[1]))
|
||||
{
|
||||
if (argc < 3) /* exclude only configure with 'remote-id' */
|
||||
{
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
break;
|
||||
}
|
||||
remote_id = argv[2];
|
||||
if (argc == 5)
|
||||
{
|
||||
if (0 == ipcom_strcmp("circuit-id", argv[3]))
|
||||
{
|
||||
circuit_id = argv[4];
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
retval = ipdhcpr_interface_option82(argv[0], circuit_id, remote_id);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ipdhcpr_printf(IP_LF);
|
||||
ipdhcpr_errmsg_print(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_handle_cmd_option82
|
||||
*===========================================================================
|
||||
* Description: Handles the OPTION82 command.
|
||||
* Parameters: argc - number of command line arguments
|
||||
* argv - array of command line arguments
|
||||
* subcmd - sub command descriptor.
|
||||
*
|
||||
* Returns: IPCOM_SUCCESS - the operation was successful
|
||||
* IPCOM_ERR... - failed
|
||||
*
|
||||
*/
|
||||
IP_STATIC Ip_err
|
||||
ipdhcpr_handle_cmd_option82 (int argc, char *argv[], int subcmd)
|
||||
{
|
||||
Ip_err retval = 0;
|
||||
|
||||
switch(subcmd)
|
||||
{
|
||||
case IPDHCPR_SUBCMD_LST:
|
||||
ipdhcpr_printf(" DHCP relay agent authentication is %s"IP_LF,
|
||||
ipdhcprc.enable_ra_auth ? "enabled" : "disabled");
|
||||
ipdhcpr_printf(" DHCP relay agent drop policy is %s"IP_LF,
|
||||
ipdhcprc.enable_drop ? "enabled" : "disabled");
|
||||
break;
|
||||
|
||||
case IPDHCPR_SUBCMD_ENA:
|
||||
{
|
||||
if (1 == argc)
|
||||
{
|
||||
if (0 == ipcom_strcmp(argv[0], "auth"))
|
||||
{
|
||||
retval = ipdhcpr_option82_auth_set(IP_TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (0 == ipcom_strcmp(argv[0], "drop"))
|
||||
retval = ipdhcpr_option82_drop_set(IP_TRUE);
|
||||
else
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case IPDHCPR_SUBCMD_DIS:
|
||||
{
|
||||
if (1 == argc)
|
||||
{
|
||||
if (0 == ipcom_strcmp(argv[0], "auth"))
|
||||
{
|
||||
retval = ipdhcpr_option82_auth_set(IP_FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (0 == ipcom_strcmp(argv[0], "drop"))
|
||||
retval = ipdhcpr_option82_drop_set(IP_FALSE);
|
||||
else
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ipdhcpr_printf(IP_LF);
|
||||
ipdhcpr_errmsg_print(retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_subnet_print
|
||||
*===========================================================================
|
||||
* Description: Callback function used for printing server information
|
||||
* Parameters: obj - Pointer to server descriptor
|
||||
* data - not used
|
||||
*
|
||||
* Returns: -
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
ipdhcpr_server_print( void *obj, void *data)
|
||||
{
|
||||
Ipdhcpr_server *s =(Ipdhcpr_server*)obj;
|
||||
char buf[20];
|
||||
|
||||
(void)data;
|
||||
|
||||
(void)ipcom_inet_ntop(IP_AF_INET, &s->saddr, buf, sizeof(buf));
|
||||
|
||||
ipdhcpr_printf(" %s :: shareKey : %s, firstPacket : %s, curSendRDCount : %u, lastRecvRDCount : %u"IP_LF,
|
||||
buf,
|
||||
s->shareKey ? s->shareKey : "null",
|
||||
s->notFirstPacket ? "FALSE" : "TRUE",
|
||||
s->curSendRDCount,
|
||||
s->lastRecvRDCount);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_interface_print
|
||||
*===========================================================================
|
||||
* Description: Callback function used for printing interface information.
|
||||
* Parameters: obj - Pointer to interface descriptor
|
||||
* data - not used.
|
||||
*
|
||||
* Returns: -
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
ipdhcpr_interface_print(void *obj, void *data)
|
||||
{
|
||||
Ipdhcpr_if *i = (Ipdhcpr_if*)obj;
|
||||
char buf [20];
|
||||
|
||||
(void)data;
|
||||
|
||||
(void)ipcom_inet_ntop(IP_AF_INET, &i->ifaddr, buf, sizeof(buf));
|
||||
|
||||
ipdhcpr_printf(" Interface %s (%s) :: %s, circuit-ID : %s, remote-ID : %s"IP_LF,
|
||||
i->ifname,
|
||||
buf,
|
||||
i->enabled == IP_TRUE ? "enabled" : "disabled",
|
||||
i->circuitID ? i->circuitID : "",
|
||||
i->remoteID ? i->remoteID : "");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_errmsg_print
|
||||
*===========================================================================
|
||||
* Description: Prints error messages in clear text.
|
||||
* Parameters: code - error code
|
||||
* Returns: -
|
||||
*
|
||||
*/
|
||||
IP_STATIC void
|
||||
ipdhcpr_errmsg_print(Ip_err code)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case IPCOM_ERR_INVALID_ARG:
|
||||
ipdhcpr_printf("failed :: invalid argument"IP_LF);
|
||||
break;
|
||||
case IPCOM_ERR_INVALID_CONFIG:
|
||||
ipdhcpr_printf("failed :: invalid config"IP_LF);
|
||||
break;
|
||||
case IPCOM_ERR_NOT_FOUND:
|
||||
ipdhcpr_printf("failed :: not found"IP_LF);
|
||||
break;
|
||||
case IPCOM_ERR_NO_MEMORY:
|
||||
ipdhcpr_printf("failed :: out of memory"IP_LF);
|
||||
break;
|
||||
case IPCOM_ERR_ALREADY_INSTALLED:
|
||||
ipdhcpr_printf("failed :: already exists"IP_LF);
|
||||
break;
|
||||
case IPCOM_ERR_NOT_OPENED:
|
||||
ipdhcpr_printf("failed :: ipdhcpr not open"IP_LF);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 10 GLOBAL FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_cmd_dhcpr
|
||||
*===========================================================================
|
||||
* Description: Shell command used to start,stop and configure the DHCP
|
||||
* relay agent.
|
||||
* Parameters: argc - The number of arguments passed to the command.
|
||||
* argv - The arguments passed to the command.
|
||||
* Returns: 0 = success,
|
||||
*
|
||||
*/
|
||||
IP_GLOBAL int
|
||||
ipdhcpr_cmd_dhcpr(int argc, char **argv)
|
||||
{
|
||||
Ip_err retval;
|
||||
int i, s;
|
||||
|
||||
retval = IPCOM_ERR_INVALID_ARG;
|
||||
|
||||
if(argc < 2)
|
||||
IPDHCPR_LEAVE(IPCOM_ERR_INVALID_ARG);
|
||||
|
||||
for(i = 0; i < IPDHCPR_MAX_CMD; i++)
|
||||
{
|
||||
if(ipcom_strcmp(argv[1], ipdhcpr_cmd_callback[i].cmd) == 0)
|
||||
{
|
||||
for(s = IPDHCPR_MAX_SUBCMD; s > 0 && argc > 2; s--)
|
||||
if(ipcom_strcmp(argv[2], ipdhcpr_subcmd[s - 1]) == 0)
|
||||
break;
|
||||
|
||||
retval = ipdhcpr_cmd_callback[i].cmd_cb(argc-3, &argv[3], s - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
leave:
|
||||
if(retval == IPCOM_ERR_INVALID_ARG)
|
||||
(void) ipdhcpr_cmd_print_usage();
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* #ifdef IPDHCPR_INCLUDE_CMD */
|
||||
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 11 PUBLIC FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,429 @@
|
||||
/*
|
||||
******************************************************************************
|
||||
* HEADER FILE
|
||||
*
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipdhcpr_h.h,v $ $Revision: 1.8.10.1 $
|
||||
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipdhcpr_h.h,v $ $Revision: 1.8.10.1 $
|
||||
* $Source: /home/interpeak/CVSRoot/ipdhcpr/src/ipdhcpr_h.h,v $
|
||||
* $Author: hxu0 $ $Date: 2013-06-20 08:03:50 $
|
||||
* $State: Exp $ $Locker: $
|
||||
*
|
||||
* INTERPEAK_COPYRIGHT_STRING
|
||||
* Design and implementation by Jonas Rendel <jonas@interpeak.se>
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef IPDHCPR_H_H
|
||||
#define IPDHCPR_H_H
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 1 DESCRIPTION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 2 CONFIGURATION
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 3 INCLUDE FILES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
#include <ipcom_cstyle.h>
|
||||
#include <ipcom_tmo.h>
|
||||
#include <ipcom_sock.h>
|
||||
#include <ipcom_hash.h>
|
||||
#include <ipcom_inet.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 4 DEFINES
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Syslog priority and facility.
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#ifdef IPCOM_SYSLOG_PRIORITY
|
||||
#undef IPCOM_SYSLOG_PRIORITY
|
||||
#endif
|
||||
|
||||
#if defined(_WRS_CONFIG_IPDHCPR_SYSLOG_PRIORITY)
|
||||
#define IPCOM_SYSLOG_PRIORITY _WRS_CONFIG_IPDHCPR_SYSLOG_PRIORITY
|
||||
#else
|
||||
#define IPCOM_SYSLOG_PRIORITY IPCOM_SYSLOG_PRIO_DEFAULT
|
||||
#endif
|
||||
|
||||
#ifdef IPCOM_SYSLOG_FACILITY
|
||||
#undef IPCOM_SYSLOG_FACILITY
|
||||
#endif
|
||||
#define IPCOM_SYSLOG_FACILITY IPCOM_LOG_IPDHCPR
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Offset in a DHCP/Config option field
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define IPDHCPR_OPT_CODE (0)
|
||||
#define IPDHCPR_OPT_LEN (1)
|
||||
#define IPDHCPR_OPT_DATA (2)
|
||||
|
||||
#define IPDHCPR_OPTCODE_PAD (0)
|
||||
#define IPDHCPR_OPTCODE_END (255)
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* DHCP magic cookie
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define IPDHCPR_MAGIC_COOKIE (0x63825363)
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* DHCP Broadcast bit in flags field
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define IPDHCPR_BROADCAST_FLAG (0x8000)
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* DHCP Packet config
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define IPDHCPR_PKT_MINLEN (576)
|
||||
#define IPDHCPR_PKT_DEFAULT_LEN IPDHCPR_PKT_MINLEN
|
||||
#define IPDHCPR_PKT_HDR_SNAME_LEN (64)
|
||||
#define IPDHCPR_PKT_HDR_FILE_LEN (128)
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Macros
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Quick exit upon error
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define IPDHCPR_LEAVE(xerrval) do { retval = xerrval; goto leave; } while(0)
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Mutex handling
|
||||
*===========================================================================
|
||||
*/
|
||||
#define IPDHCPR_ISLOCKED_ASSERT() ip_assert(ipdhcprc.code_mutex_count == 1)
|
||||
#define IPDHCPR_LOCK() do { ipcom_mutex_lock(ipdhcprc.code_mutex); \
|
||||
ip_assert(ipdhcprc.code_mutex_count == 0); \
|
||||
ipdhcprc.code_mutex_count++; \
|
||||
} while(0)
|
||||
|
||||
#define IPDHCPR_UNLOCK() do { ip_assert(ipdhcprc.code_mutex_count == 1); \
|
||||
ipdhcprc.code_mutex_count--; \
|
||||
ipcom_mutex_unlock(ipdhcprc.code_mutex); \
|
||||
} while(0)
|
||||
/*
|
||||
*===========================================================================
|
||||
* Size of raw dhcp packet to transmit
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define IPDHCPR_RAW_PACKET_SIZE(sz) (sz - sizeof(Ipdhcpr_pkt) + sizeof(Ipdhcpr_raw_pkt))
|
||||
#define IPDHCPR_DHCP_PAYLOAD_SIZE(sz) (sz - sizeof(Ipdhcpr_raw_pkt) + sizeof(Ipdhcpr_pkt))
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Quick "for" macro applicable on lists
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
#define IPDHCPR_LIST_FOREACH(var, head, type) for(var = (type)(head->next); \
|
||||
(var != IP_NULL); \
|
||||
var = ((type)(var->node.next)))
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 5 TYPES
|
||||
****************************************************************************
|
||||
*/
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcpr_node_delete_cb
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
typedef Ip_err (*Ipdhcpr_node_delete_cb)(void* obj);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcpr_list
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
typedef struct Ipdhcpr_list_struct
|
||||
{
|
||||
struct Ipdhcpr_list_struct *next; /* Next element in list */
|
||||
struct Ipdhcpr_list_struct *prev; /* Prev element in list */
|
||||
Ipdhcpr_node_delete_cb delete; /* Destructor callback */
|
||||
}
|
||||
Ipdhcpr_list;
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcpr_if
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
typedef struct Ipdhcpr_if_struct
|
||||
{
|
||||
Ipdhcpr_list node; /* List element */
|
||||
int ifindex; /* Interface index */
|
||||
char ifname[IP_IFNAMSIZ]; /* Interface name */
|
||||
Ip_u32 ifaddr; /* Interface main IPv4 address */
|
||||
Ip_bool enabled; /* Use interface or not */
|
||||
Ip_bool trusted; /* Trusted interface or not */
|
||||
char *circuitID; /* circuit identifier */
|
||||
char *remoteID; /* remote identifier */
|
||||
}
|
||||
Ipdhcpr_if;
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcpr_server
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
typedef struct Ipdhcpr_server_struct
|
||||
{
|
||||
Ipdhcpr_list node; /* List element */
|
||||
Ip_u32 saddr; /* Servers IPv4 address */
|
||||
char *shareKey; /* share key for AUTH */
|
||||
/* current send Replay Detection count value */
|
||||
Ip_u32 curSendRDCount;
|
||||
/* current received Replay Detection count value */
|
||||
Ip_u32 lastRecvRDCount;
|
||||
Ip_bool notFirstPacket;
|
||||
}
|
||||
Ipdhcpr_server;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcpr_config
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
typedef struct Ipdhcpr_config_struct
|
||||
{
|
||||
Ip_u16 server_port;
|
||||
Ip_u16 client_port;
|
||||
Ip_u16 packet_size;
|
||||
Ip_u16 hops_treshold;
|
||||
}
|
||||
Ipdhcpr_config;
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_hdr
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
IP_PACKED typedef struct Ipdhcpr_hdr_struct
|
||||
{
|
||||
Ip_u8 op; /* Message operation code */
|
||||
Ip_u8 htype; /* Link-layer address type */
|
||||
Ip_u8 hlen; /* Link-layer address length */
|
||||
Ip_u8 hops; /* Number of relay agents between client and server */
|
||||
Ip_u32 xid; /* Transaction ID */
|
||||
Ip_u16 secs; /* Elapsed time since a client began the dhcp process */
|
||||
Ip_u16 flags; /* Flags field. The least significant bit is the broadcast bit */
|
||||
Ip_u32 ciaddr; /* Client IP address if client in bound,renew or rebinding. */
|
||||
Ip_u32 yiaddr; /* 'your' (client) IP address. */
|
||||
Ip_u32 siaddr; /* IP address of next server to use in bootstrap */
|
||||
Ip_u32 giaddr; /* Relay agent IP address, used in booting via a relay agent. */
|
||||
Ip_u8 chaddr[16]; /* Client hardware address. */
|
||||
Ip_u8 sname[IPDHCPR_PKT_HDR_SNAME_LEN]; /* Optional server host name, null terminated string. */
|
||||
Ip_u8 file[IPDHCPR_PKT_HDR_FILE_LEN]; /* Boot file name, null terminated string */
|
||||
Ip_u32 cookie; /* DHCP/BOOTP magic cookie */
|
||||
}
|
||||
Ipdhcpr_hdr;
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcpr_pkt
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
IP_PACKED typedef struct Ipdhcpr_pkt_struct
|
||||
{
|
||||
Ipdhcpr_hdr hdr; /* DHCP/BOOTP header */
|
||||
Ip_u8 options[1]; /* DHCP options */
|
||||
}
|
||||
Ipdhcpr_pkt;
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcpr_udp_header
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
/*
|
||||
* We can not use the standard udp header structure defined in ipnet here
|
||||
* because it includes a 4 byte data field.
|
||||
*/
|
||||
|
||||
typedef IP_PACKED struct Ipdhcpr_udp_header_struct
|
||||
{
|
||||
Ip_u16 src_port; /* Source UDP Port */
|
||||
Ip_u16 dst_port; /* Destination UDP Port */
|
||||
Ip_u16 length; /* Length of UDP header + data = 8+X */
|
||||
Ip_u16 checksum; /* UDP Checksum (0 = No checksum) */
|
||||
}
|
||||
Ipdhcpr_udp_header;
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcpr_raw_pkt
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
IP_PACKED typedef struct Ipdhcpr_raw_pkt_struct
|
||||
{
|
||||
Ipcom_ip_header ip; /* IP header */
|
||||
Ipdhcpr_udp_header udp; /* UDP header */
|
||||
Ipdhcpr_pkt dhcp; /* DHCP message */
|
||||
}
|
||||
Ipdhcpr_raw_pkt;
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcpr_handle
|
||||
*===========================================================================
|
||||
*/
|
||||
typedef struct Ipdhcpr_handle_struct
|
||||
{
|
||||
Ipdhcpr_raw_pkt *raw_packet; /* Points to first byte of raw dhcp packet */
|
||||
Ipdhcpr_pkt *packet; /* Points to dhcp message in raw packet */
|
||||
Ip_size_t packet_len; /* Length of dhcp message */
|
||||
Ipdhcpr_if *rx_if; /* Points to receiving interface */
|
||||
Ipdhcpr_if *tx_if; /* Points to transmitting interface */
|
||||
}
|
||||
Ipdhcpr_handle;
|
||||
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* Ipdhcpr_data
|
||||
*===========================================================================
|
||||
*/
|
||||
|
||||
typedef struct Ipdhcpr_data_struct
|
||||
{
|
||||
Ip_bool opened; /* Tells if ipdhcpr is open or not */
|
||||
Ip_bool preconfiguring;
|
||||
Ipcom_mutex code_mutex; /* Mutex to protect global data. */
|
||||
int code_mutex_count; /* Mutex counter */
|
||||
Ip_fd dhcp_fd; /* UDP receive socket */
|
||||
Ip_fd rt_fd; /* Route sock */
|
||||
Ip_fd ipd_fd; /* IPD socket */
|
||||
struct Ip_sockaddr_in addr; /* Listen address */
|
||||
Ipdhcpr_list if_head; /* Interface table */
|
||||
Ipdhcpr_list server_head; /* Server table */
|
||||
Ipdhcpr_config config; /* IPDHCPR configuration */
|
||||
Ipdhcpr_handle handle; /* DHCP packet handle */
|
||||
Ip_bool enable_ra_auth; /* Enable relay-agent authentication */
|
||||
Ip_bool enable_drop; /* Enable relay-agent drop poily */
|
||||
}
|
||||
Ipdhcpr_data;
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* 6 FUNCTIONS
|
||||
****************************************************************************
|
||||
*/
|
||||
|
||||
IPCOM_PROCESS(ipdhcpr);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_interface_for_each
|
||||
*===========================================================================
|
||||
* Description: Apply supplied callback for each interface descriptor
|
||||
* found in database.
|
||||
*
|
||||
* Parameters: cb - Pointer to callback function.
|
||||
* data - user supplied data.
|
||||
*
|
||||
* Returns: IPCOM_SUCCESS - success
|
||||
* other - failure
|
||||
*
|
||||
*/
|
||||
|
||||
IP_GLOBAL Ip_err
|
||||
ipdhcpr_interface_for_each(void (*cb)(void *obj, void *data), void* data);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_interface_for_each
|
||||
*===========================================================================
|
||||
* Description: Apply supplied callback for each server descriptor
|
||||
* found in database.
|
||||
*
|
||||
* Parameters: cb - Pointer to callback function.
|
||||
* data - user supplied data.
|
||||
*
|
||||
* Returns: IPCOM_SUCCESS - success
|
||||
* other - failure
|
||||
*
|
||||
*/
|
||||
|
||||
IP_GLOBAL Ip_err
|
||||
ipdhcpr_server_for_each(void (*cb)(void *obj, void *data), void* data);
|
||||
|
||||
/*
|
||||
*===========================================================================
|
||||
* ipdhcpr_cmd_dhcpr
|
||||
*===========================================================================
|
||||
* Description: Installs the ipdhcpr shell commands.
|
||||
* Parameters:
|
||||
* Returns:
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifdef IPDHCPR_INCLUDE_CMD
|
||||
IP_GLOBAL int
|
||||
ipdhcpr_cmd_dhcpr(int argc, char **argv);
|
||||
#endif
|
||||
|
||||
IP_PUBLIC Ip_err ipdhcpr_configure(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
****************************************************************************
|
||||
* END OF FILE
|
||||
****************************************************************************
|
||||
*/
|
||||
Reference in New Issue
Block a user