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