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;
87 sw_if_index, enable_disable, 0, 0);
89 sw_if_index, enable_disable, 0, 0);
90 if (url_init_done == 0)
106 int enable_disable = 1;
117 else if (
unformat (input,
"sw_if_index %d", &sw_if_index))
123 if (sw_if_index == ~0)
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;
200 message_size = sizeof(*ep) + vec_len(dev->device_name) +
201 vec_len(dev->ranges) * sizeof(ep->ranges[0]);
203 ep = vl_msg_api_alloc (message_size);
204 memset (ep, 0, message_size);
205 ep->_vl_msg_id = clib_host_to_net_u16 (VL_API_MACTIME_DETAILS
207 ep->context = mp->context;
209 ep->pool_index = clib_host_to_net_u32 (dev - mm->devices);
211 clib_memcpy_fast (ep->mac_address, dev->mac_address,
212 sizeof (ep->mac_address));
213 ep->data_quota = clib_host_to_net_u64 (dev->data_quota);
214 ep->data_used_in_range = clib_host_to_net_u64 (dev->data_used_in_range);
215 ep->flags = clib_host_to_net_u32 (dev->flags);
216 nranges = vec_len (dev->ranges);
217 ep->nranges = clib_host_to_net_u32 (nranges);
219 for (i = 0; i < vec_len (dev->ranges); i++)
221 ep->ranges[i].start = dev->ranges[i].start;
222 ep->ranges[i].end = dev->ranges[i].end;
240 rmp->table_epoch = clib_host_to_net_u32 (mm->device_table_epoch);
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",
477 .arc_name =
"interface-output",
478 .node_name =
"mactime-tx",
486 .version = VPP_BUILD_VER,
487 .description =
"Time-based MAC Source Address Filter",
495 int width = va_arg (*va,
int);
501 fmt =
format (0,
"%%%d.3f%%s%c", width, 0);
503 fmt =
format (0,
"%%.3f%%s%c", 0);
505 if (nbytes > (1024ULL * 1024ULL * 1024ULL))
507 nbytes_f64 = ((
f64) nbytes) / (1024.0 * 1024.0 * 1024.0);
510 else if (nbytes > (1024ULL * 1024ULL))
512 nbytes_f64 = ((
f64) nbytes) / (1024.0 * 1024.0);
515 else if (nbytes > 1024ULL)
517 nbytes_f64 = ((
f64) nbytes) / (1024.0);
522 nbytes_f64 = (
f64) nbytes;
526 s =
format (s, (
char *) fmt, nbytes_f64, suffix);
549 u32 *pool_indices = 0;
551 int current_status = 99;
560 "Feature not initialized, suggest 'help mactime enable-disable'...");
571 if (
unformat (input,
"verbose %d", &verbose))
583 vec_add1 (pool_indices, dp - mm->devices);
588 "Device Name",
"Addresses",
"Status",
589 "AllowPkt",
"AllowByte",
"DropPkt");
591 for (i = 0; i <
vec_len (pool_indices); i++)
608 if (now >= start0 && now <= end0)
642 switch (current_status)
645 status_string =
"static drop";
648 status_string =
"static allow";
651 status_string =
"dynamic drop";
654 status_string =
"dynamic allow";
657 status_string =
"d-quota inact";
660 status_string =
"d-quota activ";
663 status_string =
"code bug!";
699 .path =
"show mactime",
700 .short_help =
"show mactime [verbose]",
714 "Feature not initialized, suggest 'help mactime enable-disable'...");
725 .path =
"clear mactime",
726 .short_help =
"clear mactime counters",
#define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW_QUOTA
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
static walk_rc_t mactime_ip_neighbor_copy(index_t ipni, void *ctx)
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.
string device_name[64]
device name
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)
const ip46_address_t * ip_neighbor_get_ip(const ip_neighbor_t *ipn)
#define clib_memcpy_fast(a, b, c)
#define REPLY_MACRO2(t, body)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
#define MACTIME_DEVICE_FLAG_DYNAMIC_ALLOW
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Combined counter to hold both packets and byte differences.
mactime table entry details
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
static void vl_api_mactime_dump_t_handler(vl_api_mactime_dump_t *mp)
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_DROP_UDP_10001
#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
enum walk_rc_t_ walk_rc_t
Walk return code.
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)
A representation of an IP neighbour/peer.
#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 MACTIME_DEVICE_FLAG_STATIC_ALLOW
vl_api_interface_index_t sw_if_index
the interface handle
#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.
mactime_main_t mactime_main
counter_t packets
packet counter
vlib_combined_counter_main_t allow_counters
u32 client_index
client index, from api_main
u32 lookup_table_num_buckets
u32 my_table_epoch
to suppress dump if no changes
#define MACTIME_DEVICE_FLAG_DYNAMIC_DROP
#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
mac_address_t ipn_mac
The learned MAC address of the neighbour.
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)
format_function_t format_ip46_address
An API client registration, only in vpp/vlib.
#define BAD_SW_IF_INDEX_LABEL
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...
dump mactime table reply Includes the vpp table epoch, needed to optimize API traffic ...
sll srl srl sll sra u16x4 i
#define vec_free(V)
Free vector's memory (no header).
void ip_neighbor_walk(ip46_type_t type, u32 sw_if_index, ip_neighbor_walk_cb_t cb, void *ctx)
f64 clib_timebase_find_sunday_midnight(f64 start_time)
#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
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
void mactime_url_init(vlib_main_t *vm)
svm_queue_t * vl_input_queue
#define VLIB_CLI_COMMAND(x,...)
mactime_device_t * devices
bool enable_disable
enable=1, disable=0
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
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)
#define MACTIME_DEVICE_FLAG_STATIC_DROP
Always drop packets from this device.
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
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
vl_api_mac_address_t mac_address
src mac address
char * name
The counter collection's name.
u8 * format_bytes_with_width(u8 *s, va_list *va)
u8 * format_mac_address(u8 *s, va_list *args)
static api_main_t * vlibapi_get_main(void)
vnet_sw_interface_type_t type
ip_neighbor_t * ip_neighbor_get(index_t ipni)
static void setup_message_id_table(snat_main_t *sm, api_main_t *am)
void * vl_msg_api_alloc_as_if_client(int nbytes)
manual_print typedef u8 mac_address[6]
#define MACTIME_NUM_BUCKETS
bool no_udp_10001
drop udp to port 10001
u8 allow_quota
allow subject to quota
vl_api_interface_index_t sw_if_index
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)