ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani/***
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani This file is part of systemd.
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani Copyright (C) 2014 Tom Gundersen
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani Copyright (C) 2014 Susant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani systemd is free software; you can redistribute it and/or modify it
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani under the terms of the GNU Lesser General Public License as published by
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani the Free Software Foundation; either version 2.1 of the License, or
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani (at your option) any later version.
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani systemd is distributed in the hope that it will be useful, but
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani WITHOUT ANY WARRANTY; without even the implied warranty of
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani Lesser General Public License for more details.
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani You should have received a copy of the GNU Lesser General Public License
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani along with systemd; If not, see <http://www.gnu.org/licenses/>.
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani***/
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani#pragma once
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "sd-event.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani#include "list.h"
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani#include "lldp-tlv.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "log.h"
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani#include "prioq.h"
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanitypedef struct lldp_neighbour_port lldp_neighbour_port;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanitypedef struct lldp_chassis lldp_chassis;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanitypedef struct lldp_chassis_id lldp_chassis_id;
6b3fd9a14d378a35d95ec4be65065708d092bee2Torstein Husebøtypedef struct lldp_agent_statistics lldp_agent_statistics;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistruct lldp_neighbour_port {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani uint8_t type;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani uint8_t *data;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani uint16_t length;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani usec_t until;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani unsigned prioq_idx;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani lldp_chassis *c;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani tlv_packet *packet;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani LIST_FIELDS(lldp_neighbour_port, port);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani};
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahaniint lldp_neighbour_port_new(lldp_chassis *c, tlv_packet *tlv, lldp_neighbour_port **ret);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanivoid lldp_neighbour_port_free(lldp_neighbour_port *p);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanivoid lldp_neighbour_port_remove_and_free(lldp_neighbour_port *p);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant SahaniDEFINE_TRIVIAL_CLEANUP_FUNC(lldp_neighbour_port *, lldp_neighbour_port_free);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani#define _cleanup_lldp_neighbour_port_free_ _cleanup_(lldp_neighbour_port_freep)
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistruct lldp_chassis_id {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani uint8_t type;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani uint16_t length;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani uint8_t *data;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani};
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanistruct lldp_chassis {
9c8e3101ceef00342263d57dce3fa61956824985Lennart Poettering unsigned n_ref;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani lldp_chassis_id chassis_id;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani Prioq *by_expiry;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani Hashmap *neighbour_mib;
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani LIST_HEAD(lldp_neighbour_port, ports);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani};
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahaniint lldp_chassis_new(tlv_packet *tlv,
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani Prioq *by_expiry,
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani Hashmap *neighbour_mib,
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani lldp_chassis **ret);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahanivoid lldp_chassis_free(lldp_chassis *c);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant SahaniDEFINE_TRIVIAL_CLEANUP_FUNC(lldp_chassis *, lldp_chassis_free);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani#define _cleanup_lldp_chassis_free_ _cleanup_(lldp_chassis_freep)
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahaniint lldp_mib_update_objects(lldp_chassis *c, tlv_packet *tlv);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahaniint lldp_mib_add_objects(Prioq *by_expiry, Hashmap *neighbour_mib, tlv_packet *tlv);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahaniint lldp_mib_remove_objects(lldp_chassis *c, tlv_packet *tlv);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
7a6f1457462840ed52f2a332e2bd56ca210cff2dTom Gundersenint lldp_handle_packet(tlv_packet *m, uint16_t length);
0037c2dc54ca5bc5a3ec428619ff136066467565Beniamino Galvaniint lldp_receive_packet(sd_event_source *s, int fd, uint32_t revents, void *userdata);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani#define log_lldp(fmt, ...) log_internal(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, "LLDP: " fmt, ##__VA_ARGS__)