1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <linux/kernel.h>
3 #include <linux/slab.h>
4 #include <net/flow_offload.h>
6 struct flow_rule
*flow_rule_alloc(unsigned int num_actions
)
8 struct flow_rule
*rule
;
10 rule
= kzalloc(sizeof(struct flow_rule
) +
11 sizeof(struct flow_action_entry
) * num_actions
,
16 rule
->action
.num_entries
= num_actions
;
20 EXPORT_SYMBOL(flow_rule_alloc
);
22 #define FLOW_DISSECTOR_MATCH(__rule, __type, __out) \
23 const struct flow_match *__m = &(__rule)->match; \
24 struct flow_dissector *__d = (__m)->dissector; \
26 (__out)->key = skb_flow_dissector_target(__d, __type, (__m)->key); \
27 (__out)->mask = skb_flow_dissector_target(__d, __type, (__m)->mask); \
29 void flow_rule_match_basic(const struct flow_rule *rule,
30 struct flow_match_basic
*out
)
32 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_BASIC
, out
);
34 EXPORT_SYMBOL(flow_rule_match_basic
);
36 void flow_rule_match_control(const struct flow_rule
*rule
,
37 struct flow_match_control
*out
)
39 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_CONTROL
, out
);
41 EXPORT_SYMBOL(flow_rule_match_control
);
43 void flow_rule_match_eth_addrs(const struct flow_rule
*rule
,
44 struct flow_match_eth_addrs
*out
)
46 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_ETH_ADDRS
, out
);
48 EXPORT_SYMBOL(flow_rule_match_eth_addrs
);
50 void flow_rule_match_vlan(const struct flow_rule
*rule
,
51 struct flow_match_vlan
*out
)
53 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_VLAN
, out
);
55 EXPORT_SYMBOL(flow_rule_match_vlan
);
57 void flow_rule_match_cvlan(const struct flow_rule
*rule
,
58 struct flow_match_vlan
*out
)
60 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_CVLAN
, out
);
62 EXPORT_SYMBOL(flow_rule_match_cvlan
);
64 void flow_rule_match_ipv4_addrs(const struct flow_rule
*rule
,
65 struct flow_match_ipv4_addrs
*out
)
67 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_IPV4_ADDRS
, out
);
69 EXPORT_SYMBOL(flow_rule_match_ipv4_addrs
);
71 void flow_rule_match_ipv6_addrs(const struct flow_rule
*rule
,
72 struct flow_match_ipv6_addrs
*out
)
74 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_IPV6_ADDRS
, out
);
76 EXPORT_SYMBOL(flow_rule_match_ipv6_addrs
);
78 void flow_rule_match_ip(const struct flow_rule
*rule
,
79 struct flow_match_ip
*out
)
81 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_IP
, out
);
83 EXPORT_SYMBOL(flow_rule_match_ip
);
85 void flow_rule_match_ports(const struct flow_rule
*rule
,
86 struct flow_match_ports
*out
)
88 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_PORTS
, out
);
90 EXPORT_SYMBOL(flow_rule_match_ports
);
92 void flow_rule_match_tcp(const struct flow_rule
*rule
,
93 struct flow_match_tcp
*out
)
95 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_TCP
, out
);
97 EXPORT_SYMBOL(flow_rule_match_tcp
);
99 void flow_rule_match_icmp(const struct flow_rule
*rule
,
100 struct flow_match_icmp
*out
)
102 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_ICMP
, out
);
104 EXPORT_SYMBOL(flow_rule_match_icmp
);
106 void flow_rule_match_mpls(const struct flow_rule
*rule
,
107 struct flow_match_mpls
*out
)
109 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_MPLS
, out
);
111 EXPORT_SYMBOL(flow_rule_match_mpls
);
113 void flow_rule_match_enc_control(const struct flow_rule
*rule
,
114 struct flow_match_control
*out
)
116 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_ENC_CONTROL
, out
);
118 EXPORT_SYMBOL(flow_rule_match_enc_control
);
120 void flow_rule_match_enc_ipv4_addrs(const struct flow_rule
*rule
,
121 struct flow_match_ipv4_addrs
*out
)
123 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS
, out
);
125 EXPORT_SYMBOL(flow_rule_match_enc_ipv4_addrs
);
127 void flow_rule_match_enc_ipv6_addrs(const struct flow_rule
*rule
,
128 struct flow_match_ipv6_addrs
*out
)
130 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS
, out
);
132 EXPORT_SYMBOL(flow_rule_match_enc_ipv6_addrs
);
134 void flow_rule_match_enc_ip(const struct flow_rule
*rule
,
135 struct flow_match_ip
*out
)
137 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_ENC_IP
, out
);
139 EXPORT_SYMBOL(flow_rule_match_enc_ip
);
141 void flow_rule_match_enc_ports(const struct flow_rule
*rule
,
142 struct flow_match_ports
*out
)
144 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_ENC_PORTS
, out
);
146 EXPORT_SYMBOL(flow_rule_match_enc_ports
);
148 void flow_rule_match_enc_keyid(const struct flow_rule
*rule
,
149 struct flow_match_enc_keyid
*out
)
151 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_ENC_KEYID
, out
);
153 EXPORT_SYMBOL(flow_rule_match_enc_keyid
);
155 void flow_rule_match_enc_opts(const struct flow_rule
*rule
,
156 struct flow_match_enc_opts
*out
)
158 FLOW_DISSECTOR_MATCH(rule
, FLOW_DISSECTOR_KEY_ENC_OPTS
, out
);
160 EXPORT_SYMBOL(flow_rule_match_enc_opts
);