Only try to parse the MAC address if the file has a known type.

Parsing unconditionally logs errors when serving non-kernel/initrd
files.
This commit is contained in:
David Anderson 2017-02-20 17:43:59 -08:00
parent 3df58430a4
commit a762c94d61

View File

@ -134,15 +134,20 @@ func (s *Server) handleFile(w http.ResponseWriter, r *http.Request) {
}
s.log("HTTP", "Sent file %q to %s", name, r.RemoteAddr)
mac, err := net.ParseMAC(r.URL.Query().Get("mac"))
if err != nil {
s.log("HTTP", "File fetch provided invalid MAC address %q", r.URL.Query().Get("mac"))
return
}
switch r.URL.Query().Get("type") {
case "kernel":
mac, err := net.ParseMAC(r.URL.Query().Get("mac"))
if err != nil {
s.log("HTTP", "File fetch provided invalid MAC address %q", r.URL.Query().Get("mac"))
return
}
s.machineEvent(mac, machineStateKernel, "Sent kernel %q", name)
case "initrd":
mac, err := net.ParseMAC(r.URL.Query().Get("mac"))
if err != nil {
s.log("HTTP", "File fetch provided invalid MAC address %q", r.URL.Query().Get("mac"))
return
}
s.machineEvent(mac, machineStateInitrd, "Sent initrd %q", name)
}
}