optimize wire_put_uint64; use protokey for flowlabel fallback.

This commit is contained in:
cathugger 2018-07-30 01:58:52 +00:00
parent fec7100898
commit 36dcab9300
No known key found for this signature in database
GPG key ID: 9BADDA2DAF6F01A8
2 changed files with 20 additions and 15 deletions

View file

@ -440,12 +440,21 @@ func (sinfo *sessionInfo) doSend(bs []byte) {
coords = append(coords, sinfo.coords...) // Start with the real coords
coords = append(coords, 0) // Then target the local switchport
coords = wire_put_uint64(uint64(flowlabel), coords) // Then variable-length encoded flowlabel
} else if len(bs) >= 48 /* min UDP len, others are bigger */ &&
(bs[6] == 0x06 || bs[6] == 0x11 || bs[6] == 0x84) /* TCP UDP SCTP */ {
// if flowlabel was unspecified (0), try to use known protocols' ports
// protokey: proto | sport | dport
pkey := uint64(bs[6])<<32 /* proto */ |
uint64(bs[40])<<24 | uint64(bs[41])<<16 /* sport */ |
uint64(bs[42])<<8 | uint64(bs[43]) /* dport */
coords = append(coords, sinfo.coords...) // Start with the real coords
coords = append(coords, 0) // Then target the local switchport
coords = wire_put_uint64(pkey, coords) // Then variable-length encoded protokey
} else {
// 0 value means that flowlabels aren't being generated by OS.
// flowlabel was unspecified (0) and protocol unrecognised.
// To save bytes, we're not including it, therefore we won't need self-port override either.
// So just use sinfo.coords directly to avoid golang GC allocations.
// Recent enough Linux kernel supports flowlabels out of the box so this will be rare.
// XXX Attempt to look into TCP/UDP/SCTP/DCCP headers' sport/dport fields there?
// Recent enough Linux and BSDs support flowlabels (auto_flowlabel) out of the box so this will be rare.
coords = sinfo.coords
}
payload, nonce := boxSeal(&sinfo.sharedSesKey, bs, &sinfo.myNonce)