Skip to content

Commit da3eeb9

Browse files
ummakynesdavem330
authored andcommitted
net: flow_offload: add list handling functions
This patch adds the list handling functions for the flow block API: * flow_block_cb_lookup() allows drivers to look up for existing flow blocks. * flow_block_cb_add() adds a flow block to the per driver list to be registered by the core. * flow_block_cb_remove() to remove a flow block from the list of existing flow blocks per driver and to request the core to unregister this. The flow block API also annotates the netns this flow block belongs to. Signed-off-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d63db30 commit da3eeb9

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

include/net/flow_offload.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,16 @@ struct flow_block_offload {
256256
enum flow_block_command command;
257257
enum flow_block_binder_type binder_type;
258258
struct tcf_block *block;
259+
struct net *net;
260+
struct list_head cb_list;
259261
struct list_head *driver_block_list;
260262
struct netlink_ext_ack *extack;
261263
};
262264

263265
struct flow_block_cb {
266+
struct list_head driver_list;
264267
struct list_head list;
268+
struct net *net;
265269
tc_setup_cb_t *cb;
266270
void *cb_ident;
267271
void *cb_priv;
@@ -274,6 +278,21 @@ struct flow_block_cb *flow_block_cb_alloc(struct net *net, tc_setup_cb_t *cb,
274278
void (*release)(void *cb_priv));
275279
void flow_block_cb_free(struct flow_block_cb *block_cb);
276280

281+
struct flow_block_cb *flow_block_cb_lookup(struct flow_block_offload *offload,
282+
tc_setup_cb_t *cb, void *cb_ident);
283+
284+
static inline void flow_block_cb_add(struct flow_block_cb *block_cb,
285+
struct flow_block_offload *offload)
286+
{
287+
list_add_tail(&block_cb->list, &offload->cb_list);
288+
}
289+
290+
static inline void flow_block_cb_remove(struct flow_block_cb *block_cb,
291+
struct flow_block_offload *offload)
292+
{
293+
list_move(&block_cb->list, &offload->cb_list);
294+
}
295+
277296
int flow_block_cb_setup_simple(struct flow_block_offload *f,
278297
struct list_head *driver_list, tc_setup_cb_t *cb,
279298
void *cb_ident, void *cb_priv, bool ingress_only);

net/core/flow_offload.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ struct flow_block_cb *flow_block_cb_alloc(struct net *net, tc_setup_cb_t *cb,
176176
if (!block_cb)
177177
return ERR_PTR(-ENOMEM);
178178

179+
block_cb->net = net;
179180
block_cb->cb = cb;
180181
block_cb->cb_ident = cb_ident;
181182
block_cb->cb_priv = cb_priv;
@@ -194,6 +195,22 @@ void flow_block_cb_free(struct flow_block_cb *block_cb)
194195
}
195196
EXPORT_SYMBOL(flow_block_cb_free);
196197

198+
struct flow_block_cb *flow_block_cb_lookup(struct flow_block_offload *f,
199+
tc_setup_cb_t *cb, void *cb_ident)
200+
{
201+
struct flow_block_cb *block_cb;
202+
203+
list_for_each_entry(block_cb, f->driver_block_list, driver_list) {
204+
if (block_cb->net == f->net &&
205+
block_cb->cb == cb &&
206+
block_cb->cb_ident == cb_ident)
207+
return block_cb;
208+
}
209+
210+
return NULL;
211+
}
212+
EXPORT_SYMBOL(flow_block_cb_lookup);
213+
197214
int flow_block_cb_setup_simple(struct flow_block_offload *f,
198215
struct list_head *driver_block_list,
199216
tc_setup_cb_t *cb, void *cb_ident, void *cb_priv,

net/sched/cls_api.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ static void tc_indr_block_ing_cmd(struct tc_indr_block_dev *indr_dev,
680680
struct tc_block_offload bo = {
681681
.command = command,
682682
.binder_type = FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS,
683+
.net = dev_net(indr_dev->dev),
683684
.block = indr_dev->block,
684685
};
685686

@@ -768,6 +769,7 @@ static void tc_indr_block_call(struct tcf_block *block, struct net_device *dev,
768769
struct tc_block_offload bo = {
769770
.command = command,
770771
.binder_type = ei->binder_type,
772+
.net = dev_net(dev),
771773
.block = block,
772774
.extack = extack,
773775
};
@@ -796,6 +798,7 @@ static int tcf_block_offload_cmd(struct tcf_block *block,
796798
{
797799
struct tc_block_offload bo = {};
798800

801+
bo.net = dev_net(dev);
799802
bo.command = command;
800803
bo.binder_type = ei->binder_type;
801804
bo.block = block;

0 commit comments

Comments
 (0)