lldp-tlv.c revision 4fc6de5df31c81ae35e82ed91d0a2ee515edad41
/*-*- 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 "macro.h"
#include "lldp-tlv.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 herader */
p += sizeof(struct ether_header);
for (l = 0; l <= size; ) {
r = tlv_section_new(§ion);
if (r < 0)
return r;
break;
}
p += 2;
}
return 0;
}
tlv_section *s;
assert_return(m, -EINVAL);
break;
if (!s)
return -1;
m->container = s;
m->container = 0;
return -1;
}
return 0;
}
int lldp_tlv_packet_exit_container(tlv_packet *m) {
assert_return(m, -EINVAL);
m->container = 0;
return 0;
}
int r;
if (r < 0)
goto out2;
if (r < 0)
goto out1;
switch (subtype) {
if (r < 0)
goto out1;
break;
default:
r = -EOPNOTSUPP;
break;
}
out1:
(void) lldp_tlv_packet_exit_container(tlv);
out2:
return r;
}
char *s;
int r;
if (r < 0)
goto out2;
if (r < 0)
goto out1;
switch (subtype) {
if (r < 0)
goto out1;
break;
if (r < 0)
goto out1;
break;
default:
r = -EOPNOTSUPP;
break;
}
out1:
(void) lldp_tlv_packet_exit_container(tlv);
out2:
return r;
}
int r;
if (r < 0)
goto out;
(void) lldp_tlv_packet_exit_container(tlv);
out:
return r;
}
char **data,
char *s;
int r;
if (r < 0)
return r;
if (r < 0)
goto out;
*data = (char *) s;
out:
(void) lldp_tlv_packet_exit_container(tlv);
return r;
}
char **data,
char *s;
int r;
if (r < 0)
return r;
if (r < 0)
goto out;
*data = (char *) s;
out:
(void) lldp_tlv_packet_exit_container(tlv);
return r;
}
char **data,
char *s;
int r;
if (r < 0)
return r;
if (r < 0)
goto out;
*data = (char *) s;
out:
(void) lldp_tlv_packet_exit_container(tlv);
return r;
}
int r;
if (r < 0)
return r;
if (r < 0)
goto out;
return 0;
out:
(void) lldp_tlv_packet_exit_container(tlv);
return r;
}
/* 802.1AB-2009, Table 7-1 */
else
return -EINVAL;
return 0;
}