From e2294482a6ee2f16a3aca50005518b86ec0cadf5 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 27 May 2016 16:51:42 +0100 Subject: [PATCH] Refactor: extract functional parts of `weave export` so they can be called from elsewhere --- weave | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/weave b/weave index 4d1bf012..bd9de658 100755 --- a/weave +++ b/weave @@ -654,6 +654,25 @@ EOF 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 # veth on failure. No-op of veth already exists. create_veth() { @@ -2106,7 +2125,6 @@ EOF expose) collect_cidr_args "$@" shift $CIDR_ARG_COUNT - ipam_cidrs allocate_no_check_alive weave:expose $CIDR_ARGS if [ $# -eq 0 ] ; then FQDN="" else @@ -2114,16 +2132,8 @@ EOF FQDN="$2" fi create_bridge --without-ethtool - 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 - 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 + expose_ip + expose_nat show_addrs $ALL_CIDRS ;; hide)