~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/sched/em_ipset.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /net/sched/em_ipset.c (Version linux-6.12-rc7) and /net/sched/em_ipset.c (Version linux-5.8.18)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*                                                  2 /*
  3  * net/sched/em_ipset.c ipset ematch                3  * net/sched/em_ipset.c ipset ematch
  4  *                                                  4  *
  5  * Copyright (c) 2012 Florian Westphal <fw@str      5  * Copyright (c) 2012 Florian Westphal <fw@strlen.de>
  6  */                                                 6  */
  7                                                     7 
  8 #include <linux/gfp.h>                              8 #include <linux/gfp.h>
  9 #include <linux/module.h>                           9 #include <linux/module.h>
 10 #include <linux/types.h>                           10 #include <linux/types.h>
 11 #include <linux/kernel.h>                          11 #include <linux/kernel.h>
 12 #include <linux/string.h>                          12 #include <linux/string.h>
 13 #include <linux/skbuff.h>                          13 #include <linux/skbuff.h>
 14 #include <linux/netfilter/xt_set.h>                14 #include <linux/netfilter/xt_set.h>
 15 #include <linux/ipv6.h>                            15 #include <linux/ipv6.h>
 16 #include <net/ip.h>                                16 #include <net/ip.h>
 17 #include <net/pkt_cls.h>                           17 #include <net/pkt_cls.h>
 18                                                    18 
 19 static int em_ipset_change(struct net *net, vo     19 static int em_ipset_change(struct net *net, void *data, int data_len,
 20                            struct tcf_ematch *     20                            struct tcf_ematch *em)
 21 {                                                  21 {
 22         struct xt_set_info *set = data;            22         struct xt_set_info *set = data;
 23         ip_set_id_t index;                         23         ip_set_id_t index;
 24                                                    24 
 25         if (data_len != sizeof(*set))              25         if (data_len != sizeof(*set))
 26                 return -EINVAL;                    26                 return -EINVAL;
 27                                                    27 
 28         index = ip_set_nfnl_get_byindex(net, s     28         index = ip_set_nfnl_get_byindex(net, set->index);
 29         if (index == IPSET_INVALID_ID)             29         if (index == IPSET_INVALID_ID)
 30                 return -ENOENT;                    30                 return -ENOENT;
 31                                                    31 
 32         em->datalen = sizeof(*set);                32         em->datalen = sizeof(*set);
 33         em->data = (unsigned long)kmemdup(data     33         em->data = (unsigned long)kmemdup(data, em->datalen, GFP_KERNEL);
 34         if (em->data)                              34         if (em->data)
 35                 return 0;                          35                 return 0;
 36                                                    36 
 37         ip_set_nfnl_put(net, index);               37         ip_set_nfnl_put(net, index);
 38         return -ENOMEM;                            38         return -ENOMEM;
 39 }                                                  39 }
 40                                                    40 
 41 static void em_ipset_destroy(struct tcf_ematch     41 static void em_ipset_destroy(struct tcf_ematch *em)
 42 {                                                  42 {
 43         const struct xt_set_info *set = (const     43         const struct xt_set_info *set = (const void *) em->data;
 44         if (set) {                                 44         if (set) {
 45                 ip_set_nfnl_put(em->net, set->     45                 ip_set_nfnl_put(em->net, set->index);
 46                 kfree((void *) em->data);          46                 kfree((void *) em->data);
 47         }                                          47         }
 48 }                                                  48 }
 49                                                    49 
 50 static int em_ipset_match(struct sk_buff *skb,     50 static int em_ipset_match(struct sk_buff *skb, struct tcf_ematch *em,
 51                           struct tcf_pkt_info      51                           struct tcf_pkt_info *info)
 52 {                                                  52 {
 53         struct ip_set_adt_opt opt;                 53         struct ip_set_adt_opt opt;
 54         struct xt_action_param acpar;              54         struct xt_action_param acpar;
 55         const struct xt_set_info *set = (const     55         const struct xt_set_info *set = (const void *) em->data;
 56         struct net_device *dev, *indev = NULL;     56         struct net_device *dev, *indev = NULL;
 57         struct nf_hook_state state = {             57         struct nf_hook_state state = {
 58                 .net    = em->net,                 58                 .net    = em->net,
 59         };                                         59         };
 60         int ret, network_offset;                   60         int ret, network_offset;
 61                                                    61 
 62         switch (skb_protocol(skb, true)) {         62         switch (skb_protocol(skb, true)) {
 63         case htons(ETH_P_IP):                      63         case htons(ETH_P_IP):
 64                 state.pf = NFPROTO_IPV4;           64                 state.pf = NFPROTO_IPV4;
 65                 if (!pskb_network_may_pull(skb     65                 if (!pskb_network_may_pull(skb, sizeof(struct iphdr)))
 66                         return 0;                  66                         return 0;
 67                 acpar.thoff = ip_hdrlen(skb);      67                 acpar.thoff = ip_hdrlen(skb);
 68                 break;                             68                 break;
 69         case htons(ETH_P_IPV6):                    69         case htons(ETH_P_IPV6):
 70                 state.pf = NFPROTO_IPV6;           70                 state.pf = NFPROTO_IPV6;
 71                 if (!pskb_network_may_pull(skb     71                 if (!pskb_network_may_pull(skb, sizeof(struct ipv6hdr)))
 72                         return 0;                  72                         return 0;
 73                 /* doesn't call ipv6_find_hdr(     73                 /* doesn't call ipv6_find_hdr() because ipset doesn't use thoff, yet */
 74                 acpar.thoff = sizeof(struct ip     74                 acpar.thoff = sizeof(struct ipv6hdr);
 75                 break;                             75                 break;
 76         default:                                   76         default:
 77                 return 0;                          77                 return 0;
 78         }                                          78         }
 79                                                    79 
 80         opt.family = state.pf;                     80         opt.family = state.pf;
 81         opt.dim = set->dim;                        81         opt.dim = set->dim;
 82         opt.flags = set->flags;                    82         opt.flags = set->flags;
 83         opt.cmdflags = 0;                          83         opt.cmdflags = 0;
 84         opt.ext.timeout = ~0u;                     84         opt.ext.timeout = ~0u;
 85                                                    85 
 86         network_offset = skb_network_offset(sk     86         network_offset = skb_network_offset(skb);
 87         skb_pull(skb, network_offset);             87         skb_pull(skb, network_offset);
 88                                                    88 
 89         dev = skb->dev;                            89         dev = skb->dev;
 90                                                    90 
 91         rcu_read_lock();                           91         rcu_read_lock();
 92                                                    92 
 93         if (skb->skb_iif)                          93         if (skb->skb_iif)
 94                 indev = dev_get_by_index_rcu(e     94                 indev = dev_get_by_index_rcu(em->net, skb->skb_iif);
 95                                                    95 
 96         state.in      = indev ? indev : dev;       96         state.in      = indev ? indev : dev;
 97         state.out     = dev;                       97         state.out     = dev;
 98         acpar.state   = &state;                    98         acpar.state   = &state;
 99                                                    99 
100         ret = ip_set_test(set->index, skb, &ac    100         ret = ip_set_test(set->index, skb, &acpar, &opt);
101                                                   101 
102         rcu_read_unlock();                        102         rcu_read_unlock();
103                                                   103 
104         skb_push(skb, network_offset);            104         skb_push(skb, network_offset);
105         return ret;                               105         return ret;
106 }                                                 106 }
107                                                   107 
108 static struct tcf_ematch_ops em_ipset_ops = {     108 static struct tcf_ematch_ops em_ipset_ops = {
109         .kind     = TCF_EM_IPSET,                 109         .kind     = TCF_EM_IPSET,
110         .change   = em_ipset_change,              110         .change   = em_ipset_change,
111         .destroy  = em_ipset_destroy,             111         .destroy  = em_ipset_destroy,
112         .match    = em_ipset_match,               112         .match    = em_ipset_match,
113         .owner    = THIS_MODULE,                  113         .owner    = THIS_MODULE,
114         .link     = LIST_HEAD_INIT(em_ipset_op    114         .link     = LIST_HEAD_INIT(em_ipset_ops.link)
115 };                                                115 };
116                                                   116 
117 static int __init init_em_ipset(void)             117 static int __init init_em_ipset(void)
118 {                                                 118 {
119         return tcf_em_register(&em_ipset_ops);    119         return tcf_em_register(&em_ipset_ops);
120 }                                                 120 }
121                                                   121 
122 static void __exit exit_em_ipset(void)            122 static void __exit exit_em_ipset(void)
123 {                                                 123 {
124         tcf_em_unregister(&em_ipset_ops);         124         tcf_em_unregister(&em_ipset_ops);
125 }                                                 125 }
126                                                   126 
127 MODULE_LICENSE("GPL");                            127 MODULE_LICENSE("GPL");
128 MODULE_AUTHOR("Florian Westphal <fw@strlen.de>    128 MODULE_AUTHOR("Florian Westphal <fw@strlen.de>");
129 MODULE_DESCRIPTION("TC extended match for IP s    129 MODULE_DESCRIPTION("TC extended match for IP sets");
130                                                   130 
131 module_init(init_em_ipset);                       131 module_init(init_em_ipset);
132 module_exit(exit_em_ipset);                       132 module_exit(exit_em_ipset);
133                                                   133 
134 MODULE_ALIAS_TCF_EMATCH(TCF_EM_IPSET);            134 MODULE_ALIAS_TCF_EMATCH(TCF_EM_IPSET);
135                                                   135 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php