]> git.pld-linux.org Git - packages/kernel.git/blob - pom-ng-time-20060829.patch
BINFMT_COFF is off
[packages/kernel.git] / pom-ng-time-20060829.patch
1  include/linux/netfilter_ipv4/ipt_time.h |   18 ++
2  net/ipv4/netfilter/Kconfig              |   14 ++
3  net/ipv4/netfilter/Makefile             |    1 
4  net/ipv4/netfilter/ipt_time.c           |  198 ++++++++++++++++++++++++++++++++
5  4 files changed, 231 insertions(+)
6
7 diff -Nur --exclude '*.orig' linux.org/include/linux/netfilter_ipv4/ipt_time.h linux/include/linux/netfilter_ipv4/ipt_time.h
8 --- linux.org/include/linux/netfilter_ipv4/ipt_time.h   1970-01-01 00:00:00.000000000 +0000
9 +++ linux/include/linux/netfilter_ipv4/ipt_time.h       2006-08-29 12:37:43.000000000 +0000
10 @@ -0,0 +1,18 @@
11 +#ifndef __ipt_time_h_included__
12 +#define __ipt_time_h_included__
13 +
14 +
15 +struct ipt_time_info {
16 +       u_int8_t  days_match;   /* 1 bit per day. -SMTWTFS                      */
17 +       u_int16_t time_start;   /* 0 < time_start < 23*60+59 = 1439             */
18 +       u_int16_t time_stop;    /* 0:0 < time_stat < 23:59                      */
19 +
20 +                               /* FIXME: Keep this one for userspace iptables binary compability: */
21 +       u_int8_t  kerneltime;   /* ignore skb time (and use kerneltime) or not. */
22 +
23 +       time_t    date_start;
24 +       time_t    date_stop;
25 +};
26 +
27 +
28 +#endif /* __ipt_time_h_included__ */
29 diff -Nur --exclude '*.orig' linux.org/net/ipv4/netfilter/ipt_time.c linux/net/ipv4/netfilter/ipt_time.c
30 --- linux.org/net/ipv4/netfilter/ipt_time.c     1970-01-01 00:00:00.000000000 +0000
31 +++ linux/net/ipv4/netfilter/ipt_time.c 2006-08-29 12:37:43.000000000 +0000
32 @@ -0,0 +1,198 @@
33 +/*
34 +  This is a module which is used for time matching
35 +  It is using some modified code from dietlibc (localtime() function)
36 +  that you can find at http://www.fefe.de/dietlibc/
37 +  This file is distributed under the terms of the GNU General Public
38 +  License (GPL). Copies of the GPL can be obtained from: ftp://prep.ai.mit.edu/pub/gnu/GPL
39 +  2001-05-04 Fabrice MARIE <fabrice@netfilter.org> : initial development.
40 +  2001-21-05 Fabrice MARIE <fabrice@netfilter.org> : bug fix in the match code,
41 +     thanks to "Zeng Yu" <zengy@capitel.com.cn> for bug report.
42 +  2001-26-09 Fabrice MARIE <fabrice@netfilter.org> : force the match to be in LOCAL_IN or PRE_ROUTING only.
43 +  2001-30-11 Fabrice : added the possibility to use the match in FORWARD/OUTPUT with a little hack,
44 +     added Nguyen Dang Phuoc Dong <dongnd@tlnet.com.vn> patch to support timezones.
45 +  2004-05-02 Fabrice : added support for date matching, from an idea of Fabien COELHO.
46 +*/
47 +
48 +#include <linux/module.h>
49 +#include <linux/skbuff.h>
50 +#include <linux/version.h>
51 +#include <linux/netfilter_ipv4/ip_tables.h>
52 +#include <linux/netfilter_ipv4/ipt_time.h>
53 +#include <linux/time.h>
54 +
55 +MODULE_AUTHOR("Fabrice MARIE <fabrice@netfilter.org>");
56 +MODULE_DESCRIPTION("Match arrival timestamp/date");
57 +MODULE_LICENSE("GPL");
58 +
59 +struct tm
60 +{
61 +       int tm_sec;                   /* Seconds.     [0-60] (1 leap second) */
62 +       int tm_min;                   /* Minutes.     [0-59] */
63 +       int tm_hour;                  /* Hours.       [0-23] */
64 +       int tm_mday;                  /* Day.         [1-31] */
65 +       int tm_mon;                   /* Month.       [0-11] */
66 +       int tm_year;                  /* Year - 1900.  */
67 +       int tm_wday;                  /* Day of week. [0-6] */
68 +       int tm_yday;                  /* Days in year.[0-365] */
69 +       int tm_isdst;                 /* DST.         [-1/0/1]*/
70 +
71 +       long int tm_gmtoff;           /* we don't care, we count from GMT */
72 +       const char *tm_zone;          /* we don't care, we count from GMT */
73 +};
74 +
75 +void
76 +localtime(const u32 time, struct tm *r);
77 +
78 +static int
79 +match(const struct sk_buff *skb,
80 +      const struct net_device *in,
81 +      const struct net_device *out,
82 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
83 +      const struct xt_match *match,
84 +#endif
85 +      const void *matchinfo,
86 +      int offset,
87 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
88 +      unsigned int protoff,
89 +#endif
90 +      int *hotdrop)
91 +{
92 +       const struct ipt_time_info *info = matchinfo;   /* match info for rule */
93 +       struct tm currenttime;                          /* time human readable */
94 +       u_int8_t days_of_week[7] = {64, 32, 16, 8, 4, 2, 1};
95 +       u_int16_t packet_time;
96 +
97 +       /* We might not have a timestamp, get one */
98 +       if (skb->tstamp.off_sec == 0)
99 +               __net_timestamp((struct sk_buff *)skb);
100 +
101 +       /* First we make sure we are in the date start-stop boundaries */
102 +       if ((skb->tstamp.off_sec < info->date_start) || (skb->tstamp.off_sec > info->date_stop))
103 +               return 0; /* We are outside the date boundaries */
104 +
105 +       /* Transform the timestamp of the packet, in a human readable form */
106 +       localtime(skb->tstamp.off_sec, &currenttime);
107 +
108 +       /* check if we match this timestamp, we start by the days... */
109 +       if ((days_of_week[currenttime.tm_wday] & info->days_match) != days_of_week[currenttime.tm_wday])
110 +               return 0; /* the day doesn't match */
111 +
112 +       /* ... check the time now */
113 +       packet_time = (currenttime.tm_hour * 60) + currenttime.tm_min;
114 +       if ((packet_time < info->time_start) || (packet_time > info->time_stop))
115 +               return 0;
116 +
117 +       /* here we match ! */
118 +       return 1;
119 +}
120 +
121 +static int
122 +checkentry(const char *tablename,
123 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
124 +           const void *ip,
125 +#else
126 +           const struct ipt_ip *ip,
127 +#endif
128 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
129 +            const struct xt_match *match,
130 +#endif
131 +           void *matchinfo,
132 +           unsigned int matchsize,
133 +           unsigned int hook_mask)
134 +{
135 +       struct ipt_time_info *info = matchinfo;   /* match info for rule */
136 +
137 +       /* First, check that we are in the correct hooks */
138 +       if (hook_mask
139 +            & ~((1 << NF_IP_PRE_ROUTING) | (1 << NF_IP_LOCAL_IN) | (1 << NF_IP_FORWARD) | (1 << NF_IP_LOCAL_OUT)))
140 +       {
141 +               printk("ipt_time: error, only valid for PRE_ROUTING, LOCAL_IN, FORWARD and OUTPUT)\n");
142 +               return 0;
143 +       }
144 +
145 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
146 +       /* Check the size */
147 +       if (matchsize != IPT_ALIGN(sizeof(struct ipt_time_info)))
148 +               return 0;
149 +#endif
150 +
151 +       /* Now check the coherence of the data ... */
152 +       if ((info->time_start > 1439) ||        /* 23*60+59 = 1439*/
153 +           (info->time_stop  > 1439))
154 +       {
155 +               printk(KERN_WARNING "ipt_time: invalid argument\n");
156 +               return 0;
157 +       }
158 +
159 +       return 1;
160 +}
161 +
162 +static struct ipt_match time_match = {
163 +       .name           = "time",
164 +       .match          = &match,
165 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
166 +       .matchsize      = sizeof(struct ipt_time_info),
167 +#endif
168 +       .checkentry     = &checkentry,
169 +       .me = THIS_MODULE
170 +};
171 +
172 +static int __init init(void)
173 +{
174 +       printk("ipt_time loading\n");
175 +       return ipt_register_match(&time_match);
176 +}
177 +
178 +static void __exit fini(void)
179 +{
180 +       ipt_unregister_match(&time_match);
181 +       printk("ipt_time unloaded\n");
182 +}
183 +
184 +module_init(init);
185 +module_exit(fini);
186 +
187 +
188 +/* The part below is borowed and modified from dietlibc */
189 +
190 +/* seconds per day */
191 +#define SPD 24*60*60
192 +
193 +void
194 +localtime(const u32 time, struct tm *r) {
195 +       u32 i, timep;
196 +       extern struct timezone sys_tz;
197 +       const unsigned int __spm[12] =
198 +               { 0,
199 +                 (31),
200 +                 (31+28),
201 +                 (31+28+31),
202 +                 (31+28+31+30),
203 +                 (31+28+31+30+31),
204 +                 (31+28+31+30+31+30),
205 +                 (31+28+31+30+31+30+31),
206 +                 (31+28+31+30+31+30+31+31),
207 +                 (31+28+31+30+31+30+31+31+30),
208 +                 (31+28+31+30+31+30+31+31+30+31),
209 +                 (31+28+31+30+31+30+31+31+30+31+30),
210 +               };
211 +       register u32 work;
212 +
213 +       timep = time - (sys_tz.tz_minuteswest * 60);
214 +       work=timep%(SPD);
215 +       r->tm_sec=work%60; work/=60;
216 +       r->tm_min=work%60; r->tm_hour=work/60;
217 +       work=timep/(SPD);
218 +       r->tm_wday=(4+work)%7;
219 +       for (i=1970; ; ++i) {
220 +               register time_t k= (!(i%4) && ((i%100) || !(i%400)))?366:365;
221 +               if (work>k)
222 +                       work-=k;
223 +               else
224 +                       break;
225 +       }
226 +       r->tm_year=i-1900;
227 +       for (i=11; i && __spm[i]>work; --i) ;
228 +       r->tm_mon=i;
229 +       r->tm_mday=work-__spm[i]+1;
230 +}
231 diff -Nur --exclude '*.orig' linux.org/net/ipv4/netfilter/Kconfig linux/net/ipv4/netfilter/Kconfig
232 --- linux.org/net/ipv4/netfilter/Kconfig        2006-06-18 01:49:35.000000000 +0000
233 +++ linux/net/ipv4/netfilter/Kconfig    2006-08-29 12:37:43.000000000 +0000
234 @@ -613,5 +613,19 @@
235           Allows altering the ARP packet payload: source and destination
236           hardware and network addresses.
237  
238 +config IP_NF_MATCH_TIME
239 +       tristate  'TIME match support'
240 +       depends on IP_NF_IPTABLES
241 +       help
242 +         This option adds a `time' match, which allows you
243 +         to match based on the packet arrival time/date
244 +         (arrival time/date at the machine which netfilter is running on) or
245 +         departure time/date (for locally generated packets).
246 +       
247 +         If you say Y here, try iptables -m time --help for more information.
248 +        
249 +         If you want to compile it as a module, say M here and read
250 +         Documentation/modules.txt.  If unsure, say `N'.
251 +
252  endmenu
253  
254 diff -Nur --exclude '*.orig' linux.org/net/ipv4/netfilter/Makefile linux/net/ipv4/netfilter/Makefile
255 --- linux.org/net/ipv4/netfilter/Makefile       2006-06-18 01:49:35.000000000 +0000
256 +++ linux/net/ipv4/netfilter/Makefile   2006-08-29 12:37:43.000000000 +0000
257 @@ -0,0 +0,1 @@
258 +obj-$(CONFIG_IP_NF_MATCH_TIME) += ipt_time.o
This page took 0.062739 seconds and 3 git commands to generate.