]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - net/core/flow_offload.c
net: flow_offload: rename TCF_BLOCK_BINDER_TYPE_* to FLOW_BLOCK_BINDER_TYPE_*
[mirror_ubuntu-hirsute-kernel.git] / net / core / flow_offload.c
CommitLineData
8f256622
PNA
1/* SPDX-License-Identifier: GPL-2.0 */
2#include <linux/kernel.h>
3#include <linux/slab.h>
4#include <net/flow_offload.h>
4e95bc26 5#include <net/pkt_cls.h>
8f256622 6
e3ab786b 7struct flow_rule *flow_rule_alloc(unsigned int num_actions)
8f256622 8{
e3ab786b
PNA
9 struct flow_rule *rule;
10
6dca9360 11 rule = kzalloc(struct_size(rule, action.entries, num_actions),
e3ab786b
PNA
12 GFP_KERNEL);
13 if (!rule)
14 return NULL;
15
16 rule->action.num_entries = num_actions;
17
18 return rule;
8f256622
PNA
19}
20EXPORT_SYMBOL(flow_rule_alloc);
21
22#define FLOW_DISSECTOR_MATCH(__rule, __type, __out) \
23 const struct flow_match *__m = &(__rule)->match; \
24 struct flow_dissector *__d = (__m)->dissector; \
25 \
26 (__out)->key = skb_flow_dissector_target(__d, __type, (__m)->key); \
27 (__out)->mask = skb_flow_dissector_target(__d, __type, (__m)->mask); \
28
9558a83a
JP
29void flow_rule_match_meta(const struct flow_rule *rule,
30 struct flow_match_meta *out)
31{
32 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_META, out);
33}
34EXPORT_SYMBOL(flow_rule_match_meta);
35
8f256622
PNA
36void flow_rule_match_basic(const struct flow_rule *rule,
37 struct flow_match_basic *out)
38{
39 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_BASIC, out);
40}
41EXPORT_SYMBOL(flow_rule_match_basic);
42
43void flow_rule_match_control(const struct flow_rule *rule,
44 struct flow_match_control *out)
45{
46 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_CONTROL, out);
47}
48EXPORT_SYMBOL(flow_rule_match_control);
49
50void flow_rule_match_eth_addrs(const struct flow_rule *rule,
51 struct flow_match_eth_addrs *out)
52{
53 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS, out);
54}
55EXPORT_SYMBOL(flow_rule_match_eth_addrs);
56
57void flow_rule_match_vlan(const struct flow_rule *rule,
58 struct flow_match_vlan *out)
59{
60 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_VLAN, out);
61}
62EXPORT_SYMBOL(flow_rule_match_vlan);
63
bae9ed69
EC
64void flow_rule_match_cvlan(const struct flow_rule *rule,
65 struct flow_match_vlan *out)
66{
67 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_CVLAN, out);
68}
69EXPORT_SYMBOL(flow_rule_match_cvlan);
70
8f256622
PNA
71void flow_rule_match_ipv4_addrs(const struct flow_rule *rule,
72 struct flow_match_ipv4_addrs *out)
73{
74 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_IPV4_ADDRS, out);
75}
76EXPORT_SYMBOL(flow_rule_match_ipv4_addrs);
77
78void flow_rule_match_ipv6_addrs(const struct flow_rule *rule,
79 struct flow_match_ipv6_addrs *out)
80{
81 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_IPV6_ADDRS, out);
82}
83EXPORT_SYMBOL(flow_rule_match_ipv6_addrs);
84
85void flow_rule_match_ip(const struct flow_rule *rule,
86 struct flow_match_ip *out)
87{
88 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_IP, out);
89}
90EXPORT_SYMBOL(flow_rule_match_ip);
91
92void flow_rule_match_ports(const struct flow_rule *rule,
93 struct flow_match_ports *out)
94{
95 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_PORTS, out);
96}
97EXPORT_SYMBOL(flow_rule_match_ports);
98
99void flow_rule_match_tcp(const struct flow_rule *rule,
100 struct flow_match_tcp *out)
101{
102 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_TCP, out);
103}
104EXPORT_SYMBOL(flow_rule_match_tcp);
105
106void flow_rule_match_icmp(const struct flow_rule *rule,
107 struct flow_match_icmp *out)
108{
109 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_ICMP, out);
110}
111EXPORT_SYMBOL(flow_rule_match_icmp);
112
113void flow_rule_match_mpls(const struct flow_rule *rule,
114 struct flow_match_mpls *out)
115{
116 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_MPLS, out);
117}
118EXPORT_SYMBOL(flow_rule_match_mpls);
119
120void flow_rule_match_enc_control(const struct flow_rule *rule,
121 struct flow_match_control *out)
122{
123 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_ENC_CONTROL, out);
124}
125EXPORT_SYMBOL(flow_rule_match_enc_control);
126
127void flow_rule_match_enc_ipv4_addrs(const struct flow_rule *rule,
128 struct flow_match_ipv4_addrs *out)
129{
130 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS, out);
131}
132EXPORT_SYMBOL(flow_rule_match_enc_ipv4_addrs);
133
134void flow_rule_match_enc_ipv6_addrs(const struct flow_rule *rule,
135 struct flow_match_ipv6_addrs *out)
136{
137 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS, out);
138}
139EXPORT_SYMBOL(flow_rule_match_enc_ipv6_addrs);
140
141void flow_rule_match_enc_ip(const struct flow_rule *rule,
142 struct flow_match_ip *out)
143{
144 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_ENC_IP, out);
145}
146EXPORT_SYMBOL(flow_rule_match_enc_ip);
147
148void flow_rule_match_enc_ports(const struct flow_rule *rule,
149 struct flow_match_ports *out)
150{
151 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_ENC_PORTS, out);
152}
153EXPORT_SYMBOL(flow_rule_match_enc_ports);
154
155void flow_rule_match_enc_keyid(const struct flow_rule *rule,
156 struct flow_match_enc_keyid *out)
157{
158 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_ENC_KEYID, out);
159}
160EXPORT_SYMBOL(flow_rule_match_enc_keyid);
161
162void flow_rule_match_enc_opts(const struct flow_rule *rule,
163 struct flow_match_enc_opts *out)
164{
165 FLOW_DISSECTOR_MATCH(rule, FLOW_DISSECTOR_KEY_ENC_OPTS, out);
166}
167EXPORT_SYMBOL(flow_rule_match_enc_opts);
4e95bc26
PNA
168
169int flow_block_cb_setup_simple(struct flow_block_offload *f,
170 struct list_head *driver_block_list,
171 tc_setup_cb_t *cb, void *cb_ident, void *cb_priv,
172 bool ingress_only)
173{
174 if (ingress_only &&
32f8c409 175 f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
4e95bc26
PNA
176 return -EOPNOTSUPP;
177
178 f->driver_block_list = driver_block_list;
179
180 switch (f->command) {
9c0e189e 181 case FLOW_BLOCK_BIND:
4e95bc26
PNA
182 return tcf_block_cb_register(f->block, cb, cb_ident, cb_priv,
183 f->extack);
9c0e189e 184 case FLOW_BLOCK_UNBIND:
4e95bc26
PNA
185 tcf_block_cb_unregister(f->block, cb, cb_ident);
186 return 0;
187 default:
188 return -EOPNOTSUPP;
189 }
190}
191EXPORT_SYMBOL(flow_block_cb_setup_simple);