blob: 990a581db7b8caaee3f311599bb15d1dca8eb30b [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 * llc.h: LLC 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_llc_h
41#define included_llc_h
42
43#include <vnet/vnet.h>
44#include <vnet/pg/pg.h>
45
46/* Protocol (SSAP/DSAP) types. */
47#define foreach_llc_protocol \
48 _ (null, 0x0) \
49 _ (sublayer, 0x2) \
50 _ (sna_path_control, 0x4) \
51 _ (ip4, 0x6) \
52 _ (sna1, 0x8) \
53 _ (sna2, 0xc) \
54 _ (sna3, 0x40) \
55 _ (proway_lan, 0x0e) \
56 _ (netware1, 0x10) \
57 _ (netware2, 0xe0) \
58 _ (osi_layer1, 0x14) \
59 _ (osi_layer2, 0x20) \
60 _ (osi_layer3, 0x34) \
61 _ (osi_layer4, 0x54) \
62 _ (osi_layer5, 0xfe) \
63 _ (bpdu, 0x42) \
64 _ (arp, 0x98) \
65 _ (snap, 0xaa) \
66 _ (vines1, 0xba) \
67 _ (vines2, 0xbc) \
68 _ (netbios, 0xf0) \
69 _ (global_dsap, 0xff)
70
Calvin151fb722016-08-24 10:35:59 -040071typedef enum
72{
Ed Warnickecb9cada2015-12-08 15:45:58 -070073#define _(f,n) LLC_PROTOCOL_##f = n,
74 foreach_llc_protocol
75#undef _
76} llc_protocol_t;
77
Calvin151fb722016-08-24 10:35:59 -040078typedef struct
79{
Ed Warnickecb9cada2015-12-08 15:45:58 -070080#define LLC_DST_SAP_IS_GROUP (1 << 0)
81#define LLC_SRC_SAP_IS_RESPONSE (1 << 0)
82 u8 dst_sap, src_sap;
83
84 /* Control byte.
85 [0] 1 => supervisory 0 => information
86 [1] unnumbered frame. */
87 u8 control;
88
89 /* Only present if (control & 3) != 3. */
90 u8 extended_control[0];
91} llc_header_t;
92
93always_inline u16
94llc_header_get_control (llc_header_t * h)
95{
96 u16 r = h->control;
97 return r | ((((r & 3) != 3) ? h->extended_control[0] : 0) << 8);
98}
99
100always_inline u8
101llc_header_length (llc_header_t * h)
102{
103 return ((h->control & 3) != 3 ? 4 : 3);
104}
105
Calvin151fb722016-08-24 10:35:59 -0400106typedef struct
107{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700108 /* Name (a c string). */
Calvin151fb722016-08-24 10:35:59 -0400109 char *name;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700110
111 /* LLC protocol (SAP type). */
112 llc_protocol_t protocol;
113
114 /* Node which handles this type. */
115 u32 node_index;
116
117 /* Next index for this type. */
118 u32 next_index;
119} llc_protocol_info_t;
120
121#define foreach_llc_error \
122 _ (NONE, "no error") \
123 _ (UNKNOWN_PROTOCOL, "unknown llc ssap/dsap") \
124 _ (UNKNOWN_CONTROL, "control != 0x3")
125
Calvin151fb722016-08-24 10:35:59 -0400126typedef enum
127{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128#define _(f,s) LLC_ERROR_##f,
129 foreach_llc_error
130#undef _
Calvin151fb722016-08-24 10:35:59 -0400131 LLC_N_ERROR,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700132} llc_error_t;
133
Calvin151fb722016-08-24 10:35:59 -0400134typedef struct
135{
136 vlib_main_t *vlib_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700137
Calvin151fb722016-08-24 10:35:59 -0400138 llc_protocol_info_t *protocol_infos;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700139
140 /* Hash tables mapping name/protocol to protocol info index. */
Calvin151fb722016-08-24 10:35:59 -0400141 uword *protocol_info_by_name, *protocol_info_by_protocol;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700142
143 /* llc-input next index indexed by protocol. */
144 u8 input_next_by_protocol[256];
145} llc_main_t;
146
147always_inline llc_protocol_info_t *
148llc_get_protocol_info (llc_main_t * m, llc_protocol_t protocol)
149{
Calvin151fb722016-08-24 10:35:59 -0400150 uword *p = hash_get (m->protocol_info_by_protocol, protocol);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700151 return p ? vec_elt_at_index (m->protocol_infos, p[0]) : 0;
152}
153
154extern llc_main_t llc_main;
155
156/* Register given node index to take input for given llc type. */
157void
158llc_register_input_protocol (vlib_main_t * vm,
Calvin151fb722016-08-24 10:35:59 -0400159 llc_protocol_t protocol, u32 node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700160
Ed Warnickecb9cada2015-12-08 15:45:58 -0700161format_function_t format_llc_protocol;
162format_function_t format_llc_header;
163format_function_t format_llc_header_with_length;
164
165/* Parse llc protocol as 0xXXXX or protocol name. */
166unformat_function_t unformat_llc_protocol;
167
168/* Parse llc header. */
169unformat_function_t unformat_llc_header;
170unformat_function_t unformat_pg_llc_header;
171
172always_inline void
173llc_setup_node (vlib_main_t * vm, u32 node_index)
174{
Calvin151fb722016-08-24 10:35:59 -0400175 vlib_node_t *n = vlib_get_node (vm, node_index);
176 pg_node_t *pn = pg_get_node (node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700177
178 n->format_buffer = format_llc_header_with_length;
179 n->unformat_buffer = unformat_llc_header;
180 pn->unformat_edit = unformat_pg_llc_header;
181}
182
183#endif /* included_llc_h */
Calvin151fb722016-08-24 10:35:59 -0400184
185/*
186 * fd.io coding-style-patch-verification: ON
187 *
188 * Local Variables:
189 * eval: (c-set-style "gnu")
190 * End:
191 */