/* ipdhcpc.h - API of DHCP client */ /* ****************************************************************************** * HEADER FILE * * Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipdhcpc.h,v $ $Revision: 1.29.16.3 $ * $Source: /home/interpeak/CVSRoot/ipappl/include/ipdhcpc.h,v $ * $Author: jwang9 $ $Date: 2016-05-20 07:17:44 $ * $State: Exp $ $Locker: $ * * INTERPEAK_COPYRIGHT_STRING * Design and implementation by Lennart Bang * and Jonas Rendel ****************************************************************************** */ #ifndef IPDHCPC_H #define IPDHCPC_H /* **************************************************************************** * 1 DESCRIPTION **************************************************************************** */ /* DESCRIPTION This library contains the API for the DHCP client */ /* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */ /* **************************************************************************** * 3 INCLUDE FILES **************************************************************************** */ #include #include #include #ifdef __cplusplus extern "C" { #endif /* **************************************************************************** * 4 DEFINES **************************************************************************** */ /* *=========================================================================== * DHCP option codes *=========================================================================== * Option codes automatically handled by IPDHCP. */ /* *=========================================================================== * DHCP option codes - auto *=========================================================================== * Option codes handled transparantly by IPDHCPC, i.e. user code does not * need to add/remove/modify these options. */ #define IPDHCPC_OPTCODE_DHCP_MESSAGE_TYPE 53 #define IPDHCPC_OPTCODE_DHCP_SERVER_IDENTIFIER 54 #define IPDHCPC_OPTCODE_DHCP_MAX_MESSAGE_SIZE 57 #define IPDHCPC_OPTCODE_DHCP_CLIENT_IDENTIFIER 61 #define IPDHCPC_OPTCODE_END 255 /* *=========================================================================== * DHCP option codes - used *=========================================================================== * Option codes used by IPDHCPC in some way or another. */ #define IPDHCPC_OPTCODE_PAD 0 #define IPDHCPC_OPTCODE_SUBNET_MASK 1 #define IPDHCPC_OPTCODE_ROUTERS 3 #define IPDHCPC_OPTCODE_DOMAIN_NAME_SERVERS 6 #define IPDHCPC_OPTCODE_DOMAIN_NAME 15 #define IPDHCPC_OPTCODE_DHCP_LEASE_TIME 51 #define IPDHCPC_OPTCODE_OPTION_OVERLOAD 52 #define IPDHCPC_OPTCODE_DHCP_PARAMETER_REQUEST_LIST 55 #define IPDHCPC_OPTCODE_DHCP_MESSAGE 56 #define IPDHCPC_OPTCODE_DHCP_RENEWAL_TIME 58 #define IPDHCPC_OPTCODE_DHCP_REBINDING_TIME 59 /* *=========================================================================== * DHCP option codes - user *=========================================================================== * Option codes not read or written by IPDHCPC. */ #define IPDHCPC_OPTCODE_TIME_OFFSET 2 #define IPDHCPC_OPTCODE_TIME_SERVERS 4 #define IPDHCPC_OPTCODE_NAME_SERVERS 5 #define IPDHCPC_OPTCODE_LOG_SERVERS 7 #define IPDHCPC_OPTCODE_COOKIE_SERVERS 8 #define IPDHCPC_OPTCODE_LPR_SERVERS 9 #define IPDHCPC_OPTCODE_IMPRESS_SERVERS 10 #define IPDHCPC_OPTCODE_RESOURCE_LOCATION_SERVERS 11 #define IPDHCPC_OPTCODE_HOST_NAME 12 #define IPDHCPC_OPTCODE_BOOT_SIZE 13 #define IPDHCPC_OPTCODE_MERIT_DUMP 14 #define IPDHCPC_OPTCODE_SWAP_SERVER 16 #define IPDHCPC_OPTCODE_ROOT_PATH 17 #define IPDHCPC_OPTCODE_EXTENSIONS_PATH 18 #define IPDHCPC_OPTCODE_IP_FORWARDING 19 #define IPDHCPC_OPTCODE_NON_LOCAL_SOURCE_ROUTING 20 #define IPDHCPC_OPTCODE_POLICY_FILTER 21 #define IPDHCPC_OPTCODE_MAX_DGRAM_REASSEMBLY 22 #define IPDHCPC_OPTCODE_DEFAULT_IP_TTL 23 #define IPDHCPC_OPTCODE_PATH_MTU_AGING_TIMEOUT 24 #define IPDHCPC_OPTCODE_PATH_MTU_PLATEAU_TABLE 25 #define IPDHCPC_OPTCODE_INTERFACE_MTU 26 #define IPDHCPC_OPTCODE_ALL_SUBNETS_LOCAL 27 #define IPDHCPC_OPTCODE_BROADCAST_ADDRESS 28 #define IPDHCPC_OPTCODE_PERFORM_MASK_DISCOVERY 29 #define IPDHCPC_OPTCODE_MASK_SUPPLIER 30 #define IPDHCPC_OPTCODE_ROUTER_DISCOVERY 31 #define IPDHCPC_OPTCODE_ROUTER_SOLICITATION_ADDRESS 32 #define IPDHCPC_OPTCODE_STATIC_ROUTES 33 #define IPDHCPC_OPTCODE_TRAILER_ENCAPSULATION 34 #define IPDHCPC_OPTCODE_ARP_CACHE_TIMEOUT 35 #define IPDHCPC_OPTCODE_IEEE802_3_ENCAPSULATION 36 #define IPDHCPC_OPTCODE_DEFAULT_TCP_TTL 37 #define IPDHCPC_OPTCODE_TCP_KEEPALIVE_INTERVAL 38 #define IPDHCPC_OPTCODE_TCP_KEEPALIVE_GARBAGE 39 #define IPDHCPC_OPTCODE_NIS_DOMAIN 40 #define IPDHCPC_OPTCODE_NIS_SERVERS 41 #define IPDHCPC_OPTCODE_NTP_SERVERS 42 #define IPDHCPC_OPTCODE_VENDOR_ENCAPSULATED_OPTIONS 43 #define IPDHCPC_OPTCODE_NETBIOS_NAME_SERVERS 44 #define IPDHCPC_OPTCODE_NETBIOS_DD_SERVER 45 #define IPDHCPC_OPTCODE_NETBIOS_NODE_TYPE 46 #define IPDHCPC_OPTCODE_NETBIOS_SCOPE 47 #define IPDHCPC_OPTCODE_FONT_SERVERS 48 #define IPDHCPC_OPTCODE_X_DISPLAY_MANAGER 49 #define IPDHCPC_OPTCODE_DHCP_REQUESTED_ADDRESS 50 #define IPDHCPC_OPTCODE_VENDOR_CLASS_IDENTIFIER 60 #define IPDHCPC_OPTCODE_TFTP_SERVER_NAME 66 #define IPDHCPC_OPTCODE_BOOTFILE_NAME 67 #define IPDHCPC_OPTCODE_VI_VENDOR_CLASS 124 #define IPDHCPC_OPTCODE_VI_VENDOR_INFORMATION 125 #define IPDHCPC_OPTCODE_TFTP_SERVER_ADDRESS 0 /* Fake option code */ /* *=========================================================================== * DHCP magic cookie *=========================================================================== * See RFC 2132. */ #define IPDHCPC_MAGIC_COOKIE 0x63825363 /* *=========================================================================== * DHCP reply callback event codes *=========================================================================== * Possible events to be sent and handled by a DHCP client reply callback. */ #define IPDHCPC_REPLY_CB_EVENT_ACK 1 /* Received an ACK */ #define IPDHCPC_REPLY_CB_EVENT_NAK 2 /* Received a NAK */ #define IPDHCPC_REPLY_CB_EVENT_EXPIRE 3 /* Lease expiration */ #define IPDHCPC_REPLY_CB_EVENT_FAIL_IFLOST 4 /* Lost the interface */ #define IPDHCPC_REPLY_CB_EVENT_BOOTREPLY 5 /* Received a boot reply */ #define IPDHCPC_REPLY_CB_EVENT_OFFER 6 /* Received an offer */ #define IPDHCPC_REPLY_CB_EVENT_FAIL_RETRY 7 /* Retries expired */ /* *=========================================================================== * DHCP reply callback return codes *=========================================================================== * Possible return values to be returned by a DHCP client reply callback. */ #define IPDHCPC_REPLY_CB_ERROR -1 #define IPDHCPC_REPLY_CB_SUCCESS 0 /* *=========================================================================== * RFC2131 3.6 Use of DHCP in clients with multiple interfaces *=========================================================================== * A client with multiple network interfaces must use DHCP through each interface independently to obtain configuration information parameters for those separate interfaces. */ #define IPDHCPC_OPTION_DOMAIN_CONF 1 #define IPDHCPC_OPTION_DNSSERVER_CONF 2 #define IPDHCPC_OPTION_NTPSERVER_CONF 4 #define IPDHCPC_SNAME_LEN (64) #define IPDHCPC_BOOTFILE_NAME_LEN (128) /* Reply callback for DHCP replies. */ struct Ipdhcpc_handle_priv_struct; struct Ipdhcpc_handle_struct; typedef int (*Ipdhcpc_reply_cb)(struct Ipdhcpc_handle_struct *handle, int event); /* **************************************************************************** * 5 TYPES **************************************************************************** */ /* *=========================================================================== * Ipdhcpc_info *=========================================================================== * This structure is filled in by the IPDHCPC code upon valid DHCP client * request reply. */ typedef struct Ipdhcpc_info_struct { Ip_err status; /* IPCOM_SUCCESS else IPCOM_ERR_XXX. */ Ip_u32 ipaddr_n; /* Client IP address (yiaddr). */ Ip_u32 serveraddr_n; /* Server IP in network endian. Default = 0 -> broadcast */ Ip_u16 serverport_n; /* Server UDP port in network endian. Default = ip_htons(67). */ Ip_u16 reserved; int optlen; /* Options length excluding cookie. */ Ip_u8 *options; /* DHCP options */ Ip_u8 sname[IPDHCPC_SNAME_LEN]; /* Optional server host name, null terminated string. */ Ip_u32 bootaddr_n; /* IP address of next bootstrap server (siaddr). */ Ip_u8 file[IPDHCPC_BOOTFILE_NAME_LEN]; /* Optional boot file name, null terminated string. */ Ip_time_t t1; /* Time at which we enter RENEWING state */ Ip_time_t t2; /* Time at which we enter REBINDING state */ } Ipdhcpc_info; /* *=========================================================================== * Ipdhcpc_handle *=========================================================================== * Created and initialized by ipdhcpc_handle_malloc() to prepare for a * DHCP client request. User may modify the handle before calling * ipdhcpc_ifrequest(). * */ typedef struct Ipdhcpc_handle_struct { Ip_u32 user_res[2]; /* Reserved for user use. IPDHCPC does not touch it. */ Ip_u32 ifindex; /* DHCP interface index. Set by ipdhcpc_handle_malloc(). */ Ip_u32 clientaddr_n; /* Desired IP in network endian else 0. */ Ip_u32 serveraddr_n; /* Server IP in network endian. Default = 0 -> broadcast */ Ip_u16 serverport_n; /* Server UDP port in network endian. Default = ip_htons(67). */ Ip_u16 reserved; Ip_u32 magic_cookie; /* Magic vendor cookie. Default=0x63825363. */ char file[IPDHCPC_BOOTFILE_NAME_LEN]; /* Optional boot file name, null terminated string. */ char sname[IPDHCPC_SNAME_LEN]; /* Optional server host name, null terminated string. */ /* User callback for the reply. Set to IP_NULL for blocking mode. */ Ipdhcpc_reply_cb reply_cb; int optlen; /* User options length. */ Ip_u8 *options; /* Additional user options. */ Ip_u32 option_confvar;/* interface set sysvar of dnsserver ,doname, or ntpserver */ /***** IPDHCPC info for the user after succesful DHCP server reply. */ Ipdhcpc_info info; /***** IPDHCPC private info. do not read/write *****/ struct Ipdhcpc_handle_priv_struct *priv; } Ipdhcpc_handle; /* **************************************************************************** * 6 FUNCTIONS **************************************************************************** */ /******************************************************************************* * * ipdhcpc_option_callback - apply user-defined actions based on DHCP option * * This callback routine examines each DHCP option returned by a DHCP server and * can execute user-defined operations for specific options. For example, it can * be implemented to apply a different operation to each of three vendor-specific * options received from the server. * * The callback is executed before any other client action on the server\'s * response and can be used to change the contents of the response before it is * acted on further. For a sample implementation, see 'ipdhcpc_example.c'. * * Parameter: * \is * \i