Skip to content

Commit

Permalink
lookup: Support mark option
Browse files Browse the repository at this point in the history
Signed-off-by: Yutaro Hayakawa <[email protected]>
  • Loading branch information
YutaroHayakawa committed Sep 1, 2024
1 parent b8a4003 commit 90392e4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion cmd/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type lookupIn struct {
SrcAddr netip.Addr
DstAddr netip.Addr
TableID *uint32
Mark *uint32
}

func (in *lookupIn) marshal() []byte {
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -552,6 +559,22 @@ var lookupCmdOpts = map[string]lookupOpt{
},
probe: func() bool { return true },
},
"mark": {
desc: []string{"mark", "<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 {
Expand Down

0 comments on commit 90392e4

Please sign in to comment.