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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 * snap.h: SNAP definitions
18 * Copyright (c) 2008 Eliot Dresselhaus
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:
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
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.
40 #ifndef included_snap_h
41 #define included_snap_h
43 #include <vnet/vnet.h>
45 #define foreach_ieee_oui \
46 _ (0x000000, ethernet) \
51 #define _(n,f) IEEE_OUI_##f = n,
56 #define foreach_snap_cisco_protocol \
58 _ (0x0104, port_aggregation_protocol) \
59 _ (0x0105, mls_hello) \
60 _ (0x010b, per_vlan_spanning_tree) \
61 _ (0x010c, vlan_bridge) \
62 _ (0x0111, unidirectional_link_detection) \
67 _ (0x200a, stp_uplink_fast)
71 #define _(n,f) SNAP_cisco_##f = n,
72 foreach_snap_cisco_protocol
74 } snap_cisco_protocol_t;
80 /* OUI: organization unique identifier. */
83 /* Per-OUI protocol. */
95 } snap_oui_and_protocol_t;
99 /* Name vector string. */
102 snap_oui_and_protocol_t oui_and_protocol;
104 /* Node which handles this type. */
107 /* snap-input next index for this type. */
109 } snap_protocol_info_t;
112 snap_header_set_protocol (snap_header_t * h, snap_oui_and_protocol_t * p)
114 u16 protocol = p->protocol;
116 h->protocol = clib_host_to_net_u16 (protocol);
117 h->oui[0] = (oui >> 16) & 0xff;
118 h->oui[1] = (oui >> 8) & 0xff;
119 h->oui[2] = (oui >> 0) & 0xff;
122 #define foreach_snap_error \
123 _ (NONE, "no error") \
124 _ (UNKNOWN_PROTOCOL, "unknown oui/snap protocol")
128 #define _(f,s) SNAP_ERROR_##f,
136 vlib_main_t *vlib_main;
138 /* Vector of known SNAP oui/protocol pairs. */
139 snap_protocol_info_t *protocols;
141 /* Hash table mapping oui/protocol to protocol index. */
142 mhash_t protocol_hash;
144 /* Hash table mapping protocol by name. */
145 uword *protocol_info_by_name;
149 snap_header_get_oui (snap_header_t * h)
151 return (h->oui[0] << 16) | (h->oui[1] << 8) | h->oui[2];
154 always_inline snap_protocol_info_t *
155 snap_get_protocol_info (snap_main_t * sm, snap_header_t * h)
157 snap_oui_and_protocol_t key;
160 key.oui = snap_header_get_oui (h);
161 key.protocol = h->protocol;
163 p = mhash_get (&sm->protocol_hash, &key);
164 return p ? vec_elt_at_index (sm->protocols, p[0]) : 0;
167 extern snap_main_t snap_main;
169 /* Register given node index to take input for given snap type. */
171 snap_register_input_protocol (vlib_main_t * vm,
173 u32 ieee_oui, u16 protocol, u32 node_index);
175 format_function_t format_snap_protocol;
176 format_function_t format_snap_header;
177 format_function_t format_snap_header_with_length;
179 /* Parse snap protocol as 0xXXXX or protocol name. */
180 unformat_function_t unformat_snap_protocol;
182 /* Parse snap header. */
183 unformat_function_t unformat_snap_header;
184 unformat_function_t unformat_pg_snap_header;
186 #endif /* included_snap_h */
189 * fd.io coding-style-patch-verification: ON
192 * eval: (c-set-style "gnu")