l2-rw: Packet rewrite feature for L2 bridges
This patch defines a new l2input feature: l2-rw It makes use of vnet_classify in order to match packets and applies mask/value changes depending on the matched classify entry. Change-Id: Ia98c128931e59195bf3ecb66721e155ff9049a2e Signed-off-by: Pierre Pfister <ppfister@cisco.com>
This commit is contained in:

committed by
Gerrit Code Review

parent
2e89a894a4
commit
d6f5b96e6f
@ -114,6 +114,7 @@ libvnet_la_SOURCES += \
|
||||
vnet/l2/l2_output_acl.c \
|
||||
vnet/l2/l2_output.c \
|
||||
vnet/l2/l2_patch.c \
|
||||
vnet/l2/l2_rw.c \
|
||||
vnet/l2/l2_vtr.c \
|
||||
vnet/l2/l2_xcrw.c
|
||||
|
||||
@ -129,6 +130,7 @@ nobase_include_HEADERS += \
|
||||
vnet/l2/l2_bvi.h \
|
||||
vnet/l2/l2_flood.h \
|
||||
vnet/l2/l2_fib.h \
|
||||
vnet/l2/l2_rw.h \
|
||||
vnet/l2/l2_xcrw.h \
|
||||
vnet/l2/l2_classify.h
|
||||
|
||||
|
@ -507,7 +507,16 @@ u32 l2input_intf_bitmap_enable (u32 sw_if_index,
|
||||
return config->feature_bitmap;
|
||||
}
|
||||
|
||||
|
||||
u32 l2input_set_bridge_features(u32 bd_index,
|
||||
u32 feat_mask, u32 feat_value)
|
||||
{
|
||||
l2_bridge_domain_t * bd_config;
|
||||
vec_validate (l2input_main.bd_configs, bd_index);
|
||||
bd_config = vec_elt_at_index(l2input_main.bd_configs, bd_index);
|
||||
bd_validate (bd_config);
|
||||
bd_config->feature_bitmap = (bd_config->feature_bitmap & ~feat_mask) | feat_value;
|
||||
return bd_config->feature_bitmap;
|
||||
}
|
||||
|
||||
// Set the subinterface to run in l2 or l3 mode.
|
||||
// for L3 mode, just the sw_if_index is specified
|
||||
|
@ -93,6 +93,7 @@ l2input_bd_config_from_index (l2input_main_t * l2im, u32 bd_index)
|
||||
_(ARP_TERM, "arp-term-l2bd") \
|
||||
_(UU_FLOOD, "l2-flood") \
|
||||
_(FWD, "l2-fwd") \
|
||||
_(RW, "l2-rw") \
|
||||
_(LEARN, "l2-learn") \
|
||||
_(VTR, "l2-input-vtr") \
|
||||
_(VPATH, "vpath-input-l2") \
|
||||
@ -196,6 +197,11 @@ u32 l2input_intf_bitmap_enable (u32 sw_if_index,
|
||||
u32 feature_bitmap,
|
||||
u32 enable);
|
||||
|
||||
//Sets modifies flags from a bridge domain
|
||||
u32 l2input_set_bridge_features(u32 bd_index,
|
||||
u32 feat_mask,
|
||||
u32 feat_value);
|
||||
|
||||
|
||||
#define MODE_L3 0
|
||||
#define MODE_L2_BRIDGE 1
|
||||
|
588
vnet/vnet/l2/l2_rw.c
Normal file
588
vnet/vnet/l2/l2_rw.c
Normal file
File diff suppressed because it is too large
Load Diff
84
vnet/vnet/l2/l2_rw.h
Normal file
84
vnet/vnet/l2/l2_rw.h
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* l2_rw is based on vnet classifier and provides a way
|
||||
* to modify packets matching a given table.
|
||||
*
|
||||
* Tables must be created using vnet's classify features.
|
||||
* Entries contained within these tables must have their
|
||||
* opaque index set to the rewrite entry created with l2_rw_mod_entry.
|
||||
*/
|
||||
|
||||
#ifndef L2_RW_H_
|
||||
#define L2_RW_H_
|
||||
|
||||
#include <vnet/l2/l2_input.h>
|
||||
|
||||
typedef CLIB_PACKED(struct _l2_rw_entry {
|
||||
u16 skip_n_vectors;
|
||||
u16 rewrite_n_vectors;
|
||||
u64 hit_count;
|
||||
u32x4 *mask;
|
||||
u32x4 *value;
|
||||
}) l2_rw_entry_t;
|
||||
|
||||
// l2_rw configuration for one interface
|
||||
typedef CLIB_PACKED(struct _l2_rw_config {
|
||||
u32 table_index; //Which classify table to use
|
||||
u32 miss_index; //Rewrite entry to use if table does not match
|
||||
}) l2_rw_config_t;
|
||||
|
||||
typedef struct {
|
||||
/* Next feature node indexes */
|
||||
u32 feat_next_node_index[32];
|
||||
|
||||
/* A pool of entries */
|
||||
l2_rw_entry_t *entries;
|
||||
|
||||
/* Config vector indexed by sw_if_index */
|
||||
l2_rw_config_t *configs;
|
||||
uword *configs_bitmap;
|
||||
} l2_rw_main_t;
|
||||
|
||||
extern l2_rw_main_t l2_rw_main;
|
||||
|
||||
/*
|
||||
* Specifies which classify table and miss_index should be used
|
||||
* with the given interface.
|
||||
* Use special values ~0 in order to un-set table_index
|
||||
* or miss_index.
|
||||
* l2_rw feature is automatically enabled for the interface
|
||||
* when table_index or miss_index is not ~0.
|
||||
* returns 0 on success and something else on error.
|
||||
*/
|
||||
int l2_rw_interface_set_table(u32 sw_if_index,
|
||||
u32 table_index,
|
||||
u32 miss_index);
|
||||
|
||||
/*
|
||||
* Creates, modifies or delete a rewrite entry.
|
||||
* If *index != ~0, modifies an existing entry (or simply
|
||||
* deletes it if is_del is set).
|
||||
* If *index == ~0, creates a new entry and the created
|
||||
* entry index is stored in *index (Does nothing if is_del
|
||||
* is set).
|
||||
* returns 0 on success and something else on error.
|
||||
*/
|
||||
int l2_rw_mod_entry(u32 *index,
|
||||
u8 *mask, u8 *value, u32 len,
|
||||
u32 skip, u8 is_del);
|
||||
|
||||
#endif /* L2_FW_H_ */
|
Reference in New Issue
Block a user