]>
Commit | Line | Data |
---|---|---|
ad1ad5c8 SS |
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 <net/ethernet.h> | |
26 | ||
176c355b BG |
27 | #include "sd-lldp.h" |
28 | ||
71d35b6b TA |
29 | #include "list.h" |
30 | #include "lldp.h" | |
31 | #include "util.h" | |
32 | ||
adf88a70 BG |
33 | typedef struct sd_lldp_packet tlv_packet; |
34 | typedef struct sd_lldp_section tlv_section; | |
ad1ad5c8 | 35 | |
d8c89d61 BG |
36 | #define LLDP_OUI_LEN 3 |
37 | ||
adf88a70 | 38 | struct sd_lldp_section { |
ad1ad5c8 SS |
39 | uint16_t type; |
40 | uint16_t length; | |
d8c89d61 BG |
41 | uint8_t *oui; |
42 | uint8_t subtype; | |
ad1ad5c8 SS |
43 | |
44 | uint8_t *read_pos; | |
45 | uint8_t *data; | |
46 | ||
47 | LIST_FIELDS(tlv_section, section); | |
48 | }; | |
49 | ||
4fc6de5d BG |
50 | #define LLDP_MAC_NEAREST_BRIDGE (uint8_t[]) { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e } |
51 | #define LLDP_MAC_NEAREST_NON_TPMR_BRIDGE (uint8_t[]) { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 } | |
52 | #define LLDP_MAC_NEAREST_CUSTOMER_BRIDGE (uint8_t[]) { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 } | |
53 | ||
ad1ad5c8 SS |
54 | int tlv_section_new(tlv_section **ret); |
55 | void tlv_section_free(tlv_section *ret); | |
56 | ||
adf88a70 | 57 | struct sd_lldp_packet { |
2212d76d BG |
58 | unsigned n_ref; |
59 | ||
ad1ad5c8 SS |
60 | uint16_t type; |
61 | uint16_t length; | |
62 | usec_t ts; | |
63 | ||
64 | uint8_t *container_pos; | |
65 | uint8_t pdu[ETHER_MAX_LEN]; | |
66 | ||
67 | void *userdata; | |
68 | ||
69 | struct ether_addr mac; | |
70 | tlv_section *container; | |
71 | ||
72 | LIST_HEAD(tlv_section, sections); | |
73 | }; | |
74 | ||
75 | int tlv_packet_new(tlv_packet **ret); | |
ad1ad5c8 | 76 | |
176c355b BG |
77 | DEFINE_TRIVIAL_CLEANUP_FUNC(sd_lldp_packet*, sd_lldp_packet_unref); |
78 | #define _cleanup_lldp_packet_unref_ _cleanup_(sd_lldp_packet_unrefp) | |
ad1ad5c8 SS |
79 | |
80 | int lldp_tlv_packet_open_container(tlv_packet *m, uint16_t type); | |
81 | int lldp_tlv_packet_close_container(tlv_packet *m); | |
82 | ||
83 | int tlv_packet_append_bytes(tlv_packet *m, const void *data, size_t data_length); | |
84 | int tlv_packet_append_u8(tlv_packet *m, uint8_t data); | |
85 | int tlv_packet_append_u16(tlv_packet *m, uint16_t data); | |
86 | int tlv_packet_append_u32(tlv_packet *m, uint32_t data); | |
87 | int tlv_packet_append_string(tlv_packet *m, char *data, uint16_t size); | |
88 | ||
89 | int lldp_tlv_packet_enter_container(tlv_packet *m, uint16_t type); | |
d8c89d61 | 90 | int lldp_tlv_packet_enter_container_oui(tlv_packet *m, const uint8_t *oui, uint8_t subtype); |
ad1ad5c8 SS |
91 | int lldp_tlv_packet_exit_container(tlv_packet *m); |
92 | ||
93 | int tlv_packet_read_bytes(tlv_packet *m, uint8_t **data, uint16_t *data_length); | |
94 | int tlv_packet_read_string(tlv_packet *m, char **data, uint16_t *data_length); | |
95 | int tlv_packet_read_u8(tlv_packet *m, uint8_t *data); | |
96 | int tlv_packet_read_u16(tlv_packet *m, uint16_t *data); | |
97 | int tlv_packet_read_u32(tlv_packet *m, uint32_t *data); | |
98 | ||
99 | int tlv_packet_parse_pdu(tlv_packet *t, uint16_t size); |