Skip to content

Commit 2fc7be1

Browse files
author
Naredula Janardhana Reddy
committed
bug 10557: implemented the TODO - opening the stats port using iptable
1 parent 527a668 commit 2fc7be1

7 files changed

Lines changed: 59 additions & 9 deletions

File tree

‎api/src/com/cloud/agent/api/routing/LoadBalancerConfigCommand.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public class LoadBalancerConfigCommand extends NetworkElementCommand {
2727
LoadBalancerTO[] loadBalancers;
2828
public String lbStatsVisibility;
2929
public String lbStatsIp; /* load balancer listen on this ip for stats */
30-
public String lbStatsPort = "8081"; /*TODO: need to open the firewall port, load balancer listen on this port for stats */
30+
public String lbStatsPort = "8081"; /*load balancer listen on this port for stats */
31+
public String lbStatsSrcCidrs = "0/0" ; /* TODO : currently there is no filtering based on the source ip */
3132
public String lbStatsAuth = "admin1:AdMiN123";
3233
public String lbStatsUri = "/admin?stats";
3334

‎core/src/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResource.java‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ private Answer execute(LoadBalancerConfigCommand cmd) {
201201
final String result = setLoadBalancerConfig(cfgFilePath,
202202
rules[LoadBalancerConfigurator.ADD],
203203
rules[LoadBalancerConfigurator.REMOVE],
204+
rules[LoadBalancerConfigurator.STATS],
204205
routerIp);
205206

206207
return new Answer(cmd, result == null, result);
@@ -294,7 +295,7 @@ protected Answer execute(final IpAssocCommand cmd) {
294295
}
295296

296297
private String setLoadBalancerConfig(final String cfgFile,
297-
final String[] addRules, final String[] removeRules, String routerIp) {
298+
final String[] addRules, final String[] removeRules, final String[] statsRules,String routerIp) {
298299

299300
if (routerIp == null) {
300301
routerIp = "none";
@@ -321,6 +322,14 @@ private String setLoadBalancerConfig(final String cfgFile,
321322
command.add("-d", sb.toString());
322323
}
323324

325+
sb = new StringBuilder();
326+
if (statsRules.length > 0) {
327+
for (int i=0; i< statsRules.length; i++) {
328+
sb.append(statsRules[i]).append(',');
329+
}
330+
command.add("-s", sb.toString());
331+
}
332+
324333
return command.execute();
325334
}
326335

‎core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,8 @@ protected Answer execute(final LoadBalancerConfigCommand cmd) {
13031303

13041304
String[] addRules = rules[LoadBalancerConfigurator.ADD];
13051305
String[] removeRules = rules[LoadBalancerConfigurator.REMOVE];
1306-
1306+
String[] statRules = rules[LoadBalancerConfigurator.STATS];
1307+
13071308
String args = "";
13081309
args += "-i " + routerIp;
13091310
args += " -f " + tmpCfgFilePath;
@@ -1325,7 +1326,16 @@ protected Answer execute(final LoadBalancerConfigCommand cmd) {
13251326

13261327
args += " -d " + sb.toString();
13271328
}
1329+
1330+
sb = new StringBuilder();
1331+
if (statRules.length > 0) {
1332+
for (int i = 0; i < statRules.length; i++) {
1333+
sb.append(statRules[i]).append(',');
1334+
}
13281335

1336+
args += " -s " + sb.toString();
1337+
}
1338+
13291339
result = callHostPlugin(conn, "vmops", "setLoadBalancerRule", "args", args);
13301340

13311341
if (result == null || result.isEmpty()) {

‎core/src/com/cloud/network/HAProxyConfigurator.java‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,10 @@ public String[] generateConfiguration(LoadBalancerConfigCommand lbCmd) {
244244

245245
@Override
246246
public String[][] generateFwRules(LoadBalancerConfigCommand lbCmd) {
247-
String [][] result = new String [2][];
247+
String [][] result = new String [3][];
248248
Set<String> toAdd = new HashSet<String>();
249249
Set<String> toRemove = new HashSet<String>();
250+
Set<String> toStats = new HashSet<String>();
250251

251252
for (LoadBalancerTO lbTO: lbCmd.getLoadBalancers()) {
252253

@@ -266,9 +267,12 @@ public String[][] generateFwRules(LoadBalancerConfigCommand lbCmd) {
266267
toRemove.add(lbRuleEntry);
267268
}
268269
}
270+
StringBuilder sb = new StringBuilder(lbCmd.lbStatsIp).append(":").append(lbCmd.lbStatsPort).append(":").append(lbCmd.lbStatsSrcCidrs).append(":,");
271+
toStats.add(sb.toString());
269272
toRemove.removeAll(toAdd);
270273
result[ADD] = toAdd.toArray(new String[toAdd.size()]);
271274
result[REMOVE] = toRemove.toArray(new String[toRemove.size()]);
275+
result[STATS] = toStats.toArray(new String[toStats.size()]);
272276

273277
return result;
274278
}

‎core/src/com/cloud/network/LoadBalancerConfigurator.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
public interface LoadBalancerConfigurator {
3131
public final static int ADD = 0;
3232
public final static int REMOVE = 1;
33+
public final static int STATS = 2;
3334

3435
public String [] generateConfiguration(List<PortForwardingRuleTO> fwRules);
3536

‎patches/systemvm/debian/config/root/loadbalancer.sh‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# @VERSION@
2828

2929
usage() {
30-
printf "Usage: %s: -i <domR eth1 ip> -a <added public ip address> -d <removed> -f <load balancer config> \n" $(basename $0) >&2
30+
printf "Usage: %s: -i <domR eth1 ip> -a <added public ip address> -d <removed> -f <load balancer config> -s <stats guest ip address> \n" $(basename $0) >&2
3131
}
3232

3333
# set -x
@@ -48,6 +48,9 @@ fw_remove_backup() {
4848
iptables -D INPUT -i $vif -p tcp -j back_load_balancer_$vif 2> /dev/null
4949
iptables -X back_load_balancer_$vif 2> /dev/null
5050
done
51+
iptables -F back_lb_stats 2> /dev/null
52+
iptables -D INPUT -i $STAT_IF -p tcp -j back_lb_stats 2> /dev/null
53+
iptables -X back_lb_stats 2> /dev/null
5154
}
5255
fw_restore() {
5356
for vif in $VIF_LIST; do
@@ -56,11 +59,16 @@ fw_restore() {
5659
iptables -X load_balancer_$vif 2> /dev/null
5760
iptables -E back_load_balancer_$vif load_balancer_$vif 2> /dev/null
5861
done
62+
iptables -F lb_stats 2> /dev/null
63+
iptables -D INPUT -i $STAT_IF -p tcp -j lb_stats 2> /dev/null
64+
iptables -X lb_stats 2> /dev/null
65+
iptables -E back_lb_stats lb_stats 2> /dev/null
5966
}
6067
# firewall entry to ensure that haproxy can receive on specified port
6168
fw_entry() {
6269
local added=$1
6370
local removed=$2
71+
local stats=$3
6472

6573
if [ "$added" == "none" ]
6674
then
@@ -81,6 +89,9 @@ fw_entry() {
8189
iptables -N load_balancer_$vif 2> /dev/null
8290
iptables -A INPUT -i $vif -p tcp -j load_balancer_$vif
8391
done
92+
iptables -E lb_stats back_lb_stats 2> /dev/null
93+
iptables -N lb_stats 2> /dev/null
94+
iptables -A INPUT -i $STAT_IF -p tcp -j lb_stats
8495

8596
for i in $a
8697
do
@@ -97,6 +108,10 @@ fw_entry() {
97108
fi
98109
done
99110
done
111+
local pubIp=$(echo $stats | cut -d: -f1)
112+
local dport=$(echo $stats | cut -d: -f2)
113+
local cidrs=$(echo $stats | cut -d: -f3 | sed 's/-/,/')
114+
iptables -A lb_stats -s $cidrs -p tcp -m state --state NEW -d $pubIp --dport $dport -j ACCEPT
100115

101116
return 0
102117
}
@@ -137,8 +152,9 @@ iflag=
137152
aflag=
138153
dflag=
139154
fflag=
155+
sflag=
140156

141-
while getopts 'i:a:d:f:' OPTION
157+
while getopts 'i:a:d:f:s:' OPTION
142158
do
143159
case $OPTION in
144160
i) iflag=1
@@ -153,13 +169,18 @@ do
153169
f) fflag=1
154170
cfgfile="$OPTARG"
155171
;;
172+
s) sflag=1
173+
statsIp="$OPTARG"
174+
;;
156175
?) usage
157176
exit 2
158177
;;
159178
esac
160179
done
161180

162181
VIF_LIST=$(get_vif_list)
182+
# TODO make the stat interface generic
183+
STAT_IF="eth0"
163184

164185
# hot reconfigure haproxy
165186
reconfig_lb $cfgfile
@@ -181,7 +202,7 @@ then
181202
fi
182203

183204
# iptables entry to ensure that haproxy receives traffic
184-
fw_entry $addedIps $removedIps
205+
fw_entry $addedIps $removedIps $statsIp
185206

186207
if [ $? -gt 0 ]
187208
then

‎scripts/network/domr/call_loadbalancer.sh‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#
2727

2828
usage() {
29-
printf "Usage: %s: -i <domR eth1 ip> -a <added public ip address> -d <removed> -f <load balancer config> \n" $(basename $0) >&2
29+
printf "Usage: %s: -i <domR eth1 ip> -a <added public ip address> -d <removed> -f <load balancer config> -s <stats guest ip >\n" $(basename $0) >&2
3030
}
3131

3232
set -x
@@ -55,8 +55,9 @@ iflag=
5555
aflag=
5656
dflag=
5757
fflag=
58+
sflag=
5859

59-
while getopts 'i:a:d:f:' OPTION
60+
while getopts 'i:a:d:f:s:' OPTION
6061
do
6162
case $OPTION in
6263
i) iflag=1
@@ -71,6 +72,9 @@ do
7172
f) fflag=1
7273
cfgfile="$OPTARG"
7374
;;
75+
s) sflag=1
76+
statsIps="$OPTARG"
77+
;;
7478
?) usage
7579
exit 2
7680
;;

0 commit comments

Comments
 (0)