|
FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
|
Go to the documentation of this file.
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);
97 s =
format (s,
" dscp %d",
c->dscp);
99 if (
c->installed.leased_address.as_u32)
101 s =
format (s,
" addr %U/%d gw %U server %U",
103 c->installed.subnet_mask_width,
112 s =
format (s,
" no address");
119 "\n lease: lifetime:%d renewal-interval:%d expires:%.2f (now:%.2f)",
120 c->lease_lifetime,
c->lease_renewal_interval,
123 format (s,
"\n retry-count:%d, next-xmt:%.2f",
c->retry_count,
125 s =
format (s,
"\n broadcast adjacency:%d",
c->ai_bcast);
136 if (!
c->addresses_installed)
139 (
void *) &
c->learned.leased_address,
140 c->learned.subnet_mask_width,
142 if (
c->learned.router_address.as_u32)
148 ip46_address_t
nh = {
149 .ip4 =
c->learned.router_address,
168 c->addresses_installed = 1;
178 if (
c->addresses_installed)
181 (
void *) &
c->installed.leased_address,
182 c->installed.subnet_mask_width,
186 if (
c->installed.router_address.as_u32)
192 ip46_address_t
nh = {
193 .ip4 =
c->installed.router_address,
204 c->addresses_installed = 0;
226 "ip4-dhcp-client-detect",
227 c->sw_if_index, 0 , 0, 0);
228 c->client_detect_feature_enabled = 0;
231 if (0 !=
clib_memcmp (&
c->installed, &
c->learned, sizeof (
c->learned)))
240 if (
c->event_callback)
241 c->event_callback (
c->client_index,
c);
250 if (
c->client_detect_feature_enabled == 1)
253 "ip4-dhcp-client-detect",
254 c->sw_if_index, 0, 0, 0);
255 c->client_detect_feature_enabled = 0;
261 c->state = DHCP_DISCOVER;
264 c->lease_renewal_interval = 0;
285 u8 dhcp_message_type = 0;
301 if (
c->state == DHCP_BOUND &&
c->retry_count == 0)
306 sizeof (
c->client_hardware_address)))
309 DHCP_STAT_NOT_FOR_US, 1);
327 dhcp_message_type = o->
data[0];
332 u32 lease_time_in_seconds =
335 c->lease_expires =
now + (
f64) lease_time_in_seconds;
336 c->lease_lifetime = lease_time_in_seconds;
338 c->lease_renewal_interval = lease_time_in_seconds / 2;
344 u32 lease_renew_time_in_seconds =
346 c->lease_renewal_interval = lease_renew_time_in_seconds;
397 DHCP_STAT_NON_OFFER_DISCOVER, 1);
398 c->next_transmit =
now + 5.0;
403 c->state = DHCP_REQUEST;
405 c->next_transmit = 0;
409 (
u8 *) & client_id,
sizeof (
uword));
428 DHCP_STAT_NON_OFFER_DISCOVER, 1);
429 clib_warning (
"sw_if_index %d state %U message type %d",
431 c->state, dhcp_message_type);
432 c->next_transmit =
now + 5.0;
441 (
u8 *) & cindex,
sizeof (
u32));
444 c->state = DHCP_BOUND;
446 c->next_transmit =
now + (
f64)
c->lease_renewal_interval;
447 c->lease_expires =
now + (
f64)
c->lease_lifetime;
479 u16 udp_length, ip_length;
497 c->next_transmit = 0;
507 b->
flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
532 ip->ip_version_and_header_length = 0x45;
534 ip->protocol = IP_PROTOCOL_UDP;
546 b->
flags |= VNET_BUFFER_F_QOS_DATA_VALID;
552 ip->dst_address.as_u32 = ~0;
557 ip->src_address.as_u32 =
c->learned.leased_address.as_u32;
558 ip->dst_address.as_u32 =
c->learned.dhcp_server.as_u32;
561 udp->
src_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client);
562 udp->
dst_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_server);
570 sizeof (
c->client_hardware_address));
573 if (is_broadcast == 0)
581 clib_host_to_net_u16 (is_broadcast &&
c->set_broadcast_flag ?
600 *o2 = clib_host_to_net_u16 (1152);
609 if (
c->learned.dhcp_server.as_u32)
618 if (
c->learned.leased_address.as_u32)
670 ip->length = clib_host_to_net_u16 (ip_length);
673 udp_length = ip_length - (
sizeof (*ip));
674 udp->
length = clib_host_to_net_u16 (udp_length);
678 #define _(a,b) case DHCP_PACKET_##a: {counter_index = DHCP_STAT_##a; break;}
706 if (
c->client_detect_feature_enabled == 0)
710 "ip4-dhcp-client-detect",
711 c->sw_if_index, 1 , 0, 0);
713 c->client_detect_feature_enabled = 1;
719 if (
c->retry_count > 10)
720 c->next_transmit =
now + 5.0;
722 c->next_transmit =
now + 1.0;
739 if (
c->retry_count > 7 )
741 c->state = DHCP_DISCOVER;
742 c->next_transmit =
now;
746 c->next_transmit =
now + 1.0;
758 if (
c->client_detect_feature_enabled == 0)
762 "ip4-dhcp-client-detect",
763 c->sw_if_index, 1 , 0, 0);
765 c->client_detect_feature_enabled = 1;
774 if (
now >
c->lease_expires)
789 if (
c->retry_count > 10)
790 c->next_transmit =
now + 5.0;
792 c->next_transmit =
now + 1.0;
810 if (now < c->next_transmit)
811 return c->next_transmit;
839 return c->next_transmit;
846 f64 timeout = 1000.0;
847 f64 next_expire_time, this_next_expire_time;
850 uword *event_data = 0;
874 next_expire_time = 1e70;
879 next_expire_time = this_next_expire_time < next_expire_time ?
880 this_next_expire_time : next_expire_time;
882 if (next_expire_time >
now)
883 timeout = next_expire_time -
now;
907 .name =
"dhcp-client-process",
908 .process_log2_n_stack_bytes = 16,
930 else if (
unformat (input,
"verbose"))
960 .path =
"show dhcp client",
961 .short_help =
"show dhcp client [intfc <intfc>][verbose]",
977 if ((p &&
a->is_add) || (!p &&
a->is_add == 0))
978 return VNET_API_ERROR_INVALID_VALUE;
985 c->state = DHCP_DISCOVER;
986 c->sw_if_index =
a->sw_if_index;
987 c->client_index =
a->client_index;
989 c->event_callback =
a->event_callback;
990 c->option_55_data =
a->option_55_data;
991 c->hostname =
a->hostname;
992 c->client_identifier =
a->client_identifier;
993 c->set_broadcast_flag =
a->set_broadcast_flag;
1003 while (
c->transaction_id == 0);
1046 a->client_index = client_index;
1048 a->event_callback = event_callback;
1053 vec_validate (
a->client_identifier, strlen ((
char *) client_id) - 1);
1054 strncpy ((
char *)
a->client_identifier, (
char *) client_id,
1096 case VNET_API_ERROR_INVALID_VALUE:
1109 DHCP_INFO (
"dhcp_client_add_del returned %d",
rv);
1140 u8 sw_if_index_set = 0;
1150 sw_if_index_set = 1;
1161 if (sw_if_index_set == 0)
1168 a->client_identifier =
format (0,
"vpp 1.1%c", 0);
1210 case VNET_API_ERROR_INVALID_VALUE:
1234 .path =
"set dhcp client",
1235 .short_help =
"set dhcp client [del] intfc <interface> [hostname <name>]",
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static int dhcp_bound_state(dhcp_client_main_t *dcm, dhcp_client_t *c, f64 now)
static clib_error_t * dhcp_client_set_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
vlib_node_registration_t ip4_lookup_node
(constructor) VLIB_REGISTER_NODE (ip4_lookup_node)
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.
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
enum ip_dscp_t_ ip_dscp_t
#define clib_memcpy(d, s, n)
static int dhcp_request_state(dhcp_client_main_t *dcm, dhcp_client_t *c, f64 now)
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.
static clib_error_t * show_dhcp_client_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
#define clib_memcmp(s1, s2, m1)
void dhcp_maybe_register_udp_ports(dhcp_port_reg_flags_t ports)
Register the dhcp client and/or server ports, if not already done.
static void dhcp_client_release_address(dhcp_client_main_t *dcm, dhcp_client_t *c)
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
@ foreach_dhcp_client_state
vnet_hw_interface_flags_t flags
#define clib_error_return(e, args...)
static void dhcp_client_acquire_address(dhcp_client_main_t *dcm, dhcp_client_t *c)
uword * client_by_sw_if_index
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
const ip46_address_t ADJ_BCAST_ADDR
The special broadcast address (to construct a broadcast adjacency.
static u8 * format_dhcp_client_state(u8 *s, va_list *va)
u16 fp_len
The mask length.
@ VNET_SW_INTERFACE_FLAG_ADMIN_UP
#define pool_put(P, E)
Free an object E in pool P.
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
static u32 counter_index(vlib_main_t *vm, vlib_error_t e)
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
@ VNET_HW_INTERFACE_FLAG_LINK_UP
vl_api_dhcp_client_state_t state
vlib_node_registration_t ip4_rewrite_node
(constructor) VLIB_REGISTER_NODE (ip4_rewrite_node)
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
static void dhcp_client_reset(dhcp_client_main_t *dcm, dhcp_client_t *c)
static int dhcp_discover_state(dhcp_client_main_t *dcm, dhcp_client_t *c, f64 now)
#define DHCP_FLAG_BROADCAST
vnet_sw_interface_flags_t flags
static u32 random_u32(u32 *seed)
32-bit random number generator
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
#define hash_set(h, key, value)
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,...
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
#define pool_foreach(VAR, POOL)
Iterate through pool.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
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)
@ DHCP_PACKET_OPTION_MSG_TYPE
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
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.
static __clib_warn_unused_result u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
static vlib_cli_command_t dhcp_client_set_command
(constructor) VLIB_CLI_COMMAND (dhcp_client_set_command)
vl_api_address_t router_address
vnet_main_t * vnet_get_main(void)
void vl_api_force_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
#define vlib_worker_thread_barrier_sync(X)
static_always_inline uword vlib_get_thread_index(void)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
#define foreach_dhcp_error_counter
static const u8 * vnet_sw_interface_get_hw_address(vnet_main_t *vnm, u32 sw_if_index)
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
void(* dhcp_event_cb_t)(u32 client_index, const struct dhcp_client_t_ *client)
Callback function for DHCP complete events.
u8 * format_dhcp_packet_type(u8 *s, va_list *args)
sll srl srl sll sra u16x4 i
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
#define VLIB_CLI_COMMAND(x,...)
static void dhcp_client_addr_callback(u32 *cindex)
struct _vlib_node_registration vlib_node_registration_t
u16 current_length
Nbytes between current data and the end of this buffer.
static uword count_set_bits(uword x)
#define vec_free(V)
Free vector's memory (no header).
static u8 * format_dhcp_client(u8 *s, va_list *va)
#define EVENT_DHCP_CLIENT_WAKEUP
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
static void send_dhcp_pkt(dhcp_client_main_t *dcm, dhcp_client_t *c, dhcp_packet_type_t type, int is_broadcast)
int dhcp_client_for_us(u32 bi, vlib_buffer_t *b, ip4_header_t *ip, udp_header_t *udp, dhcp_header_t *dhcp)
format_function_t format_vnet_sw_if_index_name
unformat_function_t unformat_vnet_sw_interface
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...
description fragment has unexpected format
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.
@ FIB_ROUTE_PATH_FLAG_NONE
#define VLIB_INIT_FUNCTION(x)
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
static vlib_cli_command_t show_dhcp_client_command
(constructor) VLIB_CLI_COMMAND (show_dhcp_client_command)
vlib_log_class_t dhcp_logger
void dhcp_client_walk(dhcp_client_walk_cb_t cb, void *ctx)
Walk (visit each) DHCP client configuration.
#define vec_foreach(var, vec)
Vector iterator.
void vl_api_rpc_call_main_thread(void *fp, u8 *data, u32 data_length)
static uword pool_elts(void *v)
Number of active elements in a pool.
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_walk_cb_t)(const dhcp_client_t *client, void *data)
callback function for clients walking the DHCP client configurations
#define hash_unset(h, key)
void vlib_cli_output(struct vlib_main_t *vm, char *fmt,...)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 dhcp_client_sm(f64 now, f64 timeout, uword pool_index)
static vlib_main_t * vlib_get_main(void)
static char * dhcp_client_process_stat_strings[]
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
vnet_interface_output_runtime_t * rt
static u16 ip4_header_checksum(ip4_header_t *i)
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
int dhcp_client_add_del(dhcp_client_add_del_args_t *a)
u32 ip4_lookup_node_index
#define clib_warning(format, args...)
static f64 vlib_time_now(vlib_main_t *vm)
static vnet_sw_interface_t * vnet_get_sup_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
static vlib_node_registration_t dhcp_client_process_node
(constructor) VLIB_REGISTER_NODE (dhcp_client_process_node)
static u64 clib_cpu_time_now(void)
vl_api_interface_index_t sw_if_index
dhcp_client_main_t dhcp_client_main
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 uword dhcp_client_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Aggregate type for a prefix.
static void dhcp_client_proc_callback(uword *client_index)
vl_api_fib_path_type_t type
#define foreach_dhcp_sent_packet_stat
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
VLIB buffer representation.
static clib_error_t * dhcp_client_init(vlib_main_t *vm)
#define VLIB_REGISTER_NODE(x,...)