diff options
author | Jason Kölker <jason@koelker.net> | 2016-03-26 02:26:27 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-27 22:29:46 +0900 |
commit | 00c31a4d73f201d9207f48d76bbda8c6c203592f (patch) | |
tree | 22432aea6ac60e351933ed6fc5641e4114f99a2a | |
parent | 9bc162493235cc59585de1c352e9a22838d2d376 (diff) |
packet/tcp: Add TCP Control Flags
Add the control flags constants and a helper function to test which
flags are on.
Signed-off-by: Jason Kölker <jason@koelker.net>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/lib/packet/tcp.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/ryu/lib/packet/tcp.py b/ryu/lib/packet/tcp.py index 7b5a7c7b..80c49928 100644 --- a/ryu/lib/packet/tcp.py +++ b/ryu/lib/packet/tcp.py @@ -35,6 +35,16 @@ TCP_OPTION_KIND_TIMESTAMPS = 8 # Timestamps TCP_OPTION_KIND_USER_TIMEOUT = 28 # User Timeout Option TCP_OPTION_KIND_AUTHENTICATION = 29 # TCP Authentication Option (TCP-AO) +TCP_FIN = 0x001 +TCP_SYN = 0x002 +TCP_RST = 0x004 +TCP_PSH = 0x008 +TCP_ACK = 0x010 +TCP_URG = 0x020 +TCP_ECE = 0x040 +TCP_CWR = 0x080 +TCP_NS = 0x100 + class tcp(packet_base.PacketBase): """TCP (RFC 793) header encoder/decoder class. @@ -83,6 +93,21 @@ class tcp(packet_base.PacketBase): def __len__(self): return self.offset * 4 + def has_flags(self, *flags): + """Check if flags are set on this packet. + + returns boolean if all passed flags is set + + eg. + + # Check if this is a syn+ack + if pkt.has_flags(tcp.TCP_SYN, tcp.TCP_ACK): + ... + """ + + mask = sum(flags) + return (self.bits & mask) == mask + @classmethod def parser(cls, buf): (src_port, dst_port, seq, ack, offset, bits, window_size, |