ACL plugin 1.2

L3 path support, L2+L3 unified processing node, skip IPv6 EH support.

Change-Id: Iac37a466ba1c035e5c2997b03c0743bfec5c9a08
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
This commit is contained in:
Andrew Yourtchenko
2017-03-21 10:31:55 +01:00
committed by Ole Trøan
parent 4868ff65ed
commit d2a59bed1e
7 changed files with 2809 additions and 19 deletions

View File

@ -18,6 +18,7 @@ acl_plugin_la_SOURCES = \
acl/acl.c \
acl/node_in.c \
acl/node_out.c \
acl/fa_node.c \
acl/l2sess.c \
acl/l2sess_node.c \
acl/l2sess.h \

File diff suppressed because it is too large Load Diff

View File

@ -22,10 +22,13 @@
#include <vppinfra/hash.h>
#include <vppinfra/error.h>
#include <vppinfra/bitmap.h>
#include <vppinfra/elog.h>
#include "bihash_40_8.h"
#include "fa_node.h"
#define ACL_PLUGIN_VERSION_MAJOR 1
#define ACL_PLUGIN_VERSION_MINOR 1
#define ACL_PLUGIN_VERSION_MINOR 2
extern vlib_node_registration_t acl_in_node;
extern vlib_node_registration_t acl_out_node;
@ -33,6 +36,14 @@ extern vlib_node_registration_t acl_out_node;
void input_acl_packet_match(u32 sw_if_index, vlib_buffer_t * b0, u32 *nextp, u32 *acl_match_p, u32 *rule_match_p, u32 *trace_bitmap);
void output_acl_packet_match(u32 sw_if_index, vlib_buffer_t * b0, u32 *nextp, u32 *acl_match_p, u32 *rule_match_p, u32 *trace_bitmap);
enum acl_timeout_e {
ACL_TIMEOUT_UDP_IDLE = 0,
ACL_TIMEOUT_TCP_IDLE,
ACL_TIMEOUT_TCP_TRANSIENT,
ACL_N_TIMEOUTS
};
enum address_e { IP4, IP6 };
typedef struct
{
@ -118,8 +129,8 @@ typedef struct {
u32 *macip_acl_by_sw_if_index;
/* next indices for our nodes in the l2-classify tables */
u32 l2_input_classify_next_acl;
u32 l2_output_classify_next_acl;
u32 l2_input_classify_next_acl_old;
u32 l2_output_classify_next_acl_old;
/* next node indices for feature bitmap */
u32 acl_in_node_feat_next_node_index[32];
@ -133,12 +144,117 @@ typedef struct {
u32 acl_out_ip6_match_next[256];
u32 n_match_actions;
/* bitmaps when set the processing is enabled on the interface */
uword *fa_in_acl_on_sw_if_index;
uword *fa_out_acl_on_sw_if_index;
/* bitmap, when set the hash is initialized */
uword *fa_sessions_on_sw_if_index;
clib_bihash_40_8_t *fa_sessions_by_sw_if_index;
/* pool for FA session data. See fa_node.h */
fa_session_t *fa_sessions_pool;
/* The process node which is responsible to deleting the sessions */
u32 fa_cleaner_node_index;
/* FA session timeouts, in seconds */
u32 session_timeout_sec[ACL_N_TIMEOUTS];
/* session add/delete counters */
u64 *fa_session_adds_by_sw_if_index;
u64 *fa_session_dels_by_sw_if_index;
/* L2 datapath glue */
/* active next indices within L2 classifiers - switch old/new path */
u32 l2_input_classify_next_acl_ip4;
u32 l2_input_classify_next_acl_ip6;
u32 l2_output_classify_next_acl_ip4;
u32 l2_output_classify_next_acl_ip6;
/* saved next indices within L2 classifiers for ip4/ip6 fa L2 nodes */
u32 fa_l2_input_classify_next_acl_ip4;
u32 fa_l2_input_classify_next_acl_ip6;
u32 fa_l2_output_classify_next_acl_ip4;
u32 fa_l2_output_classify_next_acl_ip6;
/* next node indices for L2 dispatch */
u32 fa_acl_in_ip4_l2_node_feat_next_node_index[32];
u32 fa_acl_in_ip6_l2_node_feat_next_node_index[32];
u32 fa_acl_out_ip4_l2_node_feat_next_node_index[32];
u32 fa_acl_out_ip6_l2_node_feat_next_node_index[32];
/* EH values that we can skip over */
uword *fa_ipv6_known_eh_bitmap;
/* conn table per-interface conn table parameters */
u32 fa_conn_table_hash_num_buckets;
uword fa_conn_table_hash_memory_size;
u64 fa_conn_table_max_entries;
/*
* If the cleaner has to delete more than this number
* of connections, it halves the sleep time.
*/
#define ACL_FA_DEFAULT_MAX_DELETED_SESSIONS_PER_INTERVAL 100
u64 fa_max_deleted_sessions_per_interval;
/*
* If the cleaner deletes less than these connections,
* it increases the wait time by the "increment"
*/
#define ACL_FA_DEFAULT_MIN_DELETED_SESSIONS_PER_INTERVAL 1
u64 fa_min_deleted_sessions_per_interval;
#define ACL_FA_DEFAULT_CLEANER_WAIT_TIME_INCREMENT 0.1
f64 fa_cleaner_wait_time_increment;
u64 fa_current_cleaner_timer_wait_interval;
u32 fa_conn_list_head[ACL_N_TIMEOUTS];
u32 fa_conn_list_tail[ACL_N_TIMEOUTS];
/* convenience */
vlib_main_t * vlib_main;
vnet_main_t * vnet_main;
} acl_main_t;
#define foreach_acl_eh \
_(HOPBYHOP , 0 , "IPv6ExtHdrHopByHop") \
_(ROUTING , 43 , "IPv6ExtHdrRouting") \
_(DESTOPT , 60 , "IPv6ExtHdrDestOpt") \
_(MOBILITY , 135, "Mobility Header") \
_(HIP , 139, "Experimental use Host Identity Protocol") \
_(SHIM6 , 140, "Shim6 Protocol") \
_(EXP1 , 253, "Use for experimentation and testing") \
_(EXP2 , 254, "Use for experimentation and testing")
/*
"No Next Header" is not a header.
Also, Fragment header needs special processing.
_(NONEXT , 59 , "NoNextHdr") \
_(FRAGMENT , 44 , "IPv6ExtHdrFragment") \
ESP is hiding its internal format, so no point in trying to go past it.
_(ESP , 50 , "EncapsulatingSecurityPayload") \
AH has a special treatment of its length, it is in 32-bit words, not 64-bit words like the rest.
_(AUTH , 51 , "Authentication Header") \
*/
typedef enum {
#define _(N, v, s) ACL_EH_##N = v,
foreach_acl_eh
#undef _
} acl_eh_t;
extern acl_main_t acl_main;

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 2015 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#undef BIHASH_TYPE
#define BIHASH_TYPE _40_8
#define BIHASH_KVP_PER_PAGE 4
#ifndef __included_bihash_40_8_h__
#define __included_bihash_40_8_h__
#include <vppinfra/heap.h>
#include <vppinfra/format.h>
#include <vppinfra/pool.h>
#include <vppinfra/xxhash.h>
typedef struct
{
u64 key[5];
u64 value;
} clib_bihash_kv_40_8_t;
static inline int
clib_bihash_is_free_40_8 (const clib_bihash_kv_40_8_t * v)
{
/* Free values are memset to 0xff, check a bit... */
if (v->key[0] == ~0ULL && v->value == ~0ULL)
return 1;
return 0;
}
static inline u64
clib_bihash_hash_40_8 (const clib_bihash_kv_40_8_t * v)
{
#if __SSE4_2__
u32 value = 0;
value = _mm_crc32_u64 (value, v->key[0]);
value = _mm_crc32_u64 (value, v->key[1]);
value = _mm_crc32_u64 (value, v->key[2]);
value = _mm_crc32_u64 (value, v->key[3]);
value = _mm_crc32_u64 (value, v->key[4]);
return value;
#else
u64 tmp = v->key[0] ^ v->key[1] ^ v->key[2] ^ v->key[3] ^ v->key[4];
return clib_xxhash (tmp);
#endif
}
static inline u8 *
format_bihash_kvp_40_8 (u8 * s, va_list * args)
{
clib_bihash_kv_40_8_t *v = va_arg (*args, clib_bihash_kv_40_8_t *);
s = format (s, "key %llu %llu %llu %llu %llu value %llu",
v->key[0], v->key[1], v->key[2], v->key[3], v->key[4],
v->value);
return s;
}
static inline int
clib_bihash_key_compare_40_8 (const u64 * a, const u64 * b)
{
return ((a[0] ^ b[0]) | (a[1] ^ b[1]) | (a[2] ^ b[2]) | (a[3] ^ b[3]) |
(a[4] ^ b[4])) == 0;
}
#undef __included_bihash_template_h__
#include <vppinfra/bihash_template.h>
#endif /* __included_bihash_40_8_h__ */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

1444
src/plugins/acl/fa_node.c Normal file

File diff suppressed because it is too large Load Diff

99
src/plugins/acl/fa_node.h Normal file
View File

@ -0,0 +1,99 @@
#ifndef _FA_NODE_H_
#define _FA_NODE_H_
#include <stddef.h>
#include "bihash_40_8.h"
#define TCP_FLAG_FIN 0x01
#define TCP_FLAG_SYN 0x02
#define TCP_FLAG_RST 0x04
#define TCP_FLAG_PUSH 0x08
#define TCP_FLAG_ACK 0x10
#define TCP_FLAG_URG 0x20
#define TCP_FLAG_ECE 0x40
#define TCP_FLAG_CWR 0x80
#define TCP_FLAGS_RSTFINACKSYN (TCP_FLAG_RST + TCP_FLAG_FIN + TCP_FLAG_SYN + TCP_FLAG_ACK)
#define TCP_FLAGS_ACKSYN (TCP_FLAG_SYN + TCP_FLAG_ACK)
#define ACL_FA_CONN_TABLE_DEFAULT_HASH_NUM_BUCKETS (64 * 1024)
#define ACL_FA_CONN_TABLE_DEFAULT_HASH_MEMORY_SIZE (1<<30)
#define ACL_FA_CONN_TABLE_DEFAULT_MAX_ENTRIES 1000000
typedef union {
u64 as_u64;
struct {
u8 tcp_flags_valid;
u8 tcp_flags;
u8 is_input;
u8 l4_valid;
};
} fa_packet_info_t;
typedef union {
u64 as_u64;
struct {
u16 port[2];
u16 proto;
u16 rsvd;
};
} fa_session_l4_key_t;
typedef union {
struct {
ip46_address_t addr[2];
fa_session_l4_key_t l4;
/* This field should align with u64 value in bihash_40_8 keyvalue struct */
fa_packet_info_t pkt;
};
clib_bihash_kv_40_8_t kv;
} fa_5tuple_t;
typedef struct {
fa_5tuple_t info; /* (5+1)*8 = 48 bytes */
u64 last_active_time; /* +8 bytes = 56 */
u32 sw_if_index; /* +4 bytes = 60 */
union {
u8 as_u8[2];
u16 as_u16;
} tcp_flags_seen; ; /* +2 bytes = 62 */
u8 link_list_id; /* +1 bytes = 63 */
u8 reserved1; /* +1 bytes = 64 */
u32 link_prev_idx;
u32 link_next_idx;
u64 reserved2[7];
} fa_session_t;
/*
* A few compile-time constraints on the size and the layout of the union, to ensure
* it makes sense both for bihash and for us.
*/
#define CT_ASSERT_EQUAL(name, x,y) typedef int assert_ ## name ## _compile_time_assertion_failed[((x) == (y))-1]
CT_ASSERT_EQUAL(fa_l3_key_size_is_40, offsetof(fa_5tuple_t, pkt), offsetof(clib_bihash_kv_40_8_t, value));
CT_ASSERT_EQUAL(fa_l4_key_t_is_8, sizeof(fa_session_l4_key_t), sizeof(u64));
CT_ASSERT_EQUAL(fa_packet_info_t_is_8, sizeof(fa_packet_info_t), sizeof(u64));
CT_ASSERT_EQUAL(fa_l3_kv_size_is_48, sizeof(fa_5tuple_t), sizeof(clib_bihash_kv_40_8_t));
/* Let's try to fit within the cacheline */
CT_ASSERT_EQUAL(fa_session_t_size_is_64, sizeof(fa_session_t), 128);
#undef CT_ASSERT_EQUAL
typedef enum {
ACL_FA_ERROR_DROP,
ACL_FA_N_NEXT,
} acl_fa_next_t;
enum
{
ACL_FA_CLEANER_RESCHEDULE = 1,
ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX,
} acl_fa_cleaner_process_event_e;
void acl_fa_enable_disable(u32 sw_if_index, int is_input, int enable_disable);
#endif

File diff suppressed because it is too large Load Diff