* [patch iproute2] tc: add support for vlan tc action [not found] <reply-to=1415700789-9171-2-git-send-email-jiri@resnulli.us> @ 2014-11-11 10:16 ` Jiri Pirko 2014-11-11 12:35 ` Jamal Hadi Salim 2014-11-11 13:36 ` Jamal Hadi Salim 0 siblings, 2 replies; 7+ messages in thread From: Jiri Pirko @ 2014-11-11 10:16 UTC (permalink / raw) To: netdev Cc: davem, jhs, pshelar, therbert, edumazet, willemb, dborkman, mst, fw, Paul.Durrant, tgraf Signed-off-by: Jiri Pirko <jiri@resnulli.us> --- include/linux/tc_act/tc_vlan.h | 35 +++++++ tc/Makefile | 1 + tc/m_vlan.c | 205 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100644 include/linux/tc_act/tc_vlan.h create mode 100644 tc/m_vlan.c diff --git a/include/linux/tc_act/tc_vlan.h b/include/linux/tc_act/tc_vlan.h new file mode 100644 index 0000000..f7b8d44 --- /dev/null +++ b/include/linux/tc_act/tc_vlan.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef __LINUX_TC_VLAN_H +#define __LINUX_TC_VLAN_H + +#include <linux/pkt_cls.h> + +#define TCA_ACT_VLAN 12 + +#define TCA_VLAN_ACT_POP 1 +#define TCA_VLAN_ACT_PUSH 2 + +struct tc_vlan { + tc_gen; + int v_action; +}; + +enum { + TCA_VLAN_UNSPEC, + TCA_VLAN_TM, + TCA_VLAN_PARMS, + TCA_VLAN_PUSH_VLAN_ID, + TCA_VLAN_PUSH_VLAN_PROTOCOL, + __TCA_VLAN_MAX, +}; +#define TCA_VLAN_MAX (__TCA_VLAN_MAX - 1) + +#endif diff --git a/tc/Makefile b/tc/Makefile index 1ab36c6..830c97d 100644 --- a/tc/Makefile +++ b/tc/Makefile @@ -40,6 +40,7 @@ TCMODULES += m_pedit.o TCMODULES += m_skbedit.o TCMODULES += m_csum.o TCMODULES += m_simple.o +TCMODULES += m_vlan.o TCMODULES += p_ip.o TCMODULES += p_icmp.o TCMODULES += p_tcp.o diff --git a/tc/m_vlan.c b/tc/m_vlan.c new file mode 100644 index 0000000..54c0ce7 --- /dev/null +++ b/tc/m_vlan.c @@ -0,0 +1,205 @@ +/* + * m_vlan.c vlan manipulation module + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * Authors: Jiri Pirko <jiri@resnulli.us> + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include "utils.h" +#include "rt_names.h" +#include "tc_util.h" +#include <linux/tc_act/tc_vlan.h> + +static void explain(void) +{ + fprintf(stderr, "Usage: vlan pop\n"); + fprintf(stderr, " vlan push [ protocol VLANPROTO ] id VLANID\n"); +} + +static void usage(void) +{ + explain(); + exit(-1); +} + +static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p, + int tca_id, struct nlmsghdr *n) +{ + int argc = *argc_p; + char **argv = *argv_p; + struct rtattr *tail; + int action = 0; + __u16 id; + int id_set = 0; + __u16 proto; + int proto_set = 0; + struct tc_vlan parm = { 0 }; + + if (matches(*argv, "vlan") != 0) + return -1; + + NEXT_ARG(); + + while (argc > 0) { + if (matches(*argv, "pop") == 0) { + if (action) { + fprintf(stderr, "unexpexted \"%s\" - action already specified\n", + *argv); + explain(); + return -1; + } + action = TCA_VLAN_ACT_POP; + } else if (matches(*argv, "push") == 0) { + if (action) { + fprintf(stderr, "unexpexted \"%s\" - action already specified\n", + *argv); + explain(); + return -1; + } + action = TCA_VLAN_ACT_PUSH; + } else if (matches(*argv, "id") == 0) { + if (action != TCA_VLAN_ACT_PUSH) { + fprintf(stderr, "\"%s\" is only valid for push\n", + *argv); + explain(); + return -1; + } + NEXT_ARG(); + if (get_u16(&id, *argv, 0)) + invarg("id is invalid", *argv); + id_set = 1; + } else if (matches(*argv, "protocol") == 0) { + if (action != TCA_VLAN_ACT_PUSH) { + fprintf(stderr, "\"%s\" is only valid for push\n", + *argv); + explain(); + return -1; + } + NEXT_ARG(); + if (ll_proto_a2n(&proto, *argv)) + invarg("protocol is invalid", *argv); + proto_set = 1; + } else if (matches(*argv, "help") == 0) { + usage(); + } else { + break; + } + argc--; + argv++; + } + + parm.action = TC_ACT_PIPE; + if (argc) { + if (matches(*argv, "reclassify") == 0) { + parm.action = TC_ACT_RECLASSIFY; + NEXT_ARG(); + } else if (matches(*argv, "pipe") == 0) { + parm.action = TC_ACT_PIPE; + NEXT_ARG(); + } else if (matches(*argv, "drop") == 0 || + matches(*argv, "shot") == 0) { + parm.action = TC_ACT_SHOT; + NEXT_ARG(); + } else if (matches(*argv, "continue") == 0) { + parm.action = TC_ACT_UNSPEC; + NEXT_ARG(); + } else if (matches(*argv, "pass") == 0) { + parm.action = TC_ACT_OK; + NEXT_ARG(); + } + } + + if (argc) { + if (matches(*argv, "index") == 0) { + NEXT_ARG(); + if (get_u32(&parm.index, *argv, 10)) { + fprintf(stderr, "Pedit: Illegal \"index\"\n"); + return -1; + } + argc--; + argv++; + } + } + + if (action == TCA_VLAN_ACT_PUSH && !id_set) { + fprintf(stderr, "id needs to be set for push\n"); + explain(); + return -1; + } + + parm.v_action = action; + tail = NLMSG_TAIL(n); + addattr_l(n, MAX_MSG, tca_id, NULL, 0); + addattr_l(n, MAX_MSG, TCA_VLAN_PARMS, &parm, sizeof(parm)); + if (id_set) + addattr_l(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_ID, &id, 2); + if (proto_set) + addattr_l(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_PROTOCOL, &proto, 2); + tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail; + + *argc_p = argc; + *argv_p = argv; + return 0; +} + +static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg) +{ + struct rtattr *tb[TCA_VLAN_MAX + 1]; + __u16 val; + struct tc_vlan *parm; + + if (arg == NULL) + return -1; + + parse_rtattr_nested(tb, TCA_VLAN_MAX, arg); + + if (!tb[TCA_VLAN_PARMS]) { + fprintf(f, "[NULL vlan parameters]"); + return -1; + } + parm = RTA_DATA(tb[TCA_VLAN_PARMS]); + + fprintf(f, " vlan"); + + switch(parm->v_action) { + case TCA_VLAN_ACT_POP: + fprintf(f, " pop"); + break; + case TCA_VLAN_ACT_PUSH: + fprintf(f, " push"); + if (tb[TCA_VLAN_PUSH_VLAN_ID]) { + val = rta_getattr_u16(tb[TCA_VLAN_PUSH_VLAN_ID]); + fprintf(f, " id %d", val); + } + if (tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]) { + val = rta_getattr_u16(tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]); + fprintf(f, " proto %04x", val); + } + break; + } + + if (show_stats) { + if (tb[TCA_VLAN_TM]) { + struct tcf_t *tm = RTA_DATA(tb[TCA_VLAN_TM]); + print_tm(f, tm); + } + } + + fprintf(f, "\n "); + + return 0; +} + +struct action_util vlan_action_util = { + .id = "vlan", + .parse_aopt = parse_vlan, + .print_aopt = print_vlan, +}; -- 1.9.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [patch iproute2] tc: add support for vlan tc action 2014-11-11 10:16 ` [patch iproute2] tc: add support for vlan tc action Jiri Pirko @ 2014-11-11 12:35 ` Jamal Hadi Salim 2014-11-11 13:36 ` Jamal Hadi Salim 1 sibling, 0 replies; 7+ messages in thread From: Jamal Hadi Salim @ 2014-11-11 12:35 UTC (permalink / raw) To: Jiri Pirko, netdev Cc: davem, pshelar, therbert, edumazet, willemb, dborkman, mst, fw, Paul.Durrant, tgraf On 11/11/14 05:16, Jiri Pirko wrote: > Signed-off-by: Jiri Pirko <jiri@resnulli.us> Looks good. Acked-by: Jamal Hadi Salim <jhs@mojatatu.com> cheers, jamal ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch iproute2] tc: add support for vlan tc action 2014-11-11 10:16 ` [patch iproute2] tc: add support for vlan tc action Jiri Pirko 2014-11-11 12:35 ` Jamal Hadi Salim @ 2014-11-11 13:36 ` Jamal Hadi Salim 2014-11-11 13:46 ` Jiri Pirko 1 sibling, 1 reply; 7+ messages in thread From: Jamal Hadi Salim @ 2014-11-11 13:36 UTC (permalink / raw) To: Jiri Pirko, netdev Cc: davem, pshelar, therbert, edumazet, willemb, dborkman, mst, fw, Paul.Durrant, tgraf, Stephen Hemminger [-- Attachment #1: Type: text/plain, Size: 115 bytes --] Ive run out of time - but will test; so far looks good. Attached a small patchlet on top of yours. cheers, jamal [-- Attachment #2: patch-for-jiri --] [-- Type: text/plain, Size: 1493 bytes --] diff --git a/tc/m_vlan.c b/tc/m_vlan.c index 54c0ce7..2755e20 100644 --- a/tc/m_vlan.c +++ b/tc/m_vlan.c @@ -13,6 +13,7 @@ #include <stdlib.h> #include <unistd.h> #include <string.h> +#include <linux/if_ether.h> #include "utils.h" #include "rt_names.h" #include "tc_util.h" @@ -22,6 +23,8 @@ static void explain(void) { fprintf(stderr, "Usage: vlan pop\n"); fprintf(stderr, " vlan push [ protocol VLANPROTO ] id VLANID\n"); + fprintf(stderr, " VLANPROTO is one of 802.1Q or 802.1ad\n"); + fprintf(stderr, " with default: 802.1Q\n"); } static void usage(void) @@ -121,7 +124,7 @@ static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p, if (matches(*argv, "index") == 0) { NEXT_ARG(); if (get_u32(&parm.index, *argv, 10)) { - fprintf(stderr, "Pedit: Illegal \"index\"\n"); + fprintf(stderr, "vlan: Illegal \"index\"\n"); return -1; } argc--; @@ -141,8 +144,15 @@ static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p, addattr_l(n, MAX_MSG, TCA_VLAN_PARMS, &parm, sizeof(parm)); if (id_set) addattr_l(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_ID, &id, 2); - if (proto_set) + if (proto_set) { + if (proto != ETH_P_8021Q && proto != ETH_P_8021AD) { + fprintf(stderr, "protocol id 0x%x not supported\n", proto); + explain(); + return -1; + } + addattr_l(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_PROTOCOL, &proto, 2); + } tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail; *argc_p = argc; ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [patch iproute2] tc: add support for vlan tc action 2014-11-11 13:36 ` Jamal Hadi Salim @ 2014-11-11 13:46 ` Jiri Pirko 0 siblings, 0 replies; 7+ messages in thread From: Jiri Pirko @ 2014-11-11 13:46 UTC (permalink / raw) To: Jamal Hadi Salim Cc: netdev, davem, pshelar, therbert, edumazet, willemb, dborkman, mst, fw, Paul.Durrant, tgraf, Stephen Hemminger Tue, Nov 11, 2014 at 02:36:42PM CET, jhs@mojatatu.com wrote: > >Ive run out of time - but will test; so far looks good. >Attached a small patchlet on top of yours. Will squash it in and send v2. > >cheers, >jamal >diff --git a/tc/m_vlan.c b/tc/m_vlan.c >index 54c0ce7..2755e20 100644 >--- a/tc/m_vlan.c >+++ b/tc/m_vlan.c >@@ -13,6 +13,7 @@ > #include <stdlib.h> > #include <unistd.h> > #include <string.h> >+#include <linux/if_ether.h> > #include "utils.h" > #include "rt_names.h" > #include "tc_util.h" >@@ -22,6 +23,8 @@ static void explain(void) > { > fprintf(stderr, "Usage: vlan pop\n"); > fprintf(stderr, " vlan push [ protocol VLANPROTO ] id VLANID\n"); >+ fprintf(stderr, " VLANPROTO is one of 802.1Q or 802.1ad\n"); >+ fprintf(stderr, " with default: 802.1Q\n"); > } > > static void usage(void) >@@ -121,7 +124,7 @@ static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p, > if (matches(*argv, "index") == 0) { > NEXT_ARG(); > if (get_u32(&parm.index, *argv, 10)) { >- fprintf(stderr, "Pedit: Illegal \"index\"\n"); >+ fprintf(stderr, "vlan: Illegal \"index\"\n"); > return -1; > } > argc--; >@@ -141,8 +144,15 @@ static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p, > addattr_l(n, MAX_MSG, TCA_VLAN_PARMS, &parm, sizeof(parm)); > if (id_set) > addattr_l(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_ID, &id, 2); >- if (proto_set) >+ if (proto_set) { >+ if (proto != ETH_P_8021Q && proto != ETH_P_8021AD) { >+ fprintf(stderr, "protocol id 0x%x not supported\n", proto); >+ explain(); >+ return -1; >+ } >+ > addattr_l(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_PROTOCOL, &proto, 2); >+ } > tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail; > > *argc_p = argc; ^ permalink raw reply [flat|nested] 7+ messages in thread
* [patch net-next v2 4/4] sched: introduce vlan action @ 2014-11-12 14:52 Jiri Pirko 2014-11-12 14:55 ` [patch iproute2] tc: add support for vlan tc action Jiri Pirko 0 siblings, 1 reply; 7+ messages in thread From: Jiri Pirko @ 2014-11-12 14:52 UTC (permalink / raw) To: netdev Cc: davem, jhs, pshelar, therbert, edumazet, willemb, dborkman, mst, fw, Paul.Durrant, tgraf This tc action allows to work with vlan tagged skbs. Two supported sub-actions are header pop and header push. Signed-off-by: Jiri Pirko <jiri@resnulli.us> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com> --- v1->v2: - fixed protocol dumping in tcf_vlan_dump include/net/tc_act/tc_vlan.h | 27 +++++ include/uapi/linux/tc_act/tc_vlan.h | 35 ++++++ net/sched/Kconfig | 11 ++ net/sched/Makefile | 1 + net/sched/act_vlan.c | 207 ++++++++++++++++++++++++++++++++++++ 5 files changed, 281 insertions(+) create mode 100644 include/net/tc_act/tc_vlan.h create mode 100644 include/uapi/linux/tc_act/tc_vlan.h create mode 100644 net/sched/act_vlan.c diff --git a/include/net/tc_act/tc_vlan.h b/include/net/tc_act/tc_vlan.h new file mode 100644 index 0000000..c809c1d --- /dev/null +++ b/include/net/tc_act/tc_vlan.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef __NET_TC_VLAN_H +#define __NET_TC_VLAN_H + +#include <net/act_api.h> + +#define VLAN_F_POP 0x1 +#define VLAN_F_PUSH 0x2 + +struct tcf_vlan { + struct tcf_common common; + int tcfv_action; + __be16 tcfv_push_vid; + __be16 tcfv_push_proto; +}; +#define to_vlan(a) \ + container_of(a->priv, struct tcf_vlan, common) + +#endif /* __NET_TC_VLAN_H */ diff --git a/include/uapi/linux/tc_act/tc_vlan.h b/include/uapi/linux/tc_act/tc_vlan.h new file mode 100644 index 0000000..f7b8d44 --- /dev/null +++ b/include/uapi/linux/tc_act/tc_vlan.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef __LINUX_TC_VLAN_H +#define __LINUX_TC_VLAN_H + +#include <linux/pkt_cls.h> + +#define TCA_ACT_VLAN 12 + +#define TCA_VLAN_ACT_POP 1 +#define TCA_VLAN_ACT_PUSH 2 + +struct tc_vlan { + tc_gen; + int v_action; +}; + +enum { + TCA_VLAN_UNSPEC, + TCA_VLAN_TM, + TCA_VLAN_PARMS, + TCA_VLAN_PUSH_VLAN_ID, + TCA_VLAN_PUSH_VLAN_PROTOCOL, + __TCA_VLAN_MAX, +}; +#define TCA_VLAN_MAX (__TCA_VLAN_MAX - 1) + +#endif diff --git a/net/sched/Kconfig b/net/sched/Kconfig index a1a8e29..88618f8 100644 --- a/net/sched/Kconfig +++ b/net/sched/Kconfig @@ -686,6 +686,17 @@ config NET_ACT_CSUM To compile this code as a module, choose M here: the module will be called act_csum. +config NET_ACT_VLAN + tristate "Vlan manipulation" + depends on NET_CLS_ACT + ---help--- + Say Y here to push or pop vlan headers. + + If unsure, say N. + + To compile this code as a module, choose M here: the + module will be called act_vlan. + config NET_CLS_IND bool "Incoming device classification" depends on NET_CLS_U32 || NET_CLS_FW diff --git a/net/sched/Makefile b/net/sched/Makefile index 0a869a1..679f24a 100644 --- a/net/sched/Makefile +++ b/net/sched/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_NET_ACT_PEDIT) += act_pedit.o obj-$(CONFIG_NET_ACT_SIMP) += act_simple.o obj-$(CONFIG_NET_ACT_SKBEDIT) += act_skbedit.o obj-$(CONFIG_NET_ACT_CSUM) += act_csum.o +obj-$(CONFIG_NET_ACT_VLAN) += act_vlan.o obj-$(CONFIG_NET_SCH_FIFO) += sch_fifo.o obj-$(CONFIG_NET_SCH_CBQ) += sch_cbq.o obj-$(CONFIG_NET_SCH_HTB) += sch_htb.o diff --git a/net/sched/act_vlan.c b/net/sched/act_vlan.c new file mode 100644 index 0000000..d735ecf --- /dev/null +++ b/net/sched/act_vlan.c @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/skbuff.h> +#include <linux/rtnetlink.h> +#include <linux/if_vlan.h> +#include <net/netlink.h> +#include <net/pkt_sched.h> + +#include <linux/tc_act/tc_vlan.h> +#include <net/tc_act/tc_vlan.h> + +#define VLAN_TAB_MASK 15 + +static int tcf_vlan(struct sk_buff *skb, const struct tc_action *a, + struct tcf_result *res) +{ + struct tcf_vlan *v = a->priv; + int action; + int err; + + spin_lock(&v->tcf_lock); + v->tcf_tm.lastuse = jiffies; + bstats_update(&v->tcf_bstats, skb); + action = v->tcf_action; + + switch (v->tcfv_action) { + case TCA_VLAN_ACT_POP: + err = skb_vlan_pop(skb); + if (err) + goto drop; + break; + case TCA_VLAN_ACT_PUSH: + err = skb_vlan_push(skb, v->tcfv_push_proto, v->tcfv_push_vid); + if (err) + goto drop; + break; + default: + BUG(); + } + + goto unlock; + +drop: + action = TC_ACT_SHOT; + v->tcf_qstats.drops++; +unlock: + spin_unlock(&v->tcf_lock); + return action; +} + +static const struct nla_policy vlan_policy[TCA_VLAN_MAX + 1] = { + [TCA_VLAN_PARMS] = { .len = sizeof(struct tc_vlan) }, + [TCA_VLAN_PUSH_VLAN_ID] = { .type = NLA_U16 }, + [TCA_VLAN_PUSH_VLAN_PROTOCOL] = { .type = NLA_U16 }, +}; + +static int tcf_vlan_init(struct net *net, struct nlattr *nla, + struct nlattr *est, struct tc_action *a, + int ovr, int bind) +{ + struct nlattr *tb[TCA_VLAN_MAX + 1]; + struct tc_vlan *parm; + struct tcf_vlan *v; + int action; + __be16 push_vid = 0; + __be16 push_proto = 0; + int ret = 0; + int err; + + if (!nla) + return -EINVAL; + + err = nla_parse_nested(tb, TCA_VLAN_MAX, nla, vlan_policy); + if (err < 0) + return err; + + if (!tb[TCA_VLAN_PARMS]) + return -EINVAL; + parm = nla_data(tb[TCA_VLAN_PARMS]); + switch (parm->v_action) { + case TCA_VLAN_ACT_POP: + break; + case TCA_VLAN_ACT_PUSH: + if (!tb[TCA_VLAN_PUSH_VLAN_ID]) + return -EINVAL; + push_vid = nla_get_u16(tb[TCA_VLAN_PUSH_VLAN_ID]); + if (push_vid >= VLAN_VID_MASK) + return -ERANGE; + + if (tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]) { + push_proto = nla_get_be16(tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]); + switch (push_proto) { + case htons(ETH_P_8021Q): + case htons(ETH_P_8021AD): + break; + default: + return -EPROTONOSUPPORT; + } + } else { + push_proto = htons(ETH_P_8021Q); + } + break; + default: + return -EINVAL; + } + action = parm->v_action; + + if (!tcf_hash_check(parm->index, a, bind)) { + ret = tcf_hash_create(parm->index, est, a, sizeof(*v), bind); + if (ret) + return ret; + + ret = ACT_P_CREATED; + } else { + if (bind) + return 0; + tcf_hash_release(a, bind); + if (!ovr) + return -EEXIST; + } + + v = to_vlan(a); + + spin_lock_bh(&v->tcf_lock); + + v->tcfv_action = action; + v->tcfv_push_vid = push_vid; + v->tcfv_push_proto = push_proto; + + v->tcf_action = parm->action; + + spin_unlock_bh(&v->tcf_lock); + + if (ret == ACT_P_CREATED) + tcf_hash_insert(a); + return ret; +} + +static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a, + int bind, int ref) +{ + unsigned char *b = skb_tail_pointer(skb); + struct tcf_vlan *v = a->priv; + struct tc_vlan opt = { + .index = v->tcf_index, + .refcnt = v->tcf_refcnt - ref, + .bindcnt = v->tcf_bindcnt - bind, + .action = v->tcf_action, + .v_action = v->tcfv_action, + }; + struct tcf_t t; + + if (nla_put(skb, TCA_VLAN_PARMS, sizeof(opt), &opt)) + goto nla_put_failure; + + if (v->tcfv_action == TCA_VLAN_ACT_PUSH && + (nla_put_u16(skb, TCA_VLAN_PUSH_VLAN_ID, v->tcfv_push_vid) || + nla_put_be16(skb, TCA_VLAN_PUSH_VLAN_PROTOCOL, v->tcfv_push_proto))) + goto nla_put_failure; + + t.install = jiffies_to_clock_t(jiffies - v->tcf_tm.install); + t.lastuse = jiffies_to_clock_t(jiffies - v->tcf_tm.lastuse); + t.expires = jiffies_to_clock_t(v->tcf_tm.expires); + if (nla_put(skb, TCA_VLAN_TM, sizeof(t), &t)) + goto nla_put_failure; + return skb->len; + +nla_put_failure: + nlmsg_trim(skb, b); + return -1; +} + +static struct tc_action_ops act_vlan_ops = { + .kind = "vlan", + .type = TCA_ACT_VLAN, + .owner = THIS_MODULE, + .act = tcf_vlan, + .dump = tcf_vlan_dump, + .init = tcf_vlan_init, +}; + +static int __init vlan_init_module(void) +{ + return tcf_register_action(&act_vlan_ops, VLAN_TAB_MASK); +} + +static void __exit vlan_cleanup_module(void) +{ + tcf_unregister_action(&act_vlan_ops); +} + +module_init(vlan_init_module); +module_exit(vlan_cleanup_module); + +MODULE_AUTHOR("Jiri Pirko <jiri@resnulli.us>"); +MODULE_DESCRIPTION("vlan manipulation actions"); +MODULE_LICENSE("GPL v2"); -- 1.9.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [patch iproute2] tc: add support for vlan tc action 2014-11-12 14:52 [patch net-next v2 4/4] sched: introduce vlan action Jiri Pirko @ 2014-11-12 14:55 ` Jiri Pirko 2014-11-16 20:19 ` Jamal Hadi Salim 0 siblings, 1 reply; 7+ messages in thread From: Jiri Pirko @ 2014-11-12 14:55 UTC (permalink / raw) To: netdev Cc: davem, jhs, pshelar, therbert, edumazet, willemb, dborkman, mst, fw, Paul.Durrant, tgraf Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com> Signed-off-by: Jiri Pirko <jiri@resnulli.us> v1->v2: - included changes suggested by Jamal --- include/linux/tc_act/tc_vlan.h | 35 +++++++ tc/Makefile | 1 + tc/m_vlan.c | 221 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 257 insertions(+) create mode 100644 include/linux/tc_act/tc_vlan.h create mode 100644 tc/m_vlan.c diff --git a/include/linux/tc_act/tc_vlan.h b/include/linux/tc_act/tc_vlan.h new file mode 100644 index 0000000..f7b8d44 --- /dev/null +++ b/include/linux/tc_act/tc_vlan.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014 Jiri Pirko <jiri@resnulli.us> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#ifndef __LINUX_TC_VLAN_H +#define __LINUX_TC_VLAN_H + +#include <linux/pkt_cls.h> + +#define TCA_ACT_VLAN 12 + +#define TCA_VLAN_ACT_POP 1 +#define TCA_VLAN_ACT_PUSH 2 + +struct tc_vlan { + tc_gen; + int v_action; +}; + +enum { + TCA_VLAN_UNSPEC, + TCA_VLAN_TM, + TCA_VLAN_PARMS, + TCA_VLAN_PUSH_VLAN_ID, + TCA_VLAN_PUSH_VLAN_PROTOCOL, + __TCA_VLAN_MAX, +}; +#define TCA_VLAN_MAX (__TCA_VLAN_MAX - 1) + +#endif diff --git a/tc/Makefile b/tc/Makefile index 1ab36c6..830c97d 100644 --- a/tc/Makefile +++ b/tc/Makefile @@ -40,6 +40,7 @@ TCMODULES += m_pedit.o TCMODULES += m_skbedit.o TCMODULES += m_csum.o TCMODULES += m_simple.o +TCMODULES += m_vlan.o TCMODULES += p_ip.o TCMODULES += p_icmp.o TCMODULES += p_tcp.o diff --git a/tc/m_vlan.c b/tc/m_vlan.c new file mode 100644 index 0000000..872bf72 --- /dev/null +++ b/tc/m_vlan.c @@ -0,0 +1,221 @@ +/* + * m_vlan.c vlan manipulation module + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * Authors: Jiri Pirko <jiri@resnulli.us> + */ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <linux/if_ether.h> +#include "utils.h" +#include "rt_names.h" +#include "tc_util.h" +#include <linux/tc_act/tc_vlan.h> + +static void explain(void) +{ + fprintf(stderr, "Usage: vlan pop\n"); + fprintf(stderr, " vlan push [ protocol VLANPROTO ] id VLANID\n"); + fprintf(stderr, " VLANPROTO is one of 802.1Q or 802.1AD\n"); + fprintf(stderr, " with default: 802.1Q\n"); +} + +static void usage(void) +{ + explain(); + exit(-1); +} + +static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p, + int tca_id, struct nlmsghdr *n) +{ + int argc = *argc_p; + char **argv = *argv_p; + struct rtattr *tail; + int action = 0; + __u16 id; + int id_set = 0; + __u16 proto; + int proto_set = 0; + struct tc_vlan parm = { 0 }; + + if (matches(*argv, "vlan") != 0) + return -1; + + NEXT_ARG(); + + while (argc > 0) { + if (matches(*argv, "pop") == 0) { + if (action) { + fprintf(stderr, "unexpexted \"%s\" - action already specified\n", + *argv); + explain(); + return -1; + } + action = TCA_VLAN_ACT_POP; + } else if (matches(*argv, "push") == 0) { + if (action) { + fprintf(stderr, "unexpexted \"%s\" - action already specified\n", + *argv); + explain(); + return -1; + } + action = TCA_VLAN_ACT_PUSH; + } else if (matches(*argv, "id") == 0) { + if (action != TCA_VLAN_ACT_PUSH) { + fprintf(stderr, "\"%s\" is only valid for push\n", + *argv); + explain(); + return -1; + } + NEXT_ARG(); + if (get_u16(&id, *argv, 0)) + invarg("id is invalid", *argv); + id_set = 1; + } else if (matches(*argv, "protocol") == 0) { + if (action != TCA_VLAN_ACT_PUSH) { + fprintf(stderr, "\"%s\" is only valid for push\n", + *argv); + explain(); + return -1; + } + NEXT_ARG(); + if (ll_proto_a2n(&proto, *argv)) + invarg("protocol is invalid", *argv); + proto_set = 1; + } else if (matches(*argv, "help") == 0) { + usage(); + } else { + break; + } + argc--; + argv++; + } + + parm.action = TC_ACT_PIPE; + if (argc) { + if (matches(*argv, "reclassify") == 0) { + parm.action = TC_ACT_RECLASSIFY; + NEXT_ARG(); + } else if (matches(*argv, "pipe") == 0) { + parm.action = TC_ACT_PIPE; + NEXT_ARG(); + } else if (matches(*argv, "drop") == 0 || + matches(*argv, "shot") == 0) { + parm.action = TC_ACT_SHOT; + NEXT_ARG(); + } else if (matches(*argv, "continue") == 0) { + parm.action = TC_ACT_UNSPEC; + NEXT_ARG(); + } else if (matches(*argv, "pass") == 0) { + parm.action = TC_ACT_OK; + NEXT_ARG(); + } + } + + if (argc) { + if (matches(*argv, "index") == 0) { + NEXT_ARG(); + if (get_u32(&parm.index, *argv, 10)) { + fprintf(stderr, "vlan: Illegal \"index\"\n"); + return -1; + } + argc--; + argv++; + } + } + + if (action == TCA_VLAN_ACT_PUSH && !id_set) { + fprintf(stderr, "id needs to be set for push\n"); + explain(); + return -1; + } + + parm.v_action = action; + tail = NLMSG_TAIL(n); + addattr_l(n, MAX_MSG, tca_id, NULL, 0); + addattr_l(n, MAX_MSG, TCA_VLAN_PARMS, &parm, sizeof(parm)); + if (id_set) + addattr_l(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_ID, &id, 2); + if (proto_set) { + if (proto != htons(ETH_P_8021Q) && + proto != htons(ETH_P_8021AD)) { + fprintf(stderr, "protocol not supported\n"); + explain(); + return -1; + } + + addattr_l(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_PROTOCOL, &proto, 2); + } + tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail; + + *argc_p = argc; + *argv_p = argv; + return 0; +} + +static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg) +{ + SPRINT_BUF(b1); + struct rtattr *tb[TCA_VLAN_MAX + 1]; + __u16 val; + struct tc_vlan *parm; + + if (arg == NULL) + return -1; + + parse_rtattr_nested(tb, TCA_VLAN_MAX, arg); + + if (!tb[TCA_VLAN_PARMS]) { + fprintf(f, "[NULL vlan parameters]"); + return -1; + } + parm = RTA_DATA(tb[TCA_VLAN_PARMS]); + + fprintf(f, " vlan"); + + switch(parm->v_action) { + case TCA_VLAN_ACT_POP: + fprintf(f, " pop"); + break; + case TCA_VLAN_ACT_PUSH: + fprintf(f, " push"); + if (tb[TCA_VLAN_PUSH_VLAN_ID]) { + val = rta_getattr_u16(tb[TCA_VLAN_PUSH_VLAN_ID]); + fprintf(f, " id %u", val); + } + if (tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]) { + fprintf(f, " protocol %s", + ll_proto_n2a(rta_getattr_u16(tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]), + b1, sizeof(b1))); + } + break; + } + + fprintf(f, "\n\t index %d ref %d bind %d", parm->index, parm->refcnt, + parm->bindcnt); + + if (show_stats) { + if (tb[TCA_VLAN_TM]) { + struct tcf_t *tm = RTA_DATA(tb[TCA_VLAN_TM]); + print_tm(f, tm); + } + } + + fprintf(f, "\n "); + + return 0; +} + +struct action_util vlan_action_util = { + .id = "vlan", + .parse_aopt = parse_vlan, + .print_aopt = print_vlan, +}; -- 1.9.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [patch iproute2] tc: add support for vlan tc action 2014-11-12 14:55 ` [patch iproute2] tc: add support for vlan tc action Jiri Pirko @ 2014-11-16 20:19 ` Jamal Hadi Salim 2014-11-18 20:48 ` Jiri Pirko 0 siblings, 1 reply; 7+ messages in thread From: Jamal Hadi Salim @ 2014-11-16 20:19 UTC (permalink / raw) To: Jiri Pirko, netdev Cc: davem, pshelar, therbert, edumazet, willemb, dborkman, mst, fw, Paul.Durrant, tgraf On 11/12/14 09:55, Jiri Pirko wrote: > Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com> > Signed-off-by: Jiri Pirko <jiri@resnulli.us> > Latest patches work great. If you want you can include these notes in the iproute2 commit log. There is only one small doubt when i add two vlan tags(Q followed by QandQ). Look at the very end of the text i have below... cheers, jamal --- export TC=/media/MT1/other-gits/iproute2-jiri/tc/tc export ETH=eth0 #index supplied by kernel sudo $TC actions add action vlan pop #explicit add with our index sudo $TC actions add action vlan pop index 10 sudo $TC actions add action vlan push id 123 sudo $TC actions add action vlan push id 456 protocol 802.1Q sudo $TC actions add action vlan push id 789 protocol 802.1ad sudo $TC actions ls action vlan ------ expect something like ---- action order 0: vlan pop index 1 ref 1 bind 0 action order 1: vlan push id 123 protocol 802.1Q index 2 ref 1 bind 0 action order 2: vlan push id 456 protocol 802.1Q index 3 ref 1 bind 0 action order 3: vlan push id 789 protocol 802.1ad index 4 ref 1 bind 0 action order 4: vlan pop index 10 ref 1 bind 0 ------- #show stats sudo $TC -s actions ls action vlan ------- action order 0: vlan pop index 1 ref 1 bind 0 installed 78 sec used 78 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 action order 1: vlan push id 123 protocol 802.1Q index 2 ref 1 bind 0 installed 44 sec used 44 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 action order 2: vlan push id 456 protocol 802.1Q index 3 ref 1 bind 0 installed 42 sec used 42 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 action order 3: vlan push id 789 protocol 802.1ad index 4 ref 1 bind 0 installed 39 sec used 39 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 action order 4: vlan pop index 10 ref 1 bind 0 installed 47 sec used 47 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 ----- sudo $TC actions flush action vlan #expect all actions to be gone.. sudo $TC actions ls action vlan #lets bind actions to filters... sudo ip li add dev dummy0 type dummy sudo ifconfig dummy0 up # sudo tc qdisc del dev $ETH ingress sudo tc qdisc add dev $ETH ingress # sudo $TC filter add dev $ETH parent ffff: pref 11 protocol ip \ u32 match ip src 10.0.0.1 flowid 1:1 \ action vlan push id 123 \ action mirred egress redirect dev dummy0 window 1> sudo tcpdump -n -i dummy0 -e -X window 2> ping -c 1 10.0.0.1 Expect something like: 52:54:00:c3:4b:c5 > 02:00:00:22:01:01, ethertype 802.1Q (0x8100), length 102: vlan 123, p 0, ethertype IPv4, ... #now look at the stats.. sudo $TC -s filter ls dev $ETH parent ffff: protocol ip # sudo $TC filter add dev $ETH parent ffff: pref 12 protocol ip \ u32 match ip src 10.0.0.2 flowid 1:2 \ action vlan push id 456 protocol 802.1Q \ action mirred egress redirect dev dummy0 sudo tcpdump -n -i dummy0 -X -e ping -c 1 10.0.0.2 #look at the stats.. sudo $TC -s filter ls dev $ETH parent ffff: protocol ip # sudo $TC filter add dev $ETH parent ffff: pref 13 protocol ip \ u32 match ip src 10.0.0.13 flowid 1:13 \ action vlan push id 789 protocol 802.1ad \ action mirred egress redirect dev dummy0 ping -c 1 10.0.0.2 sudo tcpdump -n -i dummy0 -X -e Expect ... 52:54:00:c3:4b:c5 > 02:00:00:22:01:01, ethertype 802.1Q-QinQ (0x88a8), length 102: vlan 789, p 0, ethertype IPv4,,, # sudo $TC -s filter ls dev $ETH parent 1: protocol ip # # Speaking in New Brunswickian: # For shits and giggles lets add two vlans ... # match all pings this time... # sudo $TC filter add dev $ETH parent ffff: pref 11 protocol ip u32 \ match ip protocol 1 0xff flowid 1:1 \ action vlan push id 123 \ action vlan push id 789 protocol 802.1ad \ action mirred egress redirect dev dummy0 sudo $TC -s filter ls dev $ETH parent ffff: protocol ip ------ filter pref 11 u32 filter pref 11 u32 fh 800: ht divisor 1 filter pref 11 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 (rule hit 2 success 0) match 00010000/00ff0000 at 8 (success 0 ) action order 1: vlan push id 123 protocol 802.1Q index 13 ref 1 bind 1 installed 6 sec used 6 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 action order 2: vlan push id 789 protocol 802.1ad index 14 ref 1 bind 1 installed 6 sec used 6 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 action order 3: mirred (Egress Redirect to device dummy0) stolen index 9 ref 1 bind 1 installed 6 sec used 6 sec Action statistics: Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 ---- Send 10 pings to 192.168.100.1 ping 192.168.100.1 -c 10 sudo $TC -s filter ls dev $ETH parent ffff: protocol ip ------ filter pref 11 u32 filter pref 11 u32 fh 800: ht divisor 1 filter pref 11 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 (rule hit 24 success 10) match 00010000/00ff0000 at 8 (success 10 ) action order 1: vlan push id 123 protocol 802.1Q index 13 ref 1 bind 1 installed 143 sec used 60 sec Action statistics: Sent 840 bytes 10 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 action order 2: vlan push id 789 protocol 802.1ad index 14 ref 1 bind 1 installed 143 sec used 60 sec Action statistics: Sent 840 bytes 10 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 action order 3: mirred (Egress Redirect to device dummy0) stolen index 9 ref 1 bind 1 installed 143 sec used 60 sec Action statistics: Sent 840 bytes 10 pkt (dropped 0, overlimits 0 requeues 0) backlog 0b 0p requeues 0 -------- As can be seen, the two vlan tags were supposedly added. I am not sure how well it worked. I see 4 more bytes added. tcpdump doesnt do a good job telling me if it worked... 17:58:31.636816 00:22:01:01:52:54 > 00:00:00:00:02:00, ethertype 802.1Q-QinQ (0x88a8), length 106: vlan 789, p 0, LLC, dsap Unknown (0x44) Group, ssap Null (0x00) Command, ctrl 0x5400: Information, send seq 0, rcv seq 42, Flags [Command], length 88 0x0000: 0000 0000 0200 0022 0101 5254 88a8 0315 0x0010: 00c3 4500 0054 c06b 0000 4001 704c 8100 0x0020: 007b c0a8 6401 c0a8 649f 0000 24b8 027c 0x0030: 000a c7e5 6854 0000 0000 e0b4 0900 0000 0x0040: 0000 1011 1213 1415 1617 1819 1a1b 1c1d 0x0050: 1e1f 2021 2223 2425 2627 2829 2a2b 2c2d 0x0060: 2e2f 3031 3233 3435 3637 Here it is with just 802.1q tag... 17:53:38.198323 52:54:00:c3:4b:c5 > 02:00:00:22:01:01, ethertype 802.1Q (0x8100), length 102: vlan 456, p 0, ethertype IPv4, 192.168.100.1 > 192.168.100.159: ICMP echo reply, id 620, seq 1, length 64 0x0000: 0200 0022 0101 5254 00c3 4bc5 8100 01c8 0x0010: 0800 4500 0054 c052 0000 4001 7065 c0a8 0x0020: 6401 c0a8 649f 0000 6482 026c 0001 a2e4 0x0030: 6854 0000 0000 cc04 0300 0000 0000 1011 0x0040: 1213 1415 1617 1819 1a1b 1c1d 1e1f 2021 0x0050: 2223 2425 2627 2829 2a2b 2c2d 2e2f 3031 0x0060: 3233 3435 3637 ------------ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch iproute2] tc: add support for vlan tc action 2014-11-16 20:19 ` Jamal Hadi Salim @ 2014-11-18 20:48 ` Jiri Pirko 0 siblings, 0 replies; 7+ messages in thread From: Jiri Pirko @ 2014-11-18 20:48 UTC (permalink / raw) To: Jamal Hadi Salim Cc: netdev, davem, pshelar, therbert, edumazet, willemb, dborkman, mst, fw, Paul.Durrant, tgraf Sun, Nov 16, 2014 at 09:19:34PM CET, jhs@mojatatu.com wrote: >On 11/12/14 09:55, Jiri Pirko wrote: >>Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com> >>Signed-off-by: Jiri Pirko <jiri@resnulli.us> >> > >Latest patches work great. If you want you can >include these notes in the iproute2 commit log. > >There is only one small doubt when i add two vlan >tags(Q followed by QandQ). Look at the very end >of the text i have below... I fixed that. Trouble was that tc action finds skb->data in different state so I have to push and pull. Sending v3 shortly. > >cheers, >jamal > >--- >export TC=/media/MT1/other-gits/iproute2-jiri/tc/tc >export ETH=eth0 >#index supplied by kernel >sudo $TC actions add action vlan pop >#explicit add with our index >sudo $TC actions add action vlan pop index 10 >sudo $TC actions add action vlan push id 123 >sudo $TC actions add action vlan push id 456 protocol 802.1Q >sudo $TC actions add action vlan push id 789 protocol 802.1ad > >sudo $TC actions ls action vlan >------ expect something like ---- > action order 0: vlan pop > index 1 ref 1 bind 0 > > action order 1: vlan push id 123 protocol 802.1Q > index 2 ref 1 bind 0 > > action order 2: vlan push id 456 protocol 802.1Q > index 3 ref 1 bind 0 > > action order 3: vlan push id 789 protocol 802.1ad > index 4 ref 1 bind 0 > > action order 4: vlan pop > index 10 ref 1 bind 0 >------- >#show stats >sudo $TC -s actions ls action vlan > >------- > action order 0: vlan pop > index 1 ref 1 bind 0 installed 78 sec used 78 sec > Action statistics: > Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) > backlog 0b 0p requeues 0 > > action order 1: vlan push id 123 protocol 802.1Q > index 2 ref 1 bind 0 installed 44 sec used 44 sec > Action statistics: > Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) > backlog 0b 0p requeues 0 > > action order 2: vlan push id 456 protocol 802.1Q > index 3 ref 1 bind 0 installed 42 sec used 42 sec > Action statistics: > Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) > backlog 0b 0p requeues 0 > > action order 3: vlan push id 789 protocol 802.1ad > index 4 ref 1 bind 0 installed 39 sec used 39 sec > Action statistics: > Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) > backlog 0b 0p requeues 0 > > action order 4: vlan pop > index 10 ref 1 bind 0 installed 47 sec used 47 sec > Action statistics: > Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) > backlog 0b 0p requeues 0 >----- > >sudo $TC actions flush action vlan >#expect all actions to be gone.. >sudo $TC actions ls action vlan > >#lets bind actions to filters... >sudo ip li add dev dummy0 type dummy >sudo ifconfig dummy0 up ># >sudo tc qdisc del dev $ETH ingress >sudo tc qdisc add dev $ETH ingress ># >sudo $TC filter add dev $ETH parent ffff: pref 11 protocol ip \ >u32 match ip src 10.0.0.1 flowid 1:1 \ >action vlan push id 123 \ >action mirred egress redirect dev dummy0 > >window 1> sudo tcpdump -n -i dummy0 -e -X >window 2> ping -c 1 10.0.0.1 > >Expect something like: >52:54:00:c3:4b:c5 > 02:00:00:22:01:01, ethertype 802.1Q (0x8100), length 102: >vlan 123, p 0, ethertype IPv4, ... >#now look at the stats.. >sudo $TC -s filter ls dev $ETH parent ffff: protocol ip ># >sudo $TC filter add dev $ETH parent ffff: pref 12 protocol ip \ >u32 match ip src 10.0.0.2 flowid 1:2 \ >action vlan push id 456 protocol 802.1Q \ >action mirred egress redirect dev dummy0 > >sudo tcpdump -n -i dummy0 -X -e >ping -c 1 10.0.0.2 >#look at the stats.. >sudo $TC -s filter ls dev $ETH parent ffff: protocol ip ># >sudo $TC filter add dev $ETH parent ffff: pref 13 protocol ip \ >u32 match ip src 10.0.0.13 flowid 1:13 \ >action vlan push id 789 protocol 802.1ad \ >action mirred egress redirect dev dummy0 >ping -c 1 10.0.0.2 > >sudo tcpdump -n -i dummy0 -X -e >Expect ... >52:54:00:c3:4b:c5 > 02:00:00:22:01:01, ethertype 802.1Q-QinQ (0x88a8), length >102: vlan 789, p 0, ethertype IPv4,,, ># >sudo $TC -s filter ls dev $ETH parent 1: protocol ip ># ># Speaking in New Brunswickian: ># For shits and giggles lets add two vlans ... ># match all pings this time... ># >sudo $TC filter add dev $ETH parent ffff: pref 11 protocol ip u32 \ >match ip protocol 1 0xff flowid 1:1 \ >action vlan push id 123 \ >action vlan push id 789 protocol 802.1ad \ >action mirred egress redirect dev dummy0 > >sudo $TC -s filter ls dev $ETH parent ffff: protocol ip >------ >filter pref 11 u32 >filter pref 11 u32 fh 800: ht divisor 1 >filter pref 11 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 (rule >hit 2 success 0) > match 00010000/00ff0000 at 8 (success 0 ) > action order 1: vlan push id 123 protocol 802.1Q > index 13 ref 1 bind 1 installed 6 sec used 6 sec > Action statistics: > Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) > backlog 0b 0p requeues 0 > > action order 2: vlan push id 789 protocol 802.1ad > index 14 ref 1 bind 1 installed 6 sec used 6 sec > Action statistics: > Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) > backlog 0b 0p requeues 0 > > action order 3: mirred (Egress Redirect to device dummy0) stolen > index 9 ref 1 bind 1 installed 6 sec used 6 sec > Action statistics: > Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0) > backlog 0b 0p requeues 0 >---- > >Send 10 pings to 192.168.100.1 >ping 192.168.100.1 -c 10 > >sudo $TC -s filter ls dev $ETH parent ffff: protocol ip >------ >filter pref 11 u32 >filter pref 11 u32 fh 800: ht divisor 1 >filter pref 11 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1 (rule >hit 24 success 10) > match 00010000/00ff0000 at 8 (success 10 ) > action order 1: vlan push id 123 protocol 802.1Q > index 13 ref 1 bind 1 installed 143 sec used 60 sec > Action statistics: > Sent 840 bytes 10 pkt (dropped 0, overlimits 0 requeues 0) > backlog 0b 0p requeues 0 > > action order 2: vlan push id 789 protocol 802.1ad > index 14 ref 1 bind 1 installed 143 sec used 60 sec > Action statistics: > Sent 840 bytes 10 pkt (dropped 0, overlimits 0 requeues 0) > backlog 0b 0p requeues 0 > > action order 3: mirred (Egress Redirect to device dummy0) stolen > index 9 ref 1 bind 1 installed 143 sec used 60 sec > Action statistics: > Sent 840 bytes 10 pkt (dropped 0, overlimits 0 requeues 0) > backlog 0b 0p requeues 0 >-------- > >As can be seen, the two vlan tags were supposedly added. I am >not sure how well it worked. I see 4 more bytes added. tcpdump doesnt do >a good job telling me if it worked... > >17:58:31.636816 00:22:01:01:52:54 > 00:00:00:00:02:00, ethertype 802.1Q-QinQ >(0x88a8), length 106: vlan 789, p 0, LLC, dsap Unknown (0x44) Group, ssap >Null (0x00) Command, ctrl 0x5400: Information, send seq 0, rcv seq 42, Flags >[Command], length 88 > 0x0000: 0000 0000 0200 0022 0101 5254 88a8 0315 > 0x0010: 00c3 4500 0054 c06b 0000 4001 704c 8100 > 0x0020: 007b c0a8 6401 c0a8 649f 0000 24b8 027c > 0x0030: 000a c7e5 6854 0000 0000 e0b4 0900 0000 > 0x0040: 0000 1011 1213 1415 1617 1819 1a1b 1c1d > 0x0050: 1e1f 2021 2223 2425 2627 2829 2a2b 2c2d > 0x0060: 2e2f 3031 3233 3435 3637 > >Here it is with just 802.1q tag... >17:53:38.198323 52:54:00:c3:4b:c5 > 02:00:00:22:01:01, ethertype 802.1Q >(0x8100), length 102: vlan 456, p 0, ethertype IPv4, 192.168.100.1 > >192.168.100.159: ICMP echo reply, id 620, seq 1, length 64 > 0x0000: 0200 0022 0101 5254 00c3 4bc5 8100 01c8 > 0x0010: 0800 4500 0054 c052 0000 4001 7065 c0a8 > 0x0020: 6401 c0a8 649f 0000 6482 026c 0001 a2e4 > 0x0030: 6854 0000 0000 cc04 0300 0000 0000 1011 > 0x0040: 1213 1415 1617 1819 1a1b 1c1d 1e1f 2021 > 0x0050: 2223 2425 2627 2829 2a2b 2c2d 2e2f 3031 > 0x0060: 3233 3435 3637 > >------------ > > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-11-18 20:48 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <reply-to=1415700789-9171-2-git-send-email-jiri@resnulli.us>
2014-11-11 10:16 ` [patch iproute2] tc: add support for vlan tc action Jiri Pirko
2014-11-11 12:35 ` Jamal Hadi Salim
2014-11-11 13:36 ` Jamal Hadi Salim
2014-11-11 13:46 ` Jiri Pirko
2014-11-12 14:52 [patch net-next v2 4/4] sched: introduce vlan action Jiri Pirko
2014-11-12 14:55 ` [patch iproute2] tc: add support for vlan tc action Jiri Pirko
2014-11-16 20:19 ` Jamal Hadi Salim
2014-11-18 20:48 ` Jiri Pirko
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).