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