├── LICENSE
├── Makefile
├── README.md
├── dnsproxy.c
└── dnsproxy.h
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | CURRENT = $(shell uname -r)
2 | KDIR = /lib/modules/$(CURRENT)/build
3 | PWD = $(shell pwd)
4 | DEST = /lib/modules/$(CURRENT)
5 | EXTRA_CFLAGS += -O3
6 | TARGET = dnsproxy
7 |
8 | obj-m := $(TARGET).o
9 |
10 | all: default clean
11 |
12 | default:
13 | $(MAKE) -C $(KDIR) M=$(PWD) modules
14 |
15 | install:
16 | sudo cp -v $(TARGET).ko $(DEST)
17 | sudo /sbin/insmod $(TARGET).ko
18 | sudo /sbin/lsmod | grep $(TARGET)
19 |
20 | uninstall:
21 | sudo /sbin/rmmod $(TARGET)
22 | sudo rm -v $(DEST)/$(TARGET).ko
23 |
24 | clean:
25 | @rm -f *.o .*.cmd .*.flags *.mod.c *.order
26 | @rm -f .*.*.cmd *.symvers *~ *.*~
27 | @rm -fR .tmp*
28 | @rm -rf .tmp_versions
29 |
30 | disclean: clean
31 | @rm -f *.ko *.symvers
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Сaching Dns proxy
2 |
3 | Сaching Dns proxy in the form of GNU/Linux kernel module.
4 |
5 | Module was written and tested on Ubuntu 12.04.5 Server 32-bit (3.13 kernel), GCC 4.6.3.
6 |
7 | Restrictions:
8 | * support only protocol IPv4
9 | * handles only requests of type A (i.e. conversion of the domain to the protocol IPv4)
10 | * limited cache size (specified during configuration)
11 | * delete cache on shutdown or restart (cache is located in RAM)
12 |
13 |
14 | ## How works caching Dns proxy
15 |
16 | Scheme of work module:
17 | ```txt
18 | +----------------------------------------------+
19 | /| /|
20 | +----------------------------------------------+ |
21 | | | | |
22 | | | Gateway machine | |
23 | | | | |
24 | | | ________________________________ | |
25 | +---------+ | | | | | | +----------+
26 | / /| | | | Kernel | | | / /|
27 | +---------+ | | | | | | | +----------+ |
28 | | | | | | | +-------+ +----------+ | | | | Dns | |
29 | | Client | |-----|-------|-->| Dns |---->| iptables |---|-----|------>| Server | |
30 | |(browser)| |<----|-------|---| proxy |<----| (NAT) |<--|-----|-------| on | |
31 | | |/ | | | +-------+ +----------+ | | | | Internet |/
32 | +---------+ | | | | ^ | | | +----------+
33 | | | | V | | | |
34 | | | | +-------+ | | |
35 | | | | | Cache | | | |
36 | | | | +-------+ | | |
37 | | | |________________________________| | |
38 | | | | |
39 | | |____________________________________________|_|
40 | |/ |/
41 | +----------------------------------------------+
42 | ```
43 |
44 |
45 | ## Main moments
46 | ### Listening of network traffic
47 |
48 | The path of the package inspection in the system **Netfilter**:
49 | ```txt
50 | +------------------+
51 | / /|
52 | +------------------+ |
53 | | | |
54 | | Network driver | |
55 | | |/
56 | +------------------+
57 | |
58 | V
59 | +-----------------------+
60 | / /|
61 | +-----------------------+ |
62 | | | |
63 | | NF_INET_PRE_ROUTING | |
64 | | |/
65 | +-----------------------+
66 | |
67 | V
68 | +-----------+ +-----------------------+
69 | / /| / /|
70 | +-----------+ | +-----------------------+ |
71 | | | | | | |
72 | | Routing | | --------> | NF_INET_LOCAL_IN | |
73 | | |/ | |/
74 | +-----------+ +-----------------------+
75 | | |
76 | | V
77 | +-----------------------+ +--------------------+
78 | / /| / /|
79 | +-----------------------+ | +--------------------+ |
80 | | | | | | |
81 | | NF_INET_FORWARD | | | Local IP service | |
82 | | |/ | |/
83 | +-----------------------+ +--------------------+
84 | | |
85 | V V
86 | +-----------+ +-----------------------+
87 | / /| / /|
88 | +-----------+ | +-----------------------+ |
89 | | | | | | |
90 | | Routing | | <-------- | NF_INET_LOCAL_OUT | |
91 | | |/ | |/
92 | +-----------+ +-----------------------+
93 | |
94 | V
95 | +-----------------------+
96 | / /|
97 | +-----------------------+ |
98 | | | |
99 | | NF_INET_POST_ROUTING | |
100 | | |/
101 | +-----------------------+
102 | |
103 | V
104 | +------------------+
105 | / /|
106 | +------------------+ |
107 | | | |
108 | | Network driver | |
109 | | |/
110 | +------------------+
111 | ```
112 | ### Data processing
113 |
114 | The format of the network packet:
115 | ```txt
116 | +----------+----------+----------+--------+
117 | / / / / /|
118 | +----------+----------+----------+--------+ |
119 | | | | | | |
120 | | MAC | IP | UPD | DNS | |
121 | | header | header | header | data | |
122 | | | | | |/
123 | +----------+----------+ ---------+--------+
124 | ```
125 | ### Forming a reply message
126 |
127 | The structure of the DNS packet:
128 | ```txt
129 | +----------+------------+----------+-------------+--------------+
130 | / / / / / /|
131 | +----------+------------+----------+-------------+--------------+ |
132 | | | | | | | |
133 | | Header | Question | Answer | Authority | Additional | |
134 | | | | | | |/
135 | +----------+------------+ ---------+-------------+--------------+
136 | ```
137 |
138 |
139 | ## Cache
140 |
141 | The entire cache is stored in RAM PC. Cache is implemented on a data structure: the hash table.
142 |
143 | The hash table is static and has a fixed size. The size is defined in the header file `dnsproxy.h` constant `HASHTAB_SIZE`.
144 |
145 | Used the **RS hash function** (for strings).
146 |
147 | Function listing:
148 | ```c
149 | static unsigned int rs_hash(unsigned char *str, unsigned int len)
150 | {
151 | unsigned int b = 378551;
152 | unsigned int a = 63689;
153 | unsigned int hash = 0;
154 | unsigned int i = 0;
155 |
156 | for (i = 0; i < len; str++, i++){
157 | hash = hash * a + (unsigned char)(*str);
158 | a *= b;
159 | }
160 |
161 | return (hash % HASHTAB_SIZE);
162 | }
163 | ```
164 | Advantage hash function:
165 | * fast calculation of the hash code
166 | * deterministic
167 | * uniform distribution of hash values
168 |
169 |
170 | ## Installing
171 |
172 | Building:
173 | ```bash
174 | $ make
175 | ```
176 | Installing:
177 | ```bash
178 | $ make install
179 | ```
180 | Uninstalling:
181 | ```bash
182 | $ make uninstall
183 | ```
184 |
185 |
186 | ## License
187 |
188 | This software is licensed under the terms of the GNU General Public License version 2.
189 |
--------------------------------------------------------------------------------
/dnsproxy.c:
--------------------------------------------------------------------------------
1 | /*
2 | **
3 | ** dnsproxy.c
4 | **
5 | ** About: Caching Dns proxy
6 | ** Author: oct2i
7 | ** Data: april/may 2015
8 | **
9 | ** This software is licensed under the terms of the GNU GPL version 2.
10 | **
11 | */
12 |
13 | #include "dnsproxy.h"
14 |
15 | /*
16 | * Register netfilter module.
17 | *
18 | */
19 | static int __init dnsproxy_start(void)
20 | {
21 | nf_register_hook(&HOOK_POST);
22 | nf_register_hook(&HOOK_PRE);
23 |
24 | hashtab_init(hashtab);
25 |
26 | printk(KERN_ALERT "Register dnsproxy.\nHashtable size: %d\n", HASHTAB_SIZE);
27 |
28 | return 0;
29 | }
30 |
31 |
32 | /*
33 | * Unregister netfilter module.
34 | *
35 | */
36 | static void __exit dnsproxy_stop(void)
37 | {
38 | nf_unregister_hook(&HOOK_POST);
39 | nf_unregister_hook(&HOOK_PRE);
40 |
41 | printk(KERN_ALERT "Unregister dnsproxy.\n");
42 | }
43 |
44 |
45 | /*
46 | * Netfilter POST_ROUTING.
47 | * Intercept Question data sent to the server DNS (port 'XX' -> port '53').
48 | * Processing data.
49 | * Return value: NF_ACCEPT or NF_DROP.
50 | */
51 | static unsigned int hook_post(unsigned int hooknum,
52 | struct sk_buff *skb,
53 | const struct net_device *in,
54 | const struct net_device *out,
55 | int (*okfn)(struct sk_buff *))
56 | {
57 | struct iphdr *ip_h;
58 | struct udphdr *udp_h;
59 |
60 | struct HEADER *dns_h;
61 | struct QUESTION *dns_q;
62 | //struct _QUESTION *dns__q;
63 |
64 | struct DATA_NODE dnode;
65 |
66 | unsigned int dns_q_qnamelen = 0;
67 |
68 | //ETHERNET
69 | if (skb->protocol == htons(ETH_P_IP)) {
70 | ip_h = ip_hdr(skb);
71 |
72 | //UDP
73 | if (ip_h->protocol == IPPROTO_UDP) {
74 | udp_h = (void *)(struct updhdr *)skb_transport_header(skb);
75 |
76 | if (udp_h->dest == ntohs(DNS_SERVER_PORT)) {
77 | /*
78 | printk(KERN_ALERT "--UDP dns-packet POST: %u -> %u\n",
79 | ntohs(udp_h->source),
80 | ntohs(udp_h->dest));
81 | */
82 | //DNS HEADER
83 | dns_h = (struct HEADER *)
84 | (skb->data + (ip_h->ihl * 4) + UPD_HDRLEN);
85 | /*
86 | printk(KERN_ALERT "DNS HEADER\n--ID=%u\n--QR=%u\n--QDCount=%u\n--ANCount=%u\n",
87 | ntohs(dns_h->id), (dns_h->qr),
88 | ntohs(dns_h->qd_count),
89 | ntohs(dns_h->an_count));
90 | */
91 | DNSH_ID = ntohs(dns_h->id);
92 |
93 | //DNS QUESTION
94 | dns_q = (struct QUESTION *)
95 | (skb->data + (ip_h->ihl * 4) + UPD_HDRLEN + DNS_HDRLEN);
96 |
97 | dns_q_qnamelen = get_datalen_question(dns_q);
98 | if (dns_q_qnamelen <= 0) {
99 | return NF_ACCEPT;
100 | }
101 |
102 | /*
103 | printk(KERN_ALERT "domain name: ");
104 | for (i = 0; i < bufflen; i++) {
105 | printk(KERN_ALERT "%c", buff[i]);
106 | }
107 | */
108 |
109 | /*
110 | dns__q = (struct _QUESTION *)
111 | (skb->data + (ip_h->ihl * 4) + UPD_HDRLEN + DNS_HDRLEN +
112 | dns_q_qnamelen);
113 | printk(KERN_ALERT "DNS QUESTION\n--QName=%s\n--QType=%u\n--QClass=%u\n\n",
114 | dns_q,
115 | ntohs(dns__q->q_type),
116 | ntohs(dns__q->q_class));
117 | */
118 |
119 | dnode = hashtab_lookup(hashtab, dns_q, dns_q_qnamelen);
120 |
121 | if (dnode.flag == FLAG_FILLING_0) {
122 | hashtab_add_key(hashtab, dns_q, dns_q_qnamelen);
123 | }
124 | else if ( (dnode.flag == FLAG_FILLING_2) && (dnode.node != NULL) ) {
125 | send_reply_dnspacket(skb, ip_h->saddr, \
126 | udp_h->source, \
127 | ip_h->daddr, dnode.node);
128 |
129 | printk(KERN_ALERT "** SEND REPLY DNS PACKET **\n");
130 |
131 | return NF_DROP;
132 | }
133 | }
134 | }
135 | }
136 |
137 | return NF_ACCEPT;
138 | }
139 |
140 |
141 | /*
142 | * Netfilter PRE_ROUTING.
143 | * Intercept Answer data sent from the server DNS (port 'XX' <- port '53').
144 | * Processing data.
145 | * Return value: NF_ACCEPT.
146 | */
147 | static unsigned int hook_pre(unsigned int hooknum,
148 | struct sk_buff *skb,
149 | const struct net_device *in,
150 | const struct net_device *out,
151 | int (*okfn)(struct sk_buff *))
152 | {
153 | struct iphdr *ip_h;
154 | struct udphdr *udp_h;
155 |
156 | struct HEADER *dns_h;
157 | struct QUESTION *dns_q;
158 | //struct _QUESTION *dns__q;
159 | struct ANSWER *dns_a;
160 | struct _ANSWER *dns__a;
161 |
162 | struct DATA_NODE dnode;
163 |
164 | unsigned int dns_q_qnamelen = 0;
165 | unsigned int dns_a_len = 0;
166 |
167 | //ETHERNET
168 | if (skb->protocol == htons(ETH_P_IP)) {
169 | ip_h = ip_hdr(skb);
170 |
171 | //UDP
172 | if (ip_h->protocol == IPPROTO_UDP) {
173 | udp_h = (void *)(struct updhdr *)skb_transport_header(skb);
174 |
175 | if (udp_h->source == ntohs(DNS_SERVER_PORT)) {
176 | /*
177 | printk(KERN_ALERT "--UDP dns-packet PRE: %u <- %u\n",
178 | ntohs(udp_h->dest),
179 | ntohs(udp_h->source));
180 | */
181 | //DNS HEADER
182 | dns_h = (struct HEADER *)
183 | (skb->data + (ip_h->ihl * 4) + UPD_HDRLEN);
184 | /*
185 | printk(KERN_ALERT "DNS HEADER\n--ID=%u\n--QR=%u\n--QDCount=%u\n--ANCount=%u\n",
186 | ntohs(dns_h->id), dns_h->qr,
187 | ntohs(dns_h->qd_count),
188 | ntohs(dns_h->an_count));
189 | */
190 | DNSA_ANCOUNT = ntohs(dns_h->an_count);
191 |
192 | //DNS QUESTION
193 | dns_q = (struct QUESTION *)
194 | (skb->data + (ip_h->ihl * 4) + UPD_HDRLEN + DNS_HDRLEN);
195 |
196 | dns_q_qnamelen = get_datalen_question(dns_q);
197 | if (dns_q_qnamelen <= 0) {
198 | return NF_ACCEPT;
199 | }
200 |
201 | /*
202 | dns__q = (struct _QUESTION *)
203 | (skb->data + (ip_h->ihl * 4) + UPD_HDRLEN + DNS_HDRLEN +
204 | dns_q_qnamelen);
205 | printk(KERN_ALERT "DNS QUESTION\n--QName=%s\n--QType=%u\n--QClass=%u\n",
206 | dns_q,
207 | ntohs(dns__q->q_type),
208 | ntohs(dns__q->q_class));
209 | */
210 |
211 | //DNS ANSWER
212 | dns__a = (struct _ANSWER *)
213 | (skb->data + (ip_h->ihl * 4) + UPD_HDRLEN + DNS_HDRLEN +
214 | (dns_q_qnamelen + DNS_Q_CONSTLEN) + DNS_A_OFFSET);
215 | /*
216 | printk(KERN_ALERT "DNS ANSWER\n--Type=%u\n--Class=%u\n--TTL=%d\n--RDLen=%u\n\n",
217 | ntohs(dns__a->type),
218 | ntohs(dns__a->_class), dns__a->ttl,
219 | ntohs(dns__a->rd_length));
220 | */
221 |
222 | //Pointer on DNS ANSWER
223 | dns_a = (struct ANSWER *)
224 | (skb->data + (ip_h->ihl * 4) + UPD_HDRLEN + DNS_HDRLEN +
225 | (dns_q_qnamelen + DNS_Q_CONSTLEN));
226 |
227 | dns_a_len = get_datalen_answer();
228 | if (dns_a_len <= 0) {
229 | return NF_ACCEPT;
230 | }
231 |
232 | dnode = hashtab_lookup(hashtab, dns_q, dns_q_qnamelen);
233 |
234 | if ( (dnode.flag == FLAG_FILLING_1) && (dnode.node != NULL) ) {
235 | hashtab_add_value(dnode.node, dns_a, dns_a_len);
236 | }
237 | }
238 | }
239 | }
240 |
241 | return NF_ACCEPT;
242 | }
243 |
244 |
245 | /*
246 | * Get length Question DNS.
247 | * Parsing domain name and counting length.
248 | * Return value: length field 'q_name'.
249 | */
250 | static unsigned int get_datalen_question(struct QUESTION *dnsq)
251 | {
252 | unsigned char *buff;
253 | unsigned int i;
254 | unsigned int index = 0;
255 | unsigned int bufflen = 1;
256 |
257 | buff = (unsigned char *)kmalloc(bufflen, GFP_KERNEL);
258 | memset(buff, 0, bufflen);
259 | memcpy(buff, dnsq, bufflen);
260 |
261 | for ( ; (unsigned int)buff[index] != 0; ) {
262 | // while ( (unsigned int)buff[index] != 0 ) {
263 |
264 | for (i = 1; i <= (QNAME_MAXLEN + 1); i++) {
265 | if ((unsigned int)buff[index] == i) {
266 | bufflen += i;
267 | bufflen++;
268 | index = bufflen;
269 | index--;
270 | break;
271 | }
272 | }
273 |
274 | if (i == (QNAME_MAXLEN + 1)) {
275 | printk(KERN_ERR "\nERROR: length domain name more '63' symbols\n\n");
276 | kfree(buff);
277 | return -1;
278 | }
279 |
280 | buff = (unsigned char *)kmalloc(bufflen, GFP_KERNEL);
281 | memset(buff, 0, bufflen);
282 | memcpy(buff, dnsq, bufflen);
283 | }
284 |
285 | if ( (index == 0) && ((unsigned int)buff[index] == 0) ) {
286 | printk(KERN_ERR "\nERROR: length domain name is equal '0' symbols\n\n");
287 | kfree(buff);
288 | return -1;
289 | }
290 |
291 | kfree(buff);
292 | return bufflen;
293 | }
294 |
295 |
296 | /*
297 | * Get length Answer DNS.
298 | * Counting length.
299 | * Return value: length section Answer.
300 | */
301 | static unsigned int get_datalen_answer(void)
302 | {
303 | return (DNS_ANSWLEN * (DNSA_ANCOUNT + CONSTMAGIC));
304 | }
305 |
306 |
307 | /*
308 | * Sending a response packet DNS.
309 | * The formation of the packet.
310 | * Sending packet routing circuit.
311 | * Return value: no.
312 | *
313 | */
314 | static void send_reply_dnspacket(struct sk_buff *in_skb,
315 | unsigned int dst_ip,
316 | unsigned int dst_port,
317 | unsigned int src_ip,
318 | struct NODE *node)
319 | {
320 | struct sk_buff *nskb;
321 | struct iphdr *ip_h;
322 | struct udphdr *udp_h;
323 |
324 | struct HEADER *dns_h;
325 | struct _QUESTION *dns__q;
326 |
327 | unsigned char *data_q;
328 | void *data_a;
329 |
330 | unsigned int dns_q_len;
331 | unsigned int dns_a_len;
332 | unsigned int udp_len;
333 |
334 | dns_q_len = (node->key_len);
335 | dns_a_len = (node->value_len);
336 | udp_len = (UPD_HDRLEN + DNS_HDRLEN + dns_q_len + dns_a_len);
337 |
338 | nskb = alloc_skb(sizeof(struct iphdr) + udp_len + LL_MAX_HEADER, GFP_ATOMIC);
339 | if (!nskb) {
340 | printk (KERN_ERR "ERROR! Allocate memory to DNS reply\n");
341 | return;
342 | }
343 |
344 | skb_reserve(nskb, LL_MAX_HEADER);
345 | skb_reset_network_header(nskb);
346 |
347 | //IP HEADER
348 | ip_h = (struct iphdr *)skb_put(nskb, sizeof(struct iphdr));
349 | ip_h->version = 4;
350 | ip_h->ihl = sizeof(struct iphdr) / 4;
351 | ip_h->ttl = 64;
352 | ip_h->tos = 0;
353 | ip_h->id = 0;
354 | ip_h->frag_off = htons(IP_DF);
355 | ip_h->protocol = IPPROTO_UDP;
356 | ip_h->saddr = src_ip;
357 | ip_h->daddr = dst_ip;
358 | ip_h->tot_len = htons(sizeof(struct iphdr) + udp_len);
359 | ip_h->check = 0;
360 | ip_h->check = ip_fast_csum((unsigned char *)ip_h, ip_h->ihl);
361 |
362 | //UDP HEADER
363 | udp_h = (struct udphdr *)skb_put(nskb, UPD_HDRLEN);
364 | memset(udp_h, 0, sizeof(*udp_h));
365 | udp_h->source = htons(DNS_SERVER_PORT);
366 | udp_h->dest = dst_port;
367 | udp_h->len = htons(udp_len);
368 |
369 | //DNS HEADER
370 | dns_h = (struct HEADER *)skb_put(nskb, DNS_HDRLEN);
371 | dns_h->id = (unsigned short) htons(DNSH_ID);
372 | dns_h->qr = 0;
373 | dns_h->opcode = 0;
374 | dns_h->aa = 0;
375 | dns_h->tc = 0;
376 | dns_h->rd = 1;
377 | dns_h->ra = 0;
378 | dns_h->z = 0;
379 | dns_h->ad = 0;
380 | dns_h->cd = 0;
381 | dns_h->rcode = 0;
382 | dns_h->qd_count = htons(1);
383 | dns_h->an_count = htons(DNSA_ANCOUNT);
384 | dns_h->ns_count = 0;
385 | dns_h->ar_count = 0;
386 |
387 | skb_dst_set(nskb, dst_clone(skb_dst(in_skb)));
388 | nskb->protocol = htons(ETH_P_IP);
389 |
390 | //DNS QUESTION field 'q_name'
391 | data_q = (char *)skb_put(nskb, dns_q_len);
392 | memcpy(data_q, (node->key), dns_q_len);
393 |
394 | //DNS QUESTION fields 'q_type' and 'q_class'
395 | dns__q = (struct _QUESTION *)skb_put(nskb, DNS_Q_CONSTLEN);
396 | dns__q->q_type = htons(1);
397 | dns__q->q_class = htons(1);
398 |
399 | //DNS ANSWER
400 | data_a = (void *)skb_put(nskb, dns_a_len);
401 | memcpy(data_a, (node->value), dns_a_len);
402 |
403 | //UDP HEADER continuation
404 | udp_h->check = 0;
405 | udp_h->check = csum_tcpudp_magic(src_ip, dst_ip,
406 | udp_len, IPPROTO_UDP,
407 | csum_partial(udp_h, udp_len, 0));
408 |
409 | if (ip_route_me_harder(nskb, RTN_UNSPEC)) {
410 | printk (KERN_ERR "\nERROR: fail function ip_route_me_harder()\n");
411 | kfree_skb(nskb);
412 | }
413 |
414 | ip_local_out(nskb);
415 | return;
416 | }
417 |
418 |
419 | /*
420 | * Hash function for type data 'unsigned char'.
421 | * Return the hash value of the function is the
422 | * address of a cell in the main memory, which
423 | * will be located on a pair of (key, value).
424 | *
425 | */
426 | static unsigned int rs_hash(unsigned char *str, unsigned int len)
427 | {
428 | unsigned int b = 378551;
429 | unsigned int a = 63689;
430 | unsigned int hash = 0;
431 | unsigned int i = 0;
432 |
433 | for (i = 0; i < len; str++, i++) {
434 | hash = hash * a + (unsigned char)(*str);
435 | a *= b;
436 | }
437 |
438 | return (hash % HASHTAB_SIZE);
439 | }
440 |
441 |
442 | /*
443 | * Initialization hash table.
444 | */
445 | static void hashtab_init(struct NODE **hashtab)
446 | {
447 | unsigned int i;
448 |
449 | for (i = 0; i < HASHTAB_SIZE; i++) {
450 | hashtab[i] = NULL;
451 | }
452 | }
453 |
454 |
455 | /*
456 | * Lookup slot in hash table.
457 | * Return 'struct DATA_NODE' contains fields 'flag' and 'ptr on node'.
458 | *
459 | */
460 | static struct DATA_NODE hashtab_lookup(struct NODE **hashtab,
461 | struct QUESTION *dnsq,
462 | unsigned int dnsqlen)
463 | {
464 | unsigned char *key;
465 | unsigned int index = 0;
466 |
467 | struct NODE *node;
468 |
469 | struct DATA_NODE dnode = {
470 | .flag = FLAG_FILLING_0,
471 | .node = NULL,
472 | };
473 |
474 | key = (unsigned char *)kmalloc(dnsqlen, GFP_KERNEL);
475 | memset(key, 0, dnsqlen);
476 | memcpy(key, dnsq, dnsqlen);
477 |
478 | index = rs_hash(key, dnsqlen);
479 |
480 | for (node = hashtab[index];
481 | node != NULL;
482 | node = node->next)
483 | {
484 | if (memcmp(node->key, key, dnsqlen) == 0) {
485 | dnode.flag = FLAG_FILLING_1;
486 | dnode.node = node;
487 | if (node->value_len != 0) {
488 | dnode.flag = FLAG_FILLING_2;
489 | }
490 | }
491 | }
492 | /*
493 | printk(KERN_ALERT "\n*** RESULT = %d\n", dnode.flag);
494 | */
495 |
496 | kfree(key);
497 | return dnode;
498 | }
499 |
500 |
501 | /*
502 | * Creation hash table slot.
503 | * Addition data 'question' i.e.'key'.
504 | */
505 | static void hashtab_add_key(struct NODE **hashtab,
506 | struct QUESTION *dnsq,
507 | unsigned int dnsqlen)
508 | {
509 | unsigned char *key;
510 | unsigned int index = 0;
511 |
512 | struct NODE *node;
513 |
514 | key = (unsigned char *)kmalloc(dnsqlen, GFP_KERNEL);
515 | memset(key, 0, dnsqlen);
516 | memcpy(key, dnsq, dnsqlen);
517 |
518 | index = rs_hash(key, dnsqlen);
519 |
520 | node = kmalloc(sizeof(*node), GFP_KERNEL);
521 | if (node != NULL) {
522 | node->key = key;
523 | node->key_len = dnsqlen;
524 | node->value_len = 0;
525 | node->next = hashtab[index];
526 | hashtab[index] = node;
527 | }
528 | /*
529 | printk(KERN_ALERT "\n~~~ add node->key\n");
530 | */
531 | }
532 |
533 |
534 | /*
535 | * Addition hash table slot data 'answer' i.e. 'value'.
536 | */
537 | static void hashtab_add_value(struct NODE *node,
538 | struct ANSWER *dnsa,
539 | unsigned int dnsalen)
540 | {
541 | void *value;
542 |
543 | value = (void *)kmalloc(dnsalen, GFP_KERNEL);
544 | memset(value, 0, dnsalen);
545 | memcpy(value, dnsa, dnsalen);
546 |
547 | node->value = value;
548 | node->value_len = dnsalen;
549 | /*
550 | printk (KERN_ALERT "\n~~~ add node->value\n");
551 | */
552 | }
553 |
554 | module_init(dnsproxy_start);
555 | module_exit(dnsproxy_stop);
556 |
557 | MODULE_AUTHOR("oct2i");
558 | MODULE_DESCRIPTION("Caching Dns proxy");
559 | MODULE_LICENSE("GPLv2");
560 |
561 |
--------------------------------------------------------------------------------
/dnsproxy.h:
--------------------------------------------------------------------------------
1 | /*
2 | **
3 | ** dnsproxy.h
4 | **
5 | ** About: Caching Dns proxy
6 | ** Author: oct2i
7 | ** Data: april/may 2015
8 | **
9 | ** This software is licensed under the terms of the GNU GPL version 2.
10 | **
11 | */
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 |
19 | #include
20 | #include
21 | #include
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #define DNS_SERVER_PORT 53
29 | #define UPD_HDRLEN 8
30 | #define DNS_HDRLEN 12
31 | #define DNS_ANSWLEN 16
32 | #define DNS_Q_CONSTLEN 4 /* Constant sized fields struct _QUESTION */
33 | #define DNS_A_OFFSET 2 /* Offset in association with DNS packet compression */
34 | #define QNAME_MAXLEN 63
35 | #define CONSTMAGIC 1
36 |
37 | /* Filling fields hash table 'key' and 'value' */
38 | #define FLAG_FILLING_0 0 /* Filling zero fields */
39 | #define FLAG_FILLING_1 1 /* Filling one field 'key' */
40 | #define FLAG_FILLING_2 2 /* Filling two fields 'key' and 'value' */
41 |
42 | #define HASHTAB_SIZE 8192
43 |
44 | static unsigned short DNSH_ID;
45 | static unsigned int DNSA_ANCOUNT;
46 |
47 | /******************* NETFILTER FUNCTIONS *******************/
48 | static unsigned int hook_post(unsigned int hooknum,
49 | struct sk_buff *skb,
50 | const struct net_device *in,
51 | const struct net_device *out,
52 | int (*okfn)(struct sk_buff *));
53 |
54 | static unsigned int hook_pre(unsigned int hooknum,
55 | struct sk_buff *skb,
56 | const struct net_device *in,
57 | const struct net_device *out,
58 | int (*okfn)(struct sk_buff *));
59 |
60 | /******************* NETFILTER STRUCTURS *******************/
61 | static struct nf_hook_ops HOOK_POST = {
62 | .hook = (void *)hook_post,
63 | .owner = THIS_MODULE,
64 | .pf = NFPROTO_IPV4,
65 | .hooknum = NF_INET_POST_ROUTING,
66 | .priority = NF_IP_PRI_FIRST,
67 | };
68 |
69 | static struct nf_hook_ops HOOK_PRE = {
70 | .hook = (void *)hook_pre,
71 | .owner = THIS_MODULE,
72 | .pf = NFPROTO_IPV4,
73 | .hooknum = NF_INET_PRE_ROUTING,
74 | .priority = NF_IP_PRI_FIRST,
75 | };
76 |
77 |
78 | /******************* DNS STRUCTURS *******************/
79 | /* Structure of Header DNS */
80 | struct HEADER
81 | {
82 | unsigned short id; // identification number
83 |
84 | /******* flags ********/
85 | unsigned char qr :1; // query/response flag
86 | unsigned char opcode :4; // purpose of message
87 | unsigned char aa :1; // authoritive answer
88 | unsigned char tc :1; // truncated message
89 | unsigned char rd :1; // recursion desired
90 | unsigned char ra :1; // recursion available
91 | unsigned char z :1; // its z! reserved
92 | unsigned char ad :1; // authenticated data
93 | unsigned char cd :1; // checking disabled
94 | unsigned char rcode :4; // response code
95 | /**********************/
96 |
97 | unsigned short qd_count; // number of question entries
98 | unsigned short an_count; // number of answer entries
99 | unsigned short ns_count; // number of authority entries
100 | unsigned short ar_count; // number of resource entries
101 | };
102 |
103 | /* Constant sized fields of Question structure */
104 | struct _QUESTION
105 | {
106 | unsigned short q_type;
107 | unsigned short q_class;
108 | };
109 |
110 | /* Structure of a Question DNS */
111 | struct QUESTION
112 | {
113 | unsigned char *q_name;
114 | struct _QUESTION *question;
115 | };
116 |
117 | /* Constant sized fields of Answer structure */
118 | struct _ANSWER
119 | {
120 | unsigned short type;
121 | unsigned short _class;
122 | unsigned int ttl; // number of seconds
123 | unsigned short rd_length; // length field rdata
124 | };
125 |
126 | /* Structure of a Answer DNS */
127 | struct ANSWER
128 | {
129 | unsigned char *name;
130 | struct _ANSWER *answer;
131 | unsigned char *rdata;
132 | };
133 |
134 |
135 | /******************* HASH TABLE STRUCTURS *******************/
136 | /* Hash table slot */
137 | struct NODE
138 | {
139 | unsigned char *key;
140 | void *value;
141 | unsigned int key_len;
142 | unsigned int value_len;
143 |
144 | struct NODE *next;
145 | };
146 |
147 | /* Data node hash table */
148 | struct DATA_NODE
149 | {
150 | unsigned int flag;
151 | struct NODE *node;
152 | };
153 |
154 | /* Declaration hash table*/
155 | static struct NODE *hashtab[HASHTAB_SIZE];
156 |
157 | /******************* HASH TABLE FUNCTIONS *******************/
158 | static unsigned int rs_hash(unsigned char *str, unsigned int len);
159 | static void hashtab_init(struct NODE **hashtab);
160 | static struct DATA_NODE hashtab_lookup(struct NODE **hashtab,
161 | struct QUESTION *dnsq,
162 | unsigned int dnsqlen);
163 | static void hashtab_add_key(struct NODE **hashtab,
164 | struct QUESTION *dnsq,
165 | unsigned int dnsqlen);
166 | static void hashtab_add_value(struct NODE *node,
167 | struct ANSWER *dnsa,
168 | unsigned int dnsalen);
169 |
170 | /******************* DNS DATA FUNCTIONS *******************/
171 | static unsigned int get_datalen_question(struct QUESTION *dnsq);
172 | static unsigned int get_datalen_answer(void);
173 | static void send_reply_dnspacket(struct sk_buff *in_skb,
174 | unsigned int dst_ip,
175 | unsigned int dst_port,
176 | unsigned int src_ip,
177 | struct NODE *node);
178 |
179 |
--------------------------------------------------------------------------------