Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * net/sched/em_u32.c U32 Ematch |
| 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 17 | static 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; |
Arnaldo Carvalho de Melo | d56f90a | 2007-04-10 20:50:43 -0700 | [diff] [blame] | 21 | const unsigned char *ptr = skb_network_header(skb); |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 33 | |
Eric Dumazet | cc7ec45 | 2011-01-19 19:26:56 +0000 | [diff] [blame] | 34 | return !(((*(__be32 *) ptr) ^ key->val) & key->mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static 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 | |
| 45 | static int __init init_em_u32(void) |
| 46 | { |
| 47 | return tcf_em_register(&em_u32_ops); |
| 48 | } |
| 49 | |
YOSHIFUJI Hideaki | 10297b9 | 2007-02-09 23:25:16 +0900 | [diff] [blame] | 50 | static void __exit exit_em_u32(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
| 52 | tcf_em_unregister(&em_u32_ops); |
| 53 | } |
| 54 | |
| 55 | MODULE_LICENSE("GPL"); |
| 56 | |
| 57 | module_init(init_em_u32); |
| 58 | module_exit(exit_em_u32); |
Patrick McHardy | db3d99c | 2007-07-11 19:46:26 -0700 | [diff] [blame] | 59 | |
| 60 | MODULE_ALIAS_TCF_EMATCH(TCF_EM_U32); |