5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 16:31:41 +00:00

Improve command flow

This commit is contained in:
Neil Alexander 2019-01-21 16:22:49 +00:00
parent cdfb930703
commit d3f67ad017
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -554,33 +554,31 @@ func (sinfo *sessionInfo) doSend(bs []byte) {
} }
// code isn't multithreaded so appending to this is safe // code isn't multithreaded so appending to this is safe
coords := sinfo.coords coords := sinfo.coords
// Work out the flowkey - this is used to determine which switch queue
// traffic will be pushed to in the event of congestion
var flowkey uint64 var flowkey uint64
// Try to read IPv6 flowlabel field (20 bits) switch bs[0] & 0xf0 {
if bs[0]&0xf0 == 0x60 { case 0x40: // IPv4 packet
flowkey = uint64(bs[1]&0x0f)<<16 | uint64(bs[2])<<8 | uint64(bs[3]) // Check the packet meets minimum UDP packet length
} if len(bs) >= 24 {
// Check if the flowlabel was specified. If not then try to use known if bs[9] == 0x06 || bs[9] == 0x11 || bs[9] == 0x84 {
// protocols' ports: protokey: proto | sport | dport ihl := bs[0] & 0x0f * 4 // Header length
if flowkey == 0 { flowkey = uint64(bs[9])<<32 /* proto */ |
// Is the protocol TCP, UDP, SCTP? uint64(bs[ihl+0])<<24 | uint64(bs[ihl+1])<<16 /* sport */ |
switch bs[0] & 0xf0 { uint64(bs[ihl+2])<<8 | uint64(bs[ihl+3]) /* dport */
case 0x40: // IPv4 packet
if len(bs) >= 24 {
if bs[9] == 0x06 || bs[9] == 0x11 || bs[9] == 0x84 {
ihl := bs[0] & 0x0f * 4 // Header length
flowkey = uint64(bs[9])<<32 /* proto */ |
uint64(bs[ihl+0])<<24 | uint64(bs[ihl+1])<<16 /* sport */ |
uint64(bs[ihl+2])<<8 | uint64(bs[ihl+3]) /* dport */
}
} }
case 0x60: // IPv6 packet }
// Does the packet meet the minimum UDP packet size? (others are bigger) case 0x60: // IPv6 packet
if len(bs) >= 48 { // Check if the flowlabel was specified in the packet header
if bs[6] == 0x06 || bs[6] == 0x11 || bs[6] == 0x84 { flowkey = uint64(bs[1]&0x0f)<<16 | uint64(bs[2])<<8 | uint64(bs[3])
flowkey = uint64(bs[6])<<32 /* proto */ | // If the flowlabel isn't present, make protokey from proto | sport | dport
uint64(bs[40])<<24 | uint64(bs[41])<<16 /* sport */ | // if the packet meets minimum UDP packet length
uint64(bs[42])<<8 | uint64(bs[43]) /* dport */ if flowkey == 0 && len(bs) >= 48 {
} // Is the protocol TCP, UDP or SCTP?
if bs[6] == 0x06 || bs[6] == 0x11 || bs[6] == 0x84 {
flowkey = uint64(bs[6])<<32 /* proto */ |
uint64(bs[40])<<24 | uint64(bs[41])<<16 /* sport */ |
uint64(bs[42])<<8 | uint64(bs[43]) /* dport */
} }
} }
} }