babeld.init 3.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
#!/bin/sh /etc/rc.common

START=70

pidfile='/var/run/babeld.pid'
EXTRA_COMMANDS="status"
EXTRA_HELP="        status Dump Babel's table to the log file."

listen_ifname() {
	local ifname=$(uci_get_state network "$1" ifname "$1")
	local switch="$2"
	append args "$switch $ifname"
	append interfaces "$ifname"
}

append_ifname() {
	local section="$1"
	local option="$2"
	local switch="$3"
	local _name
	config_get _name "$section" "$option"
	[ -z "$_name" ] && return 0
	local ifname=$(uci_get_state network "$_name" ifname "$_name")
	append args "$switch $ifname"
}

append_bool() {
	local section="$1"
	local option="$2"
	local value="$3"
	local _loctmp
	config_get_bool _loctmp "$section" "$option" 0
	[ "$_loctmp" -gt 0 ] && append args "$value"
}

append_switch() {
	local value="$1"
	local switch="$2"
	append args "$switch $value"
}

append_parm() {
	local section="$1"
	local option="$2"
	local switch="$3"
	local _loctmp
	config_get _loctmp "$section" "$option"
	[ -z "$_loctmp" ] && return 0
	append args "$switch $_loctmp"
}

babel_filter() {
	local cfg="$1"
	local _loctmp

	local _ignored
	config_get_bool _ignored "$cfg" 'ignore' 0
	[ "$_ignored" -eq 1 ] && return 0
	
	append args "-C '"

	append_parm "$cfg" 'type' ''

	append_bool "$cfg" 'local' 'local'

	append_parm "$cfg" 'ip' 'ip'
	append_parm "$cfg" 'eq' 'eq'
	append_parm "$cfg" 'le' 'le'
	append_parm "$cfg" 'ge' 'ge'
	append_parm "$cfg" 'neigh' 'neigh'
	append_parm "$cfg" 'id' 'id'
	append_parm "$cfg" 'proto' 'proto'

	append_ifname "$cfg" 'if' 'if'

	append_parm "$cfg" 'action' ''

	append args ' ' "'"
}

babel_addif() {
	local cfg="$1"

	local _ignored
	config_get_bool _ignored "$cfg" 'ignore' 0
	[ "$_ignored" -eq 1 ] && return 0
	
	listen_ifname "$cfg" "-C 'interface"

	append_parm "$cfg" 'wired' 'wired'
	append_parm "$cfg" 'link_quality' 'link-quality'
	append_parm "$cfg" 'split_horizon' 'split-horizon'
	append_parm "$cfg" 'rxcost' 'rxcost'
	append_parm "$cfg" 'hello_interval' 'hello-interval'
	append_parm "$cfg" 'update_interval' 'update-interval'
96 97 98 99 100
	append_bool "$cfg" 'enable_timestamps' 'enable-timestamps'
	append_parm "$cfg" 'max_rtt_penalty' 'max-rtt-penalty'
	append_parm "$cfg" 'rtt_decay' 'rtt-decay'
	append_parm "$cfg" 'rtt_min' 'rtt-min'
	append_parm "$cfg" 'rtt_max' 'rtt-max'
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

	append args ' ' "'"
}

babel_config() {
	local cfg="$1"

	append_bool "$cfg" 'carrier_sense' '-l'
	append_bool "$cfg" 'assume_wireless' '-w'
	append_bool "$cfg" 'no_split_horizon' '-s'
	append_bool "$cfg" 'keep_unfeasible' '-u'
	append_bool "$cfg" 'random_router_id' '-r'

	append_parm "$cfg" 'multicast_address' '-m'
	append_parm "$cfg" 'port' '-p'
	append_parm "$cfg" 'state_file' '-S'
	append_parm "$cfg" 'hello_interval' '-h'
	append_parm "$cfg" 'wired_hello_interval' '-H'
	append_parm "$cfg" 'diversity' '-z'
	append_parm "$cfg" 'smoothing_half_time' '-M'
	append_parm "$cfg" 'kernel_priority' '-k'
	append_parm "$cfg" 'duplication_priority' '-A'
	append_parm "$cfg" 'debug' '-d'
	append_parm "$cfg" 'local_server' '-g'
	append_parm "$cfg" 'export_table' '-t'
	config_list_foreach "$cfg" 'import_table' append_switch '-T'
	append_parm "$cfg" 'conf_file' '-c'
	append_parm "$cfg" 'log_file' '-L'
}

start() {
	mkdir -p /var/lib
	config_load babeld
	unset args
	unset interfaces
	config_foreach babel_config general
	config_foreach babel_addif interface
	config_foreach babel_filter filter
	[ -z "$interfaces" ] && return 0
	eval "/usr/sbin/babeld -D -I $pidfile $args $interfaces"
}

stop() {
	[ -f "$pidfile" ] && kill $(cat $pidfile)
  # avoid race-condition on restart: wait for
  # babeld to die for real.
  [ -f "$pidfile" ] && sleep 1
  [ -f "$pidfile" ] && sleep 1
  [ -f "$pidfile" ] && sleep 1
  [ -f "$pidfile" ] && exit 42
}

status() {
	[ -f "$pidfile" ] && kill -USR1 $(cat $pidfile)
}