chiark / gitweb /
028a35ffdd466288e5af1f48046453dbe7817178
[elogind.git] / src / libsystemd-network / lldp-internal.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright (C) 2014 Tom Gundersen
7   Copyright (C) 2014 Susant Sahani
8
9   systemd is free software; you can redistribute it and/or modify it
10   under the terms of the GNU Lesser General Public License as published by
11   the Free Software Foundation; either version 2.1 of the License, or
12   (at your option) any later version.
13
14   systemd is distributed in the hope that it will be useful, but
15   WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   Lesser General Public License for more details.
18
19   You should have received a copy of the GNU Lesser General Public License
20   along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 ***/
22
23 #pragma once
24
25 #include "log.h"
26 #include "list.h"
27 #include "refcnt.h"
28 #include "lldp-tlv.h"
29 #include "prioq.h"
30
31 typedef struct lldp_neighbour_port lldp_neighbour_port;
32 typedef struct lldp_chassis lldp_chassis;
33 typedef struct lldp_chassis_id lldp_chassis_id;
34
35 struct lldp_neighbour_port {
36         uint8_t type;
37         uint8_t *data;
38
39         uint16_t length;
40         usec_t until;
41
42         unsigned prioq_idx;
43
44         lldp_chassis *c;
45         tlv_packet *packet;
46
47         LIST_FIELDS(lldp_neighbour_port, port);
48 };
49
50 int lldp_neighbour_port_new(lldp_chassis *c, tlv_packet *tlv, lldp_neighbour_port **ret);
51 void lldp_neighbour_port_free(lldp_neighbour_port *p);
52 void lldp_neighbour_port_remove_and_free(lldp_neighbour_port *p);
53
54 DEFINE_TRIVIAL_CLEANUP_FUNC(lldp_neighbour_port *, lldp_neighbour_port_free);
55 #define _cleanup_lldp_neighbour_port_free_ _cleanup_(lldp_neighbour_port_freep)
56
57 struct lldp_chassis_id {
58         uint8_t type;
59         uint16_t length;
60
61         uint8_t *data;
62 };
63
64 struct lldp_chassis {
65         RefCount n_ref;
66
67         lldp_chassis_id chassis_id;
68
69         Prioq *by_expiry;
70         Hashmap *neighbour_mib;
71
72         LIST_HEAD(lldp_neighbour_port, ports);
73 };
74
75 int lldp_chassis_new(tlv_packet *tlv,
76                      Prioq *by_expiry,
77                      Hashmap *neighbour_mib,
78                      lldp_chassis **ret);
79
80 void lldp_chassis_free(lldp_chassis *c);
81
82 DEFINE_TRIVIAL_CLEANUP_FUNC(lldp_chassis *, lldp_chassis_free);
83 #define _cleanup_lldp_chassis_free_ _cleanup_(lldp_chassis_freep)
84
85 int lldp_mib_update_objects(lldp_chassis *c, tlv_packet *tlv);
86 int lldp_mib_add_objects(Prioq *by_expiry, Hashmap *neighbour_mib, tlv_packet *tlv);
87 int lldp_mib_remove_objects(lldp_chassis *c, tlv_packet *tlv);
88
89 int lldp_read_chassis_id(tlv_packet *tlv, uint8_t *type, uint16_t *length, uint8_t **data);
90 int lldp_read_port_id(tlv_packet *tlv, uint8_t *type, uint16_t *length, uint8_t **data);
91 int lldp_read_ttl(tlv_packet *tlv, uint16_t *ttl);
92 int lldp_read_system_name(tlv_packet *tlv, uint16_t *length, char **data);
93 int lldp_read_system_description(tlv_packet *tlv, uint16_t *length, char **data);
94 int lldp_read_system_capability(tlv_packet *tlv, uint16_t *data);
95 int lldp_read_port_description(tlv_packet *tlv, uint16_t *length, char **data);
96
97 #define log_lldp(fmt, ...) log_internal(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, "LLDP: " fmt, ##__VA_ARGS__)