Merge pull request #160 from gravitl/feature_v0.5_uiint

feature_v0.5_uiint
This commit is contained in:
Alex 2021-05-31 18:43:55 -04:00 committed by GitHub
commit 0ffb590b99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 21 deletions

View file

@ -565,17 +565,28 @@ func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, erro
var nodechange models.Node var nodechange models.Node
nodechange.IsEgressGateway = true nodechange.IsEgressGateway = true
nodechange.EgressGatewayRange = gateway.RangeString nodechange.EgressGatewayRange = gateway.RangeString
if gateway.PostUp == "" { nodechange.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
nodechange.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + gateway.Interface + " -j MASQUERADE" nodechange.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
} else { if gateway.PostUp != "" {
nodechange.PostUp = gateway.PostUp nodechange.PostUp = gateway.PostUp
} }
if gateway.PostDown == "" { if gateway.PostDown != "" {
nodechange.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
} else {
nodechange.PostDown = gateway.PostDown nodechange.PostDown = gateway.PostDown
} }
if node.PostUp != "" {
if !strings.Contains(node.PostUp, nodechange.PostUp) {
nodechange.PostUp = node.PostUp + "; " + nodechange.PostUp
} else {
nodechange.PostUp = node.PostUp
}
}
if node.PostDown != "" {
if !strings.Contains(node.PostDown, nodechange.PostDown) {
nodechange.PostDown = node.PostDown + "; " + nodechange.PostDown
} else {
nodechange.PostDown = node.PostDown
}
}
collection := mongoconn.Client.Database("netmaker").Collection("nodes") collection := mongoconn.Client.Database("netmaker").Collection("nodes")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
// Create filter // Create filter
@ -705,16 +716,26 @@ func CreateIngressGateway(netid string, macaddress string) (models.Node, error)
log.Println("Could not find network.") log.Println("Could not find network.")
return models.Node{}, err return models.Node{}, err
} }
var nodechange models.Node
nodechange.IngressGatewayRange = network.AddressRange
nodechange.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + node.Interface + " -j MASQUERADE"
nodechange.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + node.Interface + " -j MASQUERADE"
if node.PostUp != "" {
if !strings.Contains(node.PostUp, nodechange.PostUp) {
nodechange.PostUp = node.PostUp + "; " + nodechange.PostUp
} else {
nodechange.PostUp = node.PostUp
}
}
if node.PostDown != "" {
if !strings.Contains(node.PostDown, nodechange.PostDown) {
nodechange.PostDown = node.PostDown + "; " + nodechange.PostDown
} else {
nodechange.PostDown = node.PostDown
}
}
if node.IsEgressGateway { collection := mongoconn.Client.Database("netmaker").Collection("nodes")
errors.New("Node cannot be both Ingress and Egress Gateway in same network.")
return models.Node{}, err
}
node.IngressGatewayRange = network.AddressRange
node.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + node.Interface + " -j MASQUERADE"
node.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + node.Interface + " -j MASQUERADE"
collection := mongoconn.Client.Database("netmaker").Collection("nodes")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
// Create filter // Create filter
filter := bson.M{"macaddress": macaddress, "network": netid} filter := bson.M{"macaddress": macaddress, "network": netid}
@ -722,10 +743,10 @@ func CreateIngressGateway(netid string, macaddress string) (models.Node, error)
// prepare update model. // prepare update model.
update := bson.D{ update := bson.D{
{"$set", bson.D{ {"$set", bson.D{
{"postup", node.PostUp}, {"postup", nodechange.PostUp},
{"postdown", node.PostDown}, {"postdown", nodechange.PostDown},
{"isingressgateway", true}, {"isingressgateway", true},
{"ingressgatewayrange", node.IngressGatewayRange}, {"ingressgatewayrange", nodechange.IngressGatewayRange},
{"lastmodified", node.LastModified}, {"lastmodified", node.LastModified},
}}, }},
} }

View file

@ -3,7 +3,8 @@ set -e
[ -z "$KEY" ] && KEY=nokey; [ -z "$KEY" ] && KEY=nokey;
wget -O netclient https://github.com/gravitl/netmaker/releases/download/latest/netclient wget -O netclient https://github.com/gravitl/netmaker/releases/download/v0.5/netclient
chmod +x netclient chmod +x netclient
sudo ./netclient -c install -t $KEY sudo ./netclient register -t $KEY
sudo ./netclient join -t $KEY
rm -f netclient rm -f netclient