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;
133 if (sw_if_index == ~0)
143 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
145 (0,
"Invalid interface, only works on physical ports");
148 case VNET_API_ERROR_UNIMPLEMENTED:
150 "Device driver doesn't support redirection");
162 .path =
"mactime enable-disable",
164 "mactime enable-disable <interface-name> [disable]",
176 vl_api_mactime_enable_disable_reply_t *rmp;
203 mp->_vl_msg_id = ntohs (VL_API_MACTIME_ADD_DEL_RANGE + mm->
msg_id_base);
221 vl_api_mactime_add_del_range_reply_t *rmp;
234 if (clib_bihash_search_8_8 (lut, &kv, &kv) < 0)
254 for (i = 0; i < clib_net_to_host_u32 (mp->
count); i++)
281 clib_bihash_add_del_8_8 (lut, &kv, 1 );
286 for (i = 0; i < clib_net_to_host_u32 (mp->
count); i++)
299 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
307 clib_bihash_add_del_8_8 (lut, &kv, 0 );
322 vl_msg_api_set_handlers((VL_API_##N + mm->msg_id_base), \ 324 vl_api_##n##_t_handler, \ 326 vl_api_##n##_t_endian, \ 327 vl_api_##n##_t_print, \ 328 sizeof(vl_api_##n##_t), 1); 335 #define vl_msg_name_crc_list 337 #undef vl_msg_name_crc_list 342 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + mm->msg_id_base); 343 foreach_vl_msg_name_crc_mactime;
357 name =
format (0,
"mactime_%08x%c", api_version, 0);
385 if (
unformat (input,
"lookup-table-buckets %u",
388 else if (
unformat (input,
"lookup-table-memory %U",
407 .arc_name =
"device-input",
408 .node_name =
"mactime",
416 .arc_name =
"interface-output",
417 .node_name =
"mactime-tx",
425 .version = VPP_BUILD_VER,
426 .description =
"Time-based MAC Source Address Filter",
438 u32 *pool_indices = 0;
440 int current_status = 99;
461 if (
unformat (input,
"verbose %d", &verbose))
473 vec_add1 (pool_indices, dp - mm->devices);
478 "Device Name",
"Addresses",
"Status",
479 "AllowPkt",
"AllowByte",
"DropPkt");
481 for (i = 0; i <
vec_len (pool_indices); i++)
498 if (now >= start0 && now <= end0)
528 switch (current_status)
531 status_string =
"static drop";
534 status_string =
"static allow";
537 status_string =
"dynamic drop";
540 status_string =
"dynamic allow";
543 status_string =
"code bug!";
572 .path =
"show mactime",
573 .short_help =
"show mactime [verbose]",
596 .path =
"clear mactime",
597 .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
void vlib_validate_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
validate a combined counter
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.
#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
#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
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_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,...)
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)