aboutsummaryrefslogtreecommitdiffstats
path: root/prog/mutation.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-04-01 15:28:01 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-04-01 15:28:01 +0200
commit185ac3525e708353d3cae302277225aec1fde165 (patch)
tree8c7d8e2ccf3e58d864922bc7893fc9b8e8ccdead /prog/mutation.go
parent0a78e248b7b6537ccdf66dc8806d76e0a97efe21 (diff)
prog: support big-endian during hints matching
Use big-endian match/replace for both blobs and ints. Sometimes we have unmarked blobs (no little/big-endian info); for ANYBLOBs we intentionally lose all marking; but even for marked ints we may need this too. Consider that kernel code does not convert the data (i.e. not ntohs(pkt->proto) == ETH_P_BATMAN), but instead converts the constant (i.e. pkt->proto == htons(ETH_P_BATMAN)). In such case we will see dynamic operand that does not match what we have in the program.
Diffstat (limited to 'prog/mutation.go')
-rw-r--r--prog/mutation.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/prog/mutation.go b/prog/mutation.go
index 2e1039551..9ab47d8d6 100644
--- a/prog/mutation.go
+++ b/prog/mutation.go
@@ -604,3 +604,18 @@ func swap64(v uint64) uint64 {
v |= uint64(v0) << 56
return v
}
+
+func swap(v, size uint64) uint64 {
+ switch size {
+ case 64:
+ return swap64(v)
+ case 32:
+ return uint64(swap32(uint32(v)))
+ case 16:
+ return uint64(swap16(uint16(v)))
+ case 8:
+ return v
+ default:
+ panic(fmt.Sprintf("swap: bad size %v", size))
+ }
+}