FD.io VPP  v16.09
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 #define _(n,f) IEEE_OUI_##f = n,
53 #undef _
54 } ieee_oui_t;
55 
56 #define foreach_snap_cisco_protocol \
57  _ (0x0102, drip) \
58  _ (0x0104, port_aggregation_protocol) \
59  _ (0x0105, mls_hello) \
60  _ (0x010b, per_vlan_spanning_tree) \
61  _ (0x010c, vlan_bridge) \
62  _ (0x0111, unidirectional_link_detection) \
63  _ (0x2000, cdp) \
64  _ (0x2001, cgmp) \
65  _ (0x2003, vtp) \
66  _ (0x2004, dtp) \
67  _ (0x200a, stp_uplink_fast)
68 
69 typedef enum {
70 #define _(n,f) SNAP_cisco_##f = n,
72 #undef _
74 
75 typedef union {
76  CLIB_PACKED (struct {
77  /* OUI: organization unique identifier. */
78  u8 oui[3];
79 
80  /* Per-OUI protocol. */
81  u16 protocol;
82  });
83 
84  u8 as_u8[5];
86 
87 typedef struct {
91 
92 typedef struct {
93  /* Name vector string. */
94  u8 * name;
95 
97 
98  /* Node which handles this type. */
100 
101  /* snap-input next index for this type. */
104 
105 always_inline void
107 {
108  u16 protocol = p->protocol;
109  u32 oui = p->oui;
110  h->protocol = clib_host_to_net_u16 (protocol);
111  h->oui[0] = (oui >> 16) & 0xff;
112  h->oui[1] = (oui >> 8) & 0xff;
113  h->oui[2] = (oui >> 0) & 0xff;
114 }
115 
116 #define foreach_snap_error \
117  _ (NONE, "no error") \
118  _ (UNKNOWN_PROTOCOL, "unknown oui/snap protocol")
119 
120 typedef enum {
121 #define _(f,s) SNAP_ERROR_##f,
123 #undef _
125 } snap_error_t;
126 
127 typedef struct {
129 
130  /* Vector of known SNAP oui/protocol pairs. */
132 
133  /* Hash table mapping oui/protocol to protocol index. */
135 
136  /* Hash table mapping protocol by name. */
138 } snap_main_t;
139 
142 {
143  return (h->oui[0] << 16) | (h->oui[1] << 8) | h->oui[2];
144 }
145 
148 {
150  uword * p;
151 
152  key.oui = snap_header_get_oui (h);
153  key.protocol = h->protocol;
154 
155  p = mhash_get (&sm->protocol_hash, &key);
156  return p ? vec_elt_at_index (sm->protocols, p[0]) : 0;
157 }
158 
160 
161 /* Register given node index to take input for given snap type. */
162 void
164  char * name,
165  u32 ieee_oui,
166  u16 protocol,
167  u32 node_index);
168 
169 void snap_set_adjacency (vnet_rewrite_header_t * rw,
170  uword max_data_bytes,
171  u32 ieee_oui,
172  u16 protocol);
173 
177 
178 /* Parse snap protocol as 0xXXXX or protocol name. */
180 
181 /* Parse snap header. */
184 
185 always_inline void
186 snap_setup_node (vlib_main_t * vm, u32 node_index)
187 {
188  vlib_node_t * n = vlib_get_node (vm, node_index);
189  pg_node_t * pn = pg_get_node (node_index);
190 
194 }
195 
196 #endif /* included_snap_h */
static void snap_setup_node(vlib_main_t *vm, u32 node_index)
Definition: snap.h:186
snap_error_t
Definition: snap.h:120
Definition: mhash.h:46
uword( unformat_function_t)(unformat_input_t *input, va_list *args)
Definition: format.h:231
ieee_oui_t
Definition: snap.h:50
#define foreach_snap_error
Definition: snap.h:116
format_function_t format_snap_header
Definition: snap.h:175
static pg_node_t * pg_get_node(uword node_index)
Definition: pg.h:343
#define always_inline
Definition: clib.h:84
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
static void snap_header_set_protocol(snap_header_t *h, snap_oui_and_protocol_t *p)
Definition: snap.h:106
unformat_function_t unformat_snap_protocol
Definition: snap.h:179
void snap_set_adjacency(vnet_rewrite_header_t *rw, uword max_data_bytes, u32 ieee_oui, u16 protocol)
snap_oui_and_protocol_t oui_and_protocol
Definition: snap.h:96
format_function_t format_snap_header_with_length
Definition: snap.h:176
format_function_t * format_buffer
Definition: node.h:311
snap_cisco_protocol_t
Definition: snap.h:69
mhash_t protocol_hash
Definition: snap.h:134
#define foreach_snap_cisco_protocol
Definition: snap.h:56
static snap_protocol_info_t * snap_get_protocol_info(snap_main_t *sm, snap_header_t *h)
Definition: snap.h:147
uword * protocol_info_by_name
Definition: snap.h:137
unformat_function_t * unformat_buffer
Definition: node.h:312
unformat_function_t * unformat_edit
Definition: pg.h:299
static uword * mhash_get(mhash_t *h, void *key)
Definition: mhash.h:110
unformat_function_t unformat_pg_snap_header
Definition: snap.h:183
static u32 snap_header_get_oui(snap_header_t *h)
Definition: snap.h:141
snap_main_t snap_main
Definition: snap.h:159
unsigned int u32
Definition: types.h:88
#define foreach_ieee_oui
Definition: snap.h:46
unformat_function_t unformat_snap_header
Definition: snap.h:182
format_function_t format_snap_protocol
Definition: snap.h:174
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
u64 uword
Definition: types.h:112
void snap_register_input_protocol(vlib_main_t *vm, char *name, u32 ieee_oui, u16 protocol, u32 node_index)
Definition: node.c:305
unsigned short u16
Definition: types.h:57
unsigned char u8
Definition: types.h:56
vlib_main_t * vlib_main
Definition: snap.h:128
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
Definition: node_funcs.h:58
snap_protocol_info_t * protocols
Definition: snap.h:131
Definition: pg.h:297
#define CLIB_PACKED(x)
Definition: clib.h:78