mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-10 17:48:25 +08:00
settings for comms network
This commit is contained in:
parent
0b1bf1b9aa
commit
f55eeedbb9
8 changed files with 82 additions and 8 deletions
|
@ -77,6 +77,7 @@ type ServerConfig struct {
|
|||
ManageIPTables string `yaml:"manageiptables"`
|
||||
PortForwardServices string `yaml:"portforwardservices"`
|
||||
HostNetwork string `yaml:"hostnetwork"`
|
||||
CommsCIDR string `yaml:"commscidr"`
|
||||
}
|
||||
|
||||
// SQLConfig - Generic SQL Config
|
||||
|
|
|
@ -174,10 +174,10 @@ func (s *NodeServiceServer) UpdateNode(ctx context.Context, req *nodepb.Object)
|
|||
}
|
||||
|
||||
func getServerAddrs(node *models.Node) {
|
||||
serverNodes := logic.GetServerNodes(node.Network)
|
||||
serverNodes := logic.GetServerNodes(serverctl.COMMS_NETID)
|
||||
//pubIP, _ := servercfg.GetPublicIP()
|
||||
if len(serverNodes) == 0 {
|
||||
if err := serverctl.SyncServerNetwork(node.Network); err != nil {
|
||||
if err := serverctl.SyncServerNetwork(serverctl.COMMS_NETID); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,7 +142,7 @@ func DecrimentKey(networkName string, keyvalue string) {
|
|||
var network models.Network
|
||||
|
||||
network, err := GetParentNetwork(networkName)
|
||||
if err != nil {
|
||||
if err != nil || network.IsComms == "yes" {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -170,13 +170,21 @@ func DecrimentKey(networkName string, keyvalue string) {
|
|||
// IsKeyValid - check if key is valid
|
||||
func IsKeyValid(networkname string, keyvalue string) bool {
|
||||
|
||||
network, _ := GetParentNetwork(networkname)
|
||||
network, err := GetParentNetwork(networkname)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
accesskeys := network.AccessKeys
|
||||
if network.IsComms == "yes" {
|
||||
accesskeys = getAllAccessKeys()
|
||||
}
|
||||
|
||||
var key models.AccessKey
|
||||
foundkey := false
|
||||
isvalid := false
|
||||
|
||||
for i := len(network.AccessKeys) - 1; i >= 0; i-- {
|
||||
currentkey := network.AccessKeys[i]
|
||||
for i := len(accesskeys) - 1; i >= 0; i-- {
|
||||
currentkey := accesskeys[i]
|
||||
if currentkey.Value == keyvalue {
|
||||
key = currentkey
|
||||
foundkey = true
|
||||
|
@ -230,3 +238,15 @@ func genKey() string {
|
|||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func getAllAccessKeys() []models.AccessKey {
|
||||
var accesskeys = make([]models.AccessKey, 0)
|
||||
networks, err := GetNetworks()
|
||||
if err != nil {
|
||||
return accesskeys
|
||||
}
|
||||
for i := range networks {
|
||||
accesskeys = append(accesskeys, networks[i].AccessKeys...)
|
||||
}
|
||||
return accesskeys
|
||||
}
|
||||
|
|
|
@ -39,7 +39,10 @@ func ServerJoin(networkSettings *models.Network) (models.Node, error) {
|
|||
if currentServers != nil {
|
||||
serverCount = len(currentServers) + 1
|
||||
}
|
||||
|
||||
var ishub = "no"
|
||||
if serverCount == 1 && (networkSettings.IsHubAndSpoke == "yes" || networkSettings.IsComms == "yes") {
|
||||
ishub = "yes"
|
||||
}
|
||||
var node = &models.Node{
|
||||
IsServer: "yes",
|
||||
DNSOn: "no",
|
||||
|
@ -52,6 +55,7 @@ func ServerJoin(networkSettings *models.Network) (models.Node, error) {
|
|||
LocalRange: networkSettings.LocalRange,
|
||||
OS: runtime.GOOS,
|
||||
Version: servercfg.Version,
|
||||
IsHub: ishub,
|
||||
}
|
||||
|
||||
SetNodeDefaults(node)
|
||||
|
|
3
main.go
3
main.go
|
@ -81,6 +81,9 @@ func initialize() { // Client Mode Prereq Check
|
|||
if err := serverctl.InitServerNetclient(); err != nil {
|
||||
logger.FatalLog("Did not find netclient to use CLIENT_MODE")
|
||||
}
|
||||
if err := serverctl.InitializeCommsNetwork(); err != nil {
|
||||
logger.FatalLog("could not inintialize comms network")
|
||||
}
|
||||
}
|
||||
// initialize iptables to ensure gateways work correctly and mq is forwarded if containerized
|
||||
if servercfg.ManageIPTables() != "off" {
|
||||
|
|
|
@ -27,6 +27,7 @@ type Network struct {
|
|||
IsIPv4 string `json:"isipv4" bson:"isipv4" validate:"checkyesorno"`
|
||||
IsIPv6 string `json:"isipv6" bson:"isipv6" validate:"checkyesorno"`
|
||||
IsHubAndSpoke string `json:"ishubandspoke" bson:"ishubandspoke" validate:"checkyesorno"`
|
||||
IsComms string `json:"iscomms" bson:"iscomms" validate:"checkyesorno"`
|
||||
LocalRange string `json:"localrange" bson:"localrange" validate:"omitempty,cidr"`
|
||||
DefaultUDPHolePunch string `json:"defaultudpholepunch" bson:"defaultudpholepunch" validate:"checkyesorno"`
|
||||
DefaultExtClientDNS string `json:"defaultextclientdns" bson:"defaultextclientdns"`
|
||||
|
@ -65,6 +66,9 @@ func (network *Network) SetDefaults() {
|
|||
if network.IsHubAndSpoke == "" {
|
||||
network.IsHubAndSpoke = "no"
|
||||
}
|
||||
if network.IsComms == "" {
|
||||
network.IsComms = "no"
|
||||
}
|
||||
if network.DefaultInterface == "" {
|
||||
if len(network.NetID) < 13 {
|
||||
network.DefaultInterface = "nm-" + network.NetID
|
||||
|
|
|
@ -3,6 +3,7 @@ package servercfg
|
|||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
@ -253,6 +254,21 @@ func GetGRPCPort() string {
|
|||
return grpcport
|
||||
}
|
||||
|
||||
// GetGRPCPort - gets the grpc port
|
||||
func GetCommsCIDR() string {
|
||||
netrange := "172.242.0.0/16"
|
||||
if os.Getenv("COMMS_CIDR") != "" {
|
||||
netrange = os.Getenv("COMMS_CIDR")
|
||||
} else if config.Config.Server.CommsCIDR != "" {
|
||||
netrange = config.Config.Server.CommsCIDR
|
||||
}
|
||||
_, _, err := net.ParseCIDR(netrange)
|
||||
if err == nil {
|
||||
return netrange
|
||||
}
|
||||
return "172.242.0.0/16"
|
||||
}
|
||||
|
||||
// GetMessageQueueEndpoint - gets the message queue endpoint
|
||||
func GetMessageQueueEndpoint() string {
|
||||
host, _ := GetPublicIP()
|
||||
|
|
|
@ -9,10 +9,36 @@ import (
|
|||
"github.com/gravitl/netmaker/database"
|
||||
"github.com/gravitl/netmaker/logger"
|
||||
"github.com/gravitl/netmaker/logic"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
"github.com/gravitl/netmaker/netclient/ncutils"
|
||||
"github.com/gravitl/netmaker/servercfg"
|
||||
)
|
||||
|
||||
const NETMAKER_BINARY_NAME = "netmaker"
|
||||
const (
|
||||
// NETMAKER_BINARY_NAME - name of netmaker binary
|
||||
NETMAKER_BINARY_NAME = "netmaker"
|
||||
|
||||
// COMMS_NETID - name of comms net
|
||||
COMMS_NETID = "n37m8k3r"
|
||||
)
|
||||
|
||||
func InitializeCommsNetwork() error {
|
||||
|
||||
_, err := logic.GetNetwork(COMMS_NETID)
|
||||
if err != nil {
|
||||
logger.Log(1, "comms net does not exist, creating")
|
||||
var network models.Network
|
||||
network.NetID = COMMS_NETID
|
||||
network.AddressRange = servercfg.GetCommsCIDR()
|
||||
network.IsHubAndSpoke = "yes"
|
||||
network.IsComms = "yes"
|
||||
return logic.CreateNetwork(network)
|
||||
} else {
|
||||
SyncServerNetwork(COMMS_NETID)
|
||||
}
|
||||
logger.Log(1, "comms network initialized")
|
||||
return nil
|
||||
}
|
||||
|
||||
// InitServerNetclient - intializes the server netclient
|
||||
// 1. Check if config directory exists, if not attempt to make
|
||||
|
|
Loading…
Reference in a new issue