Skip to content

Commit

Permalink
net: flow_offload: add list handling functions
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ummakynes authored and davem330 committed Jul 9, 2019
1 parent d63db30 commit da3eeb9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
19 changes: 19 additions & 0 deletions include/net/flow_offload.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,16 @@ struct flow_block_offload {
enum flow_block_command command;
enum flow_block_binder_type binder_type;
struct tcf_block *block;
struct net *net;
struct list_head cb_list;
struct list_head *driver_block_list;
struct netlink_ext_ack *extack;
};

struct flow_block_cb {
struct list_head driver_list;
struct list_head list;
struct net *net;
tc_setup_cb_t *cb;
void *cb_ident;
void *cb_priv;
Expand All @@ -274,6 +278,21 @@ struct flow_block_cb *flow_block_cb_alloc(struct net *net, tc_setup_cb_t *cb,
void (*release)(void *cb_priv));
void flow_block_cb_free(struct flow_block_cb *block_cb);

struct flow_block_cb *flow_block_cb_lookup(struct flow_block_offload *offload,
tc_setup_cb_t *cb, void *cb_ident);

static inline void flow_block_cb_add(struct flow_block_cb *block_cb,
struct flow_block_offload *offload)
{
list_add_tail(&block_cb->list, &offload->cb_list);
}

static inline void flow_block_cb_remove(struct flow_block_cb *block_cb,
struct flow_block_offload *offload)
{
list_move(&block_cb->list, &offload->cb_list);
}

int flow_block_cb_setup_simple(struct flow_block_offload *f,
struct list_head *driver_list, tc_setup_cb_t *cb,
void *cb_ident, void *cb_priv, bool ingress_only);
Expand Down
17 changes: 17 additions & 0 deletions net/core/flow_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ struct flow_block_cb *flow_block_cb_alloc(struct net *net, tc_setup_cb_t *cb,
if (!block_cb)
return ERR_PTR(-ENOMEM);

block_cb->net = net;
block_cb->cb = cb;
block_cb->cb_ident = cb_ident;
block_cb->cb_priv = cb_priv;
Expand All @@ -194,6 +195,22 @@ void flow_block_cb_free(struct flow_block_cb *block_cb)
}
EXPORT_SYMBOL(flow_block_cb_free);

struct flow_block_cb *flow_block_cb_lookup(struct flow_block_offload *f,
tc_setup_cb_t *cb, void *cb_ident)
{
struct flow_block_cb *block_cb;

list_for_each_entry(block_cb, f->driver_block_list, driver_list) {
if (block_cb->net == f->net &&
block_cb->cb == cb &&
block_cb->cb_ident == cb_ident)
return block_cb;
}

return NULL;
}
EXPORT_SYMBOL(flow_block_cb_lookup);

int flow_block_cb_setup_simple(struct flow_block_offload *f,
struct list_head *driver_block_list,
tc_setup_cb_t *cb, void *cb_ident, void *cb_priv,
Expand Down
3 changes: 3 additions & 0 deletions net/sched/cls_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ static void tc_indr_block_ing_cmd(struct tc_indr_block_dev *indr_dev,
struct tc_block_offload bo = {
.command = command,
.binder_type = FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS,
.net = dev_net(indr_dev->dev),
.block = indr_dev->block,
};

Expand Down Expand Up @@ -768,6 +769,7 @@ static void tc_indr_block_call(struct tcf_block *block, struct net_device *dev,
struct tc_block_offload bo = {
.command = command,
.binder_type = ei->binder_type,
.net = dev_net(dev),
.block = block,
.extack = extack,
};
Expand Down Expand Up @@ -796,6 +798,7 @@ static int tcf_block_offload_cmd(struct tcf_block *block,
{
struct tc_block_offload bo = {};

bo.net = dev_net(dev);
bo.command = command;
bo.binder_type = ei->binder_type;
bo.block = block;
Expand Down

0 comments on commit da3eeb9

Please sign in to comment.