net/packet: add TCPFlag type and some more constants
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>pull/1112/head
parent
ad3fb6125d
commit
5eeaea9ef9
|
@ -17,10 +17,15 @@ import (
|
||||||
// RFC1858: prevent overlapping fragment attacks.
|
// RFC1858: prevent overlapping fragment attacks.
|
||||||
const minFrag = 60 + 20 // max IPv4 header + basic TCP header
|
const minFrag = 60 + 20 // max IPv4 header + basic TCP header
|
||||||
|
|
||||||
|
type TCPFlag uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TCPSyn = 0x02
|
TCPFin TCPFlag = 0x01
|
||||||
TCPAck = 0x10
|
TCPSyn TCPFlag = 0x02
|
||||||
TCPSynAck = TCPSyn | TCPAck
|
TCPRst TCPFlag = 0x04
|
||||||
|
TCPPsh TCPFlag = 0x08
|
||||||
|
TCPAck TCPFlag = 0x10
|
||||||
|
TCPSynAck TCPFlag = TCPSyn | TCPAck
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parsed is a minimal decoding of a packet suitable for use in filters.
|
// Parsed is a minimal decoding of a packet suitable for use in filters.
|
||||||
|
@ -46,7 +51,7 @@ type Parsed struct {
|
||||||
// DstIP4 is the destination address. Family matches IPVersion.
|
// DstIP4 is the destination address. Family matches IPVersion.
|
||||||
Dst netaddr.IPPort
|
Dst netaddr.IPPort
|
||||||
// TCPFlags is the packet's TCP flag bigs. Valid iff IPProto == TCP.
|
// TCPFlags is the packet's TCP flag bigs. Valid iff IPProto == TCP.
|
||||||
TCPFlags uint8
|
TCPFlags TCPFlag
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parsed) String() string {
|
func (p *Parsed) String() string {
|
||||||
|
@ -186,7 +191,7 @@ func (q *Parsed) decode4(b []byte) {
|
||||||
}
|
}
|
||||||
q.Src.Port = binary.BigEndian.Uint16(sub[0:2])
|
q.Src.Port = binary.BigEndian.Uint16(sub[0:2])
|
||||||
q.Dst.Port = binary.BigEndian.Uint16(sub[2:4])
|
q.Dst.Port = binary.BigEndian.Uint16(sub[2:4])
|
||||||
q.TCPFlags = sub[13] & 0x3F
|
q.TCPFlags = TCPFlag(sub[13]) & 0x3F
|
||||||
headerLength := (sub[12] & 0xF0) >> 2
|
headerLength := (sub[12] & 0xF0) >> 2
|
||||||
q.dataofs = q.subofs + int(headerLength)
|
q.dataofs = q.subofs + int(headerLength)
|
||||||
return
|
return
|
||||||
|
@ -274,7 +279,7 @@ func (q *Parsed) decode6(b []byte) {
|
||||||
}
|
}
|
||||||
q.Src.Port = binary.BigEndian.Uint16(sub[0:2])
|
q.Src.Port = binary.BigEndian.Uint16(sub[0:2])
|
||||||
q.Dst.Port = binary.BigEndian.Uint16(sub[2:4])
|
q.Dst.Port = binary.BigEndian.Uint16(sub[2:4])
|
||||||
q.TCPFlags = sub[13] & 0x3F
|
q.TCPFlags = TCPFlag(sub[13]) & 0x3F
|
||||||
headerLength := (sub[12] & 0xF0) >> 2
|
headerLength := (sub[12] & 0xF0) >> 2
|
||||||
q.dataofs = q.subofs + int(headerLength)
|
q.dataofs = q.subofs + int(headerLength)
|
||||||
return
|
return
|
||||||
|
|
|
@ -414,7 +414,7 @@ func raw6(proto packet.IPProto, src, dst string, sport, dport uint16, trimLen in
|
||||||
|
|
||||||
payload := make([]byte, 12)
|
payload := make([]byte, 12)
|
||||||
// Set the right bit to look like a TCP SYN, if the packet ends up interpreted as TCP
|
// Set the right bit to look like a TCP SYN, if the packet ends up interpreted as TCP
|
||||||
payload[5] = packet.TCPSyn
|
payload[5] = byte(packet.TCPSyn)
|
||||||
|
|
||||||
b := packet.Generate(&u, payload) // payload large enough to possibly be TCP
|
b := packet.Generate(&u, payload) // payload large enough to possibly be TCP
|
||||||
|
|
||||||
|
@ -443,7 +443,7 @@ func raw4(proto packet.IPProto, src, dst string, sport, dport uint16, trimLength
|
||||||
|
|
||||||
payload := make([]byte, 12)
|
payload := make([]byte, 12)
|
||||||
// Set the right bit to look like a TCP SYN, if the packet ends up interpreted as TCP
|
// Set the right bit to look like a TCP SYN, if the packet ends up interpreted as TCP
|
||||||
payload[5] = packet.TCPSyn
|
payload[5] = byte(packet.TCPSyn)
|
||||||
|
|
||||||
b := packet.Generate(&u, payload) // payload large enough to possibly be TCP
|
b := packet.Generate(&u, payload) // payload large enough to possibly be TCP
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue