aboutsummaryrefslogtreecommitdiff
path: root/net/nlbwmon/files/nlbwmon.init
blob: c12b838644184a8ecab8efe4c8decfc8eddc85a4 (plain)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/sh /etc/rc.common

START=60

USE_PROCD=1
NAME=nlbwmon
PROG=/usr/sbin/nlbwmon
NICEPRIO=19

add_subnet() {
	local network="$1"
	local range ranges

	case "$network" in
		*.*|*:*)
			procd_append_param command '-s' "$network"
		;;
		*)
			if network_get_subnets ranges "$network"; then
				for range in $ranges; do
					procd_append_param command '-s' "$range"
				done
			fi

			if network_get_subnets6 ranges "$network"; then
				for range in $ranges; do
					procd_append_param command '-s' "$range"
				done
			fi
		;;
	esac
}

add_option() {
	local cfg="$1"
	local flag="$2"
	local option="$3"
	local default="$4"
	local value

	config_get value "$cfg" "$option" "$default"
	[ -n "$value" ] && procd_append_param command "$flag" "$value"
}

add_bool() {
	local cfg="$1"
	local flag="$2"
	local option="$3"
	local default="$4"
	local value

	config_get_bool value "$cfg" "$option" "$default"
	[ $value -eq 1 ] && procd_append_param command "$flag"
}

parse_config() {
	. /lib/functions/network.sh

	local cfg="$1"
	local dir

	config_get dir "$cfg" database_directory /var/lib/nlbwmon

	mkdir -p "$dir"
	procd_append_param command -o "$dir"

	add_option "$cfg" -b netlink_buffer_size 524288
	add_option "$cfg" -i commit_interval 24h
	add_option "$cfg" -r refresh_interval 30s
	add_option "$cfg" -p protocol_database /usr/share/nlbwmon/protocols
	add_option "$cfg" -G database_generations 10
	add_option "$cfg" -I database_interval 1
	add_option "$cfg" -L database_limit 10000

	add_bool "$cfg" -P database_prealloc 0
	add_bool "$cfg" -Z database_compress 1

	config_list_foreach "$cfg" local_network add_subnet
}

start_service() {
	procd_open_instance
	procd_set_param stderr 1
	procd_set_param command "$PROG"
	procd_set_param nice "$NICEPRIO"

	config_load nlbwmon
	config_foreach parse_config nlbwmon

	procd_close_instance
}

add_interface_trigger() {
	local interface ignore

	config_get interface "$1" interface
	config_get_bool ignore "$1" ignore 0

	[ -n "$interface" -a $ignore -eq 0 ] && procd_add_interface_trigger "interface.*" "$interface" /etc/init.d/nlbwmon reload
}

service_triggers() {
	procd_add_reload_trigger "dhcp" "system" "nlbwmon"

	config_load dhcp
	config_foreach add_interface_trigger dhcp
}