forked from iovisor/bcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcp.py
More file actions
61 lines (57 loc) · 1.63 KB
/
Copy pathtcp.py
File metadata and controls
61 lines (57 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright 2018 Netflix, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# from include/net/tcp_states.h:
_tcpstate = {}
_tcpstate[1] = 'ESTABLISHED'
_tcpstate[2] = 'SYN_SENT'
_tcpstate[3] = 'SYN_RECV'
_tcpstate[4] = 'FIN_WAIT1'
_tcpstate[5] = 'FIN_WAIT2'
_tcpstate[6] = 'TIME_WAIT'
_tcpstate[7] = 'CLOSE'
_tcpstate[8] = 'CLOSE_WAIT'
_tcpstate[9] = 'LAST_ACK'
_tcpstate[10] = 'LISTEN'
_tcpstate[11] = 'CLOSING'
_tcpstate[12] = 'NEW_SYN_RECV'
# from include/net/tcp.h:
TCPHDR_FIN = 0x01
TCPHDR_SYN = 0x02
TCPHDR_RST = 0x04
TCPHDR_PSH = 0x08
TCPHDR_ACK = 0x10
TCPHDR_URG = 0x20
TCPHDR_ECE = 0x40
TCPHDR_CWR = 0x80
def flags2str(flags):
arr = []
if flags & TCPHDR_FIN:
arr.append("FIN")
if flags & TCPHDR_SYN:
arr.append("SYN")
if flags & TCPHDR_RST:
arr.append("RST")
if flags & TCPHDR_PSH:
arr.append("PSH")
if flags & TCPHDR_ACK:
arr.append("ACK")
if flags & TCPHDR_URG:
arr.append("URG")
if flags & TCPHDR_ECE:
arr.append("ECE")
if flags & TCPHDR_CWR:
arr.append("CWR")
return "|".join(arr)
def state2str(state):
return _tcpstate.get(state, str(state))