MissValeska 10 years ago
parent
commit
0fdc2ad732
100 changed files with 10135 additions and 24239 deletions
  1. 4
    0
      .gitignore
  2. 0
    7
      Install-Ntk-Debug.sh
  3. 0
    1
      Makefile.am
  4. 0
    560
      Makefile.in
  5. 54
    0
      SConstruct
  6. 0
    932
      aclocal.m4
  7. 0
    1517
      config.guess
  8. 0
    1598
      config.sub
  9. 0
    6749
      configure
  10. 0
    184
      configure.ac
  11. 0
    530
      depcomp
  12. 0
    323
      install-sh
  13. 0
    360
      missing
  14. 0
    21
      src/Makefile.am
  15. 0
    809
      src/Makefile.in
  16. 0
    14
      src/Ntk-Console/Makefile
  17. 0
    322
      src/Ntk-Console/Netsukuku-Console.c
  18. 0
    36
      src/Ntk-Console/Netsukuku-Console.h
  19. 0
    3
      src/Ntk-Console/Ntk-Console-Compile.sh
  20. 30
    61
      src/SConscript
  21. 126
    105
      src/accept.c
  22. 19
    20
      src/accept.h
  23. 856
    777
      src/andna.c
  24. 74
    77
      src/andna.h
  25. 824
    754
      src/andna_cache.c
  26. 196
    192
      src/andna_cache.h
  27. 546
    521
      src/andns.c
  28. 21
    21
      src/andns.h
  29. 457
    419
      src/andns_lib.c
  30. 55
    56
      src/andns_lib.h
  31. 140
    118
      src/andns_net.c
  32. 39
    15
      src/andns_net.h
  33. 154
    123
      src/andns_snsd.c
  34. 34
    10
      src/andns_snsd.h
  35. 172
    141
      src/bmap.c
  36. 53
    45
      src/bmap.h
  37. 5
    4
      src/buffer.c
  38. 1
    1
      src/buffer.h
  39. 18
    0
      src/common.h
  40. 42
    39
      src/conf.c
  41. 36
    38
      src/conf.h
  42. 0
    1
      src/conf/Makefile.am
  43. 0
    464
      src/conf/Makefile.in
  44. 0
    199
      src/conf/netsukuku.conf.in
  45. 0
    109
      src/config.h.in
  46. 60
    0
      src/console.h
  47. 57
    43
      src/crypto.c
  48. 10
    8
      src/crypto.h
  49. 143
    134
      src/daemon.c
  50. 10
    9
      src/daemon.h
  51. 36
    29
      src/dns_wrapper.c
  52. 11
    12
      src/dns_wrapper.h
  53. 722
    640
      src/dnslib.c
  54. 83
    84
      src/dnslib.h
  55. 70
    63
      src/endianness.c
  56. 23
    23
      src/endianness.h
  57. 32
    36
      src/err_errno.c
  58. 4
    4
      src/err_errno.h
  59. 480
    404
      src/gmap.c
  60. 137
    118
      src/gmap.h
  61. 66
    60
      src/hash.c
  62. 2
    2
      src/hash.h
  63. 618
    556
      src/hook.c
  64. 31
    29
      src/hook.h
  65. 200
    172
      src/if.c
  66. 20
    18
      src/if.h
  67. 510
    458
      src/igs.c
  68. 71
    68
      src/igs.h
  69. 1
    1
      src/includes.h
  70. 366
    314
      src/inet.c
  71. 63
    55
      src/inet.h
  72. 109
    85
      src/iptunnel.c
  73. 20
    18
      src/iptunnel.h
  74. 53
    43
      src/ipv6-gmp.c
  75. 2
    2
      src/ipv6-gmp.h
  76. 210
    179
      src/krnl_route.c
  77. 7
    7
      src/krnl_route.h
  78. 66
    58
      src/krnl_rule.c
  79. 6
    6
      src/krnl_rule.h
  80. 2
    4
      src/libiptc/ipt_conntrack.h
  81. 50
    47
      src/libiptc/iptables.h
  82. 71
    77
      src/libiptc/libip4tc.c
  83. 333
    349
      src/libiptc/libiptc.c
  84. 68
    73
      src/libiptc/libiptc.h
  85. 63
    44
      src/libiptc/linux_list.h
  86. 97
    76
      src/libnetlink.c
  87. 54
    32
      src/libnetlink.h
  88. 241
    232
      src/libping.c
  89. 56
    56
      src/libping.h
  90. 49
    39
      src/ll_map.c
  91. 17
    2
      src/ll_map.h
  92. 9
    10
      src/llist.c
  93. 64
    57
      src/log.c
  94. 2
    2
      src/log.h
  95. 0
    2
      src/man/Makefile.am
  96. 0
    527
      src/man/Makefile.in
  97. 308
    259
      src/map.c
  98. 104
    93
      src/map.h
  99. 292
    244
      src/mark.c
  100. 0
    0
      src/mark.h

+ 4
- 0
.gitignore View File

@@ -17,3 +17,7 @@
17 17
 *.app
18 18
 .*
19 19
 *~
20
+
21
+config.h
22
+*.log
23
+build.conf

+ 0
- 7
Install-Ntk-Debug.sh View File

@@ -1,7 +0,0 @@
1
-#!/bin/sh
2
-
3
-make clean
4
-autoreconf -i
5
-CFLAGS="-g" "-std=c99" ./configure
6
-make
7
-sudo make install

+ 0
- 1
Makefile.am View File

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

+ 0
- 560
Makefile.in View File

@@ -1,560 +0,0 @@
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:

+ 54
- 0
SConstruct View File

@@ -0,0 +1,54 @@
1
+import os
2
+import sys
3
+import platform as _platform
4
+
5
+#
6
+#   Command line options and help
7
+#
8
+
9
+opts = Variables('build.conf')
10
+opts.AddVariables(('CONF_DIR', """Directory where the Netsukuku configuration files will be installed""", '/etc/netsukuku'),
11
+        ('DATA_DIR', 'Directory to install data files', '/usr/share/netsukuku'),
12
+        ('MAN_DIR',  'Where the manuals will be installed', '/usr/man'),
13
+        ('BIN_DIR' , 'Directory to install the binaries', '/usr/bin'),
14
+        ('PID_DIR',  'Specify location of ntkd.pid file', '/var/run'),
15
+        ('destdir', 'SCons will copy all the files under destdir during installation', '/'),
16
+        EnumVariable('debug', 'build the debug code', 'no',
17
+            allowed_values=('yes', 'no', '1', '0'), map={},
18
+            ignorecase=0),
19
+        EnumVariable('static', 'build statically the binaries', 'no',
20
+            allowed_values=('yes', 'no', '1', '0'), map={},
21
+            ignorecase=0))
22
+opts.Add('CC', 'The C compiler.')
23
+opts.Add('CXX', 'The C++ compiler.')
24
+
25
+env = Environment(options = opts, ENV = os.environ, CCFLAGS = ' -Wall')
26
+
27
+env['platform'] = _platform.system().lower();
28
+env["CC"] = os.getenv("CC") or env["CC"]
29
+env["CXX"] = os.getenv("CXX") or env["CXX"]
30
+env["ENV"].update(x for x in os.environ.items() if x[0].startswith("CCC_"))
31
+
32
+env.Append(CPPPATH = ['#src'])
33
+env.Append(LIBPATH = ['#src'])
34
+env.Append(CFLAGS = ['-g'])
35
+
36
+opts.Save('build.conf', env)
37
+
38
+Help("""
39
+*** Usage
40
+      'scons' to build the ntkd binary,
41
+      'scons debug=yes' to build the debug version.
42
+      'scons install' to install it in the system.
43
+
44
+*** General options
45
+""" + opts.GenerateHelpText(env))
46
+
47
+print "===================================================="
48
+print "Compiling Netsukuku for " + env['platform']
49
+print "===================================================="
50
+
51
+Export("env")
52
+
53
+# Main Sources
54
+SConscript("#src/SConscript")

+ 0
- 932
aclocal.m4 View File

@@ -1,932 +0,0 @@
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
-

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


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


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


+ 0
- 184
configure.ac View File

@@ -1,184 +0,0 @@
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

+ 0
- 530
depcomp View File

@@ -1,530 +0,0 @@
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:

+ 0
- 323
install-sh View File

@@ -1,323 +0,0 @@
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:

+ 0
- 360
missing View File

@@ -1,360 +0,0 @@
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:

+ 0
- 21
src/Makefile.am View File

@@ -1,21 +0,0 @@
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

+ 0
- 809
src/Makefile.in View File

@@ -1,809 +0,0 @@
1
-# Makefile.in generated by automake 1.13.3 from Makefile.am.
2
-# @configure_input@
3
-
4
-# Copyright (C) 1994-2013 Free Software Foundation, Inc.
5
-
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
-VPATH = @srcdir@
18
-am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
19
-am__make_running_with_option = \
20
-  case $${target_option-} in \
21
-      ?) ;; \
22
-      *) echo "am__make_running_with_option: internal error: invalid" \
23
-              "target option '$${target_option-}' specified" >&2; \
24
-         exit 1;; \
25
-  esac; \
26
-  has_opt=no; \
27
-  sane_makeflags=$$MAKEFLAGS; \
28
-  if $(am__is_gnu_make); then \
29
-    sane_makeflags=$$MFLAGS; \
30
-  else \
31
-    case $$MAKEFLAGS in \
32
-      *\\[\ \	]*) \
33
-        bs=\\; \
34
-        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
35
-          | sed "s/$$bs$$bs[$$bs $$bs	]*//g"`;; \
36
-    esac; \
37
-  fi; \
38
-  skip_next=no; \
39
-  strip_trailopt () \
40
-  { \
41
-    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
42
-  }; \
43
-  for flg in $$sane_makeflags; do \
44
-    test $$skip_next = yes && { skip_next=no; continue; }; \
45
-    case $$flg in \
46
-      *=*|--*) continue;; \
47
-        -*I) strip_trailopt 'I'; skip_next=yes;; \
48
-      -*I?*) strip_trailopt 'I';; \
49
-        -*O) strip_trailopt 'O'; skip_next=yes;; \
50
-      -*O?*) strip_trailopt 'O';; \
51
-        -*l) strip_trailopt 'l'; skip_next=yes;; \
52
-      -*l?*) strip_trailopt 'l';; \
53
-      -[dEDm]) skip_next=yes;; \
54
-      -[JT]) skip_next=yes;; \
55
-    esac; \
56
-    case $$flg in \
57
-      *$$target_option*) has_opt=yes; break;; \
58
-    esac; \
59
-  done; \
60
-  test $$has_opt = yes
61
-am__make_dryrun = (target_option=n; $(am__make_running_with_option))
62
-am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
63
-pkgdatadir = $(datadir)/@PACKAGE@
64
-pkgincludedir = $(includedir)/@PACKAGE@
65
-pkglibdir = $(libdir)/@PACKAGE@
66
-pkglibexecdir = $(libexecdir)/@PACKAGE@
67
-am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
68
-install_sh_DATA = $(install_sh) -c -m 644
69
-install_sh_PROGRAM = $(install_sh) -c
70
-install_sh_SCRIPT = $(install_sh) -c
71
-INSTALL_HEADER = $(INSTALL_DATA)
72
-transform = $(program_transform_name)
73
-NORMAL_INSTALL = :
74
-PRE_INSTALL = :
75
-POST_INSTALL = :
76
-NORMAL_UNINSTALL = :
77
-PRE_UNINSTALL = :
78
-POST_UNINSTALL = :
79
-build_triplet = @build@
80
-host_triplet = @host@
81
-bin_PROGRAMS = ntkd$(EXEEXT) ntk-resolv$(EXEEXT)
82
-subdir = src
83
-DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
84
-	$(srcdir)/config.h.in $(top_srcdir)/depcomp TODO
85
-ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
86
-am__aclocal_m4_deps = $(top_srcdir)/configure.ac
87
-am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
88
-	$(ACLOCAL_M4)
89
-mkinstalldirs = $(install_sh) -d
90
-CONFIG_HEADER = config.h
91
-CONFIG_CLEAN_FILES =
92
-CONFIG_CLEAN_VPATH_FILES =
93
-am__installdirs = "$(DESTDIR)$(bindir)"
94
-PROGRAMS = $(bin_PROGRAMS)
95
-am_ntk_resolv_OBJECTS = andns_lib.$(OBJEXT) ntkresolv.$(OBJEXT) \
96
-	andns_net.$(OBJEXT) crypto.$(OBJEXT) snsd_cache.$(OBJEXT) \
97
-	inet.$(OBJEXT) ll_map.$(OBJEXT) libnetlink.$(OBJEXT) \
98
-	log.$(OBJEXT) xmalloc.$(OBJEXT) endianness.$(OBJEXT) \
99
-	misc.$(OBJEXT) err_errno.$(OBJEXT) buffer.$(OBJEXT)
100
-ntk_resolv_OBJECTS = $(am_ntk_resolv_OBJECTS)
101
-ntk_resolv_DEPENDENCIES =
102
-am_ntkd_OBJECTS = accept.$(OBJEXT) map.$(OBJEXT) misc.$(OBJEXT) \
103
-	buffer.$(OBJEXT) hash.$(OBJEXT) pkts.$(OBJEXT) qspn.$(OBJEXT) \
104
-	request.$(OBJEXT) radar.$(OBJEXT) gmap.$(OBJEXT) \
105
-	hook.$(OBJEXT) rehook.$(OBJEXT) if.$(OBJEXT) inet.$(OBJEXT) \
106
-	ipv6-gmp.$(OBJEXT) krnl_route.$(OBJEXT) andna.$(OBJEXT) \
107
-	snsd_cache.$(OBJEXT) andna_cache.$(OBJEXT) err_errno.$(OBJEXT) \
108
-	andns.$(OBJEXT) andns_lib.$(OBJEXT) dnslib.$(OBJEXT) \
109
-	andns_net.$(OBJEXT) andns_snsd.$(OBJEXT) bmap.$(OBJEXT) \
110
-	conf.$(OBJEXT) crypto.$(OBJEXT) daemon.$(OBJEXT) \
111
-	dns_wrapper.$(OBJEXT) endianness.$(OBJEXT) krnl_rule.$(OBJEXT) \
112
-	iptunnel.$(OBJEXT) libnetlink.$(OBJEXT) ll_map.$(OBJEXT) \
113
-	llist.$(OBJEXT) log.$(OBJEXT) route.$(OBJEXT) tracer.$(OBJEXT) \
114
-	igs.$(OBJEXT) libping.$(OBJEXT) xmalloc.$(OBJEXT) \
115
-	netsukuku.$(OBJEXT) mark.$(OBJEXT) libip4tc.$(OBJEXT)
116
-ntkd_OBJECTS = $(am_ntkd_OBJECTS)
117
-ntkd_DEPENDENCIES =
118
-AM_V_P = $(am__v_P_@AM_V@)
119
-am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
120
-am__v_P_0 = false
121
-am__v_P_1 = :
122
-AM_V_GEN = $(am__v_GEN_@AM_V@)
123
-am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
124
-am__v_GEN_0 = @echo "  GEN     " $@;
125
-am__v_GEN_1 = 
126
-AM_V_at = $(am__v_at_@AM_V@)
127
-am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
128
-am__v_at_0 = @
129
-am__v_at_1 = 
130
-DEFAULT_INCLUDES = -I.@am__isrc@
131
-depcomp = $(SHELL) $(top_srcdir)/depcomp
132
-am__depfiles_maybe = depfiles
133
-am__mv = mv -f
134
-AM_V_lt = $(am__v_lt_@AM_V@)
135
-am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
136
-am__v_lt_0 = --silent
137
-am__v_lt_1 = 
138
-COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
139
-	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
140
-AM_V_CC = $(am__v_CC_@AM_V@)
141
-am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
142
-am__v_CC_0 = @echo "  CC      " $@;
143
-am__v_CC_1 = 
144
-CCLD = $(CC)
145
-LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
146
-AM_V_CCLD = $(am__v_CCLD_@AM_V@)
147
-am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
148
-am__v_CCLD_0 = @echo "  CCLD    " $@;
149
-am__v_CCLD_1 = 
150
-SOURCES = $(ntk_resolv_SOURCES) $(ntkd_SOURCES)
151
-DIST_SOURCES = $(ntk_resolv_SOURCES) $(ntkd_SOURCES)
152
-RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \
153
-	ctags-recursive dvi-recursive html-recursive info-recursive \
154
-	install-data-recursive install-dvi-recursive \
155
-	install-exec-recursive install-html-recursive \
156
-	install-info-recursive install-pdf-recursive \
157
-	install-ps-recursive install-recursive installcheck-recursive \
158
-	installdirs-recursive pdf-recursive ps-recursive \
159
-	tags-recursive uninstall-recursive
160
-am__can_run_installinfo = \
161
-  case $$AM_UPDATE_INFO_DIR in \
162
-    n|no|NO) false;; \
163
-    *) (install-info --version) >/dev/null 2>&1;; \
164
-  esac
165
-RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive	\
166
-  distclean-recursive maintainer-clean-recursive
167
-am__recursive_targets = \
168
-  $(RECURSIVE_TARGETS) \
169
-  $(RECURSIVE_CLEAN_TARGETS) \
170
-  $(am__extra_recursive_targets)
171
-AM_RECURSIVE_TARGETS = $(am__recursive_targets:-recursive=) TAGS CTAGS \
172
-	distdir
173
-am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) \
174
-	$(LISP)config.h.in
175
-# Read a list of newline-separated strings from the standard input,
176
-# and print each of them once, without duplicates.  Input order is
177
-# *not* preserved.
178
-am__uniquify_input = $(AWK) '\
179
-  BEGIN { nonempty = 0; } \
180
-  { items[$$0] = 1; nonempty = 1; } \
181
-  END { if (nonempty) { for (i in items) print i; }; } \
182
-'
183
-# Make sure the list of sources is unique.  This is necessary because,
184
-# e.g., the same source file might be shared among _SOURCES variables
185
-# for different programs/libraries.
186
-am__define_uniq_tagged_files = \
187
-  list='$(am__tagged_files)'; \
188
-  unique=`for i in $$list; do \
189
-    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
190
-  done | $(am__uniquify_input)`
191
-ETAGS = etags
192
-CTAGS = ctags
193
-DIST_SUBDIRS = $(SUBDIRS)
194
-DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
195
-am__relativize = \
196
-  dir0=`pwd`; \
197
-  sed_first='s,^\([^/]*\)/.*$$,\1,'; \
198
-  sed_rest='s,^[^/]*/*,,'; \
199
-  sed_last='s,^.*/\([^/]*\)$$,\1,'; \
200
-  sed_butlast='s,/*[^/]*$$,,'; \
201
-  while test -n "$$dir1"; do \
202
-    first=`echo "$$dir1" | sed -e "$$sed_first"`; \
203
-    if test "$$first" != "."; then \
204
-      if test "$$first" = ".."; then \
205
-        dir2=`echo "$$dir0" | sed -e "$$sed_last"`/"$$dir2"; \
206
-        dir0=`echo "$$dir0" | sed -e "$$sed_butlast"`; \
207
-      else \
208
-        first2=`echo "$$dir2" | sed -e "$$sed_first"`; \
209
-        if test "$$first2" = "$$first"; then \
210
-          dir2=`echo "$$dir2" | sed -e "$$sed_rest"`; \
211
-        else \
212
-          dir2="../$$dir2"; \
213
-        fi; \
214
-        dir0="$$dir0"/"$$first"; \
215
-      fi; \
216
-    fi; \
217
-    dir1=`echo "$$dir1" | sed -e "$$sed_rest"`; \
218
-  done; \
219
-  reldir="$$dir2"
220
-ACLOCAL = @ACLOCAL@
221
-AMTAR = @AMTAR@
222
-AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
223
-AUTOCONF = @AUTOCONF@
224
-AUTOHEADER = @AUTOHEADER@
225
-AUTOMAKE = @AUTOMAKE@
226
-AWK = @AWK@
227
-CC = @CC@
228
-CCDEPMODE = @CCDEPMODE@
229
-CFLAGS = @CFLAGS@
230
-CONF_DIR = @CONF_DIR@
231
-CPP = @CPP@
232
-CPPFLAGS = @CPPFLAGS@
233
-CXX = @CXX@
234
-CXXDEPMODE = @CXXDEPMODE@
235
-CXXFLAGS = @CXXFLAGS@
236
-CYGPATH_W = @CYGPATH_W@
237
-DATA_DIR = @DATA_DIR@
238
-DEFS = @DEFS@
239
-DEPDIR = @DEPDIR@
240
-ECHO_C = @ECHO_C@
241
-ECHO_N = @ECHO_N@
242
-ECHO_T = @ECHO_T@
243
-EGREP = @EGREP@
244
-EXEEXT = @EXEEXT@
245
-GREP = @GREP@
246
-IF_METHOD = @IF_METHOD@
247
-INSTALL = @INSTALL@
248
-INSTALL_DATA = @INSTALL_DATA@
249
-INSTALL_PROGRAM = @INSTALL_PROGRAM@
250
-INSTALL_SCRIPT = @INSTALL_SCRIPT@
251
-INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
252
-KERNEL_METHOD = @KERNEL_METHOD@
253
-LDFLAGS = @LDFLAGS@
254
-LIBOBJS = @LIBOBJS@
255
-LIBS = @LIBS@
256
-LTLIBOBJS = @LTLIBOBJS@
257
-MAKEINFO = @MAKEINFO@
258
-MKDIR_P = @MKDIR_P@
259
-OBJEXT = @OBJEXT@
260
-OTHER_METHOD = @OTHER_METHOD@
261
-PACKAGE = @PACKAGE@
262
-PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
263
-PACKAGE_NAME = @PACKAGE_NAME@
264
-PACKAGE_STRING = @PACKAGE_STRING@
265
-PACKAGE_TARNAME = @PACKAGE_TARNAME@
266
-PACKAGE_URL = @PACKAGE_URL@
267
-PACKAGE_VERSION = @PACKAGE_VERSION@
268
-PATH_SEPARATOR = @PATH_SEPARATOR@
269
-PID_DIR = @PID_DIR@
270
-RT_METHOD = @RT_METHOD@
271
-SET_MAKE = @SET_MAKE@
272
-SHELL = @SHELL@
273
-STRIP = @STRIP@
274
-VERSION = @VERSION@
275
-abs_builddir = @abs_builddir@
276
-abs_srcdir = @abs_srcdir@
277
-abs_top_builddir = @abs_top_builddir@
278
-abs_top_srcdir = @abs_top_srcdir@
279
-ac_ct_CC = @ac_ct_CC@
280
-ac_ct_CXX = @ac_ct_CXX@
281
-am__include = @am__include@
282
-am__leading_dot = @am__leading_dot@
283
-am__quote = @am__quote@
284
-am__tar = @am__tar@
285
-am__untar = @am__untar@
286
-bindir = @bindir@
287
-build = @build@
288
-build_alias = @build_alias@
289
-build_cpu = @build_cpu@
290
-build_os = @build_os@
291
-build_vendor = @build_vendor@
292
-builddir = @builddir@
293
-datadir = @datadir@
294
-datarootdir = @datarootdir@
295
-debug_flags = @debug_flags@
296
-docdir = @docdir@
297
-dvidir = @dvidir@
298
-exec_prefix = @exec_prefix@
299
-gmp = @gmp@
300
-host = @host@
301
-host_alias = @host_alias@
302
-host_cpu = @host_cpu@
303
-host_os = @host_os@
304
-host_vendor = @host_vendor@
305
-htmldir = @htmldir@
306
-includedir = @includedir@
307
-infodir = @infodir@
308
-install_sh = @install_sh@
309
-libdir = @libdir@
310
-libexecdir = @libexecdir@
311
-localedir = @localedir@
312
-localstatedir = @localstatedir@
313
-mandir = @mandir@
314
-mkdir_p = @mkdir_p@
315
-oldincludedir = @oldincludedir@
316
-pdfdir = @pdfdir@
317
-prefix = @prefix@
318
-program_transform_name = @program_transform_name@
319
-psdir = @psdir@
320
-sbindir = @sbindir@
321
-sharedstatedir = @sharedstatedir@
322
-srcdir = @srcdir@
323
-sysconfdir = @sysconfdir@
324
-target_alias = @target_alias@
325
-top_build_prefix = @top_build_prefix@
326
-top_builddir = @top_builddir@
327
-top_srcdir = @top_srcdir@
328
-SUBDIRS = man scripts conf
329
-AM_CFLAGS = -g -I. @debug_flags@ -I@gmp@
330
-AM_CXXFLAGS = -g -I. @debug_flags@ -I@gmp@
331
-ntkd_SOURCES = accept.c map.c misc.c buffer.c hash.c pkts.c qspn.c   \
332
-	request.c  \
333
-	radar.c gmap.c hook.c rehook.c if.c inet.c ipv6-gmp.c        \
334
-	krnl_route.c andna.c snsd_cache.c andna_cache.c err_errno.c  \
335
-	andns.c andns_lib.c dnslib.c andns_net.c andns_snsd.c	     \
336
-	bmap.c  conf.c crypto.c daemon.c dns_wrapper.c endianness.c  \
337
-	krnl_rule.c iptunnel.c libnetlink.c ll_map.c llist.c log.c   \
338
-	route.c tracer.c igs.c libping.c xmalloc.c netsukuku.c       \
339
-	mark.c libiptc/libip4tc.c
340
-
341
-ntkd_LDADD = -lpthread -lgmp -lcrypto -lresolv -lz
342
-ntk_resolv_SOURCES = andns_lib.c ntkresolv.c andns_net.c crypto.c    \
343
-		  snsd_cache.c inet.c ll_map.c libnetlink.c log.c    \
344
-		  xmalloc.c endianness.c misc.c err_errno.c buffer.c
345
-
346
-ntk_resolv_LDADD = -lz -lcrypto
347
-all: config.h
348
-	$(MAKE) $(AM_MAKEFLAGS) all-recursive
349
-
350
-.SUFFIXES:
351
-.SUFFIXES: .c .o .obj
352
-$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
353
-	@for dep in $?; do \
354
-	  case '$(am__configure_deps)' in \
355
-	    *$$dep*) \
356
-	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
357
-	        && { if test -f $@; then exit 0; else break; fi; }; \
358
-	      exit 1;; \
359
-	  esac; \
360
-	done; \
361
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/Makefile'; \
362
-	$(am__cd) $(top_srcdir) && \
363
-	  $(AUTOMAKE) --gnu src/Makefile
364
-.PRECIOUS: Makefile
365
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
366
-	@case '$?' in \
367
-	  *config.status*) \
368
-	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
369
-	  *) \
370
-	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
371
-	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
372
-	esac;
373
-
374
-$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
375
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
376
-
377
-$(top_srcdir)/configure:  $(am__configure_deps)
378
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
379
-$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
380
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
381
-$(am__aclocal_m4_deps):
382
-
383
-config.h: stamp-h1
384
-	@if test ! -f $@; then rm -f stamp-h1; else :; fi
385
-	@if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) stamp-h1; else :; fi
386
-
387
-stamp-h1: $(srcdir)/config.h.in $(top_builddir)/config.status
388
-	@rm -f stamp-h1
389
-	cd $(top_builddir) && $(SHELL) ./config.status src/config.h
390
-$(srcdir)/config.h.in:  $(am__configure_deps) 
391
-	($(am__cd) $(top_srcdir) && $(AUTOHEADER))
392
-	rm -f stamp-h1
393
-	touch $@
394
-
395
-distclean-hdr:
396
-	-rm -f config.h stamp-h1
397
-install-binPROGRAMS: $(bin_PROGRAMS)
398
-	@$(NORMAL_INSTALL)
399
-	@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
400
-	if test -n "$$list"; then \
401
-	  echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \
402
-	  $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \
403
-	fi; \
404
-	for p in $$list; do echo "$$p $$p"; done | \
405
-	sed 's/$(EXEEXT)$$//' | \
406
-	while read p p1; do if test -f $$p \
407
-	  ; then echo "$$p"; echo "$$p"; else :; fi; \
408
-	done | \
409
-	sed -e 'p;s,.*/,,;n;h' \
410
-	    -e 's|.*|.|' \
411
-	    -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
412
-	sed 'N;N;N;s,\n, ,g' | \
413
-	$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
414
-	  { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
415
-	    if ($$2 == $$4) files[d] = files[d] " " $$1; \
416
-	    else { print "f", $$3 "/" $$4, $$1; } } \
417
-	  END { for (d in files) print "f", d, files[d] }' | \
418
-	while read type dir files; do \
419
-	    if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
420
-	    test -z "$$files" || { \
421
-	      echo " $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
422
-	      $(INSTALL_PROGRAM_ENV) $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
423
-	    } \
424
-	; done
425
-
426
-uninstall-binPROGRAMS:
427
-	@$(NORMAL_UNINSTALL)
428
-	@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
429
-	files=`for p in $$list; do echo "$$p"; done | \
430
-	  sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
431
-	      -e 's/$$/$(EXEEXT)/' \
432
-	`; \
433
-	test -n "$$list" || exit 0; \
434
-	echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
435
-	cd "$(DESTDIR)$(bindir)" && rm -f $$files
436
-
437
-clean-binPROGRAMS:
438
-	-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
439
-
440
-ntk-resolv$(EXEEXT): $(ntk_resolv_OBJECTS) $(ntk_resolv_DEPENDENCIES) $(EXTRA_ntk_resolv_DEPENDENCIES) 
441
-	@rm -f ntk-resolv$(EXEEXT)
442
-	$(AM_V_CCLD)$(LINK) $(ntk_resolv_OBJECTS) $(ntk_resolv_LDADD) $(LIBS)
443
-
444
-ntkd$(EXEEXT): $(ntkd_OBJECTS) $(ntkd_DEPENDENCIES) $(EXTRA_ntkd_DEPENDENCIES) 
445
-	@rm -f ntkd$(EXEEXT)
446
-	$(AM_V_CCLD)$(LINK) $(ntkd_OBJECTS) $(ntkd_LDADD) $(LIBS)
447
-
448
-mostlyclean-compile:
449
-	-rm -f *.$(OBJEXT)
450
-
451
-distclean-compile:
452
-	-rm -f *.tab.c
453
-
454
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/accept.Po@am__quote@
455
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/andna.Po@am__quote@
456
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/andna_cache.Po@am__quote@
457
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/andns.Po@am__quote@
458
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/andns_lib.Po@am__quote@
459
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/andns_net.Po@am__quote@
460
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/andns_snsd.Po@am__quote@
461
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bmap.Po@am__quote@
462
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/buffer.Po@am__quote@
463
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/conf.Po@am__quote@
464
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/crypto.Po@am__quote@
465
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/daemon.Po@am__quote@
466
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dns_wrapper.Po@am__quote@
467
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dnslib.Po@am__quote@
468
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/endianness.Po@am__quote@
469
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/err_errno.Po@am__quote@
470
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gmap.Po@am__quote@
471
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hash.Po@am__quote@
472
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hook.Po@am__quote@
473
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/if.Po@am__quote@
474
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/igs.Po@am__quote@
475
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inet.Po@am__quote@
476
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iptunnel.Po@am__quote@
477
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ipv6-gmp.Po@am__quote@
478
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/krnl_route.Po@am__quote@
479
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/krnl_rule.Po@am__quote@
480
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libip4tc.Po@am__quote@
481
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libnetlink.Po@am__quote@
482
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libping.Po@am__quote@
483
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ll_map.Po@am__quote@
484
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/llist.Po@am__quote@
485
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/log.Po@am__quote@
486
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/map.Po@am__quote@
487
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mark.Po@am__quote@
488
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/misc.Po@am__quote@
489
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netsukuku.Po@am__quote@
490
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntkresolv.Po@am__quote@
491
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pkts.Po@am__quote@
492
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/qspn.Po@am__quote@
493
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/radar.Po@am__quote@
494
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/rehook.Po@am__quote@
495
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/request.Po@am__quote@
496
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/route.Po@am__quote@
497
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/snsd_cache.Po@am__quote@
498
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tracer.Po@am__quote@
499
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xmalloc.Po@am__quote@
500
-
501
-.c.o:
502
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
503
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
504
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
505
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
506
-@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(COMPILE) -c $<
507
-
508
-.c.obj:
509
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
510
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
511
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
512
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
513
-@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'`
514
-
515
-libip4tc.o: libiptc/libip4tc.c
516
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(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
517
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libip4tc.Tpo $(DEPDIR)/libip4tc.Po
518
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libiptc/libip4tc.c' object='libip4tc.o' libtool=no @AMDEPBACKSLASH@
519
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
520
-@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(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
521
-
522
-libip4tc.obj: libiptc/libip4tc.c
523
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(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`
524
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) $(DEPDIR)/libip4tc.Tpo $(DEPDIR)/libip4tc.Po
525
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libiptc/libip4tc.c' object='libip4tc.obj' libtool=no @AMDEPBACKSLASH@
526
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
527
-@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(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`
528
-
529
-# This directory's subdirectories are mostly independent; you can cd
530
-# into them and run 'make' without going through this Makefile.
531
-# To change the values of 'make' variables: instead of editing Makefiles,
532
-# (1) if the variable is set in 'config.status', edit 'config.status'
533
-#     (which will cause the Makefiles to be regenerated when you run 'make');
534
-# (2) otherwise, pass the desired values on the 'make' command line.
535
-$(am__recursive_targets):
536
-	@fail=; \
537
-	if $(am__make_keepgoing); then \
538
-	  failcom='fail=yes'; \
539
-	else \
540
-	  failcom='exit 1'; \
541
-	fi; \
542
-	dot_seen=no; \
543
-	target=`echo $@ | sed s/-recursive//`; \
544
-	case "$@" in \
545
-	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
546
-	  *) list='$(SUBDIRS)' ;; \
547
-	esac; \
548
-	for subdir in $$list; do \
549
-	  echo "Making $$target in $$subdir"; \
550
-	  if test "$$subdir" = "."; then \
551
-	    dot_seen=yes; \
552
-	    local_target="$$target-am"; \
553
-	  else \
554
-	    local_target="$$target"; \
555
-	  fi; \
556
-	  ($(am__cd) $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
557
-	  || eval $$failcom; \
558
-	done; \
559
-	if test "$$dot_seen" = "no"; then \
560
-	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
561
-	fi; test -z "$$fail"
562
-
563
-ID: $(am__tagged_files)
564
-	$(am__define_uniq_tagged_files); mkid -fID $$unique
565
-tags: tags-recursive
566
-TAGS: tags
567
-
568
-tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
569
-	set x; \
570
-	here=`pwd`; \
571
-	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
572
-	  include_option=--etags-include; \
573
-	  empty_fix=.; \
574
-	else \
575
-	  include_option=--include; \
576
-	  empty_fix=; \
577
-	fi; \
578
-	list='$(SUBDIRS)'; for subdir in $$list; do \
579
-	  if test "$$subdir" = .; then :; else \
580
-	    test ! -f $$subdir/TAGS || \
581
-	      set "$$@" "$$include_option=$$here/$$subdir/TAGS"; \
582
-	  fi; \
583
-	done; \
584
-	$(am__define_uniq_tagged_files); \
585
-	shift; \
586
-	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
587
-	  test -n "$$unique" || unique=$$empty_fix; \
588
-	  if test $$# -gt 0; then \
589
-	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
590
-	      "$$@" $$unique; \
591
-	  else \
592
-	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
593
-	      $$unique; \
594
-	  fi; \
595
-	fi
596
-ctags: ctags-recursive
597
-
598
-CTAGS: ctags
599
-ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
600
-	$(am__define_uniq_tagged_files); \
601
-	test -z "$(CTAGS_ARGS)$$unique" \
602
-	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
603
-	     $$unique
604
-
605
-GTAGS:
606
-	here=`$(am__cd) $(top_builddir) && pwd` \
607
-	  && $(am__cd) $(top_srcdir) \
608
-	  && gtags -i $(GTAGS_ARGS) "$$here"
609
-cscopelist: cscopelist-recursive
610
-
611
-cscopelist-am: $(am__tagged_files)
612
-	list='$(am__tagged_files)'; \
613
-	case "$(srcdir)" in \
614
-	  [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
615
-	  *) sdir=$(subdir)/$(srcdir) ;; \
616
-	esac; \
617
-	for i in $$list; do \
618
-	  if test -f "$$i"; then \
619
-	    echo "$(subdir)/$$i"; \
620
-	  else \
621
-	    echo "$$sdir/$$i"; \
622
-	  fi; \
623
-	done >> $(top_builddir)/cscope.files
624
-
625
-distclean-tags:
626
-	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
627
-
628
-distdir: $(DISTFILES)
629
-	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
630
-	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
631
-	list='$(DISTFILES)'; \
632
-	  dist_files=`for file in $$list; do echo $$file; done | \
633
-	  sed -e "s|^$$srcdirstrip/||;t" \
634
-	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
635
-	case $$dist_files in \
636
-	  */*) $(MKDIR_P) `echo "$$dist_files" | \
637
-			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
638
-			   sort -u` ;; \
639
-	esac; \
640
-	for file in $$dist_files; do \
641
-	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
642
-	  if test -d $$d/$$file; then \
643
-	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
644
-	    if test -d "$(distdir)/$$file"; then \
645
-	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
646
-	    fi; \
647
-	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
648
-	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
649
-	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
650
-	    fi; \
651
-	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
652
-	  else \
653
-	    test -f "$(distdir)/$$file" \
654
-	    || cp -p $$d/$$file "$(distdir)/$$file" \
655
-	    || exit 1; \
656
-	  fi; \
657
-	done
658
-	@list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
659
-	  if test "$$subdir" = .; then :; else \
660
-	    $(am__make_dryrun) \
661
-	      || test -d "$(distdir)/$$subdir" \
662
-	      || $(MKDIR_P) "$(distdir)/$$subdir" \
663
-	      || exit 1; \
664
-	    dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
665
-	    $(am__relativize); \
666
-	    new_distdir=$$reldir; \
667
-	    dir1=$$subdir; dir2="$(top_distdir)"; \
668
-	    $(am__relativize); \
669
-	    new_top_distdir=$$reldir; \
670
-	    echo " (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) top_distdir="$$new_top_distdir" distdir="$$new_distdir" \\"; \
671
-	    echo "     am__remove_distdir=: am__skip_length_check=: am__skip_mode_fix=: distdir)"; \
672
-	    ($(am__cd) $$subdir && \
673
-	      $(MAKE) $(AM_MAKEFLAGS) \
674
-	        top_distdir="$$new_top_distdir" \
675
-	        distdir="$$new_distdir" \
676
-		am__remove_distdir=: \
677
-		am__skip_length_check=: \
678
-		am__skip_mode_fix=: \
679
-	        distdir) \
680
-	      || exit 1; \
681
-	  fi; \
682
-	done
683
-check-am: all-am
684
-check: check-recursive
685
-all-am: Makefile $(PROGRAMS) config.h
686
-installdirs: installdirs-recursive
687
-installdirs-am:
688
-	for dir in "$(DESTDIR)$(bindir)"; do \
689
-	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
690
-	done
691
-install: install-recursive
692
-install-exec: install-exec-recursive
693
-install-data: install-data-recursive
694
-uninstall: uninstall-recursive
695
-
696
-install-am: all-am
697
-	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
698
-
699
-installcheck: installcheck-recursive
700
-install-strip:
701
-	if test -z '$(STRIP)'; then \
702
-	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
703
-	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
704
-	      install; \
705
-	else \
706
-	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
707
-	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
708
-	    "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
709
-	fi
710
-mostlyclean-generic:
711
-
712
-clean-generic:
713
-
714
-distclean-generic:
715
-	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
716
-	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
717
-
718
-maintainer-clean-generic:
719
-	@echo "This command is intended for maintainers to use"
720
-	@echo "it deletes files that may require special tools to rebuild."
721
-clean: clean-recursive
722
-
723
-clean-am: clean-binPROGRAMS clean-generic mostlyclean-am
724
-
725
-distclean: distclean-recursive
726
-	-rm -rf ./$(DEPDIR)
727
-	-rm -f Makefile
728
-distclean-am: clean-am distclean-compile distclean-generic \
729
-	distclean-hdr distclean-tags
730
-
731
-dvi: dvi-recursive
732
-
733
-dvi-am:
734
-
735
-html: html-recursive
736
-
737
-html-am:
738
-
739
-info: info-recursive
740
-
741
-info-am:
742
-
743
-install-data-am:
744
-
745
-install-dvi: install-dvi-recursive
746
-
747
-install-dvi-am:
748
-
749
-install-exec-am: install-binPROGRAMS
750
-
751
-install-html: install-html-recursive
752
-
753
-install-html-am:
754
-
755
-install-info: install-info-recursive
756
-
757
-install-info-am:
758
-
759
-install-man:
760
-
761
-install-pdf: install-pdf-recursive
762
-
763
-install-pdf-am:
764
-
765
-install-ps: install-ps-recursive
766
-
767
-install-ps-am:
768
-
769
-installcheck-am:
770
-
771
-maintainer-clean: maintainer-clean-recursive
772
-	-rm -rf ./$(DEPDIR)
773
-	-rm -f Makefile
774
-maintainer-clean-am: distclean-am maintainer-clean-generic
775
-
776
-mostlyclean: mostlyclean-recursive
777
-
778
-mostlyclean-am: mostlyclean-compile mostlyclean-generic
779
-
780
-pdf: pdf-recursive
781
-
782
-pdf-am:
783
-
784
-ps: ps-recursive
785
-
786
-ps-am:
787
-
788
-uninstall-am: uninstall-binPROGRAMS
789
-
790
-.MAKE: $(am__recursive_targets) all install-am install-strip
791
-
792
-.PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am check \
793
-	check-am clean clean-binPROGRAMS clean-generic cscopelist-am \
794
-	ctags ctags-am distclean distclean-compile distclean-generic \
795
-	distclean-hdr distclean-tags distdir dvi dvi-am html html-am \
796
-	info info-am install install-am install-binPROGRAMS \
797
-	install-data install-data-am install-dvi install-dvi-am \
798
-	install-exec install-exec-am install-html install-html-am \
799
-	install-info install-info-am install-man install-pdf \
800
-	install-pdf-am install-ps install-ps-am install-strip \
801
-	installcheck installcheck-am installdirs installdirs-am \
802
-	maintainer-clean maintainer-clean-generic mostlyclean \
803
-	mostlyclean-compile mostlyclean-generic pdf pdf-am ps ps-am \
804
-	tags tags-am uninstall uninstall-am uninstall-binPROGRAMS
805
-
806
-
807
-# Tell versions [3.59,3.63) of GNU make to not export all variables.
808
-# Otherwise a system limit (for SysV at least) may be exceeded.
809
-.NOEXPORT:

+ 0
- 14
src/Ntk-Console/Makefile View File

@@ -1,14 +0,0 @@
1
-C=clang
2
-DEBUG=-g -fno-builtin -Wfatal-errors -pedantic -Wunreachable-code -Winline -Wredundant-decls -Wno-vla
3
-CFLAGS=-Wall ${DEBUG}
4
-SRCBIN=Netsukuku-Console
5
-
6
-all: ${SRCBIN}
7
-
8
-${SRCBIN}: Netsukuku-Console.o
9
-	${C} ${LDFLAGS} ${LIBS} $^ -o $@
10
-
11
-.PHONY: clean
12
-
13
-clean:
14
-	rm -f *.o ${SRCBIN}

+ 0
- 322
src/Ntk-Console/Netsukuku-Console.c View File

@@ -1,322 +0,0 @@
1
-#include "Netsukuku-Console.h"
2
-
3
-char response[BUFFER_LENGTH];
4
-
5
-void usage();
6
-
7
-void clean_up();
8
-
9
-int validity_check(char *request) {
10
-    
11
-        if(strncmp(request,"help", (int)strlen(request))  == 0)
12
-            return 1;
13
-        
14
-        else if(strncmp(request,"uptime", (int)strlen(request))  == 0)
15
-            return 0;
16
-        
17
-        else if(strncmp(request,"kill", (int)strlen(request))  == 0)
18
-            return 2;
19
-        
20
-        else if(strncmp(request,"version", (int)strlen(request))  == 0)
21
-            return 3;
22
-        
23
-        else if(strncmp(request,"console_uptime", (int)strlen(request))  == 0)
24
-            return 4;
25
-        
26
-        else if(strlen(request) > BUFFER_LENGTH)
27
-            return 5;
28
-        
29
-        else if(strncmp(request,"inet_connected", (int)strlen(request))  == 0)
30
-            return 0;
31
-        
32
-        else if(strncmp(request,"cur_ifs", (int)strlen(request))  == 0)
33
-            return 0;
34
-        
35
-        else if(strncmp(request,"cur_ifs_n", (int)strlen(request))  == 0)
36
-            return 0;
37
-        
38
-        else if(strncmp(request,"cur_qspn_id", (int)strlen(request))  == 0)
39
-            return 0;
40
-        
41
-        else if(strncmp(request,"cur_ip", (int)strlen(request))  == 0)
42
-            return 0;
43
-        
44
-        else if(strncmp(request,"cur_node", (int)strlen(request))  == 0)
45
-            return 0;
46
-        
47
-        else if(strncmp(request,"ifs", (int)strlen(request))  == 0)
48
-            return 0;
49
-        
50
-        else if(strncmp(request,"ifs_n", (int)strlen(request))  == 0)
51
-            return 0;
52
-        
53
-        else {
54
-            printf("Incorrect or unreadable command, Please correct it.\n");
55
-            return -1;
56
-        }
57
-    
58
-    return -2;
59
-    
60
-}
61
-
62
-void response_cleanup(char response[BUFFER_LENGTH]) {
63
-    
64
-    char remove = 'a';
65
-
66
-    char* c;
67
-    char* pPosition;
68
-    while((pPosition = strchr(response, 'a')) != NULL)  {
69
-        if ((c = index(response, remove)) != NULL) {
70
-        size_t len_left = sizeof(response) - (c+1-response);
71
-        memmove(c, c+1, len_left);
72
-        }
73
-    }
74
-    printf("Sent and received Successfully!\n The Response was: %s", response);
75
-}
76
-
77
-/* Sends and receives to ntkd */
78
-void ntkd_request(char *request) {
79
-
80
-    int request_length;
81
-    
82
-            rc = connect(sockfd, (struct sockaddr *)&serveraddr, SUN_LEN(&serveraddr));
83
-                if (rc < 0) {
84
-                    perror("connect() failed");
85
-                    exit(-1);
86
-                }
87
-    
88
-    
89
-            request_length = (int)strlen(request);
90
-            memset(request, 'a', BUFFER_LENGTH - request_length);
91
-            rc = send(sockfd, request, sizeof(request), 0);
92
-            if (rc < 0) {
93
-                perror("send() failed");
94
-                exit(-1);
95
-            }
96
-
97
-            bytesReceived = 0;
98
-            while (bytesReceived < BUFFER_LENGTH) {
99
-                rc = recv(sockfd, & response[bytesReceived],
100
-                   BUFFER_LENGTH - bytesReceived, 0);
101
-                if (rc < 0) {
102
-                    perror("recv() failed");
103
-                    exit(-1);
104
-                }
105
-            else if (rc == 0) {
106
-                printf("The server closed the connection\n");
107
-                exit(-1);
108
-            }
109
-
110
-            /* Increment the number of bytes that have been received so far  */
111
-            bytesReceived += rc;        
112
-            }
113
-            response_cleanup(response);
114
-}
115
-
116
-void opensocket(void) {
117
-    
118
-    sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
119
-    if (sockfd < 0) {
120
-         perror("socket creation failed");
121
-         exit(-1);
122
-    }
123
-    
124
-    memset(&serveraddr, 0, sizeof(serveraddr));
125
-    serveraddr.sun_family = AF_UNIX;
126
-    strcpy(serveraddr.sun_path, SERVER_PATH);
127
-}
128
-
129
-void console_uptime(void) {
130
-    
131
-    int uptime_sec1;
132
-    int uptime_min1;
133
-    int uptime_hour1;
134
-    
135
-    int uptime_day1;
136
-    int uptime_month1;
137
-    int uptime_year1;
138
-    
139
-    time(&rawtime);
140
-    
141
-    timeinfo = localtime(&rawtime);
142
-    
143
-    uptime_sec1 = timeinfo->tm_sec;
144
-    uptime_min1 = timeinfo->tm_min;
145
-    uptime_hour1 = timeinfo->tm_hour;
146
-    
147
-    uptime_day1 = timeinfo->tm_mday;
148
-    uptime_month1 = timeinfo->tm_mon;
149
-    uptime_year1 = timeinfo->tm_year;
150
-    
151
-    uptime_sec1 -= uptime_sec;
152
-    uptime_min1 -= uptime_min;
153
-    uptime_hour1 -= uptime_hour;
154
-    
155
-    uptime_day1 -= uptime_day;
156
-    uptime_month1 -= uptime_month;
157
-    uptime_year1 -= uptime_year;
158
-    /* Checks if the date/time is negative,
159
-     * And makes it positive.
160
-     * e.g -11 is 1 because this is a signed variable
161
-     * at a modulus of 12. Thus after 12, It is -12
162
-     * which is zero, Every number after this is counting up
163
-     * to 12 again, Which is going to be 0 in this instance.
164
-     * -12 to 12 is 24 actual months.
165
-     * So -11 + 12 is 1, As it should be, And -12 + 12 is zero
166
-     * as it should be. The only difference is the modulus number,
167
-     * i.e: 12, 24, etc. */
168
-    if(uptime_month1 < 0)
169
-        uptime_month1 + 12;
170
-    if(uptime_day1 < 0)
171
-        uptime_day1 + 365;
172
-    if(uptime_hour1 < 0)
173
-        uptime_hour1 + 24;
174
-    if(uptime_min1 < 0)
175
-        uptime_min1 + 60;
176
-    if(uptime_sec1 < 0)
177
-        uptime_sec1 + 60;
178
-    /* Checks if the date/time is the modulus, And resets it to zero.
179
-     * e.g: 12 months is a year, Listing 12 months and one year
180
-     * is confusing,
181
-     * And implies that it has been two years. */
182
-    if(uptime_month1 == 12)
183
-        uptime_month1 = 0;
184
-    if(uptime_day1 == 365)
185
-        uptime_day1 = 0;
186
-    if(uptime_hour1 == 24)
187
-        uptime_hour1 = 0;
188
-    if(uptime_min1 == 60)
189
-        uptime_min1 = 0;
190
-    if(uptime_sec1 == 60)
191
-        uptime_sec1 = 0;
192
-    
193
-    printf("Total Uptime is: %i Year(s), %i Month(s), %i Day(s), %i Hour(s), %i Minute(s), %i Second(s)\n",uptime_year1, uptime_month1, uptime_day1, uptime_hour1, uptime_min1, uptime_sec1);
194
-    
195
-}
196
-
197
-int millisleep(unsigned ms)
198
-{
199
-  return usleep(1000 * ms);
200
-}
201
-
202
-void console(char * request) {
203
-    
204
-    if(validity_check(request) == -2)
205
-            printf("Error: Command has not been processed!\n");
206
-        
207
-    if(validity_check(request) == -1)
208
-            usage();
209
-        
210
-    if(strncmp(request,"quit", (int)strlen(request)) == 0) {
211
-            clean_up();
212
-            exit(0);
213
-        }
214
-    
215
-    if(validity_check(request) == 0) {
216
-            ntkd_request(request);
217
-            millisleep(200);
218
-    }
219
-        
220
-    if(validity_check(request) == 1)
221
-            usage();
222
-        
223
-    if(validity_check(request) == 2)
224
-            system("ntkd -k");
225
-        
226
-    if(validity_check(request) == 3) {
227
-            printf("Ntk-Console Version: %s\n", VERSION_STR);
228
-            ntkd_request(request);
229
-        }
230
-
231
-    if(validity_check(request) == 4)
232
-            console_uptime();
233
-    
234
-    if(validity_check(request) == 5)
235
-        printf("Error: Command longer than 250 bytes.\n");
236
-}
237
-
238
-int main(void) {
239
-    
240
-    time(&rawtime);
241
-    
242
-    timeinfo = localtime(&rawtime);
243
-    
244
-    uptime_sec = timeinfo->tm_sec;
245
-    uptime_min = timeinfo->tm_min;
246
-    uptime_hour = timeinfo->tm_hour;
247
-    uptime_day = timeinfo->tm_mday;
248
-    uptime_month = timeinfo->tm_mon;
249
-    uptime_year = timeinfo->tm_year;
250
-    
251
-    opensocket();
252
-    
253
-    printf("This is the Netsukuku Console, Please type 'help' for more information.\n");
254
-    
255
-    char request;
256
-
257
-    char request1;
258
-    
259
-    request = (char)malloc(BUFFER_LENGTH);
260
-    
261
-    request1 = (char)malloc(BUFFER_LENGTH);
262
-    
263
-    do {
264
-    
265
-    printf("\n>");
266
-        
267
-    fgets(request1, 16, stdin);
268
-    
269
-    fflush(stdin);
270
-    
271
-    request1 = request;
272
-    
273
-    console(request);
274
-    } while(FALSE);
275
-    
276
-clean_up(); 
277
-return 0;
278
-}
279
-
280
-void usage(void) {
281
-    
282
-    	printf("Usage\n"
283
-		" uptime    Returns the time when ntkd finished the hooking," 
284
-					  "to get the the actual uptime just do) "
285
-					  "time(0)-me.uptime \n"
286
-		" help	Shows this\n"
287
-		" kill	Kills the running instance of netsukuku with SIGINT\n\n"
288
-		" version   Shows the running version of the ntk-console, and ntkd.\n"
289
-		" inet_connected    If it is 1, Ntkd is connected to the Internet\n"
290
-		"\n"
291
-		" cur_ifs   Lists all of the interfaces in cur_ifs\n"
292
-		" cur_ifs_n Lists the number of interfaces present in `cur_ifs'\n"
293
-		"\n");
294
-        printf(" cur_qspn_id   The current qspn_id we are processing. "
295
-                                "It is cur_qspn_id[levels] big\n"
296
-		" cur_ip    Current IP address\n"
297
-		"\n"
298
-		" cur_node  Current Node\n"
299
-		" ifs   Lists all of the interfaces in server_opt.ifs\n"
300
-                " ifs_n Lists the number of interfaces present in server_opt.ifs\n"
301
-                " quit Exits this program\n"
302
-		" console_uptime    Gets the uptime of this console\n");
303
-    
304
-}
305
-
306
-void clean_up(void) {
307
-    
308
-    const int optVal = 1;
309
-    const socklen_t optLen = sizeof(optVal);
310
-    
311
-    setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (void*) &optVal, optLen);
312
-    setsockopt(sockfd1, SOL_SOCKET, SO_REUSEADDR, (void*) &optVal, optLen);
313
-    
314
-    if (sockfd != -1)
315
-        close(sockfd);
316
-
317
-    if (sockfd1 != -1)
318
-        close(sockfd1);
319
-   
320
-   unlink(SERVER_PATH);
321
-    
322
-}

+ 0
- 36
src/Ntk-Console/Netsukuku-Console.h View File

@@ -1,36 +0,0 @@
1
-#ifndef NETSUKUKUCONSOLE_H
2
-#define NETSUKUKUCONSOLE_H
3
-
4
-#include <stdio.h>
5
-#include <stdlib.h>
6
-#include <string.h>
7
-#include <sys/types.h> 
8
-#include <sys/socket.h>
9
-#include <utmp.h>
10
-#include <sys/un.h>
11
-#include <unistd.h>
12
-#include <time.h>
13
-#include <errno.h>
14
-
15
-#define SERVER_PATH     "/tmp/ntk-console"
16
-#define BUFFER_LENGTH    250
17
-#define VERSION_STR     "0.0.2"
18
-#define FALSE              0
19
-
20
-int sockfd = -1, sockfd1 = -1;
21
-struct sockaddr_un serveraddr;
22
-int rc, bytesReceived;
23
-
24
-time_t rawtime;
25
-struct tm *timeinfo;
26
-
27
-int uptime_sec;
28
-int uptime_min;
29
-int uptime_hour;
30
-int uptime_day;
31
-int uptime_month;
32
-int uptime_year;
33
-
34
-int i;
35
-
36
-#endif /*NETSUKUKUCONSOLE_H*/

+ 0
- 3
src/Ntk-Console/Ntk-Console-Compile.sh View File

@@ -1,3 +0,0 @@
1
-#!/bin/bash
2
-make clean
3
-make

src/SConstruct → src/SConscript View File

@@ -18,57 +18,35 @@
18 18
 import sys
19 19
 import os
20 20
 
21
+Import("env")
22
+
21 23
 NTK_VERSION="0.0.9b"
22 24
 
23 25
 #
24 26
 #	Sources and libs
25 27
 #
26 28
 
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""") 
29
+sources_common    = ['xmalloc.c', 'log.c', 'misc.c', 'buffer.c', 'endianness.c']
30
+
31
+sources_qspn      = ['qspn-empiric.c'] + sources_common
32
+sources_netsukuku = ['accept.c', 'llist.c', 'ipv6-gmp.c', 'inet.c', 'request.c',
33
+					 'map.c', 'gmap.c', 'bmap.c', 'pkts.c', 'radar.c', 'hook.c',
34
+					 'rehook.c', 'tracer.c', 'qspn.c', 'hash.c', 'daemon.c',
35
+					 'crypto.c', 'snsd_cache.c', 'andna_cache.c', 'andna.c',
36
+					 'andns_lib.c', 'err_errno.c', 'dnslib.c', 'andns.c',
37
+					 'andns_net.c', 'andns_snsd.c', 'll_map.c', 'libnetlink.c',
38
+					 'if.c', 'krnl_route.c', 'krnl_rule.c', 'iptunnel.c',
39
+					 'route.c', 'conf.c', 'dns_wrapper.c', 'igs.c', 'mark.c',
40
+					 'libiptc/libip4tc.c', 'libping.c', 'ntk-console-server.c',
41
+					 'netsukuku.c'] + sources_common
42
+sources_ntkresolv = ['andns_lib.c', 'andns_net.c', 'crypto.c', 'snsd_cache.c',
43
+					 'inet.c', 'll_map.c', 'libnetlink.c', 'err_errno.c',
44
+					 'ntkresolv.c'] + sources_common
45
+
46
+sources_ntkconsole = ['ntk-console.c']
41 47
 
42 48
 libs = ['gmp', 'pthread', 'crypto', 'z']
43 49
 
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 50
 if ("yes" in env['debug']) or ("1" in env['debug']):
73 51
 	debug = 1
74 52
 	env.Append(CPPDEFINES={'DEBUG' : '${debug}'}, CCFLAGS = ' -ggdb -Wall', CXXFLAGS = '-g')
@@ -85,8 +63,6 @@ else:
85 63
 if (env['destdir'] == "/"):
86 64
 	env['destdir']=""
87 65
 
88
-opts.Save('build.conf', env)
89
-
90 66
 if os.path.exists("conf/netsukuku.conf") and env.GetOption('clean'):
91 67
 	Execute(Delete('conf/netsukuku.conf'))
92 68
 if os.path.exists("config.h") and env.GetOption('clean'):
@@ -94,15 +70,6 @@ if os.path.exists("config.h") and env.GetOption('clean'):
94 70
 if os.path.exists("config.log") and env.GetOption('clean'):
95 71
 	Execute(Delete('config.log'))
96 72
 	
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 73
 if ARGUMENTS.get('install'):
107 74
 		print "you aren't root"
108 75
 
@@ -145,10 +112,10 @@ if not os.path.exists("config.log") and not env.GetOption('clean'):
145 112
 
146 113
 def conf_build(target, source, env):
147 114
     conf_defines = {
148
-        "CONF_DIR": env["CONF_DIR"],
149
-	"DATA_DIR": env["DATA_DIR"],
150
-	"PID_DIR": env["PID_DIR"],
151
-	"VERSION": NTK_VERSION,
115
+		"CONF_DIR": env["CONF_DIR"],
116
+		"DATA_DIR": env["DATA_DIR"],
117
+		"PID_DIR": env["PID_DIR"],
118
+		"VERSION": NTK_VERSION,
152 119
         "debug": debug # this is an int.  1 for true, 0 for false
153 120
     }
154 121
 
@@ -187,11 +154,12 @@ build_config_files(env = env)
187 154
 #	Build
188 155
 #
189 156
 
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 = '.')
157
+ntkd 		= env.Program('ntkd', sources_netsukuku, LIBS = libs, CPPPATH = '.')
158
+qspn  		= env.Program('qspn-empiric', sources_qspn, LIBS = libs, CPPPATH = '.')
159
+ntkresolv 	= env.Program('ntk-resolv', sources_ntkresolv, LIBS = libs, CPPPATH = '.')
160
+ntkconsole 	= env.Program('ntk-console', sources_ntkconsole, LIBS = libs, CPPPATH = '.', CFLAGS = '-std=c99')
193 161
 
194
-Default(ntkd, ntkresolv)
162
+Default(ntkd, ntkresolv, ntkconsole, qspn)
195 163
 
196 164
 
197 165
 #
@@ -208,6 +176,7 @@ idir_pid    = '$destdir' + '$PID_DIR'
208 176
 
209 177
 env.Install(idir_bin, [ntkd])
210 178
 env.Install(idir_bin, [ntkresolv])
179
+env.Install(idir_bin, [ntkconsole])
211 180
 env.Alias('install', [idir_bin, idir_conf])
212 181
 
213 182
 #Dirty hack ;( Why GetOption("install") doesn't work?

+ 126
- 105
src/accept.c View File

@@ -35,170 +35,187 @@
35 35
 #include "log.h"
36 36
 
37 37
 
38
-void init_accept_tbl(int startups, int accepts, int time)
38
+void
39
+init_accept_tbl(int startups, int accepts, int time)
39 40
 {
40 41
 	/* TODO: activate and test it !! */
41 42
 #if 0
42 43
 	int i;
43 44
 
44
-	max_connections=startups;
45
-	max_accepts_per_host=accepts;
46
-	free_accept_time=time;
47
-	accept_idx=accept_sidx=0;
45
+	max_connections = startups;
46
+	max_accepts_per_host = accepts;
47
+	free_accept_time = time;
48
+	accept_idx = accept_sidx = 0;
48 49
 	pthread_mutex_init(&mtx_acpt_idx, NULL);
49 50
 	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);
51
+
52
+	accept_tbl =
53
+		(struct accept_table *) xmalloc(sizeof(struct accept_table) *
54
+										max_connections);
55
+	memset(accept_tbl, '\0',
56
+		   sizeof(struct accept_table) * max_connections);
57
+
58
+	for (i = 0; i < max_connections; i++) {
59
+		accept_tbl[i].pid =
60
+			(pid_t *) xmalloc(sizeof(pid_t) * max_accepts_per_host);
61
+		memset(accept_tbl[i].pid, '\0',
62
+			   sizeof(pid_t) * max_accepts_per_host);
63
+
64
+		accept_tbl[i].closed =
65
+			(unsigned char *) xmalloc(sizeof(unsigned char) *
66
+									  max_accepts_per_host);
67
+		memset(accept_tbl[i].closed, '\0',
68
+			   sizeof(unsigned char) * max_accepts_per_host);
69
+
70
+		accept_tbl[i].acp_t =
71
+			(time_t *) xmalloc(sizeof(time_t) * max_accepts_per_host);
72
+		memset(accept_tbl[i].acp_t, '\0',
73
+			   sizeof(time_t) * max_accepts_per_host);
63 74
 	}
64 75
 #endif
65 76
 }
66 77
 
67
-void destroy_accept_tbl(void)
78
+void
79
+destroy_accept_tbl(void)
68 80
 {
69 81
 	/* TODO: activate and test it !! */
70 82
 #if 0
71
-	int i; 
72
-	
73
-	if(!accept_tbl)
83
+	int i;
84
+
85
+	if (!accept_tbl)
74 86
 		return;
75
-	for(i=0; i<max_connections; i++) {
87
+	for (i = 0; i < max_connections; i++) {
76 88
 		xfree(accept_tbl[i].pid);
77 89
 		xfree(accept_tbl[i].closed);
78 90
 		xfree(accept_tbl[i].acp_t);
79 91
 	}
80 92
 	xfree(accept_tbl);
81
-	accept_tbl=0;
93
+	accept_tbl = 0;
82 94
 #endif
83 95
 }
84 96
 
85 97
 
86
-void update_accept_tbl(void)
98
+void
99
+update_accept_tbl(void)
87 100
 {
88 101
 	time_t cur_t, passed_time;
89
-	int i,e,k,ee, pid_exists;
90
-	
91
-	if(update_accept_tbl_mutex)
102
+	int i, e, k, ee, pid_exists;
103
+
104
+	if (update_accept_tbl_mutex)
92 105
 		return;
93 106
 	else
94
-		update_accept_tbl_mutex=1;
95
-	
107
+		update_accept_tbl_mutex = 1;
108
+
96 109
 	time(&cur_t);
97
-	
98
-	for(i=0; i < max_connections; i++) {
99
-		if(!accept_tbl[i].ip.len)
110
+
111
+	for (i = 0; i < max_connections; i++) {
112
+		if (!accept_tbl[i].ip.len)
100 113
 			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])
114
+		if (accept_tbl[i].accepts) {
115
+			for (e = 0; e < max_accepts_per_host; e++) {
116
+				if (!accept_tbl[i].acp_t[e])
104 117
 					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);
118
+
119
+				if (accept_tbl[i].pid[e]) {
120
+					k = kill(accept_tbl[i].pid[e], 0);
121
+					pid_exists = !(k == -1 && errno == ESRCH);
109 122
 				} else
110
-					pid_exists=0;
123
+					pid_exists = 0;
111 124
 
112 125
 #if 0
113 126
 				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);
127
+					  "accept_tbl[%d].acp_t[%d]:%d+%d, "
128
+					  "accept_tbl[i].pid[e]: %d, "
129
+					  "kill=%d (ESRCH=%d)",
130
+					  cur_t, i, e, accept_tbl[i].acp_t[e],
131
+					  free_accept_time, accept_tbl[i].pid[e], k, ESRCH);
120 132
 #endif
121 133
 
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;
134
+				passed_time = accept_tbl[i].acp_t[e] + free_accept_time;
135
+				if ((accept_tbl[i].closed[e] || !pid_exists) &&
136
+					passed_time <= cur_t) {
137
+					ee = e;
126 138
 					del_accept(i, &ee);
127 139
 				}
128 140
 			}
129 141
 		}
130 142
 	}
131
-	update_accept_tbl_mutex=0;
143
+	update_accept_tbl_mutex = 0;
132 144
 }
133 145
 
134
-int find_ip_acpt(inet_prefix ip)
146
+int
147
+find_ip_acpt(inet_prefix ip)
135 148
 {
136 149
 	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))
150
+
151
+	for (i = 0; i < max_accepts_per_host; i++) {
152
+		if (!memcmp(accept_tbl[i].ip.data, &ip.data, MAX_IP_SZ))
140 153
 			return i;
141 154
 	}
142 155
 
143 156
 	return -1;
144 157
 }
145 158
 
146
-int find_first_free(void)
159
+int
160
+find_first_free(void)
147 161
 {
148 162
 	int i;
149
-	
150
-	for(i=0; i<max_connections; i++)
151
-		if(!accept_tbl[i].accepts)
163
+
164
+	for (i = 0; i < max_connections; i++)
165
+		if (!accept_tbl[i].accepts)
152 166
 			return i;
153 167
 	return -1;
154 168
 }
155 169
 
156
-int is_ip_acpt_free(inet_prefix ip, int *index)
170
+int
171
+is_ip_acpt_free(inet_prefix ip, int *index)
157 172
 {
158 173
 	int idx;
159
-	
174
+
160 175
 	update_accept_tbl();
161
-	
162
-	if((idx=find_ip_acpt(ip))==-1)
163
-		if((idx=find_first_free())==-1)
176
+
177
+	if ((idx = find_ip_acpt(ip)) == -1)
178
+		if ((idx = find_first_free()) == -1)
164 179
 			return E_TOO_MANY_CONN;
165
-	
180
+
166 181
 	/*debug(DBG_NOISE, "ACPT: accept_tbl[%d].accepts: %d, max_acp: %d", idx,
167
-			accept_tbl[idx].accepts, max_accepts_per_host); */
182
+	   accept_tbl[idx].accepts, max_accepts_per_host); */
168 183
 
169
-	if(accept_tbl[idx].accepts >= max_accepts_per_host)
184
+	if (accept_tbl[idx].accepts >= max_accepts_per_host)
170 185
 		return E_ACCEPT_TBL_FULL;
171 186
 
172
-	*index=idx;
187
+	*index = idx;
173 188
 	return 0;
174 189
 }
175 190
 
176
-int find_free_acp_t(int idx)
191
+int
192
+find_free_acp_t(int idx)
177 193
 {
178 194
 	int e;
179
-	
180
-	for(e=0; e < max_accepts_per_host; e++) {
181
-		if(!accept_tbl[idx].acp_t[e])
195
+
196
+	for (e = 0; e < max_accepts_per_host; e++) {
197
+		if (!accept_tbl[idx].acp_t[e])
182 198
 			return e;
183 199
 	}
184
-	
185
-	return -1;	/*This happens if the rq_tbl is full for the "rq" request*/
200
+
201
+	return -1;					/*This happens if the rq_tbl is full for the "rq" request */
186 202
 }
187 203
 
188
-int new_accept(int idx, inet_prefix ip)
204
+int
205
+new_accept(int idx, inet_prefix ip)
189 206
 {
190
-	int cl=0;
207
+	int cl = 0;
191 208
 	/* TODO: activate and test it !! */
192 209
 #if 0
193 210
 	time_t cur_t;
194
-	
211
+
195 212
 	time(&cur_t);
196
-	
197
-	if((cl=find_free_acp_t(idx))==-1)
213
+
214
+	if ((cl = find_free_acp_t(idx)) == -1)
198 215
 		return -1;
199 216
 	accept_tbl[idx].accepts++;
200
-	accept_tbl[idx].acp_t[cl]=cur_t;
201
-	accept_tbl[idx].closed[cl]=0;
217
+	accept_tbl[idx].acp_t[cl] = cur_t;
218
+	accept_tbl[idx].closed[cl] = 0;
202 219
 	inet_copy(&accept_tbl[idx].ip, &ip);
203 220
 #endif
204 221
 	return cl;
@@ -208,67 +225,71 @@ int new_accept(int idx, inet_prefix ip)
208 225
  * add_accept: It adds a new accept of `ip'. If `replace' is not 0 the `ip's
209 226
  * accepts are not incremented and accept_sidx is set to 0.
210 227
  */
211
-int add_accept(inet_prefix ip, int replace)
228
+int
229
+add_accept(inet_prefix ip, int replace)
212 230
 {
213 231
 	/* TODO: activate and test it !! */
214 232
 #if 0
215 233
 	int err, idx, cl;
216
-	
217
-	if((err=is_ip_acpt_free(ip, &idx)))
234
+
235
+	if ((err = is_ip_acpt_free(ip, &idx)))
218 236
 		return err;
219 237
 
220
-	if(!replace || !accept_tbl[idx].accepts) {
221
-		cl=new_accept(idx, ip);
222
-		if(cl < 0)
238
+	if (!replace || !accept_tbl[idx].accepts) {
239
+		cl = new_accept(idx, ip);
240
+		if (cl < 0)
223 241
 			return -1;
224
-	} else 
225
-		cl=0;
242
+	} else
243
+		cl = 0;
226 244
 
227
-	/*This global var will be given to the thread*/
245
+	/*This global var will be given to the thread */
228 246
 	pthread_mutex_lock(&mtx_acpt_idx);
229
-	accept_idx=idx;
247
+	accept_idx = idx;
230 248
 	pthread_mutex_unlock(&mtx_acpt_idx);
231 249
 
232 250
 	pthread_mutex_lock(&mtx_acpt_sidx);
233
-	accept_sidx=cl;
251
+	accept_sidx = cl;
234 252
 	pthread_mutex_unlock(&mtx_acpt_sidx);
235 253
 #endif
236 254
 	return 0;
237 255
 }
238 256
 
239
-void del_accept(int idx, int *sidx)
257
+void
258
+del_accept(int idx, int *sidx)
240 259
 {
241 260
 #if 0
242
-	if(!accept_tbl[idx].accepts) 
261
+	if (!accept_tbl[idx].accepts)
243 262
 		return;
244 263
 
245
-	if(accept_tbl[idx].acp_t[*sidx]) {
264
+	if (accept_tbl[idx].acp_t[*sidx]) {
246 265
 		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)
266
+		accept_tbl[idx].acp_t[*sidx] = 0;
267
+		accept_tbl[idx].closed[*sidx] = 0;
268
+		if (!accept_tbl[idx].accepts)
250 269
 			memset(&accept_tbl[idx].ip, '\0', sizeof(inet_prefix));
251 270
 		(*sidx)--;
252 271
 	}
253 272
 #endif
254 273
 }
255 274
 
256
-int close_accept(int idx, int sidx)
275
+int
276
+close_accept(int idx, int sidx)
257 277
 {
258 278
 #if 0
259
-	if(!accept_tbl[idx].accepts) 
279
+	if (!accept_tbl[idx].accepts)
260 280
 		return -1;
261
-	
262
-	accept_tbl[idx].closed[sidx]=1;
281
+
282
+	accept_tbl[idx].closed[sidx] = 1;
263 283
 #endif
264 284
 	return 0;
265 285
 }
266 286
 
267
-void add_accept_pid(pid_t pid, int idx, int sidx)
287
+void
288
+add_accept_pid(pid_t pid, int idx, int sidx)
268 289
 {
269 290
 	/* TODO: activate and test it !! */
270 291
 #if 0
271
-	accept_tbl[idx].pid[sidx]=pid;
292
+	accept_tbl[idx].pid[sidx] = pid;
272 293
 /*	debug(DBG_NOISE, "ACPT: Added pig %d in accept_tbl[%d].pid[%d]", 
273 294
 			accept_tbl[idx].pid[sidx], idx, sidx);
274 295
 */

+ 19
- 20
src/accept.h View File

@@ -22,26 +22,25 @@
22 22
 #define MAX_CONNECTIONS		512
23 23
 
24 24
 #define MAX_ACCEPTS		16
25
-#define FREE_ACCEPT_TIME	4		/*in seconds*/
25
+#define FREE_ACCEPT_TIME	4	/*in seconds */
26 26
 
27 27
 /*
28 28
  * This struct keep tracks of single connection to the server.
29 29
  * The thread_daemon who handle the connection knows the connection
30 30
  * position in the accept_tbl.
31 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*/
32
+struct accept_table {
33
+	inet_prefix ip;				/*Ip of the node connected */
34
+	unsigned char accepts;		/*Number of connection from this node */
35
+	pid_t *pid;					/*The pid of each child that have accepted the conn */
36
+	unsigned char *closed;		/*Each element of this array is 1 or 0. It indicates if the connection has
37
+								   been closed */
38
+	time_t *acp_t;				/*The time when the connection was accepted. The "accepts" counter
39
+								   will decrement when one of the acp_t+FREE_ACCEPT_TIME will 
40
+								   be <= current_time AND (the relative pid will be non existent OR
41
+								   the relative closed element will be == 1)
42
+								 */
43
+	struct request_tbl rqtbl;	/*The request table */
45 44
 };
46 45
 
47 46
 /* This struct keeps all the info regarding each node connected */
@@ -62,14 +61,14 @@ int max_connections, max_accepts_per_host, free_accept_time;
62 61
 void init_accept_tbl(int startups, int accepts, int time);
63 62
 void destroy_accept_tbl(void);
64 63
 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);
64
+int find_ip_acpt(inet_prefix ip);
65
+int find_first_free(void);
66
+int is_ip_acpt_free(inet_prefix ip, int *index);
67
+int find_free_acp_t(int idx);
69 68
 int new_accept(int idx, inet_prefix ip);
70 69
 int add_accept(inet_prefix ip, int replace);
71 70
 void del_accept(int idx, int *sidx);
72
-int  close_accept(int idx, int sidx);
71
+int close_accept(int idx, int sidx);
73 72
 void add_accept_pid(pid_t pid, int idx, int sidx);
74 73
 
75
-#endif /*ACCEPT_H*/
74
+#endif							/*ACCEPT_H */

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


+ 74
- 77
src/andna.h View File

@@ -28,7 +28,7 @@
28 28
 #define ETC_RESOLV_CONF_BAK	"/etc/resolv.conf.bak"
29 29
 
30 30
 /* How many different andna pkt can be flooded simultaneusly */
31
-#define ANDNA_MAX_FLOODS	(ANDNA_MAX_QUEUE*3+1) 
31
+#define ANDNA_MAX_FLOODS	(ANDNA_MAX_QUEUE*3+1)
32 32
 
33 33
 /* How many new hash_gnodes are supported in the andna hash_gnode mutation */
34 34
 #define ANDNA_MAX_NEW_GNODES	1024
@@ -77,12 +77,12 @@ int last_spread_acache_pkt_id[ANDNA_MAX_FLOODS];
77 77
 #define ANDNA_REV_RESOLVE_RQ_TIMEOUT	60
78 78
 
79 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 */
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 86
 
87 87
 /*
88 88
  * andna_reg_pkt
@@ -98,32 +98,31 @@ int last_spread_acache_pkt_id[ANDNA_MAX_FLOODS];
98 98
  * that have to be registered. However the packet forwarded to the counter 
99 99
  * node won't keep this part.
100 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
-	
101
+struct andna_reg_pkt {
102
+	u_int rip[MAX_IP_INT];		/* register_node ip */
103
+	u_int hash[MAX_IP_INT];		/* md5 hash of the host name to
104
+								   register. */
105
+	char pubkey[ANDNA_PKEY_LEN];	/* public key of the register
106
+									   node. */
107
+	u_short hname_updates;		/* number of updates already 
108
+								   made for the hostname */
109
+
110
+	char sign[ANDNA_SIGNATURE_LEN];	/* RSA signature of the 
111
+									   entire pkt (excluding 
112
+									   `sign' itself and `flags'
113
+									 */
114
+	char flags;
115
+
117 116
 } _PACKED_;
118 117
 #define ANDNA_REG_PKT_SZ	     (sizeof(struct andna_reg_pkt))
119 118
 #define ANDNA_REG_SIGNED_BLOCK_SZ (ANDNA_REG_PKT_SZ - ANDNA_SIGNATURE_LEN - \
120 119
 				 	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
-				 
120
+INT_INFO andna_reg_pkt_iinfo = { 1,	/* `rip' and `hash' aren't considered */
121
+	{INT_TYPE_16BIT},
122
+	{MAX_IP_SZ * 2 + ANDNA_PKEY_LEN},
123
+	{1},
124
+};
125
+
127 126
 
128 127
 /*
129 128
  *   andna_resolve_rq_pkt
@@ -131,42 +130,40 @@ INT_INFO andna_reg_pkt_iinfo = 	{ 1, /* `rip' and `hash' aren't considered */
131 130
  * The andna resolve request pkt is used to resolve hostnames, IPs and MX
132 131
  * hostnames.
133 132
  */
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' */
133
+struct andna_resolve_rq_pkt {
134
+	u_int rip[MAX_IP_INT];		/* the ip of the requester node */
135
+	char flags;
136
+
137
+	u_int hash[MAX_IP_INT];		/* md5 hash of the hostname to
138
+								   resolve. */
139
+	int service;				/* the snsd service of the hname */
140
+	u_char proto;				/* the protocol of `service' */
143 141
 } _PACKED_;
144 142
 #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
-					};
143
+INT_INFO andna_resolve_rq_pkt_iinfo = { 1,	/* `rip' and `hash' are ignored */
144
+	{INT_TYPE_32BIT},
145
+	{MAX_IP_SZ * 2 + sizeof(char)},
146
+	{1},
147
+};
150 148
 
151 149
 /* 
152 150
  * The reply to the resolve request
153 151
  */
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 */
152
+struct andna_resolve_reply_pkt {
153
+	uint32_t timestamp;			/* the difference between the current
154
+								   time and the last time the resolved
155
+								   hname was updated */
159 156
 	/*
160 157
 	 * the rest of the pkt is a pack of one snsd_service llist:
161
-	 * char		service[SNSD_SERVICE_LLIST_PACK_SZ(service)];
158
+	 * char     service[SNSD_SERVICE_LLIST_PACK_SZ(service)];
162 159
 	 */
163 160
 } _PACKED_;
164 161
 #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
-					 };
162
+INT_INFO andna_resolve_reply_pkt_iinfo = { 1,	/* `ip' is ignored */
163
+	{INT_TYPE_32BIT},
164
+	{0},
165
+	{1}
166
+};
170 167
 
171 168
 
172 169
 /* 
@@ -189,19 +186,19 @@ INT_INFO andna_resolve_reply_pkt_iinfo = { 1, /* `ip' is ignored */
189 186
  * the pkt reaches a true old hash_gnode, or cannot be forwarded anymore since
190 187
  * there are no more older hash_gnodes.
191 188
  */
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;
189
+struct single_acache_hdr {
190
+	u_int rip[MAX_IP_INT];		/* the ip of the requester node */
191
+	u_int hash[MAX_IP_INT];
192
+	u_short hgnodes;			/* Number of hgnodes in the 
193
+								   body. */
194
+	u_char flags;
199 195
 } _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
-				   };
196
+INT_INFO single_acache_hdr_iinfo = { 1,	/* `rip' and `hash' are ignored */
197
+	{INT_TYPE_16BIT},
198
+	{MAX_IP_SZ * 2},
199
+	{1},
200
+};
201
+
205 202
 /*
206 203
  * The single_acache body is:
207 204
  * struct {
@@ -220,12 +217,11 @@ INT_INFO single_acache_hdr_iinfo = { 1, /* `rip' and `hash' are ignored */
220 217
  * Tell the node, which receives the pkt, to send a ANDNA_GET_SINGLE_ACACHE
221 218
  * request to fetch the andna_cache for the `hash' included in the pkt.
222 219
  */
223
-struct spread_acache_pkt
224
-{
225
-	u_int		hash[MAX_IP_INT];
220
+struct spread_acache_pkt {
221
+	u_int hash[MAX_IP_INT];
226 222
 } _PACKED_;
227 223
 #define SPREAD_ACACHE_PKT_SZ	(sizeof(struct spread_acache_pkt))
228
-INT_INFO spread_acache_pkt_info = { 0, { 0 }, { 0 }, { 0 } };
224
+INT_INFO spread_acache_pkt_info = { 0, {0}, {0}, {0} };
229 225
 
230 226
 
231 227
 
@@ -243,16 +239,16 @@ void andna_close(void);
243 239
 void andna_resolvconf_modify(void);
244 240
 void andna_resolvconf_restore(void);
245 241
 
246
-int andna_register_hname(lcl_cache *alcl, snsd_service *snsd_delete);
242
+int andna_register_hname(lcl_cache * alcl, snsd_service * snsd_delete);
247 243
 int andna_recv_reg_rq(PACKET rpkt);
248 244
 
249 245
 int andna_check_counter(PACKET pkt);
250 246
 int andna_recv_check_counter(PACKET rpkt);
251 247
 
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);
248
+snsd_service *andna_resolve_hash(u_int hname_hash[MAX_IP_INT], int service,
249
+								 u_char proto, int *records);
250
+snsd_service *andna_resolve_hname(char *hname, int service, u_char proto,
251
+								  int *records);
256 252
 int andna_recv_resolve_rq(PACKET rpkt);
257 253
 
258 254
 lcl_cache *andna_reverse_resolve(inet_prefix ip);
@@ -260,7 +256,8 @@ int andna_recv_rev_resolve_rq(PACKET rpkt);
260 256
 
261 257
 int spread_single_acache(u_int hash[MAX_IP_INT]);
262 258
 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]);
259
+andna_cache *get_single_andna_c(u_int hash[MAX_IP_INT],
260
+								u_int hash_gnode[MAX_IP_INT]);
264 261
 int put_single_acache(PACKET rpkt);
265 262
 int put_andna_cache(PACKET rq_pkt);
266 263
 int put_counter_cache(PACKET rq_pkt);
@@ -270,4 +267,4 @@ void andna_update_hnames(int only_new_hname);
270 267
 void *andna_maintain_hnames_active(void *null);
271 268
 void *andna_main(void *);
272 269
 
273
-#endif /*ANDNA_H*/
270
+#endif							/*ANDNA_H */

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


+ 196
- 192
src/andna_cache.h View File

@@ -34,11 +34,11 @@
34 34
 #define ANDNA_MAX_HNAME_LEN		512	/* (null terminator included) */
35 35
 #define ANDNA_MAX_HOSTNAMES		256	/* Max number of hnames per node */
36 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)*/
37
+										   the resolved_hnames cache* */
38
+#define ANDNA_EXPIRATION_TIME		259200	/* 3 days (in seconds) */
39 39
 #define ANDNA_MIN_UPDATE_TIME		3600	/* The minum amount of time to
40
-						   be waited before sending an 
41
-						   update of the hname. */
40
+											   be waited before sending an 
41
+											   update of the hname. */
42 42
 
43 43
 #define ANDNA_PRIVKEY_BITS		1024
44 44
 #define ANDNA_SKEY_MAX_LEN		900
@@ -51,75 +51,73 @@
51 51
 					  ((seeds)*32)/MAXGROUPNODE : (seeds);})
52 52
 
53 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 
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 59
 
60 60
 /* 
61 61
  * * *  Cache stuff  * * *
62 62
  */
63 63
 
64 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 */
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 71
 
72 72
 /* 
73 73
  * andna_cache_queue
74 74
  * 
75 75
  * The queue of the andna_cache. (see below).
76 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;
77
+struct andna_cache_queue {
78
+	LLIST_HDR(struct andna_cache_queue);
79
+
80
+	time_t timestamp;
81
+	u_short hname_updates;		/* numbers of hname's updates */
82
+	char pubkey[ANDNA_PKEY_LEN];
83
+
84
+	u_short snsd_counter;		/* # of `snsd' nodes */
85
+	snsd_service *service;
87 86
 };
88 87
 typedef struct andna_cache_queue andna_cache_queue;
89
-		
88
+
90 89
 /*
91 90
  * andna_cache
92 91
  * 
93 92
  * It keeps the entries of the hostnames registered by other nodes.
94 93
  */
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 */
94
+struct andna_cache {
95
+	LLIST_HDR(struct andna_cache);
96
+
97
+	u_int hash[MAX_IP_INT];		/* hostname's hash */
98
+	char flags;
99
+
100
+	u_short queue_counter;
101
+	andna_cache_queue *acq;		/* The queue of the registration.
102
+								   The first is the active one */
105 103
 };
106 104
 typedef struct andna_cache andna_cache;
107 105
 
108 106
 /* part of the counter cache, see below */
109
-struct counter_c_hashes
110
-{
111
-	LLIST_HDR	(struct counter_c_hashes);
107
+struct counter_c_hashes {
108
+	LLIST_HDR(struct counter_c_hashes);
112 109
 
113
-	time_t		timestamp;
114
-	u_short		hname_updates;
115
-	int		hash[MAX_IP_INT];
110
+	time_t timestamp;
111
+	u_short hname_updates;
112
+	int hash[MAX_IP_INT];
116 113
 };
117 114
 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
-				       };
115
+INT_INFO counter_c_hashes_body_iinfo = { 2,
116
+	{INT_TYPE_32BIT, INT_TYPE_16BIT},
117
+	{0, sizeof(time_t)}
118
+	,
119
+	{1, 1}
120
+};
123 121
 
124 122
 /*
125 123
  * counter_c
@@ -128,22 +126,21 @@ INT_INFO counter_c_hashes_body_iinfo = { 2,
128 126
  * All the infos regarding a particular register_node are stored here. For
129 127
  * example, we need to know how many hostnames he already registered.
130 128
  */
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 */
129
+struct counter_c {
130
+	LLIST_HDR(struct counter_c);
131
+
132
+	char pubkey[ANDNA_PKEY_LEN];
133
+	char flags;
134
+
135
+	u_short hashes;				/* The number of hashes in cch */
136
+	counter_c_hashes *cch;		/* The hashes of the hnames */
140 137
 };
141 138
 typedef struct counter_c counter_c;
142 139
 INT_INFO counter_c_body_iinfo = { 1,
143
-				  { INT_TYPE_16BIT },
144
-				  { ANDNA_PKEY_LEN+sizeof(char) },
145
-				  { 1 }
146
-				};
140
+	{INT_TYPE_16BIT},
141
+	{ANDNA_PKEY_LEN + sizeof(char)},
142
+	{1}
143
+};
147 144
 
148 145
 /*
149 146
  * lcl_cache_keyring
@@ -151,15 +148,14 @@ INT_INFO counter_c_body_iinfo = { 1,
151 148
  * The lcl keyring is used to store the RSA keys used to complete some of the
152 149
  * ANDNA requests, (f.e. registering or updating a hname).
153 150
  */
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 */
151
+typedef struct {
152
+	u_int skey_len;
153
+	u_int pkey_len;
154
+
155
+	u_char *privkey;			/* secret key packed */
156
+	u_char *pubkey;				/* pubkey packed */
157
+
158
+	RSA *priv_rsa;				/* key pair unpacked */
163 159
 } lcl_cache_keyring;
164 160
 
165 161
 
@@ -169,24 +165,23 @@ typedef struct
169 165
  * The Local Andna Cache keeps all the hostnames which have been register by
170 166
  * localhost (ourself).
171 167
  */
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;
168
+struct lcl_cache {
169
+	LLIST_HDR(struct lcl_cache);
170
+
171
+	char *hostname;				/* The registered hostname */
172
+	u_int hash;					/* 32bit hash of the md5 hash 
173
+								   of the hname */
174
+	u_short hname_updates;		/* How many updates we've done 
175
+								   for this hostname */
176
+	time_t timestamp;			/* the last time when the hname
177
+								   was updated. If it is 0, the
178
+								   hname has still to be 
179
+								   registered */
180
+
181
+	u_short snsd_counter;		/* # of `snsds' */
182
+	snsd_service *service;
183
+
184
+	char flags;
190 185
 };
191 186
 typedef struct lcl_cache lcl_cache;
192 187
 
@@ -205,21 +200,20 @@ typedef struct lcl_cache lcl_cache;
205 200
  * removed to empty new space.
206 201
  * The hname which have the `timestamp' expired are removed too.
207 202
  */
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;
203
+struct resolved_hnames_cache {
204
+	LLIST_HDR(struct resolved_hnames_cache);
205
+
206
+	u_int hash;					/* 32bit hash of the md5 hash of the
207
+								   hname */
208
+	char flags;
209
+
210
+	time_t timestamp;			/* the last time when the hname
211
+								   was updated. With this we know that
212
+								   at timestamp+ANDNA_EXPIRATION_TIME
213
+								   this cache will expire. */
214
+
215
+	u_short snsd_counter;
216
+	snsd_service *service;
223 217
 };
224 218
 typedef struct resolved_hnames_cache rh_cache;
225 219
 
@@ -252,22 +246,23 @@ int rhc_counter;
252 246
  *  * * * lcl cache package * * *
253 247
  */
254 248
 
255
-struct lcl_keyring_pkt_hdr
256
-{
257
-	u_int		skey_len;
258
-	u_int		pkey_len;
259
-}_PACKED_;
249
+struct lcl_keyring_pkt_hdr {
250
+	u_int skey_len;
251
+	u_int pkey_len;
252
+} _PACKED_;
260 253
 /* 
261 254
  * the rest of the pkt is:
262 255
  * 
263 256
  *	char		privkey[hdr.skey_len];
264 257
  *	char		pubkey[hdr.pkey_len];
265 258
  */
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
-				   };
259
+INT_INFO lcl_keyring_pkt_hdr_iinfo = { 2,
260
+	{INT_TYPE_32BIT, INT_TYPE_32BIT},
261
+	{0, sizeof(u_int)}
262
+	,
263
+	{1, 1}
264
+};
265
+
271 266
 #define LCL_KEYRING_HDR_PACK_SZ(khdr)	(sizeof(struct lcl_keyring_pkt_hdr) + \
272 267
 					(khdr)->skey_len + (khdr)->pkey_len)
273 268
 
@@ -275,14 +270,14 @@ INT_INFO lcl_keyring_pkt_hdr_iinfo = { 2,
275 270
  * The local cache pkt is used to pack the entire local cache to save it in a 
276 271
  * file or to send it to a node.
277 272
  */
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 } };
273
+struct lcl_cache_pkt_hdr {
274
+	u_short tot_caches;			/* How many lcl structs there 
275
+								   are in the pkt's body */
276
+} _PACKED_;
277
+INT_INFO lcl_cache_pkt_hdr_iinfo = { 1, {INT_TYPE_16BIT}, {0}, {1} };
278
+
284 279
 #define LCL_CACHE_HDR_PACK_SZ		(sizeof(struct lcl_cache_pkt_hdr))
285
-		
280
+
286 281
 /* 
287 282
  * The body is:
288 283
  *	
@@ -295,10 +290,11 @@ INT_INFO lcl_cache_pkt_hdr_iinfo = { 1, { INT_TYPE_16BIT }, { 0 }, { 1 } };
295 290
  */
296 291
 #define LCL_CACHE_BODY_PACK_SZ(hname_len) 	((hname_len) + sizeof(u_short) \
297 292
 						  + 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
-				    };
293
+INT_INFO lcl_cache_pkt_body_iinfo = { 2, {INT_TYPE_16BIT, INT_TYPE_32BIT},
294
+{0, sizeof(u_short)}
295
+,
296
+{1, 1}
297
+};
302 298
 
303 299
 /*
304 300
  *  * * * andna cache package * * *
@@ -316,20 +312,23 @@ INT_INFO lcl_cache_pkt_body_iinfo = { 2, { INT_TYPE_16BIT, INT_TYPE_32BIT },
316 312
  * };
317 313
  */
318 314
 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
-			  };
315
+	{INT_TYPE_32BIT, INT_TYPE_16BIT, INT_TYPE_16BIT}
316
+	,
317
+	{0, sizeof(time_t),
318
+	 sizeof(time_t) + sizeof(u_short) + ANDNA_PKEY_LEN}
319
+	,
320
+	{1, 1, 1}
321
+};
322
+
324 323
 #define ACQ_BODY_PACK_SZ		(sizeof(time_t) + sizeof(u_short)*2 + \
325 324
 					 ANDNA_PKEY_LEN)
326 325
 #define ACQ_PACK_SZ(snsd_pack_sz)	(ACQ_BODY_PACK_SZ + (snsd_pack_sz))
327 326
 
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 } };
327
+struct andna_cache_pkt_hdr {
328
+	u_short tot_caches;
329
+} _PACKED_;
330
+INT_INFO andna_cache_pkt_hdr_iinfo = { 1, {INT_TYPE_16BIT}, {0}, {1} };
331
+
333 332
 /*
334 333
  * The body is:
335 334
  * struct andna_cache_pack {
@@ -339,11 +338,12 @@ INT_INFO andna_cache_pkt_hdr_iinfo = { 1, { INT_TYPE_16BIT }, { 0 }, { 1 } };
339 338
  * 	char		acq_pack[ACQ_PACK_SZ*queue_counter];
340 339
  * } acache_pack[hdr.tot_caches];
341 340
  */
342
-INT_INFO andna_cache_body_iinfo = { 1, 
343
-				    { INT_TYPE_16BIT },
344
-				    { MAX_IP_SZ+sizeof(char) },
345
-				    { 1 }
346
-				  };
341
+INT_INFO andna_cache_body_iinfo = { 1,
342
+	{INT_TYPE_16BIT},
343
+	{MAX_IP_SZ + sizeof(char)},
344
+	{1}
345
+};
346
+
347 347
 #define ACACHE_BODY_PACK_SZ		(ANDNA_HASH_SZ + sizeof(char) + 	\
348 348
 					   sizeof(u_short))
349 349
 #define ACACHE_PACK_SZ(acq_pack_sz)	((acq_pack_sz) + ACACHE_BODY_PACK_SZ)
@@ -368,11 +368,11 @@ INT_INFO andna_cache_body_iinfo = { 1,
368 368
  * The counter cache pkt is similar to the andna_cache_pkt, it is completely
369 369
  * arranged in the same way.
370 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 } };
371
+struct counter_c_pkt_hdr {
372
+	u_short tot_caches;
373
+} _PACKED_;
374
+INT_INFO counter_c_pkt_hdr_iinfo = { 1, {INT_TYPE_16BIT}, {0}, {1} };
375
+
376 376
 #define COUNTER_CACHE_HASHES_PACK_SZ	(sizeof(time_t) + sizeof(u_short) +	\
377 377
 						ANDNA_HASH_SZ)
378 378
 #define COUNTER_CACHE_BODY_PACK_SZ	(ANDNA_PKEY_LEN + sizeof(char)    + 	\
@@ -384,12 +384,12 @@ INT_INFO counter_c_pkt_hdr_iinfo = { 1, { INT_TYPE_16BIT }, { 0 }, { 1 } };
384 384
  *  * * * Resolved hostnames cache pkt. * * *
385 385
  */
386 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 } };
387
+struct rh_cache_pkt_hdr {
388
+	u_short tot_caches;			/* How many lcl structs there 
389
+								   are in the pkt's hdr */
390
+} _PACKED_;
391
+INT_INFO rh_cache_pkt_hdr_iinfo = { 1, {INT_TYPE_16BIT}, {0}, {1} };
392
+
393 393
 /*
394 394
  * The body is:
395 395
  * struct rh_cache_pkt_body {
@@ -405,11 +405,12 @@ INT_INFO rh_cache_pkt_hdr_iinfo = { 1, { INT_TYPE_16BIT }, { 0 }, { 1 } };
405 405
 						 sizeof(time_t)+sizeof(u_short)+\
406 406
 						 (snsd_pack_sz))
407 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
-				   };
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
+	,
412
+	{1, 1, 1}
413
+};
413 414
 
414 415
 
415 416
 /*
@@ -418,35 +419,35 @@ INT_INFO rh_cache_pkt_body_iinfo = { 3,
418 419
 
419 420
 void andna_caches_init(int family);
420 421
 
421
-void lcl_new_keyring(lcl_cache_keyring *keyring);
422
-void lcl_destroy_keyring(lcl_cache_keyring *keyring);
422
+void lcl_new_keyring(lcl_cache_keyring * keyring);
423
+void lcl_destroy_keyring(lcl_cache_keyring * keyring);
423 424
 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);
425
+void lcl_cache_free(lcl_cache * alcl);
426
+void lcl_cache_destroy(lcl_cache * head, int *counter);
427
+lcl_cache *lcl_cache_find_hname(lcl_cache * head, char *hname);
428
+lcl_cache *lcl_cache_find_hash(lcl_cache * alcl, u_int hash);
429
+lcl_cache *lcl_get_registered_hnames(lcl_cache * alcl);
430
+
431
+andna_cache_queue *ac_queue_findpubk(andna_cache * ac, char *pubk);
432
+andna_cache_queue *ac_queue_add(andna_cache * ac, char *pubkey);
433
+void ac_queue_del(andna_cache * ac, andna_cache_queue * acq);
434
+void ac_queue_del_expired(andna_cache * ac);
435
+void ac_queue_destroy(andna_cache * ac);
435 436
 andna_cache *andna_cache_findhash(int hash[MAX_IP_INT]);
436 437
 andna_cache *andna_cache_gethash(int hash[MAX_IP_INT]);
437 438
 andna_cache *andna_cache_addhash(int hash[MAX_IP_INT]);
438
-int andna_cache_del_ifexpired(andna_cache *ac);
439
+int andna_cache_del_ifexpired(andna_cache * ac);
439 440
 void andna_cache_del_expired(void);
440 441
 void andna_cache_destroy(void);
441 442
 
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]);
443
+counter_c_hashes *cc_hashes_add(counter_c * cc, int hash[MAX_IP_INT]);
444
+void cc_hashes_del(counter_c * cc, counter_c_hashes * cch);
445
+int counter_c_del_ifexpired(counter_c * cc);
446
+void cc_hashes_del_expired(counter_c * cc);
447
+void cc_hashes_destroy(counter_c * cc);
448
+counter_c_hashes *cc_findhash(counter_c * cc, int hash[MAX_IP_INT]);
448 449
 counter_c *counter_c_findpubk(char *pubk);
449
-counter_c *counter_c_add(inet_prefix *rip, char *pubkey);
450
+counter_c *counter_c_add(inet_prefix * rip, char *pubkey);
450 451
 void counter_c_del_expired(void);
451 452
 void counter_c_destroy(void);
452 453
 
@@ -455,45 +456,48 @@ rh_cache *rh_cache_add_hash(u_int hash, time_t timestamp);
455 456
 rh_cache *rh_cache_add(char *hname, time_t timestamp);
456 457
 rh_cache *rh_cache_find_hash(u_int hash);
457 458
 rh_cache *rh_cache_find_hname(char *hname);
458
-void rh_cache_del(rh_cache *rhc);
459
+void rh_cache_del(rh_cache * rhc);
459 460
 void rh_cache_del_expired(void);
460 461
 void rh_cache_flush(void);
461 462
 
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);
463
+char *pack_lcl_keyring(lcl_cache_keyring * keyring, size_t * pack_sz);
464
+int unpack_lcl_keyring(lcl_cache_keyring * keyring, char *pack,
465
+					   size_t pack_sz);
464 466
 
465
-char *pack_lcl_cache(lcl_cache *local_cache, size_t *pack_sz);
467
+char *pack_lcl_cache(lcl_cache * local_cache, size_t * pack_sz);
466 468
 lcl_cache *unpack_lcl_cache(char *pack, size_t pack_sz, int *counter);
467 469
 
468
-char *pack_andna_cache(andna_cache *acache, size_t *pack_sz, int pack_type);
470
+char *pack_andna_cache(andna_cache * acache, size_t * pack_sz,
471
+					   int pack_type);
469 472
 andna_cache *unpack_andna_cache(char *pack, size_t pack_sz, int *counter,
470
-				int pack_type);
473
+								int pack_type);
471 474
 
472
-char *pack_counter_cache(counter_c *countercache,  size_t *pack_sz);
475
+char *pack_counter_cache(counter_c * countercache, size_t * pack_sz);
473 476
 counter_c *unpack_counter_cache(char *pack, size_t pack_sz, int *counter);
474 477
 
475
-char *pack_rh_cache(rh_cache *rhcache, size_t *pack_sz);
478
+char *pack_rh_cache(rh_cache * rhcache, size_t * pack_sz);
476 479
 rh_cache *unpack_rh_cache(char *pack, size_t pack_sz, int *counter);
477 480
 
478
-int save_lcl_keyring(lcl_cache_keyring *keyring, char *file);
479
-int load_lcl_keyring(lcl_cache_keyring *keyring, char *file);
481
+int save_lcl_keyring(lcl_cache_keyring * keyring, char *file);
482
+int load_lcl_keyring(lcl_cache_keyring * keyring, char *file);
480 483
 
481
-int save_lcl_cache(lcl_cache *lcl, char *file);
484
+int save_lcl_cache(lcl_cache * lcl, char *file);
482 485
 lcl_cache *load_lcl_cache(char *file, int *counter);
483 486
 
484
-int save_andna_cache(andna_cache *acache, char *file);
487
+int save_andna_cache(andna_cache * acache, char *file);
485 488
 andna_cache *load_andna_cache(char *file, int *counter);
486 489
 
487
-int save_counter_c(counter_c *countercache, char *file);
490
+int save_counter_c(counter_c * countercache, char *file);
488 491
 counter_c *load_counter_c(char *file, int *counter);
489 492
 
490
-int save_rh_cache(rh_cache *rh, char *file);
493
+int save_rh_cache(rh_cache * rh, char *file);
491 494
 rh_cache *load_rh_cache(char *file, int *counter);
492 495
 
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);
496
+int load_hostnames(char *file, lcl_cache ** old_alcl_head,
497
+				   int *old_alcl_counter);
498
+int load_snsd(char *file, lcl_cache * alcl_head);
495 499
 
496 500
 int add_resolv_conf(char *hname, char *file);
497 501
 int del_resolv_conf(char *hname, char *file);
498 502
 
499
-#endif		/*ANDNA_CACHE_H*/
503
+#endif							/*ANDNA_CACHE_H */

+ 546
- 521
src/andns.c
File diff suppressed because it is too large
View File


+ 21
- 21
src/andns.h View File

@@ -1,4 +1,4 @@
1
-	         /**************************************
1
+			 /**************************************
2 2
 	        *     AUTHOR: Federico Tomassini        *
3 3
 	       *     Copyright (C) Federico Tomassini    *
4 4
 	      *     Contact effetom@gmail.com	          *
@@ -30,7 +30,7 @@
30 30
 #define ANDNS_TIMEOUT		15
31 31
 
32 32
 #define MAXNSSERVERS 		3
33
-#define DNS_REPLY_TIMEOUT       10      /* seconds */
33
+#define DNS_REPLY_TIMEOUT       10	/* seconds */
34 34
 
35 35
 #define DNS_PORT		53
36 36
 #define DNS_PORT_STR		"53"
@@ -50,7 +50,7 @@
50 50
 #define NK_INET			2
51 51
 #define GET_NK_BIT(msg)		(*((msg+3))>>4)&0x03
52 52
 
53
-#define RCODE_NOERR		0	
53
+#define RCODE_NOERR		0
54 54
 #define RCODE_EINTRPRT		1
55 55
 #define RCODE_ESRVFAIL		2
56 56
 #define RCODE_ENSDMN 		3
@@ -64,23 +64,23 @@
64 64
 int store_ns(char *ns);
65 65
 int collect_resolv_conf(char *resolve_conf);
66 66
 void reset_andns_ns(void);
67
-int andns_init(int restricted, char *resolv_conf,int family);
67
+int andns_init(int restricted, char *resolv_conf, int family);
68 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);
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 85
 
86
-#endif /* ANDNS_H */
86
+#endif							/* ANDNS_H */

+ 457
- 419
src/andns_lib.c
File diff suppressed because it is too large
View File


+ 55
- 56
src/andns_lib.h View File

@@ -1,4 +1,4 @@
1
-                 /**************************************
1
+				 /**************************************
2 2
                 *     AUTHOR: Federico Tomassini        *
3 3
                *     Copyright (C) Federico Tomassini    *
4 4
               *     Contact effetom@gmail.com             *
@@ -25,7 +25,7 @@
25 25
 #include <stdint.h>
26 26
 #include <sys/types.h>
27 27
 
28
-#define ANDNS_MAX_QUESTION_LEN	263 /* TODO */
28
+#define ANDNS_MAX_QUESTION_LEN	263	/* TODO */
29 29
 #define ANDNS_MAX_ANSWER_LEN	516
30 30
 #define ANDNS_MAX_ANSWERS_NUM	256
31 31
 #define ANDNS_MAX_PK_LEN	ANDNS_MAX_QUESTION_LEN+\
@@ -42,15 +42,14 @@
42 42
 #define ANDNS_COMPR_LEVEL	Z_BEST_COMPRESSION
43 43
 #define ANDNS_COMPR_THRESHOLD	1000
44 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;
45
+struct andns_pkt_data {
46
+	uint8_t m;
47
+	uint8_t wg;
48
+	uint8_t prio;
49
+	uint16_t rdlength;
50
+	uint16_t service;
51
+	char *rdata;
52
+	struct andns_pkt_data *next;
54 53
 };
55 54
 typedef struct andns_pkt_data andns_pkt_data;
56 55
 #define ANDNS_PKT_DATA_SZ sizeof(andns_pkt_data)
@@ -61,22 +60,21 @@ typedef struct andns_pkt_data andns_pkt_data;
61 60
 #define APD_TCP		1<<2
62 61
 #define APD_UDP		1<<3
63 62
 
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;
63
+typedef struct andns_pkt {
64
+	uint16_t id;
65
+	uint8_t r;
66
+	uint8_t qr;
67
+	uint8_t p;
68
+	uint8_t z;
69
+	uint8_t qtype;
70
+	uint16_t ancount;
71
+	uint8_t ipv;
72
+	uint8_t nk;
73
+	uint8_t rcode;
74
+	uint16_t service;
75
+	uint16_t qstlength;
76
+	char *qstdata;
77
+	andns_pkt_data *pkt_answ;
80 78
 } andns_pkt;
81 79
 #define ANDNS_PKT_SZ sizeof(andns_pkt)
82 80
 #define AP_ALIGN(ap)	(ap)->qstdata=(char*)xmalloc((ap)->qstlength)
@@ -96,16 +94,16 @@ typedef struct andns_pkt
96 94
 #define ANDNS_PROTO_TCP	0
97 95
 #define ANDNS_PROTO_UDP	1
98 96
 /* ANDNS QUERY-TYPE */
99
-#define AT_A            0 /* h->ip */
100
-#define AT_PTR          1 /* ip->h */
101
-#define AT_G          	2 /* global */
97
+#define AT_A            0		/* h->ip */
98
+#define AT_PTR          1		/* ip->h */
99
+#define AT_G          	2		/* global */
102 100
 /* 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 */
101
+#define ANDNS_RCODE_NOERR     0	/* No error */
102
+#define ANDNS_RCODE_EINTRPRT  1	/* Intepret error */
103
+#define ANDNS_RCODE_ESRVFAIL  2	/* Server failure */
104
+#define ANDNS_RCODE_ENSDMN    3	/* No such domain */
105
+#define ANDNS_RCODE_ENIMPL    4	/* Not implemented */
106
+#define ANDNS_RCODE_ERFSD     5	/* Refused */
109 107
 /* REALMS TO SEARCH */
110 108
 #define NTK_REALM               1
111 109
 #define INET_REALM              2
@@ -113,24 +111,25 @@ typedef struct andns_pkt
113 111
 #define ANDNS_IPV4		0
114 112
 #define ANDNS_IPV6		1
115 113
 
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);
114
+int andns_compress(char *src, int srclen);
115
+char *andns_uncompress(char *src, int srclen, int *dstlen);
116
+int a_hdr_u(char *buf, andns_pkt * ap);
117
+int a_qst_u(char *buf, andns_pkt * ap, int limitlen);
118
+int a_answ_u(char *buf, andns_pkt * ap, int limitlen);
119
+int a_answs_u(char *buf, andns_pkt * ap, int limitlen);
120
+int a_u(char *buf, int pktlen, andns_pkt ** app);
121
+int a_hdr_p(andns_pkt * ap, char *buf);
122
+int a_qst_p(andns_pkt * ap, char *buf, int limitlen);
123
+int a_answ_p(andns_pkt * ap, andns_pkt_data * apd, char *buf,
124
+			 int limitlen);
125
+int a_answs_p(andns_pkt * ap, char *buf, int limitlen);
126
+int a_p(andns_pkt * ap, char *buf);
127
+andns_pkt *create_andns_pkt(void);
128
+andns_pkt_data *create_andns_pkt_data(void);
129
+andns_pkt_data *andns_add_answ(andns_pkt * ap);
130
+void destroy_andns_pkt_data(andns_pkt_data * apd);
131
+void andns_del_answ(andns_pkt * ap);
132
+void destroy_andns_pkt_datas(andns_pkt * ap);
133
+void destroy_andns_pkt(andns_pkt * ap);
135 134
 
136
-#endif /* ANDNS_LIB_H */
135
+#endif							/* ANDNS_LIB_H */

+ 140
- 118
src/andns_net.c View File

@@ -1,4 +1,4 @@
1
-	         /**************************************
1
+			 /**************************************
2 2
 	        *     AUTHOR: Federico Tomassini        *
3 3
 	       *     Copyright (C) Federico Tomassini    *
4 4
 	      *     Contact effetom@gmail.com             *
@@ -21,116 +21,128 @@
21 21
 #include "log.h"
22 22
 #include "andns_net.h"
23 23
 
24
-int idp_inet_ntop(int family,struct sockaddr *addr,char *buf,int buflen)
24
+int
25
+idp_inet_ntop(int family, struct sockaddr *addr, char *buf, int buflen)
25 26
 {
26 27
 	const char *res;
27 28
 	struct sockaddr_in *saddr;
28 29
 	struct sockaddr_in6 *saddr6;
29 30
 
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;
31
+	switch (family) {
32
+	case AF_INET:
33
+		saddr = (struct sockaddr_in *) addr;
34
+		res =
35
+			inet_ntop(family, (void *) (&(saddr->sin_addr)), buf, buflen);
36
+		break;
37
+	case AF_INET6:
38
+		saddr6 = (struct sockaddr_in6 *) addr;
39
+		res =
40
+			inet_ntop(family, (void *) (&(saddr6->sin6_addr)), buf,
41
+					  buflen);
42
+		break;
43
+	default:
44
+		return -1;
41 45
 	}
42 46
 	if (!res)
43 47
 		return -1;
44 48
 	return 0;
45 49
 }
50
+
46 51
 /* Connection Layer */
47 52
 
48
-int w_socket(int family,int type, int proto,int die)
53
+int
54
+w_socket(int family, int type, int proto, int die)
49 55
 {
50 56
 	int sk;
51
-	sk=socket(family,type,proto);
52
-	if (sk==-1) {
57
+	sk = socket(family, type, proto);
58
+	if (sk == -1) {
53 59
 		if (die)
54
-			fatal("w_socket: %s.",strerror(errno));
55
-		debug(DBG_NORMAL,"w_socket: %s.",strerror(errno));
60
+			fatal("w_socket: %s.", strerror(errno));
61
+		debug(DBG_NORMAL, "w_socket: %s.", strerror(errno));
56 62
 		return -1;
57 63
 	}
58 64
 	return sk;
59 65
 }
60 66
 
61
-int w_connect(struct addrinfo *ai,int die) 
67
+int
68
+w_connect(struct addrinfo *ai, int die)
62 69
 {
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) 
70
+	int sk, res;
71
+	sk = w_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol, die);
72
+	res = connect(sk, ai->ai_addr, ai->ai_addrlen);
73
+	if (!res)
67 74
 		return sk;
68 75
 	if (die)
69 76
 		fatal("Unable to connect: %s.", strerror(errno));
70
-	debug(DBG_NORMAL,"w_connect: %s.",strerror(errno));
77
+	debug(DBG_NORMAL, "w_connect: %s.", strerror(errno));
71 78
 	close(sk);
72 79
 	return -1;
73 80
 }
74
-int serial_connect(struct addrinfo *ai,int die)
81
+
82
+int
83
+serial_connect(struct addrinfo *ai, int die)
75 84
 {
76 85
 	int res;
77 86
 	struct addrinfo *temp;
78 87
 
79
-	temp=ai;
88
+	temp = ai;
80 89
 	if (!temp) {
81 90
 		if (die)
82 91
 			fatal("Unable to connect: no host specified.");
83
-		debug(DBG_NORMAL,"serial_connect: no host specified.");
92
+		debug(DBG_NORMAL, "serial_connect: no host specified.");
84 93
 		return -1;
85 94
 	}
86 95
 	do {
87
-		res=w_connect(temp,0);
88
-		temp=temp->ai_next;
89
-	} while (res==-1 && temp);
90
-	if (res==-1)  {
96
+		res = w_connect(temp, 0);
97
+		temp = temp->ai_next;
98
+	} while (res == -1 && temp);
99
+	if (res == -1) {
91 100
 		if (die)
92 101
 			fatal("Unable to connect.");
93
-		debug(DBG_NORMAL,"serial_connect: unable to connect.");
102
+		debug(DBG_NORMAL, "serial_connect: unable to connect.");
94 103
 		return -1;
95 104
 	}
96 105
 	return res;
97 106
 }
98
-	
107
+
99 108
 /*
100 109
  * host_connect returns a connected socket to (host,port)
101 110
  * endpoint. It is protocol independent.
102 111
  * -1 on error.
103 112
  */
104
-int host_connect(const char *host,uint16_t port,int type,int die) 
113
+int
114
+host_connect(const char *host, uint16_t port, int type, int die)
105 115
 {
106 116
 	int res;
107 117
 	char portstr[6];
108
-	struct addrinfo *ai,filter;
118
+	struct addrinfo *ai, filter;
109 119
 
110
-	memset(&filter,0,sizeof(struct addrinfo));
111
-	filter.ai_socktype=type;
120
+	memset(&filter, 0, sizeof(struct addrinfo));
121
+	filter.ai_socktype = type;
112 122
 	if (!host)
113 123
 		fatal("w_connect: malicious call.");
114
-	memset(portstr,0,6);
115
-	res=snprintf(portstr,6,"%d",port);
116
-	if (res<0 || res>=6) {
124
+	memset(portstr, 0, 6);
125
+	res = snprintf(portstr, 6, "%d", port);
126
+	if (res < 0 || res >= 6) {
117 127
 		printf("Depousceve\n");
118 128
 		return -1;
119 129
 	}
120
-	res=getaddrinfo(host,portstr,&filter,&ai);
121
-	if (res!=0) {
122
-		printf("w_connect: error %s.\n",gai_strerror(errno));
130
+	res = getaddrinfo(host, portstr, &filter, &ai);
131
+	if (res != 0) {
132
+		printf("w_connect: error %s.\n", gai_strerror(errno));
123 133
 		return -1;
124 134
 	}
125
-	res=serial_connect(ai,die);
135
+	res = serial_connect(ai, die);
126 136
 	freeaddrinfo(ai);
127 137
 	return res;
128 138
 }
129
-int ai_connect(struct addrinfo *ai,int die,int free_ai)
139
+
140
+int
141
+ai_connect(struct addrinfo *ai, int die, int free_ai)
130 142
 {
131 143
 	int res;
132 144
 
133
-	res=serial_connect(ai,die);
145
+	res = serial_connect(ai, die);
134 146
 	if (free_ai)
135 147
 		freeaddrinfo(ai);
136 148
 	return res;
@@ -138,28 +150,30 @@ int ai_connect(struct addrinfo *ai,int die,int free_ai)
138 150
 
139 151
 /* Communication Layer */
140 152
 
141
-ssize_t w_send(int sk,const void *buf,size_t len,int die) 
153
+ssize_t
154
+w_send(int sk, const void *buf, size_t len, int die)
142 155
 {
143 156
 	ssize_t ret;
144 157
 
145
-	ret=send(sk,buf,len,0);
146
-	if (ret!=len) {
158
+	ret = send(sk, buf, len, 0);
159
+	if (ret != len) {
147 160
 		if (die)
148
-			fatal("Unable to send(): %s.",strerror(errno));
149
-		debug(DBG_NORMAL,"w_send(): %s.",strerror(errno));
161
+			fatal("Unable to send(): %s.", strerror(errno));
162
+		debug(DBG_NORMAL, "w_send(): %s.", strerror(errno));
150 163
 	}
151 164
 	return ret;
152 165
 }
153 166
 
154
-ssize_t w_recv(int sk,void *buf,size_t len,int die)
167
+ssize_t
168
+w_recv(int sk, void *buf, size_t len, int die)
155 169
 {
156 170
 	ssize_t ret;
157 171
 
158
-	ret=recv(sk,buf,len,0);
159
-	if (ret<=0) {
172
+	ret = recv(sk, buf, len, 0);
173
+	if (ret <= 0) {
160 174
 		if (die)
161
-			fatal("Unable to recv(): %s.",strerror(errno));
162
-		debug(DBG_INSANE,"w_recv(): %s.",strerror(errno));
175
+			fatal("Unable to recv(): %s.", strerror(errno));
176
+		debug(DBG_INSANE, "w_recv(): %s.", strerror(errno));
163 177
 	}
164 178
 	return ret;
165 179
 }
@@ -177,121 +191,129 @@ do{                                                                     \
177 191
         (t).tv_usec=((x) - ((x)/1000)*1000)*1000;                       \
178 192
 }while(0)
179 193
 
180
-ssize_t w_send_timeout(int s,const void *buf,size_t len,int die,int timeout)
194
+ssize_t
195
+w_send_timeout(int s, const void *buf, size_t len, int die, int timeout)
181 196
 {
182
-        struct timeval timeout_t;
183
-        fd_set fdset;
184
-        int ret;
197
+	struct timeval timeout_t;
198
+	fd_set fdset;
199
+	int ret;
185 200
 
186
-        MILLISEC_TO_TV(timeout*1000, timeout_t);
201
+	MILLISEC_TO_TV(timeout * 1000, timeout_t);
187 202
 
188
-        FD_ZERO(&fdset);
189
-        FD_SET(s, &fdset);
203
+	FD_ZERO(&fdset);
204
+	FD_SET(s, &fdset);
190 205
 
191
-        ret = select(s+1, &fdset, NULL, NULL, &timeout_t);
192
-        if (ret == -1) {
206
+	ret = select(s + 1, &fdset, NULL, NULL, &timeout_t);
207
+	if (ret == -1) {
193 208
 		if (die)
194 209
 			fatal("send(): select error.");
195
-		debug(DBG_NORMAL,"send(): select error.");
210
+		debug(DBG_NORMAL, "send(): select error.");
196 211
 		return ret;
197
-        }
212
+	}
198 213
 
199
-        if(FD_ISSET(s, &fdset))
200
-                return w_send(s, buf, len, die);
201
-        return -1;
214
+	if (FD_ISSET(s, &fdset))
215
+		return w_send(s, buf, len, die);
216
+	return -1;
202 217
 }
203 218
 
204
-ssize_t w_recv_timeout(int s,void *buf,size_t len,int die,int timeout)
219
+ssize_t
220
+w_recv_timeout(int s, void *buf, size_t len, int die, int timeout)
205 221
 {
206
-        struct timeval timeout_t;
207
-        fd_set fdset;
208
-        int ret;
222
+	struct timeval timeout_t;
223
+	fd_set fdset;
224
+	int ret;
209 225
 
210
-        MILLISEC_TO_TV(timeout*1000, timeout_t);
226
+	MILLISEC_TO_TV(timeout * 1000, timeout_t);
211 227
 
212
-        FD_ZERO(&fdset);
213
-        FD_SET(s, &fdset);
228
+	FD_ZERO(&fdset);
229
+	FD_SET(s, &fdset);
214 230
 
215
-        ret = select(s+1, NULL, &fdset, NULL, &timeout_t);
231
+	ret = select(s + 1, NULL, &fdset, NULL, &timeout_t);
216 232
 
217
-        if (ret == -1) {
233
+	if (ret == -1) {
218 234
 		if (die)
219 235
 			fatal("recv(): select error.");
220
-		debug(DBG_NORMAL,"recv(): select error.");
236
+		debug(DBG_NORMAL, "recv(): select error.");
221 237
 		return ret;
222
-        }
238
+	}
223 239
 
224
-        if(FD_ISSET(s, &fdset))
225
-                return w_recv(s, buf, len, die);
226
-        return -1;
240
+	if (FD_ISSET(s, &fdset))
241
+		return w_recv(s, buf, len, die);
242
+	return -1;
227 243
 }
228 244
 
229 245
 
230
-	
246
+
231 247
 /* Dialog Layer */
232 248
 
233 249
 /* "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)
250
+ssize_t
251
+hn_send_recv_close(const char *host, uint16_t port, int type, void *buf,
252
+				   size_t buflen, void *anbuf, size_t anlen, int die,
253
+				   int timeout)
236 254
 {
237 255
 	ssize_t ret;
238 256
 	int res;
239 257
 
240
-	res=host_connect(host,port,type,die);
241
-	if (res==-1) 
258
+	res = host_connect(host, port, type, die);
259
+	if (res == -1)
242 260
 		return -1;
243 261
 	if (timeout)
244
-		ret=w_send_timeout(res,buf,buflen,die,timeout);
262
+		ret = w_send_timeout(res, buf, buflen, die, timeout);
245 263
 	else
246
-		ret=w_send(res,buf,buflen,die);
247
-	if (ret==-1) 
264
+		ret = w_send(res, buf, buflen, die);
265
+	if (ret == -1)
248 266
 		return -2;
249 267
 	if (timeout)
250
-		ret=w_recv_timeout(res,anbuf,anlen,die,timeout);
268
+		ret = w_recv_timeout(res, anbuf, anlen, die, timeout);
251 269
 	else
252
-		ret=w_recv(res,anbuf,anlen,die);
253
-	if (ret==-1)
270
+		ret = w_recv(res, anbuf, anlen, die);
271
+	if (ret == -1)
254 272
 		return -3;
255 273
 	close(res);
256 274
 	return ret;
257 275
 }
276
+
258 277
 /* "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)
278
+ssize_t
279
+ai_send_recv_close(struct addrinfo * ai, void *buf, size_t buflen,
280
+				   void *anbuf, size_t anlen, int die, int free_ai,
281
+				   int timeout)
261 282
 {
262 283
 	ssize_t ret;
263 284
 	int res;
264 285
 
265
-	res=ai_connect(ai,die,free_ai);
266
-	if (res==-1) 
286
+	res = ai_connect(ai, die, free_ai);
287
+	if (res == -1)
267 288
 		return -1;
268 289
 	if (timeout)
269
-		ret=w_send_timeout(res,buf,buflen,die,timeout);
290
+		ret = w_send_timeout(res, buf, buflen, die, timeout);
270 291
 	else
271
-		ret=w_send(res,buf,buflen,die);
272
-	if (ret==-1) 
292
+		ret = w_send(res, buf, buflen, die);
293
+	if (ret == -1)
273 294
 		return -2;
274 295
 	if (timeout)
275
-		ret=w_recv_timeout(res,anbuf,anlen,die,timeout);
296
+		ret = w_recv_timeout(res, anbuf, anlen, die, timeout);
276 297
 	else
277
-		ret=w_recv(res,anbuf,anlen,die);
278
-	if (ret==-1) 
298
+		ret = w_recv(res, anbuf, anlen, die);
299
+	if (ret == -1)
279 300
 		return -3;
280 301
 	close(res);
281 302
 	return ret;
282 303
 }
283
-	
284
-void char_print(char *buf, int len)
304
+
305
+void
306
+char_print(char *buf, int len)
285 307
 {
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;
308
+	int i, count = 0;
309
+
310
+	printf("Printing %d bytes\n", len);
311
+	for (i = 0; i < len; i++) {
312
+		printf("%02X ", (unsigned char) (buf[i]));
313
+		count++;
314
+		if ((count % 16) == 0)
315
+			printf("\n");
316
+	}
317
+	printf("\n");
318
+	return;
296 319
 }
297
-

+ 39
- 15
src/andns_net.h View File

@@ -1,3 +1,23 @@
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
+
1 21
 #ifndef ANDNS_NET_H
2 22
 #define ANDNS_NET_H
3 23
 
@@ -12,21 +32,25 @@
12 32
 
13 33
 
14 34
 
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);
35
+int idp_inet_ntop(int family, struct sockaddr *addr, char *buf,
36
+				  int buflen);
37
+int w_socket(int family, int type, int proto, int die);
38
+int w_connect(struct addrinfo *ai, int die);
39
+int serial_connect(struct addrinfo *ai, int die);
40
+int host_connect(const char *host, uint16_t port, int type, int die);
41
+int ai_connect(struct addrinfo *ai, int die, int free_ai);
42
+ssize_t w_send(int sk, const void *buf, size_t len, int die);
43
+ssize_t w_recv(int sk, void *buf, size_t len, int die);
44
+ssize_t w_send_timeout(int s, const void *buf, size_t len, int die,
45
+					   int timeout);
46
+ssize_t w_recv_timeout(int s, void *buf, size_t len, int die, int timeout);
47
+ssize_t ai_send_recv_close(struct addrinfo *ai, void *buf, size_t buflen,
48
+						   void *anbuf, size_t anlen, int die, int free_ai,
49
+						   int timeout);
50
+ssize_t hn_send_recv_close(const char *host, uint16_t port, int type,
51
+						   void *buf, size_t buflen, void *anbuf,
52
+						   size_t anlen, int die, int timeout);
29 53
 void char_print(char *buf, int len);
30 54
 
31 55
 
32
-#endif /* ANDNS_NET_H */
56
+#endif							/* ANDNS_NET_H */

+ 154
- 123
src/andns_snsd.c View File

@@ -1,3 +1,23 @@
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
+
1 21
 #include "includes.h"
2 22
 
3 23
 #include "llist.c"
@@ -19,32 +39,33 @@
19 39
  * 	0
20 40
  * 	-1
21 41
  */
22
-int snsd_main_ip(u_int *hname_hash,snsd_node *dst)
42
+int
43
+snsd_main_ip(u_int * hname_hash, snsd_node * dst)
23 44
 {
24 45
 	snsd_service *ss;
25 46
 	snsd_prio *sp;
26 47
 	snsd_node *sn;
27 48
 	int records;
28 49
 
29
-	ss=andna_resolve_hash(hname_hash,0,0,&records);
30
-	if (!ss) 
31
-		err_ret(ERR_SNDMRF,-1);
32
-	if (!(sp=ss->prio)) {
50
+	ss = andna_resolve_hash(hname_hash, 0, 0, &records);
51
+	if (!ss)
52
+		err_ret(ERR_SNDMRF, -1);
53
+	if (!(sp = ss->prio)) {
33 54
 		goto destroy_return;
34 55
 	}
35 56
 	list_for(sp) {
36
-		sn=sp->node;
37
-		list_for(sn) 
57
+		sn = sp->node;
58
+		list_for(sn)
38 59
 			if (sn->flags & SNSD_NODE_MAIN_IP) {
39
-				memcpy(dst,sn,sizeof(snsd_node));
40
-				snsd_service_llist_del(&ss);
41
-				return 0;
42
-			}
60
+			memcpy(dst, sn, sizeof(snsd_node));
61
+			snsd_service_llist_del(&ss);
62
+			return 0;
63
+		}
43 64
 	}
44 65
 	goto destroy_return;
45
-destroy_return:
66
+  destroy_return:
46 67
 	snsd_service_llist_del(&ss);
47
-	err_ret(ERR_SNDMRF,-1);
68
+	err_ret(ERR_SNDMRF, -1);
48 69
 }
49 70
 
50 71
 /*
@@ -56,34 +77,36 @@ destroy_return:
56 77
  * 	bytes writed
57 78
  * 	
58 79
  */
59
-int snsd_node_to_data(char *buf,snsd_node *sn,u_char prio,int iplen,int recursion)
80
+int
81
+snsd_node_to_data(char *buf, snsd_node * sn, u_char prio, int iplen,
82
+				  int recursion)
60 83
 {
61 84
 	int res;
62 85
 	int family;
63 86
 
64
-	if (recursion!=-1) {
65
-		*buf|=sn->weight&0x3f;
66
-		*(buf+1)|=prio;
87
+	if (recursion != -1) {
88
+		*buf |= sn->weight & 0x3f;
89
+		*(buf + 1) |= prio;
67 90
 	}
68 91
 
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);
92
+	if (!(sn->flags & SNSD_NODE_HNAME)) {
93
+		*buf |= 0x40;
94
+		if (sn->flags & SNSD_NODE_MAIN_IP)
95
+			*buf |= 0x80;
96
+		memcpy(buf + 2, sn->record, iplen);
97
+		family = (iplen == 4) ? AF_INET : AF_INET6;
98
+		inet_htonl((u_int *) (buf + 2), family);
99
+		return iplen + 2;
100
+	} else if (recursion) {
101
+		snsd_node snt;
102
+		res = snsd_main_ip(sn->record, &snt);
103
+		if (!res) {				/* I love recursion */
104
+			res = snsd_node_to_data(buf, &snt, prio, iplen, -1);
82 105
 			return res;
83 106
 		}
84 107
 	}
85
-	memcpy(buf+2,sn->record,ANDNS_HASH_H);
86
-	return ANDNS_HASH_H+2;
108
+	memcpy(buf + 2, sn->record, ANDNS_HASH_H);
109
+	return ANDNS_HASH_H + 2;
87 110
 }
88 111
 
89 112
 /*
@@ -125,30 +148,34 @@ size_t snsd_node_to_aansw(char *buf,snsd_node *sn,u_char prio,int iplen)
125 148
  * in prio list and take ANDNS_MAX_ANSW_IP_LEN * n space.
126 149
  *
127 150
  */
128
-int snsd_prio_to_aansws(char *buf,snsd_prio *sp,int iplen,int recursion,int *count)
151
+int
152
+snsd_prio_to_aansws(char *buf, snsd_prio * sp, int iplen, int recursion,
153
+					int *count)
129 154
 {
130
-	int res=0;
155
+	int res = 0;
131 156
 	snsd_node *sn;
132
-	int c=0;
133
-	
134
-	if(!sp || !buf)
157
+	int c = 0;
158
+
159
+	if (!sp || !buf)
135 160
 		return 0;
136 161
 
137
-	sn=sp->node;
138
-	list_for(sn) { 
139
-		res+=snsd_node_to_data(buf+res,sn,sp->prio,
140
-			iplen,recursion);
162
+	sn = sp->node;
163
+	list_for(sn) {
164
+		res += snsd_node_to_data(buf + res, sn, sp->prio,
165
+								 iplen, recursion);
141 166
 		c++;
142 167
 	}
143
-	*count=c;
168
+	*count = c;
144 169
 	return res;
145 170
 }
146 171
 
147
-int snsd_service_to_aansws(char *buf,snsd_service *ss,int iplen,int *count,int recursion)
172
+int
173
+snsd_service_to_aansws(char *buf, snsd_service * ss, int iplen, int *count,
174
+					   int recursion)
148 175
 {
149
-	int family,c=0;
176
+	int family, c = 0;
150 177
 	uint16_t service;
151
-	uint8_t prio,proto;
178
+	uint8_t prio, proto;
152 179
 	snsd_prio *sp;
153 180
 	snsd_node *sn;
154 181
 	char *rem;
@@ -156,42 +183,42 @@ int snsd_service_to_aansws(char *buf,snsd_service *ss,int iplen,int *count,int r
156 183
 
157 184
 	if (!ss || !buf)
158 185
 		return 0;
159
-	rem=buf;
160
-	
186
+	rem = buf;
187
+
161 188
 	list_for(ss) {
162
-		service=htons(ss->service);
163
-		proto=ss->proto;
164
-		sp=ss->prio;
189
+		service = htons(ss->service);
190
+		proto = ss->proto;
191
+		sp = ss->prio;
165 192
 		list_for(sp) {
166
-			prio=sp->prio;
167
-			sn=sp->node;
193
+			prio = sp->prio;
194
+			sn = sp->node;
168 195
 			list_for(sn) {
169 196
 				if (sn->flags & SNSD_NODE_MAIN_IP)
170
-					(*buf)|=0xc0;
197
+					(*buf) |= 0xc0;
171 198
 				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;
199
+					(*buf) |= 0x40;
200
+				if (proto == ANDNS_SNSD_PROTO_UDP)
201
+					(*buf) |= 0x20;
202
+				*buf++ |= (sn->weight & 0x1f);
203
+				*buf++ |= prio;
204
+				memcpy(buf, &service, 2);
205
+				buf += 2;
179 206
 				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;
207
+					sn->flags & SNSD_NODE_IP) {
208
+					memcpy(buf, sn->record, iplen);
209
+					family = (iplen == 4) ? AF_INET : AF_INET6;
210
+					inet_htonl((u_int *) buf, family);
211
+					buf += iplen;
212
+				} else {
213
+					if (recursion && !snsd_main_ip(sn->record, &snt)) {
214
+						memcpy(buf, snt.record, iplen);
215
+						*(buf - 4) |= 0x40;
216
+						family = (iplen == 4) ? AF_INET : AF_INET6;
217
+						inet_htonl((u_int *) buf, family);
218
+						buf += iplen;
192 219
 					} else {
193
-						memcpy(buf,sn->record, ANDNS_HASH_H);
194
-						buf+=ANDNS_HASH_H;
220
+						memcpy(buf, sn->record, ANDNS_HASH_H);
221
+						buf += ANDNS_HASH_H;
195 222
 					}
196 223
 /*					service=strlen((char*)sn->record);
197 224
 					temp=htons(service);
@@ -212,79 +239,82 @@ int snsd_service_to_aansws(char *buf,snsd_service *ss,int iplen,int *count,int r
212 239
 			}
213 240
 		}
214 241
 	}
215
-	*count=c;
216
-	return (int)(buf-rem);
242
+	*count = c;
243
+	return (int) (buf - rem);
217 244
 }
218
-					
219
-				
220
-				
245
+
246
+
247
+
221 248
 /*
222 249
  * Given a dns_packet, this function add an answer to it
223 250
  * and returns 0;
224 251
  * Otherwise returns -1.
225 252
  */
226
-int snsd_node_to_dansw(dns_pkt *dp,snsd_node *sn,int iplen)
253
+int
254
+snsd_node_to_dansw(dns_pkt * dp, snsd_node * sn, int iplen)
227 255
 {
228 256
 	char temp[18];
229 257
 	dns_pkt_a *dpa;
230
-	snsd_node snt,*s;
258
+	snsd_node snt, *s;
231 259
 	int res;
232 260
 
233 261
 	if (!(sn->flags & SNSD_NODE_HNAME)) {
234
-		if (!(res=snsd_main_ip(sn->record,&snt)))
262
+		if (!(res = snsd_main_ip(sn->record, &snt)))
235 263
 			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);
264
+		s = &snt;
265
+	} else
266
+		s = sn;
267
+
268
+	memcpy(temp, sn->record, iplen);
269
+	inet_htonl((u_int *) (temp), (iplen == 4) ? AF_INET : AF_INET6);
270
+
271
+	dpa = DP_ADD_ANSWER(dp);
272
+	dns_a_default_fill(dp, dpa);
273
+	dpa->rdlength = iplen;
274
+	memcpy(dpa->rdata, temp, iplen);
248 275
 	return 0;
249 276
 }
277
+
250 278
 /*
251 279
  * Converts a snsd_prio struct, adding a set of answers to
252 280
  * the dns_packet dp.
253 281
  * Returns the number of answers added to dp.
254 282
  */
255
-int snsd_prio_to_dansws(dns_pkt *dp,snsd_prio *sp,int iplen)
283
+int
284
+snsd_prio_to_dansws(dns_pkt * dp, snsd_prio * sp, int iplen)
256 285
 {
257
-	int res=0;
286
+	int res = 0;
258 287
 	snsd_node *sn;
259
-	
260
-	sn=sp->node;
261
-	list_for(sn) 
262
-		if (!snsd_node_to_dansw(dp,sn,iplen))
263
-			res++;
288
+
289
+	sn = sp->node;
290
+	list_for(sn)
291
+		if (!snsd_node_to_dansw(dp, sn, iplen))
292
+		res++;
264 293
 	return res;
265 294
 }
266
-		
267
-		
268
-		
295
+
296
+
297
+
269 298
 	/* ip2h functions */
270 299
 
271 300
 /*
272 301
  * Converts a lcl_cache struct to a set of dns answers.
273 302
  * Returns the number of answers added.
274 303
  */
275
-int lcl_cache_to_dansws(dns_pkt *dp,lcl_cache *lc)
304
+int
305
+lcl_cache_to_dansws(dns_pkt * dp, lcl_cache * lc)
276 306
 {
277 307
 	dns_pkt_a *dpa;
278
-	int res=0;
279
-	
308
+	int res = 0;
309
+
280 310
 	list_for(lc) {
281
-		dpa=DP_ADD_ANSWER(dp);
282
-		dns_a_default_fill(dp,dpa);
283
-		strcpy(dpa->rdata,lc->hostname);
311
+		dpa = DP_ADD_ANSWER(dp);
312
+		dns_a_default_fill(dp, dpa);
313
+		strcpy(dpa->rdata, lc->hostname);
284 314
 		res++;
285 315
 	}
286 316
 
287
-	if(lc)
317
+	if (lc)
288 318
 		lcl_cache_free(lc);
289 319
 
290 320
 	return res;
@@ -294,23 +324,24 @@ int lcl_cache_to_dansws(dns_pkt *dp,lcl_cache *lc)
294 324
  * Converts a lcl_cache to andns data. 
295 325
  * Returns the number of bytes writed.
296 326
  */
297
-size_t lcl_cache_to_aansws(char *buf,lcl_cache *lc,int *count)
327
+size_t
328
+lcl_cache_to_aansws(char *buf, lcl_cache * lc, int *count)
298 329
 {
299 330
 	uint16_t slen;
300
-	size_t ret=0;
301
-	int lcount=0;
302
-	lcl_cache *lcl=lc;
303
-	
331
+	size_t ret = 0;
332
+	int lcount = 0;
333
+	lcl_cache *lcl = lc;
334
+
304 335
 	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);
336
+		slen = strlen(lc->hostname);
337
+		ret += 2 + slen;
338
+		slen = htons(slen);
339
+		memcpy(buf, &slen, 2);
340
+		buf += 2;
341
+		strcpy(buf, lc->hostname);
311 342
 		lcount++;
312 343
 	}
313
-	*count=lcount;
344
+	*count = lcount;
314 345
 	lcl_cache_free(lc);
315 346
 	return ret;
316 347
 }

+ 34
- 10
src/andns_snsd.h View File

@@ -1,3 +1,23 @@
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
+
1 21
 #ifndef ANDNS_SNSD_H
2 22
 #define ANDNS_SNSD_H
3 23
 
@@ -10,13 +30,17 @@
10 30
 
11 31
 /* functions */
12 32
 
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 */
33
+int snsd_main_ip(u_int * hname_hash, snsd_node * dst);
34
+int snsd_node_to_data(char *buf, snsd_node * sn, u_char prio, int iplen,
35
+					  int recursion);
36
+size_t snsd_node_to_aansw(char *buf, snsd_node * sn, u_char prio,
37
+						  int iplen);
38
+int snsd_prio_to_aansws(char *buf, snsd_prio * sp, int iplen,
39
+						int recursion, int *count);
40
+int snsd_service_to_aansws(char *buf, snsd_service * ss, int iplen,
41
+						   int *count, int recursion);
42
+int snsd_node_to_dansw(dns_pkt * dp, snsd_node * sn, int iplen);
43
+int snsd_prio_to_dansws(dns_pkt * dp, snsd_prio * sp, int iplen);
44
+int lcl_cache_to_dansws(dns_pkt * dp, lcl_cache * lc);
45
+size_t lcl_cache_to_aansws(char *buf, lcl_cache * lc, int *count);
46
+#endif							/* ANDNS_SNSD_H */

+ 172
- 141
src/bmap.c View File

@@ -29,37 +29,43 @@
29 29
 #include "gmap.h"
30 30
 #include "bmap.h"
31 31
 
32
-void bmap_levels_init(u_char levels, map_bnode ***bmap, u_int **bmap_nodes)
32
+void
33
+bmap_levels_init(u_char levels, map_bnode *** bmap, u_int ** bmap_nodes)
33 34
 {
34
-	*bmap=xmalloc(sizeof(map_bnode *) * levels);
35
-	*bmap_nodes=(u_int *)xmalloc(sizeof(u_int) * levels);
35
+	*bmap = xmalloc(sizeof(map_bnode *) * levels);
36
+	*bmap_nodes = (u_int *) xmalloc(sizeof(u_int) * levels);
36 37
 
37 38
 	setzero(*bmap, sizeof(map_bnode *) * levels);
38 39
 	bmap_counter_reset(levels, *bmap_nodes);
39 40
 }
40 41
 
41
-void bmap_levels_free(map_bnode **bmap, u_int *bmap_nodes)
42
+void
43
+bmap_levels_free(map_bnode ** bmap, u_int * bmap_nodes)
42 44
 {
43 45
 	xfree(bmap);
44 46
 	xfree(bmap_nodes);
45 47
 }
46 48
 
47
-void bmap_counter_init(u_char levels, u_int **bnodes_closed, u_int **bnodes_opened)
49
+void
50
+bmap_counter_init(u_char levels, u_int ** bnodes_closed,
51
+				  u_int ** bnodes_opened)
48 52
 {
49
-	*bnodes_closed=(u_int *)xmalloc(sizeof(u_int) * levels);
50
-	*bnodes_opened=(u_int *)xmalloc(sizeof(u_int) * levels);
51
-	
53
+	*bnodes_closed = (u_int *) xmalloc(sizeof(u_int) * levels);
54
+	*bnodes_opened = (u_int *) xmalloc(sizeof(u_int) * levels);
55
+
52 56
 	bmap_counter_reset(levels, *bnodes_closed);
53 57
 	bmap_counter_reset(levels, *bnodes_opened);
54 58
 }
55 59
 
56
-void bmap_counter_free(u_int *bnodes_closed, u_int *bnodes_opened)
60
+void
61
+bmap_counter_free(u_int * bnodes_closed, u_int * bnodes_opened)
57 62
 {
58 63
 	xfree(bnodes_closed);
59 64
 	xfree(bnodes_opened);
60 65
 }
61 66
 
62
-void bmap_counter_reset(u_char levels, u_int *counter)
67
+void
68
+bmap_counter_reset(u_char levels, u_int * counter)
63 69
 {
64 70
 	setzero(counter, sizeof(u_int) * levels);
65 71
 }
@@ -70,22 +76,24 @@ void bmap_counter_reset(u_char levels, u_int *counter)
70 76
  * to `bnode' and the links to `links'.
71 77
  * Note that the `bmap' argument must be an adress of a pointer.
72 78
  */
73
-int map_add_bnode(map_bnode **bmap, u_int *bmap_nodes, u_int bnode, u_int links)
79
+int
80
+map_add_bnode(map_bnode ** bmap, u_int * bmap_nodes, u_int bnode,
81
+			  u_int links)
74 82
 {
75 83
 	map_bnode *bnode_map;
76 84
 	u_int bm;
77
-	
78
-	bm=*bmap_nodes; 
85
+
86
+	bm = *bmap_nodes;
79 87
 	(*bmap_nodes)++;
80
-	if(!bm)
81
-		*bmap=xmalloc(sizeof(map_bnode));
88
+	if (!bm)
89
+		*bmap = xmalloc(sizeof(map_bnode));
82 90
 	else
83
-		*bmap=xrealloc(*bmap, sizeof(map_bnode) * *bmap_nodes);
91
+		*bmap = xrealloc(*bmap, sizeof(map_bnode) * *bmap_nodes);
84 92
 
85
-	bnode_map=*bmap;
93
+	bnode_map = *bmap;
86 94
 	setzero(bnode_map, sizeof(map_bnode));
87
-	bnode_map[bm].bnode_ptr=bnode;
88
-	bnode_map[bm].links=links;
95
+	bnode_map[bm].bnode_ptr = bnode;
96
+	bnode_map[bm].links = links;
89 97
 	return bm;
90 98
 }
91 99
 
@@ -93,18 +101,20 @@ int map_add_bnode(map_bnode **bmap, u_int *bmap_nodes, u_int bnode, u_int links)
93 101
  * map_bnode_del: It deletes the `bnode' in the `bmap' which has `bmap_nodes'.
94 102
  * It returns the newly rescaled `bmap'.
95 103
  * 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)
104
+map_bnode *
105
+map_bnode_del(map_bnode * bmap, u_int * bmap_nodes, map_bnode * bnode)
97 106
 {
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));
107
+	map_node_del((map_node *) bnode);
108
+
109
+	if (((char *) bnode - (char *) bmap) / sizeof(map_bnode) !=
110
+		(*bmap_nodes) - 1)
111
+		memcpy(bnode, &bmap[*bmap_nodes - 1], sizeof(map_bnode));
102 112
 
103 113
 	(*bmap_nodes)--;
104
-	if(*bmap_nodes)
114
+	if (*bmap_nodes)
105 115
 		return xrealloc(bmap, (*bmap_nodes) * sizeof(map_bnode));
106 116
 	else {
107
-		*bmap_nodes=0;
117
+		*bmap_nodes = 0;
108 118
 		xfree(bmap);
109 119
 		return 0;
110 120
 	}
@@ -117,18 +127,19 @@ map_bnode *map_bnode_del(map_bnode *bmap, u_int *bmap_nodes,  map_bnode *bnode)
117 127
  * `total_levels' must be equal to the maximum levels 
118 128
  * available (use FAMILY_LVLS).
119 129
  */
120
-int bmap_del_rnode_by_level(map_bnode *bnode, int level, map_gnode **ext_map,
121
-		int total_levels)
122
-{ 
130
+int
131
+bmap_del_rnode_by_level(map_bnode * bnode, int level, map_gnode ** ext_map,
132
+						int total_levels)
133
+{
123 134
 	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) {
135
+	int i, ret = 0, lvl;
136
+
137
+
138
+	for (i = 0; i < bnode->links; i++) {
139
+		gn = (map_gnode *) bnode->r_node[i].r_node;
140
+		lvl = extmap_find_level(ext_map, gn, total_levels);
141
+
142
+		if (lvl != level) {
132 143
 			rnode_del(bnode, i);
133 144
 			ret++;
134 145
 		}
@@ -141,14 +152,15 @@ int bmap_del_rnode_by_level(map_bnode *bnode, int level, map_gnode **ext_map,
141 152
  * map_find_bnode: Find the given `node' (in the pos_from_node() format) in the
142 153
  * given map_bnode `bmap'.
143 154
  */
144
-int map_find_bnode(map_bnode *bmap, int bmap_nodes, int node)
155
+int
156
+map_find_bnode(map_bnode * bmap, int bmap_nodes, int node)
145 157
 {
146 158
 	int e;
147 159
 
148
-	for(e=0; e<bmap_nodes; e++)
149
-		if(bmap[e].bnode_ptr == node)
160
+	for (e = 0; e < bmap_nodes; e++)
161
+		if (bmap[e].bnode_ptr == node)
150 162
 			return e;
151
-	
163
+
152 164
 	return -1;
153 165
 }
154 166
 
@@ -157,12 +169,13 @@ int map_find_bnode(map_bnode *bmap, int bmap_nodes, int node)
157 169
  * which points to `n'. If it is found the pos of the bnode in the `bmap' is
158 170
  * returned, otherwise -1 is the return value. 
159 171
  */
160
-int map_find_bnode_rnode(map_bnode *bmap, int bmap_nodes, void *n)
172
+int
173
+map_find_bnode_rnode(map_bnode * bmap, int bmap_nodes, void *n)
161 174
 {
162 175
 	int e;
163 176
 
164
-	for(e=0; e<bmap_nodes; e++)
165
-		if(rnode_find((map_node *)&bmap[e], (map_node *)n) != -1)
177
+	for (e = 0; e < bmap_nodes; e++)
178
+		if (rnode_find((map_node *) & bmap[e], (map_node *) n) != -1)
166 179
 			return e;
167 180
 
168 181
 	return -1;
@@ -172,12 +185,13 @@ int map_find_bnode_rnode(map_bnode *bmap, int bmap_nodes, void *n)
172 185
  * map_count_bnode_rnode: counts how many bnode which have a rnode which
173 186
  * points to `n' there are in `bmap'.
174 187
  */
175
-int map_count_bnode_rnode(map_bnode *bmap, int bmap_nodes, void *n)
188
+int
189
+map_count_bnode_rnode(map_bnode * bmap, int bmap_nodes, void *n)
176 190
 {
177 191
 	int e, i;
178 192
 
179
-	for(i=0, e=0; i<bmap_nodes; i++)
180
-		if(rnode_find((map_node *)&bmap[i], (map_node *)n) != -1)
193
+	for (i = 0, e = 0; i < bmap_nodes; i++)
194
+		if (rnode_find((map_node *) & bmap[i], (map_node *) n) != -1)
181 195
 			e++;
182 196
 
183 197
 	return e;
@@ -188,12 +202,14 @@ int map_count_bnode_rnode(map_bnode *bmap, int bmap_nodes, void *n)
188 202
  * `bmap' and returns the sum of the results.
189 203
  * `levels' are the total levels of `bmap'.
190 204
  */
191
-int bmaps_count_bnode_rnode(map_bnode **bmap, int *bmap_nodes, int levels, void *n)
205
+int
206
+bmaps_count_bnode_rnode(map_bnode ** bmap, int *bmap_nodes, int levels,
207
+						void *n)
192 208
 {
193 209
 	int i, e;
194 210
 
195
-	for(i=0, e=0; i<levels; i++)
196
-		e+=map_count_bnode_rnode(bmap[i], bmap_nodes[i], n);
211
+	for (i = 0, e = 0; i < levels; i++)
212
+		e += map_count_bnode_rnode(bmap[i], bmap_nodes[i], n);
197 213
 
198 214
 	return e;
199 215
 }
@@ -204,19 +220,20 @@ int bmaps_count_bnode_rnode(map_bnode **bmap, int *bmap_nodes, int levels, void
204 220
  * `bmap' is the address of the pointer to the bmap.
205 221
  * It returns the number of rnodes deleted.
206 222
  */
207
-int map_del_bnode_rnode(map_bnode **bmap, int *bmap_nodes, void *n)
223
+int
224
+map_del_bnode_rnode(map_bnode ** bmap, int *bmap_nodes, void *n)
208 225
 {
209 226
 	map_bnode *bm;
210
-	int e, p, ret=0;
227
+	int e, p, ret = 0;
211 228
 
212
-	bm=*bmap;
213
-	for(e=0; e < *bmap_nodes; e++) {
214
-		if((p=rnode_find((map_node *)&bm[e], (map_node *)n)) != -1) {
229
+	bm = *bmap;
230
+	for (e = 0; e < *bmap_nodes; e++) {
231
+		if ((p = rnode_find((map_node *) & bm[e], (map_node *) n)) != -1) {
215 232
 			rnode_del(&bm[e], p);
216 233
 
217
-			if(!bm[e].links) {
218
-				*bmap=map_bnode_del(*bmap,(u_int*)bmap_nodes, &bm[e]);
219
-				bm=*bmap;
234
+			if (!bm[e].links) {
235
+				*bmap = map_bnode_del(*bmap, (u_int *) bmap_nodes, &bm[e]);
236
+				bm = *bmap;
220 237
 			}
221 238
 			ret++;
222 239
 		}
@@ -231,12 +248,14 @@ int map_del_bnode_rnode(map_bnode **bmap, int *bmap_nodes, void *n)
231 248
  * `levels' are the total levels of `bmap'.
232 249
  * It returns the total number of rnodes deleted
233 250
  */
234
-int bmaps_del_bnode_rnode(map_bnode **bmap, int *bmap_nodes, int levels, void *n)
251
+int
252
+bmaps_del_bnode_rnode(map_bnode ** bmap, int *bmap_nodes, int levels,
253
+					  void *n)
235 254
 {
236 255
 	int i, e;
237 256
 
238
-	for(i=0, e=0; i<levels; i++)
239
-		e+=map_del_bnode_rnode(&bmap[i], &bmap_nodes[i], n);
257
+	for (i = 0, e = 0; i < levels; i++)
258
+		e += map_del_bnode_rnode(&bmap[i], &bmap_nodes[i], n);
240 259
 
241 260
 	return e;
242 261
 }
@@ -245,22 +264,25 @@ int bmaps_del_bnode_rnode(map_bnode **bmap, int *bmap_nodes, int levels, void *n
245 264
  * map_set_bnode_flag: sets the `flags' to all the `bmap_nodes'# present in
246 265
  * `bmap'.
247 266
  */
248
-void map_set_bnode_flag(map_bnode *bmap, int bmap_nodes, int flags)
267
+void
268
+map_set_bnode_flag(map_bnode * bmap, int bmap_nodes, int flags)
249 269
 {
250 270
 	int e;
251
-	for(e=0; e<bmap_nodes; e++)
252
-		bmap[e].flags|=flags;
271
+	for (e = 0; e < bmap_nodes; e++)
272
+		bmap[e].flags |= flags;
253 273
 }
254 274
 
255 275
 /*
256 276
  * bmaps_set_bnode_flag: sets the `flags' to all the bnodes present in the
257 277
  * `levels'#  `bmap'.
258 278
  */
259
-void bmaps_set_bnode_flag(map_bnode **bmap, int *bmap_nodes, int levels, int flags)
279
+void
280
+bmaps_set_bnode_flag(map_bnode ** bmap, int *bmap_nodes, int levels,
281
+					 int flags)
260 282
 {
261
-	int i;		
262
-	
263
-	for(i=0; i<levels; i++)
283
+	int i;
284
+
285
+	for (i = 0; i < levels; i++)
264 286
 		map_set_bnode_flag(bmap[i], bmap_nodes[i], flags);
265 287
 }
266 288
 
@@ -272,35 +294,37 @@ void bmaps_set_bnode_flag(map_bnode **bmap, int *bmap_nodes, int levels, int fla
272 294
  * The package will be in network order.
273 295
  */
274 296
 char *
275
-pack_all_bmaps(map_bnode **bmaps,  u_int *bmap_nodes, map_gnode **ext_map,
276
-		quadro_group quadg, size_t *pack_sz)
297
+pack_all_bmaps(map_bnode ** bmaps, u_int * bmap_nodes,
298
+			   map_gnode ** ext_map, quadro_group quadg, size_t * pack_sz)
277 299
 {
278 300
 	struct bnode_maps_hdr bmaps_hdr;
279 301
 	size_t sz, tmp_sz[BMAP_LEVELS(quadg.levels)];
280 302
 	char *pack[BMAP_LEVELS(quadg.levels)], *final_pack, *buf;
281 303
 	u_char level;
282 304
 
283
-	*pack_sz=0;
305
+	*pack_sz = 0;
284 306
 
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;
307
+	for (level = 0; level < BMAP_LEVELS(quadg.levels); level++) {
308
+		pack[level] =
309
+			pack_map((map_node *) bmaps[level],
310
+					 (int *) ext_map[_EL(level + 1)], bmap_nodes[level], 0,
311
+					 &sz);
312
+		tmp_sz[level] = sz;
313
+		(*pack_sz) += sz;
290 314
 	}
291 315
 
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));
316
+	bmaps_hdr.levels = BMAP_LEVELS(quadg.levels);
317
+	bmaps_hdr.bmaps_block_sz = *pack_sz;
318
+	(*pack_sz) += sizeof(struct bnode_maps_hdr);
319
+
320
+	final_pack = xmalloc((*pack_sz));
297 321
 	memcpy(final_pack, &bmaps_hdr, sizeof(struct bnode_maps_hdr));
298 322
 	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++) {
323
+
324
+	buf = final_pack + sizeof(struct bnode_maps_hdr);
325
+	for (level = 0; level < BMAP_LEVELS(quadg.levels); level++) {
302 326
 		memcpy(buf, pack[level], tmp_sz[level]);
303
-		buf+=tmp_sz[level];
327
+		buf += tmp_sz[level];
304 328
 		xfree(pack[level]);
305 329
 	}
306 330
 
@@ -319,57 +343,60 @@ pack_all_bmaps(map_bnode **bmaps,  u_int *bmap_nodes, map_gnode **ext_map,
319 343
  * contain.
320 344
  * On error 0 is returned.
321 345
  * Note: `pack' will be modified during the unpacking.
322
- */ 
346
+ */
323 347
 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)
348
+unpack_all_bmaps(char *pack, u_char max_levels, map_gnode ** ext_map,
349
+				 u_int ** bmap_nodes, int maxbnodes,
350
+				 int maxbnode_rnodeblock)
326 351
 {
327 352
 	struct bnode_maps_hdr *bmaps_hdr;
328 353
 	struct bnode_map_hdr *bmap_hdr;
329 354
 	map_bnode **bmap, *unpacked_bmap;
330 355
 	size_t bblock_sz, pack_sz;
331
-	int i,e=0;
356
+	int i, e = 0;
332 357
 	char *bblock, *buf;
333 358
 	u_char levels;
334
-	
335
-	bmaps_hdr=(struct bnode_maps_hdr *)pack;
359
+
360
+	bmaps_hdr = (struct bnode_maps_hdr *) pack;
336 361
 	ints_network_to_host(bmaps_hdr, bnode_maps_hdr_iinfo);
337 362
 
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))
363
+	levels = bmaps_hdr->levels;
364
+	pack_sz = bmaps_hdr->bmaps_block_sz;
365
+
366
+	if (levels > max_levels || pack_sz < sizeof(struct bnode_maps_hdr))
342 367
 		return 0;
343 368
 
344 369
 	bmap_levels_init(levels, &bmap, bmap_nodes);
345 370
 
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);
371
+	buf = pack + sizeof(struct bnode_maps_hdr);
372
+	for (i = 0; i < levels; i++) {
373
+		bmap_hdr = (struct bnode_map_hdr *) buf;
374
+		if (!bmap_hdr->bnode_map_sz) {
375
+			buf += sizeof(struct bnode_map_hdr);
351 376
 			continue;
352 377
 		}
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);
378
+
379
+		/*Extracting the map... */
380
+		bblock = (char *) bmap_hdr;
381
+		unpacked_bmap = unpack_map(bblock, (int *) ext_map[_EL(i + 1)], 0,
382
+								   maxbnodes, maxbnode_rnodeblock);
383
+		if (!unpacked_bmap) {
384
+			error("Cannot unpack the bnode_map at level %d ! Skipping...",
385
+				  i);
360 386
 			e++;
361 387
 			continue;
362 388
 		}
363 389
 
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);
390
+		(*bmap_nodes)[i] = bmap_hdr->bnode_map_sz / MAP_BNODE_PACK_SZ;
391
+		bblock_sz =
392
+			INT_MAP_BLOCK_SZ(bmap_hdr->bnode_map_sz, bmap_hdr->rblock_sz);
366 393
 
367
-		bmap[i]=unpacked_bmap;
394
+		bmap[i] = unpacked_bmap;
368 395
 
369
-		buf+=bblock_sz;
396
+		buf += bblock_sz;
370 397
 	}
371
-	
372
-	if(e == levels)
398
+
399
+	if (e == levels)
373 400
 		/* Not a single map was restored */
374 401
 		return 0;
375 402
 
@@ -383,20 +410,22 @@ unpack_all_bmaps(char *pack, u_char max_levels, map_gnode **ext_map,
383 410
  * `bmap_nodes[x]' nodes. `ext_map' is the pointer to the external map the bmap is
384 411
  * referring to.
385 412
  */
386
-int save_bmap(map_bnode **bmaps, u_int *bmap_nodes, map_gnode **ext_map, 
387
-		quadro_group quadg, char *file)
413
+int
414
+save_bmap(map_bnode ** bmaps, u_int * bmap_nodes, map_gnode ** ext_map,
415
+		  quadro_group quadg, char *file)
388 416
 {
389 417
 	FILE *fd;
390 418
 	char *pack;
391 419
 	size_t pack_sz;
392
-	
393
-	
394
-	pack=pack_all_bmaps(bmaps, bmap_nodes, ext_map, quadg, &pack_sz);
395
-	if(!pack_sz || !pack)
420
+
421
+
422
+	pack = pack_all_bmaps(bmaps, bmap_nodes, ext_map, quadg, &pack_sz);
423
+	if (!pack_sz || !pack)
396 424
 		return 0;
397 425
 
398
-	if((fd=fopen(file, "w"))==NULL) {
399
-		error("Cannot save the bnode_map in %s: %s", file, strerror(errno));
426
+	if ((fd = fopen(file, "w")) == NULL) {
427
+		error("Cannot save the bnode_map in %s: %s", file,
428
+			  strerror(errno));
400 429
 		return -1;
401 430
 	}
402 431
 	fwrite(pack, pack_sz, 1, fd);
@@ -412,43 +441,45 @@ int save_bmap(map_bnode **bmaps, u_int *bmap_nodes, map_gnode **ext_map,
412 441
  * the bmap shall refer to. In `bmap_nodes' the address of the u_int array, used
413 442
  * to count the nodes in each bmaps, is stored. On error 0 is returned.
414 443
  */
415
-map_bnode **load_bmap(char *file, map_gnode **ext_map, u_char max_levels, u_int **bmap_nodes)
444
+map_bnode **
445
+load_bmap(char *file, map_gnode ** ext_map, u_char max_levels,
446
+		  u_int ** bmap_nodes)
416 447
 {
417
-	map_bnode **bmap=0;
448
+	map_bnode **bmap = 0;
418 449
 	FILE *fd;
419 450
 	struct bnode_maps_hdr bmaps_hdr;
420 451
 	size_t pack_sz;
421 452
 	u_char levels;
422
-	char *pack=0;
423
-	
424
-	if((fd=fopen(file, "r"))==NULL) {
453
+	char *pack = 0;
454
+
455
+	if ((fd = fopen(file, "r")) == NULL) {
425 456
 		error("Cannot load the bmap from %s: %s", file, strerror(errno));
426 457
 		return 0;
427 458
 	}
428
-	
429
-	if(!fread(&bmaps_hdr, sizeof(struct bnode_maps_hdr), 1, fd))
459
+
460
+	if (!fread(&bmaps_hdr, sizeof(struct bnode_maps_hdr), 1, fd))
430 461
 		goto finish;
431
-		
462
+
432 463
 	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))
464
+	levels = bmaps_hdr.levels;
465
+	pack_sz = bmaps_hdr.bmaps_block_sz;
466
+	if (levels > max_levels || pack_sz < sizeof(struct bnode_maps_hdr))
436 467
 		goto finish;
437 468
 
438 469
 	/* Extracting the map... */
439 470
 	rewind(fd);
440
-	pack=xmalloc(pack_sz);
441
-	if(!fread(pack, pack_sz, 1, fd))
471
+	pack = xmalloc(pack_sz);
472
+	if (!fread(pack, pack_sz, 1, fd))
442 473
 		goto finish;
443
-	
444
-	bmap=unpack_all_bmaps(pack, max_levels, ext_map, bmap_nodes, 
445
-			MAXGROUPNODE, MAXBNODE_RNODEBLOCK);
446
-	
447
-finish:
474
+
475
+	bmap = unpack_all_bmaps(pack, max_levels, ext_map, bmap_nodes,
476
+							MAXGROUPNODE, MAXBNODE_RNODEBLOCK);
477
+
478
+  finish:
448 479
 	fclose(fd);
449
-	if(pack)
480
+	if (pack)
450 481
 		xfree(pack);
451
-	if(!bmap)
482
+	if (!bmap)
452 483
 		error("Malformed bmap file. Cannot load the bnode maps.");
453 484
 	return bmap;
454 485
 }

+ 53
- 45
src/bmap.h View File

@@ -22,10 +22,10 @@
22 22
 #include "gmap.h"
23 23
 
24 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
-					   
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 29
 /* 
30 30
  * map_bnode is the struct used to create the "map border node". 
31 31
  * This map keeps all the border node of the map, making it easy to retrieve
@@ -51,17 +51,17 @@
51 51
 typedef map_node map_bnode;
52 52
 #define MAP_BNODE_PACK_SZ	MAP_NODE_PACK_SZ
53 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*/
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 58
 #define MAXBNODE_RNODEBLOCK	(MAXBNODE_LINKS*MAXGROUPBNODE*MAP_RNODE_PACK_SZ)
59 59
 
60 60
 /* 
61 61
  * These defines make the life easier, so instead of writing int_map_hdr I
62 62
  * write bnode_map_hdr. Cool eh? ^_^.
63 63
  */
64
-#define bnode_ptr		brdcast		/*Don't kill me*/
64
+#define bnode_ptr		brdcast	/*Don't kill me */
65 65
 #define bnode_map_hdr 		int_map_hdr
66 66
 #define bnode_map_sz   		int_map_sz
67 67
 
@@ -86,12 +86,11 @@ typedef map_node map_bnode;
86 86
  * The bblock is also used to store the Internet gateways, see igs.h for more
87 87
  * details.
88 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 } };
89
+typedef struct {
90
+	u_char bnode_levels;
91
+	u_short links;				/*The number of linked gnode */
92
+} _PACKED_ bnode_hdr;
93
+INT_INFO bnode_hdr_iinfo = { 1, {INT_TYPE_16BIT}, {sizeof(char)}, {1} };
95 94
 
96 95
 /*
97 96
  * This is part of the bnode_hdr.
@@ -101,18 +100,18 @@ INT_INFO bnode_hdr_iinfo = { 1, { INT_TYPE_16BIT }, { sizeof(char) }, { 1 } };
101 100
 #define BNODE_HDR_SZ(levels)		(sizeof(bnode_hdr)+sizeof(u_char)*(levels))
102 101
 
103 102
 
104
-typedef struct
105
-{
103
+typedef struct {
106 104
 	/* The `bnode_hdr.bnode' borders on the `gnode' of `level'th level with
107 105
 	 * a round trip time which is stored in `rtt'. */
108 106
 
109
-	u_char		gnode;	     
110
-	u_char		level;
111
-	u_int		rtt;
112
-}_PACKED_ bnode_chunk;
107
+	u_char gnode;
108
+	u_char level;
109
+	u_int rtt;
110
+} _PACKED_ bnode_chunk;
113 111
 #define BNODEBLOCK_SZ(levels, links) (BNODE_HDR_SZ((levels)) +		       \
114 112
 					(sizeof(bnode_chunk)*(links)))
115
-INT_INFO bnode_chunk_iinfo = { 1, { INT_TYPE_32BIT }, { sizeof(char)*2 }, { 1 } };
113
+INT_INFO bnode_chunk_iinfo =
114
+	{ 1, {INT_TYPE_32BIT}, {sizeof(char) * 2}, {1} };
116 115
 
117 116
 
118 117
 /* 
@@ -131,39 +130,48 @@ INT_INFO bnode_chunk_iinfo = { 1, { INT_TYPE_32BIT }, { sizeof(char)*2 }, { 1 }
131 130
  * 	
132 131
  * 	...
133 132
  */
134
-struct bnode_maps_hdr
135
-{
133
+struct bnode_maps_hdr {
136 134
 	u_char levels;
137 135
 	size_t bmaps_block_sz;
138
-}_PACKED_;
139
-INT_INFO bnode_maps_hdr_iinfo = { 1, { INT_TYPE_32BIT }, { sizeof(char) }, { 1 } };
136
+} _PACKED_;
137
+INT_INFO bnode_maps_hdr_iinfo =
138
+	{ 1, {INT_TYPE_32BIT}, {sizeof(char)}, {1} };
140 139
 
141 140
 /* * * 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);
141
+void bmap_levels_init(u_char levels, map_bnode *** bmap,
142
+					  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,
145
+					   u_int ** bnodes_opened);
146
+void bmap_counter_free(u_int * bnodes_closed, u_int * bnodes_opened);
147
+void bmap_counter_reset(u_char levels, u_int * counter);
148
+
149
+int map_add_bnode(map_bnode ** bmap, u_int * bmap_nodes, u_int bnode,
150
+				  u_int links);
151
+map_bnode *map_bnode_del(map_bnode * bmap, u_int * bmap_nodes,
152
+						 map_bnode * bnode);
150 153
 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);
154
+int map_find_bnode(map_bnode * bmap, int bmap_nodes, int node);
155
+int map_find_bnode_rnode(map_bnode * bmap, int bmap_nodes, void *n);
153 156
 
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);
157
+int map_count_bnode_rnode(map_bnode * bmap, int bmap_nodes, void *n);
158
+int bmaps_count_bnode_rnode(map_bnode ** bmap, int *bmap_nodes, int levels,
159
+							void *n);
160
+int map_del_bnode_rnode(map_bnode ** bmap, int *bmap_nodes, void *n);
161
+int bmaps_del_bnode_rnode(map_bnode ** bmap, int *bmap_nodes, int levels,
162
+						  void *n);
158 163
 
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);
164
+void map_set_bnode_flag(map_bnode * bmap, int bmap_nodes, int flags);
165
+void bmaps_set_bnode_flag(map_bnode ** bmap, int *bmap_nodes, int levels,
166
+						  int flags);
161 167
 
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);
168
+char *pack_all_bmaps(map_bnode **, u_int *, map_gnode **, quadro_group,
169
+					 size_t *);
170
+map_bnode **unpack_all_bmaps(char *, u_char, map_gnode **, u_int **, int,
171
+							 int);
164 172
 
165 173
 int save_bmap(map_bnode **, u_int *, map_gnode **, quadro_group, char *);
166 174
 map_bnode **load_bmap(char *, map_gnode **, u_char, u_int **);
167 175
 
168 176
 
169
-#endif /*BMAP_H*/
177
+#endif							/*BMAP_H */

+ 5
- 4
src/buffer.c View File

@@ -25,12 +25,13 @@
25 25
  * Is the buffer `a' filled with `sz'# of zeros?
26 26
  * If yes return 1. 
27 27
  */
28
-int is_bufzero(const void *a, int sz)
28
+int
29
+is_bufzero(const void *a, int sz)
29 30
 {
30
-	const char *p=a;
31
+	const char *p = a;
31 32
 	int i;
32
-	for(i=0; i<sz; i++, p++)
33
-		if(*p)
33
+	for (i = 0; i < sz; i++, p++)
34
+		if (*p)
34 35
 			return 0;
35 36
 	return 1;
36 37
 }

+ 1
- 1
src/buffer.h View File

@@ -73,4 +73,4 @@
73 73
 \*/
74 74
 int is_bufzero(const void *a, int sz);
75 75
 
76
-#endif /*BUFFER_H*/
76
+#endif							/*BUFFER_H */

+ 18
- 0
src/common.h View File

@@ -1,3 +1,21 @@
1
+/* This file is part of Netsukuku
2
+ *
3
+ * This source code is free software; you can redistribute it and/or
4
+ * modify it under the terms of the GNU General Public License as published
5
+ * by the Free Software Foundation; either version 2 of the License,
6
+ * or (at your option) any later version.
7
+ *
8
+ * This source code is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
+ * Please refer to the GNU Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU Public License along with
14
+ * this source code; if not, write to:
15
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ *
17
+ */
18
+
1 19
 #ifndef COMMON_H
2 20
 #define COMMON_H
3 21
 

+ 42
- 39
src/conf.c View File

@@ -32,12 +32,13 @@
32 32
  *
33 33
  * do not make the environment dirty
34 34
  */
35
-void clear_config_env(void)
35
+void
36
+clear_config_env(void)
36 37
 {
37 38
 	int i;
38 39
 
39
-	for(i=0; config_str[i][0]; i++)
40
-		if(getenv(config_str[i]))
40
+	for (i = 0; config_str[i][0]; i++)
41
+		if (getenv(config_str[i]))
41 42
 			unsetenv(config_str[i]);
42 43
 }
43 44
 
@@ -48,31 +49,32 @@ void clear_config_env(void)
48 49
  * On failure fatal() is called, so it will never return ;)
49 50
  * `file' and `pos' are used by fatal() to tell where the corrupted `line' was.
50 51
  */
51
-void parse_config_line(char *file, int pos, char *line)
52
+void
53
+parse_config_line(char *file, int pos, char *line)
52 54
 {
53
-	int i, e=0;
55
+	int i, e = 0;
54 56
 	char *value;
55
-	
56
-	if(!(value=strchr(line, '=')))
57
+
58
+	if (!(value = strchr(line, '=')))
57 59
 		fatal("The line %s:%d is invalid, it does not contain the '=' "
58
-				"character. Aborting.", file, pos);
60
+			  "character. Aborting.", file, pos);
59 61
 
60
-	for(i=0; config_str[i][0]; i++)
61
-		if(strstr(line, config_str[i])) {
62
-			e=1;
62
+	for (i = 0; config_str[i][0]; i++)
63
+		if (strstr(line, config_str[i])) {
64
+			e = 1;
63 65
 			break;
64 66
 		}
65
-	if(!e)
66
- 	    fatal("The line %s:%d does not contain a valid option. Aborting.",
67
-				file, pos);
67
+	if (!e)
68
+		fatal("The line %s:%d does not contain a valid option. Aborting.",
69
+			  file, pos);
68 70
 
69 71
 	value++;
70
-	while(isspace(*value)) 
72
+	while (isspace(*value))
71 73
 		value++;
72
-	
73
-	if(setenv(config_str[i], value, 1))
74
-		fatal("Error in line %s:%d: %s. Aborting.", file, pos, 
75
-				strerror(errno));
74
+
75
+	if (setenv(config_str[i], value, 1))
76
+		fatal("Error in line %s:%d: %s. Aborting.", file, pos,
77
+			  strerror(errno));
76 78
 }
77 79
 
78 80
 
@@ -83,47 +85,48 @@ void parse_config_line(char *file, int pos, char *line)
83 85
  * parse_config_line() detects a corrupted line, fatal() is directly called.
84 86
  * On success 0 is returned.
85 87
  */
86
-int load_config_file(char *file)
88
+int
89
+load_config_file(char *file)
87 90
 {
88 91
 	FILE *fd;
89
-	char buf[PATH_MAX+1], *p, *str;
92
+	char buf[PATH_MAX + 1], *p, *str;
90 93
 	size_t slen;
91
-	int i=0, e=0;
94
+	int i = 0, e = 0;
92 95
 
93
-	if(!(fd=fopen(file, "r"))) {
96
+	if (!(fd = fopen(file, "r"))) {
94 97
 		fatal("Cannot load the configuration file from %s: %s\n"
95
-			"  Maybe you want to use the -c option ?",
96
-			file, strerror(errno));
98
+			  "  Maybe you want to use the -c option ?",
99
+			  file, strerror(errno));
97 100
 		return -1;
98 101
 	}
99 102
 
100
-	while(!feof(fd) && i < CONF_MAX_LINES) {
101
-		setzero(buf, PATH_MAX+1);
103
+	while (!feof(fd) && i < CONF_MAX_LINES) {
104
+		setzero(buf, PATH_MAX + 1);
102 105
 		fgets(buf, PATH_MAX, fd);
103 106
 		e++;
104 107
 
105
-		if(feof(fd))
108
+		if (feof(fd))
106 109
 			break;
107 110
 
108
-		str=buf;
109
-		while(isspace(*str))
111
+		str = buf;
112
+		while (isspace(*str))
110 113
 			str++;
111
-		if(*str=='#' || !*str) {
114
+		if (*str == '#' || !*str) {
112 115
 			/* Strip off any comment or null lines */
113 116
 			continue;
114 117
 		} else {
115 118
 			/* Remove the last part of the string where a side
116
-			 * comment starts, 	#a comment like this.
119
+			 * comment starts,  #a comment like this.
117 120
 			 */
118
-			if((p=strrchr(str, '#')))
119
-				*p='\0';
120
-			
121
+			if ((p = strrchr(str, '#')))
122
+				*p = '\0';
123
+
121 124
 			/* Don't include the newline and spaces of the end of 
122 125
 			 * the string */
123
-			slen=strlen(str);
124
-			for(p=&str[slen-1]; isspace(*p); p--)
125
-				*p='\0';
126
-			
126
+			slen = strlen(str);
127
+			for (p = &str[slen - 1]; isspace(*p); p--)
128
+				*p = '\0';
129
+
127 130
 
128 131
 			parse_config_line(file, e, str);
129 132
 			i++;

+ 36
- 38
src/conf.h View File

@@ -41,8 +41,7 @@
41 41
 /* 
42 42
  * The allowed options in the configuration file
43 43
  */
44
-enum config_options
45
-{
44
+enum config_options {
46 45
 	CONF_NTK_INT_MAP_FILE,
47 46
 	CONF_NTK_BNODE_MAP_FILE,
48 47
 	CONF_NTK_EXT_MAP_FILE,
@@ -62,7 +61,7 @@ enum config_options
62 61
 
63 62
 	CONF_DISABLE_ANDNA,
64 63
 	CONF_DISABLE_RESOLVCONF,
65
-	
64
+
66 65
 	CONF_NTK_RESTRICTED_MODE,
67 66
 	CONF_NTK_RESTRICTED_CLASS,
68 67
 	CONF_NTK_INTERNET_CONNECTION,
@@ -77,44 +76,43 @@ enum config_options
77 76
 	CONF_NTK_TC_SHAPER_SCRIPT,
78 77
 };
79 78
 
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 },
79
+const static char config_str[][30] = {
80
+	{"ntk_int_map_file"},
81
+	{"ntk_bnode_map_file"},
82
+	{"ntk_ext_map_file"},
83
+
84
+	{"andna_hnames_file"},
85
+	{"snsd_nodes_file"},
86
+	{"andna_cache_file"},
87
+	{"andna_lclkey_file"},
88
+	{"andna_lcl_file"},
89
+	{"andna_rhc_file"},
90
+	{"andna_counter_c_file"},
91
+
92
+	{"pid_file"},
93
+	{"ntk_max_connections"},
94
+	{"ntk_max_accepts_per_host"},
95
+	{"max_accepts_per_host_time"},
96
+
97
+	{"disable_andna"},
98
+	{"disable_resolvconf"},
99
+	{"ntk_restricted_mode"},
100
+	{"ntk_restricted_class"},
101
+	{"internet_connection"},
102
+	{"internet_gateway"},
103
+	{"internet_upload_rate"},
104
+	{"internet_download_rate"},
105
+	{"internet_ping_hosts"},
106
+	{"share_internet"},
107
+	{"shape_internet"},
108
+	{"use_shared_internet"},
109
+	{"ip_masquerade_script"},
110
+	{"tc_shaper_script"},
111
+	{0},
114 112
 };
115 113
 
116 114
 
117 115
 void clear_config_env(void);
118 116
 int load_config_file(char *file);
119 117
 
120
-#endif /*CONF_H*/
118
+#endif							/*CONF_H */

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

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

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

@@ -1,464 +0,0 @@
1
-# Makefile.in generated by automake 1.13.3 from Makefile.am.
2
-# @configure_input@
3
-
4
-# Copyright (C) 1994-2013 Free Software Foundation, Inc.
5
-
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
-VPATH = @srcdir@
18
-am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
19
-am__make_running_with_option = \
20
-  case $${target_option-} in \
21
-      ?) ;; \
22
-      *) echo "am__make_running_with_option: internal error: invalid" \
23
-              "target option '$${target_option-}' specified" >&2; \
24
-         exit 1;; \
25
-  esac; \
26
-  has_opt=no; \
27
-  sane_makeflags=$$MAKEFLAGS; \
28
-  if $(am__is_gnu_make); then \
29
-    sane_makeflags=$$MFLAGS; \
30
-  else \
31
-    case $$MAKEFLAGS in \
32
-      *\\[\ \	]*) \
33
-        bs=\\; \
34
-        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
35
-          | sed "s/$$bs$$bs[$$bs $$bs	]*//g"`;; \
36
-    esac; \
37
-  fi; \
38
-  skip_next=no; \
39
-  strip_trailopt () \
40
-  { \
41
-    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
42
-  }; \
43
-  for flg in $$sane_makeflags; do \
44
-    test $$skip_next = yes && { skip_next=no; continue; }; \
45
-    case $$flg in \
46
-      *=*|--*) continue;; \
47
-        -*I) strip_trailopt 'I'; skip_next=yes;; \
48
-      -*I?*) strip_trailopt 'I';; \
49
-        -*O) strip_trailopt 'O'; skip_next=yes;; \
50
-      -*O?*) strip_trailopt 'O';; \
51
-        -*l) strip_trailopt 'l'; skip_next=yes;; \
52
-      -*l?*) strip_trailopt 'l';; \
53
-      -[dEDm]) skip_next=yes;; \
54
-      -[JT]) skip_next=yes;; \
55
-    esac; \
56
-    case $$flg in \
57
-      *$$target_option*) has_opt=yes; break;; \
58
-    esac; \
59
-  done; \
60
-  test $$has_opt = yes
61
-am__make_dryrun = (target_option=n; $(am__make_running_with_option))
62
-am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
63
-pkgdatadir = $(datadir)/@PACKAGE@
64
-pkgincludedir = $(includedir)/@PACKAGE@
65
-pkglibdir = $(libdir)/@PACKAGE@
66
-pkglibexecdir = $(libexecdir)/@PACKAGE@
67
-am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
68
-install_sh_DATA = $(install_sh) -c -m 644
69
-install_sh_PROGRAM = $(install_sh) -c
70
-install_sh_SCRIPT = $(install_sh) -c
71
-INSTALL_HEADER = $(INSTALL_DATA)
72
-transform = $(program_transform_name)
73
-NORMAL_INSTALL = :
74
-PRE_INSTALL = :
75
-POST_INSTALL = :
76
-NORMAL_UNINSTALL = :
77
-PRE_UNINSTALL = :
78
-POST_UNINSTALL = :
79
-build_triplet = @build@
80
-host_triplet = @host@
81
-subdir = src/conf
82
-DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \
83
-	$(srcdir)/netsukuku.conf.in
84
-ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
85
-am__aclocal_m4_deps = $(top_srcdir)/configure.ac
86
-am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
87
-	$(ACLOCAL_M4)
88
-mkinstalldirs = $(install_sh) -d
89
-CONFIG_HEADER = $(top_builddir)/src/config.h
90
-CONFIG_CLEAN_FILES = netsukuku.conf
91
-CONFIG_CLEAN_VPATH_FILES =
92
-AM_V_P = $(am__v_P_@AM_V@)
93
-am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
94
-am__v_P_0 = false
95
-am__v_P_1 = :
96
-AM_V_GEN = $(am__v_GEN_@AM_V@)
97
-am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
98
-am__v_GEN_0 = @echo "  GEN     " $@;
99
-am__v_GEN_1 = 
100
-AM_V_at = $(am__v_at_@AM_V@)
101
-am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
102
-am__v_at_0 = @
103
-am__v_at_1 = 
104
-SOURCES =
105
-DIST_SOURCES =
106
-am__can_run_installinfo = \
107
-  case $$AM_UPDATE_INFO_DIR in \
108
-    n|no|NO) false;; \
109
-    *) (install-info --version) >/dev/null 2>&1;; \
110
-  esac
111
-am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
112
-am__vpath_adj = case $$p in \
113
-    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
114
-    *) f=$$p;; \
115
-  esac;
116
-am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
117
-am__install_max = 40
118
-am__nobase_strip_setup = \
119
-  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
120
-am__nobase_strip = \
121
-  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
122
-am__nobase_list = $(am__nobase_strip_setup); \
123
-  for p in $$list; do echo "$$p $$p"; done | \
124
-  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
125
-  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
126
-    if (++n[$$2] == $(am__install_max)) \
127
-      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
128
-    END { for (dir in files) print dir, files[dir] }'
129
-am__base_list = \
130
-  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
131
-  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
132
-am__uninstall_files_from_dir = { \
133
-  test -z "$$files" \
134
-    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
135
-    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
136
-         $(am__cd) "$$dir" && rm -f $$files; }; \
137
-  }
138
-am__installdirs = "$(DESTDIR)$(sysconfdir)"
139
-DATA = $(sysconf_DATA)
140
-am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
141
-DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
142
-ACLOCAL = @ACLOCAL@
143
-AMTAR = @AMTAR@
144
-AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
145
-AUTOCONF = @AUTOCONF@
146
-AUTOHEADER = @AUTOHEADER@
147
-AUTOMAKE = @AUTOMAKE@
148
-AWK = @AWK@
149
-CC = @CC@
150
-CCDEPMODE = @CCDEPMODE@
151
-CFLAGS = @CFLAGS@
152
-CONF_DIR = @CONF_DIR@
153
-CPP = @CPP@
154
-CPPFLAGS = @CPPFLAGS@
155
-CXX = @CXX@
156
-CXXDEPMODE = @CXXDEPMODE@
157
-CXXFLAGS = @CXXFLAGS@
158
-CYGPATH_W = @CYGPATH_W@
159
-DATA_DIR = @DATA_DIR@
160
-DEFS = @DEFS@
161
-DEPDIR = @DEPDIR@
162
-ECHO_C = @ECHO_C@
163
-ECHO_N = @ECHO_N@
164
-ECHO_T = @ECHO_T@
165
-EGREP = @EGREP@
166
-EXEEXT = @EXEEXT@
167
-GREP = @GREP@
168
-IF_METHOD = @IF_METHOD@
169
-INSTALL = @INSTALL@
170
-INSTALL_DATA = @INSTALL_DATA@
171
-INSTALL_PROGRAM = @INSTALL_PROGRAM@
172
-INSTALL_SCRIPT = @INSTALL_SCRIPT@
173
-INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
174
-KERNEL_METHOD = @KERNEL_METHOD@
175
-LDFLAGS = @LDFLAGS@
176
-LIBOBJS = @LIBOBJS@
177
-LIBS = @LIBS@
178
-LTLIBOBJS = @LTLIBOBJS@
179
-MAKEINFO = @MAKEINFO@
180
-MKDIR_P = @MKDIR_P@
181
-OBJEXT = @OBJEXT@
182
-OTHER_METHOD = @OTHER_METHOD@
183
-PACKAGE = @PACKAGE@
184
-PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
185
-PACKAGE_NAME = @PACKAGE_NAME@
186
-PACKAGE_STRING = @PACKAGE_STRING@
187
-PACKAGE_TARNAME = @PACKAGE_TARNAME@
188
-PACKAGE_URL = @PACKAGE_URL@
189
-PACKAGE_VERSION = @PACKAGE_VERSION@
190
-PATH_SEPARATOR = @PATH_SEPARATOR@
191
-PID_DIR = @PID_DIR@
192
-RT_METHOD = @RT_METHOD@
193
-SET_MAKE = @SET_MAKE@
194
-SHELL = @SHELL@
195
-STRIP = @STRIP@
196
-VERSION = @VERSION@
197
-abs_builddir = @abs_builddir@
198
-abs_srcdir = @abs_srcdir@
199
-abs_top_builddir = @abs_top_builddir@
200
-abs_top_srcdir = @abs_top_srcdir@
201
-ac_ct_CC = @ac_ct_CC@
202
-ac_ct_CXX = @ac_ct_CXX@
203
-am__include = @am__include@
204
-am__leading_dot = @am__leading_dot@
205
-am__quote = @am__quote@
206
-am__tar = @am__tar@
207
-am__untar = @am__untar@
208
-bindir = @bindir@
209
-build = @build@
210
-build_alias = @build_alias@
211
-build_cpu = @build_cpu@
212
-build_os = @build_os@
213
-build_vendor = @build_vendor@
214
-builddir = @builddir@
215
-datadir = @datadir@
216
-datarootdir = @datarootdir@
217
-debug_flags = @debug_flags@
218
-docdir = @docdir@
219
-dvidir = @dvidir@
220
-exec_prefix = @exec_prefix@
221
-gmp = @gmp@
222
-host = @host@
223
-host_alias = @host_alias@
224
-host_cpu = @host_cpu@
225
-host_os = @host_os@
226
-host_vendor = @host_vendor@
227
-htmldir = @htmldir@
228
-includedir = @includedir@
229
-infodir = @infodir@
230
-install_sh = @install_sh@
231
-libdir = @libdir@
232
-libexecdir = @libexecdir@
233
-localedir = @localedir@
234
-localstatedir = @localstatedir@
235
-mandir = @mandir@
236
-mkdir_p = @mkdir_p@
237
-oldincludedir = @oldincludedir@
238
-pdfdir = @pdfdir@
239
-prefix = @prefix@
240
-program_transform_name = @program_transform_name@
241
-psdir = @psdir@
242
-sbindir = @sbindir@
243
-sharedstatedir = @sharedstatedir@
244
-srcdir = @srcdir@
245
-sysconfdir = @sysconfdir@
246
-target_alias = @target_alias@
247
-top_build_prefix = @top_build_prefix@
248
-top_builddir = @top_builddir@
249
-top_srcdir = @top_srcdir@
250
-sysconf_DATA = netsukuku.conf andna_hostnames snsd_nodes
251
-all: all-am
252
-
253
-.SUFFIXES:
254
-$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
255
-	@for dep in $?; do \
256
-	  case '$(am__configure_deps)' in \
257
-	    *$$dep*) \
258
-	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
259
-	        && { if test -f $@; then exit 0; else break; fi; }; \
260
-	      exit 1;; \
261
-	  esac; \
262
-	done; \
263
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/conf/Makefile'; \
264
-	$(am__cd) $(top_srcdir) && \
265
-	  $(AUTOMAKE) --gnu src/conf/Makefile
266
-.PRECIOUS: Makefile
267
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
268
-	@case '$?' in \
269
-	  *config.status*) \
270
-	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
271
-	  *) \
272
-	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
273
-	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
274
-	esac;
275
-
276
-$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
277
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
278
-
279
-$(top_srcdir)/configure:  $(am__configure_deps)
280
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
281
-$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
282
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
283
-$(am__aclocal_m4_deps):
284
-netsukuku.conf: $(top_builddir)/config.status $(srcdir)/netsukuku.conf.in
285
-	cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
286
-install-sysconfDATA: $(sysconf_DATA)
287
-	@$(NORMAL_INSTALL)
288
-	@list='$(sysconf_DATA)'; test -n "$(sysconfdir)" || list=; \
289
-	if test -n "$$list"; then \
290
-	  echo " $(MKDIR_P) '$(DESTDIR)$(sysconfdir)'"; \
291
-	  $(MKDIR_P) "$(DESTDIR)$(sysconfdir)" || exit 1; \
292
-	fi; \
293
-	for p in $$list; do \
294
-	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
295
-	  echo "$$d$$p"; \
296
-	done | $(am__base_list) | \
297
-	while read files; do \
298
-	  echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(sysconfdir)'"; \
299
-	  $(INSTALL_DATA) $$files "$(DESTDIR)$(sysconfdir)" || exit $$?; \
300
-	done
301
-
302
-uninstall-sysconfDATA:
303
-	@$(NORMAL_UNINSTALL)
304
-	@list='$(sysconf_DATA)'; test -n "$(sysconfdir)" || list=; \
305
-	files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
306
-	dir='$(DESTDIR)$(sysconfdir)'; $(am__uninstall_files_from_dir)
307
-tags TAGS:
308
-
309
-ctags CTAGS:
310
-
311
-cscope cscopelist:
312
-
313
-
314
-distdir: $(DISTFILES)
315
-	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
316
-	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
317
-	list='$(DISTFILES)'; \
318
-	  dist_files=`for file in $$list; do echo $$file; done | \
319
-	  sed -e "s|^$$srcdirstrip/||;t" \
320
-	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
321
-	case $$dist_files in \
322
-	  */*) $(MKDIR_P) `echo "$$dist_files" | \
323
-			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
324
-			   sort -u` ;; \
325
-	esac; \
326
-	for file in $$dist_files; do \
327
-	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
328
-	  if test -d $$d/$$file; then \
329
-	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
330
-	    if test -d "$(distdir)/$$file"; then \
331
-	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
332
-	    fi; \
333
-	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
334
-	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
335
-	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
336
-	    fi; \
337
-	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
338
-	  else \
339
-	    test -f "$(distdir)/$$file" \
340
-	    || cp -p $$d/$$file "$(distdir)/$$file" \
341
-	    || exit 1; \
342
-	  fi; \
343
-	done
344
-check-am: all-am
345
-check: check-am
346
-all-am: Makefile $(DATA)
347
-installdirs:
348
-	for dir in "$(DESTDIR)$(sysconfdir)"; do \
349
-	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
350
-	done
351
-install: install-am
352
-install-exec: install-exec-am
353
-install-data: install-data-am
354
-uninstall: uninstall-am
355
-
356
-install-am: all-am
357
-	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
358
-
359
-installcheck: installcheck-am
360
-install-strip:
361
-	if test -z '$(STRIP)'; then \
362
-	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
363
-	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
364
-	      install; \
365
-	else \
366
-	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
367
-	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
368
-	    "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
369
-	fi
370
-mostlyclean-generic:
371
-
372
-clean-generic:
373
-
374
-distclean-generic:
375
-	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
376
-	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
377
-
378
-maintainer-clean-generic:
379
-	@echo "This command is intended for maintainers to use"
380
-	@echo "it deletes files that may require special tools to rebuild."
381
-clean: clean-am
382
-
383
-clean-am: clean-generic mostlyclean-am
384
-
385
-distclean: distclean-am
386
-	-rm -f Makefile
387
-distclean-am: clean-am distclean-generic
388
-
389
-dvi: dvi-am
390
-
391
-dvi-am:
392
-
393
-html: html-am
394
-
395
-html-am:
396
-
397
-info: info-am
398
-
399
-info-am:
400
-
401
-install-data-am:
402
-
403
-install-dvi: install-dvi-am
404
-
405
-install-dvi-am:
406
-
407
-install-exec-am: install-sysconfDATA
408
-
409
-install-html: install-html-am
410
-
411
-install-html-am:
412
-
413
-install-info: install-info-am
414
-
415
-install-info-am:
416
-
417
-install-man:
418
-
419
-install-pdf: install-pdf-am
420
-
421
-install-pdf-am:
422
-
423
-install-ps: install-ps-am
424
-
425
-install-ps-am:
426
-
427
-installcheck-am:
428
-
429
-maintainer-clean: maintainer-clean-am
430
-	-rm -f Makefile
431
-maintainer-clean-am: distclean-am maintainer-clean-generic
432
-
433
-mostlyclean: mostlyclean-am
434
-
435
-mostlyclean-am: mostlyclean-generic
436
-
437
-pdf: pdf-am
438
-
439
-pdf-am:
440
-
441
-ps: ps-am
442
-
443
-ps-am:
444
-
445
-uninstall-am: uninstall-sysconfDATA
446
-
447
-.MAKE: install-am install-strip
448
-
449
-.PHONY: all all-am check check-am clean clean-generic cscopelist-am \
450
-	ctags-am distclean distclean-generic distdir dvi dvi-am html \
451
-	html-am info info-am install install-am install-data \
452
-	install-data-am install-dvi install-dvi-am install-exec \
453
-	install-exec-am install-html install-html-am install-info \
454
-	install-info-am install-man install-pdf install-pdf-am \
455
-	install-ps install-ps-am install-strip install-sysconfDATA \
456
-	installcheck installcheck-am installdirs maintainer-clean \
457
-	maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
458
-	pdf-am ps ps-am tags-am uninstall uninstall-am \
459
-	uninstall-sysconfDATA
460
-
461
-
462
-# Tell versions [3.59,3.63) of GNU make to not export all variables.
463
-# Otherwise a system limit (for SysV at least) may be exceeded.
464
-.NOEXPORT:

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

@@ -1,199 +0,0 @@
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

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

@@ -1,109 +0,0 @@
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 home page for this package. */
94
-#undef PACKAGE_URL
95
-
96
-/* Define to the version of this package. */
97
-#undef PACKAGE_VERSION
98
-
99
-/* ntkd.pid file location */
100
-#undef PID_DIR
101
-
102
-/* Define to 1 if you have the ANSI C header files. */
103
-#undef STDC_HEADERS
104
-
105
-/* SunOS 5 */
106
-#undef SUNOS
107
-
108
-/* Version number of package */
109
-#undef VERSION

+ 60
- 0
src/console.h View File

@@ -0,0 +1,60 @@
1
+/* This file is part of Netsukuku
2
+ *
3
+ * This source code is free software; you can redistribute it and/or
4
+ * modify it under the terms of the GNU General Public License as published
5
+ * by the Free Software Foundation; either version 2 of the License,
6
+ * or (at your option) any later version.
7
+ *
8
+ * This source code is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
+ * Please refer to the GNU Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU Public License along with
14
+ * this source code; if not, write to:
15
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ *
17
+ */
18
+#ifndef CONSOLE_H
19
+#define CONSOLE_H
20
+
21
+
22
+#define CONSOLE_SOCKET_PATH 	"/tmp/ntk-console"
23
+#define CONSOLE_VERSION_MAJOR	0
24
+#define CONSOLE_VERSION_MINOR 	3
25
+#define CONSOLE_ARGV_LENGTH 	250
26
+#define CONSOLE_BUFFER_LENGTH 	250
27
+
28
+#ifndef TRUE
29
+#define FALSE               0
30
+#define TRUE                1
31
+#endif
32
+
33
+
34
+typedef enum {
35
+	COMMAND_HELP = 0x100,
36
+	COMMAND_UPTIME,
37
+	COMMAND_KILL,
38
+	COMMAND_VERSION,
39
+	COMMAND_INETCONN,
40
+	COMMAND_CURIFS,
41
+	COMMAND_CURIFSCT,
42
+	COMMAND_CURQSPNID,
43
+	COMMAND_CURIP,
44
+	COMMAND_CURNODE,
45
+	COMMAND_IFS,
46
+	COMMAND_IFSCT,
47
+	COMMAND_QUIT,
48
+	COMMAND_CONSUPTIME,
49
+} command_t;
50
+
51
+
52
+#pragma pack(1)
53
+typedef struct {
54
+	command_t command;
55
+	char *argv[CONSOLE_ARGV_LENGTH];
56
+} cmd_packet_t;
57
+#pragma pack(0)
58
+
59
+
60
+#endif							/* CONSOLE_H */

+ 57
- 43
src/crypto.c View File

@@ -35,18 +35,21 @@
35 35
 #include "log.h"
36 36
 #include "xmalloc.h"
37 37
 
38
-void init_crypto(void)
38
+void
39
+init_crypto(void)
39 40
 {
40 41
 	RAND_load_file("/dev/urandom", 1024);
41 42
 	ERR_load_crypto_strings();
42 43
 }
43 44
 
44
-void free_crypto(void)
45
+void
46
+free_crypto(void)
45 47
 {
46 48
 	ERR_free_strings();
47 49
 }
48 50
 
49
-char *ssl_strerr(void)
51
+char *
52
+ssl_strerr(void)
50 53
 {
51 54
 	return ERR_error_string(ERR_get_error(), 0);
52 55
 }
@@ -58,43 +61,47 @@ char *ssl_strerr(void)
58 61
  * `priv' and `priv_len'.
59 62
  * On error null is returned.
60 63
  */
61
-RSA *genrsa(int key_bits, u_char **pub, u_int *pub_len, u_char **priv, u_int *priv_len)
64
+RSA *
65
+genrsa(int key_bits, u_char ** pub, u_int * pub_len, u_char ** priv,
66
+	   u_int * priv_len)
62 67
 {
63
-	RSA *rsa=0;
68
+	RSA *rsa = 0;
64 69
 	int len;
65
-	
66
-	rsa=RSA_generate_key(key_bits, RSA_F4, NULL, NULL);
70
+
71
+	rsa = RSA_generate_key(key_bits, RSA_F4, NULL, NULL);
67 72
 	if (!rsa) {
68
-		debug(DBG_SOFT, "RSA key generation failed"); 
73
+		debug(DBG_SOFT, "RSA key generation failed");
69 74
 		goto error;
70 75
 	}
71 76
 
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());
77
+	if (priv) {
78
+		*priv = 0;
79
+		len = i2d_RSAPrivateKey(rsa, priv);
80
+		if (priv_len)
81
+			*priv_len = len;
82
+		if (len <= 0) {
83
+			debug(DBG_SOFT, "Cannot dump RSA public key: %s",
84
+				  ssl_strerr());
79 85
 			goto error;
80 86
 		}
81 87
 	}
82 88
 
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());
89
+	if (pub) {
90
+		*pub = 0;
91
+		len = i2d_RSAPublicKey(rsa, pub);
92
+		if (pub_len)
93
+			*pub_len = len;
94
+		if (len <= 0) {
95
+			debug(DBG_SOFT, "Cannot dump RSA public key: %s",
96
+				  ssl_strerr());
90 97
 			goto error;
91 98
 		}
92 99
 	}
93
-	
100
+
94 101
 	return rsa;
95
-error:
96
-	if(rsa)
97
-		RSA_free(rsa);	
102
+  error:
103
+	if (rsa)
104
+		RSA_free(rsa);
98 105
 	return 0;
99 106
 }
100 107
 
@@ -104,9 +111,10 @@ error:
104 111
  * Converts a dump of a rsa pub key to a RSA structure, which is returned.
105 112
  * Remeber to RSA_free() the returned key.
106 113
  */
107
-RSA *get_rsa_pub(const u_char **pub_key, long length)
114
+RSA *
115
+get_rsa_pub(const u_char ** pub_key, long length)
108 116
 {
109
-	 return d2i_RSAPublicKey(NULL, pub_key, length);
117
+	return d2i_RSAPublicKey(NULL, pub_key, length);
110 118
 }
111 119
 
112 120
 /*
@@ -115,17 +123,20 @@ RSA *get_rsa_pub(const u_char **pub_key, long length)
115 123
  * Converts a dump of a rsa priv key to a RSA structure, which is returned.
116 124
  * Remeber to RSA_free() the returned key.
117 125
  */
118
-RSA *get_rsa_priv(const u_char **priv_key, long length)
126
+RSA *
127
+get_rsa_priv(const u_char ** priv_key, long length)
119 128
 {
120
-	 return d2i_RSAPrivateKey(NULL, priv_key, length);
129
+	return d2i_RSAPrivateKey(NULL, priv_key, length);
121 130
 }
122 131
 
123
-u_char *hash_sha1(u_char *msg, u_int m_len, u_char *hash)
132
+u_char *
133
+hash_sha1(u_char * msg, u_int m_len, u_char * hash)
124 134
 {
125 135
 	return SHA1(msg, m_len, hash);
126 136
 }
127 137
 
128
-u_char *hash_md5(u_char *msg, u_int m_len, u_char *hash)
138
+u_char *
139
+hash_md5(u_char * msg, u_int m_len, u_char * hash)
129 140
 {
130 141
 	return MD5(msg, m_len, hash);
131 142
 }
@@ -135,20 +146,21 @@ u_char *hash_md5(u_char *msg, u_int m_len, u_char *hash)
135 146
  * signature. In `siglen' it stores the signature's lenght.
136 147
  * On error null is returned.
137 148
  */
138
-u_char *rsa_sign(u_char *msg, u_int m_len, RSA *priv, u_int *siglen)
149
+u_char *
150
+rsa_sign(u_char * msg, u_int m_len, RSA * priv, u_int * siglen)
139 151
 {
140 152
 	u_char *signature;
141 153
 	int ret, len;
142 154
 
143
-	ret=RSA_size(priv);
144
-	if(!ret)
155
+	ret = RSA_size(priv);
156
+	if (!ret)
145 157
 		return 0;
146 158
 
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;
159
+	signature = (u_char *) xmalloc(ret);
160
+	ret = RSA_sign(NID_sha1, hash_sha1(msg, m_len, 0), SHA_DIGEST_LENGTH,
161
+				   signature, (u_int *) & len, priv);
162
+	if (siglen)
163
+		*siglen = len;
152 164
 
153 165
 	return !ret ? 0 : signature;
154 166
 }
@@ -157,8 +169,10 @@ u_char *rsa_sign(u_char *msg, u_int m_len, RSA *priv, u_int *siglen)
157 169
  * verify_sign: verifies the rsa `signature' of `msg'.
158 170
  * It returns 1 if the signature is valid, otherwise 0 is returned.
159 171
  */
160
-int verify_sign(u_char *msg, u_int m_len, u_char *signature, u_int siglen, RSA *pub)
172
+int
173
+verify_sign(u_char * msg, u_int m_len, u_char * signature, u_int siglen,
174
+			RSA * pub)
161 175
 {
162
-        return RSA_verify(NID_sha1, hash_sha1(msg, m_len, 0), SHA_DIGEST_LENGTH,
163
-			signature, siglen, pub);
176
+	return RSA_verify(NID_sha1, hash_sha1(msg, m_len, 0),
177
+					  SHA_DIGEST_LENGTH, signature, siglen, pub);
164 178
 }

+ 10
- 8
src/crypto.h View File

@@ -35,12 +35,14 @@
35 35
 void init_crypto(void);
36 36
 void free_crypto(void);
37 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);
38
+RSA *genrsa(int key_bits, u_char ** pub, u_int * pub_len, u_char ** priv,
39
+			u_int * priv_len);
40
+RSA *get_rsa_pub(const u_char ** pub_key, long length);
41
+RSA *get_rsa_priv(const u_char ** priv_key, long length);
42
+u_char *hash_sha1(u_char * msg, u_int len, u_char * hash);
43
+u_char *hash_md5(u_char * msg, u_int m_len, u_char * hash);
44
+u_char *rsa_sign(u_char * msg, u_int m_len, RSA * priv, u_int * siglen);
45
+int verify_sign(u_char * msg, u_int m_len, u_char * signature,
46
+				u_int siglen, RSA * pub);
45 47
 
46
-#endif /*CRYPTO_H*/
48
+#endif							/*CRYPTO_H */

+ 143
- 134
src/daemon.c View File

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

+ 10
- 9
src/daemon.h View File

@@ -28,28 +28,29 @@ pthread_mutex_t tcp_daemon_lock;
28 28
 
29 29
 /* flags for udp_exec_pkt_argv and udp_daemon_argv */
30 30
 #define UDP_THREAD_FOR_EACH_PKT		1	/* For each incoming udp
31
-						   packets use threads */
31
+										   packets use threads */
32 32
 
33 33
 /* Argv passed to udp_exec_pkt() */
34 34
 struct udp_exec_pkt_argv {
35
-	PACKET 		*recv_pkt;
36
-	int		acpt_idx;
37
-	int		acpt_sidx;
38
-	u_char		flags;
35
+	PACKET *recv_pkt;
36
+	int acpt_idx;
37
+	int acpt_sidx;
38
+	u_char flags;
39 39
 };
40 40
 
41 41
 /* Argv passed to udp_daemon */
42 42
 struct udp_daemon_argv {
43
-	u_short		port;
44
-	u_char		flags;
43
+	u_short port;
44
+	u_char flags;
45 45
 };
46 46
 
47 47
 pthread_mutex_t udp_exec_lock;
48 48
 pthread_mutex_t tcp_exec_lock;
49 49
 
50
-int prepare_listen_socket(int family, int socktype, u_short port, interface *dev);
50
+int prepare_listen_socket(int family, int socktype, u_short port,
51
+						  interface * dev);
51 52
 void *tcp_recv_loop(void *recv_pkt);
52 53
 void *tcp_daemon(void *null);
53 54
 void *udp_daemon(void *door);
54 55
 
55
-#endif /*DAEMON_H*/
56
+#endif							/*DAEMON_H */

+ 36
- 29
src/dns_wrapper.c View File

@@ -52,7 +52,8 @@
52 52
  * the reply to from.
53 53
  * `passed_argv' is a pointer to a dns_exec_pkt_argv struct.
54 54
  */
55
-void *dns_exec_pkt(void *passed_argv)
55
+void *
56
+dns_exec_pkt(void *passed_argv)
56 57
 {
57 58
 	struct dns_exec_pkt_argv argv;
58 59
 
@@ -71,16 +72,19 @@ void *dns_exec_pkt(void *passed_argv)
71 72
 	}
72 73
 
73 74
 	/* Unpack the DNS query and resolve the hostname */
74
-	if(!andns_rslv(buf, argv.rpkt_sz, answer_buffer, &answer_length))
75
+	if (!andns_rslv(buf, argv.rpkt_sz, answer_buffer, &answer_length))
75 76
 		return 0;
76 77
 
77 78
 	/* Send the DNS reply */
78
-	bytes_sent=inet_sendto(argv.sk, answer_buffer, answer_length, 0,
79
-			&argv.from, argv.from_len);
80
-        error("bytes_sent is: %d argv.sk is: %d answer_buffer is: %s answer_length is: %d argv.from is: %p agrv.from_len is: %p", bytes_sent,argv.sk, answer_buffer, answer_length, argv.from, argv.from_len);
81
-	if(bytes_sent != answer_length)
79
+	bytes_sent = inet_sendto(argv.sk, answer_buffer, answer_length, 0,
80
+							 &argv.from, argv.from_len);
81
+	error
82
+		("bytes_sent is: %d argv.sk is: %d answer_buffer is: %s answer_length is: %d argv.from is: %p agrv.from_len is: %p",
83
+		 bytes_sent, argv.sk, answer_buffer, answer_length, argv.from,
84
+		 argv.from_len);
85
+	if (bytes_sent != answer_length)
82 86
 		debug(DBG_SOFT, ERROR_MSG "inet_sendto error: %s", ERROR_POS,
83
-				strerror(errno));
87
+			  strerror(errno));
84 88
 
85 89
 	return 0;
86 90
 }
@@ -90,7 +94,8 @@ void *dns_exec_pkt(void *passed_argv)
90 94
  * replies with a DNS reply.
91 95
  * It listens to `port'.
92 96
  */
93
-void dns_wrapper_daemon(u_short port)
97
+void
98
+dns_wrapper_daemon(u_short port)
94 99
 {
95 100
 	struct dns_exec_pkt_argv exec_pkt_argv;
96 101
 	char buf[MAX_DNS_PKT_SZ];
@@ -99,44 +104,45 @@ void dns_wrapper_daemon(u_short port)
99 104
 	int ret, sk;
100 105
 	pthread_t thread;
101 106
 	pthread_attr_t t_attr;
102
-	ssize_t err=-1;
107
+	ssize_t err = -1;
103 108
 
104 109
 #ifdef DEBUG
105
-	int select_errors=0;
110
+	int select_errors = 0;
106 111
 #endif
107 112
 
108 113
 	pthread_attr_init(&t_attr);
109 114
 	pthread_attr_setdetachstate(&t_attr, PTHREAD_CREATE_DETACHED);
110 115
 	pthread_mutex_init(&dns_exec_lock, 0);
111 116
 
112
-	debug(DBG_SOFT, "Preparing the dns_udp listening socket on port %d", port);
113
-	sk=prepare_listen_socket(my_family, SOCK_DGRAM, port, 0);
114
-	if(sk == -1)
117
+	debug(DBG_SOFT, "Preparing the dns_udp listening socket on port %d",
118
+		  port);
119
+	sk = prepare_listen_socket(my_family, SOCK_DGRAM, port, 0);
120
+	if (sk == -1)
115 121
 		return;
116 122
 
117 123
 	debug(DBG_NORMAL, "DNS wrapper daemon on port %d up & running", port);
118
-	for(;;) {
119
-		if(!sk)
124
+	for (;;) {
125
+		if (!sk)
120 126
 			fatal("The dns_wrapper_daemon socket got corrupted");
121 127
 
122 128
 		FD_ZERO(&fdset);
123 129
 		FD_SET(sk, &fdset);
124 130
 
125
-		ret = select(sk+1, &fdset, NULL, NULL, NULL);
126
-		if(sigterm_timestamp)
131
+		ret = select(sk + 1, &fdset, NULL, NULL, NULL);
132
+		if (sigterm_timestamp)
127 133
 			/* NetsukukuD has been closed */
128 134
 			break;
129 135
 		if (ret < 0) {
130 136
 #ifdef DEBUG
131
-			if(select_errors > 20)
137
+			if (select_errors > 20)
132 138
 				break;
133 139
 			select_errors++;
134 140
 #endif
135 141
 			error("dns_wrapper_daemonp: select error: %s",
136
-					strerror(errno));
142
+				  strerror(errno));
137 143
 			continue;
138 144
 		}
139
-		if(!FD_ISSET(sk, &fdset))
145
+		if (!FD_ISSET(sk, &fdset))
140 146
 			continue;
141 147
 
142 148
 		setzero(&buf, MAX_DNS_PKT_SZ);
@@ -147,28 +153,29 @@ void dns_wrapper_daemon(u_short port)
147 153
 			sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6);
148 154
 
149 155
 		/* we get the DNS query */
150
-		err=inet_recvfrom(sk, buf, MAX_DNS_PKT_SZ, MSG_WAITALL,
151
-				&exec_pkt_argv.from, &exec_pkt_argv.from_len);
152
-		if(err < 0) {
156
+		err = inet_recvfrom(sk, buf, MAX_DNS_PKT_SZ, MSG_WAITALL,
157
+							&exec_pkt_argv.from, &exec_pkt_argv.from_len);
158
+		if (err < 0) {
153 159
 			debug(DBG_NOISE, "dns_wrapper_daemonp: recv of the dns"
154
-					" query pkt aborted!");
160
+				  " query pkt aborted!");
155 161
 			continue;
156 162
 		}
157 163
 
158 164
 		/* Exec the pkt in another thread */
159
-		exec_pkt_argv.sk=sk;
160
-		exec_pkt_argv.rpkt_sz=err;
161
-		exec_pkt_argv.rpkt=buf;
165
+		exec_pkt_argv.sk = sk;
166
+		exec_pkt_argv.rpkt_sz = err;
167
+		exec_pkt_argv.rpkt = buf;
162 168
 
163 169
 		pthread_mutex_lock(&dns_exec_lock);
164 170
 		pthread_create(&thread, &t_attr, dns_exec_pkt,
165
-				(void *)&exec_pkt_argv);
171
+					   (void *) &exec_pkt_argv);
166 172
 		pthread_mutex_lock(&dns_exec_lock);
167 173
 		pthread_mutex_unlock(&dns_exec_lock);
168 174
 	}
169 175
 }
170 176
 
171
-void *dns_wrapper_thread(void *null)
177
+void *
178
+dns_wrapper_thread(void *null)
172 179
 {
173 180
 	dns_wrapper_daemon(DNS_WRAPPER_PORT);
174 181
 	return 0;

+ 11
- 12
src/dns_wrapper.h View File

@@ -24,21 +24,20 @@
24 24
 #define MIN_PKT_SZ		7
25 25
 
26 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));
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 30
 
31 31
 /*
32 32
  * dns_exec_pkt_argv is the struct passed to dns_exec_pkt() as argument 
33 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;
34
+struct dns_exec_pkt_argv {
35
+	char *rpkt;					/* Received dns query pkt */
36
+	ssize_t rpkt_sz;
37
+
38
+	int sk;
39
+	struct sockaddr from;
40
+	socklen_t from_len;
42 41
 };
43 42
 
44 43
 pthread_mutex_t dns_exec_lock;
@@ -47,4 +46,4 @@ pthread_mutex_t dns_exec_lock;
47 46
 
48 47
 void *dns_wrapper_thread(void *null);
49 48
 
50
-#endif /*DNS_WRAPPER_H*/
49
+#endif							/*DNS_WRAPPER_H */

+ 722
- 640
src/dnslib.c
File diff suppressed because it is too large
View File


+ 83
- 84
src/dnslib.h View File

@@ -1,4 +1,4 @@
1
-                 /**************************************
1
+				 /**************************************
2 2
                 *     AUTHOR: Federico Tomassini        *
3 3
                *     Copyright (C) Federico Tomassini    *
4 4
               *     Contact effetom@gmail.com             *
@@ -25,30 +25,30 @@
25 25
 #include <sys/socket.h>
26 26
 #include <arpa/inet.h>
27 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 */
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 31
 
32 32
 #define MAX_RECURSION_PTR	20
33 33
 
34 34
 /* PREFIXES FOR PTR QUERY */
35 35
 #define DNS_INV_PREFIX          ".IN-ADDR.ARPA"
36 36
 #define DNS_INV_PREFIX6         ".IP6.ARPA"
37
-#define OLD_DNS_INV_PREFIX6     ".IP6.INT" /* For backward compatibility */
37
+#define OLD_DNS_INV_PREFIX6     ".IP6.INT"	/* For backward compatibility */
38 38
 
39 39
 /* DNS QUERY-TYPE: others type will be discarded */
40 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 */
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 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 */
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 52
 
53 53
 /* INET CLASS */
54 54
 #define C_IN    1
@@ -63,19 +63,19 @@
63 63
 #define min(x,y)		((x)<(y))?(x):(y)
64 64
 
65 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;
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 79
 } dns_pkt_hdr;
80 80
 #define DNS_PKT_HDR_SZ sizeof(dns_pkt_hdr)
81 81
 
@@ -87,34 +87,32 @@ typedef struct dns_pkt_hdr {
87 87
 
88 88
 
89 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;
90
+	char qname[DNS_MAX_HNAME_LEN];
91
+	uint16_t qtype;
92
+	uint16_t qclass;
93
+	struct dns_pkt_qst *next;
94 94
 };
95 95
 typedef struct dns_pkt_qst dns_pkt_qst;
96 96
 #define DNS_PKT_QST_SZ sizeof(dns_pkt_qst)
97 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;
98
+struct dns_pkt_a {
99
+	char name[DNS_MAX_HNAME_LEN];
100
+	uint16_t type;
101
+	uint16_t cl;
102
+	uint32_t ttl;
103
+	uint16_t rdlength;
104
+	char rdata[DNS_MAX_HNAME_LEN];
105
+	struct dns_pkt_a *next;
107 106
 };
108 107
 typedef struct dns_pkt_a dns_pkt_a;
109 108
 #define DNS_PKT_A_SZ sizeof(dns_pkt_a)
110 109
 
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;
110
+typedef struct dns_pkt {
111
+	dns_pkt_hdr pkt_hdr;
112
+	dns_pkt_qst *pkt_qst;
113
+	dns_pkt_a *pkt_answ;
114
+	dns_pkt_a *pkt_auth;
115
+	dns_pkt_a *pkt_add;
118 116
 } dns_pkt;
119 117
 #define DNS_PKT_SZ sizeof(dns_pkt)
120 118
 
@@ -147,43 +145,44 @@ typedef struct dns_pkt
147 145
 #define DNS_SET_NSCOUNT(dp,x)	(dp)->pkt_hdr.nscount=x
148 146
 #define DNS_SET_ARCOUNT(dp,x)	(dp)->pkt_hdr.arcount=x
149 147
 
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;	
148
+#define DP_ADD_ANSWER(dp)       dns_add_a(&((dp)->pkt_answ));DP_ANCOUNT(dp)+=1;
149
+#define DP_ADD_AUTH(dp)         dns_add_a(&((dp)->pkt_auth));DP_NSCOUNT(dp)+=1;
150
+#define DP_ADD_ADD(dp)          dns_add_a(&((dp)->pkt_add));DP_ARCOUNT(dp)+=1;
153 151
 
154 152
 
155 153
 	/* Functions */
156 154
 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
-
155
+int read_label_octet(const char *src, char *dst, int limit);
156
+int lbltoname(char *buf, char *start_pkt, char *dst, int limit);
157
+int swap_straddr(char *src, char *dst);
158
+int swap_straddr6(char *src, char *dst);
159
+int rm_inv_prefix(char *src, char *dst);
160
+int add_inv_prefix(char *s, int family);
161
+int swapped_straddr(char *src, char *dst);
162
+int swapped_straddr_pref(char *src, char *dst, int family);
163
+int nametolbl(char *name, char *dst);
164
+int d_hdr_u(char *buf, dns_pkt_hdr * dph);
165
+int d_qst_u(char *start_buf, char *buf, dns_pkt * dp, int limit_len);
166
+int d_qsts_u(char *start_buf, char *buf, dns_pkt * dp, int limit_len);
167
+int d_a_u(char *start_buf, char *buf, dns_pkt_a ** dpa_orig,
168
+		  int limit_len);
169
+int d_as_u(char *start_buf, char *buf, dns_pkt_a ** dpa, int limit_len,
170
+		   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 */

+ 70
- 63
src/endianness.c View File

@@ -40,50 +40,54 @@
40 40
 
41 41
 #define IS_DYNAMIC(i) ({do_nothing();})
42 42
 
43
-#endif	/*DEBUG*/
44
-
45
-void *int_info_copy(int_info *dst, const int_info *src)
43
+#endif /*DEBUG*/
44
+void *
45
+int_info_copy(int_info * dst, const int_info * src)
46 46
 {
47 47
 	return memcpy(dst, src, sizeof(int_info));
48 48
 }
49
-		
50
-void ints_array_ntohl(int *hostlong, int nmemb)
49
+
50
+void
51
+ints_array_ntohl(int *hostlong, int nmemb)
51 52
 {
52 53
 #if BYTE_ORDER == LITTLE_ENDIAN
53 54
 	int i;
54
-	
55
-	for(i=0; i<nmemb; i++)
56
-		hostlong[i]=ntohl(hostlong[i]);
55
+
56
+	for (i = 0; i < nmemb; i++)
57
+		hostlong[i] = ntohl(hostlong[i]);
57 58
 #endif
58 59
 }
59 60
 
60
-void ints_array_htonl(int *netlong, int nmemb)
61
+void
62
+ints_array_htonl(int *netlong, int nmemb)
61 63
 {
62 64
 #if BYTE_ORDER == LITTLE_ENDIAN
63 65
 	int i;
64
-	
65
-	for(i=0; i<nmemb; i++)
66
-		netlong[i]=htonl(netlong[i]);
66
+
67
+	for (i = 0; i < nmemb; i++)
68
+		netlong[i] = htonl(netlong[i]);
67 69
 #endif
68 70
 }
69 71
 
70
-void ints_array_ntohs(short *hostshort, int nmemb)
72
+void
73
+ints_array_ntohs(short *hostshort, int nmemb)
71 74
 {
72 75
 #if BYTE_ORDER == LITTLE_ENDIAN
73 76
 	int i;
74
-	
75
-	for(i=0; i<nmemb; i++)
76
-		hostshort[i]=ntohs(hostshort[i]);
77
+
78
+	for (i = 0; i < nmemb; i++)
79
+		hostshort[i] = ntohs(hostshort[i]);
77 80
 #endif
78 81
 }
79 82
 
80
-void ints_array_htons(short *netshort, int nmemb)
83
+void
84
+ints_array_htons(short *netshort, int nmemb)
81 85
 {
82 86
 #if BYTE_ORDER == LITTLE_ENDIAN
83 87
 	int i;
84
-	
85
-	for(i=0; i<nmemb; i++)
86
-		netshort[i]=htons(netshort[i]);
88
+
89
+	for (i = 0; i < nmemb; i++)
90
+		netshort[i] = htons(netshort[i]);
87 91
 #endif
88 92
 }
89 93
 
@@ -93,7 +97,8 @@ void ints_array_htons(short *netshort, int nmemb)
93 97
  * struct `s' from network order to host order. The `s' struct must be
94 98
  * described in the `iinfo' struct.
95 99
  */
96
-void ints_network_to_host(void *s, int_info iinfo)
100
+void
101
+ints_network_to_host(void *s, int_info iinfo)
97 102
 {
98 103
 #if BYTE_ORDER == LITTLE_ENDIAN
99 104
 
@@ -101,15 +106,15 @@ void ints_network_to_host(void *s, int_info iinfo)
101 106
 	char *p;
102 107
 
103 108
 	IS_DYNAMIC(iinfo.total_ints);
104
-	
105
-	for(i=0; i < iinfo.total_ints; i++) {
106
-		if(!iinfo.int_type[i])
109
+
110
+	for (i = 0; i < iinfo.total_ints; i++) {
111
+		if (!iinfo.int_type[i])
107 112
 			continue;
108 113
 
109 114
 		IS_DYNAMIC(iinfo.int_offset[i]);
110
-		
111
-		p=(char *)s + iinfo.int_offset[i];
112
-		
115
+
116
+		p = (char *) s + iinfo.int_offset[i];
117
+
113 118
 		IS_DYNAMIC(iinfo.int_nmemb[i]);
114 119
 		IS_DYNAMIC(iinfo.int_type[i]);
115 120
 
@@ -117,20 +122,19 @@ void ints_network_to_host(void *s, int_info iinfo)
117 122
 		 * Swap the entire array if it is a single integer and if we 
118 123
 		 * are on a little endian machine.
119 124
 		 */
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
+		if (iinfo.int_type[i] & INT_TYPE_WORDS) {
126
+
127
+			if (iinfo.int_type[i] & INT_TYPE_32BIT)
128
+				swap_ints(iinfo.int_nmemb[i], (u_int *) p, (u_int *) p);
125 129
 			else
126
-				swap_shorts(iinfo.int_nmemb[i], (u_short *)p,
127
-						(u_short *)p);
130
+				swap_shorts(iinfo.int_nmemb[i], (u_short *) p,
131
+							(u_short *) p);
128 132
 		}
129
-		
130
-		if(iinfo.int_type[i] & INT_TYPE_32BIT)
131
-			ints_array_ntohl((int *)p, iinfo.int_nmemb[i]);
133
+
134
+		if (iinfo.int_type[i] & INT_TYPE_32BIT)
135
+			ints_array_ntohl((int *) p, iinfo.int_nmemb[i]);
132 136
 		else
133
-			ints_array_ntohs((short *)p, iinfo.int_nmemb[i]);
137
+			ints_array_ntohs((short *) p, iinfo.int_nmemb[i]);
134 138
 	}
135 139
 #endif
136 140
 }
@@ -140,7 +144,8 @@ void ints_network_to_host(void *s, int_info iinfo)
140 144
  * struct `s' from host order to network order. The `s' struct must be
141 145
  * described in the `iinfo' struct.
142 146
  */
143
-void ints_host_to_network(void *s, int_info iinfo)
147
+void
148
+ints_host_to_network(void *s, int_info iinfo)
144 149
 {
145 150
 #if BYTE_ORDER == LITTLE_ENDIAN
146 151
 	int i;
@@ -148,14 +153,14 @@ void ints_host_to_network(void *s, int_info iinfo)
148 153
 
149 154
 	IS_DYNAMIC(iinfo.total_ints);
150 155
 
151
-	for(i=0; i < iinfo.total_ints; i++) {
152
-		if(!iinfo.int_type[i])
156
+	for (i = 0; i < iinfo.total_ints; i++) {
157
+		if (!iinfo.int_type[i])
153 158
 			continue;
154 159
 
155 160
 		IS_DYNAMIC(iinfo.int_offset[i]);
156 161
 
157
-		p=(char *)s + iinfo.int_offset[i];
158
-		
162
+		p = (char *) s + iinfo.int_offset[i];
163
+
159 164
 		IS_DYNAMIC(iinfo.int_nmemb[i]);
160 165
 		IS_DYNAMIC(iinfo.int_type[i]);
161 166
 
@@ -163,18 +168,19 @@ void ints_host_to_network(void *s, int_info iinfo)
163 168
 		 * Swap the entire array if it is a single integer and if we 
164 169
 		 * are on a little endian machine.
165 170
 		 */
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);
171
+		if (iinfo.int_type[i] & INT_TYPE_WORDS) {
172
+
173
+			if (iinfo.int_type[i] & INT_TYPE_32BIT)
174
+				swap_ints(iinfo.int_nmemb[i], (u_int *) p, (u_int *) p);
170 175
 			else
171
-				swap_shorts(iinfo.int_nmemb[i], (u_short *)p, (u_short *)p);
176
+				swap_shorts(iinfo.int_nmemb[i], (u_short *) p,
177
+							(u_short *) p);
172 178
 		}
173 179
 
174
-		if(iinfo.int_type[i] & INT_TYPE_32BIT)
175
-			ints_array_htonl((int *)p, iinfo.int_nmemb[i]);
180
+		if (iinfo.int_type[i] & INT_TYPE_32BIT)
181
+			ints_array_htonl((int *) p, iinfo.int_nmemb[i]);
176 182
 		else
177
-			ints_array_htons((short *)p, iinfo.int_nmemb[i]);
183
+			ints_array_htons((short *) p, iinfo.int_nmemb[i]);
178 184
 	}
179 185
 #endif
180 186
 }
@@ -183,7 +189,8 @@ void ints_host_to_network(void *s, int_info iinfo)
183 189
  * ints_printf: prints all the int/short vars present in the `s' struct
184 190
  * described by `iinfo'. It uses `print_func' as the the printing function
185 191
  */
186
-void ints_printf(void *s, int_info iinfo, void(*print_func(const char *, ...)))
192
+void
193
+ints_printf(void *s, int_info iinfo, void (*print_func(const char *, ...)))
187 194
 {
188 195
 	int i, e, *i32;
189 196
 	short *i16;
@@ -191,27 +198,27 @@ void ints_printf(void *s, int_info iinfo, void(*print_func(const char *, ...)))
191 198
 
192 199
 	IS_DYNAMIC(iinfo.total_ints);
193 200
 
194
-	for(i=0; i < iinfo.total_ints; i++) {
195
-		if(!iinfo.int_type[i])
201
+	for (i = 0; i < iinfo.total_ints; i++) {
202
+		if (!iinfo.int_type[i])
196 203
 			continue;
197 204
 
198 205
 		IS_DYNAMIC(iinfo.int_offset[i]);
199 206
 
200
-		p=(char *)s + iinfo.int_offset[i];
201
-		
207
+		p = (char *) s + iinfo.int_offset[i];
208
+
202 209
 		IS_DYNAMIC(iinfo.int_nmemb[i]);
203 210
 		IS_DYNAMIC(iinfo.int_type[i]);
204 211
 
205
-		for(e=0; e < iinfo.int_nmemb[i]; e++) {
212
+		for (e = 0; e < iinfo.int_nmemb[i]; e++) {
213
+
214
+			print_func("ints_printf: offset %d, nmemb %d, ",
215
+					   iinfo.int_offset[i], e);
206 216
 
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));
217
+			if (iinfo.int_type[i] & INT_TYPE_32BIT) {
218
+				i32 = (int *) (p + (sizeof(int) * e));
212 219
 				print_func("32bit value %d\n", *i32);
213 220
 			} else {
214
-				i16  = (short *)(p + (sizeof(short) * e));
221
+				i16 = (short *) (p + (sizeof(short) * e));
215 222
 				print_func("16bit value %d\n", *i16);
216 223
 			}
217 224
 		}

+ 23
- 23
src/endianness.h View File

@@ -19,24 +19,24 @@
19 19
 #ifndef ENDIANNESS_H
20 20
 #define ENDIANNESS_H
21 21
 
22
-#define MAX_INTS_PER_STRUCT	8		/* The maximum number of short/int variables 
23
-						   present in a struct */
22
+#define MAX_INTS_PER_STRUCT	8	/* The maximum number of short/int variables 
23
+								   present in a struct */
24 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. */
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 30
 
31 31
 
32 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 */
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 40
 
41 41
 /*
42 42
  * int_info: this struct is used to keep the information about the int/short
@@ -66,23 +66,22 @@
66 66
  *		           { 1, 1, 4 }
67 67
  *			 };
68 68
  */
69
-typedef struct
70
-{
69
+typedef struct {
71 70
 	/* The total int/short vars present in the struct */
72
-	int 	total_ints;				
71
+	int total_ints;
73 72
 
74 73
 	/* Each member in the int_type array corresponds to a int/short var
75 74
 	 * and it is set using the above INT_TYPE_ flags */
76
-	char 	int_type[MAX_INTS_PER_STRUCT];
75
+	char int_type[MAX_INTS_PER_STRUCT];
77 76
 
78 77
 	/* Each member in the int_offset array specifies the amount of bytes
79 78
 	 * to be added at the end of the struct to get the relative int/short
80 79
 	 * var. */
81
-	size_t	int_offset[MAX_INTS_PER_STRUCT];
80
+	size_t int_offset[MAX_INTS_PER_STRUCT];
82 81
 
83 82
 	/* int_nmemb[x] is equal to the number of consecutive ints/shorts var,
84 83
 	 * which start at the int_offset[x] offset. */
85
-	size_t	int_nmemb[MAX_INTS_PER_STRUCT];
84
+	size_t int_nmemb[MAX_INTS_PER_STRUCT];
86 85
 
87 86
 } int_info;
88 87
 
@@ -97,13 +96,14 @@ typedef struct
97 96
 
98 97
 
99 98
 /* * * Functions declaration * * */
100
-void *int_info_copy(int_info *dst, const int_info *src);
99
+void *int_info_copy(int_info * dst, const int_info * src);
101 100
 void ints_array_htons(short *netshort, int nmemb);
102 101
 void ints_array_ntohs(short *hostshort, int nmemb);
103 102
 void ints_array_htonl(int *netlong, int nmemb);
104 103
 void ints_array_ntohl(int *hostlong, int nmemb);
105 104
 void ints_network_to_host(void *s, int_info iinfo);
106 105
 void ints_host_to_network(void *s, int_info iinfo);
107
-void ints_printf(void *s, int_info iinfo, void(*print_func(const char *, ...)));
106
+void ints_printf(void *s, int_info iinfo,
107
+				 void (*print_func(const char *, ...)));
108 108
 
109
-#endif /*ENDIANNESS_H*/
109
+#endif							/*ENDIANNESS_H */

+ 32
- 36
src/err_errno.c View File

@@ -1,4 +1,4 @@
1
-                 /**************************************
1
+				 /**************************************
2 2
                 *     AUTHOR: Federico Tomassini        *
3 3
                *     Copyright (C) Federico Tomassini    *
4 4
               *     Contact effetom@gmail.com             *
@@ -22,48 +22,44 @@
22 22
 
23 23
 static const char *err_strings[] = {
24 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 */
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 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 */
33
+	"Error Packing Dns Struct.",	/* ERR_DNSPDS */
34
+	 /**/ "Malformed Andna Packet.",	/* ERR_ANDMAP */
35
+	"Andns Packet Len Break.",	/* ERR_ANDPLB */
36
+	"Malformed Andns Data.",	/* ERR_ANDMAD */
37
+	"Andna Not Compatbile Query.",	/* ERR_ANDNCQ */
38
+	 /**/ "Error reading resolv.conf.",	/* ERR_RSLERC */
39
+	"Andns init error.",		/* ERR_RSLAIE */
40
+	"There isn't No NameServer.",	/* ERR_RSLNNS */
41
+	"Error Forwarding DNS Query.",	/* ERR_RSLFDQ */
42
+	"Resolution Error.",		/* ERR_RSLRSL */
43
+	"Andns Query Discarded.",	/* ERR_RSLAQD */
44
+	 /**/ "mark_init error!.",	/* ERR_NETINI */
48 45
 	"netfilter table not loadable.",	/* ERR_NETFIL */
49 46
 	"error adding netfilter rules.",	/* ERR_NETRUL */
50 47
 	"error committing netfilter rules.",	/* ERR_NETCOM */
51 48
 	"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 */
49
+	"netfilter delete error.",	/* ERR_NETDEL */
50
+	"error storing rules.",		/* ERR_NETSTO */
51
+	"Nefilter was not restored.",	/* ERR_NETRST */
52
+	 /**/ "SNSD main record not found.",	/* ERR_SNDMRF */
53
+	"SNSD recursion failed.",	/* ERR_SNDRCS */
54
+	 /**/ "Zlib Compression Fail.",	/* ERR_ZLIBCP */
55
+	"Zlib Uncompression Fail.",	/* ERR_ZLIBUP */
56
+	"Zlib compression is useless.",	/* ERR_ZLIBNU */
62 57
 };
63 58
 
64
-const char *__err_strerror(int n)
59
+const char *
60
+__err_strerror(int n)
65 61
 {
66
-        int __n=-((n)+1);
62
+	int __n = -((n) + 1);
67 63
 
68
-	return (__n>=ERR_NERR || __n<0) ? ERR_OVERFLOW : err_strings[__n];
64
+	return (__n >= ERR_NERR || __n < 0) ? ERR_OVERFLOW : err_strings[__n];
69 65
 }

+ 4
- 4
src/err_errno.h View File

@@ -1,4 +1,4 @@
1
-                 /**************************************
1
+				 /**************************************
2 2
                 *     AUTHOR: Federico Tomassini        *
3 3
                *     Copyright (C) Federico Tomassini    *
4 4
               *     Contact effetom@gmail.com             *
@@ -68,13 +68,13 @@
68 68
 #define ERR_TOTAL_ERRS	(-(ERR_ZLIBNU))
69 69
 #define ERR_OVERFLOW    "Error number does not exist."
70 70
 
71
-        /* END OF DEFS */
71
+		/* END OF DEFS */
72 72
 
73 73
 
74 74
  /*
75 75
   * Core
76 76
   */
77
-const char *err_func,*err_file;
77
+const char *err_func, *err_file;
78 78
 #define ERR_NERR                (ERR_TOTAL_ERRS)
79 79
 #define err_seterrno(n)         errno=(n);err_func=__func__;	\
80 80
                                 err_file=__FILE__
@@ -92,4 +92,4 @@ const char *err_func,*err_file;
92 92
 
93 93
 const char *__err_strerror(int n);
94 94
 
95
-#endif /* ERR_ERRNO_H */
95
+#endif							/* ERR_ERRNO_H */

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


+ 137
- 118
src/gmap.h View File

@@ -19,44 +19,46 @@
19 19
 #ifndef GMAP_H
20 20
 #define GMAP_H
21 21
 
22
+#include "includes.h"
22 23
 #include "llist.c"
23 24
 #include "map.h"
24 25
 
25 26
 /* * * Groupnode stuff * * */
26
-#define GMAP_ME		MAP_ME		/*1*/
27
-#define GMAP_VOID	MAP_VOID	/*(1<<1)*/
27
+#define GMAP_ME		MAP_ME		/*1 */
28
+#define GMAP_VOID	MAP_VOID	/*(1<<1) */
28 29
 #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!*/
30
+								   this gnode */
31
+#define GMAP_FULL	(1<<3)		/*The gnode is full!! aaahh, run away! */
31 32
 
32 33
 /* This is the holy external_map. Each struct corresponds to a groupnode. 
33 34
  * This groupnode cointains MAXGROUPNODE nodes if we are at level 1 or 
34 35
  * MAXGROUPNODE groups. The map is equal to the int_map, in fact, a map_node
35 36
  * is embedded in a map_gnode. 
36 37
  * This int_map uses the QSPN_MAP_STYLEII (see qspn.h). */
37
-typedef struct
38
-{
38
+typedef struct {
39 39
 	/* 
40 40
 	 * The gnode_map starts here. Note that it is a normal map. (See map.h). 
41 41
 	 * It is here, at the top of the struct to allow to manipulate a map_gnode
42 42
 	 * as a map_node with the help of the magic cast. The cast is heavily 
43 43
 	 * used in qspn.c
44 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*/
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 53
 } map_gnode;
54 54
 
55
-INT_INFO map_gnode_iinfo = { 1, 
56
-			     { INT_TYPE_32BIT }, 
57
-			     { MAP_NODE_PACK_SZ+sizeof(u_char)*2 }, 
58
-			     { 1 }
59
-			   };
55
+INT_INFO map_gnode_iinfo = { 1,
56
+	{INT_TYPE_32BIT},
57
+	{MAP_NODE_PACK_SZ + sizeof(u_char) * 2}
58
+	,
59
+	{1}
60
+};
61
+
60 62
 #define MAP_GNODE_PACK_SZ	(MAP_NODE_PACK_SZ+sizeof(u_char)*2+sizeof(int))
61 63
 
62 64
 
@@ -125,23 +127,25 @@ INT_INFO map_gnode_iinfo = { 1,
125 127
 /* Struct used to keep all the quadro_group ids of a node. (The node is part of this
126 128
  * quadro groups) */
127 129
 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;
130
+	u_char levels;				/*How many levels we have */
131
+	int gid[MAX_LEVELS];		/*Group ids. Each element is the gid of the quadrogroup in the 
132
+								   relative level. (ex: gid[n] is the gid of the quadropgroup a 
133
+								   the n-th level) */
134
+	map_gnode *gnode[MAX_LEVELS - ZERO_LEVEL];	/*Each element is a pointer to the relative
135
+												   gnode in the ext_map. */
136
+	inet_prefix ipstart[MAX_LEVELS];	/*The ipstart of each quadg.gid in their respective levels */
137
+} quadro_group;
136 138
 
137 139
 /* Note: this is the int_info of the a packed quadro_group struct, which
138 140
  * hasnt't the `map_gnode *gnode' pointers. The ipstart structs must be also
139 141
  * packed with pack_inet_prefix() */
140
-INT_INFO quadro_group_iinfo = { 1, 
141
-				{ INT_TYPE_32BIT },
142
-				{ sizeof(u_char) },
143
-				{ MAX_LEVELS }
144
-			      };
142
+INT_INFO quadro_group_iinfo = { 1,
143
+	{INT_TYPE_32BIT},
144
+	{sizeof(u_char)}
145
+	,
146
+	{MAX_LEVELS}
147
+};
148
+
145 149
 #define QUADRO_GROUP_PACK_SZ (sizeof(u_char) + sizeof(int)*MAX_LEVELS +     \
146 150
 				+ INET_PREFIX_PACK_SZ * MAX_LEVELS)
147 151
 
@@ -151,28 +155,28 @@ INT_INFO quadro_group_iinfo = { 1,
151 155
 #define QUADG_GNODE   (1<<2)
152 156
 
153 157
 /* 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_;
158
+struct ext_map_hdr {
159
+	char quadg[QUADRO_GROUP_PACK_SZ];	/* The packed me.cur_quadg */
160
+
161
+	size_t ext_map_sz;			/*It's the sum of all the gmaps_sz.
162
+								   The size of a single map is:
163
+								   (ext_map_sz/(MAP_GNODE_PACK_SZ*
164
+								   (quadg.levels-EXTRA_LEVELS)); */
165
+	size_t rblock_sz[MAX_LEVELS];	/*The size of the rblock of each gmap */
166
+	size_t total_rblock_sz;		/*The sum of all rblock_sz */
167
+} _PACKED_;
165 168
 
166 169
 /* Note: You have to consider the quadro_group struct when convert between
167 170
  * 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
-	
171
+INT_INFO ext_map_hdr_iinfo = { 3,
172
+	{INT_TYPE_32BIT, INT_TYPE_32BIT, INT_TYPE_32BIT},
173
+	{QUADRO_GROUP_PACK_SZ,
174
+	 QUADRO_GROUP_PACK_SZ + sizeof(size_t),
175
+	 QUADRO_GROUP_PACK_SZ + (sizeof(size_t) * (MAX_LEVELS + 1))}
176
+	,
177
+	{1, MAX_LEVELS, 1}
178
+};
179
+
176 180
 /* The ext_map_block is:
177 181
  * 	struct ext_map_hdr hdr;
178 182
  * 	char ext_map[ext_map_sz];
@@ -185,86 +189,101 @@ INT_INFO ext_map_hdr_iinfo = { 3,
185 189
  * doesn't belongs to our same gnode.
186 190
  */
187 191
 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;
192
+	map_node node;
193
+	quadro_group quadg;			/* quadg.gnode[level] may be set to 0
194
+								 * if that gnode doesn't belong to the
195
+								 * same upper level of me.cur_quadg:
196
+								 * quadg.gid[level+1] != me.cur_quadg.gid[level+1]
197
+								 */
198
+} ext_rnode;
195 199
 
196 200
 /*This cache keeps the list of all the ext_rnode used.*/
197 201
 struct ext_rnode_cache {
198
-	LLIST_HDR	(struct ext_rnode_cache);
202
+	LLIST_HDR(struct ext_rnode_cache);
199 203
 
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 */
204
+	ext_rnode *e;				/*The pointer to the ext_rnode struct */
205
+	int rnode_pos;				/*The ext_rnode position in the 
206
+								   array of rnodes of the root_node */
203 207
 };
204 208
 typedef struct ext_rnode_cache ext_rnode_cache;
205 209
 
206 210
 /* * * Functions' declaration * * */
207
-inline int get_groups(int family, int lvl);
211
+int get_groups(int family, int lvl);
208 212
 int is_group_invalid(int *gids, int gid, int lvl, int family);
209 213
 
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);
214
+int pos_from_gnode(map_gnode * gnode, map_gnode * map);
215
+map_gnode *gnode_from_pos(int pos, map_gnode * map);
216
+void rnodetoip(u_int mapstart, u_int maprnode, inet_prefix ipstart,
217
+			   inet_prefix * ret);
218
+const char *rnode_to_ipstr(u_int mapstart, u_int maprnode,
219
+						   inet_prefix ipstart);
220
+int iptogid(inet_prefix * ip, int level);
221
+void iptogids(inet_prefix * ip, int *gid, int levels);
222
+void gidtoipstart(int *gid, u_char total_levels, u_char levels, int family,
223
+				  inet_prefix * ip);
224
+void iptoquadg(inet_prefix ip, map_gnode ** ext_map, quadro_group * qg,
225
+			   char flags);
226
+
227
+void quadg_setflags(quadro_group * qg, char flags);
228
+void quadg_free(quadro_group * qg);
229
+void quadg_destroy(quadro_group * qg);
230
+void gnode_inc_seeds(quadro_group * qg, int level);
231
+void gnode_dec_seeds(quadro_group * qg, int level);
232
+void pack_quadro_group(quadro_group * qg, char *pack);
233
+void unpack_quadro_group(quadro_group * qg, char *pack);
234
+
235
+int free_gids(quadro_group * qg, int level, map_gnode ** ext_map,
236
+			  map_node * int_map);
237
+int void_gids(quadro_group * qg, int level, map_gnode ** ext_map,
238
+			  map_node * int_map);
239
+
240
+int random_ip(inet_prefix * ipstart, int final_level, int final_gid,
241
+			  int total_levels, map_gnode ** ext_map, int only_free_gnode,
242
+			  inet_prefix * new_ip, int my_family);
243
+void gnodetoip(quadro_group * quadg, int gnodeid, u_char level,
244
+			   inet_prefix * ip);
235 245
 int gids_cmp(int *gids_a, int *gids_b, int lvl, int max_lvl);
236 246
 int quadg_gids_cmp(quadro_group a, quadro_group b, int lvl);
237 247
 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);
248
+ext_rnode_cache *erc_find(ext_rnode_cache * erc, ext_rnode * e_rnode);
249
+void e_rnode_del(ext_rnode_cache ** erc_head, u_int * counter,
250
+				 ext_rnode_cache * erc);
251
+void e_rnode_add(ext_rnode_cache ** erc, ext_rnode * e_rnode,
252
+				 int rnode_pos, u_int * counter);
253
+ext_rnode_cache *e_rnode_init(u_int * counter);
254
+void e_rnode_free(ext_rnode_cache ** erc, u_int * counter);
255
+ext_rnode_cache *e_rnode_find(ext_rnode_cache * erc, quadro_group * qg,
256
+							  int level);
257
+void erc_update_rnodepos(ext_rnode_cache * erc, map_node * root_node,
258
+						 int old_rnode_pos);
259
+void erc_reorder_rnodepos(ext_rnode_cache ** erc, u_int * erc_counter,
260
+						  map_node * root_node);
261
+ext_rnode_cache *erc_find_gnode(ext_rnode_cache * erc, map_gnode * gnode,
262
+								u_char level);
247 263
 
248 264
 map_gnode *init_gmap(int groups);
249
-void reset_gmap(map_gnode *gmap, int groups);
265
+void reset_gmap(map_gnode * gmap, int groups);
250 266
 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*/
267
+void free_extmap(map_gnode ** ext_map, u_char levels, int groups);
268
+void reset_extmap(map_gnode ** ext_map, u_char levels, int groups);
269
+
270
+int g_rnode_find(map_gnode * gnode, map_gnode * n);
271
+int extmap_find_level(map_gnode ** ext_map, map_gnode * gnode,
272
+					  u_char max_level);
273
+void gmap_node_del(map_gnode * gnode);
274
+
275
+int merge_ext_maps(map_gnode ** base, map_gnode ** new,
276
+				   quadro_group base_root, quadro_group new_root);
277
+
278
+int verify_ext_map_hdr(struct ext_map_hdr *emap_hdr, quadro_group * quadg);
279
+void free_extmap_rblock(map_rnode ** rblock, u_char levels);
280
+void pack_map_gnode(map_gnode * gnode, char *pack);
281
+void unpack_map_gnode(map_gnode * gnode, char *pack);
282
+char *pack_extmap(map_gnode ** ext_map, int maxgroupnode,
283
+				  quadro_group * quadg, size_t * pack_sz);
284
+map_gnode **unpack_extmap(char *package, quadro_group * quadg);
285
+int save_extmap(map_gnode ** ext_map, int maxgroupnode,
286
+				quadro_group * quadg, char *file);
287
+map_gnode **load_extmap(char *file, quadro_group * quadg);
288
+
289
+#endif							/*GMAP_H */

+ 66
- 60
src/hash.c View File

@@ -23,7 +23,8 @@
23 23
 #include "hash.h"
24 24
 
25 25
 /* Robert Jenkins's 32 bit Mix Function */
26
-unsigned int inthash(unsigned int key)
26
+unsigned int
27
+inthash(unsigned int key)
27 28
 {
28 29
 	key += (key << 12);
29 30
 	key ^= (key >> 22);
@@ -70,25 +71,28 @@ unsigned int inthash(unsigned int key)
70 71
  * returns:
71 72
  *	32 bit hash as a static hash type
72 73
  */
73
-u_long fnv_32_buf(void *buf, size_t len, u_long hval)
74
+u_long
75
+fnv_32_buf(void *buf, size_t len, u_long hval)
74 76
 {
75
-    u_char *bp = (u_char *)buf;	/* start of buffer */
76
-    u_char *be = bp + len;		/* beyond end of buffer */
77
+	u_char *bp = (u_char *) buf;	/* start of buffer */
78
+	u_char *be = bp + len;		/* beyond end of buffer */
77 79
 
78
-    /*
79
-     * FNV-1 hash each octet in the buffer
80
-     */
81
-    while (bp < be) {
80
+	/*
81
+	 * FNV-1 hash each octet in the buffer
82
+	 */
83
+	while (bp < be) {
82 84
 
83
-	/* multiply by the 32 bit FNV magic prime mod 2^32 */
84
-	hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
85
+		/* multiply by the 32 bit FNV magic prime mod 2^32 */
86
+		hval +=
87
+			(hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) +
88
+			(hval << 24);
85 89
 
86
-	/* xor the bottom with the current octet */
87
-	hval ^= (u_long)*bp++;
88
-    }
90
+		/* xor the bottom with the current octet */
91
+		hval ^= (u_long) * bp++;
92
+	}
89 93
 
90
-    /* return our new hash value */
91
-    return hval;
94
+	/* return our new hash value */
95
+	return hval;
92 96
 }
93 97
 
94 98
 
@@ -98,44 +102,45 @@ u_long fnv_32_buf(void *buf, size_t len, u_long hval)
98 102
  * first five operations no overflow is possible so we optimized it a
99 103
  * bit.  
100 104
  */
101
-inline unsigned int dl_elf_hash (const unsigned char *name)
105
+unsigned int
106
+dl_elf_hash(const unsigned char *name)
102 107
 {
103
-  unsigned long int hash = 0;
104
-  if (*name != '\0') {
105
-      hash = *name++;
106
-      if (*name != '\0') {
107
-	  hash = (hash << 4) + *name++;
108
-	  if (*name != '\0') {
109
-	      hash = (hash << 4) + *name++;
110
-	      if (*name != '\0') {
111
-		  hash = (hash << 4) + *name++;
112
-		  if (*name != '\0') {
113
-		      hash = (hash << 4) + *name++;
114
-		      while (*name != '\0') {
115
-			  unsigned long int hi;
116
-			  hash = (hash << 4) + *name++;
117
-			  hi = hash & 0xf0000000;
118
-
119
-			  /* The algorithm specified in the ELF ABI is as
120
-			     follows:
121
-
122
-			     if (hi != 0)
123
-			       hash ^= hi >> 24;
124
-
125
-			     hash &= ~hi;
126
-
127
-			     But the following is equivalent and a lot
128
-			     faster, especially on modern processors.  */
129
-
130
-			  hash ^= hi;
131
-			  hash ^= hi >> 24;
108
+	unsigned long int hash = 0;
109
+	if (*name != '\0') {
110
+		hash = *name++;
111
+		if (*name != '\0') {
112
+			hash = (hash << 4) + *name++;
113
+			if (*name != '\0') {
114
+				hash = (hash << 4) + *name++;
115
+				if (*name != '\0') {
116
+					hash = (hash << 4) + *name++;
117
+					if (*name != '\0') {
118
+						hash = (hash << 4) + *name++;
119
+						while (*name != '\0') {
120
+							unsigned long int hi;
121
+							hash = (hash << 4) + *name++;
122
+							hi = hash & 0xf0000000;
123
+
124
+							/* The algorithm specified in the ELF ABI is as
125
+							   follows:
126
+
127
+							   if (hi != 0)
128
+							   hash ^= hi >> 24;
129
+
130
+							   hash &= ~hi;
131
+
132
+							   But the following is equivalent and a lot
133
+							   faster, especially on modern processors.  */
134
+
135
+							hash ^= hi;
136
+							hash ^= hi >> 24;
137
+						}
138
+					}
139
+				}
132 140
 			}
133
-		    }
134 141
 		}
135
-	    }
136 142
 	}
137
-    }
138
-  return hash;
143
+	return hash;
139 144
 }
140 145
 
141 146
 /* 
@@ -145,22 +150,23 @@ inline unsigned int dl_elf_hash (const unsigned char *name)
145 150
  * If h_sec or h_usec are not null, it stores in them respectively the hash of
146 151
  * the second and the microsecond.
147 152
  */
148
-int hash_time(int *h_sec, int *h_usec)
153
+int
154
+hash_time(int *h_sec, int *h_usec)
149 155
 {
150 156
 	struct timeval t;
151
-	char str[sizeof(struct timeval)+1];
157
+	char str[sizeof(struct timeval) + 1];
152 158
 	u_int elf_hash;
153
-	
159
+
154 160
 	gettimeofday(&t, 0);
155 161
 	memcpy(str, &t, sizeof(struct timeval));
156
-	str[sizeof(struct timeval)]=0;
157
-
158
-	elf_hash=dl_elf_hash((u_char *)str);
159
-	
160
-	if(h_sec)
161
-		*h_sec=inthash(t.tv_sec);
162
-	if(h_usec)
163
-		*h_usec=inthash(t.tv_usec);
162
+	str[sizeof(struct timeval)] = 0;
163
+
164
+	elf_hash = dl_elf_hash((u_char *) str);
165
+
166
+	if (h_sec)
167
+		*h_sec = inthash(t.tv_sec);
168
+	if (h_usec)
169
+		*h_usec = inthash(t.tv_usec);
164 170
 
165 171
 	return inthash(elf_hash);
166 172
 }

+ 2
- 2
src/hash.h View File

@@ -27,8 +27,8 @@
27 27
 \*/
28 28
 u_long fnv_32_buf(void *buf, size_t len, u_long hval);
29 29
 unsigned int inthash(unsigned int key);
30
-inline unsigned int dl_elf_hash (const unsigned char *name);
30
+unsigned int dl_elf_hash(const unsigned char *name);
31 31
 char xor_int(int i);
32 32
 int hash_time(int *h_sec, int *h_usec);
33 33
 
34
-#endif /*HASH_H*/
34
+#endif							/*HASH_H */

+ 618
- 556
src/hook.c
File diff suppressed because it is too large
View File


+ 31
- 29
src/hook.h View File

@@ -21,9 +21,9 @@
21 21
 
22 22
 #include "qspn.h"
23 23
 
24
-#define MAX_FIRST_RADAR_SCANS	1  /* How many time we have to retry 
25
-				      the first radar_scan if we
26
-				      didn't found anything */
24
+#define MAX_FIRST_RADAR_SCANS	1	/* How many time we have to retry 
25
+									   the first radar_scan if we
26
+									   didn't found anything */
27 27
 #ifdef DEBUG
28 28
 #undef  MAX_FIRST_RADAR_SCANS
29 29
 #define MAX_FIRST_RADAR_SCANS	1
@@ -34,7 +34,7 @@
34 34
 #define HOOKING_IP_172		0xac100001	/* 172.16.0.1 */
35 35
 #define HOOKING_IPV6		0xfec00000	/* fec0:: */
36 36
 
37
-#define HOOK_RQ_TIMEOUT		8  /* seconds */
37
+#define HOOK_RQ_TIMEOUT		8	/* seconds */
38 38
 
39 39
 /*
40 40
  * * *  Global vars  * * *
@@ -45,7 +45,7 @@ int total_hooks;
45 45
 
46 46
 /* Current join_rate */
47 47
 u_int hook_join_rate;
48
-u_int rnodes_rehooked;		/* How many rnodes have rehooked with us */
48
+u_int rnodes_rehooked;			/* How many rnodes have rehooked with us */
49 49
 
50 50
 
51 51
 /*
@@ -62,20 +62,21 @@ u_int rnodes_rehooked;		/* How many rnodes have rehooked with us */
62 62
  * the gnode with `fn_hdr.gid' gid of the `fn_hdr.level'th level. So the free gnodes
63 63
  * are part of the (fn_hdr.level - 1)th level.
64 64
  */
65
-struct free_nodes_hdr
66
-{
67
-	u_char 		max_levels;	/* How many levels we are managing */
68
-
69
-	uint32_t 	ipstart[MAX_IP_INT];	 /* The ipstart of the gnode */
70
-	u_char 		level;		/* The level where the gnode belongs */
71
-	u_char  	gid;		/* The gnode id */
72
-	u_char		nodes;		/* The number of free (g)nodes - 1 */
73
-	uint32_t	join_rate;	/* Join_rate of `level' */
74
-}_PACKED_;
75
-INT_INFO free_nodes_hdr_iinfo = { 1, { INT_TYPE_32BIT }, 
76
-				     { sizeof(struct free_nodes_hdr)-sizeof(uint32_t) },
77
-				     { 1 }
78
-				};
65
+struct free_nodes_hdr {
66
+	u_char max_levels;			/* How many levels we are managing */
67
+
68
+	uint32_t ipstart[MAX_IP_INT];	/* The ipstart of the gnode */
69
+	u_char level;				/* The level where the gnode belongs */
70
+	u_char gid;					/* The gnode id */
71
+	u_char nodes;				/* The number of free (g)nodes - 1 */
72
+	uint32_t join_rate;			/* Join_rate of `level' */
73
+} _PACKED_;
74
+INT_INFO free_nodes_hdr_iinfo = { 1, {INT_TYPE_32BIT},
75
+{sizeof(struct free_nodes_hdr) - sizeof(uint32_t)}
76
+,
77
+{1}
78
+};
79
+
79 80
 #define FREE_NODES_SZ(nodes) (sizeof(struct free_nodes_hdr)  	      +\
80 81
 					    (sizeof(u_char) * (nodes)))
81 82
 
@@ -105,12 +106,13 @@ INT_INFO free_nodes_hdr_iinfo = { 1, { INT_TYPE_32BIT },
105 106
  */
106 107
 /* Note: for this int_info we are considering the timeval array as one int
107 108
  * with `max_levels'*2 members */
108
-INT_INFO qspn_round_pkt_iinfo = { 3, 
109
-				  { INT_TYPE_32BIT, INT_TYPE_32BIT, INT_TYPE_32BIT }, 
110
-				  { sizeof(char), IINFO_DYNAMIC_VALUE, IINFO_DYNAMIC_VALUE },
111
-				  { IINFO_DYNAMIC_VALUE, IINFO_DYNAMIC_VALUE, GCOUNT_LEVELS }
112
-				};
113
-	
109
+INT_INFO qspn_round_pkt_iinfo = { 3,
110
+	{INT_TYPE_32BIT, INT_TYPE_32BIT, INT_TYPE_32BIT}
111
+	,
112
+	{sizeof(char), IINFO_DYNAMIC_VALUE, IINFO_DYNAMIC_VALUE},
113
+	{IINFO_DYNAMIC_VALUE, IINFO_DYNAMIC_VALUE, GCOUNT_LEVELS}
114
+};
115
+
114 116
 #define QSPN_ROUND_PKT_SZ(levels)	(sizeof(u_char) + 			\
115 117
 					    ((levels) * sizeof(int32_t)) +	\
116 118
 			                    ((levels) * sizeof(struct timeval))+\
@@ -120,17 +122,17 @@ INT_INFO qspn_round_pkt_iinfo = { 3,
120 122
 /* 
121 123
  * * * Functions declaration * * *
122 124
  */
123
-	
125
+
124 126
 int put_free_nodes(PACKET rq_pkt);
125 127
 int put_qspn_round(PACKET rq_pkt);
126 128
 int put_ext_map(PACKET rq_pkt);
127 129
 int put_int_map(PACKET rq_pkt);
128 130
 int put_bnode_map(PACKET rq_pkt);
129 131
 
130
-int create_gnodes(inet_prefix *ip, int final_level);
132
+int create_gnodes(inet_prefix * ip, int final_level);
131 133
 void set_ip_and_def_gw(char *dev, inet_prefix ip);
132 134
 
133 135
 int hook_init(void);
134
-int netsukuku_hook(map_gnode *hook_gnode, int hook_level);
136
+int netsukuku_hook(map_gnode * hook_gnode, int hook_level);
135 137
 
136
-#endif /*HOOK_H*/
138
+#endif							/*HOOK_H */

+ 200
- 172
src/if.c View File

@@ -28,22 +28,21 @@
28 28
 
29 29
 extern int errno;
30 30
 
31
-static struct
32
-{       
33
-        int ifindex;
34
-        int family;
35
-        int oneline;
36
-        int showqueue;
37
-        inet_prefix pfx;
38
-        int scope, scopemask;
39
-        int flags, flagmask;
40
-        int up;
41
-        char *label;
42
-        int flushed;
43
-        char *flushb;
44
-        int flushp;
45
-        int flushe; 
46
-        struct rtnl_handle *rth;
31
+static struct {
32
+	int ifindex;
33
+	int family;
34
+	int oneline;
35
+	int showqueue;
36
+	inet_prefix pfx;
37
+	int scope, scopemask;
38
+	int flags, flagmask;
39
+	int up;
40
+	char *label;
41
+	int flushed;
42
+	char *flushb;
43
+	int flushp;
44
+	int flushe;
45
+	struct rtnl_handle *rth;
47 46
 } filter;
48 47
 
49 48
 /*
@@ -51,26 +50,28 @@ static struct
51 50
  * device which has the index equal to `dev_idx'.
52 51
  * `ifs' is the array which keeps the interface list and has `ifs_n' elements.
53 52
  */
54
-interface *ifs_find_idx(interface *ifs, int ifs_n, int dev_idx)
53
+interface *
54
+ifs_find_idx(interface * ifs, int ifs_n, int dev_idx)
55 55
 {
56 56
 	int i;
57 57
 
58
-	for(i=0; i<ifs_n; i++)
59
-		if(ifs[i].dev_idx == dev_idx)
58
+	for (i = 0; i < ifs_n; i++)
59
+		if (ifs[i].dev_idx == dev_idx)
60 60
 			return &ifs[i];
61 61
 
62 62
 	return 0;
63 63
 }
64 64
 
65
-int ifs_find_devname(interface *ifs, int ifs_n, char *dev_name)
65
+int
66
+ifs_find_devname(interface * ifs, int ifs_n, char *dev_name)
66 67
 {
67 68
 	int i;
68 69
 
69
-	if(!dev_name)
70
+	if (!dev_name)
70 71
 		return -1;
71 72
 
72
-	for(i=0; i<ifs_n; i++)
73
-		if(ifs[i].dev_name && 
73
+	for (i = 0; i < ifs_n; i++)
74
+		if (ifs[i].dev_name &&
74 75
 			!strncmp(ifs[i].dev_name, dev_name, IFNAMSIZ))
75 76
 			return i;
76 77
 
@@ -81,13 +82,14 @@ int ifs_find_devname(interface *ifs, int ifs_n, char *dev_name)
81 82
  * ifs_del: removes from the `ifs' array the device which is at the
82 83
  * `if_pos'th position. `*ifs_n' is then decremented.
83 84
  */
84
-void ifs_del(interface *ifs, int *ifs_n, int if_pos)
85
+void
86
+ifs_del(interface * ifs, int *ifs_n, int if_pos)
85 87
 {
86
-	if(if_pos == (*ifs_n)-1)
88
+	if (if_pos == (*ifs_n) - 1)
87 89
 		setzero(&ifs[if_pos], sizeof(interface));
88 90
 	else {
89
-		memcpy(&ifs[if_pos], &ifs[(*ifs_n)-1], sizeof(interface));
90
-		setzero(&ifs[(*ifs_n)-1], sizeof(interface));
91
+		memcpy(&ifs[if_pos], &ifs[(*ifs_n) - 1], sizeof(interface));
92
+		setzero(&ifs[(*ifs_n) - 1], sizeof(interface));
91 93
 	}
92 94
 
93 95
 	(*ifs_n)--;
@@ -97,12 +99,13 @@ void ifs_del(interface *ifs, int *ifs_n, int if_pos)
97 99
  * ifs_del_byname: deletes from the `ifs' array the device whose name is equal
98 100
  * to `dev_name'
99 101
  */
100
-void ifs_del_byname(interface *ifs, int *ifs_n, char *dev_name)
102
+void
103
+ifs_del_byname(interface * ifs, int *ifs_n, char *dev_name)
101 104
 {
102 105
 	int if_pos;
103 106
 
104
-	if_pos=ifs_find_devname(ifs, *ifs_n, dev_name);
105
-	if(if_pos < 0)
107
+	if_pos = ifs_find_devname(ifs, *ifs_n, dev_name);
108
+	if (if_pos < 0)
106 109
 		return;
107 110
 
108 111
 	ifs_del(ifs, ifs_n, if_pos);
@@ -113,20 +116,21 @@ void ifs_del_byname(interface *ifs, int *ifs_n, char *dev_name)
113 116
  * device name that begins with `dev_name'. For example, 
114 117
  * ifs_del_all_name(ifs, ifs_n, "tun") deletes all the tunnel iifs
115 118
  */
116
-void ifs_del_all_name(interface *ifs, int *ifs_n, char *dev_name)
119
+void
120
+ifs_del_all_name(interface * ifs, int *ifs_n, char *dev_name)
117 121
 {
118 122
 	int i, dev_len;
119 123
 
120
-	if(!dev_name || (dev_len=strlen(dev_name)) > IFNAMSIZ)
124
+	if (!dev_name || (dev_len = strlen(dev_name)) > IFNAMSIZ)
121 125
 		return;
122
-	
123
-	for(i=0; i<(*ifs_n); i++) {
124
-		if(ifs[i].dev_name && 
126
+
127
+	for (i = 0; i < (*ifs_n); i++) {
128
+		if (ifs[i].dev_name &&
125 129
 			!strncmp(ifs[i].dev_name, dev_name, dev_len)) {
126 130
 
127
-				ifs_del(ifs, ifs_n, i);
128
-				if(i <= (*ifs_n)-1)
129
-					i--;
131
+			ifs_del(ifs, ifs_n, i);
132
+			if (i <= (*ifs_n) - 1)
133
+				i--;
130 134
 		}
131 135
 	}
132 136
 }
@@ -137,12 +141,13 @@ void ifs_del_all_name(interface *ifs, int *ifs_n, char *dev_name)
137 141
  * `dev'->dev_idx. The `ifs' array has `ifs_n' members.
138 142
  * If it is not found -1 is returned.
139 143
  */
140
-int ifs_get_pos(interface *ifs, int ifs_n, interface *dev)
144
+int
145
+ifs_get_pos(interface * ifs, int ifs_n, interface * dev)
141 146
 {
142 147
 	int i;
143 148
 
144
-	for(i=0; i<ifs_n; i++)
145
-		if(ifs[i].dev_idx == dev->dev_idx)
149
+	for (i = 0; i < ifs_n; i++)
150
+		if (ifs[i].dev_idx == dev->dev_idx)
146 151
 			return i;
147 152
 
148 153
 	return -1;
@@ -152,17 +157,18 @@ int ifs_get_pos(interface *ifs, int ifs_n, interface *dev)
152 157
  * get_dev: It returs the first dev it finds up and sets `*dev_ids' to the
153 158
  * device's index. On error NULL is returned.
154 159
  */
155
-const char *get_dev(int *dev_idx) 
160
+const char *
161
+get_dev(int *dev_idx)
156 162
 {
157 163
 	int idx;
158 164
 
159
-	if((idx=ll_first_up_if()) == -1) {
165
+	if ((idx = ll_first_up_if()) == -1) {
160 166
 		error("Couldn't find \"up\" devices. Set one dev \"up\", or "
161
-				"specify the device name in the options.");
167
+			  "specify the device name in the options.");
162 168
 		return 0;
163 169
 	}
164
-	if(dev_idx)
165
-		*dev_idx=idx;
170
+	if (dev_idx)
171
+		*dev_idx = idx;
166 172
 	return ll_index_to_name(idx);
167 173
 }
168 174
 
@@ -171,48 +177,52 @@ const char *get_dev(int *dev_idx)
171 177
  * finds up. The `ifs' array has `ifs_n'# members.
172 178
  * It returns the number of filled interfaces.
173 179
  */
174
-int get_all_up_ifs(interface *ifs, int ifs_n)
180
+int
181
+get_all_up_ifs(interface * ifs, int ifs_n)
175 182
 {
176 183
 	int i, idx, n;
177 184
 
178
-	for(i=0, n=0; i<ifs_n; i++) {
179
-		idx=ll_nth_up_if(n+1);
180
-		if(idx <= 0)
185
+	for (i = 0, n = 0; i < ifs_n; i++) {
186
+		idx = ll_nth_up_if(n + 1);
187
+		if (idx <= 0)
181 188
 			continue;
182
-		
183
-		ifs[n].dev_idx=idx;
184
-	        strncpy(ifs[n].dev_name, ll_index_to_name(idx), IFNAMSIZ);
189
+
190
+		ifs[n].dev_idx = idx;
191
+		strncpy(ifs[n].dev_name, ll_index_to_name(idx), IFNAMSIZ);
185 192
 		loginfo("Network interface \"%s\" detected", ifs[n].dev_name);
186 193
 		n++;
187 194
 
188
-		if((idx-1) > i)
189
-			i=idx-1;
195
+		if ((idx - 1) > i)
196
+			i = idx - 1;
190 197
 	}
191
-	
198
+
192 199
 	return n;
193 200
 }
194 201
 
195
-int set_flags(char *dev, u_int flags, u_int mask)
202
+int
203
+set_flags(char *dev, u_int flags, u_int mask)
196 204
 {
197 205
 	struct ifreq ifr;
198 206
 	int s;
199 207
 
200 208
 	strcpy(ifr.ifr_name, dev);
201
-	if((s=new_socket(AF_INET)) < 0) {
209
+	if ((s = new_socket(AF_INET)) < 0) {
202 210
 		error("Error while setting \"%s\" flags: Cannot open socket", dev);
203 211
 		return -1;
204 212
 	}
205 213
 
206
-	if(ioctl(s, SIOCGIFFLAGS, &ifr)) {
207
-		error("Error while setting \"%s\" flags: %s", dev, strerror(errno));
214
+	if (ioctl(s, SIOCGIFFLAGS, &ifr)) {
215
+		error("Error while setting \"%s\" flags: %s", dev,
216
+			  strerror(errno));
208 217
 		close(s);
209 218
 		return -1;
210 219
 	}
211 220
 
212 221
 	ifr.ifr_flags &= ~mask;
213
-	ifr.ifr_flags |= mask&flags;
214
-	if(ioctl(s, SIOCSIFFLAGS, &ifr)) {
215
-		error("Error while setting \"%s\" flags: %s", dev, strerror(errno));
222
+	ifr.ifr_flags |= mask & flags;
223
+	if (ioctl(s, SIOCSIFFLAGS, &ifr)) {
224
+		error("Error while setting \"%s\" flags: %s", dev,
225
+			  strerror(errno));
216 226
 		close(s);
217 227
 		return -1;
218 228
 	}
@@ -220,19 +230,21 @@ int set_flags(char *dev, u_int flags, u_int mask)
220 230
 	return 0;
221 231
 }
222 232
 
223
-int set_dev_up(char *dev)
233
+int
234
+set_dev_up(char *dev)
224 235
 {
225
-	u_int mask=0, flags=0;
226
-	
236
+	u_int mask = 0, flags = 0;
237
+
227 238
 	mask |= IFF_UP;
228 239
 	flags |= IFF_UP;
229 240
 	return set_flags(dev, flags, mask);
230 241
 }
231 242
 
232
-int set_dev_down(char *dev)
243
+int
244
+set_dev_down(char *dev)
233 245
 {
234
-	u_int mask=0, flags=0;
235
-	
246
+	u_int mask = 0, flags = 0;
247
+
236 248
 	mask |= IFF_UP;
237 249
 	flags &= ~IFF_UP;
238 250
 	return set_flags(dev, flags, mask);
@@ -245,12 +257,13 @@ int set_dev_down(char *dev)
245 257
  * It returns the sum of all each return code, of set_func, therefore if it
246 258
  * returns a negative value, some `set_func' gave an error.
247 259
  */
248
-int set_all_ifs(interface *ifs, int ifs_n, int (*set_func)(char *dev))
260
+int
261
+set_all_ifs(interface * ifs, int ifs_n, int (*set_func) (char *dev))
249 262
 {
250
-	int i, ret=0;
263
+	int i, ret = 0;
251 264
 
252
-	for(i=0; i<ifs_n; i++)
253
-		ret+=set_func(ifs[i].dev_name);
265
+	for (i = 0; i < ifs_n; i++)
266
+		ret += set_func(ifs[i].dev_name);
254 267
 
255 268
 	return ret;
256 269
 }
@@ -264,47 +277,48 @@ int set_all_ifs(interface *ifs, int ifs_n, int (*set_func)(char *dev))
264 277
  * stores all the initialized interfaces, updating the `new_ifs_n' counter.
265 278
  * On error -1 is returned.
266 279
  */
267
-int if_init_all(char *ifs_name[MAX_INTERFACES], int ifs_n, 
268
-		interface *new_ifs, int *new_ifs_n)
280
+int
281
+if_init_all(char *ifs_name[MAX_INTERFACES], int ifs_n,
282
+			interface * new_ifs, int *new_ifs_n)
269 283
 {
270 284
 	struct rtnl_handle rth;
271
-	int ret=0, i, n;
285
+	int ret = 0, i, n;
272 286
 
273 287
 	if (rtnl_open(&rth, 0) < 0) {
274 288
 		error("Cannot open the rtnetlink socket to talk to the kernel's "
275
-				"soul");
289
+			  "soul");
276 290
 		return -1;
277 291
 	}
278 292
 	ll_init_map(&rth);
279 293
 
280
-	if(!ifs_n) {
281
-		ret=get_all_up_ifs(new_ifs, MAX_INTERFACES);
294
+	if (!ifs_n) {
295
+		ret = get_all_up_ifs(new_ifs, MAX_INTERFACES);
282 296
 
283
-		if(!ret)
297
+		if (!ret)
284 298
 			return -1;
285 299
 
286
-		*new_ifs_n=ret;
300
+		*new_ifs_n = ret;
287 301
 	} else {
288
-		for(i=0, n=0; i<ifs_n; i++) {
289
-			
290
-			new_ifs[n].dev_idx=ll_name_to_index(ifs_name[n]);
291
-			if(!new_ifs[n].dev_idx) {
302
+		for (i = 0, n = 0; i < ifs_n; i++) {
303
+
304
+			new_ifs[n].dev_idx = ll_name_to_index(ifs_name[n]);
305
+			if (!new_ifs[n].dev_idx) {
292 306
 				error("Cannot initialize the %s interface. "
293
-						"Ignoring it", ifs_name[n]);
307
+					  "Ignoring it", ifs_name[n]);
294 308
 				continue;
295 309
 			}
296 310
 
297 311
 			strncpy(new_ifs[n].dev_name, ifs_name[n], IFNAMSIZ);
298 312
 			n++;
299 313
 		}
300
-		
301
-		if(!n)
314
+
315
+		if (!n)
302 316
 			return -1;
303
-			
304
-		*new_ifs_n=n;
317
+
318
+		*new_ifs_n = n;
305 319
 	}
306 320
 
307
-	if(set_all_ifs(new_ifs, *new_ifs_n, set_dev_up) < 0)
321
+	if (set_all_ifs(new_ifs, *new_ifs_n, set_dev_up) < 0)
308 322
 		return -1;
309 323
 
310 324
 	rtnl_close(&rth);
@@ -312,7 +326,8 @@ int if_init_all(char *ifs_name[MAX_INTERFACES], int ifs_n,
312 326
 	return ret;
313 327
 }
314 328
 
315
-void if_close_all(void)
329
+void
330
+if_close_all(void)
316 331
 {
317 332
 #if 0
318 333
 	/* XXX: disabled for now, it is buggy */
@@ -324,43 +339,48 @@ void if_close_all(void)
324 339
  * set_dev_ip: Assign the given `ip' to the interface named `dev'
325 340
  * On success 0 is returned, -1 otherwise.
326 341
  */
327
-int set_dev_ip(inet_prefix ip, char *dev)
342
+int
343
+set_dev_ip(inet_prefix ip, char *dev)
328 344
 {
329
-	int s=-1;
345
+	int s = -1;
330 346
 
331
-	if(ip.family == AF_INET) {
347
+	if (ip.family == AF_INET) {
332 348
 		struct ifreq req;
333 349
 
334
-		if((s=new_socket(AF_INET)) < 0) {
335
-			error("Error while setting \"%s\" ip: Cannot open socket", dev);
350
+		if ((s = new_socket(AF_INET)) < 0) {
351
+			error("Error while setting \"%s\" ip: Cannot open socket",
352
+				  dev);
336 353
 			return -1;
337 354
 		}
338 355
 
339 356
 		strncpy(req.ifr_name, dev, IFNAMSIZ);
340 357
 		inet_to_sockaddr(&ip, 0, &req.ifr_addr, 0);
341 358
 
342
-		if(ioctl(s, SIOCSIFADDR, &req)) {
343
-			error("Error while setting \"%s\" ip: %s", dev, strerror(errno));
359
+		if (ioctl(s, SIOCSIFADDR, &req)) {
360
+			error("Error while setting \"%s\" ip: %s", dev,
361
+				  strerror(errno));
344 362
 			close(s);
345 363
 			return -1;
346 364
 		}
347
-	} else if(ip.family == AF_INET6) {
365
+	} else if (ip.family == AF_INET6) {
348 366
 		struct in6_ifreq req6;
349 367
 		struct sockaddr_in6 sin6;
350
-		struct sockaddr *sa=(struct sockaddr *)&sin6;
368
+		struct sockaddr *sa = (struct sockaddr *) &sin6;
351 369
 
352
-		if((s=new_socket(AF_INET6)) < 0) {
353
-			error("Error while setting \"%s\" ip: Cannot open socket", dev);
370
+		if ((s = new_socket(AF_INET6)) < 0) {
371
+			error("Error while setting \"%s\" ip: Cannot open socket",
372
+				  dev);
354 373
 			return -1;
355 374
 		}
356
-		
357
-		req6.ifr6_ifindex=ll_name_to_index(dev);
358
-		req6.ifr6_prefixlen=0;
375
+
376
+		req6.ifr6_ifindex = ll_name_to_index(dev);
377
+		req6.ifr6_prefixlen = 0;
359 378
 		inet_to_sockaddr(&ip, 0, sa, 0);
360 379
 		memcpy(&req6.ifr6_addr, sin6.sin6_addr.s6_addr32, ip.len);
361 380
 
362
-		if(ioctl(s, SIOCSIFADDR, &req6)) {
363
-			error("Error while setting \"%s\" ip: %s", dev, strerror(errno));
381
+		if (ioctl(s, SIOCSIFADDR, &req6)) {
382
+			error("Error while setting \"%s\" ip: %s", dev,
383
+				  strerror(errno));
364 384
 			close(s);
365 385
 			return -1;
366 386
 		}
@@ -376,12 +396,13 @@ int set_dev_ip(inet_prefix ip, char *dev)
376 396
  * present in the `ifs' array.
377 397
  * On error -1 is returned.
378 398
  */
379
-int set_all_dev_ip(inet_prefix ip, interface *ifs, int ifs_n)
399
+int
400
+set_all_dev_ip(inet_prefix ip, interface * ifs, int ifs_n)
380 401
 {
381
-	int i, ret=0;
382
-	
383
-	for(i=0; i<ifs_n; i++)
384
-		ret+=set_dev_ip(ip, ifs[i].dev_name);
402
+	int i, ret = 0;
403
+
404
+	for (i = 0; i < ifs_n; i++)
405
+		ret += set_dev_ip(ip, ifs[i].dev_name);
385 406
 
386 407
 	return ret;
387 408
 }
@@ -391,46 +412,47 @@ int set_all_dev_ip(inet_prefix ip, interface *ifs, int ifs_n)
391 412
  * and stores it to `ip'.
392 413
  * On success 0 is returned, -1 otherwise.
393 414
  */
394
-int get_dev_ip(inet_prefix *ip, int family, char *dev)
415
+int
416
+get_dev_ip(inet_prefix * ip, int family, char *dev)
395 417
 {
396
-	int s=-1;
397
-	int ret=0;
418
+	int s = -1;
419
+	int ret = 0;
398 420
 
399 421
 	setzero(ip, sizeof(inet_prefix));
400 422
 
401
-	if((s=new_socket(family)) < 0) {
423
+	if ((s = new_socket(family)) < 0) {
402 424
 		error("Error while setting \"%s\" ip: Cannot open socket", dev);
403 425
 		return -1;
404 426
 	}
405 427
 
406
-	if(family == AF_INET) {
428
+	if (family == AF_INET) {
407 429
 		struct ifreq req;
408 430
 
409 431
 		strncpy(req.ifr_name, dev, IFNAMSIZ);
410 432
 		req.ifr_addr.sa_family = family;
411
-		
412
-		if(ioctl(s, SIOCGIFADDR, &req))
433
+
434
+		if (ioctl(s, SIOCGIFADDR, &req))
413 435
 			ERROR_FINISH(ret, -1, finish);
414 436
 
415 437
 		sockaddr_to_inet(&req.ifr_addr, ip, 0);
416
-	} else if(family == AF_INET6) {
438
+	} else if (family == AF_INET6) {
417 439
 		struct in6_ifreq req6;
418 440
 
419 441
 		/*
420 442
 		 * XXX: NOT TESTED
421 443
 		 */
422 444
 
423
-		req6.ifr6_ifindex=ll_name_to_index(dev);
424
-		req6.ifr6_prefixlen=0;
445
+		req6.ifr6_ifindex = ll_name_to_index(dev);
446
+		req6.ifr6_prefixlen = 0;
425 447
 
426
-		if(ioctl(s, SIOCGIFADDR, &req6))
448
+		if (ioctl(s, SIOCGIFADDR, &req6))
427 449
 			ERROR_FINISH(ret, -1, finish);
428 450
 
429
-		inet_setip(ip, (u_int *)&req6.ifr6_addr, family);
451
+		inet_setip(ip, (u_int *) & req6.ifr6_addr, family);
430 452
 	}
431 453
 
432
-finish:
433
-	if(s != -1)
454
+  finish:
455
+	if (s != -1)
434 456
 		close(s);
435 457
 	return ret;
436 458
 }
@@ -442,22 +464,24 @@ finish:
442 464
  *
443 465
  * Modified lightly
444 466
  */
445
-static int flush_update(void)
446
-{                       
447
-        if (rtnl_send(filter.rth, filter.flushb, filter.flushp) < 0) {
448
-                error("Failed to send flush request: %s", strerror(errno));
449
-                return -1;
450
-        }               
451
-        filter.flushp = 0;
452
-        return 0;
467
+static int
468
+flush_update(void)
469
+{
470
+	if (rtnl_send(filter.rth, filter.flushb, filter.flushp) < 0) {
471
+		error("Failed to send flush request: %s", strerror(errno));
472
+		return -1;
473
+	}
474
+	filter.flushp = 0;
475
+	return 0;
453 476
 }
454 477
 
455
-int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n, 
456
-		   void *arg)
478
+int
479
+print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
480
+			   void *arg)
457 481
 {
458 482
 	struct ifaddrmsg *ifa = NLMSG_DATA(n);
459 483
 	int len = n->nlmsg_len;
460
-	struct rtattr * rta_tb[IFA_MAX+1];
484
+	struct rtattr *rta_tb[IFA_MAX + 1];
461 485
 	char b1[64];
462 486
 
463 487
 	if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR)
@@ -471,7 +495,8 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
471 495
 	if (filter.flushb && n->nlmsg_type != RTM_NEWADDR)
472 496
 		return 0;
473 497
 
474
-	parse_rtattr(rta_tb, IFA_MAX, IFA_RTA(ifa), n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa)));
498
+	parse_rtattr(rta_tb, IFA_MAX, IFA_RTA(ifa),
499
+				 n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa)));
475 500
 
476 501
 	if (!rta_tb[IFA_LOCAL])
477 502
 		rta_tb[IFA_LOCAL] = rta_tb[IFA_ADDRESS];
@@ -480,9 +505,9 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
480 505
 
481 506
 	if (filter.ifindex && filter.ifindex != ifa->ifa_index)
482 507
 		return 0;
483
-	if ((filter.scope^ifa->ifa_scope)&filter.scopemask)
508
+	if ((filter.scope ^ ifa->ifa_scope) & filter.scopemask)
484 509
 		return 0;
485
-	if ((filter.flags^ifa->ifa_flags)&filter.flagmask)
510
+	if ((filter.flags ^ ifa->ifa_flags) & filter.flagmask)
486 511
 		return 0;
487 512
 	if (filter.label) {
488 513
 		const char *label;
@@ -498,8 +523,8 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
498 523
 			inet_prefix dst;
499 524
 			setzero(&dst, sizeof(dst));
500 525
 			dst.family = ifa->ifa_family;
501
-			memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]), 
502
-					RTA_PAYLOAD(rta_tb[IFA_LOCAL]));
526
+			memcpy(&dst.data, RTA_DATA(rta_tb[IFA_LOCAL]),
527
+				   RTA_PAYLOAD(rta_tb[IFA_LOCAL]));
503 528
 			if (inet_addr_match(&dst, &filter.pfx, filter.pfx.bits))
504 529
 				return 0;
505 530
 		}
@@ -511,46 +536,48 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
511 536
 			if (flush_update())
512 537
 				return -1;
513 538
 		}
514
-		fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp));
539
+		fn = (struct nlmsghdr *) (filter.flushb +
540
+								  NLMSG_ALIGN(filter.flushp));
515 541
 		memcpy(fn, n, n->nlmsg_len);
516 542
 		fn->nlmsg_type = RTM_DELADDR;
517 543
 		fn->nlmsg_flags = NLM_F_REQUEST;
518 544
 		fn->nlmsg_seq = ++filter.rth->seq;
519
-		filter.flushp = (((char*)fn) + n->nlmsg_len) - filter.flushb;
545
+		filter.flushp = (((char *) fn) + n->nlmsg_len) - filter.flushb;
520 546
 		filter.flushed++;
521 547
 	}
522 548
 
523 549
 	return 0;
524 550
 }
525 551
 
526
-struct nlmsg_list
527
-{
528
-        struct nlmsg_list *next;
529
-        struct nlmsghdr   h;
552
+struct nlmsg_list {
553
+	struct nlmsg_list *next;
554
+	struct nlmsghdr h;
530 555
 };
531 556
 
532
-static int store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n,
533
-                       void *arg)
557
+static int
558
+store_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
534 559
 {
535
-        struct nlmsg_list **linfo = (struct nlmsg_list**)arg;
536
-        struct nlmsg_list *h;
537
-        struct nlmsg_list **lp;
560
+	struct nlmsg_list **linfo = (struct nlmsg_list **) arg;
561
+	struct nlmsg_list *h;
562
+	struct nlmsg_list **lp;
538 563
 
539
-        h = malloc(n->nlmsg_len+sizeof(void*));
540
-        if (h == NULL)
541
-                return -1;
564
+	h = malloc(n->nlmsg_len + sizeof(void *));
565
+	if (h == NULL)
566
+		return -1;
542 567
 
543
-        memcpy(&h->h, n, n->nlmsg_len);
544
-        h->next = NULL;
568
+	memcpy(&h->h, n, n->nlmsg_len);
569
+	h->next = NULL;
545 570
 
546
-        for (lp = linfo; *lp; lp = &(*lp)->next) /* NOTHING */;
547
-        *lp = h;
571
+	for (lp = linfo; *lp; lp = &(*lp)->next)	/* NOTHING */
572
+		;
573
+	*lp = h;
548 574
 
549
-        ll_remember_index((struct sockaddr_nl *)who, n, NULL);
550
-        return 0;
575
+	ll_remember_index((struct sockaddr_nl *) who, n, NULL);
576
+	return 0;
551 577
 }
552 578
 
553
-int ip_addr_flush(int family, char *dev, int scope)
579
+int
580
+ip_addr_flush(int family, char *dev, int scope)
554 581
 {
555 582
 	struct nlmsg_list *linfo = NULL;
556 583
 	struct rtnl_handle rth;
@@ -582,15 +609,15 @@ int ip_addr_flush(int family, char *dev, int scope)
582 609
 	}
583 610
 
584 611
 	int round = 0;
585
-	char flushb[4096-512];
612
+	char flushb[4096 - 512];
586 613
 
587 614
 	filter.flushb = flushb;
588 615
 	filter.flushp = 0;
589 616
 	filter.flushe = sizeof(flushb);
590 617
 	filter.rth = &rth;
591
-        filter.scopemask = -1;
618
+	filter.scopemask = -1;
592 619
 	filter.scope = scope;
593
-	
620
+
594 621
 	for (;;) {
595 622
 		if (rtnl_wilddump_request(&rth, filter.family, RTM_GETADDR) < 0) {
596 623
 			error("Cannot send dump request: %s", strerror(errno));
@@ -612,12 +639,13 @@ int ip_addr_flush(int family, char *dev, int scope)
612 639
 	rtnl_close(&rth);
613 640
 }
614 641
 
615
-int ip_addr_flush_all_ifs(interface *ifs, int ifs_n, int family, int scope)
642
+int
643
+ip_addr_flush_all_ifs(interface * ifs, int ifs_n, int family, int scope)
616 644
 {
617
-	int i, ret=0;
618
-	
619
-	for(i=0; i<ifs_n; i++)
620
-		ret+=ip_addr_flush(family, ifs[i].dev_name, scope);
645
+	int i, ret = 0;
646
+
647
+	for (i = 0; i < ifs_n; i++)
648
+		ret += ip_addr_flush(family, ifs[i].dev_name, scope);
621 649
 
622 650
 	return ret;
623 651
 }

+ 20
- 18
src/if.h View File

@@ -23,39 +23,41 @@
23 23
 #include "inet.h"
24 24
 
25 25
 #define MAX_INTERFACES		16	/* The maximum number of network 
26
-					   interfaces, which can be used 
27
-					   by Netsukuku */
26
+								   interfaces, which can be used 
27
+								   by Netsukuku */
28 28
 
29 29
 typedef struct {
30
-	char		dev_name[IFNAMSIZ];	/* If name */
31
-	int		dev_idx;		/* If index */
30
+	char dev_name[IFNAMSIZ];	/* If name */
31
+	int dev_idx;				/* If index */
32 32
 } interface;
33 33
 
34 34
 /* from linux/ipv6.h */
35 35
 struct in6_ifreq {
36 36
 	struct in6_addr ifr6_addr;
37
-	uint32_t        ifr6_prefixlen;
38
-	int             ifr6_ifindex;
37
+	uint32_t ifr6_prefixlen;
38
+	int ifr6_ifindex;
39 39
 };
40 40
 
41 41
 
42
-int ifs_get_pos(interface *ifs, int ifs_n, interface *dev);
43
-interface *ifs_find_idx(interface *ifs, int ifs_n, int dev_idx);
44
-int ifs_find_devname(interface *ifs, int ifs_n, char *dev_name);
45
-void ifs_del(interface *ifs, int *ifs_n, int if_pos);
46
-void ifs_del_byname(interface *ifs, int *ifs_n, char *dev_name);
47
-void ifs_del_all_name(interface *ifs, int *ifs_n, char *dev_name);
42
+int ifs_get_pos(interface * ifs, int ifs_n, interface * dev);
43
+interface *ifs_find_idx(interface * ifs, int ifs_n, int dev_idx);
44
+int ifs_find_devname(interface * ifs, int ifs_n, char *dev_name);
45
+void ifs_del(interface * ifs, int *ifs_n, int if_pos);
46
+void ifs_del_byname(interface * ifs, int *ifs_n, char *dev_name);
47
+void ifs_del_all_name(interface * ifs, int *ifs_n, char *dev_name);
48 48
 const char *get_dev(int *dev_idx);
49 49
 int set_dev_up(char *dev);
50 50
 int set_dev_down(char *dev);
51 51
 int set_flags(char *dev, u_int flags, u_int mask);
52
-int set_all_ifs(interface *ifs, int ifs_n, int (*set_func)(char *dev));
53
-int if_init_all(char *ifs_name[MAX_INTERFACES], int ifs_n, interface *new_ifs, int *new_ifs_n);
52
+int set_all_ifs(interface * ifs, int ifs_n, int (*set_func) (char *dev));
53
+int if_init_all(char *ifs_name[MAX_INTERFACES], int ifs_n,
54
+				interface * new_ifs, int *new_ifs_n);
54 55
 void if_close_all(void);
55
-int set_all_dev_ip(inet_prefix ip, interface *ifs, int ifs_n);
56
+int set_all_dev_ip(inet_prefix ip, interface * ifs, int ifs_n);
56 57
 int set_dev_ip(inet_prefix ip, char *dev);
57
-int get_dev_ip(inet_prefix *ip, int family, char *dev);
58
+int get_dev_ip(inet_prefix * ip, int family, char *dev);
58 59
 int ip_addr_flush(int family, char *dev, int scope);
59
-int ip_addr_flush_all_ifs(interface *ifs, int ifs_n, int family, int scope);
60
+int ip_addr_flush_all_ifs(interface * ifs, int ifs_n, int family,
61
+						  int scope);
60 62
 
61
-#endif /*IF_H*/
63
+#endif							/*IF_H */

+ 510
- 458
src/igs.c
File diff suppressed because it is too large
View File


+ 71
- 68
src/igs.h View File

@@ -43,7 +43,7 @@
43 43
 \*/
44 44
 
45 45
 /* Minum bandwidth necessary to share an internet connection */
46
-#define MIN_CONN_BANDWIDTH	3		/* 16 Kb/s */
46
+#define MIN_CONN_BANDWIDTH	3	/* 16 Kb/s */
47 47
 
48 48
 #define MAX_INTERNET_HNAMES	10
49 49
 #define MAX_INTERNET_HNAME_SZ	64
@@ -51,17 +51,17 @@
51 51
 #define IGW_HOST_PING_TIMEOUT	10
52 52
 #define INET_NEXT_PING_WAIT	10
53 53
 
54
-#define IGW_BW_DELTA		1		/* If the difference between the old and the new
55
-						   igw->bandwidth is >= IGW_BW_DELTA, then 
56
-						   me.igws is reordered and the routing table
57
-						   updated */
54
+#define IGW_BW_DELTA		1	/* If the difference between the old and the new
55
+								   igw->bandwidth is >= IGW_BW_DELTA, then 
56
+								   me.igws is reordered and the routing table
57
+								   updated */
58 58
 #define MAXIGWS			MAXGROUPNODE	/* max number of internet 
59
-						   gateways in each level */
59
+										   gateways in each level */
60 60
 
61 61
 #define RTTABLE_IGW		221		/* Routing tables from 221 to 244 */
62
-#define RTTABLE_ALISHIELD	245		/* Anti Loop multi-Igw Shield
63
-						   (what a damn long name, read the Ntk_IGS
64
-						   RFC) */
62
+#define RTTABLE_ALISHIELD	245	/* Anti Loop multi-Igw Shield
63
+								   (what a damn long name, read the Ntk_IGS
64
+								   RFC) */
65 65
 #define FWMARK_ALISHIELD	25
66 66
 
67 67
 #ifdef DEBUG
@@ -73,10 +73,10 @@
73 73
  * inet_gw flags
74 74
  */
75 75
 #define IGW_TUNNELED		1
76
-#define IGW_ACTIVE		(1<<1)		/* This gw is being used in the
77
-						   routing table */
78
-#define IGW_RTRULE		(1<<2)		/* The relative routing rule is already
79
-						   present */
76
+#define IGW_ACTIVE		(1<<1)	/* This gw is being used in the
77
+								   routing table */
78
+#define IGW_RTRULE		(1<<2)	/* The relative routing rule is already
79
+								   present */
80 80
 
81 81
 /*
82 82
  * internet_gateway
@@ -84,29 +84,28 @@
84 84
  * This struct points to a particular (g)node which is sharing its Internet 
85 85
  * connection
86 86
  */
87
-struct internet_gateway
88
-{
89
-	LLIST_HDR	(struct internet_gateway);
87
+struct internet_gateway {
88
+	LLIST_HDR(struct internet_gateway);
90 89
 
91
-	u_int		ip[MAX_IP_INT];
92
-	u_char		gid;
93
-	map_node	*node;
90
+	u_int ip[MAX_IP_INT];
91
+	u_char gid;
92
+	map_node *node;
94 93
 
95
-	char		flags;
96
-	u_char		bandwidth;	/* Its Internet bandwidth */
94
+	char flags;
95
+	u_char bandwidth;			/* Its Internet bandwidth */
97 96
 };
98 97
 typedef struct internet_gateway inet_gw;
99 98
 
100 99
 /* We pack only `gid' and `bandwidth' */
101 100
 #define INET_GW_PACK_SZ		(sizeof(u_char)*2 + MAX_IP_SZ)
102 101
 
103
-struct inet_gw_pack_hdr
104
-{
105
-	int16_t		gws[MAX_LEVELS];/* Number of inet_gws there are in the
106
-					   pack, for each level */
107
-	u_char		levels;
108
-}_PACKED_;
109
-INT_INFO inet_gw_pack_hdr_iinfo = { 1, { INT_TYPE_16BIT }, { 0 }, { MAX_LEVELS } };
102
+struct inet_gw_pack_hdr {
103
+	int16_t gws[MAX_LEVELS];	/* Number of inet_gws there are in the
104
+								   pack, for each level */
105
+	u_char levels;
106
+} _PACKED_;
107
+INT_INFO inet_gw_pack_hdr_iinfo =
108
+	{ 1, {INT_TYPE_16BIT}, {0}, {MAX_LEVELS} };
110 109
 
111 110
 /* 
112 111
  * The inet_gw_pack_body is:
@@ -141,15 +140,15 @@ INT_INFO inet_gw_pack_hdr_iinfo = { 1, { INT_TYPE_16BIT }, { 0 }, { MAX_LEVELS }
141 140
  * keep track of them.
142 141
  */
143 142
 struct default_inet_gw_nexthop {
144
-	inet_prefix	nexthop;
145
-
146
-	u_char		flags;		/* inet_gw flags */
147
-	
148
-	u_char		table;
149
-	u_char		tunl;		/* `tunl' is the number of the tunnel
150
-					   we are using to reach this igw. 
151
-					   (tunl = 4 means we are using the 
152
-					   "tunl4" device) */
143
+	inet_prefix nexthop;
144
+
145
+	u_char flags;				/* inet_gw flags */
146
+
147
+	u_char table;
148
+	u_char tunl;				/* `tunl' is the number of the tunnel
149
+								   we are using to reach this igw. 
150
+								   (tunl = 4 means we are using the 
151
+								   "tunl4" device) */
153 152
 };
154 153
 typedef struct default_inet_gw_nexthop igw_nexthop;
155 154
 
@@ -169,8 +168,8 @@ typedef struct default_inet_gw_nexthop igw_nexthop;
169 168
 \*/
170 169
 
171 170
 #define MAX_IGW_PER_QSPN_CHUNK		16	/* Maximum number of IGWs 
172
-						   contained in a single 
173
-						   QSPN chunk */
171
+										   contained in a single 
172
+										   QSPN chunk */
174 173
 
175 174
 
176 175
 /*\
@@ -190,46 +189,50 @@ igw_nexthop multigw_nh[MAX_MULTIPATH_ROUTES];
190 189
 \*/
191 190
 
192 191
 u_char bandwidth_in_8bit(u_int x);
193
-int str_to_inet_gw(char *str, inet_prefix *gw, char **dev);
192
+int str_to_inet_gw(char *str, inet_prefix * gw, char **dev);
194 193
 char **parse_internet_hosts(char *str, int *hosts);
195 194
 void free_internet_hosts(char **hnames, int hosts);
196 195
 
197 196
 void init_my_igw(void);
198
-void init_igws(inet_gw ***igws, int **igws_counter, int levels);
199
-void reset_igws(inet_gw **igws, int *igws_counter, int levels);
200
-void free_igws(inet_gw **igws, int *igws_counter, int levels);
201
-void init_my_igws(inet_gw **igws, int *igws_counter,
202
-		inet_gw ***my_new_igws, u_char my_bandwidth, 
203
-		map_node *cur_node, quadro_group *qg);
204
-void free_my_igws(inet_gw ***my_igs);
197
+void init_igws(inet_gw *** igws, int **igws_counter, int levels);
198
+void reset_igws(inet_gw ** igws, int *igws_counter, int levels);
199
+void free_igws(inet_gw ** igws, int *igws_counter, int levels);
200
+void init_my_igws(inet_gw ** igws, int *igws_counter,
201
+				  inet_gw *** my_new_igws, u_char my_bandwidth,
202
+				  map_node * cur_node, quadro_group * qg);
203
+void free_my_igws(inet_gw *** my_igs);
205 204
 void init_internet_gateway_search(void);
206 205
 void close_internet_gateway_search(void);
207
-inet_gw *igw_add_node(inet_gw **igws, int *igws_counter,  int level,
208
-		int gid, map_node *node, int ip[MAX_IP_INT], u_char bandwidth);
209
-int igw_del(inet_gw **igws, int *igws_counter, inet_gw *igw, int level);
210
-inet_gw *igw_find_node(inet_gw **igws, int level, map_node *node);
211
-inet_gw *igw_find_ip(inet_gw **igws, int level, u_int ip[MAX_IP_INT]);
212
-int igw_del_node(inet_gw **, int *,  int, map_node *);
206
+inet_gw *igw_add_node(inet_gw ** igws, int *igws_counter, int level,
207
+					  int gid, map_node * node, int ip[MAX_IP_INT],
208
+					  u_char bandwidth);
209
+int igw_del(inet_gw ** igws, int *igws_counter, inet_gw * igw, int level);
210
+inet_gw *igw_find_node(inet_gw ** igws, int level, map_node * node);
211
+inet_gw *igw_find_ip(inet_gw ** igws, int level, u_int ip[MAX_IP_INT]);
212
+int igw_del_node(inet_gw **, int *, int, map_node *);
213 213
 void igw_update_gnode_bw(int *, inet_gw **, inet_gw *, int, int, int);
214
-void igw_order(inet_gw **igws, int *igws_counter, inet_gw **my_igws, int level);
214
+void igw_order(inet_gw ** igws, int *igws_counter, inet_gw ** my_igws,
215
+			   int level);
215 216
 
216 217
 int igw_check_inet_conn(void);
217 218
 void *igw_check_inet_conn_t(void *null);
218 219
 void *igw_monitor_igws_t(void *null);
219 220
 
220 221
 int igw_exec_masquerade_sh(char *script, int stop);
221
-int igw_exec_tcshaper_sh(char *script, int stop, 
222
-		char *dev, int upload_bw, int dnload_bw);
223
-void reset_igw_nexthop(igw_nexthop *igwn);
222
+int igw_exec_tcshaper_sh(char *script, int stop,
223
+						 char *dev, int upload_bw, int dnload_bw);
224
+void reset_igw_nexthop(igw_nexthop * igwn);
224 225
 void reset_igw_rules(void);
225
-int igw_replace_def_igws(inet_gw **igws, int *igws_counter, 
226
-		inet_gw **my_igws, int max_levels, int family);
227
-
228
-char *igw_build_bentry(u_char level, size_t *pack_sz, int *new_bblocks);
229
-int igw_store_bblock(bnode_hdr *bblock_hdr, bnode_chunk *bchunk, u_char level);
230
-char *pack_igws(inet_gw **igws, int *igws_counter, int levels, int *pack_sz);
231
-int unpack_igws(char *pack, size_t pack_sz,
232
-		map_node *int_map, map_gnode **ext_map, int levels,
233
-		inet_gw ***new_igws, int **new_igws_counter);
234
-
235
-#endif /*IGS_H*/
226
+int igw_replace_def_igws(inet_gw ** igws, int *igws_counter,
227
+						 inet_gw ** my_igws, int max_levels, int family);
228
+
229
+char *igw_build_bentry(u_char level, size_t * pack_sz, int *new_bblocks);
230
+int igw_store_bblock(bnode_hdr * bblock_hdr, bnode_chunk * bchunk,
231
+					 u_char level);
232
+char *pack_igws(inet_gw ** igws, int *igws_counter, int levels,
233
+				int *pack_sz);
234
+int unpack_igws(char *pack, size_t pack_sz, map_node * int_map,
235
+				map_gnode ** ext_map, int levels, inet_gw *** new_igws,
236
+				int **new_igws_counter);
237
+
238
+#endif							/*IGS_H */

+ 1
- 1
src/includes.h View File

@@ -68,4 +68,4 @@
68 68
 #undef USE_DMALLOC
69 69
 #endif
70 70
 
71
-#endif /*INCLUDES_H*/
71
+#endif							/*INCLUDES_H */

+ 366
- 314
src/inet.c
File diff suppressed because it is too large
View File


+ 63
- 55
src/inet.h View File

@@ -52,7 +52,7 @@
52 52
  */
53 53
 #define NTK_RESTRICTED_10_MASK(x)	(((x) & ~0xff000000)|0x0a000000)
54 54
 #define NTK_RESTRICTED_172_MASK(x)	(((((x) & ~0xff000000) | 0xac000000) & ~0x00e00000) | 0x00100000)
55
-#define NTK_RESTRICTED_IPV6_MASK(x)	(((x) & ~0xffff0000)|0xfec00000) 
55
+#define NTK_RESTRICTED_IPV6_MASK(x)	(((x) & ~0xffff0000)|0xfec00000)
56 56
 
57 57
 
58 58
 /* `x' is in network order.
@@ -70,23 +70,24 @@
70 70
  * The inet_prefix struct is used to store IP addresses in the internals of
71 71
  * the Netsukuku code
72 72
  */
73
-typedef struct
74
-{
75
-	u_char	family;		     /* AF_INET or AF_INET6 */
76
-	u_short len;		     /* IP length: 4 or 16 (bytes) */
77
-	u_char	bits;		     /* Number of used bits of the IP */
78
-	u_int	data[MAX_IP_INT];    /* The address is kept in host long format, 
79
-				       word ORDER 1 (most significant word first) */
80
-}inet_prefix;
73
+typedef struct {
74
+	u_char family;				/* AF_INET or AF_INET6 */
75
+	u_short len;				/* IP length: 4 or 16 (bytes) */
76
+	u_char bits;				/* Number of used bits of the IP */
77
+	u_int data[MAX_IP_INT];		/* The address is kept in host long format, 
78
+								   word ORDER 1 (most significant word first) */
79
+} inet_prefix;
81 80
 
82 81
 /* int_info struct used for packing the inet_prefix struct.
83 82
  * Note that `data' is ignored 'cause it will be converted with
84 83
  * inet_htonl() / inet_ntohl() */
85 84
 INT_INFO inet_prefix_iinfo = { 1,
86
-			       { INT_TYPE_16BIT },
87
-			       { sizeof(u_char) },
88
-			       { 1 }
89
-			     };
85
+	{INT_TYPE_16BIT},
86
+	{sizeof(u_char)}
87
+	,
88
+	{1}
89
+};
90
+
90 91
 #define INET_PREFIX_PACK_SZ (sizeof(u_char) + sizeof(u_short) +\
91 92
 				sizeof(u_char) + MAX_IP_SZ)
92 93
 
@@ -101,8 +102,8 @@ INT_INFO inet_prefix_iinfo = { 1,
101 102
 /* * * defines from linux/include/net/ipv6.h * * */
102 103
 #define IPV6_ADDR_ANY		0x0000U
103 104
 
104
-#define IPV6_ADDR_UNICAST      	0x0001U	
105
-#define IPV6_ADDR_MULTICAST    	0x0002U	
105
+#define IPV6_ADDR_UNICAST      	0x0001U
106
+#define IPV6_ADDR_MULTICAST    	0x0002U
106 107
 
107 108
 #define IPV6_ADDR_LOOPBACK	0x0010U
108 109
 #define IPV6_ADDR_LINKLOCAL	0x0020U
@@ -124,7 +125,7 @@ INT_INFO inet_prefix_iinfo = { 1,
124 125
 #define IPTOS_RELIABILITY	0x04
125 126
 #define IPTOS_LOWCOST		0x02
126 127
 #define IPTOS_MINCOST		IPTOS_LOWCOST
127
-#endif /* IPTOS_LOWDELAY */
128
+#endif							/* IPTOS_LOWDELAY */
128 129
 
129 130
 
130 131
 /* 
@@ -132,45 +133,48 @@ INT_INFO inet_prefix_iinfo = { 1,
132 133
  */
133 134
 
134 135
 #define RESTRICTED_10		1	/* We are using the 10.x.x.x class for 
135
-					   the restricted mode */
136
+								   the restricted mode */
136 137
 #define RESTRICTED_172		2	/* 172.16.0.0-172.31.255.255 class */
137 138
 
138 139
 #define RESTRICTED_10_STR	"10.0.0.0-10.255.255.255"
139 140
 #define RESTRICTED_172_STR	"172.16.0.0-172.31.255.255"
140 141
 
141 142
 int my_family, restricted_mode, restricted_class;
142
-	
143
+
143 144
 /* 
144 145
  * * * Functions declaration * * 
145 146
  */
146
-void inet_ntohl(u_int *data, int family);
147
-void inet_htonl(u_int *data, int family);
148
-int inet_setip_raw(inet_prefix *ip, u_int *data, int family);
149
-int inet_setip(inet_prefix *ip, u_int *data, int family);
150
-int inet_setip_bcast(inet_prefix *ip, int family);
151
-int inet_setip_anyaddr(inet_prefix *ip, int family);
152
-int inet_setip_loopback(inet_prefix *ip, int family);
153
-int inet_setip_localaddr(inet_prefix *ip, int family, int class);
154
-int inet_is_ip_local(inet_prefix *ip, int class);
155
-void inet_copy_ipdata_raw(u_int *dst_data, inet_prefix *ip);
156
-void inet_copy_ipdata(u_int *dst_data, inet_prefix *ip);
157
-void inet_copy(inet_prefix *dst, inet_prefix *src);
158
-void pack_inet_prefix(inet_prefix *ip, char *pack);
159
-void unpack_inet_prefix(inet_prefix *ip, char *pack);
160
-int inet_addr_match(const inet_prefix *a, const inet_prefix *b, int bits);
147
+void inet_ntohl(u_int * data, int family);
148
+void inet_htonl(u_int * data, int family);
149
+int inet_setip_raw(inet_prefix * ip, u_int * data, int family);
150
+int inet_setip(inet_prefix * ip, u_int * data, int family);
151
+int inet_setip_bcast(inet_prefix * ip, int family);
152
+int inet_setip_anyaddr(inet_prefix * ip, int family);
153
+int inet_setip_loopback(inet_prefix * ip, int family);
154
+int inet_setip_localaddr(inet_prefix * ip, int family, int class);
155
+int inet_is_ip_local(inet_prefix * ip, int class);
156
+void inet_copy_ipdata_raw(u_int * dst_data, inet_prefix * ip);
157
+void inet_copy_ipdata(u_int * dst_data, inet_prefix * ip);
158
+void inet_copy(inet_prefix * dst, inet_prefix * src);
159
+void pack_inet_prefix(inet_prefix * ip, char *pack);
160
+void unpack_inet_prefix(inet_prefix * ip, char *pack);
161
+int inet_addr_match(const inet_prefix * a, const inet_prefix * b,
162
+					int bits);
161 163
 int ipv6_addr_type(inet_prefix addr);
162 164
 int inet_validate_ip(inet_prefix ip);
163 165
 
164 166
 const char *ipraw_to_str(u_int ip[MAX_IP_INT], int family);
165 167
 const char *inet_to_str(inet_prefix ip);
166
-int str_to_inet(const char *src, inet_prefix *ip);
167
-int inet_to_sockaddr(inet_prefix *ip, u_short port, struct sockaddr *dst, socklen_t *dstlen);
168
-int sockaddr_to_inet(struct sockaddr *ip, inet_prefix *dst, u_short *port);
168
+int str_to_inet(const char *src, inet_prefix * ip);
169
+int inet_to_sockaddr(inet_prefix * ip, u_short port, struct sockaddr *dst,
170
+					 socklen_t * dstlen);
171
+int sockaddr_to_inet(struct sockaddr *ip, inet_prefix * dst,
172
+					 u_short * port);
169 173
 
170 174
 int new_socket(int sock_type);
171 175
 int new_dgram_socket(int sock_type);
172 176
 int inet_close(int *sk);
173
-int inet_getpeername(int sk, inet_prefix *ip, short *port);
177
+int inet_getpeername(int sk, inet_prefix * ip, short *port);
174 178
 int join_ipv6_multicast(int socket, int idx);
175 179
 
176 180
 int set_keepalive_sk(int socket);
@@ -179,27 +183,31 @@ int set_nonblock_sk(int fd);
179 183
 int unset_nonblock_sk(int fd);
180 184
 int set_reuseaddr_sk(int socket);
181 185
 int set_bindtodevice_sk(int socket, char *dev);
182
-int set_broadcast_sk(int socket, int family, inet_prefix *host, short port, 
183
-		int dev_idx);
186
+int set_broadcast_sk(int socket, int family, inet_prefix * host,
187
+					 short port, int dev_idx);
184 188
 int new_broadcast_sk(int family, int dev_idx);
185 189
 int set_tos_sk(int socket, int lowdelay);
186 190
 
187
-int new_tcp_conn(inet_prefix *host, short port, char *dev);
188
-int new_udp_conn(inet_prefix *host, short port, char *dev);
189
-int new_bcast_conn(inet_prefix *host, short port, int dev_idx);
191
+int new_tcp_conn(inet_prefix * host, short port, char *dev);
192
+int new_udp_conn(inet_prefix * host, short port, char *dev);
193
+int new_bcast_conn(inet_prefix * host, short port, int dev_idx);
190 194
 
191 195
 ssize_t inet_recv(int s, void *buf, size_t len, int flags);
192
-ssize_t inet_recvfrom(int s, void *buf, size_t len, int flags, 
193
-		struct sockaddr *from, socklen_t *fromlen);
194
-ssize_t inet_recv_timeout(int s, void *buf, size_t len, int flags, u_int timeout);
195
-ssize_t inet_recvfrom_timeout(int s, void *buf, size_t len, int flags, 
196
-		struct sockaddr *from, socklen_t *fromlen, u_int timeout);
196
+ssize_t inet_recvfrom(int s, void *buf, size_t len, int flags,
197
+					  struct sockaddr *from, socklen_t * fromlen);
198
+ssize_t inet_recv_timeout(int s, void *buf, size_t len, int flags,
199
+						  u_int timeout);
200
+ssize_t inet_recvfrom_timeout(int s, void *buf, size_t len, int flags,
201
+							  struct sockaddr *from, socklen_t * fromlen,
202
+							  u_int timeout);
197 203
 ssize_t inet_send(int s, const void *msg, size_t len, int flags);
198
-ssize_t inet_sendto(int s, const void *msg, size_t len, int flags, 
199
-		const struct sockaddr *to, socklen_t tolen);
200
-ssize_t inet_send_timeout(int s, const void *msg, size_t len, int flags, u_int timeout);
201
-ssize_t inet_sendto_timeout(int s, const void *msg, size_t len, int flags, 
202
-		const struct sockaddr *to, socklen_t tolen, u_int timeout);
203
-ssize_t inet_sendfile(int out_fd, int in_fd, off_t *offset, size_t count);
204
-
205
-#endif /*INET_H*/
204
+ssize_t inet_sendto(int s, const void *msg, size_t len, int flags,
205
+					const struct sockaddr *to, socklen_t tolen);
206
+ssize_t inet_send_timeout(int s, const void *msg, size_t len, int flags,
207
+						  u_int timeout);
208
+ssize_t inet_sendto_timeout(int s, const void *msg, size_t len, int flags,
209
+							const struct sockaddr *to, socklen_t tolen,
210
+							u_int timeout);
211
+ssize_t inet_sendfile(int out_fd, int in_fd, off_t * offset, size_t count);
212
+
213
+#endif							/*INET_H */

+ 109
- 85
src/iptunnel.c View File

@@ -41,32 +41,36 @@
41 41
 #include "iptunnel.h"
42 42
 #include "common.h"
43 43
 
44
-static int do_add(int cmd, inet_prefix *remote, inet_prefix *local, char *dev,
45
-		char *tunl_prefix, int tunl_number);
46
-int do_del(inet_prefix *remote, inet_prefix *local, char *dev,
47
-		char *tunl_prefix, int tunl_number);
48
-
49
-int tunnel_add(inet_prefix *remote, inet_prefix *local, char *dev,
50
-		char *tunl_prefix, int tunl_number)
44
+static int do_add(int cmd, inet_prefix * remote, inet_prefix * local,
45
+				  char *dev, char *tunl_prefix, int tunl_number);
46
+int do_del(inet_prefix * remote, inet_prefix * local, char *dev,
47
+		   char *tunl_prefix, int tunl_number);
48
+
49
+int
50
+tunnel_add(inet_prefix * remote, inet_prefix * local, char *dev,
51
+		   char *tunl_prefix, int tunl_number)
51 52
 {
52 53
 	return do_add(SIOCADDTUNNEL, remote, local, dev, tunl_prefix,
53
-			tunl_number);
54
+				  tunl_number);
54 55
 }
55 56
 
56
-int tunnel_change(inet_prefix *remote, inet_prefix *local, char *dev,
57
-		char *tunl_prefix, int tunl_number)
57
+int
58
+tunnel_change(inet_prefix * remote, inet_prefix * local, char *dev,
59
+			  char *tunl_prefix, int tunl_number)
58 60
 {
59 61
 	return do_add(SIOCGETTUNNEL, remote, local, dev, tunl_prefix,
60
-			tunl_number);
62
+				  tunl_number);
61 63
 }
62 64
 
63
-int tunnel_del(inet_prefix *remote, inet_prefix *local, char *dev,
64
-		char *tunl_prefix, int tunl_number)
65
+int
66
+tunnel_del(inet_prefix * remote, inet_prefix * local, char *dev,
67
+		   char *tunl_prefix, int tunl_number)
65 68
 {
66 69
 	return do_del(remote, local, dev, tunl_prefix, tunl_number);
67 70
 }
68 71
 
69
-static int do_ioctl_get_ifindex(const char *dev)
72
+static int
73
+do_ioctl_get_ifindex(const char *dev)
70 74
 {
71 75
 	struct ifreq ifr;
72 76
 	int fd;
@@ -84,7 +88,8 @@ static int do_ioctl_get_ifindex(const char *dev)
84 88
 }
85 89
 
86 90
 #if 0
87
-static int do_ioctl_get_iftype(const char *dev)
91
+static int
92
+do_ioctl_get_iftype(const char *dev)
88 93
 {
89 94
 	struct ifreq ifr;
90 95
 	int fd;
@@ -94,14 +99,15 @@ static int do_ioctl_get_iftype(const char *dev)
94 99
 	fd = socket(AF_INET, SOCK_DGRAM, 0);
95 100
 	err = ioctl(fd, SIOCGIFHWADDR, &ifr);
96 101
 	if (err) {
97
-		error(ERROR_MSG "ioctl: %s",ERROR_POS, strerror(errno));
102
+		error(ERROR_MSG "ioctl: %s", ERROR_POS, strerror(errno));
98 103
 		return -1;
99 104
 	}
100 105
 	close(fd);
101 106
 	return ifr.ifr_addr.sa_family;
102 107
 }
103 108
 
104
-static char * do_ioctl_get_ifname(int idx)
109
+static char *
110
+do_ioctl_get_ifname(int idx)
105 111
 {
106 112
 	static struct ifreq ifr;
107 113
 	int fd;
@@ -111,7 +117,7 @@ static char * do_ioctl_get_ifname(int idx)
111 117
 	fd = socket(AF_INET, SOCK_DGRAM, 0);
112 118
 	err = ioctl(fd, SIOCGIFNAME, &ifr);
113 119
 	if (err) {
114
-		error(ERROR_MSG "ioctl: %s",ERROR_POS, strerror(errno));
120
+		error(ERROR_MSG "ioctl: %s", ERROR_POS, strerror(errno));
115 121
 		return NULL;
116 122
 	}
117 123
 	close(fd);
@@ -119,14 +125,15 @@ static char * do_ioctl_get_ifname(int idx)
119 125
 }
120 126
 #endif
121 127
 
122
-static int do_get_ioctl(const char *basedev, struct ip_tunnel_parm *p)
128
+static int
129
+do_get_ioctl(const char *basedev, struct ip_tunnel_parm *p)
123 130
 {
124 131
 	struct ifreq ifr;
125 132
 	int fd;
126 133
 	int err;
127 134
 
128 135
 	strncpy(ifr.ifr_name, basedev, IFNAMSIZ);
129
-	ifr.ifr_ifru.ifru_data = (void*)p;
136
+	ifr.ifr_ifru.ifru_data = (void *) p;
130 137
 	fd = socket(AF_INET, SOCK_DGRAM, 0);
131 138
 	err = ioctl(fd, SIOCGETTUNNEL, &ifr);
132 139
 	/*
@@ -137,7 +144,8 @@ static int do_get_ioctl(const char *basedev, struct ip_tunnel_parm *p)
137 144
 	return err;
138 145
 }
139 146
 
140
-static int do_add_ioctl(int cmd, const char *basedev, struct ip_tunnel_parm *p)
147
+static int
148
+do_add_ioctl(int cmd, const char *basedev, struct ip_tunnel_parm *p)
141 149
 {
142 150
 	struct ifreq ifr;
143 151
 	int fd;
@@ -147,17 +155,20 @@ static int do_add_ioctl(int cmd, const char *basedev, struct ip_tunnel_parm *p)
147 155
 		strncpy(ifr.ifr_name, p->name, IFNAMSIZ);
148 156
 	else
149 157
 		strncpy(ifr.ifr_name, basedev, IFNAMSIZ);
150
-	ifr.ifr_ifru.ifru_data = (void*)p;
158
+	ifr.ifr_ifru.ifru_data = (void *) p;
151 159
 	fd = socket(AF_INET, SOCK_DGRAM, 0);
152 160
 	err = ioctl(fd, cmd, &ifr);
153
-    error("Socket File Descriptor Is: %i cmd is: %i err is: %i ifr is: %s Errno is: %d", fd, cmd, err, &ifr, errno);
161
+	error
162
+		("Socket File Descriptor Is: %i cmd is: %i err is: %i ifr is: %s Errno is: %d",
163
+		 fd, cmd, err, &ifr, errno);
154 164
 	if (err)
155
-		error(ERROR_MSG "ioctl: %s",ERROR_POS, strerror(errno));
165
+		error(ERROR_MSG "ioctl: %s", ERROR_POS, strerror(errno));
156 166
 	close(fd);
157 167
 	return err;
158 168
 }
159 169
 
160
-static int do_del_ioctl(const char *basedev, struct ip_tunnel_parm *p)
170
+static int
171
+do_del_ioctl(const char *basedev, struct ip_tunnel_parm *p)
161 172
 {
162 173
 	struct ifreq ifr;
163 174
 	int fd;
@@ -167,11 +178,11 @@ static int do_del_ioctl(const char *basedev, struct ip_tunnel_parm *p)
167 178
 		strncpy(ifr.ifr_name, p->name, IFNAMSIZ);
168 179
 	else
169 180
 		strncpy(ifr.ifr_name, basedev, IFNAMSIZ);
170
-	ifr.ifr_ifru.ifru_data = (void*)p;
181
+	ifr.ifr_ifru.ifru_data = (void *) p;
171 182
 	fd = socket(AF_INET, SOCK_DGRAM, 0);
172 183
 	err = ioctl(fd, SIOCDELTUNNEL, &ifr);
173 184
 	if (err)
174
-		error(ERROR_MSG "ioctl: %s",ERROR_POS, strerror(errno));
185
+		error(ERROR_MSG "ioctl: %s", ERROR_POS, strerror(errno));
175 186
 	close(fd);
176 187
 	return err;
177 188
 }
@@ -180,9 +191,10 @@ static int do_del_ioctl(const char *basedev, struct ip_tunnel_parm *p)
180 191
  * fill_tunnel_parm: fills the `p' struct.
181 192
  * `remote' and `local' must be in host order
182 193
  */
183
-static int fill_tunnel_parm(int cmd, inet_prefix *remote, inet_prefix *local,
184
-		char *dev, char *tunl_prefix, int tunl_number,
185
-		struct ip_tunnel_parm *p)
194
+static int
195
+fill_tunnel_parm(int cmd, inet_prefix * remote, inet_prefix * local,
196
+				 char *dev, char *tunl_prefix, int tunl_number,
197
+				 struct ip_tunnel_parm *p)
186 198
 {
187 199
 	char medium[IFNAMSIZ];
188 200
 
@@ -192,17 +204,17 @@ static int fill_tunnel_parm(int cmd, inet_prefix *remote, inet_prefix *local,
192 204
 	p->iph.version = 4;
193 205
 	p->iph.ihl = 5;
194 206
 #ifndef IP_DF
195
-#define IP_DF		0x4000		/* Flag: "Don't Fragment"	*/
207
+#define IP_DF		0x4000		/* Flag: "Don't Fragment"   */
196 208
 #endif
197 209
 	p->iph.frag_off = htons(IP_DF);
198 210
 	p->iph.protocol = IPPROTO_IPIP;
199 211
 
200
-	if(remote)
212
+	if (remote)
201 213
 		p->iph.daddr = htonl(remote->data[0]);
202
-	if(local)
214
+	if (local)
203 215
 		p->iph.saddr = htonl(local->data[0]);
204
-	if(dev)
205
-		strncpy(medium, dev, IFNAMSIZ-1);
216
+	if (dev)
217
+		strncpy(medium, dev, IFNAMSIZ - 1);
206 218
 
207 219
 	sprintf(p->name, TUNL_STRING, TUNL_N(tunl_prefix, tunl_number));
208 220
 	if (cmd == SIOCCHGTUNNEL) {
@@ -233,7 +245,8 @@ static int fill_tunnel_parm(int cmd, inet_prefix *remote, inet_prefix *local,
233 245
 /*
234 246
  * do_get: returns 1 if the tunnel named `dev' exists.
235 247
  */
236
-int do_get(char *dev)
248
+int
249
+do_get(char *dev)
237 250
 {
238 251
 	struct ip_tunnel_parm old_p;
239 252
 	memset(&old_p, 0, sizeof(old_p));
@@ -244,41 +257,43 @@ int do_get(char *dev)
244 257
 	return 1;
245 258
 }
246 259
 
247
-static int do_add(int cmd, inet_prefix *remote, inet_prefix *local, char *dev,
248
-		char *tunl_prefix, int tunl_number)
260
+static int
261
+do_add(int cmd, inet_prefix * remote, inet_prefix * local, char *dev,
262
+	   char *tunl_prefix, int tunl_number)
249 263
 {
250 264
 	struct ip_tunnel_parm p;
251 265
 
252 266
 	if (fill_tunnel_parm(cmd, remote, local, dev, tunl_prefix,
253
-				tunl_number, &p) < 0)
267
+						 tunl_number, &p) < 0)
254 268
 		return -1;
255 269
 
256 270
 	if (p.iph.ttl && p.iph.frag_off == 0)
257 271
 		fatal("ttl != 0 and noptmudisc are incompatible");
258 272
 
259 273
 	switch (p.iph.protocol) {
260
-		case IPPROTO_IPIP:
261
-			return do_add_ioctl(cmd, DEFAULT_TUNL_IF, &p);
262
-		default:
263
-			fatal("cannot determine tunnel mode (ipip, gre or sit)\n");
274
+	case IPPROTO_IPIP:
275
+		return do_add_ioctl(cmd, DEFAULT_TUNL_IF, &p);
276
+	default:
277
+		fatal("cannot determine tunnel mode (ipip, gre or sit)\n");
264 278
 	}
265 279
 	return -1;
266 280
 }
267 281
 
268
-int do_del(inet_prefix *remote, inet_prefix *local, char *dev, char *tunl_prefix,
269
-		int tunl_number)
282
+int
283
+do_del(inet_prefix * remote, inet_prefix * local, char *dev,
284
+	   char *tunl_prefix, int tunl_number)
270 285
 {
271 286
 	struct ip_tunnel_parm p;
272 287
 
273 288
 	if (fill_tunnel_parm(SIOCDELTUNNEL, remote, local, dev, tunl_prefix,
274
-				tunl_number, &p) < 0)
289
+						 tunl_number, &p) < 0)
275 290
 		return -1;
276 291
 
277 292
 	switch (p.iph.protocol) {
278
-		case IPPROTO_IPIP:
279
-			return do_del_ioctl(DEFAULT_TUNL_IF, &p);
280
-		default:
281
-			return do_del_ioctl(p.name, &p);
293
+	case IPPROTO_IPIP:
294
+		return do_del_ioctl(DEFAULT_TUNL_IF, &p);
295
+	default:
296
+		return do_del_ioctl(p.name, &p);
282 297
 	}
283 298
 	return -1;
284 299
 }
@@ -287,13 +302,14 @@ int do_del(inet_prefix *remote, inet_prefix *local, char *dev, char *tunl_prefix
287 302
  * tun_add_tunl: it adds in the `ifs' array a new struct which refers to
288 303
  * the tunnel "tunlX", where X is a number equal to `tunl'.
289 304
  */
290
-int tun_add_tunl(interface *ifs, char *tunl_prefix, u_char tunl_number)
305
+int
306
+tun_add_tunl(interface * ifs, char *tunl_prefix, u_char tunl_number)
291 307
 {
292 308
 	char tunl_name[IFNAMSIZ];
293 309
 
294 310
 	sprintf(tunl_name, TUNL_STRING, TUNL_N(tunl_prefix, tunl_number));
295 311
 	strncpy(ifs->dev_name, tunl_name, IFNAMSIZ);
296
-	if(!(ifs->dev_idx=do_ioctl_get_ifindex(tunl_name)))
312
+	if (!(ifs->dev_idx = do_ioctl_get_ifindex(tunl_name)))
297 313
 		return -1;
298 314
 
299 315
 	return 0;
@@ -305,15 +321,16 @@ int tun_add_tunl(interface *ifs, char *tunl_prefix, u_char tunl_number)
305 321
  * is a number equal to `tunl'.
306 322
  * If no such struct is found, -1 is returned.
307 323
  */
308
-int tun_del_tunl(interface *ifs, char *tunl_prefix, u_char tunl_number)
324
+int
325
+tun_del_tunl(interface * ifs, char *tunl_prefix, u_char tunl_number)
309 326
 {
310 327
 	char tunl_name[IFNAMSIZ];
311 328
 	int i;
312 329
 
313 330
 	sprintf(tunl_name, TUNL_STRING, TUNL_N(tunl_prefix, tunl_number));
314 331
 
315
-	for(i=0; i<MAX_TUNNEL_IFS; i++)
316
-		if(!strncmp(ifs[i].dev_name, tunl_name, IFNAMSIZ)) {
332
+	for (i = 0; i < MAX_TUNNEL_IFS; i++)
333
+		if (!strncmp(ifs[i].dev_name, tunl_name, IFNAMSIZ)) {
317 334
 			memset(&ifs[i], 0, sizeof(interface));
318 335
 			return 0;
319 336
 		}
@@ -323,9 +340,10 @@ int tun_del_tunl(interface *ifs, char *tunl_prefix, u_char tunl_number)
323 340
 
324 341
 
325 342
 
326
-void init_tunnels_ifs(void)
343
+void
344
+init_tunnels_ifs(void)
327 345
 {
328
-	memset(tunnel_ifs, 0, sizeof(interface)*MAX_TUNNEL_IFS);
346
+	memset(tunnel_ifs, 0, sizeof(interface) * MAX_TUNNEL_IFS);
329 347
 }
330 348
 
331 349
 /*
@@ -333,12 +351,13 @@ void init_tunnels_ifs(void)
333 351
  * `tunnel_ifs' array which isn't used yet.
334 352
  * If the whole array is full, -1 is returned.
335 353
  */
336
-int first_free_tunnel_if(void)
354
+int
355
+first_free_tunnel_if(void)
337 356
 {
338 357
 	int i;
339 358
 
340
-	for(i=0; i<MAX_TUNNEL_IFS; i++)
341
-		if(!*tunnel_ifs[i].dev_name && !tunnel_ifs[i].dev_idx)
359
+	for (i = 0; i < MAX_TUNNEL_IFS; i++)
360
+		if (!*tunnel_ifs[i].dev_name && !tunnel_ifs[i].dev_idx)
342 361
 			return i;
343 362
 	return -1;
344 363
 }
@@ -347,16 +366,17 @@ int first_free_tunnel_if(void)
347 366
  * set_tunnel_ip: it brings down and up and set the `tunl_ip' IP to the
348 367
  * "tunl`tunl_number'" tunnel device
349 368
  */
350
-int set_tunnel_ip(char *tunl_prefix, int tunl_number, inet_prefix *tunl_ip)
369
+int
370
+set_tunnel_ip(char *tunl_prefix, int tunl_number, inet_prefix * tunl_ip)
351 371
 {
352 372
 	const char *ntop;
353
-	ntop=inet_to_str(*tunl_ip);
373
+	ntop = inet_to_str(*tunl_ip);
354 374
 
355 375
 	set_all_ifs(&tunnel_ifs[tunl_number], 1, set_dev_down);
356 376
 	set_all_ifs(&tunnel_ifs[tunl_number], 1, set_dev_up);
357
-	if(set_all_dev_ip(*tunl_ip, &tunnel_ifs[tunl_number], 1) < 0) {
377
+	if (set_all_dev_ip(*tunl_ip, &tunnel_ifs[tunl_number], 1) < 0) {
358 378
 		error("Cannot set the %s ip to " TUNL_STRING,
359
-				ntop, TUNL_N(tunl_prefix, tunl_number));
379
+			  ntop, TUNL_N(tunl_prefix, tunl_number));
360 380
 		return -1;
361 381
 	}
362 382
 	return 0;
@@ -366,8 +386,9 @@ int set_tunnel_ip(char *tunl_prefix, int tunl_number, inet_prefix *tunl_ip)
366 386
  * add_tunnel_if: creates a new tunnel, adds it in the `tunnel_ifs' array, and
367 387
  * if `tunl_ip' isn't null, sets to the tunnel the IP `tunl_ip'.
368 388
  */
369
-int add_tunnel_if(inet_prefix *remote, inet_prefix *local, char *dev,
370
-		char *tunl_prefix, int tunl_number, inet_prefix *tunl_ip)
389
+int
390
+add_tunnel_if(inet_prefix * remote, inet_prefix * local, char *dev,
391
+			  char *tunl_prefix, int tunl_number, inet_prefix * tunl_ip)
371 392
 {
372 393
 	char tunl_name[IFNAMSIZ];
373 394
 
@@ -375,26 +396,27 @@ int add_tunnel_if(inet_prefix *remote, inet_prefix *local, char *dev,
375 396
 	 * tunl0 zero is a special tunnel, it cannot be created nor destroyed.
376 397
 	 * It's pure energy.
377 398
 	 */
378
-	if(!strcmp(tunl_prefix, DEFAULT_TUNL_PREFIX) && !tunl_number)
399
+	if (!strcmp(tunl_prefix, DEFAULT_TUNL_PREFIX) && !tunl_number)
379 400
 		goto skip_krnl_add_tunl;
380 401
 
381
-	if(tunnel_add(remote, local, dev, tunl_prefix, tunl_number) < 0) {
402
+	if (tunnel_add(remote, local, dev, tunl_prefix, tunl_number) < 0) {
382 403
 		error("Cannot add the \"" TUNL_STRING "\" tunnel",
383
-				TUNL_N(tunl_prefix, tunl_number));
404
+			  TUNL_N(tunl_prefix, tunl_number));
384 405
 		return -1;
385 406
 	}
386 407
 
387
-skip_krnl_add_tunl:
408
+  skip_krnl_add_tunl:
388 409
 
389
-	if(tun_add_tunl(&tunnel_ifs[tunl_number], tunl_prefix, tunl_number) < 0)
410
+	if (tun_add_tunl(&tunnel_ifs[tunl_number], tunl_prefix, tunl_number) <
411
+		0)
390 412
 		return -1;
391 413
 
392
-	if(tunl_ip) {
414
+	if (tunl_ip) {
393 415
 
394 416
 		/*
395 417
 		 * ifconfig tunnel `tunl_ip' up
396 418
 		 */
397
-		if(set_tunnel_ip(tunl_prefix, tunl_number, tunl_ip) < 0)
419
+		if (set_tunnel_ip(tunl_prefix, tunl_number, tunl_ip) < 0)
398 420
 			return -1;
399 421
 
400 422
 
@@ -405,8 +427,8 @@ skip_krnl_add_tunl:
405 427
 		sprintf(tunl_name, TUNL_STRING, TUNL_N(tunl_prefix, tunl_number));
406 428
 		rt_append_subnet_src(tunl_ip, tunl_name);
407 429
 
408
-		if(route_rp_filter_all_dev(my_family, &tunnel_ifs[tunl_number],
409
-				1, 0) < 0)
430
+		if (route_rp_filter_all_dev(my_family, &tunnel_ifs[tunl_number],
431
+									1, 0) < 0)
410 432
 			return -1;
411 433
 	}
412 434
 
@@ -416,34 +438,36 @@ skip_krnl_add_tunl:
416 438
 /*
417 439
  * del_tunnel_if: the inverse of add_tunnel_if() (see above)
418 440
  */
419
-int del_tunnel_if(inet_prefix *remote, inet_prefix *local, char *dev,
420
-		char *tunl_prefix, int tunl_number)
441
+int
442
+del_tunnel_if(inet_prefix * remote, inet_prefix * local, char *dev,
443
+			  char *tunl_prefix, int tunl_number)
421 444
 {
422 445
 	/* tunl0 is a highlander */
423
-	if(!strcmp(tunl_prefix, DEFAULT_TUNL_PREFIX) && !tunl_number)
446
+	if (!strcmp(tunl_prefix, DEFAULT_TUNL_PREFIX) && !tunl_number)
424 447
 		goto skip_krnl_del_tunl;
425 448
 
426
-	if(tunnel_del(remote, local, dev, tunl_prefix, tunl_number) < 0) {
449
+	if (tunnel_del(remote, local, dev, tunl_prefix, tunl_number) < 0) {
427 450
 		error("Cannot delete the \"" TUNL_STRING "\" tunnel",
428
-				TUNL_N(tunl_prefix, tunl_number));
451
+			  TUNL_N(tunl_prefix, tunl_number));
429 452
 		return -1;
430 453
 	}
431 454
 
432
-skip_krnl_del_tunl:
455
+  skip_krnl_del_tunl:
433 456
 
434 457
 	tun_del_tunl(tunnel_ifs, tunl_prefix, tunl_number);
435 458
 	return 0;
436 459
 }
437 460
 
438
-void del_all_tunnel_ifs(inet_prefix *remote, inet_prefix *local, char *dev,
439
-		char *tunl_prefix)
461
+void
462
+del_all_tunnel_ifs(inet_prefix * remote, inet_prefix * local, char *dev,
463
+				   char *tunl_prefix)
440 464
 {
441 465
 	char tunl_name[IFNAMSIZ];
442 466
 	int i;
443 467
 
444
-	for(i=0; i<MAX_TUNNEL_IFS; i++) {
468
+	for (i = 0; i < MAX_TUNNEL_IFS; i++) {
445 469
 		sprintf(tunl_name, TUNL_STRING, TUNL_N(tunl_prefix, i));
446
-		if(do_get(tunl_name))
470
+		if (do_get(tunl_name))
447 471
 			del_tunnel_if(remote, local, 0, tunl_prefix, i);
448 472
 		else
449 473
 			break;

+ 20
- 18
src/iptunnel.h View File

@@ -31,8 +31,8 @@
31 31
 #define TUNL_N(prefix, x)	prefix, x
32 32
 
33 33
 #define MAX_TUNNEL_IFS		24	/* it must be >= MAX_MULTIPATH_ROUTES,
34
-					   since in igs.c we are using a tunnel
35
-					   for each nexthop inet-gw */
34
+								   since in igs.c we are using a tunnel
35
+								   for each nexthop inet-gw */
36 36
 
37 37
 /*
38 38
  * * Globals * *
@@ -46,23 +46,25 @@ interface tunnel_ifs[MAX_TUNNEL_IFS];
46 46
  */
47 47
 
48 48
 
49
-int tunnel_add(inet_prefix *remote, inet_prefix *local, char *dev,
50
-		char *tunl_prefix, int tunl_number);
51
-int tunnel_change(inet_prefix *remote, inet_prefix *local, char *dev,
52
-		char *tunl_prefix, int tunl_number);
53
-int tunnel_del(inet_prefix *remote, inet_prefix *local, char *dev,
54
-		char *tunl_prefix, int tunl_number);
49
+int tunnel_add(inet_prefix * remote, inet_prefix * local, char *dev,
50
+			   char *tunl_prefix, int tunl_number);
51
+int tunnel_change(inet_prefix * remote, inet_prefix * local, char *dev,
52
+				  char *tunl_prefix, int tunl_number);
53
+int tunnel_del(inet_prefix * remote, inet_prefix * local, char *dev,
54
+			   char *tunl_prefix, int tunl_number);
55 55
 
56
-int tun_add_tunl(interface *ifs, char *tunl_prefix, u_char tunl_number);
57
-int tun_del_tunl(interface *ifs, char *tunl_prefix, u_char tunl_number);
56
+int tun_add_tunl(interface * ifs, char *tunl_prefix, u_char tunl_number);
57
+int tun_del_tunl(interface * ifs, char *tunl_prefix, u_char tunl_number);
58 58
 void init_tunnels_ifs(void);
59
-int set_tunnel_ip(char *tunl_prefix, int tunl_number, inet_prefix *tunl_ip);
59
+int set_tunnel_ip(char *tunl_prefix, int tunl_number,
60
+				  inet_prefix * tunl_ip);
60 61
 int first_free_tunnel_if(void);
61 62
 int do_get(char *dev);
62
-int add_tunnel_if(inet_prefix *remote, inet_prefix *local, char *dev,
63
-		char *tunl_prefix, int tunl_number, inet_prefix *tunl_ip);
64
-int del_tunnel_if(inet_prefix *remote, inet_prefix *local, char *dev,
65
-		char *tunl_prefix, int tunl_number);
66
-void del_all_tunnel_ifs(inet_prefix *remote, inet_prefix *local, char *dev,
67
-		char *tunl_prefix);
68
-#endif /* IPTUNNEL_H */
63
+int add_tunnel_if(inet_prefix * remote, inet_prefix * local, char *dev,
64
+				  char *tunl_prefix, int tunl_number,
65
+				  inet_prefix * tunl_ip);
66
+int del_tunnel_if(inet_prefix * remote, inet_prefix * local, char *dev,
67
+				  char *tunl_prefix, int tunl_number);
68
+void del_all_tunnel_ifs(inet_prefix * remote, inet_prefix * local,
69
+						char *dev, char *tunl_prefix);
70
+#endif							/* IPTUNNEL_H */

+ 53
- 43
src/ipv6-gmp.c View File

@@ -24,42 +24,45 @@
24 24
 #include "ipv6-gmp.h"
25 25
 
26 26
 /*y=x+y*/
27
-int sum_128(unsigned int *x, unsigned int *y)
27
+int
28
+sum_128(unsigned int *x, unsigned int *y)
28 29
 {
29 30
 	mpz_t xx, yy, res;
30 31
 	size_t count;
31
-	
32
+
32 33
 	mpz_init(res);
33 34
 	mpz_init(xx);
34 35
 	mpz_init(yy);
35
-	mpz_import (xx, 4, HOST_ORDER, sizeof(x[0]), NATIVE_ENDIAN, 0, x);
36
-	mpz_import (yy, 4, HOST_ORDER, sizeof(y[0]), NATIVE_ENDIAN, 0, y);
36
+	mpz_import(xx, 4, HOST_ORDER, sizeof(x[0]), NATIVE_ENDIAN, 0, x);
37
+	mpz_import(yy, 4, HOST_ORDER, sizeof(y[0]), NATIVE_ENDIAN, 0, y);
37 38
 
38 39
 	mpz_add(res, xx, yy);
39
-	memset(y, '\0', sizeof(y[0])*4);
40
+	memset(y, '\0', sizeof(y[0]) * 4);
40 41
 	mpz_export(y, &count, HOST_ORDER, sizeof(x[0]), NATIVE_ENDIAN, 0, res);
41
-	
42
+
42 43
 	mpz_clear(xx);
43 44
 	mpz_clear(yy);
44 45
 	mpz_clear(res);
45
-	return 0;	
46
+	return 0;
46 47
 }
47 48
 
48 49
 /*y=x+y*/
49
-int sum_int(unsigned int x, unsigned int *y)
50
+int
51
+sum_int(unsigned int x, unsigned int *y)
50 52
 {
51
-	unsigned int z[4]=ZERO128;
52
-	
53
-	z[3]=x;
53
+	unsigned int z[4] = ZERO128;
54
+
55
+	z[3] = x;
54 56
 	return sum_128(z, y);
55 57
 }
56 58
 
57 59
 /*y=x-y*/
58
-int sub_128(unsigned int *x, unsigned int *y)
60
+int
61
+sub_128(unsigned int *x, unsigned int *y)
59 62
 {
60 63
 	mpz_t xx, yy, res;
61 64
 	size_t count;
62
-	
65
+
63 66
 	mpz_init(res);
64 67
 	mpz_init(xx);
65 68
 	mpz_init(yy);
@@ -67,57 +70,61 @@ int sub_128(unsigned int *x, unsigned int *y)
67 70
 	mpz_import(yy, 4, HOST_ORDER, sizeof(y[0]), NATIVE_ENDIAN, 0, y);
68 71
 
69 72
 	mpz_sub(res, xx, yy);
70
-	memset(y, '\0', sizeof(y[0])*4);
73
+	memset(y, '\0', sizeof(y[0]) * 4);
71 74
 	mpz_export(y, &count, HOST_ORDER, sizeof(x[0]), NATIVE_ENDIAN, 0, res);
72
-	
75
+
73 76
 	mpz_clear(xx);
74 77
 	mpz_clear(yy);
75 78
 	mpz_clear(res);
76
-	return 0;	
79
+	return 0;
77 80
 }
78 81
 
79 82
 /* y=y-x */
80
-int sub_int(unsigned int *y, unsigned int x)
83
+int
84
+sub_int(unsigned int *y, unsigned int x)
81 85
 {
82
-	unsigned int z[4]=ZERO128;
86
+	unsigned int z[4] = ZERO128;
83 87
 
84
-	z[3]=x;
88
+	z[3] = x;
85 89
 	return sub_128(z, y);
86 90
 }
87 91
 
88 92
 /*y=x/y*/
89
-int div_128(unsigned int *x, unsigned int *y)
93
+int
94
+div_128(unsigned int *x, unsigned int *y)
90 95
 {
91 96
 	mpz_t xx, yy, res;
92 97
 	size_t count;
93
-	
98
+
94 99
 	mpz_init(res);
95 100
 	mpz_init(xx);
96 101
 	mpz_init(yy);
97 102
 	mpz_import(xx, 4, HOST_ORDER, sizeof(x[0]), NATIVE_ENDIAN, 0, x);
98 103
 	mpz_import(yy, 4, HOST_ORDER, sizeof(y[0]), NATIVE_ENDIAN, 0, y);
99
-	
104
+
100 105
 	mpz_tdiv_q(res, xx, yy);
101
-	memset(y, '\0', sizeof(y[0])*4);
106
+	memset(y, '\0', sizeof(y[0]) * 4);
102 107
 	mpz_export(y, &count, HOST_ORDER, sizeof(x[0]), NATIVE_ENDIAN, 0, res);
103
-	
108
+
104 109
 	mpz_clear(xx);
105 110
 	mpz_clear(yy);
106 111
 	mpz_clear(res);
107
-	return 0;	
112
+	return 0;
108 113
 }
109 114
 
110 115
 /* y=y/x */
111
-int div_int(unsigned int *y, unsigned int x)
116
+int
117
+div_int(unsigned int *y, unsigned int x)
112 118
 {
113
-	unsigned int z[4]=ZERO128;
119
+	unsigned int z[4] = ZERO128;
114 120
 
115
-	z[3]=x;
121
+	z[3] = x;
116 122
 	return div_128(z, y);
117 123
 }
118 124
 
119 125
 /* y=y/x */
120
-int div_mpz(unsigned int *y, mpz_t x)
126
+int
127
+div_mpz(unsigned int *y, mpz_t x)
121 128
 {
122 129
 	mpz_t yy, res;
123 130
 	size_t count;
@@ -125,39 +132,42 @@ int div_mpz(unsigned int *y, mpz_t x)
125 132
 	mpz_init(res);
126 133
 	mpz_init(yy);
127 134
 	mpz_import(yy, 4, HOST_ORDER, sizeof(y[0]), NATIVE_ENDIAN, 0, y);
128
-	
135
+
129 136
 	mpz_tdiv_q(res, yy, x);
130
-	memset(y, '\0', sizeof(y[0])*4);
137
+	memset(y, '\0', sizeof(y[0]) * 4);
131 138
 	mpz_export(y, &count, HOST_ORDER, sizeof(x[0]), NATIVE_ENDIAN, 0, res);
132
-	
139
+
133 140
 	mpz_clear(yy);
134 141
 	mpz_clear(res);
135
-	return 0;	
142
+	return 0;
136 143
 }
137 144
 
138 145
 /* "ORDER can be 1 for most significant word first or -1 for least significant first." */
139
-int htonl_128(unsigned int *x, unsigned int *y)
146
+int
147
+htonl_128(unsigned int *x, unsigned int *y)
140 148
 {
141 149
 	mpz_t xx;
142 150
 	size_t count;
143
-	
151
+
144 152
 	mpz_init(xx);
145
-	mpz_import(xx, 4,     HOST_ORDER, sizeof(x[0]), NATIVE_ENDIAN,  0, x);
146
-	memset(y, '\0', sizeof(y[0])*4);
147
-	mpz_export(y, &count, NETWORK_ORDER, sizeof(x[0]), NETWORK_ENDIAN, 0, xx);
153
+	mpz_import(xx, 4, HOST_ORDER, sizeof(x[0]), NATIVE_ENDIAN, 0, x);
154
+	memset(y, '\0', sizeof(y[0]) * 4);
155
+	mpz_export(y, &count, NETWORK_ORDER, sizeof(x[0]), NETWORK_ENDIAN, 0,
156
+			   xx);
148 157
 	mpz_clear(xx);
149 158
 	return 0;
150 159
 }
151 160
 
152
-int ntohl_128(unsigned int *x, unsigned int *y)
161
+int
162
+ntohl_128(unsigned int *x, unsigned int *y)
153 163
 {
154 164
 	mpz_t xx;
155 165
 	size_t count;
156
-	
166
+
157 167
 	mpz_init(xx);
158
-	mpz_import(xx, 4,     NETWORK_ORDER, sizeof(x[0]), NETWORK_ENDIAN, 0, x);
159
-	memset(y, '\0', sizeof(y[0])*4);
160
-	mpz_export(y, &count, HOST_ORDER, sizeof(x[0]), NATIVE_ENDIAN,  0, xx);	
168
+	mpz_import(xx, 4, NETWORK_ORDER, sizeof(x[0]), NETWORK_ENDIAN, 0, x);
169
+	memset(y, '\0', sizeof(y[0]) * 4);
170
+	mpz_export(y, &count, HOST_ORDER, sizeof(x[0]), NATIVE_ENDIAN, 0, xx);
161 171
 	mpz_clear(xx);
162 172
 
163 173
 	return 0;

+ 2
- 2
src/ipv6-gmp.h View File

@@ -32,7 +32,7 @@
32 32
 #define HOST_ENDIAN  		-1
33 33
 #define NETWORK_ENDIAN		1
34 34
 
35
-int sum_int(unsigned int , unsigned int *);
35
+int sum_int(unsigned int, unsigned int *);
36 36
 int sum_128(unsigned int *, unsigned int *);
37 37
 int sub_int(unsigned int *, unsigned int);
38 38
 int sub_128(unsigned int *, unsigned int *);
@@ -42,4 +42,4 @@ int div_mpz(unsigned int *, mpz_t);
42 42
 int htonl_128(unsigned int *, unsigned int *);
43 43
 int ntohl_128(unsigned int *, unsigned int *);
44 44
 
45
-#endif /*IPV6_GMP_H*/
45
+#endif							/*IPV6_GMP_H */

+ 210
- 179
src/krnl_route.c View File

@@ -36,90 +36,100 @@
36 36
 #define NTK_MULTIPATH_ALGO IP_MP_ALG_WRANDOM
37 37
 #endif
38 38
 
39
-static struct
40
-{
41
-        int tb;
42
-        int flushed;
43
-        char *flushb;
44
-        int flushp;
45
-        int flushe;
46
-        struct rtnl_handle *rth;
47
-        int protocol, protocolmask;
48
-        int scope, scopemask;
49
-        int type, typemask;
50
-        int tos, tosmask;
51
-        int iif, iifmask;
52
-        int oif, oifmask;
53
-        int realm, realmmask;
54
-        inet_prefix rprefsrc;
55
-        inet_prefix rvia;
56
-        inet_prefix rdst;
57
-        inet_prefix mdst;
58
-        inet_prefix rsrc;
59
-        inet_prefix msrc;
39
+static struct {
40
+	int tb;
41
+	int flushed;
42
+	char *flushb;
43
+	int flushp;
44
+	int flushe;
45
+	struct rtnl_handle *rth;
46
+	int protocol, protocolmask;
47
+	int scope, scopemask;
48
+	int type, typemask;
49
+	int tos, tosmask;
50
+	int iif, iifmask;
51
+	int oif, oifmask;
52
+	int realm, realmmask;
53
+	inet_prefix rprefsrc;
54
+	inet_prefix rvia;
55
+	inet_prefix rdst;
56
+	inet_prefix mdst;
57
+	inet_prefix rsrc;
58
+	inet_prefix msrc;
60 59
 } filter;
61 60
 
62
-void route_reset_filter()
61
+void
62
+route_reset_filter()
63 63
 {
64
-        setzero(&filter, sizeof(filter));
65
-        filter.mdst.bits = -1;
66
-        filter.msrc.bits = -1;
64
+	setzero(&filter, sizeof(filter));
65
+	filter.mdst.bits = -1;
66
+	filter.msrc.bits = -1;
67 67
 }
68 68
 
69
-int route_exec(int route_cmd, int route_type, int route_scope, unsigned flags,
70
-		inet_prefix *src, inet_prefix *to, struct nexthop *nhops, 
71
-		char *dev, u_char table);
69
+int route_exec(int route_cmd, int route_type, int route_scope,
70
+			   unsigned flags, inet_prefix * src, inet_prefix * to,
71
+			   struct nexthop *nhops, char *dev, u_char table);
72 72
 
73
-int route_add(ROUTE_CMD_VARS)
73
+int
74
+route_add(ROUTE_CMD_VARS)
74 75
 {
75 76
 	return route_exec(RTM_NEWROUTE, type, scope, NLM_F_CREATE | NLM_F_EXCL,
76
-			src, to, nhops, dev, table);
77
+					  src, to, nhops, dev, table);
77 78
 }
78 79
 
79
-int route_del(ROUTE_CMD_VARS)
80
+int
81
+route_del(ROUTE_CMD_VARS)
80 82
 {
81
-	return route_exec(RTM_DELROUTE, type, scope, 0, src, to, nhops, dev, table);
83
+	return route_exec(RTM_DELROUTE, type, scope, 0, src, to, nhops, dev,
84
+					  table);
82 85
 }
83 86
 
84 87
 /*If it doesn't exist, CREATE IT! de ih oh oh*/
85
-int route_replace(ROUTE_CMD_VARS)
88
+int
89
+route_replace(ROUTE_CMD_VARS)
86 90
 {
87
-	return route_exec(RTM_NEWROUTE, type, scope, NLM_F_REPLACE | NLM_F_CREATE,
88
-			src, to, nhops, dev, table);
91
+	return route_exec(RTM_NEWROUTE, type, scope,
92
+					  NLM_F_REPLACE | NLM_F_CREATE, src, to, nhops, dev,
93
+					  table);
89 94
 }
90 95
 
91
-int route_change(ROUTE_CMD_VARS)
96
+int
97
+route_change(ROUTE_CMD_VARS)
92 98
 {
93
-	return route_exec(RTM_NEWROUTE, type, scope, NLM_F_REPLACE, src, to, nhops, 
94
-			dev, table);
99
+	return route_exec(RTM_NEWROUTE, type, scope, NLM_F_REPLACE, src, to,
100
+					  nhops, dev, table);
95 101
 }
96 102
 
97
-int route_append(ROUTE_CMD_VARS)
103
+int
104
+route_append(ROUTE_CMD_VARS)
98 105
 {
99
-	return route_exec(RTM_NEWROUTE, type, scope, NLM_F_CREATE|NLM_F_APPEND,
100
-			src, to, nhops, dev, table);
106
+	return route_exec(RTM_NEWROUTE, type, scope,
107
+					  NLM_F_CREATE | NLM_F_APPEND, src, to, nhops, dev,
108
+					  table);
101 109
 }
102 110
 
103
-int add_nexthops(struct nlmsghdr *n, struct rtmsg *r, struct nexthop *nhop)
111
+int
112
+add_nexthops(struct nlmsghdr *n, struct rtmsg *r, struct nexthop *nhop)
104 113
 {
105 114
 	char buf[1024];
106
-	struct rtattr *rta = (void*)buf;
115
+	struct rtattr *rta = (void *) buf;
107 116
 	struct rtnexthop *rtnh;
108
-	int i=0, idx;
117
+	int i = 0, idx;
109 118
 
110 119
 	rta->rta_type = RTA_MULTIPATH;
111 120
 	rta->rta_len = RTA_LENGTH(0);
112 121
 	rtnh = RTA_DATA(rta);
113 122
 
114
-	if(!nhop[i+1].dev) {
123
+	if (!nhop[i + 1].dev) {
115 124
 		/* Just one gateway */
116 125
 		r->rtm_family = nhop[i].gw.family;
117
-		addattr_l(n, sizeof(struct rt_request), RTA_GATEWAY, &nhop[i].gw.data, nhop[i].gw.len);
126
+		addattr_l(n, sizeof(struct rt_request), RTA_GATEWAY,
127
+				  &nhop[i].gw.data, nhop[i].gw.len);
118 128
 
119
-		if(nhop[0].dev) {
129
+		if (nhop[0].dev) {
120 130
 			if ((idx = ll_name_to_index(nhop[0].dev)) == 0) {
121
-				error(ERROR_MSG "Device \"%s\" doesn't really exist\n", 
122
-						ERROR_POS, nhop[0].dev);
131
+				error(ERROR_MSG "Device \"%s\" doesn't really exist\n",
132
+					  ERROR_POS, nhop[0].dev);
123 133
 				return -1;
124 134
 			}
125 135
 			addattr32(n, sizeof(struct rt_request), RTA_OIF, idx);
@@ -127,32 +137,34 @@ int add_nexthops(struct nlmsghdr *n, struct rtmsg *r, struct nexthop *nhop)
127 137
 
128 138
 		return 0;
129 139
 	}
130
-
131 140
 #if 0
132 141
 	/* We have more than one nexthop, equalize them */
133
-	req.rt.rtm_flags|=RTM_F_EQUALIZE;
142
+	req.rt.rtm_flags |= RTM_F_EQUALIZE;
134 143
 #endif
135 144
 
136
-	while (nhop[i].dev!=0) {
145
+	while (nhop[i].dev != 0) {
137 146
 		setzero(rtnh, sizeof(*rtnh));
138 147
 		rtnh->rtnh_len = sizeof(*rtnh);
139 148
 		rta->rta_len += rtnh->rtnh_len;
140 149
 
141 150
 		if (nhop[i].gw.len) {
142
-			if(nhop[i].gw.family==AF_INET)
151
+			if (nhop[i].gw.family == AF_INET)
143 152
 				rta_addattr32(rta, 4096, RTA_GATEWAY, nhop[i].gw.data[0]);
144
-			else if(nhop[i].gw.family==AF_INET6)
145
-				rta_addattr_l(rta, 4096, RTA_GATEWAY, nhop[i].gw.data, nhop[i].gw.len);
153
+			else if (nhop[i].gw.family == AF_INET6)
154
+				rta_addattr_l(rta, 4096, RTA_GATEWAY, nhop[i].gw.data,
155
+							  nhop[i].gw.len);
146 156
 			rtnh->rtnh_len += sizeof(struct rtattr) + nhop[i].gw.len;
147 157
 		}
148 158
 
149
-		if (nhop[i].dev) 
159
+		if (nhop[i].dev)
150 160
 			if ((rtnh->rtnh_ifindex = ll_name_to_index(nhop[i].dev)) == 0)
151
-				fatal("%s:%d, Cannot find device \"%s\"\n", ERROR_POS, nhop[i].dev);
161
+				fatal("%s:%d, Cannot find device \"%s\"\n", ERROR_POS,
162
+					  nhop[i].dev);
152 163
 
153 164
 		if (nhop[i].hops == 0) {
154
-			debug(DBG_NORMAL, "hops=%d is invalid. Using hops=255\n", nhop[i].hops);
155
-			rtnh->rtnh_hops=255;
165
+			debug(DBG_NORMAL, "hops=%d is invalid. Using hops=255\n",
166
+				  nhop[i].hops);
167
+			rtnh->rtnh_hops = 255;
156 168
 		} else
157 169
 			rtnh->rtnh_hops = nhop[i].hops - 1;
158 170
 
@@ -169,20 +181,21 @@ int add_nexthops(struct nlmsghdr *n, struct rtmsg *r, struct nexthop *nhop)
169 181
  * route_exec: replaces, adds or deletes a route from the routing table.
170 182
  * `to' and nhops->gw must be addresses given in network order
171 183
  */
172
-int route_exec(int route_cmd, int route_type, int route_scope, unsigned flags,
173
-		inet_prefix *src, inet_prefix *to, struct nexthop *nhops, 
174
-		char *dev, u_char table)
184
+int
185
+route_exec(int route_cmd, int route_type, int route_scope, unsigned flags,
186
+		   inet_prefix * src, inet_prefix * to, struct nexthop *nhops,
187
+		   char *dev, u_char table)
175 188
 {
176 189
 	struct rt_request req;
177 190
 	struct rtnl_handle rth;
178 191
 
179 192
 	setzero(&req, sizeof(req));
180 193
 
181
-	if(!table)
182
-		table=RT_TABLE_MAIN;
194
+	if (!table)
195
+		table = RT_TABLE_MAIN;
183 196
 
184 197
 	req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
185
-	req.nh.nlmsg_flags = NLM_F_REQUEST|flags;
198
+	req.nh.nlmsg_flags = NLM_F_REQUEST | flags;
186 199
 	req.nh.nlmsg_type = route_cmd;
187 200
 	req.rt.rtm_family = AF_UNSPEC;
188 201
 	req.rt.rtm_table = table;
@@ -191,27 +204,27 @@ int route_exec(int route_cmd, int route_type, int route_scope, unsigned flags,
191 204
 	req.rt.rtm_type = RTN_UNSPEC;
192 205
 
193 206
 	/* kernel protocol layer */
194
-	if(table == RT_TABLE_LOCAL)
207
+	if (table == RT_TABLE_LOCAL)
195 208
 		req.rt.rtm_protocol = RTPROT_KERNEL;
196
-	
209
+
197 210
 	if (route_cmd != RTM_DELROUTE) {
198 211
 		req.rt.rtm_scope = RT_SCOPE_UNIVERSE;
199 212
 		req.rt.rtm_type = RTN_UNICAST;
200 213
 	}
201
-	
202
-	if(route_type)
214
+
215
+	if (route_type)
203 216
 		req.rt.rtm_type = route_type;
204 217
 
205
-	if(route_scope)
218
+	if (route_scope)
206 219
 		req.rt.rtm_scope = route_scope;
207
-	else if(req.rt.rtm_type==RTN_LOCAL)
208
-		req.rt.rtm_scope=RT_SCOPE_HOST;
220
+	else if (req.rt.rtm_type == RTN_LOCAL)
221
+		req.rt.rtm_scope = RT_SCOPE_HOST;
222
+
209 223
 
210
-	
211 224
 	if (rtnl_open(&rth, 0) < 0)
212 225
 		return -1;
213 226
 
214
-	if (dev || nhops) 
227
+	if (dev || nhops)
215 228
 		ll_init_map(&rth);
216 229
 
217 230
 #ifdef LINUX_2_6_14
@@ -223,39 +236,40 @@ int route_exec(int route_cmd, int route_type, int route_scope, unsigned flags,
223 236
 		int idx;
224 237
 
225 238
 		if ((idx = ll_name_to_index(dev)) == 0) {
226
-			error("%s:%d, Device \"%s\" doesn't really exist\n", ERROR_POS, dev);
239
+			error("%s:%d, Device \"%s\" doesn't really exist\n", ERROR_POS,
240
+				  dev);
227 241
 			return -1;
228 242
 		}
229 243
 		addattr32(&req.nh, sizeof(req), RTA_OIF, idx);
230 244
 	}
231 245
 
232
-	if(to) {
246
+	if (to) {
233 247
 		req.rt.rtm_family = to->family;
234 248
 		req.rt.rtm_dst_len = to->bits;
235 249
 
236
-		if(!to->data[0] && !to->data[1] && !to->data[2] && !to->data[3]) {
237
-			/* Modify the default gw*/
238
-			if(route_cmd == RTM_DELROUTE)
239
-				req.rt.rtm_protocol=0;
250
+		if (!to->data[0] && !to->data[1] && !to->data[2] && !to->data[3]) {
251
+			/* Modify the default gw */
252
+			if (route_cmd == RTM_DELROUTE)
253
+				req.rt.rtm_protocol = 0;
240 254
 		}
241 255
 
242
-		if(to->len)		
256
+		if (to->len)
243 257
 			addattr_l(&req.nh, sizeof(req), RTA_DST, &to->data, to->len);
244 258
 	}
245 259
 
246
-	if(src) {
260
+	if (src) {
247 261
 		if (req.rt.rtm_family == AF_UNSPEC)
248 262
 			req.rt.rtm_family = src->family;
249 263
 		addattr_l(&req.nh, sizeof(req), RTA_PREFSRC, &src->data, src->len);
250 264
 	}
251
-	
252
-	if(nhops)
265
+
266
+	if (nhops)
253 267
 		add_nexthops(&req.nh, &req.rt, nhops);
254
-	
255
-        if (req.rt.rtm_family == AF_UNSPEC)
256
-                req.rt.rtm_family = AF_INET;
257 268
 
258
-	/*Finaly stage: <<Hey krnl, r u there?>>*/
269
+	if (req.rt.rtm_family == AF_UNSPEC)
270
+		req.rt.rtm_family = AF_INET;
271
+
272
+	/*Finaly stage: <<Hey krnl, r u there?>> */
259 273
 	if (rtnl_talk(&rth, &req.nh, 0, 0, NULL, NULL, NULL) < 0)
260 274
 		return -1;
261 275
 
@@ -271,11 +285,12 @@ int route_exec(int route_cmd, int route_type, int route_scope, unsigned flags,
271 285
  * The dev name of the route is appended at `arg'+sizeof(inet_prefix).
272 286
  * Only the non-deleted routes are considered.
273 287
  */
274
-int route_get_gw(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
288
+int
289
+route_get_gw(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
275 290
 {
276 291
 	struct rtmsg *r = NLMSG_DATA(n);
277 292
 	int len = n->nlmsg_len;
278
-	struct rtattr * tb[RTA_MAX+1];
293
+	struct rtattr *tb[RTA_MAX + 1];
279 294
 	inet_prefix dst;
280 295
 	inet_prefix via;
281 296
 	int host_len = -1;
@@ -301,10 +316,10 @@ int route_get_gw(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
301 316
 	if (r->rtm_family == AF_INET6) {
302 317
 		if (filter.tb) {
303 318
 			if (filter.tb < 0) {
304
-				if (!(r->rtm_flags&RTM_F_CLONED))
319
+				if (!(r->rtm_flags & RTM_F_CLONED))
305 320
 					return 0;
306 321
 			} else {
307
-				if (r->rtm_flags&RTM_F_CLONED)
322
+				if (r->rtm_flags & RTM_F_CLONED)
308 323
 					return 0;
309 324
 				if (filter.tb == RT_TABLE_LOCAL) {
310 325
 					if (r->rtm_type != RTN_LOCAL)
@@ -321,27 +336,29 @@ int route_get_gw(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
321 336
 		if (filter.tb > 0 && filter.tb != r->rtm_table)
322 337
 			return 0;
323 338
 	}
324
-	if ((filter.protocol^r->rtm_protocol)&filter.protocolmask)
339
+	if ((filter.protocol ^ r->rtm_protocol) & filter.protocolmask)
325 340
 		return 0;
326
-	if ((filter.scope^r->rtm_scope)&filter.scopemask)
341
+	if ((filter.scope ^ r->rtm_scope) & filter.scopemask)
327 342
 		return 0;
328
-	if ((filter.type^r->rtm_type)&filter.typemask)
343
+	if ((filter.type ^ r->rtm_type) & filter.typemask)
329 344
 		return 0;
330
-	if ((filter.tos^r->rtm_tos)&filter.tosmask)
345
+	if ((filter.tos ^ r->rtm_tos) & filter.tosmask)
331 346
 		return 0;
332 347
 	if (filter.rdst.family &&
333
-			(r->rtm_family != filter.rdst.family || filter.rdst.bits > r->rtm_dst_len))
348
+		(r->rtm_family != filter.rdst.family
349
+		 || filter.rdst.bits > r->rtm_dst_len))
334 350
 		return 0;
335 351
 	if (filter.mdst.family &&
336
-			(r->rtm_family != filter.mdst.family ||
337
-			 (filter.mdst.bits < r->rtm_dst_len)))
352
+		(r->rtm_family != filter.mdst.family ||
353
+		 (filter.mdst.bits < r->rtm_dst_len)))
338 354
 		return 0;
339 355
 	if (filter.rsrc.family &&
340
-			(r->rtm_family != filter.rsrc.family || filter.rsrc.bits > r->rtm_src_len))
356
+		(r->rtm_family != filter.rsrc.family
357
+		 || filter.rsrc.bits > r->rtm_src_len))
341 358
 		return 0;
342 359
 	if (filter.msrc.family &&
343
-			(r->rtm_family != filter.msrc.family ||
344
-			 (filter.msrc.bits < r->rtm_src_len)))
360
+		(r->rtm_family != filter.msrc.family ||
361
+		 (filter.msrc.bits < r->rtm_src_len)))
345 362
 		return 0;
346 363
 	if (filter.rvia.family && r->rtm_family != filter.rvia.family)
347 364
 		return 0;
@@ -353,12 +370,13 @@ int route_get_gw(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
353 370
 	setzero(&dst, sizeof(dst));
354 371
 	dst.family = r->rtm_family;
355 372
 	if (tb[RTA_DST]) {
356
-		memcpy(&dst.data, RTA_DATA(tb[RTA_DST]), (r->rtm_dst_len+7)/8);
373
+		memcpy(&dst.data, RTA_DATA(tb[RTA_DST]), (r->rtm_dst_len + 7) / 8);
357 374
 	}
358
-	if (filter.rdst.family && inet_addr_match(&dst, &filter.rdst, filter.rdst.bits))
375
+	if (filter.rdst.family
376
+		&& inet_addr_match(&dst, &filter.rdst, filter.rdst.bits))
359 377
 		return 0;
360 378
 	if (filter.mdst.family &&
361
-			inet_addr_match(&dst, &filter.mdst, r->rtm_dst_len))
379
+		inet_addr_match(&dst, &filter.mdst, r->rtm_dst_len))
362 380
 		return 0;
363 381
 
364 382
 	if (n->nlmsg_type == RTM_DELROUTE)
@@ -367,11 +385,11 @@ int route_get_gw(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
367 385
 	/*
368 386
 	 * ... and finally if all the tests passed, copy the gateway address
369 387
 	 */
370
-	if(tb[RTA_GATEWAY]) {
371
-		memcpy(&via.data, RTA_DATA(tb[RTA_GATEWAY]), host_len/8);
372
-		via.family=r->rtm_family;
373
-		inet_setip(arg, (u_int *)&via.data, via.family);
374
-	} else if(tb[RTA_MULTIPATH]) {
388
+	if (tb[RTA_GATEWAY]) {
389
+		memcpy(&via.data, RTA_DATA(tb[RTA_GATEWAY]), host_len / 8);
390
+		via.family = r->rtm_family;
391
+		inet_setip(arg, (u_int *) & via.data, via.family);
392
+	} else if (tb[RTA_MULTIPATH]) {
375 393
 		struct rtnexthop *nh = RTA_DATA(tb[RTA_MULTIPATH]);
376 394
 
377 395
 		len = RTA_PAYLOAD(tb[RTA_MULTIPATH]);
@@ -381,23 +399,26 @@ int route_get_gw(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
381 399
 				break;
382 400
 			if (nh->rtnh_len > len)
383 401
 				break;
384
-			if (r->rtm_flags&RTM_F_CLONED && r->rtm_type == RTN_MULTICAST)
402
+			if (r->rtm_flags & RTM_F_CLONED
403
+				&& r->rtm_type == RTN_MULTICAST)
385 404
 				goto skip_nexthop;
386 405
 
387 406
 			if (nh->rtnh_len > sizeof(*nh)) {
388
-				parse_rtattr(tb, RTA_MAX, RTNH_DATA(nh), nh->rtnh_len - sizeof(*nh));
407
+				parse_rtattr(tb, RTA_MAX, RTNH_DATA(nh),
408
+							 nh->rtnh_len - sizeof(*nh));
389 409
 				if (tb[RTA_GATEWAY]) {
390
-					memcpy(&via.data, RTA_DATA(tb[RTA_GATEWAY]), host_len/8);
391
-					via.family=r->rtm_family;
392
-					inet_setip(arg, (u_int *)&via.data, via.family);
410
+					memcpy(&via.data, RTA_DATA(tb[RTA_GATEWAY]),
411
+						   host_len / 8);
412
+					via.family = r->rtm_family;
413
+					inet_setip(arg, (u_int *) & via.data, via.family);
393 414
 
394 415
 					/* Copy the interface name */
395
-					strncpy((char *)arg+sizeof(inet_prefix),
396
-						ll_index_to_name(nh->rtnh_ifindex), IFNAMSIZ);
416
+					strncpy((char *) arg + sizeof(inet_prefix),
417
+							ll_index_to_name(nh->rtnh_ifindex), IFNAMSIZ);
397 418
 					break;
398 419
 				}
399 420
 			}
400
-skip_nexthop:
421
+		  skip_nexthop:
401 422
 			len -= NLMSG_ALIGN(nh->rtnh_len);
402 423
 			nh = RTNH_NEXT(nh);
403 424
 		}
@@ -406,9 +427,10 @@ skip_nexthop:
406 427
 
407 428
 	/* Copy the interface name */
408 429
 	if (tb[RTA_OIF] && filter.oifmask != -1)
409
-		strncpy((char *)arg+sizeof(inet_prefix),
410
-			ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF])), IFNAMSIZ);
411
-	
430
+		strncpy((char *) arg + sizeof(inet_prefix),
431
+				ll_index_to_name(*(int *) RTA_DATA(tb[RTA_OIF])),
432
+				IFNAMSIZ);
433
+
412 434
 	return 0;
413 435
 }
414 436
 
@@ -418,8 +440,9 @@ skip_nexthop:
418 440
  * address is stored in `dst' and its interface name in `dev_name' (which must
419 441
  * be IFNAMSIZ big).
420 442
  */
421
-int route_get_exact_prefix_dst(inet_prefix prefix, inet_prefix *dst, 
422
-		char *dev_name)
443
+int
444
+route_get_exact_prefix_dst(inet_prefix prefix, inet_prefix * dst,
445
+						   char *dev_name)
423 446
 {
424 447
 	int do_ipv6 = AF_UNSPEC;
425 448
 	struct rtnl_handle rth;
@@ -428,7 +451,7 @@ int route_get_exact_prefix_dst(inet_prefix prefix, inet_prefix *dst,
428 451
 	route_reset_filter();
429 452
 	filter.tb = RT_TABLE_MAIN;
430 453
 
431
-	filter.mdst=prefix;
454
+	filter.mdst = prefix;
432 455
 	filter.rdst = filter.mdst;
433 456
 
434 457
 	if (do_ipv6 == AF_UNSPEC && filter.tb)
@@ -440,7 +463,7 @@ int route_get_exact_prefix_dst(inet_prefix prefix, inet_prefix *dst,
440 463
 	ll_init_map(&rth);
441 464
 
442 465
 	if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) {
443
-		error(ERROR_MSG"Cannot send dump request"ERROR_POS);
466
+		error(ERROR_MSG "Cannot send dump request" ERROR_POS);
444 467
 		return -1;
445 468
 	}
446 469
 
@@ -449,40 +472,42 @@ int route_get_exact_prefix_dst(inet_prefix prefix, inet_prefix *dst,
449 472
 		debug(DBG_NORMAL, ERROR_MSG "Dump terminated" ERROR_POS);
450 473
 		return -1;
451 474
 	}
452
-	inet_copy(dst, (inet_prefix *)dst_data);
453
-	memcpy(dev_name, dst_data+sizeof(inet_prefix), IFNAMSIZ);
454
-	
475
+	inet_copy(dst, (inet_prefix *) dst_data);
476
+	memcpy(dev_name, dst_data + sizeof(inet_prefix), IFNAMSIZ);
477
+
455 478
 	rtnl_close(&rth);
456 479
 
457 480
 	return 0;
458 481
 }
459 482
 
460
-int route_flush_cache(int family)
483
+int
484
+route_flush_cache(int family)
461 485
 {
462 486
 	int len, err;
463 487
 	int flush_fd;
464
-	char ROUTE_FLUSH_SYSCTL[]="/proc/sys/net/ipvX/route/flush";
488
+	char ROUTE_FLUSH_SYSCTL[] = "/proc/sys/net/ipvX/route/flush";
465 489
 	char *buf = "-1";
466 490
 
467 491
 	len = strlen(buf);
468
-	if(family==AF_INET)
469
-		ROUTE_FLUSH_SYSCTL[17]='4';
470
-	else if(family==AF_INET6)
471
-		ROUTE_FLUSH_SYSCTL[17]='6';
492
+	if (family == AF_INET)
493
+		ROUTE_FLUSH_SYSCTL[17] = '4';
494
+	else if (family == AF_INET6)
495
+		ROUTE_FLUSH_SYSCTL[17] = '6';
472 496
 	else
473 497
 		return -1;
474 498
 
475
-	flush_fd=open(ROUTE_FLUSH_SYSCTL, O_WRONLY);
499
+	flush_fd = open(ROUTE_FLUSH_SYSCTL, O_WRONLY);
476 500
 	if (flush_fd < 0) {
477 501
 		debug(DBG_NORMAL, "Cannot open \"%s\"\n", ROUTE_FLUSH_SYSCTL);
478 502
 		return -1;
479 503
 	}
480
-		
481
-	if ((err=write (flush_fd, (void *)buf, len)) == 0) {
504
+
505
+	if ((err = write(flush_fd, (void *) buf, len)) == 0) {
482 506
 		debug(DBG_NORMAL, "Warning: Route Cache not flushed\n");
483 507
 		return -1;
484
-	} else if(err==-1) {
485
-		debug(DBG_NORMAL, "Cannot flush routing cache: %s\n", strerror(errno));
508
+	} else if (err == -1) {
509
+		debug(DBG_NORMAL, "Cannot flush routing cache: %s\n",
510
+			  strerror(errno));
486 511
 		return -1;
487 512
 	}
488 513
 	close(flush_fd);
@@ -490,39 +515,42 @@ int route_flush_cache(int family)
490 515
 	return 0;
491 516
 }
492 517
 
493
-int route_ip_forward(int family, int enable)
518
+int
519
+route_ip_forward(int family, int enable)
494 520
 {
495 521
 	int len, err;
496 522
 	int flush_fd;
497
-	char *ROUTE_FORWARD_SYSCTL="/proc/sys/net/ipv4/ip_forward";
498
-	char *ROUTE_FORWARD_SYSCTL_6="/proc/sys/net/ipv6/conf/all/forwarding";
523
+	char *ROUTE_FORWARD_SYSCTL = "/proc/sys/net/ipv4/ip_forward";
524
+	char *ROUTE_FORWARD_SYSCTL_6 =
525
+		"/proc/sys/net/ipv6/conf/all/forwarding";
499 526
 	char *sysctl_path, buf[2];
500 527
 
501
-	buf[0]='1';
502
-	buf[1]=0;
503
-	
528
+	buf[0] = '1';
529
+	buf[1] = 0;
530
+
504 531
 	len = strlen(buf);
505
-	if(family==AF_INET)
532
+	if (family == AF_INET)
506 533
 		sysctl_path = ROUTE_FORWARD_SYSCTL;
507
-	else if(family==AF_INET6)
534
+	else if (family == AF_INET6)
508 535
 		sysctl_path = ROUTE_FORWARD_SYSCTL_6;
509 536
 	else
510 537
 		return -1;
511 538
 
512
-	if(!enable)
513
-		buf[0]='0';
539
+	if (!enable)
540
+		buf[0] = '0';
514 541
 
515
-	flush_fd=open(sysctl_path, O_WRONLY);
542
+	flush_fd = open(sysctl_path, O_WRONLY);
516 543
 	if (flush_fd < 0) {
517 544
 		debug(DBG_NORMAL, "Cannot open \"%s\"\n", sysctl_path);
518 545
 		return -1;
519 546
 	}
520
-		
521
-	if ((err=write (flush_fd, (void *)buf, len)) == 0) {
547
+
548
+	if ((err = write(flush_fd, (void *) buf, len)) == 0) {
522 549
 		debug(DBG_NORMAL, "Warning: ip_forward setting changed\n");
523 550
 		return -1;
524
-	} else if(err==-1) {
525
-		debug(DBG_NORMAL, "Cannot change the ip_forward setting: %s\n", strerror(errno));
551
+	} else if (err == -1) {
552
+		debug(DBG_NORMAL, "Cannot change the ip_forward setting: %s\n",
553
+			  strerror(errno));
526 554
 		return -1;
527 555
 	}
528 556
 	close(flush_fd);
@@ -535,27 +563,28 @@ int route_ip_forward(int family, int enable)
535 563
  *
536 564
  * Modifies the /proc/sys/net/ipv4/conf/INTERFACE/rp_filter config file.
537 565
  */
538
-int route_rp_filter(int family, char *dev, int enable)
566
+int
567
+route_rp_filter(int family, char *dev, int enable)
539 568
 {
540
-	int len, err, ret=0;
569
+	int len, err, ret = 0;
541 570
 	int flush_fd;
542
-	
571
+
543 572
 	/* The path is /proc/sys/net/ipv4/conf/INTERFACE/rp_filter */
544
-	const char *RP_FILTER_SYSCTL_1="/proc/sys/net/ipv4/conf/";
545
-	const char *RP_FILTER_SYSCTL_1_IPV6="/proc/sys/net/ipv6/conf/";
546
-	const char *RP_FILTER_SYSCTL_2="/rp_filter";
547
-	char *final_path=0, buf[2];
573
+	const char *RP_FILTER_SYSCTL_1 = "/proc/sys/net/ipv4/conf/";
574
+	const char *RP_FILTER_SYSCTL_1_IPV6 = "/proc/sys/net/ipv6/conf/";
575
+	const char *RP_FILTER_SYSCTL_2 = "/rp_filter";
576
+	char *final_path = 0, buf[2];
548 577
 
549
-	buf[0]='1';
550
-	buf[1]=0;
578
+	buf[0] = '1';
579
+	buf[1] = 0;
551 580
 #define RP_FILTER_PATH_SZ (strlen(RP_FILTER_SYSCTL_1)+		   \
552 581
 			   strlen(RP_FILTER_SYSCTL_2)+IF_NAMESIZE+1)
553
-	final_path=xzalloc(RP_FILTER_PATH_SZ);
582
+	final_path = xzalloc(RP_FILTER_PATH_SZ);
554 583
 
555 584
 	len = strlen(buf);
556
-	if(family==AF_INET) {
585
+	if (family == AF_INET) {
557 586
 		strcpy(final_path, RP_FILTER_SYSCTL_1);
558
-	} else if(family==AF_INET6) {
587
+	} else if (family == AF_INET6) {
559 588
 		strcpy(final_path, RP_FILTER_SYSCTL_1_IPV6);
560 589
 	} else
561 590
 		ERROR_FINISH(ret, -1, finish);
@@ -563,26 +592,27 @@ int route_rp_filter(int family, char *dev, int enable)
563 592
 	strcat(final_path, dev);
564 593
 	strcat(final_path, RP_FILTER_SYSCTL_2);
565 594
 
566
-	if(!enable)
567
-		buf[0]='0';
595
+	if (!enable)
596
+		buf[0] = '0';
568 597
 
569
-	flush_fd=open(final_path, O_WRONLY);
598
+	flush_fd = open(final_path, O_WRONLY);
570 599
 	if (flush_fd < 0) {
571 600
 		debug(DBG_NORMAL, "Cannot open \"%s\"\n", final_path);
572 601
 		ERROR_FINISH(ret, -1, finish);
573 602
 	}
574
-		
575
-	if ((err=write (flush_fd, (void *)buf, len)) == 0) {
603
+
604
+	if ((err = write(flush_fd, (void *) buf, len)) == 0) {
576 605
 		debug(DBG_NORMAL, "Warning: rp_filter setting changed\n");
577 606
 		ERROR_FINISH(ret, -1, finish);
578
-	} else if(err==-1) {
579
-		debug(DBG_NORMAL, "Cannot change the rp_filter setting: %s\n", strerror(errno));
607
+	} else if (err == -1) {
608
+		debug(DBG_NORMAL, "Cannot change the rp_filter setting: %s\n",
609
+			  strerror(errno));
580 610
 		ERROR_FINISH(ret, -1, finish);
581 611
 	}
582 612
 	close(flush_fd);
583 613
 
584
-finish:
585
-	if(final_path)
614
+  finish:
615
+	if (final_path)
586 616
 		xfree(final_path);
587 617
 	return ret;
588 618
 }
@@ -591,12 +621,13 @@ finish:
591 621
  * route_rp_filter_all_dev: do route_rp_filter() for all the interfaces
592 622
  * present in the `ifs' array.
593 623
  */
594
-int route_rp_filter_all_dev(int family, interface *ifs, int ifs_n, int enable)
624
+int
625
+route_rp_filter_all_dev(int family, interface * ifs, int ifs_n, int enable)
595 626
 {
596
-	int i, ret=0;
627
+	int i, ret = 0;
597 628
 
598
-	for(i=0; i<ifs_n; i++)
599
-		ret+=route_rp_filter(family, ifs[i].dev_name, enable);
629
+	for (i = 0; i < ifs_n; i++)
630
+		ret += route_rp_filter(family, ifs[i].dev_name, enable);
600 631
 
601 632
 	return ret;
602 633
 }

+ 7
- 7
src/krnl_route.h View File

@@ -23,17 +23,16 @@
23 23
 
24 24
 #define RTPROT_NETSUKUKU	15
25 25
 
26
-struct nexthop 
27
-{
26
+struct nexthop {
28 27
 	inet_prefix gw;
29 28
 	char *dev;
30 29
 	u_char hops;
31 30
 };
32 31
 
33 32
 struct rt_request {
34
-	struct nlmsghdr 	nh;
35
-	struct rtmsg 		rt;
36
-	char   			buf[1024];
33
+	struct nlmsghdr nh;
34
+	struct rtmsg rt;
35
+	char buf[1024];
37 36
 };
38 37
 
39 38
 
@@ -49,6 +48,7 @@ int route_get_exact_prefix_dst(inet_prefix, inet_prefix *, char *);
49 48
 int route_flush_cache(int family);
50 49
 int route_ip_forward(int family, int enable);
51 50
 int route_rp_filter(int family, char *dev, int enable);
52
-int route_rp_filter_all_dev(int family, interface *ifs, int ifs_n, int enable);
51
+int route_rp_filter_all_dev(int family, interface * ifs, int ifs_n,
52
+							int enable);
53 53
 
54
-#endif /*KRNL_ROUTE_H*/
54
+#endif							/*KRNL_ROUTE_H */

+ 66
- 58
src/krnl_rule.c View File

@@ -28,45 +28,49 @@
28 28
 #include "krnl_rule.h"
29 29
 #include "common.h"
30 30
 
31
-int rule_exec(int rtm_cmd, inet_prefix *from, inet_prefix *to, char *dev, 
32
-		int prio, u_int fwmark, u_char table);
31
+int rule_exec(int rtm_cmd, inet_prefix * from, inet_prefix * to, char *dev,
32
+			  int prio, u_int fwmark, u_char table);
33 33
 
34
-int rule_add(inet_prefix *from, inet_prefix *to, char *dev, 
35
-		int prio, u_int fwmark, u_char table)
34
+int
35
+rule_add(inet_prefix * from, inet_prefix * to, char *dev,
36
+		 int prio, u_int fwmark, u_char table)
36 37
 {
37 38
 	return rule_exec(RTM_NEWRULE, from, to, dev, prio, fwmark, table);
38 39
 }
39 40
 
40
-int rule_del(inet_prefix *from, inet_prefix *to, char *dev, 
41
-		int prio, u_int fwmark, u_char table)
41
+int
42
+rule_del(inet_prefix * from, inet_prefix * to, char *dev,
43
+		 int prio, u_int fwmark, u_char table)
42 44
 {
43 45
 	return rule_exec(RTM_DELRULE, from, to, dev, prio, fwmark, table);
44 46
 }
45 47
 
46
-int rule_replace(inet_prefix *from, inet_prefix *to, char *dev,
47
-		int prio, u_int fwmark, u_char table)
48
+int
49
+rule_replace(inet_prefix * from, inet_prefix * to, char *dev,
50
+			 int prio, u_int fwmark, u_char table)
48 51
 {
49 52
 	rule_del(from, to, dev, prio, fwmark, table);
50
-	return	rule_add(from, to, dev, prio, fwmark, table);
53
+	return rule_add(from, to, dev, prio, fwmark, table);
51 54
 }
52 55
 
53 56
 /*
54 57
  * rule_exec:
55 58
  * `from' and `to' have to be in network order
56 59
  */
57
-int rule_exec(int rtm_cmd, inet_prefix *from, inet_prefix *to, char *dev, 
58
-		int prio, u_int fwmark, u_char table)
60
+int
61
+rule_exec(int rtm_cmd, inet_prefix * from, inet_prefix * to, char *dev,
62
+		  int prio, u_int fwmark, u_char table)
59 63
 {
60 64
 	struct {
61
-		struct nlmsghdr 	nh;
62
-		struct rtmsg 		rt;
63
-		char   			buf[1024];
65
+		struct nlmsghdr nh;
66
+		struct rtmsg rt;
67
+		char buf[1024];
64 68
 	} req;
65 69
 	struct rtnl_handle rth;
66 70
 
67 71
 	setzero(&req, sizeof(req));
68 72
 	table = !table ? RT_TABLE_MAIN : table;
69
-	
73
+
70 74
 	req.nh.nlmsg_type = rtm_cmd;
71 75
 	req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg));
72 76
 	req.nh.nlmsg_flags = NLM_F_REQUEST;
@@ -77,21 +81,21 @@ int rule_exec(int rtm_cmd, inet_prefix *from, inet_prefix *to, char *dev,
77 81
 	req.rt.rtm_table = table;
78 82
 
79 83
 	if (rtm_cmd == RTM_NEWRULE) {
80
-		req.nh.nlmsg_flags |= NLM_F_CREATE|NLM_F_EXCL;
84
+		req.nh.nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL;
81 85
 		req.rt.rtm_type = RTN_UNICAST;
82 86
 	}
83 87
 
84 88
 	if (from) {
85 89
 		req.rt.rtm_src_len = from->bits;
86 90
 		addattr_l(&req.nh, sizeof(req), RTA_SRC, &from->data, from->len);
87
-		req.rt.rtm_family=from->family;
91
+		req.rt.rtm_family = from->family;
88 92
 	}
89 93
 
90 94
 	if (to) {
91 95
 		req.rt.rtm_dst_len = to->bits;
92 96
 		addattr_l(&req.nh, sizeof(req), RTA_DST, &to->data, to->len);
93
-		req.rt.rtm_family=to->family;
94
-	} 
97
+		req.rt.rtm_family = to->family;
98
+	}
95 99
 
96 100
 	if (prio)
97 101
 		addattr32(&req.nh, sizeof(req), RTA_PRIORITY, prio);
@@ -100,8 +104,8 @@ int rule_exec(int rtm_cmd, inet_prefix *from, inet_prefix *to, char *dev,
100 104
 		addattr32(&req.nh, sizeof(req), RTA_PROTOINFO, fwmark);
101 105
 
102 106
 	if (dev) {
103
-		addattr_l(&req.nh, sizeof(req), RTA_IIF, dev, strlen(dev)+1);
104
-	} 
107
+		addattr_l(&req.nh, sizeof(req), RTA_IIF, dev, strlen(dev) + 1);
108
+	}
105 109
 
106 110
 	if (req.rt.rtm_family == AF_UNSPEC)
107 111
 		req.rt.rtm_family = AF_INET;
@@ -121,62 +125,66 @@ int rule_exec(int rtm_cmd, inet_prefix *from, inet_prefix *to, char *dev,
121 125
  * rule_flush_table_range_filter: rtnl_dump filter for
122 126
  * rule_flush_table_range() (see below)
123 127
  */
124
-int rule_flush_table_range_filter(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
128
+int
129
+rule_flush_table_range_filter(const struct sockaddr_nl *who,
130
+							  struct nlmsghdr *n, void *arg)
125 131
 {
126
-        struct rtnl_handle rth2;
127
-        struct rtmsg *r = NLMSG_DATA(n);
128
-        int len = n->nlmsg_len;
129
-        struct rtattr *tb[RTA_MAX+1];
130
-	u_int a=*(u_int *)arg;
131
-	u_int b=*((u_int *)arg+1);
132
+	struct rtnl_handle rth2;
133
+	struct rtmsg *r = NLMSG_DATA(n);
134
+	int len = n->nlmsg_len;
135
+	struct rtattr *tb[RTA_MAX + 1];
136
+	u_int a = *(u_int *) arg;
137
+	u_int b = *((u_int *) arg + 1);
132 138
 
133
-        len -= NLMSG_LENGTH(sizeof(*r));
134
-        if (len < 0)
135
-                return -1;
139
+	len -= NLMSG_LENGTH(sizeof(*r));
140
+	if (len < 0)
141
+		return -1;
136 142
 
137
-        parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
143
+	parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
138 144
 
139
-        if (tb[RTA_PRIORITY] && (r->rtm_table >= a && r->rtm_table <= b)) {
140
-                n->nlmsg_type = RTM_DELRULE;
141
-                n->nlmsg_flags = NLM_F_REQUEST;
145
+	if (tb[RTA_PRIORITY] && (r->rtm_table >= a && r->rtm_table <= b)) {
146
+		n->nlmsg_type = RTM_DELRULE;
147
+		n->nlmsg_flags = NLM_F_REQUEST;
142 148
 
143
-                if (rtnl_open(&rth2, 0) < 0)
144
-                        return -1;
149
+		if (rtnl_open(&rth2, 0) < 0)
150
+			return -1;
145 151
 
146
-                if (rtnl_talk(&rth2, n, 0, 0, NULL, NULL, NULL) < 0)
147
-                        return -2;
152
+		if (rtnl_talk(&rth2, n, 0, 0, NULL, NULL, NULL) < 0)
153
+			return -2;
148 154
 
149
-                rtnl_close(&rth2);
150
-        }
155
+		rtnl_close(&rth2);
156
+	}
151 157
 
152
-        return 0;
158
+	return 0;
153 159
 }
154 160
 
155 161
 /*
156 162
  * rule_flush_table_range: deletes all the rules which lookup the table X.
157 163
  * The table X is any table in the range of `a' <= X <= `b'.
158 164
  */
159
-int rule_flush_table_range(int family, int a, int b)
165
+int
166
+rule_flush_table_range(int family, int a, int b)
160 167
 {
161 168
 	struct rtnl_handle rth;
162 169
 	int arg[2];
163
-	
170
+
164 171
 	if (rtnl_open(&rth, 0) < 0)
165 172
 		return 1;
166 173
 
167
-        if (rtnl_wilddump_request(&rth, family, RTM_GETRULE) < 0) {
168
-                error("Cannot dump the routing rule table");
169
-                return -1;
170
-        }
171
-        
172
-	arg[0]=a;
173
-	arg[1]=b;
174
-        if (rtnl_dump_filter(&rth, rule_flush_table_range_filter, arg, NULL, NULL) < 0) {
175
-                error("Flush terminated");
176
-                return -1;
177
-        }
178
-	
174
+	if (rtnl_wilddump_request(&rth, family, RTM_GETRULE) < 0) {
175
+		error("Cannot dump the routing rule table");
176
+		return -1;
177
+	}
178
+
179
+	arg[0] = a;
180
+	arg[1] = b;
181
+	if (rtnl_dump_filter
182
+		(&rth, rule_flush_table_range_filter, arg, NULL, NULL) < 0) {
183
+		error("Flush terminated");
184
+		return -1;
185
+	}
186
+
179 187
 	rtnl_close(&rth);
180
-	
181
-        return 0;
188
+
189
+	return 0;
182 190
 }

+ 6
- 6
src/krnl_rule.h View File

@@ -16,10 +16,10 @@
16 16
  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 17
  */
18 18
 
19
-int rule_add(inet_prefix *from, inet_prefix *to, char *dev, 
20
-		int prio, u_int fwmark, u_char table);
21
-int rule_del(inet_prefix *from, inet_prefix *to, char *dev, 
22
-		int prio, u_int fwmark, u_char table);
23
-int rule_replace(inet_prefix *from, inet_prefix *to, char *dev,
24
-		int prio, u_int fwmark, u_char table);
19
+int rule_add(inet_prefix * from, inet_prefix * to, char *dev,
20
+			 int prio, u_int fwmark, u_char table);
21
+int rule_del(inet_prefix * from, inet_prefix * to, char *dev,
22
+			 int prio, u_int fwmark, u_char table);
23
+int rule_replace(inet_prefix * from, inet_prefix * to, char *dev,
24
+				 int prio, u_int fwmark, u_char table);
25 25
 int rule_flush_table_range(int family, int a, int b);

+ 2
- 4
src/libiptc/ipt_conntrack.h View File

@@ -45,8 +45,7 @@
45 45
 #define IPT_CONNTRACK_EXPIRES	0x80
46 46
 
47 47
 /* This is exposed to userspace, so remains frozen in time. */
48
-struct ip_conntrack_old_tuple
49
-{
48
+struct ip_conntrack_old_tuple {
50 49
 	struct {
51 50
 		u_int32_t ip;
52 51
 		union {
@@ -65,8 +64,7 @@ struct ip_conntrack_old_tuple
65 64
 	} dst;
66 65
 };
67 66
 
68
-struct ipt_conntrack_info
69
-{
67
+struct ipt_conntrack_info {
70 68
 	unsigned int statemask, statusmask;
71 69
 
72 70
 	struct ip_conntrack_old_tuple tuple[IP_CT_DIR_MAX];

+ 50
- 47
src/libiptc/iptables.h View File

@@ -12,28 +12,25 @@
12 12
 #define IPPROTO_SCTP 132
13 13
 #endif
14 14
 
15
-#ifndef IPT_SO_GET_REVISION_MATCH /* Old kernel source. */
15
+#ifndef IPT_SO_GET_REVISION_MATCH	/* Old kernel source. */
16 16
 #define IPT_SO_GET_REVISION_MATCH	(IPT_BASE_CTL + 2)
17 17
 #define IPT_SO_GET_REVISION_TARGET	(IPT_BASE_CTL + 3)
18 18
 
19
-struct ipt_get_revision
20
-{
21
-	char name[IPT_FUNCTION_MAXNAMELEN-1];
19
+struct ipt_get_revision {
20
+	char name[IPT_FUNCTION_MAXNAMELEN - 1];
22 21
 
23 22
 	u_int8_t revision;
24 23
 };
25
-#endif /* IPT_SO_GET_REVISION_MATCH   Old kernel source */
24
+#endif							/* IPT_SO_GET_REVISION_MATCH   Old kernel source */
26 25
 
27
-struct iptables_rule_match
28
-{
26
+struct iptables_rule_match {
29 27
 	struct iptables_rule_match *next;
30 28
 
31 29
 	struct iptables_match *match;
32 30
 };
33 31
 
34 32
 /* Include file for additions: new matches and targets. */
35
-struct iptables_match
36
-{
33
+struct iptables_match {
37 34
 	struct iptables_match *next;
38 35
 
39 36
 	ipt_chainlabel name;
@@ -50,28 +47,27 @@ struct iptables_match
50 47
 	size_t userspacesize;
51 48
 
52 49
 	/* Function which prints out usage message. */
53
-	void (*help)(void);
50
+	void (*help) (void);
54 51
 
55 52
 	/* Initialize the match. */
56
-	void (*init)(struct ipt_entry_match *m, unsigned int *nfcache);
53
+	void (*init) (struct ipt_entry_match * m, unsigned int *nfcache);
57 54
 
58 55
 	/* Function which parses command options; returns true if it
59
-           ate an option */
60
-	int (*parse)(int c, char **argv, int invert, unsigned int *flags,
61
-		     const struct ipt_entry *entry,
62
-		     unsigned int *nfcache,
63
-		     struct ipt_entry_match **match);
56
+	   ate an option */
57
+	int (*parse) (int c, char **argv, int invert, unsigned int *flags,
58
+				  const struct ipt_entry * entry,
59
+				  unsigned int *nfcache, struct ipt_entry_match ** match);
64 60
 
65 61
 	/* Final check; exit if not ok. */
66
-	void (*final_check)(unsigned int flags);
62
+	void (*final_check) (unsigned int flags);
67 63
 
68 64
 	/* Prints out the match iff non-NULL: put space at end */
69
-	void (*print)(const struct ipt_ip *ip,
70
-		      const struct ipt_entry_match *match, int numeric);
65
+	void (*print) (const struct ipt_ip * ip,
66
+				   const struct ipt_entry_match * match, int numeric);
71 67
 
72 68
 	/* Saves the match info in parsable form to stdout. */
73
-	void (*save)(const struct ipt_ip *ip,
74
-		     const struct ipt_entry_match *match);
69
+	void (*save) (const struct ipt_ip * ip,
70
+				  const struct ipt_entry_match * match);
75 71
 
76 72
 	/* Pointer to list of extra command-line options */
77 73
 	const struct option *extra_opts;
@@ -81,12 +77,11 @@ struct iptables_match
81 77
 	struct ipt_entry_match *m;
82 78
 	unsigned int mflags;
83 79
 #ifdef NO_SHARED_LIBS
84
-	unsigned int loaded; /* simulate loading so options are merged properly */
80
+	unsigned int loaded;		/* simulate loading so options are merged properly */
85 81
 #endif
86 82
 };
87 83
 
88
-struct iptables_target
89
-{
84
+struct iptables_target {
90 85
 	struct iptables_target *next;
91 86
 
92 87
 	ipt_chainlabel name;
@@ -103,27 +98,27 @@ struct iptables_target
103 98
 	size_t userspacesize;
104 99
 
105 100
 	/* Function which prints out usage message. */
106
-	void (*help)(void);
101
+	void (*help) (void);
107 102
 
108 103
 	/* Initialize the target. */
109
-	void (*init)(struct ipt_entry_target *t, unsigned int *nfcache);
104
+	void (*init) (struct ipt_entry_target * t, unsigned int *nfcache);
110 105
 
111 106
 	/* Function which parses command options; returns true if it
112
-           ate an option */
113
-	int (*parse)(int c, char **argv, int invert, unsigned int *flags,
114
-		     const struct ipt_entry *entry,
115
-		     struct ipt_entry_target **target);
107
+	   ate an option */
108
+	int (*parse) (int c, char **argv, int invert, unsigned int *flags,
109
+				  const struct ipt_entry * entry,
110
+				  struct ipt_entry_target ** target);
116 111
 
117 112
 	/* Final check; exit if not ok. */
118
-	void (*final_check)(unsigned int flags);
113
+	void (*final_check) (unsigned int flags);
119 114
 
120 115
 	/* Prints out the target iff non-NULL: put space at end */
121
-	void (*print)(const struct ipt_ip *ip,
122
-		      const struct ipt_entry_target *target, int numeric);
116
+	void (*print) (const struct ipt_ip * ip,
117
+				   const struct ipt_entry_target * target, int numeric);
123 118
 
124 119
 	/* Saves the targinfo in parsable form to stdout. */
125
-	void (*save)(const struct ipt_ip *ip,
126
-		     const struct ipt_entry_target *target);
120
+	void (*save) (const struct ipt_ip * ip,
121
+				  const struct ipt_entry_target * target);
127 122
 
128 123
 	/* Pointer to list of extra command-line options */
129 124
 	struct option *extra_opts;
@@ -134,7 +129,7 @@ struct iptables_target
134 129
 	unsigned int tflags;
135 130
 	unsigned int used;
136 131
 #ifdef NO_SHARED_LIBS
137
-	unsigned int loaded; /* simulate loading so options are merged properly */
132
+	unsigned int loaded;		/* simulate loading so options are merged properly */
138 133
 #endif
139 134
 };
140 135
 
@@ -149,13 +144,16 @@ extern char *addr_to_dotted(const struct in_addr *addrp);
149 144
 extern char *addr_to_anyname(const struct in_addr *addr);
150 145
 extern char *mask_to_dotted(const struct in_addr *mask);
151 146
 
152
-extern void parse_hostnetworkmask(const char *name, struct in_addr **addrpp,
153
-                      struct in_addr *maskp, unsigned int *naddrs);
147
+extern void parse_hostnetworkmask(const char *name,
148
+								  struct in_addr **addrpp,
149
+								  struct in_addr *maskp,
150
+								  unsigned int *naddrs);
154 151
 extern u_int16_t parse_protocol(const char *s);
155
-extern void parse_interface(const char *arg, char *vianame, unsigned char *mask);
152
+extern void parse_interface(const char *arg, char *vianame,
153
+							unsigned char *mask);
156 154
 
157 155
 extern int do_command(int argc, char *argv[], char **table,
158
-		      iptc_handle_t *handle);
156
+					  iptc_handle_t * handle);
159 157
 /* Keeping track of external matches and targets: linked lists.  */
160 158
 extern struct iptables_match *iptables_matches;
161 159
 extern struct iptables_target *iptables_targets;
@@ -166,15 +164,20 @@ enum ipt_tryload {
166 164
 	LOAD_MUST_SUCCEED
167 165
 };
168 166
 
169
-extern struct iptables_target *find_target(const char *name, enum ipt_tryload);
170
-extern struct iptables_match *find_match(const char *name, enum ipt_tryload, struct iptables_rule_match **match);
167
+extern struct iptables_target *find_target(const char *name,
168
+										   enum ipt_tryload);
169
+extern struct iptables_match *find_match(const char *name,
170
+										 enum ipt_tryload,
171
+										 struct iptables_rule_match
172
+										 **match);
171 173
 
172 174
 extern int delete_chain(const ipt_chainlabel chain, int verbose,
173
-			iptc_handle_t *handle);
174
-extern int flush_entries(const ipt_chainlabel chain, int verbose, 
175
-			iptc_handle_t *handle);
176
-extern int for_each_chain(int (*fn)(const ipt_chainlabel, int, iptc_handle_t *),
177
-		int verbose, int builtinstoo, iptc_handle_t *handle);
175
+						iptc_handle_t * handle);
176
+extern int flush_entries(const ipt_chainlabel chain, int verbose,
177
+						 iptc_handle_t * handle);
178
+extern int
179
+for_each_chain(int (*fn) (const ipt_chainlabel, int, iptc_handle_t *),
180
+			   int verbose, int builtinstoo, iptc_handle_t * handle);
178 181
 
179 182
 /* kernel revision handling */
180 183
 extern int kernel_version;

+ 71
- 77
src/libiptc/libip4tc.c View File

@@ -175,37 +175,37 @@ dump_entry(STRUCT_ENTRY *e, const TC_HANDLE_T handle)
175 175
 }*/
176 176
 
177 177
 static unsigned char *
178
-is_same(const STRUCT_ENTRY *a, const STRUCT_ENTRY *b, unsigned char *matchmask)
178
+is_same(const STRUCT_ENTRY * a, const STRUCT_ENTRY * b,
179
+		unsigned char *matchmask)
179 180
 {
180 181
 	unsigned int i;
181 182
 	unsigned char *mptr;
182 183
 
183 184
 	/* Always compare head structures: ignore mask here. */
184 185
 	if (a->ip.src.s_addr != b->ip.src.s_addr
185
-	    || a->ip.dst.s_addr != b->ip.dst.s_addr
186
-	    || a->ip.smsk.s_addr != b->ip.smsk.s_addr
187
-	    || a->ip.dmsk.s_addr != b->ip.dmsk.s_addr
188
-	    || a->ip.proto != b->ip.proto
189
-	    || a->ip.flags != b->ip.flags
190
-	    || a->ip.invflags != b->ip.invflags)
186
+		|| a->ip.dst.s_addr != b->ip.dst.s_addr
187
+		|| a->ip.smsk.s_addr != b->ip.smsk.s_addr
188
+		|| a->ip.dmsk.s_addr != b->ip.dmsk.s_addr
189
+		|| a->ip.proto != b->ip.proto
190
+		|| a->ip.flags != b->ip.flags || a->ip.invflags != b->ip.invflags)
191 191
 		return NULL;
192 192
 
193 193
 	for (i = 0; i < IFNAMSIZ; i++) {
194 194
 		if (a->ip.iniface_mask[i] != b->ip.iniface_mask[i])
195 195
 			return NULL;
196 196
 		if ((a->ip.iniface[i] & a->ip.iniface_mask[i])
197
-		    != (b->ip.iniface[i] & b->ip.iniface_mask[i]))
197
+			!= (b->ip.iniface[i] & b->ip.iniface_mask[i]))
198 198
 			return NULL;
199 199
 		if (a->ip.outiface_mask[i] != b->ip.outiface_mask[i])
200 200
 			return NULL;
201 201
 		if ((a->ip.outiface[i] & a->ip.outiface_mask[i])
202
-		    != (b->ip.outiface[i] & b->ip.outiface_mask[i]))
202
+			!= (b->ip.outiface[i] & b->ip.outiface_mask[i]))
203 203
 			return NULL;
204 204
 	}
205 205
 
206 206
 	if (a->nfcache != b->nfcache
207
-	    || a->target_offset != b->target_offset
208
-	    || a->next_offset != b->next_offset)
207
+		|| a->target_offset != b->target_offset
208
+		|| a->next_offset != b->next_offset)
209 209
 		return NULL;
210 210
 
211 211
 	mptr = matchmask + sizeof(STRUCT_ENTRY);
@@ -223,15 +223,15 @@ unconditional(const struct ipt_ip *ip)
223 223
 {
224 224
 	unsigned int i;
225 225
 
226
-	for (i = 0; i < sizeof(*ip)/sizeof(u_int32_t); i++)
227
-		if (((u_int32_t *)ip)[i])
226
+	for (i = 0; i < sizeof(*ip) / sizeof(u_int32_t); i++)
227
+		if (((u_int32_t *) ip)[i])
228 228
 			return 0;
229 229
 
230 230
 	return 1;
231 231
 }
232 232
 
233 233
 static inline int
234
-check_match(const STRUCT_ENTRY_MATCH *m, unsigned int *off)
234
+check_match(const STRUCT_ENTRY_MATCH * m, unsigned int *off)
235 235
 {
236 236
 	assert(m->u.match_size >= sizeof(STRUCT_ENTRY_MATCH));
237 237
 	assert(ALIGN(m->u.match_size) == m->u.match_size);
@@ -241,23 +241,22 @@ check_match(const STRUCT_ENTRY_MATCH *m, unsigned int *off)
241 241
 }
242 242
 
243 243
 static inline int
244
-check_entry(const STRUCT_ENTRY *e, unsigned int *i, unsigned int *off,
245
-	    unsigned int user_offset, int *was_return,
246
-	    TC_HANDLE_T h)
244
+check_entry(const STRUCT_ENTRY * e, unsigned int *i, unsigned int *off,
245
+			unsigned int user_offset, int *was_return, TC_HANDLE_T h)
247 246
 {
248 247
 	unsigned int toff;
249 248
 	STRUCT_STANDARD_TARGET *t;
250 249
 
251 250
 	assert(e->target_offset >= sizeof(STRUCT_ENTRY));
252 251
 	assert(e->next_offset >= e->target_offset
253
-	       + sizeof(STRUCT_ENTRY_TARGET));
252
+		   + sizeof(STRUCT_ENTRY_TARGET));
254 253
 	toff = sizeof(STRUCT_ENTRY);
255 254
 	IPT_MATCH_ITERATE(e, check_match, &toff);
256 255
 
257 256
 	assert(toff == e->target_offset);
258 257
 
259 258
 	t = (STRUCT_STANDARD_TARGET *)
260
-		GET_TARGET((STRUCT_ENTRY *)e);
259
+		GET_TARGET((STRUCT_ENTRY *) e);
261 260
 	/* next_offset will have to be multiple of entry alignment. */
262 261
 	assert(e->next_offset == ALIGN(e->next_offset));
263 262
 	assert(e->target_offset == ALIGN(e->target_offset));
@@ -266,47 +265,45 @@ check_entry(const STRUCT_ENTRY *e, unsigned int *i, unsigned int *off,
266 265
 
267 266
 	if (strcmp(t->target.u.user.name, STANDARD_TARGET) == 0) {
268 267
 		assert(t->target.u.target_size
269
-		       == ALIGN(sizeof(STRUCT_STANDARD_TARGET)));
268
+			   == ALIGN(sizeof(STRUCT_STANDARD_TARGET)));
270 269
 
271
-		assert(t->verdict == -NF_DROP-1
272
-		       || t->verdict == -NF_ACCEPT-1
273
-		       || t->verdict == RETURN
274
-		       || t->verdict < (int)h->entries->size);
270
+		assert(t->verdict == -NF_DROP - 1
271
+			   || t->verdict == -NF_ACCEPT - 1
272
+			   || t->verdict == RETURN
273
+			   || t->verdict < (int) h->entries->size);
275 274
 
276 275
 		if (t->verdict >= 0) {
277 276
 			STRUCT_ENTRY *te = get_entry(h, t->verdict);
278 277
 			int idx;
279 278
 
280 279
 			idx = iptcb_entry2index(h, te);
281
-			assert(strcmp(GET_TARGET(te)->u.user.name,
282
-				      IPT_ERROR_TARGET)
283
-			       != 0);
280
+			assert(strcmp(GET_TARGET(te)->u.user.name, IPT_ERROR_TARGET)
281
+				   != 0);
284 282
 			assert(te != e);
285 283
 
286 284
 			/* Prior node must be error node, or this node. */
287
-			assert(t->verdict == iptcb_entry2offset(h, e)+e->next_offset
288
-			       || strcmp(GET_TARGET(index2entry(h, idx-1))
289
-					 ->u.user.name, IPT_ERROR_TARGET)
290
-			       == 0);
285
+			assert(t->verdict == iptcb_entry2offset(h, e) + e->next_offset
286
+				   || strcmp(GET_TARGET(index2entry(h, idx - 1))
287
+							 ->u.user.name, IPT_ERROR_TARGET)
288
+				   == 0);
291 289
 		}
292 290
 
293
-		if (t->verdict == RETURN
294
-		    && unconditional(&e->ip)
295
-		    && e->target_offset == sizeof(*e))
291
+		if (t->verdict == RETURN && unconditional(&e->ip)
292
+			&& e->target_offset == sizeof(*e))
296 293
 			*was_return = 1;
297 294
 		else
298 295
 			*was_return = 0;
299 296
 	} else if (strcmp(t->target.u.user.name, IPT_ERROR_TARGET) == 0) {
300 297
 		assert(t->target.u.target_size
301
-		       == ALIGN(sizeof(struct ipt_error_target)));
298
+			   == ALIGN(sizeof(struct ipt_error_target)));
302 299
 
303 300
 		/* If this is in user area, previous must have been return */
304 301
 		if (*off > user_offset)
305 302
 			assert(*was_return);
306 303
 
307 304
 		*was_return = 0;
308
-	}
309
-	else *was_return = 0;
305
+	} else
306
+		*was_return = 0;
310 307
 
311 308
 	if (*off == user_offset)
312 309
 		assert(strcmp(t->target.u.user.name, IPT_ERROR_TARGET) == 0);
@@ -322,15 +319,14 @@ static void
322 319
 do_check(TC_HANDLE_T h, unsigned int line)
323 320
 {
324 321
 	unsigned int i, n;
325
-	unsigned int user_offset; /* Offset of first user chain */
322
+	unsigned int user_offset;	/* Offset of first user chain */
326 323
 	int was_return;
327 324
 
328 325
 	assert(h->changed == 0 || h->changed == 1);
329 326
 	if (strcmp(h->info.name, "filter") == 0) {
330 327
 		assert(h->info.valid_hooks
331
-		       == (1 << NF_IP_LOCAL_IN
332
-			   | 1 << NF_IP_FORWARD
333
-			   | 1 << NF_IP_LOCAL_OUT));
328
+			   == (1 << NF_IP_LOCAL_IN
329
+				   | 1 << NF_IP_FORWARD | 1 << NF_IP_LOCAL_OUT));
334 330
 
335 331
 		/* Hooks should be first three */
336 332
 		assert(h->info.hook_entry[NF_IP_LOCAL_IN] == 0);
@@ -346,14 +342,13 @@ do_check(TC_HANDLE_T h, unsigned int line)
346 342
 		user_offset = h->info.hook_entry[NF_IP_LOCAL_OUT];
347 343
 	} else if (strcmp(h->info.name, "nat") == 0) {
348 344
 		assert((h->info.valid_hooks
349
-		        == (1 << NF_IP_PRE_ROUTING
350
-			    | 1 << NF_IP_POST_ROUTING
351
-			    | 1 << NF_IP_LOCAL_OUT)) ||
352
-		       (h->info.valid_hooks
353
-			== (1 << NF_IP_PRE_ROUTING
354
-			    | 1 << NF_IP_LOCAL_IN
355
-			    | 1 << NF_IP_POST_ROUTING
356
-			    | 1 << NF_IP_LOCAL_OUT)));
345
+				== (1 << NF_IP_PRE_ROUTING
346
+					| 1 << NF_IP_POST_ROUTING
347
+					| 1 << NF_IP_LOCAL_OUT)) ||
348
+			   (h->info.valid_hooks
349
+				== (1 << NF_IP_PRE_ROUTING
350
+					| 1 << NF_IP_LOCAL_IN
351
+					| 1 << NF_IP_POST_ROUTING | 1 << NF_IP_LOCAL_OUT)));
357 352
 
358 353
 		assert(h->info.hook_entry[NF_IP_PRE_ROUTING] == 0);
359 354
 
@@ -379,14 +374,13 @@ do_check(TC_HANDLE_T h, unsigned int line)
379 374
 		 * two mangle hooks, linux >= 2.4.18-pre6 has five mangle hooks
380 375
 		 * */
381 376
 		assert((h->info.valid_hooks
382
-			== (1 << NF_IP_PRE_ROUTING
383
-			    | 1 << NF_IP_LOCAL_OUT)) || 
384
-		       (h->info.valid_hooks
385
-			== (1 << NF_IP_PRE_ROUTING
386
-			    | 1 << NF_IP_LOCAL_IN
387
-			    | 1 << NF_IP_FORWARD
388
-			    | 1 << NF_IP_LOCAL_OUT
389
-			    | 1 << NF_IP_POST_ROUTING)));
377
+				== (1 << NF_IP_PRE_ROUTING
378
+					| 1 << NF_IP_LOCAL_OUT)) ||
379
+			   (h->info.valid_hooks
380
+				== (1 << NF_IP_PRE_ROUTING
381
+					| 1 << NF_IP_LOCAL_IN
382
+					| 1 << NF_IP_FORWARD
383
+					| 1 << NF_IP_LOCAL_OUT | 1 << NF_IP_POST_ROUTING)));
390 384
 
391 385
 		/* Hooks should be first five */
392 386
 		assert(h->info.hook_entry[NF_IP_PRE_ROUTING] == 0);
@@ -417,8 +411,7 @@ do_check(TC_HANDLE_T h, unsigned int line)
417 411
 		}
418 412
 	} else if (strcmp(h->info.name, "raw") == 0) {
419 413
 		assert(h->info.valid_hooks
420
-		       == (1 << NF_IP_PRE_ROUTING
421
-			   | 1 << NF_IP_LOCAL_OUT));
414
+			   == (1 << NF_IP_PRE_ROUTING | 1 << NF_IP_LOCAL_OUT));
422 415
 
423 416
 		/* Hooks should be first three */
424 417
 		assert(h->info.hook_entry[NF_IP_PRE_ROUTING] == 0);
@@ -447,7 +440,7 @@ do_check(TC_HANDLE_T h, unsigned int line)
447 440
 	user_offset += get_entry(h, user_offset)->next_offset;
448 441
 
449 442
 	/* Overflows should be end of entry chains, and unconditional
450
-           policy nodes. */
443
+	   policy nodes. */
451 444
 	for (i = 0; i < NUMHOOKS; i++) {
452 445
 		STRUCT_ENTRY *e;
453 446
 		STRUCT_STANDARD_TARGET *t;
@@ -455,47 +448,48 @@ do_check(TC_HANDLE_T h, unsigned int line)
455 448
 		if (!(h->info.valid_hooks & (1 << i)))
456 449
 			continue;
457 450
 		assert(h->info.underflow[i]
458
-		       == get_chain_end(h, h->info.hook_entry[i]));
451
+			   == get_chain_end(h, h->info.hook_entry[i]));
459 452
 
460 453
 		e = get_entry(h, get_chain_end(h, h->info.hook_entry[i]));
461 454
 		assert(unconditional(&e->ip));
462 455
 		assert(e->target_offset == sizeof(*e));
463
-		t = (STRUCT_STANDARD_TARGET *)GET_TARGET(e);
456
+		t = (STRUCT_STANDARD_TARGET *) GET_TARGET(e);
464 457
 		assert(t->target.u.target_size == ALIGN(sizeof(*t)));
465 458
 		assert(e->next_offset == sizeof(*e) + ALIGN(sizeof(*t)));
466 459
 
467
-		assert(strcmp(t->target.u.user.name, STANDARD_TARGET)==0);
468
-		assert(t->verdict == -NF_DROP-1 || t->verdict == -NF_ACCEPT-1);
460
+		assert(strcmp(t->target.u.user.name, STANDARD_TARGET) == 0);
461
+		assert(t->verdict == -NF_DROP - 1 || t->verdict == -NF_ACCEPT - 1);
469 462
 
470 463
 		/* Hooks and underflows must be valid entries */
471 464
 		entry2index(h, get_entry(h, h->info.hook_entry[i]));
472 465
 		entry2index(h, get_entry(h, h->info.underflow[i]));
473 466
 	}
474 467
 
475
-	assert(h->info.size
476
-	       >= h->info.num_entries * (sizeof(STRUCT_ENTRY)
477
-					 +sizeof(STRUCT_STANDARD_TARGET)));
468
+	assert(h->info.size >= h->info.num_entries * (sizeof(STRUCT_ENTRY)
469
+												  +
470
+												  sizeof
471
+												  (STRUCT_STANDARD_TARGET)));
478 472
 
479
-	assert(h->entries.size
480
-	       >= (h->new_number
481
-		   * (sizeof(STRUCT_ENTRY)
482
-		      + sizeof(STRUCT_STANDARD_TARGET))));
473
+	assert(h->entries.size >= (h->new_number * (sizeof(STRUCT_ENTRY)
474
+												+
475
+												sizeof
476
+												(STRUCT_STANDARD_TARGET))));
483 477
 	assert(strcmp(h->info.name, h->entries.name) == 0);
484 478
 
485
-	i = 0; n = 0;
479
+	i = 0;
480
+	n = 0;
486 481
 	was_return = 0;
487 482
 	/* Check all the entries. */
488 483
 	ENTRY_ITERATE(h->entries.entrytable, h->entries.size,
489
-		      check_entry, &i, &n, user_offset, &was_return, h);
484
+				  check_entry, &i, &n, user_offset, &was_return, h);
490 485
 
491 486
 	assert(i == h->new_number);
492 487
 	assert(n == h->entries.size);
493 488
 
494 489
 	/* Final entry must be error node */
495
-	assert(strcmp(GET_TARGET(index2entry(h, h->new_number-1))
496
-		      ->u.user.name,
497
-		      ERROR_TARGET) == 0);
490
+	assert(strcmp(GET_TARGET(index2entry(h, h->new_number - 1))
491
+				  ->u.user.name, ERROR_TARGET) == 0);
498 492
 }
499
-#endif /*IPTC_DEBUG*/
493
+#endif							/*IPTC_DEBUG */
500 494
 
501 495
 #endif

+ 333
- 349
src/libiptc/libiptc.c
File diff suppressed because it is too large
View File


+ 68
- 73
src/libiptc/libiptc.h View File

@@ -13,7 +13,7 @@
13 13
 #include <netinet/udp.h>
14 14
 #include <net/if.h>
15 15
 #include <sys/types.h>
16
-#else /* libc5 */
16
+#else							/* libc5 */
17 17
 #include <sys/socket.h>
18 18
 #include <linux/ip.h>
19 19
 #include <linux/in.h>
@@ -40,7 +40,7 @@ extern "C" {
40 40
 
41 41
 #define IPT_ALIGN(s) (((s) + ((IPT_MIN_ALIGN)-1)) & ~((IPT_MIN_ALIGN)-1))
42 42
 
43
-typedef char ipt_chainlabel[32];
43
+	typedef char ipt_chainlabel[32];
44 44
 
45 45
 #define IPTC_LABEL_ACCEPT  "ACCEPT"
46 46
 #define IPTC_LABEL_DROP    "DROP"
@@ -48,141 +48,136 @@ typedef char ipt_chainlabel[32];
48 48
 #define IPTC_LABEL_RETURN  "RETURN"
49 49
 
50 50
 /* Transparent handle type. */
51
-typedef struct iptc_handle *iptc_handle_t;
51
+	typedef struct iptc_handle *iptc_handle_t;
52 52
 
53 53
 /* Does this chain exist? */
54
-int iptc_is_chain(const char *chain, const iptc_handle_t handle);
54
+	int iptc_is_chain(const char *chain, const iptc_handle_t handle);
55 55
 
56 56
 /* Take a snapshot of the rules.  Returns NULL on error. */
57
-iptc_handle_t iptc_init(const char *tablename);
57
+	iptc_handle_t iptc_init(const char *tablename);
58 58
 
59 59
 /* Cleanup after iptc_init(). */
60
-void iptc_free(iptc_handle_t *h);
60
+	void iptc_free(iptc_handle_t * h);
61 61
 
62 62
 /* Iterator functions to run through the chains.  Returns NULL at end. */
63
-const char *iptc_first_chain(iptc_handle_t *handle);
64
-const char *iptc_next_chain(iptc_handle_t *handle);
63
+	const char *iptc_first_chain(iptc_handle_t * handle);
64
+	const char *iptc_next_chain(iptc_handle_t * handle);
65 65
 
66 66
 /* Get first rule in the given chain: NULL for empty chain. */
67
-const struct ipt_entry *iptc_first_rule(const char *chain,
68
-					iptc_handle_t *handle);
67
+	const struct ipt_entry *iptc_first_rule(const char *chain,
68
+											iptc_handle_t * handle);
69 69
 
70 70
 /* Returns NULL when rules run out. */
71
-const struct ipt_entry *iptc_next_rule(const struct ipt_entry *prev,
72
-				       iptc_handle_t *handle);
71
+	const struct ipt_entry *iptc_next_rule(const struct ipt_entry *prev,
72
+										   iptc_handle_t * handle);
73 73
 
74 74
 /* Returns a pointer to the target name of this entry. */
75
-const char *iptc_get_target(const struct ipt_entry *e,
76
-			    iptc_handle_t *handle);
75
+	const char *iptc_get_target(const struct ipt_entry *e,
76
+								iptc_handle_t * handle);
77 77
 
78 78
 /* Is this a built-in chain? */
79
-int iptc_builtin(const char *chain, const iptc_handle_t handle);
79
+	int iptc_builtin(const char *chain, const iptc_handle_t handle);
80 80
 
81 81
 /* Get the policy of a given built-in chain */
82
-const char *iptc_get_policy(const char *chain,
83
-			    struct ipt_counters *counter,
84
-			    iptc_handle_t *handle);
82
+	const char *iptc_get_policy(const char *chain,
83
+								struct ipt_counters *counter,
84
+								iptc_handle_t * handle);
85 85
 
86 86
 /* These functions return TRUE for OK or 0 and set errno.  If errno ==
87 87
    0, it means there was a version error (ie. upgrade libiptc). */
88 88
 /* Rule numbers start at 1 for the first rule. */
89 89
 
90 90
 /* Insert the entry `e' in chain `chain' into position `rulenum'. */
91
-int iptc_insert_entry(const ipt_chainlabel chain,
92
-		      const struct ipt_entry *e,
93
-		      unsigned int rulenum,
94
-		      iptc_handle_t *handle);
91
+	int iptc_insert_entry(const ipt_chainlabel chain,
92
+						  const struct ipt_entry *e,
93
+						  unsigned int rulenum, iptc_handle_t * handle);
95 94
 
96 95
 /* Atomically replace rule `rulenum' in `chain' with `e'. */
97
-int iptc_replace_entry(const ipt_chainlabel chain,
98
-		       const struct ipt_entry *e,
99
-		       unsigned int rulenum,
100
-		       iptc_handle_t *handle);
96
+	int iptc_replace_entry(const ipt_chainlabel chain,
97
+						   const struct ipt_entry *e,
98
+						   unsigned int rulenum, iptc_handle_t * handle);
101 99
 
102 100
 /* Append entry `e' to chain `chain'.  Equivalent to insert with
103 101
    rulenum = length of chain. */
104
-int iptc_append_entry(const ipt_chainlabel chain,
105
-		      const struct ipt_entry *e,
106
-		      iptc_handle_t *handle);
102
+	int iptc_append_entry(const ipt_chainlabel chain,
103
+						  const struct ipt_entry *e,
104
+						  iptc_handle_t * handle);
107 105
 
108 106
 /* Delete the first rule in `chain' which matches `e', subject to
109 107
    matchmask (array of length == origfw) */
110
-int iptc_delete_entry(const ipt_chainlabel chain,
111
-		      const struct ipt_entry *origfw,
112
-		      unsigned char *matchmask,
113
-		      iptc_handle_t *handle);
108
+	int iptc_delete_entry(const ipt_chainlabel chain,
109
+						  const struct ipt_entry *origfw,
110
+						  unsigned char *matchmask,
111
+						  iptc_handle_t * handle);
114 112
 
115 113
 /* Delete the rule in position `rulenum' in `chain'. */
116
-int iptc_delete_num_entry(const ipt_chainlabel chain,
117
-			  unsigned int rulenum,
118
-			  iptc_handle_t *handle);
114
+	int iptc_delete_num_entry(const ipt_chainlabel chain,
115
+							  unsigned int rulenum,
116
+							  iptc_handle_t * handle);
119 117
 
120 118
 /* Check the packet `e' on chain `chain'.  Returns the verdict, or
121 119
    NULL and sets errno. */
122
-const char *iptc_check_packet(const ipt_chainlabel chain,
123
-			      struct ipt_entry *entry,
124
-			      iptc_handle_t *handle);
120
+	const char *iptc_check_packet(const ipt_chainlabel chain,
121
+								  struct ipt_entry *entry,
122
+								  iptc_handle_t * handle);
125 123
 
126 124
 /* Flushes the entries in the given chain (ie. empties chain). */
127
-int iptc_flush_entries(const ipt_chainlabel chain,
128
-		       iptc_handle_t *handle);
125
+	int iptc_flush_entries(const ipt_chainlabel chain,
126
+						   iptc_handle_t * handle);
129 127
 
130 128
 /* Zeroes the counters in a chain. */
131
-int iptc_zero_entries(const ipt_chainlabel chain,
132
-		      iptc_handle_t *handle);
129
+	int iptc_zero_entries(const ipt_chainlabel chain,
130
+						  iptc_handle_t * handle);
133 131
 
134 132
 /* Creates a new chain. */
135
-int iptc_create_chain(const ipt_chainlabel chain,
136
-		      iptc_handle_t *handle);
133
+	int iptc_create_chain(const ipt_chainlabel chain,
134
+						  iptc_handle_t * handle);
137 135
 
138 136
 /* Deletes a chain. */
139
-int iptc_delete_chain(const ipt_chainlabel chain,
140
-		      iptc_handle_t *handle);
137
+	int iptc_delete_chain(const ipt_chainlabel chain,
138
+						  iptc_handle_t * handle);
141 139
 
142 140
 /* Renames a chain. */
143
-int iptc_rename_chain(const ipt_chainlabel oldname,
144
-		      const ipt_chainlabel newname,
145
-		      iptc_handle_t *handle);
141
+	int iptc_rename_chain(const ipt_chainlabel oldname,
142
+						  const ipt_chainlabel newname,
143
+						  iptc_handle_t * handle);
146 144
 
147 145
 /* Sets the policy on a built-in chain. */
148
-int iptc_set_policy(const ipt_chainlabel chain,
149
-		    const ipt_chainlabel policy,
150
-		    struct ipt_counters *counters,
151
-		    iptc_handle_t *handle);
146
+	int iptc_set_policy(const ipt_chainlabel chain,
147
+						const ipt_chainlabel policy,
148
+						struct ipt_counters *counters,
149
+						iptc_handle_t * handle);
152 150
 
153 151
 /* Get the number of references to this chain */
154
-int iptc_get_references(unsigned int *ref,
155
-			const ipt_chainlabel chain,
156
-			iptc_handle_t *handle);
152
+	int iptc_get_references(unsigned int *ref,
153
+							const ipt_chainlabel chain,
154
+							iptc_handle_t * handle);
157 155
 
158 156
 /* read packet and byte counters for a specific rule */
159
-struct ipt_counters *iptc_read_counter(const ipt_chainlabel chain,
160
-				       unsigned int rulenum,
161
-				       iptc_handle_t *handle);
157
+	struct ipt_counters *iptc_read_counter(const ipt_chainlabel chain,
158
+										   unsigned int rulenum,
159
+										   iptc_handle_t * handle);
162 160
 
163 161
 /* zero packet and byte counters for a specific rule */
164
-int iptc_zero_counter(const ipt_chainlabel chain,
165
-		      unsigned int rulenum,
166
-		      iptc_handle_t *handle);
162
+	int iptc_zero_counter(const ipt_chainlabel chain,
163
+						  unsigned int rulenum, iptc_handle_t * handle);
167 164
 
168 165
 /* set packet and byte counters for a specific rule */
169
-int iptc_set_counter(const ipt_chainlabel chain,
170
-		     unsigned int rulenum,
171
-		     struct ipt_counters *counters,
172
-		     iptc_handle_t *handle);
166
+	int iptc_set_counter(const ipt_chainlabel chain,
167
+						 unsigned int rulenum,
168
+						 struct ipt_counters *counters,
169
+						 iptc_handle_t * handle);
173 170
 
174 171
 /* Makes the actual changes. */
175
-int iptc_commit(iptc_handle_t *handle);
172
+	int iptc_commit(iptc_handle_t * handle);
176 173
 
177 174
 /* Get raw socket. */
178
-int iptc_get_raw_socket();
175
+	int iptc_get_raw_socket();
179 176
 
180 177
 /* Translates errno numbers into more human-readable form than strerror. */
181
-const char *iptc_strerror(int err);
178
+	const char *iptc_strerror(int err);
182 179
 
183 180
 #ifdef __cplusplus
184 181
 }
185 182
 #endif
186
-
187
-
188
-#endif /* _LIBIPTC_H */
183
+#endif							/* _LIBIPTC_H */

+ 63
- 44
src/libiptc/linux_list.h View File

@@ -69,9 +69,9 @@ struct list_head {
69 69
  * This is only for internal list manipulation where we know
70 70
  * the prev/next entries already!
71 71
  */
72
-static inline void __list_add(struct list_head *new,
73
-			      struct list_head *prev,
74
-			      struct list_head *next)
72
+static inline void
73
+__list_add(struct list_head *new,
74
+		   struct list_head *prev, struct list_head *next)
75 75
 {
76 76
 	next->prev = new;
77 77
 	new->next = next;
@@ -87,7 +87,8 @@ static inline void __list_add(struct list_head *new,
87 87
  * Insert a new entry after the specified head.
88 88
  * This is good for implementing stacks.
89 89
  */
90
-static inline void list_add(struct list_head *new, struct list_head *head)
90
+static inline void
91
+list_add(struct list_head *new, struct list_head *head)
91 92
 {
92 93
 	__list_add(new, head, head->next);
93 94
 }
@@ -100,7 +101,8 @@ static inline void list_add(struct list_head *new, struct list_head *head)
100 101
  * Insert a new entry before the specified head.
101 102
  * This is useful for implementing queues.
102 103
  */
103
-static inline void list_add_tail(struct list_head *new, struct list_head *head)
104
+static inline void
105
+list_add_tail(struct list_head *new, struct list_head *head)
104 106
 {
105 107
 	__list_add(new, head->prev, head);
106 108
 }
@@ -111,8 +113,9 @@ static inline void list_add_tail(struct list_head *new, struct list_head *head)
111 113
  * This is only for internal list manipulation where we know
112 114
  * the prev/next entries already!
113 115
  */
114
-static inline void __list_add_rcu(struct list_head * new,
115
-		struct list_head * prev, struct list_head * next)
116
+static inline void
117
+__list_add_rcu(struct list_head *new,
118
+			   struct list_head *prev, struct list_head *next)
116 119
 {
117 120
 	new->next = next;
118 121
 	new->prev = prev;
@@ -137,7 +140,8 @@ static inline void __list_add_rcu(struct list_head * new,
137 140
  * the _rcu list-traversal primitives, such as
138 141
  * list_for_each_entry_rcu().
139 142
  */
140
-static inline void list_add_rcu(struct list_head *new, struct list_head *head)
143
+static inline void
144
+list_add_rcu(struct list_head *new, struct list_head *head)
141 145
 {
142 146
 	__list_add_rcu(new, head, head->next);
143 147
 }
@@ -158,8 +162,8 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
158 162
  * the _rcu list-traversal primitives, such as
159 163
  * list_for_each_entry_rcu().
160 164
  */
161
-static inline void list_add_tail_rcu(struct list_head *new,
162
-					struct list_head *head)
165
+static inline void
166
+list_add_tail_rcu(struct list_head *new, struct list_head *head)
163 167
 {
164 168
 	__list_add_rcu(new, head->prev, head);
165 169
 }
@@ -171,7 +175,8 @@ static inline void list_add_tail_rcu(struct list_head *new,
171 175
  * This is only for internal list manipulation where we know
172 176
  * the prev/next entries already!
173 177
  */
174
-static inline void __list_del(struct list_head * prev, struct list_head * next)
178
+static inline void
179
+__list_del(struct list_head *prev, struct list_head *next)
175 180
 {
176 181
 	next->prev = prev;
177 182
 	prev->next = next;
@@ -183,7 +188,8 @@ static inline void __list_del(struct list_head * prev, struct list_head * next)
183 188
  * Note: list_empty on entry does not return true after this, the entry is
184 189
  * in an undefined state.
185 190
  */
186
-static inline void list_del(struct list_head *entry)
191
+static inline void
192
+list_del(struct list_head *entry)
187 193
 {
188 194
 	__list_del(entry->prev, entry->next);
189 195
 	entry->next = LIST_POISON1;
@@ -214,7 +220,8 @@ static inline void list_del(struct list_head *entry)
214 220
  * or call_rcu() must be used to defer freeing until an RCU
215 221
  * grace period has elapsed.
216 222
  */
217
-static inline void list_del_rcu(struct list_head *entry)
223
+static inline void
224
+list_del_rcu(struct list_head *entry)
218 225
 {
219 226
 	__list_del(entry->prev, entry->next);
220 227
 	entry->prev = LIST_POISON2;
@@ -224,7 +231,8 @@ static inline void list_del_rcu(struct list_head *entry)
224 231
  * list_del_init - deletes entry from list and reinitialize it.
225 232
  * @entry: the element to delete from the list.
226 233
  */
227
-static inline void list_del_init(struct list_head *entry)
234
+static inline void
235
+list_del_init(struct list_head *entry)
228 236
 {
229 237
 	__list_del(entry->prev, entry->next);
230 238
 	INIT_LIST_HEAD(entry);
@@ -235,10 +243,11 @@ static inline void list_del_init(struct list_head *entry)
235 243
  * @list: the entry to move
236 244
  * @head: the head that will precede our entry
237 245
  */
238
-static inline void list_move(struct list_head *list, struct list_head *head)
246
+static inline void
247
+list_move(struct list_head *list, struct list_head *head)
239 248
 {
240
-        __list_del(list->prev, list->next);
241
-        list_add(list, head);
249
+	__list_del(list->prev, list->next);
250
+	list_add(list, head);
242 251
 }
243 252
 
244 253
 /**
@@ -246,18 +255,19 @@ static inline void list_move(struct list_head *list, struct list_head *head)
246 255
  * @list: the entry to move
247 256
  * @head: the head that will follow our entry
248 257
  */
249
-static inline void list_move_tail(struct list_head *list,
250
-				  struct list_head *head)
258
+static inline void
259
+list_move_tail(struct list_head *list, struct list_head *head)
251 260
 {
252
-        __list_del(list->prev, list->next);
253
-        list_add_tail(list, head);
261
+	__list_del(list->prev, list->next);
262
+	list_add_tail(list, head);
254 263
 }
255 264
 
256 265
 /**
257 266
  * list_empty - tests whether a list is empty
258 267
  * @head: the list to test.
259 268
  */
260
-static inline int list_empty(const struct list_head *head)
269
+static inline int
270
+list_empty(const struct list_head *head)
261 271
 {
262 272
 	return head->next == head;
263 273
 }
@@ -274,14 +284,15 @@ static inline int list_empty(const struct list_head *head)
274 284
  *
275 285
  * @head: the list to test.
276 286
  */
277
-static inline int list_empty_careful(const struct list_head *head)
287
+static inline int
288
+list_empty_careful(const struct list_head *head)
278 289
 {
279 290
 	struct list_head *next = head->next;
280 291
 	return (next == head) && (next == head->prev);
281 292
 }
282 293
 
283
-static inline void __list_splice(struct list_head *list,
284
-				 struct list_head *head)
294
+static inline void
295
+__list_splice(struct list_head *list, struct list_head *head)
285 296
 {
286 297
 	struct list_head *first = list->next;
287 298
 	struct list_head *last = list->prev;
@@ -299,7 +310,8 @@ static inline void __list_splice(struct list_head *list,
299 310
  * @list: the new list to add.
300 311
  * @head: the place to add it in the first list.
301 312
  */
302
-static inline void list_splice(struct list_head *list, struct list_head *head)
313
+static inline void
314
+list_splice(struct list_head *list, struct list_head *head)
303 315
 {
304 316
 	if (!list_empty(list))
305 317
 		__list_splice(list, head);
@@ -312,8 +324,8 @@ static inline void list_splice(struct list_head *list, struct list_head *head)
312 324
  *
313 325
  * The list at @list is reinitialised
314 326
  */
315
-static inline void list_splice_init(struct list_head *list,
316
-				    struct list_head *head)
327
+static inline void
328
+list_splice_init(struct list_head *list, struct list_head *head)
317 329
 {
318 330
 	if (!list_empty(list)) {
319 331
 		__list_splice(list, head);
@@ -519,17 +531,20 @@ struct hlist_node {
519 531
 #define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
520 532
 #define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL)
521 533
 
522
-static inline int hlist_unhashed(const struct hlist_node *h)
534
+static inline int
535
+hlist_unhashed(const struct hlist_node *h)
523 536
 {
524 537
 	return !h->pprev;
525 538
 }
526 539
 
527
-static inline int hlist_empty(const struct hlist_head *h)
540
+static inline int
541
+hlist_empty(const struct hlist_head *h)
528 542
 {
529 543
 	return !h->first;
530 544
 }
531 545
 
532
-static inline void __hlist_del(struct hlist_node *n)
546
+static inline void
547
+__hlist_del(struct hlist_node *n)
533 548
 {
534 549
 	struct hlist_node *next = n->next;
535 550
 	struct hlist_node **pprev = n->pprev;
@@ -538,7 +553,8 @@ static inline void __hlist_del(struct hlist_node *n)
538 553
 		next->pprev = pprev;
539 554
 }
540 555
 
541
-static inline void hlist_del(struct hlist_node *n)
556
+static inline void
557
+hlist_del(struct hlist_node *n)
542 558
 {
543 559
 	__hlist_del(n);
544 560
 	n->next = LIST_POISON1;
@@ -564,15 +580,17 @@ static inline void hlist_del(struct hlist_node *n)
564 580
  * the _rcu list-traversal primitives, such as
565 581
  * hlist_for_each_entry().
566 582
  */
567
-static inline void hlist_del_rcu(struct hlist_node *n)
583
+static inline void
584
+hlist_del_rcu(struct hlist_node *n)
568 585
 {
569 586
 	__hlist_del(n);
570 587
 	n->pprev = LIST_POISON2;
571 588
 }
572 589
 
573
-static inline void hlist_del_init(struct hlist_node *n)
590
+static inline void
591
+hlist_del_init(struct hlist_node *n)
574 592
 {
575
-	if (n->pprev)  {
593
+	if (n->pprev) {
576 594
 		__hlist_del(n);
577 595
 		INIT_HLIST_NODE(n);
578 596
 	}
@@ -580,7 +598,8 @@ static inline void hlist_del_init(struct hlist_node *n)
580 598
 
581 599
 #define hlist_del_rcu_init hlist_del_init
582 600
 
583
-static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
601
+static inline void
602
+hlist_add_head(struct hlist_node *n, struct hlist_head *h)
584 603
 {
585 604
 	struct hlist_node *first = h->first;
586 605
 	n->next = first;
@@ -610,8 +629,8 @@ static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
610 629
  *
611 630
  * OK, so why don't we have an hlist_for_each_entry_rcu()???
612 631
  */
613
-static inline void hlist_add_head_rcu(struct hlist_node *n,
614
-					struct hlist_head *h)
632
+static inline void
633
+hlist_add_head_rcu(struct hlist_node *n, struct hlist_head *h)
615 634
 {
616 635
 	struct hlist_node *first = h->first;
617 636
 	n->next = first;
@@ -623,8 +642,8 @@ static inline void hlist_add_head_rcu(struct hlist_node *n,
623 642
 }
624 643
 
625 644
 /* next must be != NULL */
626
-static inline void hlist_add_before(struct hlist_node *n,
627
-					struct hlist_node *next)
645
+static inline void
646
+hlist_add_before(struct hlist_node *n, struct hlist_node *next)
628 647
 {
629 648
 	n->pprev = next->pprev;
630 649
 	n->next = next;
@@ -632,15 +651,15 @@ static inline void hlist_add_before(struct hlist_node *n,
632 651
 	*(n->pprev) = n;
633 652
 }
634 653
 
635
-static inline void hlist_add_after(struct hlist_node *n,
636
-					struct hlist_node *next)
654
+static inline void
655
+hlist_add_after(struct hlist_node *n, struct hlist_node *next)
637 656
 {
638 657
 	next->next = n->next;
639 658
 	n->next = next;
640 659
 	next->pprev = &n->next;
641 660
 
642
-	if(next->next)
643
-		next->next->pprev  = &next->next;
661
+	if (next->next)
662
+		next->next->pprev = &next->next;
644 663
 }
645 664
 
646 665
 #define hlist_entry(ptr, type, member) container_of(ptr,type,member)

+ 97
- 76
src/libnetlink.c View File

@@ -31,12 +31,15 @@
31 31
 #include "libnetlink.h"
32 32
 #include "log.h"
33 33
 
34
-void rtnl_close(struct rtnl_handle *rth)
34
+void
35
+rtnl_close(struct rtnl_handle *rth)
35 36
 {
36 37
 	close(rth->fd);
37 38
 }
38 39
 
39
-int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, int protocol)
40
+int
41
+rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions,
42
+				  int protocol)
40 43
 {
41 44
 	socklen_t addr_len;
42 45
 	int sndbuf = 32768;
@@ -50,12 +53,14 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, int proto
50 53
 		return -1;
51 54
 	}
52 55
 
53
-	if (setsockopt(rth->fd,SOL_SOCKET,SO_SNDBUF,&sndbuf,sizeof(sndbuf)) < 0) {
56
+	if (setsockopt(rth->fd, SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf))
57
+		< 0) {
54 58
 		perror("SO_SNDBUF");
55 59
 		return -1;
56 60
 	}
57 61
 
58
-	if (setsockopt(rth->fd,SOL_SOCKET,SO_RCVBUF,&rcvbuf,sizeof(rcvbuf)) < 0) {
62
+	if (setsockopt(rth->fd, SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf))
63
+		< 0) {
59 64
 		perror("SO_RCVBUF");
60 65
 		return -1;
61 66
 	}
@@ -64,12 +69,14 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, int proto
64 69
 	rth->local.nl_family = AF_NETLINK;
65 70
 	rth->local.nl_groups = subscriptions;
66 71
 
67
-	if (bind(rth->fd, (struct sockaddr*)&rth->local, sizeof(rth->local)) < 0) {
72
+	if (bind(rth->fd, (struct sockaddr *) &rth->local, sizeof(rth->local))
73
+		< 0) {
68 74
 		perror("Cannot bind netlink socket");
69 75
 		return -1;
70 76
 	}
71 77
 	addr_len = sizeof(rth->local);
72
-	if (getsockname(rth->fd, (struct sockaddr*)&rth->local, &addr_len) < 0) {
78
+	if (getsockname(rth->fd, (struct sockaddr *) &rth->local, &addr_len) <
79
+		0) {
73 80
 		perror("Cannot getsockname");
74 81
 		return -1;
75 82
 	}
@@ -85,12 +92,14 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, int proto
85 92
 	return 0;
86 93
 }
87 94
 
88
-int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
95
+int
96
+rtnl_open(struct rtnl_handle *rth, unsigned subscriptions)
89 97
 {
90 98
 	return rtnl_open_byproto(rth, subscriptions, NETLINK_ROUTE);
91 99
 }
92 100
 
93
-int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
101
+int
102
+rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
94 103
 {
95 104
 	struct {
96 105
 		struct nlmsghdr nlh;
@@ -104,36 +113,40 @@ int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type)
104 113
 	memset(&req, 0, sizeof(req));
105 114
 	req.nlh.nlmsg_len = sizeof(req);
106 115
 	req.nlh.nlmsg_type = type;
107
-	req.nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
116
+	req.nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
108 117
 	req.nlh.nlmsg_pid = 0;
109 118
 	req.nlh.nlmsg_seq = rth->dump = ++rth->seq;
110 119
 	req.g.rtgen_family = family;
111 120
 
112
-	return sendto(rth->fd, (void*)&req, sizeof(req), 0,
113
-			(struct sockaddr*)&nladdr, sizeof(nladdr));
121
+	return sendto(rth->fd, (void *) &req, sizeof(req), 0,
122
+				  (struct sockaddr *) &nladdr, sizeof(nladdr));
114 123
 }
115 124
 
116
-int rtnl_send(struct rtnl_handle *rth, const char *buf, int len)
125
+int
126
+rtnl_send(struct rtnl_handle *rth, const char *buf, int len)
117 127
 {
118 128
 	struct sockaddr_nl nladdr;
119 129
 
120 130
 	memset(&nladdr, 0, sizeof(nladdr));
121 131
 	nladdr.nl_family = AF_NETLINK;
122 132
 
123
-	return sendto(rth->fd, buf, len, 0, (struct sockaddr*)&nladdr, sizeof(nladdr));
133
+	return sendto(rth->fd, buf, len, 0, (struct sockaddr *) &nladdr,
134
+				  sizeof(nladdr));
124 135
 }
125 136
 
126
-int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
137
+int
138
+rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
127 139
 {
128 140
 	struct nlmsghdr nlh;
129 141
 	struct sockaddr_nl nladdr;
130 142
 	struct iovec iov[2] = {
131
-		{ .iov_base = &nlh, .iov_len = sizeof(nlh) },
132
-		{ .iov_base = req, .iov_len = len }
143
+		{.iov_base = &nlh,.iov_len = sizeof(nlh)}
144
+		,
145
+		{.iov_base = req,.iov_len = len}
133 146
 	};
134 147
 	struct msghdr msg = {
135 148
 		.msg_name = &nladdr,
136
-		.msg_namelen = 	sizeof(nladdr),
149
+		.msg_namelen = sizeof(nladdr),
137 150
 		.msg_iov = iov,
138 151
 		.msg_iovlen = 2,
139 152
 	};
@@ -143,18 +156,17 @@ int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len)
143 156
 
144 157
 	nlh.nlmsg_len = NLMSG_LENGTH(len);
145 158
 	nlh.nlmsg_type = type;
146
-	nlh.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
159
+	nlh.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
147 160
 	nlh.nlmsg_pid = 0;
148 161
 	nlh.nlmsg_seq = rth->dump = ++rth->seq;
149 162
 
150 163
 	return sendmsg(rth->fd, &msg, 0);
151 164
 }
152 165
 
153
-int rtnl_dump_filter(struct rtnl_handle *rth,
154
-		     rtnl_filter_t filter,
155
-		     void *arg1,
156
-		     rtnl_filter_t junk,
157
-		     void *arg2)
166
+int
167
+rtnl_dump_filter(struct rtnl_handle *rth,
168
+				 rtnl_filter_t filter,
169
+				 void *arg1, rtnl_filter_t junk, void *arg2)
158 170
 {
159 171
 	struct sockaddr_nl nladdr;
160 172
 	struct iovec iov;
@@ -180,19 +192,19 @@ int rtnl_dump_filter(struct rtnl_handle *rth,
180 192
 			perror("OVERRUN");
181 193
 			continue;
182 194
 		}
183
-		
195
+
184 196
 		if (status == 0) {
185 197
 			error("EOF on netlink\n");
186 198
 			return -1;
187 199
 		}
188 200
 
189
-		h = (struct nlmsghdr*)buf;
201
+		h = (struct nlmsghdr *) buf;
190 202
 		while (NLMSG_OK(h, status)) {
191 203
 			int err;
192 204
 
193 205
 			if (nladdr.nl_pid != 0 ||
194
-			    h->nlmsg_pid != rth->local.nl_pid ||
195
-			    h->nlmsg_seq != rth->dump) {
206
+				h->nlmsg_pid != rth->local.nl_pid ||
207
+				h->nlmsg_seq != rth->dump) {
196 208
 				if (junk) {
197 209
 					err = junk(&nladdr, h, arg2);
198 210
 					if (err < 0)
@@ -204,7 +216,7 @@ int rtnl_dump_filter(struct rtnl_handle *rth,
204 216
 			if (h->nlmsg_type == NLMSG_DONE)
205 217
 				return 0;
206 218
 			if (h->nlmsg_type == NLMSG_ERROR) {
207
-				struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
219
+				struct nlmsgerr *err = (struct nlmsgerr *) NLMSG_DATA(h);
208 220
 				if (h->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
209 221
 					error("ERROR truncated\n");
210 222
 				} else {
@@ -217,7 +229,7 @@ int rtnl_dump_filter(struct rtnl_handle *rth,
217 229
 			if (err < 0)
218 230
 				return err;
219 231
 
220
-skip_it:
232
+		  skip_it:
221 233
 			h = NLMSG_NEXT(h, status);
222 234
 		}
223 235
 		if (msg.msg_flags & MSG_TRUNC) {
@@ -230,17 +242,17 @@ skip_it:
230 242
 	}
231 243
 }
232 244
 
233
-int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
234
-	      unsigned groups, struct nlmsghdr *answer,
235
-	      rtnl_filter_t junk,
236
-	      void *jarg)
245
+int
246
+rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
247
+		  unsigned groups, struct nlmsghdr *answer,
248
+		  rtnl_filter_t junk, void *jarg)
237 249
 {
238 250
 	int status;
239 251
 	unsigned seq;
240 252
 	struct nlmsghdr *h;
241 253
 	struct sockaddr_nl nladdr;
242 254
 	struct iovec iov = {
243
-		.iov_base = (void*) n,
255
+		.iov_base = (void *) n,
244 256
 		.iov_len = n->nlmsg_len
245 257
 	};
246 258
 	struct msghdr msg = {
@@ -249,7 +261,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
249 261
 		.msg_iov = &iov,
250 262
 		.msg_iovlen = 1,
251 263
 	};
252
-	char   buf[16384];
264
+	char buf[16384];
253 265
 
254 266
 	memset(&nladdr, 0, sizeof(nladdr));
255 267
 	nladdr.nl_family = AF_NETLINK;
@@ -268,7 +280,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
268 280
 		return -1;
269 281
 	}
270 282
 
271
-	memset(buf,0,sizeof(buf));
283
+	memset(buf, 0, sizeof(buf));
272 284
 
273 285
 	iov.iov_base = buf;
274 286
 
@@ -289,12 +301,12 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
289 301
 		if (msg.msg_namelen != sizeof(nladdr)) {
290 302
 			fatal("sender address length == %d\n", msg.msg_namelen);
291 303
 		}
292
-		for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) {
304
+		for (h = (struct nlmsghdr *) buf; status >= sizeof(*h);) {
293 305
 			int err;
294 306
 			int len = h->nlmsg_len;
295 307
 			int l = len - sizeof(*h);
296 308
 
297
-			if (l<0 || len>status) {
309
+			if (l < 0 || len > status) {
298 310
 				if (msg.msg_flags & MSG_TRUNC) {
299 311
 					error("Truncated message\n");
300 312
 					return -1;
@@ -303,8 +315,8 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
303 315
 			}
304 316
 
305 317
 			if (nladdr.nl_pid != peer ||
306
-			    h->nlmsg_pid != rtnl->local.nl_pid ||
307
-			    h->nlmsg_seq != seq) {
318
+				h->nlmsg_pid != rtnl->local.nl_pid ||
319
+				h->nlmsg_seq != seq) {
308 320
 				if (junk) {
309 321
 					err = junk(&nladdr, h, jarg);
310 322
 					if (err < 0)
@@ -314,7 +326,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
314 326
 			}
315 327
 
316 328
 			if (h->nlmsg_type == NLMSG_ERROR) {
317
-				struct nlmsgerr *err = (struct nlmsgerr*)NLMSG_DATA(h);
329
+				struct nlmsgerr *err = (struct nlmsgerr *) NLMSG_DATA(h);
318 330
 				if (l < sizeof(struct nlmsgerr)) {
319 331
 					error("ERROR truncated\n");
320 332
 				} else {
@@ -324,7 +336,8 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
324 336
 							memcpy(answer, h, h->nlmsg_len);
325 337
 						return 0;
326 338
 					}
327
-					error("RTNETLINK answers (%d): %s", err->error, strerror(errno));
339
+					error("RTNETLINK answers (%d): %s", err->error,
340
+						  strerror(errno));
328 341
 				}
329 342
 				return -1;
330 343
 			}
@@ -336,7 +349,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
336 349
 			error("Unexpected reply!!!\n");
337 350
 
338 351
 			status -= NLMSG_ALIGN(len);
339
-			h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
352
+			h = (struct nlmsghdr *) ((char *) h + NLMSG_ALIGN(len));
340 353
 		}
341 354
 		if (msg.msg_flags & MSG_TRUNC) {
342 355
 			error("Message truncated\n");
@@ -347,9 +360,8 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
347 360
 	}
348 361
 }
349 362
 
350
-int rtnl_listen(struct rtnl_handle *rtnl,
351
-		rtnl_filter_t handler,
352
-		void *jarg)
363
+int
364
+rtnl_listen(struct rtnl_handle *rtnl, rtnl_filter_t handler, void *jarg)
353 365
 {
354 366
 	int status;
355 367
 	struct nlmsghdr *h;
@@ -361,7 +373,7 @@ int rtnl_listen(struct rtnl_handle *rtnl,
361 373
 		.msg_iov = &iov,
362 374
 		.msg_iovlen = 1,
363 375
 	};
364
-	char   buf[8192];
376
+	char buf[8192];
365 377
 
366 378
 	memset(&nladdr, 0, sizeof(nladdr));
367 379
 	nladdr.nl_family = AF_NETLINK;
@@ -386,12 +398,12 @@ int rtnl_listen(struct rtnl_handle *rtnl,
386 398
 		if (msg.msg_namelen != sizeof(nladdr)) {
387 399
 			fatal("Sender address length == %d\n", msg.msg_namelen);
388 400
 		}
389
-		for (h = (struct nlmsghdr*)buf; status >= sizeof(*h); ) {
401
+		for (h = (struct nlmsghdr *) buf; status >= sizeof(*h);) {
390 402
 			int err;
391 403
 			int len = h->nlmsg_len;
392 404
 			int l = len - sizeof(*h);
393 405
 
394
-			if (l<0 || len>status) {
406
+			if (l < 0 || len > status) {
395 407
 				if (msg.msg_flags & MSG_TRUNC) {
396 408
 					error("Truncated message\n");
397 409
 					return -1;
@@ -404,7 +416,7 @@ int rtnl_listen(struct rtnl_handle *rtnl,
404 416
 				return err;
405 417
 
406 418
 			status -= NLMSG_ALIGN(len);
407
-			h = (struct nlmsghdr*)((char*)h + NLMSG_ALIGN(len));
419
+			h = (struct nlmsghdr *) ((char *) h + NLMSG_ALIGN(len));
408 420
 		}
409 421
 		if (msg.msg_flags & MSG_TRUNC) {
410 422
 			error("Message truncated\n");
@@ -416,13 +428,13 @@ int rtnl_listen(struct rtnl_handle *rtnl,
416 428
 	}
417 429
 }
418 430
 
419
-int rtnl_from_file(FILE *rtnl, rtnl_filter_t handler,
420
-		   void *jarg)
431
+int
432
+rtnl_from_file(FILE * rtnl, rtnl_filter_t handler, void *jarg)
421 433
 {
422 434
 	int status;
423 435
 	struct sockaddr_nl nladdr;
424
-	char   buf[8192];
425
-	struct nlmsghdr *h = (void*)buf;
436
+	char buf[8192];
437
+	struct nlmsghdr *h = (void *) buf;
426 438
 
427 439
 	memset(&nladdr, 0, sizeof(nladdr));
428 440
 	nladdr.nl_family = AF_NETLINK;
@@ -445,12 +457,11 @@ int rtnl_from_file(FILE *rtnl, rtnl_filter_t handler,
445 457
 			return 0;
446 458
 
447 459
 		len = h->nlmsg_len;
448
-		type= h->nlmsg_type;
460
+		type = h->nlmsg_type;
449 461
 		l = len - sizeof(*h);
450 462
 
451
-		if (l<0 || len>sizeof(buf)) {
452
-			error("!!!malformed message: len=%d @%lu\n",
453
-				len, ftell(rtnl));
463
+		if (l < 0 || len > sizeof(buf)) {
464
+			error("!!!malformed message: len=%d @%lu\n", len, ftell(rtnl));
454 465
 			return -1;
455 466
 		}
456 467
 
@@ -471,12 +482,13 @@ int rtnl_from_file(FILE *rtnl, rtnl_filter_t handler,
471 482
 	}
472 483
 }
473 484
 
474
-int addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data)
485
+int
486
+addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data)
475 487
 {
476 488
 	int len = RTA_LENGTH(4);
477 489
 	struct rtattr *rta;
478 490
 	if (NLMSG_ALIGN(n->nlmsg_len) + len > maxlen) {
479
-		error("addattr32: Error! max allowed bound %d exceeded\n",maxlen);
491
+		error("addattr32: Error! max allowed bound %d exceeded\n", maxlen);
480 492
 		return -1;
481 493
 	}
482 494
 	rta = NLMSG_TAIL(n);
@@ -487,14 +499,15 @@ int addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data)
487 499
 	return 0;
488 500
 }
489 501
 
490
-int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data,
491
-	      int alen)
502
+int
503
+addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data,
504
+		  int alen)
492 505
 {
493 506
 	int len = RTA_LENGTH(alen);
494 507
 	struct rtattr *rta;
495 508
 
496 509
 	if (NLMSG_ALIGN(n->nlmsg_len) + RTA_ALIGN(len) > maxlen) {
497
-		error("addattr_l ERROR: message exceeded bound of %d\n",maxlen);
510
+		error("addattr_l ERROR: message exceeded bound of %d\n", maxlen);
498 511
 		return -1;
499 512
 	}
500 513
 	rta = NLMSG_TAIL(n);
@@ -505,10 +518,11 @@ int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data,
505 518
 	return 0;
506 519
 }
507 520
 
508
-int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len)
521
+int
522
+addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len)
509 523
 {
510 524
 	if (NLMSG_ALIGN(n->nlmsg_len) + NLMSG_ALIGN(len) > maxlen) {
511
-		error("addraw_l ERROR: message exceeded bound of %d\n",maxlen);
525
+		error("addraw_l ERROR: message exceeded bound of %d\n", maxlen);
512 526
 		return -1;
513 527
 	}
514 528
 
@@ -518,16 +532,18 @@ int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len)
518 532
 	return 0;
519 533
 }
520 534
 
521
-int rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t data)
535
+int
536
+rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t data)
522 537
 {
523 538
 	int len = RTA_LENGTH(4);
524 539
 	struct rtattr *subrta;
525 540
 
526 541
 	if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
527
-		error("rta_addattr32: Error! max allowed bound %d exceeded\n",maxlen);
542
+		error("rta_addattr32: Error! max allowed bound %d exceeded\n",
543
+			  maxlen);
528 544
 		return -1;
529 545
 	}
530
-	subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
546
+	subrta = (struct rtattr *) (((char *) rta) + RTA_ALIGN(rta->rta_len));
531 547
 	subrta->rta_type = type;
532 548
 	subrta->rta_len = len;
533 549
 	memcpy(RTA_DATA(subrta), &data, 4);
@@ -535,17 +551,19 @@ int rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t data)
535 551
 	return 0;
536 552
 }
537 553
 
538
-int rta_addattr_l(struct rtattr *rta, int maxlen, int type, 
539
-		  const void *data, int alen)
554
+int
555
+rta_addattr_l(struct rtattr *rta, int maxlen, int type,
556
+			  const void *data, int alen)
540 557
 {
541 558
 	struct rtattr *subrta;
542 559
 	int len = RTA_LENGTH(alen);
543 560
 
544 561
 	if (RTA_ALIGN(rta->rta_len) + len > maxlen) {
545
-		error("rta_addattr_l: Error! max allowed bound %d exceeded\n",maxlen);
562
+		error("rta_addattr_l: Error! max allowed bound %d exceeded\n",
563
+			  maxlen);
546 564
 		return -1;
547 565
 	}
548
-	subrta = (struct rtattr*)(((char*)rta) + RTA_ALIGN(rta->rta_len));
566
+	subrta = (struct rtattr *) (((char *) rta) + RTA_ALIGN(rta->rta_len));
549 567
 	subrta->rta_type = type;
550 568
 	subrta->rta_len = len;
551 569
 	memcpy(RTA_DATA(subrta), data, alen);
@@ -553,20 +571,23 @@ int rta_addattr_l(struct rtattr *rta, int maxlen, int type,
553 571
 	return 0;
554 572
 }
555 573
 
556
-int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
574
+int
575
+parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len)
557 576
 {
558 577
 	memset(tb, 0, sizeof(struct rtattr *) * (max + 1));
559 578
 	while (RTA_OK(rta, len)) {
560 579
 		if (rta->rta_type <= max)
561 580
 			tb[rta->rta_type] = rta;
562
-		rta = RTA_NEXT(rta,len);
581
+		rta = RTA_NEXT(rta, len);
563 582
 	}
564 583
 	if (len)
565 584
 		error("!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);
566 585
 	return 0;
567 586
 }
568 587
 
569
-int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int len)
588
+int
589
+parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta,
590
+					 int len)
570 591
 {
571 592
 	int i = 0;
572 593
 
@@ -574,7 +595,7 @@ int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int l
574 595
 	while (RTA_OK(rta, len)) {
575 596
 		if (rta->rta_type <= max && i < max)
576 597
 			tb[i++] = rta;
577
-		rta = RTA_NEXT(rta,len);
598
+		rta = RTA_NEXT(rta, len);
578 599
 	}
579 600
 	if (len)
580 601
 		error("!!!Deficit %d, rta_len=%d\n", len, rta->rta_len);

+ 54
- 32
src/libnetlink.h View File

@@ -1,3 +1,21 @@
1
+/* This file is part of Netsukuku
2
+ *
3
+ * This source code is free software; you can redistribute it and/or
4
+ * modify it under the terms of the GNU General Public License as published
5
+ * by the Free Software Foundation; either version 2 of the License,
6
+ * or (at your option) any later version.
7
+ *
8
+ * This source code is distributed in the hope that it will be useful,
9
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
+ * Please refer to the GNU Public License for more details.
12
+ *
13
+ * You should have received a copy of the GNU Public License along with
14
+ * this source code; if not, write to:
15
+ * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
+ *
17
+ */
18
+
1 19
 #ifndef __LIBNETLINK_H__
2 20
 #define __LIBNETLINK_H__ 1
3 21
 
@@ -5,53 +23,57 @@
5 23
 #include <linux/netlink.h>
6 24
 #include <linux/rtnetlink.h>
7 25
 
8
-struct rtnl_handle
9
-{
10
-	int			fd;
11
-	struct sockaddr_nl	local;
12
-	struct sockaddr_nl	peer;
13
-	uint32_t		seq;
14
-	uint32_t		dump;
26
+struct rtnl_handle {
27
+	int fd;
28
+	struct sockaddr_nl local;
29
+	struct sockaddr_nl peer;
30
+	uint32_t seq;
31
+	uint32_t dump;
15 32
 };
16 33
 
17 34
 extern int rtnl_open(struct rtnl_handle *rth, unsigned subscriptions);
18
-extern int rtnl_open_byproto(struct rtnl_handle *rth, unsigned subscriptions, int protocol);
35
+extern int rtnl_open_byproto(struct rtnl_handle *rth,
36
+							 unsigned subscriptions, int protocol);
19 37
 extern void rtnl_close(struct rtnl_handle *rth);
20
-extern int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type);
21
-extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len);
38
+extern int rtnl_wilddump_request(struct rtnl_handle *rth, int fam,
39
+								 int type);
40
+extern int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req,
41
+							 int len);
22 42
 
23
-typedef int (*rtnl_filter_t)(const struct sockaddr_nl *, 
24
-			     struct nlmsghdr *n, void *);
43
+typedef int (*rtnl_filter_t) (const struct sockaddr_nl *,
44
+							  struct nlmsghdr * n, void *);
25 45
 extern int rtnl_dump_filter(struct rtnl_handle *rth, rtnl_filter_t filter,
26
-			    void *arg1,
27
-			    rtnl_filter_t junk,
28
-			    void *arg2);
29
-extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
30
-		     unsigned groups, struct nlmsghdr *answer,
31
-		     rtnl_filter_t junk,
32
-		     void *jarg);
46
+							void *arg1, rtnl_filter_t junk, void *arg2);
47
+extern int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
48
+					 pid_t peer, unsigned groups, struct nlmsghdr *answer,
49
+					 rtnl_filter_t junk, void *jarg);
33 50
 extern int rtnl_send(struct rtnl_handle *rth, const char *buf, int);
34 51
 
35 52
 
36
-extern int addattr32(struct nlmsghdr *n, int maxlen, int type, uint32_t data);
37
-extern int addattr_l(struct nlmsghdr *n, int maxlen, int type, const void *data, int alen);
38
-extern int addraw_l(struct nlmsghdr *n, int maxlen, const void *data, int len);
39
-extern int rta_addattr32(struct rtattr *rta, int maxlen, int type, uint32_t data);
40
-extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type, const void *data, int alen);
53
+extern int addattr32(struct nlmsghdr *n, int maxlen, int type,
54
+					 uint32_t data);
55
+extern int addattr_l(struct nlmsghdr *n, int maxlen, int type,
56
+					 const void *data, int alen);
57
+extern int addraw_l(struct nlmsghdr *n, int maxlen, const void *data,
58
+					int len);
59
+extern int rta_addattr32(struct rtattr *rta, int maxlen, int type,
60
+						 uint32_t data);
61
+extern int rta_addattr_l(struct rtattr *rta, int maxlen, int type,
62
+						 const void *data, int alen);
41 63
 
42
-extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta, int len);
43
-extern int parse_rtattr_byindex(struct rtattr *tb[], int max, struct rtattr *rta, int len);
64
+extern int parse_rtattr(struct rtattr *tb[], int max, struct rtattr *rta,
65
+						int len);
66
+extern int parse_rtattr_byindex(struct rtattr *tb[], int max,
67
+								struct rtattr *rta, int len);
44 68
 
45 69
 #define parse_rtattr_nested(tb, max, rta) \
46 70
 	(parse_rtattr((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta)))
47 71
 
48
-extern int rtnl_listen(struct rtnl_handle *, rtnl_filter_t handler, 
49
-		       void *jarg);
50
-extern int rtnl_from_file(FILE *, rtnl_filter_t handler,
51
-		       void *jarg);
72
+extern int rtnl_listen(struct rtnl_handle *, rtnl_filter_t handler,
73
+					   void *jarg);
74
+extern int rtnl_from_file(FILE *, rtnl_filter_t handler, void *jarg);
52 75
 
53 76
 #define NLMSG_TAIL(nmsg) \
54 77
 	((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
55 78
 
56
-#endif /* __LIBNETLINK_H__ */
57
-
79
+#endif							/* __LIBNETLINK_H__ */

+ 241
- 232
src/libping.c View File

@@ -34,19 +34,19 @@
34 34
 #include "log.h"
35 35
 
36 36
 #define  MAXPACKET   65535
37
-#define  PKTSIZE     64 
37
+#define  PKTSIZE     64
38 38
 #define  HDRLEN      ICMP_MINLEN
39 39
 #define  DATALEN     (PKTSIZE-HDRLEN)
40 40
 #define  MAXDATA     (MAXPKT-HDRLEN-TIMLEN)
41 41
 #define  DEF_TIMEOUT 5
42 42
 
43 43
 struct ping_priv
44
-ping_priv_default (void)
44
+ping_priv_default(void)
45 45
 {
46
-  struct ping_priv datum;
47
-  datum.ident = IDENT_DEFAULT;
48
-  datum.timo = TIMO_DEFAULT;
49
-  return datum;
46
+	struct ping_priv datum;
47
+	datum.ident = IDENT_DEFAULT;
48
+	datum.timo = TIMO_DEFAULT;
49
+	return datum;
50 50
 }
51 51
 
52 52
 /**
@@ -55,323 +55,332 @@ ping_priv_default (void)
55 55
  * between now and starttime in milliseconds.
56 56
  */
57 57
 int
58
-elapsed_time( struct timeval *starttime ){
59
-  struct timeval *newtime;
60
-  int elapsed;
61
-  newtime = (struct timeval*)xmalloc( sizeof(struct timeval));
62
-  gettimeofday(newtime,NULL);
63
-  elapsed = 0;
64
-  
65
-  if(( newtime->tv_usec - starttime->tv_usec) > 0 ){
66
-    elapsed += (newtime->tv_usec - starttime->tv_usec)/1000 ;
67
-  } 
68
-  else{
69
-    elapsed += ( 1000000 + newtime->tv_usec - starttime->tv_usec ) /1000;
70
-    newtime->tv_sec--;
71
-  } 
72
-  if(( newtime->tv_sec - starttime->tv_sec ) > 0 ){
73
-    elapsed += 1000 * ( newtime->tv_sec - starttime->tv_sec );
74
-  } 
75
-  if( elapsed < 1 )
76
-    elapsed = 1;
77
-    
78
-  xfree( newtime );
79
-  return( elapsed );
58
+elapsed_time(struct timeval *starttime)
59
+{
60
+	struct timeval *newtime;
61
+	int elapsed;
62
+	newtime = (struct timeval *) xmalloc(sizeof(struct timeval));
63
+	gettimeofday(newtime, NULL);
64
+	elapsed = 0;
65
+
66
+	if ((newtime->tv_usec - starttime->tv_usec) > 0) {
67
+		elapsed += (newtime->tv_usec - starttime->tv_usec) / 1000;
68
+	} else {
69
+		elapsed +=
70
+			(1000000 + newtime->tv_usec - starttime->tv_usec) / 1000;
71
+		newtime->tv_sec--;
72
+	}
73
+	if ((newtime->tv_sec - starttime->tv_sec) > 0) {
74
+		elapsed += 1000 * (newtime->tv_sec - starttime->tv_sec);
75
+	}
76
+	if (elapsed < 1)
77
+		elapsed = 1;
78
+
79
+	xfree(newtime);
80
+	return (elapsed);
80 81
 }
81 82
 
82 83
 void
83
-JOEfreeprotoent( struct protoent *p )
84
+JOEfreeprotoent(struct protoent *p)
84 85
 {
85
-  char **a;
86
-  xfree( p->p_name );
87
-  if( p->p_aliases != NULL ){
88
-    for( a = p->p_aliases; *a != NULL; a++ ){
89
-      xfree( *a );
90
-    }
91
-  }
92
-  xfree( p );
86
+	char **a;
87
+	xfree(p->p_name);
88
+	if (p->p_aliases != NULL) {
89
+		for (a = p->p_aliases; *a != NULL; a++) {
90
+			xfree(*a);
91
+		}
92
+	}
93
+	xfree(p);
93 94
 }
94 95
 
95 96
 void
96
-JOEfreehostent( struct hostent *h )
97
+JOEfreehostent(struct hostent *h)
97 98
 {
98
-  char **p;
99
+	char **p;
99 100
 
100
-  xfree( h->h_name );
101
-  if( h->h_aliases != NULL ){
102
-    for( p = h->h_aliases; *p != NULL; ++p )
103
-      xfree( *p );
104
-    xfree( h->h_aliases );
105
-  }
106
-  if( h->h_addr_list != NULL ){
107
-    for( p = h->h_addr_list; *p != NULL; ++p )
108
-      xfree( *p );
109
-    xfree (h->h_addr_list);
110
-  }
111
-  xfree( h );
101
+	xfree(h->h_name);
102
+	if (h->h_aliases != NULL) {
103
+		for (p = h->h_aliases; *p != NULL; ++p)
104
+			xfree(*p);
105
+		xfree(h->h_aliases);
106
+	}
107
+	if (h->h_addr_list != NULL) {
108
+		for (p = h->h_addr_list; *p != NULL; ++p)
109
+			xfree(*p);
110
+		xfree(h->h_addr_list);
111
+	}
112
+	xfree(h);
112 113
 }
113 114
 
114
-static int 
115
-in_checksum( u_short *buf, int len )
115
+static int
116
+in_checksum(u_short * buf, int len)
116 117
 {
117
-  register long sum = 0;
118
-  u_short  answer = 0;
118
+	register long sum = 0;
119
+	u_short answer = 0;
119 120
 
120
-  while( len > 1 ){
121
-    sum += *buf++;
122
-    len -= 2;
123
-  }
121
+	while (len > 1) {
122
+		sum += *buf++;
123
+		len -= 2;
124
+	}
124 125
 
125
-  if( len == 1 ){
126
-    *( u_char* )( &answer ) = *( u_char* )buf;
127
-    sum += answer;
128
-  }
129
-  sum = ( sum >> 16 ) + ( sum & 0xffff );
130
-  sum += ( sum >> 16 );     
131
-  answer = ~sum;     
126
+	if (len == 1) {
127
+		*(u_char *) (&answer) = *(u_char *) buf;
128
+		sum += answer;
129
+	}
130
+	sum = (sum >> 16) + (sum & 0xffff);
131
+	sum += (sum >> 16);
132
+	answer = ~sum;
132 133
 
133
-  return ( answer );
134
+	return (answer);
134 135
 
135
-} 
136
+}
136 137
 
137 138
 static int
138
-send_ping( const char *host, struct sockaddr_in *taddr, struct ping_priv * datum )
139
+send_ping(const char *host, struct sockaddr_in *taddr,
140
+		  struct ping_priv *datum)
139 141
 {
140
-  int len;
141
-  int ss;
142
-  unsigned char buf[ HDRLEN + DATALEN ];
142
+	int len;
143
+	int ss;
144
+	unsigned char buf[HDRLEN + DATALEN];
143 145
 
144 146
 #define PROTO_BUF_LEN	1024
145
-  char   proto_buf[PROTO_BUF_LEN];
146
-  struct protoent *proto = NULL;
147
-  struct protoent proto_datum;
148
-
149
-  struct hostent  *hp = NULL;
150
-  struct hostent  hent;
151
-  int herrno;
152
-  char hbf[9000];
147
+	char proto_buf[PROTO_BUF_LEN];
148
+	struct protoent *proto = NULL;
149
+	struct protoent proto_datum;
150
+
151
+	struct hostent *hp = NULL;
152
+	struct hostent hent;
153
+	int herrno;
154
+	char hbf[9000];
153 155
 #if defined(_AIX)
154
-  char *aixbuf;
155
-  char *probuf;
156
-  int  rc;
156
+	char *aixbuf;
157
+	char *probuf;
158
+	int rc;
157 159
 #endif/*_AIX*/
158 160
 
159
-  struct icmp     *icp;
160
-  unsigned short  last;
161
+	struct icmp *icp;
162
+	unsigned short last;
161 163
 
162
-  len = HDRLEN + DATALEN;
164
+	len = HDRLEN + DATALEN;
163 165
 
164 166
 #if defined(__GLIBC__)
165
-  /* for systems using GNU libc */
166
-  getprotobyname_r("icmp", &proto_datum, proto_buf, PROTO_BUF_LEN, &proto);
167
-  if(( gethostbyname_r( host, &hent, hbf, sizeof(hbf), &hp, &herrno ) < 0 )){
168
-    hp = NULL;
169
-  }
167
+	/* for systems using GNU libc */
168
+	getprotobyname_r("icmp", &proto_datum, proto_buf, PROTO_BUF_LEN,
169
+					 &proto);
170
+	if ((gethostbyname_r(host, &hent, hbf, sizeof(hbf), &hp, &herrno) < 0)) {
171
+		hp = NULL;
172
+	}
170 173
 #elif defined(sun)
171
-  /* Solaris 5++ */
172
-  proto = getprotobyname_r("icmp", &proto_datum, proto_buf, PROTO_BUF_LEN);
173
-  hp    = gethostbyname_r( host, &hent, hbf, sizeof(hbf), &herrno );
174
+	/* Solaris 5++ */
175
+	proto =
176
+		getprotobyname_r("icmp", &proto_datum, proto_buf, PROTO_BUF_LEN);
177
+	hp = gethostbyname_r(host, &hent, hbf, sizeof(hbf), &herrno);
174 178
 #elif defined(_AIX)
175
-  aixbuf = (char*)xmalloc( 9000 );
176
-  probuf = (char*)xmalloc( 9000 );
177
-  rc  = getprotobyname_r( "icmp", &proto,
178
-                        ( struct protoent_data *)(probuf + sizeof( struct protoent)));
179
-  rc  = gethostbyname_r ( host, (struct hostent *)aixbuf,
180
-                        (struct hostent_data *)(aixbuf + sizeof(struct hostent)));
181
-  hp = (struct hostent*)aixbuf;
179
+	aixbuf = (char *) xmalloc(9000);
180
+	probuf = (char *) xmalloc(9000);
181
+	rc = getprotobyname_r("icmp", &proto,
182
+						  (struct protoent_data *) (probuf +
183
+													sizeof(struct
184
+														   protoent)));
185
+	rc = gethostbyname_r(host, (struct hostent *) aixbuf,
186
+						 (struct hostent_data *) (aixbuf +
187
+												  sizeof(struct hostent)));
188
+	hp = (struct hostent *) aixbuf;
182 189
 #elif ( defined(hpux) || defined(__osf__) )
183
-  proto  = getprotobyname( "icmp" ); 
184
-  hp     = gethostbyname( host );
185
-  herrno = h_errno;
190
+	proto = getprotobyname("icmp");
191
+	hp = gethostbyname(host);
192
+	herrno = h_errno;
186 193
 #else
187
-  /* simply hoping that get*byname is thread-safe */
188
-  proto  = getprotobyname( "icmp" ); 
189
-  hp     = gethostbyname( host );
190
-  herrno = h_errno;
191
-#endif/*OS SPECIFICS*/
192
-  
193
-  if( proto == NULL ) {
194
-    return -1;
195
-  }
194
+	/* simply hoping that get*byname is thread-safe */
195
+	proto = getprotobyname("icmp");
196
+	hp = gethostbyname(host);
197
+	herrno = h_errno;
198
+#endif							/*OS SPECIFICS */
199
+
200
+	if (proto == NULL) {
201
+		return -1;
202
+	}
196 203
 
197
-  if(hp != NULL ){
198
-    memcpy( &taddr->sin_addr, hp->h_addr_list[0], sizeof( taddr->sin_addr ));
199
-    taddr->sin_port = 0;
200
-    taddr->sin_family = AF_INET;
201
-  }
202
-  else if( inet_aton( host, &taddr->sin_addr ) == 0 ){
203
-    return -1;
204
-  }
204
+	if (hp != NULL) {
205
+		memcpy(&taddr->sin_addr, hp->h_addr_list[0],
206
+			   sizeof(taddr->sin_addr));
207
+		taddr->sin_port = 0;
208
+		taddr->sin_family = AF_INET;
209
+	} else if (inet_aton(host, &taddr->sin_addr) == 0) {
210
+		return -1;
211
+	}
205 212
 
206
-  last = ntohl( taddr->sin_addr.s_addr ) & 0xFF;
207
-  if(( last == 0x00 ) || ( last == 0xFF )){
208
-    return -1;
209
-  }
213
+	last = ntohl(taddr->sin_addr.s_addr) & 0xFF;
214
+	if ((last == 0x00) || (last == 0xFF)) {
215
+		return -1;
216
+	}
210 217
 
211
-  if(( datum->sock = socket( AF_INET, SOCK_RAW, proto->p_proto )) < 0 ){
218
+	if ((datum->sock = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) {
212 219
 #ifdef  DEBUG
213
-	  debug(DBG_NORMAL, ERROR_MSG "sock: %s" ERROR_POS, strerror(errno));
214
-#endif/*DEBUG*/
215
-	  return -2;
216
-  }
220
+		debug(DBG_NORMAL, ERROR_MSG "sock: %s" ERROR_POS, strerror(errno));
221
+#endif	 /*DEBUG*/
222
+			return -2;
223
+	}
217 224
 
218
-  icp = (struct icmp *)buf;
219
-  icp->icmp_type  = ICMP_ECHO;
220
-  icp->icmp_code  = 0;
221
-  icp->icmp_cksum = 0;
222
-  icp->icmp_id    = getpid() & 0xFFFF;
223
-  icp->icmp_cksum = in_checksum((u_short *)icp, len );
225
+	icp = (struct icmp *) buf;
226
+	icp->icmp_type = ICMP_ECHO;
227
+	icp->icmp_code = 0;
228
+	icp->icmp_cksum = 0;
229
+	icp->icmp_id = getpid() & 0xFFFF;
230
+	icp->icmp_cksum = in_checksum((u_short *) icp, len);
224 231
 
225
-  if(( ss = sendto( datum->sock, buf, sizeof( buf ), 0, 
226
-				  (struct sockaddr*)taddr, sizeof( *taddr ))) < 0 ){
232
+	if ((ss = sendto(datum->sock, buf, sizeof(buf), 0,
233
+					 (struct sockaddr *) taddr, sizeof(*taddr))) < 0) {
227 234
 #ifdef  DEBUG
228
-	  debug(DBG_NORMAL, ERROR_MSG "sock: %s" ERROR_POS, strerror(errno));
229
-#endif/*DEBUG*/
230
-	  return -2;
231
-  }
232
-  if( ss != len ){
235
+		debug(DBG_NORMAL, ERROR_MSG "sock: %s" ERROR_POS, strerror(errno));
236
+#endif	 /*DEBUG*/
237
+			return -2;
238
+	}
239
+	if (ss != len) {
233 240
 #ifdef  DEBUG
234
-	  debug(DBG_NORMAL, ERROR_MSG "sock: %s" ERROR_POS, strerror(errno));
235
-#endif/*DEBUG*/
236
-	  return -2;
237
-  }
238
-
241
+		debug(DBG_NORMAL, ERROR_MSG "sock: %s" ERROR_POS, strerror(errno));
242
+#endif	 /*DEBUG*/
243
+			return -2;
244
+	}
239 245
 #if defined(_AIX)
240
-  xfree( aixbuf );
241
-  xfree( probuf );
242
-#endif 
243
-  /* JOEfreeprotoent( proto ); */
244
-  /* JOEfreeprotoent( &proto_datum ); */
245
-  /* JOEfreehostent( hp ); */
246
-  /* JOEfreehostent( &hent ); */
247
-  return 0;
246
+	xfree(aixbuf);
247
+	xfree(probuf);
248
+#endif
249
+	/* JOEfreeprotoent( proto ); */
250
+	/* JOEfreeprotoent( &proto_datum ); */
251
+	/* JOEfreehostent( hp ); */
252
+	/* JOEfreehostent( &hent ); */
253
+	return 0;
248 254
 }
249 255
 
250
-static int 
251
-recv_ping( struct sockaddr_in *taddr, struct ping_priv * datum )
256
+static int
257
+recv_ping(struct sockaddr_in *taddr, struct ping_priv *datum)
252 258
 {
253 259
 	int len;
254 260
 	int from;
255 261
 	int nf, cc;
256
-	unsigned char buf[ HDRLEN + DATALEN ];
257
-	struct icmp        *icp;
262
+	unsigned char buf[HDRLEN + DATALEN];
263
+	struct icmp *icp;
258 264
 	struct sockaddr_in faddr;
259 265
 	struct timeval to;
260 266
 	fd_set readset;
261 267
 
262 268
 	to.tv_sec = datum->timo / 100000;
263
-	to.tv_usec = ( datum->timo - ( to.tv_sec * 100000 ) ) * 10;
269
+	to.tv_usec = (datum->timo - (to.tv_sec * 100000)) * 10;
264 270
 
265
-	FD_ZERO( &readset );
266
-	FD_SET( datum->sock, &readset );
271
+	FD_ZERO(&readset);
272
+	FD_SET(datum->sock, &readset);
267 273
 	/* we use select to see if there is any activity
268 274
 	   on the socket.  If not, then we've requested an
269 275
 	   unreachable network and we'll time out here. */
270
-	if(( nf = select( datum->sock + 1, &readset, NULL, NULL, &to )) < 0 ){
276
+	if ((nf = select(datum->sock + 1, &readset, NULL, NULL, &to)) < 0) {
271 277
 		datum->rrt = -4;
272 278
 #ifdef  DEBUG
273 279
 		debug(DBG_NORMAL, ERROR_MSG "sock: %s" ERROR_POS, strerror(errno));
274
-#endif/*DEBUG*/    
275
-		return 0;
280
+#endif	 /*DEBUG*/
281
+			return 0;
276 282
 	}
277
-	if( nf == 0 ){ 
278
-		return -1; 
283
+	if (nf == 0) {
284
+		return -1;
279 285
 	}
280 286
 
281 287
 	len = HDRLEN + DATALEN;
282
-	from = sizeof( faddr ); 
288
+	from = sizeof(faddr);
283 289
 
284
-	cc = recvfrom( datum->sock, buf, len, 0, (struct sockaddr*)&faddr,(socklen_t*)&from );
285
-	if( cc < 0 ){
290
+	cc = recvfrom(datum->sock, buf, len, 0, (struct sockaddr *) &faddr,
291
+				  (socklen_t *) & from);
292
+	if (cc < 0) {
286 293
 		datum->rrt = -4;
287 294
 #ifdef  DEBUG
288 295
 		debug(DBG_NORMAL, ERROR_MSG "sock: %s" ERROR_POS, strerror(errno));
289
-#endif/*DEBUG*/    
290
-    return 0;
291
-  }
296
+#endif	 /*DEBUG*/
297
+			return 0;
298
+	}
292 299
 
293
-  icp = (struct icmp *)(buf + HDRLEN + DATALEN );
294
-  if( faddr.sin_addr.s_addr != taddr->sin_addr.s_addr ){
295
-    return 1;
296
-  }
300
+	icp = (struct icmp *) (buf + HDRLEN + DATALEN);
301
+	if (faddr.sin_addr.s_addr != taddr->sin_addr.s_addr) {
302
+		return 1;
303
+	}
297 304
   /*****
298 305
   if( icp->icmp_id   != ( getpid() & 0xFFFF )){
299 306
     printf( "id: %d\n",  icp->icmp_id );
300 307
     return 1; 
301 308
   }
302 309
   *****/
303
-  return 0;
310
+	return 0;
304 311
 }
305 312
 
306
-int 
307
-myping( const char *hostname, int t , struct ping_priv * datum)
313
+int
314
+myping(const char *hostname, int t, struct ping_priv *datum)
308 315
 {
309
-  int err;
310
-  int rrt;
311
-  struct sockaddr_in sa;
312
-  struct timeval mytime;
313
- 
314
-  datum->ident = getpid() & 0xFFFF;
315
-
316
-  if( t == 0 ) datum->timo = 2; 
317
-  else         datum->timo = t;
318
-
319
-  datum->rrt = 0;
320
-  
321
-  (void) gettimeofday( &mytime, (struct timezone *)NULL); 
322
-  if(( err = send_ping( hostname, &sa, datum)) < 0 ){
323
-    close( datum->sock );
324
-    return err;
325
-  }
326
-  do {
327
-    rrt = elapsed_time( &mytime );
328
-    if (datum->rrt < 0)
329
-      return 0;
330
-    datum->rrt = rrt;
331
-    if (datum->rrt > datum->timo * 1000 ) {
332
-      close( datum->sock );
333
-      return 0;
334
-    }
335
-  } while( recv_ping( &sa, datum ));
336
-  close( datum->sock ); 
337
- 
338
-  return 1;
316
+	int err;
317
+	int rrt;
318
+	struct sockaddr_in sa;
319
+	struct timeval mytime;
320
+
321
+	datum->ident = getpid() & 0xFFFF;
322
+
323
+	if (t == 0)
324
+		datum->timo = 2;
325
+	else
326
+		datum->timo = t;
327
+
328
+	datum->rrt = 0;
329
+
330
+	(void) gettimeofday(&mytime, (struct timezone *) NULL);
331
+	if ((err = send_ping(hostname, &sa, datum)) < 0) {
332
+		close(datum->sock);
333
+		return err;
334
+	}
335
+	do {
336
+		rrt = elapsed_time(&mytime);
337
+		if (datum->rrt < 0)
338
+			return 0;
339
+		datum->rrt = rrt;
340
+		if (datum->rrt > datum->timo * 1000) {
341
+			close(datum->sock);
342
+			return 0;
343
+		}
344
+	} while (recv_ping(&sa, datum));
345
+	close(datum->sock);
346
+
347
+	return 1;
339 348
 }
340 349
 
341 350
 int
342
-pinghost( const char *hostname )
351
+pinghost(const char *hostname)
343 352
 {
344
-  struct ping_priv datum = ping_priv_default();
345
-  return myping( hostname, 0, &datum );
353
+	struct ping_priv datum = ping_priv_default();
354
+	return myping(hostname, 0, &datum);
346 355
 }
347 356
 
348 357
 int
349
-pingthost( const char *hostname, int t )
358
+pingthost(const char *hostname, int t)
350 359
 {
351
-  struct ping_priv datum = ping_priv_default();
352
-  return myping( hostname, t, &datum );
360
+	struct ping_priv datum = ping_priv_default();
361
+	return myping(hostname, t, &datum);
353 362
 }
354 363
 
355 364
 int
356
-tpinghost( const char *hostname )
365
+tpinghost(const char *hostname)
357 366
 {
358
-  int ret;
359
-  struct ping_priv datum = ping_priv_default();
367
+	int ret;
368
+	struct ping_priv datum = ping_priv_default();
360 369
 
361
-  ret = myping( hostname, 0, &datum );
362
-  if(ret > 0 )
363
-    ret = datum.rrt;
364
-  return ret;
365
-} 
370
+	ret = myping(hostname, 0, &datum);
371
+	if (ret > 0)
372
+		ret = datum.rrt;
373
+	return ret;
374
+}
366 375
 
367 376
 int
368
-tpingthost( const char *hostname, int t )
377
+tpingthost(const char *hostname, int t)
369 378
 {
370
-  int ret;
371
-  struct ping_priv datum = ping_priv_default();
379
+	int ret;
380
+	struct ping_priv datum = ping_priv_default();
372 381
 
373
-  ret = myping( hostname, t, &datum );
374
-  if(ret > 0 )
375
-    ret = datum.rrt;
376
-  return ret;
382
+	ret = myping(hostname, t, &datum);
383
+	if (ret > 0)
384
+		ret = datum.rrt;
385
+	return ret;
377 386
 }

+ 56
- 56
src/libping.h View File

@@ -26,65 +26,65 @@
26 26
 
27 27
 #if defined( __linux__ )
28 28
 
29
-#define ICMP_ECHOREPLY          0 
29
+#define ICMP_ECHOREPLY          0
30 30
 #define ICMP_ECHO               8
31 31
 #define ICMP_MINLEN             8
32 32
 
33 33
 struct ip {
34 34
 #if (BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN)
35
-        u_char  ip_hl:4,                /* header length */
36
-                ip_v:4;                 /* version */
35
+	u_char ip_hl:4,				/* header length */
36
+	 ip_v:4;					/* version */
37 37
 #else
38
-        u_char  ip_v:4,                 /* version */
39
-                ip_hl:4;                /* header length */
38
+	u_char ip_v:4,				/* version */
39
+	 ip_hl:4;					/* header length */
40 40
 #endif
41
-        u_char  ip_tos;                 /* type of service */
42
-        short   ip_len;                 /* total length */
43
-        u_short ip_id;                  /* identification */
44
-        short   ip_off;                 /* fragment offset field */
45
-#define IP_DF 0x4000                    /* dont fragment flag */
46
-#define IP_MF 0x2000                    /* more fragments flag */
47
-        u_char  ip_ttl;                 /* time to live */
48
-        u_char  ip_p;                   /* protocol */
49
-        u_short ip_sum;                 /* checksum */
50
-        struct  in_addr ip_src,ip_dst;  /* source and dest address */
41
+	u_char ip_tos;				/* type of service */
42
+	short ip_len;				/* total length */
43
+	u_short ip_id;				/* identification */
44
+	short ip_off;				/* fragment offset field */
45
+#define IP_DF 0x4000			/* dont fragment flag */
46
+#define IP_MF 0x2000			/* more fragments flag */
47
+	u_char ip_ttl;				/* time to live */
48
+	u_char ip_p;				/* protocol */
49
+	u_short ip_sum;				/* checksum */
50
+	struct in_addr ip_src, ip_dst;	/* source and dest address */
51 51
 };
52 52
 
53
-#define n_short u_short                 /* normally defined in in_systm.h */
54
-#define n_long  u_int                   /* redefine for 64-bit machines */
55
-#define n_time  u_int                   /* redefine for 64-bit machines */
53
+#define n_short u_short			/* normally defined in in_systm.h */
54
+#define n_long  u_int			/* redefine for 64-bit machines */
55
+#define n_time  u_int			/* redefine for 64-bit machines */
56 56
 
57 57
 struct icmp {
58
-        u_char  icmp_type;              /* type of message, see below */
59
-        u_char  icmp_code;              /* type sub code */
60
-        u_short icmp_cksum;             /* ones complement cksum of struct */
61
-        union {
62
-                u_char ih_pptr;                 /* ICMP_PARAMPROB */
63
-                struct in_addr ih_gwaddr;       /* ICMP_REDIRECT */
64
-                struct ih_idseq {
65
-                        n_short icd_id;
66
-                        n_short icd_seq;
67
-                } ih_idseq;
68
-                int ih_void;
69
-        } icmp_hun;
58
+	u_char icmp_type;			/* type of message, see below */
59
+	u_char icmp_code;			/* type sub code */
60
+	u_short icmp_cksum;			/* ones complement cksum of struct */
61
+	union {
62
+		u_char ih_pptr;			/* ICMP_PARAMPROB */
63
+		struct in_addr ih_gwaddr;	/* ICMP_REDIRECT */
64
+		struct ih_idseq {
65
+			n_short icd_id;
66
+			n_short icd_seq;
67
+		} ih_idseq;
68
+		int ih_void;
69
+	} icmp_hun;
70 70
 #define icmp_pptr       icmp_hun.ih_pptr
71 71
 #define icmp_gwaddr     icmp_hun.ih_gwaddr
72 72
 #define icmp_id         icmp_hun.ih_idseq.icd_id
73 73
 #define icmp_seq        icmp_hun.ih_idseq.icd_seq
74 74
 #define icmp_void       icmp_hun.ih_void
75
-        union {
76
-                struct id_ts {
77
-                        n_time its_otime;
78
-                        n_time its_rtime;
79
-                        n_time its_ttime;
80
-                } id_ts;
81
-                struct id_ip  {
82
-                        struct ip idi_ip;
83
-                        /* options and then 64 bits of data */
84
-                } id_ip;
85
-                n_long  id_mask;
86
-                char    id_data[1];
87
-        } icmp_dun;
75
+	union {
76
+		struct id_ts {
77
+			n_time its_otime;
78
+			n_time its_rtime;
79
+			n_time its_ttime;
80
+		} id_ts;
81
+		struct id_ip {
82
+			struct ip idi_ip;
83
+			/* options and then 64 bits of data */
84
+		} id_ip;
85
+		n_long id_mask;
86
+		char id_data[1];
87
+	} icmp_dun;
88 88
 #define icmp_otime      icmp_dun.id_ts.its_otime
89 89
 #define icmp_rtime      icmp_dun.id_ts.its_rtime
90 90
 #define icmp_ttime      icmp_dun.id_ts.its_ttime
@@ -94,25 +94,25 @@ struct icmp {
94 94
 };
95 95
 
96 96
 #else
97
-# include <netinet/ip.h>
98
-# include <netinet/ip_icmp.h>
99
-#endif /* defined(__linux__) */   
97
+#include <netinet/ip.h>
98
+#include <netinet/ip_icmp.h>
99
+#endif							/* defined(__linux__) */
100 100
 
101 101
 #define IDENT_DEFAULT 0
102 102
 #define TIMO_DEFAULT 2
103 103
 
104 104
 struct ping_priv {
105
-  int   ident;
106
-  int   timo;
107
-  int   rrt;
108
-  int   sock;
105
+	int ident;
106
+	int timo;
107
+	int rrt;
108
+	int sock;
109 109
 };
110 110
 
111
-struct ping_priv ping_priv_default (void);
111
+struct ping_priv ping_priv_default(void);
112 112
 
113
-int pinghost  ( const char *hostname );
114
-int pingthost ( const char *hostname, int t );
115
-int tpinghost ( const char *hostname );
116
-int tpingthost( const char *hostname, int t );
113
+int pinghost(const char *hostname);
114
+int pingthost(const char *hostname, int t);
115
+int tpinghost(const char *hostname);
116
+int tpingthost(const char *hostname, int t);
117 117
 
118
-#endif/*PING_H*/
118
+#endif							/*PING_H */

+ 49
- 39
src/ll_map.c View File

@@ -19,36 +19,37 @@
19 19
 #include "xmalloc.h"
20 20
 #include "log.h"
21 21
 
22
-struct idxmap
23
-{
24
-	struct idxmap * next;
25
-	int		index;
26
-	int		type;
27
-	int		alen;
28
-	unsigned	flags;
29
-	unsigned char	addr[8];
30
-	char		name[16];
22
+struct idxmap {
23
+	struct idxmap *next;
24
+	int index;
25
+	int type;
26
+	int alen;
27
+	unsigned flags;
28
+	unsigned char addr[8];
29
+	char name[16];
31 30
 };
32 31
 
33 32
 static struct idxmap *idxmap[16];
34 33
 
35
-void ll_free_index(void)
34
+void
35
+ll_free_index(void)
36 36
 {
37 37
 	struct idxmap *im, **imp;
38 38
 	int i;
39
-	for(i=0; i<16; i++)
40
-		for (imp=&idxmap[i]; (im=*imp)!=NULL; ) {
39
+	for (i = 0; i < 16; i++)
40
+		for (imp = &idxmap[i]; (im = *imp) != NULL;) {
41 41
 			imp = &im->next;
42 42
 			xfree(im);
43 43
 		}
44 44
 }
45 45
 
46
-int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
46
+int
47
+ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
47 48
 {
48 49
 	int h;
49 50
 	struct ifinfomsg *ifi = NLMSG_DATA(n);
50 51
 	struct idxmap *im, **imp;
51
-	struct rtattr *tb[IFLA_MAX+1];
52
+	struct rtattr *tb[IFLA_MAX + 1];
52 53
 
53 54
 	if (n->nlmsg_type != RTM_NEWLINK)
54 55
 		return 0;
@@ -62,9 +63,9 @@ int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
62 63
 	if (tb[IFLA_IFNAME] == NULL)
63 64
 		return 0;
64 65
 
65
-	h = ifi->ifi_index&0xF;
66
+	h = ifi->ifi_index & 0xF;
66 67
 
67
-	for (imp=&idxmap[h]; (im=*imp)!=NULL; imp = &im->next)
68
+	for (imp = &idxmap[h]; (im = *imp) != NULL; imp = &im->next)
68 69
 		if (im->index == ifi->ifi_index)
69 70
 			break;
70 71
 
@@ -93,13 +94,14 @@ int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
93 94
 	return 0;
94 95
 }
95 96
 
96
-const char *ll_idx_n2a(int idx, char *buf)
97
+const char *
98
+ll_idx_n2a(int idx, char *buf)
97 99
 {
98 100
 	struct idxmap *im;
99 101
 
100 102
 	if (idx == 0)
101 103
 		return "*";
102
-	for (im = idxmap[idx&0xF]; im; im = im->next)
104
+	for (im = idxmap[idx & 0xF]; im; im = im->next)
103 105
 		if (im->index == idx)
104 106
 			return im->name;
105 107
 	snprintf(buf, 16, "if%d", idx);
@@ -107,39 +109,43 @@ const char *ll_idx_n2a(int idx, char *buf)
107 109
 }
108 110
 
109 111
 
110
-const char *ll_index_to_name(int idx)
112
+const char *
113
+ll_index_to_name(int idx)
111 114
 {
112 115
 	static char nbuf[16];
113 116
 
114 117
 	return ll_idx_n2a(idx, nbuf);
115 118
 }
116 119
 
117
-int ll_index_to_type(int idx)
120
+int
121
+ll_index_to_type(int idx)
118 122
 {
119 123
 	struct idxmap *im;
120 124
 
121 125
 	if (idx == 0)
122 126
 		return -1;
123
-	for (im = idxmap[idx&0xF]; im; im = im->next)
127
+	for (im = idxmap[idx & 0xF]; im; im = im->next)
124 128
 		if (im->index == idx)
125 129
 			return im->type;
126 130
 	return -1;
127 131
 }
128 132
 
129
-unsigned ll_index_to_flags(int idx)
133
+unsigned
134
+ll_index_to_flags(int idx)
130 135
 {
131 136
 	struct idxmap *im;
132 137
 
133 138
 	if (idx == 0)
134 139
 		return 0;
135 140
 
136
-	for (im = idxmap[idx&0xF]; im; im = im->next)
141
+	for (im = idxmap[idx & 0xF]; im; im = im->next)
137 142
 		if (im->index == idx)
138 143
 			return im->flags;
139 144
 	return 0;
140 145
 }
141 146
 
142
-int ll_name_to_index(const char *name)
147
+int
148
+ll_name_to_index(const char *name)
143 149
 {
144 150
 	static char ncache[16];
145 151
 	static int icache;
@@ -150,7 +156,7 @@ int ll_name_to_index(const char *name)
150 156
 		return 0;
151 157
 	if (icache && strcmp(name, ncache) == 0)
152 158
 		return icache;
153
-	for (i=0; i<16; i++) {
159
+	for (i = 0; i < 16; i++) {
154 160
 		for (im = idxmap[i]; im; im = im->next) {
155 161
 			if (strcmp(im->name, name) == 0) {
156 162
 				icache = im->index;
@@ -163,39 +169,43 @@ int ll_name_to_index(const char *name)
163 169
 }
164 170
 
165 171
 /* It returns the idx of the `n'th interface it finds up in the map */
166
-int ll_nth_up_if(int n)
172
+int
173
+ll_nth_up_if(int n)
167 174
 {
168 175
 	unsigned char i, found;
169 176
 	unsigned flags;
170 177
 
171
-	if(n <= 0)
178
+	if (n <= 0)
172 179
 		fatal("%s:%d: Bad argument given", ERROR_POS);
173
-	
174
-	for(found=0, i=1; i<=16; i++) {
175
-		flags=ll_index_to_flags(i);
176
-		if((flags & IFF_UP) && !(flags & IFF_LOOPBACK)) {
180
+
181
+	for (found = 0, i = 1; i <= 16; i++) {
182
+		flags = ll_index_to_flags(i);
183
+		if ((flags & IFF_UP) && !(flags & IFF_LOOPBACK)) {
177 184
 			found++;
178
-			if(found == n)
185
+			if (found == n)
179 186
 				return i;
180 187
 		}
181 188
 	}
182
-	
189
+
183 190
 	return -1;
184 191
 }
185 192
 
186 193
 /* It returns the first the idx of the first interface it finds up in the map */
187
-int ll_first_up_if(void)
194
+int
195
+ll_first_up_if(void)
188 196
 {
189 197
 	return ll_nth_up_if(1);
190 198
 }
191
-			
192
-int ll_init_map(struct rtnl_handle *rth)
199
+
200
+int
201
+ll_init_map(struct rtnl_handle *rth)
193 202
 {
194
-	if (rtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK) < 0) 
203
+	if (rtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK) < 0)
195 204
 		fatal("%s:%d: Cannot send dump request", ERROR_POS);
196 205
 
197
-	if (rtnl_dump_filter(rth, (rtnl_filter_t)ll_remember_index, &idxmap, NULL, NULL) < 0) 
198
-		fatal(ERROR_MSG "Dump terminated",ERROR_POS);
206
+	if (rtnl_dump_filter
207
+		(rth, (rtnl_filter_t) ll_remember_index, &idxmap, NULL, NULL) < 0)
208
+		fatal(ERROR_MSG "Dump terminated", ERROR_POS);
199 209
 
200 210
 	return 0;
201 211
 }

+ 17
- 2
src/ll_map.h View File

@@ -1,8 +1,23 @@
1
+/*
2
+ * ll_map.c
3
+ *
4
+ *		This program is free software; you can redistribute it and/or
5
+ *		modify it under the terms of the GNU General Public License
6
+ *		as published by the Free Software Foundation; either version
7
+ *		2 of the License, or (at your option) any later version.
8
+ *
9
+ * Authors:	Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10
+ *
11
+ *
12
+ * Alpt: Added ll_first_up_if
13
+ */
14
+
1 15
 #ifndef LL_MAP_H
2 16
 #define LL_MAP_H
3 17
 
4 18
 void ll_free_index(void);
5
-int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg);
19
+int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n,
20
+					  void *arg);
6 21
 int ll_init_map(struct rtnl_handle *rth);
7 22
 int ll_name_to_index(const char *name);
8 23
 const char *ll_index_to_name(int idx);
@@ -12,4 +27,4 @@ unsigned ll_index_to_flags(int idx);
12 27
 int ll_first_up_if(void);
13 28
 int ll_nth_up_if(int n);
14 29
 
15
-#endif /*LL_MAP_H*/
30
+#endif							/*LL_MAP_H */

+ 9
- 10
src/llist.c View File

@@ -43,10 +43,9 @@
43 43
 
44 44
 #define LLIST_HDR(_struct)	_struct *next, *prev
45 45
 
46
-struct linked_list
47
-{
48
-	LLIST_HDR	(struct linked_list);
49
-}linked_list;
46
+struct linked_list {
47
+	LLIST_HDR(struct linked_list);
48
+} linked_list;
50 49
 typedef struct linked_list l_list;
51 50
 
52 51
 #define is_list_zero(list)						\
@@ -193,7 +192,7 @@ do {									\
193 192
 	}								\
194 193
 	(typeof((_head)))_nd;						\
195 194
 })
196
- 
195
+
197 196
 /*
198 197
  * list_join: 
199 198
  * before list_join(list):
@@ -252,7 +251,7 @@ do {									\
252 251
 	_lin->next=_n;							\
253 252
 	_n->prev=_lin;							\
254 253
 } while (0)
255
-	
254
+
256 255
 /* 
257 256
  * list_substitute
258 257
  *
@@ -324,7 +323,7 @@ do{									\
324 323
 	if(_lmf->next)							\
325 324
 		list_swap(_lmf->next, _lmf);				\
326 325
 }while(0)
327
- 
326
+
328 327
 /* 
329 328
  * list_moveontop
330 329
  *
@@ -510,7 +509,7 @@ do{ 									\
510 509
  */
511 510
 #define list_copy_all_yes(_nil)	(1)
512 511
 #define list_copy_all(list)	list_copy_some((list), list_copy_all_yes)
513
- 
512
+
514 513
 /*
515 514
  * Here below there are the definitions for the linked list with a counter.
516 515
  * The arguments format is:
@@ -566,7 +565,7 @@ do{                  							\
566 565
 		(*(_counter))--;					\
567 566
 	}								\
568 567
 } while(0)
569
-	
568
+
570 569
 
571 570
 /* 
572 571
  * Zeros the `counter' and set the head pointer to 0.
@@ -632,4 +631,4 @@ do{                  							\
632 631
 	_new_head = (typeof((_head)))_hecq;						\
633 632
 })									\
634 633
 
635
-#endif /*LLIST_C*/
634
+#endif							/*LLIST_C */

+ 64
- 57
src/log.c View File

@@ -33,21 +33,22 @@
33 33
 char *__argv0;
34 34
 int dbg_lvl;
35 35
 int log_to_stderr;
36
-static int log_facility=LOG_DAEMON;
37
-int log_file_opened=0;
36
+static int log_facility = LOG_DAEMON;
37
+int log_file_opened = 0;
38 38
 FILE *log_file, *log_fd;
39 39
 
40
-void log_init(char *prog, int dbg, int log_stderr)
40
+void
41
+log_init(char *prog, int dbg, int log_stderr)
41 42
 {
42
-	__argv0=prog;
43
-	dbg_lvl=dbg;
44
-	log_to_stderr=log_stderr;
45
-	if(log_stderr)
46
-		log_fd=stderr;
47
-	if(!log_file_opened)
48
-		log_file=0;
49
-
50
-	if(!log_to_stderr)
43
+	__argv0 = prog;
44
+	dbg_lvl = dbg;
45
+	log_to_stderr = log_stderr;
46
+	if (log_stderr)
47
+		log_fd = stderr;
48
+	if (!log_file_opened)
49
+		log_file = 0;
50
+
51
+	if (!log_to_stderr)
51 52
 		openlog(__argv0, dbg ? LOG_PID : 0, log_facility);
52 53
 }
53 54
 
@@ -59,48 +60,51 @@ void log_init(char *prog, int dbg, int log_stderr)
59 60
  *
60 61
  * On errors it returns -1;
61 62
  */
62
-int log_to_file(char *filename)
63
+int
64
+log_to_file(char *filename)
63 65
 {
64
-	if(!filename) {
65
-		if(log_file)
66
-			log_fd=log_file;
66
+	if (!filename) {
67
+		if (log_file)
68
+			log_fd = log_file;
67 69
 		else
68 70
 			return -1;
69 71
 		return 0;
70 72
 	}
71 73
 
72
-	if(!(log_file=fopen(filename, "w"))) {
73
-		log_fd=stderr;
74
+	if (!(log_file = fopen(filename, "w"))) {
75
+		log_fd = stderr;
74 76
 		error("Cannot open the \"%s\" logfile: %s",
75
-				filename, strerror(errno));
77
+			  filename, strerror(errno));
76 78
 		return -1;
77 79
 	}
78 80
 
79
-	log_fd=log_file;
80
-	log_file_opened=1;
81
+	log_fd = log_file;
82
+	log_file_opened = 1;
81 83
 
82 84
 	return 0;
83 85
 }
84 86
 
85
-void close_log_file(void)
87
+void
88
+close_log_file(void)
86 89
 {
87
-	if(log_file) {
90
+	if (log_file) {
88 91
 		fflush(log_file);
89 92
 		fclose(log_file);
90 93
 	}
91 94
 }
92 95
 
93 96
 /* Life is fatal! */
94
-void fatal(const char *fmt,...)
97
+void
98
+fatal(const char *fmt, ...)
95 99
 {
96
-	char str[strlen(fmt)+3];
100
+	char str[strlen(fmt) + 3];
97 101
 	va_list args;
98 102
 
99
-	if(fmt) {
100
-		str[0]='!';
101
-		str[1]=' ';
102
-		strncpy(str+2, fmt, strlen(fmt));
103
-		str[strlen(fmt)+2]=0;
103
+	if (fmt) {
104
+		str[0] = '!';
105
+		str[1] = ' ';
106
+		strncpy(str + 2, fmt, strlen(fmt));
107
+		str[strlen(fmt) + 2] = 0;
104 108
 
105 109
 		va_start(args, fmt);
106 110
 		print_log(LOG_CRIT, str, args);
@@ -108,29 +112,29 @@ void fatal(const char *fmt,...)
108 112
 	}
109 113
 
110 114
 	/** Flush the stream if we want to read something */
111
-	if(log_to_stderr || log_file)
115
+	if (log_to_stderr || log_file)
112 116
 		fflush(log_fd);
113
-	if(log_file)
117
+	if (log_file)
114 118
 		close_log_file();
115
-	/**/
116
-
119
+	 /**/
117 120
 #ifdef DEBUG
118
-	/* Useful to catch the error in gdb */
119
-	kill(getpid(), SIGSEGV);
121
+		/* Useful to catch the error in gdb */
122
+		kill(getpid(), SIGSEGV);
120 123
 #endif
121 124
 	exit(1);
122 125
 }
123 126
 
124 127
 /* Misc errors */
125
-void error(const char *fmt,...)
128
+void
129
+error(const char *fmt, ...)
126 130
 {
127
-	char str[strlen(fmt)+3];
131
+	char str[strlen(fmt) + 3];
128 132
 	va_list args;
129 133
 
130
-	str[0]='*';
131
-	str[1]=' ';
132
-	strncpy(str+2, fmt, strlen(fmt));
133
-	str[strlen(fmt)+2]=0;
134
+	str[0] = '*';
135
+	str[1] = ' ';
136
+	strncpy(str + 2, fmt, strlen(fmt));
137
+	str[strlen(fmt) + 2] = 0;
134 138
 
135 139
 	va_start(args, fmt);
136 140
 	print_log(LOG_ERR, str, args);
@@ -138,15 +142,16 @@ void error(const char *fmt,...)
138 142
 }
139 143
 
140 144
 /* Let's give some news */
141
-void loginfo(const char *fmt,...)
145
+void
146
+loginfo(const char *fmt, ...)
142 147
 {
143
-	char str[strlen(fmt)+3];
148
+	char str[strlen(fmt) + 3];
144 149
 	va_list args;
145 150
 
146
-	str[0]='+';
147
-	str[1]=' ';
148
-	strncpy(str+2, fmt, strlen(fmt));
149
-	str[strlen(fmt)+2]=0;
151
+	str[0] = '+';
152
+	str[1] = ' ';
153
+	strncpy(str + 2, fmt, strlen(fmt));
154
+	str[strlen(fmt) + 2] = 0;
150 155
 
151 156
 	va_start(args, fmt);
152 157
 	print_log(LOG_INFO, str, args);
@@ -159,16 +164,17 @@ void loginfo(const char *fmt,...)
159 164
  * Damn!
160 165
  */
161 166
 
162
-void debug(int lvl, const char *fmt,...)
167
+void
168
+debug(int lvl, const char *fmt, ...)
163 169
 {
164
-	char str[strlen(fmt)+3];
170
+	char str[strlen(fmt) + 3];
165 171
 	va_list args;
166 172
 
167
-	if(lvl <= dbg_lvl) {
168
-		str[0]='#';
169
-		str[1]=' ';
170
-		strncpy(str+2, fmt, strlen(fmt));
171
-		str[strlen(fmt)+2]=0;
173
+	if (lvl <= dbg_lvl) {
174
+		str[0] = '#';
175
+		str[1] = ' ';
176
+		strncpy(str + 2, fmt, strlen(fmt));
177
+		str[strlen(fmt) + 2] = 0;
172 178
 
173 179
 		va_start(args, fmt);
174 180
 		print_log(LOG_DEBUG, str, args);
@@ -176,9 +182,10 @@ void debug(int lvl, const char *fmt,...)
176 182
 	}
177 183
 }
178 184
 
179
-void print_log(int level, const char *fmt, va_list args)
185
+void
186
+print_log(int level, const char *fmt, va_list args)
180 187
 {
181
-	if(log_to_stderr || log_file) {
188
+	if (log_to_stderr || log_file) {
182 189
 		vfprintf(log_fd, fmt, args);
183 190
 		fprintf(log_fd, "\n");
184 191
 	} else

+ 2
- 2
src/log.h View File

@@ -107,7 +107,7 @@
107 107
 #endif
108 108
 
109 109
 /* functions declaration */
110
-void log_init(char *, int, int );
110
+void log_init(char *, int, int);
111 111
 int log_to_file(char *filename);
112 112
 void close_log_file(void);
113 113
 
@@ -118,4 +118,4 @@ void debug(int lvl, const char *, ...);
118 118
 
119 119
 void print_log(int level, const char *fmt, va_list args);
120 120
 
121
-#endif /*LOG_H*/
121
+#endif							/*LOG_H */

+ 0
- 2
src/man/Makefile.am View File

@@ -1,2 +0,0 @@
1
-man8_MANS = andna.8 ntkd.8 ntk-wifi.8 ntk-resolv.8 netsukuku.conf.5
2
-man5_MANS = netsukuku.conf.5

+ 0
- 527
src/man/Makefile.in View File

@@ -1,527 +0,0 @@
1
-# Makefile.in generated by automake 1.13.3 from Makefile.am.
2
-# @configure_input@
3
-
4
-# Copyright (C) 1994-2013 Free Software Foundation, Inc.
5
-
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
-VPATH = @srcdir@
17
-am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
18
-am__make_running_with_option = \
19
-  case $${target_option-} in \
20
-      ?) ;; \
21
-      *) echo "am__make_running_with_option: internal error: invalid" \
22
-              "target option '$${target_option-}' specified" >&2; \
23
-         exit 1;; \
24
-  esac; \
25
-  has_opt=no; \
26
-  sane_makeflags=$$MAKEFLAGS; \
27
-  if $(am__is_gnu_make); then \
28
-    sane_makeflags=$$MFLAGS; \
29
-  else \
30
-    case $$MAKEFLAGS in \
31
-      *\\[\ \	]*) \
32
-        bs=\\; \
33
-        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
34
-          | sed "s/$$bs$$bs[$$bs $$bs	]*//g"`;; \
35
-    esac; \
36
-  fi; \
37
-  skip_next=no; \
38
-  strip_trailopt () \
39
-  { \
40
-    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
41
-  }; \
42
-  for flg in $$sane_makeflags; do \
43
-    test $$skip_next = yes && { skip_next=no; continue; }; \
44
-    case $$flg in \
45
-      *=*|--*) continue;; \
46
-        -*I) strip_trailopt 'I'; skip_next=yes;; \
47
-      -*I?*) strip_trailopt 'I';; \
48
-        -*O) strip_trailopt 'O'; skip_next=yes;; \
49
-      -*O?*) strip_trailopt 'O';; \
50
-        -*l) strip_trailopt 'l'; skip_next=yes;; \
51
-      -*l?*) strip_trailopt 'l';; \
52
-      -[dEDm]) skip_next=yes;; \
53
-      -[JT]) skip_next=yes;; \
54
-    esac; \
55
-    case $$flg in \
56
-      *$$target_option*) has_opt=yes; break;; \
57
-    esac; \
58
-  done; \
59
-  test $$has_opt = yes
60
-am__make_dryrun = (target_option=n; $(am__make_running_with_option))
61
-am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
62
-pkgdatadir = $(datadir)/@PACKAGE@
63
-pkgincludedir = $(includedir)/@PACKAGE@
64
-pkglibdir = $(libdir)/@PACKAGE@
65
-pkglibexecdir = $(libexecdir)/@PACKAGE@
66
-am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
67
-install_sh_DATA = $(install_sh) -c -m 644
68
-install_sh_PROGRAM = $(install_sh) -c
69
-install_sh_SCRIPT = $(install_sh) -c
70
-INSTALL_HEADER = $(INSTALL_DATA)
71
-transform = $(program_transform_name)
72
-NORMAL_INSTALL = :
73
-PRE_INSTALL = :
74
-POST_INSTALL = :
75
-NORMAL_UNINSTALL = :
76
-PRE_UNINSTALL = :
77
-POST_UNINSTALL = :
78
-build_triplet = @build@
79
-host_triplet = @host@
80
-subdir = src/man
81
-DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
82
-ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
83
-am__aclocal_m4_deps = $(top_srcdir)/configure.ac
84
-am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
85
-	$(ACLOCAL_M4)
86
-mkinstalldirs = $(install_sh) -d
87
-CONFIG_HEADER = $(top_builddir)/src/config.h
88
-CONFIG_CLEAN_FILES =
89
-CONFIG_CLEAN_VPATH_FILES =
90
-AM_V_P = $(am__v_P_@AM_V@)
91
-am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
92
-am__v_P_0 = false
93
-am__v_P_1 = :
94
-AM_V_GEN = $(am__v_GEN_@AM_V@)
95
-am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
96
-am__v_GEN_0 = @echo "  GEN     " $@;
97
-am__v_GEN_1 = 
98
-AM_V_at = $(am__v_at_@AM_V@)
99
-am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
100
-am__v_at_0 = @
101
-am__v_at_1 = 
102
-SOURCES =
103
-DIST_SOURCES =
104
-am__can_run_installinfo = \
105
-  case $$AM_UPDATE_INFO_DIR in \
106
-    n|no|NO) false;; \
107
-    *) (install-info --version) >/dev/null 2>&1;; \
108
-  esac
109
-am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
110
-am__vpath_adj = case $$p in \
111
-    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
112
-    *) f=$$p;; \
113
-  esac;
114
-am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
115
-am__install_max = 40
116
-am__nobase_strip_setup = \
117
-  srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
118
-am__nobase_strip = \
119
-  for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
120
-am__nobase_list = $(am__nobase_strip_setup); \
121
-  for p in $$list; do echo "$$p $$p"; done | \
122
-  sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
123
-  $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
124
-    if (++n[$$2] == $(am__install_max)) \
125
-      { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
126
-    END { for (dir in files) print dir, files[dir] }'
127
-am__base_list = \
128
-  sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
129
-  sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
130
-am__uninstall_files_from_dir = { \
131
-  test -z "$$files" \
132
-    || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
133
-    || { echo " ( cd '$$dir' && rm -f" $$files ")"; \
134
-         $(am__cd) "$$dir" && rm -f $$files; }; \
135
-  }
136
-man5dir = $(mandir)/man5
137
-am__installdirs = "$(DESTDIR)$(man5dir)" "$(DESTDIR)$(man8dir)"
138
-man8dir = $(mandir)/man8
139
-NROFF = nroff
140
-MANS = $(man5_MANS) $(man8_MANS)
141
-am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
142
-DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
143
-ACLOCAL = @ACLOCAL@
144
-AMTAR = @AMTAR@
145
-AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
146
-AUTOCONF = @AUTOCONF@
147
-AUTOHEADER = @AUTOHEADER@
148
-AUTOMAKE = @AUTOMAKE@
149
-AWK = @AWK@
150
-CC = @CC@
151
-CCDEPMODE = @CCDEPMODE@
152
-CFLAGS = @CFLAGS@
153
-CONF_DIR = @CONF_DIR@
154
-CPP = @CPP@
155
-CPPFLAGS = @CPPFLAGS@
156
-CXX = @CXX@
157
-CXXDEPMODE = @CXXDEPMODE@
158
-CXXFLAGS = @CXXFLAGS@
159
-CYGPATH_W = @CYGPATH_W@
160
-DATA_DIR = @DATA_DIR@
161
-DEFS = @DEFS@
162
-DEPDIR = @DEPDIR@
163
-ECHO_C = @ECHO_C@
164
-ECHO_N = @ECHO_N@
165
-ECHO_T = @ECHO_T@
166
-EGREP = @EGREP@
167
-EXEEXT = @EXEEXT@
168
-GREP = @GREP@
169
-IF_METHOD = @IF_METHOD@
170
-INSTALL = @INSTALL@
171
-INSTALL_DATA = @INSTALL_DATA@
172
-INSTALL_PROGRAM = @INSTALL_PROGRAM@
173
-INSTALL_SCRIPT = @INSTALL_SCRIPT@
174
-INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
175
-KERNEL_METHOD = @KERNEL_METHOD@
176
-LDFLAGS = @LDFLAGS@
177
-LIBOBJS = @LIBOBJS@
178
-LIBS = @LIBS@
179
-LTLIBOBJS = @LTLIBOBJS@
180
-MAKEINFO = @MAKEINFO@
181
-MKDIR_P = @MKDIR_P@
182
-OBJEXT = @OBJEXT@
183
-OTHER_METHOD = @OTHER_METHOD@
184
-PACKAGE = @PACKAGE@
185
-PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
186
-PACKAGE_NAME = @PACKAGE_NAME@
187
-PACKAGE_STRING = @PACKAGE_STRING@
188
-PACKAGE_TARNAME = @PACKAGE_TARNAME@
189
-PACKAGE_URL = @PACKAGE_URL@
190
-PACKAGE_VERSION = @PACKAGE_VERSION@
191
-PATH_SEPARATOR = @PATH_SEPARATOR@
192
-PID_DIR = @PID_DIR@
193
-RT_METHOD = @RT_METHOD@
194
-SET_MAKE = @SET_MAKE@
195
-SHELL = @SHELL@
196
-STRIP = @STRIP@
197
-VERSION = @VERSION@
198
-abs_builddir = @abs_builddir@
199
-abs_srcdir = @abs_srcdir@
200
-abs_top_builddir = @abs_top_builddir@
201
-abs_top_srcdir = @abs_top_srcdir@
202
-ac_ct_CC = @ac_ct_CC@
203
-ac_ct_CXX = @ac_ct_CXX@
204
-am__include = @am__include@
205
-am__leading_dot = @am__leading_dot@
206
-am__quote = @am__quote@
207
-am__tar = @am__tar@
208
-am__untar = @am__untar@
209
-bindir = @bindir@
210
-build = @build@
211
-build_alias = @build_alias@
212
-build_cpu = @build_cpu@
213
-build_os = @build_os@
214
-build_vendor = @build_vendor@
215
-builddir = @builddir@
216
-datadir = @datadir@
217
-datarootdir = @datarootdir@
218
-debug_flags = @debug_flags@
219
-docdir = @docdir@
220
-dvidir = @dvidir@
221
-exec_prefix = @exec_prefix@
222
-gmp = @gmp@
223
-host = @host@
224
-host_alias = @host_alias@
225
-host_cpu = @host_cpu@
226
-host_os = @host_os@
227
-host_vendor = @host_vendor@
228
-htmldir = @htmldir@
229
-includedir = @includedir@
230
-infodir = @infodir@
231
-install_sh = @install_sh@
232
-libdir = @libdir@
233
-libexecdir = @libexecdir@
234
-localedir = @localedir@
235
-localstatedir = @localstatedir@
236
-mandir = @mandir@
237
-mkdir_p = @mkdir_p@
238
-oldincludedir = @oldincludedir@
239
-pdfdir = @pdfdir@
240
-prefix = @prefix@
241
-program_transform_name = @program_transform_name@
242
-psdir = @psdir@
243
-sbindir = @sbindir@
244
-sharedstatedir = @sharedstatedir@
245
-srcdir = @srcdir@
246
-sysconfdir = @sysconfdir@
247
-target_alias = @target_alias@
248
-top_build_prefix = @top_build_prefix@
249
-top_builddir = @top_builddir@
250
-top_srcdir = @top_srcdir@
251
-man8_MANS = andna.8 ntkd.8 ntk-wifi.8 ntk-resolv.8 netsukuku.conf.5
252
-man5_MANS = netsukuku.conf.5
253
-all: all-am
254
-
255
-.SUFFIXES:
256
-$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
257
-	@for dep in $?; do \
258
-	  case '$(am__configure_deps)' in \
259
-	    *$$dep*) \
260
-	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
261
-	        && { if test -f $@; then exit 0; else break; fi; }; \
262
-	      exit 1;; \
263
-	  esac; \
264
-	done; \
265
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu src/man/Makefile'; \
266
-	$(am__cd) $(top_srcdir) && \
267
-	  $(AUTOMAKE) --gnu src/man/Makefile
268
-.PRECIOUS: Makefile
269
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
270
-	@case '$?' in \
271
-	  *config.status*) \
272
-	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
273
-	  *) \
274
-	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
275
-	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
276
-	esac;
277
-
278
-$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
279
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
280
-
281
-$(top_srcdir)/configure:  $(am__configure_deps)
282
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
283
-$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
284
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
285
-$(am__aclocal_m4_deps):
286
-install-man5: $(man5_MANS)
287
-	@$(NORMAL_INSTALL)
288
-	@list1='$(man5_MANS)'; \
289
-	list2=''; \
290
-	test -n "$(man5dir)" \
291
-	  && test -n "`echo $$list1$$list2`" \
292
-	  || exit 0; \
293
-	echo " $(MKDIR_P) '$(DESTDIR)$(man5dir)'"; \
294
-	$(MKDIR_P) "$(DESTDIR)$(man5dir)" || exit 1; \
295
-	{ for i in $$list1; do echo "$$i"; done;  \
296
-	if test -n "$$list2"; then \
297
-	  for i in $$list2; do echo "$$i"; done \
298
-	    | sed -n '/\.5[a-z]*$$/p'; \
299
-	fi; \
300
-	} | while read p; do \
301
-	  if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
302
-	  echo "$$d$$p"; echo "$$p"; \
303
-	done | \
304
-	sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^5][0-9a-z]*$$,5,;x' \
305
-	      -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \
306
-	sed 'N;N;s,\n, ,g' | { \
307
-	list=; while read file base inst; do \
308
-	  if test "$$base" = "$$inst"; then list="$$list $$file"; else \
309
-	    echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man5dir)/$$inst'"; \
310
-	    $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man5dir)/$$inst" || exit $$?; \
311
-	  fi; \
312
-	done; \
313
-	for i in $$list; do echo "$$i"; done | $(am__base_list) | \
314
-	while read files; do \
315
-	  test -z "$$files" || { \
316
-	    echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man5dir)'"; \
317
-	    $(INSTALL_DATA) $$files "$(DESTDIR)$(man5dir)" || exit $$?; }; \
318
-	done; }
319
-
320
-uninstall-man5:
321
-	@$(NORMAL_UNINSTALL)
322
-	@list='$(man5_MANS)'; test -n "$(man5dir)" || exit 0; \
323
-	files=`{ for i in $$list; do echo "$$i"; done; \
324
-	} | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^5][0-9a-z]*$$,5,;x' \
325
-	      -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \
326
-	dir='$(DESTDIR)$(man5dir)'; $(am__uninstall_files_from_dir)
327
-install-man8: $(man8_MANS)
328
-	@$(NORMAL_INSTALL)
329
-	@list1='$(man8_MANS)'; \
330
-	list2=''; \
331
-	test -n "$(man8dir)" \
332
-	  && test -n "`echo $$list1$$list2`" \
333
-	  || exit 0; \
334
-	echo " $(MKDIR_P) '$(DESTDIR)$(man8dir)'"; \
335
-	$(MKDIR_P) "$(DESTDIR)$(man8dir)" || exit 1; \
336
-	{ for i in $$list1; do echo "$$i"; done;  \
337
-	if test -n "$$list2"; then \
338
-	  for i in $$list2; do echo "$$i"; done \
339
-	    | sed -n '/\.8[a-z]*$$/p'; \
340
-	fi; \
341
-	} | while read p; do \
342
-	  if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
343
-	  echo "$$d$$p"; echo "$$p"; \
344
-	done | \
345
-	sed -e 'n;s,.*/,,;p;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \
346
-	      -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,' | \
347
-	sed 'N;N;s,\n, ,g' | { \
348
-	list=; while read file base inst; do \
349
-	  if test "$$base" = "$$inst"; then list="$$list $$file"; else \
350
-	    echo " $(INSTALL_DATA) '$$file' '$(DESTDIR)$(man8dir)/$$inst'"; \
351
-	    $(INSTALL_DATA) "$$file" "$(DESTDIR)$(man8dir)/$$inst" || exit $$?; \
352
-	  fi; \
353
-	done; \
354
-	for i in $$list; do echo "$$i"; done | $(am__base_list) | \
355
-	while read files; do \
356
-	  test -z "$$files" || { \
357
-	    echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(man8dir)'"; \
358
-	    $(INSTALL_DATA) $$files "$(DESTDIR)$(man8dir)" || exit $$?; }; \
359
-	done; }
360
-
361
-uninstall-man8:
362
-	@$(NORMAL_UNINSTALL)
363
-	@list='$(man8_MANS)'; test -n "$(man8dir)" || exit 0; \
364
-	files=`{ for i in $$list; do echo "$$i"; done; \
365
-	} | sed -e 's,.*/,,;h;s,.*\.,,;s,^[^8][0-9a-z]*$$,8,;x' \
366
-	      -e 's,\.[0-9a-z]*$$,,;$(transform);G;s,\n,.,'`; \
367
-	dir='$(DESTDIR)$(man8dir)'; $(am__uninstall_files_from_dir)
368
-tags TAGS:
369
-
370
-ctags CTAGS:
371
-
372
-cscope cscopelist:
373
-
374
-
375
-distdir: $(DISTFILES)
376
-	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
377
-	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
378
-	list='$(DISTFILES)'; \
379
-	  dist_files=`for file in $$list; do echo $$file; done | \
380
-	  sed -e "s|^$$srcdirstrip/||;t" \
381
-	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
382
-	case $$dist_files in \
383
-	  */*) $(MKDIR_P) `echo "$$dist_files" | \
384
-			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
385
-			   sort -u` ;; \
386
-	esac; \
387
-	for file in $$dist_files; do \
388
-	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
389
-	  if test -d $$d/$$file; then \
390
-	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
391
-	    if test -d "$(distdir)/$$file"; then \
392
-	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
393
-	    fi; \
394
-	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
395
-	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
396
-	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
397
-	    fi; \
398
-	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
399
-	  else \
400
-	    test -f "$(distdir)/$$file" \
401
-	    || cp -p $$d/$$file "$(distdir)/$$file" \
402
-	    || exit 1; \
403
-	  fi; \
404
-	done
405
-check-am: all-am
406
-check: check-am
407
-all-am: Makefile $(MANS)
408
-installdirs:
409
-	for dir in "$(DESTDIR)$(man5dir)" "$(DESTDIR)$(man8dir)"; do \
410
-	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
411
-	done
412
-install: install-am
413
-install-exec: install-exec-am
414
-install-data: install-data-am
415
-uninstall: uninstall-am
416
-
417
-install-am: all-am
418
-	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
419
-
420
-installcheck: installcheck-am
421
-install-strip:
422
-	if test -z '$(STRIP)'; then \
423
-	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
424
-	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
425
-	      install; \
426
-	else \
427
-	  $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
428
-	    install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
429
-	    "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
430
-	fi
431
-mostlyclean-generic:
432
-
433
-clean-generic:
434
-
435
-distclean-generic:
436
-	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
437
-	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
438
-
439
-maintainer-clean-generic:
440
-	@echo "This command is intended for maintainers to use"
441
-	@echo "it deletes files that may require special tools to rebuild."
442
-clean: clean-am
443
-
444
-clean-am: clean-generic mostlyclean-am
445
-
446
-distclean: distclean-am
447
-	-rm -f Makefile
448
-distclean-am: clean-am distclean-generic
449
-
450
-dvi: dvi-am
451
-
452
-dvi-am:
453
-
454
-html: html-am
455
-
456
-html-am:
457
-
458
-info: info-am
459
-
460
-info-am:
461
-
462
-install-data-am: install-man
463
-
464
-install-dvi: install-dvi-am
465
-
466
-install-dvi-am:
467
-
468
-install-exec-am:
469
-
470
-install-html: install-html-am
471
-
472
-install-html-am:
473
-
474
-install-info: install-info-am
475
-
476
-install-info-am:
477
-
478
-install-man: install-man5 install-man8
479
-
480
-install-pdf: install-pdf-am
481
-
482
-install-pdf-am:
483
-
484
-install-ps: install-ps-am
485
-
486
-install-ps-am:
487
-
488
-installcheck-am:
489
-
490
-maintainer-clean: maintainer-clean-am
491
-	-rm -f Makefile
492
-maintainer-clean-am: distclean-am maintainer-clean-generic
493
-
494
-mostlyclean: mostlyclean-am
495
-
496
-mostlyclean-am: mostlyclean-generic
497
-
498
-pdf: pdf-am
499
-
500
-pdf-am:
501
-
502
-ps: ps-am
503
-
504
-ps-am:
505
-
506
-uninstall-am: uninstall-man
507
-
508
-uninstall-man: uninstall-man5 uninstall-man8
509
-
510
-.MAKE: install-am install-strip
511
-
512
-.PHONY: all all-am check check-am clean clean-generic cscopelist-am \
513
-	ctags-am distclean distclean-generic distdir dvi dvi-am html \
514
-	html-am info info-am install install-am install-data \
515
-	install-data-am install-dvi install-dvi-am install-exec \
516
-	install-exec-am install-html install-html-am install-info \
517
-	install-info-am install-man install-man5 install-man8 \
518
-	install-pdf install-pdf-am install-ps install-ps-am \
519
-	install-strip installcheck installcheck-am installdirs \
520
-	maintainer-clean maintainer-clean-generic mostlyclean \
521
-	mostlyclean-generic pdf pdf-am ps ps-am tags-am uninstall \
522
-	uninstall-am uninstall-man uninstall-man5 uninstall-man8
523
-
524
-
525
-# Tell versions [3.59,3.63) of GNU make to not export all variables.
526
-# Otherwise a system limit (for SysV at least) may be exceeded.
527
-.NOEXPORT:

+ 308
- 259
src/map.c
File diff suppressed because it is too large
View File


+ 104
- 93
src/map.h View File

@@ -19,6 +19,7 @@
19 19
 #ifndef MAP_H
20 20
 #define MAP_H
21 21
 
22
+#include "includes.h"
22 23
 #include "inet.h"
23 24
 
24 25
 /* Generic map defines */
@@ -29,31 +30,31 @@
29 30
 #define MAXLINKS		MAXROUTES
30 31
 
31 32
 /*** flags ***/
32
-#define MAP_ME		1		/*The root_node, in other words, me ;)*/
33
-#define MAP_VOID	(1<<1)		/*It indicates a non existent node*/
33
+#define MAP_ME		1			/*The root_node, in other words, me ;) */
34
+#define MAP_VOID	(1<<1)		/*It indicates a non existent node */
34 35
 #define MAP_HNODE	(1<<2)		/*Hooking node. The node is currently 
35
-					  hooking*/
36
+								   hooking */
36 37
 #define MAP_BNODE	(1<<3)		/*The node is a border_node. If this 
37
-					  flag is set to a root_node, this means 
38
-					  that we are a bnode at the root_node's 
39
-					  level*/
40
-#define MAP_ERNODE	(1<<4)		/*It is an External Rnode*/
41
-#define MAP_GNODE	(1<<5)		/*It is a gnode*/
42
-#define MAP_RNODE	(1<<6)		/*If a node has this set, it is one of the rnodes*/
38
+								   flag is set to a root_node, this means 
39
+								   that we are a bnode at the root_node's 
40
+								   level */
41
+#define MAP_ERNODE	(1<<4)		/*It is an External Rnode */
42
+#define MAP_GNODE	(1<<5)		/*It is a gnode */
43
+#define MAP_RNODE	(1<<6)		/*If a node has this set, it is one of the rnodes */
43 44
 #define MAP_UPDATE	(1<<7)		/*If it is set, the corresponding route 
44
-					  in the krnl will be updated*/
45
+								   in the krnl will be updated */
45 46
 #define QSPN_CLOSED	(1<<8)		/*This flag is set only to the rnodes, 
46
-					  it puts a link in a QSPN_CLOSED state*/
47
-#define QSPN_OPENED	(1<<9)		/*It puts a link in a QSPN_OPEN state*/
47
+								   it puts a link in a QSPN_CLOSED state */
48
+#define QSPN_OPENED	(1<<9)		/*It puts a link in a QSPN_OPEN state */
48 49
 #define QSPN_OLD	(1<<10)		/*If a node isn't updated by the current
49
-					  qspn_round it is marked with QSPN_ROUND.
50
-					  If in the next qspn_round the same node 
51
-					  isn't updated it is removed from the map.*/
52
-#define QSPN_STARTER	(1<<11)		/*The root node is marked with this flag
53
-					  if it is a qspn_starter*/
50
+								   qspn_round it is marked with QSPN_ROUND.
51
+								   If in the next qspn_round the same node 
52
+								   isn't updated it is removed from the map. */
53
+#define QSPN_STARTER	(1<<11)	/*The root node is marked with this flag
54
+								   if it is a qspn_starter */
54 55
 #define QSPN_OPENER	(1<<12)		/*If the root_node sent a new qspn_open
55
-					  it is a qspn_opener*/
56
-#define MAP_IGW		(1<<13)		/*This node is an Internet gateway*/
56
+								   it is a qspn_opener */
57
+#define MAP_IGW		(1<<13)		/*This node is an Internet gateway */
57 58
 
58 59
 
59 60
 /*\ 			    
@@ -71,11 +72,10 @@
71 72
 \*/
72 73
 
73 74
 /* map_rnode is what map_node.r_node points to. (read struct map_node below) */
74
-typedef struct
75
-{
76
-	int	 	*r_node;	/*It's the pointer to the struct of the
77
-					  r_node in the map*/
78
-	u_int		trtt;		
75
+typedef struct {
76
+	int *r_node;				/*It's the pointer to the struct of the
77
+								   r_node in the map */
78
+	u_int trtt;
79 79
 	/*
80 80
 	 * node <-> root_node total rtt: The rtt to reach the root_node 
81 81
 	 * starting from the node which uses this rnode (in millisec). 
@@ -88,17 +88,18 @@ typedef struct
88 88
 	 * route_number_to_follow. Gotcha? I hope so.
89 89
 	 * Note: The trtt is mainly used to sort the routes
90 90
 	 */
91
-}map_rnode;
91
+} map_rnode;
92 92
 
93 93
 /* Note: This int_info is used for the pack of a map_rnode struct (see 
94 94
  * get_rnode_block()). 
95 95
  * Since the r_node pointer, in the pack, is an integer, we add it in the
96 96
  * int_info as a normal 32bit int. */
97
-INT_INFO map_rnode_iinfo  = { 2, 
98
-			      { INT_TYPE_32BIT, INT_TYPE_32BIT },
99
-			      { 0, sizeof(int) },
100
-			      { 1, 1 }
101
-			    };
97
+INT_INFO map_rnode_iinfo = { 2,
98
+	{INT_TYPE_32BIT, INT_TYPE_32BIT},
99
+	{0, sizeof(int)},
100
+	{1, 1}
101
+};
102
+
102 103
 #define MAP_RNODE_PACK_SZ	(sizeof(int *)+sizeof(u_int))
103 104
 
104 105
 /*
@@ -122,22 +123,21 @@ INT_INFO map_rnode_iinfo  = { 2,
122 123
  * The rnodes of the root_node of 0 level are updated by the radar(), 
123 124
  * instead the root_nodes of greater levels are updated by the qspn.
124 125
  */
125
-typedef struct
126
-{
127
-	u_short 	flags;
128
-	u_int		brdcast;	 /*Pkt_id of the last brdcast_pkt sent by this node*/
129
-	u_short		links;		 /*Number of r_nodes*/
130
-	map_rnode	*r_node;	 /*These structs will be kept in ascending
131
-					   order considering their rnode_t.rtt*/
132
-}map_node;
126
+typedef struct {
127
+	u_short flags;
128
+	u_int brdcast;				/*Pkt_id of the last brdcast_pkt sent by this node */
129
+	u_short links;				/*Number of r_nodes */
130
+	map_rnode *r_node;			/*These structs will be kept in ascending
131
+								   order considering their rnode_t.rtt */
132
+} map_node;
133 133
 
134 134
 /* Note: This int_info is used for the pack of a map_rnode struct (see
135 135
  * pack_map()) */
136
-INT_INFO map_node_iinfo = { 3, 
137
-			    { INT_TYPE_16BIT, INT_TYPE_32BIT, INT_TYPE_16BIT },
138
-			    { 0, sizeof(short), sizeof(short)+sizeof(int) },
139
-			    { 1, 1, 1 }
140
-			  };
136
+INT_INFO map_node_iinfo = { 3,
137
+	{INT_TYPE_16BIT, INT_TYPE_32BIT, INT_TYPE_16BIT},
138
+	{0, sizeof(short), sizeof(short) + sizeof(int)},
139
+	{1, 1, 1}
140
+};
141 141
 
142 142
 #define MAP_NODE_PACK_SZ	(sizeof(u_short)*2 + sizeof(u_int))
143 143
 
@@ -146,17 +146,17 @@ INT_INFO map_node_iinfo = { 3,
146 146
 #define INTMAP_END(mapstart)	((sizeof(map_node)*MAXGROUPNODE)+(mapstart))
147 147
 
148 148
 /*This block is used to send/save the int_map and the bnode_map*/
149
-struct int_map_hdr
150
-{
149
+struct int_map_hdr {
151 150
 	u_char root_node;
152 151
 	size_t int_map_sz;
153 152
 	size_t rblock_sz;
154
-}_PACKED_;
155
-INT_INFO int_map_hdr_iinfo = { 2, 
156
-			       { INT_TYPE_32BIT, INT_TYPE_32BIT }, 
157
-			       { sizeof(char), sizeof(char)+sizeof(size_t) },
158
-			       { 1, 1 }
159
-			     };
153
+} _PACKED_;
154
+INT_INFO int_map_hdr_iinfo = { 2,
155
+	{INT_TYPE_32BIT, INT_TYPE_32BIT},
156
+	{sizeof(char), sizeof(char) + sizeof(size_t)}
157
+	,
158
+	{1, 1}
159
+};
160 160
 
161 161
 /*
162 162
  * The int_map_block is:
@@ -172,49 +172,60 @@ INT_INFO int_map_hdr_iinfo = { 2,
172 172
  */
173 173
 
174 174
 /*conversion functions*/
175
-int pos_from_node(map_node *node, map_node *map);
176
-map_node *node_from_pos(int pos, map_node *map);
177
-void postoip(u_int map_pos, inet_prefix ipstart, inet_prefix *ret);
178
-void maptoip(u_int mapstart, u_int mapoff, inet_prefix ipstart, inet_prefix *ret);
179
-int iptomap(u_int mapstart, inet_prefix ip, inet_prefix ipstart, map_node **ret);
175
+int pos_from_node(map_node * node, map_node * map);
176
+map_node *node_from_pos(int pos, map_node * map);
177
+void postoip(u_int map_pos, inet_prefix ipstart, inet_prefix * ret);
178
+void maptoip(u_int mapstart, u_int mapoff, inet_prefix ipstart,
179
+			 inet_prefix * ret);
180
+int iptomap(u_int mapstart, inet_prefix ip, inet_prefix ipstart,
181
+			map_node ** ret);
180 182
 
181 183
 map_node *init_map(size_t len);
182
-void free_map(map_node *map, size_t count);
183
-void map_node_del(map_node *node);
184
-void reset_int_map(map_node *map, int maxgroupnode);
185
-
186
-map_rnode *rnode_insert(map_rnode *buf, size_t pos, map_rnode *new);
187
-map_rnode *map_rnode_insert(map_node *node, size_t pos, map_rnode *new);
188
-map_rnode *rnode_add(map_node *node, map_rnode *new);
189
-void rnode_swap(map_rnode *one, map_rnode *two);
190
-void rnode_del(map_node *node, size_t pos);
191
-void rnode_destroy(map_node *node);
192
-int rnode_find(map_node *node, void *n);
184
+void free_map(map_node * map, size_t count);
185
+void map_node_del(map_node * node);
186
+void reset_int_map(map_node * map, int maxgroupnode);
187
+
188
+map_rnode *rnode_insert(map_rnode * buf, size_t pos, map_rnode * new);
189
+map_rnode *map_rnode_insert(map_node * node, size_t pos, map_rnode * new);
190
+map_rnode *rnode_add(map_node * node, map_rnode * new);
191
+void rnode_swap(map_rnode * one, map_rnode * two);
192
+void rnode_del(map_node * node, size_t pos);
193
+void rnode_destroy(map_node * node);
194
+int rnode_find(map_node * node, void *n);
193 195
 
194 196
 int rnode_trtt_compar(const void *a, const void *b);
195
-void rnode_trtt_order(map_node *node);
196
-void map_routes_order(map_node *map);
197
-
198
-u_int get_route_trtt(map_node *node, u_short route);
199
-void rnode_set_trtt(map_node *node);
200
-void rnode_recurse_trtt(map_rnode *rnode, int route, struct timeval *trtt);
201
-void node_recurse_trtt(map_node *node);
202
-void map_set_trtt(map_node *map);
203
-map_node *get_gw_node(map_node *node, u_short route);
204
-
205
-int merge_maps(map_node *base, map_node *new, map_node *base_root, map_node *new_root);
206
-int mod_rnode_addr(map_rnode *node, int *map_start, int *new_start);
207
-int get_rnode_block(int *map, map_node *node, map_rnode *rblock, int rstart);
208
-map_rnode *map_get_rblock(map_node *map, int *addr_map, int maxgroupnode, int *count);
209
-int store_rnode_block(int *map, map_node *node, map_rnode *rblock, int rstart);
210
-int map_store_rblock(map_node *map, int *addr_map, int maxgroupnode, map_rnode *rblock);
211
-
212
-int verify_int_map_hdr(struct int_map_hdr *imap_hdr, int maxgroupnode, int maxrnodeblock);
213
-void pack_map_node(map_node *node, char *pack);
214
-void unpack_map_node(map_node *node, char *pack);
215
-char *pack_map(map_node *map, int *addr_map, int maxgroupnode, map_node *root_node, size_t *pack_sz);
216
-map_node *unpack_map(char *pack, int *addr_map, map_node **new_root, int maxgroupnode, int maxrnodeblock);
217
-int save_map(map_node *map, map_node *root_node, char *file);
218
-map_node *load_map(char *file, map_node **new_root);
219
-
220
-#endif /*MAP_H*/
197
+void rnode_trtt_order(map_node * node);
198
+void map_routes_order(map_node * map);
199
+
200
+u_int get_route_trtt(map_node * node, u_short route);
201
+void rnode_set_trtt(map_node * node);
202
+void rnode_recurse_trtt(map_rnode * rnode, int route,
203
+						struct timeval *trtt);
204
+void node_recurse_trtt(map_node * node);
205
+void map_set_trtt(map_node * map);
206
+map_node *get_gw_node(map_node * node, u_short route);
207
+
208
+int merge_maps(map_node * base, map_node * new, map_node * base_root,
209
+			   map_node * new_root);
210
+int mod_rnode_addr(map_rnode * node, int *map_start, int *new_start);
211
+int get_rnode_block(int *map, map_node * node, map_rnode * rblock,
212
+					int rstart);
213
+map_rnode *map_get_rblock(map_node * map, int *addr_map, int maxgroupnode,
214
+						  int *count);
215
+int store_rnode_block(int *map, map_node * node, map_rnode * rblock,
216
+					  int rstart);
217
+int map_store_rblock(map_node * map, int *addr_map, int maxgroupnode,
218
+					 map_rnode * rblock);
219
+
220
+int verify_int_map_hdr(struct int_map_hdr *imap_hdr, int maxgroupnode,
221
+					   int maxrnodeblock);
222
+void pack_map_node(map_node * node, char *pack);
223
+void unpack_map_node(map_node * node, char *pack);
224
+char *pack_map(map_node * map, int *addr_map, int maxgroupnode,
225
+			   map_node * root_node, size_t * pack_sz);
226
+map_node *unpack_map(char *pack, int *addr_map, map_node ** new_root,
227
+					 int maxgroupnode, int maxrnodeblock);
228
+int save_map(map_node * map, map_node * root_node, char *file);
229
+map_node *load_map(char *file, map_node ** new_root);
230
+
231
+#endif							/*MAP_H */

+ 292
- 244
src/mark.c View File

@@ -1,4 +1,4 @@
1
-	         /**************************************
1
+			 /**************************************
2 2
 	        *     AUTHOR: Federico Tomassini        *
3 3
 	       *     Copyright (C) Federico Tomassini    *
4 4
 	      *     Contact effetom@gmail.com             *
@@ -44,7 +44,7 @@
44 44
 
45 45
 static int death_loop_rule;
46 46
 static int clean_on_exit;
47
-static rule_store rr,fr,dr;
47
+static rule_store rr, fr, dr;
48 48
 static int dumped;
49 49
 
50 50
 /* Table init: is too easy for comments.
@@ -52,17 +52,20 @@ static int dumped;
52 52
  * 	0
53 53
  * 	-1
54 54
  */
55
-int table_init(const char *table, iptc_handle_t *t)
55
+int
56
+table_init(const char *table, iptc_handle_t * t)
56 57
 {
57
-	*t=iptc_init(table);
58
-	error("In table_int, t: %s and errno %d", table,errno);
58
+	*t = iptc_init(table);
59
+	error("In table_int, t: %s and errno %d", table, errno);
59 60
 	if (!(*t)) {
60
-		error("In table_init, table %s: -> %s", table,iptc_strerror(errno));
61
-		err_ret(ERR_NETFIL,-1);
61
+		error("In table_init, table %s: -> %s", table,
62
+			  iptc_strerror(errno));
63
+		err_ret(ERR_NETFIL, -1);
62 64
 	}
63 65
 	return 0;
64 66
 
65 67
 }
68
+
66 69
 /*
67 70
  * insert the rule -rule- on chain -chain-
68 71
  * at the position pos.
@@ -70,48 +73,59 @@ int table_init(const char *table, iptc_handle_t *t)
70 73
  * 	0
71 74
  * 	-1
72 75
  */
73
-int insert_rule(const char *rule,iptc_handle_t *t,const char *chain,int pos)
76
+int
77
+insert_rule(const char *rule, iptc_handle_t * t, const char *chain,
78
+			int pos)
74 79
 {
75 80
 	int res;
76
-	res=iptc_insert_entry(chain,(struct ipt_entry*)rule,0,t);
77
-	error("res is: %d rule is: %p chain is: %s pos is: %d t is: %p errno is: %d", res, rule, chain, pos, t, errno);
81
+	res = iptc_insert_entry(chain, (struct ipt_entry *) rule, 0, t);
82
+	error
83
+		("res is: %d rule is: %p chain is: %s pos is: %d t is: %p errno is: %d",
84
+		 res, rule, chain, pos, t, errno);
78 85
 	if (!res) {
79
-		error("In insert_rule: %s.",iptc_strerror(errno));
80
-		err_ret(ERR_NETRUL,-1);
86
+		error("In insert_rule: %s.", iptc_strerror(errno));
87
+		err_ret(ERR_NETRUL, -1);
81 88
 	}
82 89
 	return 0;
83 90
 }
91
+
84 92
 /*
85 93
  * append the rule -rule- on chain -chain-.
86 94
  * Returns:
87 95
  * 	0
88 96
  * 	-1
89 97
  */
90
-int append_rule(const char *rule,iptc_handle_t *t,const char *chain)
98
+int
99
+append_rule(const char *rule, iptc_handle_t * t, const char *chain)
91 100
 {
92 101
 	int res;
93
-	res=iptc_append_entry(chain,(struct ipt_entry*)rule,t);
94
-	error("res is: %d, chain: %s, rule: %s, t: %s, Errno is: %d",res,chain,rule,t,errno);
102
+	res = iptc_append_entry(chain, (struct ipt_entry *) rule, t);
103
+	error("res is: %d, chain: %s, rule: %s, t: %s, Errno is: %d", res,
104
+		  chain, rule, t, errno);
95 105
 	if (!res) {
96
-		error("In append_rule: %s.",iptc_strerror(errno));
97
-		err_ret(ERR_NETRUL,-1);
106
+		error("In append_rule: %s.", iptc_strerror(errno));
107
+		err_ret(ERR_NETRUL, -1);
98 108
 	}
99 109
 	return 0;
100 110
 }
111
+
101 112
 /*
102 113
  * commit modified rules and chains.
103 114
  * Returns:
104 115
  * 	0
105 116
  * 	-1
106 117
  */
107
-int commit_rules(iptc_handle_t *t)
118
+int
119
+commit_rules(iptc_handle_t * t)
108 120
 {
109 121
 	int res;
110
-	res=iptc_commit(t);
111
-	error("This is the value of res: %i This is the value of t is: %p errno is: %d", res, t, errno);
122
+	res = iptc_commit(t);
123
+	error
124
+		("This is the value of res: %i This is the value of t is: %p errno is: %d",
125
+		 res, t, errno);
112 126
 	if (!res) {
113
-		error("In commit_rules: %s.",iptc_strerror(errno));
114
-		err_ret(ERR_NETCOM,-1);
127
+		error("In commit_rules: %s.", iptc_strerror(errno));
128
+		err_ret(ERR_NETCOM, -1);
115 129
 	}
116 130
 	return 0;
117 131
 }
@@ -126,7 +140,8 @@ int commit_rules(iptc_handle_t *t)
126 140
  *
127 141
  * -rule- has to be RESTORE_OUTPUT_RULE_SZ-sized
128 142
  */
129
-void restore_output_rule_init(char *rule)
143
+void
144
+restore_output_rule_init(char *rule)
130 145
 {
131 146
 	struct ipt_entry *ee;
132 147
 	struct ipt_entry_match *em;
@@ -134,35 +149,36 @@ void restore_output_rule_init(char *rule)
134 149
 	struct ipt_conntrack_info *ici;
135 150
 	struct ipt_connmark_target_info *icmi;
136 151
 
137
-	memset(rule,0,RESTORE_OUTPUT_RULE_SZ);
152
+	memset(rule, 0, RESTORE_OUTPUT_RULE_SZ);
138 153
 
139
-	ee=(struct ipt_entry*)(rule);
140
-	em=(struct ipt_entry_match*)(rule+OFFSET_MATCH);
141
-	ici=(struct ipt_conntrack_info*)(rule+OFFSET_MATCH_INFO);
142
-	et=(struct ipt_entry_target*)(rule+OFFSET_TARGET);
143
-	icmi=(struct ipt_connmark_target_info*)(rule+OFFSET_TARGET_INFO);
154
+	ee = (struct ipt_entry *) (rule);
155
+	em = (struct ipt_entry_match *) (rule + OFFSET_MATCH);
156
+	ici = (struct ipt_conntrack_info *) (rule + OFFSET_MATCH_INFO);
157
+	et = (struct ipt_entry_target *) (rule + OFFSET_TARGET);
158
+	icmi = (struct ipt_connmark_target_info *) (rule + OFFSET_TARGET_INFO);
144 159
 
145
-	ee->next_offset=RESTORE_OUTPUT_RULE_SZ;
146
-	ee->target_offset=OFFSET_TARGET;
160
+	ee->next_offset = RESTORE_OUTPUT_RULE_SZ;
161
+	ee->target_offset = OFFSET_TARGET;
147 162
 
148
-	snprintf(ee->ip.outiface,IFNAMSIZ,"%s+",NTK_TUNL_PREFIX);
149
-	memset(ee->ip.outiface_mask,0xFF,strlen(ee->ip.outiface)-1);
163
+	snprintf(ee->ip.outiface, IFNAMSIZ, "%s+", NTK_TUNL_PREFIX);
164
+	memset(ee->ip.outiface_mask, 0xFF, strlen(ee->ip.outiface) - 1);
150 165
 
151
-	strcpy(em->u.user.name,MOD_CONNTRACK);
152
-	em->u.match_size=MATCH_SZ;;
153
-	em->u.user.match_size=em->u.match_size;
166
+	strcpy(em->u.user.name, MOD_CONNTRACK);
167
+	em->u.match_size = MATCH_SZ;;
168
+	em->u.user.match_size = em->u.match_size;
154 169
 
155
-	et->u.target_size=TARGET_SZ;
156
-	et->u.user.target_size=et->u.target_size;
157
-	strcpy(et->u.user.name,MOD_CONNMARK);
170
+	et->u.target_size = TARGET_SZ;
171
+	et->u.user.target_size = et->u.target_size;
172
+	strcpy(et->u.user.name, MOD_CONNMARK);
158 173
 
159
-	ici->flags=1;
160
-	ici->statemask|=IPT_CONNTRACK_STATE_BIT(IP_CT_RELATED);
161
-	ici->statemask|=IPT_CONNTRACK_STATE_BIT(IP_CT_ESTABLISHED);
174
+	ici->flags = 1;
175
+	ici->statemask |= IPT_CONNTRACK_STATE_BIT(IP_CT_RELATED);
176
+	ici->statemask |= IPT_CONNTRACK_STATE_BIT(IP_CT_ESTABLISHED);
162 177
 
163
-	icmi->mode=IPT_CONNMARK_RESTORE;
164
-	icmi->mask= 0xffffffffUL;
178
+	icmi->mode = IPT_CONNMARK_RESTORE;
179
+	icmi->mask = 0xffffffffUL;
165 180
 }
181
+
166 182
 /*
167 183
  * Put in -rule- the netfilter rule:
168 184
  *
@@ -171,36 +187,38 @@ void restore_output_rule_init(char *rule)
171 187
  *
172 188
  * -rule- has to be NTK_FORWARD_RULE_SZ-sized
173 189
  */
174
-void ntk_forward_rule_init(char *rule)
190
+void
191
+ntk_forward_rule_init(char *rule)
175 192
 {
176 193
 	struct ipt_entry *ee;
177 194
 	struct ipt_entry_match *em;
178 195
 	struct ipt_entry_target *et;
179 196
 	struct ipt_conntrack_info *ici;
180 197
 
181
-	memset(rule,0,NTK_FORWARD_RULE_SZ);
198
+	memset(rule, 0, NTK_FORWARD_RULE_SZ);
182 199
 
183
-	ee=(struct ipt_entry*)(rule);
184
-	em=(struct ipt_entry_match*)(rule+IPT_ENTRY_SZ);
185
-	ici=(struct ipt_conntrack_info*)(rule+OFFSET_MATCH_INFO);
186
-	et=(struct ipt_entry_target*)(rule+OFFSET_TARGET);
200
+	ee = (struct ipt_entry *) (rule);
201
+	em = (struct ipt_entry_match *) (rule + IPT_ENTRY_SZ);
202
+	ici = (struct ipt_conntrack_info *) (rule + OFFSET_MATCH_INFO);
203
+	et = (struct ipt_entry_target *) (rule + OFFSET_TARGET);
187 204
 
188
-	ee->next_offset=NTK_FORWARD_RULE_SZ;
189
-	ee->target_offset=OFFSET_TARGET;
190
-	snprintf(ee->ip.outiface,IFNAMSIZ,"%s+",NTK_TUNL_PREFIX);
191
-	memset(ee->ip.outiface_mask,0xFF,strlen(ee->ip.outiface)-1);
205
+	ee->next_offset = NTK_FORWARD_RULE_SZ;
206
+	ee->target_offset = OFFSET_TARGET;
207
+	snprintf(ee->ip.outiface, IFNAMSIZ, "%s+", NTK_TUNL_PREFIX);
208
+	memset(ee->ip.outiface_mask, 0xFF, strlen(ee->ip.outiface) - 1);
192 209
 
193
-	strcpy(em->u.user.name,MOD_CONNTRACK);
194
-	em->u.match_size=MATCH_SZ;
195
-	em->u.user.match_size=em->u.match_size;
210
+	strcpy(em->u.user.name, MOD_CONNTRACK);
211
+	em->u.match_size = MATCH_SZ;
212
+	em->u.user.match_size = em->u.match_size;
196 213
 
197
-	ici->flags=1;
198
-	ici->statemask|=IPT_CONNTRACK_STATE_BIT(IP_CT_NEW);
214
+	ici->flags = 1;
215
+	ici->statemask |= IPT_CONNTRACK_STATE_BIT(IP_CT_NEW);
199 216
 
200
-	et->u.target_size=IPT_ENTRY_TARGET_SZ+4;
201
-	et->u.user.target_size=et->u.target_size;
202
-	strcpy(et->u.user.name,NTK_MARK_CHAIN);
217
+	et->u.target_size = IPT_ENTRY_TARGET_SZ + 4;
218
+	et->u.user.target_size = et->u.target_size;
219
+	strcpy(et->u.user.name, NTK_MARK_CHAIN);
203 220
 }
221
+
204 222
 /*
205 223
  * Put in -rule- the netfilter rule:
206 224
  *
@@ -210,31 +228,35 @@ void ntk_forward_rule_init(char *rule)
210 228
  *
211 229
  * -rule- has to be MARK_RULE_SZ-sized
212 230
  */
213
-void mark_rule_init(char *rule,char *outiface,int outiface_num)
231
+void
232
+mark_rule_init(char *rule, char *outiface, int outiface_num)
214 233
 {
215 234
 	struct ipt_entry *ee;
216 235
 	struct ipt_entry_target *et;
217 236
 	struct ipt_connmark_target_info *icmi;
218 237
 
219
-	memset(rule,0,MARK_RULE_SZ);
238
+	memset(rule, 0, MARK_RULE_SZ);
220 239
 
221
-	ee=(struct ipt_entry*)(rule);
222
-	et=(struct ipt_entry_target*)(rule+IPT_ENTRY_SZ);
223
-	icmi=(struct ipt_connmark_target_info*)(rule+IPT_ENTRY_SZ+IPT_ENTRY_TARGET_SZ);
240
+	ee = (struct ipt_entry *) (rule);
241
+	et = (struct ipt_entry_target *) (rule + IPT_ENTRY_SZ);
242
+	icmi =
243
+		(struct ipt_connmark_target_info *) (rule + IPT_ENTRY_SZ +
244
+											 IPT_ENTRY_TARGET_SZ);
224 245
 
225
-	ee->next_offset=MARK_RULE_SZ;
226
-	ee->target_offset=IPT_ENTRY_SZ;
246
+	ee->next_offset = MARK_RULE_SZ;
247
+	ee->target_offset = IPT_ENTRY_SZ;
227 248
 
228
-	et->u.target_size=TARGET_SZ;
229
-	et->u.user.target_size=et->u.target_size;
230
-	strcpy(et->u.user.name,MOD_CONNMARK);
249
+	et->u.target_size = TARGET_SZ;
250
+	et->u.user.target_size = et->u.target_size;
251
+	strcpy(et->u.user.name, MOD_CONNMARK);
231 252
 
232
-	icmi->mode=IPT_CONNMARK_SET;
233
-	icmi->mask= 0xffffffffUL;
234
-	snprintf(ee->ip.outiface,IFNAMSIZ,"%s%d",outiface,outiface_num);
235
-	memset(ee->ip.outiface_mask,0xFF,strlen(ee->ip.outiface));
236
-	icmi->mark=outiface_num+1;
253
+	icmi->mode = IPT_CONNMARK_SET;
254
+	icmi->mask = 0xffffffffUL;
255
+	snprintf(ee->ip.outiface, IFNAMSIZ, "%s%d", outiface, outiface_num);
256
+	memset(ee->ip.outiface_mask, 0xFF, strlen(ee->ip.outiface));
257
+	icmi->mark = outiface_num + 1;
237 258
 }
259
+
238 260
 /*
239 261
  * Put in -rule- the netfilter rule:
240 262
  *
@@ -244,51 +266,55 @@ void mark_rule_init(char *rule,char *outiface,int outiface_num)
244 266
  *
245 267
  * -rule- has to be IGW_FILTER_RULE_SZ-sized
246 268
  */
247
-void igw_mark_rule_init(char *rule)
269
+void
270
+igw_mark_rule_init(char *rule)
248 271
 {
249 272
 	int res;
250 273
 	struct ipt_entry *e;
251 274
 	struct ipt_entry_target *et;
252 275
 
253
-	memset(rule,0,IGW_FILTER_RULE_SZ);
254
-	e=(struct ipt_entry*)rule;
255
-	et=(struct ipt_entry_target*)(rule+IPT_ENTRY_SZ);
276
+	memset(rule, 0, IGW_FILTER_RULE_SZ);
277
+	e = (struct ipt_entry *) rule;
278
+	et = (struct ipt_entry_target *) (rule + IPT_ENTRY_SZ);
256 279
 
257
-	e->next_offset=IGW_FILTER_RULE_SZ;
258
-	e->target_offset=IPT_ENTRY_SZ;
259
-	snprintf(e->ip.iniface,IFNAMSIZ,"%s+",NTK_TUNL_PREFIX);
260
-	memset(e->ip.iniface_mask,0xFF,strlen(e->ip.iniface)-1);
280
+	e->next_offset = IGW_FILTER_RULE_SZ;
281
+	e->target_offset = IPT_ENTRY_SZ;
282
+	snprintf(e->ip.iniface, IFNAMSIZ, "%s+", NTK_TUNL_PREFIX);
283
+	memset(e->ip.iniface_mask, 0xFF, strlen(e->ip.iniface) - 1);
261 284
 
262
-	et->u.target_size=IPT_ENTRY_TARGET_SZ+4;
263
-	et->u.user.target_size=et->u.target_size;
264
-	strcpy(et->u.user.name,MARK_TARGET);
265
-	res=INET_MARK;
266
-	memcpy(et->data,&res,4);
285
+	et->u.target_size = IPT_ENTRY_TARGET_SZ + 4;
286
+	et->u.user.target_size = et->u.target_size;
287
+	strcpy(et->u.user.name, MARK_TARGET);
288
+	res = INET_MARK;
289
+	memcpy(et->data, &res, 4);
267 290
 }
291
+
268 292
 /*
269 293
  * Build the chain ntk_mark_chain on
270 294
  * mangle table.
271 295
  */
272
-int ntk_mark_chain_init(iptc_handle_t *t)
296
+int
297
+ntk_mark_chain_init(iptc_handle_t * t)
273 298
 {
274 299
 	int res;
275
-	res=iptc_is_chain(NTK_MARK_CHAIN,*t);
300
+	res = iptc_is_chain(NTK_MARK_CHAIN, *t);
276 301
 	if (res) {
277
-		debug(DBG_NORMAL,"In mark_init: bizarre, ntk mangle"
278
-				 "chain is present yet. it will be flushed.");
279
-		res=iptc_flush_entries(NTK_MARK_CHAIN,t);
302
+		debug(DBG_NORMAL, "In mark_init: bizarre, ntk mangle"
303
+			  "chain is present yet. it will be flushed.");
304
+		res = iptc_flush_entries(NTK_MARK_CHAIN, t);
280 305
 		if (!res)
281 306
 			goto dontwork;
282 307
 	} else {
283
-		res=iptc_create_chain(NTK_MARK_CHAIN,t);
308
+		res = iptc_create_chain(NTK_MARK_CHAIN, t);
284 309
 		if (!res)
285 310
 			goto dontwork;
286 311
 	}
287 312
 	return 0;
288
-dontwork:
313
+  dontwork:
289 314
 	error("In ntk_mark_chain_init: -> %s", iptc_strerror(errno));
290
-	err_ret(ERR_NETCHA,-1)
315
+	err_ret(ERR_NETCHA, -1)
291 316
 }
317
+
292 318
 /*
293 319
  * Takes committed rules and copies them
294 320
  * to structs. This is usefule to delete
@@ -298,94 +324,98 @@ dontwork:
298 324
  * 	0
299 325
  * 	-1
300 326
  */
301
-int store_rules()
327
+int
328
+store_rules()
302 329
 {
303 330
 	int res;
304 331
 	iptc_handle_t t;
305
-	struct ipt_entry *r,*f,*d;
332
+	struct ipt_entry *r, *f, *d;
306 333
 
307
-	res=table_init(MANGLE_TABLE,&t);
334
+	res = table_init(MANGLE_TABLE, &t);
308 335
 	if (res) {
309 336
 		error(err_str);
310
-		err_ret(ERR_NETSTO,-1);
337
+		err_ret(ERR_NETSTO, -1);
311 338
 	}
312
-	r=(struct ipt_entry*)iptc_first_rule(CHAIN_OUTPUT,&t);
313
-	f=(struct ipt_entry*)iptc_first_rule(CHAIN_POSTROUTING,&t);
339
+	r = (struct ipt_entry *) iptc_first_rule(CHAIN_OUTPUT, &t);
340
+	f = (struct ipt_entry *) iptc_first_rule(CHAIN_POSTROUTING, &t);
314 341
 	/* Not elegant style, but faster */
315 342
 	if (death_loop_rule) {
316
-		d=(struct ipt_entry*)iptc_first_rule(CHAIN_PREROUTING,&t);
343
+		d = (struct ipt_entry *) iptc_first_rule(CHAIN_PREROUTING, &t);
317 344
 		if (r && f && d) {
318
-			rr.sz=RESTORE_OUTPUT_RULE_SZ;
319
-			memcpy(rr.e,r,rr.sz);
320
-			rr.chain=CHAIN_OUTPUT;
321
-			fr.sz=NTK_FORWARD_RULE_SZ;
322
-			memcpy(fr.e,f,fr.sz);
323
-			fr.chain=CHAIN_POSTROUTING;
324
-			dr.sz=IGW_FILTER_RULE_SZ;
325
-			memcpy(dr.e,d,dr.sz);
326
-			dr.chain=CHAIN_PREROUTING;
327
-            error("This is store_rules, And the value of t is: %p", t);
328
-            commit_rules(&t);
345
+			rr.sz = RESTORE_OUTPUT_RULE_SZ;
346
+			memcpy(rr.e, r, rr.sz);
347
+			rr.chain = CHAIN_OUTPUT;
348
+			fr.sz = NTK_FORWARD_RULE_SZ;
349
+			memcpy(fr.e, f, fr.sz);
350
+			fr.chain = CHAIN_POSTROUTING;
351
+			dr.sz = IGW_FILTER_RULE_SZ;
352
+			memcpy(dr.e, d, dr.sz);
353
+			dr.chain = CHAIN_PREROUTING;
354
+			error("This is store_rules, And the value of t is: %p", t);
355
+			commit_rules(&t);
329 356
 			return 0;
330
-		}
331
-		else {
357
+		} else {
332 358
 
333
-            error("This is store_rules else, And the value of t is: %p", t);
359
+			error("This is store_rules else, And the value of t is: %p",
360
+				  t);
334 361
 			commit_rules(&t);
335
-			error("In store_rules: %s.",iptc_strerror(errno));
336
-			err_ret(ERR_NETSTO,-1);
362
+			error("In store_rules: %s.", iptc_strerror(errno));
363
+			err_ret(ERR_NETSTO, -1);
337 364
 		}
338 365
 	}
339
-	if (r && f ) {
340
-		rr.sz=RESTORE_OUTPUT_RULE_SZ;
341
-		memcpy(rr.e,r,rr.sz);
342
-		rr.chain=CHAIN_OUTPUT;
343
-		fr.sz=NTK_FORWARD_RULE_SZ;
344
-		memcpy(fr.e,f,fr.sz);
345
-		fr.chain=CHAIN_POSTROUTING;
366
+	if (r && f) {
367
+		rr.sz = RESTORE_OUTPUT_RULE_SZ;
368
+		memcpy(rr.e, r, rr.sz);
369
+		rr.chain = CHAIN_OUTPUT;
370
+		fr.sz = NTK_FORWARD_RULE_SZ;
371
+		memcpy(fr.e, f, fr.sz);
372
+		fr.chain = CHAIN_POSTROUTING;
346 373
 		commit_rules(&t);
347 374
 		return 0;
348 375
 	}
349 376
 	commit_rules(&t);
350
-	err_ret(ERR_NETSTO,-1);
377
+	err_ret(ERR_NETSTO, -1);
351 378
 }
352 379
 
353 380
 /* Two debugging functions: to delete */
354
-int dump_rules()
381
+int
382
+dump_rules()
355 383
 {
356 384
 	int fd;
357 385
 
358
-	fd=open(DATA_DIR"/mark_rules",O_CREAT | O_WRONLY | O_TRUNC,0540);
359
-	if (fd==-1) {
360
-		dumped=0;
386
+	fd = open(DATA_DIR "/mark_rules", O_CREAT | O_WRONLY | O_TRUNC, 0540);
387
+	if (fd == -1) {
388
+		dumped = 0;
361 389
 		error("Storing rules to fs: %s.", strerror(errno));
362 390
 		return -1;
363 391
 	}
364
-	write(fd,&rr,sizeof(rule_store));
365
-	write(fd,&fr,sizeof(rule_store));
366
-	write(fd,&dr,sizeof(rule_store));
392
+	write(fd, &rr, sizeof(rule_store));
393
+	write(fd, &fr, sizeof(rule_store));
394
+	write(fd, &dr, sizeof(rule_store));
367 395
 	close(fd);
368
-	dumped=1;
396
+	dumped = 1;
369 397
 	return 0;
370 398
 }
371
-int load_dump_rules()
399
+
400
+int
401
+load_dump_rules()
372 402
 {
373 403
 	int fd;
374
-	rule_store d_rr,d_fr,d_dr;
404
+	rule_store d_rr, d_fr, d_dr;
375 405
 	if (!dumped)
376 406
 		return 0;
377
-	fd=open("/usr/share/netsukuku/mark_rules",O_RDONLY );
378
-	if (fd==-1)
407
+	fd = open("/usr/share/netsukuku/mark_rules", O_RDONLY);
408
+	if (fd == -1)
379 409
 		return -1;
380
-	read(fd,&d_rr,sizeof(rule_store));
381
-	read(fd,&d_fr,sizeof(rule_store));
382
-	read(fd,&d_dr,sizeof(rule_store));
410
+	read(fd, &d_rr, sizeof(rule_store));
411
+	read(fd, &d_fr, sizeof(rule_store));
412
+	read(fd, &d_dr, sizeof(rule_store));
383 413
 	close(fd);
384
-	if (memcmp(&rr,&d_rr,sizeof(rule_store)))
414
+	if (memcmp(&rr, &d_rr, sizeof(rule_store)))
385 415
 		error("Stored rule rr differs from original.");
386
-	if (memcmp(&fr,&d_fr,sizeof(rule_store)))
416
+	if (memcmp(&fr, &d_fr, sizeof(rule_store)))
387 417
 		error("Stored rule fr differs from original.");
388
-	if (memcmp(&dr,&d_dr,sizeof(rule_store)))
418
+	if (memcmp(&dr, &d_dr, sizeof(rule_store)))
389 419
 		error("Stored rule dr differs from original.");
390 420
 	return 0;
391 421
 }
@@ -404,107 +434,112 @@ int load_dump_rules()
404 434
  *
405 435
  * If -1, any rule will be committed.
406 436
  */
407
-int mark_init(int igw)
437
+int
438
+mark_init(int igw)
408 439
 {
409 440
 	int res;
410 441
 	iptc_handle_t t;
411 442
 	char rule[MAX_RULE_SZ];
412 443
 
413 444
 	/*res=inet_aton(NTK_NET_STR,&inet_dst);
414
-	if (!res) {
415
-		error("Can not convert str to addr.");
416
-		goto cannot_init;
417
-	}
418
-	res=inet_aton(NTK_NET_MASK_STR,&inet_dst_mask);
419
-	if (!res) {
420
-		error("Can not convert str to addr.");
421
-		goto cannot_init;
422
-	}*/
423
-
424
-	res=table_init(MANGLE_TABLE,&t);
445
+	   if (!res) {
446
+	   error("Can not convert str to addr.");
447
+	   goto cannot_init;
448
+	   }
449
+	   res=inet_aton(NTK_NET_MASK_STR,&inet_dst_mask);
450
+	   if (!res) {
451
+	   error("Can not convert str to addr.");
452
+	   goto cannot_init;
453
+	   } */
454
+
455
+	res = table_init(MANGLE_TABLE, &t);
425 456
 	if (res) {
426 457
 		error(err_str);
427 458
 		goto cannot_init;
428 459
 	}
429
-	res=ntk_mark_chain_init(&t);
460
+	res = ntk_mark_chain_init(&t);
430 461
 	if (res) {
431 462
 		error(err_str);
432 463
 		error("Unable to create netfilter ntk_mark_chain.");
433 464
 		goto cannot_init;
434 465
 	}
435 466
 	restore_output_rule_init(rule);
436
-	res=insert_rule(rule,&t,CHAIN_OUTPUT,0);
467
+	res = insert_rule(rule, &t, CHAIN_OUTPUT, 0);
437 468
 	if (res) {
438 469
 		error(err_str);
439 470
 		error("Unable to create netfilter restore-marking rule.");
440 471
 		goto cannot_init;
441 472
 	}
442 473
 	ntk_forward_rule_init(rule);
443
-	res=insert_rule(rule,&t,CHAIN_POSTROUTING,0);
474
+	res = insert_rule(rule, &t, CHAIN_POSTROUTING, 0);
444 475
 	if (res) {
445 476
 		error(err_str);
446 477
 		error("Unable to create netfilter forwarding rule.");
447 478
 		goto cannot_init;
448 479
 	}
449 480
 	if (igw) {
450
-		death_loop_rule=1;
481
+		death_loop_rule = 1;
451 482
 		igw_mark_rule_init(rule);
452
-		res=insert_rule(rule,&t,CHAIN_PREROUTING,0);
483
+		res = insert_rule(rule, &t, CHAIN_PREROUTING, 0);
453 484
 		if (res) {
454 485
 			error(err_str);
455 486
 			error("Unable to create netfilter igw death loop rule.");
456
-			death_loop_rule=0;
487
+			death_loop_rule = 0;
457 488
 			goto cannot_init;
458 489
 		}
459
-	}
460
-	else
461
-		death_loop_rule=0;
490
+	} else
491
+		death_loop_rule = 0;
462 492
 
463
-	res=commit_rules(&t);
493
+	res = commit_rules(&t);
464 494
 	if (res) {
465 495
 		error(err_str);
466 496
 		error("Netfilter mangle table was not altered!");
467 497
 		goto cannot_init;
468 498
 	}
469
-	res=store_rules();
499
+	res = store_rules();
470 500
 	if (res) {
471 501
 		error(err_str);
472
-		error("Rules storing failed: autocleaning netfilter on exit disable.");
473
-		clean_on_exit=0;
474
-	}
475
-	else
476
-		clean_on_exit=1;
502
+		error
503
+			("Rules storing failed: autocleaning netfilter on exit disable.");
504
+		clean_on_exit = 0;
505
+	} else
506
+		clean_on_exit = 1;
477 507
 	dump_rules();
478
-	debug(DBG_NORMAL,"Netfilter chain ntk_mark_chain created (mangle).");
479
-	debug(DBG_NORMAL,"Netfilter restoring rule created (mangle->output).");
480
-	debug(DBG_NORMAL,"Netfilter forwarding rule created (mangle->postrouting).");
508
+	debug(DBG_NORMAL, "Netfilter chain ntk_mark_chain created (mangle).");
509
+	debug(DBG_NORMAL,
510
+		  "Netfilter restoring rule created (mangle->output).");
511
+	debug(DBG_NORMAL,
512
+		  "Netfilter forwarding rule created (mangle->postrouting).");
481 513
 	if (igw)
482
-		debug(DBG_NORMAL,"Netfilter death loop igw rule created.");
483
-	debug(DBG_NORMAL,"mark_init(), netfilter mangle table initialized.");
514
+		debug(DBG_NORMAL, "Netfilter death loop igw rule created.");
515
+	debug(DBG_NORMAL, "mark_init(), netfilter mangle table initialized.");
484 516
 	loginfo("Netfilter mangle table modified.");
485 517
 	return 0;
486
-cannot_init:
487
-	err_ret(ERR_MRKINI,-1);
518
+  cannot_init:
519
+	err_ret(ERR_MRKINI, -1);
488 520
 
489 521
 }
522
+
490 523
 /*
491 524
  * Count the number of rules in ntk_mangle_chain.
492 525
  *
493 526
  * Returns the number of rules present in
494 527
  * this chain.
495 528
  */
496
-int count_ntk_mark_chain(iptc_handle_t *t)
529
+int
530
+count_ntk_mark_chain(iptc_handle_t * t)
497 531
 {
498
-	int nchain=0;
532
+	int nchain = 0;
499 533
 	const struct ipt_entry *e;
500 534
 
501
-	e=iptc_first_rule(NTK_MARK_CHAIN,t);
535
+	e = iptc_first_rule(NTK_MARK_CHAIN, t);
502 536
 	while (e) {
503 537
 		nchain++;
504
-		e=iptc_next_rule(e,t);
538
+		e = iptc_next_rule(e, t);
505 539
 	}
506 540
 	return nchain;
507 541
 }
542
+
508 543
 /*
509 544
  * This function build the rules:
510 545
  *
@@ -523,43 +558,45 @@ int count_ntk_mark_chain(iptc_handle_t *t)
523 558
  * 	0
524 559
  * 	-1
525 560
  */
526
-int create_mark_rules(int n)
561
+int
562
+create_mark_rules(int n)
527 563
 {
528 564
 	int nchain;
529
-	int res,i;
565
+	int res, i;
530 566
 	char rule[MARK_RULE_SZ];
531 567
 	iptc_handle_t t;
532 568
 
533
-	res=table_init(MANGLE_TABLE,&t);
569
+	res = table_init(MANGLE_TABLE, &t);
534 570
 	if (res) {
535 571
 		error(err_str);
536
-		err_ret(ERR_NETRUL,-1);
572
+		err_ret(ERR_NETRUL, -1);
537 573
 	}
538
-	nchain=count_ntk_mark_chain(&t);
539
-	if (nchain==-1) {
574
+	nchain = count_ntk_mark_chain(&t);
575
+	if (nchain == -1) {
540 576
 		error("In create_mark_rules: can not read ntk_mark_chain.");
541
-		err_ret(ERR_NETRUL,-1);
577
+		err_ret(ERR_NETRUL, -1);
542 578
 	}
543
-	if (nchain>=n) {
544
-		debug(DBG_NORMAL,"In create_mark_rules: rules present yet.");
579
+	if (nchain >= n) {
580
+		debug(DBG_NORMAL, "In create_mark_rules: rules present yet.");
545 581
 		return 0;
546 582
 	}
547
-	for (i=nchain;i<n;i++) {
548
-		mark_rule_init(rule,NTK_TUNL_PREFIX,i);
549
-		res=append_rule(rule,&t,NTK_MARK_CHAIN);
583
+	for (i = nchain; i < n; i++) {
584
+		mark_rule_init(rule, NTK_TUNL_PREFIX, i);
585
+		res = append_rule(rule, &t, NTK_MARK_CHAIN);
550 586
 		if (res) {
551 587
 			error(err_str);
552
-			err_ret(ERR_NETRUL,-1);
588
+			err_ret(ERR_NETRUL, -1);
553 589
 		}
554 590
 	}
555
-	res=commit_rules(&t);
591
+	res = commit_rules(&t);
556 592
 	if (res) {
557 593
 		error(err_str);
558
-		err_ret(ERR_NETRUL,-1);
594
+		err_ret(ERR_NETRUL, -1);
559 595
 	}
560
-	debug(DBG_NORMAL,"Created %d marking rules.", n-nchain);
596
+	debug(DBG_NORMAL, "Created %d marking rules.", n - nchain);
561 597
 	return 0;
562 598
 }
599
+
563 600
 /*
564 601
  * Deltion function:
565 602
  * this delete the chain ntk_mark_chain
@@ -568,44 +605,48 @@ int create_mark_rules(int n)
568 605
  * 	-1
569 606
  */
570 607
 
571
-int delete_ntk_forward_chain(iptc_handle_t *t)
608
+int
609
+delete_ntk_forward_chain(iptc_handle_t * t)
572 610
 {
573 611
 	int res;
574 612
 
575
-	res=iptc_is_chain(NTK_MARK_CHAIN,*t);
613
+	res = iptc_is_chain(NTK_MARK_CHAIN, *t);
576 614
 	if (!res)
577 615
 		return 0;
578
-	res=iptc_flush_entries(NTK_MARK_CHAIN,t);
579
-        if (!res)
616
+	res = iptc_flush_entries(NTK_MARK_CHAIN, t);
617
+	if (!res)
580 618
 		goto cannot_delete;
581
-	res=iptc_delete_chain(NTK_MARK_CHAIN,t);
619
+	res = iptc_delete_chain(NTK_MARK_CHAIN, t);
582 620
 	if (!res)
583 621
 		goto cannot_delete;
584 622
 	return 0;
585 623
 
586
-cannot_delete:
624
+  cannot_delete:
587 625
 	error("In delete_ntk_forward_chain: -> %s", iptc_strerror(errno));
588
-	err_ret(ERR_NETDEL,-1);
626
+	err_ret(ERR_NETDEL, -1);
589 627
 }
628
+
590 629
 /* delete the first rule of a chain.
591 630
  * Unused.
592 631
  */
593
-int delete_first_rule(iptc_handle_t *t,const char *chain)
632
+int
633
+delete_first_rule(iptc_handle_t * t, const char *chain)
594 634
 {
595 635
 	int res;
596 636
 	const struct ipt_entry *e;
597 637
 
598
-	e=iptc_first_rule(chain,t);
638
+	e = iptc_first_rule(chain, t);
599 639
 	if (!e)
600 640
 		return 0;
601
-	res=iptc_delete_num_entry(chain,0,t);
641
+	res = iptc_delete_num_entry(chain, 0, t);
602 642
 	if (!res)
603 643
 		goto cannot_delete;
604 644
 	return 0;
605
-cannot_delete:
645
+  cannot_delete:
606 646
 	error("In delete_first_rule: -> %s", iptc_strerror(errno));
607
-	err_ret(ERR_NETDEL,-1);
647
+	err_ret(ERR_NETDEL, -1);
608 648
 }
649
+
609 650
 /*
610 651
  * Search for the position of rule -rule.rule-
611 652
  * on the chain rule.chain
@@ -613,23 +654,25 @@ cannot_delete:
613 654
  * 	pos if rule was found
614 655
  * 	-1  if rule wasn't found
615 656
  */
616
-int rule_position(rule_store *rule,iptc_handle_t *t)
657
+int
658
+rule_position(rule_store * rule, iptc_handle_t * t)
617 659
 {
618 660
 	const struct ipt_entry *e;
619
-	int res,count=-1,found=0;
661
+	int res, count = -1, found = 0;
620 662
 
621
-	e=iptc_first_rule(rule->chain,t);
663
+	e = iptc_first_rule(rule->chain, t);
622 664
 	while (e) {
623 665
 		count++;
624
-		res=memcmp(e,rule->e,rule->sz);
666
+		res = memcmp(e, rule->e, rule->sz);
625 667
 		if (!res) {
626
-			found=1;
668
+			found = 1;
627 669
 			break;
628 670
 		}
629
-		e=iptc_next_rule(e,t);
671
+		e = iptc_next_rule(e, t);
630 672
 	}
631
-	return found?count:-1;
673
+	return found ? count : -1;
632 674
 }
675
+
633 676
 /*
634 677
  * Delete rule -rule.rule- on chain rule.chain.
635 678
  * Returns
@@ -637,21 +680,24 @@ int rule_position(rule_store *rule,iptc_handle_t *t)
637 680
  * 		has to be deleted
638 681
  * 	-1 error
639 682
  */
640
-int delete_rule(rule_store *rule,iptc_handle_t *t)
683
+int
684
+delete_rule(rule_store * rule, iptc_handle_t * t)
641 685
 {
642
-	int pos,res;
643
-	pos=rule_position(rule,t);
644
-	if (pos==-1) {
645
-		debug(DBG_NORMAL,"No rule in %s to be deleted.",rule->chain);
686
+	int pos, res;
687
+	pos = rule_position(rule, t);
688
+	if (pos == -1) {
689
+		debug(DBG_NORMAL, "No rule in %s to be deleted.", rule->chain);
646 690
 		return 0;
647 691
 	}
648
-	res=iptc_delete_num_entry(rule->chain,pos,t);
692
+	res = iptc_delete_num_entry(rule->chain, pos, t);
649 693
 	if (!res) {
650
-		debug(DBG_NORMAL,"Unable to delete rule in chain %s.",rule->chain);
651
-		err_ret(ERR_NETDEL,-1);
694
+		debug(DBG_NORMAL, "Unable to delete rule in chain %s.",
695
+			  rule->chain);
696
+		err_ret(ERR_NETDEL, -1);
652 697
 	}
653 698
 	return 0;
654 699
 }
700
+
655 701
 /*
656 702
  * clean the rules committed by:
657 703
  * 	- mark_init
@@ -661,40 +707,42 @@ int delete_rule(rule_store *rule,iptc_handle_t *t)
661 707
  * 	-1
662 708
  */
663 709
 
664
-int mark_close()
710
+int
711
+mark_close()
665 712
 {
666 713
 	iptc_handle_t t;
667 714
 	int res;
668 715
 
669 716
 	if (!clean_on_exit) {
670
-		debug(DBG_NORMAL,"mark_close: cleaning is not my task.");
717
+		debug(DBG_NORMAL, "mark_close: cleaning is not my task.");
671 718
 		return 0;
672 719
 	}
673 720
 	load_dump_rules();
674
-	res=table_init(MANGLE_TABLE,&t);
721
+	res = table_init(MANGLE_TABLE, &t);
675 722
 	if (res)
676 723
 		goto reset_error;
677
-	res=0;
678
-	res+=delete_rule(&rr,&t);
679
-	res+=delete_rule(&fr,&t);
724
+	res = 0;
725
+	res += delete_rule(&rr, &t);
726
+	res += delete_rule(&fr, &t);
680 727
 	if (death_loop_rule) {
681
-		debug(DBG_INSANE,"In mark_close: I'm an IGW: deleting death loop rule.");
682
-		res+=delete_rule(&dr,&t);
728
+		debug(DBG_INSANE,
729
+			  "In mark_close: I'm an IGW: deleting death loop rule.");
730
+		res += delete_rule(&dr, &t);
683 731
 	}
684 732
 	if (res)
685 733
 		goto reset_error;
686
-	res=delete_ntk_forward_chain(&t);
734
+	res = delete_ntk_forward_chain(&t);
687 735
 	if (res)
688 736
 		goto reset_error;
689
-	res=commit_rules(&t);
737
+	res = commit_rules(&t);
690 738
 	if (res)
691 739
 		goto reset_error;
692
-	debug(DBG_NORMAL,"Netfilter completely restored.");
740
+	debug(DBG_NORMAL, "Netfilter completely restored.");
693 741
 	return 0;
694
-reset_error:
742
+  reset_error:
695 743
 	error(err_str);
696 744
 	loginfo("Netfilter was not restored. To clean, run:\n"
697
-		"\tiptables -t mangle -F\n"
698
-		"\tiptables -t mangle -X %s",NTK_MARK_CHAIN);
699
-	err_ret(ERR_NETRST,-1);
745
+			"\tiptables -t mangle -F\n"
746
+			"\tiptables -t mangle -X %s", NTK_MARK_CHAIN);
747
+	err_ret(ERR_NETRST, -1);
700 748
 }

+ 0
- 0
src/mark.h View File


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

Loading…
Cancel
Save