-
Notifications
You must be signed in to change notification settings - Fork 43
/
lldp_med_cmds.c
349 lines (296 loc) · 11.1 KB
/
lldp_med_cmds.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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/*******************************************************************************
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 <[email protected]>
*******************************************************************************/
#include <stdio.h>
#include <syslog.h>
#include <sys/un.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include "lldpad.h"
#include "ctrl_iface.h"
#include "lldp.h"
#include "lldp_med.h"
#include "lldp_8023.h"
#include "lldp_mand_clif.h"
#include "lldp_med_clif.h"
#include "lldp/ports.h"
#include "libconfig.h"
#include "config.h"
#include "clif_msgs.h"
#include "lldpad_status.h"
#include "lldp/states.h"
static int get_arg_tlvtxenable(struct cmd *, char *, char *, char *, int);
static int set_arg_tlvtxenable(struct cmd *, char *, char *, char *, int);
static int test_arg_tlvtxenable(struct cmd *, char *, char *, char *, int);
static int get_arg_med_devtype(struct cmd *, char *, char *, char *, int);
static int set_arg_med_devtype(struct cmd *, char *, char *, char *, int);
static int test_arg_med_devtype(struct cmd *, char *, char *, char *, int);
static struct arg_handlers arg_handlers[] = {
{ .arg = ARG_TLVTXENABLE, .arg_class = TLV_ARG,
.handle_get = get_arg_tlvtxenable,
.handle_set = set_arg_tlvtxenable,
.handle_test = test_arg_tlvtxenable, },
{ .arg = ARG_MED_DEVTYPE, .arg_class = TLV_ARG,
.handle_get = get_arg_med_devtype,
.handle_set = set_arg_med_devtype,
.handle_test = test_arg_med_devtype, },
{ .arg = 0 }
};
static int
get_arg_tlvtxenable(struct cmd *cmd, char *arg, UNUSED char *argvalue,
char *obuf, int obuf_len)
{
int value;
char *s;
char arg_path[256];
if (cmd->cmd != cmd_gettlv)
return cmd_invalid;
switch (cmd->tlvid) {
case (OUI_TIA_TR41 << 8):
case (OUI_TIA_TR41 << 8) | LLDP_MED_CAPABILITIES:
case (OUI_TIA_TR41 << 8) | LLDP_MED_NETWORK_POLICY:
case (OUI_TIA_TR41 << 8) | LLDP_MED_LOCATION_ID:
case (OUI_TIA_TR41 << 8) | LLDP_MED_EXTENDED_PVMDI:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_HWREV:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_FWREV:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_SWREV:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_SERIAL:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_MANUFACTURER:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_MODELNAME:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_ASSETID:
snprintf(arg_path, sizeof(arg_path), "%s%08x.%s",
TLVID_PREFIX, cmd->tlvid, arg);
if (get_config_setting(cmd->ifname, cmd->type, arg_path,
&value, CONFIG_TYPE_BOOL))
value = false;
break;
case INVALID_TLVID:
return cmd_invalid;
default:
return cmd_not_applicable;
}
if (value)
s = VAL_YES;
else
s = VAL_NO;
snprintf(obuf, obuf_len, "%02zx%s%04zx%s",
strlen(arg), arg, strlen(s), s);
return cmd_success;
}
static int _set_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue,
char *obuf, int obuf_len, bool test)
{
int value;
char arg_path[256];
if (cmd->cmd != cmd_settlv)
return cmd_invalid;
switch (cmd->tlvid) {
case (OUI_TIA_TR41 << 8):
case (OUI_TIA_TR41 << 8) | LLDP_MED_CAPABILITIES:
case (OUI_TIA_TR41 << 8) | LLDP_MED_NETWORK_POLICY:
case (OUI_TIA_TR41 << 8) | LLDP_MED_LOCATION_ID:
case (OUI_TIA_TR41 << 8) | LLDP_MED_EXTENDED_PVMDI:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_HWREV:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_FWREV:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_SWREV:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_SERIAL:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_MANUFACTURER:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_MODELNAME:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_ASSETID:
break;
case INVALID_TLVID:
return cmd_invalid;
default:
return cmd_not_applicable;
}
if (!strcasecmp(argvalue, VAL_YES))
value = 1;
else if (!strcasecmp(argvalue, VAL_NO))
value = 0;
else
return cmd_invalid;
if (test)
return cmd_success;
snprintf(arg_path, sizeof(arg_path), "%s%08x.%s", TLVID_PREFIX,
cmd->tlvid, arg);
if (set_config_setting(cmd->ifname, cmd->type, arg_path,
&value, CONFIG_TYPE_BOOL))
return cmd_failed;
snprintf(obuf, obuf_len, "enableTx = %s\n", value ? "yes" : "no");
somethingChangedLocal(cmd->ifname, cmd->type);
return cmd_success;
}
static int set_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue,
char *obuf, int obuf_len)
{
return _set_arg_tlvtxenable(cmd, arg, argvalue, obuf, obuf_len, false);
}
static int test_arg_tlvtxenable(struct cmd *cmd, char *arg, char *argvalue,
char *obuf, int obuf_len)
{
return _set_arg_tlvtxenable(cmd, arg, argvalue, obuf, obuf_len, true);
}
static int
get_arg_med_devtype(struct cmd *cmd, char *arg, UNUSED char *argvalue,
char *obuf, int obuf_len)
{
long value;
char *s;
if (cmd->cmd != cmd_gettlv)
return cmd_invalid;
switch (cmd->tlvid) {
case (OUI_TIA_TR41 << 8):
value = get_med_devtype(cmd->ifname, cmd->type);
break;
case (OUI_TIA_TR41 << 8) | LLDP_MED_CAPABILITIES:
case (OUI_TIA_TR41 << 8) | LLDP_MED_NETWORK_POLICY:
case (OUI_TIA_TR41 << 8) | LLDP_MED_LOCATION_ID:
case (OUI_TIA_TR41 << 8) | LLDP_MED_EXTENDED_PVMDI:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_HWREV:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_FWREV:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_SWREV:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_SERIAL:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_MANUFACTURER:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_MODELNAME:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_ASSETID:
return cmd_not_applicable;
case INVALID_TLVID:
return cmd_invalid;
default:
return cmd_not_applicable;
}
switch (value) {
case LLDP_MED_DEVTYPE_NOT_DEFINED:
s = VAL_MED_NOT;
break;
case LLDP_MED_DEVTYPE_ENDPOINT_CLASS_I:
s = VAL_MED_CLASS_I;
break;
case LLDP_MED_DEVTYPE_ENDPOINT_CLASS_II:
s = VAL_MED_CLASS_II;
break;
case LLDP_MED_DEVTYPE_ENDPOINT_CLASS_III:
s = VAL_MED_CLASS_III;
break;
case LLDP_MED_DEVTYPE_NETWORK_CONNECTIVITY:
s = VAL_MED_NETCON;
break;
default:
return cmd_failed;
}
snprintf(obuf, obuf_len, "%02x%s%04x%s", (unsigned int)strlen(arg), arg,
(unsigned int)strlen(s), s);
return cmd_success;
}
static int _set_arg_med_devtype(struct cmd *cmd, char *argvalue,
char *obuf, int obuf_len, bool test)
{
long value;
if (cmd->cmd != cmd_settlv)
return cmd_invalid;
switch (cmd->tlvid) {
case (OUI_TIA_TR41 << 8):
break;
case (OUI_TIA_TR41 << 8) | LLDP_MED_CAPABILITIES:
case (OUI_TIA_TR41 << 8) | LLDP_MED_NETWORK_POLICY:
case (OUI_TIA_TR41 << 8) | LLDP_MED_LOCATION_ID:
case (OUI_TIA_TR41 << 8) | LLDP_MED_EXTENDED_PVMDI:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_HWREV:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_FWREV:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_SWREV:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_SERIAL:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_MANUFACTURER:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_MODELNAME:
case (OUI_TIA_TR41 << 8) | LLDP_MED_INV_ASSETID:
case INVALID_TLVID:
return cmd_invalid;
default:
return cmd_not_applicable;
}
if (!strcasecmp(argvalue, VAL_MED_NOT))
value = LLDP_MED_DEVTYPE_NOT_DEFINED;
else if (!strcasecmp(argvalue, VAL_MED_CLASS_I))
value = LLDP_MED_DEVTYPE_ENDPOINT_CLASS_I;
else if (!strcasecmp(argvalue, VAL_MED_CLASS_II))
value = LLDP_MED_DEVTYPE_ENDPOINT_CLASS_II;
else if (!strcasecmp(argvalue, VAL_MED_CLASS_III))
value = LLDP_MED_DEVTYPE_ENDPOINT_CLASS_III;
else if (!strcasecmp(argvalue, VAL_MED_NETCON))
value = LLDP_MED_DEVTYPE_NETWORK_CONNECTIVITY;
else
return cmd_invalid;
if (test)
return cmd_success;
set_med_devtype(cmd->ifname, cmd->type, value);
/* set up default enabletx values based on class type */
switch (value) {
case LLDP_MED_DEVTYPE_NOT_DEFINED:
tlv_disabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_RESERVED);
tlv_disabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_CAPABILITIES);
tlv_disabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_NETWORK_POLICY);
tlv_disabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_LOCATION_ID);
tlv_disabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_EXTENDED_PVMDI);
tlv_disabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_HWREV);
tlv_disabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_FWREV);
tlv_disabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_SWREV);
tlv_disabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_SERIAL);
tlv_disabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_MANUFACTURER);
tlv_disabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_MODELNAME);
tlv_disabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_ASSETID);
break;
case LLDP_MED_DEVTYPE_ENDPOINT_CLASS_III:
case LLDP_MED_DEVTYPE_ENDPOINT_CLASS_II:
tlv_enabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_NETWORK_POLICY);
/* FALLTHROUGH */
case LLDP_MED_DEVTYPE_ENDPOINT_CLASS_I:
case LLDP_MED_DEVTYPE_NETWORK_CONNECTIVITY:
tlv_enabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_RESERVED);
tlv_enabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_CAPABILITIES);
tlv_enabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_HWREV);
tlv_enabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_FWREV);
tlv_enabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_SWREV);
tlv_enabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_SERIAL);
tlv_enabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_MANUFACTURER);
tlv_enabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_MODELNAME);
tlv_enabletx(cmd->ifname, cmd->type, (OUI_TIA_TR41 << 8) | LLDP_MED_INV_ASSETID);
tlv_enabletx(cmd->ifname, cmd->type, SYSTEM_CAPABILITIES_TLV);
tlv_enabletx(cmd->ifname, cmd->type, (LLDP_MOD_8023 << 8) | LLDP_8023_MACPHY_CONFIG_STATUS);
break;
default:
return cmd_failed;
}
snprintf(obuf, obuf_len, "devtype = %li\n", value);
somethingChangedLocal(cmd->ifname, cmd->type);
return cmd_success;
}
static int
set_arg_med_devtype(struct cmd *cmd, UNUSED char *arg, char *argvalue,
char *obuf, int obuf_len)
{
return _set_arg_med_devtype(cmd, argvalue, obuf, obuf_len, false);
}
static int
test_arg_med_devtype(struct cmd *cmd, UNUSED char *arg, char *argvalue,
char *obuf, int obuf_len)
{
return _set_arg_med_devtype(cmd, argvalue, obuf, obuf_len, true);
}
struct arg_handlers *med_get_arg_handlers()
{
return &arg_handlers[0];
}