mirror of
https://github.com/gravitl/netmaker.git
synced 2025-02-25 08:34:47 +08:00
Merge pull request #160 from gravitl/feature_v0.5_uiint
feature_v0.5_uiint
This commit is contained in:
commit
0ffb590b99
2 changed files with 43 additions and 21 deletions
|
@ -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},
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue