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
@@ -119,6 +119,7 @@ var (
|
||||
errNotRelative = errors.New("not a relative path")
|
||||
errFolderPaused = errors.New("folder is paused")
|
||||
errFolderMissing = errors.New("no such folder")
|
||||
errNetworkNotAllowed = errors.New("network not allowed")
|
||||
)
|
||||
|
||||
// NewModel creates and starts a new model. The model starts in read-only mode,
|
||||
@@ -1321,21 +1322,27 @@ func (m *Model) OnHello(remoteID protocol.DeviceID, addr net.Addr, hello protoco
|
||||
return errDeviceIgnored
|
||||
}
|
||||
|
||||
if cfg, ok := m.cfg.Device(remoteID); ok {
|
||||
// The device exists
|
||||
if cfg.Paused {
|
||||
return errDevicePaused
|
||||
}
|
||||
return nil
|
||||
cfg, ok := m.cfg.Device(remoteID)
|
||||
if !ok {
|
||||
events.Default.Log(events.DeviceRejected, map[string]string{
|
||||
"name": hello.DeviceName,
|
||||
"device": remoteID.String(),
|
||||
"address": addr.String(),
|
||||
})
|
||||
return errDeviceUnknown
|
||||
}
|
||||
|
||||
events.Default.Log(events.DeviceRejected, map[string]string{
|
||||
"name": hello.DeviceName,
|
||||
"device": remoteID.String(),
|
||||
"address": addr.String(),
|
||||
})
|
||||
if cfg.Paused {
|
||||
return errDevicePaused
|
||||
}
|
||||
|
||||
return errDeviceUnknown
|
||||
if len(cfg.AllowedNetworks) > 0 {
|
||||
if !connections.IsAllowedNetwork(addr.String(), cfg.AllowedNetworks) {
|
||||
return errNetworkNotAllowed
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetHello is called when we are about to connect to some remote device.
|
||||
|
||||
Reference in New Issue
Block a user