/* ****************************************************************************** * 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 ****************************************************************************** */ #ifndef IPDHCPR_H_H #define IPDHCPR_H_H /* **************************************************************************** * 1 DESCRIPTION **************************************************************************** */ /* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */ /* **************************************************************************** * 3 INCLUDE FILES **************************************************************************** */ #include #include #include #include #include #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 **************************************************************************** */