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