| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include <linux/fib_rules.h> |
| 5 |
|
| 6 |
#include "in-addr-prefix-util.h" |
| 7 |
#include "networkd-forward.h" |
| 8 |
#include "networkd-util.h" |
| 9 |
|
| 10 |
typedef struct RoutingPolicyRule { |
| 11 |
Manager *manager; |
| 12 |
Network *network; |
| 13 |
ConfigSection *section; |
| 14 |
NetworkConfigSource source; |
| 15 |
NetworkConfigState state; |
| 16 |
|
| 17 |
unsigned n_ref; |
| 18 |
|
| 19 |
/* struct fib_rule_hdr */ |
| 20 |
AddressFamily address_family; /* Used when parsing Family= */ |
| 21 |
int family; /* Automatically determined by From=, To=, and Family= */ |
| 22 |
uint8_t tos; |
| 23 |
uint8_t action; |
| 24 |
uint32_t flags; |
| 25 |
|
| 26 |
/* attributes */ |
| 27 |
struct in_addr_prefix to; /* FRA_DST */ |
| 28 |
struct in_addr_prefix from; /* FRA_SRC */ |
| 29 |
char *iif; /* FRA_IIFNAME */ |
| 30 |
uint32_t priority_goto; /* FRA_GOTO */ |
| 31 |
bool priority_set; |
| 32 |
uint32_t priority; /* FRA_PRIORITY */ |
| 33 |
uint32_t fwmark; /* FRA_FWMARK */ |
| 34 |
uint32_t realms; /* FRA_FLOW (IPv4 only) */ |
| 35 |
uint64_t tunnel_id; /* FRA_TUN_ID */ |
| 36 |
int32_t suppress_ifgroup; /* FRA_SUPPRESS_IFGROUP */ |
| 37 |
int32_t suppress_prefixlen; /* FRA_SUPPRESS_PREFIXLEN */ |
| 38 |
uint32_t table; /* FRA_TABLE, also used in struct fib_rule_hdr */ |
| 39 |
uint32_t fwmask; /* FRA_FWMASK */ |
| 40 |
char *oif; /* FRA_OIFNAME */ |
| 41 |
bool l3mdev; /* FRA_L3MDEV */ |
| 42 |
struct fib_rule_uid_range uid_range; /* FRA_UID_RANGE */ |
| 43 |
uint8_t protocol; /* FRA_PROTOCOL */ |
| 44 |
uint8_t ipproto; /* FRA_IP_PROTO */ |
| 45 |
struct fib_rule_port_range sport; /* FRA_SPORT_RANGE */ |
| 46 |
struct fib_rule_port_range dport; /* FRA_DPORT_RANGE */ |
| 47 |
} RoutingPolicyRule; |
| 48 |
|
| 49 |
DECLARE_STRING_TABLE_LOOKUP(fr_act_type, int); |
| 50 |
|
| 51 |
DECLARE_TRIVIAL_REF_UNREF_FUNC(RoutingPolicyRule, routing_policy_rule); |
| 52 |
|
| 53 |
void network_drop_invalid_routing_policy_rules(Network *network); |
| 54 |
|
| 55 |
int link_request_static_routing_policy_rules(Link *link); |
| 56 |
|
| 57 |
int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, Manager *m); |
| 58 |
|
| 59 |
int link_drop_routing_policy_rules(Link *link, bool only_static); |
| 60 |
static inline int link_drop_unmanaged_routing_policy_rules(Link *link) { |
| 61 |
return link_drop_routing_policy_rules(link, false); |
| 62 |
} |
| 63 |
static inline int link_drop_static_routing_policy_rules(Link *link) { |
| 64 |
return link_drop_routing_policy_rules(link, true); |
| 65 |
} |
| 66 |
|
| 67 |
DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(RoutingPolicyRule, routing_policy_rule); |
| 68 |
|
| 69 |
typedef enum RoutingPolicyRuleConfParserType { |
| 70 |
ROUTING_POLICY_RULE_IIF, |
| 71 |
ROUTING_POLICY_RULE_OIF, |
| 72 |
ROUTING_POLICY_RULE_FAMILY, |
| 73 |
ROUTING_POLICY_RULE_FWMARK, |
| 74 |
ROUTING_POLICY_RULE_GOTO, |
| 75 |
ROUTING_POLICY_RULE_INVERT, |
| 76 |
ROUTING_POLICY_RULE_IP_PROTOCOL, |
| 77 |
ROUTING_POLICY_RULE_L3MDEV, |
| 78 |
ROUTING_POLICY_RULE_SPORT, |
| 79 |
ROUTING_POLICY_RULE_DPORT, |
| 80 |
ROUTING_POLICY_RULE_FROM, |
| 81 |
ROUTING_POLICY_RULE_TO, |
| 82 |
ROUTING_POLICY_RULE_PRIORITY, |
| 83 |
ROUTING_POLICY_RULE_SUPPRESS_IFGROUP, |
| 84 |
ROUTING_POLICY_RULE_SUPPRESS_PREFIXLEN, |
| 85 |
ROUTING_POLICY_RULE_TABLE, |
| 86 |
ROUTING_POLICY_RULE_TOS, |
| 87 |
ROUTING_POLICY_RULE_ACTION, |
| 88 |
ROUTING_POLICY_RULE_UID_RANGE, |
| 89 |
_ROUTING_POLICY_RULE_CONF_PARSER_MAX, |
| 90 |
_ROUTING_POLICY_RULE_CONF_PARSER_INVALID = -EINVAL, |
| 91 |
} RoutingPolicyRuleConfParserType; |
| 92 |
|
| 93 |
CONFIG_PARSER_PROTOTYPE(config_parse_routing_policy_rule); |