Merge pull request #390 from gravitl/hotfix_v0.8.5_client_adjustment

Hotfix v0.8.5 client adjustment
This commit is contained in:
dcarns 2021-10-27 15:27:11 -04:00 committed by GitHub
commit 9e9945bb1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 98 additions and 38 deletions

View file

@ -12,7 +12,7 @@ services:
cap_add:
- NET_ADMIN
restart: always
network_mode: host
privileged: true
environment:
SERVER_HOST: "SERVER_PUBLIC_IP"
SERVER_API_CONN_STRING: "api.NETMAKER_BASE_DOMAIN:443"
@ -29,11 +29,15 @@ services:
SERVER_GRPC_WIREGUARD: "off"
CORS_ALLOWED_ORIGIN: "*"
DATABASE: "sqlite"
ports:
- "51821-51830:51821-51830/udp"
- "8081:8081"
- "50051:50051"
netmaker-ui:
container_name: netmaker-ui
depends_on:
- netmaker
image: gravitl/netmaker-ui:v0.8
image: gravitl/netmaker-ui:v0.8.5
links:
- "netmaker:api"
ports:

View file

@ -11,7 +11,7 @@ services:
cap_add:
- NET_ADMIN
restart: always
network_mode: host
privileged: true
environment:
SERVER_HOST: "SERVER_PUBLIC_IP"
SERVER_API_CONN_STRING: "api.NETMAKER_BASE_DOMAIN:443"
@ -28,11 +28,15 @@ services:
SERVER_GRPC_WIREGUARD: "off"
CORS_ALLOWED_ORIGIN: "*"
DATABASE: "sqlite"
ports:
- "51821-51830:51821-51830/udp"
- "8081:8081"
- "50051:50051"
netmaker-ui:
container_name: netmaker-ui
depends_on:
- netmaker
image: gravitl/netmaker-ui:v0.8
image: gravitl/netmaker-ui:v0.8.5
links:
- "netmaker:api"
ports:

View file

@ -12,7 +12,7 @@ services:
cap_add:
- NET_ADMIN
restart: always
network_mode: host
privileged: true
environment:
SERVER_HOST: "SERVER_PUBLIC_IP"
SERVER_API_CONN_STRING: "api.NETMAKER_BASE_DOMAIN:443"
@ -29,11 +29,15 @@ services:
SERVER_GRPC_WIREGUARD: "off"
CORS_ALLOWED_ORIGIN: "*"
DATABASE: "sqlite"
ports:
- "51821-51830:51821-51830/udp"
- "8081:8081"
- "50051:50051"
netmaker-ui:
container_name: netmaker-ui
depends_on:
- netmaker
image: gravitl/netmaker-ui:v0.8
image: gravitl/netmaker-ui:v0.8.5
links:
- "netmaker:api"
ports:

View file

@ -451,9 +451,11 @@ func isInterfacePresent(iface string, address string) (string, bool) {
}
for _, addr := range currAddrs {
if strings.Contains(addr.String(), address) && currIface.Name != iface {
Log("found iface "+addr.String()+" "+currIface.Name, 2)
return currIface.Name, false
}
}
}
Log("failed to find iface "+iface, 2)
return "", true
}

View file

