Files
m241Neelima/components/ip_net2-6.9/ipappl/src/ipdhcpc_h.h
T
2026-07-30 11:19:44 +05:30

533 lines
16 KiB
C

/*
******************************************************************************
* HEADER FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipdhcpc_h.h,v $ $Revision: 1.6.16.7 $
* $Source: /home/interpeak/CVSRoot/ipappl/src/ipdhcpc_h.h,v $
* $Author: jwang9 $ $Date: 2016-01-04 08:50:32 $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Lennart Bang <lob@interpeak.se>
* and Jonas Rendel <jonas@interpeak.se>
******************************************************************************
*/
#ifndef IPDHCPC_H_H
#define IPDHCPC_H_H
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#include <ipcom_type.h>
#include <ipcom_cstyle.h>
#include <ipcom_tmo.h>
#include <ipcom_os.h>
#include <ipcom_tags.h>
#include "ipdhcpc.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
/* DHCP pkt opcode: */
#define IPDHCPC_OP_BOOTREQUEST 1
#define IPDHCPC_OP_BOOTREPLY 2
/* DHCP pkt htype & hlen: */
#define IPDHCPC_HTYPE_ETHERNET 1
#define IPDHCPC_HLEN_ETHERNET 6
/* DHCP pkt message types: */
#define IPDHCPC_MSG_INVALID 0
#define IPDHCPC_MSG_DISCOVER 1
#define IPDHCPC_MSG_OFFER 2
#define IPDHCPC_MSG_REQUEST 3
#define IPDHCPC_MSG_DECLINE 4
#define IPDHCPC_MSG_ACK 5
#define IPDHCPC_MSG_NAK 6
#define IPDHCPC_MSG_RELEASE 7
#define IPDHCPC_MSG_INFORM 8
/* DHCP client message bitvalues: */
#define IPDHCPC_MB_DISCOVER 0x01
#define IPDHCPC_MB_OFFER 0x02
#define IPDHCPC_MB_REQUEST 0x04
#define IPDHCPC_MB_DECLINE 0x08
#define IPDHCPC_MB_ACK 0x10
#define IPDHCPC_MB_NAK 0x20
#define IPDHCPC_MB_RELEASE 0x40
#define IPDHCPC_MB_INFORM 0x80
/* DHCP client states: */
#define IPDHCPC_STATE_INIT 1
#define IPDHCPC_STATE_INIT_REBOOT 2
#define IPDHCPC_STATE_SELECTING 3
#define IPDHCPC_STATE_REBOOTING 4
#define IPDHCPC_STATE_REQUESTING 5
#define IPDHCPC_STATE_INFORMING 6
#define IPDHCPC_STATE_BOUND 7
#define IPDHCPC_STATE_RENEWING 8
#define IPDHCPC_STATE_REBINDING 9
#define IPDHCPC_STATE_STOPPED 10
#define IPDHCPC_STATE_ASSIGNING 11
/*DHCP event states*/
#define IPDHCPC_IF_EVENT_INFORM 1
#define IPDHCPC_IF_EVENT_RENEW 2
/* DHCP ports. */
#define IPDHCPC_SERVER_PORT 67
#define IPDHCPC_CLIENT_PORT 68
/* Minimum BOOTP header length. RFC1542:p5 */
#define IPDHCPC_PKT_MINLEN 300
#define IPDHCPC_RAW_HSIZE (sizeof(Ipcom_udp_header) + sizeof(Ipcom_ip_header))
/* DHCP Header size without options, as per RFC 2131 */
#define IPDHCPC_MESSAGE_DHCP_HEADER_SIZE ip_offsetof(Ipdhcpc_pkt, options)
/* DHCP Header size including IP, UDP, DHCP */
#define IPDHCPC_MESSAGE_HEADER_SIZE (IPDHCPC_RAW_HSIZE + IPDHCPC_MESSAGE_DHCP_HEADER_SIZE)
/* DHCP Max size of one option. Arbitrary. Used to alloc buffer holding options from sysvar struct */
#define IPDHCPC_MAX_OPTION_SIZE (ipdhcpc.max_message_size - IPDHCPC_MESSAGE_HEADER_SIZE)
#define IPDHCPC_LEFT_OPTION_SPACE(occupy_byte) (IPDHCPC_MAX_OPTION_SIZE - occupy_byte)
/*
*===========================================================================
* DHCP FLAGS FIELD
*===========================================================================
* See RFC 2132.
*/
#define IPDHCPC_FLAGS_BROADCAST 0X8000
/*
* DHCP mode of operation
*===========================================================================
* Defines the different modes the client can operate in.
*/
#define IPDHCPC_MODE_ALLOC_DYNAMIC 1
#define IPDHCPC_MODE_REUSE_DYNAMIC 2
#define IPDHCPC_MODE_RELEASE_DYNAMIC 3
#define IPDHCPC_MODE_INFORM_STATIC 4
/* overload option value */
#define IPDHCPC_OVERLOAD_NONE (0)
#define IPDHCPC_OVERLOAD_FILE (1)
#define IPDHCPC_OVERLOAD_SNAME (2)
#define IPDHCPC_OVERLOAD_BOTH (3)
#define IPDHCPC_OPT_CODE (0)
#define IPDHCPC_OPT_LEN (1)
#define IPDHCPC_OPT_DATA (2)
#define IPDHCPC_OPT_MIN_LEN (2)
#define IPDHCPC_PKT_HDR_SNAME_LEN (64)
#define IPDHCPC_PKT_HDR_FILE_LEN (128)
/* MACROS */
#define IPDHCPC_LEAVE(xerrval) do { retval = xerrval; goto leave; } while(0)
#define IPDHCPC_ISLOCKED_ASSERT() ip_assert(ipdhcpc.code_mutex_count == 1)
#define IPDHCPC_LOCK() do { ipcom_mutex_lock(ipdhcpc.code_mutex); \
ip_assert(ipdhcpc.code_mutex_count == 0); \
ipdhcpc.code_mutex_count++; \
} while(0)
#define IPDHCPC_UNLOCK() do { ip_assert(ipdhcpc.code_mutex_count == 1); \
ipdhcpc.code_mutex_count--; \
ipcom_mutex_unlock(ipdhcpc.code_mutex); \
} while(0)
#define IPDHCPC_ISINIT(handle) (IPDHCPC_STATE_BOUND > ((handle)->priv->state))
#define IPDHCPC_MAX_CID_LEN (254) /*the maximum length of option 61 is 255, the data is filled 0 at the beginning, so the real length is 255-1*/
#define IPDHCPC_CID_CFG_DELIMITER ":"
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
/*
*===========================================================================
* Ipdhcpc_handle_priv
*===========================================================================
*/
typedef struct Ipdhcpc_handle_priv_struct
{
struct Ipdhcpc_handle_struct *next;
Ipcom_tmo tmo;
int tmo_ignore;
Ipcom_tmo tmo_t2;
int tmo2_ignore;
int retrans_counter;
int mode;
int state;
Ip_u32 xid_n;
Ip_u16 in_optlen;
Ip_u8 msgtype;
Ip_u8 pad;
/* Cached server info. */
Ip_u32 serverid_n; /* Server IP address */
Ip_u32 gw_n; /* Gateway IP address */
Ip_u32 yiaddr; /* 'your' (client) IP address */
}
Ipdhcpc_handle_priv;
/*
*===========================================================================
* Ipdhcpc_options
*===========================================================================
*/
typedef struct Ipdhcpc_options_struct
{
Ip_u8 optcode;
Ip_u8 minlen;
Ip_u8 maxlen;
Ip_u8 msgmust;
Ip_u8 msgmustnot;
}
Ipdhcpc_options;
/*
*===========================================================================
* Ipdhcpc_pkt
*===========================================================================
*/
IP_PACKED typedef struct Ipdhcpc_pkt_struct
{
Ip_u8 op;
Ip_u8 htype;
Ip_u8 hlen;
Ip_u8 hops;
Ip_u32 xid;
Ip_u16 secs;
Ip_u16 flags;
Ip_u32 ciaddr; /* Client IP address */
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 */
Ip_u8 chaddr[16]; /* Client hardware address. */
char sname[IPDHCPC_PKT_HDR_SNAME_LEN]; /* Optional server host name */
char file[IPDHCPC_PKT_HDR_FILE_LEN]; /* Boot file name */
Ip_u8 options[1];
}
Ipdhcpc_pkt;
/*
*===========================================================================
* Ipdhcpc_lease
*===========================================================================
*/
typedef struct Ipdhcpc_lease_struct
{
Ip_time_t t1;
Ip_time_t t2;
Ip_time_t tlease;
}
Ipdhcpc_lease;
/*
*===========================================================================
* Ipdhcpc_if
*===========================================================================
*/
typedef struct Ipdhcpc_if_struct
{
struct Ipdhcpc_if_struct *next;
Ip_u32 ifindex;
char ifname[IP_IFNAMSIZ];
int num_opened;
/* ifopen configuration. */
/* Time stuff. */
Ip_time_t time_addr_req; /* same as time when ifopen() was made. */
/* Interface stuff. */
Ip_u8 chaddr[16]; /* Client hardware address. */
Ip_u8 hlen;
Ip_u8 pad;
/* Config. */
char *clientid;
/* Interface lease. */
Ipdhcpc_handle *handle;
Ipdhcpc_lease lease;
Ip_u8 clientid_len;
Ip_bool isdown;
/*whether or not it is in inform only mode*/
Ip_bool information_only;
}
Ipdhcpc_if;
/*
*===========================================================================
* Ipdhcpc_data
*===========================================================================
*/
typedef struct Ipdhcpc_data_struct
{
Ip_bool opened;
Ipcom_mutex code_mutex; /* Mutex to protect IPDHCPC global data. */
int code_mutex_count;
Ip_fd fd;
Ip_fd ipd_fd;
Ip_fd rt_fd;
Ip_fd pkt_fd;
char buf[16];
struct Ip_sockaddr_in addr;
Ip_u32 last_brd_ifindex;
int open_interfaces;
Ip_u8 *in_raw;
Ipdhcpc_pkt *in_pkt;
Ip_ssize_t in_pkt_len;
Ipdhcpc_pkt *out_pkt;
Ipdhcpc_if *ift_head;
Ipdhcpc_handle *handle_head;
Ip_u16 max_message_size;
Ip_bool shut_down;
Ip_bool cid_uuid_type;
}
Ipdhcpc_data;
/*
*===========================================================================
* Ipdhcpc_ifopen
*===========================================================================
*/
typedef struct Ipdhcpc_ifopen_struct
{
Ip_u32 api_version; /* Currently version 1. Used for future compability. */
char clientid[IPDHCPC_CLIENT_ID_MAXSIZE+1]; /* must be null terminated! */
Ip_tag conf[1]; /* None available, included for future compability. */
}
Ipdhcpc_ifopen;
/*
****************************************************************************
* 6 FUNCTIONS
****************************************************************************
*/
/*
*===========================================================================
* Ipdhcpc_cmd_dhcpc
*===========================================================================
* Description: Install IPDHCPC shell commands
* Parameters:
* Returns:
*
*/
#ifdef IPDHCPC_INCLUDE_CMD
IP_GLOBAL int ipdhcpc_cmd_dhcpc(int argc, char **argv);
#endif
/*
*===========================================================================
* ipdhcpc_ifopen
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipdhcpc_ifopen(Ip_u32 ifindex, Ipdhcpc_ifopen *config);
/*
*===========================================================================
* ipdhcpc_ifclose
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipdhcpc_ifclose(Ip_u32 ifindex);
/*
*===========================================================================
* ipdhcpc_if_isopen
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_bool ipdhcpc_if_isopen(Ip_u32 ifindex);
/*
*===========================================================================
* ipdhcpc_ifrequest
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipdhcpc_ifrequest(Ip_u32 ifindex, Ipdhcpc_handle *handle);
/*
*===========================================================================
* ipdhcpc_iflease
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipdhcpc_iflease(Ip_u32 ifindex, Ipdhcpc_handle *handle);
/*
*===========================================================================
* ipdhcpc_ifunlease
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipdhcpc_ifunlease(Ip_u32 ifindex, Ipdhcpc_handle **handlep);
/*
*===========================================================================
* ipdhcpc_handle_malloc
*===========================================================================
* Description: Mallocate and initialize a DHCP client request handle for
* use with ipdhcpc_ifrequest().
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipdhcpc_handle_malloc(Ip_u32 ifindex,
int mode,
Ipdhcpc_handle **handlep);
/*
*===========================================================================
* ipdhcpc_handle_free
*===========================================================================
* Description: Free a DHCP client handle.
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_err ipdhcpc_handle_free(Ip_u32 ifindex, Ipdhcpc_handle *handle);
/*
*===========================================================================
* ipdhcpc_option_sprintf
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL int ipdhcpc_option_sprintf(Ip_u8 *option, char *buf, int buflen);
/*
*===========================================================================
* ipdhcpc_option_find
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_u8 *ipdhcpc_option_find(Ipdhcpc_handle *handle, Ip_u8 code);
/*
*===========================================================================
* ipdhcpc_option_get_first
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_u8 *ipdhcpc_option_get_first(Ip_u8 *options);
/*
*===========================================================================
* ipdhcpc_option_limit_get_next
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL Ip_u8 *
ipdhcpc_option_limit_get_next(Ip_u8 * options, Ip_u16 *size);
#ifdef __cplusplus
}
#endif
#endif
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/