lib/connections, lib/model, gui: Specify allowed networks per device (fixes #219)
This adds a new config AllowedNetworks per device, which when set should contain a list of network prefixes (192.168.0.0/126 etc) that are allowed for the given device. The connection service will not attempt connections to addresses outside of the given networks and incoming connections will be rejected as well. I've added the config to the normal device editor and shown it (when set) in the device summary on the main screen. There's a unit test for the IsAllowedNetwork method, I've done some manual sanity testing on top of that. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4073
This commit is contained in:
committed by
Audrius Butkevicius
parent
4253f22680
commit
c5e0c47989
@@ -18,22 +18,36 @@ type DeviceConfiguration struct {
|
||||
SkipIntroductionRemovals bool `xml:"skipIntroductionRemovals,attr" json:"skipIntroductionRemovals"`
|
||||
IntroducedBy protocol.DeviceID `xml:"introducedBy,attr" json:"introducedBy"`
|
||||
Paused bool `xml:"paused" json:"paused"`
|
||||
AllowedNetworks []string `xml:"allowedNetwork,omitempty" json:"allowedNetworks"`
|
||||
}
|
||||
|
||||
func NewDeviceConfiguration(id protocol.DeviceID, name string) DeviceConfiguration {
|
||||
return DeviceConfiguration{
|
||||
d := DeviceConfiguration{
|
||||
DeviceID: id,
|
||||
Name: name,
|
||||
}
|
||||
d.prepare()
|
||||
return d
|
||||
}
|
||||
|
||||
func (orig DeviceConfiguration) Copy() DeviceConfiguration {
|
||||
c := orig
|
||||
c.Addresses = make([]string, len(orig.Addresses))
|
||||
copy(c.Addresses, orig.Addresses)
|
||||
func (cfg DeviceConfiguration) Copy() DeviceConfiguration {
|
||||
c := cfg
|
||||
c.Addresses = make([]string, len(cfg.Addresses))
|
||||
copy(c.Addresses, cfg.Addresses)
|
||||
c.AllowedNetworks = make([]string, len(cfg.AllowedNetworks))
|
||||
copy(c.AllowedNetworks, cfg.AllowedNetworks)
|
||||
return c
|
||||
}
|
||||
|
||||
func (cfg *DeviceConfiguration) prepare() {
|
||||
if len(cfg.Addresses) == 0 || len(cfg.Addresses) == 1 && cfg.Addresses[0] == "" {
|
||||
cfg.Addresses = []string{"dynamic"}
|
||||
}
|
||||
if len(cfg.AllowedNetworks) == 0 {
|
||||
cfg.AllowedNetworks = []string{}
|
||||
}
|
||||
}
|
||||
|
||||
type DeviceConfigurationList []DeviceConfiguration
|
||||
|
||||
func (l DeviceConfigurationList) Less(a, b int) bool {
|
||||
|
||||
Reference in New Issue
Block a user