FD.io VPP  v16.06
Vector Packet Processing
llc.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  * 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 
71 typedef enum {
72 #define _(f,n) LLC_PROTOCOL_##f = n,
74 #undef _
76 
77 typedef struct {
78 #define LLC_DST_SAP_IS_GROUP (1 << 0)
79 #define LLC_SRC_SAP_IS_RESPONSE (1 << 0)
80  u8 dst_sap, src_sap;
81 
82  /* Control byte.
83  [0] 1 => supervisory 0 => information
84  [1] unnumbered frame. */
86 
87  /* Only present if (control & 3) != 3. */
88  u8 extended_control[0];
89 } llc_header_t;
90 
93 {
94  u16 r = h->control;
95  return r | ((((r & 3) != 3) ? h->extended_control[0] : 0) << 8);
96 }
97 
100 {
101  return ((h->control & 3) != 3 ? 4 : 3);
102 }
103 
104 typedef struct {
105  /* Name (a c string). */
106  char * name;
107 
108  /* LLC protocol (SAP type). */
110 
111  /* Node which handles this type. */
113 
114  /* Next index for this type. */
117 
118 #define foreach_llc_error \
119  _ (NONE, "no error") \
120  _ (UNKNOWN_PROTOCOL, "unknown llc ssap/dsap") \
121  _ (UNKNOWN_CONTROL, "control != 0x3")
122 
123 typedef enum {
124 #define _(f,s) LLC_ERROR_##f,
126 #undef _
128 } llc_error_t;
129 
130 typedef struct {
132 
134 
135  /* Hash tables mapping name/protocol to protocol info index. */
136  uword * protocol_info_by_name, * protocol_info_by_protocol;
137 
138  /* llc-input next index indexed by protocol. */
139  u8 input_next_by_protocol[256];
140 } llc_main_t;
141 
144 {
145  uword * p = hash_get (m->protocol_info_by_protocol, protocol);
146  return p ? vec_elt_at_index (m->protocol_infos, p[0]) : 0;
147 }
148 
149 extern llc_main_t llc_main;
150 
151 /* Register given node index to take input for given llc type. */
152 void
154  llc_protocol_t protocol,
155  u32 node_index);
156 
157 void llc_set_adjacency (vnet_rewrite_header_t * rw,
158  uword max_data_bytes,
159  llc_protocol_t protocol);
160 
164 
165 /* Parse llc protocol as 0xXXXX or protocol name. */
167 
168 /* Parse llc header. */
171 
172 always_inline void
173 llc_setup_node (vlib_main_t * vm, u32 node_index)
174 {
175  vlib_node_t * n = vlib_get_node (vm, node_index);
176  pg_node_t * pn = pg_get_node (node_index);
177 
181 }
182 
183 #endif /* included_llc_h */
always_inline u16 llc_header_get_control(llc_header_t *h)
Definition: llc.h:92
unformat_function_t unformat_pg_llc_header
Definition: llc.h:170
llc_protocol_info_t * protocol_infos
Definition: llc.h:133
uword * protocol_info_by_protocol
Definition: llc.h:136
always_inline llc_protocol_info_t * llc_get_protocol_info(llc_main_t *m, llc_protocol_t protocol)
Definition: llc.h:143
uword( unformat_function_t)(unformat_input_t *input, va_list *args)
Definition: format.h:229
always_inline pg_node_t * pg_get_node(uword node_index)
Definition: pg.h:335
always_inline vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Definition: node_funcs.h:46
always_inline u8 llc_header_length(llc_header_t *h)
Definition: llc.h:99
u8 src_sap
Definition: llc.h:80
#define always_inline
Definition: clib.h:84
u8 extended_control[0]
Definition: llc.h:88
void llc_set_adjacency(vnet_rewrite_header_t *rw, uword max_data_bytes, llc_protocol_t protocol)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
llc_protocol_t
Definition: llc.h:71
#define hash_get(h, key)
Definition: hash.h:231
unformat_function_t unformat_llc_header
Definition: llc.h:169
format_function_t * format_buffer
Definition: node.h:277
format_function_t format_llc_header
Definition: llc.h:162
void llc_register_input_protocol(vlib_main_t *vm, llc_protocol_t protocol, u32 node_index)
Definition: node.c:288
unformat_function_t * unformat_buffer
Definition: node.h:278
unformat_function_t * unformat_edit
Definition: pg.h:290
#define foreach_llc_error
Definition: llc.h:118
format_function_t format_llc_header_with_length
Definition: llc.h:163
unsigned int u32
Definition: types.h:88
llc_protocol_t protocol
Definition: llc.h:109
vlib_main_t * vlib_main
Definition: llc.h:131
always_inline void llc_setup_node(vlib_main_t *vm, u32 node_index)
Definition: llc.h:173
u8 control
Definition: llc.h:85
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
u64 uword
Definition: types.h:112
unsigned short u16
Definition: types.h:57
llc_error_t
Definition: llc.h:123
unsigned char u8
Definition: types.h:56
llc_main_t llc_main
Definition: llc.c:44
#define foreach_llc_protocol
Definition: llc.h:47
unformat_function_t unformat_llc_protocol
Definition: llc.h:166
Definition: pg.h:288
char * name
Definition: llc.h:106
format_function_t format_llc_protocol
Definition: llc.h:161