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 49 clib_bihash_init_8_8 (&mm->
lookup_table,
"mactime lookup table",
70 static u8 url_init_done;
77 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
82 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
85 sw_if_index, enable_disable, 0, 0);
87 sw_if_index, enable_disable, 0, 0);
88 if (url_init_done == 0)
104 int enable_disable = 1;
115 else if (
unformat (input,
"sw_if_index %d", &sw_if_index))
121 if (sw_if_index == ~0)
131 case VNET_API_ERROR_INVALID_SW_IF_INDEX:
133 (0,
"Invalid interface, only works on physical ports");
145 .path =
"mactime enable-disable",
147 "mactime enable-disable <interface-name> [disable]",
159 vl_api_mactime_enable_disable_reply_t *rmp;
191 rv = VNET_API_ERROR_NO_CHANGE;
198 message_size = sizeof(*ep) + vec_len(dev->device_name) +
199 vec_len(dev->ranges) * sizeof(ep->ranges[0]);
201 ep = vl_msg_api_alloc (message_size);
202 memset (ep, 0, message_size);
203 ep->_vl_msg_id = clib_host_to_net_u16 (VL_API_MACTIME_DETAILS
205 ep->context = mp->context;
207 ep->pool_index = clib_host_to_net_u32 (dev - mm->devices);
209 clib_memcpy_fast (ep->mac_address, dev->mac_address,
210 sizeof (ep->mac_address));
211 ep->data_quota = clib_host_to_net_u64 (dev->data_quota);
212 ep->data_used_in_range = clib_host_to_net_u64 (dev->data_used_in_range);
213 ep->flags = clib_host_to_net_u32 (dev->flags);
214 nranges = vec_len (dev->ranges);
215 ep->nranges = clib_host_to_net_u32 (nranges);
217 for (i = 0; i < vec_len (dev->ranges); i++)
219 ep->ranges[i].start = dev->ranges[i].start;
220 ep->ranges[i].end = dev->ranges[i].end;
238 rmp->table_epoch = clib_host_to_net_u32 (mm->device_table_epoch);
258 mp->_vl_msg_id = ntohs (VL_API_MACTIME_ADD_DEL_RANGE + mm->
msg_id_base);
276 vl_api_mactime_add_del_range_reply_t *rmp;
294 data_quota = clib_net_to_host_u64 (mp->
data_quota);
300 if (clib_bihash_search_8_8 (lut, &kv, &kv) < 0)
320 for (i = 0; i < clib_net_to_host_u32 (mp->
count); i++)
353 clib_bihash_add_del_8_8 (lut, &kv, 1 );
359 for (i = 0; i < clib_net_to_host_u32 (mp->
count); i++)
395 rv = VNET_API_ERROR_NO_SUCH_ENTRY;
403 clib_bihash_add_del_8_8 (lut, &kv, 0 );
412 #include <mactime/mactime.api.c> 444 if (
unformat (input,
"lookup-table-buckets %u",
447 else if (
unformat (input,
"lookup-table-memory %U",
466 .arc_name =
"device-input",
467 .node_name =
"mactime",
475 .arc_name =
"interface-output",
476 .node_name =
"mactime-tx",
484 .version = VPP_BUILD_VER,
485 .description =
"Time-based MAC Source Address Filter",
493 int width = va_arg (*va,
int);
499 fmt =
format (0,
"%%%d.3f%%s%c", width, 0);
501 fmt =
format (0,
"%%.3f%%s%c", 0);
503 if (nbytes > (1024ULL * 1024ULL * 1024ULL))
505 nbytes_f64 = ((
f64) nbytes) / (1024.0 * 1024.0 * 1024.0);
508 else if (nbytes > (1024ULL * 1024ULL))
510 nbytes_f64 = ((
f64) nbytes) / (1024.0 * 1024.0);
513 else if (nbytes > 1024ULL)
515 nbytes_f64 = ((
f64) nbytes) / (1024.0);
520 nbytes_f64 = (
f64) nbytes;
524 s =
format (s, (
char *) fmt, nbytes_f64, suffix);
547 u32 *pool_indices = 0;
549 int current_status = 99;
564 if (
unformat (input,
"verbose %d", &verbose))
576 vec_add1 (pool_indices, dp - mm->devices);
581 "Device Name",
"Addresses",
"Status",
582 "AllowPkt",
"AllowByte",
"DropPkt");
584 for (i = 0; i <
vec_len (pool_indices); i++)
601 if (now >= start0 && now <= end0)
635 switch (current_status)
638 status_string =
"static drop";
641 status_string =
"static allow";
644 status_string =
"dynamic drop";
647 status_string =
"dynamic allow";
650 status_string =
"d-quota inact";
653 status_string =
"d-quota activ";
656 status_string =
"code bug!";
692 .path =
"show mactime",
693 .short_help =
"show mactime [verbose]",
716 .path =
"clear mactime",
717 .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.
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)
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 ...
#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)
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 VLIB_CLI_COMMAND(x,...)
mactime_device_t * devices
bool enable_disable
enable=1, disable=0
#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
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)