347e3076f23c2c6392ba7651ec775ddf66399a69
[openwrt/svn-archive/archive.git] / net / batman-adv / files / lib / batman-adv / config.sh
1 #!/bin/sh
2 # Copyright (C) 2011 OpenWrt.org
3
4 is_module_loaded() {
5
6 if [ ! -d "/sys/module/batman_adv" ]; then
7 echo "batman-adv module directory not found - was the kernel module loaded ?" >&2
8 return 0
9 fi
10
11 return 1
12 }
13
14 start_mesh () {
15 local meshif="$1"
16 local interfaces aggregated_ogms bonding fragmentation gw_bandwidth gw_mode gw_sel_class log_level orig_interval vis_mode
17
18 is_module_loaded
19 [ $? -ne 1 ] && return
20
21 config_get interfaces "$meshif" interfaces
22 config_get aggregated_ogms "$meshif" aggregated_ogms
23 config_get bonding "$meshif" bonding
24 config_get fragmentation "$meshif" fragmentation
25 config_get gw_bandwidth "$meshif" gw_bandwidth
26 config_get gw_mode "$meshif" gw_mode
27 config_get gw_sel_class "$meshif" gw_sel_class
28 config_get log_level "$meshif" log_level
29 config_get orig_interval "$meshif" orig_interval
30 config_get vis_mode "$meshif" vis_mode
31
32 if [ "$interfaces" = "" ]; then
33 echo Error, you must specify at least a network interface
34 return
35 fi
36
37 for interface in $interfaces
38 do
39 ifname=$(uci -P /var/state get network.$interface.ifname 2>&-)
40 [ ! -f "/sys/class/net/$ifname/batman_adv/mesh_iface" ] && {
41 ifname=${interface}
42 [ ! -f "/sys/class/net/$ifname/batman_adv/mesh_iface" ] && echo "Can't add interface $ifname - ignoring" && continue
43 }
44
45 echo $meshif > /sys/class/net/$ifname/batman_adv/mesh_iface
46 done
47
48 if [ $orig_interval ]; then
49 echo $orig_interval > /sys/class/net/$meshif/mesh/orig_interval
50 fi
51
52 if [ $log_level ]; then
53 echo $log_level > /sys/class/net/$meshif/mesh/log_level 2>&-
54 fi
55
56 if [ $aggregated_ogms ]; then
57 echo $aggregated_ogms > /sys/class/net/$meshif/mesh/aggregated_ogms
58 fi
59
60 if [ $bonding ]; then
61 echo $bonding > /sys/class/net/$meshif/mesh/bonding
62 fi
63
64 if [ $fragmentation ]; then
65 echo $fragmentation > /sys/class/net/$meshif/mesh/fragmentation
66 fi
67
68 if [ $gw_bandwidth ]; then
69 echo $gw_bandwidth > /sys/class/net/$meshif/mesh/gw_bandwidth
70 fi
71
72 if [ $gw_mode ]; then
73 echo $gw_mode > /sys/class/net/$meshif/mesh/gw_mode
74 fi
75
76 if [ $gw_sel_class ]; then
77 echo $gw_sel_class > /sys/class/net/$meshif/mesh/gw_sel_class
78 fi
79
80 if [ $vis_mode ]; then
81 echo $vis_mode > /sys/class/net/$meshif/mesh/vis_mode
82 fi
83 }
84
85 stop_mesh() {
86 local meshif="$1"
87
88 is_module_loaded
89 [ $? -ne 1 ] && return
90
91 for iface in $(ls /sys/class/net/*)
92 do
93 [ ! -f "$iface/batman_adv/mesh_iface" ] && continue
94 [ "$(head -1 $iface/batman_adv/mesh_iface)" != "$meshif" ] && continue
95
96 echo "none" > $iface/batman_adv/mesh_iface
97 done
98 }