lldp-internal.h revision 7a6f1457462840ed52f2a332e2bd56ca210cff2d
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
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
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani#include "log.h"
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani#include "list.h"
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani#include "refcnt.h"
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani#include "lldp-tlv.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;
7a6f1457462840ed52f2a332e2bd56ca210cff2dTom Gundersentypedef struct lldp_agent_statitics lldp_agent_statitics;
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 {
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani RefCount 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
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahaniint lldp_read_chassis_id(tlv_packet *tlv, uint8_t *type, uint16_t *length, uint8_t **data);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahaniint lldp_read_port_id(tlv_packet *tlv, uint8_t *type, uint16_t *length, uint8_t **data);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahaniint lldp_read_ttl(tlv_packet *tlv, uint16_t *ttl);
49699bac94d24b444274f91f85c82e6fad04d029Susant Sahaniint lldp_read_system_name(tlv_packet *tlv, uint16_t *length, char **data);
49699bac94d24b444274f91f85c82e6fad04d029Susant Sahaniint lldp_read_system_description(tlv_packet *tlv, uint16_t *length, char **data);
49699bac94d24b444274f91f85c82e6fad04d029Susant Sahaniint lldp_read_system_capability(tlv_packet *tlv, uint16_t *data);
49699bac94d24b444274f91f85c82e6fad04d029Susant Sahaniint lldp_read_port_description(tlv_packet *tlv, uint16_t *length, char **data);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani
7a6f1457462840ed52f2a332e2bd56ca210cff2dTom Gundersenint lldp_handle_packet(tlv_packet *m, uint16_t length);
ad1ad5c8e36ea795034fcdac660b15d7c141d55bSusant Sahani#define log_lldp(fmt, ...) log_internal(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, "LLDP: " fmt, ##__VA_ARGS__)