aboutsummaryrefslogtreecommitdiffstats
path: root/sysgen
diff options
context:
space:
mode:
authorAndrey Konovalov <andreyknvl@google.com>2017-02-08 15:49:03 +0100
committerAndrey Konovalov <andreyknvl@google.com>2017-02-08 17:11:54 +0100
commit0130c7b34e9e4e831c2794f00a0d017040a967a9 (patch)
treed004778543ebef9d348e491f428d0de17d332b28 /sysgen
parent8792b9237970ec1e93423de538bbe646a8ecff90 (diff)
prog, sys: add icmpv6 packet descriptions and checksums
Also generalize checksums into the two kinds: inet and pseudo. Inet checksums is just the Internet checksum of a packet. Pseudo checksum is the Internet checksum of a packet with a pseudo header.
Diffstat (limited to 'sysgen')
-rw-r--r--sysgen/sysgen.go30
1 files changed, 21 insertions, 9 deletions
diff --git a/sysgen/sysgen.go b/sysgen/sysgen.go
index e88710d56..09efdf66a 100644
--- a/sysgen/sysgen.go
+++ b/sysgen/sysgen.go
@@ -501,22 +501,34 @@ func generateArg(
}
fmt.Fprintf(out, "&LenType{%v, Buf: \"%v\", ByteSize: %v}", intCommon(size, bigEndian, bitfieldLen), a[0], byteSize)
case "csum":
- if want := 2; len(a) != want {
- failf("wrong number of arguments for %v arg %v, want %v, got %v", typ, name, want, len(a))
+ if len(a) != 3 && len(a) != 4 {
+ failf("wrong number of arguments for %v arg %v, want 3-4, got %v", typ, name, len(a))
}
- size, bigEndian, bitfieldLen := decodeIntType(a[1])
+ var size uint64
+ var bigEndian bool
+ var bitfieldLen uint64
+ var protocol uint64
var kind string
- switch a[0] {
+ switch a[1] {
case "inet":
kind = "CsumInet"
- case "tcp":
- kind = "CsumTCP"
- case "udp":
- kind = "CsumUDP"
+ size, bigEndian, bitfieldLen = decodeIntType(a[2])
+ case "pseudo":
+ kind = "CsumPseudo"
+ size, bigEndian, bitfieldLen = decodeIntType(a[3])
+ if v, ok := consts[a[2]]; ok {
+ protocol = v
+ } else {
+ v, err := strconv.ParseUint(a[2], 10, 64)
+ if err != nil {
+ failf("failed to parse protocol %v", a[2])
+ }
+ protocol = v
+ }
default:
failf("unknown checksum kind '%v'", a[0])
}
- fmt.Fprintf(out, "&CsumType{%v, Kind: %v}", intCommon(size, bigEndian, bitfieldLen), kind)
+ fmt.Fprintf(out, "&CsumType{%v, Buf: \"%s\", Kind: %v, Protocol: %v}", intCommon(size, bigEndian, bitfieldLen), a[0], kind, protocol)
case "flags":
canBeArg = true
size := uint64(ptrSize)