Debian Codegraph @

src/network/networkd-route.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "in-addr-util.h"
5 #include "networkd-forward.h"
6 #include "networkd-route-metric.h"
7 #include "networkd-route-nexthop.h"
8 #include "networkd-util.h"
9
10 typedef int (*route_netlink_handler_t)(
11 sd_netlink *rtnl,
12 sd_netlink_message *m,
13 Request *req,
14 Link *link,
15 Route *route);
16
17 typedef struct Route {
18 Manager *manager;
19 Network *network;
20 Wireguard *wireguard;
21 ConfigSection *section;
22 NetworkConfigSource source;
23 NetworkConfigState state;
24 union in_addr_union provider; /* DHCP server or router address */
25
26 unsigned n_ref;
27
28 /* rtmsg header */
29 int family;
30 unsigned char dst_prefixlen;
31 unsigned char src_prefixlen; /* IPv6 only */
32 unsigned char tos; /* IPv4 only */
33 unsigned char protocol; /* RTPROT_* */
34 unsigned char scope; /* IPv4 only */
35 unsigned char type; /* RTN_*, e.g. RTN_LOCAL, RTN_UNREACHABLE */
36 unsigned flags; /* e.g. RTNH_F_ONLINK */
37
38 /* attributes */
39 union in_addr_union dst; /* RTA_DST */
40 union in_addr_union src; /* RTA_SRC (IPv6 only) */
41 uint32_t priority; /* RTA_PRIORITY, note that ip(8) calls this 'metric' */
42 union in_addr_union prefsrc; /* RTA_PREFSRC */
43 uint32_t table; /* RTA_TABLE, also used in rtmsg header */
44 uint8_t pref; /* RTA_PREF (IPv6 only) */
45
46 /* nexthops */
47 RouteNextHop nexthop; /* RTA_OIF, and RTA_GATEWAY or RTA_VIA (IPv4 only) */
48 OrderedSet *nexthops; /* RTA_MULTIPATH */
49 uint32_t nexthop_id; /* RTA_NH_ID */
50
51 /* metrics (RTA_METRICS) */
52 RouteMetric metric;
53
54 /* This is an absolute point in time, and NOT a timespan/duration.
55 * Must be specified with clock_boottime_or_monotonic(). */
56 usec_t lifetime_usec; /* RTA_EXPIRES (IPv6 only) */
57 /* Used when kernel does not support RTA_EXPIRES attribute. */
58 sd_event_source *expire;
59 bool expiration_managed_by_kernel:1; /* RTA_CACHEINFO has nonzero rta_expires */
60
61 /* Only used by conf persers and route_section_verify(). */
62 bool prefsrc_set:1;
63 bool scope_set:1;
64 bool table_set:1;
65 bool priority_set:1;
66 bool protocol_set:1;
67 bool pref_set:1;
68 bool gateway_from_dhcp_or_ra:1;
69 int gateway_onlink;
70 } Route;
71
72 void log_route_debug(const Route *route, const char *str, Manager *manager);
73
74 extern const struct hash_ops route_hash_ops;
75 extern const struct hash_ops route_hash_ops_unref;
76
77 DECLARE_TRIVIAL_REF_UNREF_FUNC(Route, route);
78 DEFINE_SECTION_CLEANUP_FUNCTIONS(Route, route_unref);
79
80 void route_detach(Route *route);
81
82 int route_new(Route **ret);
83 int route_new_static(Network *network, const char *filename, unsigned section_line, Route **ret);
84 int route_dup(const Route *src, const RouteNextHop *nh, Route **ret);
85
86 int route_configure_handler_internal(sd_netlink_message *m, Request *req, Route *route);
87 int route_remove(Route *route, Manager *manager);
88 int route_remove_and_cancel(Route *route, Manager *manager);
89
90 int route_get(Manager *manager, const Route *route, Route **ret);
91 bool route_is_bound_to_link(const Route *route, Link *link);
92 int route_get_request(Manager *manager, const Route *route, Request **ret);
93
94 bool route_can_update(Manager *manager, const Route *existing, const Route *requesting);
95
96 int link_drop_routes(Link *link, bool only_static);
97 static inline int link_drop_static_routes(Link *link) {
98 return link_drop_routes(link, true);
99 }
100 static inline int link_drop_unmanaged_routes(Link *link) {
101 return link_drop_routes(link, false);
102 }
103 void link_forget_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 typedef enum RouteConfParserType {
123 ROUTE_DESTINATION,
124 ROUTE_PREFERRED_SOURCE,
125 ROUTE_PRIORITY,
126 ROUTE_SCOPE,
127 ROUTE_TABLE,
128 ROUTE_PREFERENCE,
129 ROUTE_PROTOCOL,
130 ROUTE_TYPE,
131 ROUTE_GATEWAY_NETWORK,
132 ROUTE_GATEWAY,
133 ROUTE_GATEWAY_ONLINK,
134 ROUTE_MULTIPATH,
135 ROUTE_NEXTHOP,
136 ROUTE_METRIC_MTU,
137 ROUTE_METRIC_ADVMSS,
138 ROUTE_METRIC_HOPLIMIT,
139 ROUTE_METRIC_INITCWND,
140 ROUTE_METRIC_RTO_MIN,
141 ROUTE_METRIC_INITRWND,
142 ROUTE_METRIC_QUICKACK,
143 ROUTE_METRIC_CC_ALGO,
144 ROUTE_METRIC_FASTOPEN_NO_COOKIE,
145 _ROUTE_CONF_PARSER_MAX,
146 _ROUTE_CONF_PARSER_INVALID = -EINVAL,
147 } RouteConfParserType;
148
149 CONFIG_PARSER_PROTOTYPE(config_parse_route_section);