|
@@ -106,13 +106,12 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb,
|
|
|
|
|
|
static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb,
|
|
static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb,
|
|
struct nlmsghdr *n,
|
|
struct nlmsghdr *n,
|
|
- struct tcf_proto __rcu **chain, int event)
|
|
|
|
|
|
+ struct tcf_chain *chain, int event)
|
|
{
|
|
{
|
|
- struct tcf_proto __rcu **it_chain;
|
|
|
|
struct tcf_proto *tp;
|
|
struct tcf_proto *tp;
|
|
|
|
|
|
- for (it_chain = chain; (tp = rtnl_dereference(*it_chain)) != NULL;
|
|
|
|
- it_chain = &tp->next)
|
|
|
|
|
|
+ for (tp = rtnl_dereference(chain->filter_chain);
|
|
|
|
+ tp; tp = rtnl_dereference(tp->next))
|
|
tfilter_notify(net, oskb, n, tp, 0, event, false);
|
|
tfilter_notify(net, oskb, n, tp, 0, event, false);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -125,11 +124,12 @@ static inline u32 tcf_auto_prio(struct tcf_proto *tp)
|
|
if (tp)
|
|
if (tp)
|
|
first = tp->prio - 1;
|
|
first = tp->prio - 1;
|
|
|
|
|
|
- return first;
|
|
|
|
|
|
+ return TC_H_MAJ(first);
|
|
}
|
|
}
|
|
|
|
|
|
static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol,
|
|
static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol,
|
|
- u32 prio, u32 parent, struct Qdisc *q)
|
|
|
|
|
|
+ u32 prio, u32 parent, struct Qdisc *q,
|
|
|
|
+ struct tcf_chain *chain)
|
|
{
|
|
{
|
|
struct tcf_proto *tp;
|
|
struct tcf_proto *tp;
|
|
int err;
|
|
int err;
|
|
@@ -165,6 +165,7 @@ static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol,
|
|
tp->prio = prio;
|
|
tp->prio = prio;
|
|
tp->classid = parent;
|
|
tp->classid = parent;
|
|
tp->q = q;
|
|
tp->q = q;
|
|
|
|
+ tp->chain = chain;
|
|
|
|
|
|
err = tp->ops->init(tp);
|
|
err = tp->ops->init(tp);
|
|
if (err) {
|
|
if (err) {
|
|
@@ -185,16 +186,213 @@ static void tcf_proto_destroy(struct tcf_proto *tp)
|
|
kfree_rcu(tp, rcu);
|
|
kfree_rcu(tp, rcu);
|
|
}
|
|
}
|
|
|
|
|
|
-void tcf_destroy_chain(struct tcf_proto __rcu **fl)
|
|
|
|
|
|
+static struct tcf_chain *tcf_chain_create(struct tcf_block *block,
|
|
|
|
+ u32 chain_index)
|
|
|
|
+{
|
|
|
|
+ struct tcf_chain *chain;
|
|
|
|
+
|
|
|
|
+ chain = kzalloc(sizeof(*chain), GFP_KERNEL);
|
|
|
|
+ if (!chain)
|
|
|
|
+ return NULL;
|
|
|
|
+ list_add_tail(&chain->list, &block->chain_list);
|
|
|
|
+ chain->block = block;
|
|
|
|
+ chain->index = chain_index;
|
|
|
|
+ chain->refcnt = 1;
|
|
|
|
+ return chain;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void tcf_chain_destroy(struct tcf_chain *chain)
|
|
{
|
|
{
|
|
struct tcf_proto *tp;
|
|
struct tcf_proto *tp;
|
|
|
|
|
|
- while ((tp = rtnl_dereference(*fl)) != NULL) {
|
|
|
|
- RCU_INIT_POINTER(*fl, tp->next);
|
|
|
|
|
|
+ list_del(&chain->list);
|
|
|
|
+ while ((tp = rtnl_dereference(chain->filter_chain)) != NULL) {
|
|
|
|
+ RCU_INIT_POINTER(chain->filter_chain, tp->next);
|
|
tcf_proto_destroy(tp);
|
|
tcf_proto_destroy(tp);
|
|
}
|
|
}
|
|
|
|
+ kfree(chain);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+struct tcf_chain *tcf_chain_get(struct tcf_block *block, u32 chain_index)
|
|
|
|
+{
|
|
|
|
+ struct tcf_chain *chain;
|
|
|
|
+
|
|
|
|
+ list_for_each_entry(chain, &block->chain_list, list) {
|
|
|
|
+ if (chain->index == chain_index) {
|
|
|
|
+ chain->refcnt++;
|
|
|
|
+ return chain;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return tcf_chain_create(block, chain_index);
|
|
|
|
+}
|
|
|
|
+EXPORT_SYMBOL(tcf_chain_get);
|
|
|
|
+
|
|
|
|
+void tcf_chain_put(struct tcf_chain *chain)
|
|
|
|
+{
|
|
|
|
+ /* Destroy unused chain, with exception of chain 0, which is the
|
|
|
|
+ * default one and has to be always present.
|
|
|
|
+ */
|
|
|
|
+ if (--chain->refcnt == 0 && !chain->filter_chain && chain->index != 0)
|
|
|
|
+ tcf_chain_destroy(chain);
|
|
|
|
+}
|
|
|
|
+EXPORT_SYMBOL(tcf_chain_put);
|
|
|
|
+
|
|
|
|
+static void
|
|
|
|
+tcf_chain_filter_chain_ptr_set(struct tcf_chain *chain,
|
|
|
|
+ struct tcf_proto __rcu **p_filter_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 tcf_block *block = kzalloc(sizeof(*block), GFP_KERNEL);
|
|
|
|
+ struct tcf_chain *chain;
|
|
|
|
+ int err;
|
|
|
|
+
|
|
|
|
+ if (!block)
|
|
|
|
+ return -ENOMEM;
|
|
|
|
+ INIT_LIST_HEAD(&block->chain_list);
|
|
|
|
+ /* Create chain 0 by default, it has to be always present. */
|
|
|
|
+ chain = tcf_chain_create(block, 0);
|
|
|
|
+ if (!chain) {
|
|
|
|
+ err = -ENOMEM;
|
|
|
|
+ goto err_chain_create;
|
|
|
|
+ }
|
|
|
|
+ tcf_chain_filter_chain_ptr_set(chain, p_filter_chain);
|
|
|
|
+ *p_block = block;
|
|
|
|
+ return 0;
|
|
|
|
+
|
|
|
|
+err_chain_create:
|
|
|
|
+ kfree(block);
|
|
|
|
+ return err;
|
|
|
|
+}
|
|
|
|
+EXPORT_SYMBOL(tcf_block_get);
|
|
|
|
+
|
|
|
|
+void tcf_block_put(struct tcf_block *block)
|
|
|
|
+{
|
|
|
|
+ struct tcf_chain *chain, *tmp;
|
|
|
|
+
|
|
|
|
+ if (!block)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ list_for_each_entry_safe(chain, tmp, &block->chain_list, list)
|
|
|
|
+ tcf_chain_destroy(chain);
|
|
|
|
+ kfree(block);
|
|
|
|
+}
|
|
|
|
+EXPORT_SYMBOL(tcf_block_put);
|
|
|
|
+
|
|
|
|
+/* Main classifier routine: scans classifier chain attached
|
|
|
|
+ * to this qdisc, (optionally) tests for protocol and asks
|
|
|
|
+ * specific classifiers.
|
|
|
|
+ */
|
|
|
|
+int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
|
|
|
|
+ struct tcf_result *res, bool compat_mode)
|
|
|
|
+{
|
|
|
|
+ __be16 protocol = tc_skb_protocol(skb);
|
|
|
|
+#ifdef CONFIG_NET_CLS_ACT
|
|
|
|
+ const int max_reclassify_loop = 4;
|
|
|
|
+ const struct tcf_proto *old_tp = tp;
|
|
|
|
+ int limit = 0;
|
|
|
|
+
|
|
|
|
+reclassify:
|
|
|
|
+#endif
|
|
|
|
+ for (; tp; tp = rcu_dereference_bh(tp->next)) {
|
|
|
|
+ int err;
|
|
|
|
+
|
|
|
|
+ if (tp->protocol != protocol &&
|
|
|
|
+ tp->protocol != htons(ETH_P_ALL))
|
|
|
|
+ continue;
|
|
|
|
+
|
|
|
|
+ err = tp->classify(skb, tp, res);
|
|
|
|
+#ifdef CONFIG_NET_CLS_ACT
|
|
|
|
+ if (unlikely(err == TC_ACT_RECLASSIFY && !compat_mode)) {
|
|
|
|
+ goto reset;
|
|
|
|
+ } else if (unlikely(TC_ACT_EXT_CMP(err, TC_ACT_GOTO_CHAIN))) {
|
|
|
|
+ old_tp = res->goto_tp;
|
|
|
|
+ goto reset;
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+ if (err >= 0)
|
|
|
|
+ return err;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return TC_ACT_UNSPEC; /* signal: continue lookup */
|
|
|
|
+#ifdef CONFIG_NET_CLS_ACT
|
|
|
|
+reset:
|
|
|
|
+ if (unlikely(limit++ >= max_reclassify_loop)) {
|
|
|
|
+ net_notice_ratelimited("%s: reclassify loop, rule prio %u, protocol %02x\n",
|
|
|
|
+ tp->q->ops->id, tp->prio & 0xffff,
|
|
|
|
+ ntohs(tp->protocol));
|
|
|
|
+ return TC_ACT_SHOT;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ tp = old_tp;
|
|
|
|
+ protocol = tc_skb_protocol(skb);
|
|
|
|
+ goto reclassify;
|
|
|
|
+#endif
|
|
|
|
+}
|
|
|
|
+EXPORT_SYMBOL(tcf_classify);
|
|
|
|
+
|
|
|
|
+struct tcf_chain_info {
|
|
|
|
+ struct tcf_proto __rcu **pprev;
|
|
|
|
+ struct tcf_proto __rcu *next;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+static struct tcf_proto *tcf_chain_tp_prev(struct tcf_chain_info *chain_info)
|
|
|
|
+{
|
|
|
|
+ return rtnl_dereference(*chain_info->pprev);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void tcf_chain_tp_insert(struct tcf_chain *chain,
|
|
|
|
+ struct tcf_chain_info *chain_info,
|
|
|
|
+ struct tcf_proto *tp)
|
|
|
|
+{
|
|
|
|
+ if (chain->p_filter_chain &&
|
|
|
|
+ *chain_info->pprev == chain->filter_chain)
|
|
|
|
+ *chain->p_filter_chain = tp;
|
|
|
|
+ RCU_INIT_POINTER(tp->next, tcf_chain_tp_prev(chain_info));
|
|
|
|
+ rcu_assign_pointer(*chain_info->pprev, tp);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void tcf_chain_tp_remove(struct tcf_chain *chain,
|
|
|
|
+ struct tcf_chain_info *chain_info,
|
|
|
|
+ struct tcf_proto *tp)
|
|
|
|
+{
|
|
|
|
+ struct tcf_proto *next = rtnl_dereference(chain_info->next);
|
|
|
|
+
|
|
|
|
+ if (chain->p_filter_chain && tp == chain->filter_chain)
|
|
|
|
+ *chain->p_filter_chain = next;
|
|
|
|
+ RCU_INIT_POINTER(*chain_info->pprev, next);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static struct tcf_proto *tcf_chain_tp_find(struct tcf_chain *chain,
|
|
|
|
+ struct tcf_chain_info *chain_info,
|
|
|
|
+ u32 protocol, u32 prio,
|
|
|
|
+ bool prio_allocate)
|
|
|
|
+{
|
|
|
|
+ struct tcf_proto **pprev;
|
|
|
|
+ struct tcf_proto *tp;
|
|
|
|
+
|
|
|
|
+ /* Check the chain for existence of proto-tcf with this priority */
|
|
|
|
+ for (pprev = &chain->filter_chain;
|
|
|
|
+ (tp = rtnl_dereference(*pprev)); pprev = &tp->next) {
|
|
|
|
+ if (tp->prio >= prio) {
|
|
|
|
+ if (tp->prio == prio) {
|
|
|
|
+ if (prio_allocate ||
|
|
|
|
+ (tp->protocol != protocol && protocol))
|
|
|
|
+ return ERR_PTR(-EINVAL);
|
|
|
|
+ } else {
|
|
|
|
+ tp = NULL;
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ chain_info->pprev = pprev;
|
|
|
|
+ chain_info->next = tp ? tp->next : NULL;
|
|
|
|
+ return tp;
|
|
}
|
|
}
|
|
-EXPORT_SYMBOL(tcf_destroy_chain);
|
|
|
|
|
|
|
|
/* Add/change/delete/get a filter node */
|
|
/* Add/change/delete/get a filter node */
|
|
|
|
|
|
@@ -206,13 +404,14 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
|
|
struct tcmsg *t;
|
|
struct tcmsg *t;
|
|
u32 protocol;
|
|
u32 protocol;
|
|
u32 prio;
|
|
u32 prio;
|
|
- u32 nprio;
|
|
|
|
|
|
+ bool prio_allocate;
|
|
u32 parent;
|
|
u32 parent;
|
|
|
|
+ u32 chain_index;
|
|
struct net_device *dev;
|
|
struct net_device *dev;
|
|
struct Qdisc *q;
|
|
struct Qdisc *q;
|
|
- struct tcf_proto __rcu **back;
|
|
|
|
- struct tcf_proto __rcu **chain;
|
|
|
|
- struct tcf_proto *next;
|
|
|
|
|
|
+ struct tcf_chain_info chain_info;
|
|
|
|
+ struct tcf_chain *chain = NULL;
|
|
|
|
+ struct tcf_block *block;
|
|
struct tcf_proto *tp;
|
|
struct tcf_proto *tp;
|
|
const struct Qdisc_class_ops *cops;
|
|
const struct Qdisc_class_ops *cops;
|
|
unsigned long cl;
|
|
unsigned long cl;
|
|
@@ -234,7 +433,7 @@ replay:
|
|
t = nlmsg_data(n);
|
|
t = nlmsg_data(n);
|
|
protocol = TC_H_MIN(t->tcm_info);
|
|
protocol = TC_H_MIN(t->tcm_info);
|
|
prio = TC_H_MAJ(t->tcm_info);
|
|
prio = TC_H_MAJ(t->tcm_info);
|
|
- nprio = prio;
|
|
|
|
|
|
+ prio_allocate = false;
|
|
parent = t->tcm_parent;
|
|
parent = t->tcm_parent;
|
|
cl = 0;
|
|
cl = 0;
|
|
|
|
|
|
@@ -250,6 +449,7 @@ replay:
|
|
*/
|
|
*/
|
|
if (n->nlmsg_flags & NLM_F_CREATE) {
|
|
if (n->nlmsg_flags & NLM_F_CREATE) {
|
|
prio = TC_H_MAKE(0x80000000U, 0U);
|
|
prio = TC_H_MAKE(0x80000000U, 0U);
|
|
|
|
+ prio_allocate = true;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
/* fall-through */
|
|
/* fall-through */
|
|
@@ -280,7 +480,7 @@ replay:
|
|
if (!cops)
|
|
if (!cops)
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
- if (cops->tcf_chain == NULL)
|
|
|
|
|
|
+ if (!cops->tcf_block)
|
|
return -EOPNOTSUPP;
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
/* Do we search for filter, attached to class? */
|
|
/* Do we search for filter, attached to class? */
|
|
@@ -291,34 +491,35 @@ replay:
|
|
}
|
|
}
|
|
|
|
|
|
/* And the last stroke */
|
|
/* And the last stroke */
|
|
- chain = cops->tcf_chain(q, cl);
|
|
|
|
- if (chain == NULL) {
|
|
|
|
|
|
+ block = cops->tcf_block(q, cl);
|
|
|
|
+ if (!block) {
|
|
|
|
+ err = -EINVAL;
|
|
|
|
+ goto errout;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0;
|
|
|
|
+ if (chain_index > TC_ACT_EXT_VAL_MASK) {
|
|
err = -EINVAL;
|
|
err = -EINVAL;
|
|
goto errout;
|
|
goto errout;
|
|
}
|
|
}
|
|
|
|
+ chain = tcf_chain_get(block, chain_index);
|
|
|
|
+ if (!chain) {
|
|
|
|
+ err = -ENOMEM;
|
|
|
|
+ goto errout;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (n->nlmsg_type == RTM_DELTFILTER && prio == 0) {
|
|
if (n->nlmsg_type == RTM_DELTFILTER && prio == 0) {
|
|
tfilter_notify_chain(net, skb, n, chain, RTM_DELTFILTER);
|
|
tfilter_notify_chain(net, skb, n, chain, RTM_DELTFILTER);
|
|
- tcf_destroy_chain(chain);
|
|
|
|
|
|
+ tcf_chain_destroy(chain);
|
|
err = 0;
|
|
err = 0;
|
|
goto errout;
|
|
goto errout;
|
|
}
|
|
}
|
|
|
|
|
|
- /* Check the chain for existence of proto-tcf with this priority */
|
|
|
|
- for (back = chain;
|
|
|
|
- (tp = rtnl_dereference(*back)) != NULL;
|
|
|
|
- back = &tp->next) {
|
|
|
|
- if (tp->prio >= prio) {
|
|
|
|
- if (tp->prio == prio) {
|
|
|
|
- if (!nprio ||
|
|
|
|
- (tp->protocol != protocol && protocol)) {
|
|
|
|
- err = -EINVAL;
|
|
|
|
- goto errout;
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- tp = NULL;
|
|
|
|
- }
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ tp = tcf_chain_tp_find(chain, &chain_info, protocol,
|
|
|
|
+ prio, prio_allocate);
|
|
|
|
+ if (IS_ERR(tp)) {
|
|
|
|
+ err = PTR_ERR(tp);
|
|
|
|
+ goto errout;
|
|
}
|
|
}
|
|
|
|
|
|
if (tp == NULL) {
|
|
if (tp == NULL) {
|
|
@@ -335,11 +536,11 @@ replay:
|
|
goto errout;
|
|
goto errout;
|
|
}
|
|
}
|
|
|
|
|
|
- if (!nprio)
|
|
|
|
- nprio = TC_H_MAJ(tcf_auto_prio(rtnl_dereference(*back)));
|
|
|
|
|
|
+ if (prio_allocate)
|
|
|
|
+ prio = tcf_auto_prio(tcf_chain_tp_prev(&chain_info));
|
|
|
|
|
|
tp = tcf_proto_create(nla_data(tca[TCA_KIND]),
|
|
tp = tcf_proto_create(nla_data(tca[TCA_KIND]),
|
|
- protocol, nprio, parent, q);
|
|
|
|
|
|
+ protocol, prio, parent, q, chain);
|
|
if (IS_ERR(tp)) {
|
|
if (IS_ERR(tp)) {
|
|
err = PTR_ERR(tp);
|
|
err = PTR_ERR(tp);
|
|
goto errout;
|
|
goto errout;
|
|
@@ -354,8 +555,7 @@ replay:
|
|
|
|
|
|
if (fh == 0) {
|
|
if (fh == 0) {
|
|
if (n->nlmsg_type == RTM_DELTFILTER && t->tcm_handle == 0) {
|
|
if (n->nlmsg_type == RTM_DELTFILTER && t->tcm_handle == 0) {
|
|
- next = rtnl_dereference(tp->next);
|
|
|
|
- RCU_INIT_POINTER(*back, next);
|
|
|
|
|
|
+ tcf_chain_tp_remove(chain, &chain_info, tp);
|
|
tfilter_notify(net, skb, n, tp, fh,
|
|
tfilter_notify(net, skb, n, tp, fh,
|
|
RTM_DELTFILTER, false);
|
|
RTM_DELTFILTER, false);
|
|
tcf_proto_destroy(tp);
|
|
tcf_proto_destroy(tp);
|
|
@@ -384,11 +584,10 @@ replay:
|
|
err = tp->ops->delete(tp, fh, &last);
|
|
err = tp->ops->delete(tp, fh, &last);
|
|
if (err)
|
|
if (err)
|
|
goto errout;
|
|
goto errout;
|
|
- next = rtnl_dereference(tp->next);
|
|
|
|
tfilter_notify(net, skb, n, tp, t->tcm_handle,
|
|
tfilter_notify(net, skb, n, tp, t->tcm_handle,
|
|
RTM_DELTFILTER, false);
|
|
RTM_DELTFILTER, false);
|
|
if (last) {
|
|
if (last) {
|
|
- RCU_INIT_POINTER(*back, next);
|
|
|
|
|
|
+ tcf_chain_tp_remove(chain, &chain_info, tp);
|
|
tcf_proto_destroy(tp);
|
|
tcf_proto_destroy(tp);
|
|
}
|
|
}
|
|
goto errout;
|
|
goto errout;
|
|
@@ -405,10 +604,8 @@ replay:
|
|
err = tp->ops->change(net, skb, tp, cl, t->tcm_handle, tca, &fh,
|
|
err = tp->ops->change(net, skb, tp, cl, t->tcm_handle, tca, &fh,
|
|
n->nlmsg_flags & NLM_F_CREATE ? TCA_ACT_NOREPLACE : TCA_ACT_REPLACE);
|
|
n->nlmsg_flags & NLM_F_CREATE ? TCA_ACT_NOREPLACE : TCA_ACT_REPLACE);
|
|
if (err == 0) {
|
|
if (err == 0) {
|
|
- if (tp_created) {
|
|
|
|
- RCU_INIT_POINTER(tp->next, rtnl_dereference(*back));
|
|
|
|
- rcu_assign_pointer(*back, tp);
|
|
|
|
- }
|
|
|
|
|
|
+ if (tp_created)
|
|
|
|
+ tcf_chain_tp_insert(chain, &chain_info, tp);
|
|
tfilter_notify(net, skb, n, tp, fh, RTM_NEWTFILTER, false);
|
|
tfilter_notify(net, skb, n, tp, fh, RTM_NEWTFILTER, false);
|
|
} else {
|
|
} else {
|
|
if (tp_created)
|
|
if (tp_created)
|
|
@@ -416,6 +613,8 @@ replay:
|
|
}
|
|
}
|
|
|
|
|
|
errout:
|
|
errout:
|
|
|
|
+ if (chain)
|
|
|
|
+ tcf_chain_put(chain);
|
|
if (cl)
|
|
if (cl)
|
|
cops->put(q, cl);
|
|
cops->put(q, cl);
|
|
if (err == -EAGAIN)
|
|
if (err == -EAGAIN)
|
|
@@ -444,6 +643,8 @@ static int tcf_fill_node(struct net *net, struct sk_buff *skb,
|
|
tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol);
|
|
tcm->tcm_info = TC_H_MAKE(tp->prio, tp->protocol);
|
|
if (nla_put_string(skb, TCA_KIND, tp->ops->kind))
|
|
if (nla_put_string(skb, TCA_KIND, tp->ops->kind))
|
|
goto nla_put_failure;
|
|
goto nla_put_failure;
|
|
|
|
+ if (nla_put_u32(skb, TCA_CHAIN, tp->chain->index))
|
|
|
|
+ goto nla_put_failure;
|
|
tcm->tcm_handle = fh;
|
|
tcm->tcm_handle = fh;
|
|
if (RTM_DELTFILTER != event) {
|
|
if (RTM_DELTFILTER != event) {
|
|
tcm->tcm_handle = 0;
|
|
tcm->tcm_handle = 0;
|
|
@@ -500,22 +701,76 @@ static int tcf_node_dump(struct tcf_proto *tp, unsigned long n,
|
|
RTM_NEWTFILTER);
|
|
RTM_NEWTFILTER);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static bool tcf_chain_dump(struct tcf_chain *chain, struct sk_buff *skb,
|
|
|
|
+ struct netlink_callback *cb,
|
|
|
|
+ long index_start, long *p_index)
|
|
|
|
+{
|
|
|
|
+ struct net *net = sock_net(skb->sk);
|
|
|
|
+ struct tcmsg *tcm = nlmsg_data(cb->nlh);
|
|
|
|
+ struct tcf_dump_args arg;
|
|
|
|
+ struct tcf_proto *tp;
|
|
|
|
+
|
|
|
|
+ for (tp = rtnl_dereference(chain->filter_chain);
|
|
|
|
+ tp; tp = rtnl_dereference(tp->next), (*p_index)++) {
|
|
|
|
+ if (*p_index < index_start)
|
|
|
|
+ continue;
|
|
|
|
+ if (TC_H_MAJ(tcm->tcm_info) &&
|
|
|
|
+ TC_H_MAJ(tcm->tcm_info) != tp->prio)
|
|
|
|
+ continue;
|
|
|
|
+ if (TC_H_MIN(tcm->tcm_info) &&
|
|
|
|
+ TC_H_MIN(tcm->tcm_info) != tp->protocol)
|
|
|
|
+ continue;
|
|
|
|
+ if (*p_index > index_start)
|
|
|
|
+ memset(&cb->args[1], 0,
|
|
|
|
+ sizeof(cb->args) - sizeof(cb->args[0]));
|
|
|
|
+ if (cb->args[1] == 0) {
|
|
|
|
+ if (tcf_fill_node(net, skb, tp, 0,
|
|
|
|
+ NETLINK_CB(cb->skb).portid,
|
|
|
|
+ cb->nlh->nlmsg_seq, NLM_F_MULTI,
|
|
|
|
+ RTM_NEWTFILTER) <= 0)
|
|
|
|
+ return false;
|
|
|
|
+
|
|
|
|
+ cb->args[1] = 1;
|
|
|
|
+ }
|
|
|
|
+ if (!tp->ops->walk)
|
|
|
|
+ continue;
|
|
|
|
+ arg.w.fn = tcf_node_dump;
|
|
|
|
+ arg.skb = skb;
|
|
|
|
+ arg.cb = cb;
|
|
|
|
+ arg.w.stop = 0;
|
|
|
|
+ arg.w.skip = cb->args[1] - 1;
|
|
|
|
+ arg.w.count = 0;
|
|
|
|
+ tp->ops->walk(tp, &arg.w);
|
|
|
|
+ cb->args[1] = arg.w.count + 1;
|
|
|
|
+ if (arg.w.stop)
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+}
|
|
|
|
+
|
|
/* called with RTNL */
|
|
/* called with RTNL */
|
|
static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
|
|
static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
|
|
{
|
|
{
|
|
struct net *net = sock_net(skb->sk);
|
|
struct net *net = sock_net(skb->sk);
|
|
- int t;
|
|
|
|
- int s_t;
|
|
|
|
|
|
+ struct nlattr *tca[TCA_MAX + 1];
|
|
struct net_device *dev;
|
|
struct net_device *dev;
|
|
struct Qdisc *q;
|
|
struct Qdisc *q;
|
|
- struct tcf_proto *tp, __rcu **chain;
|
|
|
|
|
|
+ struct tcf_block *block;
|
|
|
|
+ struct tcf_chain *chain;
|
|
struct tcmsg *tcm = nlmsg_data(cb->nlh);
|
|
struct tcmsg *tcm = nlmsg_data(cb->nlh);
|
|
unsigned long cl = 0;
|
|
unsigned long cl = 0;
|
|
const struct Qdisc_class_ops *cops;
|
|
const struct Qdisc_class_ops *cops;
|
|
- struct tcf_dump_args arg;
|
|
|
|
|
|
+ long index_start;
|
|
|
|
+ long index;
|
|
|
|
+ int err;
|
|
|
|
|
|
if (nlmsg_len(cb->nlh) < sizeof(*tcm))
|
|
if (nlmsg_len(cb->nlh) < sizeof(*tcm))
|
|
return skb->len;
|
|
return skb->len;
|
|
|
|
+
|
|
|
|
+ err = nlmsg_parse(cb->nlh, sizeof(*tcm), tca, TCA_MAX, NULL, NULL);
|
|
|
|
+ if (err)
|
|
|
|
+ return err;
|
|
|
|
+
|
|
dev = __dev_get_by_index(net, tcm->tcm_ifindex);
|
|
dev = __dev_get_by_index(net, tcm->tcm_ifindex);
|
|
if (!dev)
|
|
if (!dev)
|
|
return skb->len;
|
|
return skb->len;
|
|
@@ -529,56 +784,29 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
|
|
cops = q->ops->cl_ops;
|
|
cops = q->ops->cl_ops;
|
|
if (!cops)
|
|
if (!cops)
|
|
goto errout;
|
|
goto errout;
|
|
- if (cops->tcf_chain == NULL)
|
|
|
|
|
|
+ if (!cops->tcf_block)
|
|
goto errout;
|
|
goto errout;
|
|
if (TC_H_MIN(tcm->tcm_parent)) {
|
|
if (TC_H_MIN(tcm->tcm_parent)) {
|
|
cl = cops->get(q, tcm->tcm_parent);
|
|
cl = cops->get(q, tcm->tcm_parent);
|
|
if (cl == 0)
|
|
if (cl == 0)
|
|
goto errout;
|
|
goto errout;
|
|
}
|
|
}
|
|
- chain = cops->tcf_chain(q, cl);
|
|
|
|
- if (chain == NULL)
|
|
|
|
|
|
+ block = cops->tcf_block(q, cl);
|
|
|
|
+ if (!block)
|
|
goto errout;
|
|
goto errout;
|
|
|
|
|
|
- s_t = cb->args[0];
|
|
|
|
|
|
+ index_start = cb->args[0];
|
|
|
|
+ index = 0;
|
|
|
|
|
|
- for (tp = rtnl_dereference(*chain), t = 0;
|
|
|
|
- tp; tp = rtnl_dereference(tp->next), t++) {
|
|
|
|
- if (t < s_t)
|
|
|
|
- continue;
|
|
|
|
- if (TC_H_MAJ(tcm->tcm_info) &&
|
|
|
|
- TC_H_MAJ(tcm->tcm_info) != tp->prio)
|
|
|
|
- continue;
|
|
|
|
- if (TC_H_MIN(tcm->tcm_info) &&
|
|
|
|
- TC_H_MIN(tcm->tcm_info) != tp->protocol)
|
|
|
|
|
|
+ list_for_each_entry(chain, &block->chain_list, list) {
|
|
|
|
+ if (tca[TCA_CHAIN] &&
|
|
|
|
+ nla_get_u32(tca[TCA_CHAIN]) != chain->index)
|
|
continue;
|
|
continue;
|
|
- if (t > s_t)
|
|
|
|
- memset(&cb->args[1], 0,
|
|
|
|
- sizeof(cb->args)-sizeof(cb->args[0]));
|
|
|
|
- if (cb->args[1] == 0) {
|
|
|
|
- if (tcf_fill_node(net, skb, tp, 0,
|
|
|
|
- NETLINK_CB(cb->skb).portid,
|
|
|
|
- cb->nlh->nlmsg_seq, NLM_F_MULTI,
|
|
|
|
- RTM_NEWTFILTER) <= 0)
|
|
|
|
- break;
|
|
|
|
-
|
|
|
|
- cb->args[1] = 1;
|
|
|
|
- }
|
|
|
|
- if (tp->ops->walk == NULL)
|
|
|
|
- continue;
|
|
|
|
- arg.w.fn = tcf_node_dump;
|
|
|
|
- arg.skb = skb;
|
|
|
|
- arg.cb = cb;
|
|
|
|
- arg.w.stop = 0;
|
|
|
|
- arg.w.skip = cb->args[1] - 1;
|
|
|
|
- arg.w.count = 0;
|
|
|
|
- tp->ops->walk(tp, &arg.w);
|
|
|
|
- cb->args[1] = arg.w.count + 1;
|
|
|
|
- if (arg.w.stop)
|
|
|
|
|
|
+ if (!tcf_chain_dump(chain, skb, cb, index_start, &index))
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
- cb->args[0] = t;
|
|
|
|
|
|
+ cb->args[0] = index;
|
|
|
|
|
|
errout:
|
|
errout:
|
|
if (cl)
|
|
if (cl)
|
|
@@ -608,8 +836,9 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
|
|
struct tc_action *act;
|
|
struct tc_action *act;
|
|
|
|
|
|
if (exts->police && tb[exts->police]) {
|
|
if (exts->police && tb[exts->police]) {
|
|
- act = tcf_action_init_1(net, tb[exts->police], rate_tlv,
|
|
|
|
- "police", ovr, TCA_ACT_BIND);
|
|
|
|
|
|
+ act = tcf_action_init_1(net, tp, tb[exts->police],
|
|
|
|
+ rate_tlv, "police", ovr,
|
|
|
|
+ TCA_ACT_BIND);
|
|
if (IS_ERR(act))
|
|
if (IS_ERR(act))
|
|
return PTR_ERR(act);
|
|
return PTR_ERR(act);
|
|
|
|
|
|
@@ -620,8 +849,8 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
|
|
LIST_HEAD(actions);
|
|
LIST_HEAD(actions);
|
|
int err, i = 0;
|
|
int err, i = 0;
|
|
|
|
|
|
- err = tcf_action_init(net, tb[exts->action], rate_tlv,
|
|
|
|
- NULL, ovr, TCA_ACT_BIND,
|
|
|
|
|
|
+ err = tcf_action_init(net, tp, tb[exts->action],
|
|
|
|
+ rate_tlv, NULL, ovr, TCA_ACT_BIND,
|
|
&actions);
|
|
&actions);
|
|
if (err)
|
|
if (err)
|
|
return err;
|
|
return err;
|