24 #include <vpp/app/version.h> 40 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) 46 #define vl_api_version(n,v) static u32 api_version=(v); 50 #define REPLY_MSG_ID_BASE mm->msg_id_base 60 #define foreach_mactime_plugin_api_msg \ 61 _(MACTIME_ENABLE_DISABLE, mactime_enable_disable) \ 62 _(MACTIME_ADD_DEL_RANGE, mactime_add_del_range) 70 clib_bihash_init_8_8 (&mm->
lookup_table,
"mactime lookup table",
97 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
102 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
105 sw_if_index, enable_disable, 0, 0);
107 sw_if_index, enable_disable, 0, 0);
118 int enable_disable = 1;
129 else if (
unformat (input,
"sw_if_index %d", &sw_if_index))
135 if (sw_if_index == ~0)
145 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
147 (0,
"Invalid interface, only works on physical ports");
159 .path =
"mactime enable-disable",
161 "mactime enable-disable <interface-name> [disable]",
173 vl_api_mactime_enable_disable_reply_t *rmp;
200 mp->_vl_msg_id = ntohs (VL_API_MACTIME_ADD_DEL_RANGE + mm->
msg_id_base);
218 vl_api_mactime_add_del_range_reply_t *rmp;
228 data_quota = clib_net_to_host_u64 (mp->
data_quota);
234 if (clib_bihash_search_8_8 (lut, &kv, &kv) < 0)
254 for (i = 0; i < clib_net_to_host_u32 (mp->
count); i++)
287 clib_bihash_add_del_8_8 (lut, &kv, 1 );
293 for (i = 0; i < clib_net_to_host_u32 (mp->
count); i++)
329 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
337 clib_bihash_add_del_8_8 (lut, &kv, 0 );
352 vl_msg_api_set_handlers((VL_API_##N + mm->msg_id_base), \ 354 vl_api_##n##_t_handler, \ 356 vl_api_##n##_t_endian, \ 357 vl_api_##n##_t_print, \ 358 sizeof(vl_api_##n##_t), 1); 365 #define vl_msg_name_crc_list 367 #undef vl_msg_name_crc_list 372 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + mm->msg_id_base); 373 foreach_vl_msg_name_crc_mactime;
387 name =
format (0,
"mactime_%08x%c", api_version, 0);
415 if (
unformat (input,
"lookup-table-buckets %u",
418 else if (
unformat (input,
"lookup-table-memory %U",
437 .arc_name =
"device-input",
438 .node_name =
"mactime",
446 .arc_name =
"interface-output",
447 .node_name =
"mactime-tx",
455 .version = VPP_BUILD_VER,
456 .description =
"Time-based MAC Source Address Filter",
464 int width = va_arg (*va,
int);
470 fmt =
format (0,
"%%%d.3f%%s%c", width, 0);
472 fmt =
format (0,
"%%.3f%%s%c", 0);
474 if (nbytes > (1024ULL * 1024ULL * 1024ULL))
476 nbytes_f64 = ((
f64) nbytes) / (1024.0 * 1024.0 * 1024.0);
479 else if (nbytes > (1024ULL * 1024ULL))
481 nbytes_f64 = ((
f64) nbytes) / (1024.0 * 1024.0);
484 else if (nbytes > 1024ULL)
486 nbytes_f64 = ((
f64) nbytes) / (1024.0);
491 nbytes_f64 = (
f64) nbytes;
495 s =
format (s, (
char *) fmt, nbytes_f64, suffix);
508 u32 *pool_indices = 0;
510 int current_status = 99;
519 "Feature not initialized, suggest 'help mactime enable-disable'...");
536 if (
unformat (input,
"verbose %d", &verbose))
548 vec_add1 (pool_indices, dp - mm->devices);
553 "Device Name",
"Addresses",
"Status",
554 "AllowPkt",
"AllowByte",
"DropPkt");
556 for (i = 0; i <
vec_len (pool_indices); i++)
573 if (now >= start0 && now <= end0)
607 switch (current_status)
610 status_string =
"static drop";
613 status_string =
"static allow";
616 status_string =
"dynamic drop";
619 status_string =
"dynamic allow";
622 status_string =
"d-quota inact";
625 status_string =
"d-quota activ";
628 status_string =
"code bug!";
663 .path =
"show mactime",
664 .short_help =
"show mactime [verbose]",
678 "Feature not initialized, suggest 'help mactime enable-disable'...");
689 .path =
"clear mactime",
690 .short_help =
"clear mactime counters",
configure per src-mac time ranges
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.
vlib_combined_counter_main_t drop_counters
u64 data_quota
max bytes this device
void vlib_validate_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
validate a combined counter
#define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA
char * stat_segment_name
Name in stat segment directory.
vnet_main_t * vnet_get_main(void)
VNET_FEATURE_INIT(mactime, static)
vnet_interface_main_t interface_main
int mactime_enable_disable(mactime_main_t *mm, u32 sw_if_index, int enable_disable)
Action function shared between message handler and debug CLI.
static clib_error_t * clear_mactime_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define foreach_mactime_plugin_api_msg
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Combined counter to hold both packets and byte differences.
f64 end
end of the time range
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
unformat_function_t unformat_vnet_sw_interface
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
#define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static clib_error_t * show_mactime_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u32 count
number of time ranges to follow
clib_timebase_range_t * ranges
void vlib_clear_combined_counters(vlib_combined_counter_main_t *cm)
Clear a collection of combined counters.
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
vl_api_interface_index_t sw_if_index
#define VLIB_INIT_FUNCTION(x)
#define MACTIME_MEMORY_SIZE
static f64 clib_timebase_now(clib_timebase_t *tb)
#define clib_error_return(e, args...)
struct vl_shmem_hdr_ * shmem_hdr
Binary API shared-memory segment header pointer.
void vl_msg_api_send_shmem(svm_queue_t *q, u8 *elem)
format_function_t format_clib_timebase_time
u8 no_udp_10001
drop udp to port 10001
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
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.
ethernet_arp_ip4_entry_t * arp_cache_copy
mactime_main_t mactime_main
counter_t packets
packet counter
vlib_combined_counter_main_t allow_counters
ip4_address_t ip4_address
u32 lookup_table_num_buckets
ethernet_arp_ip4_entry_t * ip4_neighbors_pool(void)
#define pool_put(P, E)
Free an object E in pool P.
#define VLIB_CONFIG_FUNCTION(x, n,...)
static clib_error_t * mactime_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
uword lookup_table_memory_size
static clib_error_t * mactime_config(vlib_main_t *vm, unformat_input_t *input)
api to enable or disable the time-based src mac filter on an interface
API main structure, used by both vpp and binary API clients.
static clib_error_t * mactime_init(vlib_main_t *vm)
#define BAD_SW_IF_INDEX_LABEL
#define MACTIME_DEVICE_FLAG_DROP_UDP_10001
u8 mac_address[6]
src mac address
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...
#define vec_free(V)
Free vector's memory (no header).
f64 clib_timebase_find_sunday_midnight(f64 start_time)
static void setup_message_id_table(mactime_main_t *mm, api_main_t *am)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
8 octet key, 8 octet key value pair
void clib_timebase_init(clib_timebase_t *tb, i32 timezone_offset_in_hours, clib_timebase_daylight_time_t daylight_type)
svm_queue_t * vl_input_queue
#define MACTIME_DEVICE_FLAG_STATIC_DROP
Always drop packets from this device.
#define VLIB_CLI_COMMAND(x,...)
mactime_device_t * devices
static clib_error_t * mactime_plugin_api_hookup(vlib_main_t *vm)
f64 start
start of the time range
clib_bihash_8_8_t lookup_table
vl_api_time_range_t ranges[count]
time ranges, in seconds since Sunday began
static void feature_init(mactime_main_t *mm)
#define VNET_FEATURES(...)
void mactime_send_create_entry_message(u8 *mac_address)
Create a lookup table entry for the indicated mac address.
counter_t bytes
byte counter
u32 sw_if_index
the interface handle
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.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vnet_sw_interface_t * sw_interfaces
char * name
The counter collection's name.
#define MACTIME_DEVICE_FLAG_STATIC_ALLOW
u8 * format_bytes_with_width(u8 *s, va_list *va)
u8 * format_mac_address(u8 *s, va_list *args)
vnet_sw_interface_type_t type
#define MACTIME_DEVICE_FLAG_DYNAMIC_DROP
u8 enable_disable
enable=1, disable=0
void * vl_msg_api_alloc_as_if_client(int nbytes)
#define MACTIME_NUM_BUCKETS
u8 device_name[64]
device name
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
u8 allow_quota
allow subject to quota
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)
#define VALIDATE_SW_IF_INDEX(mp)
u16 vl_msg_api_get_msg_ids(const char *name, int n)