1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
7 #include "sd-netlink.h"
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"
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
;
22 typedef int (*route_netlink_handler_t
)(
24 sd_netlink_message
*m
,
33 ConfigSection
*section
;
34 NetworkConfigSource source
;
35 NetworkConfigState state
;
36 union in_addr_union provider
; /* DHCP server or router address */
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 */
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) */
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 */
61 /* metrics (RTA_METRICS) */
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 */
71 /* Only used by conf persers and route_section_verify(). */
77 bool gateway_from_dhcp_or_ra
:1;
81 extern const struct hash_ops route_hash_ops
;
83 Route
* route_free(Route
*route
);
84 DEFINE_SECTION_CLEANUP_FUNCTIONS(Route
, route_free
);
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
);
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
);
94 int route_get(Manager
*manager
, const Route
*route
, Route
**ret
);
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);
100 static inline int link_drop_foreign_routes(Link
*link
) {
101 return link_drop_routes(link
, true);
103 int link_foreignize_routes(Link
*link
);
105 int link_request_route(
108 unsigned *message_counter
,
109 route_netlink_handler_t netlink_handler
);
110 int link_request_static_routes(Link
*link
, bool only_ipv4
);
112 int manager_rtnl_process_route(sd_netlink
*rtnl
, sd_netlink_message
*message
, Manager
*m
);
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
);
119 DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(Route
, route
);
120 void manager_mark_routes(Manager
*manager
, Link
*link
, NetworkConfigSource source
);
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
);