fa571068ef4d37c04938ff7f22714eecac1ddc99
[feed/routing.git] / files / olsrd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 Alina Friedrichsen <x-alina@gmx.net>
3 # Special thanks to bittorf wireless ))
4
5 START=65
6 BIN=/usr/sbin/olsrd
7 CONF=/var/etc/olsrd.conf
8 PID=/var/run/olsrd.pid
9 PID6=/var/run/olsrd.ipv6.pid
10
11 OLSRD_OLSRD_SCHEMA='ignore:internal config_file:internal DebugLevel=0 AllowNoInt=yes'
12 OLSRD_IPCCONNECT_SCHEMA='ignore:internal Host:list Net:list2'
13 OLSRD_LOADPLUGIN_SCHEMA='ignore:internal library:internal Host4:list Net4:list2 Host:list Net:list2 Host6:list Net6:list2 Ping:list redistribute:list NonOlsrIf:list name:list lat lon latlon_infile HNA:list2 hosts:list2'
14 OLSRD_INTERFACE_SCHEMA='ignore:internal interface:internal AutoDetectChanges:bool'
15 OLSRD_INTERFACE_DEFAULTS_SCHEMA='AutoDetectChanges:bool'
16
17 T=' '
18 N='
19 '
20
21 validate_varname() {
22 local varname="$1"
23 [ -z "$varname" -o "$varname" != "${varname%%[!A-Za-z0-9_]*}" ] && return 1
24 return 0
25 }
26
27 validate_ifname() {
28 local ifname="$1"
29 [ -z "$ifname" -o "$ifname" != "${ifname%%[!A-Za-z0-9.:_-]*}" ] && return 1
30 return 0
31 }
32
33 validate_olsrd_option() {
34 local str="$1"
35 [ -z "$str" -o "$str" != "${str%%[! 0-9A-Za-z./|:_-]*}" ] && return 1
36 return 0
37 }
38
39 get_ifname() {
40 IFNAME=
41 local interface="$1"
42 validate_varname "$interface" || return 1
43 local ifname
44
45 config_get ifname "$interface" ifname
46 validate_ifname "$ifname" || return 1
47 IFNAME="$ifname"
48 return 0
49 }
50
51 system_config() {
52 local cfg="$1"
53 local cfgt
54 local hostname
55 local latlon
56
57 config_get cfgt "$cfg" TYPE
58
59 if [ "$cfgt" = "system" ]; then
60 config_get hostname "$cfg" hostname
61 hostname="${hostname:-OpenWrt}"
62 SYSTEM_HOSTNAME="$hostname"
63 fi
64
65 if [ -z "$SYSTEM_LAT" -o -z "$SYSTEM_LON" ]; then
66 config_get latlon "$cfg" latlon
67 IFS=" ${T}${N},"
68 set -- $latlon
69 unset IFS
70 SYSTEM_LAT="$1"
71 SYSTEM_LON="$2"
72 fi
73
74 if [ -z "$SYSTEM_LAT" -o -z "$SYSTEM_LON" ]; then
75 config_get latlon "$cfg" latitude
76 SYSTEM_LAT="$latlon"
77 config_get latlon "$cfg" longitude
78 SYSTEM_LON="$latlon"
79 fi
80 }
81
82 olsrd_find_config_file() {
83 local cfg="$1"
84 validate_varname "$cfg" || return 0
85
86 config_get_bool ignore "$cfg" ignore 0
87 [ "$ignore" -ne 0 ] && return 0
88 config_get OLSRD_CONFIG_FILE "$cfg" config_file
89
90 return 0
91 }
92
93 warning_invalid_value() {
94 local package="$1"
95 validate_varname "$package" || package=
96 local config="$2"
97 validate_varname "$config" || config=
98 local option="$3"
99 validate_varname "$option" || option=
100
101 echo -n "Warning: Invalid value" 1>&2
102
103 if [ -n "$package" -a -n "$config" ]; then
104 echo -n " in option '$package.$config${option:+.}$option'" 1>&2
105 fi
106
107 echo ", skipped" 1>&2
108
109 return 0
110 }
111
112 olsrd_write_option() {
113 local param="$1"
114 local cfg="$2"
115 validate_varname "$cfg" || return 1
116 local option="$3"
117 validate_varname "$option" || return 1
118 local value="$4"
119 local option_type="$5"
120
121 if [ "$option_type" = bool ]; then
122 case "$value" in
123 1|on|true|enabled|yes) value=yes;;
124 0|off|false|disabled|no) value=no;;
125 *) warning_invalid_value olsrd "$cfg" "$option"; return 1;;
126 esac
127 fi
128
129 if ! validate_olsrd_option "$value"; then
130 warning_invalid_value olsrd "$cfg" "$option"
131 return 1
132 fi
133
134 if [ "$value" != "${value%%[G-Zg-z_-]*}" ]; then
135 if [ "$option" != "Ip6AddrType" -a "$option" != "LinkQualityMult" -a "$value" != "yes" -a "$value" != "no" ]; then
136 value="\"$value\""
137 fi
138 fi
139
140 echo -n "${N}$param$option $value"
141
142 return 0
143 }
144
145 olsrd_write_plparam() {
146 local param="$1"
147 local cfg="$2"
148 validate_varname "$cfg" || return 1
149 local option="$3"
150 validate_varname "$option" || return 1
151 local value="$4"
152 local option_type="$5"
153 local _option
154
155 if [ "$option_type" = bool ]; then
156 case "$value" in
157 1|on|true|enabled|yes) value=yes;;
158 0|off|false|disabled|no) value=no;;
159 *) warning_invalid_value olsrd "$cfg" "$option"; return 1;;
160 esac
161 fi
162
163 if ! validate_olsrd_option "$value"; then
164 warning_invalid_value olsrd "$cfg" "$option"
165 return 1
166 fi
167
168 IFS='-_'
169 set -- $option
170 option="$*"
171 unset IFS
172 _option="$option"
173 if [ "$option" = 'hosts' ]; then
174 set -- $value
175 option="$1"
176 shift
177 value="$*"
178 fi
179 if [ "$option" = 'NonOlsrIf' ]; then
180 if validate_varname "$value"; then
181 if get_ifname "$value"; then
182 ifname="$IFNAME"
183 echo "Info: mdns Interface '$value' ifname '$ifname' found" 1>&2
184 else
185 echo "Warning: mdns Interface '$value' not found, skipped" 1>&2
186 fi
187 else
188 warning_invalid_value olsrd "$cfg" "NonOlsrIf"
189 fi
190 [ -z "$ifname" ] || value=$ifname
191 fi
192
193 echo -n "${N}${param}PlParam \"$option\" \"$value\""
194
195 return 0
196 }
197
198 config_update_schema() {
199 unset IFS
200 local schema_varname="$1"
201 validate_varname "$schema_varname" || return 1
202 local command="$2"
203 validate_varname "$command" || return 1
204 local option="$3"
205 validate_varname "$option" || return 1
206 local value="$4"
207 local schema
208 local cur_option
209
210 case "$varname" in
211 *_LENGTH) return 0;;
212 *_ITEM*) return 0;;
213 esac
214
215 eval "export -n -- \"schema=\${$schema_varname}\""
216
217 for cur_option in $schema; do
218 [ "${cur_option%%[:=]*}" = "$option" ] && return 0
219 done
220
221 if [ "$command" = list ]; then
222 set -- $value
223 if [ "$#" -ge "3" ]; then
224 schema_entry="$option:list3"
225 elif [ "$#" -ge "2" ]; then
226 schema_entry="$option:list2"
227 else
228 schema_entry="$option:list"
229 fi
230 else
231 schema_entry="$option"
232 fi
233
234 append "$schema_varname" "$schema_entry"
235
236 return 0
237 }
238
239 config_write_options() {
240 unset IFS
241 local schema="$1"
242 local cfg="$2"
243 validate_varname "$cfg" || return 1
244 local write_func="$3"
245 [ -z "$write_func" ] && output_func=echo
246 local write_param="$4"
247 local schema_entry
248 local option
249 local option_length
250 local option_type
251 local default
252 local value
253 local list_size
254 local list_item
255 local list_value
256 local i
257 local position
258
259 for schema_entry in $schema; do
260 default="${schema_entry#*[=]}"
261 [ "$default" = "$schema_entry" ] && default=
262 option="${schema_entry%%[=]*}"
263 IFS=':'
264 set -- $option
265 unset IFS
266 option="$1"
267 option_type="$2"
268 validate_varname "$option" || continue
269 [ -z "$option_type" ] || validate_varname "$option_type" || continue
270 [ "$option_type" = internal ] && continue
271 config_get value "$cfg" "$option"
272
273 if [ -z "$value" ]; then
274 IFS='+'
275 set -- $default
276 unset IFS
277 value=$*
278 elif [ "$value" = '-' -a -n "$default" ]; then
279 continue
280 fi
281
282 [ -z "$value" ] && continue
283
284 case "$option_type" in
285 list) list_size=1;;
286 list2) list_size=2;;
287 list3) list_size=3;;
288 *) list_size=0;;
289 esac
290
291 if [ "$list_size" -gt 0 ]; then
292 config_get option_length "$cfg" "${option}_LENGTH"
293 if [ -n "$option_length" ]; then
294 i=1
295 while [ "$i" -le "$option_length" ]; do
296 config_get list_value "$cfg" "${option}_ITEM$i"
297 "$write_func" "$write_param" "$cfg" "$option" "$list_value" "$option_type" || break
298 i=$((i + 1))
299 done
300 else
301 list_value=
302 i=0
303 for list_item in $value; do
304 append "list_value" "$list_item"
305 i=$((i + 1))
306 position=$((i % list_size))
307 if [ "$position" -eq 0 ]; then
308 "$write_func" "$write_param" "$cfg" "$option" "$list_value" "$option_type" || break
309 list_value=
310 fi
311 done
312 [ "$position" -ne 0 ] && "$write_func" "$write_param" "$cfg" "$option" "$list_value" "$option_type"
313 fi
314 else
315 "$write_func" "$write_param" "$cfg" "$option" "$value" "$option_type"
316 fi
317 done
318
319 return 0
320 }
321
322 olsrd_write_olsrd() {
323 local cfg="$1"
324 validate_varname "$cfg" || return 0
325 local ignore
326
327 config_get_bool ignore "$cfg" ignore 0
328 [ "$ignore" -ne 0 ] && return 0
329
330 [ "$OLSRD_COUNT" -gt 0 ] && return 0
331
332 config_get ipversion "$cfg" IpVersion
333 if [ "$ipversion" = "6and4" ]; then
334 OLSRD_IPVERSION_6AND4=1
335 config_set "$cfg" IpVersion '6'
336 fi
337 config_get smartgateway "$cfg" SmartGateway
338 config_get smartgatewayuplink "$cfg" SmartGatewayUplink
339
340 config_write_options "$OLSRD_OLSRD_SCHEMA" "$cfg" olsrd_write_option
341 echo
342 OLSRD_COUNT=$((OLSRD_COUNT + 1))
343 return 0
344 }
345
346 olsrd_write_ipcconnect() {
347 local cfg="$1"
348 validate_varname "$cfg" || return 0
349 local ignore
350
351 config_get_bool ignore "$cfg" ignore 0
352 [ "$ignore" -ne 0 ] && return 0
353
354 [ "$IPCCONNECT_COUNT" -gt 0 ] && return 0
355
356 echo -n "${N}IpcConnect${N}{"
357 config_write_options "$OLSRD_IPCCONNECT_SCHEMA" "$cfg" olsrd_write_option "${T}"
358 echo "${N}}"
359 IPCCONNECT_COUNT=$((IPCCONNECT_COUNT + 1))
360
361 return 0
362 }
363
364 olsrd_write_hna4() {
365 local cfg="$1"
366 validate_varname "$cfg" || return 0
367 local ignore
368
369 config_get_bool ignore "$cfg" ignore 0
370 [ "$ignore" -ne 0 ] && return 0
371
372 config_get netaddr "$cfg" netaddr
373 if ! validate_olsrd_option "$netaddr"; then
374 warning_invalid_value olsrd "$cfg" "netaddr"
375 return 0
376 fi
377
378 config_get netmask "$cfg" netmask
379 if ! validate_olsrd_option "$netmask"; then
380 warning_invalid_value olsrd "$cfg" "netmask"
381 return 0
382 fi
383
384 [ "$HNA4_COUNT" -le 0 ] && echo -n "${N}Hna4${N}{"
385 echo -n "${N}${T}${T}$netaddr $netmask"
386 HNA4_COUNT=$((HNA4_COUNT + 1))
387
388 return 0
389 }
390
391 olsrd_write_hna6() {
392 local cfg="$1"
393 validate_varname "$cfg" || return 0
394 local ignore
395
396 config_get_bool ignore "$cfg" ignore 0
397 [ "$ignore" -ne 0 ] && return 0
398
399 config_get netaddr "$cfg" netaddr
400 if ! validate_olsrd_option "$netaddr"; then
401 warning_invalid_value olsrd "$cfg" "netaddr"
402 return 0
403 fi
404
405 config_get prefix "$cfg" prefix
406 if ! validate_olsrd_option "$prefix"; then
407 warning_invalid_value olsrd "$cfg" "prefix"
408 return 0
409 fi
410
411 [ "$HNA6_COUNT" -le 0 ] && echo -n "${N}Hna6${N}{"
412 echo -n "${N}${T}${T}$netaddr $prefix"
413 HNA6_COUNT=$((HNA6_COUNT + 1))
414
415 return 0
416 }
417
418 olsrd_write_loadplugin() {
419 local cfg="$1"
420 validate_varname "$cfg" || return 0
421 local ignore
422 local name
423 local suffix
424 local lat
425 local lon
426 local latlon_infile
427
428 config_get_bool ignore "$cfg" ignore 0
429 [ "$ignore" -ne 0 ] && return 0
430
431 config_get library "$cfg" library
432 if ! validate_olsrd_option "$library"; then
433 warning_invalid_value olsrd "$cfg" "library"
434 return 0
435 fi
436 if ! [ -x "/lib/$library" -o -x "/usr/lib/$library" -o -x "/usr/local/lib/$library" ]; then
437 echo "Warning: Plugin library '$library' not found, skipped" 1>&2
438 return 0
439 fi
440
441 case "$library" in
442 olsrd_nameservice.*)
443 config_get name "$cfg" name
444 [ -z "$name" ] && config_set "$cfg" name $SYSTEM_HOSTNAME
445
446 config_get suffix "$cfg" suffix
447 [ -z "$suffix" ] && config_set "$cfg" suffix '.olsr'
448
449 config_get lat "$cfg" lat
450 config_get lon "$cfg" lon
451 config_get latlon_infile "$cfg" latlon_infile
452 if [ \( -z "$lat" -o -z "$lat" \) -a -z "$latlon_infile" ]; then
453 if [ -f '/var/run/latlon.txt' ]; then
454 config_set "$cfg" lat ''
455 config_set "$cfg" lon ''
456 config_set "$cfg" latlon_infile '/var/run/latlon.txt'
457 else
458 config_set "$cfg" lat "$SYSTEM_LAT"
459 config_set "$cfg" lon "$SYSTEM_LON"
460 fi
461 fi
462
463 for f in latlon_file hosts_file services_file resolv_file macs_file; do
464 config_get $f "$cfg" $f
465 done
466
467 [ -z "$latlon_file" ] && config_set "$cfg" latlon_file '/var/run/latlon.js'
468 ;;
469 olsrd_watchdog.*)
470 config_get wd_file "$cfg" file
471 ;;
472 esac
473
474 echo -n "${N}LoadPlugin \"$library\"${N}{"
475 config_write_options "$OLSRD_LOADPLUGIN_SCHEMA" "$cfg" olsrd_write_plparam "${T}"
476 echo "${N}}"
477
478 return 0
479 }
480
481 olsrd_write_interface() {
482 local cfg="$1"
483 validate_varname "$cfg" || return 0
484 local ignore
485 local interfaces
486 local interface
487 local ifnames
488
489 config_get_bool ignore "$cfg" ignore 0
490 [ "$ignore" -ne 0 ] && return 0
491
492 ifnames=
493 config_get interfaces "$cfg" interface
494 for interface in $interfaces; do
495 if validate_varname "$interface"; then
496 if get_ifname "$interface"; then
497 ifnames="$ifnames \"$IFNAME\""
498 ifsglobal="$ifsglobal $IFNAME"
499 else
500 echo "Warning: Interface '$interface' not found, skipped" 1>&2
501 fi
502 else
503 warning_invalid_value olsrd "$cfg" "interface"
504 fi
505 done
506
507 [ -z "$ifnames" ] && return 0
508
509 echo -n "${N}Interface$ifnames${N}{"
510 config_write_options "$OLSRD_INTERFACE_SCHEMA" "$cfg" olsrd_write_option "${T}"
511 echo "${N}}"
512 INTERFACES_COUNT=$((INTERFACES_COUNT + 1))
513
514 return 0
515 }
516
517 olsrd_write_interface_defaults() {
518 local cfg="$1"
519 validate_varname "$cfg" || return 0
520
521 echo -n "${N}InterfaceDefaults$ifnames${N}{"
522 config_write_options "$OLSRD_INTERFACE_DEFAULTS_SCHEMA" "$cfg" olsrd_write_option "${T}"
523 echo "${N}}"
524
525 return 1
526 }
527
528 olsrd_update_schema() {
529 local command="$1"
530 validate_varname "$command" || return 0
531 local varname="$2"
532 validate_varname "$varname" || return 0
533 local value="$3"
534 local cfg="$CONFIG_SECTION"
535 local cfgt
536 local cur_varname
537
538 config_get cfgt "$cfg" TYPE
539 case "$cfgt" in
540 olsrd) config_update_schema OLSRD_OLSRD_SCHEMA "$command" "$varname" "$value";;
541 IpcConnect) config_update_schema OLSRD_IPCCONNECT_SCHEMA "$command" "$varname" "$value";;
542 LoadPlugin) config_update_schema OLSRD_LOADPLUGIN_SCHEMA "$command" "$varname" "$value";;
543 Interface) config_update_schema OLSRD_INTERFACE_SCHEMA "$command" "$varname" "$value";;
544 InterfaceDefaults) config_update_schema OLSRD_INTERFACE_DEFAULTS_SCHEMA "$command" "$varname" "$value";;
545 esac
546
547 return 0
548 }
549
550 olsrd_write_config() {
551 OLSRD_IPVERSION_6AND4=0
552 OLSRD_COUNT=0
553 config_foreach olsrd_write_olsrd olsrd
554 IPCCONNECT_COUNT=0
555 config_foreach olsrd_write_ipcconnect IpcConnect
556 HNA4_COUNT=0
557 config_foreach olsrd_write_hna4 Hna4
558 [ "$HNA4_COUNT" -gt 0 ] && echo "${N}}"
559 HNA6_COUNT=0
560 config_foreach olsrd_write_hna6 Hna6
561 [ "$HNA6_COUNT" -gt 0 ] && echo "${N}}"
562 config_foreach olsrd_write_loadplugin LoadPlugin
563 INTERFACES_COUNT=0
564 config_foreach olsrd_write_interface_defaults InterfaceDefaults
565 config_foreach olsrd_write_interface Interface
566 echo
567
568 return 0
569 }
570
571 olsrd_setup_smartgw_rules() {
572 # Check if ipip is installed
573 [ ! -e /etc/modules.d/[0-9]*-ipip ] && echo "Warning: kmod-ipip is missing. SmartGateway will not work until you install it."
574
575 wanifnames=$(ip r l e 0/0 t all | sed -e 's/^.* dev //' |cut -d " " -f 1 | sort | uniq)
576 nowan=0
577 if [ -z "$wanifnames" ]; then
578 nowan=1
579 fi
580
581 IP4T=$(which iptables)
582 IP6T=$(which ip6tables)
583
584 # Delete smartgw firewall rules first
585 for IPT in $IP4T $IP6T; do
586 while $IPT -D forwarding_rule -o tnl_+ -j ACCEPT 2> /dev/null; do :;done
587 for IFACE in $wanifnames; do
588 while $IPT -D forwarding_rule -i tunl0 -o $IFACE -j ACCEPT 2> /dev/null; do :; done
589 done
590 for IFACE in $ifsglobal; do
591 while $IPT -D input_rule -i $IFACE -p 4 -j ACCEPT 2> /dev/null; do :; done
592 done
593 done
594 while $IP4T -t nat -D postrouting_rule -o tnl_+ -j MASQUERADE 2> /dev/null; do :;done
595
596 if [ "$smartgateway" == "yes" ]; then
597 echo "Notice: Inserting firewall rules for SmartGateway"
598 if [ ! "$smartgatewayuplink" == "none" ]; then
599 if [ "$smartgatewayuplink" == "ipv4" ]; then
600 # Allow everything to be forwarded to tnl_+ and use NAT for it
601 $IP4T -I forwarding_rule -o tnl_+ -j ACCEPT
602 $IP4T -t nat -I postrouting_rule -o tnl_+ -j MASQUERADE
603 # Allow forwarding from tunl0 to (all) wan-interfaces
604 if [ "$nowan"="0" ]; then
605 for IFACE in $wanifnames; do
606 $IP4T -A forwarding_rule -i tunl0 -o $IFACE -j ACCEPT
607 done
608 fi
609 # Allow incoming ipip on all olsr-interfaces
610 for IFACE in $ifsglobal; do
611 $IP4T -I input_rule -i $IFACE -p 4 -j ACCEPT
612 done
613 elif [ "$smartgatewayuplink" == "ipv6" ]; then
614 $IP6T -I forwarding_rule -o tnl_+ -j ACCEPT
615 if [ "$nowan"="0" ]; then
616 for IFACE in $wanifnames; do
617 $IP6T -A forwarding_rule -i tunl0 -o $IFACE -j ACCEPT
618 done
619 fi
620 for IFACE in $ifsglobal; do
621 $IP6T -I input_rule -i $IFACE -p 4 -j ACCEPT
622 done
623 else
624 for IPT in $IP4T $IP6T; do
625 $IPT -I forwarding_rule -o tnl_+ -j ACCEPT
626 $IPT -t nat -I postrouting_rule -o tnl_+ -j MASQUERADE
627 if [ "$nowan"="0" ]; then
628 for IFACE in $wanifnames; do
629 $IPT -A forwarding_rule -i tunl0 -o $IFACE -j ACCEPT
630 done
631 fi
632 for IFACE in $ifsglobal; do
633 $IPT -I input_rule -i $IFACE -p 4 -j ACCEPT
634 done
635 done
636 fi
637 fi
638 fi
639 }
640
641 start() {
642 SYSTEM_HOSTNAME=
643 SYSTEM_LAT=
644 SYSTEM_LON=
645 config_load system
646 config_foreach system_config system
647
648 option_cb() {
649 olsrd_update_schema "option" "$@"
650 }
651
652 list_cb() {
653 olsrd_update_schema "list" "$@"
654 }
655
656 include /lib/network
657 scan_interfaces
658 config_load olsrd
659 reset_cb
660
661 OLSRD_CONFIG_FILE=
662 config_foreach olsrd_find_config_file olsrd
663
664 if [ -z "$OLSRD_CONFIG_FILE" ]; then
665 mkdir -p -- /var/etc/
666 olsrd_write_config > /var/etc/olsrd.conf
667 if [ "$INTERFACES_COUNT" -gt 0 -a "$OLSRD_COUNT" -gt 0 ]; then
668 OLSRD_CONFIG_FILE=/var/etc/olsrd.conf
669 fi
670 fi
671
672 [ -z "$OLSRD_CONFIG_FILE" ] && return 1
673
674 local bindv6only='0'
675 if [ "$OLSRD_IPVERSION_6AND4" -ne 0 ]; then
676 bindv6only="$(sysctl -n net.ipv6.bindv6only)"
677 sysctl -w net.ipv6.bindv6only=1 > /dev/null
678 sed -e '/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/d' < "$OLSRD_CONFIG_FILE" > /var/etc/olsrd.conf.ipv6
679 sed -e 's/^IpVersion[ ][ ]*6$/IpVersion 4/' -e 's/^\t\t[A-Fa-f0-9.:]*[:][A-Fa-f0-9.:]*[ ][0-9]*$//' < "$OLSRD_CONFIG_FILE" > /var/etc/olsrd.conf.ipv4
680 rm $OLSRD_CONFIG_FILE
681
682 # some filenames should get the suffix .ipv6
683 for file in $latlon_file $hosts_file $services_file $resolv_file $macs_file $wd_file;do
684 f=$(echo $file|sed 's/\//\\\//g')
685 sed -i "s/$f/$f.ipv6/g" /var/etc/olsrd.conf.ipv6
686 done
687
688 if ([ -s $PID6 ] && kill -0 $(cat $PID6) 2>&-); then
689 echo "Error: There already is a IPv6 instance of olsrd running ($(cat $PID6)), not starting."
690 else
691 start-stop-daemon -q -b -m -p $PID6 -x $BIN -S -- -f /var/etc/olsrd.conf.ipv6 -nofork
692 fi
693
694 if ([ -s $PID ] && kill -0 $(cat $PID) 2>&-); then
695 echo "Error: There already is a IPv4 instance of olsrd running ($(cat $PID)), not starting."
696 else
697 start-stop-daemon -q -b -m -p $PID -x $BIN -S -- -f /var/etc/olsrd.conf.ipv4 -nofork
698 fi
699
700 sleep 3
701 sysctl -w net.ipv6.bindv6only="$bindv6only" > /dev/null
702
703 else
704
705 if [ "$ipversion" = "6" ]; then
706 sed -i '/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/d' "$OLSRD_CONFIG_FILE"
707 fi
708
709 ### check for running instance
710 if ([ -s $PID ] && kill -0 $(cat $PID) 2>&-); then
711 echo "Error: There already is a instance of olsrd running ($(cat $PID)), exiting now."
712 return 1
713 else
714 start-stop-daemon -q -b -m -p $PID -x $BIN -S -- -f "$OLSRD_CONFIG_FILE" -nofork
715 fi
716 fi
717 olsrd_setup_smartgw_rules
718 }
719
720 stop() {
721 start-stop-daemon -q -p $PID -x $BIN -K
722 start-stop-daemon -q -p $PID6 -x $BIN -K
723 test -s $PID && rm $PID
724 test -s $PID6 && rm $PID6
725 }