Merge pull request #3388 from myENA/feature/skip-nat-via-weave-expose

add --without-masquerade option to `weave expose`
This commit is contained in:
Martynas Pumputis authored and GitHub committed 2018-09-10 15:45:52 +03:00
commit a182bd4514
5 files changed
+37 -14

No files matched your search

+1 -1
View File
@@ -607,7 +607,7 @@ func reexpose(config *BridgeConfig, log *logrus.Logger) error {
for _, addr := range addrs {
log.Infof("Re-exposing %s on bridge %q", addr.IPNet, config.WeaveBridgeName)
if err := Expose(config.WeaveBridgeName, addr.IPNet, config.AWSVPC, config.NPC); err != nil {
if err := Expose(config.WeaveBridgeName, addr.IPNet, config.AWSVPC, config.NPC, false); err != nil {
return errors.Wrapf(err, "unable to re-expose %s on bridge: %q", addr.IPNet, config.WeaveBridgeName)
}
}
+6 -3
View File
@@ -18,7 +18,8 @@ import (
// * "ipAddr" - IP addr to be assigned to the bridge.
// * "removeDefaultRoute" - whether to remove a default route installed by the kernel (used only in the AWSVPC mode).
// * "npc" - whether is Weave NPC running.
func Expose(bridgeName string, ipAddr *net.IPNet, removeDefaultRoute, npc bool) error {
// * "skipNAT" - whether to skip adding iptables NAT rules
func Expose(bridgeName string, ipAddr *net.IPNet, removeDefaultRoute, npc bool, skipNAT bool) error {
ipt, err := iptables.New()
if err != nil {
return errors.Wrap(err, "iptables.New")
@@ -29,8 +30,10 @@ func Expose(bridgeName string, ipAddr *net.IPNet, removeDefaultRoute, npc bool)
return errors.Wrap(err, "addBridgeIPAddr")
}
if err := exposeNAT(ipt, cidr); err != nil {
return errors.Wrap(err, "exposeNAT")
if !skipNAT {
if err := exposeNAT(ipt, cidr); err != nil {
return errors.Wrap(err, "exposeNAT")
}
}
if !npc {
+1 -1
View File
@@ -513,7 +513,7 @@ func exposeForAWSVPC(alloc *ipam.Allocator, subnet address.CIDR, bridgeName stri
addr, err := alloc.Allocate("weave:expose", subnet, false, func() bool { return false })
checkFatal(err)
cidr := address.MakeCIDR(subnet, addr)
err = weavenet.Expose(bridgeName, cidr.IPNet(), true, false)
err = weavenet.Expose(bridgeName, cidr.IPNet(), true, false, false)
checkFatal(err)
Log.Printf("Bridge %q exposed on address %v", bridgeName, cidr)
ready()
+9 -1
View File
@@ -3,6 +3,7 @@ package router
import (
"fmt"
"net/http"
"strconv"
"github.com/gorilla/mux"
@@ -37,7 +38,14 @@ func (router *NetworkRouter) HandleHTTP(muxRouter *mux.Router) {
return
}
if err = net.Expose(router.BridgeConfig.WeaveBridgeName, cidr.IPNet(), router.BridgeConfig.AWSVPC, router.BridgeConfig.NPC); err != nil {
var skipNAT bool
if r.FormValue("skipNAT") != "" {
if skipNAT, err = strconv.ParseBool(r.FormValue("skipNAT")); err != nil {
http.Error(w, fmt.Sprint("unable to parse skipNAT option: ", err.Error()), http.StatusBadRequest)
}
}
if err = net.Expose(router.BridgeConfig.WeaveBridgeName, cidr.IPNet(), router.BridgeConfig.AWSVPC, router.BridgeConfig.NPC, skipNAT); err != nil {
http.Error(w, fmt.Sprint("unable to expose: ", err.Error()), http.StatusInternalServerError)
return
}
+20 -8
View File
@@ -69,7 +69,7 @@ weave attach [--without-dns] [--rewrite-hosts] [--no-multicast-route]
[<addr> ...] <container_id>
detach [<addr> ...] <container_id>
weave expose [<addr> ...] [-h <fqdn>]
weave expose [<addr> ...] [-h <fqdn>] [--without-masquerade]
hide [<addr> ...]
weave dns-add [<ip_address> ...] <container_id> [-h <fqdn>] |
@@ -430,9 +430,10 @@ EOF
}
expose_ip() {
[ -z $WITHOUT_MASQUERADE ] || skipNAT="?skipNAT=true"
ipam_cidrs allocate_no_check_alive weave:expose $CIDR_ARGS
for CIDR in $ALL_CIDRS ; do
call_weave "POST" "/expose/$CIDR"
call_weave "POST" "/expose/$CIDR$skipNAT"
[ -z "$FQDN" ] || when_weave_running put_dns_fqdn_no_check_alive weave:expose $FQDN $CIDR
done
@@ -1491,14 +1492,25 @@ case "$COMMAND" in
dig @$DOCKER_BRIDGE_IP +short $1
;;
expose)
WITHOUT_MASQUERADE=
FQDN=
collect_cidr_args "$@"
shift $CIDR_ARG_COUNT
if [ $# -eq 0 ] ; then
FQDN=""
else
[ $# -eq 2 -a "$1" = "-h" ] || usage
FQDN="$2"
fi
while [ $# -gt 0 ]; do
case "$1" in
-h)
[ -z $FQDN ] && FQDN=$2 && shift || usage
;;
--without-masquerade)
WITHOUT_MASQUERADE=1
;;
*)
break
;;
esac
shift
done
[ $# -eq 0 ] || usage
expose_ip
show_addrs $ALL_CIDRS
;;