Refactor: extract functional parts of weave export so they can be called from elsewhere

This commit is contained in:
Bryan Boreham committed 2016-05-27 16:52:53 +01:00
1 parent d9da08792f
commit e2294482a6
1 file changed
+21 -11
+21 -11
View File
@@ -654,6 +654,25 @@ EOF
configure_arp_cache $BRIDGE configure_arp_cache $BRIDGE
} }
expose_ip() {
ipam_cidrs allocate_no_check_alive weave:expose $CIDR_ARGS
for CIDR in $ALL_CIDRS ; do
if ! ip addr show dev $BRIDGE | grep -qF $CIDR ; then
ip addr add dev $BRIDGE $CIDR
arp_update $BRIDGE $CIDR || true
fi
[ -z "$FQDN" ] || when_weave_running put_dns_fqdn_no_check_alive weave:expose $FQDN $CIDR
done
}
expose_nat() {
for CIDR in $ALL_CIDRS ; do
add_iptables_rule nat WEAVE -s $CIDR -d 224.0.0.0/4 -j RETURN
add_iptables_rule nat WEAVE -d $CIDR ! -s $CIDR -j MASQUERADE
add_iptables_rule nat WEAVE -s $CIDR ! -d $CIDR -j MASQUERADE
done
}
# create veth with ends $1-$2, and then invoke $3..., removing the # create veth with ends $1-$2, and then invoke $3..., removing the
# veth on failure. No-op of veth already exists. # veth on failure. No-op of veth already exists.
create_veth() { create_veth() {
@@ -2106,7 +2125,6 @@ EOF
expose) expose)
collect_cidr_args "$@" collect_cidr_args "$@"
shift $CIDR_ARG_COUNT shift $CIDR_ARG_COUNT
ipam_cidrs allocate_no_check_alive weave:expose $CIDR_ARGS
if [ $# -eq 0 ] ; then if [ $# -eq 0 ] ; then
FQDN="" FQDN=""
else else
@@ -2114,16 +2132,8 @@ EOF
FQDN="$2" FQDN="$2"
fi fi
create_bridge --without-ethtool create_bridge --without-ethtool
for CIDR in $ALL_CIDRS ; do expose_ip
if ! ip addr show dev $BRIDGE | grep -qF $CIDR ; then expose_nat
ip addr add dev $BRIDGE $CIDR
arp_update $BRIDGE $CIDR || true
add_iptables_rule nat WEAVE -s $CIDR -d 224.0.0.0/4 -j RETURN
add_iptables_rule nat WEAVE -d $CIDR ! -s $CIDR -j MASQUERADE
add_iptables_rule nat WEAVE -s $CIDR ! -d $CIDR -j MASQUERADE
fi
[ -n "$FQDN" ] && when_weave_running put_dns_fqdn_no_check_alive weave:expose $FQDN $CIDR
done
show_addrs $ALL_CIDRS show_addrs $ALL_CIDRS
;; ;;
hide) hide)