-
Notifications
You must be signed in to change notification settings - Fork 8
/
lldp_cisco_clif.c
146 lines (119 loc) · 3.59 KB
/
lldp_cisco_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
/*******************************************************************************
Implementation of Cisco Specific TLVs for LLDP
(c) Copyright SuSE Linux Products GmbH, 2011
Author(s): Hannes Reinecke <hare at suse dot de>
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".
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <sys/un.h>
#include <sys/stat.h>
#include "lldp_mod.h"
#include "clif_msgs.h"
#include "lldp.h"
#include "lldp_cisco_clif.h"
static void cisco_print_upoe_tlv(u16 len, char *info);
static int cisco_print_help();
static u32 cisco_lookup_tlv_name(char *tlvid_str);
static const struct lldp_mod_ops cisco_ops_clif = {
.lldp_mod_register = cisco_cli_register,
.lldp_mod_unregister = cisco_cli_unregister,
.print_tlv = cisco_print_tlv,
.lookup_tlv_name = cisco_lookup_tlv_name,
.print_help = cisco_print_help,
};
struct type_name_info cisco_tlv_names[] = {
{ .type = (OUI_CISCO << 8) | 1,
.name = "Cisco 4-wire Power-via-MDI TLV", .key = "uPoE",
.print_info = cisco_print_upoe_tlv },
{ .type = INVALID_TLVID, }
};
static int cisco_print_help()
{
struct type_name_info *tn = &cisco_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 *cisco_cli_register(void)
{
struct lldp_module *mod;
mod = malloc(sizeof(*mod));
if (!mod) {
fprintf(stderr, "failed to malloc module data\n");
return NULL;
}
mod->id = OUI_IEEE_8021;
mod->ops = &cisco_ops_clif;
return mod;
}
void cisco_cli_unregister(struct lldp_module *mod)
{
free(mod);
}
static void cisco_print_upoe_tlv(u16 len, char *info)
{
u8 cap;
if (len != 1) {
printf("Bad uPoE TLV: %s\n", info);
return;
}
if (!hexstr2bin(info, (u8 *)&cap, sizeof(cap))) {
printf("4-Pair PoE %ssupported\n",
cap & 0x01 ? "" : "not ");
printf("\tSpare pair Detection/Classification %srequired\n",
cap & 0x02 ? "" : "not ");
printf("\tPD Spare pair Desired State: %s\n",
cap & 0x04 ? "Enabled" : "Disabled");
printf("\tPSE Spare pair Operational State: %s\n",
cap & 0x08 ? "Enabled" : "Disabled");
}
}
/* return 1: if it printed the TLV
* 0: if it did not
*/
int cisco_print_tlv(u32 tlvid, u16 len, char *info)
{
struct type_name_info *tn = &cisco_tlv_names[0];
while (tn->type != INVALID_TLVID) {
if (tlvid == tn->type) {
printf("%s\n", tn->name);
if (tn->print_info) {
printf("\t");
tn->print_info(len-4, info);
}
return 1;
}
tn++;
}
return 0;
}
static u32 cisco_lookup_tlv_name(char *tlvid_str)
{
struct type_name_info *tn = &cisco_tlv_names[0];
while (tn->type != INVALID_TLVID) {
if (!strcasecmp(tn->key, tlvid_str))
return tn->type;
tn++;
}
return INVALID_TLVID;
}