]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-route.h
network: make address/route_configure optionally return created Address/Route object
[thirdparty/systemd.git] / src / network / networkd-route.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include "conf-parser.h"
5 #include "macro.h"
6
7 typedef struct Route Route;
8 typedef struct NetworkConfigSection NetworkConfigSection;
9
10 #include "networkd-network.h"
11 #include "networkd-util.h"
12
13 typedef struct MultipathRouteVia {
14 uint16_t family;
15 union in_addr_union address;
16 } _packed_ MultipathRouteVia;
17
18 typedef struct MultipathRoute {
19 MultipathRouteVia gateway;
20 int ifindex;
21 uint32_t weight;
22 } MultipathRoute;
23
24 struct Route {
25 Network *network;
26 NetworkConfigSection *section;
27
28 Link *link;
29
30 int family;
31 int quickack;
32 int fast_open_no_cookie;
33 int ttl_propagate;
34
35 unsigned char dst_prefixlen;
36 unsigned char src_prefixlen;
37 unsigned char scope;
38 bool scope_set;
39 unsigned char protocol; /* RTPROT_* */
40 unsigned char type; /* RTN_* */
41 unsigned char tos;
42 uint32_t priority; /* note that ip(8) calls this 'metric' */
43 uint32_t table;
44 bool table_set;
45 uint32_t mtu;
46 uint32_t initcwnd;
47 uint32_t initrwnd;
48 unsigned char pref;
49 unsigned flags;
50 int gateway_onlink;
51 bool gateway_from_dhcp;
52
53 union in_addr_union gw;
54 union in_addr_union dst;
55 union in_addr_union src;
56 union in_addr_union prefsrc;
57 OrderedSet *multipath_routes;
58
59 usec_t lifetime;
60 sd_event_source *expire;
61
62 LIST_FIELDS(Route, routes);
63 };
64
65 extern const struct hash_ops route_hash_ops;
66
67 int route_new(Route **ret);
68 void route_free(Route *route);
69 int route_configure(Route *route, Link *link, link_netlink_message_handler_t callback, Route **ret);
70 int route_remove(Route *route, Link *link, link_netlink_message_handler_t callback);
71
72 int route_get(Link *link, Route *in, Route **ret);
73 int route_add(Link *link, Route *in, Route **ret);
74 int route_add_foreign(Link *link, Route *in, Route **ret);
75 bool route_equal(Route *r1, Route *r2);
76
77 int route_expire_handler(sd_event_source *s, uint64_t usec, void *userdata);
78 int route_section_verify(Route *route, Network *network);
79
80 DEFINE_NETWORK_SECTION_FUNCTIONS(Route, route_free);
81
82 int network_add_ipv4ll_route(Network *network);
83 int network_add_default_route_on_device(Network *network);
84
85 const char* route_type_to_string(int t) _const_;
86 int route_type_from_string(const char *s) _pure_;
87
88 #define ROUTE_SCOPE_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("nowhere") + 1)
89 const char *format_route_scope(int scope, char *buf, size_t size);
90
91 #define ROUTE_TABLE_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("default") + 1)
92 const char *format_route_table(int table, char *buf, size_t size);
93
94 #define ROUTE_PROTOCOL_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("redirect") + 1)
95 const char *format_route_protocol(int protocol, char *buf, size_t size);
96
97 CONFIG_PARSER_PROTOTYPE(config_parse_gateway);
98 CONFIG_PARSER_PROTOTYPE(config_parse_preferred_src);
99 CONFIG_PARSER_PROTOTYPE(config_parse_destination);
100 CONFIG_PARSER_PROTOTYPE(config_parse_route_priority);
101 CONFIG_PARSER_PROTOTYPE(config_parse_route_scope);
102 CONFIG_PARSER_PROTOTYPE(config_parse_route_table);
103 CONFIG_PARSER_PROTOTYPE(config_parse_route_boolean);
104 CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_route_preference);
105 CONFIG_PARSER_PROTOTYPE(config_parse_route_protocol);
106 CONFIG_PARSER_PROTOTYPE(config_parse_route_type);
107 CONFIG_PARSER_PROTOTYPE(config_parse_tcp_window);
108 CONFIG_PARSER_PROTOTYPE(config_parse_route_mtu);
109 CONFIG_PARSER_PROTOTYPE(config_parse_multipath_route);