lldp-internal.c revision ad1ad5c8e36ea795034fcdac660b15d7c141d55b
/*-*- 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 "lldp-internal.h"
/* We store maximum 1K chassis entries */
#define LLDP_MIB_MAX_CHASSIS 1024
/* Maximum Ports can be attached to any chassis */
#define LLDP_MIB_MAX_PORT_PER_CHASSIS 32
int r;
if (r < 0)
goto out2;
if (r < 0)
goto out1;
switch (subtype) {
if (r < 0)
goto out1;
break;
default:
r = -ENOTSUP;
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 = -ENOTSUP;
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;
}
/* 10.5.5.2.2 mibUpdateObjects ()
* The mibUpdateObjects () procedure updates the MIB objects corresponding to
* the TLVs contained in the received LLDPDU for the LLDP remote system
* indicated by the LLDP remote systems update process defined in 10.3.5 */
int r;
assert_return(c, -EINVAL);
if (r < 0)
return r;
/* Update the packet if we already have */
if (r < 0)
return r;
tlv_packet_free(p->packet);
return 0;
}
}
return -1;
}
lldp_neighbour_port *p, *q;
int r;
assert_return(c, -EINVAL);
if (r < 0)
return r;
/* Find the port */
break;
}
}
return 0;
}
tlv_packet *tlv) {
bool new_chassis = false;
int r;
if (r < 0)
goto drop;
if (r < 0)
goto drop;
/* Make hash key */
/* Try to find the Chassis */
if (!c) {
/* Don't create chassis if ttl 0 is received . Silently drop it */
if (ttl == 0) {
log_lldp("TTL value 0 received. Skiping Chassis creation.");
goto drop;
}
/* Admission Control: Can we store this packet ? */
log_lldp("Exceeding number of chassie: %d. Dropping ...",
goto drop;
}
if (r < 0)
goto drop;
new_chassis = true;
if (r < 0)
goto drop;
} else {
/* When the TTL field is set to zero, the receiving LLDP agent is notified all
if (ttl == 0) {
log_lldp("TTL value 0 received . Deleting associated Port ...");
c = NULL;
goto drop;
}
/* if we already have this port just update it */
r = lldp_mib_update_objects(c, tlv);
if (r >= 0) {
c = NULL;
return r;
}
/* Admission Control: Can this port attached to the existing chassis ? */
log_lldp("Port limit reached. Chassis has: %d ports. Dropping ...",
REFCNT_GET(c->n_ref));
c = NULL;
goto drop;
}
}
/* This is a new port */
r = lldp_neighbour_port_new(c, tlv, &p);
if (r < 0)
goto drop;
if (r < 0)
goto drop;
/* Attach new port to chassis */
REFCNT_INC(c->n_ref);
p = NULL;
c = NULL;
return 0;
drop:
if (new_chassis)
return r;
}
lldp_chassis *c;
assert(p);
assert(p->c);
c = p->c;
/* Drop the Chassis if no port is attached */
}
}
void lldp_neighbour_port_free(lldp_neighbour_port *p) {
if(!p)
return;
tlv_packet_free(p->packet);
free(p);
}
int lldp_neighbour_port_new(lldp_chassis *c,
lldp_neighbour_port **ret) {
int r;
if (r < 0)
return r;
if (r < 0)
return r;
if (!p)
return -ENOMEM;
p->c = c;
p->prioq_idx = PRIOQ_IDX_NULL;
if (!p->data)
return -ENOMEM;
*ret = p;
p = NULL;
return 0;
}
void lldp_chassis_free(lldp_chassis *c) {
if (!c)
return;
return;
free(c);
}
lldp_chassis **ret) {
int r;
if (r < 0)
return r;
if (!c)
return -ENOMEM;
c->n_ref = REFCNT_INIT;
if (!c->chassis_id.data)
return -ENOMEM;
LIST_HEAD_INIT(c->ports);
c->neighbour_mib = neighbour_mib;
*ret = c;
c = NULL;
return 0;
}