Browse Source

git repo init

Kirill Sotnikov 11 years ago
parent
commit
f1761cad9a
100 changed files with 38947 additions and 0 deletions
  1. 24
    0
      AUTHORS
  2. 340
    0
      COPYING
  3. 295
    0
      ChangeLog
  4. 231
    0
      INSTALL
  5. 1
    0
      Makefile.am
  6. 560
    0
      Makefile.in
  7. 1
    0
      NEWS
  8. 272
    0
      README
  9. 932
    0
      aclocal.m4
  10. 1517
    0
      config.guess
  11. 1598
    0
      config.sub
  12. 6749
    0
      configure
  13. 184
    0
      configure.ac
  14. 530
    0
      depcomp
  15. 14
    0
      doc/README
  16. 51
    0
      doc/articles/Ntk_Developing_World
  17. 29
    0
      doc/articles/Ntk_New_Global_Net
  18. 28
    0
      doc/articles/Ntk_New_Global_Net.fr
  19. 19
    0
      doc/articles/Ntk_New_Global_Net.ita
  20. 66
    0
      doc/articles/Ntk_civic_net
  21. 68
    0
      doc/articles/Ntk_civic_net.fr
  22. 91
    0
      doc/articles/Ntk_civic_net.ita
  23. 223
    0
      doc/faq/FAQ
  24. 27
    0
      doc/faq/FAQ.fr
  25. 65
    0
      doc/faq/FAQ.ru
  26. 147
    0
      doc/howto/igs_howto
  27. 1616
    0
      doc/main_doc/netsukuku
  28. 1208
    0
      doc/main_doc/netsukuku.ita
  29. 130
    0
      doc/main_doc/ntk_rfc/Ntk_IGS
  30. 56
    0
      doc/main_doc/ntk_rfc/Ntk_MX_request
  31. 203
    0
      doc/main_doc/ntk_rfc/Ntk_SNSD
  32. 436
    0
      doc/main_doc/ntk_rfc/Ntk_andna_and_dns
  33. 38
    0
      doc/main_doc/ntk_rfc/Ntk_andna_counter_pubk
  34. 121
    0
      doc/main_doc/ntk_rfc/Ntk_bandwidth_measurement
  35. 198
    0
      doc/main_doc/ntk_rfc/Ntk_gnodes_contiguity
  36. 46
    0
      doc/main_doc/ntk_rfc/Ntk_life_probability
  37. 64
    0
      doc/main_doc/ntk_rfc/Ntk_restricted_ip_classes
  38. 193
    0
      doc/main_doc/ntk_rfc/Ntk_viphilama
  39. 160
    0
      doc/manuals/andna
  40. 241
    0
      doc/manuals/netsukuku.conf
  41. 208
    0
      doc/manuals/ntk-resolv
  42. 54
    0
      doc/manuals/ntk-wifi
  43. 243
    0
      doc/manuals/ntkd
  44. 95
    0
      doc/misc/Ntk_Grow_Netsukuku
  45. 36
    0
      doc/misc/Ntk_Internet_tunnels
  46. 100
    0
      doc/misc/Ntk_features_list
  47. 157
    0
      doc/misc/Ntk_scalability
  48. 12
    0
      doc/misc/mailinglist
  49. 3077
    0
      doc/misc/rfc1035.txt
  50. 323
    0
      install-sh
  51. 360
    0
      missing
  52. 21
    0
      src/Makefile.am
  53. 656
    0
      src/Makefile.in
  54. 215
    0
      src/SConstruct
  55. 185
    0
      src/TODO
  56. 276
    0
      src/accept.c
  57. 75
    0
      src/accept.h
  58. 2507
    0
      src/andna.c
  59. 273
    0
      src/andna.h
  60. 2154
    0
      src/andna_cache.c
  61. 499
    0
      src/andna_cache.h
  62. 959
    0
      src/andns.c
  63. 86
    0
      src/andns.h
  64. 610
    0
      src/andns_lib.c
  65. 136
    0
      src/andns_lib.h
  66. 297
    0
      src/andns_net.c
  67. 32
    0
      src/andns_net.h
  68. 316
    0
      src/andns_snsd.c
  69. 22
    0
      src/andns_snsd.h
  70. 454
    0
      src/bmap.c
  71. 169
    0
      src/bmap.h
  72. 36
    0
      src/buffer.c
  73. 76
    0
      src/buffer.h
  74. 9
    0
      src/common.h
  75. 136
    0
      src/conf.c
  76. 120
    0
      src/conf.h
  77. 1
    0
      src/conf/Makefile.am
  78. 321
    0
      src/conf/Makefile.in
  79. 6
    0
      src/conf/SConscript
  80. 16
    0
      src/conf/andna_hostnames
  81. 199
    0
      src/conf/netsukuku.conf.in
  82. 199
    0
      src/conf/ntk_scons.conf.in
  83. 53
    0
      src/conf/snsd_nodes
  84. 106
    0
      src/config.h.in
  85. 10
    0
      src/config_scons.h.in
  86. 164
    0
      src/crypto.c
  87. 46
    0
      src/crypto.h
  88. 459
    0
      src/daemon.c
  89. 55
    0
      src/daemon.h
  90. 174
    0
      src/dns_wrapper.c
  91. 50
    0
      src/dns_wrapper.h
  92. 888
    0
      src/dnslib.c
  93. 189
    0
      src/dnslib.h
  94. 219
    0
      src/endianness.c
  95. 109
    0
      src/endianness.h
  96. 69
    0
      src/err_errno.c
  97. 95
    0
      src/err_errno.h
  98. 1493
    0
      src/gmap.c
  99. 270
    0
      src/gmap.h
  100. 0
    0
      src/hash.c

+ 24
- 0
AUTHORS View File

@@ -0,0 +1,24 @@
1
+Main authors and maintainers:
2
+
3
+Andrea Lo Pumo aka AlpT <alpt@netsukuku.org>
4
+
5
+
6
+Contributors (in chronological order of initial contribution):
7
+
8
+Andrea Leofreddi <andrea.leofreddi@gmail.com> wrote the first implementation
9
+of the DNS wrapper code (dns_pkt.cpp, dns_rendian.h, dns_utils.h).  
10
+
11
+Enzo Nicosia (Katolaz) <katolaz@netsukuku.org> wrote the files needed to use
12
+Automake/Autoconf. (Makefile.am configure.ac, src/Makefile.am,
13
+src/man/Makefile.am).
14
+
15
+Federico Tomassini (Efphe) <efphe@netsukuku.org> wrote andns, which provides
16
+DNS compatibility for the ANDNA system. He also wrote the interface to the
17
+libiptc. (andns* ntkresolv.* dnslib.[ch] mark.[ch] libiptc/*)
18
+
19
+
20
+Website developers and maintainers:
21
+
22
+Crash 		<crash@netsukuku.org>,
23
+Entropika	<e@entropika.net>,
24
+Black		<black@netsukuku.org>

+ 340
- 0
COPYING View File

@@ -0,0 +1,340 @@
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 Library 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
+    <one line to give the program's name and a brief idea of what it does.>
294
+    Copyright (C) <year>  <name of author>
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
307
+    along with this program; if not, write to the Free Software
308
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
309
+
310
+
311
+Also add information on how to contact you by electronic and paper mail.
312
+
313
+If the program is interactive, make it output a short notice like this
314
+when it starts in an interactive mode:
315
+
316
+    Gnomovision version 69, Copyright (C) year name of author
317
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318
+    This is free software, and you are welcome to redistribute it
319
+    under certain conditions; type `show c' for details.
320
+
321
+The hypothetical commands `show w' and `show c' should show the appropriate
322
+parts of the General Public License.  Of course, the commands you use may
323
+be called something other than `show w' and `show c'; they could even be
324
+mouse-clicks or menu items--whatever suits your program.
325
+
326
+You should also get your employer (if you work as a programmer) or your
327
+school, if any, to sign a "copyright disclaimer" for the program, if
328
+necessary.  Here is a sample; alter the names:
329
+
330
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
332
+
333
+  <signature of Ty Coon>, 1 April 1989
334
+  Ty Coon, President of Vice
335
+
336
+This General Public License does not permit incorporating your program into
337
+proprietary programs.  If your program is a subroutine library, you may
338
+consider it more useful to permit linking proprietary applications with the
339
+library.  If this is what you want to do, use the GNU Library General
340
+Public License instead of this License.

+ 295
- 0
ChangeLog View File

@@ -0,0 +1,295 @@
1
+==== 0.0.9b ====
2
+
3
+New features:
4
+
5
+	* ntk-resolv has the new option "-l"
6
+
7
+	* An active tcp socket is kept for each rnode, in this way, it is
8
+	  possible to send them tcp packets without the need of estabilishing
9
+	  a new tcp connection each time.
10
+	
11
+	* The qspn packets are now sent using the tcp sockets described above.
12
+
13
+	* Since the UDP isn't used anymore for ntk packets, the udp daemon has
14
+	  been removed. The udp port of the radar daemon is now 269/udp.
15
+	  The 271/udp port has been deprecated.
16
+	
17
+	* When we have multiple interfaces to reach the same rnode, send the
18
+	  QSPN packets from a random device, each time.
19
+
20
+	* Code cleaned
21
+
22
+Bug fixes:
23
+	
24
+	* gcc-4 compilation warnings fixed.
25
+
26
+	* SNSD recursion works in ntk-resolv
27
+
28
+
29
+==== 0.0.8b ====
30
+
31
+New features:
32
+	
33
+	* The Scattered Name Service Disgregation (NTK_RFC 0009) has been
34
+	  implemented.
35
+	  See http://lab.dyne.org/Ntk_SNSD and the man page of andna(8).
36
+
37
+	* ntk-resolve has been updated to support SNSD queries.
38
+	  
39
+	* The `netsukuku_d' binary and its man page have been renamed to `ntkd'
40
+	  `netsukuku_wifi' and its man page have been renamed to `ntk-wifi'.
41
+	
42
+	* Static binaries and packages are now available.
43
+	  http://netsukuku.freaknet.org/packages/
44
+
45
+	* Netsukuku has been compiled for OpenWRT:
46
+	  http://netsukuku.freaknet.org/openwrt/
47
+
48
+	* NetsukukuD compresses automatically packets > 1024 bytes using the
49
+	  zlib.
50
+
51
+	* A pid file is written on /var/run/ntkd.pid. It is used to check if
52
+	  other instances of ntkd are already running.
53
+
54
+	* The new option `use_shared_internet' has been added. It specifies if
55
+	  ntkd will load balance the Internet traffic of this host using the 
56
+	  Inet connections shared by the Netsukuku nodes.
57
+
58
+	* The new command line option `-l' specifies that ntkd should send all
59
+	  of its messages to the specified file.
60
+
61
+	* The scripts ip_masquerade.sh, tc_shaper.sh, rc.ntk, ntk-wifi, are
62
+	  not dependent on bash anymore.
63
+
64
+	* The ANDNA keyring is now saved separately from the lcl_cache. It is
65
+	  saved in andna_lcl_keyring.
66
+
67
+	* The `andna_' prefix is now used for the filename of the andna
68
+	  caches.
69
+
70
+Bug fixes:
71
+
72
+	* A workaround to the gcc 27945 bug
73
+	  ( http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27945 ) has been
74
+	  implemented. The nodes affected with bug receive malformed packets
75
+	  during the hook.
76
+	
77
+	* The outgoing traffic to a node of the LAN is not shaped anymore.
78
+
79
+	* There was a bug that incremented the `hname_updates' counter, in the
80
+	  andna_cache of a hostname, even if the registration/update was
81
+	  rejected. Having wrong `hname_updates' counter, led to some
82
+	  syncronization problems.
83
+
84
+	* Ntkd is now able to detect, while running, the remotion of a network
85
+	  device it was using.
86
+
87
+	* Various memory leaks have been fixed.
88
+
89
+	* A workaround for the way getopt handles the optional arguments (i.e.
90
+	  -r in ntkd) has been written. It is now possible to write 
91
+	  ntkd -drdddD without expecting strange behaviours. See
92
+	  http://www.freaknet.org/alpt/src/patches/getopt-opt-arg/readme
93
+
94
+	* The code has been optimized and cleaned.
95
+
96
+Extra:
97
+
98
+	* The man page for netsukuku.conf has been written.
99
+	  netsukuku.conf(5).
100
+
101
+==== 0.0.7b ====
102
+
103
+New features:
104
+	
105
+	* Multi-inet-gateways. 
106
+	  The Netsukuku nodes will now automatically use multiple
107
+	  inet-gateways to connect to the Internet, therefore their Internet
108
+	  connection will be effectively load-balanced.
109
+	  
110
+	* Anti-loop multi-igw shield. 
111
+	  The nodes which share their Internet connection will also
112
+	  automatically use the shared connection of the other nodes. Through
113
+	  a simple marking system, death loops are avoided.
114
+	  
115
+	* Traffic shaping.
116
+	  The nodes which share their Internet connection can now shape it, in
117
+	  this way they'll prioritize their local outgoingtraffic and the
118
+	  lowdelay one (f.e. SSH).
119
+
120
+	* The lowdelay TOS is now set in the ANDNA resolve requests.
121
+
122
+
123
+Bug fixes:
124
+	
125
+	* When all the rnodes die, the radar resets the qspn counters
126
+	
127
+	* Code cleaned
128
+
129
+	* A lot of bugs, which you haven't and you will never heard, have been
130
+	  fixed. We've already forgotten them.
131
+
132
+
133
+==== 0.0.6b ====
134
+	
135
+New features:
136
+
137
+	* The NTK_RFC 0008 has been implemented.
138
+	  ( http://lab.dyne.org/Ntk_restricted_ip_classes )
139
+
140
+Bug fixes:
141
+
142
+	* The NTK_RFC 0007 has been implemented. It fixes an exploitable bug
143
+	  in the ANDNA protocol.
144
+
145
+	* NetsukukuD has been tested on big endian machines. A lot of
146
+	  endianness bugs has been fixed during the tests and now it seems to
147
+	  work gracefully.
148
+	  A lot of thanks to Vampire ;*
149
+	
150
+	* The ppp connection to the Internet doesn't set an IP address in the
151
+	  default route of the kernel but only the used ppp interface,
152
+	  therefore NetsukukuD has to deduce it from the IP assigned to the
153
+	  ppp interface, i.e. ppp0.
154
+
155
+	* Execute /etc/netsukuku/ip_masquerade.sh only if it is
156
+	  writable just by root.
157
+
158
+	* Execute "/etc/netsukuku/ip_masquerade.sh stop" when NetsukukuD is
159
+	  closed.
160
+
161
+	* Added a timeout of 60 seconds for the reverse resolution request.
162
+
163
+	* A possible memory overrun in the rsa (un)packing functions has been
164
+	  fixed.
165
+
166
+
167
+==== 0.0.5b  ====
168
+
169
+New features:
170
+	* The Internet Gateway Search (NTK_RFC 0003) has been implemented.
171
+	  A node can now share its Internet connection among the other nodes
172
+	  (only in restricted mode). 
173
+	  ( Read the RFC: http://lab.dyne.org/Ntk_IGS )
174
+
175
+	* Main part of the NTK_RFC 0001 written, the (g)nodes have now the
176
+	  ability to rehook to avoid IP collision. 
177
+	  ( http://lab.dyne.org/Ntk_gnodes_contiguity )
178
+	  
179
+	* ANDNS has been implemented. It is a new specification of the DNS
180
+	  protocol for Netsukuku. It is compatible with the actual DNS
181
+	  protocol. ( http://lab.dyne.org/Ntk_andna_and_dns )
182
+
183
+	* Multi interfaces multipath: if we can reach a rnode trough multiple
184
+	  interfaces, use them all with a multipath route.
185
+	  
186
+	* The dns_wrapper code is no more dependent on Boost.
187
+
188
+
189
+Bug fixes:
190
+
191
+	* map_rnode doesn't use anymore the timeval struct and map_rnode.rtt was
192
+	  removed 'cause it was obsolete. In conclusion we gained 12 bytes for
193
+	  each rnode.
194
+
195
+	* Added a check in get_free_nodes to verify the validity of
196
+	  fn_hdr->ipstart.
197
+	  For example if the rnode has an IP which doesn't match with
198
+	  fn_hdr->ipstart there must be some errors. This led to bug 0002.
199
+
200
+	* Fixed a bug in the multiif code: the packets destined to gnodes were
201
+	  sent only from the first device.
202
+
203
+	* qspn_remove_deads() removes the routes of the dead nodes from the
204
+	  routing table of the kernel.
205
+
206
+	* Restricted nodes and normal nodes are now invisible to each other.
207
+
208
+	* 127.0.0.0/8 banned.
209
+
210
+	* The command line options override the ones specified in the config file.
211
+
212
+	* code heavily cleaned.
213
+
214
+
215
+==== 0.0.4b  ====
216
+
217
+New features:
218
+
219
+	* The multi-interface support was added, now it is possible to use
220
+	  multiple network interfaces without the need of the bridge, just
221
+	  specify each interface you want to use with the -i option. (man
222
+	  netsukuku_d).
223
+
224
+	* The multipath support has been enabled for the external map, this
225
+	  means that more than one route will be used to reach a gnode. In other
226
+	  words the load balacing has been fully enabled.
227
+
228
+	* Endianness fixes: now the packets can be sent between two machines
229
+	  with different endianness.
230
+	  
231
+	* When the daemon is launched /etc/resolv.conf is modified
232
+	  automatically, so the "nameserver 127.0.0.1" is added in the first
233
+	  line of resolv.conf. The old resolv.conf is at /etc/resolv.conf.bak.
234
+	  When the daemon is closed /etc/resolv.conf.bak is moved to
235
+	  /etc/resolv.conf.
236
+
237
+	* Added CC and CXX options in Scontruct. 
238
+	  Changes provided by Tero Auvinen.
239
+
240
+	* At hooking the first radar_scan is retried for three times.
241
+
242
+
243
+	* The Make/configure support was added. Now you can use both SCons or
244
+	  Make to compile and install Netsukuku.
245
+
246
+
247
+Bug fixes:
248
+
249
+	* All the the packets are now sent without any alignment.
250
+
251
+	* The free_nodes struct has been optimised: to keep the list of free
252
+	  nodes it uses single bits instead of single bytes, this means that the
253
+	  list is now of 32 bytes instead of 256.
254
+
255
+	* The bug in the load_rh_cache code is now fixed. (It caused crashes
256
+	  when the daemon was closed).
257
+	  
258
+	* The installation path of the man page is now fixed.
259
+
260
+	* The installation paths are changed!! BIN_DIR=/usr/bin/,
261
+	  MAN_DIR=/usr/man
262
+
263
+	* The /usr/share/netsukuku directory is now created by the daemon
264
+	  itself.
265
+
266
+	* Now /sys/net/ipv4/conf/INTERFACE/rp_filter is automatically disabled
267
+	  for the used network interface.
268
+
269
+	* Errors in load_hostnames() fixed. (It crashed if there was an just
270
+	  an empty '\n').
271
+
272
+	
273
+
274
+==== 0.0.3b  ====
275
+
276
+	* The ANDNA code, with its DNS wrapper, is completed and tested.
277
+		
278
+	* The Netsukuku code was cleaned. Now it's ready to be an API.
279
+
280
+	* The Italian to English translation of the document is finished.
281
+
282
+
283
+==== 0.0.2b  ====
284
+
285
+	* NetsukukuD goes beta!
286
+
287
+
288
+==== 0.0.1b  ====
289
+
290
+	* NetsukukuD compiles, at least.
291
+
292
+
293
+==== 0.0.0a  ====
294
+
295
+	* The void and its nulliness filled the existence.

+ 231
- 0
INSTALL View File

@@ -0,0 +1,231 @@
1
+Installation Instructions
2
+*************************
3
+
4
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004 Free
5
+Software Foundation, Inc.
6
+
7
+This file is free documentation; the Free Software Foundation gives
8
+unlimited permission to copy, distribute and modify it.
9
+
10
+Basic Installation
11
+==================
12
+
13
+These are generic installation instructions.
14
+
15
+   The `configure' shell script attempts to guess correct values for
16
+various system-dependent variables used during compilation.  It uses
17
+those values to create a `Makefile' in each directory of the package.
18
+It may also create one or more `.h' files containing system-dependent
19
+definitions.  Finally, it creates a shell script `config.status' that
20
+you can run in the future to recreate the current configuration, and a
21
+file `config.log' containing compiler output (useful mainly for
22
+debugging `configure').
23
+
24
+   It can also use an optional file (typically called `config.cache'
25
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
26
+the results of its tests to speed up reconfiguring.  (Caching is
27
+disabled by default to prevent problems with accidental use of stale
28
+cache files.)
29
+
30
+   If you need to do unusual things to compile the package, please try
31
+to figure out how `configure' could check whether to do them, and mail
32
+diffs or instructions to the address given in the `README' so they can
33
+be considered for the next release.  If you are using the cache, and at
34
+some point `config.cache' contains results you don't want to keep, you
35
+may remove or edit it.
36
+
37
+   The file `configure.ac' (or `configure.in') is used to create
38
+`configure' by a program called `autoconf'.  You only need
39
+`configure.ac' if you want to change it or regenerate `configure' using
40
+a newer version of `autoconf'.
41
+
42
+The simplest way to compile this package is:
43
+
44
+  1. `cd' to the directory containing the package's source code and type
45
+     `./configure' to configure the package for your system.  If you're
46
+     using `csh' on an old version of System V, you might need to type
47
+     `sh ./configure' instead to prevent `csh' from trying to execute
48
+     `configure' itself.
49
+
50
+     Running `configure' takes awhile.  While running, it prints some
51
+     messages telling which features it is checking for.
52
+
53
+  2. Type `make' to compile the package.
54
+
55
+  3. Optionally, type `make check' to run any self-tests that come with
56
+     the package.
57
+
58
+  4. Type `make install' to install the programs and any data files and
59
+     documentation.
60
+
61
+  5. You can remove the program binaries and object files from the
62
+     source code directory by typing `make clean'.  To also remove the
63
+     files that `configure' created (so you can compile the package for
64
+     a different kind of computer), type `make distclean'.  There is
65
+     also a `make maintainer-clean' target, but that is intended mainly
66
+     for the package's developers.  If you use it, you may have to get
67
+     all sorts of other programs in order to regenerate files that came
68
+     with the distribution.
69
+
70
+Compilers and Options
71
+=====================
72
+
73
+Some systems require unusual options for compilation or linking that the
74
+`configure' script does not know about.  Run `./configure --help' for
75
+details on some of the pertinent environment variables.
76
+
77
+   You can give `configure' initial values for configuration parameters
78
+by setting variables in the command line or in the environment.  Here
79
+is an example:
80
+
81
+     ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
82
+
83
+   *Note Defining Variables::, for more details.
84
+
85
+Compiling For Multiple Architectures
86
+====================================
87
+
88
+You can compile the package for more than one kind of computer at the
89
+same time, by placing the object files for each architecture in their
90
+own directory.  To do this, you must use a version of `make' that
91
+supports the `VPATH' variable, such as GNU `make'.  `cd' to the
92
+directory where you want the object files and executables to go and run
93
+the `configure' script.  `configure' automatically checks for the
94
+source code in the directory that `configure' is in and in `..'.
95
+
96
+   If you have to use a `make' that does not support the `VPATH'
97
+variable, you have to compile the package for one architecture at a
98
+time in the source code directory.  After you have installed the
99
+package for one architecture, use `make distclean' before reconfiguring
100
+for another architecture.
101
+
102
+Installation Names
103
+==================
104
+
105
+By default, `make install' will install the package's files in
106
+`/usr/local/bin', `/usr/local/man', etc.  You can specify an
107
+installation prefix other than `/usr/local' by giving `configure' the
108
+option `--prefix=PREFIX'.
109
+
110
+   You can specify separate installation prefixes for
111
+architecture-specific files and architecture-independent files.  If you
112
+give `configure' the option `--exec-prefix=PREFIX', the package will
113
+use PREFIX as the prefix for installing programs and libraries.
114
+Documentation and other data files will still use the regular prefix.
115
+
116
+   In addition, if you use an unusual directory layout you can give
117
+options like `--bindir=DIR' to specify different values for particular
118
+kinds of files.  Run `configure --help' for a list of the directories
119
+you can set and what kinds of files go in them.
120
+
121
+   If the package supports it, you can cause programs to be installed
122
+with an extra prefix or suffix on their names by giving `configure' the
123
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
124
+
125
+Optional Features
126
+=================
127
+
128
+Some packages pay attention to `--enable-FEATURE' options to
129
+`configure', where FEATURE indicates an optional part of the package.
130
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
131
+is something like `gnu-as' or `x' (for the X Window System).  The
132
+`README' should mention any `--enable-' and `--with-' options that the
133
+package recognizes.
134
+
135
+   For packages that use the X Window System, `configure' can usually
136
+find the X include and library files automatically, but if it doesn't,
137
+you can use the `configure' options `--x-includes=DIR' and
138
+`--x-libraries=DIR' to specify their locations.
139
+
140
+Specifying the System Type
141
+==========================
142
+
143
+There may be some features `configure' cannot figure out automatically,
144
+but needs to determine by the type of machine the package will run on.
145
+Usually, assuming the package is built to be run on the _same_
146
+architectures, `configure' can figure that out, but if it prints a
147
+message saying it cannot guess the machine type, give it the
148
+`--build=TYPE' option.  TYPE can either be a short name for the system
149
+type, such as `sun4', or a canonical name which has the form:
150
+
151
+     CPU-COMPANY-SYSTEM
152
+
153
+where SYSTEM can have one of these forms:
154
+
155
+     OS KERNEL-OS
156
+
157
+   See the file `config.sub' for the possible values of each field.  If
158
+`config.sub' isn't included in this package, then this package doesn't
159
+need to know the machine type.
160
+
161
+   If you are _building_ compiler tools for cross-compiling, you should
162
+use the `--target=TYPE' option to select the type of system they will
163
+produce code for.
164
+
165
+   If you want to _use_ a cross compiler, that generates code for a
166
+platform different from the build platform, you should specify the
167
+"host" platform (i.e., that on which the generated programs will
168
+eventually be run) with `--host=TYPE'.
169
+
170
+Sharing Defaults
171
+================
172
+
173
+If you want to set default values for `configure' scripts to share, you
174
+can create a site shell script called `config.site' that gives default
175
+values for variables like `CC', `cache_file', and `prefix'.
176
+`configure' looks for `PREFIX/share/config.site' if it exists, then
177
+`PREFIX/etc/config.site' if it exists.  Or, you can set the
178
+`CONFIG_SITE' environment variable to the location of the site script.
179
+A warning: not all `configure' scripts look for a site script.
180
+
181
+Defining Variables
182
+==================
183
+
184
+Variables not defined in a site shell script can be set in the
185
+environment passed to `configure'.  However, some packages may run
186
+configure again during the build, and the customized values of these
187
+variables may be lost.  In order to avoid this problem, you should set
188
+them in the `configure' command line, using `VAR=value'.  For example:
189
+
190
+     ./configure CC=/usr/local2/bin/gcc
191
+
192
+will cause the specified gcc to be used as the C compiler (unless it is
193
+overridden in the site shell script).
194
+
195
+`configure' Invocation
196
+======================
197
+
198
+`configure' recognizes the following options to control how it operates.
199
+
200
+`--help'
201
+`-h'
202
+     Print a summary of the options to `configure', and exit.
203
+
204
+`--version'
205
+`-V'
206
+     Print the version of Autoconf used to generate the `configure'
207
+     script, and exit.
208
+
209
+`--cache-file=FILE'
210
+     Enable the cache: use and save the results of the tests in FILE,
211
+     traditionally `config.cache'.  FILE defaults to `/dev/null' to
212
+     disable caching.
213
+
214
+`--config-cache'
215
+`-C'
216
+     Alias for `--cache-file=config.cache'.
217
+
218
+`--quiet'
219
+`--silent'
220
+`-q'
221
+     Do not print messages saying which checks are being made.  To
222
+     suppress all normal output, redirect it to `/dev/null' (any error
223
+     messages will still be shown).
224
+
225
+`--srcdir=DIR'
226
+     Look for the package's source code in directory DIR.  Usually
227
+     `configure' can determine that directory automatically.
228
+
229
+`configure' also accepts some other, not widely useful, options.  Run
230
+`configure --help' for more details.
231
+

+ 1
- 0
Makefile.am View File

@@ -0,0 +1 @@
1
+SUBDIRS = src

+ 560
- 0
Makefile.in View File

@@ -0,0 +1,560 @@
1
+# Makefile.in generated by automake 1.8.5 from Makefile.am.
2
+# @configure_input@
3
+
4
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5
+# 2003, 2004  Free Software Foundation, Inc.
6
+# This Makefile.in is free software; the Free Software Foundation
7
+# gives unlimited permission to copy and/or distribute it,
8
+# with or without modifications, as long as this notice is preserved.
9
+
10
+# This program is distributed in the hope that it will be useful,
11
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
12
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13
+# PARTICULAR PURPOSE.
14
+
15
+@SET_MAKE@
16
+srcdir = @srcdir@
17
+top_srcdir = @top_srcdir@
18
+VPATH = @srcdir@
19
+pkgdatadir = $(datadir)/@PACKAGE@
20
+pkglibdir = $(libdir)/@PACKAGE@
21
+pkgincludedir = $(includedir)/@PACKAGE@
22
+top_builddir = .
23
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
24
+INSTALL = @INSTALL@
25
+install_sh_DATA = $(install_sh) -c -m 644
26
+install_sh_PROGRAM = $(install_sh) -c
27
+install_sh_SCRIPT = $(install_sh) -c
28
+INSTALL_HEADER = $(INSTALL_DATA)
29
+transform = $(program_transform_name)
30
+NORMAL_INSTALL = :
31
+PRE_INSTALL = :
32
+POST_INSTALL = :
33
+NORMAL_UNINSTALL = :
34
+PRE_UNINSTALL = :
35
+POST_UNINSTALL = :
36
+host_triplet = @host@
37
+DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
38
+	$(srcdir)/Makefile.in $(top_srcdir)/configure AUTHORS COPYING \
39
+	ChangeLog INSTALL NEWS TODO config.guess config.sub depcomp \
40
+	install-sh missing
41
+subdir = .
42
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
43
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
44
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
45
+	$(ACLOCAL_M4)
46
+am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
47
+ configure.lineno configure.status.lineno
48
+mkinstalldirs = $(mkdir_p)
49
+CONFIG_HEADER = $(top_builddir)/src/config.h
50
+CONFIG_CLEAN_FILES =
51
+SOURCES =
52
+DIST_SOURCES =
53
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
54
+	html-recursive info-recursive install-data-recursive \
55
+	install-exec-recursive install-info-recursive \
56
+	install-recursive installcheck-recursive installdirs-recursive \
57
+	pdf-recursive ps-recursive uninstall-info-recursive \
58
+	uninstall-recursive
59
+ETAGS = etags
60
+CTAGS = ctags
61
+DIST_SUBDIRS = $(SUBDIRS)
62
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
63
+distdir = $(PACKAGE)-$(VERSION)
64
+top_distdir = $(distdir)
65
+am__remove_distdir = \
66
+  { test ! -d $(distdir) \
67
+    || { find $(distdir) -type d ! -perm -200 -exec chmod u+w {} ';' \
68
+         && rm -fr $(distdir); }; }
69
+DIST_ARCHIVES = $(distdir).tar.gz
70
+GZIP_ENV = --best
71
+distuninstallcheck_listfiles = find . -type f -print
72
+distcleancheck_listfiles = find . -type f -print
73
+ACLOCAL = @ACLOCAL@
74
+AMDEP_FALSE = @AMDEP_FALSE@
75
+AMDEP_TRUE = @AMDEP_TRUE@
76
+AMTAR = @AMTAR@
77
+AUTOCONF = @AUTOCONF@
78
+AUTOHEADER = @AUTOHEADER@
79
+AUTOMAKE = @AUTOMAKE@
80
+AWK = @AWK@
81
+CC = @CC@
82
+CCDEPMODE = @CCDEPMODE@
83
+CFLAGS = @CFLAGS@
84
+CONF_DIR = @CONF_DIR@
85
+CPP = @CPP@
86
+CPPFLAGS = @CPPFLAGS@
87
+CXX = @CXX@
88
+CXXDEPMODE = @CXXDEPMODE@
89
+CXXFLAGS = @CXXFLAGS@
90
+CYGPATH_W = @CYGPATH_W@
91
+DATA_DIR = @DATA_DIR@
92
+DEFS = @DEFS@
93
+DEPDIR = @DEPDIR@
94
+ECHO_C = @ECHO_C@
95
+ECHO_N = @ECHO_N@
96
+ECHO_T = @ECHO_T@
97
+EGREP = @EGREP@
98
+EXEEXT = @EXEEXT@
99
+IF_METHOD = @IF_METHOD@
100
+INSTALL_DATA = @INSTALL_DATA@
101
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
102
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
103
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
104
+KERNEL_METHOD = @KERNEL_METHOD@
105
+LDFLAGS = @LDFLAGS@
106
+LIBOBJS = @LIBOBJS@
107
+LIBS = @LIBS@
108
+LTLIBOBJS = @LTLIBOBJS@
109
+MAKEINFO = @MAKEINFO@
110
+OBJEXT = @OBJEXT@
111
+OTHER_METHOD = @OTHER_METHOD@
112
+PACKAGE = @PACKAGE@
113
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
114
+PACKAGE_NAME = @PACKAGE_NAME@
115
+PACKAGE_STRING = @PACKAGE_STRING@
116
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
117
+PACKAGE_VERSION = @PACKAGE_VERSION@
118
+PATH_SEPARATOR = @PATH_SEPARATOR@
119
+PID_DIR = @PID_DIR@
120
+RT_METHOD = @RT_METHOD@
121
+SET_MAKE = @SET_MAKE@
122
+SHELL = @SHELL@
123
+STRIP = @STRIP@
124
+VERSION = @VERSION@
125
+ac_ct_CC = @ac_ct_CC@
126
+ac_ct_CXX = @ac_ct_CXX@
127
+ac_ct_STRIP = @ac_ct_STRIP@
128
+am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
129
+am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
130
+am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
131
+am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
132
+am__include = @am__include@
133
+am__leading_dot = @am__leading_dot@
134
+am__quote = @am__quote@
135
+bindir = @bindir@
136
+build = @build@
137
+build_alias = @build_alias@
138
+build_cpu = @build_cpu@
139
+build_os = @build_os@
140
+build_vendor = @build_vendor@
141
+datadir = @datadir@
142
+debug_flags = @debug_flags@
143
+exec_prefix = @exec_prefix@
144
+gmp = @gmp@
145
+host = @host@
146
+host_alias = @host_alias@
147
+host_cpu = @host_cpu@
148
+host_os = @host_os@
149
+host_vendor = @host_vendor@
150
+includedir = @includedir@
151
+infodir = @infodir@
152
+install_sh = @install_sh@
153
+libdir = @libdir@
154
+libexecdir = @libexecdir@
155
+localstatedir = @localstatedir@
156
+mandir = @mandir@
157
+mkdir_p = @mkdir_p@
158
+oldincludedir = @oldincludedir@
159
+prefix = @prefix@
160
+program_transform_name = @program_transform_name@
161
+sbindir = @sbindir@
162
+sharedstatedir = @sharedstatedir@
163
+sysconfdir = @sysconfdir@
164
+target_alias = @target_alias@
165
+SUBDIRS = src
166
+all: all-recursive
167
+
168
+.SUFFIXES:
169
+am--refresh:
170
+	@:
171
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
172
+	@for dep in $?; do \
173
+	  case '$(am__configure_deps)' in \
174
+	    *$$dep*) \
175
+	      echo ' cd $(srcdir) && $(AUTOMAKE) --gnu '; \
176
+	      cd $(srcdir) && $(AUTOMAKE) --gnu  \
177
+		&& exit 0; \
178
+	      exit 1;; \
179
+	  esac; \
180
+	done; \
181
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  Makefile'; \
182
+	cd $(top_srcdir) && \
183
+	  $(AUTOMAKE) --gnu  Makefile
184
+.PRECIOUS: Makefile
185
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
186
+	@case '$?' in \
187
+	  *config.status*) \
188
+	    echo ' $(SHELL) ./config.status'; \
189
+	    $(SHELL) ./config.status;; \
190
+	  *) \
191
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe)'; \
192
+	    cd $(top_builddir) && $(SHELL) ./config.status $@ $(am__depfiles_maybe);; \
193
+	esac;
194
+
195
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
196
+	$(SHELL) ./config.status --recheck
197
+
198
+$(top_srcdir)/configure:  $(am__configure_deps)
199
+	cd $(srcdir) && $(AUTOCONF)
200
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
201
+	cd $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
202
+uninstall-info-am:
203
+
204
+# This directory's subdirectories are mostly independent; you can cd
205
+# into them and run `make' without going through this Makefile.
206
+# To change the values of `make' variables: instead of editing Makefiles,
207
+# (1) if the variable is set in `config.status', edit `config.status'
208
+#     (which will cause the Makefiles to be regenerated when you run `make');
209
+# (2) otherwise, pass the desired values on the `make' command line.
210
+$(RECURSIVE_TARGETS):
211
+	@set fnord $$MAKEFLAGS; amf=$$2; \
212
+	dot_seen=no; \
213
+	target=`echo $@ | sed s/-recursive//`; \
214
+	list='$(SUBDIRS)'; for subdir in $$list; do \
215
+	  echo "Making $$target in $$subdir"; \
216
+	  if test "$$subdir" = "."; then \
217
+	    dot_seen=yes; \
218
+	    local_target="$$target-am"; \
219
+	  else \
220
+	    local_target="$$target"; \
221
+	  fi; \
222
+	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
223
+	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
224
+	done; \
225
+	if test "$$dot_seen" = "no"; then \
226
+	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
227
+	fi; test -z "$$fail"
228
+
229
+mostlyclean-recursive clean-recursive distclean-recursive \
230
+maintainer-clean-recursive:
231
+	@set fnord $$MAKEFLAGS; amf=$$2; \
232
+	dot_seen=no; \
233
+	case "$@" in \
234
+	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
235
+	  *) list='$(SUBDIRS)' ;; \
236
+	esac; \
237
+	rev=''; for subdir in $$list; do \
238
+	  if test "$$subdir" = "."; then :; else \
239
+	    rev="$$subdir $$rev"; \
240
+	  fi; \
241
+	done; \
242
+	rev="$$rev ."; \
243
+	target=`echo $@ | sed s/-recursive//`; \
244
+	for subdir in $$rev; do \
245
+	  echo "Making $$target in $$subdir"; \
246
+	  if test "$$subdir" = "."; then \
247
+	    local_target="$$target-am"; \
248
+	  else \
249
+	    local_target="$$target"; \
250
+	  fi; \
251
+	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
252
+	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
253
+	done && test -z "$$fail"
254
+tags-recursive:
255
+	list='$(SUBDIRS)'; for subdir in $$list; do \
256
+	  test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
257
+	done
258
+ctags-recursive:
259
+	list='$(SUBDIRS)'; for subdir in $$list; do \
260
+	  test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
261
+	done
262
+
263
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
264
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
265
+	unique=`for i in $$list; do \
266
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
267
+	  done | \
268
+	  $(AWK) '    { files[$$0] = 1; } \
269
+	       END { for (i in files) print i; }'`; \
270
+	mkid -fID $$unique
271
+tags: TAGS
272
+
273
+TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
274
+		$(TAGS_FILES) $(LISP)
275
+	tags=; \
276
+	here=`pwd`; \
277
+	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
278
+	  include_option=--etags-include; \
279
+	  empty_fix=.; \
280
+	else \
281
+	  include_option=--include; \
282
+	  empty_fix=; \
283
+	fi; \
284
+	list='$(SUBDIRS)'; for subdir in $$list; do \
285
+	  if test "$$subdir" = .; then :; else \
286
+	    test ! -f $$subdir/TAGS || \
287
+	      tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
288
+	  fi; \
289
+	done; \
290
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
291
+	unique=`for i in $$list; do \
292
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
293
+	  done | \
294
+	  $(AWK) '    { files[$$0] = 1; } \
295
+	       END { for (i in files) print i; }'`; \
296
+	if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
297
+	  test -n "$$unique" || unique=$$empty_fix; \
298
+	  $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
299
+	    $$tags $$unique; \
300
+	fi
301
+ctags: CTAGS
302
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
303
+		$(TAGS_FILES) $(LISP)
304
+	tags=; \
305
+	here=`pwd`; \
306
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
307
+	unique=`for i in $$list; do \
308
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
309
+	  done | \
310
+	  $(AWK) '    { files[$$0] = 1; } \
311
+	       END { for (i in files) print i; }'`; \
312
+	test -z "$(CTAGS_ARGS)$$tags$$unique" \
313
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
314
+	     $$tags $$unique
315
+
316
+GTAGS:
317
+	here=`$(am__cd) $(top_builddir) && pwd` \
318
+	  && cd $(top_srcdir) \
319
+	  && gtags -i $(GTAGS_ARGS) $$here
320
+
321
+distclean-tags:
322
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
323
+
324
+distdir: $(DISTFILES)
325
+	$(am__remove_distdir)
326
+	mkdir $(distdir)
327
+	$(mkdir_p) $(distdir)/src/conf
328
+	@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
329
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
330
+	list='$(DISTFILES)'; for file in $$list; do \
331
+	  case $$file in \
332
+	    $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
333
+	    $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
334
+	  esac; \
335
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
336
+	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
337
+	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
338
+	    dir="/$$dir"; \
339
+	    $(mkdir_p) "$(distdir)$$dir"; \
340
+	  else \
341
+	    dir=''; \
342
+	  fi; \
343
+	  if test -d $$d/$$file; then \
344
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
345
+	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
346
+	    fi; \
347
+	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
348
+	  else \
349
+	    test -f $(distdir)/$$file \
350
+	    || cp -p $$d/$$file $(distdir)/$$file \
351
+	    || exit 1; \
352
+	  fi; \
353
+	done
354
+	list='$(SUBDIRS)'; for subdir in $$list; do \
355
+	  if test "$$subdir" = .; then :; else \
356
+	    test -d "$(distdir)/$$subdir" \
357
+	    || mkdir "$(distdir)/$$subdir" \
358
+	    || exit 1; \
359
+	    (cd $$subdir && \
360
+	      $(MAKE) $(AM_MAKEFLAGS) \
361
+	        top_distdir="../$(top_distdir)" \
362
+	        distdir="../$(distdir)/$$subdir" \
363
+	        distdir) \
364
+	      || exit 1; \
365
+	  fi; \
366
+	done
367
+	-find $(distdir) -type d ! -perm -777 -exec chmod a+rwx {} \; -o \
368
+	  ! -type d ! -perm -444 -links 1 -exec chmod a+r {} \; -o \
369
+	  ! -type d ! -perm -400 -exec chmod a+r {} \; -o \
370
+	  ! -type d ! -perm -444 -exec $(SHELL) $(install_sh) -c -m a+r {} {} \; \
371
+	|| chmod -R a+r $(distdir)
372
+dist-gzip: distdir
373
+	$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
374
+	$(am__remove_distdir)
375
+
376
+dist-bzip2: distdir
377
+	$(AMTAR) chof - $(distdir) | bzip2 -9 -c >$(distdir).tar.bz2
378
+	$(am__remove_distdir)
379
+
380
+dist-tarZ: distdir
381
+	$(AMTAR) chof - $(distdir) | compress -c >$(distdir).tar.Z
382
+	$(am__remove_distdir)
383
+
384
+dist-shar: distdir
385
+	shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz
386
+	$(am__remove_distdir)
387
+
388
+dist-zip: distdir
389
+	-rm -f $(distdir).zip
390
+	zip -rq $(distdir).zip $(distdir)
391
+	$(am__remove_distdir)
392
+
393
+dist dist-all: distdir
394
+	$(AMTAR) chof - $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz
395
+	$(am__remove_distdir)
396
+
397
+# This target untars the dist file and tries a VPATH configuration.  Then
398
+# it guarantees that the distribution is self-contained by making another
399
+# tarfile.
400
+distcheck: dist
401
+	case '$(DIST_ARCHIVES)' in \
402
+	*.tar.gz*) \
403
+	  GZIP=$(GZIP_ENV) gunzip -c $(distdir).tar.gz | $(AMTAR) xf - ;;\
404
+	*.tar.bz2*) \
405
+	  bunzip2 -c $(distdir).tar.bz2 | $(AMTAR) xf - ;;\
406
+	*.tar.Z*) \
407
+	  uncompress -c $(distdir).tar.Z | $(AMTAR) xf - ;;\
408
+	*.shar.gz*) \
409
+	  GZIP=$(GZIP_ENV) gunzip -c $(distdir).shar.gz | unshar ;;\
410
+	*.zip*) \
411
+	  unzip $(distdir).zip ;;\
412
+	esac
413
+	chmod -R a-w $(distdir); chmod a+w $(distdir)
414
+	mkdir $(distdir)/_build
415
+	mkdir $(distdir)/_inst
416
+	chmod a-w $(distdir)
417
+	dc_install_base=`$(am__cd) $(distdir)/_inst && pwd | sed -e 's,^[^:\\/]:[\\/],/,'` \
418
+	  && dc_destdir="$${TMPDIR-/tmp}/am-dc-$$$$/" \
419
+	  && cd $(distdir)/_build \
420
+	  && ../configure --srcdir=.. --prefix="$$dc_install_base" \
421
+	    $(DISTCHECK_CONFIGURE_FLAGS) \
422
+	  && $(MAKE) $(AM_MAKEFLAGS) \
423
+	  && $(MAKE) $(AM_MAKEFLAGS) dvi \
424
+	  && $(MAKE) $(AM_MAKEFLAGS) check \
425
+	  && $(MAKE) $(AM_MAKEFLAGS) install \
426
+	  && $(MAKE) $(AM_MAKEFLAGS) installcheck \
427
+	  && $(MAKE) $(AM_MAKEFLAGS) uninstall \
428
+	  && $(MAKE) $(AM_MAKEFLAGS) distuninstallcheck_dir="$$dc_install_base" \
429
+	        distuninstallcheck \
430
+	  && chmod -R a-w "$$dc_install_base" \
431
+	  && ({ \
432
+	       (cd ../.. && umask 077 && mkdir "$$dc_destdir") \
433
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" install \
434
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" uninstall \
435
+	       && $(MAKE) $(AM_MAKEFLAGS) DESTDIR="$$dc_destdir" \
436
+	            distuninstallcheck_dir="$$dc_destdir" distuninstallcheck; \
437
+	      } || { rm -rf "$$dc_destdir"; exit 1; }) \
438
+	  && rm -rf "$$dc_destdir" \
439
+	  && $(MAKE) $(AM_MAKEFLAGS) dist \
440
+	  && rm -rf $(DIST_ARCHIVES) \
441
+	  && $(MAKE) $(AM_MAKEFLAGS) distcleancheck
442
+	$(am__remove_distdir)
443
+	@(echo "$(distdir) archives ready for distribution: "; \
444
+	  list='$(DIST_ARCHIVES)'; for i in $$list; do echo $$i; done) | \
445
+	  sed -e '1{h;s/./=/g;p;x;}' -e '$${p;x;}'
446
+distuninstallcheck:
447
+	@cd $(distuninstallcheck_dir) \
448
+	&& test `$(distuninstallcheck_listfiles) | wc -l` -le 1 \
449
+	   || { echo "ERROR: files left after uninstall:" ; \
450
+	        if test -n "$(DESTDIR)"; then \
451
+	          echo "  (check DESTDIR support)"; \
452
+	        fi ; \
453
+	        $(distuninstallcheck_listfiles) ; \
454
+	        exit 1; } >&2
455
+distcleancheck: distclean
456
+	@if test '$(srcdir)' = . ; then \
457
+	  echo "ERROR: distcleancheck can only run from a VPATH build" ; \
458
+	  exit 1 ; \
459
+	fi
460
+	@test `$(distcleancheck_listfiles) | wc -l` -eq 0 \
461
+	  || { echo "ERROR: files left in build directory after distclean:" ; \
462
+	       $(distcleancheck_listfiles) ; \
463
+	       exit 1; } >&2
464
+check-am: all-am
465
+check: check-recursive
466
+all-am: Makefile
467
+installdirs: installdirs-recursive
468
+installdirs-am:
469
+install: install-recursive
470
+install-exec: install-exec-recursive
471
+install-data: install-data-recursive
472
+uninstall: uninstall-recursive
473
+
474
+install-am: all-am
475
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
476
+
477
+installcheck: installcheck-recursive
478
+install-strip:
479
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
480
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
481
+	  `test -z '$(STRIP)' || \
482
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
483
+mostlyclean-generic:
484
+
485
+clean-generic:
486
+
487
+distclean-generic:
488
+	-rm -f $(CONFIG_CLEAN_FILES)
489
+
490
+maintainer-clean-generic:
491
+	@echo "This command is intended for maintainers to use"
492
+	@echo "it deletes files that may require special tools to rebuild."
493
+clean: clean-recursive
494
+
495
+clean-am: clean-generic mostlyclean-am
496
+
497
+distclean: distclean-recursive
498
+	-rm -f $(am__CONFIG_DISTCLEAN_FILES)
499
+	-rm -f Makefile
500
+distclean-am: clean-am distclean-generic distclean-tags
501
+
502
+dvi: dvi-recursive
503
+
504
+dvi-am:
505
+
506
+html: html-recursive
507
+
508
+info: info-recursive
509
+
510
+info-am:
511
+
512
+install-data-am:
513
+
514
+install-exec-am:
515
+
516
+install-info: install-info-recursive
517
+
518
+install-man:
519
+
520
+installcheck-am:
521
+
522
+maintainer-clean: maintainer-clean-recursive
523
+	-rm -f $(am__CONFIG_DISTCLEAN_FILES)
524
+	-rm -rf $(top_srcdir)/autom4te.cache
525
+	-rm -f Makefile
526
+maintainer-clean-am: distclean-am maintainer-clean-generic
527
+
528
+mostlyclean: mostlyclean-recursive
529
+
530
+mostlyclean-am: mostlyclean-generic
531
+
532
+pdf: pdf-recursive
533
+
534
+pdf-am:
535
+
536
+ps: ps-recursive
537
+
538
+ps-am:
539
+
540
+uninstall-am: uninstall-info-am
541
+
542
+uninstall-info: uninstall-info-recursive
543
+
544
+.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am am--refresh check \
545
+	check-am clean clean-generic clean-recursive ctags \
546
+	ctags-recursive dist dist-all dist-bzip2 dist-gzip dist-shar \
547
+	dist-tarZ dist-zip distcheck distclean distclean-generic \
548
+	distclean-recursive distclean-tags distcleancheck distdir \
549
+	distuninstallcheck dvi dvi-am html html-am info info-am \
550
+	install install-am install-data install-data-am install-exec \
551
+	install-exec-am install-info install-info-am install-man \
552
+	install-strip installcheck installcheck-am installdirs \
553
+	installdirs-am maintainer-clean maintainer-clean-generic \
554
+	maintainer-clean-recursive mostlyclean mostlyclean-generic \
555
+	mostlyclean-recursive pdf pdf-am ps ps-am tags tags-recursive \
556
+	uninstall uninstall-am uninstall-info-am
557
+
558
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
559
+# Otherwise a system limit (for SysV at least) may be exceeded.
560
+.NOEXPORT:

+ 1
- 0
NEWS View File

@@ -0,0 +1 @@
1
+ChangeLog

+ 272
- 0
README View File

@@ -0,0 +1,272 @@
1
+
2
+				   Netsukuku
3
+				   
4
+			 http://netsukuku.freaknet.org
5
+
6
+--
7
+
8
+  1.  What is this?
9
+  
10
+  2.  Get the code!
11
+  
12
+  3.  Build and install
13
+ 
14
+  	3.1  Static Binaries and Packages
15
+  
16
+  4.  Kernel dependencies
17
+  
18
+  5.  How to use it
19
+  
20
+  6.  Where to get in touch with us
21
+  
22
+  7.  Bug report
23
+  
24
+  8.  Hack the code
25
+  
26
+  9.  License and that kind of stuff...
27
+  
28
+--
29
+
30
+
31
+**
32
+****  1. What is this?
33
+**
34
+
35
+Netsukuku is a mesh network or a p2p net system that generates and sustains
36
+itself autonomously. It is designed to handle an unlimited number of nodes
37
+with minimal CPU and memory resources. Thanks to this feature it can be easily
38
+used to build a worldwide distributed, anonymous and not controlled network,
39
+separated from the Internet, without the support of any servers, ISPs or
40
+authority controls.
41
+This net is composed by computers linked physically each other, therefore it
42
+isn't build upon any existing network. Netsukuku builds only the routes which
43
+connects all the computers of the net.
44
+In other words, Netsukuku replaces the level 3 of the model iso/osi with
45
+another routing protocol.
46
+The Domain Name System is also replaced by a decentralised and distributed
47
+system: the Abnormal Netsukuku Domain Name Anarchy.
48
+
49
+The complete features list of Netsukuku is here:
50
+http://netsukuku.freaknet.org/files/doc/misc/Ntk_features_list
51
+
52
+
53
+In order to join to Netsukuku you have to use NetsukukuD, which is the daemon
54
+implementing the Npv7 protocol.
55
+
56
+Before doing anything, please read the documentation in doc/ or in
57
+http://netsukuku.freaknet.org
58
+
59
+
60
+**
61
+****  2.  Get the code!
62
+**
63
+
64
+Get the tarball of the latest stable version from:
65
+http://netsukuku.freaknet.org/files/
66
+
67
+
68
+If you want to download the development code you have to checkout it from the
69
+cvs repository:
70
+(Warning: It is highly probable the development code will not work!)
71
+
72
+$ cvs -d :pserver:anoncvs@hinezumilabs.org:/home/cvsroot login
73
+or
74
+$ export CVSROOT=":pserver:anoncvs@hinezumilabs.org:/home/cvsroot"
75
+$ cvs login
76
+
77
+then check it out:
78
+
79
+$ cvs -z3 -d :pserver:anoncvs@hinezumilabs.org:/home/cvsroot co netsukuku
80
+or
81
+$ cvs -z3 co netsukuku
82
+(providing the CVSROOT variable was set in the previous step)
83
+
84
+
85
+Once you've checked out a copy of the source tree, you can update 
86
+your source tree at any time so it is in sync with the latest and 
87
+greatest by running the command:
88
+# cvs -z3 update -d -P
89
+
90
+
91
+**
92
+****  3.  Build and install
93
+**
94
+
95
+To compile the code you can use scons or just go with the old school way:
96
+
97
+# ./configure && make && make install
98
+
99
+But SCons is cooler:
100
+http://www.scons.org/
101
+(You should have installed at least the 2.4 version of Python in order to
102
+avoid dirty bugs in scons)
103
+
104
+
105
+The code depends also on the libgmp,zlib and openssl. Generally you have
106
+already them installed on your system, but eventually you can retrieve them
107
+here: 
108
+for the libgmp:			http://www.swox.com/gmp/
109
+the openssl library here:	http://openssl.org
110
+and finally the zlibs:		http://zlib.net
111
+
112
+Then go in the src/ directory and type:
113
+$ scons --help
114
+
115
+That will show you all the options you can use in the build and installation
116
+process. Finally execute:
117
+
118
+$ scons 
119
+
120
+The code will be compiled. If all went well install NetsukukuD with:
121
+
122
+# scons install
123
+
124
+Now you should give a look at /etc/netsukuku.conf (or wherever you installed
125
+it) and modify it for your needs, but generally the default options are good.
126
+
127
+- Notes:
128
+
129
+If you want to change some scons option to do another installation, (i.e. you
130
+may want to reinstall it with another MANDIR path), you have to run:
131
+$ scons --clean
132
+
133
+
134
+**
135
+****  3.1  Static Binaries and Packages
136
+**
137
+
138
+If you prefer to just install Netsukuku, without compiling it, you can
139
+download the static binaries suitable to your platform. They come packed in
140
+various formats (.tgz, .deb, .ipk).
141
+The packages repository is at:
142
+    http://netsukuku.freaknet.org/packages/
143
+
144
+
145
+**
146
+****  4.  Kernel dependencies
147
+**
148
+
149
+On Linux be sure to have the following options set in your kernel .config.
150
+These options are taken from linux-2.6.14.
151
+ 
152
+	#
153
+	# Networking options
154
+	#
155
+	CONFIG_PACKET=y
156
+	CONFIG_UNIX=y
157
+	CONFIG_INET=y
158
+	CONFIG_IP_MULTICAST=y
159
+	CONFIG_IP_ADVANCED_ROUTER=y
160
+	CONFIG_IP_MULTIPLE_TABLES=y
161
+	CONFIG_IP_ROUTE_MULTIPATH=y
162
+	CONFIG_NET_IPIP=y
163
+	CONFIG_NETFILTER=y
164
+
165
+and these from linux-2.6.16.19.
166
+
167
+	#
168
+	# Core Netfilter Configuration
169
+	#
170
+
171
+	CONFIG_NETFILTER_XT_MATCH_CONNTRACK=y
172
+	NETFILTER_XT_TARGET_CONNMARK=y
173
+
174
+	#
175
+	# IP: Netfilter Configuration
176
+	#
177
+
178
+	CONFIG_IP_NF_IPTABLES=y
179
+	CONFIG_IP_NF_FILTER=y
180
+	CONFIG_IP_NF_TARGET_REJECT=y
181
+	CONFIG_IP_NF_NAT=y
182
+	CONFIG_IP_NF_NAT_NEEDED=y
183
+	CONFIG_IP_NF_TARGET_MASQUERADE=y
184
+	
185
+If you are using modules you have to load them before launching the daemon.
186
+
187
+
188
+**
189
+****  5.  How to use it
190
+**
191
+
192
+Before doing anything do:
193
+
194
+$ man ntkd
195
+$ man andna
196
+
197
+when you feel confortable and you are ready to dare type with root
198
+priviledges:
199
+
200
+# ntkd
201
+
202
+then just wait... ^_-
203
+
204
+(For the first times it's cool to use the -D option to see what happens).
205
+
206
+-  Note:
207
+The daemon at startup takes the list of all the network interfaces which are
208
+currently UP and it uses all of them to send and receive packets. If you want
209
+to force the daemon to use specific interfaces you should use the B<-i>
210
+option.
211
+
212
+
213
+**
214
+****  6.  Where to get in touch with us
215
+**
216
+
217
+> Mailing list
218
+
219
+Subscribe to the netsukuku mailing to get help, be updated on the latest news
220
+and discuss on its development.
221
+
222
+To subscribe to the list, send a message to:
223
+    netsukuku-subscribe@lists.dyne.org
224
+or use the web interface:
225
+    http://lists.dyne.org/mailman/listinfo/netsukuku
226
+   
227
+You can browse the archive here:
228
+    http://lists.dyne.org/netsukuku/
229
+    http://dir.gmane.org/gmane.network.peer-to-peer.netsukuku
230
+ 
231
+
232
+> IRC
233
+
234
+We live night and day in IRC, come to see us on channel
235
+   #netsukuku
236
+on the FreeNode irc server (irc.freenode.org).
237
+
238
+
239
+**
240
+****  7.  Bug report
241
+**
242
+
243
+{ Don't panic! }
244
+
245
+If you encounter any bug, please report it.
246
+Use the online bug track system:
247
+    http://bugs.dyne.org/
248
+or the mailing list:
249
+    http://lists.dyne.org/netsukuku/
250
+and explain what the problem is and if possible a way to reproduce it.
251
+
252
+
253
+**
254
+****  8.  Hack the code
255
+**
256
+
257
+Feel free to debug, patch, modify and eat the code. Then submit your results
258
+to the mailing list ^_-
259
+
260
+There is a lot to code too! If you are a Kung Foo coder, get on board and
261
+help the development writing some nice poems. For a start you can take a look
262
+at the src/TODO file.
263
+
264
+
265
+**
266
+****  9.  License and that kind of stuff...
267
+**
268
+
269
+All the Netsukuku code is released under the GPL-2, please see the COPYING
270
+file for more information.
271
+
272
+The authors of Netsukuku and NetsukukuD are listed in the file AUTHORS.

+ 932
- 0
aclocal.m4 View File

@@ -0,0 +1,932 @@
1
+# generated automatically by aclocal 1.8.5 -*- Autoconf -*-
2
+
3
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
4
+# Free Software Foundation, Inc.
5
+# This file is free software; the Free Software Foundation
6
+# gives unlimited permission to copy and/or distribute it,
7
+# with or without modifications, as long as this notice is preserved.
8
+
9
+# This program is distributed in the hope that it will be useful,
10
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
11
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12
+# PARTICULAR PURPOSE.
13
+
14
+#                                                        -*- Autoconf -*-
15
+# Copyright (C) 2002, 2003  Free Software Foundation, Inc.
16
+# Generated from amversion.in; do not edit by hand.
17
+
18
+# This program is free software; you can redistribute it and/or modify
19
+# it under the terms of the GNU General Public License as published by
20
+# the Free Software Foundation; either version 2, or (at your option)
21
+# any later version.
22
+
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+# GNU General Public License for more details.
27
+
28
+# You should have received a copy of the GNU General Public License
29
+# along with this program; if not, write to the Free Software
30
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31
+
32
+# AM_AUTOMAKE_VERSION(VERSION)
33
+# ----------------------------
34
+# Automake X.Y traces this macro to ensure aclocal.m4 has been
35
+# generated from the m4 files accompanying Automake X.Y.
36
+AC_DEFUN([AM_AUTOMAKE_VERSION], [am__api_version="1.8"])
37
+
38
+# AM_SET_CURRENT_AUTOMAKE_VERSION
39
+# -------------------------------
40
+# Call AM_AUTOMAKE_VERSION so it can be traced.
41
+# This function is AC_REQUIREd by AC_INIT_AUTOMAKE.
42
+AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
43
+	 [AM_AUTOMAKE_VERSION([1.8.5])])
44
+
45
+# AM_AUX_DIR_EXPAND
46
+
47
+# Copyright (C) 2001, 2003 Free Software Foundation, Inc.
48
+
49
+# This program is free software; you can redistribute it and/or modify
50
+# it under the terms of the GNU General Public License as published by
51
+# the Free Software Foundation; either version 2, or (at your option)
52
+# any later version.
53
+
54
+# This program is distributed in the hope that it will be useful,
55
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
56
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57
+# GNU General Public License for more details.
58
+
59
+# You should have received a copy of the GNU General Public License
60
+# along with this program; if not, write to the Free Software
61
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
62
+# 02111-1307, USA.
63
+
64
+# For projects using AC_CONFIG_AUX_DIR([foo]), Autoconf sets
65
+# $ac_aux_dir to `$srcdir/foo'.  In other projects, it is set to
66
+# `$srcdir', `$srcdir/..', or `$srcdir/../..'.
67
+#
68
+# Of course, Automake must honor this variable whenever it calls a
69
+# tool from the auxiliary directory.  The problem is that $srcdir (and
70
+# therefore $ac_aux_dir as well) can be either absolute or relative,
71
+# depending on how configure is run.  This is pretty annoying, since
72
+# it makes $ac_aux_dir quite unusable in subdirectories: in the top
73
+# source directory, any form will work fine, but in subdirectories a
74
+# relative path needs to be adjusted first.
75
+#
76
+# $ac_aux_dir/missing
77
+#    fails when called from a subdirectory if $ac_aux_dir is relative
78
+# $top_srcdir/$ac_aux_dir/missing
79
+#    fails if $ac_aux_dir is absolute,
80
+#    fails when called from a subdirectory in a VPATH build with
81
+#          a relative $ac_aux_dir
82
+#
83
+# The reason of the latter failure is that $top_srcdir and $ac_aux_dir
84
+# are both prefixed by $srcdir.  In an in-source build this is usually
85
+# harmless because $srcdir is `.', but things will broke when you
86
+# start a VPATH build or use an absolute $srcdir.
87
+#
88
+# So we could use something similar to $top_srcdir/$ac_aux_dir/missing,
89
+# iff we strip the leading $srcdir from $ac_aux_dir.  That would be:
90
+#   am_aux_dir='\$(top_srcdir)/'`expr "$ac_aux_dir" : "$srcdir//*\(.*\)"`
91
+# and then we would define $MISSING as
92
+#   MISSING="\${SHELL} $am_aux_dir/missing"
93
+# This will work as long as MISSING is not called from configure, because
94
+# unfortunately $(top_srcdir) has no meaning in configure.
95
+# However there are other variables, like CC, which are often used in
96
+# configure, and could therefore not use this "fixed" $ac_aux_dir.
97
+#
98
+# Another solution, used here, is to always expand $ac_aux_dir to an
99
+# absolute PATH.  The drawback is that using absolute paths prevent a
100
+# configured tree to be moved without reconfiguration.
101
+
102
+AC_DEFUN([AM_AUX_DIR_EXPAND],
103
+[dnl Rely on autoconf to set up CDPATH properly.
104
+AC_PREREQ([2.50])dnl
105
+# expand $ac_aux_dir to an absolute path
106
+am_aux_dir=`cd $ac_aux_dir && pwd`
107
+])
108
+
109
+# AM_CONDITIONAL                                              -*- Autoconf -*-
110
+
111
+# Copyright (C) 1997, 2000, 2001, 2003 Free Software Foundation, Inc.
112
+
113
+# This program is free software; you can redistribute it and/or modify
114
+# it under the terms of the GNU General Public License as published by
115
+# the Free Software Foundation; either version 2, or (at your option)
116
+# any later version.
117
+
118
+# This program is distributed in the hope that it will be useful,
119
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
120
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
121
+# GNU General Public License for more details.
122
+
123
+# You should have received a copy of the GNU General Public License
124
+# along with this program; if not, write to the Free Software
125
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
126
+# 02111-1307, USA.
127
+
128
+# serial 6
129
+
130
+# AM_CONDITIONAL(NAME, SHELL-CONDITION)
131
+# -------------------------------------
132
+# Define a conditional.
133
+AC_DEFUN([AM_CONDITIONAL],
134
+[AC_PREREQ(2.52)dnl
135
+ ifelse([$1], [TRUE],  [AC_FATAL([$0: invalid condition: $1])],
136
+	[$1], [FALSE], [AC_FATAL([$0: invalid condition: $1])])dnl
137
+AC_SUBST([$1_TRUE])
138
+AC_SUBST([$1_FALSE])
139
+if $2; then
140
+  $1_TRUE=
141
+  $1_FALSE='#'
142
+else
143
+  $1_TRUE='#'
144
+  $1_FALSE=
145
+fi
146
+AC_CONFIG_COMMANDS_PRE(
147
+[if test -z "${$1_TRUE}" && test -z "${$1_FALSE}"; then
148
+  AC_MSG_ERROR([conditional "$1" was never defined.
149
+Usually this means the macro was only invoked conditionally.])
150
+fi])])
151
+
152
+# serial 7						-*- Autoconf -*-
153
+
154
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004
155
+# Free Software Foundation, Inc.
156
+
157
+# This program is free software; you can redistribute it and/or modify
158
+# it under the terms of the GNU General Public License as published by
159
+# the Free Software Foundation; either version 2, or (at your option)
160
+# any later version.
161
+
162
+# This program is distributed in the hope that it will be useful,
163
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
164
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165
+# GNU General Public License for more details.
166
+
167
+# You should have received a copy of the GNU General Public License
168
+# along with this program; if not, write to the Free Software
169
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
170
+# 02111-1307, USA.
171
+
172
+
173
+# There are a few dirty hacks below to avoid letting `AC_PROG_CC' be
174
+# written in clear, in which case automake, when reading aclocal.m4,
175
+# will think it sees a *use*, and therefore will trigger all it's
176
+# C support machinery.  Also note that it means that autoscan, seeing
177
+# CC etc. in the Makefile, will ask for an AC_PROG_CC use...
178
+
179
+
180
+
181
+# _AM_DEPENDENCIES(NAME)
182
+# ----------------------
183
+# See how the compiler implements dependency checking.
184
+# NAME is "CC", "CXX", "GCJ", or "OBJC".
185
+# We try a few techniques and use that to set a single cache variable.
186
+#
187
+# We don't AC_REQUIRE the corresponding AC_PROG_CC since the latter was
188
+# modified to invoke _AM_DEPENDENCIES(CC); we would have a circular
189
+# dependency, and given that the user is not expected to run this macro,
190
+# just rely on AC_PROG_CC.
191
+AC_DEFUN([_AM_DEPENDENCIES],
192
+[AC_REQUIRE([AM_SET_DEPDIR])dnl
193
+AC_REQUIRE([AM_OUTPUT_DEPENDENCY_COMMANDS])dnl
194
+AC_REQUIRE([AM_MAKE_INCLUDE])dnl
195
+AC_REQUIRE([AM_DEP_TRACK])dnl
196
+
197
+ifelse([$1], CC,   [depcc="$CC"   am_compiler_list=],
198
+       [$1], CXX,  [depcc="$CXX"  am_compiler_list=],
199
+       [$1], OBJC, [depcc="$OBJC" am_compiler_list='gcc3 gcc'],
200
+       [$1], GCJ,  [depcc="$GCJ"  am_compiler_list='gcc3 gcc'],
201
+                   [depcc="$$1"   am_compiler_list=])
202
+
203
+AC_CACHE_CHECK([dependency style of $depcc],
204
+               [am_cv_$1_dependencies_compiler_type],
205
+[if test -z "$AMDEP_TRUE" && test -f "$am_depcomp"; then
206
+  # We make a subdir and do the tests there.  Otherwise we can end up
207
+  # making bogus files that we don't know about and never remove.  For
208
+  # instance it was reported that on HP-UX the gcc test will end up
209
+  # making a dummy file named `D' -- because `-MD' means `put the output
210
+  # in D'.
211
+  mkdir conftest.dir
212
+  # Copy depcomp to subdir because otherwise we won't find it if we're
213
+  # using a relative directory.
214
+  cp "$am_depcomp" conftest.dir
215
+  cd conftest.dir
216
+  # We will build objects and dependencies in a subdirectory because
217
+  # it helps to detect inapplicable dependency modes.  For instance
218
+  # both Tru64's cc and ICC support -MD to output dependencies as a
219
+  # side effect of compilation, but ICC will put the dependencies in
220
+  # the current directory while Tru64 will put them in the object
221
+  # directory.
222
+  mkdir sub
223
+
224
+  am_cv_$1_dependencies_compiler_type=none
225
+  if test "$am_compiler_list" = ""; then
226
+     am_compiler_list=`sed -n ['s/^#*\([a-zA-Z0-9]*\))$/\1/p'] < ./depcomp`
227
+  fi
228
+  for depmode in $am_compiler_list; do
229
+    # Setup a source with many dependencies, because some compilers
230
+    # like to wrap large dependency lists on column 80 (with \), and
231
+    # we should not choose a depcomp mode which is confused by this.
232
+    #
233
+    # We need to recreate these files for each test, as the compiler may
234
+    # overwrite some of them when testing with obscure command lines.
235
+    # This happens at least with the AIX C compiler.
236
+    : > sub/conftest.c
237
+    for i in 1 2 3 4 5 6; do
238
+      echo '#include "conftst'$i'.h"' >> sub/conftest.c
239
+      # Using `: > sub/conftst$i.h' creates only sub/conftst1.h with
240
+      # Solaris 8's {/usr,}/bin/sh.
241
+      touch sub/conftst$i.h
242
+    done
243
+    echo "${am__include} ${am__quote}sub/conftest.Po${am__quote}" > confmf
244
+
245
+    case $depmode in
246
+    nosideeffect)
247
+      # after this tag, mechanisms are not by side-effect, so they'll
248
+      # only be used when explicitly requested
249
+      if test "x$enable_dependency_tracking" = xyes; then
250
+	continue
251
+      else
252
+	break
253
+      fi
254
+      ;;
255
+    none) break ;;
256
+    esac
257
+    # We check with `-c' and `-o' for the sake of the "dashmstdout"
258
+    # mode.  It turns out that the SunPro C++ compiler does not properly
259
+    # handle `-M -o', and we need to detect this.
260
+    if depmode=$depmode \
261
+       source=sub/conftest.c object=sub/conftest.${OBJEXT-o} \
262
+       depfile=sub/conftest.Po tmpdepfile=sub/conftest.TPo \
263
+       $SHELL ./depcomp $depcc -c -o sub/conftest.${OBJEXT-o} sub/conftest.c \
264
+         >/dev/null 2>conftest.err &&
265
+       grep sub/conftst6.h sub/conftest.Po > /dev/null 2>&1 &&
266
+       grep sub/conftest.${OBJEXT-o} sub/conftest.Po > /dev/null 2>&1 &&
267
+       ${MAKE-make} -s -f confmf > /dev/null 2>&1; then
268
+      # icc doesn't choke on unknown options, it will just issue warnings
269
+      # or remarks (even with -Werror).  So we grep stderr for any message
270
+      # that says an option was ignored or not supported.
271
+      # When given -MP, icc 7.0 and 7.1 complain thusly:
272
+      #   icc: Command line warning: ignoring option '-M'; no argument required
273
+      # The diagnosis changed in icc 8.0:
274
+      #   icc: Command line remark: option '-MP' not supported
275
+      if (grep 'ignoring option' conftest.err ||
276
+          grep 'not supported' conftest.err) >/dev/null 2>&1; then :; else
277
+        am_cv_$1_dependencies_compiler_type=$depmode
278
+        break
279
+      fi
280
+    fi
281
+  done
282
+
283
+  cd ..
284
+  rm -rf conftest.dir
285
+else
286
+  am_cv_$1_dependencies_compiler_type=none
287
+fi
288
+])
289
+AC_SUBST([$1DEPMODE], [depmode=$am_cv_$1_dependencies_compiler_type])
290
+AM_CONDITIONAL([am__fastdep$1], [
291
+  test "x$enable_dependency_tracking" != xno \
292
+  && test "$am_cv_$1_dependencies_compiler_type" = gcc3])
293
+])
294
+
295
+
296
+# AM_SET_DEPDIR
297
+# -------------
298
+# Choose a directory name for dependency files.
299
+# This macro is AC_REQUIREd in _AM_DEPENDENCIES
300
+AC_DEFUN([AM_SET_DEPDIR],
301
+[AC_REQUIRE([AM_SET_LEADING_DOT])dnl
302
+AC_SUBST([DEPDIR], ["${am__leading_dot}deps"])dnl
303
+])
304
+
305
+
306
+# AM_DEP_TRACK
307
+# ------------
308
+AC_DEFUN([AM_DEP_TRACK],
309
+[AC_ARG_ENABLE(dependency-tracking,
310
+[  --disable-dependency-tracking  speeds up one-time build
311
+  --enable-dependency-tracking   do not reject slow dependency extractors])
312
+if test "x$enable_dependency_tracking" != xno; then
313
+  am_depcomp="$ac_aux_dir/depcomp"
314
+  AMDEPBACKSLASH='\'
315
+fi
316
+AM_CONDITIONAL([AMDEP], [test "x$enable_dependency_tracking" != xno])
317
+AC_SUBST([AMDEPBACKSLASH])
318
+])
319
+
320
+# Generate code to set up dependency tracking.   -*- Autoconf -*-
321
+
322
+# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
323
+
324
+# This program is free software; you can redistribute it and/or modify
325
+# it under the terms of the GNU General Public License as published by
326
+# the Free Software Foundation; either version 2, or (at your option)
327
+# any later version.
328
+
329
+# This program is distributed in the hope that it will be useful,
330
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
331
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
332
+# GNU General Public License for more details.
333
+
334
+# You should have received a copy of the GNU General Public License
335
+# along with this program; if not, write to the Free Software
336
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
337
+# 02111-1307, USA.
338
+
339
+#serial 2
340
+
341
+# _AM_OUTPUT_DEPENDENCY_COMMANDS
342
+# ------------------------------
343
+AC_DEFUN([_AM_OUTPUT_DEPENDENCY_COMMANDS],
344
+[for mf in $CONFIG_FILES; do
345
+  # Strip MF so we end up with the name of the file.
346
+  mf=`echo "$mf" | sed -e 's/:.*$//'`
347
+  # Check whether this is an Automake generated Makefile or not.
348
+  # We used to match only the files named `Makefile.in', but
349
+  # some people rename them; so instead we look at the file content.
350
+  # Grep'ing the first line is not enough: some people post-process
351
+  # each Makefile.in and add a new line on top of each file to say so.
352
+  # So let's grep whole file.
353
+  if grep '^#.*generated by automake' $mf > /dev/null 2>&1; then
354
+    dirpart=`AS_DIRNAME("$mf")`
355
+  else
356
+    continue
357
+  fi
358
+  grep '^DEP_FILES *= *[[^ @%:@]]' < "$mf" > /dev/null || continue
359
+  # Extract the definition of DEP_FILES from the Makefile without
360
+  # running `make'.
361
+  DEPDIR=`sed -n 's/^DEPDIR = //p' < "$mf"`
362
+  test -z "$DEPDIR" && continue
363
+  # When using ansi2knr, U may be empty or an underscore; expand it
364
+  U=`sed -n 's/^U = //p' < "$mf"`
365
+  test -d "$dirpart/$DEPDIR" || mkdir "$dirpart/$DEPDIR"
366
+  # We invoke sed twice because it is the simplest approach to
367
+  # changing $(DEPDIR) to its actual value in the expansion.
368
+  for file in `sed -n '
369
+    /^DEP_FILES = .*\\\\$/ {
370
+      s/^DEP_FILES = //
371
+      :loop
372
+	s/\\\\$//
373
+	p
374
+	n
375
+	/\\\\$/ b loop
376
+      p
377
+    }
378
+    /^DEP_FILES = / s/^DEP_FILES = //p' < "$mf" | \
379
+       sed -e 's/\$(DEPDIR)/'"$DEPDIR"'/g' -e 's/\$U/'"$U"'/g'`; do
380
+    # Make sure the directory exists.
381
+    test -f "$dirpart/$file" && continue
382
+    fdir=`AS_DIRNAME(["$file"])`
383
+    AS_MKDIR_P([$dirpart/$fdir])
384
+    # echo "creating $dirpart/$file"
385
+    echo '# dummy' > "$dirpart/$file"
386
+  done
387
+done
388
+])# _AM_OUTPUT_DEPENDENCY_COMMANDS
389
+
390
+
391
+# AM_OUTPUT_DEPENDENCY_COMMANDS
392
+# -----------------------------
393
+# This macro should only be invoked once -- use via AC_REQUIRE.
394
+#
395
+# This code is only required when automatic dependency tracking
396
+# is enabled.  FIXME.  This creates each `.P' file that we will
397
+# need in order to bootstrap the dependency handling code.
398
+AC_DEFUN([AM_OUTPUT_DEPENDENCY_COMMANDS],
399
+[AC_CONFIG_COMMANDS([depfiles],
400
+     [test x"$AMDEP_TRUE" != x"" || _AM_OUTPUT_DEPENDENCY_COMMANDS],
401
+     [AMDEP_TRUE="$AMDEP_TRUE" ac_aux_dir="$ac_aux_dir"])
402
+])
403
+
404
+# Like AC_CONFIG_HEADER, but automatically create stamp file. -*- Autoconf -*-
405
+
406
+# Copyright (C) 1996, 1997, 2000, 2001, 2003 Free Software Foundation, Inc.
407
+
408
+# This program is free software; you can redistribute it and/or modify
409
+# it under the terms of the GNU General Public License as published by
410
+# the Free Software Foundation; either version 2, or (at your option)
411
+# any later version.
412
+
413
+# This program is distributed in the hope that it will be useful,
414
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
415
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
416
+# GNU General Public License for more details.
417
+
418
+# You should have received a copy of the GNU General Public License
419
+# along with this program; if not, write to the Free Software
420
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
421
+# 02111-1307, USA.
422
+
423
+# serial 7
424
+
425
+# AM_CONFIG_HEADER is obsolete.  It has been replaced by AC_CONFIG_HEADERS.
426
+AU_DEFUN([AM_CONFIG_HEADER], [AC_CONFIG_HEADERS($@)])
427
+
428
+# Do all the work for Automake.                            -*- Autoconf -*-
429
+
430
+# This macro actually does too much some checks are only needed if
431
+# your package does certain things.  But this isn't really a big deal.
432
+
433
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
434
+# Free Software Foundation, Inc.
435
+
436
+# This program is free software; you can redistribute it and/or modify
437
+# it under the terms of the GNU General Public License as published by
438
+# the Free Software Foundation; either version 2, or (at your option)
439
+# any later version.
440
+
441
+# This program is distributed in the hope that it will be useful,
442
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
443
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
444
+# GNU General Public License for more details.
445
+
446
+# You should have received a copy of the GNU General Public License
447
+# along with this program; if not, write to the Free Software
448
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
449
+# 02111-1307, USA.
450
+
451
+# serial 11
452
+
453
+# AM_INIT_AUTOMAKE(PACKAGE, VERSION, [NO-DEFINE])
454
+# AM_INIT_AUTOMAKE([OPTIONS])
455
+# -----------------------------------------------
456
+# The call with PACKAGE and VERSION arguments is the old style
457
+# call (pre autoconf-2.50), which is being phased out.  PACKAGE
458
+# and VERSION should now be passed to AC_INIT and removed from
459
+# the call to AM_INIT_AUTOMAKE.
460
+# We support both call styles for the transition.  After
461
+# the next Automake release, Autoconf can make the AC_INIT
462
+# arguments mandatory, and then we can depend on a new Autoconf
463
+# release and drop the old call support.
464
+AC_DEFUN([AM_INIT_AUTOMAKE],
465
+[AC_PREREQ([2.58])dnl
466
+dnl Autoconf wants to disallow AM_ names.  We explicitly allow
467
+dnl the ones we care about.
468
+m4_pattern_allow([^AM_[A-Z]+FLAGS$])dnl
469
+AC_REQUIRE([AM_SET_CURRENT_AUTOMAKE_VERSION])dnl
470
+AC_REQUIRE([AC_PROG_INSTALL])dnl
471
+# test to see if srcdir already configured
472
+if test "`cd $srcdir && pwd`" != "`pwd`" &&
473
+   test -f $srcdir/config.status; then
474
+  AC_MSG_ERROR([source directory already configured; run "make distclean" there first])
475
+fi
476
+
477
+# test whether we have cygpath
478
+if test -z "$CYGPATH_W"; then
479
+  if (cygpath --version) >/dev/null 2>/dev/null; then
480
+    CYGPATH_W='cygpath -w'
481
+  else
482
+    CYGPATH_W=echo
483
+  fi
484
+fi
485
+AC_SUBST([CYGPATH_W])
486
+
487
+# Define the identity of the package.
488
+dnl Distinguish between old-style and new-style calls.
489
+m4_ifval([$2],
490
+[m4_ifval([$3], [_AM_SET_OPTION([no-define])])dnl
491
+ AC_SUBST([PACKAGE], [$1])dnl
492
+ AC_SUBST([VERSION], [$2])],
493
+[_AM_SET_OPTIONS([$1])dnl
494
+ AC_SUBST([PACKAGE], ['AC_PACKAGE_TARNAME'])dnl
495
+ AC_SUBST([VERSION], ['AC_PACKAGE_VERSION'])])dnl
496
+
497
+_AM_IF_OPTION([no-define],,
498
+[AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Name of package])
499
+ AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [Version number of package])])dnl
500
+
501
+# Some tools Automake needs.
502
+AC_REQUIRE([AM_SANITY_CHECK])dnl
503
+AC_REQUIRE([AC_ARG_PROGRAM])dnl
504
+AM_MISSING_PROG(ACLOCAL, aclocal-${am__api_version})
505
+AM_MISSING_PROG(AUTOCONF, autoconf)
506
+AM_MISSING_PROG(AUTOMAKE, automake-${am__api_version})
507
+AM_MISSING_PROG(AUTOHEADER, autoheader)
508
+AM_MISSING_PROG(MAKEINFO, makeinfo)
509
+AM_MISSING_PROG(AMTAR, tar)
510
+AM_PROG_INSTALL_SH
511
+AM_PROG_INSTALL_STRIP
512
+AC_REQUIRE([AM_PROG_MKDIR_P])dnl
513
+# We need awk for the "check" target.  The system "awk" is bad on
514
+# some platforms.
515
+AC_REQUIRE([AC_PROG_AWK])dnl
516
+AC_REQUIRE([AC_PROG_MAKE_SET])dnl
517
+AC_REQUIRE([AM_SET_LEADING_DOT])dnl
518
+
519
+_AM_IF_OPTION([no-dependencies],,
520
+[AC_PROVIDE_IFELSE([AC_PROG_CC],
521
+                  [_AM_DEPENDENCIES(CC)],
522
+                  [define([AC_PROG_CC],
523
+                          defn([AC_PROG_CC])[_AM_DEPENDENCIES(CC)])])dnl
524
+AC_PROVIDE_IFELSE([AC_PROG_CXX],
525
+                  [_AM_DEPENDENCIES(CXX)],
526
+                  [define([AC_PROG_CXX],
527
+                          defn([AC_PROG_CXX])[_AM_DEPENDENCIES(CXX)])])dnl
528
+])
529
+])
530
+
531
+
532
+# When config.status generates a header, we must update the stamp-h file.
533
+# This file resides in the same directory as the config header
534
+# that is generated.  The stamp files are numbered to have different names.
535
+
536
+# Autoconf calls _AC_AM_CONFIG_HEADER_HOOK (when defined) in the
537
+# loop where config.status creates the headers, so we can generate
538
+# our stamp files there.
539
+AC_DEFUN([_AC_AM_CONFIG_HEADER_HOOK],
540
+[# Compute $1's index in $config_headers.
541
+_am_stamp_count=1
542
+for _am_header in $config_headers :; do
543
+  case $_am_header in
544
+    $1 | $1:* )
545
+      break ;;
546
+    * )
547
+      _am_stamp_count=`expr $_am_stamp_count + 1` ;;
548
+  esac
549
+done
550
+echo "timestamp for $1" >`AS_DIRNAME([$1])`/stamp-h[]$_am_stamp_count])
551
+
552
+# AM_PROG_INSTALL_SH
553
+# ------------------
554
+# Define $install_sh.
555
+
556
+# Copyright (C) 2001, 2003 Free Software Foundation, Inc.
557
+
558
+# This program is free software; you can redistribute it and/or modify
559
+# it under the terms of the GNU General Public License as published by
560
+# the Free Software Foundation; either version 2, or (at your option)
561
+# any later version.
562
+
563
+# This program is distributed in the hope that it will be useful,
564
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
565
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
566
+# GNU General Public License for more details.
567
+
568
+# You should have received a copy of the GNU General Public License
569
+# along with this program; if not, write to the Free Software
570
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
571
+# 02111-1307, USA.
572
+
573
+AC_DEFUN([AM_PROG_INSTALL_SH],
574
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
575
+install_sh=${install_sh-"$am_aux_dir/install-sh"}
576
+AC_SUBST(install_sh)])
577
+
578
+#                                                          -*- Autoconf -*-
579
+# Copyright (C) 2003  Free Software Foundation, Inc.
580
+
581
+# This program is free software; you can redistribute it and/or modify
582
+# it under the terms of the GNU General Public License as published by
583
+# the Free Software Foundation; either version 2, or (at your option)
584
+# any later version.
585
+
586
+# This program is distributed in the hope that it will be useful,
587
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
588
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
589
+# GNU General Public License for more details.
590
+
591
+# You should have received a copy of the GNU General Public License
592
+# along with this program; if not, write to the Free Software
593
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
594
+# 02111-1307, USA.
595
+
596
+# serial 1
597
+
598
+# Check whether the underlying file-system supports filenames
599
+# with a leading dot.  For instance MS-DOS doesn't.
600
+AC_DEFUN([AM_SET_LEADING_DOT],
601
+[rm -rf .tst 2>/dev/null
602
+mkdir .tst 2>/dev/null
603
+if test -d .tst; then
604
+  am__leading_dot=.
605
+else
606
+  am__leading_dot=_
607
+fi
608
+rmdir .tst 2>/dev/null
609
+AC_SUBST([am__leading_dot])])
610
+
611
+# Check to see how 'make' treats includes.	-*- Autoconf -*-
612
+
613
+# Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
614
+
615
+# This program is free software; you can redistribute it and/or modify
616
+# it under the terms of the GNU General Public License as published by
617
+# the Free Software Foundation; either version 2, or (at your option)
618
+# any later version.
619
+
620
+# This program is distributed in the hope that it will be useful,
621
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
622
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
623
+# GNU General Public License for more details.
624
+
625
+# You should have received a copy of the GNU General Public License
626
+# along with this program; if not, write to the Free Software
627
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
628
+# 02111-1307, USA.
629
+
630
+# serial 2
631
+
632
+# AM_MAKE_INCLUDE()
633
+# -----------------
634
+# Check to see how make treats includes.
635
+AC_DEFUN([AM_MAKE_INCLUDE],
636
+[am_make=${MAKE-make}
637
+cat > confinc << 'END'
638
+am__doit:
639
+	@echo done
640
+.PHONY: am__doit
641
+END
642
+# If we don't find an include directive, just comment out the code.
643
+AC_MSG_CHECKING([for style of include used by $am_make])
644
+am__include="#"
645
+am__quote=
646
+_am_result=none
647
+# First try GNU make style include.
648
+echo "include confinc" > confmf
649
+# We grep out `Entering directory' and `Leaving directory'
650
+# messages which can occur if `w' ends up in MAKEFLAGS.
651
+# In particular we don't look at `^make:' because GNU make might
652
+# be invoked under some other name (usually "gmake"), in which
653
+# case it prints its new name instead of `make'.
654
+if test "`$am_make -s -f confmf 2> /dev/null | grep -v 'ing directory'`" = "done"; then
655
+   am__include=include
656
+   am__quote=
657
+   _am_result=GNU
658
+fi
659
+# Now try BSD make style include.
660
+if test "$am__include" = "#"; then
661
+   echo '.include "confinc"' > confmf
662
+   if test "`$am_make -s -f confmf 2> /dev/null`" = "done"; then
663
+      am__include=.include
664
+      am__quote="\""
665
+      _am_result=BSD
666
+   fi
667
+fi
668
+AC_SUBST([am__include])
669
+AC_SUBST([am__quote])
670
+AC_MSG_RESULT([$_am_result])
671
+rm -f confinc confmf
672
+])
673
+
674
+#  -*- Autoconf -*-
675
+
676
+
677
+# Copyright (C) 1997, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
678
+
679
+# This program is free software; you can redistribute it and/or modify
680
+# it under the terms of the GNU General Public License as published by
681
+# the Free Software Foundation; either version 2, or (at your option)
682
+# any later version.
683
+
684
+# This program is distributed in the hope that it will be useful,
685
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
686
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
687
+# GNU General Public License for more details.
688
+
689
+# You should have received a copy of the GNU General Public License
690
+# along with this program; if not, write to the Free Software
691
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
692
+# 02111-1307, USA.
693
+
694
+# serial 3
695
+
696
+# AM_MISSING_PROG(NAME, PROGRAM)
697
+# ------------------------------
698
+AC_DEFUN([AM_MISSING_PROG],
699
+[AC_REQUIRE([AM_MISSING_HAS_RUN])
700
+$1=${$1-"${am_missing_run}$2"}
701
+AC_SUBST($1)])
702
+
703
+
704
+# AM_MISSING_HAS_RUN
705
+# ------------------
706
+# Define MISSING if not defined so far and test if it supports --run.
707
+# If it does, set am_missing_run to use it, otherwise, to nothing.
708
+AC_DEFUN([AM_MISSING_HAS_RUN],
709
+[AC_REQUIRE([AM_AUX_DIR_EXPAND])dnl
710
+test x"${MISSING+set}" = xset || MISSING="\${SHELL} $am_aux_dir/missing"
711
+# Use eval to expand $SHELL
712
+if eval "$MISSING --run true"; then
713
+  am_missing_run="$MISSING --run "
714
+else
715
+  am_missing_run=
716
+  AC_MSG_WARN([`missing' script is too old or missing])
717
+fi
718
+])
719
+
720
+# AM_PROG_MKDIR_P
721
+# ---------------
722
+# Check whether `mkdir -p' is supported, fallback to mkinstalldirs otherwise.
723
+
724
+# Copyright (C) 2003, 2004 Free Software Foundation, Inc.
725
+
726
+# This program is free software; you can redistribute it and/or modify
727
+# it under the terms of the GNU General Public License as published by
728
+# the Free Software Foundation; either version 2, or (at your option)
729
+# any later version.
730
+
731
+# This program is distributed in the hope that it will be useful,
732
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
733
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
734
+# GNU General Public License for more details.
735
+
736
+# You should have received a copy of the GNU General Public License
737
+# along with this program; if not, write to the Free Software
738
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
739
+# 02111-1307, USA.
740
+
741
+# Automake 1.8 used `mkdir -m 0755 -p --' to ensure that directories
742
+# created by `make install' are always world readable, even if the
743
+# installer happens to have an overly restrictive umask (e.g. 077).
744
+# This was a mistake.  There are at least two reasons why we must not
745
+# use `-m 0755':
746
+#   - it causes special bits like SGID to be ignored,
747
+#   - it may be too restrictive (some setups expect 775 directories).
748
+#
749
+# Do not use -m 0755 and let people choose whatever they expect by
750
+# setting umask.
751
+#
752
+# We cannot accept any implementation of `mkdir' that recognizes `-p'.
753
+# Some implementations (such as Solaris 8's) are not thread-safe: if a
754
+# parallel make tries to run `mkdir -p a/b' and `mkdir -p a/c'
755
+# concurrently, both version can detect that a/ is missing, but only
756
+# one can create it and the other will error out.  Consequently we
757
+# restrict ourselves to GNU make (using the --version option ensures
758
+# this.)
759
+AC_DEFUN([AM_PROG_MKDIR_P],
760
+[if mkdir -p --version . >/dev/null 2>&1 && test ! -d ./--version; then
761
+  # Keeping the `.' argument allows $(mkdir_p) to be used without
762
+  # argument.  Indeed, we sometimes output rules like
763
+  #   $(mkdir_p) $(somedir)
764
+  # where $(somedir) is conditionally defined.
765
+  # (`test -n '$(somedir)' && $(mkdir_p) $(somedir)' is a more
766
+  # expensive solution, as it forces Make to start a sub-shell.)
767
+  mkdir_p='mkdir -p -- .'
768
+else
769
+  # On NextStep and OpenStep, the `mkdir' command does not
770
+  # recognize any option.  It will interpret all options as
771
+  # directories to create, and then abort because `.' already
772
+  # exists.
773
+  for d in ./-p ./--version;
774
+  do
775
+    test -d $d && rmdir $d
776
+  done
777
+  # $(mkinstalldirs) is defined by Automake if mkinstalldirs exists.
778
+  if test -f "$ac_aux_dir/mkinstalldirs"; then
779
+    mkdir_p='$(mkinstalldirs)'
780
+  else
781
+    mkdir_p='$(install_sh) -d'
782
+  fi
783
+fi
784
+AC_SUBST([mkdir_p])])
785
+
786
+# Helper functions for option handling.                    -*- Autoconf -*-
787
+
788
+# Copyright (C) 2001, 2002, 2003  Free Software Foundation, Inc.
789
+
790
+# This program is free software; you can redistribute it and/or modify
791
+# it under the terms of the GNU General Public License as published by
792
+# the Free Software Foundation; either version 2, or (at your option)
793
+# any later version.
794
+
795
+# This program is distributed in the hope that it will be useful,
796
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
797
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
798
+# GNU General Public License for more details.
799
+
800
+# You should have received a copy of the GNU General Public License
801
+# along with this program; if not, write to the Free Software
802
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
803
+# 02111-1307, USA.
804
+
805
+# serial 2
806
+
807
+# _AM_MANGLE_OPTION(NAME)
808
+# -----------------------
809
+AC_DEFUN([_AM_MANGLE_OPTION],
810
+[[_AM_OPTION_]m4_bpatsubst($1, [[^a-zA-Z0-9_]], [_])])
811
+
812
+# _AM_SET_OPTION(NAME)
813
+# ------------------------------
814
+# Set option NAME.  Presently that only means defining a flag for this option.
815
+AC_DEFUN([_AM_SET_OPTION],
816
+[m4_define(_AM_MANGLE_OPTION([$1]), 1)])
817
+
818
+# _AM_SET_OPTIONS(OPTIONS)
819
+# ----------------------------------
820
+# OPTIONS is a space-separated list of Automake options.
821
+AC_DEFUN([_AM_SET_OPTIONS],
822
+[AC_FOREACH([_AM_Option], [$1], [_AM_SET_OPTION(_AM_Option)])])
823
+
824
+# _AM_IF_OPTION(OPTION, IF-SET, [IF-NOT-SET])
825
+# -------------------------------------------
826
+# Execute IF-SET if OPTION is set, IF-NOT-SET otherwise.
827
+AC_DEFUN([_AM_IF_OPTION],
828
+[m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])])
829
+
830
+#
831
+# Check to make sure that the build environment is sane.
832
+#
833
+
834
+# Copyright (C) 1996, 1997, 2000, 2001, 2003 Free Software Foundation, Inc.
835
+
836
+# This program is free software; you can redistribute it and/or modify
837
+# it under the terms of the GNU General Public License as published by
838
+# the Free Software Foundation; either version 2, or (at your option)
839
+# any later version.
840
+
841
+# This program is distributed in the hope that it will be useful,
842
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
843
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
844
+# GNU General Public License for more details.
845
+
846
+# You should have received a copy of the GNU General Public License
847
+# along with this program; if not, write to the Free Software
848
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
849
+# 02111-1307, USA.
850
+
851
+# serial 3
852
+
853
+# AM_SANITY_CHECK
854
+# ---------------
855
+AC_DEFUN([AM_SANITY_CHECK],
856
+[AC_MSG_CHECKING([whether build environment is sane])
857
+# Just in case
858
+sleep 1
859
+echo timestamp > conftest.file
860
+# Do `set' in a subshell so we don't clobber the current shell's
861
+# arguments.  Must try -L first in case configure is actually a
862
+# symlink; some systems play weird games with the mod time of symlinks
863
+# (eg FreeBSD returns the mod time of the symlink's containing
864
+# directory).
865
+if (
866
+   set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null`
867
+   if test "$[*]" = "X"; then
868
+      # -L didn't work.
869
+      set X `ls -t $srcdir/configure conftest.file`
870
+   fi
871
+   rm -f conftest.file
872
+   if test "$[*]" != "X $srcdir/configure conftest.file" \
873
+      && test "$[*]" != "X conftest.file $srcdir/configure"; then
874
+
875
+      # If neither matched, then we have a broken ls.  This can happen
876
+      # if, for instance, CONFIG_SHELL is bash and it inherits a
877
+      # broken ls alias from the environment.  This has actually
878
+      # happened.  Such a system could not be considered "sane".
879
+      AC_MSG_ERROR([ls -t appears to fail.  Make sure there is not a broken
880
+alias in your environment])
881
+   fi
882
+
883
+   test "$[2]" = conftest.file
884
+   )
885
+then
886
+   # Ok.
887
+   :
888
+else
889
+   AC_MSG_ERROR([newly created file is older than distributed files!
890
+Check your system clock])
891
+fi
892
+AC_MSG_RESULT(yes)])
893
+
894
+# AM_PROG_INSTALL_STRIP
895
+
896
+# Copyright (C) 2001, 2003 Free Software Foundation, Inc.
897
+
898
+# This program is free software; you can redistribute it and/or modify
899
+# it under the terms of the GNU General Public License as published by
900
+# the Free Software Foundation; either version 2, or (at your option)
901
+# any later version.
902
+
903
+# This program is distributed in the hope that it will be useful,
904
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
905
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
906
+# GNU General Public License for more details.
907
+
908
+# You should have received a copy of the GNU General Public License
909
+# along with this program; if not, write to the Free Software
910
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
911
+# 02111-1307, USA.
912
+
913
+# One issue with vendor `install' (even GNU) is that you can't
914
+# specify the program used to strip binaries.  This is especially
915
+# annoying in cross-compiling environments, where the build's strip
916
+# is unlikely to handle the host's binaries.
917
+# Fortunately install-sh will honor a STRIPPROG variable, so we
918
+# always use install-sh in `make install-strip', and initialize
919
+# STRIPPROG with the value of the STRIP variable (set by the user).
920
+AC_DEFUN([AM_PROG_INSTALL_STRIP],
921
+[AC_REQUIRE([AM_PROG_INSTALL_SH])dnl
922
+# Installed binaries are usually stripped using `strip' when the user
923
+# run `make install-strip'.  However `strip' might not be the right
924
+# tool to use in cross-compilation environments, therefore Automake
925
+# will honor the `STRIP' environment variable to overrule this program.
926
+dnl Don't test for $cross_compiling = yes, because it might be `maybe'.
927
+if test "$cross_compiling" != no; then
928
+  AC_CHECK_TOOL([STRIP], [strip], :)
929
+fi
930
+INSTALL_STRIP_PROGRAM="\${SHELL} \$(install_sh) -c -s"
931
+AC_SUBST([INSTALL_STRIP_PROGRAM])])
932
+

+ 1517
- 0
config.guess
File diff suppressed because it is too large
View File


+ 1598
- 0
config.sub
File diff suppressed because it is too large
View File


+ 6749
- 0
configure
File diff suppressed because it is too large
View File


+ 184
- 0
configure.ac View File

@@ -0,0 +1,184 @@
1
+AC_PREREQ(2.59)
2
+AC_INIT(netsukuku, 0.0.9b)
3
+AM_INIT_AUTOMAKE(netsukuku, 0.0.9b)
4
+AC_DEFINE(VERSION, 0.0.9b)
5
+AM_CONFIG_HEADER(src/config.h) 
6
+
7
+dnl -----------------------------------
8
+dnl Get hostname and other information.
9
+dnl -----------------------------------
10
+AC_CANONICAL_HOST
11
+
12
+AC_PROG_CC
13
+AC_PROG_CPP
14
+AC_PROG_CXX
15
+
16
+prefix=/usr
17
+datadir=/usr/share/netsukuku
18
+sysconfdir=/etc/netsukuku
19
+piddir=/var/run
20
+
21
+AC_ARG_WITH(gmp-include, AS_HELP_STRING([--with-gmp-include], \
22
+[gmp include dir]), [gmp="$withval"])
23
+AC_SUBST(gmp)
24
+
25
+
26
+AC_HEADER_STDC
27
+AC_CHECK_HEADERS([unistd.h])
28
+
29
+AC_CHECK_HEADERS([pthread.h], ,\
30
+        [echo "============================ Unable to find pthread.h"; \
31
+         echo "Do you have the libpthread library installed?" ])
32
+AC_CHECK_HEADERS([zlib.h], ,\
33
+        [echo "============================ Unable to find zlib.h"; \
34
+         echo "Do you have the zlib library installed?" ])
35
+AC_CHECK_HEADERS([openssl/crypto.h], ,\
36
+        [echo "============================ Unable to find openssl/crypto.h";\
37
+         echo "Read README first!!!!!"; \
38
+         echo "Install the openssl library"])
39
+AC_CHECK_HEADERS([gmp.h], ,\
40
+        [echo "============================ Unable to find gmp.h"; \
41
+         echo "Read README first!!!!!"; \
42
+         echo "You need to install the libgmp library."; \
43
+         echo "In the debian the package is libgmp3-dev"])
44
+
45
+AC_MSG_CHECKING(OS)
46
+case "$host" in
47
+  *-sunos5.6* | *-solaris2.6*)
48
+      opsys=sol2-6
49
+      AC_DEFINE(SUNOS,,SunOS 5)
50
+      AC_CHECK_LIB(xnet, main)
51
+      AC_MSG_RESULT(solaris)
52
+  ;;
53
+  *-sunos5* | *-solaris2*)
54
+      AC_DEFINE(SUNOS,,SunOS 5)
55
+      AC_CHECK_LIB(socket, main)
56
+      AC_CHECK_LIB(nsl, main)
57
+      AC_MSG_RESULT(solaris)
58
+  ;;
59
+  *-linux-*)
60
+      opsys=gnu-linux
61
+      AC_DEFINE(GNU_LINUX,,GNU Linux)
62
+      AC_MSG_RESULT(linux)
63
+  ;;
64
+  *-nec-sysv4*)
65
+      AC_CHECK_LIB(nsl, gethostbyname)
66
+      AC_CHECK_LIB(socket, socket)
67
+      AC_MSG_RESULT(net-sysv4)
68
+  ;;
69
+  *-freebsd*)
70
+      AC_DEFINE(FREEBSD,,FreeBSD)
71
+      AC_MSG_RESULT(freebsd)
72
+  ;;
73
+  *-openbsd*)
74
+      opsys=openbsd
75
+      AC_DEFINE(OPEN_BSD,,OpenBSD)
76
+      AC_MSG_RESULT(openbsd)
77
+  ;;
78
+  *-bsdi*)
79
+      opsys=bsdi
80
+      OTHER_METHOD="mtu_kvm.o"
81
+      AC_CHECK_LIB(kvm, main)
82
+      AC_MSG_RESULT(bsdi)
83
+  ;;
84
+  *-irix6.5)
85
+      opsys=irix
86
+      AC_DEFINE(IRIX,,IRIX 6.5)
87
+      AC_MSG_RESULT(irix)
88
+  ;;
89
+esac
90
+
91
+dnl ------------------------------------
92
+dnl Determine routing get and set method
93
+dnl ------------------------------------
94
+AC_MSG_CHECKING(Netsukuku kernel interface method)
95
+if test x"$opsys" = x"gnu-linux"; then
96
+    AC_MSG_RESULT(netlink)
97
+    RT_METHOD=rt_netlink.o
98
+    AC_DEFINE(HAVE_NETLINK,,netlink)
99
+    netlink=yes
100
+else
101
+  if test "$opsys" = "sol2-6";then
102
+    AC_MSG_RESULT(solaris)
103
+    KERNEL_METHOD="kernel_socket.o"
104
+    RT_METHOD="rt_socket.o"
105
+  elif test "$opsys" = "irix" ; then
106
+    AC_MSG_RESULT(irix)
107
+    KERNEL_METHOD="kernel_socket.o"
108
+    RT_METHOD="rt_socket.o"
109
+  else
110
+    AC_TRY_RUN([#include <errno.h>
111
+#include <sys/types.h>
112
+#include <sys/socket.h>
113
+
114
+main ()
115
+{
116
+  int ac_sock;
117
+
118
+  ac_sock = socket (AF_ROUTE, SOCK_RAW, 0);
119
+  if (ac_sock < 0 && errno == EINVAL)
120
+    exit (1);
121
+  exit (0);
122
+}],
123
+  [KERNEL_METHOD=kernel_socket.o
124
+   RT_METHOD=rt_socket.o
125
+   AC_MSG_RESULT(socket)],
126
+  [RT_METHOD=rt_ioctl.o
127
+   AC_MSG_RESULT(ioctl)],
128
+  [KERNEL_METHOD=kernel_socket.o
129
+   RT_METHOD=rt_socket.o
130
+   AC_MSG_RESULT(socket)])
131
+  fi
132
+fi
133
+AC_SUBST(RT_METHOD)
134
+AC_SUBST(KERNEL_METHOD)
135
+AC_SUBST(OTHER_METHOD)
136
+
137
+
138
+dnl -----------------------------
139
+dnl check interface lookup method
140
+dnl -----------------------------
141
+AC_MSG_CHECKING(interface looking up method)
142
+if test "$netlink" = yes; then
143
+  AC_MSG_RESULT(netlink)
144
+  IF_METHOD=if_netlink.o
145
+else
146
+  if test "$opsys" = "sol2-6";then
147
+    AC_MSG_RESULT(solaris)
148
+    IF_METHOD=if_ioctl.o
149
+  elif test "$opsys" = "irix" ; then
150
+    AC_MSG_RESULT(irix)
151
+     IF_METHOD=if_ioctl.o
152
+  elif test "$opsys" = "openbsd";then
153
+    AC_MSG_RESULT(openbsd)
154
+    IF_METHOD=if_ioctl.o
155
+  elif grep NET_RT_IFLIST /usr/include/sys/socket.h >/dev/null 2>&1; then
156
+    AC_MSG_RESULT(sysctl)
157
+    IF_METHOD=if_sysctl.o
158
+    AC_DEFINE(HAVE_NET_RT_IFLIST,,NET_RT_IFLIST)
159
+  else
160
+    AC_MSG_RESULT(ioctl)
161
+    IF_METHOD=if_ioctl.o
162
+  fi
163
+fi
164
+AC_SUBST(IF_METHOD)
165
+
166
+
167
+
168
+AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], [Enable Netsukuku debug]),\
169
+[debug_flags="-Wall -DDEBUG"], [debug_flags=""])
170
+AC_SUBST(debug_flags)
171
+
172
+AC_DEFINE_UNQUOTED(DATA_DIR, "$datadir", "Where the Netsukuku data is saved")
173
+AC_DEFINE_UNQUOTED(CONF_DIR, "$sysconfdir", "Location of configuration files")
174
+AC_DEFINE_UNQUOTED(PID_DIR, "$piddir", "Location of ntkd.pid file")
175
+AC_ARG_WITH(pid_dir, 
176
+	    [  --with-pid-dir=ARG      Specify location of ntkd.pid file (default /var/run)],\
177
+	    [AC_DEFINE_UNQUOTED(PID_DIR, "$withval", ntkd.pid file location)])
178
+AC_SUBST(CONF_DIR)
179
+AC_SUBST(DATA_DIR)
180
+AC_SUBST(PID_DIR)
181
+
182
+AC_CONFIG_FILES([Makefile src/Makefile src/man/Makefile src/scripts/Makefile\
183
+		  src/conf/Makefile src/conf/netsukuku.conf])
184
+AC_OUTPUT

+ 530
- 0
depcomp View File

@@ -0,0 +1,530 @@
1
+#! /bin/sh
2
+# depcomp - compile a program generating dependencies as side-effects
3
+
4
+scriptversion=2005-07-09.11
5
+
6
+# Copyright (C) 1999, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
7
+
8
+# This program is free software; you can redistribute it and/or modify
9
+# it under the terms of the GNU General Public License as published by
10
+# the Free Software Foundation; either version 2, or (at your option)
11
+# any later version.
12
+
13
+# This program is distributed in the hope that it will be useful,
14
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+# GNU General Public License for more details.
17
+
18
+# You should have received a copy of the GNU General Public License
19
+# along with this program; if not, write to the Free Software
20
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
+# 02110-1301, USA.
22
+
23
+# As a special exception to the GNU General Public License, if you
24
+# distribute this file as part of a program that contains a
25
+# configuration script generated by Autoconf, you may include it under
26
+# the same distribution terms that you use for the rest of that program.
27
+
28
+# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.
29
+
30
+case $1 in
31
+  '')
32
+     echo "$0: No command.  Try \`$0 --help' for more information." 1>&2
33
+     exit 1;
34
+     ;;
35
+  -h | --h*)
36
+    cat <<\EOF
37
+Usage: depcomp [--help] [--version] PROGRAM [ARGS]
38
+
39
+Run PROGRAMS ARGS to compile a file, generating dependencies
40
+as side-effects.
41
+
42
+Environment variables:
43
+  depmode     Dependency tracking mode.
44
+  source      Source file read by `PROGRAMS ARGS'.
45
+  object      Object file output by `PROGRAMS ARGS'.
46
+  DEPDIR      directory where to store dependencies.
47
+  depfile     Dependency file to output.
48
+  tmpdepfile  Temporary file to use when outputing dependencies.
49
+  libtool     Whether libtool is used (yes/no).
50
+
51
+Report bugs to <bug-automake@gnu.org>.
52
+EOF
53
+    exit $?
54
+    ;;
55
+  -v | --v*)
56
+    echo "depcomp $scriptversion"
57
+    exit $?
58
+    ;;
59
+esac
60
+
61
+if test -z "$depmode" || test -z "$source" || test -z "$object"; then
62
+  echo "depcomp: Variables source, object and depmode must be set" 1>&2
63
+  exit 1
64
+fi
65
+
66
+# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.
67
+depfile=${depfile-`echo "$object" |
68
+  sed 's|[^\\/]*$|'${DEPDIR-.deps}'/&|;s|\.\([^.]*\)$|.P\1|;s|Pobj$|Po|'`}
69
+tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`}
70
+
71
+rm -f "$tmpdepfile"
72
+
73
+# Some modes work just like other modes, but use different flags.  We
74
+# parameterize here, but still list the modes in the big case below,
75
+# to make depend.m4 easier to write.  Note that we *cannot* use a case
76
+# here, because this file can only contain one case statement.
77
+if test "$depmode" = hp; then
78
+  # HP compiler uses -M and no extra arg.
79
+  gccflag=-M
80
+  depmode=gcc
81
+fi
82
+
83
+if test "$depmode" = dashXmstdout; then
84
+   # This is just like dashmstdout with a different argument.
85
+   dashmflag=-xM
86
+   depmode=dashmstdout
87
+fi
88
+
89
+case "$depmode" in
90
+gcc3)
91
+## gcc 3 implements dependency tracking that does exactly what
92
+## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like
93
+## it if -MD -MP comes after the -MF stuff.  Hmm.
94
+  "$@" -MT "$object" -MD -MP -MF "$tmpdepfile"
95
+  stat=$?
96
+  if test $stat -eq 0; then :
97
+  else
98
+    rm -f "$tmpdepfile"
99
+    exit $stat
100
+  fi
101
+  mv "$tmpdepfile" "$depfile"
102
+  ;;
103
+
104
+gcc)
105
+## There are various ways to get dependency output from gcc.  Here's
106
+## why we pick this rather obscure method:
107
+## - Don't want to use -MD because we'd like the dependencies to end
108
+##   up in a subdir.  Having to rename by hand is ugly.
109
+##   (We might end up doing this anyway to support other compilers.)
110
+## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like
111
+##   -MM, not -M (despite what the docs say).
112
+## - Using -M directly means running the compiler twice (even worse
113
+##   than renaming).
114
+  if test -z "$gccflag"; then
115
+    gccflag=-MD,
116
+  fi
117
+  "$@" -Wp,"$gccflag$tmpdepfile"
118
+  stat=$?
119
+  if test $stat -eq 0; then :
120
+  else
121
+    rm -f "$tmpdepfile"
122
+    exit $stat
123
+  fi
124
+  rm -f "$depfile"
125
+  echo "$object : \\" > "$depfile"
126
+  alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
127
+## The second -e expression handles DOS-style file names with drive letters.
128
+  sed -e 's/^[^:]*: / /' \
129
+      -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile"
130
+## This next piece of magic avoids the `deleted header file' problem.
131
+## The problem is that when a header file which appears in a .P file
132
+## is deleted, the dependency causes make to die (because there is
133
+## typically no way to rebuild the header).  We avoid this by adding
134
+## dummy dependencies for each header file.  Too bad gcc doesn't do
135
+## this for us directly.
136
+  tr ' ' '
137
+' < "$tmpdepfile" |
138
+## Some versions of gcc put a space before the `:'.  On the theory
139
+## that the space means something, we add a space to the output as
140
+## well.
141
+## Some versions of the HPUX 10.20 sed can't process this invocation
142
+## correctly.  Breaking it into two sed invocations is a workaround.
143
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
144
+  rm -f "$tmpdepfile"
145
+  ;;
146
+
147
+hp)
148
+  # This case exists only to let depend.m4 do its work.  It works by
149
+  # looking at the text of this script.  This case will never be run,
150
+  # since it is checked for above.
151
+  exit 1
152
+  ;;
153
+
154
+sgi)
155
+  if test "$libtool" = yes; then
156
+    "$@" "-Wp,-MDupdate,$tmpdepfile"
157
+  else
158
+    "$@" -MDupdate "$tmpdepfile"
159
+  fi
160
+  stat=$?
161
+  if test $stat -eq 0; then :
162
+  else
163
+    rm -f "$tmpdepfile"
164
+    exit $stat
165
+  fi
166
+  rm -f "$depfile"
167
+
168
+  if test -f "$tmpdepfile"; then  # yes, the sourcefile depend on other files
169
+    echo "$object : \\" > "$depfile"
170
+
171
+    # Clip off the initial element (the dependent).  Don't try to be
172
+    # clever and replace this with sed code, as IRIX sed won't handle
173
+    # lines with more than a fixed number of characters (4096 in
174
+    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;
175
+    # the IRIX cc adds comments like `#:fec' to the end of the
176
+    # dependency line.
177
+    tr ' ' '
178
+' < "$tmpdepfile" \
179
+    | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \
180
+    tr '
181
+' ' ' >> $depfile
182
+    echo >> $depfile
183
+
184
+    # The second pass generates a dummy entry for each header file.
185
+    tr ' ' '
186
+' < "$tmpdepfile" \
187
+   | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \
188
+   >> $depfile
189
+  else
190
+    # The sourcefile does not contain any dependencies, so just
191
+    # store a dummy comment line, to avoid errors with the Makefile
192
+    # "include basename.Plo" scheme.
193
+    echo "#dummy" > "$depfile"
194
+  fi
195
+  rm -f "$tmpdepfile"
196
+  ;;
197
+
198
+aix)
199
+  # The C for AIX Compiler uses -M and outputs the dependencies
200
+  # in a .u file.  In older versions, this file always lives in the
201
+  # current directory.  Also, the AIX compiler puts `$object:' at the
202
+  # start of each line; $object doesn't have directory information.
203
+  # Version 6 uses the directory in both cases.
204
+  stripped=`echo "$object" | sed 's/\(.*\)\..*$/\1/'`
205
+  tmpdepfile="$stripped.u"
206
+  if test "$libtool" = yes; then
207
+    "$@" -Wc,-M
208
+  else
209
+    "$@" -M
210
+  fi
211
+  stat=$?
212
+
213
+  if test -f "$tmpdepfile"; then :
214
+  else
215
+    stripped=`echo "$stripped" | sed 's,^.*/,,'`
216
+    tmpdepfile="$stripped.u"
217
+  fi
218
+
219
+  if test $stat -eq 0; then :
220
+  else
221
+    rm -f "$tmpdepfile"
222
+    exit $stat
223
+  fi
224
+
225
+  if test -f "$tmpdepfile"; then
226
+    outname="$stripped.o"
227
+    # Each line is of the form `foo.o: dependent.h'.
228
+    # Do two passes, one to just change these to
229
+    # `$object: dependent.h' and one to simply `dependent.h:'.
230
+    sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile"
231
+    sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile"
232
+  else
233
+    # The sourcefile does not contain any dependencies, so just
234
+    # store a dummy comment line, to avoid errors with the Makefile
235
+    # "include basename.Plo" scheme.
236
+    echo "#dummy" > "$depfile"
237
+  fi
238
+  rm -f "$tmpdepfile"
239
+  ;;
240
+
241
+icc)
242
+  # Intel's C compiler understands `-MD -MF file'.  However on
243
+  #    icc -MD -MF foo.d -c -o sub/foo.o sub/foo.c
244
+  # ICC 7.0 will fill foo.d with something like
245
+  #    foo.o: sub/foo.c
246
+  #    foo.o: sub/foo.h
247
+  # which is wrong.  We want:
248
+  #    sub/foo.o: sub/foo.c
249
+  #    sub/foo.o: sub/foo.h
250
+  #    sub/foo.c:
251
+  #    sub/foo.h:
252
+  # ICC 7.1 will output
253
+  #    foo.o: sub/foo.c sub/foo.h
254
+  # and will wrap long lines using \ :
255
+  #    foo.o: sub/foo.c ... \
256
+  #     sub/foo.h ... \
257
+  #     ...
258
+
259
+  "$@" -MD -MF "$tmpdepfile"
260
+  stat=$?
261
+  if test $stat -eq 0; then :
262
+  else
263
+    rm -f "$tmpdepfile"
264
+    exit $stat
265
+  fi
266
+  rm -f "$depfile"
267
+  # Each line is of the form `foo.o: dependent.h',
268
+  # or `foo.o: dep1.h dep2.h \', or ` dep3.h dep4.h \'.
269
+  # Do two passes, one to just change these to
270
+  # `$object: dependent.h' and one to simply `dependent.h:'.
271
+  sed "s,^[^:]*:,$object :," < "$tmpdepfile" > "$depfile"
272
+  # Some versions of the HPUX 10.20 sed can't process this invocation
273
+  # correctly.  Breaking it into two sed invocations is a workaround.
274
+  sed 's,^[^:]*: \(.*\)$,\1,;s/^\\$//;/^$/d;/:$/d' < "$tmpdepfile" |
275
+    sed -e 's/$/ :/' >> "$depfile"
276
+  rm -f "$tmpdepfile"
277
+  ;;
278
+
279
+tru64)
280
+   # The Tru64 compiler uses -MD to generate dependencies as a side
281
+   # effect.  `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'.
282
+   # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put
283
+   # dependencies in `foo.d' instead, so we check for that too.
284
+   # Subdirectories are respected.
285
+   dir=`echo "$object" | sed -e 's|/[^/]*$|/|'`
286
+   test "x$dir" = "x$object" && dir=
287
+   base=`echo "$object" | sed -e 's|^.*/||' -e 's/\.o$//' -e 's/\.lo$//'`
288
+
289
+   if test "$libtool" = yes; then
290
+      # With Tru64 cc, shared objects can also be used to make a
291
+      # static library.  This mecanism is used in libtool 1.4 series to
292
+      # handle both shared and static libraries in a single compilation.
293
+      # With libtool 1.4, dependencies were output in $dir.libs/$base.lo.d.
294
+      #
295
+      # With libtool 1.5 this exception was removed, and libtool now
296
+      # generates 2 separate objects for the 2 libraries.  These two
297
+      # compilations output dependencies in in $dir.libs/$base.o.d and
298
+      # in $dir$base.o.d.  We have to check for both files, because
299
+      # one of the two compilations can be disabled.  We should prefer
300
+      # $dir$base.o.d over $dir.libs/$base.o.d because the latter is
301
+      # automatically cleaned when .libs/ is deleted, while ignoring
302
+      # the former would cause a distcleancheck panic.
303
+      tmpdepfile1=$dir.libs/$base.lo.d   # libtool 1.4
304
+      tmpdepfile2=$dir$base.o.d          # libtool 1.5
305
+      tmpdepfile3=$dir.libs/$base.o.d    # libtool 1.5
306
+      tmpdepfile4=$dir.libs/$base.d      # Compaq CCC V6.2-504
307
+      "$@" -Wc,-MD
308
+   else
309
+      tmpdepfile1=$dir$base.o.d
310
+      tmpdepfile2=$dir$base.d
311
+      tmpdepfile3=$dir$base.d
312
+      tmpdepfile4=$dir$base.d
313
+      "$@" -MD
314
+   fi
315
+
316
+   stat=$?
317
+   if test $stat -eq 0; then :
318
+   else
319
+      rm -f "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
320
+      exit $stat
321
+   fi
322
+
323
+   for tmpdepfile in "$tmpdepfile1" "$tmpdepfile2" "$tmpdepfile3" "$tmpdepfile4"
324
+   do
325
+     test -f "$tmpdepfile" && break
326
+   done
327
+   if test -f "$tmpdepfile"; then
328
+      sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile"
329
+      # That's a tab and a space in the [].
330
+      sed -e 's,^.*\.[a-z]*:[	 ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile"
331
+   else
332
+      echo "#dummy" > "$depfile"
333
+   fi
334
+   rm -f "$tmpdepfile"
335
+   ;;
336
+
337
+#nosideeffect)
338
+  # This comment above is used by automake to tell side-effect
339
+  # dependency tracking mechanisms from slower ones.
340
+
341
+dashmstdout)
342
+  # Important note: in order to support this mode, a compiler *must*
343
+  # always write the preprocessed file to stdout, regardless of -o.
344
+  "$@" || exit $?
345
+
346
+  # Remove the call to Libtool.
347
+  if test "$libtool" = yes; then
348
+    while test $1 != '--mode=compile'; do
349
+      shift
350
+    done
351
+    shift
352
+  fi
353
+
354
+  # Remove `-o $object'.
355
+  IFS=" "
356
+  for arg
357
+  do
358
+    case $arg in
359
+    -o)
360
+      shift
361
+      ;;
362
+    $object)
363
+      shift
364
+      ;;
365
+    *)
366
+      set fnord "$@" "$arg"
367
+      shift # fnord
368
+      shift # $arg
369
+      ;;
370
+    esac
371
+  done
372
+
373
+  test -z "$dashmflag" && dashmflag=-M
374
+  # Require at least two characters before searching for `:'
375
+  # in the target name.  This is to cope with DOS-style filenames:
376
+  # a dependency such as `c:/foo/bar' could be seen as target `c' otherwise.
377
+  "$@" $dashmflag |
378
+    sed 's:^[  ]*[^: ][^:][^:]*\:[    ]*:'"$object"'\: :' > "$tmpdepfile"
379
+  rm -f "$depfile"
380
+  cat < "$tmpdepfile" > "$depfile"
381
+  tr ' ' '
382
+' < "$tmpdepfile" | \
383
+## Some versions of the HPUX 10.20 sed can't process this invocation
384
+## correctly.  Breaking it into two sed invocations is a workaround.
385
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
386
+  rm -f "$tmpdepfile"
387
+  ;;
388
+
389
+dashXmstdout)
390
+  # This case only exists to satisfy depend.m4.  It is never actually
391
+  # run, as this mode is specially recognized in the preamble.
392
+  exit 1
393
+  ;;
394
+
395
+makedepend)
396
+  "$@" || exit $?
397
+  # Remove any Libtool call
398
+  if test "$libtool" = yes; then
399
+    while test $1 != '--mode=compile'; do
400
+      shift
401
+    done
402
+    shift
403
+  fi
404
+  # X makedepend
405
+  shift
406
+  cleared=no
407
+  for arg in "$@"; do
408
+    case $cleared in
409
+    no)
410
+      set ""; shift
411
+      cleared=yes ;;
412
+    esac
413
+    case "$arg" in
414
+    -D*|-I*)
415
+      set fnord "$@" "$arg"; shift ;;
416
+    # Strip any option that makedepend may not understand.  Remove
417
+    # the object too, otherwise makedepend will parse it as a source file.
418
+    -*|$object)
419
+      ;;
420
+    *)
421
+      set fnord "$@" "$arg"; shift ;;
422
+    esac
423
+  done
424
+  obj_suffix="`echo $object | sed 's/^.*\././'`"
425
+  touch "$tmpdepfile"
426
+  ${MAKEDEPEND-makedepend} -o"$obj_suffix" -f"$tmpdepfile" "$@"
427
+  rm -f "$depfile"
428
+  cat < "$tmpdepfile" > "$depfile"
429
+  sed '1,2d' "$tmpdepfile" | tr ' ' '
430
+' | \
431
+## Some versions of the HPUX 10.20 sed can't process this invocation
432
+## correctly.  Breaking it into two sed invocations is a workaround.
433
+    sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile"
434
+  rm -f "$tmpdepfile" "$tmpdepfile".bak
435
+  ;;
436
+
437
+cpp)
438
+  # Important note: in order to support this mode, a compiler *must*
439
+  # always write the preprocessed file to stdout.
440
+  "$@" || exit $?
441
+
442
+  # Remove the call to Libtool.
443
+  if test "$libtool" = yes; then
444
+    while test $1 != '--mode=compile'; do
445
+      shift
446
+    done
447
+    shift
448
+  fi
449
+
450
+  # Remove `-o $object'.
451
+  IFS=" "
452
+  for arg
453
+  do
454
+    case $arg in
455
+    -o)
456
+      shift
457
+      ;;
458
+    $object)
459
+      shift
460
+      ;;
461
+    *)
462
+      set fnord "$@" "$arg"
463
+      shift # fnord
464
+      shift # $arg
465
+      ;;
466
+    esac
467
+  done
468
+
469
+  "$@" -E |
470
+    sed -n -e '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' \
471
+       -e '/^#line [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' |
472
+    sed '$ s: \\$::' > "$tmpdepfile"
473
+  rm -f "$depfile"
474
+  echo "$object : \\" > "$depfile"
475
+  cat < "$tmpdepfile" >> "$depfile"
476
+  sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile"
477
+  rm -f "$tmpdepfile"
478
+  ;;
479
+
480
+msvisualcpp)
481
+  # Important note: in order to support this mode, a compiler *must*
482
+  # always write the preprocessed file to stdout, regardless of -o,
483
+  # because we must use -o when running libtool.
484
+  "$@" || exit $?
485
+  IFS=" "
486
+  for arg
487
+  do
488
+    case "$arg" in
489
+    "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI")
490
+	set fnord "$@"
491
+	shift
492
+	shift
493
+	;;
494
+    *)
495
+	set fnord "$@" "$arg"
496
+	shift
497
+	shift
498
+	;;
499
+    esac
500
+  done
501
+  "$@" -E |
502
+  sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile"
503
+  rm -f "$depfile"
504
+  echo "$object : \\" > "$depfile"
505
+  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::	\1 \\:p' >> "$depfile"
506
+  echo "	" >> "$depfile"
507
+  . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile"
508
+  rm -f "$tmpdepfile"
509
+  ;;
510
+
511
+none)
512
+  exec "$@"
513
+  ;;
514
+
515
+*)
516
+  echo "Unknown depmode $depmode" 1>&2
517
+  exit 1
518
+  ;;
519
+esac
520
+
521
+exit 0
522
+
523
+# Local Variables:
524
+# mode: shell-script
525
+# sh-indentation: 2
526
+# eval: (add-hook 'write-file-hooks 'time-stamp)
527
+# time-stamp-start: "scriptversion="
528
+# time-stamp-format: "%:y-%02m-%02d.%02H"
529
+# time-stamp-end: "$"
530
+# End:

+ 14
- 0
doc/README View File

@@ -0,0 +1,14 @@
1
+What you can find in these sub-directories:
2
+
3
+
4
+main_doc/			Essential documentation
5
+
6
+articles/			Articles about various interesting topics
7
+
8
+faq/				Frequently Asked Questions
9
+
10
+howto/				Excuse me sir, how to do that?
11
+
12
+manuals/			Online manual pages
13
+
14
+misc/				Miscellanea documents

+ 51
- 0
doc/articles/Ntk_Developing_World View File

@@ -0,0 +1,51 @@
1
+== Netsukuku and ICT infrastructure in the Developing World ==
2
+
3
+{{{
4
+
5
+Netsukuku network: enabled self-made and self-sustained ICT infrastructure
6
+for developing countries.
7
+
8
+The end-users, in order to connect their PC to the rest of the World
9
+through the Internet, have to make a subscription with an Internet Operator.
10
+The Domain Names, as well, are the unique way by which a network attached
11
+device (which could consist of a computer, a file server, a network storage
12
+device, a fax machine, a cable modem, etc.) is known on the Internet,
13
+and are literally sold through the centralised system of the Domain
14
+Name System (DNS).  Netsukuku, an Open Source software, downloadable
15
+from http://netsukuku.freaknet.org makes possible the creation of a
16
+new distributed global Net, expandable to an unlimited number of users,
17
+alternative, independent and totally apart from the Internet.  
18
+The Netsukuku particular routing system, created by some members of the
19
+"Freaknet" group of Catania (Italy), allows the Net to be self-sustained,
20
+thanks to all the Net users, that share a small part of their own PC
21
+resources. Anybody has the chance to join the Net and, at the same time, to
22
+let other users do the same.
23
+In those countries and areas of the globe where Internet facilities are still
24
+not available, a public Net can be created and developed in a very simple way
25
+(i.e. through a wi-fi coverage), without depending on any Internet Operators.
26
+In the same way, all the contents holder will be able to share any documents
27
+simply from their PC, since a maximum of 256 hostnames can be recorded and
28
+automatically supported by each PC (i.e. node of the Net).  
29
+Last but not least, inside Netsukuku Net all the users will have the chance to
30
+get through the Internet: in fact any user can get the connectivity to
31
+Internet from other users that share and devolve into the net the bandwidth
32
+they don't use at the moment.
33
+Netsukuku routing system differs from all the other protocols and algorithms:
34
+the existing dynamic schemes are solely utilised to create small and medium
35
+nets.  
36
+The routers of Internet are also managed by different protocols as the OSPF,
37
+the RIP or the BGP, all based on different classical algorithms. 
38
+These algorithms are able to find out the best path to reach a node in the
39
+net, but require a very high waste of CPU and memory. That's why inside
40
+Internet, all the routers are powerful computers specifically dedicated to
41
+this purpose.  On the contrary, when a node hooks to Netsukuku, the net
42
+automatically rewrites itself, while all the other nodes, using a very small
43
+part of the CPU and of the memory resource (a few kb), recognised which are
44
+the fastest and more efficient routes to  communicate with the new arrived.
45
+The nodes don't have privileges or limitations: when compared to other nodes,
46
+they are part of the net and give their contribution to its expansion and
47
+efficiency. The more they increase in number the more the net grows and
48
+becomes stable. In Netsukuku there is no any difference between private and
49
+public nets and talking about LAN become meaningless.
50
+
51
+-CLazop

+ 29
- 0
doc/articles/Ntk_New_Global_Net View File

@@ -0,0 +1,29 @@
1
+== Netsukuku can create a global Net indipendent from the Internet ==
2
+
3
+{{{ 
4
+The Open Source enables you to migrate towards free software, but there is
5
+no chance to join your PC to the rest of the world in a free way.  
6
+Imagine to be titular of full membership into a global Network, without signing 
7
+contracts with any Internet Operators. Imagine to surf in a Net where there is 
8
+no central regulating Authority which assigns IP, conditions, names and
9
+suffixes...
10
+Netsukuku, an Open Source software, which can be downloaded from
11
+http://netsukuku.freaknet.org, makes possible the creation of a new distributed
12
+global Net, expandable to an unlimited number of users, independent and
13
+totally apart from the Internet.  Due to the Netsukuku particular routing
14
+system, created by the "Freaknet" group of Catania (Italy), the Net is self
15
+sustained, thanks to all the Net users, which share a small part of their
16
+own PC resources.  Anybody has the chance to join the Net and, at the same
17
+time, to let other users do the same.  
18
+In this way, the countries and areas of the globe where Internet
19
+facilities are still not available, simply through a wi-fi 
20
+coverage, can create and develop a Net without submitting themselves 
21
+to any Internet Operators or to any regulating central Authorities.
22
+
23
+"I hope someday you'll join us
24
+And the world will be as one...."
25
+J.Lennon
26
+
27
+
28
+-CLazop
29
+}}}

+ 28
- 0
doc/articles/Ntk_New_Global_Net.fr View File

@@ -0,0 +1,28 @@
1
+{{{
2
+L'Open Source vous permet  de migrer vers une informatique libre, mais il
3
+n'y a aucune possibilité de connecter votre ordinateur au reste du monde
4
+en modalité libre.  
5
+Imaginez un Réseau global ou tout le monde peut entrer sans s'obliger avec des
6
+fournisseurs d'accés a Internet.
7
+Imaginez de naviguer dans un Net sans devoir vous soumettre à aucune Autorité
8
+régulatrice centrale qui puisse contrôler les serveurs, établir les
9
+conditions.
10
+
11
+NETSUKUKU, un logiciel Open source, qui peut être téléchargé de
12
+http://netsukuku.freaknet.org, rend possible la création  d'un nouveau
13
+réseau global distribué, extensible à un nombre illimité d'utilisateurs,
14
+indépendant et totalement détaché de l'Internet.  Grâce au système
15
+particulier de cheminement de Netsukuku, créé par le groupe de "Freaknet"
16
+de Catane (Italie), les utilisateurs de ce réseau en sont, aussi, les
17
+membres actifs à travers le partage d'une petite partie des ressources de
18
+leurs ordinateur. Quiconque a la possibilité de s'unir au Réseau et, en
19
+même temps, de le faire grandir, l'objectif étant de créer et développer
20
+un réseau libre, communautaire, citoyen, accessible à tous et permettant,
21
+dans le respect des réglementations, la libre circulation des données.
22
+Les pays et les régions du globe où Internet n'est encore pas disponible,
23
+de cette façon, et simplement par l'utilisation d'une couverture wi-fi,
24
+peuvent créer et développer un Réseau sans se soumettre aux Opérateurs
25
+d'Internet ou à ses Autorités régulatrices centrales...
26
+
27
+"And the world will be as one...."
28
+J.Lennon

+ 19
- 0
doc/articles/Ntk_New_Global_Net.ita View File

@@ -0,0 +1,19 @@
1
+{{{
2
+L'Open source da' la facolta' di migrare verso il software libero, ma non c'e'
3
+alcuna possibilita' di collegare il proprio PC al resto del mondo senza
4
+sottoscrivere abbonamenti con gli Operatori Internet o di navigare in una rete
5
+libera da vincoli e condizionamenti.
6
+Un software Open source, scaricabile all'indirizzo
7
+http://netsukuku.freaknet.org, consente la creazione di una nuova rete globale
8
+distribuita, espandibile ad un numero illimitato di utenti, indipendente e del
9
+tutto staccata da Internet.
10
+Grazie al particolare sistema di routing "Netsukuku" messo a punto dal gruppo
11
+"Freaknet" di Catania, la Rete e' autogestita dagli stessi utenti, che mettono
12
+in condivisione una piccolissima parte delle risorse del proprio PC. Chiunque
13
+ha, cosi', la possibilita' di accedere alla Rete e sostenere, allo stesso
14
+tempo, la sua espansione.  
15
+I paesi e nelle aree del globo attualmente escluse da Internet, tramite
16
+Netsukuku e la semplice copertura wi-fi del territorio, possono, cosi', creare
17
+ed implementare una Rete globale, senza ricorrere ne' al supporto degli
18
+Operatori Internet ne' alle sue Autorita' regolatrici centrali.
19
+}}}

+ 66
- 0
doc/articles/Ntk_civic_net View File

@@ -0,0 +1,66 @@
1
+== Netsukuku and the civic networks ==
2
+
3
+{{{
4
+Cities and Institutions are showing a growing interest in e-government
5
+projects finilised in providing on line services to the citizens through
6
+Internet.
7
+For example are disposable:
8
+
9
+	- school related activities (enrolments, cultural and educational
10
+	  programs),
11
+	- news, local radio and televisions
12
+	- guides for expositions and events, cultural and tourist information
13
+	- discussion forums, social and cultural activities
14
+
15
+However, the diffusion and access to the Net isn't still disposable for
16
+everyone: DSL facilities aren't available in many cities and the ISPs impose
17
+expensive rates/costs to grant connectivity.  
18
+The creation of civic nets, in which the users can have free access to web
19
+sites and to the on line e-services, surfing freely and without any cost web
20
+sites dedicated to institutional, educational, tourist, commercial and social
21
+activities, which need a constant and direct dialogue with the people, is
22
+today made possible by NETSUKUKU Open Source software.
23
+His first aim is the implementation of a global mesh network, completely
24
+independent from Internet, in which the single PCs, communicating each other
25
+through radio frequencies, become automatically the nodes/access points of the
26
+net and in such way give  their contribution to make it alive and, at the same
27
+time, to expand it, exactly as in a fractal scheme.
28
+
29
+The NETSUKUKU routing system allows: 
30
+
31
+- every user to go not only through the Net of their city but also through
32
+  those located in all the other cities which, once they are inter-connected,
33
+  create a kind of global Network, parallel to Internet, which can
34
+  indefinitely  expand, completely without the support of ISPs;
35
+  
36
+- till a maximum of 256 hostnames to be recorded and supported by each PC
37
+  (i.e. node of the Net).
38
+  
39
+On the Netsukuku Net everybody wishing to offer digital contents/information,
40
+will be able to share them simply from his or her PC. The more of actors
41
+represented in the system is high in number, the more will be granted
42
+dialogue, circulation of different ideas, democratic process and the full
43
+right of citizenship inside the society of information.
44
+
45
+Last but not least, inside Netsukuku Net users will have the chance to get
46
+through the Internet free of cost: in fact any node can share with the
47
+Netsukuku Net his connectivity to Internet and get from other users the
48
+bandwidth they didn't use in any the moment.
49
+
50
+=== How to realize a wireless Netsukuku Net ===
51
+
52
+Netsukuku is an architecture of flexible net and will create autonomously an
53
+efficient wireless mesh network among PCs equipped with radio connection
54
+devices.  The simplest way to create/join the Netsukuku Net is to install a
55
+common wi-fi card inside your own PC and launch the Netsukuku program, freely
56
+downloadable from Internet. The flux of data will reach the wished
57
+destination, going through the same nodes (PCs or Access Points in which
58
+Netsukuku as been installed inside), interconnected among them.  Obviously a
59
+larger diffusion of the Netsukuku dedicated network can be achieved by the
60
+wi-fi coverage of wide urban and rural areas: in the market there are many and
61
+different solutions of wireless devices, all valid and cheap (routers, access
62
+points, omni directional antennas).  
63
+
64
+For more information or any request of assistance Netsukuku community is
65
+available on the net at the following site: 
66
+http://netsukuku.freaknet.org

+ 68
- 0
doc/articles/Ntk_civic_net.fr View File

@@ -0,0 +1,68 @@
1
+==== Netsukuku et les Réseaux citoyens ====
2
+
3
+{{{
4
+
5
+Les Institutions montrent  un intérêt croissant pour des projets visant a' 
6
+fournir des services en ligne aux citoyens par l'Internet.
7
+
8
+Par exemple les services suivants sont disponibles:  
9
+
10
+	- services pour l'école (inscriptions, projets culturel et
11
+	  éducatif),
12
+	- information,  live web cam, radio locaux 
13
+	- guides pour expositions et événements culturelle et touristiques 
14
+	- forum de discussion, sociales et culturelles
15
+	
16
+Cependant, les citoyens n'ont pas libre accès  aux  services en ligne des
17
+institutions, bien que les activités éducatives, administratives, commerciales
18
+et sociales aient besoin d'une constante  dialogue avec le public.
19
+En fait, la diffusion et l'accès à l'Internet n'est pas encore a' la porté de
20
+tous: l'ADSL n'est pas disponible dans beaucoup de région et les fournisseurs
21
+d'accès imposent des prix trop hauts pour accorder la connectivité.
22
+Le logiciel Open Source NETSUKUKU permet  aux Institutions d'ériger un réseau
23
+dans lequel les gens peuvent surfer sans besoin de supporter aucun coût ni de
24
+s'abonner aux fournisseur d'accès.
25
+Son but est la réalisation d'un réseau global, complètement indépendant de
26
+l'Internet, dans lequel les ordinateurs, communiquant entre eux (par les
27
+fréquences radio), deviennent automatiquement les noeuds du Réseau, donnent
28
+leur contribution pour le maintenir et, en même temps, pour en permettre
29
+l'expansion, exactement comme dans un schème à fractal.
30
+Avec le système de cheminement  NETSUKUKU, chaque utilisateur:
31
+
32
+- navigue dans le réseau de sa ville, et également dans ceux situés dans
33
+  toutes les autres villes qui, une fois reliées, créent un réseau global,
34
+  parallèles à l'Internet, qui peut indéfiniment augmenter, complètement sans
35
+  l'appui de fournisseur; 
36
+- peut enregistrer jusqu'à un maximum de 256 hostnames, qu'il contient dans
37
+  son ordinateu. 
38
+  
39
+Sur le réseau Netsukuku tout ceux qui souhaitent offrir contenus/informations
40
+numériques, pourront les partager simplement avec leurs ordinateurs.  Plus
41
+d'acteurs seront représentés dans le système est plus large seront le
42
+dialogue, la circulation des différentes idées, la participation au processus
43
+démocratique et le droit de citoyenneté à l'intérieur de la société
44
+d'information.
45
+  
46
+Enfin, les utilisateurs du réseau Netsukuku auront la chance d'accèder à
47
+Internet exempt de coût:  en fait n'importe tous les noeuds peuvent partager
48
+avec le réseau Netsukuku leur connectivité à Internet et obtenir des autres
49
+utilisateurs la largeur de bande qu'ils n'utilisent pas pour le moment.
50
+
51
+=== Comment réaliser un réseau sans fil Netsukuku === 
52
+
53
+Netsukuku est une architecture de réseau flexible et qui crée de façon
54
+autonome un réseau wireless, efficace entre les ordinateur équipés de
55
+dispositifs radio de raccordement.
56
+La manière la plus simple de créer ou de s'unir à un réseau Netsukuku est
57
+d'installer une commune carte wi-fi dans votre ordinateur et de lancer le
58
+programme de Netsukuku, librement téléchargeable de l'Internet.
59
+Le flux des données atteindra la destination souhaitée, passant par les noeuds
60
+(les ordinateurs ou les points d'accès dans lesquels Netsukuku est installé à
61
+l'intérieur), reliés ensemble entre eux.
62
+Évidemment une plus grande diffusion du réseau consacré à Netsukuku peut être
63
+réalisée par la couverture wi-fi de secteurs urbains et ruraux:  sur le marché
64
+il y a de nombreux et différents dispositifs sans fil, tous valides et à bon
65
+marché ( access point, antennes omnidirectionnelles).
66
+Pour plus d'information ou n'importe quelle demande d'aide, la communauté de
67
+Netsukuku est disponible sur Internet a' l'adresse suivante:
68
+http://netsukuku.freaknet.org

+ 91
- 0
doc/articles/Ntk_civic_net.ita View File

@@ -0,0 +1,91 @@
1
+== Netsukuku e le reti civiche ==
2
+
3
+{{{ 
4
+Netsukuku e le reti civiche
5
+
6
+Comuni, Enti ed Istituzioni stanno dimostrando un crescente interesse verso
7
+progetti di e-government finalizzati a fornire servizi on line ai cittadini
8
+attraverso Internet, chioschi informatici, call center, come
9
+ad esempio:
10
+
11
+	- servizi amministrativi comunali (anagrafe, tributi locali, avvio e
12
+	  monitoraggio di procedimenti amministrativi, ecc.)
13
+	- attivita' scolastiche (iscrizioni, iniziative culturali,progetti
14
+	  educativi)
15
+	- portali territoriali, news, radio e live webcam locali
16
+	- guide per eventi e fiere, informazioni di interesse turistico e
17
+	  culturale
18
+	- forum di discussione, sondaggi, iniziative socio-culturali.
19
+
20
+Tuttavia, la diffusione e l'accesso alle reti civiche sono, oggi, limitati
21
+dalla indisponibilita' della banda larga in molti Comuni e dai costi imposti
22
+dagli Internet sevice provider (ISP) per fornire la connettivita'.
23
+
24
+La realizzazione di reti telematiche cittadine, nelle quali gli utenti
25
+possano accedere gratuitamente ai siti web ed ai servizi informatici di Enti
26
+ed Istituzioni e' resa, oggi, possibile dal protocollo Netsukuku, che e' stato
27
+ideato per permettere l'implementazione di una mesh network su scala globale,
28
+indipendente da Internet, nella quale i singoli PC, collegandosi in frequenza
29
+radio fra loro, diventano i nodi (router) della rete, e contribuiscono a
30
+mantenerla e ad allargarla, secondo uno schema a frattale, recursivo ed a
31
+crescita esponenziale. 
32
+
33
+Il protocollo Netsukuku abilita:
34
+
35
+- gli utenti ad accedere non solo alla rete civica della propria citta' ma
36
+  anche a quelle allocate in tutte le citta' che, una volta interconesse,
37
+  formano una vera e propria ragnatela globale, parallela ad Internet, che
38
+  puo' espandersi indefinitamente, facendo sempre a meno di qualisiasi
39
+  operatore di telefonia o Internet (ISP);
40
+  
41
+- ciascun PC (ovvero nodo della rete) a supportare liberamente fino ad un
42
+  massimo di 256 hostnames.
43
+
44
+Per collegarsi alla rete Netsukuku, gli utenti devono semplicemnte dotare
45
+il proprio PC di una comune scheda wi-fi ed avviare il programma Netsukuku
46
+scaricabile da Internet. E' evidente che una copertura del territorio
47
+wi-fi a banda larga dedicata alla rete Netsukuku, ne puo' assicurare una
48
+piu' rapida espansione. Il mercato del wireless mette ormai a disposizione
49
+svariate soluzioni, tutte valide ed economiche (ripetitori, access point,
50
+antenne ecc.)e Comuni, Istituzioni, Associazioni non-profit, Imprenditori
51
+potranno cogliere l'opportunita' di sostenere questa rete come nuovo canale di
52
+comunicazione efficace, affidabile, simile ma indipendente da Internet, ideale
53
+per offrire a tutti la possibilita' di navigare liberamente e gratuitamente
54
+in siti web dedicati ad attivita' istituzionali, educative, commerciali,
55
+turistiche, promozionali e sociali, che richiedono un dialogo costante e
56
+diretto col pubblico.
57
+
58
+Sulla rete Netsukuku chiunque voglia, potra', semplicemente dal proprio
59
+PC, offrire in rete contenuti digitali, informazioni e servizi informatici:
60
+maggiore sara' il numero degli attori rappresentati nel sistema, piu' saranno
61
+garantiti la patertecipazione, il dialogo, la circolazione delle idee,
62
+il processo democratico ed il pieno esercizio del diritto di cittadinanza
63
+nella nuova societa' dell'informazione.
64
+
65
+La rete Netsukuku, infine, potra' essere utilizzata per connettersi
66
+gratuitamente ad Internet: 
67
+infatti, qualsiasi nodo puo' condividere con la rete Netsukuku la
68
+connettivita' ad Internet, a favore di chi non ha un account attivo con un ISP
69
+o perche' ne e' provvisto o perche' si trova fuori sede.
70
+
71
+Come realizzare facilmente una rete wireless Netsukuku: 
72
+La wireless mesh network di Netsukuku e' una architettura di rete flessibile 
73
+che fa muovere dati in maniera efficiente tra PC forniti di connessione radio, 
74
+in modo tale che il flusso di dati raggiunga la destinazione voluta, passando 
75
+attraverso gli stessi nodi (PC ovvero Access Point con Netsukuku installato) 
76
+interconnessi tra loro, e seguendo la rotta migliore.
77
+Gli utenti potranno essere interconnessi tra loro, all'interno del raggio
78
+d'azione delle proprie schede wi-fi o dei loro Access Point, sfruttando, ad
79
+esempio, i supporti delle antenne televisive del loro palazzo, ove potranno
80
+essere attaccate antenne wi-fi centralizzate (access point) o singole (schede
81
+wi-fi).
82
+Per favorire una piu' rapida e generale espansione della wireless mesh network
83
+basata sul protocollo Netsukuku, bastera', poi, assicurare sul territorio la
84
+presenza di semplici ripetitori wi-fi dotati di antenne omnidirezionali.
85
+
86
+La comunita' di Netsukuku e' disponibile in rete, per qualsiasi ulteriore
87
+informazione o richiesta di assistenza, sul sito:
88
+http://netsukuku.freaknet.org
89
+
90
+-CLazop
91
+}}}

+ 223
- 0
doc/faq/FAQ View File

@@ -0,0 +1,223 @@
1
+
2
+  0. General
3
+  	Q: What is Netsukuku?
4
+	Q: What are its features?
5
+	Q: Why did you choose that name?
6
+	Q: What does it mean "it uses chaos and fractals"?
7
+	Q: Why another p2p network?
8
+	Q: Ehi! You're crazy. This shit will not work!
9
+	Q: Where are current Netsukuku networks that I can connect to?
10
+	Q: What can I do to help the development of Netsukuku? How can I
11
+	   contribute to its growth?
12
+
13
+  1. Technical
14
+	Q: Does it scale in a network with A LOT of nodes?
15
+	Q: What do you intend to do to solve the IP unicity problem?
16
+	Q: Does it really works?
17
+	Q: Netsukuku is separated from Internet. How?
18
+	Q: How can I join in Netsukuku?
19
+	Q: And how does a new node begin to locate any of the other nodes in
20
+	   the network?
21
+	Q: Will you provide "Internet to Netsukuku" tunnels?
22
+	Q: Aside from what I hack myself I was wondering what can be done on
23
+	   the Netsukuku network?
24
+	Q: Will we be able to host websites anytime soon?
25
+	Q: Will glibc be able to resolve names for the ANDNA system?
26
+	Q: What sort of performance does Netsukuku have? Is it any good for 
27
+	   voice chat, video chat, games?
28
+
29
+  2. Software 
30
+	Q: On what OS does it run?
31
+	Q: Will Netsukuku be ported to Windows?
32
+	Q: Will Netsukuku be ported to PSP / Nintendo DS / wifi phones / PDAs?
33
+	Q: How does it join the network?
34
+	Q: For using a wifi link do I need of an access point? What to do?
35
+	Q: Why the code is not written in java?
36
+
37
+--
38
+
39
+
40
+/		 \
41
+   0. General
42
+\		 /
43
+
44
+Q: What is Netsukuku?
45
+A: Netsukuku is a mesh network or a p2p net system that generates and sustains
46
+   itself autonomously. It is designed to handle an unlimited number of nodes
47
+   with minimal CPU and memory resources. Thanks to this feature it can be
48
+   easily used to build a worldwide distributed, anonymous and anarchical
49
+   network, separated from the Internet, without the support of any servers,
50
+   ISPs or authority controls.
51
+   This net is composed by computers linked physically each other, therefore it
52
+   isn't build upon any existing network. Netsukuku builds only the routes which
53
+   connects all the computers of the net.
54
+   In other words, Netsukuku replaces the level 3 of the model iso/osi with
55
+   another routing protocol.
56
+   The Domain Name System is also replaced by a decentralised and distributed
57
+   system: the Abnormal Netsukuku Domain Name Anarchy.
58
+
59
+   For more information read the section "2.3  So, WTF is it?" of the
60
+   document ( http://netsukuku.freaknet.org/doc/netsukuku )
61
+
62
+Q: What are its features?
63
+A: The complete list of features is here:
64
+   http://netsukuku.freaknet.org/files/doc/misc/Ntk_features_list
65
+
66
+Q: Why did you choose that name?
67
+A: Networked Electronic Technician Skilled in Ultimate Killing, Utility and 
68
+   Kamikaze Uplinking.
69
+   But there is also another story: we were learning Japanese katakana with
70
+   `slimeforest', a nice game for GNU/Linux.
71
+   Unfortunately when we encountered the "Network" word, written in Japanese,
72
+   we didn't know all the relative symbols, so the only katakana we were able
73
+   to read were few and mixed with others the name was: Ne tsu ku ku.
74
+   By the way, you can always think of any other deceitful and hidden
75
+   meanings.
76
+
77
+Q: What does it mean "it uses chaos and fractals"?
78
+A: The Netsukuku protocol (Npv7) structures the entire net as a fractal and,
79
+   in order to calculate all the needed routes which are necessary to connect a
80
+   node to all the other nodes, it makes use of a particular algorithm called
81
+   Quantum Shortest Path Netsukuku (QSPN).
82
+   Here a fractal is meant as a highly clusterized graph of nodes.
83
+   (For the in depth description of the map system in Netsukuku read the 
84
+   "5.3  The truly Gnode^n for n<=INFINITE"  section in the document.)
85
+
86
+   On the other hand, the QSPN is a meta-algorithm in the sense that it
87
+   has to run on a real (or simulated) network. The nodes have to send the
88
+   QSPN pkt in order to "execute" it. For this reason it is not always true
89
+   that a determinate pkt will be sent before another one.
90
+   This system allows to get the best routes without any heavy computation.
91
+   (read the "5.1   QSPN: Quantum Shortest Path Netsukuku" section in the
92
+   document).
93
+
94
+Q: Why another p2p network?
95
+A: Netsukuku is not a p2p net built upon the Internet. It is a physical
96
+   network and it is a dynamic routing system designed to handle 2^128 nodes
97
+   without any servers or central systems, in this way, it is possible to
98
+   build a physical network separated from the Internet. Btw, read "What is
99
+   Netsukuku".
100
+
101
+Q: Ehi! You're crazy. It won't work!
102
+A: Ehi pal, this doesn't pretend to be _now_ the final solution to the meaning
103
+   of life, the universe and everything. Why don't you contribute and give us
104
+   useful hints from your great knowledge? If you want to help in the
105
+   development, read the code and contact us ;)
106
+
107
+Q: Where are current Netsukuku networks that I can connect to?
108
+A: Simply we don't know and we can't, but the website team si developing a
109
+   community portal which will ease the difficulty of coordination. (Think of
110
+   Google maps).
111
+
112
+Q: What can I do to help the development of Netsukuku? How can I contribute to
113
+   its growth?
114
+A: http://lab.dyne.org/Ntk_Grow_Netsukuku
115
+
116
+
117
+/		 \
118
+   1. Technical
119
+\		 /
120
+
121
+Q: Does it scale in a network with A LOT of nodes?
122
+A: Simple and not accurate reasons for the scalability of Netsukuku (until there
123
+   is the technical documentation with math background that is being written):
124
+   1) the size of the maps is fixed: about 4Kb for the int_map and 16Kb for
125
+      the ext_map.
126
+   2) Not all the nodes sends a broadcast discovery.
127
+   3) There are few floods for each discovery.
128
+   4) When a node receives a flood it already has the routes without
129
+      calculating anything.
130
+   5) A flood is synchronized: the same flood starts at the same time for all
131
+      the nodes.
132
+
133
+   A first draft of the explanation of the Netsukuku scalability is available
134
+   here: http://lab.dyne.org/Netsukuku_scalability
135
+
136
+Q: What do you intend to do to solve the IP unicity problem?
137
+A: It is already solved: http://lab.dyne.org/Ntk_gnodes_contiguity
138
+
139
+Q: Does it really works?
140
+A: ^_^
141
+
142
+Q: Netsukuku is separated from Internet. How?
143
+   Someone is building all new infrastructure? Who's paying for that?
144
+A: Not at all, there is no need to pay. The best way to physical link two
145
+   nodes is using the wifi. Nowadays, there are a lot of cool wifi
146
+   technologies, which allows to link two nodes distant kilometres each other.
147
+   In the city there would be no problems, it suffices only a node for
148
+   each neighbourhood and the city will be completely covered.
149
+
150
+Q: How can I join in Netsukuku?
151
+A: Take out your wifi antenna, and start the Netsukuku daemon on the relative
152
+   network interface, then wait and tell to do the same thing to all your
153
+   friends ^_-
154
+
155
+Q: And how does a new node begin to locate any of the other nodes in the
156
+   network?
157
+A: The Netsukuku radar sends echo packets about every 10 seconds, if someone
158
+   replies it communicates with it.
159
+
160
+Q: Will you provide "Internet to Netsukuku" tunnels?
161
+A: Yes, they will be used to link close cities. Please read this for more
162
+   information:
163
+   http://lab.dyne.org/Ntk_Internet_tunnels
164
+
165
+Q: Aside from what I hack myself I was wondering what can be done on the
166
+   Netsukuku network?
167
+A: Whatever you already do in the actual Internet. What the Netsukuku daemon
168
+   does is to only set the routes in the kernel routing table.
169
+
170
+Q: Will we be able to host websites anytime soon?
171
+A: You can do it by now!
172
+
173
+Q: Will glibc be able to resolve names for the ANDNA system?
174
+A: ANDNA comes with a DNS wrapper so it is trasparent to all the programs
175
+   which uses the glibc. Read "man andna":
176
+   http://netsukuku.freaknet.org/doc/manuals/html/andna.html
177
+
178
+Q: What sort of performance does Netsukuku have? Is it any good for voice chat
179
+   video chat?
180
+A: What do you mean by `performance'? 
181
+
182
+   Network performance: it is dependent on the links quality. If the nodes are
183
+   linked by 100Mbps cable you will feel like in a large LAN. 
184
+   The distance from yourself and the destination node is also relevant.
185
+   Remember that the Netsukuku daemon chooses only the best way to reach
186
+   the other nodes, but cannot improve the roads themself.
187
+   
188
+   Software performance: you really shouldn't worry about this:
189
+   PID   USER  PRI  NI  SIZE  RSS  SHARE %CPU %MEM TIME CPU COMMAND
190
+   18521 root  15   0   17708 1552 1164  0.0  0.3  0:00 0   ntkd
191
+   
192
+
193
+/		 \
194
+   2. Software
195
+\		 /
196
+
197
+Q: On what OS does it run?
198
+A: For now it runs only on GNU/Linux, but it is easy to port it on other OS.
199
+   If you want to join in the development let us now ;)
200
+
201
+Q: Will Netsukuku be ported to Windows?
202
+A: Short answer: if you code the port, yes.
203
+   Answer: We need coders for that. There are a lot of things to be done and
204
+   the Windows port is what we care less.
205
+
206
+Q: Will Netsukuku be ported to PSP / Nintendo DS / wifi phones / linux PDAs 
207
+   etc...
208
+A: We are currently working on flashing Netsukuku on Access Points (like
209
+   Linksys). See http://netsukuku.freaknet.org/openwrt/
210
+
211
+Q: For using a wifi link do I need of an access point? What to do?
212
+A: You just need a wifi network card. Put it in ad-hoc mode using "netsukuku"
213
+   as essid. ( man netsukuku_wifi:
214
+   http://netsukuku.freaknet.org/doc/manuals/html/netsukuku_wifi.html )
215
+
216
+Q: Why the code is not written in java?
217
+A: Are you kidding?
218
+
219
+
220
+--
221
+
222
+Q: My question is not answered here!
223
+A: Contact us: http://netsukuku.freaknet.org

+ 27
- 0
doc/faq/FAQ.fr View File

@@ -0,0 +1,27 @@
1
+= Questions fréquentes sur Netsukuku (fr) =
2
+
3
+== 0. Généralités ==
4
+
5
+=== 0.1. Qu'est-ce que Netsukuku ? ===
6
+
7
+Netsukuku est un réseau maillé ou un système P2P qui se génère et entretient son fonctionnement de façon autonome. Il est conçu pour gérer un nombre illimité de n?uds avec des ressources en puissance de calcul et en mémoire minimales. Il peut ainsi être facilement utilisé pour bâtir un réseau mondial distribué, anonyme et anarchique, distinct d'Internet, sans recourir à aucun serveur, fournisseur d'accès ou autorité de contrôle.
8
+
9
+Gardez à l'esprit qu'il s'agit d'un réseau ''physique'' : il ne se fonde sur aucun autre réseau existant. Il doit par conséquent y avoir des ordinateurs reliés ''physiquement'', Netsukuku créant ensuite les routes.
10
+
11
+En d'autres termes, Netsukuku remplace le niveau 3 du modèle ISO/OSI par un autre protocole de routage.
12
+
13
+Pour plus d'informations, lisez la section 2.4, ''Mais qu'est-ce que c'est, à la fin ?'' de la documentation.
14
+
15
+=== 0.2. Quelles sont ses fonctionnalités ? ===
16
+
17
+La liste complète des fonctionnalités se trouve ici : [http://netsukuku.freaknet.org/files/doc/misc/Ntk_features_list].
18
+
19
+=== 0.3. Pourquoi avoir choisi ce nom ? ===
20
+
21
+Nouveaux Électriciens Trappistes Sans Kimono Unissant Karma et Urbanité.
22
+
23
+Mais il y a une autre histoire, aussi. Nous apprenions les katakanas japonais avec slimeforest, un chouette jeu pour GNU/Linux.
24
+
25
+Malheureusement, quand nous sommes tombés sur le mot ''réseau'' écrit en japonais, nous ne connaissions pas tous les symboles employés ; nous ne pouvions donc lire que quelques katakanas et, mélangés avec d'autres, ça donnait le nom Ne-tsu-ku-ku.
26
+
27
+Bon, mais vous pouvez toujours imaginer d'autres significations exotiques...

+ 65
- 0
doc/faq/FAQ.ru View File

@@ -0,0 +1,65 @@
1
+= ???????? =
2
+
3
+ ??? ????? Netsukuku:: Netsukuku - ??? P2P ???? ? ???????? ?????????? ??????? ????????? ? ?????????????? ??????????????. ??? ???????? ???????????? ?????????????? ?????????? ????? ? ???????????? ????????? ???????? ?????????? ? ??????. ????????? ????? ??? ????? ???? ??????? ??? ???????? ?????????? ??????????????, ????????? ? ???????????? ????, ?? ????????? ? ??????????, ??? ????????, ??????????? ??? ???????? ???????. ???? ????????? ??? Netsukuku ? ??? ?????????? ????, ?? ?????????? ??? ?????-???? ???????????? ?????, ???? ? ??? ?????? ???? ????????? ??????? ????? ????? ????? Netsukuku ????????? ??????? ?????????????. ??????? ??????? Netsukuku ???????? 3-? ??????? ??????? ?????? ISO/OSI (??????? ???????) ????? ?????????? ?????????????.[[BR]](??????: "2.4 So, WTF is it?" http://netsukuku.freaknet.org/?p=Documentation)
4
+
5
+ ?????? ??????? ???  Netsukuku?:: Networked Electronic Technician Skilled in Ultimate Killing, Utility and Kamikaze Uplinking ? ??????? ??????????? ?????????? ???????????? ? ?????????? ???????????, ???????????? ? ??????????? ????? ?????????. [[BR]] ???? ??? ?? ?????? ??????. ?? ??????? ???????? ????? ? «slimeforest» ???? ??? GNU/Linux. ? ????????? ????? ?? ??????????? ?? ?????? «Network» ?????????? ?? ??????? ?? ?? ????? ?????????? ????????, ??? ??? ???????????? ????? ???????? ??????? ??? ??????? ????????? ? ??? ????: Ne tsu ku ku. ?????? ?? ?????? ?????? ????????? ???? ?????????? ????? ? ??????? ? ??? ?????? ?????.
6
+
7
+ ??? ?????? «?????????? ??????????? ? ????????»?:: ????????  Netsukuku (Npv7) ????????????? ??? ???? ??? ??????? ? ??? ?????????? ????????? ??????????? ???? ??? ?????????????? ? ????? ?????????? ???????? ?????????? ??????????? ????  Netsukuku (QSPN). ????? ??? ????????? ?????????? ???? ? ???????  ???????? ????????????? ?????????. [[BR]] (??????: 5.3 The truly Gnode^n for n<=INFINITE" http://netsukuku.freaknet.org/?p=Documentation) [[BR]] ? ?????? ??????? QPSN ? ????-???????? ????? ?? ??????????? ? ???????? ????????  ???? (??? ?????????). ??? ??? «??????????» ???? ?????? ??????? QPSN pkt(?????). ??????? ?? ?????? ????? ??? ???????????? ????? ????? ?????? ????? ????? ??????. ??? ????????? ????????? ?????? ???? ??? ??????? ??????????. [[BR]] (??????: "5.1 QSPN: Quantum Shortest Path Netsukuku" http://netsukuku.freaknet.org/?p=Documentation)
8
+
9
+ ??? ???? ??? ???? p2p ?????:: Netsukuku ?? p2p ??????????? ?????? ?????????. ??? ?????????? ???? ? ?? ????? ???????????? ????????????? ?????????????? ??? ???? ? 2^128 ????? ??? ???????? ??? ???????????????? ???????, ????? ??????? ???????? ????????? ??????????? ?? ????????? ????. ??????, ?????????? «??? ????? Netsukuku»
10
+
11
+ ??! ?? ?? ???????. ??? ????? ?? ????? ????????!:: ??, ?????? ??? ?? ???????? ???? ????????????? ???????? ????????? ??????? ?????, ????????? ? ????? ??????????. ?????? ?? ?? ????????? ????-?????? ? ?????? ? ?? ?????????? ?????? ?????????? ???????????? ??????????? ???? ?????? ?????? ? ?????????? ????? ??? ? ??????? ? ???? ;)
12
+
13
+ ??? ???? ???? Netsukuku ? ??? ? ??? ???????????????:: ?? ?? ?????? ?????, ?? ? ?? ????? ?????, ?? ?? ?????? ????? ??????? ????????? ??????, ??????? ???????? ???????????.
14
+
15
+ ??? ? ???? ?????? ???????? Netsukuku? ??? ? ?????? ????? ? ?? ?????:: ??????? ????: http://lab.dyne.org/Ntk_Grow_Netsukuku
16
+
17
+= ??????????? ????? =
18
+
19
+ ??? Netsukuku ?????????????? ? ???? ? ??????? ??????????? ??????:: ??????? ? ?? ?????? ?????? ??????? ???????????????? Netsukuku (?? ??? ??? ???? ?? ????? ???????? ???. ???????????? ? ?????????????? ????????????):
20
+ 1. ?????? ????? ??????????, ????? 4?? ??? int_map ? 16?? ??? ext_map.
21
+ 1. ?? ??? ???? ???????? ????????????????? ?????? ??? ??????????? ???????? ????? (broadcast discovery)
22
+ 1. ????????????????? ?????? ?????????????? ????????????.
23
+ 1. ? ?????? ????????? ?????????????????? ?????? ???? ???????? ??????????? ???? ??? ?????-???? ??????????
24
+ 1. ??????? ????????????????, ??? ???? ???????? ????????????? ????????????.
25
+ ???????? ?????????? ???????????? ????????????????  Netsukuku ???????? ?? ??????:  http://lab.dyne.org/Netsukuku_scalability
26
+
27
+ ??? ?????????????? ?????? ???????? ?????????? IP ??? ????????? ??????:: ???????? ??? ??????: http://lab.dyne.org/Ntk_gnodes_contiguity
28
+
29
+ ??? ??? ????????????? ?????????::   :)
30
+
31
+ Netsukuku ?????????? ?? ?????????. ???? ???-?? ?????? ?????????? ????? ??????????????? ??? ?? ??? ??? ???????:: ????? ???, ??????? ?? ????. ?????? ?????? ????????? ??????? ??? ???? ? ???????????? ?????????? (Wi-Fi). ?????? ?????????? ????????? ???????????? ?????????? ??????????? ???????? ????? ????? ???? ?? ?????????? ? ?????????. ? ??????? ?? ?????? ???? ?????-???? ???????, ?????????? Wi-Fi ???? ?? ?????/??????? ??? ??????? ????????.
32
+
33
+ ??? ?????????????? ? Netsukuku?:: ?????????? Wi-Fi ???????, ????? ????????? Netsukuku ????? ?? ??????????????? ??????? ??????????. ?????, ? ?? ???????? ??????? ??????? ??????? ???? ?????  ^_-
34
+
35
+ ??? ????? ???? ???????????? ?????? ? ?????:: «?????» Netsukuku ???????? ??? ?????? ?????? 10 ??????, ???? ???-?????? ????????, ????????????? ?????.
36
+
37
+ ?????-?? ????????????? «Netsukuku ? ????????» ????????:: ??, ??? ?????????? ????? ????????. ????? ???????? ???: http://lab.dyne.org/Ntk_Internet_tunnels
38
+
39
+ ????? ??????????? ??? ? ???? ?????? ? ???? Netsukuku?:: ???? ????? ??? ????? ?????? ? ?????????. ????? Netsukuku ?????-???? ??????????? ???????? ? ??????? ????????????? ????.
40
+
41
+ ?????-?? ????? ??????????? ??????:: ????? ??? ??????.
42
+
43
+ ??????-?? glibc ??????????????? ????? ?? ANDNAv?:: ? ANDNA ???? ??????? DNS ??? ??? ??? ????????? ??? ???? ???????? ???????????? glibc. [[BR]] (?????? "man andna": http://netsukuku.freaknet.org/doc/manuals/html/andna.html )
44
+
45
+ ?????? ?????????????????? Netsukuku? ???? ?? ???????????? ??? ?????- ??? ??????????:: ??? ??????????????? ??? «???????????????????»? [[BR]] ??????? ??????????????????: ??????? ?? ?? ???????? ?????. ???? ???? ??????? 100??/? ??????? ?? ????? ???????? ??????? ?? ??????? LAN. ?????????? ????? ?????? ????? ????? ????????. ???????? ??? ????? Netsukuku ???????? ????????? ??????? ?? ?????? ?????, ?? ?? ????? ???????? ??. [[BR]] ??????????? ??????????????????: ?? ???? ?? ????? ?????? ????????????:
46
+{{{ PID USER PRI NI SIZE RSS SHARE %CPU %MEM TIME CPU COMMAND
47
+18521 root 15 0 17708 1552 1164 0.0 0.3 0:00 0 netsukuku_d }}}
48
+
49
+= ??????????? ????? =
50
+
51
+ ?? ????? ???????????? ??????? ??????????? Netsukuku?:: ???? ?????? GNU/Linux, ???????? ??????????? ?? ????? ??. ???? ???? ??????? ???? ???????? ????? ??? ????? ;)
52
+
53
+ ?????-?? Netsukuku ??? Windows?:: ???????? ?????: ???? ?? ????????, ?? ??. [[BR]] ?????: ??? ????? ??? ?????????? ??????, ???? ??????? ?????? ???? ??? ?????????? ??? ??????? ? ???? ?? Windows ?? ????????? ?????.
54
+
55
+ ?????-?? Netsukuku ?????????? ?? PSP / Nintendo DS / Wi-Fi ?????????? / Linux
56
+ ??? ? ??? ??????:: ?????? ?? ???????? ??? Netsukuku ??? ???????????? ?????
57
+ ??????? (???????? Linksys). (http://netsukuku.freaknet.org/openwrt/)
58
+
59
+ ??? ??????????? Wi-Fi ??? ????? ????? ????????:: ??????????  Wi-Fi ???????
60
+ ?????. ?????????? ?? ? ????????? ?????????? (ad-hoc) ????????? «netsukuku»
61
+ ???  essid [[BR]] (man netsukuku_wifi: http://netsukuku.freaknet.org/doc/manuals/html/netsukuku_wifi.html )
62
+
63
+ ?????? ?? ?? ?????? ?? Java?:: ??? ????? ??????
64
+
65
+ ????? ??????? ??? ???!:: ??? ????: http://netsukuku.freaknet.org/

+ 147
- 0
doc/howto/igs_howto View File

@@ -0,0 +1,147 @@
1
+Internet connection sharing in Netsukuku HOWTO
2
+
3
+This document describes how to configure a Netsukuku node to share its
4
+Internet connection and how to configure another node that will use the shared
5
+connection.
6
+
7
+--
8
+
9
+	* Internet Gateway Search
10
+	
11
+	* Prerequisites
12
+	
13
+	* How to share your Internet connection
14
+	
15
+	* How to connect to the Internet using a shared connection
16
+	
17
+	* Some nice feature you want to know
18
+
19
+--
20
+
21
+**
22
+*** Internet Gateway Search
23
+**
24
+
25
+If the nodes are in restricted mode (compatibility with the Internet), they
26
+can share their Internet connection. This can be easily done, in fact, if a
27
+node X, connected to the Internet, activates the masquerading, it is possible
28
+for the other nodes to connect by setting as the default gateway their rnode
29
+which lead to the node X.
30
+
31
+This can be automated by Netsukuku itself.
32
+The node which is sharing its connection will tell to the Netsukuku daemon to
33
+masquerade its connection and to set a specific flag in the QSPN packets.
34
+The other nodes in restricted mode will automatically know their nearest
35
+Netsukuku Internet gateway and set it in their default route.
36
+
37
+For more information read http://lab.dyne.org/Ntk_IGS .
38
+
39
+
40
+**
41
+*** Prerequisites
42
+**
43
+
44
+The IGS code of Netsukuku depends on the IPIP tunnel code of the kernel, so if
45
+you are using Linux be sure to have the `CONFIG_NET_IPIP' option set as a
46
+module or built-in.
47
+
48
+
49
+**
50
+*** How to share your Internet connection
51
+**
52
+
53
+First of all modify the /etc/netsukuku/netsukuku.conf file.
54
+
55
+Set `internet_connection' to 1.
56
+
57
+Set the `internet_gateway' option to the IP of the gateway you use to reach 
58
+the Internet and specify the network interface too, for example:
59
+"internet_gateway = 192.168.1.1:eth0". This option is necessary only if you
60
+don't have the default route set when you run NetsukukuD (i.e. you haven't
61
+connected yet), otherwise, leave it commented.
62
+
63
+You have also to set your upload and download bandwidth in 
64
+`internet_upload_rate' and `internet_download_rate'. It is expressed in Kb/s,
65
+so if you have a line which maximum can do: 640 Kb/s in dwload and 30 Kb/s in 
66
+upload, set them to 640 and 30.
67
+
68
+`internet_ping_hosts' is a list of Internet hosts which will be pinged to
69
+verify if the connection is alive, you can use the default hosts.
70
+
71
+Finally, If you want to share your Internet connection among other Netsukuku
72
+nodes, set `share_internet' to 1.
73
+
74
+Ah, and you can set `shape_internet' to 1 if you want to shape your outgoing
75
+Internet traffic.
76
+
77
+---- netsukuku.conf snip ----
78
+internet_connection	= 1
79
+internet_gateway	= 192.168.1.1:eth0
80
+internet_download_rate  = 640
81
+internet_upload_rate	= 30
82
+internet_ping_hosts	= google.com:cisco.com:sourceforge.net:dyne.org
83
+share_internet		= 1
84
+shape_internet		= 1
85
+----       snip end      ----
86
+
87
+Now you are ready to launch the Netsukuku daemon. You have just to append the -I
88
+option in the command line. For example:
89
+
90
+# ntkd -i wlan0 -r -I
91
+
92
+
93
+**
94
+*** How to connect to the Internet using a shared connection
95
+**
96
+
97
+Just start the daemon in restricted mode, f.e:
98
+
99
+# ntkd -i wlan0 -r
100
+
101
+If you have an Internet connection and you don't want to share it, you have to
102
+set the correct options in netsukuku.conf:
103
+
104
+---- netsukuku.conf snip ----
105
+internet_connection     = 1
106
+internet_gateway        = 192.168.1.1:eth0
107
+internet_download_rate  = 640
108
+internet_upload_rate    = 30
109
+internet_ping_hosts     = google.com:cisco.com:sourceforge.net:dyne.org
110
+share_internet          = 0
111
+----       snip end      ----
112
+
113
+If you don't, your Internet connection default route will be overwritten with
114
+that of another node.
115
+
116
+
117
+**
118
+*** Some nice feature you want to know
119
+**
120
+
121
+NetsukukuD supports a routing method called "multi inet gateway", this means
122
+that your node can connect to the Internet using, at the same time, multiple
123
+node which share their connection.
124
+If there are 5 nodes which share their 640Kb/s connections, you can have 5
125
+parallel downloads at 640Kb/s. Isn't it juicy?
126
+There's more: if you decide to share your Internet connection, you will always
127
+use the Internet connections shared by the other nodes, in this way you donate
128
+your bandwidth but, at the same time, you receive donations from other users.
129
+
130
+The other nice feature is the traffic shaping of your Internet connection (it
131
+doesn't matter if you're sharing it or not).
132
+If you decide to enable the relative option (shape_internet=1), NetsukukuD
133
+will execute the /etc/netsukuku/tc_shaper.sh script. 
134
+This script shapes your Internet connection, this means that the traffic
135
+generated from your private LAN (192.168.x.x) and the low delay traffic (i.e.
136
+DNS, ssh...) are prioritised.
137
+The benefits are:
138
+* Even if you share your Internet connection to other Netsukuku nodes, your
139
+  traffic will have the maximum priority, therefore you won't notices any
140
+  slowdown
141
+* Even if you are downloading a big file, your lowdelay traffic will have the
142
+  priority, therefor your ssh connections won't slow a bit
143
+
144
+PS: for more information read: http://lab.dyne.org/Ntk_IGS
145
+
146
+That's all,
147
+enjoy ^_^

+ 1616
- 0
doc/main_doc/netsukuku
File diff suppressed because it is too large
View File


+ 1208
- 0
doc/main_doc/netsukuku.ita
File diff suppressed because it is too large
View File


+ 130
- 0
doc/main_doc/ntk_rfc/Ntk_IGS View File

@@ -0,0 +1,130 @@
1
+== NTK_RFC 0003 ==
2
+
3
+Subject: Internet Gateway Search
4
+
5
+----
6
+This text describes a change to the Npv7.
7
+It will be included in the final documentation, so feel free to correct it.
8
+But if you want to change the system here described, please contact us first.
9
+----
10
+
11
+If the nodes are in restricted mode (compatibility with the Internet), they
12
+should share their Internet connection. This can be easily done, in fact, if
13
+a node X, connected to the Internet, activates the masquerading, it is
14
+possible for the other nodes to connect by setting as the default gateway
15
+their rnode which lead to the node X.
16
+
17
+This can be automated by Netsukuku itself and it requires small changes in the
18
+code: it is just necessary that the nodes connected to the Internet set a flag
19
+in the qspn_pkt, in this way the other nodes will know the routes to reach the
20
+Internet.
21
+
22
+=== Multi-gateways ===
23
+
24
+The situation becomes a little complex when there is more than one node which
25
+shares its internet connection. Let's consider this scenario:
26
+
27
+{{{
28
+		   A(gw)      B(gw)
29
+		    \	       /
30
+		     \___  ___/
31
+		         \/
32
+		      Ntk nodes (10.x.x.x)
33
+}}}
34
+
35
+A and B are nodes which shares their internet connection, we call them
36
+gateways. Let's call X the node which wants to connect to an Internet host.
37
+In this case, the nodes near A, might find useful to use A itself to
38
+reach the Internet, the same happens for the nodes near B.
39
+Instead, the nodes in the middle don't know what is the best choice and they
40
+might continuosly change their gw. This means that a tcp connection
41
+(to an inet host), which was established trough A, when is then routed trough
42
+B dies because A and B have different public IPs on the Internet.
43
+
44
+The node X has to create an IPIP tunnel to the gateway it wants to use, and
45
+set as default gw the tunnel. In this way, the node X is sure to always use
46
+the same gateway while the routing of the packets between it and the gw is
47
+made transparently by the other Netsukuku nodes.
48
+
49
+==== Anti loop multi-inet_gw shield ====
50
+
51
+An inet-gw is a normal node like all the other, therefore it can use the
52
+Internet connections of the other inet-gws in conjunction with its own one.
53
+
54
+Consider the previous scenario, A and B are two inet-gw. 
55
+A sets in his internet default route the adsl modem and B.
56
+B does the same, but sets A as the second default route.
57
+
58
+What would happen if the default route, written in the routing cache of A, is
59
+B and, at the same time, the default route set in the routing cache of B is A?
60
+The packets would jump endlessy in a infinite loop loosing themself forever.
61
+
62
+That's why we need the "anti loop multi-inet_gw shield".
63
+It's working way is simple: each inet-gw has a netfilter rule which marks
64
+all the packets coming from the outside and directed to the Internet. These
65
+packets are then routed directly to the Internet without being sent, again, to
66
+an inet-gw. In the example:
67
+A wants to send a packet to the Internet and its looks in its routing cache.
68
+It decide to forward the packet to B. B receives the packet, recognizes it is
69
+an extern packet directed to the Internet and shoots it on its modem.
70
+
71
+=== Load sharing ===
72
+
73
+Let's consider the previous scenario.
74
+
75
+The node X can also decide to use both A and B to reach the Internet, using
76
+at the same time their connections! Even the gw A can use at the same time
77
+its own line and the connection of the gw B.
78
+
79
+The procedure to implement this is what follows:
80
+
81
+ * X creates a tunnel to A and another one to B
82
+ 
83
+ * X adds in the routing table the default route using A and B as multipath
84
+gateways. The gateway for the connections is chosen randomly.
85
+
86
+ * X adds a rule in the routing table to route all the packets of established
87
+connections trough the same gateway used to create the same connection.
88
+The rule is linked to some netfilter rules which track and mark each
89
+connection. The method is described in details here:
90
+https://lists.netfilter.org/pipermail/netfilter/2006-March/065005.html
91
+
92
+=== The bad ===
93
+
94
+The implementation of the Load sharing is very Linux specific, so it will be
95
+very difficult to port it to other kernels, therefore this feature will be
96
+available only to nodes which run Linux (ehi, one more reason to use Linux ;).
97
+
98
+=== MASQUERADING ===
99
+
100
+Each node sharing the Internet connection (inet-gw) has to masquerade its
101
+interfaces, so iptables must be used.
102
+In order to keep the daemon portable, NetsukukuD will launch the script found
103
+at /etc/netsukuku/masquerade.sh, which in Linux will be a simple script that
104
+executes "iptables -A POSTROUTING -t nat -j MASQUERADE".
105
+When NetsukukuD is closed the added firewall rules are flushed with 
106
+"/etc/netsukuku/masquerade.sh close"
107
+
108
+
109
+=== Traffic shaping ===
110
+
111
+The inet-gw can also shape its internet connection in order to prioritize its
112
+local outgoing traffic (the traffic coming from its 192.168.x.x LAN). 
113
+In this way, even if it shares its Internet connection, it won't notice any
114
+difference 'cause it will have the first priority. Moreover with the traffic
115
+shaper, the inet-gw can also prioritize some protocol, i.e. SSH.
116
+
117
+The traffic shaper will activated at the start of NetsukukuD. The daemon will
118
+run the /etc/netsukuku/tc_shaper.sh script, which in Linux utilizes the
119
+iproute2 userspace utility.
120
+When the daemon is closed the traffic shaping will be disabled with
121
+"/etc/netsukuku/tc_shaper.sh close".
122
+
123
+=== See also ===
124
+
125
+For more information on the necessity of using ipip tunnels in an adhoc
126
+network used to share internet connections, you can read this paper:
127
+http://www.olsr.org/docs/XA-OLSR-paper-for-ICC04.pdf
128
+
129
+----
130
+related: ["Netsukuku RFC"]

+ 56
- 0
doc/main_doc/ntk_rfc/Ntk_MX_request View File

@@ -0,0 +1,56 @@
1
+== NTK_RFC 0004 ==
2
+
3
+Subject: Mail Exchange request
4
+
5
+----
6
+This text describes how the MX DNS query are resolved by ANDNA.
7
+
8
+		    * WARNING *
9
+This RFC has been deprecated by the NTK_RFC 0009
10
+		    * WARNING *
11
+----
12
+
13
+In the DNS the resolution of the MX field is handled directly by the DNS
14
+servers, in ANDNA, instead, the resolution of an MX hostname is a redirect
15
+request. In short it means that the request, instead of being sent to a
16
+hash_node, is sent to the register_node itself,
17
+
18
+== hname MX resolution ==
19
+
20
+The resolution of a MX hostnames in ANDNA works in this way:
21
+ * We are trying to resolve the MX of the "pippo" hname.
22
+ * "pippo" is resolved normally and the IP of the register_node is gained.
23
+ * We ask to the register_node the IP of its MX.
24
+
25
+== hname MX registration ==
26
+
27
+Since the IP of the MX node can change during the time, the register_node must
28
+be aware of its current IP.
29
+It is the MX node itself that tells the register_node its current IP each time
30
+it changes. The MX node to contact the register_node has to simply resolve its
31
+hname.
32
+The register_node has to verify the authenticity of the IP update request,
33
+therefore the MX node will sign the request with the private key of the
34
+register_node.
35
+
36
+This system is necessary because the MX node and the register node have to be
37
+synced. In this way when the register_node dies or can't be reached anymore,
38
+the MX node can't be contacted too.
39
+Moreover this system prevents the spoofing of the MX node.
40
+
41
+The steps necessary to register a hname MX are:
42
+ * Copy the ANDNA private key of the register node, which is saved in its lcl_cache, to the MX node:
43
+{{{
44
+register_node# scp /usr/share/netsukuku/andna_lcl_keyring mx_node:/etc/netsukuku/mx/<HNAME_MX>
45
+# <HNAME_MX> is the hname relative to the MX node
46
+}}}
47
+ * Send a SIGHUP to the MX NetsukukuD:
48
+{{{
49
+register_node# ssh mx_node "killall -HUP ntkd"
50
+}}}
51
+
52
+
53
+If no MX is associated to an hostname, the register_node will use its own IP
54
+as the default MX IP.
55
+----
56
+related: [Netsukuku_RFC]

+ 203
- 0
doc/main_doc/ntk_rfc/Ntk_SNSD View File

@@ -0,0 +1,203 @@
1
+== NTK_RFC 0009 ==
2
+
3
+Subject: Scattered Name Service Disgregation
4
+
5
+----
6
+This text describes the Scattered Name Service Disgregation, an extension of
7
+the ANDNA protocol.
8
+It will be included in the final documentation, so feel free to correct it.
9
+But if you want to change the system here described, please contact us first.
10
+----
11
+
12
+== SNSD ==
13
+
14
+The Scattered Name Service Disgregation is the ANDNA equivalent of the
15
+SRV Record of the Internet Domain Name System, which is defined here:
16
+http://www.ietf.org/rfc/rfc2782.txt
17
+For a brief explanation you can read:
18
+http://en.wikipedia.org/wiki/SRV_record
19
+
20
+SNSD isn't the same of the "SRV Record", in fact, it has its own unique
21
+features.
22
+
23
+With the SNSD it is possible to associate IPs and hostnames to another
24
+hostname.
25
+Each assigned record has a service number, in this way the IPs and hostnames
26
+which have the same service number are grouped in an array.
27
+In the resolution request the client will specify the service number too,
28
+therefore it will get the record of the specified service number which is 
29
+associated to the hostname. Example:
30
+
31
+The node X has registered the hostname "angelica".
32
+The default IP of "angelica" is 1.2.3.4.
33
+X associates the "depausceve" hostname to the `http' service number (80) of
34
+"angelica".
35
+X associates the "11.22.33.44" IP to the `ftp' service number (21) of
36
+"angelica".
37
+
38
+When the node Y resolves normally "angelica", it gets 1.2.3.4, but when
39
+its web browser tries to resolve it, it asks for the record associated to
40
+the `http' service, therefore the resolution will return "depausceve".
41
+The browser will resolve "depausceve" and will finally contact the server.
42
+When the ftp client of Y will try to resolve "angelica", it will get the
43
+"11.22.33.44" IP.
44
+If Y tries to resolve a service which hasn't been associated to anything, it
45
+will get the mainip 1.2.3.4.
46
+
47
+The node associated to a SNSD record is called "SNSD node". In this example
48
+"depausceve" and 11.22.33.44 are SNSD nodes.
49
+
50
+The node which registers the records and keeps the registration of the main
51
+hostname is always called "register node", but it can also be named "Zero SNSD
52
+node", in fact, it corresponds to the most general SNSD record: the service
53
+number 0.
54
+
55
+Note that with the SNSD, the NTK_RFC 0004 will be completely deprecated.
56
+
57
+== Service, priority and weight number ==
58
+
59
+==== Service number ====
60
+
61
+The service number specifies the scope of a SNSD record. The IP associated to 
62
+the service number `x' will be returned only to a resolution request which has
63
+the same service number.
64
+
65
+A service number is the port number of a specific service. The port of the
66
+service can be retrieved from /etc/services.
67
+
68
+The service number 0 corresponds to a normal ANDNA record. The relative IP
69
+will be returned to a general resolution request.
70
+
71
+==== Priority ====
72
+
73
+The SNSD record has also a priority number. This number specifies the priority
74
+of the record inside its service array.
75
+The client will contact first the SNSD nodes which have the higher priority,
76
+and only if they are unreachable, it will try to contact the other nodes
77
+which have a lower priority.
78
+
79
+==== Weight ===
80
+
81
+The weight number, associated to each SNSD record, is used when there are
82
+more than one records which have the same priority number.
83
+In this case, this is how the client chooses which record using to contact
84
+the servers:
85
+
86
+The client asks ANDNA the resolution request and it gets, for example, 8
87
+different records.
88
+The first record which will be used by the client is chosen in a pseudo-random
89
+manner: each record has a probability to be picked, which is proportional to its
90
+weight number, therefore the records with the heavier weight are more likely to
91
+be picked.
92
+Note that if the records have the same priority, then the choice is completely
93
+random.
94
+
95
+It is also possible to use a weight equal to zero to disable a record.
96
+
97
+The weight number has to be less than 128.
98
+
99
+== SNSD Registration ==
100
+
101
+The registration method of a SNSD record is similar to that described in the
102
+NTK_RFC 0004.
103
+
104
+It is possible to associate up to 16 records to a single service.
105
+The maximum number of total records which can be registered is 256.
106
+
107
+The registration of the SNSD records is performed by the same register_node.
108
+The hash_node which receives the registration won't contact the counter_node,
109
+because the hostname is already registered and it doesn't need to verify
110
+anything about it. It has only to check the validity of the signature.
111
+
112
+The register node can also choose to use an optional SNSD feature to be sure
113
+that a SNSD hostname is always associated to its trusted machine. In this
114
+case, the register_node needs the ANDNA pubkey of the SNSD node to send a
115
+periodical challenge to the node.
116
+If the node fails to reply, the register_node will send to ANDNA a delete
117
+request for the relative SNSD record.
118
+
119
+The registration of SNSD records of hostnames which are only queued in the
120
+andna_queue is discarded.
121
+
122
+Practically, the steps necessary to register a SNSD record are:
123
+ * Modify the /etc/netsukuku/snsd_nodes file.
124
+{{{
125
+register_node# cd /etc/netsukuku/ 
126
+register_node# cat snsd_nodes
127
+#
128
+# SNSD nodes file
129
+#
130
+# The format is:
131
+# hostname:snsd_hostname:service:priority:weight[:pub_key_file]
132
+# or
133
+# hostname:snsd_ip:service:priority:weight[:pub_key_file]
134
+#
135
+# The `pub_key_file' parameter is optional. If you specify it, NetsukukuD will
136
+# check periodically `snsd_hostname' and it will verify if it is always the
137
+# same machine. If it isn't, the relative snsd will be deleted.
138
+#
139
+
140
+depausceve:pippo:http:1
141
+depausceve:1.2.3.4:21:0
142
+
143
+angelica:frenzu:ssh:1:/etc/netsukuku/snsd/frenzu.pubk
144
+
145
+register_node#
146
+register_node# scp frenzu:/usr/share/andna_lcl_keyring snsd/frenzu.pubk
147
+}}}
148
+ * Send a SIGHUP to the NetsukukuD of the register node:
149
+{{{
150
+register_node# killall -HUP ntkd
151
+# or, alternatively
152
+register_node# rc.ntk reload
153
+}}}
154
+
155
+==== Zero SNSD IP ====
156
+
157
+The main IP associated to a normal hostname has these default values:
158
+{{{
159
+IP	 = register_node IP	# This value can't be changed
160
+service  = 0
161
+priority = 16
162
+weight   = 1
163
+}}}
164
+
165
+It is possible to associate other SNSD records in the service 0, but it isn't
166
+allowed to change the main IP. The main IP can only be the IP of the
167
+register_node.
168
+Although it isn't possible to set a different association for the main IP, it
169
+can be disabled by setting its weight number to 0.
170
+
171
+The string used to change the priority and weight value of the main IP is:
172
+{{{
173
+hostname:hostname:0:priority:weight
174
+
175
+# For example:
176
+register_node# echo depausceve:depausceve:0:23:12 >> /etc/netsukuku/snsd_nodes
177
+}}}
178
+
179
+
180
+==== SNSD chain ====
181
+
182
+Since it is possible to assign different aliases and backup IPs to the zero
183
+record, there is the possibility to create a SNSD chain.
184
+For example:
185
+
186
+{{{
187
+depausceve registers: depausceve:80 --> pippo
188
+pippo registers:      pippo:0  --> frenzu
189
+frenzu registers:     frenzu:0 --> angelica
190
+}}}
191
+
192
+However the SNSD chains are ignored, only the first resolution is considered
193
+valid. Since in the zero service there's always the main IP, the resolution is
194
+always performed.
195
+In this case ("depausceve:80 --> pippo:0") the resolution will return the main
196
+IP of "pippo:0".
197
+
198
+The reply to a resolution request of service zero, returns always IPs and not
199
+hostnames.
200
+
201
+----
202
+
203
+related: ["Netsukuku RFC"]

+ 436
- 0
doc/main_doc/ntk_rfc/Ntk_andna_and_dns View File

@@ -0,0 +1,436 @@
1
+{{{
2
+
3
+
4
+
5
+                        ANDNS PROTOCOL
6
+
7
+INDEX:
8
+
9
+0 - Introduction
10
+1 - Notations
11
+2 - Packet Headers
12
+3 - Query Type
13
+4 - Query Realm
14
+5 - Rcode
15
+6 - Questions
16
+7 - Answers
17
+8 - Compression
18
+
19
+
20
+0. - INTRODUCTION -
21
+
22
+   This document describes the protocol used to communicate with ANDNA.
23
+   This protocol is used also to make query in internet realm.
24
+   So, we can query for `google.it` in internet, or for `depausceve`
25
+   in the netsukuku net.
26
+
27
+   In the case of internet queries, the dns_wrapper will contact the
28
+   dns-servers specified in /etc/resolv.conf when ntkd is loaded.
29
+
30
+1. - NOTATIONS -
31
+
32
+   In the next section, we represent a byte with this graphic:
33
+
34
+         1  2  3  4  5  6  7  8
35
+        +--+--+--+--+--+--+--+--+
36
+        |                       |
37
+        +--+--+--+--+--+--+--+--+
38
+
39
+   The numbers represent the bits
40
+   Let's show two bytes:
41
+
42
+         1  2  3  4  5  6  7  8  1  2  3  4  5  6  7  8
43
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
44
+        |                       |                       |
45
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
46
+
47
+2. - HEADERS -
48
+
49
+  Headers are 4-byte long, and the format is:
50
+
51
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
52
+        |                      ID                    | R|
53
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
54
+        |QR| P| Z| QT  |  ANCOUNT  |I |   NK|   RCODE   |
55
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
56
+
57
+  where:
58
+
59
+        ID      =  It's a 2-byte value which identifies the query.
60
+                   ID is choosed in a random way and the future
61
+                   answers must have the same ID.
62
+	
63
+	R	=  Recursion bit. If set, SNSD queries that have
64
+		   a hostname as resolution will be resolved (if
65
+		   possible).
66
+
67
+        QR      =  0 implies that this packet contains a question
68
+                   1 if the packets contains answers
69
+
70
+        P       =  If the query is h2ip and ntk-related, P specifies
71
+                   the protocol service:
72
+                   0 for TCP
73
+                   1 for UDP
74
+                   P has to be zero otherwise.
75
+	
76
+	Z	= zlib compression. If z=1, the packet contents, 
77
+		  headers excluded, are zlib-compressed. See
78
+		  Section 8.
79
+
80
+        QT      = Query Type. See below.
81
+                  Note: answers must leave this field unchanged.
82
+
83
+        ANCOUNT = Answer Count. This field is set only if QR=1,
84
+                  ie if this packet contains answers.
85
+                  ANCOUNT is the number of answers which belongs
86
+                  to this packet.
87
+
88
+        I       = Ip-version bit. Specifies the ip version for the
89
+                  packet contents. All addresses contained in the 
90
+                  packet are:
91
+                  if I==0    IPv4 addresses (4-bytes)
92
+                  if I==1    Ipv6 addresses (16-bytes)
93
+                  This bit is useful only for questions. The server 
94
+                  will reply "NO SUCH DOMAIN" if his node is running
95
+                  with a different ip-version.
96
+                  Otherwise, only IPs of the same family will be 
97
+                  returned.
98
+                  
99
+        NK      = Netsukuku bit. With this field, you can specify
100
+                  the query realm.
101
+                  If NK=1, the realm is netsukuku.
102
+                  If NK=2, the realm is internet.
103
+                  If NK=0, the packet is not encoded with this
104
+                  protocol, but with standard DNS protocol.
105
+                  To specify realms with DNS protocol, see below.
106
+                  Note: answers must leave this field unchanged.
107
+
108
+        RCODE   = This is the result of a query.
109
+                  RCODE has to be 0 if this packet contains a
110
+                  question.
111
+                  In the case of errors, ANCOUNT has to be 0.
112
+
113
+3. - QUERY TYPE -
114
+
115
+  There are different kind of questions:
116
+
117
+  QTYPE = 0
118
+        This is the classic resolution `hostname -> ip`.
119
+        A gethostbyname.
120
+        Note: this type of query is used also for SNSD
121
+        resolution (see `NTK_RFC 0009`).
122
+        You can specify a service.
123
+        So, the general way to represent this query is:
124
+
125
+                hostname:service -> ip
126
+
127
+        If you don't specify a service, the 0-service
128
+        will be used.
129
+
130
+        Example: if you want to discover which address is
131
+        hosting the http service of hostname `depausceve`,
132
+        you have to formule this query:
133
+
134
+                depausceve:80
135
+
136
+        See below how to formule queries.
137
+
138
+  QTYPE = 1
139
+        This is a reverse resolution: `ip -> host`.
140
+
141
+  QTYPE =2
142
+  	This is a global query: all services for the
143
+	hostname will be answered.
144
+	The query realm has to be Ntk.
145
+
146
+4. - QUERY REALMS -
147
+
148
+  A query can be formulated to find some object in the
149
+  netsukuku net or in internet.
150
+  Maybe you want to know the ip of `google.it`, but you
151
+  have to specify where: internet or netsukuku?
152
+
153
+  If you use ANDNS protocol, you specify this with NK
154
+  bit (See the HEADERS SECTION).
155
+
156
+  If you use DNS protocol, you have to formule the query
157
+  with some suffix: if you ask for `google.it.int` (or
158
+  google.it.INT), the question is made in internet.
159
+  If you ask for `google.it.ntk` (or `google.it.NTK)
160
+  the question is made in netsukuku.
161
+  If you don't specify any suffix, the default realm
162
+  is Netsukuku Realm
163
+
164
+  The dns_wrapper first search for a suffix, understanding
165
+  the correct realm.
166
+  If the question does not have any suffix, the query
167
+  will be made in the default realm.
168
+  Otherwise, dns_wrapper removes this suffix and
169
+  resolves the query without it.
170
+
171
+5. - RCODE -
172
+
173
+  This is the answer report.
174
+  It's always 0 if the packet carries a question.
175
+  Possible values, in the case of an answer, are:
176
+
177
+   RCODE = 0 No Error.
178
+        This answer contains answers.
179
+        The number of ANSWERS is ANCOUNT (see
180
+        HEADERS SECTION).
181
+
182
+   RCODE = 1 Interpretation Error.
183
+        The server did not understand your query.
184
+        In other words, your question is malformed.
185
+
186
+   RCODE = 2 Server Fail.
187
+        The server did encounter some error processing
188
+        your question. Your question is good.
189
+
190
+   RCODE = 3 No Such Domain
191
+        The object of your question does not exist.
192
+
193
+   RCODE = 4 Not Implemented
194
+        This type of query is not implemented yet
195
+        in this server.
196
+
197
+   RCODE = 5 Refused
198
+        The server refuse to talk with you.
199
+
200
+  Note: this expression is always true:
201
+
202
+                (RCODE XOR ANCOUNT)
203
+
204
+  ie, if RCODE contains some error (RCODE!=0), there is
205
+  not answer in this packet. If RCODE is 0 (no error),
206
+  the packet contains some answer.
207
+
208
+6. - QUESTIONS -
209
+
210
+  We have to switch the value QTYPE against realm.
211
+
212
+  - Case QTYPE = 0 (h2ip) AND Realm=NTK
213
+    The format of the question is:
214
+
215
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
216
+        |                    SERVICE                    |
217
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
218
+        |                                               |       
219
+        |                                               |       
220
+        |                                               |
221
+        |                   HOSTNAME                    |
222
+        |                     HASH                      |
223
+        |                     (HH)                      |
224
+        |                                               |
225
+        |                                               |
226
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
227
+
228
+    where:
229
+
230
+     SERVICE is a 2-byte field and represents the SNSD service
231
+     value (see `NTK_RFC 0009`).
232
+
233
+     HH is the 16-bytes hostname hash.
234
+
235
+  - Case QTYPE = 0 (h2ip) AND Realm=INET
236
+    The format of the question is:
237
+
238
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
239
+        |                   SERVICE                     |
240
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
241
+        |                   RDLENGTH                    |
242
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
243
+        |                                               |
244
+        \                                               \
245
+        \                    RDATA                      \
246
+        |                                               |
247
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
248
+
249
+    where:
250
+
251
+     SERVICE is a 2-byte field and represents the SNSD service
252
+     value (see `NTK_RFC 0009`). At this moment, for INET 
253
+     resolutions, the service is limited to value 25 
254
+     - TCP is assumed - or 0.
255
+
256
+     RDLENGTH is the RDATA len
257
+
258
+     RDATA is a hostname string, such that:
259
+                 strlen(RDATA)=RDLENGTH
260
+
261
+  - Case QTYPE = 1 (ip2h).
262
+    The format of the question is:
263
+
264
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
265
+        |                                               |
266
+        /                     RDATA                     /
267
+        /                                               /
268
+        |                                               |
269
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
270
+
271
+    where:
272
+
273
+     RDATA is an IP in the binary format.
274
+     The length of the field - ie the family address (4 or 6) -
275
+     depends on the bit `I' in the headers section. 
276
+   
277
+  - Case QTYPE = 2 (global query).
278
+    The format of the question is:
279
+
280
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
281
+        |                                               |       
282
+        |                                               |       
283
+        |                                               |
284
+        |                   HOSTNAME                    |
285
+        |                     HASH                      |
286
+        |                     (HH)                      |
287
+        |                                               |
288
+        |                                               |
289
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
290
+
291
+    where:
292
+
293
+     HH is the 16-bytes hostname hash.
294
+
295
+7. - ANSWERS -
296
+
297
+  The format of answers is:
298
+
299
+  CASE QTYPE=0    (h2ip)   
300
+
301
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
302
+        |  | T|     WG          |       PRIO            |
303
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
304
+        |                                               |
305
+        /                     RDATA                     /
306
+        /                                               /
307
+        |                                               |
308
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
309
+
310
+   where:
311
+    
312
+   T is set if this answer carries an IP.
313
+   T is 0 if the answer carries a hostname hash.
314
+     
315
+   WG is the weigth of an answer (see `NTK_RFC 0009`)
316
+
317
+   PRIO the priority (see `NTK_RFC 0009`)
318
+
319
+   RDATA is a binary ip address (His family (and his length) is specified
320
+         in the headers bit `I') or a hostname hash).
321
+
322
+  CASE QTYPE=1   (ip2h)
323
+
324
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
325
+        |                    RDLENGTH                   |
326
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
327
+        |                                               |
328
+        /                     RDATA                     /
329
+        /                                               /
330
+        |                                               |
331
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
332
+
333
+   where:
334
+
335
+   RDLENGTH is the strlen of RDATA (RDATA is a hostname).
336
+
337
+   RDATA the hostname resolution.
338
+
339
+  CASE QTYPE=2   (global query)
340
+
341
+   If QTYPE=2, there is a extra header field before answers:
342
+
343
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
344
+        |                    ANCOUNT                    |
345
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
346
+
347
+   The two bytes are the number of answers that the query
348
+   produced. After the two bytes.
349
+
350
+   Note: the ANCOUNT field on main headers has to be 1 if
351
+   RCODE=0, 0 otherwise.
352
+   The two extra bytes are the real number of answers in the
353
+   case of QTYPE=2.
354
+
355
+   After the two bytes, this is the format for each answer:
356
+	
357
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
358
+        | M| T| P|  WG          |       PRIO            |
359
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
360
+        |                    SERVICE                    |
361
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
362
+        |                                               |
363
+        /                     DATA                      /
364
+        /                                               /
365
+        |                                               |
366
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
367
+
368
+   where T is the type of the DATA.
369
+   T is:
370
+   	T = 0	Hostname
371
+	T = 1 	Ip
372
+
373
+   M is set if T is set, and specifies that this is the MAIN_IP
374
+   of the hostname.
375
+
376
+   P is The protocol: Tcp if 0, UDP if 1.
377
+   
378
+   If T=1, the ip version is specified in main headers, in the
379
+   field I.
380
+   If T=0, the format of data is:
381
+
382
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
383
+        |                                               |       
384
+        |                                               |       
385
+        |                                               |
386
+        |                   HOSTNAME                    |
387
+        |                     HASH                      |
388
+        |                     (HH)                      |
389
+        |                                               |
390
+        |                                               |
391
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
392
+
393
+   where HH is the 16 bytes hash of SNSD hostname.
394
+
395
+   If T=1, the format of data is:
396
+
397
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
398
+        |                                               |
399
+        /                    RDATA                      /
400
+        /                                               /
401
+        |                                               |
402
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
403
+
404
+   where RDATA is the binary IP and the length of his contents
405
+   depends on the field I of main headers (4 in IPv4, 16 in IPv6).
406
+
407
+   
408
+8. - COMPRESSION -
409
+
410
+  The format of a compressed packet is:
411
+
412
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
413
+        |                      ID                    | R|
414
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
415
+        |QR| P| Z| QT  |  ANCOUNT  |I |   NK|   RCODE   |
416
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
417
+        |                                               |
418
+        |                     USIZE                     |
419
+        |                                               |
420
+        |                                               |
421
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
422
+        |                                               |
423
+        /                     DATA                      /
424
+        /                                               /
425
+        |                                               |
426
+        +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
427
+
428
+  Headers remain uncompressed. The packet contents, question and
429
+  answers, are compressed with zlib. The buffer obtained with the
430
+  compression is DATA.
431
+  USIZE is the original size of packet contents (question and 
432
+  answers). 
433
+  If a packet is compressed, then Z=1.
434
+	
435
+}}}
436
+

+ 38
- 0
doc/main_doc/ntk_rfc/Ntk_andna_counter_pubk View File

@@ -0,0 +1,38 @@
1
+== NTK_RFC 0007 ==
2
+
3
+
4
+Subject: ANDNA counter system based on public key
5
+
6
+----
7
+This text describes a change to the counter_gnode system in ANDNA.
8
+It will be included in the final documentation, so feel free to correct it.
9
+But if you want to change the system here described, please contact us first.
10
+----
11
+
12
+{{{
13
+The counter_gnode is used to prevent massive registrations of hnames by a
14
+single node, however there is a bug in the actual protocol.
15
+
16
+Currently the IP of the counter_gnode is the hash of the public key of the
17
+register node.
18
+
19
+The public key is part of the key pair used by the register_node to register
20
+and update its hnames, therefore there should be only one key pair for each
21
+node.
22
+
23
+However, nothing prevents the register node to create multiple key pairs,
24
+modify the ntkd code and use them at the same time. 
25
+With this technique, the register node can have a new counter_gnode for each
26
+new generated key pair, avoiding in this way the registration limit.
27
+
28
+The solution is to calculate the IP of the counter_gnode using the hash of the
29
+IP of the register_node. This method was previously proposed but it was
30
+discarded because every time the register_node changes IP it will have a new
31
+counter_gnode. The new counter_gnode cannot know how many hnames the
32
+register_node registered before so it will accept all the new requests, but in
33
+reality, this is not a problem, in fact, the new counter_gnode can accept only
34
+256 hnames, thus the limit is maintained.
35
+}}}
36
+
37
+----
38
+related: ["Netsukuku RFC"]

+ 121
- 0
doc/main_doc/ntk_rfc/Ntk_bandwidth_measurement View File

@@ -0,0 +1,121 @@
1
+== NTK_RFC 0002 ==
2
+
3
+Subject: bandwidth measurement
4
+
5
+----
6
+This text describes a change to the Npv7.
7
+It will be included in the final documentation, so feel free to correct it.
8
+But if you want to change the system here described, please contact us first.
9
+----
10
+
11
+== Link measurement issues ==
12
+
13
+In the current version of the Npv7 the link quality is measured only with the
14
+rtt and packets loss, so only the lantecy is actually considered, this isn't
15
+optimal since also a link with a bandwidth of 20000 bps can have a good
16
+lantecy.
17
+It isn't a critical problem since more than one route is used to reach a
18
+single dst_node, so when a route is satured the kernel will use another one
19
+looking in the nexthop table of that route.
20
+
21
+== Improvement ==
22
+
23
+In order to improve the link measurement a node must include in the tracer
24
+pkts the available bandwidth of its traversed link.
25
+The link bandwidth, which will be used to modify the real rtt, in this way it
26
+will be possible to have a traffic shaping based also on the real bandwidth of
27
+the links.
28
+
29
+== Bandwidth measurement ==
30
+
31
+There are two phases of measurement: in the first the total bandwidth of the
32
+new links is measured by the hooking node and the destination nodes, in the
33
+second the bandwidth of the links is constantly monitored.
34
+
35
+The utilised bandwidth will be monitored with iptables and the libiptc library.
36
+See http://www.tldp.org/HOWTO/Querying-libiptc-HOWTO/bmeter.html .
37
+
38
+We also need to know the total bandwidth which can handle the network
39
+interface. What is a good method to do this?
40
+
41
+=== Total available bandwidth ===
42
+
43
+{{{
44
+	A  <->  B  <->  C
45
+}}}
46
+
47
+The node B is hooking to A and C. At the end of the hook, B measures the
48
+total available bandwidth of the links B<->C and B<->A.
49
+It sends an indefinite amount of random packets, for some seconds, to the
50
+destination of the link. The link is monitored with libiptc and the maximum
51
+rate of bytes per second is registered as the maximum available upload
52
+bandwidth for that specific link. These steps are repeated for each rnode.
53
+Since the link might be asymettric the measurement is also repeated by A and
54
+C. In the end we have the measurement of: A->B, B->A, C->B, B->C.
55
+
56
+=== Realtime bandwidth monitoring ===
57
+
58
+With the use of the libiptc library, B can monitor the bandwidth usage of its
59
+links.
60
+
61
+{{{
62
+Max_link_bw	= Total available bandwidth of the link
63
+free_link_bw 	= available/not used bandwidth of the link
64
+cur_used_link_bw= amount of bandwidth currently used
65
+
66
+Max_NIC_bw	= maximum bandwidth of the network interface
67
+cur_used_NIC_bw = amount of the total bandwidth currently used of the network
68
+		  interface
69
+}}}
70
+
71
+To calculate the `free_link_bw':
72
+{{{
73
+free_link_bw = Max_link_bw - cur_used_link_bw
74
+if(free_link_bw > Max_NIC_bw - cur_used_NIC_bw)
75
+	free_link_bw = (Max_NIC_bw - cur_used_NIC_bw);
76
+}}}
77
+The `free_link_bw' value will be used to modify the `rtt' used to sort the
78
+routes in the routing table.
79
+{{{
80
+modified_rtt(free_link_bw, real_rtt) = 27<<27 + real_rtt - bandwidth_in_8bit(free_link_bw)
81
+
82
+real_rtt must be <= 2^32-27<<27-1 (about 8 days)
83
+
84
+You can find the definition of bandwidth_in_8bit() here:
85
+http://hinezumilabs.org/cgi-bin/viewcvs.cgi/netsukuku/src/igs.c?rev=HEAD&content-type=text/vnd.viewcvs-markup
86
+}}}
87
+
88
+== Latency VS bandwidth ==
89
+
90
+It may also happens that a link has a good bandwidth but a high latency.
91
+A low latency is needed by semi-realtime applications: for a ssh connection
92
+we don't care to have a 100Mbs connection but we want to use the shell in
93
+realtime, so when we type a command we get a fast response.
94
+
95
+The Netsukuku should create three different routing tables:
96
+ * the first shall include the routes formed by the links with the best bandwidth value.
97
+ * the second shall include the "best latency" routes
98
+ * the routes in the third table shall be an average of the first and the second tables
99
+
100
+If the protocol of the application uses the "tos" value in its IP packets, it
101
+is possible to add a routing rule and choose the right table for that
102
+protocol: the ssh protocol will be routed by the second table.
103
+
104
+== Caveats ==
105
+
106
+If the libiptc are used, it will be more difficult to port the daemon for
107
+other kernels than Linux. Libpcap is a good alternative.
108
+It is possible to capture the packets for some seconds using libpcap, count
109
+them and find how much bandwidth is used.
110
+
111
+== IGS ==
112
+
113
+The inet-gw which share their internet connection measure also the utilzed
114
+bandwidth of the Internet connection. 
115
+The maximum download and upload bandwidth is known since it must be specified
116
+by the user in the netsukuku.conf config file. In this way, monitoring the
117
+device used by the Internet default route, it's trivial to known the
118
+available bandwidth.
119
+
120
+----
121
+related: [Netsukuku_RFC]

+ 198
- 0
doc/main_doc/ntk_rfc/Ntk_gnodes_contiguity View File

@@ -0,0 +1,198 @@
1
+= NTK_RFC 0001 =
2
+
3
+Subject: Gnode contiguity
4
+
5
+----
6
+This text describes a change to the Npv7 about the collision of IPs.
7
+It will be included in the final documentation, so feel free to correct it.
8
+But if you want to change the system here described, please contact us first.
9
+----
10
+
11
+= The real problems =
12
+
13
+A collision of IPs happens when two gnodes with the same ID are born separately,
14
+so when they meet each trough a direct link or trough other nodes many
15
+problems arise since there are some ambiguities:
16
+
17
+ * In the first case there can be nodes which have the same IP.
18
+
19
+ * In the second:
20
+		A <-> B <-> D <-> A
21
+  After a qspn_round the node B will have two routes to reach the gnode A. But in this case the gnode A isn't a contiguous gnode, so when B wants to reach a node which belongs to A, it will send the packet using only one route which may lead to the A gnode which hasn't the wanted node.
22
+	  
23
+So these are the real problems.
24
+In order to solve them it is necessary that every time two gnodes meets each
25
+other for the first time, one of them will redo the hook, in fact, this was
26
+the cause of all. 
27
+When a gnode meets for the first time another gnode is like when a new node joins
28
+the network: it hooks with the other nodes. The same must be done for the
29
+gnode.
30
+
31
+= Hook of gnodes =
32
+
33
+The hook of two gnodes works in this way: only the gnode which has less
34
+nodes than the other will change (let's call the first gnode X and the second
35
+Y). If X and Y have the same number of nodes, the gnode which has the smaller
36
+gnode_id will change.
37
+The bnodes of X will start to re-hook, the other nodes will re-hook when
38
+they notice that a new rnode which belongs to Y comes up. 
39
+Summing up: the bnodes re-hook first, then their rnodes, then the rnodes of
40
+the rnodes of the bnodes... and so on, all the nodes of the gnode have
41
+re-hooked.
42
+
43
+It doesn't matter that a gnode composed by 2^24 nodes changes all its IPs,
44
+since it will happen only very few times, i.e. when the gnode of the Europe
45
+meets that of the America.
46
+
47
+== Gnode count ==
48
+
49
+This method requires that the number of nodes present in a gnode has to be
50
+known, therefore the qspn_pkt which traverse gnodes stores also the number
51
+of nodes of each traversed gnode.
52
+
53
+== No first tracer_pkt ==
54
+
55
+While re-hooking, the first tracer_pkt won't be sent like in the normal hook
56
+'cause if all the nodes of the gnode which is re-hooking send it, there
57
+would be a broadcast pkt for each node. The next qspn_round will let
58
+the other know the routes to reach them.
59
+
60
+== Re-hook of two equal, not contiguous gnodes ==
61
+
62
+When there are two nodes with the same ip, or gnodes with the
63
+same gid, one of them will re-hook, following the same rules we've described,
64
+but all the packets that the two (g)nodes will send each other will be routed
65
+by the daemons. For example if A wants to send a packet to A' it stores in the
66
+pkt the route it received with the last qspn_pkt, the other nodes will forward
67
+the packet to A' using that route, this is to avoid the problem described
68
+above.
69
+
70
+== Re-hook details ==
71
+
72
+The gnode X is re-hooking at the gnode Y.
73
+
74
+If the gnode Y hasn't enough free nodes for all the nodes of the
75
+gnode X then the situation evolves in this way:
76
+	maxYnodes = maxmimum number of nodes in Y;
77
+	curYnodes = current number of nodes in Y (gnode count of Y).
78
+	
79
+	diff = maxYnodes - curYnodes;
80
+
81
+`diff' is the number of new nodes which the gnode Y can accept inside.
82
+The bnodes of X will say to `diff'# nodes in X to re-hook in the gnode Y, all
83
+the other non-informed nodes will create a new gnode.
84
+
85
+Let's analyse the two cases.
86
+
87
+=== informed nodes ===
88
+
89
+Remembering how the nodes re-hook (first the bnode, then its rnodes, then the
90
+rnodes of its rnodes, etc..) we adopt this strategy:
91
+
92
+	join_rate=diff/number_of_X_bnodes - 1;
93
+	
94
+Each bnode of X knows it can inform `join_rate'# nodes, so when its
95
+rnodes try to re-hook at it, they'll know that:
96
+
97
+ * they will become part of the gnode Y
98
+ * they can inform other `(join_rate-1)/(number_of_links-1)'# nodes
99
+
100
+The same procedure holds for recursively the rnodes of the rnodes of the
101
+bnode.
102
+
103
+When `join_rate' becomes zero the node becomes non-informed.
104
+
105
+=== non-informed nodes ===
106
+
107
+The gid of the new gnode they create is based on the hash of their previous
108
+gid. In this way all the non-informed nodes will be in the same new gnode,
109
+cause they all generates the same hash. If the new gid is already taken in the
110
+map they'll increment it by one until they choose a non-taken gnode.
111
+
112
+== Counting the nodes ==
113
+
114
+At this point all seems to be solved, but it is not.
115
+Anyone can modify the qspn, so for example the X which has less nodes than Y
116
+can fake the number, and Y will be forced to re-hook.
117
+It this happens anyone can easily force a gnode of 2^24 nodes to change its
118
+IPs!
119
+Therefore the problem to be solved now is: how can the gnode Y verify that the
120
+gnode X has really more nodes?
121
+
122
+What is the main property of a network which has more nodes than another?
123
+The computability power!
124
+
125
+We assume that the average computability power for a gnode of the second level
126
+or greater is constant. (a gnode of the second level can have 2^16 nodes, in the
127
+third level 2^24). Therefore the gnode of level 1 won't be checked.
128
+
129
+Each node of the gnode which has to re-hook (in this case the gnode Y,
130
+since the gnode X is faking the qspn_pkt) will send a problem to solve to the
131
+other gnode and it wait for a very small time the reply with the solution in
132
+it. If the solution is right the node receiving it will re-hook, otherwise
133
+the gnode X will be banned and excluded from all the qspn floods.
134
+Only one challenge each T time can occur, where T is proportional to the size
135
+of the Y gnode. So say that Y has 16milions IPs, if it has already sent a
136
+challenge it will send another after 10 minutes.
137
+
138
+== Computability power ==
139
+
140
+But this system leaves opened another kind of attack: the gnode X can target a single
141
+node in Y, replying only to its reply and making it re-hook. In order to
142
+prevent this the nodes act in this way:
143
+
144
+ * When a node hooks it creates a RSA key pair, then its rnodes get its public key.
145
+
146
+ * When a node receives a reply to the problem, it broadcasts the reply inside its gnode,
147
+signing it with its public key. When its rnodes receive the pkt, check the signature. 
148
+If it is valid they update the counter of received replies for the problems sent, then 
149
+they substitute the signature with their own. The packet will propagate
150
+until it reaches all the nodes of the gnode.
151
+
152
+ * The nodes will start to rehook only when all the replies will be
153
+received (during the wait time). Since it is not possible that all the reply are 
154
+received it is allowed that 10% of replies are lost.
155
+	
156
+The problem to solve sent by the nodes is:
157
+		f(x) mod k
158
+where k is a random number between 2^16  and  2^32.
159
+
160
+f(x) is a function which is not easily computable with mod k.
161
+When x gets bigger the computation time increases.
162
+We are still deciding on what f() function using.
163
+
164
+=== Dumb machines ===
165
+
166
+Generating the problem doesn't require a high computability power, in
167
+fact, the daemon will keep 8 or 16 problems cached, generated while the cpu
168
+isn't used.
169
+
170
+The machines which have a very low computability power won't reply and even
171
+try to solve the problems they receive (but only if they can't take the
172
+computability of the problem).
173
+
174
+= ANDNA changes =
175
+
176
+If a same hostname is registered in two separeted gnodes what happens when they meet?
177
+Which node will mantain the hostname?
178
+
179
+The node which is in the greater gnode wins: the hash_nodes of the smaller
180
+gnode, which re-hooks, will reset their uptime counter, in this way when they
181
+receive the update request from the node (which has changed its IP and must
182
+update its hname), they ask to the other gnode for the old andna_caches.
183
+
184
+Moreover the ANDNA_MIN_UPDATE_TIME (the minum amount of time to be waited
185
+before sending an update os the hname) has to be reduced to
186
+NEW_HOOK_WAIT_TIME, which is the minimum amount of time to be waited before
187
+re-hooking. This is necessary, because all the hname updates sent 
188
+before ANDNA_MIN_UPDATE_TIME seconds have elapsed since the last update 
189
+rejected. If a gnode re-hooked, the hostname of its nodes has to be
190
+updated, therefore the update request must be accepted.
191
+
192
+= And that's all =
193
+
194
+That's all folks.
195
+
196
+Alpt, Katolaz, Mancausoft, Uscinziatu
197
+----
198
+related: [Netsukuku_RFC]

+ 46
- 0
doc/main_doc/ntk_rfc/Ntk_life_probability View File

@@ -0,0 +1,46 @@
1
+== NTK_RFC 0005 ==
2
+
3
+Subject: Life probability 
4
+
5
+----
6
+This text describes a change to the Npv7.
7
+It will be included in the final documentation, so feel free to correct it.
8
+But if you want to change the system here described, please contact us first.
9
+----
10
+
11
+Statistically the probability of a node to continue to stay up is related to
12
+its uptime, for example if the node X has an uptime of 30 seconds and the node Y of
13
+1200 seconds, then it is more probable that the node Y will continue to stay
14
+up.
15
+
16
+For this reason we give higher credits to older nodes/gnodes, this means that
17
+in a multipath route we prefer to don't use very young nodes as main gateways.
18
+
19
+{{{
20
+		A
21
+	       / \
22
+	      L   K
23
+	       \ /
24
+                N
25
+}}}
26
+
27
+Let's say K has an uptime of 600 seconds and L of 200.
28
+The node N, to reach A, will prefer the node K.
29
+
30
+=== Implementation ===
31
+
32
+In order to implement this we penalize the new nodes/gnodes by increasing
33
+their rtt, in this way they will be considered as slow links.
34
+
35
+We can do this only for new nodes/gnodes 'cause we cannot trust the uptime
36
+value given by a node, but we can know for sure if that node is completely
37
+new.
38
+
39
+When the next qspn_round updates the routes the penality is removed.
40
+
41
+Another system would be counting the number of qspn_rounds the nodes took part
42
+in.
43
+If it has only partecipated in < 3 rounds it is considered young.
44
+
45
+----
46
+related: [Netsukuku_RFC]

+ 64
- 0
doc/main_doc/ntk_rfc/Ntk_restricted_ip_classes View File

@@ -0,0 +1,64 @@
1
+== NTK_RFC 0008 ==
2
+
3
+Subject: Private IP classes in restricted mode
4
+
5
+----
6
+This text describes a change to the Npv7.
7
+It will be included in the final documentation, so feel free to correct it.
8
+But if you want to change the system here described, please contact us first.
9
+----
10
+
11
+The user can decide to use, in restricted mode, a different private IP
12
+class from the default one ( 10.x.x.x ). This is useful if the 10.x.x.x class
13
+cannot be used, for example in Russia, it is very popular to provide Internet
14
+access through big LANs which use the 10.x.x.x class.
15
+
16
+The other available classes are:
17
+{{{
18
+172.16.0.0  - 172.31.255.255    = 16*2^16 = 1048576 IPs
19
+192.168.0.0 - 192.168.255.255   =    2^16 = 65536   IPs
20
+}}}
21
+
22
+The 192.168.x.x class cannot be used as an alternate restricted mode IP class
23
+because it is the default Netsukuku private class, thus the only alternative
24
+to 10.x.x.x is the "172.16.0.0 - 172.31.255.255" IP class.
25
+However it is adviced to always use the default class.
26
+
27
+== Netsukuku private classes ==
28
+
29
+It necessary to provide at least one private IP class inside Netsukuku to
30
+allow the creation of private LANs which are connected to Netsukuku with just
31
+one node.
32
+
33
+The default Netsukuku private class is 192.168.x.x.
34
+The random IPs choosen by the nodes will be never one of that class.
35
+The default private class is valid both in normal and restricted mode.
36
+
37
+Only in normal mode the "172.16.0.0 - 172.31.255.255" class becomes private.
38
+This class is assigned to very large private networks.
39
+
40
+The 10.x.x.x class IS NOT private since it is too big and it would be just a
41
+waste of IP addresses to use it as a private class.
42
+Note also that for each Netsukuku node you can have a private network,
43
+therefore with just 16 Netsukuku nodes you can form a private network of
44
+16777216 nodes, which is equivalent to a 10.x.x.x class.
45
+
46
+== Notes on the restricted mode ==
47
+
48
+A node which runs in restricted mode cannot be compatible with normal mode
49
+nodes, for this reason a restricted node will drop any packets coming from a
50
+normal node.
51
+
52
+While in restricted mode the "172.16.0.0 - 172.31.255.255" class IS NOT
53
+private.
54
+
55
+In restricted mode, when two different networks which use different
56
+private classes (say 10.x.x.x and 192.168.x.x) are linked, nothing happens and
57
+they will not rehook, this is necessary because it's assumed that the specified
58
+private class is the only choice the user can utilize.
59
+This leds to some problems, consider this scenario:
60
+{{{
61
+		10.0.0.0 <-> 172.16.0.0
62
+}}}
63
+In this case the rehook isn't launched, so it is possible that there will be a
64
+lot of collision.

+ 193
- 0
doc/main_doc/ntk_rfc/Ntk_viphilama View File

@@ -0,0 +1,193 @@
1
+== NTK_RFC 0010 ==
2
+
3
+Subject: Viphilama - Virtual to Physical Layer Mapper
4
+
5
+----
6
+This text describes a change to the Npv7.
7
+It will be included in the final documentation, so feel free to correct it.
8
+But if you want to change the system here described, please contact us first.
9
+----
10
+
11
+
12
+=== Viphilama ===
13
+
14
+Viphilama will permit to Netsukuku to expand itself over the Internet and then
15
+switching automatically to the physical layer without interfering with the
16
+stability of the Net.
17
+The theory of Viphilama isn't complete yet. This document, right now, is just
18
+a description of what it would be.
19
+
20
+=== Layer ===
21
+
22
+Netsukuku will be split in two layer: the virtual layer and the physical one.
23
+
24
+==== The physical layer ====
25
+
26
+This is the original Netsukuku layer: every node is linked to other nodes by
27
+physical links (wifi, cables, ...).
28
+The physical layer is prioritised over the virtual one.
29
+
30
+==== The virtual layer ====
31
+
32
+The virtual layer is built upon the Internet or any other existing network.
33
+The Netsukuku nodes, in this layer, are linked each other by tunnels.
34
+
35
+A node, in order to join in the virtual layer, has to know its physical
36
+coordinates. 
37
+The use of geographical coordinates is required for Viphilama, because it has
38
+to map the virtual layer to the physical one and it needs a way to measure
39
+the effective distance between two virtual nodes.
40
+
41
+The coordinates can be retrieved using an online map service like
42
+http://maps.google.com or with a GPS.
43
+
44
+The coordinates are stored in the internal, external and bnode maps. 
45
+In the internal map there are the coordinates of each single node.
46
+In the external maps, the coordinates which locate a gnode are set to its
47
+barycenter: it is the average of the coordinates of all its internal nodes.
48
+
49
+==== Gate node ====
50
+
51
+The two layers are joined by the gate nodes. They are nodes which belong to
52
+both layers.
53
+This means that the two layer form a unique network.
54
+
55
+
56
+=== Virtual to Physical mapper ===
57
+
58
+The mapper does a basic job: whenever it finds that a virtual link can be
59
+replaced by a physical one, it removes the virtual link.
60
+
61
+Assume this scenario:
62
+
63
+{{{
64
+	Tokyo      Moscow          Rome      London
65
+	  |	     |               |	       |
66
+	  |	     |               |	       |
67
+	  |__________|Internet tunnel|_________|
68
+}}}
69
+
70
+Only one link exists, and it is a virtual one.
71
+Only Tokyo and London are linked, all the other cities are alone.
72
+
73
+When Tokyo and Moscow will be linked by a series of physical nodes, the mapper
74
+will change the net in this way:
75
+
76
+{{{
77
+	Tokyo<--ntk nodes-->Moscow     Rome          London
78
+	                     |		|		|
79
+		   	     |______ Internet tunnel ___|
80
+}}}
81
+
82
+
83
+When even Moscow and Rome will be linked by physical nodes:
84
+
85
+{{{
86
+	Tokyo<--ntk nodes-->Moscow<--ntk nodes-->Rome          London
87
+	                                   	  |		   |
88
+		   	                          |__ Inet tunnel _|
89
+}}}
90
+
91
+And so on.
92
+
93
+Basically when there are two nodes linked physically, one of them can cut
94
+its virtual link which connects it to the virtual layer.
95
+
96
+Let's go into the details.
97
+
98
+==== Virtual hooking ====
99
+
100
+A node, which hasn't any physical neighbours, resides in a black zone and, for
101
+this reason, it can't hook to the physical layer. It will hook directly to
102
+a vnode (virtual node), joining the virtual layer.
103
+Let this hooking node be X.
104
+
105
+The first part of the Virtual Hooking is the creation of the virtual links
106
+(ip tunnels).
107
+
108
+X chooses, at first, a random vnode which can be located anywhere in the
109
+globe. If it is its first hook to the virtual layer, it will get the IP of
110
+the vnode from a small public list available on the Internet, otherwise it
111
+will consult its saved virtual maps.
112
+Let the chosen vnode be Y.
113
+
114
+X sends to Y a packet containing its coordinates. This pkt will be forwarded
115
+with a greedy technique: 
116
+Y looks up its maps and forwards the pkt to the vnode which is the nearest to X.
117
+If this latter vnode knows another vnode which is nearer to X, it forwards
118
+again the packet. Finally, the pkt will arrive to the node Z, which is a node
119
+very near to X.
120
+
121
+Let d(A, B) be the physical distance between the node A and B.
122
+
123
+The node Z appends its Internet IP to the received packet and forwards it
124
+again to a node T, so that d(X,T) ~= d(X,Z).
125
+The node T will do the same (adds its IP and forwards the pkt).
126
+When the packet will be forwarded for the 16th time or when it can't be
127
+forwarded anymore, it is sent back to the node X.
128
+
129
+The node X collects this last packet and creates a virtual link (tunnel) to
130
+each Internet IP which has been stored in the packet itself. 
131
+These linked nodes are the new rnodes of the node X.
132
+
133
+
134
+At this point the node X will hook to each linked node. This procedure is
135
+called v-linking:
136
+
137
+Let "L" be the generic linked node.
138
+
139
+X sends the I_AM_VHOOKING request to L.
140
+
141
+L analyses its virtual rnodes and compares d(L,vR) to d(X,vR), where vR is a
142
+vrnode. If d(X,vR) < d(L,vR), L adds the Internet IP of the vR in the reply
143
+packet. This means that if L finds out that X is nearer to one of its
144
+vrnodes, it tells X to create a link to it and deletes its link to the vrnode.
145
+
146
+X receives the reply packet of L and tries to create a virtual link to each
147
+vR listed in the same packet.
148
+X writes the list of all the vR nodes which has been successfully linked to X
149
+itself. This list is sent back to L.
150
+
151
+L reads this latter list and delete all its links to the vR nodes, which has
152
+been successfully linked to X.
153
+
154
+X repeats this same hooking procedure for each L.
155
+
156
+In the end, X chooses one of its vrnodes and hooks with the classical method
157
+to it.
158
+
159
+==== Gate hooking ====
160
+
161
+A node can hook to the physical layer as a normal node or as gate node.
162
+
163
+A normal node is the old plain node of Netsukuku, it doesn't have to specify
164
+its coordinates and doesn't need any other prerequisites.
165
+
166
+The gate-node has an Internet connection that it uses to connect to
167
+the virtual layer, it is also connected to physical nodes.
168
+
169
+There are two cases:
170
+
171
+ * When the node is from the start a gate node
172
+ * When it is first a vnode and then becomes a gate node
173
+
174
+In the first case it hooks directly to a physical node. If one of its rnodes
175
+is a gate node too, it will start the v-linking procedure with it. 
176
+In this way, the new gate-node will be linked to its nearer vrnodes.
177
+The old gate-node will delete all the links to the vrnodes which have been
178
+linked by the new gate-node.
179
+
180
+In the second case, the node directly v-links to the new gate node which is
181
+connected to.
182
+
183
+When a gate-node can reach one of it vrnodes using both a virtual and a
184
+physical link, it will delete the virtual one.
185
+
186
+== TODO ==
187
+
188
+ * Is it possible to avoid using the coordinates?
189
+ * What does happen when a (v)node dies?
190
+
191
+---- 
192
+
193
+Feel free to help the development of Viphilama.

+ 160
- 0
doc/manuals/andna View File

@@ -0,0 +1,160 @@
1
+NAME
2
+    ANDNA - Abnormal Netsukuku Domain Name Anarchy
3
+
4
+DESCRIPTION
5
+    ANDNA is the distributed, non hierarchical and decentralised system of
6
+    hostname management in Netsukuku. It substitutes the DNS. The ANDNA
7
+    database is scattered inside all the Netsukuku net and in the worst case
8
+    every node will have to use about some hundreds Kb of memory.
9
+
10
+    In order to join ANDNA it is necessary to be hooked at Netsukuku with
11
+    the ntkd(8) daemon.
12
+
13
+    For more information about ANDNA visit: <http://netsukuku.freaknet.org>
14
+
15
+USAGE
16
+    First of all be sure to have the ntkd(8) daemon up and running.
17
+
18
+  HOSTNAME REGISTRATION
19
+    You can register up to 256 hostnames. Each hostname can be a string of
20
+    maximum 512 bytes, which contains a newline (\n) only at its end.
21
+
22
+    The hostnames to be registered must be listed, one per line, in the
23
+    andna_hostnames file, which is by default in
24
+    /etc/netsukuku/andna_hostnames.
25
+
26
+    The ntkd(8) daemon reads it when it is started and when it receives the
27
+    SIGHUP signal. So if you've added a hostname while ntkd was running,
28
+    just do:
29
+
30
+            killall -HUP ntkd
31
+
32
+    All the hostnames, which are already registered by other nodes, are
33
+    added in the queue, in this way, when the other nodes won't update them,
34
+    your hostnames will automatically be the first in the queue.
35
+
36
+    An hostname expires after 3 days, if it isn't updated. ntkd
37
+    automatically updates the registered hostnames, therefore your hostnames
38
+    will expire only if you aren't present in the Netsukuku for 3 entire
39
+    days.
40
+
41
+    If you want to know the result of a registration read the ntkd logs.
42
+
43
+  HOSTNAME RESOLUTION
44
+    The ntkd(8) daemon runs also a DNS wrapper which receives standard DNS
45
+    queries for hostnames resolution. The hostnames are resolved in ANDNA,
46
+    then the DNS wrapper will reply to the requester.
47
+
48
+    When the ntkd(8) daemon is started it copies /etc/resolv.conf in
49
+    /etc/resolv.conf.bak and adds in the first line of /etc/resolv.conf the
50
+    "nameserver 127.0.0.1" string. When it is closed it moves back
51
+    /etc/resolv.conf.bak to /etc/resolv.conf. Use the -R option if you want
52
+    to disable this behaviour.
53
+
54
+    All the resolved hostnames are kept, until their expiration date, in the
55
+    "resolved hostnames cache". The entire cache is flushed each time the
56
+    ntkd(8) daemon receives the SIGALRM signal.
57
+
58
+    That's all.
59
+
60
+  IP RESOLUTION
61
+    It is possible to know the list of hostnames registered by a node. You
62
+    have to simply reverse resolve its ip. For example:
63
+
64
+            dig -x 127.0.0.2
65
+
66
+    This command shows your currently registered hostnames. You can use it
67
+    to know what hostnames have been already registered. Note the 127.0.0.2
68
+    ip. If you use 127.0.0.1 you get only the local hostname written in
69
+    /etc/hosts.
70
+
71
+  SCATTERED NAME SERVICE DISGREGATION
72
+    The Scattered Name Service Disgregation is the ANDNA equivalent of the
73
+    SRV Record of the Internet Domain Name System. For a complete
74
+    description of the SNSD read the NTK_RFC 0009:
75
+    <http://lab.dyne.org/Ntk_SNSD>
76
+
77
+   SNSD NODE REGISTRATION
78
+     * Modify the /etc/netsukuku/snsd_nodes file.
79
+     * Copy the needed public keys
80
+     * Send a SIGHUP to the NetsukukuD of the register node:
81
+
82
+   SNSD NODE DELETION
83
+    Not implemented
84
+
85
+   SNSD HNAME RESOLUTION
86
+    The utility ntk-resolv(8) can be used to resolve SNSD hostnames.
87
+    Examples:
88
+
89
+            ntk-resolv -s 53/udp host
90
+            ntk-resolv -s http host
91
+
92
+SIGNALS
93
+    When the SIGHUP signal is sent to ntkd(8), the andna_hostnames and
94
+    snsd_nodes files will be reloaded and it will try to register all the
95
+    new added hostnames and snsd records.
96
+
97
+    When the SIGALRM signal is sent to ntkd(8), the resolved hostnames cache
98
+    will be flushed.
99
+
100
+FILES
101
+    /etc/netsukuku/andna_hostnames
102
+        It is the file where the hostnames to be registerd in ANDNA are kept
103
+        one per line. It's location can be changed by modifying its option
104
+        in the netsukuku.conf file.
105
+
106
+    /etc/netsukuku/snsd_nodes
107
+        The snsd_nodes file keeps the list of the SNSD records which will be
108
+        register in ANDNA.
109
+
110
+    /usr/share/netsukuku/andna_lcl_keyring
111
+        In this keyring your ANDNA public and secret keys are saved. Handle
112
+        this file with care: without it, you won't be able to update your
113
+        hostnames, thus you'll definitely lose them.
114
+
115
+    /usr/share/netsukuku/andna_cache
116
+    /usr/share/netsukuku/andna_lcl_cache
117
+    /usr/share/netsukuku/andna_rh_cache
118
+    /usr/share/netsukuku/andna_counter_cache
119
+        They are the saved ANDNA caches. Their locations can be changed in
120
+        netsukuku.conf.
121
+
122
+BUGS
123
+    { Don't panic! }
124
+
125
+    If you encounter any bug, please report it. Use the online bug track
126
+    system: <http://bugs.dyne.org/>
127
+
128
+    or the mailing list: <http://lists.dyne.org/netsukuku/>
129
+
130
+    and explain what the problem is and if possible a way to reproduce it.
131
+
132
+CONTACTS
133
+    Subscribe to the netsukuku mailing to get help, be updated on the latest
134
+    news and discuss on its development.
135
+
136
+    To subscribe to the list, send a message to:
137
+    netsukuku-subscribe@lists.dyne.org
138
+
139
+    We live night and day in IRC, come to see us in: #netsukuku on the
140
+    FreeNode irc server (irc.freenode.org).
141
+
142
+AUTHORS
143
+    Main authors and maintainers:
144
+
145
+    Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
146
+
147
+    Main contributors:
148
+
149
+    Andrea Leofreddi <andrea.leofreddi@gmail.com>, Katolaz
150
+    <katolaz@freaknet.org>, Federico Tomassini <effetom@gmail.com>
151
+
152
+    For a complete list read the AUTHORS file or visit:
153
+    <http://netsukuku.freaknet.org/?p=Contacts>
154
+
155
+SEE ALSO
156
+    For more information about Netsukuku visit:
157
+    <http://netsukuku.freaknet.org>
158
+
159
+    ntkd(8), ntk-wifi(8), iproute2(8), route(8)
160
+

+ 241
- 0
doc/manuals/netsukuku.conf View File

@@ -0,0 +1,241 @@
1
+NAME
2
+    netsukuku.conf - Netsukuku daemon configuration file
3
+
4
+SYNOPSIS
5
+    /etc/netsukuku/netsukuku.conf
6
+
7
+DESCRIPTION
8
+    ntkd(8) loads its options from the command line and from netsukuku.conf.
9
+    The options that are changed infrequently resides in the configuration
10
+    file. The netsukuku.conf file is typically installed at
11
+    /etc/netsukuku/netsukuku.conf.
12
+
13
+    The comments starts with a '#'. If an option is commented, ntkd will use
14
+    its default value.
15
+
16
+    The character '=' is used to assign a value to an option.
17
+
18
+    All the options will be overridden by their command line equivalent.
19
+
20
+OPTIONS
21
+  RESTRICTED MODE
22
+    ntk_restricted_mode = *bool*
23
+        When set to 1, ntkd will be started in restricted mode to be
24
+        compatible with Internet. In the restricted mode, only IPs of the
25
+        largest private subnet, i.e. 10.x.x.x are chosen.
26
+
27
+        Default: *0*
28
+
29
+    ntk_restricted_class = *bool*
30
+        When set to 1 the IPs will be chosen from the
31
+        172.16.0.0-172.31.255.255 range (use this option only if you can't
32
+        use the 10.x.x.x class).
33
+
34
+        Default: *0*
35
+
36
+  INTERNET CONNECTION
37
+    All these Internet options requires ntk_restricted_mode set to 1.
38
+
39
+    internet_connection = *bool*
40
+        When set to 1, it specifies that this computer has an active
41
+        Internet connection. Note that ntkd will overwrite any default route
42
+        if this option is set to 0 and the shared Internet connections of
43
+        other nodes are used.
44
+
45
+        Default: *0*
46
+
47
+    internet_gateway = *IP:interface*
48
+        It specifies the default gateway used by *localhost* to reach the
49
+        Internet. This option is necessary only if you don't have the
50
+        default route set when you run ntkd (i.e. you haven't connected
51
+        yet). If this option isn't specified, ntkd will automatically
52
+        retrieve the default Internet gateway from the routing table.
53
+        Example: internet_gateway = 192.168.1.1:eth0
54
+
55
+        Default: *(null)*
56
+
57
+    internet_download_rate = *Kb*
58
+        This option is required if the internet_connection option has been
59
+        set to 1. It must be set to the download rate of the Internet
60
+        connection in KiloBytes. Example:
61
+
62
+                internet_download_rate = 640
63
+
64
+        Default: *(null)*
65
+
66
+    internet_upload_rate = *Kb*
67
+        This option is required if the internet_connection option has been
68
+        set to 1. It must be set to the upload rate of the Internet
69
+        connection in KiloBytes. Example:
70
+
71
+                internet_upload_rate = 30
72
+
73
+        Default: *(null)*
74
+
75
+    internet_ping_hosts = *host1:host2:host3:...*
76
+        Specifies a list of Internet hostnames which ntkd will ping
77
+        periodically to verify the status of the Internet connection. If all
78
+        the hosts specified aren't reachable, it will assume that the
79
+        Internet connection isn't available anymore. When one them becoms
80
+        pingable, ntkd will enable again the Internet Gateway Search.
81
+        Example:
82
+
83
+                internet_ping_hosts = google.com:cisco.com:sourceforge.net:dyne.org
84
+
85
+        This option hasn't a default value, it must be specified in the
86
+        netsukuku.conf file.
87
+
88
+    share_internet = *bool*
89
+        When set to 1, ntkd shares the Internet connection among all the
90
+        other Netsukuku nodes.
91
+
92
+        Default: *1*
93
+
94
+    shape_internet = *bool*
95
+        Specifies if ntkd will execute the /etc/netsukuku/tc_shaper.sh
96
+        script to activate the traffic shaping of the Internet connection.
97
+
98
+        Default: *0*
99
+
100
+    use_shared_internet = *bool*
101
+        Specifies if ntkd will load balance the Internet traffic of this
102
+        host using the Inet connections shared by the Netsukuku nodes. When
103
+        set to 0, localhost (this machine) uses only its local Internet
104
+        connection (if any).
105
+
106
+        Default: *1*
107
+
108
+  ANDNA
109
+    disable_andna = *bool*
110
+        When set to 1, ntkd won't load the ANDNA(8) daemon. Note that when
111
+        the ANDNA daemon is disabled, the andna system will not work at all,
112
+        so it will be impossible to resolve, register or update hostnames.
113
+
114
+        Default: *0*
115
+
116
+    disable_resolvconf = *bool*
117
+        When ntkd starts it modifies /etc/resolv.conf writing in the first
118
+        line "nameserver 127.0.0.1". The old /etc/resolv.conf is copied in
119
+        /etc/resolv.conf.bak. When the daemon is closed /etc/resolv.conf is
120
+        restored. If you want to disable this set disable_resolvconf to 1.
121
+        If it is disabled you won't be able to resolve hostnames!
122
+
123
+        Default: *0*
124
+
125
+  LIMITS
126
+    Note: in the current ntkd version these limits aren't effective.
127
+
128
+    ntk_max_connections = *number*
129
+        How many connection the netsukuku daemons can simultaneusly handle.
130
+
131
+        Default: *512*
132
+
133
+    ntk_max_accepts_per_host = *number*
134
+        How many simultaneusly connections to the daemons from a single host
135
+        are allowed.
136
+
137
+        Default: *16*
138
+
139
+    max_accepts_per_host_time = *seconds*
140
+        The wait time necessary for a host to reconnect to the daemons after
141
+        all the ntk_max_accepts_per_host were used.
142
+
143
+        Default: *4*
144
+
145
+  FILES
146
+    pid_file = *filename*
147
+        ntkd will save its process id in this file. It is used to check if
148
+        other instances of ntkd are already running. Only one instance is
149
+        allowed.
150
+
151
+        Default: */var/run/ntkd.pid*
152
+
153
+    ntk_ext_map_file = *filename*
154
+    ntk_int_map_file = *filename*
155
+    ntk_bnode_map_file = *filename*
156
+        Specify the paths of the maps saved by the daemon.
157
+
158
+        Default: */usr/share/netsukuku/ext_map_file*
159
+
160
+        Default: */usr/share/netsukuku/int_map_file*
161
+
162
+        Default: */usr/share/netsukuku/bnode_map_file*
163
+
164
+    andna_hnames_file = *filename*
165
+        Specify the path of the file which keeps the ANDNA hostnames of the
166
+        local host. These hostnames will be registerd in ANDNA.
167
+
168
+        Default: */etc/netsukuku/andna_hostnames*
169
+
170
+    snsd_nodes_file = *filename*
171
+        The snsd_nodes_file keeps the list of the SNSD records which will be
172
+        register in ANDNA.
173
+
174
+        Default: */etc/netsukuku/snsd_nodes*
175
+
176
+    andna_lclkey_file = *filename*
177
+        Specifies the location of the *local keyring* file. In this keyring
178
+        the ANDNA public and secret keys are saved. Handle this file with
179
+        care: without it, you won't be able to update your hostnames, thus
180
+        you'll definitely lose them.
181
+
182
+        Default: */usr/share/netsukuku/andna_lcl_keyring*
183
+
184
+    andna_cache_file = *filename*
185
+    andna_lcl_file = *filename*
186
+    andna_rhc_file = *filename*
187
+    andna_counter_c_file = *filename*
188
+        Specify the paths of the caches used by the ANDNA daemon.
189
+
190
+        Default: */usr/share/netsukuku/andna_cache*
191
+
192
+        Default: */usr/share/netsukuku/andna_lcl_cache*
193
+
194
+        Default: */usr/share/netsukuku/andna_rh_cache*
195
+
196
+        Default: */usr/share/netsukuku/andna_counter_cache*
197
+
198
+    ip_masquerade_script = *filename*
199
+        Specifies the path of the IP masquerading script. This script is
200
+        launched by NetsukukuD, at its start, when it shares the Internet
201
+        connection. The script will activate the IP masquerading. The script
202
+        is also used to disable the IP masquerading when ntkd is closed.
203
+
204
+        Default: */etc/netsukuku/ip_masquerade.sh*
205
+
206
+    tc_shaper_script = *filename*
207
+        Specifies the path of the traffic shaping script. This script
208
+        manages the traffic shaping for the upload bandwidth. It is executed
209
+        by ntkd at its start if its relative option has been enabled.
210
+
211
+        Default: */etc/netsukuku/tc_shaper.sh*
212
+
213
+CONTACTS
214
+    Subscribe to the netsukuku mailing to get help, be updated on the latest
215
+    news and discuss on its development.
216
+
217
+    To subscribe to the list, send a message to:
218
+    netsukuku-subscribe@lists.dyne.org
219
+
220
+    We live night and day in IRC, come to see us in: #netsukuku on the
221
+    FreeNode irc server (irc.freenode.org).
222
+
223
+AUTHORS
224
+    Main authors and maintainers:
225
+
226
+    Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
227
+
228
+    Main contributors:
229
+
230
+    Andrea Leofreddi <andrea.leofreddi@gmail.com>, Katolaz
231
+    <katolaz@freaknet.org>, Federico Tomassini <effetom@gmail.com>
232
+
233
+    For a complete list read the AUTHORS file or visit:
234
+    <http://netsukuku.freaknet.org/?p=Contacts>
235
+
236
+SEE ALSO
237
+    For more information about Netsukuku visit:
238
+    <http://netsukuku.freaknet.org>
239
+
240
+    ntkd(8), ntk-wifi(8), andna(8), iproute2(8), route(8)
241
+

+ 208
- 0
doc/manuals/ntk-resolv View File

@@ -0,0 +1,208 @@
1
+NAME
2
+    ntk-resolv - Andns Lookup Resolver
3
+
4
+SYNOPSIS
5
+    ntk-resolv [-vnPtrspShbml] host ntk-resolv -H host
6
+
7
+DESCRIPTION
8
+    Ntk-resolv is an interface to ANDNA daemon: it performs andns queries
9
+    and displays the answers to stdout. It is able to formule questions for
10
+    objects in Internet and Netsukuku realms. It uses the 'andns protocol'
11
+    to encode his contents, as explained in Netsukuku RFC 006.
12
+
13
+USAGE
14
+    The simplest example is:
15
+
16
+            ntk-resolv hname
17
+
18
+    With this comand, it asks ANDNA which IP registered the hostname
19
+    'hname'. The default behavior is to perform the query in the Netsukuku
20
+    realm.
21
+
22
+OPTIONS
23
+    -v --version
24
+        Print Version, then exit.
25
+
26
+    -n --nameserver=host
27
+        Specify the nameserver to use. The default is localhost.
28
+
29
+    -P --port=n
30
+        Uses the port <n> of nameserver. Default is 53.
31
+
32
+    -t --query-type=snsd --query-type=ptr --qury-type=global --query-type=mx
33
+        Specify the query type . Default is snsd. See the section QUERY
34
+        TYPE.
35
+
36
+    -r --realm=inet --realm=ntk
37
+        Specify the realm of the query: Internet or Netsukuku. Default is
38
+        ntk.
39
+
40
+    -s --service=n[/proto]
41
+        Specify the SNSD service and the relative protocol to search. See
42
+        services(5). The service can be specified in alfanumeric or numeric
43
+        format. The default service and protocol are 0 and tcp. Example:
44
+
45
+                ntk-resolv -s domain/udp host
46
+                ntk-resolv -s 53/udp host
47
+
48
+        See the section QUERY TYPE, SERVICES AND PROTOCOL for a better
49
+        explanation.
50
+
51
+    -S --silent
52
+        With this option, ntk-resolv will be very discrete.
53
+
54
+    -b --block-recursion
55
+        Set recursion OFF. If recursion is ON (default), when a SNSD service
56
+        is requested, and the service is specified with a hostname instead
57
+        of an IP, the IP of that hostname will be searched. In the case of a
58
+        success research, the answer will contain the IP of the hostname,
59
+        and NOT the hostname HASH.
60
+
61
+    -m --md5-hash
62
+        If this option is set, the hostname specified is interpreted as a
63
+        MD5 hash. This is useful when you want to know a hostname IP, but
64
+        you know only the hash of his name.
65
+
66
+    -H --compute-hash
67
+        Compute the hash of specified hostname and print it to stdout.
68
+        Example:
69
+
70
+                ntk-resolv -H hname
71
+
72
+        It will print the md5 hash of `hname'. This is useful to debug SNSD
73
+        configurations. In fact, if a query is not recursive, the results
74
+        are hash'ed hostnames: so, it's possible to verify if the ANDNA
75
+        cache is storing the correct hash-value for your SNSD hostnames.
76
+
77
+    -l --parsable-output
78
+        Print answers in a synthetic way. The format of output is:
79
+
80
+                ~ IP                               (SNSD s=0)
81
+                - hname                            (Inverse)
82
+                - hname prio weight                (SNSD s!=0)
83
+                ~ ip prio weight                   (SNSD s!=0)  
84
+                ~ ip service proto prio weight     (Global)
85
+                - hname service proto prio weight  (Global)
86
+
87
+        Note that when an answer contains an IP, the first character is `~';
88
+        if the answer contains a hostname (hash'ed or not) the line begins
89
+        with `-'.
90
+
91
+    -h --help
92
+        Prints to stdout a short explanation of ntk-resolv.
93
+
94
+    Final note:
95
+        All options that take string arguments could be expressed in a
96
+        shorter way, by specifing univoque abbreviation of argument. So,
97
+        there is the equivalence:
98
+
99
+                ntk-resolv -r i = ntk-resolv -r inet
100
+
101
+        with the exception of option -s, wich requires a valid service.
102
+
103
+QUERY TYPE
104
+        You can formule different kind of queries.
105
+
106
+        With a `ptr' query, you specify an IP, and you will have, if exists,
107
+        the hostname that registered that IP.
108
+
109
+        With a `snsd' query, you specify a hostname, a service and a
110
+        protocol. If service and protocol are not specified, they are set to
111
+        0, and you will have the IP assigned to the hostname at this moment.
112
+        If you specify a service and a protocol, the answer will contain the
113
+        IP that gives the specified service/protocl for the hostname. See
114
+        the section SNSD, SERVICES AND PROTOCOL to understand better the
115
+        SNSD behavior.
116
+
117
+        A global query will return the complete SNSD configuration for a
118
+        hostname. Ie, you will have an answer for each service that hostname
119
+        registered.
120
+
121
+        The `mx' query is equivalent to a snsd query with service 25 and
122
+        proto TCP.
123
+
124
+SNSD, SERVICES AND PROTOCOL
125
+        SNSD Query Type gives a hostname resolution. With SNSD (Scattered
126
+        Name Service Disgregation) ANDNA lets the user to ask for a domain
127
+        and a service. If service is 0, the resolution will show which IP
128
+        registered the hostname. If service is non-0, the resolution will
129
+        show which IP gives specified service for the hostname (considering
130
+        the protocol too). See services(5).
131
+
132
+        You can specify a service as expressed in /etc/services. It can be
133
+        expressed also in numeric form. It is also possible to specify the
134
+        protocol:
135
+
136
+                "domain", "53", "53/udp", "domain/udp"
137
+
138
+        are valid service/proto strings.
139
+
140
+        For example, the next commands will retrieve the IP(s) that offers
141
+        web-pages for the hostname "host":
142
+
143
+                ntk-resolv -s http/tcp host
144
+                ntk-resolv -s 80/tcp   host
145
+                ntk-resolv -s 80       host
146
+                ntk-resolv -s http     host
147
+
148
+        To configure the SNSD delegations, see the SNSD HowTo.
149
+
150
+        If the delegation for a service (say http) is not set, the IP
151
+        returned is the IP that registered the hostname. So, if you do not
152
+        want to set SNSD delegations for specific services, the main
153
+        hostname IP will be used and you don't need to do nothing.
154
+
155
+        The hope is that every client will build different queries: browsers
156
+        will make queries with service=80 and proto=tcp, mail-clients will
157
+        build queries with service=25 and proto tcp and so on.
158
+
159
+        The service is useless if the query realm is Internet.
160
+
161
+        The default service is 0: ie, the query will return the IP that
162
+        registered the hostname. Default protocol is tcp. Protocol is
163
+        ignored when service requested is 0.
164
+
165
+        Note: service and proto are also ignored when the query type is
166
+        `ip->host` (ptr query type).
167
+
168
+BUGS
169
+        { Don't panic! }
170
+
171
+        If you encounter any bug, please report it. Use the online bug track
172
+        system: <http://bugs.dyne.org/>
173
+
174
+        or the mailing list: <http://lists.dyne.org/netsukuku/>
175
+
176
+        and explain what the problem is and if possible a way to reproduce
177
+        it.
178
+
179
+CONTACTS
180
+        Subscribe to the netsukuku mailing to get help, be updated on the
181
+        latest news and discuss on its development.
182
+
183
+        To subscribe to the list, send a message to:
184
+        netsukuku-subscribe@lists.dyne.org
185
+
186
+        We live night and day in IRC, come to see us in: #netsukuku on the
187
+        FreeNode irc server (irc.freenode.org).
188
+
189
+AUTHORS
190
+        Main authors and maintainers:
191
+
192
+        Federico Tomassini <effetom@gmail.com> wrote ntk-resolv and network
193
+        libraries.
194
+
195
+        Andrea Lo Pumo aka AlpT <alpt@freaknet.org> wrote ANDNA and
196
+        Netsukuku Core.
197
+
198
+        Main contributors:
199
+
200
+        Andrea Leofreddi <andrea.leofreddi@gmail.com>, Katolaz
201
+        <katolaz@freaknet.org>,
202
+
203
+        For a complete list read the AUTHORS file or visit:
204
+        <http://netsukuku.freaknet.org/?p=Contacts>
205
+
206
+SEE ALSO
207
+        ntkd(8), andna(8), services(5)
208
+

+ 54
- 0
doc/manuals/ntk-wifi View File

@@ -0,0 +1,54 @@
1
+NAME
2
+    ntk-wifi - configures the specified wifi card to join Netsukuku
3
+
4
+SYNOPSIS
5
+    ntk-wifi *wifi_interface*
6
+
7
+DESCRIPTION
8
+    Netsukuku_wifi is a shell script, which takes as its first argument the
9
+    name of the wifi network interface to be used in order to join in
10
+    Netsukuku. Then it sets the wifi interface in Ad-Hoc mode and its essid
11
+    to "netsukuku". At this point the ntkd daemon is ready to be launched,
12
+
13
+EXAMPLES
14
+    ntk-wifi wlan0
15
+
16
+BUGS
17
+    { Don't panic! }
18
+
19
+    If you encounter any bug, please report it. Use the online bug track
20
+    system: <http://bugs.dyne.org/>
21
+
22
+    or the mailing list: <http://lists.dyne.org/netsukuku/>
23
+
24
+    and explain what the problem is and if possible a way to reproduce it.
25
+
26
+CONTACTS
27
+    Subscribe to the netsukuku mailing to get help, be updated on the latest
28
+    news and discuss on its development.
29
+
30
+    To subscribe to the list, send a message to:
31
+    netsukuku-subscribe@lists.dyne.org
32
+
33
+    We live night and day in IRC, come to see us in: #netsukuku on the
34
+    FreeNode irc server (irc.freenode.org).
35
+
36
+AUTHORS
37
+    Main authors and maintainers:
38
+
39
+    Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
40
+
41
+    Main contributors:
42
+
43
+    Andrea Leofreddi <andrea.leofreddi@gmail.com>, Katolaz
44
+    <katolaz@freaknet.org>, Federico Tomassini <effetom@gmail.com>
45
+
46
+    For a complete list read the AUTHORS file or visit:
47
+    <http://netsukuku.freaknet.org/?p=Contacts>
48
+
49
+SEE ALSO
50
+    For more information about Netsukuku visit:
51
+    <http://netsukuku.freaknet.org>
52
+
53
+    ntkd(8), andna(8), iproute2(8), route(8)
54
+

+ 243
- 0
doc/manuals/ntkd View File

@@ -0,0 +1,243 @@
1
+NAME
2
+    ntkd - Netsukuku protocol daemon
3
+
4
+SYNOPSIS
5
+    ntkd [-hvaldrD46] [-i net_interface] [-c conf_file] [-l logfile]
6
+
7
+DESCRIPTION
8
+    Netsukuku is a mesh network or a P2P net system that generates and
9
+    sustains itself autonomously. It is designed to handle an unlimited
10
+    number of nodes with minimal CPU and memory resources. Thanks to this
11
+    feature it can be easily used to build a worldwide distributed,
12
+    anonymous and anarchical network, separated from the Internet, without
13
+    the support of any servers, ISPs or authority controls.
14
+
15
+    The complete features list of Netsukuku is here:
16
+    <http://netsukuku.freaknet.org/files/doc/misc/Ntk_features_list>
17
+
18
+    In order to join to Netsukuku you have to use ntkd, which is the daemon
19
+    implementing the Npv7 protocol. The daemon at startup takes the list of
20
+    all the network interfaces which are currently UP and it uses all of
21
+    them to send and receive packets. If you want to force the daemon to use
22
+    specific interfaces you should use the -i option. The ports it listens
23
+    to are: 269-udp, 269-tcp, 277-udp, 277-tcp. So be sure to open them in
24
+    the firewall.
25
+
26
+    For more information about Netsukuku visit:
27
+    <http://netsukuku.freaknet.org>
28
+
29
+OPTIONS
30
+    -4, --ipv4
31
+        Forces the daemon to use ipv4 addresses only
32
+
33
+    -6, --ipv6
34
+        Forces the daemon to use ipv6 addresses only. Warning, this is still
35
+        experimental.
36
+
37
+    -i *interface*, --iface *interface*
38
+        Specifies the network interface the daemon will use to join
39
+        Netsukuku, i.e. wlan0. You can use more than one interface by
40
+        specifying multiple times the -i option. For example:
41
+
42
+                ntkd -i wlan0 -i eth0 -i wifi1 -i eth1
43
+
44
+    -a, --no_andna
45
+        Forces ntkd to don't run the ANDNA daemon when started.
46
+
47
+    -R, --no_resolv
48
+        When NetsukukuD starts it modifies /etc/resolv.conf writing in the
49
+        first line the string "nameserver 127.0.0.1". The old
50
+        /etc/resolv.conf is copied in /etc/resolv.conf.bak. When the daemon
51
+        is closed /etc/resolv.conf is restored. If you want to disable this
52
+        set use the -R option.
53
+
54
+    -r*[bool]*, --restricted=*[bool]*
55
+        With this option the daemon will run in restricted mode as specified
56
+        in the Npv7, only IPs of a private class will be chosen. It is used
57
+        for Internet compatibility. If no argument is given to the option,
58
+        the default restricted private class 10.0.0.0 is used, otherwise if
59
+        *bool* is not zero, the restricted class will be
60
+        172.16.0.0-172.31.255.255.
61
+
62
+    -I, --share-inet
63
+        Tells NetsukukuD to run in restricted mode (see -r) and to share
64
+        your Internet connection. Please check the relative options in
65
+        /etc/netsukuku/netsukuku.conf
66
+
67
+    -D, --no_daemon
68
+        This option tells ntkd to don't detach to background and daemonizing
69
+        itself. The daemon will run on foreground instead.
70
+
71
+    -c *configuration_file*, --conf *configuration_file*
72
+        Specifies the name of the configuration file. The default is
73
+        /etc/netsukuku/netsukuku.conf. ntkd will not start without a
74
+        configuration file.
75
+
76
+    -l *logfile*, --logfile *logfile*
77
+        Specifies that ntkd should send all of its messages to the specified
78
+        file. The *logfile* will be overwritten.
79
+
80
+    -d, --debug
81
+        With this option the daemon will run with displaying its debug
82
+        messages. The more -d you specify the more debug messages you'll
83
+        get. Sometimes it's cool to use it, but be careful and don't go
84
+        insane ;)
85
+
86
+    -h, --help
87
+        Display a the list of available options and their brief description.
88
+
89
+    -v, --version
90
+        Displays the version of the ntkd daemon.
91
+
92
+EXAMPLES
93
+    Usually you'll just want to use ntkd with a wifi device:
94
+
95
+            ntk-wifi wlan0
96
+            ntkd -i wlan0
97
+
98
+    If you one to use more than one network interface:
99
+
100
+            ntkd -i eth0 -i wlan0 -i wifi1 -i eth2
101
+
102
+SIGNALS
103
+    When the SIGHUP signal is sent to ntkd(8), the andna_hostnames and
104
+    snsd_nodes files will be reloaded and it will try to register all the
105
+    new added hostnames and snsd records.
106
+
107
+    When the SIGALRM signal is sent to ntkd, the resolved hostnames cache is
108
+    flushed.
109
+
110
+LOGS
111
+    If ntkd is started as a daemon (without the -D option), all the logs are
112
+    sent to syslog under the LOG_DAEMON category.
113
+
114
+    If the no-daemon option (-D) is used, all the logs are printed to
115
+    stderr.
116
+
117
+FILES
118
+    /etc/netsukuku/netsukuku.conf
119
+        It is the default path for the ntkd configuration file. It's
120
+        possible to choose another file using the -c option.
121
+
122
+    /etc/netsukuku/andna_hostnames
123
+        It is the file where the hostnames to be registerd in ANDNA are kept
124
+        one per line. It's location can be changed by modifying the relative
125
+        option in the netsukuku.conf file.
126
+
127
+    /etc/netsukuku/snsd_nodes
128
+        The snsd_nodes_file keeps the list of the SNSD records which will be
129
+        register in ANDNA.
130
+
131
+    /usr/share/netsukuku/ext_map_file
132
+    /usr/share/netsukuku/int_map_file
133
+    /usr/share/netsukuku/bnode_map_file
134
+        They are the Netsukuku maps saved by the daemon. Their locations can
135
+        be changed in netsukuku.conf.
136
+
137
+    /usr/share/netsukuku/andna_lcl_keyring
138
+        In this keyring your ANDNA public and secret keys are saved. Handle
139
+        this file with care: without it, you won't be able to update your
140
+        hostnames, thus you'll definitely lose them.
141
+
142
+    /usr/share/netsukuku/andna_cache
143
+    /usr/share/netsukuku/andna_lcl_cache
144
+    /usr/share/netsukuku/andna_rh_cache
145
+    /usr/share/netsukuku/andna_counter_cache
146
+        They are the saved ANDNA caches. Their locations can be changed in
147
+        netsukuku.conf.
148
+
149
+    /etc/netsukuku/ip_masquerade.sh
150
+        This script is launched by NetsukukuD, at its start, when it shares
151
+        the Internet connection. The script will activate the IP
152
+        masquerading. The script is also used to disable the IP masquerading
153
+        when ntkd is closed.
154
+
155
+    /etc/netsukuku/tc_shaper.sh
156
+        This script manages the traffic shaping for the upload bandwidth. It
157
+        is executed by ntkd at its start if its relative option has been
158
+        enabled.
159
+
160
+    /var/run/ntkd.pid
161
+        It is the lock file created by ntkd at its start, it is used to
162
+        check if other instances of ntkd are already running. Only one
163
+        instance is allowed.
164
+
165
+KERNEL DEPENDENCIES
166
+    On Linux be sure to have the following options set in your kernel
167
+    .config. These options are taken from linux-2.6.14.
168
+
169
+            #
170
+            # Networking options
171
+            #
172
+            CONFIG_PACKET=y
173
+            CONFIG_UNIX=y
174
+            CONFIG_INET=y
175
+            CONFIG_IP_MULTICAST=y
176
+            CONFIG_IP_ADVANCED_ROUTER=y
177
+            CONFIG_IP_MULTIPLE_TABLES=y
178
+            CONFIG_IP_ROUTE_MULTIPATH=y
179
+            CONFIG_NET_IPIP=y
180
+            CONFIG_NETFILTER=y
181
+
182
+    and these from linux-2.6.16.19.
183
+
184
+            #
185
+            # Core Netfilter Configuration
186
+            #
187
+
188
+            CONFIG_NETFILTER_XT_MATCH_CONNTRACK=y
189
+            NETFILTER_XT_TARGET_CONNMARK=y
190
+
191
+            #
192
+            # IP: Netfilter Configuration
193
+            #
194
+
195
+            CONFIG_IP_NF_IPTABLES=y
196
+            CONFIG_IP_NF_FILTER=y
197
+            CONFIG_IP_NF_TARGET_REJECT=y
198
+            CONFIG_IP_NF_NAT=y
199
+            CONFIG_IP_NF_NAT_NEEDED=y
200
+            CONFIG_IP_NF_TARGET_MASQUERADE=y
201
+
202
+    If you are using modules you have to load them before launching the
203
+    daemon.
204
+
205
+BUGS
206
+    { Don't panic! }
207
+
208
+    If you encounter any bug, please report it. Use the online bug track
209
+    system: <http://bugs.dyne.org/>
210
+
211
+    or the mailing list: <http://lists.dyne.org/netsukuku/>
212
+
213
+    and explain what the problem is and if possible a way to reproduce it.
214
+
215
+CONTACTS
216
+    Subscrive to the netsukuku mailing to get help, be updated on the latest
217
+    news and discuss on its development.
218
+
219
+    To subscribe to the list, send a message to:
220
+    netsukuku-subscribe@lists.dyne.org
221
+
222
+    We live night and day in IRC, come to see us in: #netsukuku on the
223
+    FreeNode irc server (irc.freenode.org).
224
+
225
+AUTHORS
226
+    Main authors and maintainers:
227
+
228
+    Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
229
+
230
+    Main contributors:
231
+
232
+    Andrea Leofreddi <andrea.leofreddi@gmail.com>, Katolaz
233
+    <katolaz@freaknet.org>, Federico Tomassini <effetom@gmail.com>
234
+
235
+    For a complete list read the AUTHORS file or visit:
236
+    <http://netsukuku.freaknet.org/?p=Contacts>
237
+
238
+SEE ALSO
239
+    For more information about Netsukuku visit:
240
+    <http://netsukuku.freaknet.org>
241
+
242
+    netsukuku.conf(5), ntk-wifi(8), andna(8), iproute2(8), route(8)
243
+

+ 95
- 0
doc/misc/Ntk_Grow_Netsukuku View File

@@ -0,0 +1,95 @@
1
+== Grow Netsukuku ==
2
+
3
+Netsukuku is a mesh network.
4
+The mesh networks depend on the collaboration of each node, in fact, a
5
+distributed network can grow only with the small contributions of each user.
6
+
7
+Don't expect that someone will set up the whole net for you, just
8
+because Netsukuku is decentralised, anonymous, distributed and independent
9
+and it will never be possible to anybody to control it.
10
+
11
+You have the possibility to be the citizen of a free world wide community,
12
+where no one will ever be able to limit your digital rights with measures like
13
+prosecution of file sharing, censorship, data retention, commercial
14
+connectivity and so on.
15
+
16
+=== Joining Netsukuku ===
17
+
18
+The first step is to turn your PC into a Netsukuku node:
19
+        * take a computer
20
+        * install any distro of GNU/Linux
21
+        * install Netsukuku
22
+        * buy a wifi (PCI) card
23
+        * buy/build an external antenna (with the longest range as possible)
24
+or
25
+	* buy an Access Point compatible with the Netsukuku-AP firmware
26
+        * buy/build an external antenna (with the longest range as possible)
27
+	* connect the AP to your PC. In this case it doesn't matter anymore 
28
+	  what OS you've installed and even if your PC is turned off, the AP 
29
+	  will continue to be an active Netsukuku node..
30
+
31
+It's highly probable you will be the first node in your neighborhood,
32
+but this is normal: someone have to be the first.
33
+As soon as another user will do the same thing you did, you will be
34
+automatically connected to each other.
35
+Waiting doesn't cost you nothing.
36
+
37
+In order to shorten your waiting you can help the growth of Netsukuku in your
38
+neighborhood by following the advises written below.
39
+
40
+=== Internet sharing ===
41
+
42
+If you have an Internet connection, share it with your neighbours.
43
+In this way everybody will be able to have a free Internet connection without
44
+worrying of his or her location. Moreover, when this habit will be common, you
45
+won't worry too, anywhere and anytime.
46
+
47
+Don't worry too much about sharing your bandwidth.
48
+These are some features of sharing the Internet connection with Netsukuku:
49
+ * You can connect to the Internet using, at the same time, multiple node
50
+   which share their connection. For example, if there are 5 nodes sharing
51
+   their 640Kb/s connections, you can have 5 parallel downloads at 640Kb/s.
52
+ * If you decide to share your Internet connection, you will always use the
53
+   Internet connections shared by the other nodes. In this way, you donate
54
+   your bandwidth, but, at the same time, receive donations from other users.
55
+ * Even if you share your Internet connection to other Netsukuku nodes, your
56
+   traffic will have the maximum priority, therefore you won't notice any
57
+   slowdown.
58
+
59
+=== Spread the word ===
60
+
61
+It is very important to let your neighbours aware of being inside a
62
+Netsukuku area.
63
+You have just to mark in a visible way the area, for example using:
64
+ * stickers: /* TODO: image and phrase for the sticker URL */
65
+ * papers: /* TODO: url of the sheet to print */
66
+ * posters: /* TODO */
67
+
68
+For more information on this topic go to:
69
+http://lab.dyne.org/Ntk_spread_the_word	 /* TODO */
70
+
71
+=== City-City link ===
72
+
73
+In the same way two nodes close to each other are linked, it is possible to connect 
74
+two close cities by wireless links.
75
+Otherwise, if it is impossible to link physically them (f.e. there is a desert
76
+area between them), they can still be connected with the use of Internet tunnels.
77
+
78
+For more information on this topic go to:
79
+http://lab.dyne.org/Ntk_Internet_tunnels
80
+
81
+=== Documentation ===
82
+
83
+Another useful thing you can do is writing or translating documentation.
84
+Use the wiki: http://lab.dyne.org/Netsukuku
85
+
86
+=== Code ===
87
+
88
+There is a lot to code too! If you are a Kung Foo coder, get on board and
89
+help the development writing some nice poems. For a start you can take a look
90
+at the src/TODO file.
91
+
92
+=== Misc ===
93
+
94
+Finally, every good work you can do is welcomed and it will surely be used,
95
+for example if you like to draw upload your drawings.

+ 36
- 0
doc/misc/Ntk_Internet_tunnels View File

@@ -0,0 +1,36 @@
1
+== Internet tunnels and Netsukuku ==
2
+
3
+Internet tunnels can be used to link Netsukuku nodes.
4
+
5
+Generally, it isn't a good idea because Netsukuku is meant to be a
6
+physical net, in fact, if the links are based on a lower network (the
7
+Internet), Netsukuku becomes dependent on it.
8
+If Netsukuku becomes dependent on another network, all the advantages of
9
+having a parallel net to the Internet are lost.
10
+
11
+However the Internet tunnels can be useful. 
12
+
13
+Consider this scenario:
14
+there two large gnode in two near cities and it is difficult to link the
15
+cities, f.e. using a wireless hook.
16
+In this case they can be linked with the use of Internet tunnels.
17
+
18
+Some of nodes with the best Internet connection will be linked to the nodes of
19
+the other city.  In this way the links will be like real physical links,
20
+because they'll have the same topological meaning, and the delay between the
21
+two gnode won't be high (the cities are near).
22
+Moreover the ISPs will be used to connect two large gnode, therefore the
23
+Netsukuku net will be partially dependent on the Internet.
24
+These tunnels have to be created manually.
25
+
26
+It is important to not create tunnels which undermine the topological meaning
27
+of physical links, thus you must not create a tunnel between Tokyo and
28
+Amsterdam.
29
+
30
+If there is the danger that the ISPs used to create the tunnels will try to
31
+tap them, it is possible to create encrypted tunnels, or even better the
32
+tunnel can be encrypted and routed through different routes using Tor. In the
33
+latter case the link bandwidth will be heavily afflicted therefore this
34
+countermeasure must be used with caution.
35
+
36
+For an example on how to link two nodes using a tunnel see ["Ntk_vpn_test"].

+ 100
- 0
doc/misc/Ntk_features_list View File

@@ -0,0 +1,100 @@
1
+
2
+== Netsukuku features list ==
3
+
4
+{{{
5
+
6
+- The Netsukuku mesh network is: distributed, not hierarchic, and higly
7
+  scalable. The design of Netsukuku prioritises the stability of net.
8
+  For this reason, it isn't specifically suitable for mobile nodes.
9
+  However if the mobile nodes are inside an area covered by static Netsukuku
10
+  nodes, there aren't any problems. It is also possible to use other mesh
11
+  network protocols designed for mobility in conjunction with Netsukuku (f.e.
12
+  see olsrd.org), in the same way they are used in conjunction with the 
13
+  Internet.
14
+  
15
+- Scalability: Netsukuku is specifically designed to handle an unlimited
16
+	       number of nodes with minimal CPU and memory resources.
17
+
18
+	- The net isn't overloaded with discoveries packet
19
+	
20
+	- The size of the maps is fixed: about 4Kb for the int_map and 16Kb
21
+	  for  the ext_map.
22
+	  
23
+	- Not all the nodes sends a broadcast discovery.
24
+	
25
+	- There are few floods for each discovery.
26
+	
27
+	- When a node receives a flood it has already the routes that can be
28
+	  used to reach all the nodes traversed by the flood. It doesn't need
29
+	  to calculate anything about them.
30
+	  
31
+	- A flood is synchronized: the same flood starts at the same time for
32
+	  all the nodes.
33
+
34
+	- http://lab.dyne.org/Netsukuku_scalability
35
+
36
+- zeroconf: the network builds itself, without need of human intervention
37
+
38
+- ANDNA: distributed and not hierarchic DNS
39
+
40
+	- When the net becomes larger, ANDNA scales more because its DB will
41
+	  be distributed among the nodes.
42
+	  
43
+	- Any node can register up to 256 hostnames.
44
+
45
+	- The registration is secure: it is based on asymmetric cryptography,
46
+	  thus it is very difficult to take hostnames which has been already
47
+	  registered by other nodes.
48
+
49
+	- Each hostname can be a string of maximum 512 bytes.
50
+	
51
+	- DNS compatibility: all the network programs are already compatible
52
+	  with ANDNA, because NetsukukuD comes with a DNS wrapper which
53
+	  converts DNS queries to ANDNA requests.
54
+	  
55
+	-  All the resolved hostnames are kept, in the "resolved hostnames
56
+	   cache" to speed up the resolution process. 
57
+	   The rhcache is synchronized with ANDNA, therefore its stored
58
+	   entries will expire exactly when the registered hostnames expire
59
+	   in ANDNA.
60
+	
61
+	- Scattered Name Service Disgregation
62
+	  http://lab.dyne.org/Ntk_SNSD
63
+	  The SNSD is the ANDNA equivalent of the SRV Record of the Internet 
64
+	  Domain Name System, which is defined here:
65
+	  http://www.ietf.org/rfc/rfc2782.txt
66
+	  SNSD isn't the same of the "SRV Record", in fact, it has its own
67
+	  unique features.
68
+
69
+- Internet compatibility
70
+	- internet sharing
71
+		* Multi-inet-gateways. 
72
+		  The Netsukuku nodes will now automatically use multiple
73
+		  inet-gateways to connect to the Internet, therefore their
74
+		  Internet connection will be effectively load-balanced.
75
+		  
76
+		* Anti-loop multi-igw shield. 
77
+		  The nodes which share their Internet connection will also
78
+		  automatically use the shared connection of the other nodes.
79
+		  Through a simple marking system, death loops are avoided.
80
+		  
81
+		* Traffic shaping.
82
+		  The nodes which share their Internet connection can now
83
+		  shape it, in this way they'll prioritize their local
84
+		  outgoingtraffic and the lowdelay one (f.e. SSH).
85
+
86
+- Routes based on bandwidth and latency
87
+  http://lab.dyne.org/Ntk_bandwidth_measurement
88
+
89
+- NetsukukuD:
90
+	- low memory and CPU usage
91
+		- it can run smoothly on a small Access Point
92
+		
93
+	- Support for multipath routes: to reach a destination node, the
94
+	  packets will use, at the same time, more than one route.
95
+	  
96
+	- support for multi network interfaces
97
+	
98
+	- Multi interfaces multipath: if the node can reach a rnode trough
99
+	  multiple interfaces, it uses them all with a multipath route.
100
+}}}

+ 157
- 0
doc/misc/Ntk_scalability View File

@@ -0,0 +1,157 @@
1
+-   QSPN scalability
2
+
3
+The QSPN is an optimised way of "sending a tracer_pkt from each extreme node".
4
+A tracer_pkt is just a flood, and the total number of floods is given by:
5
+
6
+	total_floods = extreme_nodes + 1
7
+	
8
+where the extreme_nodes are:
9
+
10
+	extreme_nodes = number_of_nodes_with_only_one_link + number_of_cycles*2
11
+
12
+A cycle here is meant as a set of nodes, where each node is linked at least at
13
+two other nodes of the set.
14
+
15
+The total different packets generated by a single flood is equal to:
16
+
17
+	total_packets_per_flood = Sum( number_of_links_of_each_node - 1 ) + 1
18
+
19
+Since the network is organized in gnodes, the total_floods for all the levels
20
+will be the sum of the total_floods of each level. The same applies to the
21
+total_packets_per_flood.
22
+
23
+
24
+Now we'll consider various worst scenarios.
25
+
26
+
27
+-  First scenario
28
+
29
+The first worst case is a network where all the nodes are an extreme_node, i.e.
30
+there's one node X and all the other are linked to it by just one link.
31
+
32
+			    O	    Y
33
+			     \	   / 
34
+			      \   /
35
+			 N ---- X ----L
36
+				|
37
+				|
38
+				M	(A graph describing the first worst
39
+					 scenario)
40
+
41
+In this case all the nodes, including X, will send a tracer_pkt.
42
+This means that if all the nodes in the level 0 are linked in that way, and all
43
+the gnodes of the higher levels are also linked between them in the same way,
44
+then the total floods, in all the levels, we'll be:
45
+
46
+	total_floods = MAXGROUPNODE * levels
47
+	
48
+Where MAXGROUPNODE is the number of (g)node present in a gnode.
49
+By the way, this configuration has its advantages because there is only one
50
+hop between each node, therefore each flood will end after one hop and the
51
+total packets will be:
52
+	
53
+	total_packets = MAXGROUPNODE^2 * levels
54
+
55
+MAXGROUPNODE is equal to 256.
56
+In the ipv4 we have 4 levels.
57
+This means that in a network composed by 2^32 nodes, in the first worst
58
+scenario to run the QSPN at all the levels will have:
59
+
60
+	total_floods = 1024; 	total_packets = 262144;
61
+
62
+Note that "levels" is equal to log_2(N)/MAXGROUPNODE_BITS, where N is the
63
+maximum number of nodes in the network and MAXGROUPNODE_BITS is equal to 8.
64
+MAXGROUPNODE is also equal to 2^MAXGROUPNODE_BITS.
65
+The final formulas that describes the growth of the number of floods and
66
+packets are:
67
+
68
+	total_floods = 2^5 * log_2(N)
69
+	
70
+	total_packets = 2^13 * log_2(N)
71
+
72
+
73
+-   Second scenario
74
+
75
+In this case we consider a network where each (g)node is linked to all the other
76
+(g)nodes.
77
+			   C
78
+			  /|\
79
+			 / | \	
80
+			A-----D
81
+			 \ | /
82
+			  \|/
83
+			   E
84
+
85
+That means that we have 1 cycle and 0 nodes_with_only_one_link, so the
86
+total_floods are:
87
+	
88
+	total_floods = 2
89
+
90
+Since every (g)node is linked with every other (g)gnodes, the number of links
91
+for each of them is MAXGROUPNODE and the number of total different packets
92
+generated per flood is:
93
+	
94
+	total_packets = ( ( MAXGROUPNODE - 1 ) * MAXGROUPNODE + 1)
95
+
96
+Supposing that this configuration is the same for the upper levels too, we have:
97
+
98
+	total_floods  = 2 * levels
99
+	total_packets = total_floods * ( ( MAXGROUPNODE - 1 ) * MAXGROUPNODE + 1)
100
+
101
+	N = total_number_of_nodes_in_the_network
102
+	levels = log_2(N)/MAXGROUPNODE_BITS
103
+	
104
+	total_packets = (log_2(N)/4) * ( ( MAXGROUPNODE - 1 ) * MAXGROUPNODE + 1)
105
+
106
+In ipv4, with 2^32 nodes:
107
+
108
+	total_packets = 522248
109
+
110
+-   Third scenario
111
+
112
+All the (g)nodes are in just one line: to reach the end node B from the start
113
+node A we have traverse N nodes, with N equal to the total number of nodes
114
+minus 2.
115
+
116
+In this awful case a flood will have to traverse N hops, this means that if
117
+the average rtt between two nodes is 70ms, then the flood, if started from an
118
+extreme node will take about 9 years to reach the other end.
119
+
120
+-   About the maximum size of a tracer_pkt
121
+
122
+Each time a tracer_pkt traverse a node it grows of one byte, since the
123
+tracer_pkt is always restricted to a determinate level, which has maximum
124
+MAXGROUPNODE nodes, the maximum size of a plain tracer_pkt is 256 Bytes (we
125
+are not counting the headers, which are a constant size).
126
+
127
+The things change if the tracer_pkt traverses border nodes, in fact, 
128
+(7 + 10*L) bytes are added in the the tracer_pkt each time it passes trough a
129
+bnode. L is the number of gnodes the border node is linked to.
130
+
131
+-   About the maximum size of the maps
132
+
133
+The size of levels in the maps is fixed 'cause we already know the maximum number 
134
+of nodes in the network. We are also considering that we store only the 20
135
+best routes for each node.
136
+
137
+So the maximum size of the maps, when we have all the routes stored, and the
138
+bnode with all their maximum links filled is:
139
+
140
+	internal map | external map | border node map 
141
+
142
+ipv4	 44032 	     | 	136704 	    | 	 3159552
143
+		     
144
+ipv6	 44032	     | 	683520      | 	15797760
145
+
146
+(in bytes).
147
+
148
+The bnode map is so large because we are considering the worst case in which
149
+in each of our gnodes there are 256 bnodes each of them is linked to 512
150
+gnodes.
151
+
152
+
153
+-   About the overload created by multiple hooks of (g)nodes
154
+
155
+In order to prevent that a QSPN is sent every time a (g)node joins the network
156
+the QSPN are all syncronised in each level, therefore the maps are updated at
157
+each qspn_round. (Read the section  "5.1.4 Qspn round").

+ 12
- 0
doc/misc/mailinglist View File

@@ -0,0 +1,12 @@
1
+Subscribe to the netsukuku mailing to get help, be updated on the latest news
2
+and discuss on its development.
3
+
4
+To subscribe to the list, send a message to:
5
+    netsukuku-subscribe@lists.dyne.org
6
+
7
+or use the web interface:
8
+    http://lists.dyne.org/mailman/listinfo/netsukuku
9
+   
10
+You can browse the archive here:
11
+    http://lists.dyne.org/netsukuku/
12
+    http://dir.gmane.org/gmane.network.peer-to-peer.netsukuku

+ 3077
- 0
doc/misc/rfc1035.txt
File diff suppressed because it is too large
View File


+ 323
- 0
install-sh View File

@@ -0,0 +1,323 @@
1
+#!/bin/sh
2
+# install - install a program, script, or datafile
3
+
4
+scriptversion=2005-05-14.22
5
+
6
+# This originates from X11R5 (mit/util/scripts/install.sh), which was
7
+# later released in X11R6 (xc/config/util/install.sh) with the
8
+# following copyright and license.
9
+#
10
+# Copyright (C) 1994 X Consortium
11
+#
12
+# Permission is hereby granted, free of charge, to any person obtaining a copy
13
+# of this software and associated documentation files (the "Software"), to
14
+# deal in the Software without restriction, including without limitation the
15
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16
+# sell copies of the Software, and to permit persons to whom the Software is
17
+# furnished to do so, subject to the following conditions:
18
+#
19
+# The above copyright notice and this permission notice shall be included in
20
+# all copies or substantial portions of the Software.
21
+#
22
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
25
+# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
27
+# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+#
29
+# Except as contained in this notice, the name of the X Consortium shall not
30
+# be used in advertising or otherwise to promote the sale, use or other deal-
31
+# ings in this Software without prior written authorization from the X Consor-
32
+# tium.
33
+#
34
+#
35
+# FSF changes to this file are in the public domain.
36
+#
37
+# Calling this script install-sh is preferred over install.sh, to prevent
38
+# `make' implicit rules from creating a file called install from it
39
+# when there is no Makefile.
40
+#
41
+# This script is compatible with the BSD install script, but was written
42
+# from scratch.  It can only install one file at a time, a restriction
43
+# shared with many OS's install programs.
44
+
45
+# set DOITPROG to echo to test this script
46
+
47
+# Don't use :- since 4.3BSD and earlier shells don't like it.
48
+doit="${DOITPROG-}"
49
+
50
+# put in absolute paths if you don't have them in your path; or use env. vars.
51
+
52
+mvprog="${MVPROG-mv}"
53
+cpprog="${CPPROG-cp}"
54
+chmodprog="${CHMODPROG-chmod}"
55
+chownprog="${CHOWNPROG-chown}"
56
+chgrpprog="${CHGRPPROG-chgrp}"
57
+stripprog="${STRIPPROG-strip}"
58
+rmprog="${RMPROG-rm}"
59
+mkdirprog="${MKDIRPROG-mkdir}"
60
+
61
+chmodcmd="$chmodprog 0755"
62
+chowncmd=
63
+chgrpcmd=
64
+stripcmd=
65
+rmcmd="$rmprog -f"
66
+mvcmd="$mvprog"
67
+src=
68
+dst=
69
+dir_arg=
70
+dstarg=
71
+no_target_directory=
72
+
73
+usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
74
+   or: $0 [OPTION]... SRCFILES... DIRECTORY
75
+   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
76
+   or: $0 [OPTION]... -d DIRECTORIES...
77
+
78
+In the 1st form, copy SRCFILE to DSTFILE.
79
+In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
80
+In the 4th, create DIRECTORIES.
81
+
82
+Options:
83
+-c         (ignored)
84
+-d         create directories instead of installing files.
85
+-g GROUP   $chgrpprog installed files to GROUP.
86
+-m MODE    $chmodprog installed files to MODE.
87
+-o USER    $chownprog installed files to USER.
88
+-s         $stripprog installed files.
89
+-t DIRECTORY  install into DIRECTORY.
90
+-T         report an error if DSTFILE is a directory.
91
+--help     display this help and exit.
92
+--version  display version info and exit.
93
+
94
+Environment variables override the default commands:
95
+  CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
96
+"
97
+
98
+while test -n "$1"; do
99
+  case $1 in
100
+    -c) shift
101
+        continue;;
102
+
103
+    -d) dir_arg=true
104
+        shift
105
+        continue;;
106
+
107
+    -g) chgrpcmd="$chgrpprog $2"
108
+        shift
109
+        shift
110
+        continue;;
111
+
112
+    --help) echo "$usage"; exit $?;;
113
+
114
+    -m) chmodcmd="$chmodprog $2"
115
+        shift
116
+        shift
117
+        continue;;
118
+
119
+    -o) chowncmd="$chownprog $2"
120
+        shift
121
+        shift
122
+        continue;;
123
+
124
+    -s) stripcmd=$stripprog
125
+        shift
126
+        continue;;
127
+
128
+    -t) dstarg=$2
129
+	shift
130
+	shift
131
+	continue;;
132
+
133
+    -T) no_target_directory=true
134
+	shift
135
+	continue;;
136
+
137
+    --version) echo "$0 $scriptversion"; exit $?;;
138
+
139
+    *)  # When -d is used, all remaining arguments are directories to create.
140
+	# When -t is used, the destination is already specified.
141
+	test -n "$dir_arg$dstarg" && break
142
+        # Otherwise, the last argument is the destination.  Remove it from $@.
143
+	for arg
144
+	do
145
+          if test -n "$dstarg"; then
146
+	    # $@ is not empty: it contains at least $arg.
147
+	    set fnord "$@" "$dstarg"
148
+	    shift # fnord
149
+	  fi
150
+	  shift # arg
151
+	  dstarg=$arg
152
+	done
153
+	break;;
154
+  esac
155
+done
156
+
157
+if test -z "$1"; then
158
+  if test -z "$dir_arg"; then
159
+    echo "$0: no input file specified." >&2
160
+    exit 1
161
+  fi
162
+  # It's OK to call `install-sh -d' without argument.
163
+  # This can happen when creating conditional directories.
164
+  exit 0
165
+fi
166
+
167
+for src
168
+do
169
+  # Protect names starting with `-'.
170
+  case $src in
171
+    -*) src=./$src ;;
172
+  esac
173
+
174
+  if test -n "$dir_arg"; then
175
+    dst=$src
176
+    src=
177
+
178
+    if test -d "$dst"; then
179
+      mkdircmd=:
180
+      chmodcmd=
181
+    else
182
+      mkdircmd=$mkdirprog
183
+    fi
184
+  else
185
+    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
186
+    # might cause directories to be created, which would be especially bad
187
+    # if $src (and thus $dsttmp) contains '*'.
188
+    if test ! -f "$src" && test ! -d "$src"; then
189
+      echo "$0: $src does not exist." >&2
190
+      exit 1
191
+    fi
192
+
193
+    if test -z "$dstarg"; then
194
+      echo "$0: no destination specified." >&2
195
+      exit 1
196
+    fi
197
+
198
+    dst=$dstarg
199
+    # Protect names starting with `-'.
200
+    case $dst in
201
+      -*) dst=./$dst ;;
202
+    esac
203
+
204
+    # If destination is a directory, append the input filename; won't work
205
+    # if double slashes aren't ignored.
206
+    if test -d "$dst"; then
207
+      if test -n "$no_target_directory"; then
208
+	echo "$0: $dstarg: Is a directory" >&2
209
+	exit 1
210
+      fi
211
+      dst=$dst/`basename "$src"`
212
+    fi
213
+  fi
214
+
215
+  # This sed command emulates the dirname command.
216
+  dstdir=`echo "$dst" | sed -e 's,/*$,,;s,[^/]*$,,;s,/*$,,;s,^$,.,'`
217
+
218
+  # Make sure that the destination directory exists.
219
+
220
+  # Skip lots of stat calls in the usual case.
221
+  if test ! -d "$dstdir"; then
222
+    defaultIFS='
223
+	 '
224
+    IFS="${IFS-$defaultIFS}"
225
+
226
+    oIFS=$IFS
227
+    # Some sh's can't handle IFS=/ for some reason.
228
+    IFS='%'
229
+    set x `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
230
+    shift
231
+    IFS=$oIFS
232
+
233
+    pathcomp=
234
+
235
+    while test $# -ne 0 ; do
236
+      pathcomp=$pathcomp$1
237
+      shift
238
+      if test ! -d "$pathcomp"; then
239
+        $mkdirprog "$pathcomp"
240
+	# mkdir can fail with a `File exist' error in case several
241
+	# install-sh are creating the directory concurrently.  This
242
+	# is OK.
243
+	test -d "$pathcomp" || exit
244
+      fi
245
+      pathcomp=$pathcomp/
246
+    done
247
+  fi
248
+
249
+  if test -n "$dir_arg"; then
250
+    $doit $mkdircmd "$dst" \
251
+      && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
252
+      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
253
+      && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
254
+      && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
255
+
256
+  else
257
+    dstfile=`basename "$dst"`
258
+
259
+    # Make a couple of temp file names in the proper directory.
260
+    dsttmp=$dstdir/_inst.$$_
261
+    rmtmp=$dstdir/_rm.$$_
262
+
263
+    # Trap to clean up those temp files at exit.
264
+    trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
265
+    trap '(exit $?); exit' 1 2 13 15
266
+
267
+    # Copy the file name to the temp name.
268
+    $doit $cpprog "$src" "$dsttmp" &&
269
+
270
+    # and set any options; do chmod last to preserve setuid bits.
271
+    #
272
+    # If any of these fail, we abort the whole thing.  If we want to
273
+    # ignore errors from any of these, just make sure not to ignore
274
+    # errors from the above "$doit $cpprog $src $dsttmp" command.
275
+    #
276
+    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
277
+      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
278
+      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
279
+      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
280
+
281
+    # Now rename the file to the real destination.
282
+    { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
283
+      || {
284
+	   # The rename failed, perhaps because mv can't rename something else
285
+	   # to itself, or perhaps because mv is so ancient that it does not
286
+	   # support -f.
287
+
288
+	   # Now remove or move aside any old file at destination location.
289
+	   # We try this two ways since rm can't unlink itself on some
290
+	   # systems and the destination file might be busy for other
291
+	   # reasons.  In this case, the final cleanup might fail but the new
292
+	   # file should still install successfully.
293
+	   {
294
+	     if test -f "$dstdir/$dstfile"; then
295
+	       $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
296
+	       || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
297
+	       || {
298
+		 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
299
+		 (exit 1); exit 1
300
+	       }
301
+	     else
302
+	       :
303
+	     fi
304
+	   } &&
305
+
306
+	   # Now rename the file to the real destination.
307
+	   $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
308
+	 }
309
+    }
310
+  fi || { (exit 1); exit 1; }
311
+done
312
+
313
+# The final little trick to "correctly" pass the exit status to the exit trap.
314
+{
315
+  (exit 0); exit 0
316
+}
317
+
318
+# Local variables:
319
+# eval: (add-hook 'write-file-hooks 'time-stamp)
320
+# time-stamp-start: "scriptversion="
321
+# time-stamp-format: "%:y-%02m-%02d.%02H"
322
+# time-stamp-end: "$"
323
+# End:

+ 360
- 0
missing View File

@@ -0,0 +1,360 @@
1
+#! /bin/sh
2
+# Common stub for a few missing GNU programs while installing.
3
+
4
+scriptversion=2005-06-08.21
5
+
6
+# Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2004, 2005
7
+#   Free Software Foundation, Inc.
8
+# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
9
+
10
+# This program is free software; you can redistribute it and/or modify
11
+# it under the terms of the GNU General Public License as published by
12
+# the Free Software Foundation; either version 2, or (at your option)
13
+# any later version.
14
+
15
+# This program is distributed in the hope that it will be useful,
16
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+# GNU General Public License for more details.
19
+
20
+# You should have received a copy of the GNU General Public License
21
+# along with this program; if not, write to the Free Software
22
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23
+# 02110-1301, USA.
24
+
25
+# As a special exception to the GNU General Public License, if you
26
+# distribute this file as part of a program that contains a
27
+# configuration script generated by Autoconf, you may include it under
28
+# the same distribution terms that you use for the rest of that program.
29
+
30
+if test $# -eq 0; then
31
+  echo 1>&2 "Try \`$0 --help' for more information"
32
+  exit 1
33
+fi
34
+
35
+run=:
36
+
37
+# In the cases where this matters, `missing' is being run in the
38
+# srcdir already.
39
+if test -f configure.ac; then
40
+  configure_ac=configure.ac
41
+else
42
+  configure_ac=configure.in
43
+fi
44
+
45
+msg="missing on your system"
46
+
47
+case "$1" in
48
+--run)
49
+  # Try to run requested program, and just exit if it succeeds.
50
+  run=
51
+  shift
52
+  "$@" && exit 0
53
+  # Exit code 63 means version mismatch.  This often happens
54
+  # when the user try to use an ancient version of a tool on
55
+  # a file that requires a minimum version.  In this case we
56
+  # we should proceed has if the program had been absent, or
57
+  # if --run hadn't been passed.
58
+  if test $? = 63; then
59
+    run=:
60
+    msg="probably too old"
61
+  fi
62
+  ;;
63
+
64
+  -h|--h|--he|--hel|--help)
65
+    echo "\
66
+$0 [OPTION]... PROGRAM [ARGUMENT]...
67
+
68
+Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an
69
+error status if there is no known handling for PROGRAM.
70
+
71
+Options:
72
+  -h, --help      display this help and exit
73
+  -v, --version   output version information and exit
74
+  --run           try to run the given command, and emulate it if it fails
75
+
76
+Supported PROGRAM values:
77
+  aclocal      touch file \`aclocal.m4'
78
+  autoconf     touch file \`configure'
79
+  autoheader   touch file \`config.h.in'
80
+  automake     touch all \`Makefile.in' files
81
+  bison        create \`y.tab.[ch]', if possible, from existing .[ch]
82
+  flex         create \`lex.yy.c', if possible, from existing .c
83
+  help2man     touch the output file
84
+  lex          create \`lex.yy.c', if possible, from existing .c
85
+  makeinfo     touch the output file
86
+  tar          try tar, gnutar, gtar, then tar without non-portable flags
87
+  yacc         create \`y.tab.[ch]', if possible, from existing .[ch]
88
+
89
+Send bug reports to <bug-automake@gnu.org>."
90
+    exit $?
91
+    ;;
92
+
93
+  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
94
+    echo "missing $scriptversion (GNU Automake)"
95
+    exit $?
96
+    ;;
97
+
98
+  -*)
99
+    echo 1>&2 "$0: Unknown \`$1' option"
100
+    echo 1>&2 "Try \`$0 --help' for more information"
101
+    exit 1
102
+    ;;
103
+
104
+esac
105
+
106
+# Now exit if we have it, but it failed.  Also exit now if we
107
+# don't have it and --version was passed (most likely to detect
108
+# the program).
109
+case "$1" in
110
+  lex|yacc)
111
+    # Not GNU programs, they don't have --version.
112
+    ;;
113
+
114
+  tar)
115
+    if test -n "$run"; then
116
+       echo 1>&2 "ERROR: \`tar' requires --run"
117
+       exit 1
118
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
119
+       exit 1
120
+    fi
121
+    ;;
122
+
123
+  *)
124
+    if test -z "$run" && ($1 --version) > /dev/null 2>&1; then
125
+       # We have it, but it failed.
126
+       exit 1
127
+    elif test "x$2" = "x--version" || test "x$2" = "x--help"; then
128
+       # Could not run --version or --help.  This is probably someone
129
+       # running `$TOOL --version' or `$TOOL --help' to check whether
130
+       # $TOOL exists and not knowing $TOOL uses missing.
131
+       exit 1
132
+    fi
133
+    ;;
134
+esac
135
+
136
+# If it does not exist, or fails to run (possibly an outdated version),
137
+# try to emulate it.
138
+case "$1" in
139
+  aclocal*)
140
+    echo 1>&2 "\
141
+WARNING: \`$1' is $msg.  You should only need it if
142
+         you modified \`acinclude.m4' or \`${configure_ac}'.  You might want
143
+         to install the \`Automake' and \`Perl' packages.  Grab them from
144
+         any GNU archive site."
145
+    touch aclocal.m4
146
+    ;;
147
+
148
+  autoconf)
149
+    echo 1>&2 "\
150
+WARNING: \`$1' is $msg.  You should only need it if
151
+         you modified \`${configure_ac}'.  You might want to install the
152
+         \`Autoconf' and \`GNU m4' packages.  Grab them from any GNU
153
+         archive site."
154
+    touch configure
155
+    ;;
156
+
157
+  autoheader)
158
+    echo 1>&2 "\
159
+WARNING: \`$1' is $msg.  You should only need it if
160
+         you modified \`acconfig.h' or \`${configure_ac}'.  You might want
161
+         to install the \`Autoconf' and \`GNU m4' packages.  Grab them
162
+         from any GNU archive site."
163
+    files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}`
164
+    test -z "$files" && files="config.h"
165
+    touch_files=
166
+    for f in $files; do
167
+      case "$f" in
168
+      *:*) touch_files="$touch_files "`echo "$f" |
169
+				       sed -e 's/^[^:]*://' -e 's/:.*//'`;;
170
+      *) touch_files="$touch_files $f.in";;
171
+      esac
172
+    done
173
+    touch $touch_files
174
+    ;;
175
+
176
+  automake*)
177
+    echo 1>&2 "\
178
+WARNING: \`$1' is $msg.  You should only need it if
179
+         you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'.
180
+         You might want to install the \`Automake' and \`Perl' packages.
181
+         Grab them from any GNU archive site."
182
+    find . -type f -name Makefile.am -print |
183
+	   sed 's/\.am$/.in/' |
184
+	   while read f; do touch "$f"; done
185
+    ;;
186
+
187
+  autom4te)
188
+    echo 1>&2 "\
189
+WARNING: \`$1' is needed, but is $msg.
190
+         You might have modified some files without having the
191
+         proper tools for further handling them.
192
+         You can get \`$1' as part of \`Autoconf' from any GNU
193
+         archive site."
194
+
195
+    file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'`
196
+    test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'`
197
+    if test -f "$file"; then
198
+	touch $file
199
+    else
200
+	test -z "$file" || exec >$file
201
+	echo "#! /bin/sh"
202
+	echo "# Created by GNU Automake missing as a replacement of"
203
+	echo "#  $ $@"
204
+	echo "exit 0"
205
+	chmod +x $file
206
+	exit 1
207
+    fi
208
+    ;;
209
+
210
+  bison|yacc)
211
+    echo 1>&2 "\
212
+WARNING: \`$1' $msg.  You should only need it if
213
+         you modified a \`.y' file.  You may need the \`Bison' package
214
+         in order for those modifications to take effect.  You can get
215
+         \`Bison' from any GNU archive site."
216
+    rm -f y.tab.c y.tab.h
217
+    if [ $# -ne 1 ]; then
218
+        eval LASTARG="\${$#}"
219
+	case "$LASTARG" in
220
+	*.y)
221
+	    SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'`
222
+	    if [ -f "$SRCFILE" ]; then
223
+	         cp "$SRCFILE" y.tab.c
224
+	    fi
225
+	    SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'`
226
+	    if [ -f "$SRCFILE" ]; then
227
+	         cp "$SRCFILE" y.tab.h
228
+	    fi
229
+	  ;;
230
+	esac
231
+    fi
232
+    if [ ! -f y.tab.h ]; then
233
+	echo >y.tab.h
234
+    fi
235
+    if [ ! -f y.tab.c ]; then
236
+	echo 'main() { return 0; }' >y.tab.c
237
+    fi
238
+    ;;
239
+
240
+  lex|flex)
241
+    echo 1>&2 "\
242
+WARNING: \`$1' is $msg.  You should only need it if
243
+         you modified a \`.l' file.  You may need the \`Flex' package
244
+         in order for those modifications to take effect.  You can get
245
+         \`Flex' from any GNU archive site."
246
+    rm -f lex.yy.c
247
+    if [ $# -ne 1 ]; then
248
+        eval LASTARG="\${$#}"
249
+	case "$LASTARG" in
250
+	*.l)
251
+	    SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'`
252
+	    if [ -f "$SRCFILE" ]; then
253
+	         cp "$SRCFILE" lex.yy.c
254
+	    fi
255
+	  ;;
256
+	esac
257
+    fi
258
+    if [ ! -f lex.yy.c ]; then
259
+	echo 'main() { return 0; }' >lex.yy.c
260
+    fi
261
+    ;;
262
+
263
+  help2man)
264
+    echo 1>&2 "\
265
+WARNING: \`$1' is $msg.  You should only need it if
266
+	 you modified a dependency of a manual page.  You may need the
267
+	 \`Help2man' package in order for those modifications to take
268
+	 effect.  You can get \`Help2man' from any GNU archive site."
269
+
270
+    file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
271
+    if test -z "$file"; then
272
+	file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'`
273
+    fi
274
+    if [ -f "$file" ]; then
275
+	touch $file
276
+    else
277
+	test -z "$file" || exec >$file
278
+	echo ".ab help2man is required to generate this page"
279
+	exit 1
280
+    fi
281
+    ;;
282
+
283
+  makeinfo)
284
+    echo 1>&2 "\
285
+WARNING: \`$1' is $msg.  You should only need it if
286
+         you modified a \`.texi' or \`.texinfo' file, or any other file
287
+         indirectly affecting the aspect of the manual.  The spurious
288
+         call might also be the consequence of using a buggy \`make' (AIX,
289
+         DU, IRIX).  You might want to install the \`Texinfo' package or
290
+         the \`GNU make' package.  Grab either from any GNU archive site."
291
+    # The file to touch is that specified with -o ...
292
+    file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'`
293
+    if test -z "$file"; then
294
+      # ... or it is the one specified with @setfilename ...
295
+      infile=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'`
296
+      file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $infile`
297
+      # ... or it is derived from the source name (dir/f.texi becomes f.info)
298
+      test -z "$file" && file=`echo "$infile" | sed 's,.*/,,;s,.[^.]*$,,'`.info
299
+    fi
300
+    # If the file does not exist, the user really needs makeinfo;
301
+    # let's fail without touching anything.
302
+    test -f $file || exit 1
303
+    touch $file
304
+    ;;
305
+
306
+  tar)
307
+    shift
308
+
309
+    # We have already tried tar in the generic part.
310
+    # Look for gnutar/gtar before invocation to avoid ugly error
311
+    # messages.
312
+    if (gnutar --version > /dev/null 2>&1); then
313
+       gnutar "$@" && exit 0
314
+    fi
315
+    if (gtar --version > /dev/null 2>&1); then
316
+       gtar "$@" && exit 0
317
+    fi
318
+    firstarg="$1"
319
+    if shift; then
320
+	case "$firstarg" in
321
+	*o*)
322
+	    firstarg=`echo "$firstarg" | sed s/o//`
323
+	    tar "$firstarg" "$@" && exit 0
324
+	    ;;
325
+	esac
326
+	case "$firstarg" in
327
+	*h*)
328
+	    firstarg=`echo "$firstarg" | sed s/h//`
329
+	    tar "$firstarg" "$@" && exit 0
330
+	    ;;
331
+	esac
332
+    fi
333
+
334
+    echo 1>&2 "\
335
+WARNING: I can't seem to be able to run \`tar' with the given arguments.
336
+         You may want to install GNU tar or Free paxutils, or check the
337
+         command line arguments."
338
+    exit 1
339
+    ;;
340
+
341
+  *)
342
+    echo 1>&2 "\
343
+WARNING: \`$1' is needed, and is $msg.
344
+         You might have modified some files without having the
345
+         proper tools for further handling them.  Check the \`README' file,
346
+         it often tells you about the needed prerequisites for installing
347
+         this package.  You may also peek at any GNU archive site, in case
348
+         some other package would contain this missing \`$1' program."
349
+    exit 1
350
+    ;;
351
+esac
352
+
353
+exit 0
354
+
355
+# Local variables:
356
+# eval: (add-hook 'write-file-hooks 'time-stamp)
357
+# time-stamp-start: "scriptversion="
358
+# time-stamp-format: "%:y-%02m-%02d.%02H"
359
+# time-stamp-end: "$"
360
+# End:

+ 21
- 0
src/Makefile.am View File

@@ -0,0 +1,21 @@
1
+SUBDIRS = man scripts conf
2
+
3
+AM_CFLAGS= -g -I. @debug_flags@ -I@gmp@
4
+AM_CXXFLAGS = -g -I. @debug_flags@ -I@gmp@
5
+
6
+bin_PROGRAMS = ntkd ntk-resolv
7
+ntkd_SOURCES = accept.c map.c misc.c buffer.c hash.c pkts.c qspn.c   \
8
+	request.c  \
9
+	radar.c gmap.c hook.c rehook.c if.c inet.c ipv6-gmp.c        \
10
+	krnl_route.c andna.c snsd_cache.c andna_cache.c err_errno.c  \
11
+	andns.c andns_lib.c dnslib.c andns_net.c andns_snsd.c	     \
12
+	bmap.c  conf.c crypto.c daemon.c dns_wrapper.c endianness.c  \
13
+	krnl_rule.c iptunnel.c libnetlink.c ll_map.c llist.c log.c   \
14
+	route.c tracer.c igs.c libping.c xmalloc.c netsukuku.c       \
15
+	mark.c libiptc/libip4tc.c
16
+ntkd_LDADD = -lpthread -lgmp -lcrypto -lresolv -lz
17
+
18
+ntk_resolv_SOURCES = andns_lib.c ntkresolv.c andns_net.c crypto.c    \
19
+		  snsd_cache.c inet.c ll_map.c libnetlink.c log.c    \
20
+		  xmalloc.c endianness.c misc.c err_errno.c buffer.c
21
+ntk_resolv_LDADD = -lz -lcrypto

+ 656
- 0
src/Makefile.in View File

@@ -0,0 +1,656 @@
1
+# Makefile.in generated by automake 1.8.5 from Makefile.am.
2
+# @configure_input@
3
+
4
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5
+# 2003, 2004  Free Software Foundation, Inc.
6
+# This Makefile.in is free software; the Free Software Foundation
7
+# gives unlimited permission to copy and/or distribute it,
8
+# with or without modifications, as long as this notice is preserved.
9
+
10
+# This program is distributed in the hope that it will be useful,
11
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
12
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13
+# PARTICULAR PURPOSE.
14
+
15
+@SET_MAKE@
16
+
17
+SOURCES = $(ntk_resolv_SOURCES) $(ntkd_SOURCES)
18
+
19
+srcdir = @srcdir@
20
+top_srcdir = @top_srcdir@
21
+VPATH = @srcdir@
22
+pkgdatadir = $(datadir)/@PACKAGE@
23
+pkglibdir = $(libdir)/@PACKAGE@
24
+pkgincludedir = $(includedir)/@PACKAGE@
25
+top_builddir = ..
26
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
27
+INSTALL = @INSTALL@
28
+install_sh_DATA = $(install_sh) -c -m 644
29
+install_sh_PROGRAM = $(install_sh) -c
30
+install_sh_SCRIPT = $(install_sh) -c
31
+INSTALL_HEADER = $(INSTALL_DATA)
32
+transform = $(program_transform_name)
33
+NORMAL_INSTALL = :
34
+PRE_INSTALL = :
35
+POST_INSTALL = :
36
+NORMAL_UNINSTALL = :
37
+PRE_UNINSTALL = :
38
+POST_UNINSTALL = :
39
+host_triplet = @host@
40
+bin_PROGRAMS = ntkd$(EXEEXT) ntk-resolv$(EXEEXT)
41
+subdir = src
42
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
43
+	$(srcdir)/config.h.in TODO
44
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
45
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
46
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
47
+	$(ACLOCAL_M4)
48
+mkinstalldirs = $(mkdir_p)
49
+CONFIG_HEADER = config.h
50
+CONFIG_CLEAN_FILES =
51
+am__installdirs = "$(DESTDIR)$(bindir)"
52
+binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
53
+PROGRAMS = $(bin_PROGRAMS)
54
+am_ntk_resolv_OBJECTS = andns_lib.$(OBJEXT) ntkresolv.$(OBJEXT) \
55
+	andns_net.$(OBJEXT) crypto.$(OBJEXT) snsd_cache.$(OBJEXT) \
56
+	inet.$(OBJEXT) ll_map.$(OBJEXT) libnetlink.$(OBJEXT) \
57
+	log.$(OBJEXT) xmalloc.$(OBJEXT) endianness.$(OBJEXT) \
58
+	misc.$(OBJEXT) err_errno.$(OBJEXT) buffer.$(OBJEXT)
59
+ntk_resolv_OBJECTS = $(am_ntk_resolv_OBJECTS)
60
+ntk_resolv_DEPENDENCIES =
61
+am_ntkd_OBJECTS = accept.$(OBJEXT) map.$(OBJEXT) misc.$(OBJEXT) \
62
+	buffer.$(OBJEXT) hash.$(OBJEXT) pkts.$(OBJEXT) qspn.$(OBJEXT) \
63
+	request.$(OBJEXT) radar.$(OBJEXT) gmap.$(OBJEXT) \
64
+	hook.$(OBJEXT) rehook.$(OBJEXT) if.$(OBJEXT) inet.$(OBJEXT) \
65
+	ipv6-gmp.$(OBJEXT) krnl_route.$(OBJEXT) andna.$(OBJEXT) \
66
+	snsd_cache.$(OBJEXT) andna_cache.$(OBJEXT) err_errno.$(OBJEXT) \
67
+	andns.$(OBJEXT) andns_lib.$(OBJEXT) dnslib.$(OBJEXT) \
68
+	andns_net.$(OBJEXT) andns_snsd.$(OBJEXT) bmap.$(OBJEXT) \
69
+	conf.$(OBJEXT) crypto.$(OBJEXT) daemon.$(OBJEXT) \
70
+	dns_wrapper.$(OBJEXT) endianness.$(OBJEXT) krnl_rule.$(OBJEXT) \
71
+	iptunnel.$(OBJEXT) libnetlink.$(OBJEXT) ll_map.$(OBJEXT) \
72
+	llist.$(OBJEXT) log.$(OBJEXT) route.$(OBJEXT) tracer.$(OBJEXT) \
73
+	igs.$(OBJEXT) libping.$(OBJEXT) xmalloc.$(OBJEXT) \
74
+	netsukuku.$(OBJEXT) mark.$(OBJEXT) libip4tc.$(OBJEXT)
75
+ntkd_OBJECTS = $(am_ntkd_OBJECTS)
76
+ntkd_DEPENDENCIES =
77
+DEFAULT_INCLUDES = -I. -I$(srcdir) -I.
78
+depcomp = $(SHELL) $(top_srcdir)/depcomp
79
+am__depfiles_maybe = depfiles
80
+@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/accept.Po ./$(DEPDIR)/andna.Po \
81
+@AMDEP_TRUE@	./$(DEPDIR)/andna_cache.Po ./$(DEPDIR)/andns.Po \
82
+@AMDEP_TRUE@	./$(DEPDIR)/andns_lib.Po ./$(DEPDIR)/andns_net.Po \
83
+@AMDEP_TRUE@	./$(DEPDIR)/andns_snsd.Po ./$(DEPDIR)/bmap.Po \
84
+@AMDEP_TRUE@	./$(DEPDIR)/buffer.Po ./$(DEPDIR)/conf.Po \
85
+@AMDEP_TRUE@	./$(DEPDIR)/crypto.Po ./$(DEPDIR)/daemon.Po \
86
+@AMDEP_TRUE@	./$(DEPDIR)/dns_wrapper.Po ./$(DEPDIR)/dnslib.Po \
87
+@AMDEP_TRUE@	./$(DEPDIR)/endianness.Po ./$(DEPDIR)/err_errno.Po \
88
+@AMDEP_TRUE@	./$(DEPDIR)/gmap.Po ./$(DEPDIR)/hash.Po \
89
+@AMDEP_TRUE@	./$(DEPDIR)/hook.Po ./$(DEPDIR)/if.Po \
90
+@AMDEP_TRUE@	./$(DEPDIR)/igs.Po ./$(DEPDIR)/inet.Po \
91
+@AMDEP_TRUE@	./$(DEPDIR)/iptunnel.Po ./$(DEPDIR)/ipv6-gmp.Po \
92
+@AMDEP_TRUE@	./$(DEPDIR)/krnl_route.Po ./$(DEPDIR)/krnl_rule.Po \
93
+@AMDEP_TRUE@	./$(DEPDIR)/libip4tc.Po ./$(DEPDIR)/libnetlink.Po \
94
+@AMDEP_TRUE@	./$(DEPDIR)/libping.Po ./$(DEPDIR)/ll_map.Po \
95
+@AMDEP_TRUE@	./$(DEPDIR)/llist.Po ./$(DEPDIR)/log.Po \
96
+@AMDEP_TRUE@	./$(DEPDIR)/map.Po ./$(DEPDIR)/mark.Po \
97
+@AMDEP_TRUE@	./$(DEPDIR)/misc.Po ./$(DEPDIR)/netsukuku.Po \
98
+@AMDEP_TRUE@	./$(DEPDIR)/ntkresolv.Po ./$(DEPDIR)/pkts.Po \
99
+@AMDEP_TRUE@	./$(DEPDIR)/qspn.Po ./$(DEPDIR)/radar.Po \
100
+@AMDEP_TRUE@	./$(DEPDIR)/rehook.Po ./$(DEPDIR)/request.Po \
101
+@AMDEP_TRUE@	./$(DEPDIR)/route.Po ./$(DEPDIR)/snsd_cache.Po \
102
+@AMDEP_TRUE@	./$(DEPDIR)/tracer.Po ./$(DEPDIR)/xmalloc.Po
103
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
104
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
105
+CCLD = $(CC)
106
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
107
+SOURCES = $(ntk_resolv_SOURCES) $(ntkd_SOURCES)
108
+DIST_SOURCES = $(ntk_resolv_SOURCES) $(ntkd_SOURCES)
109
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
110
+	html-recursive info-recursive install-data-recursive \
111
+	install-exec-recursive install-info-recursive \
112
+	install-recursive installcheck-recursive installdirs-recursive \
113
+	pdf-recursive ps-recursive uninstall-info-recursive \
114
+	uninstall-recursive
115
+ETAGS = etags
116
+CTAGS = ctags
117
+DIST_SUBDIRS = $(SUBDIRS)
118
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
119
+ACLOCAL = @ACLOCAL@
120
+AMDEP_FALSE = @AMDEP_FALSE@
121
+AMDEP_TRUE = @AMDEP_TRUE@
122
+AMTAR = @AMTAR@
123
+AUTOCONF = @AUTOCONF@
124
+AUTOHEADER = @AUTOHEADER@
125
+AUTOMAKE = @AUTOMAKE@
126
+AWK = @AWK@
127
+CC = @CC@
128
+CCDEPMODE = @CCDEPMODE@
129
+CFLAGS = @CFLAGS@
130
+CONF_DIR = @CONF_DIR@
131
+CPP = @CPP@
132
+CPPFLAGS = @CPPFLAGS@
133
+CXX = @CXX@
134
+CXXDEPMODE = @CXXDEPMODE@
135
+CXXFLAGS = @CXXFLAGS@
136
+CYGPATH_W = @CYGPATH_W@
137
+DATA_DIR = @DATA_DIR@
138
+DEFS = @DEFS@
139
+DEPDIR = @DEPDIR@
140
+ECHO_C = @ECHO_C@
141
+ECHO_N = @ECHO_N@
142
+ECHO_T = @ECHO_T@
143
+EGREP = @EGREP@
144
+EXEEXT = @EXEEXT@
145
+IF_METHOD = @IF_METHOD@
146
+INSTALL_DATA = @INSTALL_DATA@
147
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
148
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
149
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
150
+KERNEL_METHOD = @KERNEL_METHOD@
151
+LDFLAGS = @LDFLAGS@
152
+LIBOBJS = @LIBOBJS@
153
+LIBS = @LIBS@
154
+LTLIBOBJS = @LTLIBOBJS@
155
+MAKEINFO = @MAKEINFO@
156
+OBJEXT = @OBJEXT@
157
+OTHER_METHOD = @OTHER_METHOD@
158
+PACKAGE = @PACKAGE@
159
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
160
+PACKAGE_NAME = @PACKAGE_NAME@
161
+PACKAGE_STRING = @PACKAGE_STRING@
162
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
163
+PACKAGE_VERSION = @PACKAGE_VERSION@
164
+PATH_SEPARATOR = @PATH_SEPARATOR@
165
+PID_DIR = @PID_DIR@
166
+RT_METHOD = @RT_METHOD@
167
+SET_MAKE = @SET_MAKE@
168
+SHELL = @SHELL@
169
+STRIP = @STRIP@
170
+VERSION = @VERSION@
171
+ac_ct_CC = @ac_ct_CC@
172
+ac_ct_CXX = @ac_ct_CXX@
173
+ac_ct_STRIP = @ac_ct_STRIP@
174
+am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
175
+am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
176
+am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
177
+am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
178
+am__include = @am__include@
179
+am__leading_dot = @am__leading_dot@
180
+am__quote = @am__quote@
181
+bindir = @bindir@
182
+build = @build@
183
+build_alias = @build_alias@
184
+build_cpu = @build_cpu@
185
+build_os = @build_os@
186
+build_vendor = @build_vendor@
187
+datadir = @datadir@
188
+debug_flags = @debug_flags@
189
+exec_prefix = @exec_prefix@
190
+gmp = @gmp@
191
+host = @host@
192
+host_alias = @host_alias@
193
+host_cpu = @host_cpu@
194
+host_os = @host_os@
195
+host_vendor = @host_vendor@
196
+includedir = @includedir@
197
+infodir = @infodir@
198
+install_sh = @install_sh@
199
+libdir = @libdir@
200
+libexecdir = @libexecdir@
201
+localstatedir = @localstatedir@
202
+mandir = @mandir@
203
+mkdir_p = @mkdir_p@
204
+oldincludedir = @oldincludedir@
205
+prefix = @prefix@
206
+program_transform_name = @program_transform_name@
207
+sbindir = @sbindir@
208
+sharedstatedir = @sharedstatedir@
209
+sysconfdir = @sysconfdir@
210
+target_alias = @target_alias@
211
+SUBDIRS = man scripts conf
212
+AM_CFLAGS = -g -I. @debug_flags@ -I@gmp@
213
+AM_CXXFLAGS = -g -I. @debug_flags@ -I@gmp@
214
+ntkd_SOURCES = accept.c map.c misc.c buffer.c hash.c pkts.c qspn.c   \
215
+	request.c  \
216
+	radar.c gmap.c hook.c rehook.c if.c inet.c ipv6-gmp.c        \
217
+	krnl_route.c andna.c snsd_cache.c andna_cache.c err_errno.c  \
218
+	andns.c andns_lib.c dnslib.c andns_net.c andns_snsd.c	     \
219
+	bmap.c  conf.c crypto.c daemon.c dns_wrapper.c endianness.c  \
220
+	krnl_rule.c iptunnel.c libnetlink.c ll_map.c llist.c log.c   \
221
+	route.c tracer.c igs.c libping.c xmalloc.c netsukuku.c       \
222
+	mark.c libiptc/libip4tc.c
223
+
224
+ntkd_LDADD = -lpthread -lgmp -lcrypto -lresolv -lz
225
+ntk_resolv_SOURCES = andns_lib.c ntkresolv.c andns_net.c crypto.c    \
226
+		  snsd_cache.c inet.c ll_map.c libnetlink.c log.c    \
227
+		  xmalloc.c endianness.c misc.c err_errno.c buffer.c
228
+
229
+ntk_resolv_LDADD = -lz -lcrypto
230
+all: config.h
231
+	$(MAKE) $(AM_MAKEFLAGS) all-recursive
232
+
233
+.SUFFIXES:
234
+.SUFFIXES: .c .o .obj
235
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
236
+	@for dep in $?; do \
237
+	  case '$(am__configure_deps)' in \
238
+	    *$$dep*) \
239
+	      cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
240
+		&& exit 0; \
241
+	      exit 1;; \
242
+	  esac; \
243
+	done; \
244
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  src/Makefile'; \
245
+	cd $(top_srcdir) && \
246
+	  $(AUTOMAKE) --gnu  src/Makefile
247
+.PRECIOUS: Makefile
248
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
249
+	@case '$?' in \
250
+	  *config.status*) \
251
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
252
+	  *) \
253
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
254
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
255
+	esac;
256
+
257
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
258
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
259
+
260
+$(top_srcdir)/configure:  $(am__configure_deps)
261
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
262
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
263
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
264
+
265
+config.h: stamp-h1
266
+	@if test ! -f $@; then \
267
+	  rm -f stamp-h1; \
268
+	  $(MAKE) stamp-h1; \
269
+	else :; fi
270
+
271
+stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
272
+	@rm -f stamp-h1
273
+	cd $(top_builddir) && $(SHELL) ./config.status src/config.h
274
+$(srcdir)/config.h.in:  $(am__configure_deps) 
275
+	cd $(top_srcdir) && $(AUTOHEADER)
276
+	rm -f stamp-h1
277
+	touch $@
278
+
279
+distclean-hdr:
280
+	-rm -f config.h stamp-h1
281
+install-binPROGRAMS: $(bin_PROGRAMS)
282
+	@$(NORMAL_INSTALL)
283
+	test -z "$(bindir)" || $(mkdir_p) "$(DESTDIR)$(bindir)"
284
+	@list='$(bin_PROGRAMS)'; for p in $$list; do \
285
+	  p1=`echo $$p|sed 's/$(EXEEXT)$$//'`; \
286
+	  if test -f $$p \
287
+	  ; then \
288
+	    f=`echo "$$p1" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \
289
+	   echo " $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) '$$p' '$(DESTDIR)$(bindir)/$$f'"; \
290
+	   $(INSTALL_PROGRAM_ENV) $(binPROGRAMS_INSTALL) "$$p" "$(DESTDIR)$(bindir)/$$f" || exit 1; \
291
+	  else :; fi; \
292
+	done
293
+
294
+uninstall-binPROGRAMS:
295
+	@$(NORMAL_UNINSTALL)
296
+	@list='$(bin_PROGRAMS)'; for p in $$list; do \
297
+	  f=`echo "$$p" | sed 's,^.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/'`; \
298
+	  echo " rm -f '$(DESTDIR)$(bindir)/$$f'"; \
299
+	  rm -f "$(DESTDIR)$(bindir)/$$f"; \
300
+	done
301
+
302
+clean-binPROGRAMS:
303
+	-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
304
+ntk-resolv$(EXEEXT): $(ntk_resolv_OBJECTS) $(ntk_resolv_DEPENDENCIES) 
305
+	@rm -f ntk-resolv$(EXEEXT)
306
+	$(LINK) $(ntk_resolv_LDFLAGS) $(ntk_resolv_OBJECTS) $(ntk_resolv_LDADD) $(LIBS)
307
+ntkd$(EXEEXT): $(ntkd_OBJECTS) $(ntkd_DEPENDENCIES) 
308
+	@rm -f ntkd$(EXEEXT)
309
+	$(LINK) $(ntkd_LDFLAGS) $(ntkd_OBJECTS) $(ntkd_LDADD) $(LIBS)
310
+
311
+mostlyclean-compile:
312
+	-rm -f *.$(OBJEXT)
313
+
314
+distclean-compile:
315
+	-rm -f *.tab.c
316
+
317
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/accept.Po@am__quote@
318
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/andna.Po@am__quote@
319
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/andna_cache.Po@am__quote@
320
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/andns.Po@am__quote@
321
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/andns_lib.Po@am__quote@
322
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/andns_net.Po@am__quote@
323
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/andns_snsd.Po@am__quote@
324
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bmap.Po@am__quote@
325
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buffer.Po@am__quote@
326
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/conf.Po@am__quote@
327
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/crypto.Po@am__quote@
328
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/daemon.Po@am__quote@
329
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dns_wrapper.Po@am__quote@
330
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dnslib.Po@am__quote@
331
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/endianness.Po@am__quote@
332
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/err_errno.Po@am__quote@
333
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gmap.Po@am__quote@
334
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hash.Po@am__quote@
335
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hook.Po@am__quote@
336
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/if.Po@am__quote@
337
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/igs.Po@am__quote@
338
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inet.Po@am__quote@
339
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iptunnel.Po@am__quote@
340
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipv6-gmp.Po@am__quote@
341
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/krnl_route.Po@am__quote@
342
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/krnl_rule.Po@am__quote@
343
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libip4tc.Po@am__quote@
344
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnetlink.Po@am__quote@
345
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libping.Po@am__quote@
346
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ll_map.Po@am__quote@
347
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/llist.Po@am__quote@
348
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@
349
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/map.Po@am__quote@
350
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mark.Po@am__quote@
351
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@
352
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netsukuku.Po@am__quote@
353
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntkresolv.Po@am__quote@
354
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pkts.Po@am__quote@
355
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qspn.Po@am__quote@
356
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/radar.Po@am__quote@
357
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rehook.Po@am__quote@
358
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/request.Po@am__quote@
359
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/route.Po@am__quote@
360
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snsd_cache.Po@am__quote@
361
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tracer.Po@am__quote@
362
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmalloc.Po@am__quote@
363
+
364
+.c.o:
365
+@am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
366
+@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
367
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
368
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
369
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
370
+@am__fastdepCC_FALSE@	$(COMPILE) -c $<
371
+
372
+.c.obj:
373
+@am__fastdepCC_TRUE@	if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
374
+@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
375
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
376
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	depfile='$(DEPDIR)/$*.Po' tmpdepfile='$(DEPDIR)/$*.TPo' @AMDEPBACKSLASH@
377
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
378
+@am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
379
+
380
+libip4tc.o: libiptc/libip4tc.c
381
+@am__fastdepCC_TRUE@	if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libip4tc.o -MD -MP -MF "$(DEPDIR)/libip4tc.Tpo" -c -o libip4tc.o `test -f 'libiptc/libip4tc.c' || echo '$(srcdir)/'`libiptc/libip4tc.c; \
382
+@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/libip4tc.Tpo" "$(DEPDIR)/libip4tc.Po"; else rm -f "$(DEPDIR)/libip4tc.Tpo"; exit 1; fi
383
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='libiptc/libip4tc.c' object='libip4tc.o' libtool=no @AMDEPBACKSLASH@
384
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	depfile='$(DEPDIR)/libip4tc.Po' tmpdepfile='$(DEPDIR)/libip4tc.TPo' @AMDEPBACKSLASH@
385
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
386
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libip4tc.o `test -f 'libiptc/libip4tc.c' || echo '$(srcdir)/'`libiptc/libip4tc.c
387
+
388
+libip4tc.obj: libiptc/libip4tc.c
389
+@am__fastdepCC_TRUE@	if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libip4tc.obj -MD -MP -MF "$(DEPDIR)/libip4tc.Tpo" -c -o libip4tc.obj `if test -f 'libiptc/libip4tc.c'; then $(CYGPATH_W) 'libiptc/libip4tc.c'; else $(CYGPATH_W) '$(srcdir)/libiptc/libip4tc.c'; fi`; \
390
+@am__fastdepCC_TRUE@	then mv -f "$(DEPDIR)/libip4tc.Tpo" "$(DEPDIR)/libip4tc.Po"; else rm -f "$(DEPDIR)/libip4tc.Tpo"; exit 1; fi
391
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='libiptc/libip4tc.c' object='libip4tc.obj' libtool=no @AMDEPBACKSLASH@
392
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	depfile='$(DEPDIR)/libip4tc.Po' tmpdepfile='$(DEPDIR)/libip4tc.TPo' @AMDEPBACKSLASH@
393
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
394
+@am__fastdepCC_FALSE@	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libip4tc.obj `if test -f 'libiptc/libip4tc.c'; then $(CYGPATH_W) 'libiptc/libip4tc.c'; else $(CYGPATH_W) '$(srcdir)/libiptc/libip4tc.c'; fi`
395
+uninstall-info-am:
396
+
397
+# This directory's subdirectories are mostly independent; you can cd
398
+# into them and run `make' without going through this Makefile.
399
+# To change the values of `make' variables: instead of editing Makefiles,
400
+# (1) if the variable is set in `config.status', edit `config.status'
401
+#     (which will cause the Makefiles to be regenerated when you run `make');
402
+# (2) otherwise, pass the desired values on the `make' command line.
403
+$(RECURSIVE_TARGETS):
404
+	@set fnord $$MAKEFLAGS; amf=$$2; \
405
+	dot_seen=no; \
406
+	target=`echo $@ | sed s/-recursive//`; \
407
+	list='$(SUBDIRS)'; for subdir in $$list; do \
408
+	  echo "Making $$target in $$subdir"; \
409
+	  if test "$$subdir" = "."; then \
410
+	    dot_seen=yes; \
411
+	    local_target="$$target-am"; \
412
+	  else \
413
+	    local_target="$$target"; \
414
+	  fi; \
415
+	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
416
+	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
417
+	done; \
418
+	if test "$$dot_seen" = "no"; then \
419
+	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
420
+	fi; test -z "$$fail"
421
+
422
+mostlyclean-recursive clean-recursive distclean-recursive \
423
+maintainer-clean-recursive:
424
+	@set fnord $$MAKEFLAGS; amf=$$2; \
425
+	dot_seen=no; \
426
+	case "$@" in \
427
+	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
428
+	  *) list='$(SUBDIRS)' ;; \
429
+	esac; \
430
+	rev=''; for subdir in $$list; do \
431
+	  if test "$$subdir" = "."; then :; else \
432
+	    rev="$$subdir $$rev"; \
433
+	  fi; \
434
+	done; \
435
+	rev="$$rev ."; \
436
+	target=`echo $@ | sed s/-recursive//`; \
437
+	for subdir in $$rev; do \
438
+	  echo "Making $$target in $$subdir"; \
439
+	  if test "$$subdir" = "."; then \
440
+	    local_target="$$target-am"; \
441
+	  else \
442
+	    local_target="$$target"; \
443
+	  fi; \
444
+	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
445
+	   || case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
446
+	done && test -z "$$fail"
447
+tags-recursive:
448
+	list='$(SUBDIRS)'; for subdir in $$list; do \
449
+	  test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
450
+	done
451
+ctags-recursive:
452
+	list='$(SUBDIRS)'; for subdir in $$list; do \
453
+	  test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
454
+	done
455
+
456
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
457
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
458
+	unique=`for i in $$list; do \
459
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
460
+	  done | \
461
+	  $(AWK) '    { files[$$0] = 1; } \
462
+	       END { for (i in files) print i; }'`; \
463
+	mkid -fID $$unique
464
+tags: TAGS
465
+
466
+TAGS: tags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
467
+		$(TAGS_FILES) $(LISP)
468
+	tags=; \
469
+	here=`pwd`; \
470
+	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
471
+	  include_option=--etags-include; \
472
+	  empty_fix=.; \
473
+	else \
474
+	  include_option=--include; \
475
+	  empty_fix=; \
476
+	fi; \
477
+	list='$(SUBDIRS)'; for subdir in $$list; do \
478
+	  if test "$$subdir" = .; then :; else \
479
+	    test ! -f $$subdir/TAGS || \
480
+	      tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
481
+	  fi; \
482
+	done; \
483
+	list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
484
+	unique=`for i in $$list; do \
485
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
486
+	  done | \
487
+	  $(AWK) '    { files[$$0] = 1; } \
488
+	       END { for (i in files) print i; }'`; \
489
+	if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
490
+	  test -n "$$unique" || unique=$$empty_fix; \
491
+	  $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
492
+	    $$tags $$unique; \
493
+	fi
494
+ctags: CTAGS
495
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES) config.h.in $(TAGS_DEPENDENCIES) \
496
+		$(TAGS_FILES) $(LISP)
497
+	tags=; \
498
+	here=`pwd`; \
499
+	list='$(SOURCES) $(HEADERS) config.h.in $(LISP) $(TAGS_FILES)'; \
500
+	unique=`for i in $$list; do \
501
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
502
+	  done | \
503
+	  $(AWK) '    { files[$$0] = 1; } \
504
+	       END { for (i in files) print i; }'`; \
505
+	test -z "$(CTAGS_ARGS)$$tags$$unique" \
506
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
507
+	     $$tags $$unique
508
+
509
+GTAGS:
510
+	here=`$(am__cd) $(top_builddir) && pwd` \
511
+	  && cd $(top_srcdir) \
512
+	  && gtags -i $(GTAGS_ARGS) $$here
513
+
514
+distclean-tags:
515
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
516
+
517
+distdir: $(DISTFILES)
518
+	@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
519
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
520
+	list='$(DISTFILES)'; for file in $$list; do \
521
+	  case $$file in \
522
+	    $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
523
+	    $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
524
+	  esac; \
525
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
526
+	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
527
+	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
528
+	    dir="/$$dir"; \
529
+	    $(mkdir_p) "$(distdir)$$dir"; \
530
+	  else \
531
+	    dir=''; \
532
+	  fi; \
533
+	  if test -d $$d/$$file; then \
534
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
535
+	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
536
+	    fi; \
537
+	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
538
+	  else \
539
+	    test -f $(distdir)/$$file \
540
+	    || cp -p $$d/$$file $(distdir)/$$file \
541
+	    || exit 1; \
542
+	  fi; \
543
+	done
544
+	list='$(SUBDIRS)'; for subdir in $$list; do \
545
+	  if test "$$subdir" = .; then :; else \
546
+	    test -d "$(distdir)/$$subdir" \
547
+	    || mkdir "$(distdir)/$$subdir" \
548
+	    || exit 1; \
549
+	    (cd $$subdir && \
550
+	      $(MAKE) $(AM_MAKEFLAGS) \
551
+	        top_distdir="../$(top_distdir)" \
552
+	        distdir="../$(distdir)/$$subdir" \
553
+	        distdir) \
554
+	      || exit 1; \
555
+	  fi; \
556
+	done
557
+check-am: all-am
558
+check: check-recursive
559
+all-am: Makefile $(PROGRAMS) config.h
560
+installdirs: installdirs-recursive
561
+installdirs-am:
562
+	for dir in "$(DESTDIR)$(bindir)"; do \
563
+	  test -z "$$dir" || $(mkdir_p) "$$dir"; \
564
+	done
565
+install: install-recursive
566
+install-exec: install-exec-recursive
567
+install-data: install-data-recursive
568
+uninstall: uninstall-recursive
569
+
570
+install-am: all-am
571
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
572
+
573
+installcheck: installcheck-recursive
574
+install-strip:
575
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
576
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
577
+	  `test -z '$(STRIP)' || \
578
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
579
+mostlyclean-generic:
580
+
581
+clean-generic:
582
+
583
+distclean-generic:
584
+	-rm -f $(CONFIG_CLEAN_FILES)
585
+
586
+maintainer-clean-generic:
587
+	@echo "This command is intended for maintainers to use"
588
+	@echo "it deletes files that may require special tools to rebuild."
589
+clean: clean-recursive
590
+
591
+clean-am: clean-binPROGRAMS clean-generic mostlyclean-am
592
+
593
+distclean: distclean-recursive
594
+	-rm -rf ./$(DEPDIR)
595
+	-rm -f Makefile
596
+distclean-am: clean-am distclean-compile distclean-generic \
597
+	distclean-hdr distclean-tags
598
+
599
+dvi: dvi-recursive
600
+
601
+dvi-am:
602
+
603
+html: html-recursive
604
+
605
+info: info-recursive
606
+
607
+info-am:
608
+
609
+install-data-am:
610
+
611
+install-exec-am: install-binPROGRAMS
612
+
613
+install-info: install-info-recursive
614
+
615
+install-man:
616
+
617
+installcheck-am:
618
+
619
+maintainer-clean: maintainer-clean-recursive
620
+	-rm -rf ./$(DEPDIR)
621
+	-rm -f Makefile
622
+maintainer-clean-am: distclean-am maintainer-clean-generic
623
+
624
+mostlyclean: mostlyclean-recursive
625
+
626
+mostlyclean-am: mostlyclean-compile mostlyclean-generic
627
+
628
+pdf: pdf-recursive
629
+
630
+pdf-am:
631
+
632
+ps: ps-recursive
633
+
634
+ps-am:
635
+
636
+uninstall-am: uninstall-binPROGRAMS uninstall-info-am
637
+
638
+uninstall-info: uninstall-info-recursive
639
+
640
+.PHONY: $(RECURSIVE_TARGETS) CTAGS GTAGS all all-am check check-am \
641
+	clean clean-binPROGRAMS clean-generic clean-recursive ctags \
642
+	ctags-recursive distclean distclean-compile distclean-generic \
643
+	distclean-hdr distclean-recursive distclean-tags distdir dvi \
644
+	dvi-am html html-am info info-am install install-am \
645
+	install-binPROGRAMS install-data install-data-am install-exec \
646
+	install-exec-am install-info install-info-am install-man \
647
+	install-strip installcheck installcheck-am installdirs \
648
+	installdirs-am maintainer-clean maintainer-clean-generic \
649
+	maintainer-clean-recursive mostlyclean mostlyclean-compile \
650
+	mostlyclean-generic mostlyclean-recursive pdf pdf-am ps ps-am \
651
+	tags tags-recursive uninstall uninstall-am \
652
+	uninstall-binPROGRAMS uninstall-info-am
653
+
654
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
655
+# Otherwise a system limit (for SysV at least) may be exceeded.
656
+.NOEXPORT:

+ 215
- 0
src/SConstruct View File

@@ -0,0 +1,215 @@
1
+# This file is part of Netsukuku
2
+# (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+#
4
+# This source code is free software; you can redistribute it and/or
5
+# modify it under the terms of the GNU Public License as published 
6
+# by the Free Software Foundation; either version 2 of the License,
7
+# or (at your option) any later version.
8
+#
9
+# This source code is distributed in the hope that it will be useful,
10
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+# Please refer to the GNU Public License for more details.
13
+#
14
+# You should have received a copy of the GNU Public License along with
15
+# this source code; if not, write to:
16
+# Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+
18
+import sys
19
+import os
20
+
21
+NTK_VERSION="0.0.9b"
22
+
23
+#
24
+#	Sources and libs
25
+#
26
+
27
+sources_common    = Split('xmalloc.c log.c misc.c buffer.c endianness.c')
28
+sources_qspn      = Split('qspn-empiric.c') + sources_common
29
+sources_netsukuku = Split("""accept.c llist.c ipv6-gmp.c inet.c request.c map.c
30
+		   gmap.c bmap.c pkts.c radar.c hook.c rehook.c tracer.c qspn.c 
31
+		   hash.c daemon.c crypto.c snsd_cache.c
32
+		   andna_cache.c andna.c andns_lib.c err_errno.c
33
+		   dnslib.c andns.c andns_net.c andns_snsd.c
34
+		   ll_map.c libnetlink.c if.c krnl_route.c krnl_rule.c
35
+		   iptunnel.c route.c conf.c dns_wrapper.c igs.c mark.c 
36
+		   libiptc/libip4tc.c libping.c netsukuku.c""") + sources_common
37
+sources_ntkresolv = sources_common + Split("""andns_lib.c ntkresolv.c andns_net.c
38
+					      crypto.c snsd_cache.c inet.c
39
+					      ll_map.c libnetlink.c
40
+					      err_errno.c""") 
41
+
42
+libs = ['gmp', 'pthread', 'crypto', 'z']
43
+
44
+#
45
+#	Command line options and help
46
+#
47
+
48
+opts = Options('build.conf')
49
+opts.AddOptions(('CONF_DIR', """Directory where the Netsukuku configuration files will be installed""",
50
+				'/etc/netsukuku'),
51
+		('DATA_DIR', 'Directory to install data files',	
52
+				'/usr/share/netsukuku'),
53
+		('MAN_DIR',  'Where the manuals will be installed', 
54
+				'/usr/man'),
55
+		('BIN_DIR' , 'Directory to install the binaries',
56
+				'/usr/bin'),
57
+		('PID_DIR',  'Specify location of ntkd.pid file',
58
+				'/var/run'),
59
+		('destdir', 'SCons will copy all the files under destdir during installation',
60
+				'/'),
61
+		EnumOption('debug', 'build the debug code', 'no', 
62
+			allowed_values=('yes', 'no', '1', '0'), map={},
63
+			ignorecase=0),
64
+		EnumOption('static', 'build statically the binaries', 'no', 
65
+			allowed_values=('yes', 'no', '1', '0'), map={},
66
+			ignorecase=0))
67
+opts.Add('CC', 'The C compiler.')
68
+opts.Add('CXX', 'The C++ compiler.')
69
+
70
+env = Environment(options = opts, ENV = os.environ, CCFLAGS = ' -Wall')
71
+
72
+if ("yes" in env['debug']) or ("1" in env['debug']):
73
+	debug = 1
74
+	env.Append(CPPDEFINES={'DEBUG' : '${debug}'}, CCFLAGS = ' -ggdb -Wall', CXXFLAGS = '-g')
75
+#CCFLAGS = ' -ggdb -Wall -DDMALLOC_FUNC_CHECK'
76
+#	libs+=['dmalloc', 'dmallocth']
77
+	os.system("echo Cscoping and ctagging...; cscope -b; ctags *")
78
+else:
79
+	debug  = 0
80
+if ("yes" in env['static']) or ("1" in env['static']):
81
+	static = 1
82
+	env.Append(CCFLAGS = ' -static', CXXFLAGS = '-static')
83
+else:
84
+	static = 0
85
+if (env['destdir'] == "/"):
86
+	env['destdir']=""
87
+
88
+opts.Save('build.conf', env)
89
+
90
+if os.path.exists("conf/netsukuku.conf") and env.GetOption('clean'):
91
+	Execute(Delete('conf/netsukuku.conf'))
92
+if os.path.exists("config.h") and env.GetOption('clean'):
93
+	Execute(Delete('config.h'))
94
+if os.path.exists("config.log") and env.GetOption('clean'):
95
+	Execute(Delete('config.log'))
96
+	
97
+Help("""
98
+*** Usage
99
+      'scons' to build the ntkd binary,
100
+      'scons debug=yes' to build the debug version.
101
+      'scons install' to install it in the system.
102
+      
103
+*** General options
104
+""" + opts.GenerateHelpText(env))
105
+
106
+if ARGUMENTS.get('install'):
107
+		print "you aren't root"
108
+
109
+#
110
+#	Configure
111
+#
112
+
113
+if not os.path.exists("config.log") and not env.GetOption('clean'):
114
+	print 'Configuring... '
115
+	conf = Configure(env)
116
+	if not conf.CheckLib('gmp'): 
117
+		print 'Did not find libgmp.a or gmp.lib, exiting!'
118
+		Execute(Delete('config.log'))
119
+		Exit(1)
120
+	if not conf.CheckCHeader([ "gmp.h" ]):
121
+		print 'Did not find the gmp headers, exiting!'
122
+		Execute(Delete('config.log'))
123
+		Exit(1)
124
+	if not conf.CheckCHeader([ "zlib.h" ]):
125
+		print 'Did not find the zlib headers, exiting!'
126
+		Execute(Delete('config.log'))
127
+		Exit(1)
128
+	if not conf.CheckLib('pthread'):
129
+       		print 'Did not find pthread.a or pthread.lib, exiting!'
130
+		Execute(Delete('config.log'))
131
+		Exit(1)
132
+	if not conf.CheckLib('crypto'): 
133
+		print 'Did not find the openssl libcrypto.a or libcrypto.lib, exiting!'
134
+		Execute(Delete('config.log'))
135
+		Exit(1)
136
+	if not conf.CheckCHeader([ "openssl/bio.h", "openssl/evp.h",
137
+			"openssl/crypto.h", "openssl/x509.h",
138
+			"openssl/engine.h", "openssl/err.h", "openssl/rand.h",
139
+			"openssl/rsa.h", "openssl/pem.h" ]):
140
+		print 'Did not find the openssl headers, exiting!'
141
+		Execute(Delete('config.log'))
142
+		Exit(1)
143
+		
144
+	env = conf.Finish()
145
+
146
+def conf_build(target, source, env):
147
+    conf_defines = {
148
+        "CONF_DIR": env["CONF_DIR"],
149
+	"DATA_DIR": env["DATA_DIR"],
150
+	"PID_DIR": env["PID_DIR"],
151
+	"VERSION": NTK_VERSION,
152
+        "debug": debug # this is an int.  1 for true, 0 for false
153
+    }
154
+
155
+    conf = file(str(target), "w")
156
+    conf_in = file(str(source), "r")
157
+    conf.write(conf_in.read() % conf_defines)
158
+    conf_in.close()
159
+    conf.close()
160
+
161
+def build_config_files(target = None, source = None, env = None):
162
+	if not os.path.exists("config.h") and not env.GetOption('clean'):
163
+		print 'Generating config.h from config_scons.h.in'
164
+		conf_build('config.h', 'config_scons.h.in', env)
165
+		conf = file("config.h", "a")
166
+		if sys.platform == 'linux2' or sys.platform == 'linux-i386':
167
+			conf.write("#define GNU_LINUX\n")
168
+		elif sys.platform == 'darwin':
169
+			conf.write("#define DARWIN\n")
170
+		elif string.find (sys.platform, 'sunos') != -1:
171
+			conf.write("#define SUNOS\n")
172
+		elif sys.platform=='openbsd3':
173
+			conf.write("#define OPEN_BSD\n")
174
+		elif string.find (sys.platform, 'irix') != -1:
175
+			conf.write("#define IRIX\n")
176
+		conf.close()
177
+
178
+	if not os.path.exists("conf/netsukuku.conf") and not env.GetOption('clean'):
179
+		print 'Generating conf/netsukuku.conf from conf/ntk_scons.conf.in'
180
+		conf_build('conf/netsukuku.conf', 'conf/ntk_scons.conf.in', env)
181
+	
182
+	return 0
183
+
184
+build_config_files(env = env)
185
+
186
+#
187
+#	Build
188
+#
189
+
190
+ntkd 	= env.Program('ntkd', sources_netsukuku, LIBS = libs, CPPPATH = '.')
191
+qspn    = env.Program('qspn-empiric', sources_qspn, LIBS = libs, CPPPATH = '.')
192
+ntkresolv = env.Program('ntk-resolv', sources_ntkresolv, LIBS = libs, CPPPATH = '.')
193
+
194
+Default(ntkd, ntkresolv)
195
+
196
+
197
+#
198
+#	Install 
199
+#
200
+
201
+SConscript(['man/SConscript', 'scripts/SConscript', 'conf/SConscript'], 'env')
202
+
203
+# Here are our installation paths:
204
+idir_bin    = '$destdir' + '$BIN_DIR'
205
+idir_data   = '$destdir' + '$DATA_DIR'
206
+idir_conf   = '$destdir' + '$CONF_DIR'
207
+idir_pid    = '$destdir' + '$PID_DIR'
208
+
209
+env.Install(idir_bin, [ntkd])
210
+env.Install(idir_bin, [ntkresolv])
211
+env.Alias('install', [idir_bin, idir_conf])
212
+
213
+#Dirty hack ;( Why GetOption("install") doesn't work?
214
+#if not os.path.exists(env["DATA_DIR"]) and os.path.exists(env["CONF_DIR"]):
215
+#	Execute(Mkdir(env["DATA_DIR"]))

+ 185
- 0
src/TODO View File

@@ -0,0 +1,185 @@
1
+*
2
+**
3
+***		HIGH PRIORITY
4
+**
5
+*	
6
+
7
+* (generally these TODOs are already being implemented at the moment)
8
+
9
+- restore the network when NetsukukuD is closed (call /etc/rc.d/rc.inet1 ?)
10
+
11
+- Netsukuku WRT firmware:
12
+	- a configured openwrt release with all the necessary kernel modules
13
+	  and packages installed
14
+	- A web interface to configure the /etc/netsukuku/netsukuku.conf file
15
+	  and to use the rc.ntk script.
16
+
17
+- bugs 
18
+	- comments in resolv.conf are not considered: 
19
+		NOTE: Do not resolv this BUG: Now It's useful
20
+
21
+*
22
+**
23
+***		MEDIUM PRIORITY
24
+**
25
+*	
26
+
27
+- Equalize multipath routes. The `equalize' module is still experimental in
28
+  the kernel.
29
+
30
+- bandwidth measurement
31
+	- do not delete an inet-gw if there's still bw passing on it.
32
+
33
+- Viphilama: http://lab.dyne.org/Ntk_viphilama
34
+
35
+- Bandwidth weight for each entry of the qspn (not just rtt and latency):
36
+	- what to use to get the bandwidth of a network interface?
37
+	  Use `iperf' to measure once the max link bw, then monitor with
38
+	  iptables the link and calculate the used bw.
39
+	- See http://lab.dyne.org/Ntk_bandwidth_measurement
40
+	  
41
+- Gnodes contiguity
42
+	- gnode re-hook
43
+		- When we have two different gnodes A and C, and
44
+		  then B hooks to A, nothing happens, since C, doesn't
45
+		  receive any qspn_pkt
46
+		- test: two (g)nodes with the same IP
47
+			- currently only in particular situations the rehook
48
+			  isn't possible: A - A,  A - B - A.
49
+	
50
+	- Challenge
51
+		- RSA between rnodes: the nodes which are already hooked ask
52
+		  for the public key to the node which is hooking.
53
+		- Creation of the problem.
54
+		- Resolution of the problem.
55
+		- Diffusion of the reply.
56
+		- Reject of challenge for X time after a first challenge has
57
+		  been completed.
58
+		- Do just one challenge at the same time, reject/delay all the
59
+		  other which came later.
60
+		- If the challenge was rejected/delayed wait the right amount
61
+		  of time and retry.
62
+		- Ban of gnodes which lost the challenge ?
63
+		- Challenge between two gnode not contiguous, which have the
64
+		  same gid.
65
+
66
+- turn andns_lib.c into a real shared library
67
+
68
+- SNSD
69
+	- pubkey: automatic deletion request
70
+
71
+- A firewall script to turn a ntk node into a routing only node.
72
+
73
+
74
+	              other ntk nodes
75
+		             |
76
+			     |
77
+			     |
78
+			 _________
79
+			|    N    |
80
+    Internet ---------- | WRT ntk | - - w i f i - - - Ntk node A
81
+			|_________|             \
82
+			     |                   \
83
+			     |                    \ Ntk node B
84
+			   L A N
85
+			    
86
+  If N is set to a routing only node, then the nodes A and B will always be
87
+  able to reach the Internet and the "other ntk nodes" through it, but they 
88
+  will not be able to reach the LAN connected to the node N.
89
+  Optionally the node N can leave some "backdoor" ports opened, f.e. it might
90
+  want to leave a ssh login which accepts keys authentication only.
91
+
92
+  The port used by Netsukuku will be leaved open too, in this way the nodes
93
+  can still communicate between them.
94
+
95
+- Can multiple qspn packets be processed concurrently? Or do we need mutexes
96
+  for them? Only the tests will give answer.
97
+
98
+*
99
+**
100
+***		LOW PRIORITY
101
+**
102
+*	
103
+
104
+- Interactive shell/console. Some commands that should be implemented:
105
+	  "stats" gives statistics, 
106
+	  "rnodes" show the list of rnodes,
107
+	  "int_map" dumps the internal map in a ASCIIful way,
108
+	  "ext_map", "bnode_map", "andna_cache", ...,
109
+	  "flush rhcache"
110
+
111
+- ntk-finger: it would be handy to be able to know some info on a particular
112
+  node. The user puts his node info in /etc/netsukuku/finger.
113
+  $ ntk-finger remote_node_ip
114
+  will print out its /etc/netsukuku/finger.
115
+  	- why don't we just use fingerd?
116
+		- too bugged?
117
+	- and what about a stupid shell script like this: 
118
+	  while [ 0 ]; do cat /etc/netsukuku/finger | nc -l -p 79; done
119
+  
120
+- renice the NetsukukuD process?
121
+
122
+- small memory: if the system has <= X Mb of free memory, switch on dumb mode.
123
+  In this mode NetsukukuD keeps only the list of rnodes and forwards every
124
+  request to one of them. The lcl_cache is kept too.
125
+
126
+- better memory utilisation: see MAXMSGSZ, PKT_MAX_MSG_SZ, pkt_verify_hdr(), 
127
+			     pkt_uncompress(), andns_uncompress().
128
+	- The maximum size of an uncompressed or compressed packet must be
129
+	  proportional to the total free memory reserved to the daemon.
130
+	- pkt_uncompress() must be able to drop the packet if there's no
131
+	  free memory available. The same must be done by pkt_recv() and
132
+	  other similar functions.
133
+
134
+- option to disable the modification of the routing table
135
+
136
+- option to change on runtime the wait-times of the QSPN, radar, etc...
137
+	-normal, -high, -low
138
+
139
+- option (both on command line and in netsukuku.conf) to disable the saving of
140
+  caches. (the keyring will always be saved).
141
+
142
+- Change with something else the eliminable fatal() calls in netsukuku_hook()
143
+
144
+- Ipv6 support: use ff05::23 for multicast. qspn_gnode_count isn't IPv6
145
+  compatible!
146
+
147
+- Test request.c
148
+
149
+- Port the kernel route code for *BSD: take a look at rt_ioctl.c and
150
+  rt_socket.c of quagga.
151
+
152
+- use PREFIX in the man pages
153
+
154
+- xmalloc.c: Implement a "wrapper heap". We do a big malloc() at the start and
155
+	     then we manage personally it, in this way we avoid the huge
156
+	     overhead of malloc.
157
+
158
+- Compressed maps: save the files in compressed formats
159
+
160
+- API for the syncronization of the maps the daemon. A third party program,
161
+  might want to have always the latest maps. 
162
+
163
+- Write the documentation for the code that can be used by other
164
+  programs. (By the way it is already commented.)
165
+
166
+- krnl_conf.c: it reads /proc/kallsyms and verifies that there are the symbols
167
+	       used by the modules/builtins kernel code netsukuku is dependent
168
+	       on. kernel_conf.h will have an array like pkt_op_table (pkts.h).
169
+	       Each symbol will be checked by the init functions. There will be
170
+	       also associated an help function that tells what to do when the
171
+	       symbol is missing in /proc/kallsyms. For example,
172
+	       mark_rule_init() will do:
173
+	     		if(krnl_conf_check("netfilter") <0) {
174
+				krnl_netfilter_usage();
175
+				return -1
176
+			}
177
+
178
+- Launch a trigger script. Possible events: INET_UP, INET_DOWN, NEW_RNODE,
179
+  DEAD_RNODE.
180
+
181
+- Use bireloc from autopackage
182
+
183
+- Use qemu to make Netsukuku run on windows?!?
184
+
185
+- /*\ \*/

+ 276
- 0
src/accept.c View File

@@ -0,0 +1,276 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ *
18
+ * -- 
19
+ * accept.c: This is how it works:
20
+ *
21
+ * When a new accept is made add_accept is called. It first updates the accept
22
+ * table and then, if the accept_tbl isn't full add the new accept in the tbl.
23
+ * If the accept_tbl is full the connection is dropped.
24
+ * Each accept in the table last for free_accept_time after the close of that
25
+ * connection, so if an host has fulled the accept_tbl has to wait 
26
+ * free_accept_time of seconds to be able to reconnect again.
27
+ */
28
+
29
+#include "includes.h"
30
+
31
+#include "request.h"
32
+#include "inet.h"
33
+#include "accept.h"
34
+#include "xmalloc.h"
35
+#include "log.h"
36
+
37
+
38
+void init_accept_tbl(int startups, int accepts, int time)
39
+{
40
+	/* TODO: activate and test it !! */
41
+#if 0
42
+	int i;
43
+
44
+	max_connections=startups;
45
+	max_accepts_per_host=accepts;
46
+	free_accept_time=time;
47
+	accept_idx=accept_sidx=0;
48
+	pthread_mutex_init(&mtx_acpt_idx, NULL);
49
+	pthread_mutex_init(&mtx_acpt_sidx, NULL);
50
+	
51
+	accept_tbl=(struct accept_table *)xmalloc(sizeof(struct accept_table)*max_connections);
52
+	memset(accept_tbl, '\0', sizeof(struct accept_table)*max_connections);
53
+
54
+	for(i=0; i<max_connections; i++) {
55
+		accept_tbl[i].pid=(pid_t *)xmalloc(sizeof(pid_t)*max_accepts_per_host);
56
+		memset(accept_tbl[i].pid, '\0', sizeof(pid_t)*max_accepts_per_host);
57
+			
58
+		accept_tbl[i].closed=(unsigned char *)xmalloc(sizeof(unsigned char)*max_accepts_per_host);
59
+		memset(accept_tbl[i].closed, '\0', sizeof(unsigned char)*max_accepts_per_host);
60
+			
61
+		accept_tbl[i].acp_t=(time_t *)xmalloc(sizeof(time_t)*max_accepts_per_host);
62
+		memset(accept_tbl[i].acp_t, '\0', sizeof(time_t)*max_accepts_per_host);
63
+	}
64
+#endif
65
+}
66
+
67
+void destroy_accept_tbl(void)
68
+{
69
+	/* TODO: activate and test it !! */
70
+#if 0
71
+	int i; 
72
+	
73
+	if(!accept_tbl)
74
+		return;
75
+	for(i=0; i<max_connections; i++) {
76
+		xfree(accept_tbl[i].pid);
77
+		xfree(accept_tbl[i].closed);
78
+		xfree(accept_tbl[i].acp_t);
79
+	}
80
+	xfree(accept_tbl);
81
+	accept_tbl=0;
82
+#endif
83
+}
84
+
85
+
86
+void update_accept_tbl(void)
87
+{
88
+	time_t cur_t, passed_time;
89
+	int i,e,k,ee, pid_exists;
90
+	
91
+	if(update_accept_tbl_mutex)
92
+		return;
93
+	else
94
+		update_accept_tbl_mutex=1;
95
+	
96
+	time(&cur_t);
97
+	
98
+	for(i=0; i < max_connections; i++) {
99
+		if(!accept_tbl[i].ip.len)
100
+			continue;
101
+		if(accept_tbl[i].accepts) {
102
+			for(e=0; e<max_accepts_per_host; e++) {
103
+				if(!accept_tbl[i].acp_t[e])
104
+					continue;
105
+				
106
+				if(accept_tbl[i].pid[e]) {
107
+					k=kill(accept_tbl[i].pid[e], 0);
108
+					pid_exists = !(k==-1 && errno==ESRCH);
109
+				} else
110
+					pid_exists=0;
111
+
112
+#if 0
113
+				debug(DBG_NOISE, "ACPT: Updating tbl: cur_t: %d, "
114
+						"accept_tbl[%d].acp_t[%d]:%d+%d, "
115
+						"accept_tbl[i].pid[e]: %d, "
116
+						"kill=%d (ESRCH=%d)",
117
+						cur_t, i,e, accept_tbl[i].acp_t[e], 
118
+						free_accept_time, accept_tbl[i].pid[e], 
119
+						k, ESRCH);
120
+#endif
121
+
122
+				passed_time=accept_tbl[i].acp_t[e]+free_accept_time;
123
+				if((accept_tbl[i].closed[e] || !pid_exists) && 
124
+						passed_time <= cur_t) {
125
+					ee=e;
126
+					del_accept(i, &ee);
127
+				}
128
+			}
129
+		}
130
+	}
131
+	update_accept_tbl_mutex=0;
132
+}
133
+
134
+int find_ip_acpt(inet_prefix ip)
135
+{
136
+	int i;
137
+	
138
+	for(i=0; i<max_accepts_per_host; i++) {
139
+		if(!memcmp(accept_tbl[i].ip.data, &ip.data, MAX_IP_SZ))
140
+			return i;
141
+	}
142
+
143
+	return -1;
144
+}
145
+
146
+int find_first_free(void)
147
+{
148
+	int i;
149
+	
150
+	for(i=0; i<max_connections; i++)
151
+		if(!accept_tbl[i].accepts)
152
+			return i;
153
+	return -1;
154
+}
155
+
156
+int is_ip_acpt_free(inet_prefix ip, int *index)
157
+{
158
+	int idx;
159
+	
160
+	update_accept_tbl();
161
+	
162
+	if((idx=find_ip_acpt(ip))==-1)
163
+		if((idx=find_first_free())==-1)
164
+			return E_TOO_MANY_CONN;
165
+	
166
+	/*debug(DBG_NOISE, "ACPT: accept_tbl[%d].accepts: %d, max_acp: %d", idx,
167
+			accept_tbl[idx].accepts, max_accepts_per_host); */
168
+
169
+	if(accept_tbl[idx].accepts >= max_accepts_per_host)
170
+		return E_ACCEPT_TBL_FULL;
171
+
172
+	*index=idx;
173
+	return 0;
174
+}
175
+
176
+int find_free_acp_t(int idx)
177
+{
178
+	int e;
179
+	
180
+	for(e=0; e < max_accepts_per_host; e++) {
181
+		if(!accept_tbl[idx].acp_t[e])
182
+			return e;
183
+	}
184
+	
185
+	return -1;	/*This happens if the rq_tbl is full for the "rq" request*/
186
+}
187
+
188
+int new_accept(int idx, inet_prefix ip)
189
+{
190
+	int cl=0;
191
+	/* TODO: activate and test it !! */
192
+#if 0
193
+	time_t cur_t;
194
+	
195
+	time(&cur_t);
196
+	
197
+	if((cl=find_free_acp_t(idx))==-1)
198
+		return -1;
199
+	accept_tbl[idx].accepts++;
200
+	accept_tbl[idx].acp_t[cl]=cur_t;
201
+	accept_tbl[idx].closed[cl]=0;
202
+	inet_copy(&accept_tbl[idx].ip, &ip);
203
+#endif
204
+	return cl;
205
+}
206
+
207
+/* 
208
+ * add_accept: It adds a new accept of `ip'. If `replace' is not 0 the `ip's
209
+ * accepts are not incremented and accept_sidx is set to 0.
210
+ */
211
+int add_accept(inet_prefix ip, int replace)
212
+{
213
+	/* TODO: activate and test it !! */
214
+#if 0
215
+	int err, idx, cl;
216
+	
217
+	if((err=is_ip_acpt_free(ip, &idx)))
218
+		return err;
219
+
220
+	if(!replace || !accept_tbl[idx].accepts) {
221
+		cl=new_accept(idx, ip);
222
+		if(cl < 0)
223
+			return -1;
224
+	} else 
225
+		cl=0;
226
+
227
+	/*This global var will be given to the thread*/
228
+	pthread_mutex_lock(&mtx_acpt_idx);
229
+	accept_idx=idx;
230
+	pthread_mutex_unlock(&mtx_acpt_idx);
231
+
232
+	pthread_mutex_lock(&mtx_acpt_sidx);
233
+	accept_sidx=cl;
234
+	pthread_mutex_unlock(&mtx_acpt_sidx);
235
+#endif
236
+	return 0;
237
+}
238
+
239
+void del_accept(int idx, int *sidx)
240
+{
241
+#if 0
242
+	if(!accept_tbl[idx].accepts) 
243
+		return;
244
+
245
+	if(accept_tbl[idx].acp_t[*sidx]) {
246
+		accept_tbl[idx].accepts--;
247
+		accept_tbl[idx].acp_t[*sidx]=0;
248
+		accept_tbl[idx].closed[*sidx]=0;
249
+		if(!accept_tbl[idx].accepts)
250
+			memset(&accept_tbl[idx].ip, '\0', sizeof(inet_prefix));
251
+		(*sidx)--;
252
+	}
253
+#endif
254
+}
255
+
256
+int close_accept(int idx, int sidx)
257
+{
258
+#if 0
259
+	if(!accept_tbl[idx].accepts) 
260
+		return -1;
261
+	
262
+	accept_tbl[idx].closed[sidx]=1;
263
+#endif
264
+	return 0;
265
+}
266
+
267
+void add_accept_pid(pid_t pid, int idx, int sidx)
268
+{
269
+	/* TODO: activate and test it !! */
270
+#if 0
271
+	accept_tbl[idx].pid[sidx]=pid;
272
+/*	debug(DBG_NOISE, "ACPT: Added pig %d in accept_tbl[%d].pid[%d]", 
273
+			accept_tbl[idx].pid[sidx], idx, sidx);
274
+*/
275
+#endif
276
+}

+ 75
- 0
src/accept.h View File

@@ -0,0 +1,75 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2004 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#ifndef ACCEPT_H
20
+#define ACCEPT_H
21
+
22
+#define MAX_CONNECTIONS		512
23
+
24
+#define MAX_ACCEPTS		16
25
+#define FREE_ACCEPT_TIME	4		/*in seconds*/
26
+
27
+/*
28
+ * This struct keep tracks of single connection to the server.
29
+ * The thread_daemon who handle the connection knows the connection
30
+ * position in the accept_tbl.
31
+ */
32
+struct accept_table
33
+{
34
+	inet_prefix	   ip;			/*Ip of the node connected*/
35
+	unsigned char	   accepts;		/*Number of connection from this node*/
36
+	pid_t              *pid;   	        /*The pid of each child that have accepted the conn*/
37
+	unsigned char      *closed; 		/*Each element of this array is 1 or 0. It indicates if the connection has
38
+                                                  been closed*/
39
+	time_t		   *acp_t;		/*The time when the connection was accepted. The "accepts" counter
40
+						  will decrement when one of the acp_t+FREE_ACCEPT_TIME will 
41
+						  be <= current_time AND (the relative pid will be non existent OR
42
+						  the relative closed element will be == 1)
43
+						 */
44
+	struct request_tbl rqtbl;		/*The request table*/
45
+};
46
+
47
+/* This struct keeps all the info regarding each node connected */
48
+struct accept_table *accept_tbl;
49
+
50
+/* 
51
+ * accept_idx is the position of the accept_tbl of a thread.
52
+ * accept_sidx is the second index, it is used for example in pid[accept_sidx] 
53
+ * note: this var are used only in the child and the child doesn't need to modify them!
54
+ */
55
+int accept_idx, accept_sidx;
56
+pthread_mutex_t mtx_acpt_idx, mtx_acpt_sidx;
57
+
58
+int update_accept_tbl_mutex;
59
+
60
+int max_connections, max_accepts_per_host, free_accept_time;
61
+
62
+void init_accept_tbl(int startups, int accepts, int time);
63
+void destroy_accept_tbl(void);
64
+void update_accept_tbl(void);
65
+int  find_ip_acpt(inet_prefix ip);
66
+int  find_first_free(void);
67
+int  is_ip_acpt_free(inet_prefix ip, int *index);
68
+int  find_free_acp_t(int idx);
69
+int new_accept(int idx, inet_prefix ip);
70
+int add_accept(inet_prefix ip, int replace);
71
+void del_accept(int idx, int *sidx);
72
+int  close_accept(int idx, int sidx);
73
+void add_accept_pid(pid_t pid, int idx, int sidx);
74
+
75
+#endif /*ACCEPT_H*/

+ 2507
- 0
src/andna.c
File diff suppressed because it is too large
View File


+ 273
- 0
src/andna.h View File

@@ -0,0 +1,273 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#ifndef ANDNA_H
20
+#define ANDNA_H
21
+
22
+#include "andna_cache.h"
23
+#include "pkts.h"
24
+
25
+#define MY_NAMESERV		"nameserver 127.0.0.1"
26
+#define MY_NAMESERV_IPV6	"nameserver ::1"
27
+#define ETC_RESOLV_CONF		"/etc/resolv.conf"
28
+#define ETC_RESOLV_CONF_BAK	"/etc/resolv.conf.bak"
29
+
30
+/* How many different andna pkt can be flooded simultaneusly */
31
+#define ANDNA_MAX_FLOODS	(ANDNA_MAX_QUEUE*3+1) 
32
+
33
+/* How many new hash_gnodes are supported in the andna hash_gnode mutation */
34
+#define ANDNA_MAX_NEW_GNODES	1024
35
+
36
+/* 
37
+ * These arrays keeps the latest reg_pkt and counter_check IDs to drop pkts
38
+ * alreay received during the floods. These arrays are a FIFO, so the
39
+ * last pkt_id will be always at the 0 position, while the first one will be
40
+ * at the last position 
41
+ */
42
+int last_reg_pkt_id[ANDNA_MAX_FLOODS];
43
+int last_counter_pkt_id[ANDNA_MAX_FLOODS];
44
+int last_spread_acache_pkt_id[ANDNA_MAX_FLOODS];
45
+
46
+/*\
47
+ *			   *** ANDNA hash notes ***
48
+ * 
49
+ * In ANDNA there are three type of hashes: MD5, 32bit, 32bit hash of a MD5
50
+ * hash. These hashes are generally applied on hostnames.
51
+ *
52
+ * The andna_hash() function, defined in andna.c, is used to calculate 
53
+ * the IP of a hash_node/hash_gnode/counter_node. It makes a MD5 digest of the
54
+ * input data. If we are working on ipv4, then a 32bit hash is applied to the
55
+ * previously calculated MD5 digest. The result is the IP of the hash_gnode.
56
+ * If we are in ipv6, we'll use directly the MD5 digest as the hash_gnode IP.
57
+ *
58
+ * In all the other cases we'll use directly the MD5 hash of the hostname,
59
+ * f.e. the hname hash of the registration and resolution packets is a MD5.
60
+ * The only exceptions are the lcl_cache and the rh_cache, which use
61
+ * internally a 32bit hash to speed up the hname lookups.
62
+ * 
63
+ * The general guideline for new implementation is to always use big hashes
64
+ * (i.e. MD5) where we might get collisions (f.e in an andna_cache), and to
65
+ * use small hashes where we are safe (f.e. in the rhc_cache).
66
+ *
67
+\*/
68
+
69
+
70
+/*\
71
+ *
72
+ *  * * *  ANDNA requests/replies pkt stuff  * * * 
73
+ *
74
+\*/
75
+
76
+#define ANDNA_HOOK_TIMEOUT		8	/* seconds */
77
+#define ANDNA_REV_RESOLVE_RQ_TIMEOUT	60
78
+
79
+/* * * andna pkt flags * * */
80
+#define ANDNA_PKT_UPDATE	1		/* Update the hostname */
81
+#define ANDNA_PKT_FORWARD	(1<<1)		/* Forward this pkt, plz */
82
+#define ANDNA_PKT_REV_RESOLVE	(1<<2)		/* Give me your hostnames */
83
+#define ANDNA_PKT_JUST_CHECK	(1<<3)		/* Check only, don't update
84
+						   anything */
85
+#define ANDNA_PKT_SNSD_DEL	(1<<4)		/* SNSD delete request */
86
+
87
+/*
88
+ * andna_reg_pkt
89
+ * 
90
+ * Andna registration request pkt used to send the registration and update
91
+ * requests to the hash_gnode, backup_gnode and counter_gnode.
92
+ * When the pkt is sent to a counter_gnode, a second `rip', which is the ip
93
+ * of the hash_gnode who is contacting the counter_gnode, is appended at the
94
+ * end of the pkt.
95
+ *
96
+ * When the packet is sent to a hash_gnode, at the end of the packet is 
97
+ * included a packed snsd_service linked list. It is the list of snsd_records
98
+ * that have to be registered. However the packet forwarded to the counter 
99
+ * node won't keep this part.
100
+ */
101
+struct andna_reg_pkt
102
+{
103
+	u_int	 	rip[MAX_IP_INT];	/* register_node ip */
104
+ 	u_int		hash[MAX_IP_INT];	/* md5 hash of the host name to
105
+						   register. */
106
+ 	char		pubkey[ANDNA_PKEY_LEN];	/* public key of the register
107
+ 						   node. */
108
+	u_short		hname_updates;		/* number of updates already 
109
+						   made for the hostname */
110
+	
111
+ 	char		sign[ANDNA_SIGNATURE_LEN]; /* RSA signature of the 
112
+						      entire pkt (excluding 
113
+						      `sign' itself and `flags'
114
+						    */
115
+	char 		flags;
116
+	
117
+} _PACKED_;
118
+#define ANDNA_REG_PKT_SZ	     (sizeof(struct andna_reg_pkt))
119
+#define ANDNA_REG_SIGNED_BLOCK_SZ (ANDNA_REG_PKT_SZ - ANDNA_SIGNATURE_LEN - \
120
+				 	sizeof(char))
121
+INT_INFO andna_reg_pkt_iinfo = 	{ 1, /* `rip' and `hash' aren't considered */
122
+				 { INT_TYPE_16BIT },
123
+				 { MAX_IP_SZ*2 + ANDNA_PKEY_LEN },
124
+				 { 1 },
125
+			  	};
126
+				 
127
+
128
+/*
129
+ *   andna_resolve_rq_pkt
130
+ *
131
+ * The andna resolve request pkt is used to resolve hostnames, IPs and MX
132
+ * hostnames.
133
+ */
134
+struct andna_resolve_rq_pkt
135
+{
136
+	u_int	 	rip[MAX_IP_INT];	/* the ip of the requester node */
137
+	char		flags;
138
+	
139
+	u_int           hash[MAX_IP_INT];       /* md5 hash of the hostname to
140
+						   resolve. */
141
+	int		service;		/* the snsd service of the hname */
142
+	u_char		proto;			/* the protocol of `service' */
143
+} _PACKED_;
144
+#define ANDNA_RESOLVE_RQ_PKT_SZ		(sizeof(struct andna_resolve_rq_pkt))
145
+INT_INFO andna_resolve_rq_pkt_iinfo =	{ 1, /* `rip' and `hash' are ignored */
146
+					  { INT_TYPE_32BIT },
147
+					  { MAX_IP_SZ*2+sizeof(char) },
148
+					  { 1 },
149
+					};
150
+
151
+/* 
152
+ * The reply to the resolve request
153
+ */
154
+struct andna_resolve_reply_pkt
155
+{
156
+	uint32_t	timestamp;		/* the difference between the current
157
+						   time and the last time the resolved
158
+						   hname was updated */
159
+	/*
160
+	 * the rest of the pkt is a pack of one snsd_service llist:
161
+	 * char		service[SNSD_SERVICE_LLIST_PACK_SZ(service)];
162
+	 */
163
+} _PACKED_;
164
+#define ANDNA_RESOLVE_REPLY_PKT_SZ	(sizeof(struct andna_resolve_reply_pkt))
165
+INT_INFO andna_resolve_reply_pkt_iinfo = { 1, /* `ip' is ignored */
166
+					   { INT_TYPE_32BIT }, 
167
+					   { 0 }, 
168
+					   { 1 }
169
+					 };
170
+
171
+
172
+/* 
173
+ * The reply to the reverse resolve request is just the packed local cache.
174
+ */
175
+
176
+
177
+/* 
178
+ * single_acache
179
+ *
180
+ * The single_acache pkt is used to get from an old hash_gnode a single
181
+ * andna_cache, which has the wanted `hash'. Its propagation method is similar
182
+ * to that of andna_resolve_rq_pkt, but each new hash_gnode, which receives
183
+ * the pkt, adds in the body pkt its ip. The added ips are used as excluded 
184
+ * hash_gnode by find_hash_gnode(). In this way each time an old hash_gnode 
185
+ * receives the pkt, can verify if it is, at that current time, the true old 
186
+ * hash_gnode by excluding the hash_gnodes listed in the pkt body. If it 
187
+ * notices that there's an hash_gnode older than it, it will append its ip in 
188
+ * the pkt body and will forward it to that older hash_gnode. And so on, until
189
+ * the pkt reaches a true old hash_gnode, or cannot be forwarded anymore since
190
+ * there are no more older hash_gnodes.
191
+ */
192
+struct single_acache_hdr
193
+{
194
+	u_int		rip[MAX_IP_INT];	/* the ip of the requester node */
195
+	u_int		hash[MAX_IP_INT];
196
+	u_short		hgnodes;		/* Number of hgnodes in the 
197
+						   body. */
198
+	u_char		flags;
199
+} _PACKED_;
200
+INT_INFO single_acache_hdr_iinfo = { 1, /* `rip' and `hash' are ignored */
201
+				     { INT_TYPE_16BIT },
202
+				     { MAX_IP_SZ*2 },
203
+				     { 1 },
204
+				   };
205
+/*
206
+ * The single_acache body is:
207
+ * struct {
208
+ * 	u_int		hgnode[MAX_IP_INT];
209
+ * } body[new_hash_gnode_hdr.hgnodes];
210
+ */
211
+#define SINGLE_ACACHE_PKT_SZ(hgnodes)	(sizeof(struct single_acache_hdr)+\
212
+						MAX_IP_SZ*(hgnodes))
213
+
214
+/*
215
+ * The single_acache_reply is just an andna_cache_pkt with a single cache.
216
+ */
217
+
218
+
219
+/*
220
+ * Tell the node, which receives the pkt, to send a ANDNA_GET_SINGLE_ACACHE
221
+ * request to fetch the andna_cache for the `hash' included in the pkt.
222
+ */
223
+struct spread_acache_pkt
224
+{
225
+	u_int		hash[MAX_IP_INT];
226
+} _PACKED_;
227
+#define SPREAD_ACACHE_PKT_SZ	(sizeof(struct spread_acache_pkt))
228
+INT_INFO spread_acache_pkt_info = { 0, { 0 }, { 0 }, { 0 } };
229
+
230
+
231
+
232
+/*\
233
+ *
234
+ *   * * *  Function declaration  * * *
235
+ *
236
+\*/
237
+
238
+int andna_load_caches(void);
239
+int andna_save_caches(void);
240
+
241
+void andna_init(void);
242
+void andna_close(void);
243
+void andna_resolvconf_modify(void);
244
+void andna_resolvconf_restore(void);
245
+
246
+int andna_register_hname(lcl_cache *alcl, snsd_service *snsd_delete);
247
+int andna_recv_reg_rq(PACKET rpkt);
248
+
249
+int andna_check_counter(PACKET pkt);
250
+int andna_recv_check_counter(PACKET rpkt);
251
+
252
+snsd_service *andna_resolve_hash(u_int hname_hash[MAX_IP_INT], int service, 
253
+				 u_char proto, int *records);
254
+snsd_service *andna_resolve_hname(char *hname, int service, u_char proto, 
255
+				  int *records);
256
+int andna_recv_resolve_rq(PACKET rpkt);
257
+
258
+lcl_cache *andna_reverse_resolve(inet_prefix ip);
259
+int andna_recv_rev_resolve_rq(PACKET rpkt);
260
+
261
+int spread_single_acache(u_int hash[MAX_IP_INT]);
262
+int recv_spread_single_acache(PACKET rpkt);
263
+andna_cache *get_single_andna_c(u_int hash[MAX_IP_INT], u_int hash_gnode[MAX_IP_INT]);
264
+int put_single_acache(PACKET rpkt);
265
+int put_andna_cache(PACKET rq_pkt);
266
+int put_counter_cache(PACKET rq_pkt);
267
+
268
+void *andna_hook(void *);
269
+void andna_update_hnames(int only_new_hname);
270
+void *andna_maintain_hnames_active(void *null);
271
+void *andna_main(void *);
272
+
273
+#endif /*ANDNA_H*/

+ 2154
- 0
src/andna_cache.c
File diff suppressed because it is too large
View File


+ 499
- 0
src/andna_cache.h View File

@@ -0,0 +1,499 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#ifndef ANDNA_CACHE_H
20
+#define ANDNA_CACHE_H
21
+
22
+#include "inet.h"
23
+#include "crypto.h"
24
+#include "endianness.h"
25
+#include "llist.c"
26
+#include "snsd_cache.h"
27
+
28
+/*
29
+ * ANDNA definitions
30
+ */
31
+
32
+#define ANDNA_MAX_BACKUP_GNODES		2
33
+#define ANDNA_MAX_QUEUE			5
34
+#define ANDNA_MAX_HNAME_LEN		512	/* (null terminator included) */
35
+#define ANDNA_MAX_HOSTNAMES		256	/* Max number of hnames per node */
36
+#define ANDNA_MAX_RHC_HNAMES		512	/* Max number of hnames kept in
37
+						   the resolved_hnames cache* */
38
+#define ANDNA_EXPIRATION_TIME		259200	/* 3 days (in seconds)*/
39
+#define ANDNA_MIN_UPDATE_TIME		3600	/* The minum amount of time to
40
+						   be waited before sending an 
41
+						   update of the hname. */
42
+
43
+#define ANDNA_PRIVKEY_BITS		1024
44
+#define ANDNA_SKEY_MAX_LEN		900
45
+#define ANDNA_PKEY_LEN			140
46
+#define ANDNA_HASH_SZ			(MAX_IP_SZ)
47
+#define ANDNA_SIGNATURE_LEN		128
48
+
49
+/* Returns the number of nodes to be used in a backup_gnode */
50
+#define ANDNA_BACKUP_NODES(seeds)	({(seeds) > 8 ? 			\
51
+					  ((seeds)*32)/MAXGROUPNODE : (seeds);})
52
+
53
+#ifdef DEBUG
54
+	#undef ANDNA_EXPIRATION_TIME
55
+	#define ANDNA_EXPIRATION_TIME 100
56
+	#undef ANDNA_MIN_UPDATE_TIME
57
+	#define ANDNA_MIN_UPDATE_TIME 2
58
+#endif 
59
+
60
+/* 
61
+ * * *  Cache stuff  * * *
62
+ */
63
+
64
+/* * andna_cache flags * */
65
+#define ANDNA_BACKUP		1		/* We are a backup_node */
66
+#define ANDNA_COUNTER		(1<<1)		/* We are a counter_node */
67
+#define ANDNA_ROUNDED		(1<<2)		/* We are a rounded_hash_node */
68
+#define ANDNA_FULL		(1<<3)		/* Queue full */
69
+#define ANDNA_UPDATING		(1<<4)		/* The hname is being updated 
70
+						   right now */
71
+
72
+/* 
73
+ * andna_cache_queue
74
+ * 
75
+ * The queue of the andna_cache. (see below).
76
+ */
77
+struct andna_cache_queue
78
+{	
79
+	LLIST_HDR	(struct andna_cache_queue);
80
+		
81
+	time_t		timestamp;
82
+	u_short		hname_updates;		/* numbers of hname's updates */
83
+	char		pubkey[ANDNA_PKEY_LEN];
84
+
85
+	u_short		snsd_counter;		/* # of `snsd' nodes */
86
+	snsd_service	*service;
87
+};
88
+typedef struct andna_cache_queue andna_cache_queue;
89
+		
90
+/*
91
+ * andna_cache
92
+ * 
93
+ * It keeps the entries of the hostnames registered by other nodes.
94
+ */
95
+struct andna_cache
96
+{
97
+	LLIST_HDR	(struct andna_cache);
98
+	
99
+	u_int 		hash[MAX_IP_INT];	/* hostname's hash */
100
+	char 		flags;
101
+
102
+	u_short		queue_counter;
103
+	andna_cache_queue *acq;			/* The queue of the registration.
104
+						   The first is the active one */
105
+};
106
+typedef struct andna_cache andna_cache;
107
+
108
+/* part of the counter cache, see below */
109
+struct counter_c_hashes
110
+{
111
+	LLIST_HDR	(struct counter_c_hashes);
112
+
113
+	time_t		timestamp;
114
+	u_short		hname_updates;
115
+	int		hash[MAX_IP_INT];
116
+};
117
+typedef struct counter_c_hashes counter_c_hashes;
118
+INT_INFO counter_c_hashes_body_iinfo = { 2, 
119
+					 { INT_TYPE_32BIT, INT_TYPE_16BIT },
120
+					 { 0, sizeof(time_t) },
121
+					 { 1, 1 }
122
+				       };
123
+
124
+/*
125
+ * counter_c
126
+ * Counter node's cache.
127
+ *
128
+ * All the infos regarding a particular register_node are stored here. For
129
+ * example, we need to know how many hostnames he already registered.
130
+ */
131
+struct counter_c
132
+{
133
+	LLIST_HDR	(struct counter_c);
134
+
135
+	char            pubkey[ANDNA_PKEY_LEN];
136
+	char		flags;
137
+	
138
+	u_short		hashes;			/* The number of hashes in cch */
139
+	counter_c_hashes *cch;			/* The hashes of the hnames */
140
+};
141
+typedef struct counter_c counter_c;
142
+INT_INFO counter_c_body_iinfo = { 1,
143
+				  { INT_TYPE_16BIT },
144
+				  { ANDNA_PKEY_LEN+sizeof(char) },
145
+				  { 1 }
146
+				};
147
+
148
+/*
149
+ * lcl_cache_keyring
150
+ *
151
+ * The lcl keyring is used to store the RSA keys used to complete some of the
152
+ * ANDNA requests, (f.e. registering or updating a hname).
153
+ */
154
+typedef struct
155
+{
156
+	u_int		skey_len;
157
+	u_int		pkey_len;
158
+	
159
+	u_char		*privkey;		/* secret key packed */
160
+	u_char		*pubkey;		/* pubkey packed */
161
+
162
+	RSA		*priv_rsa;		/* key pair unpacked */
163
+} lcl_cache_keyring;
164
+
165
+
166
+/*
167
+ * lcl_cache
168
+ * 
169
+ * The Local Andna Cache keeps all the hostnames which have been register by
170
+ * localhost (ourself).
171
+ */
172
+struct lcl_cache
173
+{
174
+	LLIST_HDR	(struct lcl_cache);
175
+
176
+	char		*hostname;		/* The registered hostname */
177
+	u_int		hash;			/* 32bit hash of the md5 hash 
178
+						   of the hname */
179
+	u_short		hname_updates;		/* How many updates we've done 
180
+						   for this hostname */
181
+	time_t          timestamp;		/* the last time when the hname
182
+						   was updated. If it is 0, the
183
+						   hname has still to be 
184
+						   registered */
185
+	
186
+	u_short		snsd_counter;		/* # of `snsds' */
187
+	snsd_service	*service;
188
+	
189
+	char 		flags;
190
+};
191
+typedef struct lcl_cache lcl_cache;
192
+
193
+
194
+/*
195
+ * resolved_hnames_cache
196
+ *
197
+ * This cache keeps info on the already resolved hostnames, so we won't have
198
+ * to resolve them soon again.
199
+ * In order to optimize the search we order the linked list by the time
200
+ * of hname resolution. The last hname which has been searched/resolved is
201
+ * always moved at the head of the llist, in this way, at the end of the llist
202
+ * there is the hname which has been searched for the first time but has been
203
+ * ignored until now.
204
+ * When the cache is full, the hname which is at the end of the llist is
205
+ * removed to empty new space.
206
+ * The hname which have the `timestamp' expired are removed too.
207
+ */
208
+struct resolved_hnames_cache
209
+{
210
+	LLIST_HDR	(struct resolved_hnames_cache);
211
+
212
+	u_int		hash;		/* 32bit hash of the md5 hash of the
213
+					   hname */
214
+	char		flags;
215
+	
216
+	time_t		timestamp;	/* the last time when the hname
217
+					   was updated. With this we know that
218
+					   at timestamp+ANDNA_EXPIRATION_TIME
219
+					   this cache will expire. */
220
+	
221
+	u_short		snsd_counter;
222
+	snsd_service	*service;
223
+};
224
+typedef struct resolved_hnames_cache rh_cache;
225
+
226
+
227
+/*
228
+ *  * * *  Global vars   * * *
229
+ */
230
+andna_cache *andna_c;
231
+int andna_c_counter;
232
+
233
+counter_c *andna_counter_c;
234
+int cc_counter;
235
+
236
+lcl_cache_keyring lcl_keyring;
237
+lcl_cache *andna_lcl;
238
+int lcl_counter;
239
+
240
+rh_cache *andna_rhc;
241
+int rhc_counter;
242
+
243
+
244
+/*
245
+ * 
246
+ *  *  *  *  Package stuff  *  *  * 
247
+ *  
248
+ */
249
+
250
+
251
+/*
252
+ *  * * * lcl cache package * * *
253
+ */
254
+
255
+struct lcl_keyring_pkt_hdr
256
+{
257
+	u_int		skey_len;
258
+	u_int		pkey_len;
259
+}_PACKED_;
260
+/* 
261
+ * the rest of the pkt is:
262
+ * 
263
+ *	char		privkey[hdr.skey_len];
264
+ *	char		pubkey[hdr.pkey_len];
265
+ */
266
+INT_INFO lcl_keyring_pkt_hdr_iinfo = { 2, 
267
+				     { INT_TYPE_32BIT, INT_TYPE_32BIT }, 
268
+				     { 0, sizeof(u_int) }, 
269
+				     { 1, 1 } 
270
+				   };
271
+#define LCL_KEYRING_HDR_PACK_SZ(khdr)	(sizeof(struct lcl_keyring_pkt_hdr) + \
272
+					(khdr)->skey_len + (khdr)->pkey_len)
273
+
274
+/*
275
+ * The local cache pkt is used to pack the entire local cache to save it in a 
276
+ * file or to send it to a node.
277
+ */
278
+struct lcl_cache_pkt_hdr
279
+{
280
+	u_short		tot_caches;		/* How many lcl structs there 
281
+						   are in the pkt's body */
282
+}_PACKED_;
283
+INT_INFO lcl_cache_pkt_hdr_iinfo = { 1, { INT_TYPE_16BIT }, { 0 }, { 1 } };
284
+#define LCL_CACHE_HDR_PACK_SZ		(sizeof(struct lcl_cache_pkt_hdr))
285
+		
286
+/* 
287
+ * The body is:
288
+ *	
289
+ * struct lcl_cache_pkt_body {
290
+ *	u_short		hname_updates;
291
+ *	time_t          timestamp;
292
+ *	char		hostname[strlen(hostname)+1];  * null terminated *
293
+ * } body[ hdr.tot_caches ];
294
+ * 
295
+ */
296
+#define LCL_CACHE_BODY_PACK_SZ(hname_len) 	((hname_len) + sizeof(u_short) \
297
+						  + sizeof(time_t))
298
+INT_INFO lcl_cache_pkt_body_iinfo = { 2, { INT_TYPE_16BIT, INT_TYPE_32BIT }, 
299
+				      { 0, sizeof(u_short) },
300
+				      { 1, 1 }
301
+				    };
302
+
303
+/*
304
+ *  * * * andna cache package * * *
305
+ */
306
+
307
+/*
308
+ * the body of the acq_pkt is:
309
+ * struct acq_pkt_body {
310
+ * 	time_t		timestamp;
311
+ * 	u_short		hname_updates;
312
+ * 	char		pubkey[ANDNA_PKEY_LEN];
313
+ *
314
+ * 	u_short		snsd_counter;
315
+ * 	char		snsd_service_pack[SNSD_SERVICE_PACK_SZ];
316
+ * };
317
+ */
318
+INT_INFO acq_body_iinfo = { 3,
319
+			    { INT_TYPE_32BIT, INT_TYPE_16BIT, INT_TYPE_16BIT },
320
+			    { 0, sizeof(time_t),
321
+				    sizeof(time_t) + sizeof(u_short) + ANDNA_PKEY_LEN },
322
+			    { 1, 1, 1 }
323
+			  };
324
+#define ACQ_BODY_PACK_SZ		(sizeof(time_t) + sizeof(u_short)*2 + \
325
+					 ANDNA_PKEY_LEN)
326
+#define ACQ_PACK_SZ(snsd_pack_sz)	(ACQ_BODY_PACK_SZ + (snsd_pack_sz))
327
+
328
+struct andna_cache_pkt_hdr
329
+{
330
+	u_short		tot_caches;
331
+}_PACKED_;
332
+INT_INFO andna_cache_pkt_hdr_iinfo = { 1, { INT_TYPE_16BIT }, { 0 }, { 1 } };
333
+/*
334
+ * The body is:
335
+ * struct andna_cache_pack {
336
+ * 	u_int		hash[MAX_IP_INT];
337
+ * 	char		flags;
338
+ * 	u_short		queue_counter;
339
+ * 	char		acq_pack[ACQ_PACK_SZ*queue_counter];
340
+ * } acache_pack[hdr.tot_caches];
341
+ */
342
+INT_INFO andna_cache_body_iinfo = { 1, 
343
+				    { INT_TYPE_16BIT },
344
+				    { MAX_IP_SZ+sizeof(char) },
345
+				    { 1 }
346
+				  };
347
+#define ACACHE_BODY_PACK_SZ		(ANDNA_HASH_SZ + sizeof(char) + 	\
348
+					   sizeof(u_short))
349
+#define ACACHE_PACK_SZ(acq_pack_sz)	((acq_pack_sz) + ACACHE_BODY_PACK_SZ)
350
+
351
+/*
352
+ * If the acache pack will be sent on a network packet, the `acq->timestamp' 
353
+ * will be the difference of the current time with the same `acq->timestamp',
354
+ * in this way the node which receives the packet will add its current time to
355
+ * `acq->timestamp'. This is necessary because the sending and receiving node
356
+ * don't have the clock synced. Note that the rtt isn't considered because it
357
+ * is generally very small and the ANDNA times don't need an accurate
358
+ * precision, f.e. the expiration time is three days long.
359
+ * If the pack is saved on a file, then `acq->timestamp' remains the same.
360
+ * Problem: if the clock is changed, acq->timestamp will refer to the old
361
+ * clock.
362
+ */
363
+#define ACACHE_PACK_FILE		1
364
+#define ACACHE_PACK_PKT			2
365
+
366
+
367
+/*
368
+ * The counter cache pkt is similar to the andna_cache_pkt, it is completely
369
+ * arranged in the same way.
370
+ */
371
+struct counter_c_pkt_hdr
372
+{
373
+	u_short		tot_caches;
374
+}_PACKED_;
375
+INT_INFO counter_c_pkt_hdr_iinfo = { 1, { INT_TYPE_16BIT }, { 0 }, { 1 } };
376
+#define COUNTER_CACHE_HASHES_PACK_SZ	(sizeof(time_t) + sizeof(u_short) +	\
377
+						ANDNA_HASH_SZ)
378
+#define COUNTER_CACHE_BODY_PACK_SZ	(ANDNA_PKEY_LEN + sizeof(char)    + 	\
379
+						sizeof(u_short))
380
+#define COUNTER_CACHE_PACK_SZ(hashes)	((COUNTER_CACHE_HASHES_PACK_SZ*(hashes))\
381
+					 + COUNTER_CACHE_BODY_PACK_SZ)
382
+
383
+/* 
384
+ *  * * * Resolved hostnames cache pkt. * * *
385
+ */
386
+
387
+struct rh_cache_pkt_hdr
388
+{
389
+	u_short		tot_caches;		/* How many lcl structs there 
390
+						   are in the pkt's hdr */
391
+}_PACKED_;
392
+INT_INFO rh_cache_pkt_hdr_iinfo = { 1, { INT_TYPE_16BIT }, { 0 }, { 1 } };
393
+/*
394
+ * The body is:
395
+ * struct rh_cache_pkt_body {
396
+ *	u_int		hash;
397
+ *	char		flags;
398
+ *	time_t		timestamp;
399
+ *
400
+ * 	u_short		snsd_counter;
401
+ * 	char		snsd_service_pack[SNSD_SERVICE_PACK_SZ];
402
+ * } body[ hdr.tot_caches ];
403
+ */
404
+#define RH_CACHE_BODY_PACK_SZ(snsd_pack_sz)	(sizeof(u_int)+sizeof(char)+ \
405
+						 sizeof(time_t)+sizeof(u_short)+\
406
+						 (snsd_pack_sz))
407
+INT_INFO rh_cache_pkt_body_iinfo = { 3,
408
+				    { INT_TYPE_32BIT, INT_TYPE_32BIT, INT_TYPE_16BIT },
409
+				    { 0, sizeof(u_int)+sizeof(char), 
410
+					    sizeof(u_int)+sizeof(char)+sizeof(time_t) },
411
+				    { 1, 1, 1 }
412
+				   };
413
+
414
+
415
+/*
416
+ * * * Functions' declaration * * *
417
+ */
418
+
419
+void andna_caches_init(int family);
420
+
421
+void lcl_new_keyring(lcl_cache_keyring *keyring);
422
+void lcl_destroy_keyring(lcl_cache_keyring *keyring);
423
+lcl_cache *lcl_cache_new(char *hname);
424
+void lcl_cache_free(lcl_cache *alcl);
425
+void lcl_cache_destroy(lcl_cache *head, int *counter);
426
+lcl_cache *lcl_cache_find_hname(lcl_cache *head, char *hname);
427
+lcl_cache *lcl_cache_find_hash(lcl_cache *alcl, u_int hash);
428
+lcl_cache *lcl_get_registered_hnames(lcl_cache *alcl);
429
+
430
+andna_cache_queue *ac_queue_findpubk(andna_cache *ac, char *pubk);
431
+andna_cache_queue *ac_queue_add(andna_cache *ac, char *pubkey);
432
+void ac_queue_del(andna_cache *ac, andna_cache_queue *acq);
433
+void ac_queue_del_expired(andna_cache *ac);
434
+void ac_queue_destroy(andna_cache *ac);
435
+andna_cache *andna_cache_findhash(int hash[MAX_IP_INT]);
436
+andna_cache *andna_cache_gethash(int hash[MAX_IP_INT]);
437
+andna_cache *andna_cache_addhash(int hash[MAX_IP_INT]);
438
+int andna_cache_del_ifexpired(andna_cache *ac);
439
+void andna_cache_del_expired(void);
440
+void andna_cache_destroy(void);
441
+
442
+counter_c_hashes *cc_hashes_add(counter_c *cc, int hash[MAX_IP_INT]);
443
+void cc_hashes_del(counter_c *cc, counter_c_hashes *cch);
444
+int counter_c_del_ifexpired(counter_c *cc);
445
+void cc_hashes_del_expired(counter_c *cc);
446
+void cc_hashes_destroy(counter_c *cc);
447
+counter_c_hashes *cc_findhash(counter_c *cc, int hash[MAX_IP_INT]);
448
+counter_c *counter_c_findpubk(char *pubk);
449
+counter_c *counter_c_add(inet_prefix *rip, char *pubkey);
450
+void counter_c_del_expired(void);
451
+void counter_c_destroy(void);
452
+
453
+rh_cache *rh_cache_new(char *hname, time_t timestamp);
454
+rh_cache *rh_cache_add_hash(u_int hash, time_t timestamp);
455
+rh_cache *rh_cache_add(char *hname, time_t timestamp);
456
+rh_cache *rh_cache_find_hash(u_int hash);
457
+rh_cache *rh_cache_find_hname(char *hname);
458
+void rh_cache_del(rh_cache *rhc);
459
+void rh_cache_del_expired(void);
460
+void rh_cache_flush(void);
461
+
462
+char *pack_lcl_keyring(lcl_cache_keyring *keyring, size_t *pack_sz);
463
+int unpack_lcl_keyring(lcl_cache_keyring *keyring, char *pack, size_t pack_sz);
464
+
465
+char *pack_lcl_cache(lcl_cache *local_cache, size_t *pack_sz);
466
+lcl_cache *unpack_lcl_cache(char *pack, size_t pack_sz, int *counter);
467
+
468
+char *pack_andna_cache(andna_cache *acache, size_t *pack_sz, int pack_type);
469
+andna_cache *unpack_andna_cache(char *pack, size_t pack_sz, int *counter,
470
+				int pack_type);
471
+
472
+char *pack_counter_cache(counter_c *countercache,  size_t *pack_sz);
473
+counter_c *unpack_counter_cache(char *pack, size_t pack_sz, int *counter);
474
+
475
+char *pack_rh_cache(rh_cache *rhcache, size_t *pack_sz);
476
+rh_cache *unpack_rh_cache(char *pack, size_t pack_sz, int *counter);
477
+
478
+int save_lcl_keyring(lcl_cache_keyring *keyring, char *file);
479
+int load_lcl_keyring(lcl_cache_keyring *keyring, char *file);
480
+
481
+int save_lcl_cache(lcl_cache *lcl, char *file);
482
+lcl_cache *load_lcl_cache(char *file, int *counter);
483
+
484
+int save_andna_cache(andna_cache *acache, char *file);
485
+andna_cache *load_andna_cache(char *file, int *counter);
486
+
487
+int save_counter_c(counter_c *countercache, char *file);
488
+counter_c *load_counter_c(char *file, int *counter);
489
+
490
+int save_rh_cache(rh_cache *rh, char *file);
491
+rh_cache *load_rh_cache(char *file, int *counter);
492
+
493
+int load_hostnames(char *file, lcl_cache **old_alcl_head, int *old_alcl_counter);
494
+int load_snsd(char *file, lcl_cache *alcl_head);
495
+
496
+int add_resolv_conf(char *hname, char *file);
497
+int del_resolv_conf(char *hname, char *file);
498
+
499
+#endif		/*ANDNA_CACHE_H*/

+ 959
- 0
src/andns.c View File

@@ -0,0 +1,959 @@
1
+	         /**************************************
2
+	        *     AUTHOR: Federico Tomassini        *
3
+	       *     Copyright (C) Federico Tomassini    *
4
+	      *     Contact effetom@gmail.com             *
5
+	     ***********************************************
6
+	     *******          BEGIN 3/2006          ********
7
+*************************************************************************
8
+*                                              				* 
9
+*  This program is free software; you can redistribute it and/or modify	*
10
+*  it under the terms of the GNU General Public License as published by	*
11
+*  the Free Software Foundation; either version 2 of the License, or	*
12
+*  (at your option) any later version.					*
13
+*									*
14
+*  This program is distributed in the hope that it will be useful,	*
15
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of	*
16
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the	*
17
+*  GNU General Public License for more details.				*
18
+*									*
19
+************************************************************************/
20
+
21
+#define _GNU_SOURCE
22
+#include <string.h>
23
+#include <netdb.h>
24
+
25
+#include "includes.h"
26
+#include "common.h"
27
+#include "andns.h"
28
+#include "err_errno.h"
29
+#include "andna.h"
30
+#include "andns_lib.h"
31
+#include "andns_net.h"
32
+#include "andns_snsd.h"
33
+#include "dnslib.h"
34
+
35
+
36
+static uint8_t _dns_forwarding_;
37
+static uint8_t _andns_ns_count_;
38
+static uint8_t _default_realm_;
39
+
40
+static struct addrinfo _ns_filter_;
41
+static struct addrinfo *_andns_ns_[MAXNSSERVERS];
42
+
43
+static int _ip_len_;
44
+
45
+/* Debugging Functions to isolate andns from andna
46
+snsd_service* debug_andna_resolve_hname(char *s,int service,u_char proto,int *records)
47
+{
48
+        char *ciccio="111.222.123.123";
49
+	debug(DBG_NORMAL,"Entering debug_andna_resolve.");
50
+	snsd_service *ss;
51
+	snsd_prio *sp;
52
+	snsd_node *sn;
53
+	ss=xmalloc(sizeof(snsd_service));
54
+	ss->prio=xmalloc(sizeof(snsd_prio));
55
+	sp=ss->prio;
56
+	sp->node=xmalloc(sizeof(snsd_node));
57
+	sn=sp->node;
58
+	inet_pton(AF_INET,ciccio,sn->record);
59
+	sn->flags|=SNSD_NODE_MAIN_IP;
60
+	sn->flags|=SNSD_NODE_IP;
61
+	ss->next=0;
62
+	ss->prev=0;
63
+	sp->next=0;
64
+	sp->prev=0;
65
+	sn->next=0;
66
+	sn->prev=0;
67
+	*records=1;
68
+        return ss;
69
+}
70
+lcl_cache* debug_andna_reverse_resolve(inet_prefix addr)
71
+{
72
+	lcl_cache *lc;
73
+	debug(DBG_NORMAL,"Entering debug_andna_reverse.");
74
+	lc=xmalloc(sizeof(lcl_cache));
75
+	memset(lc,0,sizeof(lcl_cache));
76
+	lc->hostname=xmalloc(12);
77
+	strcpy(lc->hostname,"Ciao mamma");
78
+	return lc;
79
+}*/
80
+
81
+
82
+
83
+
84
+			/* INIT FUNCTIONS */
85
+
86
+
87
+/*
88
+ * Saves on `nsbuf' and `ns_count' the ip
89
+ * address ns: these infos will be used for DNS
90
+ * forwarding.
91
+ *
92
+ * Returns:
93
+ *      -1 on error
94
+ *       0 if OK
95
+ */
96
+int store_ns(char *ns)
97
+{
98
+        int res;
99
+	struct addrinfo **ai;
100
+
101
+        if (strstr(ns, "127.0.0.")) /* TODO: make it proto independent  */
102
+                return -1;
103
+
104
+	ai=&_andns_ns_[_andns_ns_count_];
105
+	res=getaddrinfo(ns, DNS_PORT_STR, &_ns_filter_, ai);
106
+	if (res) {
107
+		debug(DBG_NORMAL,"In store_ns(): gai `%s' -> %s",ns,gai_strerror(errno));
108
+		return -1;
109
+	}
110
+	_andns_ns_count_++;
111
+        return 0;
112
+}
113
+/*
114
+ * Reads resolv.conf, searching nameserver lines.
115
+ * Takes the ip address from these lines and calls store_ns.
116
+ * "nameserver 127.0.0.1" is discarded to remove looping behaviors.
117
+ * The number of stored nameservers is written in
118
+ * `*ns_count' and it is returned.
119
+ * If an error occurred or no hostnames are available, -1 is returned.
120
+ */
121
+int collect_resolv_conf(char *resolve_conf)
122
+{
123
+        FILE *erc;
124
+        char buf[512],*crow;
125
+
126
+        if (!(erc=fopen(resolve_conf,"r"))) {
127
+                error("In collect_resolv_conf: "
128
+			"error -> %s.", strerror(errno));
129
+		err_ret(ERR_RSLERC,-1);
130
+        }
131
+        while ((crow=fgets(buf,512,erc)) && _andns_ns_count_<MAXNSSERVERS) {
132
+                if (!(crow=strstr(buf,"nameserver "))) /* is a good line? */
133
+                        continue;
134
+		
135
+		/* Skip if the line is commented */
136
+		*crow=0;
137
+		if(strchr(buf, '#'))
138
+			continue;
139
+		
140
+                crow+=11;
141
+	
142
+		/* remove unwanted chars */
143
+		strip_char(crow, '\t');
144
+		strip_char(crow, ' ');
145
+		strip_char(crow, '\n');
146
+			
147
+                store_ns(crow); /* finally store nameserver */
148
+        }
149
+        if (fclose(erc)!=0) {
150
+                error("In collect_resolv_conf: closing "
151
+			"resolv.conf -> %s",strerror(errno));
152
+		err_ret(ERR_RSLERC,-1);
153
+        }
154
+        if (!_andns_ns_count_) 
155
+		err_ret(ERR_RSLNNS,-1);
156
+        return _andns_ns_count_;
157
+}
158
+
159
+void reset_andns_ns(void)
160
+{
161
+	int i;
162
+	for(i=0;  i<_andns_ns_count_; i++)
163
+		if(_andns_ns_[i])
164
+			freeaddrinfo(_andns_ns_[i]);
165
+	_andns_ns_count_=0;
166
+	setzero(_andns_ns_, sizeof(struct addrinfo *)*MAXNSSERVERS);
167
+}
168
+
169
+/*
170
+ * This function must be called before all.
171
+ * Sets the default realm for domain name resolution
172
+ * and stores infos about nameservers for dns query.
173
+ * On error -1 is returned.
174
+ */
175
+int andns_init(int restricted, char *resolv_conf,int family)
176
+{
177
+        int i,res;
178
+        char msg[(INET6_ADDRSTRLEN+2)*MAXNSSERVERS];
179
+        char buf[INET6_ADDRSTRLEN];
180
+        struct addrinfo *ai;
181
+
182
+	memset(&_ns_filter_,0,sizeof(struct addrinfo));
183
+
184
+	_ns_filter_.ai_socktype=SOCK_DGRAM;
185
+	_ip_len_=family==AF_INET?4:16;
186
+
187
+        _default_realm_=(restricted)?INET_REALM:NTK_REALM;
188
+        _andns_ns_count_=0;
189
+	setzero(_andns_ns_, sizeof(struct addrinfo *)*MAXNSSERVERS);
190
+
191
+        memset(msg,0,(INET_ADDRSTRLEN+2)*MAXNSSERVERS);
192
+
193
+	if(_default_realm_ == NTK_REALM) {
194
+		/* We are in NTK realm, every IP is assigned to Netsukuku,
195
+		 * therefore dns forwarding is meaningless */
196
+		_dns_forwarding_=0;
197
+		return 0;
198
+	}
199
+
200
+	res=collect_resolv_conf(resolv_conf);
201
+	if (res <=0) {
202
+		_dns_forwarding_=0;
203
+		debug(DBG_NORMAL,err_str);
204
+		err_ret(ERR_RSLAIE,-1);
205
+	}
206
+
207
+	/*
208
+         * Debug message
209
+         */
210
+        for (i=0;i<_andns_ns_count_;i++) {
211
+		ai=_andns_ns_[i];
212
+		res=idp_inet_ntop(ai->ai_family,ai->ai_addr,buf,
213
+					INET6_ADDRSTRLEN);
214
+		if (!res) {
215
+                        strncat(msg,buf,INET_ADDRSTRLEN);
216
+                        strncat(msg,i==_andns_ns_count_-1?". ":", ",2);
217
+                } else
218
+                        error("In andns_init: error "
219
+				"converting sockaddr -> %s.",\
220
+				strerror(errno));
221
+        }
222
+	loginfo("Inet DNS queries will be forwarded to: %s",msg);
223
+
224
+        _dns_forwarding_=1;
225
+        return 0;
226
+}
227
+
228
+void andns_close(void)
229
+{
230
+	reset_andns_ns();
231
+}
232
+
233
+
234
+			/* NET FUNCTIONS */
235
+
236
+int ns_general_send(char *msg,int msglen,char *answer,int anslen)
237
+{
238
+        int res,i;
239
+
240
+        for (i=0; i<_andns_ns_count_;i++) {
241
+		res=ai_send_recv_close(_andns_ns_[i],msg,msglen,
242
+				answer,anslen,0,0,ANDNS_TIMEOUT);
243
+                if(res != -1) {
244
+                        return res;
245
+		}
246
+        }
247
+
248
+        err_ret(ERR_RSLFDQ,-1);
249
+}
250
+
251
+			/* UTILS FUNCTIONS */
252
+
253
+/*
254
+ * Make a copy of DNS pkt data. If prefix is not NULL,
255
+ * the prefix is added to strings.
256
+ */
257
+void dpktacpy(dns_pkt *dst,dns_pkt *src,const char *prefix)
258
+{
259
+        dns_pkt_a *dpas,*dpad;
260
+        int slen;
261
+        int yet_pref=0;
262
+        char temp[257];
263
+
264
+        dpas=src->pkt_answ;
265
+        while(dpas) {
266
+                dpad=DP_ADD_ANSWER(dst);
267
+                memcpy(dpad,dpas,sizeof(dns_pkt_a));
268
+                dpad->next=NULL;
269
+                if (prefix && !yet_pref) { /* TODO: yet_pref better */
270
+                        slen=strlen(dpad->name);
271
+                        if (dpas->type!=T_PTR)
272
+                                memcpy(dpad->name+slen,prefix,REALM_PREFIX_LEN);
273
+                        else {
274
+                                strcpy(temp,dpad->name);
275
+                                memcpy(dpad->name,prefix+1,REALM_PREFIX_LEN-1);
276
+                                dpad->name[REALM_PREFIX_LEN-1]='.';
277
+                                strcpy(dpad->name+REALM_PREFIX_LEN,temp);
278
+                        }
279
+                        *(dpad->name+slen+REALM_PREFIX_LEN)=0;
280
+                        yet_pref=1;
281
+                }
282
+                dpas=dpas->next;
283
+        }
284
+        dpas=src->pkt_auth;
285
+        while(dpas) {
286
+                dpad=DP_ADD_AUTH(dst);
287
+                memcpy(dpad,dpas,sizeof(dns_pkt_a));
288
+                dpad->next=NULL;
289
+                dpas=dpas->next;
290
+        }
291
+        dpas=src->pkt_add;
292
+        while(dpas) {
293
+                dpad=DP_ADD_ADD(dst);
294
+                memcpy(dpad,dpas,sizeof(dns_pkt_a));
295
+                dpad->next=NULL;
296
+                dpas=dpas->next;
297
+        }
298
+}
299
+
300
+/*
301
+ * Make a full copy of a dns pkt. If prefix is not
302
+ * null, prefix is added to names.
303
+ */
304
+dns_pkt* dpktcpy(dns_pkt *src,const char *prefix)
305
+{
306
+        dns_pkt *dst;
307
+        dns_pkt_qst *dpq,*dpq_src;
308
+
309
+        dst=create_dns_pkt();
310
+        memcpy(dst,src,sizeof(dns_pkt));
311
+        dst->pkt_qst=NULL;
312
+        dst->pkt_answ=NULL;
313
+        dst->pkt_auth=NULL;
314
+        dst->pkt_add=NULL;
315
+
316
+        dpq_src=src->pkt_qst;
317
+        while (dpq_src) {
318
+                dpq=dns_add_qst(dst);
319
+                memcpy(dpq,dpq_src,sizeof(dns_pkt_qst));
320
+		dpq->next=NULL;
321
+                dpq_src=dpq_src->next;
322
+        }
323
+        dpktacpy(dst,src,prefix);
324
+        return dst;
325
+}
326
+
327
+/*
328
+ * Remove the suffix realm, if any.
329
+ * Writes the result on dst.
330
+ */
331
+char* rm_realm_prefix(char *from,char *dst,int type)
332
+{
333
+        int slen;
334
+        slen=strlen(from);
335
+
336
+        if (slen<5)
337
+                strcpy(dst,from);
338
+        else if (type==T_PTR) {
339
+                if (strcasestr(from,PTR_INET_REALM_PREFIX)==from ||
340
+                    strcasestr(from,PTR_NTK_REALM_PREFIX)==from)
341
+                        strcpy(dst,from+REALM_PREFIX_LEN);
342
+                else
343
+                        strcpy(dst,from);
344
+
345
+        } else if (strcasestr(from+slen-REALM_PREFIX_LEN,INET_REALM_PREFIX) ||
346
+                 strcasestr(from+slen-REALM_PREFIX_LEN,NTK_REALM_PREFIX)) {
347
+                        strncpy(dst,from,slen-REALM_PREFIX_LEN);
348
+			dst[slen-REALM_PREFIX_LEN]=0;
349
+	} else
350
+                strcpy(dst,from);
351
+        return dst;
352
+}
353
+
354
+/* Make a copy of a dns pkt, only for headers and questions.
355
+ * If the question is prefixed, the prefix is removed.
356
+ */
357
+dns_pkt* dpktcpy_rm_pref(dns_pkt *src)
358
+{
359
+	dns_pkt *dst;
360
+	dns_pkt_qst *dpq;
361
+//	char temp[DNS_MAX_HNAME_LEN];
362
+
363
+	dst=dpktcpy(src,NULL);
364
+	dpq=dst->pkt_qst;
365
+	rm_realm_prefix(src->pkt_qst->qname,dpq->qname,dpq->qtype);
366
+//	strcpy(dpq->qname,temp);
367
+	return dst;
368
+}
369
+int andns_realm(dns_pkt_qst *dpq,int *prefixed)
370
+{
371
+        int slen;
372
+        char *qst;
373
+
374
+        qst=dpq->qname;
375
+
376
+        if (!qst)
377
+                err_ret(ERR_UFOERR,-1);
378
+        slen=strlen(qst);
379
+
380
+        /* if qst is tto short, it's impossible to
381
+           consider a prefix. */
382
+        if (slen<5) return _default_realm_;
383
+
384
+        if (dpq->qtype==T_PTR) {
385
+                if (strcasestr(qst,PTR_INET_REALM_PREFIX)==qst) {
386
+                        if (prefixed) *prefixed=1;
387
+                        return INET_REALM;
388
+                }
389
+                if (strcasestr(qst,PTR_NTK_REALM_PREFIX)==qst) {
390
+                        if (prefixed) *prefixed=1;
391
+                        return NTK_REALM;
392
+                }
393
+                if (prefixed) *prefixed=0;
394
+                return _default_realm_;
395
+        }
396
+        if (strcasestr(qst+slen-REALM_PREFIX_LEN,INET_REALM_PREFIX)) {
397
+                if (prefixed) *prefixed=1;
398
+                return INET_REALM;
399
+        }
400
+        if (strcasestr(qst+slen-REALM_PREFIX_LEN,NTK_REALM_PREFIX)) {
401
+                if (prefixed) *prefixed=1;
402
+                return NTK_REALM;
403
+        }
404
+        if (prefixed) *prefixed=0;
405
+        return _default_realm_;
406
+}
407
+/*
408
+ * Returns:
409
+ *      0 if the question does not have a suffix
410
+ *      1 if the question has suffix
411
+ */
412
+int is_prefixed(dns_pkt *dp)
413
+{
414
+        int prefix=0;
415
+
416
+        andns_realm(dp->pkt_qst,&prefix);
417
+        return prefix;
418
+}
419
+
420
+/*
421
+ * A very stupid function that converts 
422
+ * ANDNS code to DNS code.
423
+ */
424
+int qtype_a_to_d(andns_pkt *ap) 
425
+{
426
+	switch (ap->qtype) {
427
+		case AT_PTR:
428
+			return T_PTR;
429
+		case AT_A:
430
+			if (ap->service==25)
431
+				return T_MX;
432
+			else if (!ap->service)
433
+				return T_A;
434
+			else 
435
+				return -1;
436
+		default:
437
+			return -1;
438
+	}
439
+}
440
+int apqsttodpqst(andns_pkt *ap,dns_pkt **dpsrc)
441
+{
442
+	dns_pkt *dp;
443
+	dns_pkt_hdr *dph;
444
+	dns_pkt_qst *dpq;
445
+	int res,qt;
446
+	int qlen,family;
447
+
448
+	qt=qtype_a_to_d(ap);
449
+	if (qt==-1)
450
+		err_ret(ERR_ANDNCQ,-1);
451
+
452
+	*dpsrc=create_dns_pkt();
453
+	dp=*dpsrc;
454
+	dph=&(dp->pkt_hdr);
455
+	dpq=dns_add_qst(dp);
456
+
457
+	if (qt==T_A || qt==T_MX) {
458
+		qlen=strlen(ap->qstdata);
459
+		if (qlen>DNS_MAX_HNAME_LEN) 
460
+			goto incomp_err;
461
+		strcpy(dpq->qname,ap->qstdata);
462
+	}
463
+	else if (qt==T_PTR) {
464
+		char temp[DNS_MAX_HNAME_LEN];
465
+		qlen=ap->qstlength;
466
+		if (qlen==4)
467
+			family=AF_INET;
468
+		else if (qlen==16)
469
+			family=AF_INET6;
470
+		else
471
+			goto incomp_err;
472
+		if (!inet_ntop(family,ap->qstdata,temp,
473
+				DNS_MAX_HNAME_LEN)) {
474
+			debug(DBG_INSANE,err_str);
475
+			goto incomp_err;
476
+		}
477
+		res=swapped_straddr_pref(temp,
478
+				dpq->qname,family); 
479
+		if (res==-1) {
480
+			debug(DBG_INSANE,err_str);
481
+			goto incomp_err;
482
+		}
483
+	}
484
+	else 
485
+		goto incomp_err;
486
+	dph->id=ap->id;
487
+	dph->rd=1;
488
+	dph->qdcount++;
489
+	dpq->qtype=qt;
490
+	dpq->qclass=C_IN;
491
+	return 0;
492
+incomp_err:
493
+	destroy_dns_pkt(dp);
494
+	err_ret(ERR_ANDNCQ,-1);
495
+}
496
+int dpanswtoapansw(dns_pkt *dp,andns_pkt *ap)
497
+{
498
+	int i,rcode,qt,ancount,nan=0;
499
+	dns_pkt_a *dpa;
500
+	andns_pkt_data *apd;
501
+
502
+	ancount=DNS_GET_ANCOUNT(dp);
503
+	rcode=DNS_GET_RCODE(dp);
504
+	ap->rcode=rcode;
505
+	ap->qr=1;
506
+	
507
+	if (rcode!=DNS_RCODE_NOERR) 
508
+		return 0;
509
+
510
+	qt=dp->pkt_qst->qtype;
511
+	dpa=dp->pkt_answ;
512
+	for (i=0;i<ancount;i++) {
513
+		if (!dpa) 
514
+			break;
515
+		apd=andns_add_answ(ap);
516
+		if (qt==T_A) {
517
+			apd->rdlength=_ip_len_;
518
+			APD_ALIGN(apd);
519
+			memcpy(apd->rdata,dpa->rdata,_ip_len_);
520
+			nan++;
521
+		} 
522
+		else if (qt==T_PTR ) {
523
+			apd->rdlength=strlen(dpa->rdata);
524
+			APD_ALIGN(apd);
525
+			strcpy(apd->rdata,dpa->rdata);
526
+			nan++;
527
+		}
528
+		else if (qt==T_MX) {
529
+			struct hostent *h;
530
+			uint16_t prio;
531
+			h=gethostbyname(dpa->rdata+2);
532
+			if (!h || !(h->h_length)) {
533
+				andns_del_answ(ap);
534
+				debug(DBG_INSANE,"MX Ip Record not found.");
535
+				continue;
536
+			}
537
+			apd->rdlength=h->h_addrtype==AF_INET?4:16;
538
+			APD_ALIGN(apd);
539
+			memcpy(apd->rdata,h->h_addr_list[0],apd->rdlength);
540
+			memcpy(&prio,dpa->rdata,sizeof(uint16_t));
541
+			apd->prio=prio>>8;
542
+//				(uint8_t)(ntohs((uint16_t)(*(dpa->rdata))));
543
+//			memcpy(&(apd->prio),dpa->rdata,sizeof(uint16_t));
544
+			nan++;
545
+		}
546
+		else 
547
+			andns_del_answ(ap);
548
+		dpa=dpa->next;
549
+	}
550
+	if (i!=ancount || nan!=ancount)
551
+		debug(DBG_INSANE,"In dpanswtoapansw: "
552
+				  "ancount=%d, andns answers=%d",\
553
+				DNS_GET_ANCOUNT(dp),i);
554
+	ap->ancount=nan;
555
+
556
+	return 0;
557
+}
558
+
559
+		/* FINALLY RESOLVING FUNCTIONS */
560
+
561
+/*
562
+ * His goal is trivial.
563
+ * DO NOT USE suffixes query, i.e. query with ".INT" or ".NTK".
564
+ * NXDOMAIN otherwise.
565
+ *
566
+ * Returns:
567
+ *      -1 on error
568
+ *      0 if OK
569
+ */
570
+int andns_gethostbyname(char *hname, inet_prefix *ip)
571
+{
572
+        dns_pkt *dp;
573
+        dns_pkt_hdr *dph;
574
+        dns_pkt_qst *dpq;
575
+        int res;
576
+        char msg[DNS_MAX_SZ],answ[DNS_MAX_SZ];
577
+        uint32_t addr;
578
+
579
+        dp=create_dns_pkt();
580
+        dph=&(dp->pkt_hdr);
581
+
582
+        dph->id=(rand() >> 16) ^ (rand() >> 16);
583
+        dph->rd=1;
584
+
585
+        dpq=dns_add_qst(dp);
586
+	rm_realm_prefix(hname,dpq->qname,T_A);
587
+        dpq->qtype=T_A;
588
+        dpq->qclass=C_IN;
589
+
590
+        DP_QDCOUNT(dp)++;
591
+
592
+        memset(msg,0,DNS_MAX_SZ);
593
+        memset(answ,0,DNS_MAX_SZ);
594
+        if ((res=d_p(dp,msg))==-1) {
595
+                error(err_str);
596
+		err_ret(ERR_RSLRSL,-1);
597
+        }
598
+        if ((res=ns_general_send(msg,res,answ,DNS_MAX_SZ))==-1) {
599
+                error(err_str);
600
+		err_ret(ERR_RSLRSL,-1);
601
+        }
602
+        if ((res=d_u(answ,res,&dp))==-1) {
603
+                error(err_str);
604
+		err_ret(ERR_RSLRSL,-1);
605
+        }
606
+        memcpy(&addr, dp->pkt_answ->rdata, sizeof(uint32_t));
607
+        addr=ntohl(addr);
608
+        if ((res=inet_setip_raw(ip,&addr, AF_INET))==-1) {
609
+                error("In andns_gethostbyname: can not fill inet_prefix.");
610
+		err_ret(ERR_RSLRSL,-1);
611
+        }
612
+        destroy_dns_pkt(dp);
613
+	return 0;
614
+}
615
+
616
+
617
+/* There is a DNS query, internet realm.
618
+ * I'm going to forward it, but first I have 
619
+ * to control suffix presence.
620
+ * 
621
+ * After this function, `answer` is the answer to be 
622
+ * sent to the client.
623
+ *
624
+ * Returns:
625
+ * 	answer len
626
+ */ 
627
+int dns_forward(dns_pkt *dp,char *msg,int msglen,char* answer)
628
+{
629
+        dns_pkt *dp_forward;
630
+        char fwdbuf[DNS_MAX_SZ];
631
+        int res;
632
+
633
+        if (!_dns_forwarding_) {
634
+                error("In rslv: dns forwardind is disable.");
635
+                goto safe_failing;
636
+        }
637
+        debug(DBG_INSANE, "Forwarding dns query to inet nameservers...");
638
+        if (!is_prefixed(dp)) {
639
+                if((res=ns_general_send(msg,msglen,answer,ANDNS_MAX_SZ))==-1) {
640
+                        error(err_str);
641
+                        goto safe_failing;
642
+                }
643
+                destroy_dns_pkt(dp);
644
+                return res;
645
+        }
646
+        /* prepare to re-format query without prefix */
647
+	dp_forward=dpktcpy_rm_pref(dp);
648
+        memset(fwdbuf,0,DNS_MAX_SZ);
649
+        if ((res=d_p(dp_forward,fwdbuf))==-1) { /* dp_foward is destroyed */
650
+                error(err_str);
651
+                goto safe_failing;
652
+        }
653
+	res=ns_general_send(fwdbuf,res,answer,ANDNS_MAX_SZ);
654
+	if (res==-1) {
655
+                error(err_str);
656
+                goto safe_failing;
657
+        }
658
+	res=d_u(answer,res,&dp_forward);
659
+        if (res<=0) {
660
+                error(err_str);
661
+                goto safe_failing;
662
+        }
663
+        dpktacpy(dp,dp_forward,INET_REALM_PREFIX);
664
+        destroy_dns_pkt(dp_forward);
665
+	DNS_SET_NSCOUNT(dp,0);
666
+	DNS_SET_ARCOUNT(dp,0);
667
+        if ((res=d_p(dp,answer))==-1) {
668
+                error(err_str);
669
+		goto failing;
670
+        }
671
+        return res;
672
+safe_failing:
673
+	destroy_dns_pkt(dp);
674
+	goto failing;
675
+failing:
676
+	memcpy(answer,msg,msglen);
677
+	ANDNS_SET_RCODE(answer,RCODE_ESRVFAIL);
678
+	ANDNS_SET_QR(answer);
679
+	res=msglen;
680
+        err_ret(ERR_RSLFDQ,res);
681
+}
682
+
683
+/* There is a DNS query, netsukuku realm.
684
+ *
685
+ * I'm going to resolve it in ANDNA.
686
+ *
687
+ * After this function, `answer` is the answer to be 
688
+ * sent to the client.
689
+ *
690
+ * Returns:
691
+ * 	answer len
692
+ */
693
+
694
+int inet_rslv(dns_pkt *dp,char *msg,int msglen,char *answer)
695
+{
696
+	inet_prefix addr;
697
+	int res,qt,rcode;
698
+	u_short service;
699
+	snsd_service *ss;
700
+	snsd_prio *sp;
701
+	int records;
702
+	u_char proto;
703
+	char temp[DNS_MAX_HNAME_LEN];
704
+
705
+	qt=dp->pkt_qst->qtype;
706
+	rm_realm_prefix(dp->pkt_qst->qname,temp,qt);
707
+
708
+	if (qt==T_A || qt==T_MX) { /* snsd tcp resolution service */
709
+		service= (qt==T_A)?0:25;
710
+		proto  = (qt!=T_A);
711
+		//ss=andna_resolve_hname(temp,service,proto,&records);
712
+		ss=andna_resolve_hname(temp,service,proto,&records);
713
+		if (!ss) {
714
+			rcode=RCODE_ENSDMN;
715
+			goto safe_return_rcode;
716
+		}
717
+		sp=ss->prio;
718
+		snsd_prio_to_dansws(dp,sp,_ip_len_);
719
+		snsd_service_llist_del(&ss);
720
+	} else if (qt==T_PTR) {
721
+		char tomp[DNS_MAX_HNAME_LEN];
722
+		lcl_cache *lc;
723
+			  
724
+		res=swapped_straddr(temp,tomp);
725
+		if (res==-1) {
726
+			rcode=RCODE_EINTRPRT;
727
+			goto safe_return_rcode;
728
+		}
729
+		res=str_to_inet(tomp,&addr);
730
+		if (res==-1) {
731
+			rcode=RCODE_ESRVFAIL;
732
+			goto safe_return_rcode;
733
+		}
734
+		lc=andna_reverse_resolve(addr);
735
+		res=lcl_cache_to_dansws(dp,lc); /* destroy lc */
736
+		if (!res) {
737
+			rcode=RCODE_ENSDMN;
738
+			goto safe_return_rcode;
739
+		}
740
+	} else {
741
+		rcode=RCODE_ENIMPL;
742
+		goto safe_return_rcode;
743
+	}
744
+	DNS_SET_QR(dp,1);
745
+	res=d_p(dp,answer);
746
+	if (res==-1) {
747
+		rcode=RCODE_ESRVFAIL;
748
+		goto return_rcode;
749
+	}
750
+	return res;
751
+safe_return_rcode:
752
+	destroy_dns_pkt(dp);
753
+	goto return_rcode;
754
+return_rcode:
755
+	memcpy(answer,msg,msglen);
756
+	ANDNS_SET_RCODE(answer,rcode);
757
+	ANDNS_SET_QR(answer);
758
+	return msglen;
759
+}
760
+	
761
+int nk_rslv(andns_pkt *ap,char *msg,int msglen,char *answer)
762
+{
763
+	int qt,res,rcode,records;
764
+	inet_prefix ipres;
765
+	uint8_t recs;
766
+	uint16_t s;
767
+	
768
+	qt=ap->qtype;
769
+	if (qt==AT_A) {
770
+		snsd_service *ss;
771
+		ss=andna_resolve_hash((u_int *)ap->qstdata,
772
+				ap->service,ap->p+1,&records);
773
+		//ss=andna_resolve_hname(ap->qstdata, //USE HASH!
774
+		//		ap->service,ap->p,&records);
775
+		if (!ss) {
776
+			rcode=RCODE_ENSDMN;
777
+			goto safe_return_rcode;
778
+		}
779
+		res=snsd_prio_to_aansws(answer+msglen,
780
+				ss->prio,_ip_len_,ap->r,&records);
781
+		if (!records) {
782
+			rcode=RCODE_ENSDMN;
783
+			goto safe_return_rcode;
784
+		}
785
+		snsd_service_llist_del(&ss);
786
+	} 
787
+	else if (qt==AT_PTR) {
788
+		lcl_cache *lc;
789
+		int family;
790
+		
791
+		family=ap->qstlength==4?AF_INET:AF_INET6;
792
+		res=inet_setip_raw(&ipres,(u_int*)ap->qstdata,family);
793
+		if (res==-1) {
794
+			rcode=RCODE_EINTRPRT;
795
+			goto safe_return_rcode;
796
+		}
797
+		inet_ntohl(ipres.data,family);
798
+		lc=andna_reverse_resolve(ipres);
799
+		//lc=andna_reverse_resolve(ipres);
800
+		if (!lc) {
801
+			rcode=RCODE_ENSDMN;
802
+			goto safe_return_rcode;
803
+		}
804
+		res=lcl_cache_to_aansws(answer+msglen,lc,&records); /* destroys lc */
805
+	} 
806
+	else if (qt==AT_G) {
807
+		snsd_service *ss;
808
+		ss=andna_resolve_hash((u_int *)ap->qstdata,
809
+				-1,0,&records);
810
+		if (!ss) {
811
+			rcode=RCODE_ENSDMN;
812
+			goto safe_return_rcode;
813
+		}
814
+		res=snsd_service_to_aansws(answer+msglen+2,ss,
815
+				_ip_len_,&records,ap->r);
816
+		if (!res) {
817
+			rcode=RCODE_ENSDMN;
818
+			goto safe_return_rcode;
819
+		}
820
+		if (!records) {
821
+			rcode=RCODE_ESRVFAIL;
822
+			goto safe_return_rcode;
823
+		}
824
+		snsd_service_llist_del(&ss);
825
+	} else {
826
+		rcode=RCODE_EINTRPRT;
827
+		goto safe_return_rcode;
828
+	}
829
+	memcpy(answer,msg,msglen);
830
+	ANDNS_SET_RCODE(answer,RCODE_NOERR);
831
+	ANDNS_SET_QR(answer);
832
+	recs=records;
833
+	if (qt==AT_G) {
834
+		ANDNS_SET_ANCOUNT(answer,1);
835
+		s=htons(recs);
836
+		memcpy(answer+msglen,&s,2);
837
+		res+=2;
838
+	}
839
+	else
840
+		ANDNS_SET_ANCOUNT(answer,recs);
841
+	return res+msglen;
842
+safe_return_rcode:
843
+	destroy_andns_pkt(ap);
844
+/*	goto return_rcode;
845
+return_rcode:*/
846
+	memcpy(answer,msg,msglen);
847
+	ANDNS_SET_RCODE(answer,rcode);
848
+	ANDNS_SET_QR(answer);
849
+	return msglen;
850
+}
851
+int nk_forward(andns_pkt *ap,char *msg,int msglen,char *answer)
852
+{
853
+	int res,rcode;
854
+	dns_pkt *dp;
855
+	char new_answ[DNS_MAX_SZ];
856
+
857
+	res=apqsttodpqst(ap,&dp);
858
+	if (res==-1) {
859
+		rcode=RCODE_EINTRPRT;
860
+		goto safe_return_rcode;
861
+	}
862
+	res=d_p(dp,answer);
863
+	if (res==-1) {
864
+		rcode=RCODE_ESRVFAIL;
865
+		goto safe_return_rcode;
866
+	}
867
+	res=ns_general_send(answer,res,new_answ,DNS_MAX_SZ);
868
+	if (res==-1) {
869
+		rcode=RCODE_ESRVFAIL;
870
+		goto safe_return_rcode;
871
+	}
872
+	res=d_u(new_answ,res,&dp);
873
+	if (res==-1) {
874
+		rcode=RCODE_ESRVFAIL;
875
+		goto safe_return_rcode;
876
+	}
877
+	res=dpanswtoapansw(dp,ap);
878
+	if (res==-1) {
879
+		rcode=RCODE_ESRVFAIL;
880
+		destroy_dns_pkt(dp);
881
+		goto safe_return_rcode;
882
+	}
883
+	destroy_dns_pkt(dp);
884
+	res=a_p(ap,answer);
885
+	if (res==-1) {
886
+		rcode=RCODE_ESRVFAIL;
887
+		goto safe_return_rcode;
888
+	}
889
+	return res;
890
+safe_return_rcode:
891
+	debug(DBG_INSANE,err_str);
892
+	destroy_andns_pkt(ap);
893
+	memcpy(answer,msg,msglen);
894
+	ANDNS_SET_QR(answer);
895
+	ANDNS_SET_RCODE(answer,rcode);
896
+	return msglen;
897
+}
898
+/*
899
+ * This is the main function for the resolution: the dns_wrapper receive the
900
+ * buffer and rslv builds the answer.
901
+ * `answer' is the buffer where the answer will be stored, it must be at
902
+ * least of `ANDNS_MAX_SZ' bytes.
903
+ *
904
+ * Returns:
905
+ *      NULL if the pkt has to be discarded.
906
+ *      A ptr to the answer to be sended if OK:
907
+ *              in this case, answ_len is filled with
908
+ *              the answer len.
909
+ */
910
+char *andns_rslv(char *msg, int msglen,char *answer, int *answ_len)
911
+{
912
+	int proto,res,r;
913
+	dns_pkt *dp;
914
+	andns_pkt *ap;
915
+
916
+	proto=GET_NK_BIT(msg);
917
+        if (proto==NK_DNS) 
918
+		res=d_u(msg,msglen,&dp);
919
+	else if (proto==NK_INET || proto==NK_NTK)
920
+		res=a_u(msg,msglen,&ap);
921
+	else {
922
+		debug(DBG_INSANE,"andns_rslv(): "
923
+				 "Which language are you speaking?");
924
+		return NULL;
925
+	}
926
+	if (res==0) 
927
+		goto discard;
928
+        memset(answer, 0, ANDNS_MAX_SZ);
929
+	if (res==-1) 
930
+		goto intrprt;
931
+        if (proto==NK_DNS) {
932
+		r=andns_realm(dp->pkt_qst,NULL);
933
+		if (r==INET_REALM)
934
+			res=dns_forward(dp,msg,msglen,answer);
935
+		else
936
+			res=inet_rslv(dp,msg,msglen,answer);
937
+	} 
938
+	else if (proto==NK_NTK)
939
+		res=nk_rslv(ap,msg,msglen,answer);
940
+	else if (proto==NK_INET)
941
+		res=nk_forward(ap,msg,msglen,answer);
942
+	*answ_len=res;
943
+	return answer;
944
+discard:
945
+	debug(DBG_INSANE,err_str);
946
+	err_ret(ERR_RSLAQD,NULL);
947
+intrprt:
948
+	debug(DBG_INSANE,err_str);
949
+	memcpy(answer,msg,msglen);
950
+	ANDNS_SET_RCODE(answer,1);
951
+	//ANDNS_SET_RCODE(answer,RCODE_EINTRPRT);
952
+	ANDNS_SET_QR(answer);
953
+	*answ_len=msglen;
954
+	return answer;
955
+}
956
+
957
+
958
+
959
+

+ 86
- 0
src/andns.h View File

@@ -0,0 +1,86 @@
1
+	         /**************************************
2
+	        *     AUTHOR: Federico Tomassini        *
3
+	       *     Copyright (C) Federico Tomassini    *
4
+	      *     Contact effetom@gmail.com	          *
5
+	     ***********************************************
6
+	     *******          BEGIN 3/2006          ********
7
+*************************************************************************
8
+*                                              				* 
9
+*  This program is free software; you can redistribute it and/or modify	*
10
+*  it under the terms of the GNU General Public License as published by	*
11
+*  the Free Software Foundation; either version 2 of the License, or	*
12
+*  (at your option) any later version.					*
13
+*									*
14
+*  This program is distributed in the hope that it will be useful,	*
15
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of	*
16
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the	*
17
+*  GNU General Public License for more details.				*
18
+*									*
19
+************************************************************************/
20
+#ifndef ANDNS_H
21
+#define ANDNS_H
22
+
23
+#include <stdio.h>
24
+#include <sys/socket.h>
25
+#include <netdb.h>
26
+#include "dnslib.h"
27
+#include "andns_lib.h"
28
+#include "inet.h"
29
+
30
+#define ANDNS_TIMEOUT		15
31
+
32
+#define MAXNSSERVERS 		3
33
+#define DNS_REPLY_TIMEOUT       10      /* seconds */
34
+
35
+#define DNS_PORT		53
36
+#define DNS_PORT_STR		"53"
37
+
38
+/* PREFIX TO QUERY THE INET REALM */
39
+#define INET_REALM_PREFIX       ".INT"
40
+#define NTK_REALM_PREFIX        ".NTK"
41
+#define PTR_INET_REALM_PREFIX   "INT."
42
+#define PTR_NTK_REALM_PREFIX    "NTK."
43
+#define REALM_PREFIX_LEN        4
44
+
45
+#define DNS_PROTO		0
46
+#define ANDNS_PROTO		1
47
+
48
+#define NK_DNS			0
49
+#define NK_NTK			1
50
+#define NK_INET			2
51
+#define GET_NK_BIT(msg)		(*((msg+3))>>4)&0x03
52
+
53
+#define RCODE_NOERR		0	
54
+#define RCODE_EINTRPRT		1
55
+#define RCODE_ESRVFAIL		2
56
+#define RCODE_ENSDMN 		3
57
+#define RCODE_ENIMPL		4
58
+#define RCODE_ERFSD		5
59
+
60
+
61
+
62
+	/* FUNCTIONS */
63
+
64
+int store_ns(char *ns);
65
+int collect_resolv_conf(char *resolve_conf);
66
+void reset_andns_ns(void);
67
+int andns_init(int restricted, char *resolv_conf,int family);
68
+void andns_close(void);
69
+int ns_general_send(char *msg,int msglen,char *answer,int anslen);
70
+void dpktacpy(dns_pkt *dst,dns_pkt *src,const char *prefix);
71
+dns_pkt* dpktcpy(dns_pkt *src,const char *prefix);
72
+char* rm_realm_prefix(char *from,char *dst,int type);
73
+dns_pkt* dpktcpy_rm_pref(dns_pkt *src);
74
+int andns_gethostbyname(char *hname, inet_prefix *ip);
75
+int andns_realm(dns_pkt_qst *dpq,int *prefixed);
76
+int is_prefixed(dns_pkt *dp);
77
+int dns_forward(dns_pkt *dp,char *msg,int msglen,char* answer);
78
+int inet_rslv(dns_pkt *dp,char *msg,int msglen,char *answer);
79
+int nk_rslv(andns_pkt *ap,char *msg,int msglen,char *answer);
80
+int qtype_a_to_d(andns_pkt *ap);
81
+int apqsttodpqst(andns_pkt *ap,dns_pkt **dpsrc);
82
+int dpanswtoapansw(dns_pkt *dp,andns_pkt *ap);
83
+int nk_forward(andns_pkt *ap,char *msg,int msglen,char *answer);
84
+char *andns_rslv(char *msg, int msglen,char *answer, int *answ_len);
85
+
86
+#endif /* ANDNS_H */

+ 610
- 0
src/andns_lib.c View File

@@ -0,0 +1,610 @@
1
+                 /**************************************
2
+                *     AUTHOR: Federico Tomassini        *
3
+               *     Copyright (C) Federico Tomassini    *
4
+              *     Contact effetom@gmail.com             *
5
+             ***********************************************
6
+             *******          BEGIN 3/2006          ********
7
+*************************************************************************
8
+*                                                                       *
9
+*  This program is free software; you can redistribute it and/or modify *
10
+*  it under the terms of the GNU General Public License as published by *
11
+*  the Free Software Foundation; either version 2 of the License, or    *
12
+*  (at your option) any later version.                                  *
13
+*                                                                       *
14
+*  This program is distributed in the hope that it will be useful,      *
15
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of       *
16
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
17
+*  GNU General Public License for more details.                         *
18
+*                                                                       *
19
+************************************************************************/
20
+
21
+#include "andns_lib.h"
22
+#include "andns_net.h"
23
+#include "log.h"
24
+#include "err_errno.h"
25
+#include "xmalloc.h"
26
+
27
+#include <arpa/inet.h>
28
+#include <zlib.h>
29
+
30
+int andns_compress(char *src,int srclen)
31
+{
32
+	int res;
33
+	uLongf space;
34
+	
35
+	src+=ANDNS_HDR_SZ;
36
+	srclen-=ANDNS_HDR_SZ;
37
+	space=compressBound(srclen);
38
+
39
+	unsigned char dst[space+ANDNS_HDR_Z];
40
+
41
+		/* The first four bytes will store
42
+		 * the uncompressed size */
43
+	res=compress2(dst+ANDNS_HDR_Z, &space,(u_char *) src, srclen,
44
+			ANDNS_COMPR_LEVEL);
45
+	if (res!=Z_OK) 
46
+		err_ret(ERR_ZLIBCP,-1);
47
+	if (space >= srclen-ANDNS_HDR_Z) /* We have to consider the four 
48
+				  		bytes too */
49
+		err_ret(ERR_ZLIBNU,-1); /* This is a 
50
+					silent return */
51
+	res=htonl(srclen);
52
+	memcpy(dst,&res,ANDNS_HDR_Z);
53
+	memcpy(src, dst, space);
54
+
55
+	return (int)space;
56
+}
57
+char* andns_uncompress(char *src,int srclen,int *dstlen) 
58
+{
59
+	unsigned char *dst;
60
+	uLongf space;
61
+	int res;
62
+	int c_len;
63
+	const int hdrsz=ANDNS_HDR_SZ+ANDNS_HDR_Z;
64
+
65
+	memcpy(&c_len,src+ANDNS_HDR_SZ,ANDNS_HDR_Z);
66
+	c_len=ntohl(c_len);
67
+	dst=xmalloc(c_len+ANDNS_HDR_SZ); 
68
+
69
+	space=c_len;
70
+
71
+	res=uncompress(dst+ANDNS_HDR_SZ,&space,(u_char*) src+hdrsz, srclen-hdrsz);
72
+	if (res!=Z_OK) {
73
+		xfree(dst);
74
+		err_ret(ERR_ZLIBUP,NULL);
75
+	}
76
+	if ((int)space!=c_len) {
77
+		xfree(dst);
78
+		err_ret(ERR_ANDMAP,NULL);
79
+	}
80
+
81
+	memcpy(dst, src, ANDNS_HDR_SZ);
82
+	*dstlen=c_len+ANDNS_HDR_SZ; 
83
+
84
+	return (char*)dst;
85
+}
86
+
87
+/*
88
+ * Takes the buffer stream and translate headers to
89
+ * andns_pkt struct.
90
+ * Returns ALWAYS 4. The pkt_len has to be controlled
91
+ * elsewhere.
92
+ */
93
+int a_hdr_u(char *buf,andns_pkt *ap)
94
+{
95
+        uint8_t c;
96
+        uint16_t s;
97
+        char *start_buf;
98
+
99
+        start_buf=buf;
100
+
101
+	ap->r=*(buf+1)&0x01;
102
+        memcpy(&s,buf,2);
103
+        ap->id=ntohs(s);
104
+	ap->id>>=1;
105
+        buf+=2;
106
+
107
+        memcpy(&c,buf,2);
108
+        ap->qr=(c>>7)&0x01;
109
+        ap->p=c&0x40?ANDNS_PROTO_UDP:ANDNS_PROTO_TCP;
110
+	ap->z=c&0x20;
111
+        ap->qtype=(c>>3)&0x03;
112
+        ap->ancount=(c<<1)&0x0e;
113
+
114
+        buf++;
115
+        memcpy(&c,buf,sizeof(uint8_t));
116
+        if (((*buf)&0x80)) ap->ancount++;
117
+
118
+	ap->ipv=(c>>6)&0x01;
119
+        ap->nk=(c>>4)&0x03;
120
+        ap->rcode=c&0x0f;
121
+        return ANDNS_HDR_SZ;
122
+}
123
+/*
124
+ * Translate the andns_pkt question stream to andns_pkt struct.
125
+ * -1 on error. Bytes readed otherwise.
126
+ *  NOTE: The qst-data size is controlled: apkt won't need
127
+ *  this control.
128
+ */
129
+int a_qst_u(char *buf,andns_pkt *ap,int limitlen)
130
+{
131
+	int ret;
132
+	uint16_t s;
133
+
134
+	if (limitlen<3)
135
+		err_ret(ERR_ANDMAP,-1);
136
+
137
+	switch(ap->qtype) {
138
+		case AT_A:
139
+			memcpy(&s,buf,2);
140
+			ap->service=ntohs(s);
141
+			buf+=2;
142
+			if (ap->nk==NTK_REALM) {
143
+				ap->qstlength=ANDNS_HASH_H;
144
+				if (ap->qstlength>limitlen-2)
145
+                			err_ret(ERR_ANDPLB,-1);
146
+				AP_ALIGN(ap);
147
+				memcpy(ap->qstdata,buf,ANDNS_HASH_H);
148
+				ret=ANDNS_HASH_H+2;
149
+			} else if (ap->nk==INET_REALM) {
150
+				memcpy(&s,buf,2);
151
+				ap->qstlength=ntohs(s);
152
+				buf+=2;
153
+        			if (ap->qstlength>=ANDNS_MAX_QST_LEN || 
154
+					ap->qstlength>limitlen-4)
155
+                			err_ret(ERR_ANDPLB,-1);
156
+				AP_ALIGN(ap);
157
+        			memcpy(ap->qstdata,buf,ap->qstlength);
158
+				ret=ap->qstlength+4;
159
+			} else
160
+				return -1;
161
+			break;
162
+		case AT_PTR:
163
+			ap->qstlength=ap->ipv?16:4;
164
+			if (ap->qstlength>limitlen)
165
+				err_ret(ERR_ANDMAP,-1)
166
+			AP_ALIGN(ap);
167
+			memcpy(ap->qstdata,buf,ap->qstlength);
168
+			ret=ap->qstlength;
169
+			break;
170
+		case AT_G:
171
+			if (ap->nk!=NTK_REALM)
172
+				err_ret(ERR_ANDMAP,-1);
173
+			ap->qstlength=ANDNS_HASH_H;
174
+			if (ap->qstlength>limitlen)
175
+                		err_ret(ERR_ANDPLB,-1);
176
+			AP_ALIGN(ap);
177
+			memcpy(ap->qstdata,buf,ANDNS_HASH_H);
178
+			ret=ap->qstlength;
179
+			break;
180
+		default:
181
+			debug(DBG_INSANE,"In a_qst_u: unknow query type.");
182
+			err_ret(ERR_ANDMAP,-1)
183
+	}
184
+	return ret;
185
+}
186
+int a_answ_u(char *buf,andns_pkt *ap,int limitlen)
187
+{
188
+        uint16_t alen;
189
+        andns_pkt_data *apd;
190
+	int limit;
191
+
192
+	if (limitlen<3)
193
+		err_ret(ERR_ANDMAP,-1);
194
+	switch (ap->qtype) {
195
+		case AT_A:
196
+			limit=2;
197
+			if (limitlen<limit)
198
+				err_ret(ERR_ANDPLB,-1);
199
+			apd=andns_add_answ(ap);
200
+			if (*buf&0x40) {
201
+				apd->m|=APD_IP;
202
+				if (*buf&0x80)
203
+					apd->m|=APD_MAIN_IP;
204
+				limit=ap->ipv?16:4;
205
+			} else
206
+				limit=ANDNS_HASH_H;
207
+			if (limitlen<limit+2)
208
+				err_ret(ERR_ANDPLB,-1);
209
+			apd->wg=(*buf&0x3f);
210
+			apd->prio=(*(buf+1));
211
+			apd->rdlength=limit;
212
+			APD_ALIGN(apd);
213
+			memcpy(apd->rdata,buf+2,limit);
214
+			limit+=2;
215
+			break;
216
+		case AT_PTR:
217
+        		memcpy(&alen,buf,2);
218
+		        alen=ntohs(alen);
219
+        		if (alen+2>limitlen)
220
+		                err_ret(ERR_ANDPLB,-1);
221
+        		if (alen>ANDNS_MAX_DATA_LEN)
222
+                		err_ret(ERR_ANDPLB,-1);
223
+		        apd=andns_add_answ(ap);
224
+        		apd->rdlength=alen;
225
+			APD_ALIGN(apd);
226
+        		memcpy(apd->rdata,buf+2,alen);
227
+			limit=alen+2;
228
+			break;
229
+		case AT_G:
230
+			if (limitlen<8)
231
+				err_ret(ERR_ANDMAP,-1);
232
+			apd=andns_add_answ(ap);
233
+			if (*buf&0x40) {
234
+				apd->m|=APD_IP;
235
+				if (*buf&0x80)
236
+					apd->m|=APD_MAIN_IP;
237
+			}
238
+			apd->m|=*buf&0x20?APD_UDP:
239
+				APD_TCP;
240
+			apd->wg=(*buf&0x1f);
241
+			apd->prio=(*(buf+1));
242
+			buf+=2;
243
+			memcpy(&alen,buf,2);
244
+			apd->service=ntohs(alen);
245
+			buf+=2;
246
+			if (apd->m&APD_IP) 
247
+				apd->rdlength=(ap->ipv?16:4);
248
+			else
249
+				apd->rdlength=ANDNS_HASH_H;
250
+			limit=4+apd->rdlength;
251
+			if (limitlen<limit)
252
+				err_ret(ERR_ANDPLB,-1);
253
+			APD_ALIGN(apd);
254
+			memcpy(apd->rdata,buf,apd->rdlength);
255
+			break;
256
+		default:
257
+			err_ret(ERR_ANDMAP,-1);
258
+	}
259
+        return limit;
260
+}
261
+int a_answs_u(char *buf,andns_pkt *ap,int limitlen)
262
+{
263
+        int ancount,i;
264
+        int offset=0,res;
265
+	uint16_t alen;
266
+
267
+	if (ap->qtype==AT_G) {
268
+		memcpy(&alen,buf,sizeof(uint16_t));
269
+		ap->ancount=ntohs(alen);
270
+		offset+=2;
271
+	} 		
272
+	ancount=ap->ancount;
273
+        for (i=0;i<ancount;i++) {
274
+                res=a_answ_u(buf+offset,ap,limitlen-offset);
275
+                if (res==-1) {
276
+                        error(err_str);
277
+                        err_ret(ERR_ANDMAD,-1);
278
+                }
279
+                offset+=res;
280
+        }
281
+        return offset;
282
+}
283
+/*
284
+ * This is a main function: takes the pkt-buf and translate
285
+ * it in structured data.
286
+ * It cares about andns_pkt allocation.
287
+ * The apkt is allocate here.
288
+ *
289
+ * Returns:
290
+ * -1 on E_INTRPRT
291
+ *  0 if pkt must be discarded.
292
+ *  Number of bytes readed otherwise
293
+ */
294
+int a_u(char *buf,int pktlen,andns_pkt **app)
295
+{
296
+        andns_pkt *ap;
297
+        int offset,res;
298
+        int limitlen,u_len;
299
+	char *u_buf;
300
+
301
+        if (pktlen<ANDNS_HDR_SZ)
302
+                err_ret(ERR_ANDPLB,0);
303
+        *app=ap=create_andns_pkt();
304
+        offset=a_hdr_u(buf,ap);
305
+
306
+	if (ap->z) { /* Controls the space to read 
307
+			uncompressed size */
308
+		if (pktlen<ANDNS_HDR_SZ+ANDNS_HDR_Z) {
309
+			destroy_andns_pkt(ap);
310
+                	err_ret(ERR_ANDPLB,0);
311
+		}
312
+		if (!(u_buf=andns_uncompress(buf,pktlen,&u_len))) 
313
+			goto andmap;
314
+		destroy_andns_pkt(ap); 
315
+		ANDNS_UNSET_Z(u_buf);
316
+		res=a_u(u_buf,u_len,app);
317
+		xfree(u_buf);
318
+		return res;
319
+	}
320
+        buf+=offset;
321
+        limitlen=pktlen-offset;
322
+        if ((res=a_qst_u(buf,ap,limitlen))==-1) 
323
+		goto andmap;
324
+	offset+=res;
325
+	if (!ap->ancount) /*No answers */
326
+		return offset;
327
+	buf+=res;
328
+	limitlen-=res;
329
+	if ((res=a_answs_u(buf,ap,limitlen))==-1) 
330
+		goto andmap;
331
+	offset+=res;
332
+	if (offset!=pktlen)
333
+		error("In a_u(): pktlen differs from readed contents: ID query %d.",ap->id);
334
+        return offset;
335
+andmap:
336
+	destroy_andns_pkt(ap);
337
+	error(err_str);
338
+	err_ret(ERR_ANDMAP,-1);
339
+}
340
+
341
+int a_hdr_p(andns_pkt *ap,char *buf)
342
+{
343
+        uint16_t s;
344
+	uint8_t an;
345
+	
346
+	ap->id<<=1;
347
+        s=htons(ap->id);
348
+        memcpy(buf,&s,sizeof(uint16_t));
349
+	if (ap->r)
350
+		*(buf+1)|=0x01;
351
+	else	
352
+		*(buf+1)&=0xfe;
353
+        buf+=2;
354
+        if (ap->qr)
355
+                (*buf)|=0x80;
356
+	if (ap->p)
357
+		(*buf)|=0x40;
358
+	if (ap->z)
359
+		(*buf)|=0x20;
360
+        (*buf)|=( (ap->qtype)<<3);
361
+	an=ap->ancount;
362
+        (*buf++)|=( (an)>>1);
363
+        (*buf)|=( (ap->ancount)<<7);
364
+	if (ap->ipv)
365
+		*buf|=0x40;
366
+        (*buf)|=( (ap->nk)<<4);
367
+        (*buf)|=(  ap->rcode);
368
+        return ANDNS_HDR_SZ;
369
+}
370
+int a_qst_p(andns_pkt *ap,char *buf,int limitlen)
371
+{
372
+	int ret=0;
373
+        uint16_t s;
374
+	int limit;
375
+
376
+	switch(ap->qtype){
377
+		case AT_A:
378
+			limit=ap->nk==NTK_REALM?ANDNS_HASH_H+2:ap->qstlength+4;
379
+			if (limitlen<limit)
380
+				err_ret(ERR_ANDMAD,-1);
381
+			s=htons(ap->service);
382
+			memcpy(buf,&s,2);
383
+			buf+=2; /* here INET and NTK REALM change */
384
+			if (ap->nk==NTK_REALM) {
385
+				memcpy(buf,ap->qstdata,ANDNS_HASH_H);
386
+				ret=ANDNS_HASH_H+2;
387
+			} else if (ap->nk==INET_REALM) {
388
+				s=htons(ap->qstlength);
389
+				memcpy(buf,&s,2);
390
+				buf+=2; 
391
+				memcpy(buf,ap->qstdata,ap->qstlength);
392
+				ret=ap->qstlength+4;
393
+			} else
394
+				err_ret(ERR_ANDMAD,-1);
395
+			break;
396
+		case AT_PTR:
397
+			limit=ap->ipv?16:4;
398
+			if (limitlen<limit)
399
+				err_ret(ERR_ANDMAD,-1);
400
+			memcpy(buf,ap->qstdata,limit);
401
+			ret=limit;
402
+			break;
403
+		case AT_G:
404
+			limit=ANDNS_HASH_H;
405
+			if (limitlen<limit)
406
+				err_ret(ERR_ANDMAD,-1);
407
+			memcpy(buf,ap->qstdata,ANDNS_HASH_H);
408
+			ret=ANDNS_HASH_H;
409
+			break;
410
+		default:
411
+			debug(DBG_INSANE,"In a_qst_p: unknow query type.");
412
+			err_ret(ERR_ANDMAD,-1);
413
+			break;
414
+	}
415
+	return ret;
416
+}
417
+int a_answ_p(andns_pkt *ap,andns_pkt_data *apd,char *buf,int limitlen)
418
+{
419
+        uint16_t s;
420
+	int limit;
421
+	int ret;
422
+	
423
+	switch(ap->qtype) {
424
+		case AT_A:
425
+			limit=ap->ipv?16:4;
426
+			if (limitlen<limit+2)
427
+                		err_ret(ERR_ANDPLB,-1);
428
+			if (apd->m)
429
+				*buf|=0x80;
430
+			*buf++|= (apd->wg&0x7f);
431
+			*buf++|=apd->prio;
432
+			memcpy(buf,apd->rdata,limit);
433
+			ret=limit+2;
434
+			break;
435
+		case AT_PTR:
436
+			if (limitlen<apd->rdlength+2)
437
+                		err_ret(ERR_ANDPLB,-1);
438
+        		s=htons(apd->rdlength);
439
+		        memcpy(buf,&s,sizeof(uint16_t));
440
+		        buf+=2;
441
+        		memcpy(buf,apd->rdata,apd->rdlength);
442
+			ret=apd->rdlength+2;
443
+			break;
444
+		case AT_G: /* TODO */
445
+			if (limitlen<4)
446
+                		err_ret(ERR_ANDPLB,-1);
447
+			if (apd->m==1)
448
+				(*buf)|=0xc0;
449
+			else if (apd->m)
450
+				(*buf)|=0x40;
451
+			*buf++|= (apd->wg&0x3f);
452
+			*buf++|=apd->prio;
453
+			s=htons(apd->service);
454
+			memcpy(buf,&s,2);
455
+			if (apd->m) {
456
+				limit=ap->ipv?16:4;
457
+				if (limitlen<limit+4)
458
+                			err_ret(ERR_ANDPLB,-1);
459
+				memcpy(buf,apd->rdata,limit);
460
+				ret=limit+4;
461
+			} else {
462
+				limit=strlen(apd->rdata);
463
+				if (limitlen<limit+6)
464
+                			err_ret(ERR_ANDPLB,-1);
465
+				s=htons(limit);
466
+				memcpy(buf,&s,2);
467
+				buf+=2;
468
+				memcpy(buf,apd->rdata,limit);
469
+				ret=limit+6;
470
+			}
471
+			break;
472
+		default:
473
+			debug(DBG_INSANE,"In a_answ_p(): unknow query type.");
474
+			err_ret(ERR_ANDMAD,-1);
475
+			break;
476
+	}
477
+	return ret;
478
+}
479
+int a_answs_p(andns_pkt *ap,char *buf, int limitlen)
480
+{
481
+        andns_pkt_data *apd;
482
+        int i;
483
+        int offset=0,res;
484
+	uint16_t s;
485
+
486
+	if (ap->qtype==AT_G) {
487
+		if (limitlen<2)
488
+			err_ret(ERR_ANDPLB,-1);
489
+		s=htons(ap->ancount);
490
+		memcpy(buf,&s,2);
491
+		offset+=2;
492
+	} 
493
+        apd=ap->pkt_answ;
494
+        for (i=0;i<ap->ancount && apd;i++) {
495
+                if((res=a_answ_p(ap,apd,buf+offset,limitlen-offset))==-1) {
496
+                        error(err_str);
497
+                        err_ret(ERR_ANDMAD,-1);
498
+                }
499
+                offset+=res;
500
+                apd=apd->next;
501
+        }
502
+        return offset;
503
+}
504
+int a_p(andns_pkt *ap, char *buf)
505
+{
506
+        int offset,res;
507
+
508
+        memset(buf,0,ANDNS_MAX_SZ);
509
+
510
+        offset=a_hdr_p(ap,buf);
511
+        buf+=offset;
512
+        if ((res=a_qst_p(ap,buf,ANDNS_MAX_SZ-offset))==-1)
513
+                goto server_fail;
514
+        offset+=res;
515
+        buf+=res;
516
+	if (ap->ancount) {
517
+	        if ((res=a_answs_p(ap,buf,ANDNS_MAX_SZ-offset))==-1)
518
+        	        goto server_fail;
519
+	        offset+=res;
520
+	}
521
+        destroy_andns_pkt(ap);
522
+	/* Compression */
523
+	if (offset>ANDNS_COMPR_THRESHOLD) {
524
+		res=andns_compress(buf,offset);
525
+		if (res==-1)
526
+			error(err_str);
527
+		else
528
+			return res;
529
+	}
530
+	/* end compression */
531
+        return offset;
532
+server_fail:
533
+        destroy_andns_pkt(ap);
534
+        error(err_str);
535
+        err_ret(ERR_ANDMAD,-1);
536
+}
537
+
538
+
539
+/* MEM */
540
+
541
+	/* Borning functions */
542
+andns_pkt* create_andns_pkt(void)
543
+{
544
+        andns_pkt *ap;
545
+        ap=xmalloc(ANDNS_PKT_SZ);
546
+	memset(ap,0,ANDNS_PKT_SZ);
547
+        return ap;
548
+}
549
+
550
+andns_pkt_data* create_andns_pkt_data(void)
551
+{
552
+        andns_pkt_data *apd;
553
+        apd=xmalloc(ANDNS_PKT_DATA_SZ);
554
+	memset(apd,0,ANDNS_PKT_DATA_SZ);
555
+        return apd;
556
+}
557
+andns_pkt_data* andns_add_answ(andns_pkt *ap)
558
+{
559
+        andns_pkt_data *apd,*a;
560
+
561
+        apd=create_andns_pkt_data();
562
+        a=ap->pkt_answ;
563
+        if (!a) {
564
+                ap->pkt_answ=apd;
565
+                return apd;
566
+        }
567
+        while (a->next) a=a->next;
568
+        a->next=apd;
569
+        return apd;
570
+}
571
+	/* Death functions */
572
+void destroy_andns_pkt_data(andns_pkt_data *apd)
573
+{
574
+	if (apd->rdata)
575
+		xfree(apd->rdata);
576
+	xfree(apd);
577
+}
578
+void andns_del_answ(andns_pkt *ap)
579
+{
580
+	andns_pkt_data *apd,*apdt;
581
+
582
+	apd=ap->pkt_answ;
583
+	if (!apd)
584
+		return;
585
+	apdt=apd->next;
586
+	while (apdt) {
587
+		apd=apdt;
588
+		apdt=apdt->next;
589
+	}
590
+	apd->next=NULL;
591
+	destroy_andns_pkt_data(apdt);
592
+}
593
+
594
+void destroy_andns_pkt_datas(andns_pkt *ap)
595
+{
596
+	andns_pkt_data *apd,*apd_t;
597
+	apd=ap->pkt_answ;
598
+	while(apd) {
599
+		apd_t=apd->next;
600
+		destroy_andns_pkt_data(apd);
601
+		apd=apd_t;
602
+	}
603
+}
604
+void destroy_andns_pkt(andns_pkt *ap)
605
+{
606
+	if (ap->qstdata)
607
+		xfree(ap->qstdata);
608
+	destroy_andns_pkt_datas(ap);
609
+        xfree(ap);
610
+}

+ 136
- 0
src/andns_lib.h View File

@@ -0,0 +1,136 @@
1
+                 /**************************************
2
+                *     AUTHOR: Federico Tomassini        *
3
+               *     Copyright (C) Federico Tomassini    *
4
+              *     Contact effetom@gmail.com             *
5
+             ***********************************************
6
+             *******          BEGIN 3/2006          ********
7
+*************************************************************************
8
+*                                                                       *
9
+*  This program is free software; you can redistribute it and/or modify *
10
+*  it under the terms of the GNU General Public License as published by *
11
+*  the Free Software Foundation; either version 2 of the License, or    *
12
+*  (at your option) any later version.                                  *
13
+*                                                                       *
14
+*  This program is distributed in the hope that it will be useful,      *
15
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of       *
16
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
17
+*  GNU General Public License for more details.                         *
18
+*                                                                       *
19
+************************************************************************/
20
+
21
+#ifndef ANDNS_LIB_H
22
+#define ANDNS_LIB_H
23
+
24
+#include <string.h>
25
+#include <stdint.h>
26
+#include <sys/types.h>
27
+
28
+#define ANDNS_MAX_QUESTION_LEN	263 /* TODO */
29
+#define ANDNS_MAX_ANSWER_LEN	516
30
+#define ANDNS_MAX_ANSWERS_NUM	256
31
+#define ANDNS_MAX_PK_LEN	ANDNS_MAX_QUESTION_LEN+\
32
+				ANDNS_MAX_ANSWERS_NUM*ANDNS_MAX_ANSWER_LEN
33
+
34
+#define ANDNS_MAX_DATA_LEN	512
35
+#define ANDNS_MAX_QST_LEN	512
36
+#define ANNDS_DNS_MAZ_QST_LEN	255
37
+#define ANDNS_MAX_ANSW_IP_LEN	20
38
+#define ANDNS_MAX_ANSW_H_LEN	516
39
+
40
+#define ANDNS_HASH_H		16
41
+
42
+#define ANDNS_COMPR_LEVEL	Z_BEST_COMPRESSION
43
+#define ANDNS_COMPR_THRESHOLD	1000
44
+
45
+struct andns_pkt_data
46
+{
47
+	uint8_t			m;
48
+	uint8_t			wg;
49
+	uint8_t			prio;
50
+        uint16_t                rdlength;
51
+        uint16_t                service;
52
+        char                    *rdata;
53
+        struct andns_pkt_data   *next;
54
+};
55
+typedef struct andns_pkt_data andns_pkt_data;
56
+#define ANDNS_PKT_DATA_SZ sizeof(andns_pkt_data)
57
+#define APD_ALIGN(apd)	(apd)->rdata=(char*)xmalloc((apd)->rdlength+1);		\
58
+				     memset((apd)->rdata,0,(apd)->rdlength+1)
59
+#define APD_MAIN_IP	1<<0
60
+#define APD_IP		1<<1
61
+#define APD_TCP		1<<2
62
+#define APD_UDP		1<<3
63
+
64
+typedef struct andns_pkt
65
+{
66
+        uint16_t        id;
67
+        uint8_t         r;
68
+        uint8_t         qr;
69
+        uint8_t         p;
70
+        uint8_t         z;
71
+        uint8_t         qtype;
72
+        uint16_t        ancount;
73
+        uint8_t         ipv;
74
+        uint8_t         nk;
75
+        uint8_t         rcode;
76
+        uint16_t        service; 
77
+        uint16_t        qstlength;
78
+        char            *qstdata;
79
+        andns_pkt_data  *pkt_answ;
80
+} andns_pkt;
81
+#define ANDNS_PKT_SZ sizeof(andns_pkt)
82
+#define AP_ALIGN(ap)	(ap)->qstdata=(char*)xmalloc((ap)->qstlength)
83
+
84
+#define ANDNS_HDR_SZ	4
85
+#define ANDNS_HDR_Z	4
86
+#define ANDNS_MAX_SZ 	ANDNS_HDR_SZ+ANDNS_MAX_QST_LEN+ANDNS_MAX_QST_LEN+4
87
+
88
+
89
+#define ANDNS_SET_RCODE(s,c)    *((s)+3)=(((*((s)+3))&0xf0)|c)
90
+#define ANDNS_SET_QR(s)         (*((s)+2))|=0x80
91
+#define ANDNS_SET_ANCOUNT(s,n)  *(s+2)|=((n)>>1);*(s+3)|=((n)<<7);
92
+#define ANDNS_SET_Z(s)		*(s+3)|=0x20;
93
+#define ANDNS_UNSET_Z(s)	*(s+3)&=0xdf;
94
+
95
+/* ANDNS PROTO-TYPE */
96
+#define ANDNS_PROTO_TCP	0
97
+#define ANDNS_PROTO_UDP	1
98
+/* ANDNS QUERY-TYPE */
99
+#define AT_A            0 /* h->ip */
100
+#define AT_PTR          1 /* ip->h */
101
+#define AT_G          	2 /* global */
102
+/* RCODES: The rcodes are portable between ANDNS and DNS */
103
+#define ANDNS_RCODE_NOERR     0       /* No error */
104
+#define ANDNS_RCODE_EINTRPRT  1       /* Intepret error */
105
+#define ANDNS_RCODE_ESRVFAIL  2       /* Server failure */
106
+#define ANDNS_RCODE_ENSDMN    3       /* No such domain */
107
+#define ANDNS_RCODE_ENIMPL    4       /* Not implemented */
108
+#define ANDNS_RCODE_ERFSD     5       /* Refused */
109
+/* REALMS TO SEARCH */
110
+#define NTK_REALM               1
111
+#define INET_REALM              2
112
+/* IP VERSION */
113
+#define ANDNS_IPV4		0
114
+#define ANDNS_IPV6		1
115
+
116
+int andns_compress(char *src,int srclen);
117
+char* andns_uncompress(char *src,int srclen,int *dstlen) ;
118
+int a_hdr_u(char *buf,andns_pkt *ap);
119
+int a_qst_u(char *buf,andns_pkt *ap,int limitlen);
120
+int a_answ_u(char *buf,andns_pkt *ap,int limitlen);
121
+int a_answs_u(char *buf,andns_pkt *ap,int limitlen);
122
+int a_u(char *buf,int pktlen,andns_pkt **app);
123
+int a_hdr_p(andns_pkt *ap,char *buf);
124
+int a_qst_p(andns_pkt *ap,char *buf,int limitlen);
125
+int a_answ_p(andns_pkt *ap,andns_pkt_data *apd,char *buf,int limitlen);
126
+int a_answs_p(andns_pkt *ap,char *buf, int limitlen);
127
+int a_p(andns_pkt *ap, char *buf);
128
+andns_pkt* create_andns_pkt(void);
129
+andns_pkt_data* create_andns_pkt_data(void);
130
+andns_pkt_data* andns_add_answ(andns_pkt *ap);
131
+void destroy_andns_pkt_data(andns_pkt_data *apd);
132
+void andns_del_answ(andns_pkt *ap);
133
+void destroy_andns_pkt_datas(andns_pkt *ap);
134
+void destroy_andns_pkt(andns_pkt *ap);
135
+
136
+#endif /* ANDNS_LIB_H */

+ 297
- 0
src/andns_net.c View File

@@ -0,0 +1,297 @@
1
+	         /**************************************
2
+	        *     AUTHOR: Federico Tomassini        *
3
+	       *     Copyright (C) Federico Tomassini    *
4
+	      *     Contact effetom@gmail.com             *
5
+	     ***********************************************
6
+	     *******          BEGIN 4/2006          ********
7
+*************************************************************************
8
+*                                              				* 
9
+*  This program is free software; you can redistribute it and/or modify	*
10
+*  it under the terms of the GNU General Public License as published by	*
11
+*  the Free Software Foundation; either version 2 of the License, or	*
12
+*  (at your option) any later version.					*
13
+*									*
14
+*  This program is distributed in the hope that it will be useful,	*
15
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of	*
16
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the	*
17
+*  GNU General Public License for more details.				*
18
+*									*
19
+************************************************************************/
20
+
21
+#include "log.h"
22
+#include "andns_net.h"
23
+
24
+int idp_inet_ntop(int family,struct sockaddr *addr,char *buf,int buflen)
25
+{
26
+	const char *res;
27
+	struct sockaddr_in *saddr;
28
+	struct sockaddr_in6 *saddr6;
29
+
30
+	switch(family) {
31
+		case AF_INET:
32
+			saddr=(struct sockaddr_in*)addr;
33
+			res=inet_ntop(family,(void*)(&(saddr->sin_addr)),buf,buflen);
34
+			break;
35
+		case AF_INET6:
36
+			saddr6=(struct sockaddr_in6*)addr;
37
+			res=inet_ntop(family,(void*)(&(saddr6->sin6_addr)),buf,buflen);
38
+			break;
39
+		default:
40
+			return -1;
41
+	}
42
+	if (!res)
43
+		return -1;
44
+	return 0;
45
+}
46
+/* Connection Layer */
47
+
48
+int w_socket(int family,int type, int proto,int die)
49
+{
50
+	int sk;
51
+	sk=socket(family,type,proto);
52
+	if (sk==-1) {
53
+		if (die)
54
+			fatal("w_socket: %s.",strerror(errno));
55
+		debug(DBG_NORMAL,"w_socket: %s.",strerror(errno));
56
+		return -1;
57
+	}
58
+	return sk;
59
+}
60
+
61
+int w_connect(struct addrinfo *ai,int die) 
62
+{
63
+	int sk,res;
64
+	sk=w_socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol,die);
65
+	res=connect(sk,ai->ai_addr,ai->ai_addrlen);
66
+	if (!res) 
67
+		return sk;
68
+	if (die)
69
+		fatal("Unable to connect: %s.", strerror(errno));
70
+	debug(DBG_NORMAL,"w_connect: %s.",strerror(errno));
71
+	close(sk);
72
+	return -1;
73
+}
74
+int serial_connect(struct addrinfo *ai,int die)
75
+{
76
+	int res;
77
+	struct addrinfo *temp;
78
+
79
+	temp=ai;
80
+	if (!temp) {
81
+		if (die)
82
+			fatal("Unable to connect: no host specified.");
83
+		debug(DBG_NORMAL,"serial_connect: no host specified.");
84
+		return -1;
85
+	}
86
+	do {
87
+		res=w_connect(temp,0);
88
+		temp=temp->ai_next;
89
+	} while (res==-1 && temp);
90
+	if (res==-1)  {
91
+		if (die)
92
+			fatal("Unable to connect.");
93
+		debug(DBG_NORMAL,"serial_connect: unable to connect.");
94
+		return -1;
95
+	}
96
+	return res;
97
+}
98
+	
99
+/*
100
+ * host_connect returns a connected socket to (host,port)
101
+ * endpoint. It is protocol independent.
102
+ * -1 on error.
103
+ */
104
+int host_connect(const char *host,uint16_t port,int type,int die) 
105
+{
106
+	int res;
107
+	char portstr[6];
108
+	struct addrinfo *ai,filter;
109
+
110
+	memset(&filter,0,sizeof(struct addrinfo));
111
+	filter.ai_socktype=type;
112
+	if (!host)
113
+		fatal("w_connect: malicious call.");
114
+	memset(portstr,0,6);
115
+	res=snprintf(portstr,6,"%d",port);
116
+	if (res<0 || res>=6) {
117
+		printf("Depousceve\n");
118
+		return -1;
119
+	}
120
+	res=getaddrinfo(host,portstr,&filter,&ai);
121
+	if (res!=0) {
122
+		printf("w_connect: error %s.\n",gai_strerror(errno));
123
+		return -1;
124
+	}
125
+	res=serial_connect(ai,die);
126
+	freeaddrinfo(ai);
127
+	return res;
128
+}
129
+int ai_connect(struct addrinfo *ai,int die,int free_ai)
130
+{
131
+	int res;
132
+
133
+	res=serial_connect(ai,die);
134
+	if (free_ai)
135
+		freeaddrinfo(ai);
136
+	return res;
137
+}
138
+
139
+/* Communication Layer */
140
+
141
+ssize_t w_send(int sk,const void *buf,size_t len,int die) 
142
+{
143
+	ssize_t ret;
144
+
145
+	ret=send(sk,buf,len,0);
146
+	if (ret!=len) {
147
+		if (die)
148
+			fatal("Unable to send(): %s.",strerror(errno));
149
+		debug(DBG_NORMAL,"w_send(): %s.",strerror(errno));
150
+	}
151
+	return ret;
152
+}
153
+
154
+ssize_t w_recv(int sk,void *buf,size_t len,int die)
155
+{
156
+	ssize_t ret;
157
+
158
+	ret=recv(sk,buf,len,0);
159
+	if (ret<=0) {
160
+		if (die)
161
+			fatal("Unable to recv(): %s.",strerror(errno));
162
+		debug(DBG_INSANE,"w_recv(): %s.",strerror(errno));
163
+	}
164
+	return ret;
165
+}
166
+
167
+
168
+/* 
169
+ * These two functions and the MACRO are
170
+ * almost VERBATIM copied from inet.c and inet.h.
171
+ * Functions by AlpT, Andrea Lo Pumo.
172
+ */
173
+
174
+#define MILLISEC_TO_TV(x,t)                                             \
175
+do{                                                                     \
176
+        (t).tv_sec=(x)/1000;                                            \
177
+        (t).tv_usec=((x) - ((x)/1000)*1000)*1000;                       \
178
+}while(0)
179
+
180
+ssize_t w_send_timeout(int s,const void *buf,size_t len,int die,int timeout)
181
+{
182
+        struct timeval timeout_t;
183
+        fd_set fdset;
184
+        int ret;
185
+
186
+        MILLISEC_TO_TV(timeout*1000, timeout_t);
187
+
188
+        FD_ZERO(&fdset);
189
+        FD_SET(s, &fdset);
190
+
191
+        ret = select(s+1, &fdset, NULL, NULL, &timeout_t);
192
+        if (ret == -1) {
193
+		if (die)
194
+			fatal("send(): select error.");
195
+		debug(DBG_NORMAL,"send(): select error.");
196
+		return ret;
197
+        }
198
+
199
+        if(FD_ISSET(s, &fdset))
200
+                return w_send(s, buf, len, die);
201
+        return -1;
202
+}
203
+
204
+ssize_t w_recv_timeout(int s,void *buf,size_t len,int die,int timeout)
205
+{
206
+        struct timeval timeout_t;
207
+        fd_set fdset;
208
+        int ret;
209
+
210
+        MILLISEC_TO_TV(timeout*1000, timeout_t);
211
+
212
+        FD_ZERO(&fdset);
213
+        FD_SET(s, &fdset);
214
+
215
+        ret = select(s+1, NULL, &fdset, NULL, &timeout_t);
216
+
217
+        if (ret == -1) {
218
+		if (die)
219
+			fatal("recv(): select error.");
220
+		debug(DBG_NORMAL,"recv(): select error.");
221
+		return ret;
222
+        }
223
+
224
+        if(FD_ISSET(s, &fdset))
225
+                return w_recv(s, buf, len, die);
226
+        return -1;
227
+}
228
+
229
+
230
+	
231
+/* Dialog Layer */
232
+
233
+/* "Botta e risposta" */
234
+ssize_t hn_send_recv_close(const char *host,uint16_t port,int type,void *buf,
235
+		size_t buflen,void *anbuf,size_t anlen,int die,int timeout)
236
+{
237
+	ssize_t ret;
238
+	int res;
239
+
240
+	res=host_connect(host,port,type,die);
241
+	if (res==-1) 
242
+		return -1;
243
+	if (timeout)
244
+		ret=w_send_timeout(res,buf,buflen,die,timeout);
245
+	else
246
+		ret=w_send(res,buf,buflen,die);
247
+	if (ret==-1) 
248
+		return -2;
249
+	if (timeout)
250
+		ret=w_recv_timeout(res,anbuf,anlen,die,timeout);
251
+	else
252
+		ret=w_recv(res,anbuf,anlen,die);
253
+	if (ret==-1)
254
+		return -3;
255
+	close(res);
256
+	return ret;
257
+}
258
+/* "Botta e risposta" */
259
+ssize_t ai_send_recv_close(struct addrinfo *ai,void *buf,size_t buflen,
260
+		void *anbuf,size_t anlen,int die,int free_ai,int timeout)
261
+{
262
+	ssize_t ret;
263
+	int res;
264
+
265
+	res=ai_connect(ai,die,free_ai);
266
+	if (res==-1) 
267
+		return -1;
268
+	if (timeout)
269
+		ret=w_send_timeout(res,buf,buflen,die,timeout);
270
+	else
271
+		ret=w_send(res,buf,buflen,die);
272
+	if (ret==-1) 
273
+		return -2;
274
+	if (timeout)
275
+		ret=w_recv_timeout(res,anbuf,anlen,die,timeout);
276
+	else
277
+		ret=w_recv(res,anbuf,anlen,die);
278
+	if (ret==-1) 
279
+		return -3;
280
+	close(res);
281
+	return ret;
282
+}
283
+	
284
+void char_print(char *buf, int len)
285
+{
286
+        int i,count=0;
287
+
288
+        printf("Printing %d bytes\n",len);
289
+        for (i=0;i<len;i++) {
290
+                printf("%02X ", (unsigned char)(buf[i]));
291
+                count++;
292
+                if ((count%16)==0) printf("\n");
293
+        }
294
+        printf("\n");
295
+        return;
296
+}
297
+

+ 32
- 0
src/andns_net.h View File

@@ -0,0 +1,32 @@
1
+#ifndef ANDNS_NET_H
2
+#define ANDNS_NET_H
3
+
4
+#include <errno.h>
5
+#include <netdb.h>
6
+#include <unistd.h>
7
+#include <stdio.h>
8
+#include <string.h>
9
+#include <sys/types.h>
10
+#include <sys/socket.h>
11
+#include <arpa/inet.h>
12
+
13
+
14
+
15
+int idp_inet_ntop(int family,struct sockaddr *addr,char *buf,int buflen);
16
+int w_socket(int family,int type, int proto,int die);
17
+int w_connect(struct addrinfo *ai,int die) ;
18
+int serial_connect(struct addrinfo *ai,int die);
19
+int host_connect(const char *host,uint16_t port,int type,int die) ;
20
+int ai_connect(struct addrinfo *ai,int die,int free_ai);
21
+ssize_t w_send(int sk,const void *buf,size_t len,int die) ;
22
+ssize_t w_recv(int sk,void *buf,size_t len,int die);
23
+ssize_t w_send_timeout(int s,const void *buf,size_t len,int die,int timeout);
24
+ssize_t w_recv_timeout(int s,void *buf,size_t len,int die,int timeout);
25
+ssize_t ai_send_recv_close(struct addrinfo *ai,void *buf,size_t buflen,
26
+		void *anbuf,size_t anlen,int die,int free_ai,int timeout);
27
+ssize_t hn_send_recv_close(const char *host,uint16_t port,int type,void *buf,
28
+	        size_t buflen,void *anbuf,size_t anlen,int die,int timeout);
29
+void char_print(char *buf, int len);
30
+
31
+
32
+#endif /* ANDNS_NET_H */

+ 316
- 0
src/andns_snsd.c View File

@@ -0,0 +1,316 @@
1
+#include "includes.h"
2
+
3
+#include "llist.c"
4
+#include "andns_snsd.h"
5
+#include "err_errno.h"
6
+#include "andna.h"
7
+#include "log.h"
8
+
9
+
10
+
11
+	/* h2ip functions */
12
+
13
+/*
14
+ * Given a a hostname hash, makes a resolution 
15
+ * call (service=0) and search the main ip entry,
16
+ * storing it to snsd_node dst.
17
+ *
18
+ * Returns:
19
+ * 	0
20
+ * 	-1
21
+ */
22
+int snsd_main_ip(u_int *hname_hash,snsd_node *dst)
23
+{
24
+	snsd_service *ss;
25
+	snsd_prio *sp;
26
+	snsd_node *sn;
27
+	int records;
28
+
29
+	ss=andna_resolve_hash(hname_hash,0,0,&records);
30
+	if (!ss) 
31
+		err_ret(ERR_SNDMRF,-1);
32
+	if (!(sp=ss->prio)) {
33
+		goto destroy_return;
34
+	}
35
+	list_for(sp) {
36
+		sn=sp->node;
37
+		list_for(sn) 
38
+			if (sn->flags & SNSD_NODE_MAIN_IP) {
39
+				memcpy(dst,sn,sizeof(snsd_node));
40
+				snsd_service_llist_del(&ss);
41
+				return 0;
42
+			}
43
+	}
44
+	goto destroy_return;
45
+destroy_return:
46
+	snsd_service_llist_del(&ss);
47
+	err_ret(ERR_SNDMRF,-1);
48
+}
49
+
50
+/*
51
+ * Convert a snsd_node to a binary ip.
52
+ * If snsd_node does not contain a ip, but a hostname hash,
53
+ * calls another resolution with service=0.
54
+ *
55
+ * Returns:
56
+ * 	bytes writed
57
+ * 	
58
+ */
59
+int snsd_node_to_data(char *buf,snsd_node *sn,u_char prio,int iplen,int recursion)
60
+{
61
+	int res;
62
+	int family;
63
+
64
+	if (recursion!=-1) {
65
+		*buf|=sn->weight&0x3f;
66
+		*(buf+1)|=prio;
67
+	}
68
+
69
+        if (! (sn->flags & SNSD_NODE_HNAME)) {
70
+		*buf|=0x40;
71
+		if (sn->flags & SNSD_NODE_MAIN_IP )
72
+			*buf|=0x80;
73
+                memcpy(buf+2,sn->record,iplen); 
74
+		family=(iplen==4)?AF_INET:AF_INET6;
75
+		inet_htonl((u_int*)(buf+2),family);
76
+		return iplen+2;
77
+        } else if (recursion) {
78
+                snsd_node snt;
79
+                res=snsd_main_ip(sn->record,&snt);
80
+		if (!res) { /* I love recursion */
81
+                	res=snsd_node_to_data(buf,&snt,prio,iplen,-1);
82
+			return res;
83
+		}
84
+	}
85
+	memcpy(buf+2,sn->record,ANDNS_HASH_H);
86
+	return ANDNS_HASH_H+2;
87
+}
88
+
89
+/*
90
+ * Converts a snsd_node struct to andns data.
91
+ * data means a packed answer.
92
+ * buf has to be ANDNS_MAX_ANSW_IP_LEN long.
93
+ *
94
+ * returns -1 on error, answer len otherwise.
95
+ *
96
+ *  O B S O L E T E
97
+
98
+size_t snsd_node_to_aansw(char *buf,snsd_node *sn,u_char prio,int iplen)
99
+{
100
+	int res;
101
+
102
+	res=snsd_node_to_data(buf+2,sn,iplen);
103
+	if (res==-1) {
104
+		error(err_str);
105
+		return -1;
106
+	}
107
+	if (sn->flags & SNSD_NODE_MAIN_IP)
108
+		*buf|=0x80;
109
+	*buf++=sn->weight;
110
+	*buf=prio;
111
+	return 0; 
112
+}
113
+*/
114
+
115
+
116
+/*
117
+ * Converts a snsd_prio list to andns data.
118
+ * data means a set of contiguous answers ready 
119
+ * to be sent.
120
+ *
121
+ * Returns the number of bytes writed to buf.
122
+ * The size is computable with iplen.
123
+ *
124
+ * buf has to be long enough, ie, you have to count node
125
+ * in prio list and take ANDNS_MAX_ANSW_IP_LEN * n space.
126
+ *
127
+ */
128
+int snsd_prio_to_aansws(char *buf,snsd_prio *sp,int iplen,int recursion,int *count)
129
+{
130
+	int res=0;
131
+	snsd_node *sn;
132
+	int c=0;
133
+	
134
+	if(!sp || !buf)
135
+		return 0;
136
+
137
+	sn=sp->node;
138
+	list_for(sn) { 
139
+		res+=snsd_node_to_data(buf+res,sn,sp->prio,
140
+			iplen,recursion);
141
+		c++;
142
+	}
143
+	*count=c;
144
+	return res;
145
+}
146
+
147
+int snsd_service_to_aansws(char *buf,snsd_service *ss,int iplen,int *count,int recursion)
148
+{
149
+	int family,c=0;
150
+	uint16_t service;
151
+	uint8_t prio,proto;
152
+	snsd_prio *sp;
153
+	snsd_node *sn;
154
+	char *rem;
155
+	snsd_node snt;
156
+
157
+	if (!ss || !buf)
158
+		return 0;
159
+	rem=buf;
160
+	
161
+	list_for(ss) {
162
+		service=htons(ss->service);
163
+		proto=ss->proto;
164
+		sp=ss->prio;
165
+		list_for(sp) {
166
+			prio=sp->prio;
167
+			sn=sp->node;
168
+			list_for(sn) {
169
+				if (sn->flags & SNSD_NODE_MAIN_IP)
170
+					(*buf)|=0xc0;
171
+				else if (sn->flags & SNSD_NODE_IP)
172
+					(*buf)|=0x40;
173
+				if (proto==ANDNS_SNSD_PROTO_UDP)
174
+					(*buf)|=0x20;
175
+				*buf++|=(sn->weight&0x1f);
176
+				*buf++|=prio;
177
+				memcpy(buf,&service,2);
178
+				buf+=2;
179
+				if (sn->flags & SNSD_NODE_MAIN_IP ||
180
+				    sn->flags & SNSD_NODE_IP ) {
181
+                			memcpy(buf,sn->record,iplen); 
182
+					family=(iplen==4)?AF_INET:AF_INET6;
183
+					inet_htonl((u_int*)buf,family);
184
+					buf+=iplen;
185
+				} else { 
186
+					if (recursion && !snsd_main_ip(sn->record,&snt)) {
187
+						memcpy(buf,snt.record,iplen);
188
+						*(buf-4)|=0x40;
189
+						family=(iplen==4)?AF_INET:AF_INET6;
190
+						inet_htonl((u_int*)buf,family);
191
+						buf+=iplen;
192
+					} else {
193
+						memcpy(buf,sn->record, ANDNS_HASH_H);
194
+						buf+=ANDNS_HASH_H;
195
+					}
196
+/*					service=strlen((char*)sn->record);
197
+					temp=htons(service);
198
+					memcpy(buf,&temp,2);
199
+					memcpy(buf+2,sn->record,service);
200
+					buf+=ANDNS_HASH_H;
201
+					res=snsd_main_ip(sn->record,&snt);
202
+					if (res) {
203
+						buf-=4;
204
+						continue;
205
+					}
206
+					memcpy(buf,snt.record,iplen);
207
+					family=(iplen==4)?AF_INET:AF_INET6;
208
+					inet_htonl((u_int*)buf,family);
209
+					buf+=iplen; */
210
+				}
211
+				c++;
212
+			}
213
+		}
214
+	}
215
+	*count=c;
216
+	return (int)(buf-rem);
217
+}
218
+					
219
+				
220
+				
221
+/*
222
+ * Given a dns_packet, this function add an answer to it
223
+ * and returns 0;
224
+ * Otherwise returns -1.
225
+ */
226
+int snsd_node_to_dansw(dns_pkt *dp,snsd_node *sn,int iplen)
227
+{
228
+	char temp[18];
229
+	dns_pkt_a *dpa;
230
+	snsd_node snt,*s;
231
+	int res;
232
+
233
+	if (!(sn->flags & SNSD_NODE_HNAME)) {
234
+		if (!(res=snsd_main_ip(sn->record,&snt)))
235
+			return -1;
236
+		s=&snt;
237
+	} else 
238
+		s=sn;
239
+
240
+        memcpy(temp,sn->record,iplen);
241
+        inet_htonl((u_int*)(temp),
242
+		(iplen==4)?AF_INET:AF_INET6);
243
+			
244
+	dpa=DP_ADD_ANSWER(dp);
245
+	dns_a_default_fill(dp,dpa);
246
+	dpa->rdlength=iplen;
247
+	memcpy(dpa->rdata,temp,iplen);
248
+	return 0;
249
+}
250
+/*
251
+ * Converts a snsd_prio struct, adding a set of answers to
252
+ * the dns_packet dp.
253
+ * Returns the number of answers added to dp.
254
+ */
255
+int snsd_prio_to_dansws(dns_pkt *dp,snsd_prio *sp,int iplen)
256
+{
257
+	int res=0;
258
+	snsd_node *sn;
259
+	
260
+	sn=sp->node;
261
+	list_for(sn) 
262
+		if (!snsd_node_to_dansw(dp,sn,iplen))
263
+			res++;
264
+	return res;
265
+}
266
+		
267
+		
268
+		
269
+	/* ip2h functions */
270
+
271
+/*
272
+ * Converts a lcl_cache struct to a set of dns answers.
273
+ * Returns the number of answers added.
274
+ */
275
+int lcl_cache_to_dansws(dns_pkt *dp,lcl_cache *lc)
276
+{
277
+	dns_pkt_a *dpa;
278
+	int res=0;
279
+	
280
+	list_for(lc) {
281
+		dpa=DP_ADD_ANSWER(dp);
282
+		dns_a_default_fill(dp,dpa);
283
+		strcpy(dpa->rdata,lc->hostname);
284
+		res++;
285
+	}
286
+
287
+	if(lc)
288
+		lcl_cache_free(lc);
289
+
290
+	return res;
291
+}
292
+
293
+/* 
294
+ * Converts a lcl_cache to andns data. 
295
+ * Returns the number of bytes writed.
296
+ */
297
+size_t lcl_cache_to_aansws(char *buf,lcl_cache *lc,int *count)
298
+{
299
+	uint16_t slen;
300
+	size_t ret=0;
301
+	int lcount=0;
302
+	lcl_cache *lcl=lc;
303
+	
304
+	list_for(lcl) {
305
+		slen=strlen(lc->hostname);
306
+		ret+=2+slen;
307
+		slen=htons(slen);
308
+		memcpy(buf,&slen,2);
309
+		buf+=2;
310
+		strcpy(buf,lc->hostname);
311
+		lcount++;
312
+	}
313
+	*count=lcount;
314
+	lcl_cache_free(lc);
315
+	return ret;
316
+}

+ 22
- 0
src/andns_snsd.h View File

@@ -0,0 +1,22 @@
1
+#ifndef ANDNS_SNSD_H
2
+#define ANDNS_SNSD_H
3
+
4
+#include "dnslib.h"
5
+#include "andns_lib.h"
6
+#include "andna_cache.h"
7
+
8
+#define ANDNS_SNSD_PROTO_TCP	1
9
+#define ANDNS_SNSD_PROTO_UDP	2
10
+
11
+/* functions */
12
+
13
+int snsd_main_ip(u_int *hname_hash,snsd_node *dst);
14
+int snsd_node_to_data(char *buf,snsd_node *sn,u_char prio,int iplen,int recursion);
15
+size_t snsd_node_to_aansw(char *buf,snsd_node *sn,u_char prio,int iplen);
16
+int snsd_prio_to_aansws(char *buf,snsd_prio *sp,int iplen,int recursion,int *count);
17
+int snsd_service_to_aansws(char *buf,snsd_service *ss,int iplen,int *count,int recursion);
18
+int snsd_node_to_dansw(dns_pkt *dp,snsd_node *sn,int iplen);
19
+int snsd_prio_to_dansws(dns_pkt *dp,snsd_prio *sp,int iplen);
20
+int lcl_cache_to_dansws(dns_pkt *dp,lcl_cache *lc);
21
+size_t lcl_cache_to_aansws(char *buf,lcl_cache *lc,int *count);
22
+#endif /* ANDNS_SNSD_H */

+ 454
- 0
src/bmap.c View File

@@ -0,0 +1,454 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ *
18
+ * --
19
+ * bmap.c:
20
+ * Border node map code.
21
+ */
22
+
23
+#include "includes.h"
24
+
25
+#include "common.h"
26
+#include "inet.h"
27
+#include "endianness.h"
28
+#include "map.h"
29
+#include "gmap.h"
30
+#include "bmap.h"
31
+
32
+void bmap_levels_init(u_char levels, map_bnode ***bmap, u_int **bmap_nodes)
33
+{
34
+	*bmap=xmalloc(sizeof(map_bnode *) * levels);
35
+	*bmap_nodes=(u_int *)xmalloc(sizeof(u_int) * levels);
36
+
37
+	setzero(*bmap, sizeof(map_bnode *) * levels);
38
+	bmap_counter_reset(levels, *bmap_nodes);
39
+}
40
+
41
+void bmap_levels_free(map_bnode **bmap, u_int *bmap_nodes)
42
+{
43
+	xfree(bmap);
44
+	xfree(bmap_nodes);
45
+}
46
+
47
+void bmap_counter_init(u_char levels, u_int **bnodes_closed, u_int **bnodes_opened)
48
+{
49
+	*bnodes_closed=(u_int *)xmalloc(sizeof(u_int) * levels);
50
+	*bnodes_opened=(u_int *)xmalloc(sizeof(u_int) * levels);
51
+	
52
+	bmap_counter_reset(levels, *bnodes_closed);
53
+	bmap_counter_reset(levels, *bnodes_opened);
54
+}
55
+
56
+void bmap_counter_free(u_int *bnodes_closed, u_int *bnodes_opened)
57
+{
58
+	xfree(bnodes_closed);
59
+	xfree(bnodes_opened);
60
+}
61
+
62
+void bmap_counter_reset(u_char levels, u_int *counter)
63
+{
64
+	setzero(counter, sizeof(u_int) * levels);
65
+}
66
+
67
+/* 
68
+ * map_add_bnode: It adds a new bnode in the `bmap' and then returns its position
69
+ * in the bmap. It also increments the `*bmap_nodes' counter. The bnode_ptr is set
70
+ * to `bnode' and the links to `links'.
71
+ * Note that the `bmap' argument must be an adress of a pointer.
72
+ */
73
+int map_add_bnode(map_bnode **bmap, u_int *bmap_nodes, u_int bnode, u_int links)
74
+{
75
+	map_bnode *bnode_map;
76
+	u_int bm;
77
+	
78
+	bm=*bmap_nodes; 
79
+	(*bmap_nodes)++;
80
+	if(!bm)
81
+		*bmap=xmalloc(sizeof(map_bnode));
82
+	else
83
+		*bmap=xrealloc(*bmap, sizeof(map_bnode) * *bmap_nodes);
84
+
85
+	bnode_map=*bmap;
86
+	setzero(bnode_map, sizeof(map_bnode));
87
+	bnode_map[bm].bnode_ptr=bnode;
88
+	bnode_map[bm].links=links;
89
+	return bm;
90
+}
91
+
92
+/* 
93
+ * map_bnode_del: It deletes the `bnode' in the `bmap' which has `bmap_nodes'.
94
+ * It returns the newly rescaled `bmap'.
95
+ * It returns 0 if the `bmap' doesn't exist anymore.*/
96
+map_bnode *map_bnode_del(map_bnode *bmap, u_int *bmap_nodes,  map_bnode *bnode)
97
+{
98
+	map_node_del((map_node *)bnode);
99
+	
100
+	if( ((char *)bnode-(char *)bmap)/sizeof(map_bnode) != (*bmap_nodes)-1 )
101
+		memcpy(bnode, &bmap[*bmap_nodes-1], sizeof(map_bnode));
102
+
103
+	(*bmap_nodes)--;
104
+	if(*bmap_nodes)
105
+		return xrealloc(bmap, (*bmap_nodes) * sizeof(map_bnode));
106
+	else {
107
+		*bmap_nodes=0;
108
+		xfree(bmap);
109
+		return 0;
110
+	}
111
+}
112
+
113
+/*
114
+ * bmap_del_rnode_by_level: it is pretty specific, it deletes all the rnodes
115
+ * of `bnode' which point to a gnode located in a level not equal to `level'.
116
+ * The number of rnode deleted is returned.
117
+ * `total_levels' must be equal to the maximum levels 
118
+ * available (use FAMILY_LVLS).
119
+ */
120
+int bmap_del_rnode_by_level(map_bnode *bnode, int level, map_gnode **ext_map,
121
+		int total_levels)
122
+{ 
123
+	map_gnode *gn;
124
+	int i, ret=0, lvl;
125
+	
126
+	
127
+	for(i=0; i < bnode->links; i++) {
128
+		gn=(map_gnode *)bnode->r_node[i].r_node;
129
+		lvl=extmap_find_level(ext_map, gn, total_levels);
130
+
131
+		if(lvl != level) {
132
+			rnode_del(bnode, i);
133
+			ret++;
134
+		}
135
+	}
136
+
137
+	return ret;
138
+}
139
+
140
+/* 
141
+ * map_find_bnode: Find the given `node' (in the pos_from_node() format) in the
142
+ * given map_bnode `bmap'.
143
+ */
144
+int map_find_bnode(map_bnode *bmap, int bmap_nodes, int node)
145
+{
146
+	int e;
147
+
148
+	for(e=0; e<bmap_nodes; e++)
149
+		if(bmap[e].bnode_ptr == node)
150
+			return e;
151
+	
152
+	return -1;
153
+}
154
+
155
+/* 
156
+ * map_find_bnode_rnode: Find the first bnode in the `bmap' which has a rnode
157
+ * which points to `n'. If it is found the pos of the bnode in the `bmap' is
158
+ * returned, otherwise -1 is the return value. 
159
+ */
160
+int map_find_bnode_rnode(map_bnode *bmap, int bmap_nodes, void *n)
161
+{
162
+	int e;
163
+
164
+	for(e=0; e<bmap_nodes; e++)
165
+		if(rnode_find((map_node *)&bmap[e], (map_node *)n) != -1)
166
+			return e;
167
+
168
+	return -1;
169
+}
170
+
171
+/*
172
+ * map_count_bnode_rnode: counts how many bnode which have a rnode which
173
+ * points to `n' there are in `bmap'.
174
+ */
175
+int map_count_bnode_rnode(map_bnode *bmap, int bmap_nodes, void *n)
176
+{
177
+	int e, i;
178
+
179
+	for(i=0, e=0; i<bmap_nodes; i++)
180
+		if(rnode_find((map_node *)&bmap[i], (map_node *)n) != -1)
181
+			e++;
182
+
183
+	return e;
184
+}
185
+
186
+/*
187
+ * bmaps_count_bnode_rnode: applies map_count_bnode_rnode() to each level of
188
+ * `bmap' and returns the sum of the results.
189
+ * `levels' are the total levels of `bmap'.
190
+ */
191
+int bmaps_count_bnode_rnode(map_bnode **bmap, int *bmap_nodes, int levels, void *n)
192
+{
193
+	int i, e;
194
+
195
+	for(i=0, e=0; i<levels; i++)
196
+		e+=map_count_bnode_rnode(bmap[i], bmap_nodes[i], n);
197
+
198
+	return e;
199
+}
200
+
201
+/*
202
+ * map_del_bnode_rnode: deletes all the rnodes of the bnode, present in `bmap',
203
+ * which points to `n' and deletes the bnodes remained empty.
204
+ * `bmap' is the address of the pointer to the bmap.
205
+ * It returns the number of rnodes deleted.
206
+ */
207
+int map_del_bnode_rnode(map_bnode **bmap, int *bmap_nodes, void *n)
208
+{
209
+	map_bnode *bm;
210
+	int e, p, ret=0;
211
+
212
+	bm=*bmap;
213
+	for(e=0; e < *bmap_nodes; e++) {
214
+		if((p=rnode_find((map_node *)&bm[e], (map_node *)n)) != -1) {
215
+			rnode_del(&bm[e], p);
216
+
217
+			if(!bm[e].links) {
218
+				*bmap=map_bnode_del(*bmap,(u_int*)bmap_nodes, &bm[e]);
219
+				bm=*bmap;
220
+			}
221
+			ret++;
222
+		}
223
+	}
224
+
225
+	return ret;
226
+}
227
+
228
+/*
229
+ * bmaps_del_bnode_rnode: applies map_del_bnode_rnode() to each level of
230
+ * `bmap'.
231
+ * `levels' are the total levels of `bmap'.
232
+ * It returns the total number of rnodes deleted
233
+ */
234
+int bmaps_del_bnode_rnode(map_bnode **bmap, int *bmap_nodes, int levels, void *n)
235
+{
236
+	int i, e;
237
+
238
+	for(i=0, e=0; i<levels; i++)
239
+		e+=map_del_bnode_rnode(&bmap[i], &bmap_nodes[i], n);
240
+
241
+	return e;
242
+}
243
+
244
+/*
245
+ * map_set_bnode_flag: sets the `flags' to all the `bmap_nodes'# present in
246
+ * `bmap'.
247
+ */
248
+void map_set_bnode_flag(map_bnode *bmap, int bmap_nodes, int flags)
249
+{
250
+	int e;
251
+	for(e=0; e<bmap_nodes; e++)
252
+		bmap[e].flags|=flags;
253
+}
254
+
255
+/*
256
+ * bmaps_set_bnode_flag: sets the `flags' to all the bnodes present in the
257
+ * `levels'#  `bmap'.
258
+ */
259
+void bmaps_set_bnode_flag(map_bnode **bmap, int *bmap_nodes, int levels, int flags)
260
+{
261
+	int i;		
262
+	
263
+	for(i=0; i<levels; i++)
264
+		map_set_bnode_flag(bmap[i], bmap_nodes[i], flags);
265
+}
266
+
267
+/* 
268
+ * pack_all_bmaps: It creates the block of all the `bmaps' which have
269
+ * `bmap_nodes' nodes. `ext_map' and `quadg' are the structs referring
270
+ * to the external map. In `pack_sz' is stored the size of the block.
271
+ * The address pointing to the block is returned otherwise 0 is given.
272
+ * The package will be in network order.
273
+ */
274
+char *
275
+pack_all_bmaps(map_bnode **bmaps,  u_int *bmap_nodes, map_gnode **ext_map,
276
+		quadro_group quadg, size_t *pack_sz)
277
+{
278
+	struct bnode_maps_hdr bmaps_hdr;
279
+	size_t sz, tmp_sz[BMAP_LEVELS(quadg.levels)];
280
+	char *pack[BMAP_LEVELS(quadg.levels)], *final_pack, *buf;
281
+	u_char level;
282
+
283
+	*pack_sz=0;
284
+
285
+	for(level=0; level < BMAP_LEVELS(quadg.levels); level++) {
286
+		pack[level]=pack_map((map_node *)bmaps[level], (int *)ext_map[_EL(level+1)], 
287
+				bmap_nodes[level], 0, &sz);
288
+		tmp_sz[level]=sz;
289
+		(*pack_sz)+=sz;
290
+	}
291
+
292
+	bmaps_hdr.levels=BMAP_LEVELS(quadg.levels);
293
+	bmaps_hdr.bmaps_block_sz=*pack_sz;
294
+	(*pack_sz)+=sizeof(struct bnode_maps_hdr);
295
+	
296
+	final_pack=xmalloc((*pack_sz));
297
+	memcpy(final_pack, &bmaps_hdr, sizeof(struct bnode_maps_hdr));
298
+	ints_host_to_network(final_pack, bnode_maps_hdr_iinfo);
299
+	
300
+	buf=final_pack+sizeof(struct bnode_maps_hdr);
301
+	for(level=0; level < BMAP_LEVELS(quadg.levels); level++) {
302
+		memcpy(buf, pack[level], tmp_sz[level]);
303
+		buf+=tmp_sz[level];
304
+		xfree(pack[level]);
305
+	}
306
+
307
+	return final_pack;
308
+}
309
+
310
+/*
311
+ * unpack_all_bmaps: Given a block `pack' of size `pack_sz' containing `levels'
312
+ * it unpacks each bnode map it finds in it. 
313
+ * `ext_map' is the external map used by the new bmaps.  
314
+ * In `bmap_nodes' unpack_all_bmaps stores the address of the newly xmallocated 
315
+ * array of u_int. Each bmap_nodes[x] contains the number of nodes of the bmap 
316
+ * of level x.  
317
+ * `maxbnodes' is the maximum number of nodes each bmap can contain,
318
+ * while `maxbnode_rnodeblock' is the maximum number of rnodes each node can
319
+ * contain.
320
+ * On error 0 is returned.
321
+ * Note: `pack' will be modified during the unpacking.
322
+ */ 
323
+map_bnode **
324
+unpack_all_bmaps(char *pack, u_char max_levels, map_gnode **ext_map, 
325
+		u_int **bmap_nodes, int maxbnodes, int maxbnode_rnodeblock)
326
+{
327
+	struct bnode_maps_hdr *bmaps_hdr;
328
+	struct bnode_map_hdr *bmap_hdr;
329
+	map_bnode **bmap, *unpacked_bmap;
330
+	size_t bblock_sz, pack_sz;
331
+	int i,e=0;
332
+	char *bblock, *buf;
333
+	u_char levels;
334
+	
335
+	bmaps_hdr=(struct bnode_maps_hdr *)pack;
336
+	ints_network_to_host(bmaps_hdr, bnode_maps_hdr_iinfo);
337
+
338
+	levels=bmaps_hdr->levels;
339
+	pack_sz=bmaps_hdr->bmaps_block_sz;
340
+	
341
+	if(levels > max_levels || pack_sz < sizeof(struct bnode_maps_hdr))
342
+		return 0;
343
+
344
+	bmap_levels_init(levels, &bmap, bmap_nodes);
345
+
346
+	buf=pack+sizeof(struct bnode_maps_hdr);
347
+	for(i=0; i<levels; i++) {
348
+		bmap_hdr=(struct bnode_map_hdr *)buf;
349
+		if(!bmap_hdr->bnode_map_sz) {
350
+			buf+=sizeof(struct bnode_map_hdr);
351
+			continue;
352
+		}
353
+		
354
+		/*Extracting the map...*/
355
+		bblock=(char *)bmap_hdr;
356
+		unpacked_bmap=unpack_map(bblock, (int *)ext_map[_EL(i+1)], 0,	
357
+				maxbnodes, maxbnode_rnodeblock);
358
+		if(!unpacked_bmap) {
359
+			error("Cannot unpack the bnode_map at level %d ! Skipping...", i);
360
+			e++;
361
+			continue;
362
+		}
363
+
364
+		(*bmap_nodes)[i]=bmap_hdr->bnode_map_sz/MAP_BNODE_PACK_SZ;
365
+		bblock_sz=INT_MAP_BLOCK_SZ(bmap_hdr->bnode_map_sz, bmap_hdr->rblock_sz);
366
+
367
+		bmap[i]=unpacked_bmap;
368
+
369
+		buf+=bblock_sz;
370
+	}
371
+	
372
+	if(e == levels)
373
+		/* Not a single map was restored */
374
+		return 0;
375
+
376
+	return bmap;
377
+}
378
+
379
+/* * *  save/load bnode_map * * */
380
+
381
+/* 
382
+ * save_bmap: It saves the bnode maps `bmaps' in `file'. The each `bmaps[x]' has
383
+ * `bmap_nodes[x]' nodes. `ext_map' is the pointer to the external map the bmap is
384
+ * referring to.
385
+ */
386
+int save_bmap(map_bnode **bmaps, u_int *bmap_nodes, map_gnode **ext_map, 
387
+		quadro_group quadg, char *file)
388
+{
389
+	FILE *fd;
390
+	char *pack;
391
+	size_t pack_sz;
392
+	
393
+	
394
+	pack=pack_all_bmaps(bmaps, bmap_nodes, ext_map, quadg, &pack_sz);
395
+	if(!pack_sz || !pack)
396
+		return 0;
397
+
398
+	if((fd=fopen(file, "w"))==NULL) {
399
+		error("Cannot save the bnode_map in %s: %s", file, strerror(errno));
400
+		return -1;
401
+	}
402
+	fwrite(pack, pack_sz, 1, fd);
403
+
404
+	xfree(pack);
405
+	fclose(fd);
406
+	return 0;
407
+}
408
+
409
+/*
410
+ * load_bmap: It loads all the bnode maps from `file' and returns the address
411
+ * of the array of pointer to the loaded bmaps. `ext_map' is the external maps
412
+ * the bmap shall refer to. In `bmap_nodes' the address of the u_int array, used
413
+ * to count the nodes in each bmaps, is stored. On error 0 is returned.
414
+ */
415
+map_bnode **load_bmap(char *file, map_gnode **ext_map, u_char max_levels, u_int **bmap_nodes)
416
+{
417
+	map_bnode **bmap=0;
418
+	FILE *fd;
419
+	struct bnode_maps_hdr bmaps_hdr;
420
+	size_t pack_sz;
421
+	u_char levels;
422
+	char *pack=0;
423
+	
424
+	if((fd=fopen(file, "r"))==NULL) {
425
+		error("Cannot load the bmap from %s: %s", file, strerror(errno));
426
+		return 0;
427
+	}
428
+	
429
+	if(!fread(&bmaps_hdr, sizeof(struct bnode_maps_hdr), 1, fd))
430
+		goto finish;
431
+		
432
+	ints_network_to_host(&bmaps_hdr, bnode_maps_hdr_iinfo);
433
+	levels=bmaps_hdr.levels;
434
+	pack_sz=bmaps_hdr.bmaps_block_sz;
435
+	if(levels > max_levels || pack_sz < sizeof(struct bnode_maps_hdr))
436
+		goto finish;
437
+
438
+	/* Extracting the map... */
439
+	rewind(fd);
440
+	pack=xmalloc(pack_sz);
441
+	if(!fread(pack, pack_sz, 1, fd))
442
+		goto finish;
443
+	
444
+	bmap=unpack_all_bmaps(pack, max_levels, ext_map, bmap_nodes, 
445
+			MAXGROUPNODE, MAXBNODE_RNODEBLOCK);
446
+	
447
+finish:
448
+	fclose(fd);
449
+	if(pack)
450
+		xfree(pack);
451
+	if(!bmap)
452
+		error("Malformed bmap file. Cannot load the bnode maps.");
453
+	return bmap;
454
+}

+ 169
- 0
src/bmap.h View File

@@ -0,0 +1,169 @@
1
+/* This file is part of Netsukuku system
2
+ * (c) Copyright 2004 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#ifndef BMAP_H
20
+#define BMAP_H
21
+
22
+#include "gmap.h"
23
+
24
+#define BMAP_UPDATE	MAP_UPDATE	/* At each new qspn_round all the bnodes flags are set 
25
+					   to BMAP_UPDATE, thus when tracer_store_pkt() updates
26
+					   them for the first time during the new round, it
27
+					   deletes their rnodes. */
28
+					   
29
+/* 
30
+ * map_bnode is the struct used to create the "map border node". 
31
+ * This map keeps all the border node of the map, making it easy to retrieve
32
+ * the gnode they are linked to.
33
+ * It is indentical to the map_node but, as always there are some little 
34
+ * differences:
35
+ *
36
+ *	uint16_t	links;		is the number of gnodes the bnode is 
37
+ *					linked to.
38
+ *	map_rnode	*r_node;	r_node[x].r_node, in this case, points 
39
+ *					to the position of the bnode's gnode in
40
+ *					the ext_map.
41
+ *	u_int           brdcast;	Where this node is in the int/ext_map.
42
+ *					The position is stored in the usual
43
+ *					pos_from_node() format. (Yep, a dirty hack)
44
+ *
45
+ * So you are asking why I didn't made a new struct for the bmap. Well, I don't 
46
+ * want to [re]write all the functions to handle the map, for example 
47
+ * rnode_add,rnode_del, save_map, etc... it's a pain, just for a little map and 
48
+ * moreover it adds new potential bugs. In conclusion: laziness + fear == hacks++;
49
+ *
50
+ */
51
+typedef map_node map_bnode;
52
+#define MAP_BNODE_PACK_SZ	MAP_NODE_PACK_SZ
53
+#define MAXGROUPBNODE		MAXGROUPNODE	/*the maximum number of bnodes in 
54
+						  a gnode is equal to the maximum 
55
+						  number of nodes*/
56
+#define MAXBNODE_LINKS		(MAXGROUPNODE*2)/*The maximum number of gnodes a
57
+						  bnode is linked to*/
58
+#define MAXBNODE_RNODEBLOCK	(MAXBNODE_LINKS*MAXGROUPBNODE*MAP_RNODE_PACK_SZ)
59
+
60
+/* 
61
+ * These defines make the life easier, so instead of writing int_map_hdr I
62
+ * write bnode_map_hdr. Cool eh? ^_^.
63
+ */
64
+#define bnode_ptr		brdcast		/*Don't kill me*/
65
+#define bnode_map_hdr 		int_map_hdr
66
+#define bnode_map_sz   		int_map_sz
67
+
68
+/*
69
+ * The bnode map uses only `me.cur_quadg.levels-1' levels, because each level of
70
+ * the bmap points to the upper one, therefore the last level is ignored.
71
+ */
72
+#define BMAP_LEVELS(levels)	(levels-1)
73
+#define BMAP_MAX_LEVELS		(BMAP_LEVELS(MAX_LEVELS))
74
+#define GET_BMAP_LEVELS(family) (BMAP_LEVELS(GET_LEVELS((family))))
75
+
76
+/* 
77
+ * border node block: this is the block which keeps the gnodes linked to the 
78
+ * `bnode' border_node. When a bnode has to add his entry in the tracer_pkt it 
79
+ * encapsulates the bnode_block at the end of the packet, in this way it is 
80
+ * possible to know all the gnodes linked to the bnode's gnode.
81
+ * Note: It is possible that the packet passes trough many bnodes, in this case 
82
+ * the bnode block is always put at the end, ex: 
83
+ * |pkt_hdr|brdcast_hdr|tracer_hdr|tracer_chunks|bnode_hdr|bnode_chunks|bnode_hdr|bnode_chunks|...
84
+ * and so on.
85
+ *
86
+ * The bblock is also used to store the Internet gateways, see igs.h for more
87
+ * details.
88
+ */
89
+typedef struct
90
+{
91
+	u_char  bnode_levels;
92
+	u_short links;			/*The number of linked gnode*/
93
+}_PACKED_ bnode_hdr;
94
+INT_INFO bnode_hdr_iinfo = { 1, { INT_TYPE_16BIT }, { sizeof(char) }, { 1 } };
95
+
96
+/*
97
+ * This is part of the bnode_hdr.
98
+ * 
99
+ * u_char bnode[bnode_levels];		The bnode this bnode_block belongs to.
100
+ */
101
+#define BNODE_HDR_SZ(levels)		(sizeof(bnode_hdr)+sizeof(u_char)*(levels))
102
+
103
+
104
+typedef struct
105
+{
106
+	/* The `bnode_hdr.bnode' borders on the `gnode' of `level'th level with
107
+	 * a round trip time which is stored in `rtt'. */
108
+
109
+	u_char		gnode;	     
110
+	u_char		level;
111
+	u_int		rtt;
112
+}_PACKED_ bnode_chunk;
113
+#define BNODEBLOCK_SZ(levels, links) (BNODE_HDR_SZ((levels)) +		       \
114
+					(sizeof(bnode_chunk)*(links)))
115
+INT_INFO bnode_chunk_iinfo = { 1, { INT_TYPE_32BIT }, { sizeof(char)*2 }, { 1 } };
116
+
117
+
118
+/* 
119
+ * This is the header placed on top of all the bnode_map blocks.
120
+ * So the bnode maps final block is:
121
+ * 	
122
+ * 	bnode_maps_hdr
123
+ * 	
124
+ * 	---------
125
+ * 	bnode_map_hdr
126
+ * 	bnode_map_block
127
+ * 	---------
128
+ * 	bnode_map_hdr
129
+ * 	bnode_map_block
130
+ * 	---------
131
+ * 	
132
+ * 	...
133
+ */
134
+struct bnode_maps_hdr
135
+{
136
+	u_char levels;
137
+	size_t bmaps_block_sz;
138
+}_PACKED_;
139
+INT_INFO bnode_maps_hdr_iinfo = { 1, { INT_TYPE_32BIT }, { sizeof(char) }, { 1 } };
140
+
141
+/* * * Functions' declaration * * */
142
+void bmap_levels_init(u_char levels, map_bnode ***bmap, u_int **bmap_nodes);
143
+void bmap_levels_free(map_bnode **bmap, u_int *bmap_nodes);
144
+void bmap_counter_init(u_char levels, u_int **bnodes_closed, u_int **bnodes_opened);
145
+void bmap_counter_free(u_int *bnodes_closed, u_int *bnodes_opened);
146
+void bmap_counter_reset(u_char levels, u_int *counter);
147
+
148
+int map_add_bnode(map_bnode **bmap, u_int *bmap_nodes, u_int bnode, u_int links);
149
+map_bnode *map_bnode_del(map_bnode *bmap, u_int *bmap_nodes,  map_bnode *bnode);
150
+int bmap_del_rnode_by_level(map_bnode *, int, map_gnode **, int);
151
+int map_find_bnode(map_bnode *bmap, int bmap_nodes, int node);
152
+int map_find_bnode_rnode(map_bnode *bmap, int bmap_nodes, void *n);
153
+
154
+int map_count_bnode_rnode(map_bnode *bmap, int bmap_nodes, void *n);
155
+int bmaps_count_bnode_rnode(map_bnode **bmap, int *bmap_nodes, int levels, void *n);
156
+int map_del_bnode_rnode(map_bnode **bmap, int *bmap_nodes, void *n);
157
+int bmaps_del_bnode_rnode(map_bnode **bmap, int *bmap_nodes, int levels, void *n);
158
+
159
+void map_set_bnode_flag(map_bnode *bmap, int bmap_nodes, int flags);
160
+void bmaps_set_bnode_flag(map_bnode **bmap, int *bmap_nodes, int levels, int flags);
161
+
162
+char *pack_all_bmaps(map_bnode **, u_int *, map_gnode **, quadro_group, size_t *);
163
+map_bnode **unpack_all_bmaps(char *, u_char, map_gnode **, u_int **, int, int);
164
+
165
+int save_bmap(map_bnode **, u_int *, map_gnode **, quadro_group, char *);
166
+map_bnode **load_bmap(char *, map_gnode **, u_char, u_int **);
167
+
168
+
169
+#endif /*BMAP_H*/

+ 36
- 0
src/buffer.c View File

@@ -0,0 +1,36 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ *
18
+ * --
19
+ * buffer.c: various functions to manipulate buffers
20
+ */
21
+
22
+/*
23
+ * is_bufzero
24
+ *
25
+ * Is the buffer `a' filled with `sz'# of zeros?
26
+ * If yes return 1. 
27
+ */
28
+int is_bufzero(const void *a, int sz)
29
+{
30
+	const char *p=a;
31
+	int i;
32
+	for(i=0; i<sz; i++, p++)
33
+		if(*p)
34
+			return 0;
35
+	return 1;
36
+}

+ 76
- 0
src/buffer.h View File

@@ -0,0 +1,76 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ *
18
+ * --
19
+ * buffer.c: various functions to manipulate buffers
20
+ */
21
+
22
+#ifndef BUFFER_H
23
+#define BUFFER_H
24
+
25
+/*
26
+ * In bzero(3):
27
+ * <<4.3BSD.  This function [bzero] is deprecated -- use memset in new 
28
+ *   programs.>>
29
+ */
30
+#define setzero(_p, _sz)	memset((_p), 0, (_sz))
31
+
32
+/*
33
+ * memput
34
+ *
35
+ * It copies `__sz' bytes from `__src' to `__dst' and then increments the `__dst'
36
+ * pointer of `__sz' bytes.
37
+ *
38
+ * *WARNING* 
39
+ * Do NOT put expression in `__dst', and `__sz', f.e.
40
+ * 	*WRONG CODE*
41
+ * 	memput(buf++, src, (size+=sizeof(src));
42
+ *
43
+ * 	*CORRECT CODE*
44
+ * 	buf++; size+=sizeof(src);
45
+ * 	memput(buf, src, size);
46
+ * *WARNING*
47
+ */
48
+#define memput(__dst, __src, __sz)					\
49
+({ 									\
50
+	void *_bufret=memcpy((__dst), (__src), (__sz));			\
51
+	(__dst)+=(__sz);						\
52
+	_bufret;							\
53
+})
54
+
55
+/*
56
+ * memget
57
+ *
58
+ * the same of memput(), but it increments `__src' instead.
59
+ */
60
+#define memget(__dst, __src, __sz)					\
61
+({ 									\
62
+	void *_bufret=memcpy((__dst), (__src), (__sz));			\
63
+	(__src)+=(__sz);						\
64
+	_bufret;							\
65
+})
66
+
67
+/* use of hardcoded `_src' and `_dst' variable names */
68
+#define bufput(_src, _sz)	(memput(buf, (_src), (_sz)))
69
+#define bufget(_dst, _sz)	(memget((_dst), buf, (_sz)))
70
+
71
+/*\
72
+ *   * * *  Functions declaration  * * *
73
+\*/
74
+int is_bufzero(const void *a, int sz);
75
+
76
+#endif /*BUFFER_H*/

+ 9
- 0
src/common.h View File

@@ -0,0 +1,9 @@
1
+#ifndef COMMON_H
2
+#define COMMON_H
3
+
4
+#include "misc.h"
5
+#include "buffer.h"
6
+#include "xmalloc.h"
7
+#include "log.h"
8
+
9
+#endif

+ 136
- 0
src/conf.c View File

@@ -0,0 +1,136 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ *
18
+ * --
19
+ * conf.c:
20
+ * Configuration file loader and parser. All the accepted option. which are
21
+ * listed in conf.h, are put in the environment for later retrievement.
22
+ */
23
+
24
+#include "includes.h"
25
+#include <ctype.h>
26
+
27
+#include "common.h"
28
+#include "conf.h"
29
+
30
+/*
31
+ * clear_config_env
32
+ *
33
+ * do not make the environment dirty
34
+ */
35
+void clear_config_env(void)
36
+{
37
+	int i;
38
+
39
+	for(i=0; config_str[i][0]; i++)
40
+		if(getenv(config_str[i]))
41
+			unsetenv(config_str[i]);
42
+}
43
+
44
+/*
45
+ * parse_config_line: it reads the `line' string and sees if it has a valid
46
+ * option assignment that is in the form of "option = value".
47
+ * On success it stores the option name with its value in the environment.
48
+ * On failure fatal() is called, so it will never return ;)
49
+ * `file' and `pos' are used by fatal() to tell where the corrupted `line' was.
50
+ */
51
+void parse_config_line(char *file, int pos, char *line)
52
+{
53
+	int i, e=0;
54
+	char *value;
55
+	
56
+	if(!(value=strchr(line, '=')))
57
+		fatal("The line %s:%d is invalid, it does not contain the '=' "
58
+				"character. Aborting.", file, pos);
59
+
60
+	for(i=0; config_str[i][0]; i++)
61
+		if(strstr(line, config_str[i])) {
62
+			e=1;
63
+			break;
64
+		}
65
+	if(!e)
66
+ 	    fatal("The line %s:%d does not contain a valid option. Aborting.",
67
+				file, pos);
68
+
69
+	value++;
70
+	while(isspace(*value)) 
71
+		value++;
72
+	
73
+	if(setenv(config_str[i], value, 1))
74
+		fatal("Error in line %s:%d: %s. Aborting.", file, pos, 
75
+				strerror(errno));
76
+}
77
+
78
+
79
+/*
80
+ * load_config_file: loads from `file' all the options that are written in it
81
+ * and stores them in the environment. See parse_config_line() above.
82
+ * If `file' cannot be opened -1 is returned, but if it is read and
83
+ * parse_config_line() detects a corrupted line, fatal() is directly called.
84
+ * On success 0 is returned.
85
+ */
86
+int load_config_file(char *file)
87
+{
88
+	FILE *fd;
89
+	char buf[PATH_MAX+1], *p, *str;
90
+	size_t slen;
91
+	int i=0, e=0;
92
+
93
+	if(!(fd=fopen(file, "r"))) {
94
+		fatal("Cannot load the configuration file from %s: %s\n"
95
+			"  Maybe you want to use the -c option ?",
96
+			file, strerror(errno));
97
+		return -1;
98
+	}
99
+
100
+	while(!feof(fd) && i < CONF_MAX_LINES) {
101
+		setzero(buf, PATH_MAX+1);
102
+		fgets(buf, PATH_MAX, fd);
103
+		e++;
104
+
105
+		if(feof(fd))
106
+			break;
107
+
108
+		str=buf;
109
+		while(isspace(*str))
110
+			str++;
111
+		if(*str=='#' || !*str) {
112
+			/* Strip off any comment or null lines */
113
+			continue;
114
+		} else {
115
+			/* Remove the last part of the string where a side
116
+			 * comment starts, 	#a comment like this.
117
+			 */
118
+			if((p=strrchr(str, '#')))
119
+				*p='\0';
120
+			
121
+			/* Don't include the newline and spaces of the end of 
122
+			 * the string */
123
+			slen=strlen(str);
124
+			for(p=&str[slen-1]; isspace(*p); p--)
125
+				*p='\0';
126
+			
127
+
128
+			parse_config_line(file, e, str);
129
+			i++;
130
+		}
131
+	}
132
+
133
+	fclose(fd);
134
+
135
+	return 0;
136
+}

+ 120
- 0
src/conf.h View File

@@ -0,0 +1,120 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#ifndef CONF_H
20
+#define CONF_H
21
+
22
+#define CONF_MAX_LINES		500	/* Max number of option lines */
23
+
24
+#define CONF_GET_VALUE(opt)		(getenv(config_str[(opt)]))
25
+#define CONF_GET_INT_VALUE(opt, n)					\
26
+({									\
27
+	char *_val;							\
28
+	_val=CONF_GET_VALUE((opt));					\
29
+	if(_val)							\
30
+		(n)=atoi(_val);						\
31
+})
32
+#define CONF_GET_STRN_VALUE(opt, str, maxbytes)				\
33
+({									\
34
+	char *_val;							\
35
+	_val=CONF_GET_VALUE((opt));					\
36
+ 	if(_val)							\
37
+ 		*(str)=xstrndup(_val, (maxbytes));			\
38
+})
39
+
40
+
41
+/* 
42
+ * The allowed options in the configuration file
43
+ */
44
+enum config_options
45
+{
46
+	CONF_NTK_INT_MAP_FILE,
47
+	CONF_NTK_BNODE_MAP_FILE,
48
+	CONF_NTK_EXT_MAP_FILE,
49
+
50
+	CONF_ANDNA_HNAMES_FILE,
51
+	CONF_SNSD_NODES_FILE,
52
+	CONF_ANDNA_CACHE_FILE,
53
+	CONF_ANDNA_LCLKEY_FILE,
54
+	CONF_ANDNA_LCL_FILE,
55
+	CONF_ANDNA_RHC_FILE,
56
+	CONF_ANDNA_COUNTER_C_FILE,
57
+
58
+	CONF_NTK_PID_FILE,
59
+	CONF_NTK_MAX_CONNECTIONS,
60
+	CONF_NTK_MAX_ACCEPTS_PER_HOST,
61
+	CONF_NTK_MAX_ACCEPTS_PER_HOST_TIME,
62
+
63
+	CONF_DISABLE_ANDNA,
64
+	CONF_DISABLE_RESOLVCONF,
65
+	
66
+	CONF_NTK_RESTRICTED_MODE,
67
+	CONF_NTK_RESTRICTED_CLASS,
68
+	CONF_NTK_INTERNET_CONNECTION,
69
+	CONF_NTK_INTERNET_GW,
70
+	CONF_NTK_INTERNET_UPLOAD,
71
+	CONF_NTK_INTERNET_DOWNLOAD,
72
+	CONF_NTK_INTERNET_PING_HOSTS,
73
+	CONF_SHARE_INTERNET,
74
+	CONF_SHAPE_INTERNET,
75
+	CONF_USE_SHARED_INET,
76
+	CONF_NTK_IP_MASQ_SCRIPT,
77
+	CONF_NTK_TC_SHAPER_SCRIPT,
78
+};
79
+
80
+const static char config_str[][30]=
81
+{
82
+	{ "ntk_int_map_file" },
83
+	{ "ntk_bnode_map_file" },
84
+	{ "ntk_ext_map_file" },
85
+	
86
+	{ "andna_hnames_file" },
87
+	{ "snsd_nodes_file" },
88
+	{ "andna_cache_file" },
89
+	{ "andna_lclkey_file" },
90
+	{ "andna_lcl_file" },
91
+	{ "andna_rhc_file" },
92
+	{ "andna_counter_c_file" },
93
+
94
+	{ "pid_file" },
95
+	{ "ntk_max_connections" },
96
+	{ "ntk_max_accepts_per_host" },
97
+	{ "max_accepts_per_host_time" },
98
+
99
+	{ "disable_andna" },
100
+	{ "disable_resolvconf" },
101
+	{ "ntk_restricted_mode" },
102
+	{ "ntk_restricted_class" },
103
+	{ "internet_connection" },
104
+	{ "internet_gateway" },
105
+	{ "internet_upload_rate" },
106
+	{ "internet_download_rate" },
107
+	{ "internet_ping_hosts" },
108
+	{ "share_internet" },
109
+	{ "shape_internet" },
110
+	{ "use_shared_internet" },
111
+	{ "ip_masquerade_script" },
112
+	{ "tc_shaper_script" },
113
+	{ 0 },
114
+};
115
+
116
+
117
+void clear_config_env(void);
118
+int load_config_file(char *file);
119
+
120
+#endif /*CONF_H*/

+ 1
- 0
src/conf/Makefile.am View File

@@ -0,0 +1 @@
1
+sysconf_DATA = netsukuku.conf andna_hostnames snsd_nodes

+ 321
- 0
src/conf/Makefile.in View File

@@ -0,0 +1,321 @@
1
+# Makefile.in generated by automake 1.8.5 from Makefile.am.
2
+# @configure_input@
3
+
4
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
5
+# 2003, 2004  Free Software Foundation, Inc.
6
+# This Makefile.in is free software; the Free Software Foundation
7
+# gives unlimited permission to copy and/or distribute it,
8
+# with or without modifications, as long as this notice is preserved.
9
+
10
+# This program is distributed in the hope that it will be useful,
11
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
12
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13
+# PARTICULAR PURPOSE.
14
+
15
+@SET_MAKE@
16
+
17
+srcdir = @srcdir@
18
+top_srcdir = @top_srcdir@
19
+VPATH = @srcdir@
20
+pkgdatadir = $(datadir)/@PACKAGE@
21
+pkglibdir = $(libdir)/@PACKAGE@
22
+pkgincludedir = $(includedir)/@PACKAGE@
23
+top_builddir = ../..
24
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
25
+INSTALL = @INSTALL@
26
+install_sh_DATA = $(install_sh) -c -m 644
27
+install_sh_PROGRAM = $(install_sh) -c
28
+install_sh_SCRIPT = $(install_sh) -c
29
+INSTALL_HEADER = $(INSTALL_DATA)
30
+transform = $(program_transform_name)
31
+NORMAL_INSTALL = :
32
+PRE_INSTALL = :
33
+POST_INSTALL = :
34
+NORMAL_UNINSTALL = :
35
+PRE_UNINSTALL = :
36
+POST_UNINSTALL = :
37
+host_triplet = @host@
38
+subdir = src/conf
39
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
40
+	$(srcdir)/netsukuku.conf.in
41
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
42
+am__aclocal_m4_deps = $(top_srcdir)/configure.ac
43
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
44
+	$(ACLOCAL_M4)
45
+mkinstalldirs = $(mkdir_p)
46
+CONFIG_HEADER = $(top_builddir)/src/config.h
47
+CONFIG_CLEAN_FILES = netsukuku.conf
48
+SOURCES =
49
+DIST_SOURCES =
50
+am__installdirs = "$(DESTDIR)$(sysconfdir)"
51
+sysconfDATA_INSTALL = $(INSTALL_DATA)
52
+DATA = $(sysconf_DATA)
53
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
54
+ACLOCAL = @ACLOCAL@
55
+AMDEP_FALSE = @AMDEP_FALSE@
56
+AMDEP_TRUE = @AMDEP_TRUE@
57
+AMTAR = @AMTAR@
58
+AUTOCONF = @AUTOCONF@
59
+AUTOHEADER = @AUTOHEADER@
60
+AUTOMAKE = @AUTOMAKE@
61
+AWK = @AWK@
62
+CC = @CC@
63
+CCDEPMODE = @CCDEPMODE@
64
+CFLAGS = @CFLAGS@
65
+CONF_DIR = @CONF_DIR@
66
+CPP = @CPP@
67
+CPPFLAGS = @CPPFLAGS@
68
+CXX = @CXX@
69
+CXXDEPMODE = @CXXDEPMODE@
70
+CXXFLAGS = @CXXFLAGS@
71
+CYGPATH_W = @CYGPATH_W@
72
+DATA_DIR = @DATA_DIR@
73
+DEFS = @DEFS@
74
+DEPDIR = @DEPDIR@
75
+ECHO_C = @ECHO_C@
76
+ECHO_N = @ECHO_N@
77
+ECHO_T = @ECHO_T@
78
+EGREP = @EGREP@
79
+EXEEXT = @EXEEXT@
80
+IF_METHOD = @IF_METHOD@
81
+INSTALL_DATA = @INSTALL_DATA@
82
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
83
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
84
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
85
+KERNEL_METHOD = @KERNEL_METHOD@
86
+LDFLAGS = @LDFLAGS@
87
+LIBOBJS = @LIBOBJS@
88
+LIBS = @LIBS@
89
+LTLIBOBJS = @LTLIBOBJS@
90
+MAKEINFO = @MAKEINFO@
91
+OBJEXT = @OBJEXT@
92
+OTHER_METHOD = @OTHER_METHOD@
93
+PACKAGE = @PACKAGE@
94
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
95
+PACKAGE_NAME = @PACKAGE_NAME@
96
+PACKAGE_STRING = @PACKAGE_STRING@
97
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
98
+PACKAGE_VERSION = @PACKAGE_VERSION@
99
+PATH_SEPARATOR = @PATH_SEPARATOR@
100
+PID_DIR = @PID_DIR@
101
+RT_METHOD = @RT_METHOD@
102
+SET_MAKE = @SET_MAKE@
103
+SHELL = @SHELL@
104
+STRIP = @STRIP@
105
+VERSION = @VERSION@
106
+ac_ct_CC = @ac_ct_CC@
107
+ac_ct_CXX = @ac_ct_CXX@
108
+ac_ct_STRIP = @ac_ct_STRIP@
109
+am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
110
+am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
111
+am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
112
+am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
113
+am__include = @am__include@
114
+am__leading_dot = @am__leading_dot@
115
+am__quote = @am__quote@
116
+bindir = @bindir@
117
+build = @build@
118
+build_alias = @build_alias@
119
+build_cpu = @build_cpu@
120
+build_os = @build_os@
121
+build_vendor = @build_vendor@
122
+datadir = @datadir@
123
+debug_flags = @debug_flags@
124
+exec_prefix = @exec_prefix@
125
+gmp = @gmp@
126
+host = @host@
127
+host_alias = @host_alias@
128
+host_cpu = @host_cpu@
129
+host_os = @host_os@
130
+host_vendor = @host_vendor@
131
+includedir = @includedir@
132
+infodir = @infodir@
133
+install_sh = @install_sh@
134
+libdir = @libdir@
135
+libexecdir = @libexecdir@
136
+localstatedir = @localstatedir@
137
+mandir = @mandir@
138
+mkdir_p = @mkdir_p@
139
+oldincludedir = @oldincludedir@
140
+prefix = @prefix@
141
+program_transform_name = @program_transform_name@
142
+sbindir = @sbindir@
143
+sharedstatedir = @sharedstatedir@
144
+sysconfdir = @sysconfdir@
145
+target_alias = @target_alias@
146
+sysconf_DATA = netsukuku.conf andna_hostnames snsd_nodes
147
+all: all-am
148
+
149
+.SUFFIXES:
150
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
151
+	@for dep in $?; do \
152
+	  case '$(am__configure_deps)' in \
153
+	    *$$dep*) \
154
+	      cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
155
+		&& exit 0; \
156
+	      exit 1;; \
157
+	  esac; \
158
+	done; \
159
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu  src/conf/Makefile'; \
160
+	cd $(top_srcdir) && \
161
+	  $(AUTOMAKE) --gnu  src/conf/Makefile
162
+.PRECIOUS: Makefile
163
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
164
+	@case '$?' in \
165
+	  *config.status*) \
166
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
167
+	  *) \
168
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
169
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
170
+	esac;
171
+
172
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
173
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
174
+
175
+$(top_srcdir)/configure:  $(am__configure_deps)
176
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
177
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
178
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
179
+netsukuku.conf: $(top_builddir)/config.status $(srcdir)/netsukuku.conf.in
180
+	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
181
+uninstall-info-am:
182
+install-sysconfDATA: $(sysconf_DATA)
183
+	@$(NORMAL_INSTALL)
184
+	test -z "$(sysconfdir)" || $(mkdir_p) "$(DESTDIR)$(sysconfdir)"
185
+	@list='$(sysconf_DATA)'; for p in $$list; do \
186
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
187
+	  f="`echo $$p | sed -e 's|^.*/||'`"; \
188
+	  echo " $(sysconfDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(sysconfdir)/$$f'"; \
189
+	  $(sysconfDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(sysconfdir)/$$f"; \
190
+	done
191
+
192
+uninstall-sysconfDATA:
193
+	@$(NORMAL_UNINSTALL)
194
+	@list='$(sysconf_DATA)'; for p in $$list; do \
195
+	  f="`echo $$p | sed -e 's|^.*/||'`"; \
196
+	  echo " rm -f '$(DESTDIR)$(sysconfdir)/$$f'"; \
197
+	  rm -f "$(DESTDIR)$(sysconfdir)/$$f"; \
198
+	done
199
+tags: TAGS
200
+TAGS:
201
+
202
+ctags: CTAGS
203
+CTAGS:
204
+
205
+
206
+distdir: $(DISTFILES)
207
+	@srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
208
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
209
+	list='$(DISTFILES)'; for file in $$list; do \
210
+	  case $$file in \
211
+	    $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
212
+	    $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
213
+	  esac; \
214
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
215
+	  dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
216
+	  if test "$$dir" != "$$file" && test "$$dir" != "."; then \
217
+	    dir="/$$dir"; \
218
+	    $(mkdir_p) "$(distdir)$$dir"; \
219
+	  else \
220
+	    dir=''; \
221
+	  fi; \
222
+	  if test -d $$d/$$file; then \
223
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
224
+	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
225
+	    fi; \
226
+	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
227
+	  else \
228
+	    test -f $(distdir)/$$file \
229
+	    || cp -p $$d/$$file $(distdir)/$$file \
230
+	    || exit 1; \
231
+	  fi; \
232
+	done
233
+check-am: all-am
234
+check: check-am
235
+all-am: Makefile $(DATA)
236
+installdirs:
237
+	for dir in "$(DESTDIR)$(sysconfdir)"; do \
238
+	  test -z "$$dir" || $(mkdir_p) "$$dir"; \
239
+	done
240
+install: install-am
241
+install-exec: install-exec-am
242
+install-data: install-data-am
243
+uninstall: uninstall-am
244
+
245
+install-am: all-am
246
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
247
+
248
+installcheck: installcheck-am
249
+install-strip:
250
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
251
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
252
+	  `test -z '$(STRIP)' || \
253
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
254
+mostlyclean-generic:
255
+
256
+clean-generic:
257
+
258
+distclean-generic:
259
+	-rm -f $(CONFIG_CLEAN_FILES)
260
+
261
+maintainer-clean-generic:
262
+	@echo "This command is intended for maintainers to use"
263
+	@echo "it deletes files that may require special tools to rebuild."
264
+clean: clean-am
265
+
266
+clean-am: clean-generic mostlyclean-am
267
+
268
+distclean: distclean-am
269
+	-rm -f Makefile
270
+distclean-am: clean-am distclean-generic
271
+
272
+dvi: dvi-am
273
+
274
+dvi-am:
275
+
276
+html: html-am
277
+
278
+info: info-am
279
+
280
+info-am:
281
+
282
+install-data-am:
283
+
284
+install-exec-am: install-sysconfDATA
285
+
286
+install-info: install-info-am
287
+
288
+install-man:
289
+
290
+installcheck-am:
291
+
292
+maintainer-clean: maintainer-clean-am
293
+	-rm -f Makefile
294
+maintainer-clean-am: distclean-am maintainer-clean-generic
295
+
296
+mostlyclean: mostlyclean-am
297
+
298
+mostlyclean-am: mostlyclean-generic
299
+
300
+pdf: pdf-am
301
+
302
+pdf-am:
303
+
304
+ps: ps-am
305
+
306
+ps-am:
307
+
308
+uninstall-am: uninstall-info-am uninstall-sysconfDATA
309
+
310
+.PHONY: all all-am check check-am clean clean-generic distclean \
311
+	distclean-generic distdir dvi dvi-am html html-am info info-am \
312
+	install install-am install-data install-data-am install-exec \
313
+	install-exec-am install-info install-info-am install-man \
314
+	install-strip install-sysconfDATA installcheck installcheck-am \
315
+	installdirs maintainer-clean maintainer-clean-generic \
316
+	mostlyclean mostlyclean-generic pdf pdf-am ps ps-am uninstall \
317
+	uninstall-am uninstall-info-am uninstall-sysconfDATA
318
+
319
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
320
+# Otherwise a system limit (for SysV at least) may be exceeded.
321
+.NOEXPORT:

+ 6
- 0
src/conf/SConscript View File

@@ -0,0 +1,6 @@
1
+Import('env')
2
+
3
+idir_conf   = '$destdir' + '$CONF_DIR'
4
+
5
+env.Install(idir_conf, ['netsukuku.conf', 'andna_hostnames', 'snsd_nodes'])
6
+env.Alias('install', [idir_conf])

+ 16
- 0
src/conf/andna_hostnames View File

@@ -0,0 +1,16 @@
1
+#
2
+#			ANDNA hostnames
3
+#
4
+#
5
+# In this file you can list, one per line, all the hostnames you want to
6
+# register in ANDNA.
7
+#
8
+# You can register up to 256 hostnames. Each hostname can be a string of
9
+# maximum 512 bytes, which contains a newline (\n) only at its end.
10
+#
11
+# Read: man andna
12
+#
13
+# *WARNING*    DO NOT LEAVE EMPTY LINES WITH SPACES OR TABS,   *WARNING*
14
+#	        THEY WILL BE REGISTERED AS REAL HOSTNAMES
15
+
16
+#my_cool_hostname

+ 199
- 0
src/conf/netsukuku.conf.in View File

@@ -0,0 +1,199 @@
1
+#
2
+#			NetsukukuD @VERSION@
3
+#
4
+#
5
+# The comments starts with a '#'.
6
+# To use a default option leave its line commented.
7
+# Use always the '=' to assign a value.
8
+#
9
+# Note: the options will be overridden by their command line equivalent.
10
+#
11
+# Options index:
12
+# 
13
+# 	## Restricted mode
14
+#		- ntk_restricted_mode
15
+#		- ntk_restricted_class
16
+#	## Internet connection
17
+#		- internet_connection
18
+#		- internet_gateway
19
+#		- internet_download_rate
20
+#		- internet_upload_rate
21
+#		- internet_ping_hosts
22
+#		- share_internet
23
+#		- shape_internet
24
+#		- use_shared_internet
25
+#	## ANDNA
26
+#		- disable_andna
27
+#		- disable_resolvconf
28
+#	## Limits
29
+#		- ntk_max_connections
30
+#		- ntk_max_accepts_per_host
31
+#		- max_accepts_per_host_time
32
+#	## Files
33
+#		- pid_file
34
+#		- ntk_ext_map_file
35
+#		- ntk_int_map_file
36
+#		- ntk_bnode_map_file
37
+#		- andna_hnames_file
38
+#		- snsd_nodes_file
39
+#		- andna_cache_file
40
+#		- andna_lclkey_file
41
+#		- andna_lcl_file
42
+#		- andna_rhc_file
43
+#		- andna_counter_c_file
44
+#		- ip_masquerade_script
45
+#		- tc_shaper_script
46
+#
47
+
48
+
49
+##
50
+#### Restricted mode
51
+##
52
+
53
+#
54
+# If the `ntk_restricted_mode' option is set to 1, NetsukukuD will be started
55
+# in restricted mode to be compatible with Internet. In the restricted mode, 
56
+# only IPs of the largest private subnet (i.e. 10.x.x.x) are chosen.
57
+#
58
+# If `ntk_restricted_class' is set to 1 the IPs will be chosen from the
59
+# 172.16.0.0-172.31.255.255 range (use this option only if you can't use the 
60
+# 10.x.x.x class).
61
+#
62
+#ntk_restricted_mode	= 0
63
+#ntk_restricted_class	= 0
64
+
65
+
66
+##
67
+#### Internet connection
68
+##
69
+
70
+#
71
+# * * If you have an Internet connection please fill this options. * *
72
+#
73
+# We are assuming that you are running in restricted mode since you want to
74
+# be both in Netsukuku and Internet. So, if you have an internet connection
75
+# set `internet_connection' to 1. Note that ntkd will overwrite any default
76
+# route if this option is set to 0 and the shared Internet connections of 
77
+# other nodes are used.
78
+#
79
+# Set the `internet_gateway' option to the IP of the gateway you use to reach 
80
+# the Internet and specify the network interface too, for example:
81
+# "internet_gateway = 192.168.1.1:eth0". This option is necessary only if you
82
+# don't have the default route set when you run NetsukukuD (i.e. you haven't
83
+# connected yet), otherwise, leave it commented.
84
+#
85
+# You have also to set your upload and download bandwidth in 
86
+# `internet_upload_rate' and `internet_download_rate'. It is expressed in Kb/s,
87
+# so if you have a line which maximum can do: 640 Kb/s in dwload and 30 Kb/s in 
88
+# upload, set them to 640 and 30.
89
+#
90
+# `internet_ping_hosts' is a list of Internet hosts which will be pinged to
91
+# verify if the connection is alive, you can use the default hosts.
92
+#
93
+# If you want to share your Internet connection among other Netsukuku nodes, 
94
+# set `share_internet' to 1.
95
+#
96
+# Set `shape_internet' to 1 if you want to shape your outgoing
97
+# Internet traffic.
98
+#
99
+# `use_shared_internet' specifies if you want to use the Internet connections
100
+# shared by the Netsukuku nodes. Set it to 0, if you want to rely only on your
101
+# connection (if any).
102
+# 
103
+#internet_connection	= 1
104
+#internet_gateway	= 192.168.1.1:eth0
105
+internet_download_rate  = 640
106
+internet_upload_rate	= 30
107
+internet_ping_hosts	= google.com:cisco.com:sourceforge.net:dyne.org
108
+#share_internet		= 1
109
+#shape_internet		= 1
110
+#use_shared_internet	= 1
111
+
112
+
113
+##
114
+#### ANDNA
115
+##
116
+
117
+#
118
+# To disable the start of the ANDNA daemon at the launch of ntkd, set
119
+# this option to 1. Note that when the ANDNA daemon is disabled, the andna
120
+# system will not work at all, so it will be impossible to resolve, register
121
+# or update hostnames.
122
+#
123
+#disable_andna		= 0
124
+
125
+#
126
+# When NetsukukuD starts it modifies /etc/resolv.conf writing in the first
127
+# line "nameserver 127.0.0.1". The old /etc/resolv.conf is copied in
128
+# /etc/resolv.conf.bak. When the daemon is closed /etc/resolv.conf is
129
+# restored. If you want to disable this set disable_resolvconf to 1.
130
+# If it is disabled you won't be able to resolve hostnames!
131
+#
132
+#disable_resolvconf	= 0
133
+
134
+
135
+##
136
+#### Limits
137
+##
138
+
139
+#
140
+# How many connection the netsukuku daemons can simultaneusly handle.
141
+#
142
+#ntk_max_connections		= 512
143
+
144
+# How many simultaneusly connections to the daemons from a single host are
145
+# allowed.
146
+#ntk_max_accepts_per_host	= 16
147
+
148
+# The wait time necessary for a host to reconnect to the daemons after all the
149
+# ntk_max_accepts_per_host were used.
150
+#
151
+#max_accepts_per_host_time	= 4	#in seconds
152
+
153
+
154
+##
155
+#### Files
156
+##
157
+
158
+#
159
+# ntkd will save its process id in this file
160
+#
161
+#pid_file 		= @PID_DIR@/ntkd.pid
162
+
163
+# 
164
+# The paths of the Netsukuku maps saved by the daemon
165
+#
166
+#ntk_ext_map_file	= @DT_DIR@/ext_map_file
167
+#ntk_int_map_file	= @DT_DIR@/int_map_file
168
+#ntk_bnode_map_file	= @DT_DIR@/bnode_map_file
169
+
170
+#
171
+# The hostnames that will be registered in ANDNA are kept, one per line, in
172
+# this file.
173
+#
174
+#andna_hnames_file	= @CONF_DIR@/andna_hostnames
175
+
176
+#
177
+# The snsd_nodes_file keeps the list of the SNSD records which will be
178
+# register in ANDNA.
179
+#
180
+#snsd_nodes_file	= @CONF_DIR@/snsd_nodes
181
+
182
+#
183
+# Caches used by the ANDNA daemon
184
+#
185
+#andna_cache_file	= @DT_DIR@/andna_cache
186
+#andna_lclkey_file	= @DT_DIR@/andna_lcl_keyring
187
+#andna_lcl_file		= @DT_DIR@/andna_lcl_cache
188
+#andna_rhc_file		= @DT_DIR@/andna_rh_cache
189
+#andna_counter_c_file	= @DT_DIR@/andna_counter_cache
190
+
191
+#
192
+# The script launched by NetsukukuD to share the Internet connection
193
+#
194
+#ip_masquerade_script	= @CONF_DIR@/ip_masquerade.sh
195
+
196
+#
197
+# The script launched by NetsukukuD to shape the Internet connection
198
+#
199
+#tc_shaper_script	= @CONF_DIR@/tc_shaper.sh

+ 199
- 0
src/conf/ntk_scons.conf.in View File

@@ -0,0 +1,199 @@
1
+#
2
+#			NetsukukuD %(VERSION)s 
3
+#
4
+#
5
+# The comments starts with a '#'.
6
+# To use a default option leave its line commented.
7
+# Use always the '=' to assign a value.
8
+#
9
+# Note: the options will be overridden by their command line equivalent.
10
+#
11
+# Options index:
12
+# 
13
+# 	## Restricted mode
14
+#		- ntk_restricted_mode
15
+#		- ntk_restricted_class
16
+#	## Internet connection
17
+#		- internet_connection
18
+#		- internet_gateway
19
+#		- internet_download_rate
20
+#		- internet_upload_rate
21
+#		- internet_ping_hosts
22
+#		- share_internet
23
+#		- shape_internet
24
+#		- use_shared_internet
25
+#	## ANDNA
26
+#		- disable_andna
27
+#		- disable_resolvconf
28
+#	## Limits
29
+#		- ntk_max_connections
30
+#		- ntk_max_accepts_per_host
31
+#		- max_accepts_per_host_time
32
+#	## Files
33
+#		- pid_file
34
+#		- ntk_ext_map_file
35
+#		- ntk_int_map_file
36
+#		- ntk_bnode_map_file
37
+#		- andna_hnames_file
38
+#		- snsd_nodes_file
39
+#		- andna_cache_file
40
+#		- andna_lclkey_file
41
+#		- andna_lcl_file
42
+#		- andna_rhc_file
43
+#		- andna_counter_c_file
44
+#		- ip_masquerade_script
45
+#		- tc_shaper_script
46
+#
47
+
48
+
49
+##
50
+#### Restricted mode
51
+##
52
+
53
+#
54
+# If the `ntk_restricted_mode' option is set to 1, NetsukukuD will be started
55
+# in restricted mode to be compatible with Internet. In the restricted mode, 
56
+# only IPs of the largest private subnet (i.e. 10.x.x.x) are chosen.
57
+#
58
+# If `ntk_restricted_class' is set to 1 the IPs will be chosen from the
59
+# 172.16.0.0-172.31.255.255 range (use this option only if you can't use the
60
+# 10.x.x.x class).
61
+#
62
+#ntk_restricted_mode	= 0
63
+#ntk_restricted_class	= 0
64
+
65
+
66
+##
67
+#### Internet connection
68
+##
69
+
70
+#
71
+# * * If you have an Internet connection please fill this options. * *
72
+#
73
+# We are assuming that you are running in restricted mode since you want to
74
+# be both in Netsukuku and Internet. So, if you have an internet connection
75
+# set `internet_connection' to 1. Note that ntkd will overwrite any default
76
+# route if this option is set to 0 and the shared Internet connections of 
77
+# other nodes are used.
78
+#
79
+# Set the `internet_gateway' option to the IP of the gateway you use to reach 
80
+# the Internet and specify the network interface too, for example:
81
+# "internet_gateway = 192.168.1.1:eth0". This option is necessary only if you
82
+# don't have the default route set when you run NetsukukuD (i.e. you haven't
83
+# connected yet), otherwise, leave it commented.
84
+#
85
+# You have also to set your upload and download bandwidth in 
86
+# `internet_upload_rate' and `internet_download_rate'. It is expressed in Kb/s,
87
+# so if you have a line which maximum can do: 640 Kb/s in dwload and 30 Kb/s in 
88
+# upload, set them to 640 and 30.
89
+#
90
+# `internet_ping_hosts' is a list of Internet hosts which will be pinged to
91
+# verify if the connection is alive, you can use the default hosts.
92
+#
93
+# If you want to share your Internet connection among other Netsukuku nodes, 
94
+# set `share_internet' to 1.
95
+#
96
+# Set `shape_internet' to 1 if you want to shape your outgoing
97
+# Internet traffic.
98
+#
99
+# `use_shared_internet' specifies if you want to use the Internet connections
100
+# shared by the Netsukuku nodes. Set it to 0, if you want to rely only on your
101
+# connection (if any).
102
+# 
103
+#internet_connection	= 1
104
+#internet_gateway	= 192.168.1.1:eth0
105
+internet_download_rate  = 640
106
+internet_upload_rate	= 30
107
+internet_ping_hosts	= google.com:cisco.com:sourceforge.net:dyne.org
108
+#share_internet		= 1
109
+#shape_internet		= 1
110
+#use_shared_internet	= 1
111
+
112
+
113
+##
114
+#### ANDNA
115
+##
116
+
117
+#
118
+# To disable the start of the ANDNA daemon at the launch of ntkd, set
119
+# this option to 1. Note that when the ANDNA daemon is disabled, the andna
120
+# system will not work at all, so it will be impossible to resolve, register
121
+# or update hostnames.
122
+#
123
+#disable_andna		= 0
124
+
125
+#
126
+# When NetsukukuD starts it modifies /etc/resolv.conf writing in the first
127
+# line "nameserver 127.0.0.1". The old /etc/resolv.conf is copied in
128
+# /etc/resolv.conf.bak. When the daemon is closed /etc/resolv.conf is
129
+# restored. If you want to disable this set disable_resolvconf to 1.
130
+# If it is disabled you won't be able to resolve hostnames!
131
+#
132
+#disable_resolvconf	= 0
133
+
134
+
135
+##
136
+#### Limits
137
+##
138
+
139
+#
140
+# How many connection the netsukuku daemons can simultaneusly handle.
141
+#
142
+#ntk_max_connections		= 512
143
+
144
+# How many simultaneusly connections to the daemons from a single host are
145
+# allowed.
146
+#ntk_max_accepts_per_host	= 16
147
+
148
+# The wait time necessary for a host to reconnect to the daemons after all the
149
+# ntk_max_accepts_per_host were used.
150
+#
151
+#max_accepts_per_host_time	= 4	#in seconds
152
+
153
+
154
+##
155
+#### Files
156
+##
157
+
158
+#
159
+# ntkd will save its process id in this file
160
+#
161
+#pid_file 		= %(PID_DIR)s/ntkd.pid
162
+
163
+# 
164
+# The paths of the Netsukuku maps saved by the daemon
165
+#
166
+#ntk_ext_map_file	= %(DATA_DIR)s/ext_map_file
167
+#ntk_int_map_file	= %(DATA_DIR)s/int_map_file
168
+#ntk_bnode_map_file	= %(DATA_DIR)s/bnode_map_file
169
+
170
+#
171
+# The hostnames that will be registered in ANDNA are kept, one per line, in
172
+# this file.
173
+#
174
+#andna_hnames_file	= %(CONF_DIR)s/andna_hostnames
175
+
176
+#
177
+# The snsd_nodes_file keeps the list of the SNSD records which will be
178
+# register in ANDNA.
179
+#
180
+#snsd_nodes_file	= %(CONF_DIR)s/snsd_nodes
181
+
182
+#
183
+# Caches used by the ANDNA daemon
184
+#
185
+#andna_cache_file	= %(DATA_DIR)s/andna_cache
186
+#andna_lclkey_file	= %(DATA_DIR)s/andna_lcl_keyring
187
+#andna_lcl_file		= %(DATA_DIR)s/andna_lcl_cache
188
+#andna_rhc_file		= %(DATA_DIR)s/andna_rh_cache
189
+#andna_counter_c_file	= %(DATA_DIR)s/andna_counter_cache
190
+
191
+#
192
+# The script launched by NetsukukuD to share the Internet connection
193
+#
194
+#ip_masquerade_script	= %(CONF_DIR)s/ip_masquerade.sh
195
+
196
+#
197
+# The script launched by NetsukukuD to shape the Internet connection
198
+#
199
+#tc_shaper_script	= %(CONF_DIR)s/tc_shaper.sh

+ 53
- 0
src/conf/snsd_nodes View File

@@ -0,0 +1,53 @@
1
+#
2
+#                       SNSD nodes file
3
+#
4
+# List, one per line, the SNSD records you want register in ANDNA.
5
+#
6
+# You can register up to 255 records and you can associate a maximum of 16
7
+# records to a service.
8
+#
9
+# Each line must be in the following format:
10
+#
11
+#	hostname:snsd_hostname:service:priority:weight[:pub_key_file]
12
+# or
13
+# 	hostname:snsd_ip:service:priority:weight[:pub_key_file]
14
+#
15
+#
16
+# The `pub_key_file' parameter is optional. If you specify it, NetsukukuD will
17
+# challenge periodically `snsd_hostname' and it will verify if it is always the
18
+# same machine. If it isn't, the relative snsd will be deleted.
19
+#
20
+# `hostname' must be one of the hostnames listed in the andna_hostnames file.
21
+#
22
+# `snsd_hostname' is the hostname of the snsd_node. `snsd_ip' is, instead, its
23
+# ip. 
24
+#
25
+# `service' specifies the service of the snsd record. It is one of the
26
+# service listed in /etc/services. It can be expressed also in numeric form.
27
+# It is also possible to specify the protocol, f.e: 
28
+# 	"domain", "53", "53/udp", "domain/udp"
29
+# are valid service strings.
30
+#
31
+# `priority' is an integer between 0 and 255, it specifies the "backup"
32
+# priority of the snsd record.
33
+#
34
+# `weight' is an integer between 0 and 12, it specifies the "load balancing"
35
+# weight of the snsd record.
36
+#
37
+# --
38
+#
39
+# The main IP associated to a normal hostname has these default values:
40
+#	IP	 = register_node IP	# This value can't be changed
41
+#	service  = 0
42
+#	priority = 16
43
+#	weight   = 1
44
+# If you want to modify the paremeters of the mainip use this syntax:
45
+#	hostname:hostname:0:priority:weight
46
+# Only one line with this syntax is allowed, duplicates will be ignored.
47
+#
48
+
49
+
50
+#my_cool_hostname:mysnsdnode:http:23:2
51
+#my_cool_hostname:1.2.4.5:21:1:4
52
+#my_good_hostname:mysnsdnode:ssh:1:9:/etc/netsukuku/snsd/mgh.pubk
53
+#another_hostname:anotherone:53/udp:1:4

+ 106
- 0
src/config.h.in View File

@@ -0,0 +1,106 @@
1
+/* src/config.h.in.  Generated from configure.ac by autoheader.  */
2
+
3
+/* "Location of configuration files" */
4
+#undef CONF_DIR
5
+
6
+/* "Where the Netsukuku data is saved" */
7
+#undef DATA_DIR
8
+
9
+/* FreeBSD */
10
+#undef FREEBSD
11
+
12
+/* GNU Linux */
13
+#undef GNU_LINUX
14
+
15
+/* Define to 1 if you have the <gmp.h> header file. */
16
+#undef HAVE_GMP_H
17
+
18
+/* Define to 1 if you have the <inttypes.h> header file. */
19
+#undef HAVE_INTTYPES_H
20
+
21
+/* Define to 1 if you have the `kvm' library (-lkvm). */
22
+#undef HAVE_LIBKVM
23
+
24
+/* Define to 1 if you have the `nsl' library (-lnsl). */
25
+#undef HAVE_LIBNSL
26
+
27
+/* Define to 1 if you have the `socket' library (-lsocket). */
28
+#undef HAVE_LIBSOCKET
29
+
30
+/* Define to 1 if you have the `xnet' library (-lxnet). */
31
+#undef HAVE_LIBXNET
32
+
33
+/* Define to 1 if you have the <memory.h> header file. */
34
+#undef HAVE_MEMORY_H
35
+
36
+/* netlink */
37
+#undef HAVE_NETLINK
38
+
39
+/* NET_RT_IFLIST */
40
+#undef HAVE_NET_RT_IFLIST
41
+
42
+/* Define to 1 if you have the <openssl/crypto.h> header file. */
43
+#undef HAVE_OPENSSL_CRYPTO_H
44
+
45
+/* Define to 1 if you have the <pthread.h> header file. */
46
+#undef HAVE_PTHREAD_H
47
+
48
+/* Define to 1 if you have the <stdint.h> header file. */
49
+#undef HAVE_STDINT_H
50
+
51
+/* Define to 1 if you have the <stdlib.h> header file. */
52
+#undef HAVE_STDLIB_H
53
+
54
+/* Define to 1 if you have the <strings.h> header file. */
55
+#undef HAVE_STRINGS_H
56
+
57
+/* Define to 1 if you have the <string.h> header file. */
58
+#undef HAVE_STRING_H
59
+
60
+/* Define to 1 if you have the <sys/stat.h> header file. */
61
+#undef HAVE_SYS_STAT_H
62
+
63
+/* Define to 1 if you have the <sys/types.h> header file. */
64
+#undef HAVE_SYS_TYPES_H
65
+
66
+/* Define to 1 if you have the <unistd.h> header file. */
67
+#undef HAVE_UNISTD_H
68
+
69
+/* Define to 1 if you have the <zlib.h> header file. */
70
+#undef HAVE_ZLIB_H
71
+
72
+/* IRIX 6.5 */
73
+#undef IRIX
74
+
75
+/* OpenBSD */
76
+#undef OPEN_BSD
77
+
78
+/* Name of package */
79
+#undef PACKAGE
80
+
81
+/* Define to the address where bug reports for this package should be sent. */
82
+#undef PACKAGE_BUGREPORT
83
+
84
+/* Define to the full name of this package. */
85
+#undef PACKAGE_NAME
86
+
87
+/* Define to the full name and version of this package. */
88
+#undef PACKAGE_STRING
89
+
90
+/* Define to the one symbol short name of this package. */
91
+#undef PACKAGE_TARNAME
92
+
93
+/* Define to the version of this package. */
94
+#undef PACKAGE_VERSION
95
+
96
+/* ntkd.pid file location */
97
+#undef PID_DIR
98
+
99
+/* Define to 1 if you have the ANSI C header files. */
100
+#undef STDC_HEADERS
101
+
102
+/* SunOS 5 */
103
+#undef SUNOS
104
+
105
+/* Version number of package */
106
+#undef VERSION

+ 10
- 0
src/config_scons.h.in View File

@@ -0,0 +1,10 @@
1
+#define CONF_DIR "%(CONF_DIR)s"
2
+#define DATA_DIR "%(DATA_DIR)s"
3
+#define PID_DIR "%(PID_DIR)s"
4
+
5
+#if %(debug)d
6
+#	undef  DEBUG
7
+#	define DEBUG
8
+#endif
9
+
10
+#define VERSION "%(VERSION)s"

+ 164
- 0
src/crypto.c View File

@@ -0,0 +1,164 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ *
18
+ * --
19
+ * crypto.c:
20
+ * front end to the OpenSSL cryptographic functions
21
+ */
22
+
23
+#include <openssl/bio.h>
24
+#include <openssl/evp.h>
25
+#include <openssl/crypto.h>
26
+#include <openssl/md5.h>
27
+#include <openssl/x509.h>
28
+#include <openssl/err.h>
29
+#include <openssl/rand.h>
30
+#include <openssl/rsa.h>
31
+#include <openssl/pem.h>
32
+
33
+#include "crypto.h"
34
+
35
+#include "log.h"
36
+#include "xmalloc.h"
37
+
38
+void init_crypto(void)
39
+{
40
+	RAND_load_file("/dev/urandom", 1024);
41
+	ERR_load_crypto_strings();
42
+}
43
+
44
+void free_crypto(void)
45
+{
46
+	ERR_free_strings();
47
+}
48
+
49
+char *ssl_strerr(void)
50
+{
51
+	return ERR_error_string(ERR_get_error(), 0);
52
+}
53
+
54
+/*
55
+ * genrsa: generates a new rsa key pair and returns the private key in the RSA
56
+ * format. If `pub' is not null, it stores in it the pointer to a newly
57
+ * allocated dump of the public key that is `*pub_len' bytes. The same is for
58
+ * `priv' and `priv_len'.
59
+ * On error null is returned.
60
+ */
61
+RSA *genrsa(int key_bits, u_char **pub, u_int *pub_len, u_char **priv, u_int *priv_len)
62
+{
63
+	RSA *rsa=0;
64
+	int len;
65
+	
66
+	rsa=RSA_generate_key(key_bits, RSA_F4, NULL, NULL);
67
+	if (!rsa) {
68
+		debug(DBG_SOFT, "RSA key generation failed"); 
69
+		goto error;
70
+	}
71
+
72
+	if(priv) {
73
+		*priv=0;
74
+		len=i2d_RSAPrivateKey(rsa, priv);
75
+		if(priv_len)
76
+			*priv_len=len;
77
+		if(len <= 0) {
78
+			debug(DBG_SOFT, "Cannot dump RSA public key: %s", ssl_strerr());
79
+			goto error;
80
+		}
81
+	}
82
+
83
+	if(pub) {
84
+		*pub=0;
85
+		len=i2d_RSAPublicKey(rsa, pub);
86
+		if(pub_len)
87
+			*pub_len=len;
88
+		if(len <= 0) {
89
+			debug(DBG_SOFT, "Cannot dump RSA public key: %s", ssl_strerr());
90
+			goto error;
91
+		}
92
+	}
93
+	
94
+	return rsa;
95
+error:
96
+	if(rsa)
97
+		RSA_free(rsa);	
98
+	return 0;
99
+}
100
+
101
+/*
102
+ * get_rsa_pub
103
+ *
104
+ * Converts a dump of a rsa pub key to a RSA structure, which is returned.
105
+ * Remeber to RSA_free() the returned key.
106
+ */
107
+RSA *get_rsa_pub(const u_char **pub_key, long length)
108
+{
109
+	 return d2i_RSAPublicKey(NULL, pub_key, length);
110
+}
111
+
112
+/*
113
+ * get_rsa_priv
114
+ *
115
+ * Converts a dump of a rsa priv key to a RSA structure, which is returned.
116
+ * Remeber to RSA_free() the returned key.
117
+ */
118
+RSA *get_rsa_priv(const u_char **priv_key, long length)
119
+{
120
+	 return d2i_RSAPrivateKey(NULL, priv_key, length);
121
+}
122
+
123
+u_char *hash_sha1(u_char *msg, u_int m_len, u_char *hash)
124
+{
125
+	return SHA1(msg, m_len, hash);
126
+}
127
+
128
+u_char *hash_md5(u_char *msg, u_int m_len, u_char *hash)
129
+{
130
+	return MD5(msg, m_len, hash);
131
+}
132
+
133
+/*
134
+ * rsa_sign: It signs the given message `msg' and returns its newly allocated
135
+ * signature. In `siglen' it stores the signature's lenght.
136
+ * On error null is returned.
137
+ */
138
+u_char *rsa_sign(u_char *msg, u_int m_len, RSA *priv, u_int *siglen)
139
+{
140
+	u_char *signature;
141
+	int ret, len;
142
+
143
+	ret=RSA_size(priv);
144
+	if(!ret)
145
+		return 0;
146
+
147
+	signature=(u_char *)xmalloc(ret);
148
+	ret=RSA_sign(NID_sha1, hash_sha1(msg, m_len, 0), SHA_DIGEST_LENGTH,
149
+			signature,(u_int*) &len, priv);
150
+	if(siglen)
151
+		*siglen=len;
152
+
153
+	return !ret ? 0 : signature;
154
+}
155
+
156
+/*
157
+ * verify_sign: verifies the rsa `signature' of `msg'.
158
+ * It returns 1 if the signature is valid, otherwise 0 is returned.
159
+ */
160
+int verify_sign(u_char *msg, u_int m_len, u_char *signature, u_int siglen, RSA *pub)
161
+{
162
+        return RSA_verify(NID_sha1, hash_sha1(msg, m_len, 0), SHA_DIGEST_LENGTH,
163
+			signature, siglen, pub);
164
+}

+ 46
- 0
src/crypto.h View File

@@ -0,0 +1,46 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#ifndef CRYPTO_H
20
+#define CRYPTO_H
21
+
22
+#include <openssl/bio.h>
23
+#include <openssl/evp.h>
24
+#include <openssl/crypto.h>
25
+#include <openssl/x509.h>
26
+#include <openssl/err.h>
27
+#include <openssl/rand.h>
28
+#include <openssl/rsa.h>
29
+#include <openssl/pem.h>
30
+
31
+#include <sys/types.h>
32
+
33
+#define RSA_PUB_EXPONENT	65537
34
+
35
+void init_crypto(void);
36
+void free_crypto(void);
37
+char *ssl_strerr(void);
38
+RSA *genrsa(int key_bits, u_char **pub, u_int *pub_len, u_char **priv, u_int *priv_len);
39
+RSA *get_rsa_pub(const u_char **pub_key, long length);
40
+RSA *get_rsa_priv(const u_char **priv_key, long length);
41
+u_char *hash_sha1(u_char *msg, u_int len, u_char *hash);
42
+u_char *hash_md5(u_char *msg, u_int m_len, u_char *hash);
43
+u_char *rsa_sign(u_char *msg, u_int m_len, RSA *priv, u_int *siglen);
44
+int verify_sign(u_char *msg, u_int m_len, u_char *signature, u_int siglen, RSA *pub);
45
+
46
+#endif /*CRYPTO_H*/

+ 459
- 0
src/daemon.c View File

@@ -0,0 +1,459 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#include "includes.h"
20
+
21
+#include "common.h"
22
+#include "inet.h"
23
+#include "request.h"
24
+#include "if.h"
25
+#include "pkts.h"
26
+#include "bmap.h"
27
+#include "daemon.h"
28
+#include "netsukuku.h"
29
+#include "accept.h"
30
+
31
+extern int errno;
32
+
33
+/* 
34
+ * prepare_listen_socket: 
35
+ * It creates a new socket of the desired `family' and binds it to the 
36
+ * specified `port'. It sets also the reuseaddr and NONBLOCK
37
+ * socket options, because this new socket shall be used to listen() and
38
+ * accept().
39
+ * If `dev' is not null, the socket will be binded to the device named 
40
+ * `dev'->dev_name with the SO_BINDTODEVICE socket option.
41
+ * The created socket is returned.
42
+ */
43
+int prepare_listen_socket(int family, int socktype, u_short port, 
44
+		interface *dev)
45
+{
46
+	struct addrinfo hints, *ai, *aitop;
47
+	char strport[NI_MAXSERV];
48
+	int err, s;
49
+
50
+	setzero(&hints, sizeof(struct addrinfo));
51
+	hints.ai_family=family;
52
+	hints.ai_socktype=socktype;
53
+	hints.ai_flags=AI_PASSIVE;
54
+	snprintf(strport, NI_MAXSERV, "%u", port);
55
+	
56
+	err=getaddrinfo(NULL, strport, &hints, &aitop);
57
+	if(err) {
58
+		error("Getaddrinfo error: %s", gai_strerror(err));
59
+		return -1;
60
+	}
61
+
62
+	for (ai = aitop; ai; ai = ai->ai_next) {
63
+		if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
64
+			continue;
65
+		
66
+		s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
67
+		if (s == -1)
68
+			/* Maybe we can use another socket...*/
69
+			continue;
70
+
71
+		/* Bind the created socket to the device named dev->dev_name */
72
+		if(dev && (set_bindtodevice_sk(s, dev->dev_name) < 0)) {
73
+			inet_close(&s);
74
+			continue;
75
+		}
76
+
77
+		if(set_reuseaddr_sk(s) < 0) {
78
+			inet_close(&s);
79
+			continue;
80
+		}
81
+
82
+		/* Let's bind it! */
83
+		if(bind(s, ai->ai_addr, ai->ai_addrlen) < 0) {
84
+			error("Cannot bind the port %d: %s. Trying another "
85
+					"socket...", port, strerror(errno));
86
+			inet_close(&s);
87
+			continue;
88
+		}
89
+		freeaddrinfo(aitop);
90
+		return s;
91
+	}
92
+	
93
+	error("Cannot open inbound socket on port %d: %s", port, strerror(errno));
94
+	freeaddrinfo(aitop);
95
+	return -1;
96
+}
97
+
98
+
99
+/*
100
+ * sockets_all_ifs
101
+ *
102
+ * creates a socket for each interface which is in the `ifs' array. 
103
+ * The array has `ifs_n' members.
104
+ * Each created socket is stored in the `dev_sk' array, which has `ifs_n'#
105
+ * members.
106
+ * The created socket will be bound to the relative interface.
107
+ * In `max_sk_idx' is stored the index of the `dev_sk' array, which has the
108
+ * biggest dev_sk.
109
+ *
110
+ * On error 0 is returned, otherwise the number of utilised interfaces is
111
+ * returned.
112
+ * If the error is fatal, a negative value is returned.
113
+ */
114
+int sockets_all_ifs(int family, int socktype, u_short port, 
115
+			interface *ifs, int ifs_n, 
116
+			int *dev_sk, int *max_sk_idx)
117
+{
118
+	int i, n, e=0;
119
+
120
+	*max_sk_idx=0;
121
+
122
+	for(i=0, n=0; i<ifs_n; i++) {
123
+		dev_sk[i] = prepare_listen_socket(family, socktype, port,
124
+				&ifs[i]);
125
+		
126
+		if(dev_sk[i] < 0) {
127
+			error("Cannot create a socket on the %s interface! "
128
+					"Ignoring it", ifs[i].dev_name);
129
+			dev_sk[i]=0;
130
+			e++;
131
+			continue;
132
+		}
133
+
134
+		if(dev_sk[i] >= dev_sk[*max_sk_idx])
135
+			*max_sk_idx=i;
136
+		
137
+		n++;
138
+	}
139
+
140
+	if(e == ifs_n)
141
+		return -1;
142
+
143
+	return n;
144
+}
145
+
146
+/*
147
+ *  udp_exec_pkt: passes the received udp packet to pkt_exec().
148
+ * `passed_argv' is a pointer to a udp_exec_pkt_argv struct 
149
+ */
150
+void *udp_exec_pkt(void *passed_argv)
151
+{
152
+	struct udp_exec_pkt_argv argv;
153
+	
154
+	PACKET rpkt;
155
+	const char *ntop;
156
+
157
+	memcpy(&argv, passed_argv, sizeof(struct udp_exec_pkt_argv));
158
+	memcpy(&rpkt, argv.recv_pkt, sizeof(PACKET));
159
+
160
+	if(argv.flags & UDP_THREAD_FOR_EACH_PKT)
161
+		pthread_mutex_unlock(&udp_exec_lock);
162
+	
163
+	/* Drop any packet we sent in broadcast */
164
+	if(!memcmp(rpkt.from.data, me.cur_ip.data, MAX_IP_SZ)) {
165
+		pkt_free(&rpkt, 0);
166
+		return 0;
167
+	}
168
+
169
+	if(add_accept(rpkt.from, 1)) {
170
+		ntop=inet_to_str(rpkt.from);
171
+		debug(DBG_NORMAL, "ACPT: dropped UDP pkt from %s: "
172
+				"Accept table full.", ntop);
173
+		return 0;
174
+	} 
175
+
176
+	pkt_exec(rpkt, argv.acpt_idx);
177
+	pkt_free(&rpkt, 0);
178
+	
179
+	return 0;
180
+}
181
+
182
+/*
183
+ * udp_daemon: Takes care of receiving udp packets.
184
+ * `passed_argv' is a pointer to a udp_daemon_argv struct
185
+ */
186
+void *udp_daemon(void *passed_argv)
187
+{
188
+	struct udp_daemon_argv argv;
189
+	struct udp_exec_pkt_argv exec_pkt_argv;
190
+	
191
+	interface *ifs;
192
+	int max_sk_idx, dev_sk[me.cur_ifs_n];
193
+
194
+	PACKET rpkt;
195
+	fd_set fdset;
196
+	int ret, i, err;
197
+	u_short udp_port;
198
+	
199
+	pthread_t thread;
200
+	pthread_attr_t t_attr;
201
+	
202
+#ifdef DEBUG
203
+	int select_errors=0;
204
+#endif
205
+	
206
+	memcpy(&argv, passed_argv, sizeof(struct udp_daemon_argv));
207
+	udp_port=argv.port;
208
+	setzero(&exec_pkt_argv, sizeof(struct udp_exec_pkt_argv));
209
+
210
+	if(argv.flags & UDP_THREAD_FOR_EACH_PKT) {
211
+		pthread_attr_init(&t_attr);
212
+		pthread_attr_setdetachstate(&t_attr, PTHREAD_CREATE_DETACHED);
213
+		exec_pkt_argv.flags|=UDP_THREAD_FOR_EACH_PKT;
214
+	}
215
+
216
+	debug(DBG_SOFT, "Preparing the udp listening socket on port %d", udp_port);
217
+	
218
+	err=sockets_all_ifs(my_family, SOCK_DGRAM, udp_port, me.cur_ifs,
219
+				me.cur_ifs_n, dev_sk, &max_sk_idx);
220
+	if(!err)
221
+		return NULL;
222
+	else if(err < 0)
223
+		fatal("Creation of the %s daemon aborted. "
224
+			"Is there another ntkd running?", "udp");
225
+	
226
+	debug(DBG_NORMAL, "Udp daemon on port %d up & running", udp_port);
227
+	pthread_mutex_unlock(&udp_daemon_lock);
228
+
229
+	pthread_mutex_init(&udp_exec_lock, 0);
230
+	
231
+	for(;;) {
232
+		FD_ZERO(&fdset);
233
+
234
+		if(!me.cur_ifs_n) {
235
+			/* All the devices have been removed while ntkd was
236
+			 * running, sleep well */
237
+			sleep(1);
238
+			continue;
239
+		}
240
+
241
+		for(i=0; i < me.cur_ifs_n; i++)
242
+			if(dev_sk[i])
243
+				FD_SET(dev_sk[i], &fdset);
244
+
245
+		ret=select(dev_sk[max_sk_idx]+1, &fdset, NULL, NULL, NULL);
246
+		if(sigterm_timestamp)
247
+			/* NetsukukuD has been closed */
248
+			break;
249
+		if (ret < 0) {
250
+#ifdef DEBUG
251
+			if(select_errors > 20)
252
+				break;
253
+			select_errors++;
254
+#endif
255
+			error("daemon_udp: select error: %s", strerror(errno));
256
+			continue;
257
+		}
258
+
259
+		for(i=0; i < me.cur_ifs_n; i++) {
260
+			ifs=&me.cur_ifs[i];
261
+			if(!dev_sk[i])
262
+				continue;
263
+			
264
+			if(!FD_ISSET(dev_sk[i], &fdset))
265
+				continue;
266
+
267
+			setzero(&rpkt, sizeof(PACKET));
268
+			pkt_addsk(&rpkt, my_family, dev_sk[i], SKT_UDP);
269
+			pkt_add_dev(&rpkt, ifs, 0);
270
+			rpkt.flags=MSG_WAITALL;
271
+			pkt_addport(&rpkt, udp_port);
272
+
273
+			if(pkt_recv(&rpkt) < 0) {
274
+				pkt_free(&rpkt, 0);
275
+				continue;
276
+			}
277
+
278
+			exec_pkt_argv.acpt_idx=accept_idx;
279
+			exec_pkt_argv.acpt_sidx=accept_sidx;
280
+
281
+			if(argv.flags & UDP_THREAD_FOR_EACH_PKT) {
282
+				exec_pkt_argv.recv_pkt=&rpkt;
283
+				pthread_mutex_lock(&udp_exec_lock);
284
+				pthread_create(&thread, &t_attr, udp_exec_pkt,
285
+						&exec_pkt_argv);
286
+				pthread_mutex_lock(&udp_exec_lock);
287
+				pthread_mutex_unlock(&udp_exec_lock);
288
+			} else {
289
+				exec_pkt_argv.recv_pkt=&rpkt;
290
+				udp_exec_pkt(&exec_pkt_argv);
291
+			}
292
+		}
293
+	}
294
+
295
+	destroy_accept_tbl();
296
+	return NULL;
297
+}
298
+
299
+void *tcp_recv_loop(void *recv_pkt)
300
+{
301
+	PACKET rpkt;
302
+	int acpt_idx, acpt_sidx;
303
+
304
+	acpt_idx=accept_idx;
305
+	acpt_sidx=accept_sidx;
306
+	memcpy(&rpkt, recv_pkt, sizeof(PACKET));
307
+	pthread_mutex_unlock(&tcp_exec_lock);
308
+
309
+#if 0
310
+	add_accept_pid(getpid(), acpt_idx, acpt_sidx);
311
+#endif
312
+
313
+	while( pkt_recv(&rpkt) != -1 ) {
314
+		if(pkt_exec(rpkt, acpt_idx) < 0) {
315
+			goto close;
316
+			break;
317
+		} else
318
+			pkt_free(&rpkt, 0);
319
+	}
320
+
321
+close:
322
+	pkt_free(&rpkt, 1);
323
+	close_accept(acpt_idx, acpt_sidx);
324
+
325
+	return NULL;
326
+}
327
+
328
+void *tcp_daemon(void *door)
329
+{
330
+	pthread_t thread;
331
+	pthread_attr_t t_attr;
332
+	
333
+	PACKET rpkt;
334
+	struct sockaddr_storage addr;
335
+	socklen_t addrlen = sizeof addr;
336
+	inet_prefix ip;
337
+	
338
+	fd_set fdset;
339
+	int fd, ret, err, i;
340
+
341
+	interface *ifs;
342
+	int max_sk_idx, dev_sk[me.cur_ifs_n];
343
+	
344
+	u_short tcp_port=*(u_short *)door;
345
+	const char *ntop;
346
+
347
+	pthread_attr_init(&t_attr);
348
+	pthread_attr_setdetachstate(&t_attr, PTHREAD_CREATE_DETACHED);
349
+	
350
+	debug(DBG_SOFT, "Preparing the tcp listening socket on port %d", tcp_port);
351
+
352
+	err=sockets_all_ifs(my_family, SOCK_STREAM, tcp_port, me.cur_ifs, 
353
+				me.cur_ifs_n, dev_sk, &max_sk_idx);
354
+	if(!err)
355
+		return NULL;
356
+	else if(err < 0)
357
+		fatal("Creation of the %s daemon aborted. "
358
+			"Is there another ntkd running?", "tcp");
359
+
360
+	pthread_mutex_init(&tcp_exec_lock, 0);
361
+
362
+	for(i=0; i<me.cur_ifs_n; i++) {
363
+		if(!dev_sk[i])
364
+			continue;
365
+		/* 
366
+		 * While we are accepting the connections we keep the socket non
367
+		 * blocking.
368
+		 */
369
+		if(set_nonblock_sk(dev_sk[i]))
370
+			return NULL;
371
+
372
+		/* Shhh, it's listening... */
373
+		if(listen(dev_sk[i], 5) == -1) {
374
+			inet_close(&dev_sk[i]);
375
+			return NULL;
376
+		}
377
+	}
378
+	
379
+	debug(DBG_NORMAL, "Tcp daemon on port %d up & running", tcp_port);
380
+	pthread_mutex_unlock(&tcp_daemon_lock);
381
+	for(;;) {
382
+		FD_ZERO(&fdset);
383
+
384
+		if(!me.cur_ifs_n) {
385
+			/* All the devices have been removed while ntkd was
386
+			 * running, sleep well */
387
+			sleep(1);
388
+			continue;
389
+		}
390
+
391
+		for(i=0; i < me.cur_ifs_n; i++)
392
+			if(dev_sk[i])
393
+				FD_SET(dev_sk[i], &fdset);
394
+
395
+		ret=select(dev_sk[max_sk_idx]+1, &fdset, NULL, NULL, NULL);
396
+		if(sigterm_timestamp)
397
+			/* NetsukukuD has been closed */
398
+			break;
399
+		if(ret < 0 && errno != EINTR)
400
+			error("daemon_tcp: select error: %s", strerror(errno));
401
+		if(ret < 0)
402
+			continue;
403
+
404
+		for(i=0; i < me.cur_ifs_n; i++) {
405
+			ifs=&me.cur_ifs[i];
406
+			if(!dev_sk[i])
407
+				continue;
408
+
409
+			if(!FD_ISSET(dev_sk[i], &fdset))
410
+				continue;
411
+
412
+			fd=accept(dev_sk[i], (struct sockaddr *)&addr, &addrlen);
413
+			if(fd == -1) {
414
+				if (errno != EINTR && errno != EWOULDBLOCK)
415
+					error("daemon_tcp: accept(): %s", strerror(errno));
416
+				continue;
417
+			}
418
+
419
+			setzero(&rpkt, sizeof(PACKET));
420
+			pkt_addsk(&rpkt, my_family, fd, SKT_TCP);
421
+			pkt_add_dev(&rpkt, ifs, 0);
422
+			rpkt.flags=MSG_WAITALL;
423
+			pkt_addport(&rpkt, tcp_port);
424
+
425
+			ntop=0;
426
+			sockaddr_to_inet((struct sockaddr *)&addr, &ip, 0);
427
+			pkt_addfrom(&rpkt, &ip);
428
+			if(server_opt.dbg_lvl)
429
+				ntop=inet_to_str(ip);
430
+
431
+			if((ret=add_accept(ip, 0))) {
432
+				debug(DBG_NORMAL, "ACPT: drop connection with %s: "
433
+						"Accept table full.", ntop);
434
+
435
+				/* Omg, we cannot take it anymore, go away: ACK_NEGATIVE */
436
+				pkt_err(rpkt, ret, 1);
437
+				inet_close(&fd);
438
+				continue;
439
+			} else {
440
+				/* 
441
+				 * Ok, the connection is good, send back the
442
+				 * ACK_AFFERMATIVE.
443
+				 */
444
+				pkt_addto(&rpkt, &rpkt.from);
445
+				send_rq(&rpkt, 0, ACK_AFFERMATIVE, 0, 0, 0, 0);
446
+			}
447
+
448
+			if(unset_nonblock_sk(fd))
449
+				continue;
450
+
451
+			pthread_mutex_lock(&tcp_exec_lock);
452
+			err=pthread_create(&thread, &t_attr, tcp_recv_loop, (void *)&rpkt);
453
+			pthread_detach(thread);
454
+			pthread_mutex_lock(&tcp_exec_lock);
455
+			pthread_mutex_unlock(&tcp_exec_lock);
456
+		}
457
+	}
458
+	return NULL;
459
+}

+ 55
- 0
src/daemon.h View File

@@ -0,0 +1,55 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2004 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#ifndef DAEMON_H
20
+#define DAEMON_H
21
+
22
+#define MAX_LISTENING_SOCKETS		MAX_INTERFACES
23
+
24
+/* These mutexes are used to wait the complete start up of the daemons when
25
+ * launched. */
26
+pthread_mutex_t udp_daemon_lock;
27
+pthread_mutex_t tcp_daemon_lock;
28
+
29
+/* flags for udp_exec_pkt_argv and udp_daemon_argv */
30
+#define UDP_THREAD_FOR_EACH_PKT		1	/* For each incoming udp
31
+						   packets use threads */
32
+
33
+/* Argv passed to udp_exec_pkt() */
34
+struct udp_exec_pkt_argv {
35
+	PACKET 		*recv_pkt;
36
+	int		acpt_idx;
37
+	int		acpt_sidx;
38
+	u_char		flags;
39
+};
40
+
41
+/* Argv passed to udp_daemon */
42
+struct udp_daemon_argv {
43
+	u_short		port;
44
+	u_char		flags;
45
+};
46
+
47
+pthread_mutex_t udp_exec_lock;
48
+pthread_mutex_t tcp_exec_lock;
49
+
50
+int prepare_listen_socket(int family, int socktype, u_short port, interface *dev);
51
+void *tcp_recv_loop(void *recv_pkt);
52
+void *tcp_daemon(void *null);
53
+void *udp_daemon(void *door);
54
+
55
+#endif /*DAEMON_H*/

+ 174
- 0
src/dns_wrapper.c View File

@@ -0,0 +1,174 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ *
18
+ * --
19
+ * dns_wrapper.c:
20
+ *
21
+ * The DNS wrapper listens to the port 53 for DNS hostname resolution queries,
22
+ * it then resolves the hostname by using the ANDNA system and sends back the
23
+ * resolved ip. In this way, every program can use ANDNA: just set 
24
+ * "nameserver localhost"
25
+ * in /etc/resolv.conf ;)
26
+ */
27
+
28
+#include "includes.h"
29
+
30
+#include "inet.h"
31
+#include "endianness.h"
32
+#include "map.h"
33
+#include "gmap.h"
34
+#include "bmap.h"
35
+#include "route.h"
36
+#include "request.h"
37
+#include "pkts.h"
38
+#include "tracer.h"
39
+#include "qspn.h"
40
+#include "radar.h"
41
+#include "netsukuku.h"
42
+#include "daemon.h"
43
+#include "crypto.h"
44
+#include "andna_cache.h"
45
+#include "andna.h"
46
+#include "andns.h"
47
+#include "dns_wrapper.h"
48
+#include "common.h"
49
+
50
+/*
51
+ * dns_exec_pkt: resolve the hostname contained in the DNS query and sends
52
+ * the reply to from. 
53
+ * `passed_argv' is a pointer to a dns_exec_pkt_argv struct.
54
+ */
55
+void *dns_exec_pkt(void *passed_argv)
56
+{
57
+	struct dns_exec_pkt_argv argv;
58
+
59
+	char buf[MAX_DNS_PKT_SZ];
60
+	char answer_buffer[ANDNS_MAX_SZ];
61
+	int answer_length;
62
+	int bytes_sent;
63
+
64
+	memcpy(&argv, passed_argv, sizeof(struct dns_exec_pkt_argv));
65
+	memcpy(&buf, argv.rpkt, argv.rpkt_sz);
66
+	pthread_mutex_unlock(&dns_exec_lock);
67
+
68
+	if (argv.rpkt_sz < MIN_PKT_SZ) {
69
+		debug(DBG_NORMAL, "Received malformed DNS packet");
70
+		return 0;
71
+	}
72
+
73
+	/* Unpack the DNS query and resolve the hostname */
74
+	if(!andns_rslv(buf, argv.rpkt_sz, answer_buffer, &answer_length))
75
+		return 0;
76
+
77
+	/* Send the DNS reply */
78
+	bytes_sent=inet_sendto(argv.sk, answer_buffer, answer_length, 0,
79
+			&argv.from, argv.from_len);
80
+	if(bytes_sent != answer_length)
81
+		debug(DBG_SOFT, ERROR_MSG "inet_sendto error: %s", ERROR_POS,
82
+				strerror(errno));
83
+
84
+	return 0;
85
+}
86
+
87
+/*
88
+ * dns_wrapper_daemon: It receives DNS query pkts, resolves them in ANDNA and
89
+ * replies with a DNS reply.
90
+ * It listens to `port'.
91
+ */
92
+void dns_wrapper_daemon(u_short port)
93
+{
94
+	struct dns_exec_pkt_argv exec_pkt_argv;
95
+	char buf[MAX_DNS_PKT_SZ];
96
+
97
+	fd_set fdset;
98
+	int ret, sk;
99
+	pthread_t thread;
100
+	pthread_attr_t t_attr;
101
+	ssize_t err=-1;
102
+
103
+#ifdef DEBUG
104
+	int select_errors=0;
105
+#endif
106
+	
107
+	pthread_attr_init(&t_attr);
108
+	pthread_attr_setdetachstate(&t_attr, PTHREAD_CREATE_DETACHED);
109
+	pthread_mutex_init(&dns_exec_lock, 0);
110
+
111
+	debug(DBG_SOFT, "Preparing the dns_udp listening socket on port %d", port);
112
+	sk=prepare_listen_socket(my_family, SOCK_DGRAM, port, 0);
113
+	if(sk == -1)
114
+		return;
115
+
116
+	debug(DBG_NORMAL, "DNS wrapper daemon on port %d up & running", port);
117
+	for(;;) {
118
+		if(!sk)
119
+			fatal("The dns_wrapper_daemon socket got corrupted");
120
+		
121
+		FD_ZERO(&fdset);
122
+		FD_SET(sk, &fdset);
123
+		
124
+		ret = select(sk+1, &fdset, NULL, NULL, NULL);
125
+		if(sigterm_timestamp)
126
+			/* NetsukukuD has been closed */
127
+			break;
128
+		if (ret < 0) {
129
+#ifdef DEBUG
130
+			if(select_errors > 20)
131
+				break;
132
+			select_errors++;
133
+#endif
134
+			error("dns_wrapper_daemonp: select error: %s", 
135
+					strerror(errno));
136
+			continue;
137
+		}
138
+		if(!FD_ISSET(sk, &fdset))
139
+			continue;
140
+
141
+		setzero(&buf, MAX_DNS_PKT_SZ);
142
+		setzero(&exec_pkt_argv.from, sizeof(struct sockaddr));
143
+		setzero(&exec_pkt_argv, sizeof(struct dns_exec_pkt_argv));
144
+		
145
+		exec_pkt_argv.from_len = my_family == AF_INET ?
146
+			sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6);
147
+
148
+		/* we get the DNS query */
149
+		err=inet_recvfrom(sk, buf, MAX_DNS_PKT_SZ, MSG_WAITALL,
150
+				&exec_pkt_argv.from, &exec_pkt_argv.from_len);
151
+		if(err < 0) {
152
+			debug(DBG_NOISE, "dns_wrapper_daemonp: recv of the dns"
153
+					" query pkt aborted!");
154
+			continue;
155
+		}
156
+		
157
+		/* Exec the pkt in another thread */
158
+		exec_pkt_argv.sk=sk;
159
+		exec_pkt_argv.rpkt_sz=err;
160
+		exec_pkt_argv.rpkt=buf;
161
+		
162
+		pthread_mutex_lock(&dns_exec_lock);
163
+		pthread_create(&thread, &t_attr, dns_exec_pkt, 
164
+				(void *)&exec_pkt_argv);
165
+		pthread_mutex_lock(&dns_exec_lock);
166
+		pthread_mutex_unlock(&dns_exec_lock);
167
+	}
168
+}
169
+
170
+void *dns_wrapper_thread(void *null)
171
+{
172
+	dns_wrapper_daemon(DNS_WRAPPER_PORT);
173
+	return 0;
174
+}

+ 50
- 0
src/dns_wrapper.h View File

@@ -0,0 +1,50 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#ifndef DNS_WRAPPER_H
20
+#define DNS_WRAPPER_H
21
+
22
+#define DNS_WRAPPER_PORT	53
23
+#define MAX_DNS_PKT_SZ		512
24
+#define MIN_PKT_SZ		7
25
+
26
+/* DNS wrapper resolver api */
27
+void resolver_process(const char *question, unsigned question_length, 
28
+		char *answer, unsigned *answer_length,
29
+		int (*callback)(const char *name, uint32_t *ip));
30
+
31
+/*
32
+ * dns_exec_pkt_argv is the struct passed to dns_exec_pkt() as argument 
33
+ */
34
+struct dns_exec_pkt_argv 
35
+{
36
+	char		*rpkt;	/* Received dns query pkt */
37
+	ssize_t		rpkt_sz;
38
+
39
+	int		sk;
40
+	struct sockaddr	from;
41
+	socklen_t	from_len;
42
+};
43
+
44
+pthread_mutex_t dns_exec_lock;
45
+
46
+/* * * Functions declarations * * */
47
+
48
+void *dns_wrapper_thread(void *null);
49
+
50
+#endif /*DNS_WRAPPER_H*/

+ 888
- 0
src/dnslib.c View File

@@ -0,0 +1,888 @@
1
+                 /**************************************
2
+                *     AUTHOR: Federico Tomassini        *
3
+               *     Copyright (C) Federico Tomassini    *
4
+              *     Contact effetom@gmail.com             *
5
+             ***********************************************
6
+             *******          BEGIN 3/2006          ********
7
+*************************************************************************
8
+*                                                                       *
9
+*  This program is free software; you can redistribute it and/or modify *
10
+*  it under the terms of the GNU General Public License as published by *
11
+*  the Free Software Foundation; either version 2 of the License, or    *
12
+*  (at your option) any later version.                                  *
13
+*                                                                       *
14
+*  This program is distributed in the hope that it will be useful,      *
15
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of       *
16
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
17
+*  GNU General Public License for more details.                         *
18
+*                                                                       *
19
+************************************************************************/
20
+#define _GNU_SOURCE
21
+#include <string.h>
22
+#include "dnslib.h"
23
+#include "err_errno.h"
24
+#include "log.h"
25
+#include "xmalloc.h"
26
+
27
+/*
28
+ * Takes a label: is there a ptr?
29
+ * Returns:
30
+ *      -1  is a malformed label is found
31
+ *       0  if there's no pointer
32
+ *      <offset from start_pkt> if a pointer is found
33
+ */
34
+int getlblptr(char *buf)
35
+{
36
+        uint16_t dlbl;
37
+        char c[2];
38
+
39
+        memcpy(c,buf,2);
40
+
41
+        if (!LBL_PTR(*c)) /* No ptr */ 
42
+		return 0;
43
+        if (LBL_PTR(*c)!=LBL_PTR_MASK) {
44
+		debug(DBG_INSANE,"In getlblptr: invalid octet %02x",(unsigned char)c[0]);
45
+                err_ret(ERR_DNSMLO,-1);
46
+	}
47
+        (*c)&=LBL_PTR_OFF_MASK;
48
+        memcpy(&dlbl,c,2);
49
+        dlbl=ntohs(dlbl);
50
+        return dlbl; /* offset */
51
+}
52
+/*
53
+ * Reads a contiguous octet-sequence-label.
54
+ * Writes on dst.
55
+ * There are two limits: 
56
+ * 	the name has to be less than MAX_SEQ_LBL_LEN
57
+ * 	we must stay in pkt_len
58
+ * -limit- is the less limit
59
+ * 
60
+ * Returns:
61
+ *      -1 On error
62
+ *      Bytes readed if OK
63
+ */
64
+int read_label_octet(const char *src,char *dst,int limit)
65
+{
66
+        int how;
67
+
68
+        how=*src++;
69
+	if ( how > limit || how > DNS_MAX_LABELS) {
70
+		error("In read_label_octet: got %d with limti %d\n",how,limit);
71
+		err_ret(ERR_DNSMSL,-1);
72
+	}
73
+	memcpy(dst,src,how);
74
+	return how;
75
+}
76
+/*
77
+ * Converts a dns compliant sequence label name to string.
78
+ * we start to read at -buf-
79
+ * we need start_pkt for pointers
80
+ * we need limit to remain under pktlen
81
+ * Returns:
82
+ *      Bytes readed if OK
83
+ *      -1 on error
84
+ */
85
+int lbltoname(char *buf,char *start_pkt,char *dst,int limit)
86
+{
87
+        char *crow;
88
+        int how,recursion=0;
89
+        int ptr;
90
+        int writed=0,readed=0;
91
+        int new_limit=limit;
92
+
93
+        crow=buf;
94
+
95
+        while (*crow) {
96
+                ptr=getlblptr(crow);
97
+                if (ptr) { /* Got a pointer.... or got an error*/
98
+                        if (ptr==-1) {
99
+                                debug(DBG_INSANE,err_str);
100
+                                err_ret(ERR_DNSMSL,-1);
101
+                        }
102
+                        if (++recursion>MAX_RECURSION_PTR) 
103
+                                err_ret(ERR_DNSTRP,-1);
104
+                        if (recursion==1) readed+=2; /* we read the pointer */
105
+                        crow=start_pkt+ptr;
106
+                        new_limit=limit - (int)(crow - buf);
107
+                        if (new_limit<=0 || new_limit > (int)(buf-start_pkt)+limit) 
108
+                                err_ret(ERR_DNSPLB,-1);
109
+                        if (getlblptr(crow)) 
110
+                                err_ret(ERR_DNSPTP,-1);
111
+                }
112
+                how=read_label_octet(crow,dst,min(new_limit,DNS_MAX_HNAME_LEN-writed));
113
+                if (how==-1) {
114
+			debug(DBG_INSANE,err_str);
115
+                        err_ret(ERR_DNSMSL,-1);
116
+		}
117
+                if (!recursion)
118
+                        readed+=how+1;
119
+                writed+=how+1;
120
+                dst+=how;
121
+                crow+=how+1;
122
+                *dst++=(*crow)?'.':0;
123
+        }
124
+        if (!recursion) readed++;
125
+        return readed;
126
+}
127
+/*
128
+ * DNS PTR query ask for 4.3.2.1.in-addr.arpa to know
129
+ * who is 1.2.3.4.
130
+ * This function reads this type of query transalting it
131
+ * in the second form.
132
+ * Writes result on *dst.
133
+ * -1 on error.
134
+ */
135
+
136
+int swap_straddr(char *src,char *dst)
137
+{
138
+        char a[3];
139
+        int i,slen;
140
+        char *crow,*tmp,*atom;
141
+        int count=0,offset=0;
142
+
143
+        slen=strlen(src);
144
+        if (slen>DNS_MAX_HNAME_LEN)
145
+                goto mlf_addr;
146
+        tmp=src;
147
+        for (i=0;i<4;i++) {
148
+                count=0;
149
+                atom=a;
150
+                while (*tmp && *tmp!='.') {
151
+                        if (count>2)
152
+                                goto mlf_addr;
153
+                        *atom++=*tmp++;
154
+                        count++;
155
+                }
156
+                if (!count)
157
+                        goto mlf_addr;
158
+                crow=dst+slen-count-offset;
159
+                strncpy(crow,a,count);
160
+                offset+=count;
161
+                if (!(*tmp))
162
+                        break;
163
+                else {
164
+                        if (i==3)
165
+                                goto mlf_addr;
166
+                        *(crow-1)='.';
167
+                        offset++;
168
+                        tmp++;
169
+                }
170
+
171
+        }
172
+        *(dst+slen)=0;
173
+        return 0;
174
+mlf_addr:
175
+        debug(DBG_INSANE,"in swap_straddr: invalid address `%s`.\n",src);
176
+	err_ret(ERR_DNSMDD,-1);
177
+}
178
+int swap_straddr6(char *src,char *dst)
179
+{
180
+        int slen;
181
+        char *tmp;
182
+        slen=strlen(src);
183
+        tmp=src+slen-1;
184
+        while (tmp!=src)
185
+                *dst++=*tmp--;
186
+        *dst++=*tmp;
187
+        *dst=0;
188
+        return 0;
189
+}
190
+int rm_inv_prefix(char *src,char *dst) 
191
+{
192
+	char *temp;
193
+	int ret;
194
+        if (!src) {
195
+                debug(DBG_INSANE,"In rm_inv_prefix: NULL argument!");
196
+                err_ret(ERR_DNSMDD,-1);
197
+        }
198
+        if( ! \
199
+          ( (temp=(char*)strcasestr(src,DNS_INV_PREFIX))  ||\
200
+            (temp=(char*)strcasestr(src,DNS_INV_PREFIX6)) ||\
201
+            (temp=(char*)strcasestr(src,OLD_DNS_INV_PREFIX6)))) {
202
+                debug(DBG_INSANE,"In rm_inv_prefix(): no suffix for PTR query.");
203
+                err_ret(ERR_DNSMDD,-1);
204
+        }
205
+	if (temp-src>=DNS_MAX_HNAME_LEN) {
206
+		error("In rm_inv_prefix(): name too long.");
207
+                err_ret(ERR_DNSMDD,-1);
208
+        }
209
+	ret=strstr(temp,"6")?AF_INET6:AF_INET;
210
+	strncpy(dst,src,temp-src);
211
+	dst[temp-src]=0;
212
+	return ret;
213
+}
214
+int add_inv_prefix(char *s,int family)
215
+{
216
+	int len;
217
+
218
+	len=strlen(s);
219
+	if (family==AF_INET) 
220
+		strcat(s,DNS_INV_PREFIX);
221
+	else
222
+		strcat(s,DNS_INV_PREFIX6);
223
+	return 0;
224
+}
225
+	
226
+int swapped_straddr(char *src,char *dst) 
227
+{
228
+	char temp[DNS_MAX_HNAME_LEN];
229
+	int res;
230
+
231
+	res=rm_inv_prefix(src,temp);
232
+	if (res==-1) {
233
+		error(err_str);
234
+		err_ret(ERR_DNSMDD,-1);
235
+	}
236
+	if (res==AF_INET)
237
+		res=swap_straddr(temp,dst);
238
+	else
239
+		res=swap_straddr6(temp,dst);
240
+	if (res==-1) {
241
+		error(err_str);
242
+		err_ret(ERR_DNSMDD,-1);
243
+	}
244
+	return 0;
245
+}
246
+int swapped_straddr_pref(char *src,char *dst,int family)
247
+{
248
+	int res;
249
+
250
+	if (family==AF_INET)
251
+		res=swap_straddr(src,dst);
252
+	else
253
+		res=swap_straddr6(src,dst);
254
+	if (res==-1) {
255
+		error(err_str);
256
+		err_ret(ERR_DNSMDD,-1);
257
+	}
258
+	add_inv_prefix(dst,family);
259
+	return 0;
260
+}
261
+
262
+/*
263
+ * Converts a domain_name_string into a sequence label format,
264
+ * dns compliant. Writes on dst.
265
+ * -1 on error, number of bytes writed on success
266
+ */
267
+int nametolbl(char *name,char *dst)
268
+{
269
+        char *crow;
270
+        int offset=0,res;
271
+
272
+	if (strlen(name)>DNS_MAX_HNAME_LEN) {
273
+		debug(DBG_INSANE,"Malformed name: %s.",name);
274
+		err_ret(ERR_DNSMDA,-1);
275
+	}
276
+        while ((crow=strstr(name+1,"."))) {
277
+                res=crow-name;
278
+                if (res>DNS_MAX_LABELS) {
279
+			debug(DBG_INSANE,"Malformed name: %s.",name);
280
+			err_ret(ERR_DNSMDA,-1);
281
+		}
282
+                *dst=(char)res; /* write the octet length */
283
+                dst++;
284
+                offset++;
285
+                memcpy(dst,name,(size_t)res); /* write label */
286
+                name+=res+1;dst+=res;offset+=res; /* shift ptrs */
287
+        }
288
+        if (!name) return offset;
289
+        if((res=(char)strlen(name))>DNS_MAX_LABELS) {
290
+                        debug(DBG_INSANE,"Malformed name: %s",name);
291
+                        err_ret(ERR_DNSMDA,-1);
292
+        }
293
+        *dst++=(char)res;
294
+        strcpy(dst,name);
295
+        offset+=res+2;
296
+        return offset;
297
+}
298
+/*
299
+ * Disassembles DNS packet headers, writing a yet allocated
300
+ * dns_pkt_hdr struct.
301
+ * No controls on len, bcz <<--the min_pkt_len is controlled
302
+ * by recv.-->>
303
+ * Returns the number of bytes readed (always DNS_HDR_SZ).
304
+ */
305
+int d_hdr_u(char *buf,dns_pkt_hdr *dph)
306
+{
307
+        uint8_t c;
308
+        uint16_t s;
309
+
310
+                // ROW 1
311
+        memcpy(&s,buf,sizeof(uint16_t));
312
+        dph->id=ntohs(s);
313
+                // ROW 2
314
+        buf+=2;
315
+        memcpy(&c,buf,sizeof(uint8_t));
316
+        dph->qr= (c>>7)&0x01;
317
+        dph->opcode=(c>>3)&0x0f;
318
+        dph->aa=(c>>2)&0x01;
319
+        dph->tc=(c>>1)&0x01;
320
+        dph->rd=c&0x01;
321
+
322
+        buf++;
323
+        memcpy(&c,buf,sizeof(uint8_t));
324
+        dph->ra=(c>>7)&0x01;
325
+        dph->z=(c>>4)&0x07;
326
+        dph->rcode=c&0x0f;
327
+
328
+                // ROW 3
329
+        buf++;
330
+        memcpy(&s,buf,sizeof(uint16_t));
331
+        dph->qdcount=ntohs(s);
332
+                // ROW 4
333
+        buf+=2;
334
+        memcpy(&s,buf,sizeof(uint16_t));
335
+        dph->ancount=ntohs(s);
336
+                // ROW 5
337
+        buf+=2;
338
+        memcpy(&s,buf,sizeof(uint16_t));
339
+        dph->nscount=ntohs(s);
340
+                // ROW 6
341
+        buf+=2;
342
+        memcpy(&s,buf,sizeof(uint16_t));
343
+        dph->arcount=ntohs(s);
344
+
345
+        buf+=2;
346
+        return DNS_HDR_SZ; // i.e. 12 :)
347
+}
348
+/*
349
+ * This function alloc a new dns_pkt_qst to store a dns_question_section.
350
+ * The new dns_pkt_qst is also added to the principal dp-struct
351
+ * Returns bytes readed if OK. -1 otherwise.
352
+ */
353
+int d_qst_u(char *start_buf,char *buf,dns_pkt *dp,int limit_len)
354
+{
355
+        int count;
356
+        uint16_t s;
357
+        dns_pkt_qst *dpq;
358
+
359
+        dpq=dns_add_qst(dp);
360
+
361
+        /* get name */
362
+        if((count=lbltoname(buf,start_buf,dpq->qname,limit_len))==-1) {
363
+                error(err_str);
364
+                err_ret(ERR_DNSMDD,1);
365
+        }
366
+        buf+=count;
367
+        /* Now we have to write 2+2 bytes */
368
+        if (count+4>limit_len)
369
+                err_ret(ERR_DNSPLB,1);
370
+
371
+        /* shift to type and class */
372
+        memcpy(&s,buf,2);
373
+        dpq->qtype=ntohs(s);
374
+        count+=2;
375
+        buf+=2;
376
+
377
+        memcpy(&s,buf,2);
378
+        dpq->qclass=ntohs(s);
379
+        count+=2;
380
+
381
+        return count;
382
+}
383
+
384
+/*
385
+ * Disassembles a DNS qst_section_set.
386
+ * Use the above function for each question section.
387
+ * -1 on error. Number of bytes readed on success.
388
+ *  If -1 is returned, rcode ha sto be set to E_INTRPRT
389
+ */
390
+int d_qsts_u(char *start_buf,char *buf,dns_pkt *dp,int limit_len)
391
+{
392
+        int offset=0,res;
393
+        int i,count;
394
+
395
+        if (!(count=DP_QDCOUNT(dp)))
396
+                return 0; /* No questions. */
397
+
398
+        for(i=0;i<count;i++) {
399
+                if ( (res=d_qst_u(start_buf,buf+offset,dp,limit_len-offset))==-1) {
400
+                        error(err_str);
401
+                        err_ret(ERR_DNSMDD,-1);
402
+                }
403
+                offset+=res;
404
+        }
405
+        return offset;
406
+}
407
+/*
408
+ * The behavior of this function is in all similar to dpkttoqst.
409
+ * Returns -1 on error. Bytes readed otherwise.
410
+ */
411
+int d_a_u(char *start_buf,char *buf,dns_pkt_a **dpa_orig,int limit_len)
412
+{
413
+        int count,rdlen;
414
+        dns_pkt_a *dpa;
415
+        uint16_t s;
416
+        uint32_t ui;
417
+
418
+        dpa=dns_add_a(dpa_orig);
419
+
420
+        /* get name */
421
+        if((count=lbltoname(buf,start_buf,dpa->name,limit_len))==-1) {
422
+                error(err_str);
423
+                err_ret(ERR_DNSMDD,-1);
424
+        }
425
+        buf+=count;
426
+        /* Now we have to write 2+2+4+2 bytes */
427
+        if (count+10>limit_len)
428
+                err_ret(ERR_DNSPLB,-1);
429
+
430
+        memcpy(&s,buf,2);
431
+        dpa->type=ntohs(s);
432
+        count+=2;
433
+        buf+=2;
434
+
435
+        memcpy(&s,buf,2);
436
+        dpa->cl=ntohs(s);
437
+        count+=2;
438
+        buf+=2;
439
+
440
+        memcpy(&ui,buf,4);
441
+        dpa->ttl=ntohl(ui);
442
+        count+=4;
443
+        buf+=4;
444
+
445
+        memcpy(&s,buf,2);
446
+        dpa->rdlength=ntohs(s);
447
+        count+=2;
448
+        buf+=2;
449
+
450
+        rdlen=dpa->rdlength;
451
+        if (rdlen>DNS_MAX_HNAME_LEN) 
452
+		err_ret(ERR_DNSMDD,-1);
453
+        /* Now we have to write dpa->rdlength bytes */
454
+        if (count+rdlen>limit_len)
455
+                err_ret(ERR_DNSPLB,-1);
456
+        if (dpa->type==T_A) {
457
+                memcpy(dpa->rdata,buf,rdlen); /* 32bit address */
458
+		count+=rdlen;
459
+	}
460
+        else if (dpa->type==T_MX) {
461
+		memcpy(dpa->rdata,buf,2);
462
+                if ((ui=lbltoname(buf+2,start_buf,dpa->rdata+2,rdlen-2))==-1) {
463
+                        error(err_str);
464
+                        err_ret(ERR_DNSMDD,-1);
465
+                }
466
+		if (rdlen!=ui+2) {
467
+			debug(DBG_NORMAL,"In d_a_u(): rdlen (%d) differs from readed bytes (%d).",rdlen,ui+2);
468
+			err_ret(ERR_DNSMDD,-1);
469
+		}
470
+		count+=2+ui;
471
+	} else {
472
+                if ((ui=lbltoname(buf,start_buf,dpa->rdata,rdlen))==-1) {
473
+                        error(err_str);
474
+                        err_intret(ERR_DNSMDD);
475
+                }
476
+		if (rdlen!=ui) {
477
+			debug(DBG_NORMAL,"In d_a_u(): rdlen (%d) differs from readed bytes (%d).",rdlen,ui);
478
+			err_ret(ERR_DNSMDD,-1);
479
+		}
480
+		count+=ui;
481
+	}
482
+        return count;
483
+}
484
+/*
485
+ * like d_qs_u. count is the number of section to read.
486
+ * -1 on error.  Bytes readed otherwise.
487
+ */
488
+int d_as_u(char *start_buf,char *buf,dns_pkt_a **dpa,int limit_len,int count)
489
+{
490
+        int offset=0,res;
491
+        int i;
492
+
493
+        if (!count) return 0;
494
+        for(i=0;i<count;i++) {
495
+                if ((res=d_a_u(start_buf,buf+offset,dpa,limit_len-offset))==-1) {
496
+                        error(err_str);
497
+                        err_intret(ERR_DNSMDD);
498
+                }
499
+                offset+=res;
500
+        }
501
+        return offset;
502
+}
503
+/*
504
+ * This is a main function: takes the pkt-buf and translate
505
+ * it in structured data.
506
+ * It cares about dns_pkt allocations.
507
+ *
508
+ * Returns:
509
+ * -1 on E_INTRPRT
510
+ *  0 if pkt must be discarded.
511
+ *  Number of bytes readed otherwise
512
+ */
513
+int d_u(char *buf,int pktlen,dns_pkt **dpp)
514
+{
515
+        dns_pkt *dp;
516
+        int offset=0,res;
517
+        char *crow;
518
+
519
+        crow=buf;
520
+        /* Controls pkt consistency: we must at least read pkt headers */
521
+        if (pktlen<DNS_HDR_SZ) 
522
+		err_ret(ERR_DNSMDP,0);
523
+        *dpp=dp=create_dns_pkt();
524
+
525
+        /* Writes headers */
526
+        offset+=d_hdr_u(buf,&(dp->pkt_hdr));
527
+        if (pktlen > DNS_MAX_SZ) /* If pkt is too long: the headers are written,
528
+                                  * so we can reply with E_INTRPRT
529
+				  */
530
+                err_intret(ERR_DNSPLB);
531
+        crow+=offset;
532
+        /* Writes qsts */
533
+	if (dp->pkt_hdr.qdcount) {
534
+	        if ((res=d_qsts_u(buf,crow,dp,pktlen-offset))==-1) {
535
+        	        error(err_str);
536
+                	err_intret(ERR_DNSMDP);
537
+        	}
538
+        	offset+=res;
539
+        	crow+=res;
540
+	}
541
+
542
+	if (dp->pkt_hdr.ancount) {
543
+	        if ((res=d_as_u(buf,crow,&(dp->pkt_answ),pktlen-offset,DP_ANCOUNT(dp)))==-1) {
544
+        	        error(err_str);
545
+                	err_intret(ERR_DNSMDP);
546
+	        }
547
+        	offset+=res;
548
+	}
549
+        /*crow+=res;
550
+        if ((res=dpkttoas(buf,crow,&(dp->pkt_auth),pktlen-offset,DP_NSCOUNT(dp)))==-1)
551
+                return -1;
552
+        offset+=res;
553
+        crow+=res;
554
+        if ((res=dpkttoas(buf,crow,&(dp->pkt_add),pktlen-offset,DP_ARCOUNT(dp)))==-1)
555
+                return -1;*/
556
+        return offset;
557
+}
558
+/*
559
+ * This function is the d_hdr_u inverse.
560
+ * Takes a dns_pkt struct and builds the
561
+ * header pkt-buffer
562
+ * Returns the number of bytes writed.
563
+ */
564
+int d_hdr_p(dns_pkt *dp,char *buf)
565
+{
566
+        char *crow=buf;
567
+        uint16_t u;
568
+        dns_pkt_hdr *dph;
569
+
570
+        dph=&(dp->pkt_hdr);
571
+        u=htons(dph->id);
572
+        memcpy(buf,&u,2);
573
+        buf+=2;
574
+
575
+        if (dph->qr) *buf|=0x80;
576
+        *buf|=dph->opcode<<3;
577
+        *buf|=dph->aa<<2;
578
+        *buf|=dph->tc<<1;
579
+        *buf|=dph->rd;
580
+
581
+        buf++;
582
+        *buf|=dph->ra<<7;
583
+        *buf|=dph->z<<4;
584
+        *buf|=dph->rcode;
585
+
586
+        buf++;
587
+
588
+        u=htons(dph->qdcount);
589
+        memcpy(buf,&u,2);
590
+        buf+=2;
591
+        u=htons(dph->ancount);
592
+        memcpy(buf,&u,2);
593
+        buf+=2;
594
+        u=htons(dph->nscount);
595
+        memcpy(buf,&u,2);
596
+        buf+=2;
597
+        u=htons(dph->arcount);
598
+        memcpy(buf,&u,2);
599
+        buf+=2;
600
+        return (int)(buf-crow);
601
+}
602
+/*
603
+ * Translate a struct dns_pkt_qst in the dns-buffer buf.
604
+ * Returns:
605
+ *      -1 On error
606
+ *      Bytes writed otherwise.
607
+ */
608
+int d_qst_p(dns_pkt_qst *dpq,char *buf, int limitlen)
609
+{
610
+        int offset;
611
+        uint16_t u;
612
+
613
+        if((offset=nametolbl(dpq->qname,buf))==-1) {
614
+                error(err_str);
615
+                err_ret(ERR_DNSMDA,-1);
616
+        }
617
+        if (offset+4>limitlen) 
618
+                err_ret(ERR_DNSPLB,-1);
619
+        buf+=offset;
620
+        u=htons(dpq->qtype);
621
+        memcpy(buf,&u,2);
622
+        buf+=2;offset+=2;
623
+        u=htons(dpq->qclass);
624
+        memcpy(buf,&u,2);
625
+        buf+=2;offset+=2;
626
+        return offset;
627
+}
628
+/*
629
+ * Translates the question sections of a struct dns_pkt
630
+ * into buf.
631
+ * Returns:
632
+ *      -1 on error.
633
+ *      Number of bytes writed otherwise,
634
+ */
635
+int d_qsts_p(dns_pkt *dp,char *buf,int limitlen)
636
+{
637
+        int offset=0,res;
638
+        int i;
639
+        dns_pkt_qst *dpq;
640
+        dpq=dp->pkt_qst;
641
+
642
+        for (i=0;dpq && i<DP_QDCOUNT(dp);i++) {
643
+                if ((res=d_qst_p(dpq,buf+offset,limitlen-offset))==-1) {
644
+                        error(err_str);
645
+                        err_ret(ERR_DNSMDA,-1);
646
+                }
647
+                offset+=res;
648
+                dpq=dpq->next;
649
+        }
650
+        return offset;
651
+}
652
+int d_a_p(dns_pkt_a *dpa,char *buf,int limitlen)
653
+{
654
+        int offset,rdlen;
655
+        uint16_t u;
656
+        int i;
657
+
658
+        if((rdlen=nametolbl(dpa->name,buf))==-1)
659
+                return -1;
660
+        offset=rdlen;
661
+        if (offset+10>limitlen)
662
+                err_intret(ERR_DNSPLB);
663
+        buf+=offset;
664
+        u=htons(dpa->type);
665
+        memcpy(buf,&u,2);
666
+        buf+=2;offset+=2;
667
+        u=htons(dpa->cl);
668
+        memcpy(buf,&u,2);
669
+        buf+=2;offset+=2;
670
+        i=htonl(dpa->ttl);
671
+        memcpy(buf,&i,4);
672
+        buf+=4;offset+=4;
673
+
674
+        if (dpa->type==T_A) {
675
+                if (offset+dpa->rdlength>limitlen)
676
+                        err_intret(ERR_DNSPLB);
677
+                memcpy(buf+2,dpa->rdata,dpa->rdlength);
678
+                offset+=dpa->rdlength;
679
+        } else if (dpa->type==T_MX) {
680
+		memcpy(buf+2,dpa->rdata,2);
681
+                if ((rdlen=nametolbl(dpa->rdata+2,buf+4))==-1) {
682
+                        error(err_str);
683
+                        err_ret(ERR_DNSMDA,-1);
684
+                }
685
+                offset+=rdlen+2;
686
+                if (offset>limitlen)
687
+                        err_ret(ERR_DNSPLB,-1);
688
+                dpa->rdlength=rdlen+2;
689
+	} else {
690
+                if ((rdlen=nametolbl(dpa->rdata,buf+2))==-1) {
691
+                        error(err_str);
692
+                        err_ret(ERR_DNSMDA,-1);
693
+                }
694
+                offset+=rdlen;
695
+                if (offset>limitlen)
696
+                        err_ret(ERR_DNSPLB,-1);
697
+                dpa->rdlength=rdlen;
698
+        }
699
+        u=htons(dpa->rdlength);
700
+        memcpy(buf,&u,2);
701
+        offset+=2;
702
+        return offset;
703
+}
704
+int d_as_p(dns_pkt_a *dpa,char *buf,int limitlen,int count)
705
+{
706
+        int offset=0,res;
707
+        int i;
708
+        for (i=0;dpa && i<count;i++) {
709
+                if ((res=d_a_p(dpa,buf+offset,limitlen-offset))==-1) {
710
+                        error(err_str);
711
+                        err_ret(ERR_DNSMDA,-1);
712
+                }
713
+                offset+=res;
714
+                dpa=dpa->next;
715
+        }
716
+        return offset;
717
+}
718
+/*
719
+ * Transform a dns_pkt structure in char stream.
720
+ *
721
+ * Returns:
722
+ *      -1 on error
723
+ *      len(stream) if OK
724
+ *
725
+ * The stream has at least the header section writed.
726
+ * `buf' must be at least of DNS_MAX_SZ bytes.
727
+ *
728
+ * DANGER: This function realeses *ALWAYS* the dns_pkt *dp!!!!
729
+ */
730
+int d_p(dns_pkt *dp,char *buf)
731
+{
732
+        int offset,res;
733
+
734
+        memset(buf,0,DNS_MAX_SZ);
735
+
736
+        offset=d_hdr_p(dp,buf);
737
+        buf+=offset;
738
+        if((res=d_qsts_p(dp,buf,DNS_MAX_SZ-offset))==-1)
739
+                goto server_fail;
740
+        offset+=res;
741
+        buf+=res;
742
+        if ( (res=d_as_p(dp->pkt_answ,buf,DNS_MAX_SZ-offset,DP_ANCOUNT(dp)))==-1)
743
+                goto server_fail;
744
+        offset+=res;
745
+        /*buf+=res;
746
+        if ( (res=astodpkt(dp->pkt_auth,buf,DNS_MAX_SZ-offset,DP_NSCOUNT(dp)))==-1)
747
+                goto server_fail;
748
+        offset+=res;
749
+        buf+=res;*/
750
+        /*if ( (res=astodpkt(dp->pkt_add,buf,DNS_MAX_SZ-offset,DP_ARCOUNT(dp)))==-1)
751
+                goto server_fail;
752
+        offset+=res;*/
753
+        destroy_dns_pkt(dp);
754
+        return offset;
755
+server_fail:
756
+        error(err_str);
757
+        destroy_dns_pkt(dp);
758
+	err_ret(ERR_DNSPDS,-1);
759
+}
760
+
761
+
762
+/* Memory Functions */
763
+
764
+dns_pkt* create_dns_pkt(void)
765
+{
766
+        dns_pkt *dp;
767
+        dp=xmalloc(DNS_PKT_SZ);
768
+        memset(dp,0,DNS_PKT_SZ);
769
+        dp->pkt_qst=NULL;
770
+        dp->pkt_answ=NULL;
771
+        dp->pkt_add=NULL;
772
+        dp->pkt_auth=NULL;
773
+        return dp;
774
+}
775
+
776
+dns_pkt_qst* create_dns_pkt_qst(void)
777
+{
778
+        dns_pkt_qst *dpq;
779
+        dpq=xmalloc(DNS_PKT_QST_SZ);
780
+        dpq->next=NULL;
781
+        memset(dpq->qname,0,DNS_MAX_HNAME_LEN);
782
+        return dpq;
783
+}
784
+dns_pkt_a* create_dns_pkt_a(void)
785
+{
786
+        dns_pkt_a *dpa;
787
+        dpa=xmalloc(DNS_PKT_A_SZ);
788
+        memset(dpa->name,0,DNS_MAX_HNAME_LEN);
789
+        memset(dpa->rdata,0,DNS_MAX_HNAME_LEN);
790
+        dpa->next=NULL;
791
+        return dpa;
792
+}
793
+
794
+dns_pkt_qst* dns_add_qst(dns_pkt *dp)
795
+{
796
+        dns_pkt_qst *dpq,*temp;
797
+        dpq=create_dns_pkt_qst();
798
+        temp=dp->pkt_qst;
799
+        if (!temp) {
800
+                dp->pkt_qst=dpq;
801
+                return dpq;
802
+        }
803
+        while (temp->next) temp=temp->next;
804
+        temp->next=dpq;
805
+        return dpq;
806
+}
807
+void dns_del_last_qst(dns_pkt *dp)
808
+{
809
+        dns_pkt_qst *dpq=dp->pkt_qst;
810
+        if (!dpq) return;
811
+        if (!(dpq->next)){
812
+                xfree(dpq);
813
+                dp->pkt_qst=NULL;
814
+                return;
815
+        }
816
+        while ((dpq->next)->next);
817
+        xfree(dpq->next);
818
+        dpq->next=NULL;
819
+        return;
820
+}
821
+
822
+dns_pkt_a* dns_add_a(dns_pkt_a **dpa)
823
+{
824
+        dns_pkt_a *dpa_add,*a;
825
+        int count=0;
826
+
827
+        a=*dpa;
828
+        dpa_add=create_dns_pkt_a();
829
+        if (!a) {
830
+                (*dpa)=dpa_add;
831
+        }
832
+        else {
833
+                while (a->next) {
834
+                        a=a->next;
835
+                        count++;
836
+                }
837
+                a->next=dpa_add;
838
+        }
839
+        return dpa_add;
840
+}
841
+void dns_a_default_fill(dns_pkt *dp,dns_pkt_a *dpa)
842
+{
843
+	strcpy(dpa->name,dp->pkt_qst->qname);
844
+	dpa->cl=C_IN;
845
+	dpa->ttl=DNS_TTL;
846
+	dpa->type=dp->pkt_qst->qtype;
847
+}
848
+void destroy_dns_pkt(dns_pkt *dp)
849
+{
850
+        dns_pkt_a *dpa,*dpa_t;
851
+        dns_pkt_qst *dpq,*dpq_t;
852
+
853
+        if (dp->pkt_qst) {
854
+                dpq=dp->pkt_qst;
855
+                while (dpq) {
856
+                        dpq_t=dpq->next;
857
+                        xfree(dpq);
858
+                        dpq=dpq_t;
859
+                }
860
+        }
861
+        if (dp->pkt_answ) {
862
+                dpa=dp->pkt_answ;
863
+                while (dpa) {
864
+                        dpa_t=dpa->next;
865
+                        xfree(dpa);
866
+                        dpa=dpa_t;
867
+                }
868
+        }
869
+        if (dp->pkt_add) {
870
+                dpa=dp->pkt_add;
871
+                while (dpa) {
872
+                        dpa_t=dpa->next;
873
+                        xfree(dpa);
874
+                        dpa=dpa_t;
875
+                }
876
+        }
877
+        if (dp->pkt_auth) {
878
+                dpa=dp->pkt_auth;
879
+                while (dpa) {
880
+                        dpa_t=dpa->next;
881
+                        xfree(dpa);
882
+                        dpa=dpa_t;
883
+                }
884
+        }
885
+        xfree(dp);
886
+        return;
887
+}
888
+

+ 189
- 0
src/dnslib.h View File

@@ -0,0 +1,189 @@
1
+                 /**************************************
2
+                *     AUTHOR: Federico Tomassini        *
3
+               *     Copyright (C) Federico Tomassini    *
4
+              *     Contact effetom@gmail.com             *
5
+             ***********************************************
6
+             *******          BEGIN 3/2006          ********
7
+*************************************************************************
8
+*                                                                       *
9
+*  This program is free software; you can redistribute it and/or modify *
10
+*  it under the terms of the GNU General Public License as published by *
11
+*  the Free Software Foundation; either version 2 of the License, or    *
12
+*  (at your option) any later version.                                  *
13
+*                                                                       *
14
+*  This program is distributed in the hope that it will be useful,      *
15
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of       *
16
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
17
+*  GNU General Public License for more details.                         *
18
+*                                                                       *
19
+************************************************************************/
20
+#ifndef DNSLIB_H
21
+#define DNSLIB_H
22
+
23
+#include <string.h>
24
+#include <stdint.h>
25
+#include <sys/socket.h>
26
+#include <arpa/inet.h>
27
+
28
+#define LBL_PTR_MASK		0xC0                    /* Network byte order */
29
+#define LBL_PTR_OFF_MASK	0x3f                   /* N.b. order */
30
+#define LBL_PTR(c)		((c)&LBL_PTR_MASK)      /* AND whith 0xC000 */
31
+
32
+#define MAX_RECURSION_PTR	20
33
+
34
+/* PREFIXES FOR PTR QUERY */
35
+#define DNS_INV_PREFIX          ".IN-ADDR.ARPA"
36
+#define DNS_INV_PREFIX6         ".IP6.ARPA"
37
+#define OLD_DNS_INV_PREFIX6     ".IP6.INT" /* For backward compatibility */
38
+
39
+/* DNS QUERY-TYPE: others type will be discarded */
40
+
41
+#define T_AAAA  28      /* h->ip IPV6  */
42
+#define T_A     1       /* h->ip IPV4 */
43
+#define T_PTR   12      /* ip->h */
44
+#define T_MX    15      /* h->mx */
45
+/* RCODES */
46
+#define DNS_RCODE_NOERR     0       /* No error */
47
+#define DNS_RCODE_EINTRPRT  1       /* Intepret error */
48
+#define DNS_RCODE_ESRVFAIL  2       /* Server failure */
49
+#define DNS_RCODE_ENSDMN    3       /* No such domain */
50
+#define DNS_RCODE_ENIMPL    4       /* Not implemented */
51
+#define DNS_RCODE_ERFSD     5       /* Refused */
52
+
53
+/* INET CLASS */
54
+#define C_IN    1
55
+
56
+/* RFC */
57
+#define DNS_MAX_SZ		512
58
+#define DNS_HDR_SZ		12
59
+#define DNS_MAX_LABELS		63
60
+#define DNS_MAX_HNAME_LEN	255
61
+#define DNS_TTL 86400;
62
+
63
+#define min(x,y)		((x)<(y))?(x):(y)
64
+
65
+typedef struct dns_pkt_hdr {
66
+        uint16_t       id;
67
+        uint8_t        qr;
68
+        uint8_t        opcode;
69
+        uint8_t        aa;
70
+        uint8_t        tc;
71
+        uint8_t        rd;
72
+        uint8_t        ra;
73
+        uint8_t        z;
74
+        uint8_t        rcode;
75
+        uint8_t        qdcount;
76
+        uint8_t        ancount;
77
+        uint8_t        nscount;
78
+        uint8_t        arcount;
79
+} dns_pkt_hdr;
80
+#define DNS_PKT_HDR_SZ sizeof(dns_pkt_hdr)
81
+
82
+/* DNS_PKT_HDR MACROS */
83
+#define DP_QDCOUNT(dp)  ((dp)->pkt_hdr).qdcount
84
+#define DP_ANCOUNT(dp)  ((dp)->pkt_hdr).ancount
85
+#define DP_NSCOUNT(dp)  ((dp)->pkt_hdr).nscount
86
+#define DP_ARCOUNT(dp)  ((dp)->pkt_hdr).arcount
87
+
88
+
89
+struct dns_pkt_qst {
90
+        char                    qname[DNS_MAX_HNAME_LEN];
91
+        uint16_t                qtype;
92
+        uint16_t                qclass;
93
+        struct dns_pkt_qst      *next;
94
+};
95
+typedef struct dns_pkt_qst dns_pkt_qst;
96
+#define DNS_PKT_QST_SZ sizeof(dns_pkt_qst)
97
+
98
+struct dns_pkt_a
99
+{
100
+        char                    name[DNS_MAX_HNAME_LEN];
101
+        uint16_t                type;
102
+        uint16_t                cl;
103
+        uint32_t                ttl;
104
+        uint16_t                rdlength;
105
+        char                    rdata[DNS_MAX_HNAME_LEN];
106
+        struct dns_pkt_a        *next;
107
+};
108
+typedef struct dns_pkt_a dns_pkt_a;
109
+#define DNS_PKT_A_SZ sizeof(dns_pkt_a)
110
+
111
+typedef struct dns_pkt
112
+{
113
+        dns_pkt_hdr     pkt_hdr;
114
+        dns_pkt_qst     *pkt_qst;
115
+        dns_pkt_a       *pkt_answ;
116
+        dns_pkt_a       *pkt_auth;
117
+        dns_pkt_a       *pkt_add;
118
+} dns_pkt;
119
+#define DNS_PKT_SZ sizeof(dns_pkt)
120
+
121
+/* USER MACRO */
122
+#define DNS_GET_ID(dp)		(dp)->pkt_hdr.id
123
+#define DNS_GET_QR(dp)		(dp)->pkt_hdr.qr
124
+#define DNS_GET_OPCODE(dp)	(dp)->pkt_hdr.opcode
125
+#define DNS_GET_AA(dp)		(dp)->pkt_hdr.aa
126
+#define DNS_GET_TC(dp)		(dp)->pkt_hdr.tc
127
+#define DNS_GET_RD(dp)		(dp)->pkt_hdr.rd
128
+#define DNS_GET_RA(dp)		(dp)->pkt_hdr.ra
129
+#define DNS_GET_Z(dp)		(dp)->pkt_hdr.z
130
+#define DNS_GET_RCODE(dp)	(dp)->pkt_hdr.rcode
131
+#define DNS_GET_QDCOUNT(dp)	(dp)->pkt_hdr.qdcount
132
+#define DNS_GET_ANCOUNT(dp)	(dp)->pkt_hdr.ancount
133
+#define DNS_GET_NSCOUNT(dp)	(dp)->pkt_hdr.nscount
134
+#define DNS_GET_ARCOUNT(dp)	(dp)->pkt_hdr.arcount
135
+
136
+#define DNS_SET_ID(dp,x)	(dp)->pkt_hdr.id=x
137
+#define DNS_SET_QR(dp,x)	(dp)->pkt_hdr.qr=x
138
+#define DNS_SET_OPCODE(dp,x)	(dp)->pkt_hdr.opcode=x
139
+#define DNS_SET_AA(dp,x)	(dp)->pkt_hdr.aa=x
140
+#define DNS_SET_TC(dp,x)	(dp)->pkt_hdr.tc=x
141
+#define DNS_SET_RD(dp,x)	(dp)->pkt_hdr.rd=x
142
+#define DNS_SET_RA(dp,x)	(dp)->pkt_hdr.ra=x
143
+#define DNS_SET_Z(dp,x)		(dp)->pkt_hdr.z=x
144
+#define DNS_SET_RCODE(dp,x)	(dp)->pkt_hdr.rcode=x
145
+#define DNS_SET_QDCOUNT(dp,x)	(dp)->pkt_hdr.qdcount=x
146
+#define DNS_SET_ANCOUNT(dp,x)	(dp)->pkt_hdr.ancount=x
147
+#define DNS_SET_NSCOUNT(dp,x)	(dp)->pkt_hdr.nscount=x
148
+#define DNS_SET_ARCOUNT(dp,x)	(dp)->pkt_hdr.arcount=x
149
+
150
+#define DP_ADD_ANSWER(dp)       dns_add_a(&((dp)->pkt_answ));DP_ANCOUNT(dp)+=1;	
151
+#define DP_ADD_AUTH(dp)         dns_add_a(&((dp)->pkt_auth));DP_NSCOUNT(dp)+=1;	
152
+#define DP_ADD_ADD(dp)          dns_add_a(&((dp)->pkt_add));DP_ARCOUNT(dp)+=1;	
153
+
154
+
155
+	/* Functions */
156
+int getlblptr(char *buf);
157
+int read_label_octet(const char *src,char *dst,int limit);
158
+int lbltoname(char *buf,char *start_pkt,char *dst,int limit);
159
+int swap_straddr(char *src,char *dst);
160
+int swap_straddr6(char *src,char *dst);
161
+int rm_inv_prefix(char *src,char *dst) ;
162
+int add_inv_prefix(char *s,int family);
163
+int swapped_straddr(char *src,char *dst) ;
164
+int swapped_straddr_pref(char *src,char *dst,int family);
165
+int nametolbl(char *name,char *dst);
166
+int d_hdr_u(char *buf,dns_pkt_hdr *dph);
167
+int d_qst_u(char *start_buf,char *buf,dns_pkt *dp,int limit_len);
168
+int d_qsts_u(char *start_buf,char *buf,dns_pkt *dp,int limit_len);
169
+int d_a_u(char *start_buf,char *buf,dns_pkt_a **dpa_orig,int limit_len);
170
+int d_as_u(char *start_buf,char *buf,dns_pkt_a **dpa,int limit_len,int count);
171
+int d_u(char *buf,int pktlen,dns_pkt **dpp);
172
+int d_hdr_p(dns_pkt *dp,char *buf);
173
+int d_qst_p(dns_pkt_qst *dpq,char *buf, int limitlen);
174
+int d_qsts_p(dns_pkt *dp,char *buf,int limitlen);
175
+int d_a_p(dns_pkt_a *dpa,char *buf,int limitlen);
176
+int d_as_p(dns_pkt_a *dpa,char *buf,int limitlen,int count);
177
+int d_p(dns_pkt *dp,char *buf);
178
+dns_pkt* create_dns_pkt(void);
179
+dns_pkt_qst* create_dns_pkt_qst(void);
180
+dns_pkt_a* create_dns_pkt_a(void);
181
+dns_pkt_qst* dns_add_qst(dns_pkt *dp);
182
+void dns_del_last_qst(dns_pkt *dp);
183
+dns_pkt_a* dns_add_a(dns_pkt_a **dpa);
184
+void dns_a_default_fill(dns_pkt *dp,dns_pkt_a *dpa);
185
+void destroy_dns_pkt(dns_pkt *dp);
186
+
187
+
188
+#endif /* DNSLIB_H */
189
+

+ 219
- 0
src/endianness.c View File

@@ -0,0 +1,219 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ *
18
+ * --
19
+ * endian.c:
20
+ * stuff to handle endianess mischief.
21
+ */
22
+
23
+#include "includes.h"
24
+
25
+#include "common.h"
26
+#include "log.h"
27
+#include "endianness.h"
28
+
29
+#ifdef DEBUG
30
+
31
+/* Call fatal if `i' is equal to IINFO_DYNAMIC_VALUE.
32
+ * Note: this is needed only for debugging purpose */
33
+#define IS_DYNAMIC(i) 							\
34
+({									\
35
+	if((i) == IINFO_DYNAMIC_VALUE)					\
36
+	  fatal("%s:%d: IINFO_DYNAMIC_VALUE encountered", ERROR_POS);	\
37
+})
38
+
39
+#else
40
+
41
+#define IS_DYNAMIC(i) ({do_nothing();})
42
+
43
+#endif	/*DEBUG*/
44
+
45
+void *int_info_copy(int_info *dst, const int_info *src)
46
+{
47
+	return memcpy(dst, src, sizeof(int_info));
48
+}
49
+		
50
+void ints_array_ntohl(int *hostlong, int nmemb)
51
+{
52
+#if BYTE_ORDER == LITTLE_ENDIAN
53
+	int i;
54
+	
55
+	for(i=0; i<nmemb; i++)
56
+		hostlong[i]=ntohl(hostlong[i]);
57
+#endif
58
+}
59
+
60
+void ints_array_htonl(int *netlong, int nmemb)
61
+{
62
+#if BYTE_ORDER == LITTLE_ENDIAN
63
+	int i;
64
+	
65
+	for(i=0; i<nmemb; i++)
66
+		netlong[i]=htonl(netlong[i]);
67
+#endif
68
+}
69
+
70
+void ints_array_ntohs(short *hostshort, int nmemb)
71
+{
72
+#if BYTE_ORDER == LITTLE_ENDIAN
73
+	int i;
74
+	
75
+	for(i=0; i<nmemb; i++)
76
+		hostshort[i]=ntohs(hostshort[i]);
77
+#endif
78
+}
79
+
80
+void ints_array_htons(short *netshort, int nmemb)
81
+{
82
+#if BYTE_ORDER == LITTLE_ENDIAN
83
+	int i;
84
+	
85
+	for(i=0; i<nmemb; i++)
86
+		netshort[i]=htons(netshort[i]);
87
+#endif
88
+}
89
+
90
+
91
+/*
92
+ * ints_network_to_host: converts all the int/short variables present in the
93
+ * struct `s' from network order to host order. The `s' struct must be
94
+ * described in the `iinfo' struct.
95
+ */
96
+void ints_network_to_host(void *s, int_info iinfo)
97
+{
98
+#if BYTE_ORDER == LITTLE_ENDIAN
99
+
100
+	int i;
101
+	char *p;
102
+
103
+	IS_DYNAMIC(iinfo.total_ints);
104
+	
105
+	for(i=0; i < iinfo.total_ints; i++) {
106
+		if(!iinfo.int_type[i])
107
+			continue;
108
+
109
+		IS_DYNAMIC(iinfo.int_offset[i]);
110
+		
111
+		p=(char *)s + iinfo.int_offset[i];
112
+		
113
+		IS_DYNAMIC(iinfo.int_nmemb[i]);
114
+		IS_DYNAMIC(iinfo.int_type[i]);
115
+
116
+		/* 
117
+		 * Swap the entire array if it is a single integer and if we 
118
+		 * are on a little endian machine.
119
+		 */
120
+		if(iinfo.int_type[i] & INT_TYPE_WORDS) {
121
+			
122
+			if(iinfo.int_type[i] & INT_TYPE_32BIT)
123
+				swap_ints(iinfo.int_nmemb[i], (u_int *)p,
124
+						(u_int *)p);
125
+			else
126
+				swap_shorts(iinfo.int_nmemb[i], (u_short *)p,
127
+						(u_short *)p);
128
+		}
129
+		
130
+		if(iinfo.int_type[i] & INT_TYPE_32BIT)
131
+			ints_array_ntohl((int *)p, iinfo.int_nmemb[i]);
132
+		else
133
+			ints_array_ntohs((short *)p, iinfo.int_nmemb[i]);
134
+	}
135
+#endif
136
+}
137
+
138
+/*
139
+ * ints_host_to_network: converts all the int/short variables present in the
140
+ * struct `s' from host order to network order. The `s' struct must be
141
+ * described in the `iinfo' struct.
142
+ */
143
+void ints_host_to_network(void *s, int_info iinfo)
144
+{
145
+#if BYTE_ORDER == LITTLE_ENDIAN
146
+	int i;
147
+	char *p;
148
+
149
+	IS_DYNAMIC(iinfo.total_ints);
150
+
151
+	for(i=0; i < iinfo.total_ints; i++) {
152
+		if(!iinfo.int_type[i])
153
+			continue;
154
+
155
+		IS_DYNAMIC(iinfo.int_offset[i]);
156
+
157
+		p=(char *)s + iinfo.int_offset[i];
158
+		
159
+		IS_DYNAMIC(iinfo.int_nmemb[i]);
160
+		IS_DYNAMIC(iinfo.int_type[i]);
161
+
162
+		/* 
163
+		 * Swap the entire array if it is a single integer and if we 
164
+		 * are on a little endian machine.
165
+		 */
166
+		if(iinfo.int_type[i] & INT_TYPE_WORDS) {
167
+			
168
+			if(iinfo.int_type[i] & INT_TYPE_32BIT)
169
+				swap_ints(iinfo.int_nmemb[i], (u_int *)p, (u_int *)p);
170
+			else
171
+				swap_shorts(iinfo.int_nmemb[i], (u_short *)p, (u_short *)p);
172
+		}
173
+
174
+		if(iinfo.int_type[i] & INT_TYPE_32BIT)
175
+			ints_array_htonl((int *)p, iinfo.int_nmemb[i]);
176
+		else
177
+			ints_array_htons((short *)p, iinfo.int_nmemb[i]);
178
+	}
179
+#endif
180
+}
181
+
182
+/*
183
+ * ints_printf: prints all the int/short vars present in the `s' struct
184
+ * described by `iinfo'. It uses `print_func' as the the printing function
185
+ */
186
+void ints_printf(void *s, int_info iinfo, void(*print_func(const char *, ...)))
187
+{
188
+	int i, e, *i32;
189
+	short *i16;
190
+	char *p;
191
+
192
+	IS_DYNAMIC(iinfo.total_ints);
193
+
194
+	for(i=0; i < iinfo.total_ints; i++) {
195
+		if(!iinfo.int_type[i])
196
+			continue;
197
+
198
+		IS_DYNAMIC(iinfo.int_offset[i]);
199
+
200
+		p=(char *)s + iinfo.int_offset[i];
201
+		
202
+		IS_DYNAMIC(iinfo.int_nmemb[i]);
203
+		IS_DYNAMIC(iinfo.int_type[i]);
204
+
205
+		for(e=0; e < iinfo.int_nmemb[i]; e++) {
206
+
207
+			print_func("ints_printf: offset %d, nmemb %d, ", 
208
+					iinfo.int_offset[i], e);
209
+			
210
+			if(iinfo.int_type[i] & INT_TYPE_32BIT) {
211
+				i32  = (int *)(p + (sizeof(int) * e));
212
+				print_func("32bit value %d\n", *i32);
213
+			} else {
214
+				i16  = (short *)(p + (sizeof(short) * e));
215
+				print_func("16bit value %d\n", *i16);
216
+			}
217
+		}
218
+	}
219
+}

+ 109
- 0
src/endianness.h View File

@@ -0,0 +1,109 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2005 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#ifndef ENDIANNESS_H
20
+#define ENDIANNESS_H
21
+
22
+#define MAX_INTS_PER_STRUCT	8		/* The maximum number of short/int variables 
23
+						   present in a struct */
24
+
25
+#define IINFO_DYNAMIC_VALUE	-1		/* This define is used to fill part in a 
26
+						   int_info struct that must be set each time. 
27
+						   If that part is not set, -1 will remain, and
28
+						   the int_info functions will call fatal(). 
29
+						   Therefore this is useful to track bugs. */
30
+
31
+
32
+/* flags for int_info.int_type */
33
+#define INT_TYPE_VOID		0		/* Emptiness is loneliness, and loneliness is 
34
+						   cleanliness */
35
+#define INT_TYPE_32BIT		1		/* The int var is of 32 bits */
36
+#define INT_TYPE_16BIT		(1<<1)		/* The int var is of 16 bits */
37
+#define INT_TYPE_WORDS		(1<<2)		/* The int var is composed by an array of ints,
38
+						   like the ipv6 ip (struct in6_addr) */
39
+#define INT_TYPE_NETWORK 	(1<<3)		/* The int var is stored in network order */
40
+
41
+/*
42
+ * int_info: this struct is used to keep the information about the int/short
43
+ * variables present in a struct. It is useful to convert all the int/short
44
+ * vars in another endian format with a simple function. 
45
+ * WARNING: There is a drawback: the struct must have the __packed__
46
+ * attribute (but since we are using this for packet structs we don't care).
47
+ *
48
+ * Here there is an example which show how to use this int_info:
49
+ * 	
50
+ * given the struct s:
51
+ *	struct 
52
+ *	{
53
+ *		u_char a;
54
+ *		int b;
55
+ *		short c;
56
+ *		char d[23];
57
+ *		int e[4];
58
+ *	}__attribute__ ((__packed__)) s;
59
+ *
60
+ * its int_info struct should be filled in this way:
61
+ * 
62
+ * int_info s_int_info = { 3,
63
+ *  			   {INT_TYPE_32BIT, INT_TYPE_16BIT, INT_TYPE_32BIT}, 
64
+ *			   { sizeof(char), sizeof(char)+sizeof(int), 
65
+ *			   	sizeof(char)+sizeof(int)+sizeof(short)+sizeof(char)*23},
66
+ *		           { 1, 1, 4 }
67
+ *			 };
68
+ */
69
+typedef struct
70
+{
71
+	/* The total int/short vars present in the struct */
72
+	int 	total_ints;				
73
+
74
+	/* Each member in the int_type array corresponds to a int/short var
75
+	 * and it is set using the above INT_TYPE_ flags */
76
+	char 	int_type[MAX_INTS_PER_STRUCT];
77
+
78
+	/* Each member in the int_offset array specifies the amount of bytes
79
+	 * to be added at the end of the struct to get the relative int/short
80
+	 * var. */
81
+	size_t	int_offset[MAX_INTS_PER_STRUCT];
82
+
83
+	/* int_nmemb[x] is equal to the number of consecutive ints/shorts var,
84
+	 * which start at the int_offset[x] offset. */
85
+	size_t	int_nmemb[MAX_INTS_PER_STRUCT];
86
+
87
+} int_info;
88
+
89
+/* Useful to declare constant static int_info structs in .h files */
90
+#define INT_INFO const static int_info
91
+
92
+#if BYTE_ORDER == LITTLE_ENDIAN
93
+#include <linux/byteorder/little_endian.h>
94
+#else
95
+#include <linux/byteorder/big_endian.h>
96
+#endif
97
+
98
+
99
+/* * * Functions declaration * * */
100
+void *int_info_copy(int_info *dst, const int_info *src);
101
+void ints_array_htons(short *netshort, int nmemb);
102
+void ints_array_ntohs(short *hostshort, int nmemb);
103
+void ints_array_htonl(int *netlong, int nmemb);
104
+void ints_array_ntohl(int *hostlong, int nmemb);
105
+void ints_network_to_host(void *s, int_info iinfo);
106
+void ints_host_to_network(void *s, int_info iinfo);
107
+void ints_printf(void *s, int_info iinfo, void(*print_func(const char *, ...)));
108
+
109
+#endif /*ENDIANNESS_H*/

+ 69
- 0
src/err_errno.c View File

@@ -0,0 +1,69 @@
1
+                 /**************************************
2
+                *     AUTHOR: Federico Tomassini        *
3
+               *     Copyright (C) Federico Tomassini    *
4
+              *     Contact effetom@gmail.com             *
5
+             ***********************************************
6
+               *****                                ******
7
+*************************************************************************
8
+*                                                                       *
9
+*  This program is free software; you can redistribute it and/or modify *
10
+*  it under the terms of the GNU General Public License as published by *
11
+*  the Free Software Foundation; either version 2 of the License, or    *
12
+*  (at your option) any later version.                                  *
13
+*                                                                       *
14
+*  This program is distributed in the hope that it will be useful,      *
15
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of       *
16
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
17
+*  GNU General Public License for more details.                         *
18
+*                                                                       *
19
+************************************************************************/
20
+
21
+#include "err_errno.h"
22
+
23
+static const char *err_strings[] = {
24
+	"UFO error -o-",			/* ERR_UFOERR */
25
+	"Malformed Label Octet.",		/* ERR_DNSMLO */
26
+	"Malformed Sequence Label.",		/* ERR_DNSMSL */
27
+	"Malformed Dns Packet.",		/* ERR_DNSMDP */
28
+	"Malformed Dns Data.",			/* ERR_DNSMDD */
29
+	"Too many Recursive Pointers.",		/* ERR_DNSTRP */
30
+	"Dns Packet Len Break.",		/* ERR_DNSPLB */
31
+	"Pointer To Pointer error.",		/* ERR_DNSPTP */
32
+	"Malformed Data.",			/* ERR_DNSMDA */
33
+	"Error Packing Dns Struct.",		/* ERR_DNSPDS */
34
+/**/	
35
+	"Malformed Andna Packet.",		/* ERR_ANDMAP */
36
+	"Andns Packet Len Break.",		/* ERR_ANDPLB */
37
+	"Malformed Andns Data.",		/* ERR_ANDMAD */
38
+	"Andna Not Compatbile Query.", 		/* ERR_ANDNCQ */
39
+/**/
40
+	"Error reading resolv.conf.",		/* ERR_RSLERC */
41
+	"Andns init error.",			/* ERR_RSLAIE */
42
+	"There isn't No NameServer.",		/* ERR_RSLNNS */
43
+	"Error Forwarding DNS Query.",		/* ERR_RSLFDQ */
44
+	"Resolution Error.",			/* ERR_RSLRSL */
45
+	"Andns Query Discarded.", 		/* ERR_RSLAQD */
46
+/**/
47
+	"mark_init error!.",			/* ERR_NETINI */
48
+	"netfilter table not loadable.",	/* ERR_NETFIL */
49
+	"error adding netfilter rules.",	/* ERR_NETRUL */
50
+	"error committing netfilter rules.",	/* ERR_NETCOM */
51
+	"error initializing ntk_mark_chain.",	/* ERR_NETCHA */
52
+	"netfilter delete error.",		/* ERR_NETDEL */
53
+	"error storing rules.",			/* ERR_NETSTO */
54
+	"Nefilter was not restored.",		/* ERR_NETRST */
55
+/**/	
56
+	"SNSD main record not found.",		/* ERR_SNDMRF */
57
+	"SNSD recursion failed.",		/* ERR_SNDRCS */
58
+/**/	
59
+	"Zlib Compression Fail.",		/* ERR_ZLIBCP */
60
+	"Zlib Uncompression Fail.",		/* ERR_ZLIBUP */
61
+	"Zlib compression is useless.",		/* ERR_ZLIBNU */
62
+};
63
+
64
+const char *__err_strerror(int n)
65
+{
66
+        int __n=-((n)+1);
67
+
68
+	return (__n>=ERR_NERR || __n<0) ? ERR_OVERFLOW : err_strings[__n];
69
+}

+ 95
- 0
src/err_errno.h View File

@@ -0,0 +1,95 @@
1
+                 /**************************************
2
+                *     AUTHOR: Federico Tomassini        *
3
+               *     Copyright (C) Federico Tomassini    *
4
+              *     Contact effetom@gmail.com             *
5
+             ***********************************************
6
+               *****                                ******
7
+*************************************************************************
8
+*                                                                       *
9
+*  This program is free software; you can redistribute it and/or modify *
10
+*  it under the terms of the GNU General Public License as published by *
11
+*  the Free Software Foundation; either version 2 of the License, or    *
12
+*  (at your option) any later version.                                  *
13
+*                                                                       *
14
+*  This program is distributed in the hope that it will be useful,      *
15
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of       *
16
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
17
+*  GNU General Public License for more details.                         *
18
+*                                                                       *
19
+************************************************************************/
20
+
21
+
22
+#ifndef ERR_ERRNO_H
23
+#define ERR_ERRNO_H
24
+
25
+#include <errno.h>
26
+#include <string.h>
27
+#include <stdlib.h>
28
+
29
+#define ERR_UFOERR	-1
30
+#define ERR_DNSMLO	-2
31
+#define ERR_DNSMSL	-3
32
+#define	ERR_DNSMDP	-4
33
+#define ERR_DNSMDD	-5
34
+#define ERR_DNSTRP	-6
35
+#define ERR_DNSPLB	-7
36
+#define ERR_DNSPTP	-8
37
+#define ERR_DNSMDA	-9
38
+#define ERR_DNSPDS	-10
39
+
40
+#define ERR_ANDMAP	-11
41
+#define ERR_ANDPLB	-12
42
+#define ERR_ANDMAD	-13
43
+#define ERR_ANDNCQ	-14
44
+
45
+#define ERR_RSLERC	-15
46
+#define ERR_RSLAIE	-16
47
+#define ERR_RSLNNS	-17
48
+#define ERR_RSLFDQ	-18
49
+#define ERR_RSLRSL	-19
50
+#define ERR_RSLAQD	-20
51
+
52
+#define ERR_MRKINI	-21
53
+#define ERR_NETFIL	-22
54
+#define ERR_NETRUL	-23
55
+#define ERR_NETCOM	-24
56
+#define ERR_NETCHA	-25
57
+#define ERR_NETDEL	-26
58
+#define ERR_NETSTO	-27
59
+#define ERR_NETRST	-28
60
+
61
+#define ERR_SNDMRF	-29
62
+#define ERR_SNDRCS	-30
63
+
64
+#define ERR_ZLIBCP	-31
65
+#define ERR_ZLIBUP	-32
66
+#define ERR_ZLIBNU	-33
67
+
68
+#define ERR_TOTAL_ERRS	(-(ERR_ZLIBNU))
69
+#define ERR_OVERFLOW    "Error number does not exist."
70
+
71
+        /* END OF DEFS */
72
+
73
+
74
+ /*
75
+  * Core
76
+  */
77
+const char *err_func,*err_file;
78
+#define ERR_NERR                (ERR_TOTAL_ERRS)
79
+#define err_seterrno(n)         errno=(n);err_func=__func__;	\
80
+                                err_file=__FILE__
81
+#define err_ret(n,ret)		{err_seterrno(n);return ret;}
82
+#define err_intret(n)           {err_seterrno(n);return -1;}
83
+#define err_voidret(n)          {err_seterrno(n);return NULL;}
84
+#define err_strerror(e)                                         \
85
+        ((e)>=0)?                                               \
86
+                strerror(e):                                    \
87
+                __err_strerror(e)
88
+#define ERR_FORMAT      "In %s(): %s() returns -> %s"
89
+#define err_str         ERR_FORMAT,__func__,                    \
90
+                        err_func,__err_strerror(errno)
91
+
92
+
93
+const char *__err_strerror(int n);
94
+
95
+#endif /* ERR_ERRNO_H */

+ 1493
- 0
src/gmap.c
File diff suppressed because it is too large
View File


+ 270
- 0
src/gmap.h View File

@@ -0,0 +1,270 @@
1
+/* This file is part of Netsukuku
2
+ * (c) Copyright 2004 Andrea Lo Pumo aka AlpT <alpt@freaknet.org>
3
+ *
4
+ * This source code is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as published 
6
+ * by the Free Software Foundation; either version 2 of the License,
7
+ * or (at your option) any later version.
8
+ *
9
+ * This source code is distributed in the hope that it will be useful,
10
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
+ * Please refer to the GNU Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU Public License along with
15
+ * this source code; if not, write to:
16
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#ifndef GMAP_H
20
+#define GMAP_H
21
+
22
+#include "llist.c"
23
+#include "map.h"
24
+
25
+/* * * Groupnode stuff * * */
26
+#define GMAP_ME		MAP_ME		/*1*/
27
+#define GMAP_VOID	MAP_VOID	/*(1<<1)*/
28
+#define GMAP_HGNODE	(1<<2)		/*Hooked Gnode. We already hooked at 
29
+					  this gnode */
30
+#define GMAP_FULL	(1<<3)		/*The gnode is full!! aaahh, run away!*/
31
+
32
+/* This is the holy external_map. Each struct corresponds to a groupnode. 
33
+ * This groupnode cointains MAXGROUPNODE nodes if we are at level 1 or 
34
+ * MAXGROUPNODE groups. The map is equal to the int_map, in fact, a map_node
35
+ * is embedded in a map_gnode. 
36
+ * This int_map uses the QSPN_MAP_STYLEII (see qspn.h). */
37
+typedef struct
38
+{
39
+	/* 
40
+	 * The gnode_map starts here. Note that it is a normal map. (See map.h). 
41
+	 * It is here, at the top of the struct to allow to manipulate a map_gnode
42
+	 * as a map_node with the help of the magic cast. The cast is heavily 
43
+	 * used in qspn.c
44
+	 */
45
+	map_node	g;
46
+	
47
+	u_char 		flags;
48
+	u_char		seeds;	/*The number of active static nodes connected to this
49
+				  gnode minus one (the root_node is not counted).
50
+				  If seeds == MAXGROUPNODE-1, the gnode is full ^_^*/
51
+	u_int		gcount;	/*The total number of nodes which are inside this 
52
+				  gnode*/
53
+} map_gnode;
54
+
55
+INT_INFO map_gnode_iinfo = { 1, 
56
+			     { INT_TYPE_32BIT }, 
57
+			     { MAP_NODE_PACK_SZ+sizeof(u_char)*2 }, 
58
+			     { 1 }
59
+			   };
60
+#define MAP_GNODE_PACK_SZ	(MAP_NODE_PACK_SZ+sizeof(u_char)*2+sizeof(int))
61
+
62
+
63
+/*
64
+ * 			* * * Levels notes * * *
65
+ * 			
66
+ * These are the levels of the external_map. Note that the 0 level is never used 
67
+ * for the ext_map because it corresponds to the internal map. Btw the 0 level is 
68
+ * counted so the number of LEVELS includes it too. 
69
+ * But we have to add another extra level: the last exiled level. It is also never 
70
+ * used but it is vital, cause, its gnode 0 includes the entire Netsukuku, the other
71
+ * gnodes aren't used, it is a mere symbol. We call it the unity level.
72
+ *
73
+ * All the structs/arrays related to the external map, and the ext_map itself, don't
74
+ * use the EXTRA_LEVELS, thus, they lack of the zero level. To retrieve the position 
75
+ * in the array from the level the _EL macro must be used. In other words: 
76
+ * because the arrays goes from 0 to n-1 we refer to the levels as the arrays,
77
+ * so the level 1 is the level 0, the level 2 is the level 1, and so on.
78
+ * These arrays/structs are: quadg.gnode, rblock, ext_map, qspn_gnode_count.
79
+ */
80
+#define ZERO_LEVEL	1
81
+#define UNITY_LEVEL	1
82
+#define EXTRA_LEVELS	(ZERO_LEVEL + UNITY_LEVEL)
83
+/* To use the right level. */
84
+#define _EL(level)    ((level)-1)
85
+/* And to restore it. */
86
+#define _NL(level)    ((level)+1)
87
+
88
+/* 
89
+ * Using MAXGROUPNODE = 2^8; IPV4_LEVELS = 3; ips = 2^32;
90
+ * 	ips/(MAXGROUPNODE^IPV4_LEVELS) == 256;
91
+ * If we use IPV4_LEVELS = 3, we almost cover all the ips, but the division gives
92
+ * 256. So there are only 256 groups in the last level (3), in fact:
93
+ *      ips/(256 * (MAXGROUPNODE^3)) == 1
94
+ * And to include them we use the unity level, thus IPV4_LEVELS is equal to 3+1.
95
+ * This means that the unity level is the one which has only one group node which includes
96
+ * the entire network.
97
+ * Sadly we cannot use all this ips, because there are the banned classes (MULTICAST,
98
+ * ZERONET), the kernel will sput on us.
99
+ * 
100
+ * For the ipv6 we have IPV6_LEVELS = 16, ips = 2^128; so:
101
+ *      ips/(MAXGROUPNODE^16) == 1
102
+ */
103
+#define IPV4_LEVELS		(2+EXTRA_LEVELS)
104
+
105
+#define IPV6_LEVELS		(14+EXTRA_LEVELS)
106
+
107
+#define MAX_LEVELS		IPV6_LEVELS
108
+#ifdef DEBUG
109
+#define GET_LEVELS(family)						\
110
+({ 									\
111
+	if((family) != AF_INET && (family) != AF_INET6)			\
112
+		fatal("GET_LEVELS: family not specified!");		\
113
+	(family) == AF_INET ? IPV4_LEVELS : IPV6_LEVELS;		\
114
+ })
115
+#else
116
+#define GET_LEVELS(family) ({ (family)==AF_INET ? IPV4_LEVELS : IPV6_LEVELS; })
117
+#endif
118
+
119
+#define FAMILY_LVLS		(GET_LEVELS(my_family))
120
+
121
+/* NODES_PER_LEVEL: returns the maximum number of nodes which can reside in
122
+ * a gnode of the `lvl'th level */
123
+#define NODES_PER_LEVEL(lvl)	((1<<(MAXGROUPNODE_BITS*(lvl))))
124
+
125
+/* Struct used to keep all the quadro_group ids of a node. (The node is part of this
126
+ * quadro groups) */
127
+typedef struct {
128
+	u_char      levels;		 /*How many levels we have*/
129
+	int         gid[MAX_LEVELS];	 /*Group ids. Each element is the gid of the quadrogroup in the 
130
+					   relative level. (ex: gid[n] is the gid of the quadropgroup a 
131
+					   the n-th level)*/
132
+	map_gnode  *gnode[MAX_LEVELS-ZERO_LEVEL]; /*Each element is a pointer to the relative
133
+						    gnode in the ext_map.*/
134
+	inet_prefix ipstart[MAX_LEVELS]; /*The ipstart of each quadg.gid in their respective levels*/
135
+}quadro_group;
136
+
137
+/* Note: this is the int_info of the a packed quadro_group struct, which
138
+ * hasnt't the `map_gnode *gnode' pointers. The ipstart structs must be also
139
+ * packed with pack_inet_prefix() */
140
+INT_INFO quadro_group_iinfo = { 1, 
141
+				{ INT_TYPE_32BIT },
142
+				{ sizeof(u_char) },
143
+				{ MAX_LEVELS }
144
+			      };
145
+#define QUADRO_GROUP_PACK_SZ (sizeof(u_char) + sizeof(int)*MAX_LEVELS +     \
146
+				+ INET_PREFIX_PACK_SZ * MAX_LEVELS)
147
+
148
+/*These are the flags passed to iptoquadg()*/
149
+#define QUADG_IPSTART 1
150
+#define QUADG_GID     (1<<1)
151
+#define QUADG_GNODE   (1<<2)
152
+
153
+/* This block is used to send the ext_map */
154
+struct ext_map_hdr
155
+{
156
+	char   quadg[QUADRO_GROUP_PACK_SZ];  /* The packed me.cur_quadg */
157
+
158
+	size_t ext_map_sz; 		/*It's the sum of all the gmaps_sz.
159
+					  The size of a single map is:
160
+					  (ext_map_sz/(MAP_GNODE_PACK_SZ*
161
+					  (quadg.levels-EXTRA_LEVELS)); */
162
+	size_t rblock_sz[MAX_LEVELS];	/*The size of the rblock of each gmap*/
163
+	size_t total_rblock_sz;		/*The sum of all rblock_sz*/
164
+}_PACKED_;
165
+
166
+/* Note: You have to consider the quadro_group struct when convert between
167
+ * endianness */
168
+INT_INFO ext_map_hdr_iinfo = { 3, 
169
+			       { INT_TYPE_32BIT, INT_TYPE_32BIT, INT_TYPE_32BIT },
170
+			       { QUADRO_GROUP_PACK_SZ, 
171
+				   QUADRO_GROUP_PACK_SZ+sizeof(size_t),
172
+				   QUADRO_GROUP_PACK_SZ+(sizeof(size_t)*(MAX_LEVELS+1)) },
173
+			       { 1, MAX_LEVELS, 1 }
174
+			     };
175
+	
176
+/* The ext_map_block is:
177
+ * 	struct ext_map_hdr hdr;
178
+ * 	char ext_map[ext_map_sz];
179
+ * 	char rnode_blocks[total_rblock_sz];
180
+ */
181
+#define EXT_MAP_BLOCK_SZ(ext_map_sz, rblock_sz) (sizeof(struct ext_map_hdr)+(ext_map_sz)+(rblock_sz))
182
+
183
+/* 
184
+ * This struct is used by the root_node to describe all the rnodes which
185
+ * doesn't belongs to our same gnode.
186
+ */
187
+typedef struct {
188
+	map_node	node;
189
+	quadro_group 	quadg;	/* quadg.gnode[level] may be set to 0
190
+				 * if that gnode doesn't belong to the
191
+				 * same upper level of me.cur_quadg:
192
+				 * quadg.gid[level+1] != me.cur_quadg.gid[level+1]
193
+				 */
194
+}ext_rnode;
195
+
196
+/*This cache keeps the list of all the ext_rnode used.*/
197
+struct ext_rnode_cache {
198
+	LLIST_HDR	(struct ext_rnode_cache);
199
+
200
+	ext_rnode	*e;		/*The pointer to the ext_rnode struct*/
201
+	int		rnode_pos;	/*The ext_rnode position in the 
202
+					  array of rnodes of the root_node */
203
+};
204
+typedef struct ext_rnode_cache ext_rnode_cache;
205
+
206
+/* * * Functions' declaration * * */
207
+inline int get_groups(int family, int lvl);
208
+int is_group_invalid(int *gids, int gid, int lvl, int family);
209
+
210
+int  pos_from_gnode(map_gnode *gnode, map_gnode *map);
211
+map_gnode * gnode_from_pos(int pos, map_gnode *map);
212
+void rnodetoip(u_int mapstart, u_int maprnode, inet_prefix ipstart, inet_prefix *ret);
213
+const char *rnode_to_ipstr(u_int mapstart, u_int maprnode, inet_prefix ipstart);
214
+int iptogid(inet_prefix *ip, int level);
215
+void iptogids(inet_prefix *ip, int *gid, int levels);
216
+void gidtoipstart(int *gid, u_char total_levels, u_char levels, int family, 
217
+		inet_prefix *ip);
218
+void iptoquadg(inet_prefix ip, map_gnode **ext_map, quadro_group *qg, char flags);
219
+
220
+void quadg_setflags(quadro_group *qg, char flags);
221
+void quadg_free(quadro_group *qg);
222
+void quadg_destroy(quadro_group *qg);
223
+void gnode_inc_seeds(quadro_group *qg, int level);
224
+void gnode_dec_seeds(quadro_group *qg, int level);
225
+void pack_quadro_group(quadro_group *qg, char *pack);
226
+void unpack_quadro_group(quadro_group *qg, char *pack);
227
+
228
+int free_gids(quadro_group *qg, int level, map_gnode **ext_map,	map_node *int_map);
229
+int void_gids(quadro_group *qg, int level, map_gnode **ext_map,	map_node *int_map);
230
+
231
+int random_ip(inet_prefix *ipstart, int final_level, int final_gid, 
232
+		int total_levels, map_gnode **ext_map, int only_free_gnode, 
233
+		inet_prefix *new_ip, int my_family);
234
+void gnodetoip(quadro_group *quadg, int gnodeid, u_char level, inet_prefix *ip);
235
+int gids_cmp(int *gids_a, int *gids_b, int lvl, int max_lvl);
236
+int quadg_gids_cmp(quadro_group a, quadro_group b, int lvl);
237
+int ip_gids_cmp(inet_prefix a, inet_prefix b, int lvl);
238
+ext_rnode_cache *erc_find(ext_rnode_cache *erc, ext_rnode *e_rnode);
239
+void e_rnode_del(ext_rnode_cache **erc_head, u_int *counter, ext_rnode_cache *erc);
240
+void e_rnode_add(ext_rnode_cache **erc, ext_rnode *e_rnode, int rnode_pos, u_int *counter);
241
+ext_rnode_cache *e_rnode_init(u_int *counter);
242
+void e_rnode_free(ext_rnode_cache **erc, u_int *counter);
243
+ext_rnode_cache *e_rnode_find(ext_rnode_cache *erc, quadro_group *qg, int level);
244
+void erc_update_rnodepos(ext_rnode_cache *erc, map_node *root_node, int old_rnode_pos);
245
+void erc_reorder_rnodepos(ext_rnode_cache **erc, u_int *erc_counter, map_node *root_node);
246
+ext_rnode_cache *erc_find_gnode(ext_rnode_cache *erc, map_gnode *gnode, u_char level);
247
+
248
+map_gnode *init_gmap(int groups);
249
+void reset_gmap(map_gnode *gmap, int groups);
250
+map_gnode **init_extmap(u_char levels, int groups);
251
+void free_extmap(map_gnode **ext_map, u_char levels, int groups);
252
+void reset_extmap(map_gnode **ext_map, u_char levels, int groups);
253
+
254
+int  g_rnode_find(map_gnode *gnode, map_gnode *n);
255
+int  extmap_find_level(map_gnode **ext_map, map_gnode *gnode, u_char max_level);
256
+void gmap_node_del(map_gnode *gnode);
257
+
258
+int merge_ext_maps(map_gnode **base, map_gnode **new, quadro_group base_root,
259
+		quadro_group new_root);
260
+
261
+int verify_ext_map_hdr(struct ext_map_hdr *emap_hdr, quadro_group *quadg);
262
+void free_extmap_rblock(map_rnode **rblock, u_char levels);
263
+void pack_map_gnode(map_gnode *gnode, char *pack);
264
+void unpack_map_gnode(map_gnode *gnode, char *pack);
265
+char *pack_extmap(map_gnode **ext_map, int maxgroupnode, quadro_group *quadg, size_t *pack_sz);
266
+map_gnode **unpack_extmap(char *package, quadro_group *quadg);
267
+int save_extmap(map_gnode **ext_map, int maxgroupnode, quadro_group *quadg, char *file);
268
+map_gnode **load_extmap(char *file, quadro_group *quadg);
269
+
270
+#endif /*GMAP_H*/

+ 0
- 0
src/hash.c View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save