blob: 0567f881e544902826e64c579354a3d9271ae574 (
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
#!/bin/sh
die ()
{
echo "$1" >&2
exit ${2:-1}
}
[ -n "$FAKE_LVS_STATE_DIR" ] || die "FAKE_LVS_STATE_DIR not set"
service_address=""
scheduling_method="wlc"
persistent_timeout=""
real_server=""
forwarding_method="Route"
set_service_address ()
{
[ -z "$service_address" ] ||
die "multiple 'service-address' options specified" 2
case "$2" in
*:*) service_address="${1} ${2}" ;;
*) service_address="${1} ${2}:0" ;;
esac
}
set_real_server ()
{
[ -z "$real_server" ] ||
die "multiple 'real-server' options specified" 2
case "$1" in
*\]:*) real_server="${1}" ;;
*\]) real_server="${1}:0" ;;
*:*) real_server="${1}" ;;
*) real_server="${1}:0" ;;
esac
case "$real_server" in
127.0.0.1:*|\[::1\]:*) forwarding_method="Local" ;;
esac
}
case "$1" in
-A)
shift
while [ -n "$1" ] ; do
case "$1" in
-t) set_service_address "TCP" "$2" ; shift 2 ;;
-u) set_service_address "UDP" "$2" ; shift 2 ;;
-s) scheduling_method="$2" ; shift 2 ;;
-p) persistent_timeout="persistent $2" ; shift 2 ;;
*) die "Unsupported -A option $1" ;;
esac
done
[ -n "$service_address" ] ||
die "You need to supply the 'service-address' option for the 'add-service' command" 2
d="${FAKE_LVS_STATE_DIR}/${service_address}"
mkdir "$d" 2>/dev/null || die "Service already exists" 255
t="${scheduling_method}${persistent_timeout:+ }${persistent_timeout}"
echo "$t" >"${d}/.info"
;;
-D)
shift
while [ -n "$1" ] ; do
case "$1" in
-t) set_service_address "TCP" "$2" ; shift 2 ;;
-u) set_service_address "UDP" "$2" ; shift 2 ;;
*) die "Unsupported -D option $1" ;;
esac
done
[ -n "$service_address" ] ||
die "You need to supply the 'service-address' option for the 'delete-service' command" 2
d="${FAKE_LVS_STATE_DIR}/${service_address}"
rm -f "${d}/"*
rm -f "${d}/.info"
rmdir "$d" 2>/dev/null || die "No such service" 255
;;
-a)
shift
while [ -n "$1" ] ; do
case "$1" in
-t) set_service_address "TCP" "$2" ; shift 2 ;;
-u) set_service_address "UDP" "$2" ; shift 2 ;;
-r) set_real_server "$2" ; shift 2 ;;
-g) forwarding_method="Route" ; shift 1 ;;
*) die "Unsupported -A option $1" ;;
esac
done
[ -n "$service_address" ] ||
die "You need to supply the 'service-address' option for the 'delete-service' command" 2
d="${FAKE_LVS_STATE_DIR}/${service_address}"
[ -d "$d" ] || die "Service not defined" 255
[ -n "$real_server" ] ||
die "You need to supply the 'real-server' option for the 'add-server' command" 2
f="${d}/${real_server}"
echo "$forwarding_method" >"$f"
;;
-l)
cat <<EOF
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
EOF
[ -d "$FAKE_LVS_STATE_DIR" ] || exit 0
(
cd "$FAKE_LVS_STATE_DIR"
for d in *; do
[ -d "$d" ] || continue
echo -n "$d "
cat "${d}/.info"
for f in "${d}/"* ; do
[ -f "$f" ] || continue
read forwarding_method <"$f"
printf " -> %-28s %-7s %-6s %-10s %-10s\n" \
"${f##*/}" "$forwarding_method" 1 0 0
done
done
)
;;
*)
die "Unknown option $1"
esac
exit 0
|