Line data Source code
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 : struct Route {
14 : Network *network;
15 : NetworkConfigSection *section;
16 :
17 : Link *link;
18 :
19 : int family;
20 : int quickack;
21 : int fast_open_no_cookie;
22 : int ttl_propagate;
23 :
24 : unsigned char dst_prefixlen;
25 : unsigned char src_prefixlen;
26 : unsigned char scope;
27 : bool scope_set;
28 : unsigned char protocol; /* RTPROT_* */
29 : unsigned char type; /* RTN_* */
30 : unsigned char tos;
31 : uint32_t priority; /* note that ip(8) calls this 'metric' */
32 : uint32_t table;
33 : bool table_set;
34 : uint32_t mtu;
35 : uint32_t initcwnd;
36 : uint32_t initrwnd;
37 : unsigned char pref;
38 : unsigned flags;
39 : int gateway_onlink;
40 :
41 : union in_addr_union gw;
42 : union in_addr_union dst;
43 : union in_addr_union src;
44 : union in_addr_union prefsrc;
45 :
46 : usec_t lifetime;
47 : sd_event_source *expire;
48 :
49 : LIST_FIELDS(Route, routes);
50 : };
51 :
52 : extern const struct hash_ops route_full_hash_ops;
53 :
54 : int route_new(Route **ret);
55 : void route_free(Route *route);
56 : int route_configure(Route *route, Link *link, link_netlink_message_handler_t callback);
57 : int route_remove(Route *route, Link *link, link_netlink_message_handler_t callback);
58 :
59 : int route_get(Link *link, int family, const union in_addr_union *dst, unsigned char dst_prefixlen, const union in_addr_union *gw, unsigned char tos, uint32_t priority, uint32_t table, Route **ret);
60 : int route_add(Link *link, int family, const union in_addr_union *dst, unsigned char dst_prefixlen, const union in_addr_union *gw, unsigned char tos, uint32_t priority, uint32_t table, Route **ret);
61 : int route_add_foreign(Link *link, int family, const union in_addr_union *dst, unsigned char dst_prefixlen, const union in_addr_union *gw, unsigned char tos, uint32_t priority, uint32_t table, Route **ret);
62 : void route_update(Route *route, const union in_addr_union *src, unsigned char src_prefixlen, const union in_addr_union *gw, const union in_addr_union *prefsrc, unsigned char scope, unsigned char protocol, unsigned char type);
63 : bool route_equal(Route *r1, Route *r2);
64 :
65 : int route_expire_handler(sd_event_source *s, uint64_t usec, void *userdata);
66 : int route_section_verify(Route *route, Network *network);
67 :
68 6 : DEFINE_NETWORK_SECTION_FUNCTIONS(Route, route_free);
69 :
70 : int network_add_ipv4ll_route(Network *network);
71 : int network_add_default_route_on_device(Network *network);
72 :
73 : const char* route_type_to_string(int t) _const_;
74 : int route_type_from_string(const char *s) _pure_;
75 :
76 : #define ROUTE_SCOPE_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("nowhere") + 1)
77 : const char *format_route_scope(int scope, char *buf, size_t size);
78 :
79 : #define ROUTE_TABLE_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("default") + 1)
80 : const char *format_route_table(int table, char *buf, size_t size);
81 :
82 : #define ROUTE_PROTOCOL_STR_MAX CONST_MAX(DECIMAL_STR_MAX(int), STRLEN("redirect") + 1)
83 : const char *format_route_protocol(int protocol, char *buf, size_t size);
84 :
85 : CONFIG_PARSER_PROTOTYPE(config_parse_gateway);
86 : CONFIG_PARSER_PROTOTYPE(config_parse_preferred_src);
87 : CONFIG_PARSER_PROTOTYPE(config_parse_destination);
88 : CONFIG_PARSER_PROTOTYPE(config_parse_route_priority);
89 : CONFIG_PARSER_PROTOTYPE(config_parse_route_scope);
90 : CONFIG_PARSER_PROTOTYPE(config_parse_route_table);
91 : CONFIG_PARSER_PROTOTYPE(config_parse_gateway_onlink);
92 : CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_route_preference);
93 : CONFIG_PARSER_PROTOTYPE(config_parse_route_protocol);
94 : CONFIG_PARSER_PROTOTYPE(config_parse_route_type);
95 : CONFIG_PARSER_PROTOTYPE(config_parse_tcp_window);
96 : CONFIG_PARSER_PROTOTYPE(config_parse_quickack);
97 : CONFIG_PARSER_PROTOTYPE(config_parse_fast_open_no_cookie);
98 : CONFIG_PARSER_PROTOTYPE(config_parse_route_ttl_propagate);
99 : CONFIG_PARSER_PROTOTYPE(config_parse_route_mtu);
|