|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
24 #include <vpp/app/version.h>
28 #include <mactime/mactime.api_enum.h>
29 #include <mactime/mactime.api_types.h>
31 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
33 #define REPLY_MSG_ID_BASE mm->msg_id_base
50 clib_bihash_init_8_8 (&mm->
lookup_table,
"mactime lookup table",
72 static u8 url_init_done;
79 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
84 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
90 if (url_init_done == 0)
106 int enable_disable = 1;
133 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
135 (0,
"Invalid interface, only works on physical ports");
147 .path =
"mactime enable-disable",
149 "mactime enable-disable <interface-name> [disable]",
161 vl_api_mactime_enable_disable_reply_t *rmp;
193 rv = VNET_API_ERROR_NO_CHANGE;
204 memset (ep, 0, message_size);
205 ep->_vl_msg_id = clib_host_to_net_u16 (VL_API_MACTIME_DETAILS
209 ep->pool_index = clib_host_to_net_u32 (dev - mm->
devices);
212 sizeof (ep->mac_address));
213 ep->data_quota = clib_host_to_net_u64 (dev->
data_quota);
215 ep->flags = clib_host_to_net_u32 (dev->
flags);
217 ep->nranges = clib_host_to_net_u32 (nranges);
226 name_len = (name_len <
ARRAY_LEN(ep->device_name)) ?
227 name_len :
ARRAY_LEN(ep->device_name) - 1;
231 ep->device_name [
ARRAY_LEN(ep->device_name) -1] = 0;
257 shmem_hdr =
am->shmem_hdr;
278 vl_api_mactime_add_del_range_reply_t *rmp;
296 data_quota = clib_net_to_host_u64 (mp->
data_quota);
302 if (clib_bihash_search_8_8 (lut, &kv, &kv) < 0)
322 for (
i = 0;
i < clib_net_to_host_u32 (mp->
count);
i++)
355 clib_bihash_add_del_8_8 (lut, &kv, 1 );
361 for (
i = 0;
i < clib_net_to_host_u32 (mp->
count);
i++)
397 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
405 clib_bihash_add_del_8_8 (lut, &kv, 0 );
414 #include <mactime/mactime.api.c>
446 if (
unformat (input,
"lookup-table-buckets %u",
449 else if (
unformat (input,
"lookup-table-memory %U",
468 .arc_name =
"device-input",
469 .node_name =
"mactime",
476 .arc_name =
"interface-output",
477 .node_name =
"mactime-tx",
485 .version = VPP_BUILD_VER,
486 .description =
"Time-based MAC Source Address Filter",
494 int width = va_arg (*va,
int);
500 fmt =
format (0,
"%%%d.3f%%s%c", width, 0);
504 if (nbytes > (1024ULL * 1024ULL * 1024ULL))
506 nbytes_f64 = ((
f64) nbytes) / (1024.0 * 1024.0 * 1024.0);
509 else if (nbytes > (1024ULL * 1024ULL))
511 nbytes_f64 = ((
f64) nbytes) / (1024.0 * 1024.0);
514 else if (nbytes > 1024ULL)
516 nbytes_f64 = ((
f64) nbytes) / (1024.0);
521 nbytes_f64 = (
f64) nbytes;
525 s =
format (s, (
char *)
fmt, nbytes_f64, suffix);
548 u32 *pool_indices = 0;
550 int current_status = 99;
559 "Feature not initialized, suggest 'help mactime enable-disable'...");
570 if (
unformat (input,
"verbose %d", &verbose))
587 "Device Name",
"Addresses",
"Status",
588 "AllowPkt",
"AllowByte",
"DropPkt");
607 if (
now >= start0 &&
now <= end0)
641 switch (current_status)
644 status_string =
"static drop";
647 status_string =
"static allow";
650 status_string =
"dynamic drop";
653 status_string =
"dynamic allow";
656 status_string =
"d-quota inact";
659 status_string =
"d-quota activ";
662 status_string =
"code bug!";
698 .path =
"show mactime",
699 .short_help =
"show mactime [verbose]",
713 "Feature not initialized, suggest 'help mactime enable-disable'...");
724 .path =
"clear mactime",
725 .short_help =
"clear mactime counters",
A representation of an IP neighbour/peer.
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
string device_name[64]
device name
#define VALIDATE_SW_IF_INDEX(mp)
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
bool no_udp_10001
drop udp to port 10001
#define MACTIME_DEVICE_FLAG_DYNAMIC_DROP
mactime table entry details
vnet_sw_interface_type_t type
#define REPLY_MACRO2(t, body)
const ip_address_t * ip_neighbor_get_ip(const ip_neighbor_t *ipn)
u32 client_index
client index, from api_main
void mactime_send_create_entry_message(u8 *mac_address)
Create a lookup table entry for the indicated mac address.
#define MACTIME_MEMORY_SIZE
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
u32 my_table_epoch
to suppress dump if no changes
static clib_error_t * show_mactime_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
VNET_FEATURE_INIT(mactime, static)
ip_neighbor_t * ip_neighbor_get(index_t ipni)
void vlib_clear_combined_counters(vlib_combined_counter_main_t *cm)
Clear a collection of combined counters.
static void vl_api_mactime_add_del_range_t_handler(vl_api_mactime_add_del_range_t *mp)
Add or delete static / dynamic accept/drop configuration for a src mac.
static void vl_api_mactime_dump_t_handler(vl_api_mactime_dump_t *mp)
#define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA
u64 data_quota
max bytes this device
vlib_combined_counter_main_t drop_counters
#define MACTIME_DEVICE_FLAG_STATIC_DROP
Always drop packets from this device.
bool enable_disable
enable=1, disable=0
#define clib_error_return(e, args...)
#define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW
int mactime_enable_disable(mactime_main_t *mm, u32 sw_if_index, int enable_disable)
Action function shared between message handler and debug CLI.
void vlib_validate_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
validate a combined counter
#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 vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
char * name
The counter collection's name.
static clib_error_t * mactime_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
vnet_hw_if_output_node_runtime_t * r
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
void * vl_msg_api_alloc_as_if_client(int nbytes)
static vlib_cli_command_t mactime_enable_disable_command
(constructor) VLIB_CLI_COMMAND (mactime_enable_disable_command)
u8 * format_mac_address(u8 *s, va_list *args)
#define VLIB_CONFIG_FUNCTION(x, n,...)
format_function_t format_clib_timebase_time
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
static clib_error_t * clear_mactime_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define pool_foreach(VAR, POOL)
Iterate through pool.
u32 context
application context
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
api to enable or disable the time-based src mac filter on an interface
u32 lookup_table_num_buckets
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
vnet_main_t * vnet_get_main(void)
Combined counter to hold both packets and byte differences.
An API client registration, only in vpp/vlib.
static void setup_message_id_table(api_main_t *am)
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
u8 allow_quota
allow subject to quota
clib_timebase_range_t * ranges
vl_api_interface_index_t sw_if_index
the interface handle
static unsigned char * print(const cJSON *const item, cJSON_bool format, const internal_hooks *const hooks)
static clib_error_t * mactime_config(vlib_main_t *vm, unformat_input_t *input)
svm_queue_t * vl_input_queue
static void vlib_zero_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
Clear a combined counter Clears the set of per-thread counters.
static api_main_t * vlibapi_get_main(void)
void ip_neighbor_walk(ip_address_family_t af, u32 sw_if_index, ip_neighbor_walk_cb_t cb, void *ctx)
configure per src-mac time ranges
vlib_combined_counter_main_t allow_counters
static clib_error_t * mactime_init(vlib_main_t *vm)
__clib_export void clib_timebase_init(clib_timebase_t *tb, i32 timezone_offset_in_hours, clib_timebase_daylight_time_t daylight_type, clib_time_t *clib_time)
static vlib_cli_command_t show_mactime_command
(constructor) VLIB_CLI_COMMAND (show_mactime_command)
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
#define VLIB_CLI_COMMAND(x,...)
u32 count
number of time ranges to follow
counter_t packets
packet counter
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
vnet_sw_interface_t * sw_interfaces
uword lookup_table_memory_size
mactime_device_t * devices
#define BAD_SW_IF_INDEX_LABEL
vl_api_mactime_time_range_t ranges[nranges]
API main structure, used by both vpp and binary API clients.
u8 * format_bytes_with_width(u8 *s, va_list *va)
static void vlib_get_combined_counter(const vlib_combined_counter_main_t *cm, u32 index, vlib_counter_t *result)
Get the value of a combined counter, never called in the speed path Scrapes the entire set of per-thr...
vl_api_time_range_t ranges[count]
time ranges, in seconds since Sunday began
#define vec_free(V)
Free vector's memory (no header).
void mactime_url_init(vlib_main_t *vm)
unformat_function_t unformat_vnet_sw_interface
description fragment has unexpected format
format_function_t format_ip46_address
mactime_main_t mactime_main
#define VLIB_INIT_FUNCTION(x)
static f64 clib_timebase_now(clib_timebase_t *tb)
counter_t bytes
byte counter
char * stat_segment_name
Name in stat segment directory.
8 octet key, 8 octet key value pair
static walk_rc_t mactime_ip_neighbor_copy(index_t ipni, void *ctx)
vl_api_mac_address_t mac_address
src mac address
@ CLIB_TIMEBASE_DAYLIGHT_USA
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)
static vlib_cli_command_t clear_mactime_command
(constructor) VLIB_CLI_COMMAND (clear_mactime_command)
#define MACTIME_DEVICE_FLAG_STATIC_ALLOW
#define MACTIME_NUM_BUCKETS
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
#define VNET_FEATURES(...)
void vl_msg_api_send_shmem(svm_queue_t *q, u8 *elem)
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
static void vl_api_mactime_enable_disable_t_handler(vl_api_mactime_enable_disable_t *mp)
Enable / disable time-base src mac filtration on an interface.
clib_bihash_8_8_t lookup_table
@ VNET_SW_INTERFACE_TYPE_HARDWARE
__clib_export f64 clib_timebase_find_sunday_midnight(f64 start_time)
static void feature_init(mactime_main_t *mm)
vl_api_interface_index_t sw_if_index
mac_address_t ipn_mac
The learned MAC address of the neighbour.
dump mactime table reply Includes the vpp table epoch, needed to optimize API traffic
enum walk_rc_t_ walk_rc_t
Walk return code.
vnet_interface_main_t interface_main
#define MACTIME_DEVICE_FLAG_DROP_UDP_10001
void * vl_msg_api_alloc(int nbytes)
manual_print typedef u8 mac_address[6]