Commit 87265d84 authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso

netfilter: flowtable: add nf_flow_offload_work_alloc()

Add helper function to allocate and initialize flow offload work and use
it to consolidate existing code.
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent a7521a60
...@@ -748,21 +748,35 @@ static void flow_offload_queue_work(struct flow_offload_work *offload) ...@@ -748,21 +748,35 @@ static void flow_offload_queue_work(struct flow_offload_work *offload)
schedule_work(&nf_flow_offload_work); schedule_work(&nf_flow_offload_work);
} }
void nf_flow_offload_add(struct nf_flowtable *flowtable, static struct flow_offload_work *
struct flow_offload *flow) nf_flow_offload_work_alloc(struct nf_flowtable *flowtable,
struct flow_offload *flow, unsigned int cmd)
{ {
struct flow_offload_work *offload; struct flow_offload_work *offload;
offload = kmalloc(sizeof(struct flow_offload_work), GFP_ATOMIC); offload = kmalloc(sizeof(struct flow_offload_work), GFP_ATOMIC);
if (!offload) if (!offload)
return; return NULL;
offload->cmd = FLOW_CLS_REPLACE; offload->cmd = cmd;
offload->flow = flow; offload->flow = flow;
offload->priority = flowtable->priority; offload->priority = flowtable->priority;
offload->flowtable = flowtable; offload->flowtable = flowtable;
flow->flags |= FLOW_OFFLOAD_HW;
return offload;
}
void nf_flow_offload_add(struct nf_flowtable *flowtable,
struct flow_offload *flow)
{
struct flow_offload_work *offload;
offload = nf_flow_offload_work_alloc(flowtable, flow, FLOW_CLS_REPLACE);
if (!offload)
return;
flow->flags |= FLOW_OFFLOAD_HW;
flow_offload_queue_work(offload); flow_offload_queue_work(offload);
} }
...@@ -771,15 +785,11 @@ void nf_flow_offload_del(struct nf_flowtable *flowtable, ...@@ -771,15 +785,11 @@ void nf_flow_offload_del(struct nf_flowtable *flowtable,
{ {
struct flow_offload_work *offload; struct flow_offload_work *offload;
offload = kzalloc(sizeof(struct flow_offload_work), GFP_ATOMIC); offload = nf_flow_offload_work_alloc(flowtable, flow, FLOW_CLS_DESTROY);
if (!offload) if (!offload)
return; return;
offload->cmd = FLOW_CLS_DESTROY; flow->flags |= FLOW_OFFLOAD_HW_DYING;
offload->flow = flow;
offload->flow->flags |= FLOW_OFFLOAD_HW_DYING;
offload->flowtable = flowtable;
flow_offload_queue_work(offload); flow_offload_queue_work(offload);
} }
...@@ -793,14 +803,10 @@ void nf_flow_offload_stats(struct nf_flowtable *flowtable, ...@@ -793,14 +803,10 @@ void nf_flow_offload_stats(struct nf_flowtable *flowtable,
if ((delta >= (9 * NF_FLOW_TIMEOUT) / 10)) if ((delta >= (9 * NF_FLOW_TIMEOUT) / 10))
return; return;
offload = kzalloc(sizeof(struct flow_offload_work), GFP_ATOMIC); offload = nf_flow_offload_work_alloc(flowtable, flow, FLOW_CLS_STATS);
if (!offload) if (!offload)
return; return;
offload->cmd = FLOW_CLS_STATS;
offload->flow = flow;
offload->flowtable = flowtable;
flow_offload_queue_work(offload); flow_offload_queue_work(offload);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment