Pierre Pfister | d6f5b96 | 2016-03-21 16:17:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * l2_rw is based on vnet classifier and provides a way |
| 18 | * to modify packets matching a given table. |
| 19 | * |
| 20 | * Tables must be created using vnet's classify features. |
| 21 | * Entries contained within these tables must have their |
| 22 | * opaque index set to the rewrite entry created with l2_rw_mod_entry. |
| 23 | */ |
| 24 | |
| 25 | #ifndef L2_RW_H_ |
| 26 | #define L2_RW_H_ |
| 27 | |
| 28 | #include <vnet/l2/l2_input.h> |
| 29 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 30 | /* *INDENT-OFF* */ |
Pierre Pfister | d6f5b96 | 2016-03-21 16:17:52 +0000 | [diff] [blame] | 31 | typedef CLIB_PACKED(struct _l2_rw_entry { |
| 32 | u16 skip_n_vectors; |
| 33 | u16 rewrite_n_vectors; |
| 34 | u64 hit_count; |
| 35 | u32x4 *mask; |
| 36 | u32x4 *value; |
| 37 | }) l2_rw_entry_t; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 38 | /* *INDENT-ON* */ |
Pierre Pfister | d6f5b96 | 2016-03-21 16:17:52 +0000 | [diff] [blame] | 39 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 40 | /* l2_rw configuration for one interface */ |
| 41 | /* *INDENT-OFF* */ |
Pierre Pfister | d6f5b96 | 2016-03-21 16:17:52 +0000 | [diff] [blame] | 42 | typedef CLIB_PACKED(struct _l2_rw_config { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 43 | u32 table_index; /* Which classify table to use */ |
| 44 | u32 miss_index; /* Rewrite entry to use if table does not match */ |
Pierre Pfister | d6f5b96 | 2016-03-21 16:17:52 +0000 | [diff] [blame] | 45 | }) l2_rw_config_t; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 46 | /* *INDENT-ON* */ |
Pierre Pfister | d6f5b96 | 2016-03-21 16:17:52 +0000 | [diff] [blame] | 47 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 48 | typedef struct |
| 49 | { |
Pierre Pfister | d6f5b96 | 2016-03-21 16:17:52 +0000 | [diff] [blame] | 50 | /* Next feature node indexes */ |
| 51 | u32 feat_next_node_index[32]; |
| 52 | |
| 53 | /* A pool of entries */ |
| 54 | l2_rw_entry_t *entries; |
| 55 | |
| 56 | /* Config vector indexed by sw_if_index */ |
| 57 | l2_rw_config_t *configs; |
| 58 | uword *configs_bitmap; |
| 59 | } l2_rw_main_t; |
| 60 | |
| 61 | extern l2_rw_main_t l2_rw_main; |
| 62 | |
| 63 | /* |
| 64 | * Specifies which classify table and miss_index should be used |
| 65 | * with the given interface. |
| 66 | * Use special values ~0 in order to un-set table_index |
| 67 | * or miss_index. |
| 68 | * l2_rw feature is automatically enabled for the interface |
| 69 | * when table_index or miss_index is not ~0. |
| 70 | * returns 0 on success and something else on error. |
| 71 | */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 72 | int l2_rw_interface_set_table (u32 sw_if_index, |
| 73 | u32 table_index, u32 miss_index); |
Pierre Pfister | d6f5b96 | 2016-03-21 16:17:52 +0000 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * Creates, modifies or delete a rewrite entry. |
| 77 | * If *index != ~0, modifies an existing entry (or simply |
| 78 | * deletes it if is_del is set). |
| 79 | * If *index == ~0, creates a new entry and the created |
| 80 | * entry index is stored in *index (Does nothing if is_del |
| 81 | * is set). |
| 82 | * returns 0 on success and something else on error. |
| 83 | */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 84 | int l2_rw_mod_entry (u32 * index, |
| 85 | u8 * mask, u8 * value, u32 len, u32 skip, u8 is_del); |
Pierre Pfister | d6f5b96 | 2016-03-21 16:17:52 +0000 | [diff] [blame] | 86 | |
Filip Tehlar | 44f0f71 | 2019-03-11 04:26:37 -0700 | [diff] [blame] | 87 | extern vlib_node_registration_t l2_rw_node; |
| 88 | |
Pierre Pfister | d6f5b96 | 2016-03-21 16:17:52 +0000 | [diff] [blame] | 89 | #endif /* L2_FW_H_ */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * fd.io coding-style-patch-verification: ON |
| 93 | * |
| 94 | * Local Variables: |
| 95 | * eval: (c-set-style "gnu") |
| 96 | * End: |
| 97 | */ |