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