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

TOMOYO Linux Cross Reference
Linux/net/netfilter/xt_rateest.c

Version: ~ [ linux-5.4-rc7 ] ~ [ linux-5.3.10 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.83 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.153 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.200 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.200 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.76 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /net/netfilter/xt_rateest.c (Version linux-4.10.17) and /net/netfilter/xt_rateest.c (Version linux-4.20.17)


  1 /*                                                  1 /*
  2  * (C) 2007 Patrick McHardy <kaber@trash.net>       2  * (C) 2007 Patrick McHardy <kaber@trash.net>
  3  *                                                  3  *
  4  * This program is free software; you can redi      4  * This program is free software; you can redistribute it and/or modify
  5  * it under the terms of the GNU General Publi      5  * it under the terms of the GNU General Public License version 2 as
  6  * published by the Free Software Foundation.       6  * published by the Free Software Foundation.
  7  */                                                 7  */
  8 #include <linux/module.h>                           8 #include <linux/module.h>
  9 #include <linux/skbuff.h>                           9 #include <linux/skbuff.h>
 10 #include <linux/gen_stats.h>                       10 #include <linux/gen_stats.h>
 11                                                    11 
 12 #include <linux/netfilter/x_tables.h>              12 #include <linux/netfilter/x_tables.h>
 13 #include <linux/netfilter/xt_rateest.h>            13 #include <linux/netfilter/xt_rateest.h>
 14 #include <net/netfilter/xt_rateest.h>              14 #include <net/netfilter/xt_rateest.h>
 15                                                    15 
 16                                                    16 
 17 static bool                                        17 static bool
 18 xt_rateest_mt(const struct sk_buff *skb, struc     18 xt_rateest_mt(const struct sk_buff *skb, struct xt_action_param *par)
 19 {                                                  19 {
 20         const struct xt_rateest_match_info *in     20         const struct xt_rateest_match_info *info = par->matchinfo;
 21         struct gnet_stats_rate_est64 sample =      21         struct gnet_stats_rate_est64 sample = {0};
 22         u_int32_t bps1, bps2, pps1, pps2;          22         u_int32_t bps1, bps2, pps1, pps2;
 23         bool ret = true;                           23         bool ret = true;
 24                                                    24 
 25         gen_estimator_read(&info->est1->rate_e     25         gen_estimator_read(&info->est1->rate_est, &sample);
 26                                                    26 
 27         if (info->flags & XT_RATEEST_MATCH_DEL     27         if (info->flags & XT_RATEEST_MATCH_DELTA) {
 28                 bps1 = info->bps1 >= sample.bp     28                 bps1 = info->bps1 >= sample.bps ? info->bps1 - sample.bps : 0;
 29                 pps1 = info->pps1 >= sample.pp     29                 pps1 = info->pps1 >= sample.pps ? info->pps1 - sample.pps : 0;
 30         } else {                                   30         } else {
 31                 bps1 = sample.bps;                 31                 bps1 = sample.bps;
 32                 pps1 = sample.pps;                 32                 pps1 = sample.pps;
 33         }                                          33         }
 34                                                    34 
 35         if (info->flags & XT_RATEEST_MATCH_ABS     35         if (info->flags & XT_RATEEST_MATCH_ABS) {
 36                 bps2 = info->bps2;                 36                 bps2 = info->bps2;
 37                 pps2 = info->pps2;                 37                 pps2 = info->pps2;
 38         } else {                                   38         } else {
 39                 gen_estimator_read(&info->est2     39                 gen_estimator_read(&info->est2->rate_est, &sample);
 40                                                    40 
 41                 if (info->flags & XT_RATEEST_M     41                 if (info->flags & XT_RATEEST_MATCH_DELTA) {
 42                         bps2 = info->bps2 >= s     42                         bps2 = info->bps2 >= sample.bps ? info->bps2 - sample.bps : 0;
 43                         pps2 = info->pps2 >= s     43                         pps2 = info->pps2 >= sample.pps ? info->pps2 - sample.pps : 0;
 44                 } else {                           44                 } else {
 45                         bps2 = sample.bps;         45                         bps2 = sample.bps;
 46                         pps2 = sample.pps;         46                         pps2 = sample.pps;
 47                 }                                  47                 }
 48         }                                          48         }
 49                                                    49 
 50         switch (info->mode) {                      50         switch (info->mode) {
 51         case XT_RATEEST_MATCH_LT:                  51         case XT_RATEEST_MATCH_LT:
 52                 if (info->flags & XT_RATEEST_M     52                 if (info->flags & XT_RATEEST_MATCH_BPS)
 53                         ret &= bps1 < bps2;        53                         ret &= bps1 < bps2;
 54                 if (info->flags & XT_RATEEST_M     54                 if (info->flags & XT_RATEEST_MATCH_PPS)
 55                         ret &= pps1 < pps2;        55                         ret &= pps1 < pps2;
 56                 break;                             56                 break;
 57         case XT_RATEEST_MATCH_GT:                  57         case XT_RATEEST_MATCH_GT:
 58                 if (info->flags & XT_RATEEST_M     58                 if (info->flags & XT_RATEEST_MATCH_BPS)
 59                         ret &= bps1 > bps2;        59                         ret &= bps1 > bps2;
 60                 if (info->flags & XT_RATEEST_M     60                 if (info->flags & XT_RATEEST_MATCH_PPS)
 61                         ret &= pps1 > pps2;        61                         ret &= pps1 > pps2;
 62                 break;                             62                 break;
 63         case XT_RATEEST_MATCH_EQ:                  63         case XT_RATEEST_MATCH_EQ:
 64                 if (info->flags & XT_RATEEST_M     64                 if (info->flags & XT_RATEEST_MATCH_BPS)
 65                         ret &= bps1 == bps2;       65                         ret &= bps1 == bps2;
 66                 if (info->flags & XT_RATEEST_M     66                 if (info->flags & XT_RATEEST_MATCH_PPS)
 67                         ret &= pps1 == pps2;       67                         ret &= pps1 == pps2;
 68                 break;                             68                 break;
 69         }                                          69         }
 70                                                    70 
 71         ret ^= info->flags & XT_RATEEST_MATCH_     71         ret ^= info->flags & XT_RATEEST_MATCH_INVERT ? true : false;
 72         return ret;                                72         return ret;
 73 }                                                  73 }
 74                                                    74 
 75 static int xt_rateest_mt_checkentry(const stru     75 static int xt_rateest_mt_checkentry(const struct xt_mtchk_param *par)
 76 {                                                  76 {
 77         struct xt_rateest_match_info *info = p     77         struct xt_rateest_match_info *info = par->matchinfo;
 78         struct xt_rateest *est1, *est2;            78         struct xt_rateest *est1, *est2;
 79         int ret = -EINVAL;                         79         int ret = -EINVAL;
 80                                                    80 
 81         if (hweight32(info->flags & (XT_RATEES     81         if (hweight32(info->flags & (XT_RATEEST_MATCH_ABS |
 82                                      XT_RATEES     82                                      XT_RATEEST_MATCH_REL)) != 1)
 83                 goto err1;                         83                 goto err1;
 84                                                    84 
 85         if (!(info->flags & (XT_RATEEST_MATCH_     85         if (!(info->flags & (XT_RATEEST_MATCH_BPS | XT_RATEEST_MATCH_PPS)))
 86                 goto err1;                         86                 goto err1;
 87                                                    87 
 88         switch (info->mode) {                      88         switch (info->mode) {
 89         case XT_RATEEST_MATCH_EQ:                  89         case XT_RATEEST_MATCH_EQ:
 90         case XT_RATEEST_MATCH_LT:                  90         case XT_RATEEST_MATCH_LT:
 91         case XT_RATEEST_MATCH_GT:                  91         case XT_RATEEST_MATCH_GT:
 92                 break;                             92                 break;
 93         default:                                   93         default:
 94                 goto err1;                         94                 goto err1;
 95         }                                          95         }
 96                                                    96 
 97         ret  = -ENOENT;                            97         ret  = -ENOENT;
 98         est1 = xt_rateest_lookup(info->name1); !!  98         est1 = xt_rateest_lookup(par->net, info->name1);
 99         if (!est1)                                 99         if (!est1)
100                 goto err1;                        100                 goto err1;
101                                                   101 
102         est2 = NULL;                              102         est2 = NULL;
103         if (info->flags & XT_RATEEST_MATCH_REL    103         if (info->flags & XT_RATEEST_MATCH_REL) {
104                 est2 = xt_rateest_lookup(info- !! 104                 est2 = xt_rateest_lookup(par->net, info->name2);
105                 if (!est2)                        105                 if (!est2)
106                         goto err2;                106                         goto err2;
107         }                                         107         }
108                                                   108 
109         info->est1 = est1;                        109         info->est1 = est1;
110         info->est2 = est2;                        110         info->est2 = est2;
111         return 0;                                 111         return 0;
112                                                   112 
113 err2:                                             113 err2:
114         xt_rateest_put(est1);                  !! 114         xt_rateest_put(par->net, est1);
115 err1:                                             115 err1:
116         return ret;                               116         return ret;
117 }                                                 117 }
118                                                   118 
119 static void xt_rateest_mt_destroy(const struct    119 static void xt_rateest_mt_destroy(const struct xt_mtdtor_param *par)
120 {                                                 120 {
121         struct xt_rateest_match_info *info = p    121         struct xt_rateest_match_info *info = par->matchinfo;
122                                                   122 
123         xt_rateest_put(info->est1);            !! 123         xt_rateest_put(par->net, info->est1);
124         if (info->est2)                           124         if (info->est2)
125                 xt_rateest_put(info->est2);    !! 125                 xt_rateest_put(par->net, info->est2);
126 }                                                 126 }
127                                                   127 
128 static struct xt_match xt_rateest_mt_reg __rea    128 static struct xt_match xt_rateest_mt_reg __read_mostly = {
129         .name       = "rateest",                  129         .name       = "rateest",
130         .revision   = 0,                          130         .revision   = 0,
131         .family     = NFPROTO_UNSPEC,             131         .family     = NFPROTO_UNSPEC,
132         .match      = xt_rateest_mt,              132         .match      = xt_rateest_mt,
133         .checkentry = xt_rateest_mt_checkentry    133         .checkentry = xt_rateest_mt_checkentry,
134         .destroy    = xt_rateest_mt_destroy,      134         .destroy    = xt_rateest_mt_destroy,
135         .matchsize  = sizeof(struct xt_rateest    135         .matchsize  = sizeof(struct xt_rateest_match_info),
                                                   >> 136         .usersize   = offsetof(struct xt_rateest_match_info, est1),
136         .me         = THIS_MODULE,                137         .me         = THIS_MODULE,
137 };                                                138 };
138                                                   139 
139 static int __init xt_rateest_mt_init(void)        140 static int __init xt_rateest_mt_init(void)
140 {                                                 141 {
141         return xt_register_match(&xt_rateest_m    142         return xt_register_match(&xt_rateest_mt_reg);
142 }                                                 143 }
143                                                   144 
144 static void __exit xt_rateest_mt_fini(void)       145 static void __exit xt_rateest_mt_fini(void)
145 {                                                 146 {
146         xt_unregister_match(&xt_rateest_mt_reg    147         xt_unregister_match(&xt_rateest_mt_reg);
147 }                                                 148 }
148                                                   149 
149 MODULE_AUTHOR("Patrick McHardy <kaber@trash.ne    150 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
150 MODULE_LICENSE("GPL");                            151 MODULE_LICENSE("GPL");
151 MODULE_DESCRIPTION("xtables rate estimator mat    152 MODULE_DESCRIPTION("xtables rate estimator match");
152 MODULE_ALIAS("ipt_rateest");                      153 MODULE_ALIAS("ipt_rateest");
153 MODULE_ALIAS("ip6t_rateest");                     154 MODULE_ALIAS("ip6t_rateest");
154 module_init(xt_rateest_mt_init);                  155 module_init(xt_rateest_mt_init);
155 module_exit(xt_rateest_mt_fini);                  156 module_exit(xt_rateest_mt_fini);
156                                                   157 

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

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | 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.

osdn.jp