|
@@ -240,8 +240,36 @@ tcf_chain_filter_chain_ptr_set(struct tcf_chain *chain,
|
|
|
chain->p_filter_chain = p_filter_chain;
|
|
|
}
|
|
|
|
|
|
-int tcf_block_get(struct tcf_block **p_block,
|
|
|
- struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q)
|
|
|
+static void tcf_block_offload_cmd(struct tcf_block *block, struct Qdisc *q,
|
|
|
+ struct tcf_block_ext_info *ei,
|
|
|
+ enum tc_block_command command)
|
|
|
+{
|
|
|
+ struct net_device *dev = q->dev_queue->dev;
|
|
|
+ struct tc_block_offload bo = {};
|
|
|
+
|
|
|
+ if (!tc_can_offload(dev))
|
|
|
+ return;
|
|
|
+ bo.command = command;
|
|
|
+ bo.binder_type = ei->binder_type;
|
|
|
+ bo.block = block;
|
|
|
+ dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_BLOCK, &bo);
|
|
|
+}
|
|
|
+
|
|
|
+static void tcf_block_offload_bind(struct tcf_block *block, struct Qdisc *q,
|
|
|
+ struct tcf_block_ext_info *ei)
|
|
|
+{
|
|
|
+ tcf_block_offload_cmd(block, q, ei, TC_BLOCK_BIND);
|
|
|
+}
|
|
|
+
|
|
|
+static void tcf_block_offload_unbind(struct tcf_block *block, struct Qdisc *q,
|
|
|
+ struct tcf_block_ext_info *ei)
|
|
|
+{
|
|
|
+ tcf_block_offload_cmd(block, q, ei, TC_BLOCK_UNBIND);
|
|
|
+}
|
|
|
+
|
|
|
+int tcf_block_get_ext(struct tcf_block **p_block,
|
|
|
+ struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
|
|
|
+ struct tcf_block_ext_info *ei)
|
|
|
{
|
|
|
struct tcf_block *block = kzalloc(sizeof(*block), GFP_KERNEL);
|
|
|
struct tcf_chain *chain;
|
|
@@ -250,6 +278,8 @@ int tcf_block_get(struct tcf_block **p_block,
|
|
|
if (!block)
|
|
|
return -ENOMEM;
|
|
|
INIT_LIST_HEAD(&block->chain_list);
|
|
|
+ INIT_LIST_HEAD(&block->cb_list);
|
|
|
+
|
|
|
/* Create chain 0 by default, it has to be always present. */
|
|
|
chain = tcf_chain_create(block, 0);
|
|
|
if (!chain) {
|
|
@@ -259,6 +289,7 @@ int tcf_block_get(struct tcf_block **p_block,
|
|
|
tcf_chain_filter_chain_ptr_set(chain, p_filter_chain);
|
|
|
block->net = qdisc_net(q);
|
|
|
block->q = q;
|
|
|
+ tcf_block_offload_bind(block, q, ei);
|
|
|
*p_block = block;
|
|
|
return 0;
|
|
|
|
|
@@ -266,15 +297,28 @@ err_chain_create:
|
|
|
kfree(block);
|
|
|
return err;
|
|
|
}
|
|
|
+EXPORT_SYMBOL(tcf_block_get_ext);
|
|
|
+
|
|
|
+int tcf_block_get(struct tcf_block **p_block,
|
|
|
+ struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q)
|
|
|
+{
|
|
|
+ struct tcf_block_ext_info ei = {0, };
|
|
|
+
|
|
|
+ return tcf_block_get_ext(p_block, p_filter_chain, q, &ei);
|
|
|
+}
|
|
|
EXPORT_SYMBOL(tcf_block_get);
|
|
|
|
|
|
-void tcf_block_put(struct tcf_block *block)
|
|
|
+void tcf_block_put_ext(struct tcf_block *block,
|
|
|
+ struct tcf_proto __rcu **p_filter_chain, struct Qdisc *q,
|
|
|
+ struct tcf_block_ext_info *ei)
|
|
|
{
|
|
|
struct tcf_chain *chain, *tmp;
|
|
|
|
|
|
if (!block)
|
|
|
return;
|
|
|
|
|
|
+ tcf_block_offload_unbind(block, q, ei);
|
|
|
+
|
|
|
/* XXX: Standalone actions are not allowed to jump to any chain, and
|
|
|
* bound actions should be all removed after flushing. However,
|
|
|
* filters are destroyed in RCU callbacks, we have to hold the chains
|
|
@@ -302,8 +346,119 @@ void tcf_block_put(struct tcf_block *block)
|
|
|
tcf_chain_put(chain);
|
|
|
kfree(block);
|
|
|
}
|
|
|
+EXPORT_SYMBOL(tcf_block_put_ext);
|
|
|
+
|
|
|
+void tcf_block_put(struct tcf_block *block)
|
|
|
+{
|
|
|
+ struct tcf_block_ext_info ei = {0, };
|
|
|
+
|
|
|
+ tcf_block_put_ext(block, NULL, block->q, &ei);
|
|
|
+}
|
|
|
EXPORT_SYMBOL(tcf_block_put);
|
|
|
|
|
|
+struct tcf_block_cb {
|
|
|
+ struct list_head list;
|
|
|
+ tc_setup_cb_t *cb;
|
|
|
+ void *cb_ident;
|
|
|
+ void *cb_priv;
|
|
|
+ unsigned int refcnt;
|
|
|
+};
|
|
|
+
|
|
|
+void *tcf_block_cb_priv(struct tcf_block_cb *block_cb)
|
|
|
+{
|
|
|
+ return block_cb->cb_priv;
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(tcf_block_cb_priv);
|
|
|
+
|
|
|
+struct tcf_block_cb *tcf_block_cb_lookup(struct tcf_block *block,
|
|
|
+ tc_setup_cb_t *cb, void *cb_ident)
|
|
|
+{ struct tcf_block_cb *block_cb;
|
|
|
+
|
|
|
+ list_for_each_entry(block_cb, &block->cb_list, list)
|
|
|
+ if (block_cb->cb == cb && block_cb->cb_ident == cb_ident)
|
|
|
+ return block_cb;
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(tcf_block_cb_lookup);
|
|
|
+
|
|
|
+void tcf_block_cb_incref(struct tcf_block_cb *block_cb)
|
|
|
+{
|
|
|
+ block_cb->refcnt++;
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(tcf_block_cb_incref);
|
|
|
+
|
|
|
+unsigned int tcf_block_cb_decref(struct tcf_block_cb *block_cb)
|
|
|
+{
|
|
|
+ return --block_cb->refcnt;
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(tcf_block_cb_decref);
|
|
|
+
|
|
|
+struct tcf_block_cb *__tcf_block_cb_register(struct tcf_block *block,
|
|
|
+ tc_setup_cb_t *cb, void *cb_ident,
|
|
|
+ void *cb_priv)
|
|
|
+{
|
|
|
+ struct tcf_block_cb *block_cb;
|
|
|
+
|
|
|
+ block_cb = kzalloc(sizeof(*block_cb), GFP_KERNEL);
|
|
|
+ if (!block_cb)
|
|
|
+ return NULL;
|
|
|
+ block_cb->cb = cb;
|
|
|
+ block_cb->cb_ident = cb_ident;
|
|
|
+ block_cb->cb_priv = cb_priv;
|
|
|
+ list_add(&block_cb->list, &block->cb_list);
|
|
|
+ return block_cb;
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(__tcf_block_cb_register);
|
|
|
+
|
|
|
+int tcf_block_cb_register(struct tcf_block *block,
|
|
|
+ tc_setup_cb_t *cb, void *cb_ident,
|
|
|
+ void *cb_priv)
|
|
|
+{
|
|
|
+ struct tcf_block_cb *block_cb;
|
|
|
+
|
|
|
+ block_cb = __tcf_block_cb_register(block, cb, cb_ident, cb_priv);
|
|
|
+ return block_cb ? 0 : -ENOMEM;
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(tcf_block_cb_register);
|
|
|
+
|
|
|
+void __tcf_block_cb_unregister(struct tcf_block_cb *block_cb)
|
|
|
+{
|
|
|
+ list_del(&block_cb->list);
|
|
|
+ kfree(block_cb);
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(__tcf_block_cb_unregister);
|
|
|
+
|
|
|
+void tcf_block_cb_unregister(struct tcf_block *block,
|
|
|
+ tc_setup_cb_t *cb, void *cb_ident)
|
|
|
+{
|
|
|
+ struct tcf_block_cb *block_cb;
|
|
|
+
|
|
|
+ block_cb = tcf_block_cb_lookup(block, cb, cb_ident);
|
|
|
+ if (!block_cb)
|
|
|
+ return;
|
|
|
+ __tcf_block_cb_unregister(block_cb);
|
|
|
+}
|
|
|
+EXPORT_SYMBOL(tcf_block_cb_unregister);
|
|
|
+
|
|
|
+static int tcf_block_cb_call(struct tcf_block *block, enum tc_setup_type type,
|
|
|
+ void *type_data, bool err_stop)
|
|
|
+{
|
|
|
+ struct tcf_block_cb *block_cb;
|
|
|
+ int ok_count = 0;
|
|
|
+ int err;
|
|
|
+
|
|
|
+ list_for_each_entry(block_cb, &block->cb_list, list) {
|
|
|
+ err = block_cb->cb(type, type_data, block_cb->cb_priv);
|
|
|
+ if (err) {
|
|
|
+ if (err_stop)
|
|
|
+ return err;
|
|
|
+ } else {
|
|
|
+ ok_count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ok_count;
|
|
|
+}
|
|
|
+
|
|
|
/* Main classifier routine: scans classifier chain attached
|
|
|
* to this qdisc, (optionally) tests for protocol and asks
|
|
|
* specific classifiers.
|
|
@@ -1051,10 +1206,25 @@ static int tc_exts_setup_cb_egdev_call(struct tcf_exts *exts,
|
|
|
return ok_count;
|
|
|
}
|
|
|
|
|
|
-int tc_setup_cb_call(struct tcf_exts *exts, enum tc_setup_type type,
|
|
|
- void *type_data, bool err_stop)
|
|
|
+int tc_setup_cb_call(struct tcf_block *block, struct tcf_exts *exts,
|
|
|
+ enum tc_setup_type type, void *type_data, bool err_stop)
|
|
|
{
|
|
|
- return tc_exts_setup_cb_egdev_call(exts, type, type_data, err_stop);
|
|
|
+ int ok_count;
|
|
|
+ int ret;
|
|
|
+
|
|
|
+ ret = tcf_block_cb_call(block, type, type_data, err_stop);
|
|
|
+ if (ret < 0)
|
|
|
+ return ret;
|
|
|
+ ok_count = ret;
|
|
|
+
|
|
|
+ if (!exts)
|
|
|
+ return ok_count;
|
|
|
+ ret = tc_exts_setup_cb_egdev_call(exts, type, type_data, err_stop);
|
|
|
+ if (ret < 0)
|
|
|
+ return ret;
|
|
|
+ ok_count += ret;
|
|
|
+
|
|
|
+ return ok_count;
|
|
|
}
|
|
|
EXPORT_SYMBOL(tc_setup_cb_call);
|
|
|
|