From b1d1a319aeb3e89bf8e84062c061d96b71bcd7ae Mon Sep 17 00:00:00 2001 From: Devon Bautista Date: Tue, 10 Dec 2024 19:09:08 -0700 Subject: [PATCH] feat(coresmd): add log messages to tftp --- coresmd/tftp.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/coresmd/tftp.go b/coresmd/tftp.go index c077ba1..3a3ae03 100644 --- a/coresmd/tftp.go +++ b/coresmd/tftp.go @@ -31,11 +31,24 @@ func startTFTPServer(directory string) { func readHandler(directory string) func(string, io.ReaderFrom) error { return func(filename string, rf io.ReaderFrom) error { + var raddr string + ot, ok := rf.(tftp.OutgoingTransfer) + if !ok { + log.Error("unable to get remote address, setting to (unknown)") + raddr = "(unknown)" + } else { + ra := ot.RemoteAddr() + raptr := &ra + raddr = raptr.IP.String() + } if filename == defaultScriptName { + log.Infof("tftp: %s requested default script") var sr ScriptReader - _, err := rf.ReadFrom(sr) + nbytes, err := rf.ReadFrom(sr) + log.Infof("tftp: sent %d bytes of default script to %s", nbytes, raddr) return err } + log.Infof("tftp: %s requested file %s", raddr, filename) filePath := filepath.Join(directory, filename) file, err := os.Open(filePath) if err != nil { @@ -43,7 +56,8 @@ func readHandler(directory string) func(string, io.ReaderFrom) error { } defer file.Close() - _, err = rf.ReadFrom(file) + nbytes, err := rf.ReadFrom(file) + log.Infof("tftp: sent %d bytes of file %s to %s", nbytes, filename, raddr) return err } }