From 90392e445a6d288cc51f3467b9484745c3ed2ba4 Mon Sep 17 00:00:00 2001 From: Yutaro Hayakawa Date: Sun, 1 Sep 2024 16:05:14 +0900 Subject: [PATCH] lookup: Support mark option Signed-off-by: Yutaro Hayakawa --- cmd/lookup.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/cmd/lookup.go b/cmd/lookup.go index 937c795..1a367d7 100644 --- a/cmd/lookup.go +++ b/cmd/lookup.go @@ -45,6 +45,7 @@ type lookupIn struct { SrcAddr netip.Addr DstAddr netip.Addr TableID *uint32 + Mark *uint32 } func (in *lookupIn) marshal() []byte { @@ -100,8 +101,14 @@ func (in *lookupIn) marshal() []byte { } else { binary.Write(buf, binary.NativeEndian, uint32(0)) } + // param->mark + if in.Mark != nil { + binary.Write(buf, binary.NativeEndian, in.Mark) + } else { + binary.Write(buf, binary.NativeEndian, uint32(0)) + } // Padding - buf.Write(bytes.Repeat([]byte{0}, 12)) + buf.Write(bytes.Repeat([]byte{0}, 8)) return buf.Bytes() } @@ -552,6 +559,22 @@ var lookupCmdOpts = map[string]lookupOpt{ }, probe: func() bool { return true }, }, + "mark": { + desc: []string{"mark", "", "Mark"}, + handle: func(in *lookupIn, args []string) (int, error) { + if len(args) == 0 { + return 0, fmt.Errorf("mark is unspecified") + } + mark, err := strconv.ParseUint(args[0], 0, 32) + if err != nil { + return 0, fmt.Errorf("cannot parse mark: %w", err) + } + mark32 := uint32(mark) + in.Mark = &mark32 + return 1, nil + }, + probe: func() bool { return false }, + }, } func parseLookupArgs(in *lookupIn, args []string) error {