FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
snap.h
Go to the documentation of this file.
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  * snap.h: SNAP definitions
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 #ifndef included_snap_h
41 #define included_snap_h
42 
43 #include <vnet/vnet.h>
44 #include <vnet/pg/pg.h>
45 
46 #define foreach_ieee_oui \
47  _ (0x000000, ethernet) \
48  _ (0x00000c, cisco)
49 
50 typedef enum
51 {
52 #define _(n,f) IEEE_OUI_##f = n,
54 #undef _
55 } ieee_oui_t;
56 
57 #define foreach_snap_cisco_protocol \
58  _ (0x0102, drip) \
59  _ (0x0104, port_aggregation_protocol) \
60  _ (0x0105, mls_hello) \
61  _ (0x010b, per_vlan_spanning_tree) \
62  _ (0x010c, vlan_bridge) \
63  _ (0x0111, unidirectional_link_detection) \
64  _ (0x2000, cdp) \
65  _ (0x2001, cgmp) \
66  _ (0x2003, vtp) \
67  _ (0x2004, dtp) \
68  _ (0x200a, stp_uplink_fast)
69 
70 typedef enum
71 {
72 #define _(n,f) SNAP_cisco_##f = n,
74 #undef _
76 
77 typedef union
78 {
79  /* *INDENT-OFF* */
80  CLIB_PACKED (struct {
81  /* OUI: organization unique identifier. */
82  u8 oui[3];
83 
84  /* Per-OUI protocol. */
85  u16 protocol;
86  });
87  /* *INDENT-ON* */
88 
89  u8 as_u8[5];
91 
92 typedef struct
93 {
97 
98 typedef struct
99 {
100  /* Name vector string. */
102 
104 
105  /* Node which handles this type. */
107 
108  /* snap-input next index for this type. */
111 
112 always_inline void
114 {
115  u16 protocol = p->protocol;
116  u32 oui = p->oui;
117  h->protocol = clib_host_to_net_u16 (protocol);
118  h->oui[0] = (oui >> 16) & 0xff;
119  h->oui[1] = (oui >> 8) & 0xff;
120  h->oui[2] = (oui >> 0) & 0xff;
121 }
122 
123 #define foreach_snap_error \
124  _ (NONE, "no error") \
125  _ (UNKNOWN_PROTOCOL, "unknown oui/snap protocol")
126 
127 typedef enum
128 {
129 #define _(f,s) SNAP_ERROR_##f,
131 #undef _
133 } snap_error_t;
134 
135 typedef struct
136 {
138 
139  /* Vector of known SNAP oui/protocol pairs. */
141 
142  /* Hash table mapping oui/protocol to protocol index. */
144 
145  /* Hash table mapping protocol by name. */
147 } snap_main_t;
148 
151 {
152  return (h->oui[0] << 16) | (h->oui[1] << 8) | h->oui[2];
153 }
154 
157 {
159  uword *p;
160 
161  key.oui = snap_header_get_oui (h);
162  key.protocol = h->protocol;
163 
164  p = mhash_get (&sm->protocol_hash, &key);
165  return p ? vec_elt_at_index (sm->protocols, p[0]) : 0;
166 }
167 
168 extern snap_main_t snap_main;
169 
170 /* Register given node index to take input for given snap type. */
171 void
173  char *name,
174  u32 ieee_oui, u16 protocol, u32 node_index);
175 
179 
180 /* Parse snap protocol as 0xXXXX or protocol name. */
182 
183 /* Parse snap header. */
186 
187 always_inline void
189 {
192 
196 }
197 
198 #endif /* included_snap_h */
199 
200 /*
201  * fd.io coding-style-patch-verification: ON
202  *
203  * Local Variables:
204  * eval: (c-set-style "gnu")
205  * End:
206  */
snap_main_t::protocol_hash
mhash_t protocol_hash
Definition: snap.h:143
snap_header_get_oui
static u32 snap_header_get_oui(snap_header_t *h)
Definition: snap.h:150
format_snap_protocol
format_function_t format_snap_protocol
Definition: snap.h:176
snap_header_t
Definition: snap.h:77
pg.h
foreach_ieee_oui
#define foreach_ieee_oui
Definition: snap.h:46
snap_oui_and_protocol_t::protocol
u32 protocol
Definition: snap.h:95
name
string name[64]
Definition: fib.api:25
mhash_t
Definition: mhash.h:46
u16
unsigned short u16
Definition: types.h:57
mhash_get
static uword * mhash_get(mhash_t *h, const void *key)
Definition: mhash.h:110
unformat_snap_protocol
unformat_function_t unformat_snap_protocol
Definition: snap.h:181
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
node_index
node node_index
Definition: interface_output.c:420
unformat_pg_snap_header
unformat_function_t unformat_pg_snap_header
Definition: snap.h:185
snap_oui_and_protocol_t
Definition: snap.h:92
vlib_node_t::unformat_buffer
unformat_function_t * unformat_buffer
Definition: node.h:349
h
h
Definition: flowhash_template.h:372
snap_setup_node
static void snap_setup_node(vlib_main_t *vm, u32 node_index)
Definition: snap.h:188
key
typedef key
Definition: ipsec_types.api:88
pg_node_t
Definition: pg.h:324
snap_protocol_info_t::name
u8 * name
Definition: snap.h:101
snap_cisco_protocol_t
snap_cisco_protocol_t
Definition: snap.h:70
vlib_node_t::format_buffer
format_function_t * format_buffer
Definition: node.h:348
snap_main_t::vlib_main
vlib_main_t * vlib_main
Definition: snap.h:137
pg_node_t::unformat_edit
unformat_function_t * unformat_edit
Definition: pg.h:327
snap_protocol_info_t::oui_and_protocol
snap_oui_and_protocol_t oui_and_protocol
Definition: snap.h:103
format_snap_header
format_function_t format_snap_header
Definition: snap.h:177
vec_elt_at_index
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Definition: vec_bootstrap.h:203
uword
u64 uword
Definition: types.h:112
pg_get_node
static pg_node_t * pg_get_node(uword node_index)
Definition: pg.h:381
unformat_snap_header
unformat_function_t unformat_snap_header
Definition: snap.h:184
snap_register_input_protocol
void snap_register_input_protocol(vlib_main_t *vm, char *name, u32 ieee_oui, u16 protocol, u32 node_index)
Definition: node.c:306
snap_main_t::protocol_info_by_name
uword * protocol_info_by_name
Definition: snap.h:146
vlib_get_node
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
Definition: node_funcs.h:86
format_function_t
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
snap_header_set_protocol
static void snap_header_set_protocol(snap_header_t *h, snap_oui_and_protocol_t *p)
Definition: snap.h:113
snap_oui_and_protocol_t::oui
u32 oui
Definition: snap.h:94
snap_main_t
Definition: snap.h:135
SNAP_N_ERROR
@ SNAP_N_ERROR
Definition: snap.h:132
snap_protocol_info_t
Definition: snap.h:98
u32
unsigned int u32
Definition: types.h:88
snap_protocol_info_t::node_index
u32 node_index
Definition: snap.h:106
protocol
vl_api_ip_proto_t protocol
Definition: lb_types.api:72
foreach_snap_cisco_protocol
#define foreach_snap_cisco_protocol
Definition: snap.h:57
unformat_function_t
uword() unformat_function_t(unformat_input_t *input, va_list *args)
Definition: format.h:225
snap_error_t
snap_error_t
Definition: snap.h:127
vlib_main_t
Definition: main.h:102
foreach_snap_error
#define foreach_snap_error
Definition: snap.h:123
vlib_node_t
Definition: node.h:247
u8
unsigned char u8
Definition: types.h:56
CLIB_PACKED
#define CLIB_PACKED(x)
Definition: clib.h:89
format_snap_header_with_length
format_function_t format_snap_header_with_length
Definition: snap.h:178
snap_get_protocol_info
static snap_protocol_info_t * snap_get_protocol_info(snap_main_t *sm, snap_header_t *h)
Definition: snap.h:156
snap_protocol_info_t::next_index
u32 next_index
Definition: snap.h:109
ieee_oui_t
ieee_oui_t
Definition: snap.h:50
vnet.h
snap_main
snap_main_t snap_main
Definition: snap.c:45
snap_main_t::protocols
snap_protocol_info_t * protocols
Definition: snap.h:140