@ -2,6 +2,7 @@ package logic
import (
"errors"
"fmt"
"net"
"os"
"runtime"
@ -108,6 +109,8 @@ func ServerJoin(network string, serverID string, privateKey string) error {
node.ListenPort, err = ncutils.GetFreePort(node.ListenPort)
if err != nil {
Log("Error retrieving port: "+err.Error(), 2)
} else {
Log("Set client port to "+fmt.Sprintf("%d", node.ListenPort)+" for network "+node.Network, 1)
}
// safety check. If returned node from server is local, but not currently configured as local, set to local addr
@ -123,7 +126,7 @@ func ServerJoin(network string, serverID string, privateKey string) error {
if err = StorePrivKey(node.ID, privateKey); err != nil {
return err
}
if err = ServerPush(node.MacAddress, node.Network); err != nil {
if err = ServerPush(node); err != nil {
return err
}
@ -151,7 +154,7 @@ func ServerCheckin(mac string, network string) error {
return err
}
newNode, err = ServerPull(mac, network, false)
newNode, err = ServerPull(&serverNode, false)
if isDeleteError(err) {
return ServerLeave(mac, network)
} else if err != nil {
@ -163,22 +166,16 @@ func ServerCheckin(mac string, network string) error {
return errors.New("node has been removed")
}
return ServerPush(newNode.MacAddress, newNode.Network)
return ServerPush(newNode)
}
// ServerPull - pulls current config/peers for server
func ServerPull(mac string, network string, onErr bool) (*models.Node, error) {
func ServerPull(serverNode *models.Node, onErr bool) (*models.Node, error) {
var serverNode models.Node
var err error
serverNode, err = GetNode(mac, network)
if err != nil {
return &serverNode, err
}
if serverNode.IPForwarding == "yes" {
if err = setIPForwardingLinux(); err != nil {
return &serverNode, err
return serverNode, err
}
}
serverNode.OS = runtime.GOOS
@ -196,38 +193,31 @@ func ServerPull(mac string, network string, onErr bool) (*models.Node, error) {
Log("removed old interface "+oldIfaceName, 1)
}
serverNode.PullChanges = "no"
if err = setWGConfig(serverNode, network, false); err != nil {
return &serverNode, err
if err = setWGConfig(*serverNode, serverNode.Network, false); err != nil {
return serverNode, err
}
// handle server side update
if err = UpdateNode(&serverNode, &serverNode); err != nil {
return &serverNode, err
if err = UpdateNode(serverNode, serverNode); err != nil {
return serverNode, err
}
} else {
if err = setWGConfig(serverNode, network, true); err != nil {
if err = setWGConfig(*serverNode, serverNode.Network, true); err != nil {
if errors.Is(err, os.ErrNotExist) {
return ServerPull(serverNode.MacAddress, serverNode.Network, true)
return ServerPull(serverNode, true)
} else {
return &serverNode, err
return serverNode, err
}
}
}
return &serverNode, nil
return serverNode, nil
}
// ServerPush - pushes config changes for server checkins/join
func ServerPush(mac string, network string) error {
var serverNode models.Node
var err error
serverNode, err = GetNode(mac, network)
if err != nil /* && !ncutils.IsEmptyRecord(err) May not be necessary */ {
return err
}
func ServerPush(serverNode *models.Node) error {
serverNode.OS = runtime.GOOS
serverNode.SetLastCheckIn()
return UpdateNode(&serverNode, &serverNode)
return UpdateNode(serverNode, serverNode)
}
// ServerLeave - removes a server node

View file

@ -169,7 +169,7 @@ func initWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
}
// set MTU of node interface
if _, err := ncutils.RunCmd(ipExec+" link set mtu "+strconv.Itoa(int(node.MTU))+" up dev "+ifacename, true); err != nil {
Log("failed to create interface with mtu "+ifacename, 2)
Log("failed to create interface with mtu "+strconv.Itoa(int(node.MTU))+" - "+ifacename, 2)
return err
}

View file

@ -271,6 +271,7 @@ func GetFreePort(rangestart int32) (int32, error) {
if err != nil {
return 0, err
}
for x := rangestart; x <= 65535; x++ {
conflict := false
for _, i := range devices {
@ -397,6 +398,12 @@ func FileExists(f string) bool {
if os.IsNotExist(err) {
return false
}
if err != nil && strings.Contains(err.Error(), "not a directory") {
return false
}
if err != nil {
Log("error reading file: " + f + ", " + err.Error())
}
return !info.IsDir()
}

View file

@ -12,6 +12,7 @@ import (
"github.com/gravitl/netmaker/config"
)
// SetHost - sets the host ip
func SetHost() error {
remoteip, err := GetPublicIP()
if err != nil {
@ -20,6 +21,8 @@ func SetHost() error {
os.Setenv("SERVER_HOST", remoteip)
return nil
}
// GetServerConfig - gets the server config into memory from file or env
func GetServerConfig() config.ServerConfig {
var cfg config.ServerConfig
cfg.APIConnString = GetAPIConnString()
@ -76,6 +79,8 @@ func GetServerConfig() config.ServerConfig {
return cfg
}
// GetFrontendURL - gets the frontend url
func GetFrontendURL() string {
var frontend = ""
if os.Getenv("FRONTEND_URL") != "" {
@ -86,6 +91,7 @@ func GetFrontendURL() string {
return frontend
}
// GetAPIConnString - gets the api connections string
func GetAPIConnString() string {
conn := ""
if os.Getenv("SERVER_API_CONN_STRING") != "" {
@ -95,6 +101,8 @@ func GetAPIConnString() string {
}
return conn
}
// GetVersion - version of netmaker
func GetVersion() string {
version := "0.8.5"
if config.Config.Server.Version != "" {
@ -102,6 +110,8 @@ func GetVersion() string {
}
return version
}
// GetDB - gets the database type
func GetDB() string {
database := "sqlite"
if os.Getenv("DATABASE") != "" {
@ -111,6 +121,8 @@ func GetDB() string {
}
return database
}
// GetAPIHost - gets the api host
func GetAPIHost() string {
serverhost := "127.0.0.1"
remoteip, _ := GetPublicIP()
@ -127,6 +139,8 @@ func GetAPIHost() string {
}
return serverhost
}
// GetPodIP - get the pod's ip
func GetPodIP() string {
podip := "127.0.0.1"
if os.Getenv("POD_IP") != "" {
@ -135,6 +149,7 @@ func GetPodIP() string {
return podip
}
// GetAPIPort - gets the api port
func GetAPIPort() string {
apiport := "8081"
if os.Getenv("API_PORT") != "" {
@ -145,6 +160,7 @@ func GetAPIPort() string {
return apiport
}
// GetCheckinInterval - get check in interval for nodes
func GetCheckinInterval() string {
seconds := "15"
if os.Getenv("CHECKIN_INTERVAL") != "" {
@ -155,6 +171,7 @@ func GetCheckinInterval() string {
return seconds
}
// GetDefaultNodeLimit - get node limit if one is set
func GetDefaultNodeLimit() int32 {
var limit int32
limit = 999999999
@ -166,6 +183,8 @@ func GetDefaultNodeLimit() int32 {
}
return limit
}
// GetGRPCConnString - get grpc conn string
func GetGRPCConnString() string {
conn := ""
if os.Getenv("SERVER_GRPC_CONN_STRING") != "" {
@ -176,6 +195,7 @@ func GetGRPCConnString() string {
return conn
}
// GetCoreDNSAddr - gets the core dns address
func GetCoreDNSAddr() string {
addr, _ := GetPublicIP()
if os.Getenv("COREDNS_ADDR") != "" {
@ -186,6 +206,7 @@ func GetCoreDNSAddr() string {
return addr
}
// GetGRPCHost - get the grpc host url
func GetGRPCHost() string {
serverhost := "127.0.0.1"
remoteip, _ := GetPublicIP()
@ -202,6 +223,8 @@ func GetGRPCHost() string {
}
return serverhost
}
// GetGRPCPort - gets the grpc port
func GetGRPCPort() string {
grpcport := "50051"
if os.Getenv("GRPC_PORT") != "" {
@ -211,6 +234,8 @@ func GetGRPCPort() string {
}
return grpcport
}
// GetMasterKey - gets the configured master key of server
func GetMasterKey() string {
key := "secretkey"
if os.Getenv("MASTER_KEY") != "" {
@ -220,6 +245,8 @@ func GetMasterKey() string {
}
return key
}
// GetAllowedOrigin - get the allowed origin
func GetAllowedOrigin() string {
allowedorigin := "*"
if os.Getenv("CORS_ALLOWED_ORIGIN") != "" {
@ -229,6 +256,8 @@ func GetAllowedOrigin() string {
}
return allowedorigin
}
// IsRestBackend - checks if rest is on or off
func IsRestBackend() bool {
isrest := true
if os.Getenv("REST_BACKEND") != "" {
@ -242,6 +271,8 @@ func IsRestBackend() bool {
}
return isrest
}
// IsAgentBackend - checks if agent backed is on or off
func IsAgentBackend() bool {
isagent := true
if os.Getenv("AGENT_BACKEND") != "" {
@ -255,6 +286,8 @@ func IsAgentBackend() bool {
}
return isagent
}
// IsClientMode - checks if it should run in client mode
func IsClientMode() string {
isclient := "on"
if os.Getenv("CLIENT_MODE") != "" {
@ -274,6 +307,8 @@ func IsClientMode() string {
}
return isclient
}
// IsDNSMode - should it run with DNS
func IsDNSMode() bool {
isdns := true
if os.Getenv("DNS_MODE") != "" {
@ -288,6 +323,7 @@ func IsDNSMode() bool {
return isdns
}
// IsGRPCSSL - ssl grpc on or off
func IsGRPCSSL() bool {
isssl := false
if os.Getenv("GRPC_SSL") != "" {
@ -302,6 +338,7 @@ func IsGRPCSSL() bool {
return isssl
}
// DisableRemoteIPCheck - disable the remote ip check
func DisableRemoteIPCheck() bool {
disabled := false
if os.Getenv("DISABLE_REMOTE_IP_CHECK") != "" {
@ -315,6 +352,8 @@ func DisableRemoteIPCheck() bool {
}
return disabled
}
// DisableDefaultNet - disable default net
func DisableDefaultNet() bool {
disabled := false
if os.Getenv("DISABLE_DEFAULT_NET") != "" {
@ -328,6 +367,8 @@ func DisableDefaultNet() bool {
}
return disabled
}
// GetPublicIP - gets public ip
func GetPublicIP() (string, error) {
endpoint := ""
@ -354,6 +395,8 @@ func GetPublicIP() (string, error) {
}
return endpoint, err
}
// GetVerbose - get the verbosity of server
func GetVerbose() int32 {
level, err := strconv.Atoi(os.Getenv("VERBOSITY"))
if err != nil || level < 0 {
@ -365,6 +408,7 @@ func GetVerbose() int32 {
return int32(level)
}
// GetPlatform - get the system type of server
func GetPlatform() string {
platform := "linux"
if os.Getenv("PLATFORM") != "" {
@ -375,6 +419,7 @@ func GetPlatform() string {
return platform
}
// GetSQLConn - get the sql connection string
func GetSQLConn() string {
sqlconn := "http://"
if os.Getenv("SQL_CONN") != "" {
@ -385,6 +430,7 @@ func GetSQLConn() string {
return sqlconn
}
// IsSplitDNS - checks if split dns is on
func IsSplitDNS() bool {
issplit := false
if os.Getenv("IS_SPLIT_DNS") == "yes" {
@ -395,6 +441,7 @@ func IsSplitDNS() bool {
return issplit
}
// GetNodeID - gets the node id
func GetNodeID() string {
var id string
id = getMacAddr()
@ -406,6 +453,7 @@ func GetNodeID() string {
return id
}
// GetServerCheckinInterval - gets the server check-in time
func GetServerCheckinInterval() int64 {
var t = int64(5)
var envt, _ = strconv.Atoi(os.Getenv("SERVER_CHECKIN_INTERVAL"))

View file

@ -107,9 +107,11 @@ func HandleContainedClient() error {
err = logic.ServerCheckin(servercfg.GetNodeID(), serverNet.NetID)
if err != nil {
logic.Log("error occurred during server checkin: "+err.Error(), 1)
} else {
logic.Log("completed peers check of network "+serverNet.NetID, 3)
}
}
logic.Log("completed a checkin call", 3)
// logic.Log("completed a checkin call", 3)
}
return nil
}
@ -168,7 +170,6 @@ func SyncNetworks(servernets []models.Network) error {
// AddNetwork - add a network to server in client mode
func AddNetwork(network string) (bool, error) {
err := logic.ServerJoin(network, servercfg.GetNodeID(), "")
logic.Log("server added to network "+network, 2)
var err = logic.ServerJoin(network, servercfg.GetNodeID(), "")
return true, err
}