]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-link.h
resolve: expose dns_server_address_valid()
[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"
910feb78 20#include "networkd-util.h"
634f0f98 21#include "set.h"
0b1831c2
TG
22
23typedef enum LinkState {
bd08ce56
YW
24 LINK_STATE_PENDING, /* udev has not initialized the link */
25 LINK_STATE_INITIALIZED, /* udev has initialized the link */
26 LINK_STATE_CONFIGURING, /* configuring addresses, routes, etc. */
27 LINK_STATE_CONFIGURED, /* everything is configured */
28 LINK_STATE_UNMANAGED, /* Unmanaged=yes is set */
29 LINK_STATE_FAILED, /* at least one configuration process failed */
30 LINK_STATE_LINGER, /* RTM_DELLINK for the link has been received */
0b1831c2
TG
31 _LINK_STATE_MAX,
32 _LINK_STATE_INVALID = -1
33} LinkState;
34
634f0f98
ZJS
35typedef struct Manager Manager;
36typedef struct Network Network;
37typedef struct Address Address;
f24648a6 38typedef struct DUID DUID;
fc2f9534 39
634f0f98 40typedef struct Link {
0b1831c2
TG
41 Manager *manager;
42
cf4b2f99 43 unsigned n_ref;
0b1831c2
TG
44
45 int ifindex;
cbff7170 46 int master_ifindex;
0b1831c2 47 char *ifname;
6cad256d 48 char *kind;
b710e6b6 49 unsigned short iftype;
0b1831c2
TG
50 char *state_file;
51 struct ether_addr mac;
c601ebf7 52 struct in6_addr ipv6ll_address;
0b1831c2 53 uint32_t mtu;
51517f9e 54 sd_device *sd_device;
0b1831c2
TG
55
56 unsigned flags;
57 uint8_t kernel_operstate;
58
59 Network *network;
60
61 LinkState state;
62 LinkOperationalState operstate;
1678fbb3
YW
63 LinkCarrierState carrier_state;
64 LinkAddressState address_state;
0b1831c2 65
7715629e
ST
66 unsigned address_messages;
67 unsigned address_label_messages;
e4a71bf3 68 unsigned neighbor_messages;
7715629e
ST
69 unsigned route_messages;
70 unsigned routing_policy_rule_messages;
71 unsigned routing_policy_rule_remove_messages;
0b1831c2
TG
72 unsigned enslaving;
73
cf1d700d 74 Set *addresses;
adda1ed9 75 Set *addresses_foreign;
1c8e710c
TG
76 Set *routes;
77 Set *routes_foreign;
0b1831c2 78
c42ff3a1 79 bool addresses_configured;
6aa5773b 80 bool addresses_ready;
c42ff3a1 81
0b1831c2 82 sd_dhcp_client *dhcp_client;
d03073dd 83 sd_dhcp_lease *dhcp_lease, *dhcp_lease_old;
0b1831c2 84 char *lease_file;
4e964aa0 85 uint32_t original_mtu;
3c9b8860
TG
86 unsigned dhcp4_messages;
87 bool dhcp4_configured;
18d29550 88 bool dhcp6_configured;
1e7a0e21 89
3b015d40
TG
90 unsigned ndisc_messages;
91 bool ndisc_configured;
b22d8a00 92
0b1831c2 93 sd_ipv4ll *ipv4ll;
e7ab854c
TG
94 bool ipv4ll_address:1;
95 bool ipv4ll_route:1;
0b1831c2 96
e4a71bf3
WKI
97 bool neighbors_configured;
98
7715629e
ST
99 bool static_routes_configured;
100 bool routing_policy_rules_configured;
97e7fb39 101 bool setting_mtu;
3c9b8860 102
0b1831c2
TG
103 LIST_HEAD(Address, pool_addresses);
104
105 sd_dhcp_server *dhcp_server;
106
1e7a0e21
LP
107 sd_ndisc *ndisc;
108 Set *ndisc_rdnss;
109 Set *ndisc_dnssl;
110
091214b6
PF
111 sd_radv *radv;
112
0b1831c2 113 sd_dhcp6_client *dhcp6_client;
be3a09b7 114 bool rtnl_extended_attrs;
ce43e484 115
8e1ad1ea 116 /* This is about LLDP reception */
ce43e484 117 sd_lldp *lldp;
49699bac 118 char *lldp_file;
0d4ad91d 119
8e1ad1ea
LP
120 /* This is about LLDP transmission */
121 unsigned lldp_tx_fast; /* The LLDP txFast counter (See 802.1ab-2009, section 9.2.5.18) */
7272b25e 122 sd_event_source *lldp_emit_event_source;
8e1ad1ea 123
0d4ad91d
AR
124 Hashmap *bound_by_links;
125 Hashmap *bound_to_links;
5f707e12 126 Set *slaves;
a879e1a4
YW
127
128 /* For speed meter */
129 struct rtnl_link_stats64 stats_old, stats_new;
130 bool stats_updated;
bafa9641
YW
131
132 int sysctl_ipv6_enabled;
634f0f98 133} Link;
0b1831c2 134
302a796f
YW
135typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
136
f24648a6 137DUID *link_get_duid(Link *link);
27dfc982 138int get_product_uuid_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
f24648a6 139
0b1831c2
TG
140Link *link_unref(Link *link);
141Link *link_ref(Link *link);
2c448c8a 142DEFINE_TRIVIAL_CLEANUP_FUNC(Link*, link_unref);
302a796f 143DEFINE_TRIVIAL_DESTRUCTOR(link_netlink_destroy_callback, Link, link_unref);
1046bf9b 144
0b1831c2 145int link_get(Manager *m, int ifindex, Link **ret);
1c4baffc 146int link_add(Manager *manager, sd_netlink_message *message, Link **ret);
0b1831c2
TG
147void link_drop(Link *link);
148
8e54db83 149int link_down(Link *link, link_netlink_message_handler_t callback);
14b6bb77 150
b22d8a00 151void link_enter_failed(Link *link);
51517f9e 152int link_initialized(Link *link, sd_device *device);
0b1831c2 153
af9ba57a 154void link_set_state(Link *link, LinkState state);
8012cd39 155void link_check_ready(Link *link);
b22d8a00 156
959f65d3 157void link_update_operstate(Link *link, bool also_update_bond_master);
1c4baffc 158int link_update(Link *link, sd_netlink_message *message);
b22d8a00 159
84de38c5
TG
160void link_dirty(Link *link);
161void link_clean(Link *link);
0b1831c2
TG
162int link_save(Link *link);
163
9c0a72f9 164int link_carrier_reset(Link *link);
a61bb41c 165bool link_has_carrier(Link *link);
0b1831c2 166
c601ebf7 167int link_ipv6ll_gained(Link *link, const struct in6_addr *address);
e7ab854c 168
933c70a0 169int link_set_mtu(Link *link, uint32_t mtu);
3c9b8860 170
910feb78 171bool link_ipv4ll_enabled(Link *link, AddressFamilyBoolean mask);
8bc17bb3 172
95355a28 173int link_stop_clients(Link *link, bool may_keep_dhcp);
946f8e14 174
0b1831c2
TG
175const char* link_state_to_string(LinkState s) _const_;
176LinkState link_state_from_string(const char *s) _pure_;
177
bdb9f580
YW
178uint32_t link_get_vrf_table(Link *link);
179uint32_t link_get_dhcp_route_table(Link *link);
180uint32_t link_get_ipv6_accept_ra_route_table(Link *link);
b5799eeb 181int link_request_set_routes(Link *link);
bdb9f580 182
bafa9641
YW
183int link_sysctl_ipv6_enabled(Link *link);
184
80431934
PM
185#define ADDRESS_FMT_VAL(address) \
186 be32toh((address).s_addr) >> 24, \
187 (be32toh((address).s_addr) >> 16) & 0xFFu, \
188 (be32toh((address).s_addr) >> 8) & 0xFFu, \
189 be32toh((address).s_addr) & 0xFFu