From 07e3705f09fb881f93c476ff26a2ef34d7277549 Mon Sep 17 00:00:00 2001 From: AlexSSD7 Date: Thu, 31 Aug 2023 20:17:55 +0100 Subject: [PATCH] More resolved TODOs --- cmd/run.go | 9 +-------- share/cfg.go | 10 ++++------ share/defaults.go | 16 ++++++++++++++++ storage/nettap.go | 6 +++++- 4 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 share/defaults.go diff --git a/cmd/run.go b/cmd/run.go index d406dc8..617e5b2 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -103,13 +103,6 @@ func init() { runCmd.Flags().StringVar(&shareBackendFlag, "share-backend", defaultShareType, "Specifies the file share backend to use. The default value is OS-specific.") runCmd.Flags().StringVar(&shareListenIPFlag, "share-listen", share.GetDefaultListenIPStr(), "Specifies the IP to bind the network share port to. NOTE: For FTP, changing the bind address is not enough to connect remotely. You should also specify --ftp-extip.") - smbExternDefault := false - if runtime.GOOS == "windows" { - smbExternDefault = true - } - runCmd.Flags().StringVar(&ftpExtIPFlag, "ftp-extip", share.GetDefaultListenIPStr(), "Specifies the external IP the FTP server should advertise.") - runCmd.Flags().BoolVar(&smbUseExternAddrFlag, "smb-extern", smbExternDefault, "Specifies whether Linsk emulate external networking for the VM's SMB server. This is the default for Windows as there is no way to specify ports in Windows SMB client.") - - // TODO: log the use of smbUseExternAddrFlag when SMB is not enabled. + runCmd.Flags().BoolVar(&smbUseExternAddrFlag, "smb-extern", share.IsSMBExtModeDefault(), "Specifies whether Linsk emulate external networking for the VM's SMB server. This is the default for Windows as there is no way to specify ports in Windows SMB client.") } diff --git a/share/cfg.go b/share/cfg.go index a78b36b..bcc0e90 100644 --- a/share/cfg.go +++ b/share/cfg.go @@ -7,12 +7,6 @@ import ( "log/slog" ) -var defaultListenIP = net.ParseIP("127.0.0.1") - -func GetDefaultListenIPStr() string { - return defaultListenIP.String() -} - type UserConfiguration struct { listenIP net.IP ftpExtIP net.IP @@ -49,6 +43,10 @@ func (rc RawUserConfiguration) Process(backend string, warnLogger *slog.Logger) } } + if rc.SMBExtMode && backend != "smb" && !IsSMBExtModeDefault() { + slog.Warn("SMB external mode specification is ineffective with non-SMB backends") + } + return &UserConfiguration{ listenIP: listenIP, ftpExtIP: ftpExtIP, diff --git a/share/defaults.go b/share/defaults.go new file mode 100644 index 0000000..cdecd28 --- /dev/null +++ b/share/defaults.go @@ -0,0 +1,16 @@ +package share + +import ( + "net" + "runtime" +) + +func IsSMBExtModeDefault() bool { + return runtime.GOOS == "windows1" +} + +var defaultListenIP = net.ParseIP("127.0.0.1") + +func GetDefaultListenIPStr() string { + return defaultListenIP.String() +} diff --git a/storage/nettap.go b/storage/nettap.go index 663ce51..9adae79 100644 --- a/storage/nettap.go +++ b/storage/nettap.go @@ -42,9 +42,13 @@ func (s *Storage) ReleaseNetTapAllocation(tapName string) error { return errors.Wrap(err, "get alloc file path") } - // TODO: Check what happens the file doesn't exist. It should not return an error. err = os.Remove(allocFilePath) if err != nil { + if errors.Is(err, os.ErrNotExist) { + s.logger.Warn("Attempted to remove non-existent tap allocation", "tap-name", tapName) + return nil + } + return errors.Wrap(err, "remove alloc file") }