]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-link.h
network: fix memleak and double free
[thirdparty/systemd.git] / src / network / networkd-link.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
fc2f9534
LP
2#pragma once
3
80431934
PM
4#include <endian.h>
5
634f0f98 6#include "sd-bus.h"
51517f9e 7#include "sd-device.h"
fc2f9534
LP
8#include "sd-dhcp-client.h"
9#include "sd-dhcp-server.h"
fc2f9534 10#include "sd-dhcp6-client.h"
07630cea 11#include "sd-ipv4ll.h"
fc2f9534 12#include "sd-lldp.h"
07630cea 13#include "sd-ndisc.h"
9d5d0090 14#include "sd-radv.h"
634f0f98 15#include "sd-netlink.h"
fc2f9534 16
634f0f98 17#include "list.h"
e67ae9f5 18#include "log-link.h"
2cd6b932 19#include "network-util.h"
634f0f98 20#include "set.h"
0b1831c2
TG
21
22typedef enum LinkState {
bd08ce56
YW
23 LINK_STATE_PENDING, /* udev has not initialized the link */
24 LINK_STATE_INITIALIZED, /* udev has initialized the link */
25 LINK_STATE_CONFIGURING, /* configuring addresses, routes, etc. */
26 LINK_STATE_CONFIGURED, /* everything is configured */
27 LINK_STATE_UNMANAGED, /* Unmanaged=yes is set */
28 LINK_STATE_FAILED, /* at least one configuration process failed */
29 LINK_STATE_LINGER, /* RTM_DELLINK for the link has been received */
0b1831c2
TG
30 _LINK_STATE_MAX,
31 _LINK_STATE_INVALID = -1
32} LinkState;
33
634f0f98
ZJS
34typedef struct Manager Manager;
35typedef struct Network Network;
36typedef struct Address Address;
f24648a6 37typedef struct DUID DUID;
fc2f9534 38
634f0f98 39typedef struct Link {
0b1831c2
TG
40 Manager *manager;
41
cf4b2f99 42 unsigned n_ref;
0b1831c2
TG
43
44 int ifindex;
cbff7170 45 int master_ifindex;
0b1831c2 46 char *ifname;
6cad256d 47 char *kind;
b710e6b6 48 unsigned short iftype;
0b1831c2
TG
49 char *state_file;
50 struct ether_addr mac;
c601ebf7 51 struct in6_addr ipv6ll_address;
0b1831c2 52 uint32_t mtu;
51517f9e 53 sd_device *sd_device;
0b1831c2
TG
54
55 unsigned flags;
56 uint8_t kernel_operstate;
57
58 Network *network;
59
60 LinkState state;
61 LinkOperationalState operstate;
62
7715629e
ST
63 unsigned address_messages;
64 unsigned address_label_messages;
e4a71bf3 65 unsigned neighbor_messages;
7715629e
ST
66 unsigned route_messages;
67 unsigned routing_policy_rule_messages;
68 unsigned routing_policy_rule_remove_messages;
0b1831c2 69 unsigned enslaving;
34bf3c00
YW
70 /* link_is_enslaved() has additional checks. So, it is named _raw. */
71 bool enslaved_raw;
0b1831c2 72
cf1d700d 73 Set *addresses;
adda1ed9 74 Set *addresses_foreign;
1c8e710c
TG
75 Set *routes;
76 Set *routes_foreign;
0b1831c2 77
c42ff3a1 78 bool addresses_configured;
6aa5773b 79 bool addresses_ready;
c42ff3a1 80
0b1831c2
TG
81 sd_dhcp_client *dhcp_client;
82 sd_dhcp_lease *dhcp_lease;
83 char *lease_file;
4e964aa0 84 uint32_t original_mtu;
3c9b8860
TG
85 unsigned dhcp4_messages;
86 bool dhcp4_configured;
18d29550 87 bool dhcp6_configured;
1e7a0e21 88
3b015d40
TG
89 unsigned ndisc_messages;
90 bool ndisc_configured;
b22d8a00 91
0b1831c2 92 sd_ipv4ll *ipv4ll;
e7ab854c
TG
93 bool ipv4ll_address:1;
94 bool ipv4ll_route:1;
0b1831c2 95
e4a71bf3
WKI
96 bool neighbors_configured;
97
7715629e
ST
98 bool static_routes_configured;
99 bool routing_policy_rules_configured;
97e7fb39 100 bool setting_mtu;
3c9b8860 101
0b1831c2
TG
102 LIST_HEAD(Address, pool_addresses);
103
104 sd_dhcp_server *dhcp_server;
105
1e7a0e21
LP
106 sd_ndisc *ndisc;
107 Set *ndisc_rdnss;
108 Set *ndisc_dnssl;
109
091214b6
PF
110 sd_radv *radv;
111
0b1831c2 112 sd_dhcp6_client *dhcp6_client;
be3a09b7 113 bool rtnl_extended_attrs;
ce43e484 114
8e1ad1ea 115 /* This is about LLDP reception */
ce43e484 116 sd_lldp *lldp;
49699bac 117 char *lldp_file;
0d4ad91d 118
8e1ad1ea
LP
119 /* This is about LLDP transmission */
120 unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
7272b25e 121 sd_event_source *lldp_emit_event_source;
8e1ad1ea 122
0d4ad91d
AR
123 Hashmap *bound_by_links;
124 Hashmap *bound_to_links;
5f707e12 125 Set *slaves;
634f0f98 126} Link;
0b1831c2 127
302a796f
YW
128typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
129
f24648a6 130DUID *link_get_duid(Link *link);
27dfc982 131int get_product_uuid_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
f24648a6 132
0b1831c2
TG
133Link *link_unref(Link *link);
134Link *link_ref(Link *link);
302a796f 135DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref);
1046bf9b 136
0b1831c2 137int link_get(Manager *m, int ifindex, Link **ret);
1c4baffc 138int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
0b1831c2
TG
139void link_drop(Link *link);
140
14b6bb77
RW
141int link_down(Link *link);
142
b22d8a00 143void link_enter_failed(Link *link);
51517f9e 144int link_initialized(Link *link, sd_device *device);
0b1831c2 145
8012cd39 146void link_check_ready(Link *link);
b22d8a00 147
959f65d3 148void link_update_operstate(Link *link, bool also_update_bond_master);
1c4baffc 149int link_update(Link *link, sd_netlink_message *message);
b22d8a00 150
84de38c5
TG
151void link_dirty(Link *link);
152void link_clean(Link *link);
0b1831c2
TG
153int link_save(Link *link);
154
9c0a72f9 155int link_carrier_reset(Link *link);
a61bb41c 156bool link_has_carrier(Link *link);
0b1831c2 157
c601ebf7 158int link_ipv6ll_gained(Link *link, const struct in6_addr *address);
e7ab854c 159
40288ece 160int link_set_mtu(Link *link, uint32_t mtu, bool force);
3c9b8860 161
b22d8a00 162int ipv4ll_configure(Link *link);
8bc17bb3
SS
163bool link_ipv4ll_enabled(Link *link);
164bool link_ipv4ll_fallback_enabled(Link *link);
165
3c9b8860 166int dhcp4_configure(Link *link);
fff1f40c 167int dhcp4_set_client_identifier(Link *link);
64b21ece 168int dhcp4_set_promote_secondaries(Link *link);
10752343 169int dhcp6_request_prefix_delegation(Link *link);
7a695d8e 170int dhcp6_configure(Link *link);
720bec40 171int dhcp6_request_address(Link *link, int ir);
65dd5e31 172int dhcp6_lease_pd_prefix_lost(sd_dhcp6_client *client, Link* link);
b22d8a00 173
946f8e14
SS
174int link_stop_clients(Link *link);
175
0b1831c2
TG
176const char* link_state_to_string(LinkState s) _const_;
177LinkState link_state_from_string(const char *s) _pure_;
178
e331e246
TG
179extern const sd_bus_vtable link_vtable[];
180
181int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
182int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
183int link_send_changed(Link *link, const char *property, ...) _sentinel_;
0b1831c2 184
bdb9f580
YW
185uint32_t link_get_vrf_table(Link *link);
186uint32_t link_get_dhcp_route_table(Link *link);
187uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
b5799eeb 188int link_request_set_routes(Link *link);
bdb9f580 189
80431934
PM
190#define ADDRESS_FMT_VAL(address) \
191 be32toh((address).s_addr) >> 24, \
192 (be32toh((address).s_addr) >> 16) & 0xFFu, \
193 (be32toh((address).s_addr) >> 8) & 0xFFu, \
194 be32toh((address).s_addr) & 0xFFu