27 #define DHCP_DBG(...) \ 28 vlib_log_debug (dhcp_logger, __VA_ARGS__) 30 #define DHCP_INFO(...) \ 31 vlib_log_notice (dhcp_logger, __VA_ARGS__) 33 #define foreach_dhcp_sent_packet_stat \ 34 _(DISCOVER, "DHCP discover packets sent") \ 35 _(OFFER, "DHCP offer packets sent") \ 36 _(REQUEST, "DHCP request packets sent") \ 37 _(ACK, "DHCP ack packets sent") 39 #define foreach_dhcp_error_counter \ 40 _(NOT_FOR_US, "DHCP packets for other hosts, dropped") \ 41 _(NAK, "DHCP nak packets received") \ 42 _(NON_OFFER_DISCOVER, "DHCP non-offer packets in discover state") \ 43 _(ODDBALL, "DHCP non-ack, non-offer packets received") \ 44 _(BOUND, "DHCP bind success") 48 #define _(sym,str) DHCP_STAT_##sym, 56 #define _(sym,string) string, 59 "DHCP unknown packets sent",
89 int verbose = va_arg (*va,
int);
92 s =
format (s,
"[%d] %U state %U installed %d", c - dcm->
clients,
101 s =
format (s,
" addr %U/%d gw %U server %U",
112 s =
format (s,
" no address");
119 "\n lease: lifetime:%d renewal-interval:%d expires:%.2f (now:%.2f)",
148 ip46_address_t
nh = {
192 ip46_address_t
nh = {
226 "ip4-dhcp-client-detect",
252 "ip4-dhcp-client-detect",
259 c->
state = DHCP_DISCOVER;
283 u8 dhcp_message_type = 0;
307 DHCP_STAT_NOT_FOR_US, 1);
319 while (o->
option != 0xFF &&
325 dhcp_message_type = o->
data[0];
330 u32 lease_time_in_seconds =
342 u32 lease_renew_time_in_seconds =
395 DHCP_STAT_NON_OFFER_DISCOVER, 1);
401 c->
state = DHCP_REQUEST;
407 (
u8 *) & client_id,
sizeof (
uword));
426 DHCP_STAT_NON_OFFER_DISCOVER, 1);
427 clib_warning (
"sw_if_index %d state %U message type %d",
429 c->
state, dhcp_message_type);
439 (
u8 *) & cindex,
sizeof (
u32));
442 c->
state = DHCP_BOUND;
477 u16 udp_length, ip_length;
506 b->
flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
529 clib_memset (ip, 0,
sizeof (*ip) +
sizeof (*udp) +
sizeof (*dhcp));
545 b->
flags |= VNET_BUFFER_F_QOS_DATA_VALID;
560 udp->
src_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client);
561 udp->
dst_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server);
572 if (is_broadcast == 0)
599 *o2 = clib_host_to_net_u16 (1152);
669 ip->
length = clib_host_to_net_u16 (ip_length);
672 udp_length = ip_length - (
sizeof (*ip));
673 udp->
length = clib_host_to_net_u16 (udp_length);
677 #define _(a,b) case DHCP_PACKET_##a: {counter_index = DHCP_STAT_##a; break;} 708 "ip4-dhcp-client-detect",
738 c->
state = DHCP_DISCOVER;
758 "ip4-dhcp-client-detect",
805 if (now < c->next_transmit)
841 f64 timeout = 1000.0;
842 f64 next_expire_time, this_next_expire_time;
845 uword *event_data = 0;
861 for (i = 0; i <
vec_len (event_data); i++)
869 next_expire_time = 1e70;
872 this_next_expire_time = dhcp_client_sm
873 (now, timeout, (uword) (c - dcm->clients));
874 next_expire_time = this_next_expire_time < next_expire_time ?
875 this_next_expire_time : next_expire_time;
877 if (next_expire_time > now)
878 timeout = next_expire_time - now;
902 .name =
"dhcp-client-process",
903 .process_log2_n_stack_bytes = 16,
925 else if (
unformat (input,
"verbose"))
931 if (sw_if_index != ~0)
944 vlib_cli_output (vm,
"%U",
945 format_dhcp_client, dcm,
955 .path =
"show dhcp client",
956 .short_help =
"show dhcp client [intfc <intfc>][verbose]",
973 return VNET_API_ERROR_INVALID_VALUE;
980 c->
state = DHCP_DISCOVER;
1091 case VNET_API_ERROR_INVALID_VALUE:
1098 DHCP_INFO (
"dhcp client already enabled on intf_idx %d", sw_if_index);
1100 DHCP_INFO (
"not enabled on on intf_idx %d", sw_if_index);
1104 DHCP_INFO (
"dhcp_client_add_del returned %d", rv);
1135 u8 sw_if_index_set = 0;
1145 sw_if_index_set = 1;
1146 else if (
unformat (input,
"hostname %v", &hostname))
1150 else if (
unformat (input,
"broadcast", &set_broadcast_flag))
1156 if (sw_if_index_set == 0)
1205 case VNET_API_ERROR_INVALID_VALUE:
1229 .path =
"set dhcp client",
1230 .short_help =
"set dhcp client [del] intfc <interface> [hostname <name>]",
1244 if (ip4_lookup_node == 0)
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
u8 client_detect_feature_enabled
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
fib_node_index_t fib_table_entry_path_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, dpo_proto_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, fib_mpls_label_t *next_hop_labels, fib_route_path_flags_t path_flags)
Add one path to an entry (aka route) in the FIB.
#define hash_set(h, key, value)
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
#define hash_unset(h, key)
int dhcp_client_add_del(dhcp_client_add_del_args_t *a)
ip4_address_t router_address
The address of this client's default gateway - may not be present.
#define foreach_dhcp_sent_packet_stat
vnet_main_t * vnet_get_main(void)
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
static char * dhcp_client_process_stat_strings[]
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static vlib_node_registration_t dhcp_client_process_node
(constructor) VLIB_REGISTER_NODE (dhcp_client_process_node)
static f64 vlib_time_now(vlib_main_t *vm)
u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto, u32 sw_if_index)
Get the index of the FIB bound to the interface.
u16 current_length
Nbytes between current data and the end of this buffer.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static u64 clib_cpu_time_now(void)
static uword dhcp_client_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
void vlib_cli_output(struct vlib_main_t *vm, char *fmt,...)
unformat_function_t unformat_vnet_sw_interface
static clib_error_t * show_dhcp_client_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
dhcp_client_fwd_addresses_t installed
dhcp_event_cb_t event_callback
dhcp_client_state_t state
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
format_function_t format_vnet_sw_if_index_name
ip4_address_t dhcp_server
the address of the DHCP server handing out the address.
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
vlib_node_registration_t ip4_lookup_node
(constructor) VLIB_REGISTER_NODE (ip4_lookup_node)
#define clib_memcpy(d, s, n)
vlib_log_class_t dhcp_logger
u32 lease_renewal_interval
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
u32 ip4_lookup_node_index
vl_api_interface_index_t sw_if_index
#define VLIB_INIT_FUNCTION(x)
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
static void dhcp_client_release_address(dhcp_client_main_t *dcm, dhcp_client_t *c)
dhcp_event_cb_t event_callback
vnet_hw_interface_flags_t flags
static vnet_sw_interface_t * vnet_get_sup_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Aggregate type for a prefix.
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
#define clib_error_return(e, args...)
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
u8 * format_dhcp_packet_type(u8 *s, va_list *args)
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
u16 fp_len
The mask length.
static const u8 * vnet_sw_interface_get_hw_address(vnet_main_t *vnm, u32 sw_if_index)
vl_api_fib_path_type_t type
clib_error_t * ip4_add_del_interface_address(vlib_main_t *vm, u32 sw_if_index, ip4_address_t *address, u32 address_length, u32 is_del)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
static u8 * format_dhcp_client_state(u8 *s, va_list *va)
dhcp_client_main_t dhcp_client_main
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
ip4_address_t leased_address
the address assigned to this client and it's mask
void(* dhcp_event_cb_t)(u32 client_index, const struct dhcp_client_t_ *client)
Callback function for DHCP complete events.
#define pool_put(P, E)
Free an object E in pool P.
static f64 dhcp_client_sm(f64 now, f64 timeout, uword pool_index)
vnet_sw_interface_flags_t flags
u8 client_hardware_address[6]
static u32 counter_index(vlib_main_t *vm, vlib_error_t e)
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
#define VLIB_REGISTER_NODE(x,...)
vlib_node_registration_t ip4_rewrite_node
(constructor) VLIB_REGISTER_NODE (ip4_rewrite_node)
static_always_inline uword vlib_get_thread_index(void)
static clib_error_t * dhcp_client_init(vlib_main_t *vm)
#define clib_memcmp(s1, s2, m1)
ip4_address_t * domain_server_address
#define vec_free(V)
Free vector's memory (no header).
#define clib_warning(format, args...)
#define foreach_dhcp_error_counter
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
static int dhcp_bound_state(dhcp_client_main_t *dcm, dhcp_client_t *c, f64 now)
static void send_dhcp_pkt(dhcp_client_main_t *dcm, dhcp_client_t *c, dhcp_packet_type_t type, int is_broadcast)
#define VLIB_CLI_COMMAND(x,...)
int dhcp_client_for_us(u32 bi, vlib_buffer_t *b, ip4_header_t *ip, udp_header_t *udp, dhcp_header_t *dhcp)
#define EVENT_DHCP_CLIENT_WAKEUP
static void dhcp_client_addr_callback(u32 *cindex)
enum ip_dscp_t_ ip_dscp_t
static void dhcp_client_acquire_address(dhcp_client_main_t *dcm, dhcp_client_t *c)
static clib_error_t * dhcp_client_set_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
void dhcp_client_walk(dhcp_client_walk_cb_t cb, void *ctx)
Walk (visit each) DHCP client configuration.
void fib_table_entry_path_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, dpo_proto_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, fib_route_path_flags_t path_flags)
remove one path to an entry (aka route) in the FIB.
#define DHCP_FLAG_BROADCAST
static vlib_main_t * vlib_get_main(void)
vl_api_address_t router_address
static int dhcp_request_state(dhcp_client_main_t *dcm, dhcp_client_t *c, f64 now)
struct _vlib_node_registration vlib_node_registration_t
static int dhcp_discover_state(dhcp_client_main_t *dcm, dhcp_client_t *c, f64 now)
int(* dhcp_client_walk_cb_t)(const dhcp_client_t *client, void *data)
callback function for clients walking the DHCP client configurations
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static u8 * format_dhcp_client(u8 *s, va_list *va)
void vl_api_force_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
VLIB buffer representation.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
void dhcp_maybe_register_udp_ports(dhcp_port_reg_flags_t ports)
Register the dhcp client and/or server ports, if not already done.
uword * client_by_sw_if_index
static u32 random_u32(u32 *seed)
32-bit random number generator
vl_api_dhcp_client_state_t state
adj_index_t adj_nbr_add_or_lock(fib_protocol_t nh_proto, vnet_link_t link_type, const ip46_address_t *nh_addr, u32 sw_if_index)
Neighbour Adjacency sub-type.
#define vec_foreach(var, vec)
Vector iterator.
static uword count_set_bits(uword x)
static void dhcp_client_reset(dhcp_client_main_t *dcm, dhcp_client_t *c)
dhcp_client_fwd_addresses_t learned
leased address, other learned info DHCP the learned set is updated by new messages recieved in the DP...
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static u16 ip4_header_checksum(ip4_header_t *i)
const ip46_address_t ADJ_BCAST_ADDR
The special broadcast address (to construct a broadcast adjacency.
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
int dhcp_client_config(u32 is_add, u32 client_index, vlib_main_t *vm, u32 sw_if_index, u8 *hostname, u8 *client_id, dhcp_event_cb_t event_callback, u8 set_broadcast_flag, ip_dscp_t dscp, u32 pid)
Add/Delete DHCP clients.
static void dhcp_client_proc_callback(uword *client_index)
static uword pool_elts(void *v)
Number of active elements in a pool.