Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * net/sched/act_meta_tc_index.c IFE skb->tc_index metadata module
0004  *
0005  * copyright Jamal Hadi Salim (2016)
0006 */
0007 
0008 #include <linux/types.h>
0009 #include <linux/kernel.h>
0010 #include <linux/string.h>
0011 #include <linux/errno.h>
0012 #include <linux/skbuff.h>
0013 #include <linux/rtnetlink.h>
0014 #include <linux/module.h>
0015 #include <linux/init.h>
0016 #include <net/netlink.h>
0017 #include <net/pkt_sched.h>
0018 #include <uapi/linux/tc_act/tc_ife.h>
0019 #include <net/tc_act/tc_ife.h>
0020 
0021 static int skbtcindex_encode(struct sk_buff *skb, void *skbdata,
0022                  struct tcf_meta_info *e)
0023 {
0024     u32 ifetc_index = skb->tc_index;
0025 
0026     return ife_encode_meta_u16(ifetc_index, skbdata, e);
0027 }
0028 
0029 static int skbtcindex_decode(struct sk_buff *skb, void *data, u16 len)
0030 {
0031     u16 ifetc_index = *(u16 *)data;
0032 
0033     skb->tc_index = ntohs(ifetc_index);
0034     return 0;
0035 }
0036 
0037 static int skbtcindex_check(struct sk_buff *skb, struct tcf_meta_info *e)
0038 {
0039     return ife_check_meta_u16(skb->tc_index, e);
0040 }
0041 
0042 static struct tcf_meta_ops ife_skbtcindex_ops = {
0043     .metaid = IFE_META_TCINDEX,
0044     .metatype = NLA_U16,
0045     .name = "tc_index",
0046     .synopsis = "skb tc_index 16 bit metadata",
0047     .check_presence = skbtcindex_check,
0048     .encode = skbtcindex_encode,
0049     .decode = skbtcindex_decode,
0050     .get = ife_get_meta_u16,
0051     .alloc = ife_alloc_meta_u16,
0052     .release = ife_release_meta_gen,
0053     .validate = ife_validate_meta_u16,
0054     .owner = THIS_MODULE,
0055 };
0056 
0057 static int __init ifetc_index_init_module(void)
0058 {
0059     return register_ife_op(&ife_skbtcindex_ops);
0060 }
0061 
0062 static void __exit ifetc_index_cleanup_module(void)
0063 {
0064     unregister_ife_op(&ife_skbtcindex_ops);
0065 }
0066 
0067 module_init(ifetc_index_init_module);
0068 module_exit(ifetc_index_cleanup_module);
0069 
0070 MODULE_AUTHOR("Jamal Hadi Salim(2016)");
0071 MODULE_DESCRIPTION("Inter-FE skb tc_index metadata module");
0072 MODULE_LICENSE("GPL");
0073 MODULE_ALIAS_IFE_META("tcindex");