add the ability to skip creation of MASQUERADE rules via iptables when executing weave expose command

This commit is contained in:
Aaron Hurt committed 2018-08-31 11:46:31 -05:00
1 parent ad4e4238a5
commit 4b9c533b94
6 files changed
+42 -15

No files matched your search

+11 -2
View File
@@ -3,6 +3,7 @@ package router
import (
"fmt"
"net/http"
"strconv"
"github.com/gorilla/mux"
@@ -29,15 +30,23 @@ func (router *NetworkRouter) HandleHTTP(muxRouter *mux.Router) {
router.ForgetConnections(r.Form["peer"])
})
muxRouter.Methods("POST").Path("/expose/{ip}/{prefixlen}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
muxRouter.Methods("POST").Path("/expose/{ip}/{prefixlen}/{skipNAT}").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
var skipNAT bool
cidr, err := address.ParseCIDR(vars["ip"] + "/" + vars["prefixlen"])
if err != nil {
http.Error(w, fmt.Sprint("unable to parse ip addr: ", err.Error()), http.StatusBadRequest)
return
}
if err = net.Expose(router.BridgeConfig.WeaveBridgeName, cidr.IPNet(), router.BridgeConfig.AWSVPC, router.BridgeConfig.NPC); err != nil {
if vars["skipNAT"] != "" {
skipNAT, err = strconv.ParseBool(vars["skipNAT"])
if 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
}