-
Notifications
You must be signed in to change notification settings - Fork 8
/
lldp_8021qaz_clif.c
318 lines (274 loc) · 7.51 KB
/
lldp_8021qaz_clif.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*******************************************************************************
LLDP Agent Daemon (LLDPAD) Software
Copyright(c) 2007-2012 Intel Corporation.
This program is free software; you can redistribute it and/or modify it
under the terms and conditions of the GNU General Public License,
version 2, as published by the Free Software Foundation.
This program is distributed in the hope it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
The full GNU General Public License is included in this distribution in
the file called "COPYING".
Contact Information:
open-lldp Mailing List <lldp-devel@open-lldp.org>
*******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <syslog.h>
#include <sys/un.h>
#include <sys/stat.h>
#include "lldp.h"
#include "lldp_mod.h"
#include "clif_msgs.h"
#include "lldp_8021qaz.h"
#include "lldp_8021qaz_clif.h"
static void ieee8021qaz_print_etscfg_tlv(u16 len, char *info);
static void ieee8021qaz_print_etsrec_tlv(u16 len, char *info);
static void ieee8021qaz_print_pfc_tlv(u16 len, char *info);
static void ieee8021qaz_print_app_tlv(u16 len, char *info);
static u32 ieee8021qaz_lookup_tlv_name(char *tlvid_str);
static int ieee8021qaz_print_help(void);
static const struct lldp_mod_ops ieee8021qaz_ops_clif = {
.lldp_mod_register = ieee8021qaz_cli_register,
.lldp_mod_unregister = ieee8021qaz_cli_unregister,
.print_tlv = ieee8021qaz_print_tlv,
.lookup_tlv_name = ieee8021qaz_lookup_tlv_name,
.print_help = ieee8021qaz_print_help,
};
struct type_name_info ieee8021qaz_tlv_names[] = {
{
.type = (OUI_IEEE_8021 << 8),
.name = "IEEE-DCBX Settings", .key = "IEEE-DCBX",
},
{
.type = (OUI_IEEE_8021 << 8) | LLDP_8021QAZ_ETSCFG,
.name = "IEEE 8021QAZ ETS Configuration TLV", .key = "ETS-CFG",
.print_info = ieee8021qaz_print_etscfg_tlv,
},
{
.type = (OUI_IEEE_8021 << 8) | LLDP_8021QAZ_ETSREC,
.name = "IEEE 8021QAZ ETS Recommendation TLV", .key = "ETS-REC",
.print_info = ieee8021qaz_print_etsrec_tlv,
},
{
.type = (OUI_IEEE_8021 << 8) | LLDP_8021QAZ_PFC,
.name = "IEEE 8021QAZ PFC TLV", .key = "PFC",
.print_info = ieee8021qaz_print_pfc_tlv,
},
{
.type = (OUI_IEEE_8021 << 8) | LLDP_8021QAZ_APP,
.name = "IEEE 8021QAZ APP TLV", .key = "APP",
.print_info = ieee8021qaz_print_app_tlv,
},
{ .type = INVALID_TLVID, }
};
static int ieee8021qaz_print_help(void)
{
struct type_name_info *tn = &ieee8021qaz_tlv_names[0];
while (tn->type != INVALID_TLVID) {
if (tn->key && strlen(tn->key) && tn->name) {
printf(" %s", tn->key);
if (strlen(tn->key)+3 < 8)
printf("\t");
printf("\t: %s\n", tn->name);
}
tn++;
}
return 0;
}
struct lldp_module *ieee8021qaz_cli_register(void)
{
struct lldp_module *mod;
mod = malloc(sizeof(*mod));
if (!mod)
return NULL;
mod->id = LLDP_MOD_8021QAZ;
mod->ops = &ieee8021qaz_ops_clif;
return mod;
}
void ieee8021qaz_cli_unregister(struct lldp_module *mod)
{
free(mod);
}
static void ieee8021qaz_print_etscfg_tlv(UNUSED u16 len, char *info)
{
u8 wc_maxtc;
u8 tc_bw[8], tsa_map[8];
u32 prio_map;
int offset = 0, i = 0;
hexstr2bin(info, (u8 *)&wc_maxtc, 1);
printf(" Willing: %s\n", (wc_maxtc & 0x80) ? "yes" : "no");
printf("\t CBS: %s\n",
(wc_maxtc & 0x40) ? "supported" : "not supported");
if (!(wc_maxtc & 0x7))
printf("\t MAX_TCS: 8\n");
else
printf("\t MAX_TCS: %i\n", wc_maxtc & 0x7);
offset += 2;
hexstr2bin(info + offset, (u8 *)&prio_map, 4);
prio_map = ntohl(prio_map);
printf("\t PRIO_MAP: ");
for (i = 0; i < 8; i++)
printf("%i:%i ", i, (prio_map >> ((7-i)*4)) & 0xf);
printf("\n");
offset += 8;
hexstr2bin(info + offset, tc_bw, 8);
printf("\t TC Bandwidth: ");
for (i = 0; i < MAX_TCS; i++)
printf("%i%% ", tc_bw[i]);
printf("\n");
offset += 16;
hexstr2bin(info + offset, (u8 *)tsa_map, 8);
printf("\t TSA_MAP: ");
for (i = 0; i < MAX_TCS; i++) {
printf("%i:", i);
switch (tsa_map[i]) {
case IEEE8021Q_TSA_STRICT:
printf("strict ");
break;
case IEEE8021Q_TSA_CBSHAPER:
printf("cbshaper ");
break;
case IEEE8021Q_TSA_ETS:
printf("ets ");
break;
case IEEE8021Q_TSA_VENDOR:
printf("vendor ");
break;
default:
printf("unknown ");
break;
}
}
printf("\n");
}
static void ieee8021qaz_print_etsrec_tlv(UNUSED u16 len, char *info)
{
u8 offset = 0;
u32 prio_map;
u8 tc_bw[8], tsa_map[8];
int i = 0;
/* advanced past initial 8bit reserved field */
offset += 2;
hexstr2bin(info + offset, (u8 *)&prio_map, 4);
prio_map = ntohl(prio_map);
printf(" PRIO_MAP: ");
for (i = 0; i < 8; i++)
printf("%i:%i ", i, (prio_map >> ((7-i)*4)) & 0xf);
printf("\n");
offset += 8;
hexstr2bin(info + offset, tc_bw, 8);
printf("\t TC Bandwidth: ");
for (i = 0; i < MAX_TCS; i++)
printf("%i%% ", tc_bw[i]);
printf("\n");
offset += 16;
hexstr2bin(info + offset, (u8 *)tsa_map, 8);
printf("\t TSA_MAP: ");
for (i = 0; i < MAX_TCS; i++) {
printf("%i:", i);
switch (tsa_map[i]) {
case IEEE8021Q_TSA_STRICT:
printf("strict ");
break;
case IEEE8021Q_TSA_CBSHAPER:
printf("cbshaper ");
break;
case IEEE8021Q_TSA_ETS:
printf("ets ");
break;
case IEEE8021Q_TSA_VENDOR:
printf("vendor ");
break;
default:
printf("unknown ");
break;
}
}
printf("\n");
}
static void ieee8021qaz_print_pfc_tlv(UNUSED u16 len, char *info)
{
int i, offset = 0;
u8 w_mbc_cap, pfc_enable;
u8 found = 0;
hexstr2bin(info + offset, (u8 *)&w_mbc_cap, 1);
printf(" Willing: %s\n", (w_mbc_cap & 0x80) ? "yes" : "no");
printf("\t MACsec Bypass Capable: %s\n",
(w_mbc_cap & 0x40) ? "yes" : "no");
printf("\t PFC capable traffic classes: %i\n", w_mbc_cap & 0x0f);
offset += 2;
printf("\t PFC enabled: ");
hexstr2bin(info + offset, (u8 *)&pfc_enable, 1);
for (i = 0; i < 8; i++) {
if ((pfc_enable >> i) & 1) {
found = 1;
printf("%i ", i);
}
}
if (!found)
printf("none");
printf("\n");
}
static void ieee8021qaz_print_app_tlv(u16 len, char *info)
{
u8 offset = 2;
u8 app;
u16 proto;
while (offset < len*2) {
hexstr2bin(info + offset, &app, 1);
hexstr2bin(info + offset + 2, (u8 *)&proto, 2);
if (offset > 6)
printf("\t");
printf("App#%i:\n", offset/6);
printf("\t Priority: %i\n", (app & 0xE0) >> 5);
printf("\t Sel: %i\n", app & 0x07);
switch (app & 0x07) {
case 1:
printf("\t Ethertype: 0x%04x\n", ntohs(proto));
break;
case 2:
printf("\t {S}TCP Port: %i\n", ntohs(proto));
break;
case 3:
printf("\t UDP or DCCP Port: %i\n", ntohs(proto));
break;
case 4:
printf("\t TCP/STCP/UDP/DCCP Port: %i\n", ntohs(proto));
break;
default:
printf("\t Reserved Port: %i\n", ntohs(proto));
break;
}
printf("\n");
offset += 6;
}
}
int ieee8021qaz_print_tlv(u32 tlvid, u16 len, char *info)
{
struct type_name_info *tn = &ieee8021qaz_tlv_names[0];
while (tn->type != INVALID_TLVID) {
if (tlvid == tn->type) {
printf("%s\n\t", tn->name);
if (tn->print_info)
tn->print_info(len - 4, info);
return 1;
}
tn++;
}
return 0;
}
static u32 ieee8021qaz_lookup_tlv_name(char *tlvid_str)
{
struct type_name_info *tn = &ieee8021qaz_tlv_names[0];
while (tn->type != INVALID_TLVID) {
if (!strcasecmp(tn->key, tlvid_str))
return tn->type;
tn++;
}
return INVALID_TLVID;
}