blob: f6b3be1847fddc529e49119c6c12f21c04fae7c0 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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>
Ed Warnickecb9cada2015-12-08 15:45:58 -070044
45#define foreach_ieee_oui \
46 _ (0x000000, ethernet) \
47 _ (0x00000c, cisco)
48
Calvin Ferencecc6ca882016-08-25 10:04:09 -040049typedef enum
50{
Ed Warnickecb9cada2015-12-08 15:45:58 -070051#define _(n,f) IEEE_OUI_##f = n,
52 foreach_ieee_oui
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
Calvin Ferencecc6ca882016-08-25 10:04:09 -040069typedef enum
70{
Ed Warnickecb9cada2015-12-08 15:45:58 -070071#define _(n,f) SNAP_cisco_##f = n,
72 foreach_snap_cisco_protocol
73#undef _
74} snap_cisco_protocol_t;
75
Calvin Ferencecc6ca882016-08-25 10:04:09 -040076typedef union
77{
78 /* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070079 CLIB_PACKED (struct {
80 /* OUI: organization unique identifier. */
81 u8 oui[3];
82
83 /* Per-OUI protocol. */
84 u16 protocol;
85 });
Calvin Ferencecc6ca882016-08-25 10:04:09 -040086 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -070087
88 u8 as_u8[5];
89} snap_header_t;
90
Calvin Ferencecc6ca882016-08-25 10:04:09 -040091typedef struct
92{
Ed Warnickecb9cada2015-12-08 15:45:58 -070093 u32 oui;
94 u32 protocol;
95} snap_oui_and_protocol_t;
96
Calvin Ferencecc6ca882016-08-25 10:04:09 -040097typedef struct
98{
Ed Warnickecb9cada2015-12-08 15:45:58 -070099 /* Name vector string. */
Calvin Ferencecc6ca882016-08-25 10:04:09 -0400100 u8 *name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700101
102 snap_oui_and_protocol_t oui_and_protocol;
103
104 /* Node which handles this type. */
105 u32 node_index;
106
107 /* snap-input next index for this type. */
108 u32 next_index;
109} snap_protocol_info_t;
110
111always_inline void
112snap_header_set_protocol (snap_header_t * h, snap_oui_and_protocol_t * p)
113{
114 u16 protocol = p->protocol;
115 u32 oui = p->oui;
116 h->protocol = clib_host_to_net_u16 (protocol);
117 h->oui[0] = (oui >> 16) & 0xff;
Calvin Ferencecc6ca882016-08-25 10:04:09 -0400118 h->oui[1] = (oui >> 8) & 0xff;
119 h->oui[2] = (oui >> 0) & 0xff;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700120}
121
122#define foreach_snap_error \
123 _ (NONE, "no error") \
124 _ (UNKNOWN_PROTOCOL, "unknown oui/snap protocol")
125
Calvin Ferencecc6ca882016-08-25 10:04:09 -0400126typedef enum
127{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128#define _(f,s) SNAP_ERROR_##f,
129 foreach_snap_error
130#undef _
Calvin Ferencecc6ca882016-08-25 10:04:09 -0400131 SNAP_N_ERROR,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700132} snap_error_t;
133
Calvin Ferencecc6ca882016-08-25 10:04:09 -0400134typedef struct
135{
136 vlib_main_t *vlib_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700137
138 /* Vector of known SNAP oui/protocol pairs. */
Calvin Ferencecc6ca882016-08-25 10:04:09 -0400139 snap_protocol_info_t *protocols;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700140
141 /* Hash table mapping oui/protocol to protocol index. */
142 mhash_t protocol_hash;
143
144 /* Hash table mapping protocol by name. */
Calvin Ferencecc6ca882016-08-25 10:04:09 -0400145 uword *protocol_info_by_name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700146} snap_main_t;
147
148always_inline u32
149snap_header_get_oui (snap_header_t * h)
150{
151 return (h->oui[0] << 16) | (h->oui[1] << 8) | h->oui[2];
152}
153
154always_inline snap_protocol_info_t *
155snap_get_protocol_info (snap_main_t * sm, snap_header_t * h)
156{
157 snap_oui_and_protocol_t key;
Calvin Ferencecc6ca882016-08-25 10:04:09 -0400158 uword *p;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700159
160 key.oui = snap_header_get_oui (h);
161 key.protocol = h->protocol;
162
163 p = mhash_get (&sm->protocol_hash, &key);
164 return p ? vec_elt_at_index (sm->protocols, p[0]) : 0;
165}
166
Dave Wallace71612d62017-10-24 01:32:41 -0400167extern snap_main_t snap_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700168
169/* Register given node index to take input for given snap type. */
170void
171snap_register_input_protocol (vlib_main_t * vm,
Calvin Ferencecc6ca882016-08-25 10:04:09 -0400172 char *name,
173 u32 ieee_oui, u16 protocol, u32 node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700174
Ed Warnickecb9cada2015-12-08 15:45:58 -0700175format_function_t format_snap_protocol;
176format_function_t format_snap_header;
177format_function_t format_snap_header_with_length;
178
179/* Parse snap protocol as 0xXXXX or protocol name. */
180unformat_function_t unformat_snap_protocol;
181
182/* Parse snap header. */
183unformat_function_t unformat_snap_header;
184unformat_function_t unformat_pg_snap_header;
185
Ed Warnickecb9cada2015-12-08 15:45:58 -0700186#endif /* included_snap_h */
Calvin Ferencecc6ca882016-08-25 10:04:09 -0400187
188/*
189 * fd.io coding-style-patch-verification: ON
190 *
191 * Local Variables:
192 * eval: (c-set-style "gnu")
193 * End:
194 */