summaryrefslogtreecommitdiff
path: root/misc/openwrt/setup-routing.sh
blob: b384541d2aabd74004e844eff6afa2af85817091 (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
#!/bin/sh

list_ipset() {
	skip=1
	while read -r line; do
		if [ "$line" = "Members:" ]; then skip=0; continue; fi;
		[ "$skip" = "1" ] && continue
		echo "$line"
	done
}

case "$1" in
	dhcp-leases)
		cat /tmp/dhcp.leases
		;;

	ipset-add)
		addr="$3"
		addr="${addr/_/\/}"
		ipset add "$2" "$addr"
		;;

	ipset-del)
		addr="$3"
		addr="${addr/_/\/}"s
		ipset del "$2" "$addr"
		;;

#	ipset_list)
#		ipset list "$2" | list_ipset
#		;;

	ipset-list-all)
		shift
		while [ -n "$1" ]; do
			echo ">$1"
			skip=1
			ipset list "$1" | list_ipset
			shift
		done
		;;

#	rule-show)
#		;;
#
#	route-show)
#		;;

	*)
		2>&1 echo "error: invalid command"
		exit 1
		;;
esac