Linux Audio

Check our new training course

Loading...
v5.4
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 * net/sched/em_u32.c	U32 Ematch
 
 
 
 
 
 4 *
 5 * Authors:	Thomas Graf <tgraf@suug.ch>
 6 *		Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
 7 *
 8 * Based on net/sched/cls_u32.c
 9 */
10
11#include <linux/module.h>
12#include <linux/types.h>
13#include <linux/kernel.h>
14#include <linux/skbuff.h>
15#include <net/pkt_cls.h>
16
17static int em_u32_match(struct sk_buff *skb, struct tcf_ematch *em,
18			struct tcf_pkt_info *info)
19{
20	struct tc_u32_key *key = (struct tc_u32_key *) em->data;
21	const unsigned char *ptr = skb_network_header(skb);
22
23	if (info) {
24		if (info->ptr)
25			ptr = info->ptr;
26		ptr += (info->nexthdr & key->offmask);
27	}
28
29	ptr += key->off;
30
31	if (!tcf_valid_offset(skb, ptr, sizeof(u32)))
32		return 0;
33
34	return !(((*(__be32 *) ptr)  ^ key->val) & key->mask);
35}
36
37static struct tcf_ematch_ops em_u32_ops = {
38	.kind	  = TCF_EM_U32,
39	.datalen  = sizeof(struct tc_u32_key),
40	.match	  = em_u32_match,
41	.owner	  = THIS_MODULE,
42	.link	  = LIST_HEAD_INIT(em_u32_ops.link)
43};
44
45static int __init init_em_u32(void)
46{
47	return tcf_em_register(&em_u32_ops);
48}
49
50static void __exit exit_em_u32(void)
51{
52	tcf_em_unregister(&em_u32_ops);
53}
54
55MODULE_LICENSE("GPL");
56
57module_init(init_em_u32);
58module_exit(exit_em_u32);
59
60MODULE_ALIAS_TCF_EMATCH(TCF_EM_U32);
v3.1
 
 1/*
 2 * net/sched/em_u32.c	U32 Ematch
 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 * Authors:	Thomas Graf <tgraf@suug.ch>
10 *		Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
11 *
12 * Based on net/sched/cls_u32.c
13 */
14
15#include <linux/module.h>
16#include <linux/types.h>
17#include <linux/kernel.h>
18#include <linux/skbuff.h>
19#include <net/pkt_cls.h>
20
21static int em_u32_match(struct sk_buff *skb, struct tcf_ematch *em,
22			struct tcf_pkt_info *info)
23{
24	struct tc_u32_key *key = (struct tc_u32_key *) em->data;
25	const unsigned char *ptr = skb_network_header(skb);
26
27	if (info) {
28		if (info->ptr)
29			ptr = info->ptr;
30		ptr += (info->nexthdr & key->offmask);
31	}
32
33	ptr += key->off;
34
35	if (!tcf_valid_offset(skb, ptr, sizeof(u32)))
36		return 0;
37
38	return !(((*(__be32 *) ptr)  ^ key->val) & key->mask);
39}
40
41static struct tcf_ematch_ops em_u32_ops = {
42	.kind	  = TCF_EM_U32,
43	.datalen  = sizeof(struct tc_u32_key),
44	.match	  = em_u32_match,
45	.owner	  = THIS_MODULE,
46	.link	  = LIST_HEAD_INIT(em_u32_ops.link)
47};
48
49static int __init init_em_u32(void)
50{
51	return tcf_em_register(&em_u32_ops);
52}
53
54static void __exit exit_em_u32(void)
55{
56	tcf_em_unregister(&em_u32_ops);
57}
58
59MODULE_LICENSE("GPL");
60
61module_init(init_em_u32);
62module_exit(exit_em_u32);
63
64MODULE_ALIAS_TCF_EMATCH(TCF_EM_U32);