From ebfd2ea96c511f52aedde09c78285dc254e07bb2 Mon Sep 17 00:00:00 2001 From: Melora Hugues Date: Sat, 16 Sep 2023 13:51:01 +0200 Subject: [PATCH] Use device path to describe boot apps --- bootserver/bootoption/bootoption.go | 5 ++--- bootserver/bootprotocol/bootprotocol.go | 9 +++++++-- bootserver/controllers/ui/ui.go | 4 +--- bootserver/udplistener/udplistener.go | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bootserver/bootoption/bootoption.go b/bootserver/bootoption/bootoption.go index e90546c..227c367 100644 --- a/bootserver/bootoption/bootoption.go +++ b/bootserver/bootoption/bootoption.go @@ -3,9 +3,8 @@ package bootoption import "github.com/google/uuid" type EFIApp struct { - Name string `json:"name"` - Path string `json:"path"` - DiskID string `json:"disk_id"` + Name string `json:"name"` + DevicePath string `json:"device_path"` } type Client struct { diff --git a/bootserver/bootprotocol/bootprotocol.go b/bootserver/bootprotocol/bootprotocol.go index ea028a1..571040a 100644 --- a/bootserver/bootprotocol/bootprotocol.go +++ b/bootserver/bootprotocol/bootprotocol.go @@ -6,6 +6,7 @@ import ( "encoding" "errors" "fmt" + "strings" "github.com/google/uuid" ) @@ -20,7 +21,7 @@ const ( ) var spaceByte = []byte(" ") -var commaByte = []byte(",") +var commaByte = []byte(";") const ( keyID = "id" @@ -140,9 +141,13 @@ func (am *acceptMessage) UnmarshalBinary(data []byte) error { func (am *acceptMessage) MarshalBinary() (data []byte, err error) { action := []byte(am.Action().String()) + // efiApp := strings.ReplaceAll(am.efiApp, `\`, `\\`) + // efiApp = strings.ReplaceAll(efiApp, "File(", "") + efiApp := strings.ReplaceAll(am.efiApp, "File(", "") + efiApp, _ = strings.CutSuffix(efiApp, ")") params := [][]byte{ []byte(fmt.Sprintf("%s=%s", keyID, am.id.String())), - []byte(fmt.Sprintf("%s=%s", keyEfiApp, am.efiApp)), + []byte(fmt.Sprintf("%s=%s", keyEfiApp, efiApp)), } param_bytes := bytes.Join(params, commaByte) return bytes.Join([][]byte{action, param_bytes}, spaceByte), nil diff --git a/bootserver/controllers/ui/ui.go b/bootserver/controllers/ui/ui.go index a9a2507..e4c881f 100644 --- a/bootserver/controllers/ui/ui.go +++ b/bootserver/controllers/ui/ui.go @@ -20,7 +20,6 @@ type templateBootOption struct { ID string Name string Path string - DiskID string Selected bool } @@ -65,9 +64,8 @@ func (uc *UIController) serveUI(w http.ResponseWriter, r *http.Request) (int, in for id, bo := range clt.Options { tplBO = append(tplBO, templateBootOption{ Name: bo.Name, - Path: bo.Path, + Path: bo.DevicePath, ID: id, - DiskID: bo.DiskID, Selected: id == clt.SelectedOption, }) sort.Slice(tplBO, func(i, j int) bool { diff --git a/bootserver/udplistener/udplistener.go b/bootserver/udplistener/udplistener.go index a583b27..fe8f78b 100644 --- a/bootserver/udplistener/udplistener.go +++ b/bootserver/udplistener/udplistener.go @@ -78,7 +78,7 @@ func (l *UDPListener) handleBootRequest(msg bootprotocol.Message, subLogger logr requestLogger.Errorf("Failed to get config for client: %s", err.Error()) return bootprotocol.Deny(msg.ID(), "unknown server error") } - return bootprotocol.Accept(msg.ID(), bootOption.Path) + return bootprotocol.Accept(msg.ID(), bootOption.DevicePath) } func (l *UDPListener) handleClient(msg *udpMessage) error {