Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net 509 515 #2496

Merged
merged 4 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion controllers/ext_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ func getExtClientConf(w http.ResponseWriter, r *http.Request) {
if network.DefaultKeepalive != 0 {
keepalive = "PersistentKeepalive = " + strconv.Itoa(int(network.DefaultKeepalive))
}
gwendpoint := host.EndpointIP.String() + ":" + strconv.Itoa(host.ListenPort)
gwendpoint := ""
if host.EndpointIP.To4() == nil {
gwendpoint = fmt.Sprintf("[%s]:%d", host.EndpointIP.String(), host.ListenPort)
} else {
gwendpoint = fmt.Sprintf("%s:%d", host.EndpointIP.String(), host.ListenPort)
}
newAllowedIPs := network.AddressRange
if newAllowedIPs != "" && network.AddressRange6 != "" {
newAllowedIPs += ","
Expand Down
8 changes: 8 additions & 0 deletions controllers/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ func createNetwork(w http.ResponseWriter, r *http.Request) {
return
}

if len(network.NetID) > 32 {
err := errors.New("network name shouldn't exceed 32 characters")
logger.Log(0, r.Header.Get("user"), "failed to create network: ",
err.Error())
logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest"))
return
}

if network.AddressRange == "" && network.AddressRange6 == "" {
err := errors.New("IPv4 or IPv6 CIDR required")
logger.Log(0, r.Header.Get("user"), "failed to create network: ",
Expand Down
4 changes: 2 additions & 2 deletions controllers/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestDeleteNetwork(t *testing.T) {
err := logic.DeleteNetwork("skynet")
assert.Nil(t, err)
})
t.Run("NonExistantNetwork", func(t *testing.T) {
t.Run("NonExistentNetwork", func(t *testing.T) {
err := logic.DeleteNetwork("skynet")
assert.Nil(t, err)
})
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestValidateNetwork(t *testing.T) {
{
testname: "NetIDTooLong",
network: models.Network{
NetID: "LongNetIDName",
NetID: "LongNetIDNameForMaxCharactersTest",
},
errMessage: "Field validation for 'NetID' failed on the 'max' tag",
},
Expand Down
8 changes: 4 additions & 4 deletions models/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
type Network struct {
AddressRange string `json:"addressrange" bson:"addressrange" validate:"omitempty,cidrv4"`
AddressRange6 string `json:"addressrange6" bson:"addressrange6" validate:"omitempty,cidrv6"`
NetID string `json:"netid" bson:"netid" validate:"required,min=1,max=12,netid_valid"`
NetID string `json:"netid" bson:"netid" validate:"required,min=1,max=32,netid_valid"`
NodesLastModified int64 `json:"nodeslastmodified" bson:"nodeslastmodified"`
NetworkLastModified int64 `json:"networklastmodified" bson:"networklastmodified"`
DefaultInterface string `json:"defaultinterface" bson:"defaultinterface" validate:"min=1,max=15"`
DefaultInterface string `json:"defaultinterface" bson:"defaultinterface" validate:"min=1,max=35"`
DefaultListenPort int32 `json:"defaultlistenport,omitempty" bson:"defaultlistenport,omitempty" validate:"omitempty,min=1024,max=65535"`
NodeLimit int32 `json:"nodelimit" bson:"nodelimit"`
DefaultPostDown string `json:"defaultpostdown" bson:"defaultpostdown"`
Expand All @@ -30,7 +30,7 @@ type Network struct {

// SaveData - sensitive fields of a network that should be kept the same
type SaveData struct { // put sensitive fields here
NetID string `json:"netid" bson:"netid" validate:"required,min=1,max=12,netid_valid"`
NetID string `json:"netid" bson:"netid" validate:"required,min=1,max=32,netid_valid"`
}

// Network.SetNodesLastModified - sets nodes last modified on network, depricated
Expand All @@ -49,7 +49,7 @@ func (network *Network) SetDefaults() {
network.DefaultUDPHolePunch = "no"
}
if network.DefaultInterface == "" {
if len(network.NetID) < 13 {
if len(network.NetID) < 33 {
network.DefaultInterface = "nm-" + network.NetID
} else {
network.DefaultInterface = network.NetID
Expand Down