Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Support to encoding decoding skb prio on IFE action

Example usage:
Set the skb priority using skbedit then allow it to be encoded

sudo tc qdisc add dev $ETH root handle 1: prio
sudo tc filter add dev $ETH parent 1: protocol ip prio 10 \
u32 match ip protocol 1 0xff flowid 1:2 \
action skbedit prio 17 \
action ife encode \
allow prio \
dst 02:15:15:15:15:15

Note: You dont need the skbedit action if you are already encoding the
skb priority earlier. A zero skb priority will not be sent

Alternative hard code static priority of decimal 33 (unlike skbedit)
then mark of 0x12 every time the filter matches

sudo $TC filter add dev $ETH parent 1: protocol ip prio 10 \
u32 match ip protocol 1 0xff flowid 1:2 \
action ife encode \
type 0xDEAD \
use prio 33 \
use mark 0x12 \
dst 02:15:15:15:15:15

Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Acked-by: Cong Wang <xiyou.wangcong@gmail.com>

Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jamal Hadi Salim and committed by
David S. Miller
200e10f4 084e2f65

+82
+5
net/sched/Kconfig
··· 756 756 depends on NET_ACT_IFE 757 757 ---help--- 758 758 759 + config NET_IFE_SKBPRIO 760 + tristate "Support to encoding decoding skb prio on IFE action" 761 + depends on NET_ACT_IFE 762 + ---help--- 763 + 759 764 config NET_CLS_IND 760 765 bool "Incoming device classification" 761 766 depends on NET_CLS_U32 || NET_CLS_FW
+1
net/sched/Makefile
··· 21 21 obj-$(CONFIG_NET_ACT_CONNMARK) += act_connmark.o 22 22 obj-$(CONFIG_NET_ACT_IFE) += act_ife.o 23 23 obj-$(CONFIG_NET_IFE_SKBMARK) += act_meta_mark.o 24 + obj-$(CONFIG_NET_IFE_SKBPRIO) += act_meta_skbprio.o 24 25 obj-$(CONFIG_NET_SCH_FIFO) += sch_fifo.o 25 26 obj-$(CONFIG_NET_SCH_CBQ) += sch_cbq.o 26 27 obj-$(CONFIG_NET_SCH_HTB) += sch_htb.o
+76
net/sched/act_meta_skbprio.c
··· 1 + /* 2 + * net/sched/act_meta_prio.c IFE skb->priority metadata module 3 + * 4 + * This program is free software; you can redistribute it and/or 5 + * modify it under the terms of the GNU General Public License 6 + * as published by the Free Software Foundation; either version 7 + * 2 of the License, or (at your option) any later version. 8 + * 9 + * copyright Jamal Hadi Salim (2015) 10 + * 11 + */ 12 + 13 + #include <linux/types.h> 14 + #include <linux/kernel.h> 15 + #include <linux/string.h> 16 + #include <linux/errno.h> 17 + #include <linux/skbuff.h> 18 + #include <linux/rtnetlink.h> 19 + #include <linux/module.h> 20 + #include <linux/init.h> 21 + #include <net/netlink.h> 22 + #include <net/pkt_sched.h> 23 + #include <uapi/linux/tc_act/tc_ife.h> 24 + #include <net/tc_act/tc_ife.h> 25 + 26 + static int skbprio_check(struct sk_buff *skb, struct tcf_meta_info *e) 27 + { 28 + return ife_check_meta_u32(skb->priority, e); 29 + } 30 + 31 + static int skbprio_encode(struct sk_buff *skb, void *skbdata, 32 + struct tcf_meta_info *e) 33 + { 34 + u32 ifeprio = skb->priority; /* avoid having to cast skb->priority*/ 35 + 36 + return ife_encode_meta_u32(ifeprio, skbdata, e); 37 + } 38 + 39 + static int skbprio_decode(struct sk_buff *skb, void *data, u16 len) 40 + { 41 + u32 ifeprio = *(u32 *)data; 42 + 43 + skb->priority = ntohl(ifeprio); 44 + return 0; 45 + } 46 + 47 + static struct tcf_meta_ops ife_prio_ops = { 48 + .metaid = IFE_META_PRIO, 49 + .metatype = NLA_U32, 50 + .name = "skbprio", 51 + .synopsis = "skb prio metadata", 52 + .check_presence = skbprio_check, 53 + .encode = skbprio_encode, 54 + .decode = skbprio_decode, 55 + .get = ife_get_meta_u32, 56 + .alloc = ife_alloc_meta_u32, 57 + .owner = THIS_MODULE, 58 + }; 59 + 60 + static int __init ifeprio_init_module(void) 61 + { 62 + return register_ife_op(&ife_prio_ops); 63 + } 64 + 65 + static void __exit ifeprio_cleanup_module(void) 66 + { 67 + unregister_ife_op(&ife_prio_ops); 68 + } 69 + 70 + module_init(ifeprio_init_module); 71 + module_exit(ifeprio_cleanup_module); 72 + 73 + MODULE_AUTHOR("Jamal Hadi Salim(2015)"); 74 + MODULE_DESCRIPTION("Inter-FE skb prio metadata action"); 75 + MODULE_LICENSE("GPL"); 76 + MODULE_ALIAS_IFE_META(IFE_META_PRIO);