Merge pull request #453 from ecsv/batadv-2019.0
[feed/routing.git] / batman-adv / files / lib / netifd / proto / batadv.sh
1 #!/bin/sh
2
3 [ -n "$INCLUDE_ONLY" ] || {
4 . /lib/functions.sh
5 . ../netifd-proto.sh
6 init_proto "$@"
7 }
8
9 proto_batadv_init_config() {
10 no_device=1
11 available=1
12
13 proto_config_add_boolean 'aggregated_ogms:bool'
14 proto_config_add_boolean 'ap_isolation:bool'
15 proto_config_add_boolean 'bonding:bool'
16 proto_config_add_boolean 'bridge_loop_avoidance:bool'
17 proto_config_add_boolean 'distributed_arp_table:bool'
18 proto_config_add_boolean 'fragmentation:bool'
19 proto_config_add_string 'gw_bandwidth'
20 proto_config_add_string 'gw_mode'
21 proto_config_add_int 'gw_sel_class'
22 proto_config_add_int 'hop_penalty'
23 proto_config_add_string 'isolation_mark'
24 proto_config_add_string 'log_level'
25 proto_config_add_boolean 'multicast_mode:bool'
26 proto_config_add_boolean 'network_coding:bool'
27 proto_config_add_int 'orig_interval'
28 proto_config_add_string 'routing_algo'
29 }
30
31 proto_batadv_setup() {
32 local config="$1"
33 local iface="$config"
34
35 local aggregated_ogms
36 local ap_isolation
37 local bonding
38 local bridge_loop_avoidance
39 local distributed_arp_table
40 local fragmentation
41 local gw_bandwidth
42 local gw_mode
43 local gw_sel_class
44 local hop_penalty
45 local isolation_mark
46 local log_level
47 local multicast_mode
48 local network_coding
49 local orig_interval
50 local routing_algo
51
52 json_get_vars aggregated_ogms
53 json_get_vars ap_isolation
54 json_get_vars bonding
55 json_get_vars bridge_loop_avoidance
56 json_get_vars distributed_arp_table
57 json_get_vars fragmentation
58 json_get_vars gw_bandwidth
59 json_get_vars gw_mode
60 json_get_vars gw_sel_class
61 json_get_vars hop_penalty
62 json_get_vars isolation_mark
63 json_get_vars log_level
64 json_get_vars multicast_mode
65 json_get_vars network_coding
66 json_get_vars orig_interval
67 json_get_vars routing_algo
68
69 set_default routing_algo 'BATMAN_IV'
70
71 batctl routing_algo "$routing_algo"
72 batctl -m "$iface" interface create
73
74 [ -n "$aggregated_ogms" ] && batctl -m "$iface" aggregation "$aggregated_ogms"
75 [ -n "$ap_isolation" ] && batctl -m "$iface" ap_isolation "$ap_isolation"
76 [ -n "$bonding" ] && batctl -m "$iface" bonding "$bonding"
77 [ -n "$bridge_loop_avoidance" ] && batctl -m "$iface" bridge_loop_avoidance "$bridge_loop_avoidance" 2>&-
78 [ -n "$distributed_arp_table" ] && batctl -m "$iface" distributed_arp_table "$distributed_arp_table" 2>&-
79 [ -n "$fragmentation" ] && batctl -m "$iface" fragmentation "$fragmentation"
80
81 case "$gw_mode" in
82 server)
83 if [ -n "$gw_bandwidth" ]; then
84 batctl -m "$iface" gw_mode "server" "$gw_bandwidth"
85 else
86 batctl -m "$iface" gw_mode "server"
87 fi
88 ;;
89 client)
90 if [ -n "$gw_sel_class" ]; then
91 batctl -m "$iface" gw_mode "client" "$gw_sel_class"
92 else
93 batctl -m "$iface" gw_mode "client"
94 fi
95 ;;
96 *)
97 batctl -m "$iface" gw_mode "off"
98 ;;
99 esac
100
101 [ -n "$hop_penalty" ] && batctl -m "$iface" hop_penalty "$hop_penalty"
102 [ -n "$isolation_mark" ] && batctl -m "$iface" isolation_mark "$isolation_mark"
103 [ -n "$multicast_mode" ] && batctl -m "$iface" multicast_mode "$multicast_mode" 2>&-
104 [ -n "$network_coding" ] && batctl -m "$iface" network_coding "$network_coding" 2>&-
105 [ -n "$log_level" ] && batctl -m "$iface" loglevel "$log_level" 2>&-
106 [ -n "$orig_interval" ] && batctl -m "$iface" orig_interval "$orig_interval"
107
108 proto_init_update "$iface" 1
109 proto_send_update "$config"
110 }
111
112 proto_batadv_teardown() {
113 local config="$1"
114 local iface="$config"
115
116 batctl -m "$iface" interface destroy
117 }
118
119 add_protocol batadv