DHCP

Overview

Declarations of API for TAPI DHCP. More…

// typedefs

typedef enum dhcp_option_type dhcp_option_type;
typedef struct dhcp_message dhcp_message;

// enums

enum dhcp_message_type;
enum dhcp_option_type;

// structs

struct dhcp_message;
struct dhcp_option;

// global functions

int ndn_dhcpv4_packet_to_plain(const asn_value* pkt, struct dhcp_message** dhcp_msg);
int ndn_dhcpv4_plain_to_packet(const dhcp_message* dhcp_msg, asn_value** pkt);
struct dhcp_message* dhcpv4_message_create(dhcp_message_type msg_type);
struct dhcp_message* dhcpv4_bootp_message_create(uint8_t op);
void dhcpv4_message_destroy(struct dhcp_message*);
int tapi_dhcpv4_plain_csap_create(const char* ta_name, const char* iface, dhcp_csap_mode mode, csap_handle_t* dhcp_csap);
int tapi_dhcpv4_message_send(const char* ta_name, csap_handle_t dhcp_csap, const struct dhcp_message* dhcp_msg);
int dhcpv4_prepare_traffic_template(const dhcp_message* dhcp_msg, const char** templ_fname);
int dhcpv4_prepare_traffic_pattern(const dhcp_message* dhcp_msg, char** pattern_fname);
int dhcpv4_message_start_recv(const char* ta_name, csap_handle_t dhcp_csap, unsigned int timeout, dhcp_message_type msg_type);
struct dhcp_message* dhcpv4_message_capture(const char* ta_name, csap_handle_t dhcp_csap, unsigned int* timeout);
struct dhcp_message* tapi_dhcpv4_send_recv(const char* ta_name, csap_handle_t dhcp_csap, const struct dhcp_message* dhcp_msg, unsigned int* tv, const char** err_msg);
int tapi_dhcpv4_csap_get_ipaddr(const char* ta_name, csap_handle_t dhcp_csap, void* addr);
const struct dhcp_option* dhcpv4_message_get_option(const struct dhcp_message* dhcp_msg, uint8_t type);
const struct dhcp_option* dhcpv4_message_get_sub_option(const struct dhcp_option* opt, uint8_t type);
void dhcpv4_message_fill_reply_from_req(struct dhcp_message* dhcp_rep, const struct dhcp_message* dhcp_req);
struct dhcp_option* dhcpv4_option_create(uint8_t type, uint8_t len, uint8_t val_len, uint8_t* val);
int dhcpv4_option_add_subopt(struct dhcp_option* opt, uint8_t type, uint8_t len, uint8_t* val);
int dhcpv4_option_insert_subopt(struct dhcp_option* opt, struct dhcp_option* subopt);
int dhcpv4_message_add_option(struct dhcp_message* dhcp_msg, uint8_t type, uint8_t len, const void* val);
int dhcpv4_message_insert_option(struct dhcp_message* dhcp_msg, struct dhcp_option* opt);
te_bool dhcpv4_option55_has_code(const struct dhcp_option* opt, uint8_t type);
te_errno tapi_dhcp_request_ip_addr(char const* ta, char const* if_name, uint8_t const mac[ETHER_ADDR_LEN], struct sockaddr* ip_addr);
te_errno tapi_dhcp_release_ip_addr(char const* ta, char const* if_name, struct sockaddr const* ip_addr);
int tapi_dhcpv6_plain_csap_create(const char* ta_name, const char* iface, dhcp6_csap_mode mode, csap_handle_t* dhcp_csap);
int dhcpv6_prepare_traffic_template(const asn_value* dhcp6_msg, asn_value** templ_p);
int dhcpv6_prepare_traffic_pattern(const asn_value* dhcp_msg, asn_value** pattern_p);

// macros

#define CONST_STRING_LENGTH(str_)
#define DHCPV4_HDR_CHADDR_SIZE
#define DHCPV4_HDR_FILE_SIZE
#define DHCPV4_HDR_SNAME_SIZE
#define DHCP_HW_TYPE_ETHERNET_10MB
#define DHCP_OP_CODE_BOOTREPLY
#define DHCP_OP_CODE_BOOTREQUEST
#define ETHER_ADDR_LEN
#define FLAG_BROADCAST
#define dhcpv4_message_get_chaddr(msg_)
#define dhcpv4_message_get_ciaddr(msg_)
#define dhcpv4_message_get_field(msg_, field_)
#define dhcpv4_message_get_flags(msg_)
#define dhcpv4_message_get_giaddr(msg_)
#define dhcpv4_message_get_hlen(msg_)
#define dhcpv4_message_get_htype(msg_)
#define dhcpv4_message_get_op(msg_)
#define dhcpv4_message_get_siaddr(msg_)
#define dhcpv4_message_get_xid(msg_)
#define dhcpv4_message_get_yiaddr(msg_)
#define dhcpv4_message_set_array_field(msg_, field_, value_)
#define dhcpv4_message_set_chaddr(msg_, value_)
#define dhcpv4_message_set_ciaddr(msg_, value_)
#define dhcpv4_message_set_file(msg_, value_)
#define dhcpv4_message_set_flags(msg_, value_)
#define dhcpv4_message_set_giaddr(msg_, value_)
#define dhcpv4_message_set_hlen(msg_, value_)
#define dhcpv4_message_set_hops(msg_, value_)
#define dhcpv4_message_set_htype(msg_, value_)
#define dhcpv4_message_set_op(msg_, value_)
#define dhcpv4_message_set_secs(msg_, value_)
#define dhcpv4_message_set_siaddr(msg_, value_)
#define dhcpv4_message_set_simple_field(msg_, field_, value_)
#define dhcpv4_message_set_sname(msg_, value_)
#define dhcpv4_message_set_xid(msg_, value_)
#define dhcpv4_message_set_yiaddr(msg_, value_)

