1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include <netinet/in.h>
6 #include <linux/fib_rules.h>
9 #include "in-addr-util.h"
10 #include "conf-parser.h"
12 typedef struct RoutingPolicyRule RoutingPolicyRule
;
14 #include "networkd-link.h"
15 #include "networkd-network.h"
16 #include "networkd-util.h"
18 typedef struct Network Network
;
19 typedef struct Link Link
;
20 typedef struct NetworkConfigSection NetworkConfigSection
;
21 typedef struct Manager Manager
;
23 struct RoutingPolicyRule
{
27 NetworkConfigSection
*section
;
40 unsigned char to_prefixlen
;
41 unsigned char from_prefixlen
;
46 union in_addr_union to
;
47 union in_addr_union from
;
49 struct fib_rule_port_range sport
;
50 struct fib_rule_port_range dport
;
52 LIST_FIELDS(RoutingPolicyRule
, rules
);
55 int routing_policy_rule_new(RoutingPolicyRule
**ret
);
56 void routing_policy_rule_free(RoutingPolicyRule
*rule
);
58 DEFINE_NETWORK_SECTION_FUNCTIONS(RoutingPolicyRule
, routing_policy_rule_free
);
60 int routing_policy_rule_configure(RoutingPolicyRule
*address
, Link
*link
, link_netlink_message_handler_t callback
);
61 int routing_policy_rule_remove(RoutingPolicyRule
*routing_policy_rule
, Link
*link
, link_netlink_message_handler_t callback
);
63 int routing_policy_rule_add(Manager
*m
, int family
, const union in_addr_union
*from
, uint8_t from_prefixlen
, const union in_addr_union
*to
, uint8_t to_prefixlen
,
64 uint8_t tos
, uint32_t fwmark
, uint32_t table
, const char *iif
, const char *oif
, uint8_t protocol
, const struct fib_rule_port_range
*sport
,
65 const struct fib_rule_port_range
*dport
, RoutingPolicyRule
**ret
);
66 int routing_policy_rule_add_foreign(Manager
*m
, int family
, const union in_addr_union
*from
, uint8_t from_prefixlen
, const union in_addr_union
*to
, uint8_t to_prefixlen
,
67 uint8_t tos
, uint32_t fwmark
, uint32_t table
, const char *iif
, const char *oif
, uint8_t protocol
, const struct fib_rule_port_range
*sport
,
68 const struct fib_rule_port_range
*dport
, RoutingPolicyRule
**ret
);
69 int routing_policy_rule_get(Manager
*m
, int family
, const union in_addr_union
*from
, uint8_t from_prefixlen
, const union in_addr_union
*to
, uint8_t to_prefixlen
, uint8_t tos
,
70 uint32_t fwmark
, uint32_t table
, const char *iif
, const char *oif
, uint8_t protocol
, struct fib_rule_port_range
*sport
,
71 struct fib_rule_port_range
*dport
, RoutingPolicyRule
**ret
);
72 int routing_policy_rule_make_local(Manager
*m
, RoutingPolicyRule
*rule
);
73 int routing_policy_serialize_rules(Set
*rules
, FILE *f
);
74 int routing_policy_load_rules(const char *state_file
, Set
**rules
);
75 void routing_policy_rule_purge(Manager
*m
, Link
*link
);
77 CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_tos
);
78 CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_table
);
79 CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_fwmark_mask
);
80 CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_prefix
);
81 CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_priority
);
82 CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_device
);
83 CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_port_range
);
84 CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_ip_protocol
);
85 CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule_invert
);