|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
45 #define foreach_ip4_source_and_port_range_check_error \
46 _(CHECK_FAIL, "ip4 source and port range check bad packets") \
47 _(CHECK_OK, "ip4 source and port range check good packets")
51 #define _(sym,str) IP4_SOURCE_AND_PORT_RANGE_CHECK_ERROR_##sym,
58 #define _(sym,string) string,
82 s =
format (s,
"PASS (bypass case)");
84 s =
format (s,
"fib %d src ip %U %s dst port %d: %s",
87 (t->
pass == 1) ?
"PASS" :
"FAIL");
105 if (NULL == ppr_dpo ||
dst_port == 0)
132 u32 good_packets = 0;
399 u32 bi0, next0, lb_index0, pass0, save_next0, fib_index0;
415 fib_index0 =
vec_elt (
im->fib_index_by_sw_if_index, sw_if_index0);
433 if (ip0->
protocol == IP_PROTOCOL_UDP)
437 if (ip0->
protocol == IP_PROTOCOL_TCP)
444 if (ip0->
protocol == IP_PROTOCOL_UDP)
448 if (ip0->
protocol == IP_PROTOCOL_TCP)
454 if (fib_index0 != ~0)
478 pass0 |= (ip0->
protocol != IP_PROTOCOL_UDP)
479 && (ip0->
protocol != IP_PROTOCOL_TCP);
488 (ppr_dpo0, clib_net_to_host_u16 (udp0->
dst_port), next0);
489 good_packets -= (save_next0 != next0);
491 [IP4_SOURCE_AND_PORT_RANGE_CHECK_ERROR_CHECK_FAIL];
495 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
499 t->
pass = next0 == save_next0;
503 t->
port = (pass0 == 0) ?
504 clib_net_to_host_u16 (udp0->
dst_port) : 0;
512 to_next, n_left_to_next,
521 IP4_SOURCE_AND_PORT_RANGE_CHECK_ERROR_CHECK_OK,
525 IP4_SOURCE_AND_PORT_RANGE_CHECK_ERROR_CHECK_OK,
527 return frame->n_vectors;
556 .name =
"ip4-source-and-port-range-check-rx",
557 .vector_size =
sizeof (
u32),
575 .name =
"ip4-source-and-port-range-check-tx",
576 .vector_size =
sizeof (
u32),
610 "ip4-source-and-port-range-check-rx",
620 "ip4-source-and-port-range-check-tx",
658 (input,
"tcp-out-vrf %d",
663 (input,
"udp-out-vrf %d",
668 (input,
"tcp-in-vrf %d",
673 (input,
"udp-in-vrf %d",
687 "TCP or UDP VRF ID required but not specified");
694 "TCP, UDP VRF ID should not be 0 (default). Should be distinct VRF for this purpose. ");
717 "set source and port-range on interface returned an unexpected value: %d",
788 .path =
"set interface ip source-and-port-range-check",
790 .short_help =
"set interface ip source-and-port-range-check <interface> [tcp-out-vrf <table-id>] [udp-out-vrf <table-id>] [tcp-in-vrf <table-id>] [udp-in-vrf <table-id>] [del]",
810 for (j = 0; j < 8; j++)
847 "ip4-source-and-port-range-check-rx",
944 return VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY;
1015 return VNET_API_ERROR_INCORRECT_ADJACENCY_TYPE;
1041 return VNET_API_ERROR_INCORRECT_ADJACENCY_TYPE;
1049 for (k = 0; k < 8; k++)
1068 for (j = 0; j < 8; j++)
1097 u16 * high_ports,
int is_add)
1103 ASSERT (~0 != fib_index);
1115 u16 * high_ports,
int is_add)
1125 low_ports, high_ports);
1130 low_ports, high_ports);
1142 u16 *high_ports = 0;
1146 ip6_address_t ip6_addr;
1150 int is_add = 1, ip_ver = ~0;
1168 if (
tmp == 0 ||
tmp > 65535)
1171 this_hi = this_low + 1;
1175 else if (
unformat (input,
"range %d - %d", &
tmp, &tmp2))
1180 if (
tmp == 0 ||
tmp > 65535)
1182 if (tmp2 == 0 || tmp2 > 65535)
1201 " Both VRF ID and range/port must be set for a protocol.");
1209 (&ip4_addr,
length,
vrf_id, low_ports, high_ports, is_add);
1218 case VNET_API_ERROR_INCORRECT_ADJACENCY_TYPE:
1220 (0,
" Incorrect adjacency for add/del operation");
1222 case VNET_API_ERROR_EXCEEDED_NUMBER_OF_PORTS_CAPACITY:
1225 case VNET_API_ERROR_EXCEEDED_NUMBER_OF_RANGES_CAPACITY:
1227 (0,
" Too many ranges requested for add operation");
1255 .path =
"set ip source-and-port-range-check",
1258 "set ip source-and-port-range-check vrf <table-id> <ip-addr>/<mask> {port nn | range <nn> - <nn>} [del]",
1298 if (~0 == fib_index)
1342 for (j = 0; j < 8; j++)
1345 s =
format (s,
"%d - %d ",
1381 .path =
"show ip source-and-port-range-check",
1384 "show ip source-and-port-range-check vrf <table-id> <ip-addr> [port <n>]",
vlib_node_registration_t ip4_source_port_and_range_check_tx
(constructor) VLIB_REGISTER_NODE (ip4_source_port_and_range_check_tx)
vnet_interface_main_t * im
@ IP4_SOURCE_AND_PORT_RANGE_CHECK_N_NEXT
dpo_type_t dpo_register_new_type(const dpo_vft_t *vft, const char *const *const *nodes)
Create and register a new DPO type.
index_t dpoi_index
the index of objects of that type
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
@ IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_IN
fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
Add a 'special' entry to the FIB that links to the DPO passed A special entry is an entry that the FI...
static char * ip4_source_and_port_range_check_error_strings[]
vl_api_ip_port_and_mask_t dst_port
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
int ip6_source_and_port_range_check_add_del(ip6_address_t *address, u32 length, u32 vrf_id, u16 *low_ports, u16 *high_ports, int is_add)
protocol_port_range_t blocks[N_BLOCKS_PER_DPO]
the fixed size array of ranges
static void ppr_dpo_unlock(dpo_id_t *dpo)
clib_error_t * ip4_source_and_port_range_check_init(vlib_main_t *vm)
nat44_ei_hairpin_src_next_t next_index
ip4_main_t ip4_main
Global ip4 main structure.
source_range_check_main_t source_range_check_main
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
dpo_type_t dpoi_type
the type
@ IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_OUT
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static protocol_port_range_dpo_t * ppr_dpo_pool
The pool of range chack DPOs.
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
vlib_main_t vlib_node_runtime_t * node
#define clib_error_return(e, args...)
#define FIB_NODE_INDEX_INVALID
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
static vlib_cli_command_t show_source_and_port_range_check
(constructor) VLIB_CLI_COMMAND (show_source_and_port_range_check)
fib_node_index_t fib_table_lookup(u32 fib_index, const fib_prefix_t *prefix)
Perfom a longest prefix match in the non-forwarding table.
static_always_inline void * vnet_feature_next_with_data(u32 *next0, vlib_buffer_t *b0, u32 n_data_bytes)
@ IP4_SOURCE_AND_PORT_RANGE_CHECK_N_ERROR
static dpo_type_t ppr_dpo_type
Dynamically registered DPO type.
const static dpo_vft_t ppr_vft
u16 n_used_blocks
The number of blocks from the 'block' array below that have ranges configured.
#define vec_elt(v, i)
Get vector value at index i.
const static char *const *const ppr_nodes[DPO_PROTO_NUM]
void fib_table_entry_special_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Remove a 'special' entry from the FIB.
vlib_error_t * errors
Vector of errors for this node.
static clib_error_t * set_ip_source_and_port_range_check_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
static uword ip4_address_is_multicast(const ip4_address_t *a)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
int set_ip_source_and_port_range_check(vlib_main_t *vm, u32 *fib_index, u32 sw_if_index, u32 is_add)
vnet_main_t * vnet_get_main(void)
const int fib_entry_get_dpo_for_source(fib_node_index_t fib_entry_index, fib_source_t source, dpo_id_t *dpo)
#define VLIB_NODE_FLAG_TRACE
void fib_entry_special_update(fib_node_index_t fib_entry_index, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
#define N_PORT_RANGES_PER_DPO
The number of supported ranges per-data path object.
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, fib_source_t src)
Get the index of the FIB for a Table-ID.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
@ IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
static clib_error_t * show_source_and_port_range_check_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u32 fib_node_index_t
A typedef of a node index.
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
enum dpo_type_t_ dpo_type_t
Common types of data-path objects New types can be dynamically added using dpo_register_new_type()
static const dpo_id_t * load_balance_get_bucket_i(const load_balance_t *lb, u32 bucket)
static int remove_port_range_adjacency(u32 fib_index, ip4_address_t *address, u32 length, u16 *low_ports, u16 *high_ports)
@ FIB_SOURCE_CLASSIFY
Classify.
static u8 * format_ip4_source_and_port_range_check_trace(u8 *s, va_list *va)
manual_print typedef address
#define VLIB_CLI_COMMAND(x,...)
dpo_lock_fn_t dv_lock
A reference counting lock function.
#define CLIB_CACHE_LINE_BYTES
struct _vlib_node_registration vlib_node_registration_t
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
@ IP4_SOURCE_AND_PORT_RANGE_CHECK_NEXT_DROP
u32 fib_index[IP_SOURCE_AND_PORT_RANGE_CHECK_N_PROTOCOLS]
fib_node_index_t fib_table_lookup_exact_match(u32 fib_index, const fib_prefix_t *prefix)
Perfom an exact match in the non-forwarding table.
The object that is in the data-path to perform the check.
#define vec_free(V)
Free vector's memory (no header).
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
static uword ip4_source_and_port_range_check_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_tx)
unformat_function_t unformat_vnet_sw_interface
description fragment has unexpected format
vlib_put_next_frame(vm, node, next_index, 0)
#define VLIB_INIT_FUNCTION(x)
static load_balance_t * load_balance_get(index_t lbi)
fib_protocol_t fp_proto
protocol type
@ FIB_SOURCE_SPECIAL
Special sources.
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 foreach_ip4_source_and_port_range_check_error
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static u8 * format_ppr_dpo(u8 *s, va_list *args)
A virtual function table regisitered for a DPO type.
vlib_node_registration_t ip4_source_port_and_range_check_rx
(constructor) VLIB_REGISTER_NODE (ip4_source_port_and_range_check_rx)
const static char *const ppr_ip4_nodes[]
protocol_port_range_dpo_t * protocol_port_range_dpo_alloc(void)
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
ip4_source_and_port_range_check_next_t
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
static uword ip4_source_and_port_range_check_rx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
u16 n_free_ranges
The total number of free ranges from all blocks.
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
static u32 check_adj_port_range_x1(const protocol_port_range_dpo_t *ppr_dpo, u16 dst_port, u32 next)
@ IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_UDP_OUT
static index_t ip4_fib_forwarding_lookup(u32 fib_index, const ip4_address_t *addr)
static void ppr_dpo_lock(dpo_id_t *dpo)
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
static vlib_cli_command_t set_interface_ip_source_and_port_range_check_command
(constructor) VLIB_CLI_COMMAND (set_interface_ip_source_and_port_range_check_command)
static uword ip4_source_and_port_range_check_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
ip4_source_and_port_range_check_error_t
static clib_error_t * ip_source_and_port_range_check_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
int ip4_source_and_port_range_check_add_del(ip4_address_t *address, u32 length, u32 vrf_id, u16 *low_ports, u16 *high_ports, int is_add)
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
vl_api_interface_index_t sw_if_index
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
static int add_port_range_adjacency(u32 fib_index, ip4_address_t *address, u32 length, u16 *low_ports, u16 *high_ports)
static vlib_cli_command_t ip_source_and_port_range_check_command
(constructor) VLIB_CLI_COMMAND (ip_source_and_port_range_check_command)
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Aggregate type for a prefix.
static void * ip4_next_header(ip4_header_t *i)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
@ IP_SOURCE_AND_PORT_RANGE_CHECK_PROTOCOL_TCP_IN
VLIB buffer representation.
#define VLIB_REGISTER_NODE(x,...)
static protocol_port_range_dpo_t * protocol_port_range_dpo_get(index_t index)