lldp-tlv.c revision 9ac8e913246d603c612b6083beac5a5ef7e307b2
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright (C) 2014 Tom Gundersen
Copyright (C) 2014 Susant Sahani
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <net/ethernet.h>
#include "alloc-util.h"
#include "lldp-tlv.h"
#include "macro.h"
tlv_section *s;
if (!s)
return -ENOMEM;
*ret = s;
return 0;
}
void tlv_section_free(tlv_section *m) {
if (!m)
return;
free(m);
}
tlv_packet *m;
if (!m)
return -ENOMEM;
LIST_HEAD_INIT(m->sections);
m->n_ref = 1;
*ret = m;
return 0;
}
if (!m)
return NULL;
m->n_ref++;
return m;
}
tlv_section *s, *n;
if (!m)
return NULL;
m->n_ref--;
if (m->n_ref > 0)
return m;
tlv_section_free(s);
free(m);
return NULL;
}
uint8_t *p;
assert_return(m, -EINVAL);
return -ENOMEM;
m->length += data_length;
return 0;
}
assert_return(m, -EINVAL);
}
assert_return(m, -EINVAL);
}
assert_return(m, -EINVAL);
}
assert_return(m, -EINVAL);
}
assert_return(m, -EINVAL);
}
int lldp_tlv_packet_close_container(tlv_packet *m) {
assert_return(m, -EINVAL);
return 0;
}
return 0;
}
int r;
assert_return(m, -EINVAL);
if (r < 0)
return r;
return 0;
}
uint16_t t;
int r;
assert_return(m, -EINVAL);
if (r < 0)
return r;
return 0;
}
uint32_t t;
void *val;
int r;
assert_return(m, -EINVAL);
if (r < 0)
return r;
return r;
}
int r;
assert_return(m, -EINVAL);
if (r < 0)
return r;
return 0;
}
int r;
assert_return(m, -EINVAL);
if (r < 0)
return r;
return 0;
}
/* parse raw TLV packet */
uint16_t t, l;
uint8_t *p;
int r;
assert_return(m, -EINVAL);
p = m->pdu;
/* extract ethernet header */
p += sizeof(struct ether_header);
for (l = 0; l <= size; ) {
r = tlv_section_new(§ion);
if (r < 0)
return r;
break;
}
p += 2;
p += LLDP_OUI_LEN;
l += LLDP_OUI_LEN + 1;
}
}
return 0;
}
tlv_section *s;
assert_return(m, -EINVAL);
break;
if (!s)
return -1;
m->container = s;
return -1;
}
return 0;
}
tlv_section *s;
assert_return(m, -EINVAL);
if (s->type == LLDP_TYPE_PRIVATE &&
s->oui &&
break;
}
if (!s)
return -1;
m->container = s;
return -1;
}
return 0;
}
int lldp_tlv_packet_exit_container(tlv_packet *m) {
assert_return(m, -EINVAL);
m->container = 0;
return 0;
}
int r, r2;
if (r < 0)
return r;
return r < 0 ? r : r2;
}
static int lldp_tlv_packet_read_string_tlv(tlv_packet *tlv, uint16_t type, char **data, uint16_t *length) {
char *s;
int r, r2;
if (r < 0)
return r;
if (r < 0)
goto out;
*data = (char *) s;
out:
return r < 0 ? r : r2;
}
int r, r2;
if (r < 0)
return r;
if (r < 0)
goto out;
switch (subtype) {
if (r < 0)
goto out;
break;
default:
r = -EOPNOTSUPP;
break;
}
out:
return r < 0 ? r : r2;
}
char *s;
int r, r2;
if (r < 0)
return r;
if (r < 0)
goto out;
switch (subtype) {
if (r < 0)
goto out;
break;
if (r < 0)
goto out;
break;
default:
r = -EOPNOTSUPP;
break;
}
out:
return r < 0 ? r : r2;
}
}
char **data,
}
char **data,
}
char **data,
}
}
int r, r2;
if (r < 0)
return r;
return r < 0 ? r : r2;
}
int r, r2;
r = lldp_tlv_packet_enter_container_oui(tlv, LLDP_OUI_802_1, LLDP_OUI_SUBTYPE_802_1_PORT_PROTOCOL_VLAN_ID);
if (r < 0)
return r;
if (r >= 0)
return r < 0 ? r : r2;
}
int sd_lldp_packet_read_vlan_name(tlv_packet *tlv, uint16_t *vlan_id, char **name, uint16_t *length) {
int r, r2;
if (r < 0)
return r;
if (r >= 0)
if (r >= 0)
return r < 0 ? r : r2;
}
int r, r2;
r = lldp_tlv_packet_enter_container_oui(tlv, LLDP_OUI_802_1, LLDP_OUI_SUBTYPE_802_1_MANAGEMENT_VID);
if (r < 0)
return r;
return r < 0 ? r : r2;
}
int r, r2;
r = lldp_tlv_packet_enter_container_oui(tlv, LLDP_OUI_802_1, LLDP_OUI_SUBTYPE_802_1_LINK_AGGREGATION);
if (r < 0)
return r;
if (r >= 0)
return r < 0 ? r : r2;
}
/* 802.1AB-2009, Table 7-1 */
else
return -EINVAL;
return 0;
}