blob: 5c585c959f26b1a42f29a8d573e394a6a66354b3 (
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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
#!/bin/sh
#
# (C) 2009 by Pablo Neira Ayuso <pablo@netfilter.org>
#
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
#
#
# This is the node ID, must be >= 1 and <= 2. You have to CHANGE IT according
# to the number of node where you are.
#
NODEID=1
CONNTRACKD_BIN="/usr/sbin/conntrackd"
CONNTRACKD_LOCK="/var/lock/conntrack.lock"
CONNTRACKD_CONFIG="/etc/conntrackd/conntrackd.conf"
ETHER1="eth1"
ETHER2="eth2"
state_primary()
{
#
# commit the external cache into the kernel table
#
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -c
if [ $? -eq 1 ]
then
logger "ERROR: failed to invoke conntrackd -c"
fi
#
# flush the internal and the external caches
#
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -f
if [ $? -eq 1 ]
then
logger "ERROR: failed to invoke conntrackd -f"
fi
#
# resynchronize my internal cache to the kernel table
#
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -R
if [ $? -eq 1 ]
then
logger "ERROR: failed to invoke conntrackd -R"
fi
#
# send a bulk update to backups
#
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -B
if [ $? -eq 1 ]
then
logger "ERROR: failed to invoke conntrackd -B"
fi
}
state_backup() {
#
# is conntrackd running? request some statistics to check it
#
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -s
if [ $? -eq 1 ]
then
#
# something's wrong, do we have a lock file?
#
if [ -f $CONNTRACKD_LOCK ]
then
logger "WARNING: conntrackd was not cleanly stopped."
logger "If you suspect that it has crashed:"
logger "1) Enable coredumps"
logger "2) Try to reproduce the problem"
logger "3) Post the coredump to netfilter-devel@vger.kernel.org"
rm -f $CONNTRACKD_LOCK
fi
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -d
if [ $? -eq 1 ]
then
logger "ERROR: cannot launch conntrackd"
exit 1
fi
fi
#
# shorten kernel conntrack timers to remove the zombie entries.
#
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -t
if [ $? -eq 1 ]
then
logger "ERROR: failed to invoke conntrackd -t"
fi
#
# request resynchronization with master firewall replica (if any)
# Note: this does nothing in the alarm approach.
#
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -n
if [ $? -eq 1 ]
then
logger "ERROR: failed to invoke conntrackd -n"
fi
}
state_fault() {
#
# shorten kernel conntrack timers to remove the zombie entries.
#
$CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -t
if [ $? -eq 1 ]
then
logger "ERROR: failed to invoke conntrackd -t"
fi
}
iptables_add_cluster_rule() {
iptables -I CLUSTERDEV1 -t mangle -m cluster \
--cluster-total-nodes 2 --cluster-local-node $1 \
--cluster-hash-seed 0xdeadbeed -j MARK --set-mark 0xffff
iptables -I CLUSTERDEV2 -t mangle -m cluster \
--cluster-total-nodes 2 --cluster-local-node $1 \
--cluster-hash-seed 0xdeadbeed -j MARK --set-mark 0xffff
}
iptables_del_cluster_rule() {
iptables -D CLUSTERDEV1 -t mangle -m cluster \
--cluster-total-nodes 2 --cluster-local-node $1 \
--cluster-hash-seed 0xdeadbeed -j MARK --set-mark 0xffff
iptables -D CLUSTERDEV2 -t mangle -m cluster \
--cluster-total-nodes 2 --cluster-local-node $1 \
--cluster-hash-seed 0xdeadbeed -j MARK --set-mark 0xffff
}
iptables_start_cluster_rule() {
iptables -N CLUSTERDEV1 -t mangle
iptables -N CLUSTERDEV2 -t mangle
iptables_add_cluster_rule $1
iptables -A CLUSTERDEV1 -t mangle -m mark ! --mark 0xffff -j DROP
iptables -A CLUSTERDEV2 -t mangle -m mark ! --mark 0xffff -j DROP
iptables -I PREROUTING -t mangle -p vrrp -j ACCEPT
iptables -A PREROUTING -t mangle -i $ETHER1 -j CLUSTERDEV1
iptables -A PREROUTING -t mangle -i $ETHER2 -j CLUSTERDEV2
}
iptables_stop_cluster_rule() {
iptables -D PREROUTING -t mangle -i $ETHER1 -j CLUSTERDEV1
iptables -D PREROUTING -t mangle -i $ETHER2 -j CLUSTERDEV2
iptables -D PREROUTING -t mangle -p vrrp -j ACCEPT
iptables -F CLUSTERDEV1 -t mangle
iptables -F CLUSTERDEV2 -t mangle
iptables -X CLUSTERDEV1 -t mangle
iptables -X CLUSTERDEV2 -t mangle
}
# this can be called without options
case "$1" in
start)
iptables_start_cluster_rule $NODEID
exit 0
;;
stop)
iptables_stop_cluster_rule $NODEID
exit 0
;;
esac
if [ $# -ne 2 ]
then
logger "ERROR: missing arguments"
echo "Usage: $0 {primary|backup|fault|start|stop} {nodeid}"
exit 1
fi
case "$1" in
primary)
#
# We are entering the MASTER state, it may be for G1 or G2, but we
# commit the external cache anyway.
#
state_primary
iptables_add_cluster_rule $2
;;
backup)
#
# We are entering the BACKUP state. We can enter it from G1 or G2.
# Assuming that we are node 1 and that we have entered BACKUP in G2,
# this means that node 2 has come back to life. In that case, skip
# state_backup because we are still in MASTER state for G1.
#
if [ $NODEID -eq $2 ]
then
state_backup
fi
iptables_del_cluster_rule $2
;;
fault)
#
# We are entering the FAULT state, something bad is happening to us.
#
state_fault
iptables_del_cluster_rule $2
;;
*)
logger "ERROR: unknown state transition"
echo "Usage: $0 {primary|backup|fault|start|stop} {nodeid}"
exit 1
;;
esac
exit 0
|