]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-route.h
51a06dd0f14c0e7e9ee7c78fa5e21f3a5e7ed5ab
[thirdparty/systemd.git] / src / network / networkd-route.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <inttypes.h>
5 #include <stdbool.h>
6
7 #include "sd-netlink.h"
8
9 #include "conf-parser.h"
10 #include "in-addr-util.h"
11 #include "networkd-link.h"
12 #include "networkd-route-metric.h"
13 #include "networkd-route-nexthop.h"
14 #include "networkd-util.h"
15
16 typedef struct Manager Manager;
17 typedef struct Network Network;
18 typedef struct Request Request;
19 typedef struct Route Route;
20 typedef struct Wireguard Wireguard;
21
22 typedef int (*route_netlink_handler_t)(
23 sd_netlink *rtnl,
24 sd_netlink_message *m,
25 Request *req,
26 Link *link,
27 Route *route);
28
29 struct Route {
30 Manager *manager;
31 Network *network;
32 Wireguard *wireguard;
33 ConfigSection *section;
34 NetworkConfigSource source;
35 NetworkConfigState state;
36 union in_addr_union provider; /* DHCP server or router address */
37
38 /* rtmsg header */
39 int family;
40 unsigned char dst_prefixlen;
41 unsigned char src_prefixlen; /* IPv6 only */
42 unsigned char tos; /* IPv4 only */
43 unsigned char protocol; /* RTPROT_* */
44 unsigned char scope; /* IPv4 only */
45 unsigned char type; /* RTN_*, e.g. RTN_LOCAL, RTN_UNREACHABLE */
46 unsigned flags; /* e.g. RTNH_F_ONLINK */
47
48 /* attributes */
49 union in_addr_union dst; /* RTA_DST */
50 union in_addr_union src; /* RTA_SRC (IPv6 only) */
51 uint32_t priority; /* RTA_PRIORITY, note that ip(8) calls this 'metric' */
52 union in_addr_union prefsrc; /* RTA_PREFSRC */
53 uint32_t table; /* RTA_TABLE, also used in rtmsg header */
54 uint8_t pref; /* RTA_PREF (IPv6 only) */
55
56 /* nexthops */
57 RouteNextHop nexthop; /* RTA_OIF, and RTA_GATEWAY or RTA_VIA (IPv4 only) */
58 OrderedSet *nexthops; /* RTA_MULTIPATH */
59 uint32_t nexthop_id; /* RTA_NH_ID */
60
61 /* metrics (RTA_METRICS) */
62 RouteMetric metric;
63
64 /* This is an absolute point in time, and NOT a timespan/duration.
65 * Must be specified with clock_boottime_or_monotonic(). */
66 usec_t lifetime_usec; /* RTA_EXPIRES (IPv6 only) */
67 /* Used when kernel does not support RTA_EXPIRES attribute. */
68 sd_event_source *expire;
69 bool expiration_managed_by_kernel:1; /* RTA_CACHEINFO has nonzero rta_expires */
70
71 /* Only used by conf persers and route_section_verify(). */
72 bool scope_set:1;
73 bool table_set:1;
74 bool priority_set:1;
75 bool protocol_set:1;
76 bool pref_set:1;
77 bool gateway_from_dhcp_or_ra:1;
78 int gateway_onlink;
79 };
80
81 extern const struct hash_ops route_hash_ops;
82
83 Route* route_free(Route *route);
84 DEFINE_SECTION_CLEANUP_FUNCTIONS(Route, route_free);
85
86 int route_new(Route **ret);
87 int route_new_static(Network *network, const char *filename, unsigned section_line, Route **ret);
88 int route_dup(const Route *src, const RouteNextHop *nh, Route **ret);
89
90 int route_configure_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, Route *route, const char *error_msg);
91 int route_remove(Route *route, Manager *manager);
92 int route_remove_and_cancel(Route *route, Manager *manager);
93
94 int route_get(Manager *manager, const Route *route, Route **ret);
95
96 int link_drop_routes(Link *link, bool foreign);
97 static inline int link_drop_managed_routes(Link *link) {
98 return link_drop_routes(link, false);
99 }
100 static inline int link_drop_foreign_routes(Link *link) {
101 return link_drop_routes(link, true);
102 }
103 int link_foreignize_routes(Link *link);
104
105 int link_request_route(
106 Link *link,
107 const Route *route,
108 unsigned *message_counter,
109 route_netlink_handler_t netlink_handler);
110 int link_request_static_routes(Link *link, bool only_ipv4);
111
112 int manager_rtnl_process_route(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);
113
114 int network_add_ipv4ll_route(Network *network);
115 int network_add_default_route_on_device(Network *network);
116 void network_drop_invalid_routes(Network *network);
117 int route_section_verify(Route *route);
118
119 DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(Route, route);
120 void manager_mark_routes(Manager *manager, Link *link, NetworkConfigSource source);
121
122 CONFIG_PARSER_PROTOTYPE(config_parse_preferred_src);
123 CONFIG_PARSER_PROTOTYPE(config_parse_destination);
124 CONFIG_PARSER_PROTOTYPE(config_parse_route_priority);
125 CONFIG_PARSER_PROTOTYPE(config_parse_route_scope);
126 CONFIG_PARSER_PROTOTYPE(config_parse_route_table);
127 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_route_preference);
128 CONFIG_PARSER_PROTOTYPE(config_parse_route_protocol);
129 CONFIG_PARSER_PROTOTYPE(config_parse_route_type);