Detailed Documentation

Declarations of API for TAPI DHCP.

Copyright (C) 2004-2022 OKTET Labs Ltd. All rights reserved.

Typedefs

typedef enum dhcp_option_type dhcp_option_type

Type of DHCP Options

typedef struct dhcp_message dhcp_message

Structure of DHCP message

Global Functions

struct dhcp_message* dhcpv4_message_create(dhcp_message_type msg_type)

Creates DHCP message of specified type. It fills the following fields as: op - According to ‘msg_type’ htype - Ethernet (10Mb) hlen - ETHER_ADDR_LEN

All other fields are left unspecified

It adds Option 53 in DHCP message with value ‘msg_type’

Parameters:

msg_type

Type of the DHCP message to be created

Returns:

Pointer to the message handle or NULL if there is not enough memory

struct dhcp_message* dhcpv4_bootp_message_create(uint8_t op)

Creates DHCP BOOTP message with specified operation set. It fills the following fields as: op - According to ‘op’ htype - Ethernet (10Mb) hlen - ETHER_ADDR_LEN

All other fields are left unspecified

Parameters:

op

Operation

Returns:

Pointer to the message handle or NULL

int dhcpv4_prepare_traffic_template(const dhcp_message* dhcp_msg, const char** templ_fname)

Creates ASN.1 text file with traffic template of one DHCPv4 message

Parameters:

dhcp_msg

DHCPv4 message

templ_fname

Traffic template file name (OUT)

Returns:

status code

int dhcpv4_prepare_traffic_pattern(const dhcp_message* dhcp_msg, char** pattern_fname)

Creates ASN.1 text file with traffic pattern of one DHCPv4 message

Parameters:

dhcp_msg

DHCPv4 message to be used as a pattern

pattern_fname

Traffic pattern file name (OUT)

Returns:

status code

int dhcpv4_message_start_recv(const char* ta_name, csap_handle_t dhcp_csap, unsigned int timeout, dhcp_message_type msg_type)

Star receive of DHCP message of desired type during timeout.

Parameters:

ta_name

Name of Test Agent

dhcp_csap

ID of DHCP CSAP, which should receive message

timeout

Time while CSAP will receive, measured in milliseconds, counted wince start receive, may be TAD_TIMEOUT_INF for infinitive wait

msg_type

Desired type of message

Returns:

status code

te_errno tapi_dhcp_request_ip_addr(char const* ta, char const* if_name, uint8_t const mac[ETHER_ADDR_LEN], struct sockaddr* ip_addr)

Request IP address via DHCP protocol

Parameters:

ta

Test agent name

if_name

Name of the interface to request from

mac

MAC address to use in request

ip_addr

Storage for IP address that is returned

Returns:

status code

te_errno tapi_dhcp_release_ip_addr(char const* ta, char const* if_name, struct sockaddr const* ip_addr)

Release IP address via DHCP protocol

Parameters:

ta

Test agent name

if_name

Name of the interface to send release request from

ip_addr

Storage for IP address that is to release

Returns:

status code

Macros

#define DHCPV4_HDR_CHADDR_SIZE

Size ‘chaddr’ field of DHCP message

#define DHCPV4_HDR_FILE_SIZE

Size ‘file’ field of DHCP message

#define DHCPV4_HDR_SNAME_SIZE

Size ‘sname’ field of DHCP message

#define DHCP_HW_TYPE_ETHERNET_10MB

Value used in DHCP ‘htype’ field for Ethernet (10Mb) hardware type [RFC 1700]

#define FLAG_BROADCAST

BROADCAST flag

#define dhcpv4_message_get_field(msg_, field_)

Gets the value of the field in dhcp_message structure

Parameters:

msg_

Pointer to DHCP message

field_

Field name whose value to be got

#define dhcpv4_message_set_array_field(msg_, field_, value_)

Sets a new value in dhcp_message structure (It is used to update array fields of the structure)

Parameters:

msg_

Pointer to DHCP message

field_

Field name to be updated

value_

Pointer to the new value

#define dhcpv4_message_set_chaddr(msg_, value_)

Note that ‘value_’ MUST be a pointer to a buffer with at least DHCPV4_HDR_CHADDR_SIZE valid bytes

#define dhcpv4_message_set_file(msg_, value_)

Note that ‘value_’ MUST be a pointer to a buffer with at least DHCPV4_HDR_FILE_SIZE valid bytes

#define dhcpv4_message_set_simple_field(msg_, field_, value_)

Sets a new value in dhcp_message structure (It is used to update simple type fields - not arrays)

Parameters:

msg_

Pointer to DHCP message

field_

Field name to be updated

value_

Pointer to the new value

#define dhcpv4_message_set_sname(msg_, value_)

Note that ‘value_’ MUST be a pointer to a buffer with at least DHCPV4_HDR_SNAME_SIZE valid bytes