mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 08:47:35 +08:00
gateway works but local address not being set to endpoint.
This commit is contained in:
@@ -20,6 +20,7 @@ func (s *NodeServiceServer) ReadNode(ctx context.Context, req *nodepb.ReadNodeRe
|
||||
// convert string id (from proto) to mongoDB ObjectId
|
||||
macaddress := req.GetMacaddress()
|
||||
networkName := req.GetNetwork()
|
||||
network, _ := functions.GetParentNetwork(networkName)
|
||||
|
||||
node, err := GetNode(macaddress, networkName)
|
||||
|
||||
@@ -50,6 +51,9 @@ func (s *NodeServiceServer) ReadNode(ctx context.Context, req *nodepb.ReadNodeRe
|
||||
Publickey: node.PublicKey,
|
||||
Listenport: node.ListenPort,
|
||||
Keepalive: node.PersistentKeepalive,
|
||||
Islocal: *network.IsLocal,
|
||||
Localrange: network.LocalRange,
|
||||
|
||||
},
|
||||
}
|
||||
return response, nil
|
||||
@@ -87,9 +91,9 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.CreateNo
|
||||
//Check to see if key is valid
|
||||
//TODO: Triple inefficient!!! This is the third call to the DB we make for networks
|
||||
validKey := functions.IsKeyValid(node.Network, node.AccessKey)
|
||||
network, _ := functions.GetParentNetwork(node.Network)
|
||||
|
||||
if !validKey {
|
||||
network, _ := functions.GetParentNetwork(node.Network)
|
||||
//Check to see if network will allow manual sign up
|
||||
//may want to switch this up with the valid key check and avoid a DB call that way.
|
||||
if *network.AllowManualSignUp {
|
||||
@@ -126,6 +130,8 @@ func (s *NodeServiceServer) CreateNode(ctx context.Context, req *nodepb.CreateNo
|
||||
Publickey: node.PublicKey,
|
||||
Listenport: node.ListenPort,
|
||||
Keepalive: node.PersistentKeepalive,
|
||||
Islocal: *network.IsLocal,
|
||||
Localrange: network.LocalRange,
|
||||
},
|
||||
}
|
||||
err = SetNetworkNodesLastModified(node.Network)
|
||||
@@ -208,6 +214,8 @@ func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.UpdateNo
|
||||
// Convert the Id string to a MongoDB ObjectId
|
||||
macaddress := nodechange.MacAddress
|
||||
networkName := nodechange.Network
|
||||
network, _ := functions.GetParentNetwork(networkName)
|
||||
|
||||
|
||||
err := ValidateNode("update", networkName, nodechange)
|
||||
if err != nil {
|
||||
@@ -247,6 +255,8 @@ func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.UpdateNo
|
||||
Publickey: newnode.PublicKey,
|
||||
Listenport: newnode.ListenPort,
|
||||
Keepalive: newnode.PersistentKeepalive,
|
||||
Islocal: *network.IsLocal,
|
||||
Localrange: network.LocalRange,
|
||||
|
||||
},
|
||||
}, nil
|
||||
|
131
grpc/node.pb.go
131
grpc/node.pb.go
@@ -137,6 +137,8 @@ type Node struct {
|
||||
Localaddress string `protobuf:"bytes,20,opt,name=localaddress,proto3" json:"localaddress,omitempty"`
|
||||
Postchanges string `protobuf:"bytes,21,opt,name=postchanges,proto3" json:"postchanges,omitempty"`
|
||||
Allowedips string `protobuf:"bytes,22,opt,name=allowedips,proto3" json:"allowedips,omitempty"`
|
||||
Islocal bool `protobuf:"varint,23,opt,name=islocal,proto3" json:"islocal,omitempty"`
|
||||
Localrange string `protobuf:"bytes,24,opt,name=localrange,proto3" json:"localrange,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
@@ -321,6 +323,20 @@ func (m *Node) GetAllowedips() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *Node) GetIslocal() bool {
|
||||
if m != nil {
|
||||
return m.Islocal
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *Node) GetLocalrange() string {
|
||||
if m != nil {
|
||||
return m.Localrange
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type CheckInResponse struct {
|
||||
Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"`
|
||||
Needpeerupdate bool `protobuf:"varint,2,opt,name=needpeerupdate,proto3" json:"needpeerupdate,omitempty"`
|
||||
@@ -1018,61 +1034,62 @@ func init() {
|
||||
func init() { proto.RegisterFile("grpc/node.proto", fileDescriptor_d13bd996b67da4ef) }
|
||||
|
||||
var fileDescriptor_d13bd996b67da4ef = []byte{
|
||||
// 882 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0x5d, 0x6f, 0xe4, 0x34,
|
||||
0x14, 0xd5, 0xcc, 0x76, 0x3a, 0xd3, 0x3b, 0x9d, 0xb6, 0xeb, 0xb2, 0x2b, 0x2b, 0x42, 0xd5, 0x28,
|
||||
0x42, 0xa8, 0x8b, 0x68, 0xa7, 0x14, 0x09, 0xf1, 0x86, 0xc4, 0x22, 0xad, 0x90, 0x60, 0x05, 0x41,
|
||||
0xbc, 0xf0, 0xe6, 0xc6, 0xb7, 0xd9, 0x68, 0x52, 0xdb, 0x8d, 0x3d, 0x1d, 0xf5, 0x07, 0x20, 0xfe,
|
||||
0x05, 0xbf, 0x94, 0x07, 0xe4, 0x8f, 0x4c, 0x9c, 0x74, 0x68, 0x97, 0xdd, 0xb7, 0xf8, 0xe4, 0xde,
|
||||
0x7b, 0x7c, 0x8f, 0x8f, 0x6f, 0x02, 0x87, 0x45, 0xad, 0xf2, 0x85, 0x90, 0x1c, 0xcf, 0x55, 0x2d,
|
||||
0x8d, 0x24, 0x3b, 0xf6, 0x39, 0xe5, 0xb0, 0xff, 0x93, 0x2c, 0x4a, 0x91, 0xe1, 0xed, 0x0a, 0xb5,
|
||||
0x21, 0x27, 0x00, 0x37, 0x2c, 0x67, 0x9c, 0xd7, 0xa8, 0x35, 0x1d, 0xcc, 0x07, 0xa7, 0x7b, 0x59,
|
||||
0x84, 0x90, 0x04, 0x26, 0x8a, 0x69, 0xbd, 0x96, 0x35, 0xa7, 0x43, 0xf7, 0x76, 0xb3, 0x26, 0x14,
|
||||
0xc6, 0x02, 0xcd, 0x5a, 0xd6, 0x4b, 0xfa, 0xcc, 0xbd, 0x6a, 0x96, 0xe9, 0x57, 0x30, 0x0b, 0x2c,
|
||||
0x5a, 0x49, 0xa1, 0x91, 0xcc, 0x61, 0xca, 0xf2, 0x1c, 0xb5, 0x36, 0x72, 0x89, 0x22, 0xf0, 0xc4,
|
||||
0x50, 0xfa, 0xf7, 0x08, 0x76, 0xde, 0x4a, 0x8e, 0xe4, 0x00, 0x86, 0x25, 0x0f, 0x11, 0xc3, 0x92,
|
||||
0x13, 0x02, 0x3b, 0x82, 0xdd, 0x60, 0x60, 0x77, 0xcf, 0x96, 0xb9, 0xd9, 0x72, 0x60, 0x6e, 0xf6,
|
||||
0x7b, 0x02, 0x50, 0x95, 0xda, 0xa0, 0x50, 0xb2, 0x36, 0x74, 0x67, 0x3e, 0x38, 0x1d, 0x65, 0x11,
|
||||
0x42, 0x3e, 0x85, 0x3d, 0xb5, 0xba, 0xaa, 0xca, 0x7c, 0x89, 0xf7, 0x74, 0xe4, 0x72, 0x5b, 0xc0,
|
||||
0x76, 0x8b, 0x82, 0x2b, 0x59, 0x0a, 0x43, 0x77, 0x7d, 0xb7, 0xcd, 0xba, 0xa7, 0xd4, 0xf8, 0x51,
|
||||
0xa5, 0x26, 0x3d, 0xa5, 0xe6, 0x30, 0xb5, 0xea, 0x37, 0x6a, 0xed, 0xf9, 0xf6, 0x23, 0xc8, 0xee,
|
||||
0xab, 0xd4, 0x0a, 0x05, 0x2f, 0x45, 0x41, 0x61, 0x3e, 0x38, 0x9d, 0x64, 0x2d, 0x40, 0x5e, 0xc2,
|
||||
0xae, 0x92, 0xda, 0xac, 0x14, 0x9d, 0xba, 0xd4, 0xb0, 0x72, 0x9c, 0x52, 0x1b, 0x2e, 0xd7, 0x82,
|
||||
0xee, 0x07, 0xce, 0xb0, 0xb6, 0x15, 0x97, 0x88, 0x8a, 0x55, 0xe5, 0x1d, 0xd2, 0x99, 0x13, 0xa2,
|
||||
0x05, 0x6c, 0x37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xfe, 0xd2, 0xae,
|
||||
0x56, 0xd7, 0x0b, 0x73, 0xaf, 0x50, 0x2f, 0x96, 0x42, 0xae, 0x85, 0xfb, 0x7f, 0x53, 0x57, 0x57,
|
||||
0xbb, 0xee, 0xe5, 0xd7, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0x4d, 0x2e, 0x68, 0x98, 0xd5, 0x09,
|
||||
0x00, 0x00,
|
||||
// 903 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0x5f, 0x6f, 0xe4, 0x34,
|
||||
0x10, 0x57, 0xf7, 0xba, 0xdd, 0xed, 0x6c, 0xb7, 0xed, 0xb9, 0xdc, 0x61, 0xad, 0x50, 0xb5, 0x8a,
|
||||
0x10, 0xea, 0x21, 0xda, 0x2d, 0x45, 0x42, 0xbc, 0x21, 0x71, 0x48, 0x27, 0x24, 0x38, 0x41, 0x10,
|
||||
0x2f, 0xbc, 0xb9, 0xf1, 0x34, 0x17, 0x6d, 0x6a, 0xa7, 0xb1, 0xb7, 0xab, 0x7e, 0x00, 0xc4, 0x57,
|
||||
0xe4, 0xc3, 0xf0, 0x80, 0x3c, 0x76, 0x36, 0x4e, 0x5a, 0xda, 0x83, 0x7b, 0x8b, 0x7f, 0x9e, 0x3f,
|
||||
0x9e, 0x9f, 0x7f, 0x33, 0x0e, 0x1c, 0xe4, 0x75, 0x95, 0x2d, 0x94, 0x96, 0x78, 0x56, 0xd5, 0xda,
|
||||
0x6a, 0xb6, 0xed, 0xbe, 0x13, 0x09, 0x7b, 0x3f, 0xea, 0xbc, 0x50, 0x29, 0xde, 0xac, 0xd0, 0x58,
|
||||
0x76, 0x0c, 0x70, 0x2d, 0x32, 0x21, 0x65, 0x8d, 0xc6, 0xf0, 0xad, 0xf9, 0xd6, 0xc9, 0x6e, 0x1a,
|
||||
0x21, 0x6c, 0x06, 0xe3, 0x4a, 0x18, 0xb3, 0xd6, 0xb5, 0xe4, 0x03, 0xda, 0xdd, 0xac, 0x19, 0x87,
|
||||
0x91, 0x42, 0xbb, 0xd6, 0xf5, 0x92, 0x3f, 0xa3, 0xad, 0x66, 0x99, 0x7c, 0x09, 0xd3, 0x90, 0xc5,
|
||||
0x54, 0x5a, 0x19, 0x64, 0x73, 0x98, 0x88, 0x2c, 0x43, 0x63, 0xac, 0x5e, 0xa2, 0x0a, 0x79, 0x62,
|
||||
0x28, 0xf9, 0x6b, 0x08, 0xdb, 0x6f, 0xb5, 0x44, 0xb6, 0x0f, 0x83, 0x42, 0x06, 0x8b, 0x41, 0x21,
|
||||
0x19, 0x83, 0x6d, 0x25, 0xae, 0x31, 0x64, 0xa7, 0x6f, 0x97, 0xb9, 0x39, 0x72, 0xc8, 0xdc, 0x9c,
|
||||
0xf7, 0x18, 0xa0, 0x2c, 0x8c, 0x45, 0x55, 0xe9, 0xda, 0xf2, 0xed, 0xf9, 0xd6, 0xc9, 0x30, 0x8d,
|
||||
0x10, 0xf6, 0x09, 0xec, 0x56, 0xab, 0xcb, 0xb2, 0xc8, 0x96, 0x78, 0xc7, 0x87, 0xe4, 0xdb, 0x02,
|
||||
0xae, 0x5a, 0x54, 0xb2, 0xd2, 0x85, 0xb2, 0x7c, 0xc7, 0x57, 0xdb, 0xac, 0x7b, 0x4c, 0x8d, 0x1e,
|
||||
0x65, 0x6a, 0xdc, 0x63, 0x6a, 0x0e, 0x13, 0xc7, 0x7e, 0xc3, 0xd6, 0xae, 0x2f, 0x3f, 0x82, 0xdc,
|
||||
0xb9, 0x0a, 0x53, 0xa1, 0x92, 0x85, 0xca, 0x39, 0xcc, 0xb7, 0x4e, 0xc6, 0x69, 0x0b, 0xb0, 0x97,
|
||||
0xb0, 0x53, 0x69, 0x63, 0x57, 0x15, 0x9f, 0x90, 0x6b, 0x58, 0x51, 0x4e, 0x6d, 0xac, 0xd4, 0x6b,
|
||||
0xc5, 0xf7, 0x42, 0xce, 0xb0, 0x76, 0x11, 0x97, 0x88, 0x95, 0x28, 0x8b, 0x5b, 0xe4, 0x53, 0x22,
|
||||
0xa2, 0x05, 0x5c, 0x35, 0x46, 0xdc, 0x62, 0xa6, 0xd5, 0x55, 0x91, 0xf3, 0x7d, 0x4a, 0x18, 0x21,
|
||||
0xce, 0xdb, 0xdf, 0x8e, 0xe3, 0xe9, 0xc0, 0xf3, 0xb4, 0x01, 0xe8, 0xb4, 0xca, 0x62, 0x7d, 0x25,
|
||||
0x32, 0xe4, 0x87, 0x7e, 0x77, 0x03, 0xb8, 0x6a, 0x4b, 0x61, 0x6c, 0xf6, 0x0e, 0xb3, 0x65, 0xa1,
|
||||
0xf8, 0x73, 0x5f, 0x6d, 0x04, 0xb1, 0x04, 0xf6, 0xdc, 0xf2, 0x5a, 0xcb, 0xe2, 0xaa, 0x40, 0xc9,
|
||||
0x19, 0x99, 0x74, 0x30, 0x76, 0x02, 0x07, 0xc1, 0x9c, 0x22, 0xdf, 0x8a, 0x92, 0x1f, 0x51, 0x15,
|
||||
0x7d, 0x98, 0xa2, 0xe9, 0x4c, 0x94, 0xcd, 0xdd, 0x7c, 0x14, 0xa2, 0x45, 0x98, 0x3b, 0x93, 0x63,
|
||||
0x26, 0x7b, 0x27, 0x54, 0x8e, 0x86, 0xbf, 0xf0, 0x67, 0x8a, 0x20, 0xc7, 0x88, 0x28, 0x4b, 0xbd,
|
||||
0x46, 0x59, 0x54, 0x86, 0xbf, 0xf4, 0xf7, 0xdb, 0x22, 0x4e, 0x73, 0x85, 0xa1, 0x98, 0xfc, 0x63,
|
||||
0xa2, 0xab, 0x59, 0x92, 0xe6, 0xdc, 0x47, 0xed, 0x02, 0x71, 0xee, 0x3d, 0x5b, 0x24, 0xf9, 0x63,
|
||||
0x00, 0x07, 0xaf, 0xdd, 0x99, 0x7f, 0x68, 0x1b, 0x82, 0xc3, 0xc8, 0xac, 0x88, 0x4f, 0x92, 0xfa,
|
||||
0x38, 0x6d, 0x96, 0xec, 0x33, 0xd8, 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, 0xa7, 0xf3, 0xfe, 0x02, 0xd3, 0xef, 0x49, 0x4f, 0xef, 0x9b, 0xd9, 0x89,
|
||||
0xdf, 0xa7, 0x7a, 0xdb, 0xbe, 0x23, 0x31, 0x94, 0xbc, 0xea, 0x86, 0x34, 0xff, 0xde, 0x9d, 0xae,
|
||||
0xea, 0x37, 0x68, 0x83, 0x8a, 0x3f, 0xa4, 0xea, 0x6f, 0xe2, 0x40, 0x86, 0xbd, 0x82, 0xa1, 0xeb,
|
||||
0x6d, 0x13, 0xca, 0x3e, 0xf2, 0x65, 0x77, 0xba, 0x25, 0xf5, 0x16, 0xc9, 0x17, 0x00, 0x9b, 0x69,
|
||||
0xf2, 0xf4, 0xbd, 0xfe, 0x14, 0x59, 0x1b, 0xf6, 0xed, 0x66, 0xa8, 0xd6, 0x21, 0x6a, 0x70, 0x7c,
|
||||
0xe1, 0x1d, 0x7b, 0x63, 0x2a, 0xed, 0x5b, 0x5f, 0xfc, 0x3d, 0x80, 0x89, 0x8b, 0xfe, 0x2b, 0xd6,
|
||||
0xb7, 0x45, 0x86, 0xec, 0x1c, 0x86, 0xf4, 0xd2, 0x33, 0xe6, 0x03, 0xc4, 0x3f, 0x17, 0xb3, 0xa3,
|
||||
0x0e, 0x16, 0x7a, 0xfe, 0x6b, 0x80, 0x56, 0xca, 0x2c, 0x98, 0x74, 0xba, 0x61, 0xf6, 0x00, 0x68,
|
||||
0xd8, 0x39, 0x8c, 0x1b, 0x99, 0xb0, 0xe7, 0xde, 0x20, 0xd2, 0xdf, 0xec, 0x1e, 0x64, 0x5c, 0xa6,
|
||||
0x56, 0xd2, 0x4d, 0xa6, 0x4e, 0x57, 0xcc, 0x1e, 0x00, 0xc9, 0xaf, 0x95, 0x43, 0xe3, 0xd7, 0xd1,
|
||||
0xdc, 0xec, 0x01, 0xd0, 0xb0, 0x0b, 0x18, 0x37, 0x57, 0xda, 0x9c, 0x30, 0xd2, 0xca, 0xec, 0x1e,
|
||||
0x64, 0xce, 0xb7, 0xd8, 0x29, 0x8c, 0x02, 0xe7, 0xec, 0xb0, 0x77, 0x05, 0x37, 0xb3, 0x3e, 0x62,
|
||||
0xbe, 0x5b, 0xfc, 0x7e, 0x9a, 0x6b, 0x9d, 0x97, 0x78, 0x96, 0xeb, 0x52, 0xa8, 0xfc, 0x4c, 0xd7,
|
||||
0xf9, 0x82, 0xfe, 0xef, 0x2e, 0x57, 0x57, 0x0b, 0x7b, 0x57, 0xa1, 0x59, 0x2c, 0x95, 0x5e, 0x2b,
|
||||
0xfa, 0xf3, 0xab, 0x2e, 0x2f, 0x77, 0x68, 0xf3, 0xab, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x44,
|
||||
0xc2, 0xe7, 0x07, 0x0f, 0x0a, 0x00, 0x00,
|
||||
}
|
||||
|
@@ -43,6 +43,8 @@ message Node {
|
||||
string localaddress = 20;
|
||||
string postchanges = 21;
|
||||
string allowedips = 22;
|
||||
bool islocal = 23;
|
||||
string localrange = 24;
|
||||
}
|
||||
|
||||
message CheckInResponse {
|
||||
|
7
main.go
7
main.go
@@ -164,12 +164,15 @@ func runGRPC(wg *sync.WaitGroup, installserver bool) {
|
||||
if installserver {
|
||||
fmt.Println("Adding server to " + config.Config.Server.DefaultNetName)
|
||||
success, err := serverctl.AddNetwork(config.Config.Server.DefaultNetName)
|
||||
if err != nil || !success {
|
||||
if err != nil {
|
||||
fmt.Printf("Error adding to default network: %v", err)
|
||||
fmt.Println("")
|
||||
fmt.Println("Unable to add server to network. Continuing.")
|
||||
fmt.Println("Please investigate client installation on server.")
|
||||
} else {
|
||||
} else if !success {
|
||||
fmt.Println("Unable to add server to network. Continuing.")
|
||||
fmt.Println("Please investigate client installation on server.")
|
||||
} else{
|
||||
fmt.Println("Server successfully added to default network.")
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,9 @@ type NodeConfig struct {
|
||||
LocalAddress string `yaml:"localaddress"`
|
||||
WGAddress string `yaml:"wgaddress"`
|
||||
RoamingOff bool `yaml:"roamingoff"`
|
||||
IsLocal bool `yaml:"islocal"`
|
||||
AllowedIPs string `yaml:"allowedips"`
|
||||
LocalRange string `yaml:"localrange"`
|
||||
PostUp string `yaml:"postup"`
|
||||
PostDown string `yaml:"postdown"`
|
||||
Port int32 `yaml:"port"`
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package functions
|
||||
|
||||
import (
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"fmt"
|
||||
"time"
|
||||
"errors"
|
||||
@@ -110,6 +109,7 @@ func Install(accesskey string, password string, server string, network string, n
|
||||
}
|
||||
fmt.Println(trange)
|
||||
if trange != "" {
|
||||
fmt.Println("This is a local network. Proceeding with local address as endpoint.")
|
||||
islocal = true
|
||||
_, localrange, err = net.ParseCIDR(trange)
|
||||
if err == nil {
|
||||
@@ -201,16 +201,6 @@ func Install(accesskey string, password string, server string, network string, n
|
||||
var name string
|
||||
var wginterface string
|
||||
|
||||
if nodecfg.Endpoint == "" {
|
||||
endpoint, err = getPublicIP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
endpoint = nodecfg.Endpoint
|
||||
}
|
||||
fmt.Println(" Public Endpoint: " + endpoint)
|
||||
|
||||
if nodecfg.LocalAddress == "" {
|
||||
ifaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
@@ -262,6 +252,21 @@ func Install(accesskey string, password string, server string, network string, n
|
||||
}
|
||||
fmt.Println(" Local Address: " + localaddress)
|
||||
|
||||
if nodecfg.Endpoint == "" {
|
||||
if islocal && localaddress != "" {
|
||||
endpoint = localaddress
|
||||
} else {
|
||||
endpoint, err = getPublicIP()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
endpoint = nodecfg.Endpoint
|
||||
}
|
||||
fmt.Println(" Public Endpoint: " + endpoint)
|
||||
|
||||
|
||||
if nodecfg.Name != "" {
|
||||
name = nodecfg.Name
|
||||
}
|
||||
@@ -405,6 +410,16 @@ func Install(accesskey string, password string, server string, network string, n
|
||||
fmt.Println(" KeepAlive: " + strconv.FormatInt(int64(node.Keepalive), 10))
|
||||
fmt.Println(" Public Key: " + node.Publickey)
|
||||
fmt.Println(" Mac Address: " + node.Macaddress)
|
||||
fmt.Println(" Is Local?: " + strconv.FormatBool(node.Islocal))
|
||||
fmt.Println(" Local Range: " + node.Localrange)
|
||||
|
||||
if !islocal && node.Islocal && node.Localrange != "" {
|
||||
node.Localaddress, err = getLocalIP(node.Localrange)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
node.Endpoint = node.Localaddress
|
||||
}
|
||||
|
||||
err = modConfig(node)
|
||||
if err != nil {
|
||||
@@ -419,10 +434,9 @@ func Install(accesskey string, password string, server string, network string, n
|
||||
err = ConfigureSystemD(network)
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
peers, err := getPeers(node.Macaddress, network, server)
|
||||
peers, hasGateway, gateways, err := getPeers(node.Macaddress, network, server)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -432,7 +446,7 @@ func Install(accesskey string, password string, server string, network string, n
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = initWireguard(node, privkeystring, peers)
|
||||
err = initWireguard(node, privkeystring, peers, hasGateway, gateways)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -446,6 +460,52 @@ func Install(accesskey string, password string, server string, network string, n
|
||||
return err
|
||||
}
|
||||
|
||||
func getLocalIP(localrange string) (string, error) {
|
||||
_, localRange, err := net.ParseCIDR(localrange)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
ifaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
var local string
|
||||
found := false
|
||||
for _, i := range ifaces {
|
||||
if i.Flags&net.FlagUp == 0 {
|
||||
continue // interface down
|
||||
}
|
||||
if i.Flags&net.FlagLoopback != 0 {
|
||||
continue // loopback interface
|
||||
}
|
||||
addrs, err := i.Addrs()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
var ip net.IP
|
||||
switch v := addr.(type) {
|
||||
case *net.IPNet:
|
||||
if !found {
|
||||
ip = v.IP
|
||||
local = ip.String()
|
||||
found = localRange.Contains(ip)
|
||||
}
|
||||
case *net.IPAddr:
|
||||
if !found {
|
||||
ip = v.IP
|
||||
local = ip.String()
|
||||
found = localRange.Contains(ip)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !found || local == "" {
|
||||
return "", errors.New("Failed to find local IP in range " + localrange)
|
||||
}
|
||||
return local, nil
|
||||
}
|
||||
|
||||
func getPublicIP() (string, error) {
|
||||
|
||||
iplist := []string{"https://ifconfig.me", "http://api.ipify.org", "http://ipinfo.io/ip"}
|
||||
@@ -478,9 +538,7 @@ func modConfig(node *nodepb.Node) error{
|
||||
if network == "" {
|
||||
return errors.New("No Network Provided")
|
||||
}
|
||||
//modconfig := config.Config
|
||||
modconfig, err := config.ReadConfig(network)
|
||||
//modconfig.ReadConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -527,6 +585,10 @@ func modConfig(node *nodepb.Node) error{
|
||||
if node.Postchanges != "" {
|
||||
nodecfg.PostChanges = node.Postchanges
|
||||
}
|
||||
if node.Localrange != "" && node.Islocal {
|
||||
nodecfg.IsLocal = true
|
||||
nodecfg.LocalRange = node.Localrange
|
||||
}
|
||||
modconfig.Node = nodecfg
|
||||
err = config.Write(modconfig, network)
|
||||
return err
|
||||
@@ -549,7 +611,7 @@ func getMacAddr() ([]string, error) {
|
||||
}
|
||||
|
||||
|
||||
func initWireguard(node *nodepb.Node, privkey string, peers []wgtypes.PeerConfig) error {
|
||||
func initWireguard(node *nodepb.Node, privkey string, peers []wgtypes.PeerConfig, hasGateway bool, gateways []string) error {
|
||||
|
||||
ipExec, err := exec.LookPath("ip")
|
||||
if err != nil {
|
||||
@@ -687,6 +749,10 @@ func initWireguard(node *nodepb.Node, privkey string, peers []wgtypes.PeerConfig
|
||||
}
|
||||
|
||||
err = cmdIPLinkUp.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if nodecfg.PostUp != "" {
|
||||
runcmds := strings.Split(nodecfg.PostUp, "; ")
|
||||
err = runCmds(runcmds)
|
||||
@@ -694,8 +760,14 @@ func initWireguard(node *nodepb.Node, privkey string, peers []wgtypes.PeerConfig
|
||||
fmt.Println("Error encountered running PostUp: " + err.Error())
|
||||
}
|
||||
}
|
||||
if (hasGateway) {
|
||||
for _, gateway := range gateways {
|
||||
out, err := exec.Command(ipExec,"-4","route","add",gateway,"dev",ifacename).Output()
|
||||
fmt.Println(string(out))
|
||||
if err != nil {
|
||||
return err
|
||||
fmt.Println("Error encountered adding gateway: " + err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -789,7 +861,7 @@ func setWGConfig(network string) error {
|
||||
nodecfg := cfg.Node
|
||||
node := getNode(network)
|
||||
|
||||
peers, err := getPeers(node.Macaddress, nodecfg.Network, servercfg.Address)
|
||||
peers, hasGateway, gateways, err := getPeers(node.Macaddress, nodecfg.Network, servercfg.Address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -798,7 +870,7 @@ func setWGConfig(network string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = initWireguard(&node, privkey, peers)
|
||||
err = initWireguard(&node, privkey, peers, hasGateway, gateways)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -875,6 +947,7 @@ func CheckIn(network string) error {
|
||||
ipchange := false
|
||||
|
||||
if !nodecfg.RoamingOff {
|
||||
if !nodecfg.IsLocal {
|
||||
fmt.Println("Checking to see if addresses have changed")
|
||||
extIP, err := getPublicIP()
|
||||
if err != nil {
|
||||
@@ -904,6 +977,25 @@ func CheckIn(network string) error {
|
||||
node.Postchanges = "true"
|
||||
ipchange = true
|
||||
}
|
||||
} else {
|
||||
fmt.Println("Checking to see if address has changed")
|
||||
localIP, err := getLocalIP(nodecfg.LocalRange)
|
||||
if err != nil {
|
||||
fmt.Printf("Error encountered checking ip addresses: %v", err)
|
||||
}
|
||||
if nodecfg.Endpoint != localIP && localIP != "" {
|
||||
fmt.Println("Endpoint has changed from " +
|
||||
nodecfg.Endpoint + " to " + localIP)
|
||||
fmt.Println("Updating address")
|
||||
nodecfg.Endpoint = localIP
|
||||
nodecfg.LocalAddress = localIP
|
||||
nodecfg.PostChanges = "true"
|
||||
node.Endpoint = localIP
|
||||
node.Localaddress = localIP
|
||||
node.Postchanges = "true"
|
||||
ipchange = true
|
||||
}
|
||||
}
|
||||
if node.Postchanges != "true" {
|
||||
fmt.Println("Addresses have not changed.")
|
||||
}
|
||||
@@ -1270,8 +1362,10 @@ func DeleteInterface(ifacename string, postdown string) error{
|
||||
return err
|
||||
}
|
||||
|
||||
func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerConfig, error) {
|
||||
func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerConfig, bool, []string, error) {
|
||||
//need to implement checkin on server side
|
||||
hasGateway := false
|
||||
var gateways []string
|
||||
var peers []wgtypes.PeerConfig
|
||||
var wcclient nodepb.NodeServiceClient
|
||||
cfg, err := config.ReadConfig(network)
|
||||
@@ -1304,7 +1398,7 @@ func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerC
|
||||
ctx, err = SetJWT(wcclient, network)
|
||||
if err != nil {
|
||||
fmt.Println("Failed to authenticate.")
|
||||
return peers, err
|
||||
return peers, hasGateway, gateways, err
|
||||
}
|
||||
var header metadata.MD
|
||||
|
||||
@@ -1312,7 +1406,7 @@ func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerC
|
||||
if err != nil {
|
||||
fmt.Println("Error retrieving peers")
|
||||
fmt.Println(err)
|
||||
return nil, err
|
||||
return nil, hasGateway, gateways, err
|
||||
}
|
||||
fmt.Println("Parsing peers response")
|
||||
for {
|
||||
@@ -1321,13 +1415,8 @@ func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerC
|
||||
|
||||
|
||||
if err == io.EOF {
|
||||
fmt.Println("ERROR ENCOUNTERED WITH peer")
|
||||
fmt.Println(res)
|
||||
fmt.Println(err)
|
||||
break
|
||||
}
|
||||
spew.Dump(res)
|
||||
|
||||
// if err, return an error
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "mongo: no documents in result") {
|
||||
@@ -1335,20 +1424,13 @@ func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerC
|
||||
} else {
|
||||
fmt.Println("ERROR ENCOUNTERED WITH RESPONSE")
|
||||
fmt.Println(res)
|
||||
return peers, err
|
||||
return peers, hasGateway, gateways, err
|
||||
}
|
||||
}
|
||||
fmt.Println("Got Peer: " + res.Peers.Publickey)
|
||||
fmt.Println(" Address: " +res.Peers.Address)
|
||||
fmt.Printf(" ListenPort: ",res.Peers.Listenport)
|
||||
fmt.Println("")
|
||||
fmt.Printf(" Gateway?: ",res.Peers.Isgateway)
|
||||
fmt.Println("")
|
||||
fmt.Println(" Gate Range: " + res.Peers.Gatewayrange)
|
||||
pubkey, err := wgtypes.ParseKey(res.Peers.Publickey)
|
||||
if err != nil {
|
||||
fmt.Println("error parsing key")
|
||||
return peers, err
|
||||
return peers, hasGateway, gateways, err
|
||||
}
|
||||
var peer wgtypes.PeerConfig
|
||||
var peeraddr = net.IPNet{
|
||||
@@ -1359,6 +1441,8 @@ func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerC
|
||||
allowedips = append(allowedips, peeraddr)
|
||||
|
||||
if res.Peers.Isgateway {
|
||||
hasGateway = true
|
||||
gateways = append(gateways,res.Peers.Gatewayrange)
|
||||
_, ipnet, err := net.ParseCIDR(res.Peers.Gatewayrange)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR ENCOUNTERED SETTING GATEWAY")
|
||||
@@ -1395,5 +1479,5 @@ func getPeers(macaddress string, network string, server string) ([]wgtypes.PeerC
|
||||
|
||||
}
|
||||
fmt.Println("Finished parsing peers response")
|
||||
return peers, err
|
||||
return peers, hasGateway, gateways, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user