mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-30 03:11:37 +00:00
Improve command flow
This commit is contained in:
parent
cdfb930703
commit
d3f67ad017
@ -554,17 +554,12 @@ 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)
|
|
||||||
if bs[0]&0xf0 == 0x60 {
|
|
||||||
flowkey = uint64(bs[1]&0x0f)<<16 | uint64(bs[2])<<8 | uint64(bs[3])
|
|
||||||
}
|
|
||||||
// Check if the flowlabel was specified. If not then try to use known
|
|
||||||
// protocols' ports: protokey: proto | sport | dport
|
|
||||||
if flowkey == 0 {
|
|
||||||
// Is the protocol TCP, UDP, SCTP?
|
|
||||||
switch bs[0] & 0xf0 {
|
switch bs[0] & 0xf0 {
|
||||||
case 0x40: // IPv4 packet
|
case 0x40: // IPv4 packet
|
||||||
|
// Check the packet meets minimum UDP packet length
|
||||||
if len(bs) >= 24 {
|
if len(bs) >= 24 {
|
||||||
if bs[9] == 0x06 || bs[9] == 0x11 || bs[9] == 0x84 {
|
if bs[9] == 0x06 || bs[9] == 0x11 || bs[9] == 0x84 {
|
||||||
ihl := bs[0] & 0x0f * 4 // Header length
|
ihl := bs[0] & 0x0f * 4 // Header length
|
||||||
@ -574,8 +569,12 @@ func (sinfo *sessionInfo) doSend(bs []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 0x60: // IPv6 packet
|
case 0x60: // IPv6 packet
|
||||||
// Does the packet meet the minimum UDP packet size? (others are bigger)
|
// Check if the flowlabel was specified in the packet header
|
||||||
if len(bs) >= 48 {
|
flowkey = uint64(bs[1]&0x0f)<<16 | uint64(bs[2])<<8 | uint64(bs[3])
|
||||||
|
// If the flowlabel isn't present, make protokey from proto | sport | dport
|
||||||
|
// if the packet meets minimum UDP packet length
|
||||||
|
if flowkey == 0 && len(bs) >= 48 {
|
||||||
|
// Is the protocol TCP, UDP or SCTP?
|
||||||
if bs[6] == 0x06 || bs[6] == 0x11 || bs[6] == 0x84 {
|
if bs[6] == 0x06 || bs[6] == 0x11 || bs[6] == 0x84 {
|
||||||
flowkey = uint64(bs[6])<<32 /* proto */ |
|
flowkey = uint64(bs[6])<<32 /* proto */ |
|
||||||
uint64(bs[40])<<24 | uint64(bs[41])<<16 /* sport */ |
|
uint64(bs[40])<<24 | uint64(bs[41])<<16 /* sport */ |
|
||||||
@ -583,7 +582,6 @@ func (sinfo *sessionInfo) doSend(bs []byte) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// If we have a flowkey, either through the IPv6 flowlabel field or through
|
// If we have a flowkey, either through the IPv6 flowlabel field or through
|
||||||
// known TCP/UDP/SCTP proto-sport-dport triplet, then append it to the coords.
|
// known TCP/UDP/SCTP proto-sport-dport triplet, then append it to the coords.
|
||||||
// Appending extra coords after a 0 ensures that we still target the local router
|
// Appending extra coords after a 0 ensures that we still target the local router
|
||||||
|
Loading…
Reference in New Issue
Block a user