Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
iproute2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
iproute2
Commits
055840f2
Commit
055840f2
authored
Feb 13, 2015
by
Vadim Kochan
Committed by
Stephen Hemminger
Feb 21, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ss: Split tcpstap struct to sockstat & tcpstat
Signed-off-by:
Vadim Kochan
<
vadim4j@gmail.com
>
parent
1527a17e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
68 deletions
+86
-68
misc/ss.c
misc/ss.c
+86
-68
No files found.
misc/ss.c
View file @
055840f2
...
...
@@ -691,16 +691,7 @@ static const char *sstate_namel[] = {
[
SS_CLOSING
]
=
"closing"
,
};
struct
dctcpstat
{
unsigned
int
ce_state
;
unsigned
int
alpha
;
unsigned
int
ab_ecn
;
unsigned
int
ab_tot
;
bool
enabled
;
};
struct
tcpstat
struct
sockstat
{
inet_prefix
local
;
inet_prefix
remote
;
...
...
@@ -713,6 +704,20 @@ struct tcpstat
int
refcnt
;
unsigned
int
iface
;
unsigned
long
long
sk
;
};
struct
dctcpstat
{
unsigned
int
ce_state
;
unsigned
int
alpha
;
unsigned
int
ab_ecn
;
unsigned
int
ab_tot
;
bool
enabled
;
};
struct
tcpstat
{
struct
sockstat
ss
;
int
timer
;
int
timeout
;
int
probes
;
...
...
@@ -1000,7 +1005,7 @@ static int unix_match(const inet_prefix *a, const inet_prefix *p)
return
!
fnmatch
(
pattern
,
addr
,
0
);
}
static
int
run_ssfilter
(
struct
ssfilter
*
f
,
struct
tcp
stat
*
s
)
static
int
run_ssfilter
(
struct
ssfilter
*
f
,
struct
sock
stat
*
s
)
{
switch
(
f
->
type
)
{
case
SSF_S_AUTO
:
...
...
@@ -1487,7 +1492,7 @@ static char *proto_name(int protocol)
return
"???"
;
}
static
void
inet_stats_print
(
struct
tcp
stat
*
s
,
int
protocol
)
static
void
inet_stats_print
(
struct
sock
stat
*
s
,
int
protocol
)
{
char
*
buf
=
NULL
;
...
...
@@ -1501,17 +1506,6 @@ static void inet_stats_print(struct tcpstat *s, int protocol)
formatted_print
(
&
s
->
local
,
s
->
lport
,
s
->
iface
);
formatted_print
(
&
s
->
remote
,
s
->
rport
,
0
);
if
(
show_options
)
{
if
(
s
->
timer
)
{
if
(
s
->
timer
>
4
)
s
->
timer
=
5
;
printf
(
" timer:(%s,%s,%d)"
,
tmr_name
[
s
->
timer
],
print_ms_timer
(
s
->
timeout
),
s
->
retrans
);
}
}
if
(
show_proc_ctx
||
show_sock_ctx
)
{
if
(
find_entry
(
s
->
ino
,
&
buf
,
(
show_proc_ctx
&
show_sock_ctx
)
?
...
...
@@ -1527,7 +1521,8 @@ static void inet_stats_print(struct tcpstat *s, int protocol)
}
}
static
int
proc_parse_inet_addr
(
char
*
loc
,
char
*
rem
,
int
family
,
struct
tcpstat
*
s
)
static
int
proc_parse_inet_addr
(
char
*
loc
,
char
*
rem
,
int
family
,
struct
sockstat
*
s
)
{
s
->
local
.
family
=
s
->
remote
.
family
=
family
;
if
(
family
==
AF_INET
)
{
...
...
@@ -1658,7 +1653,7 @@ static void tcp_stats_print(struct tcpstat *s)
printf
(
" retrans:%u/%u"
,
s
->
retrans
,
s
->
retrans_total
);
if
(
s
->
lost
)
printf
(
" lost:%u"
,
s
->
lost
);
if
(
s
->
sacked
&&
s
->
state
!=
SS_LISTEN
)
if
(
s
->
sacked
&&
s
->
s
s
.
s
tate
!=
SS_LISTEN
)
printf
(
" sacked:%u"
,
s
->
sacked
);
if
(
s
->
fackets
)
printf
(
" fackets:%u"
,
s
->
fackets
);
...
...
@@ -1670,6 +1665,18 @@ static void tcp_stats_print(struct tcpstat *s)
printf
(
" rcv_space:%d"
,
s
->
rcv_space
);
}
static
void
tcp_timer_print
(
struct
tcpstat
*
s
)
{
if
(
s
->
timer
)
{
if
(
s
->
timer
>
4
)
s
->
timer
=
5
;
printf
(
" timer:(%s,%s,%d)"
,
tmr_name
[
s
->
timer
],
print_ms_timer
(
s
->
timeout
),
s
->
retrans
);
}
}
static
int
tcp_show_line
(
char
*
line
,
const
struct
filter
*
f
,
int
family
)
{
int
rto
=
0
,
ato
=
0
;
...
...
@@ -1686,17 +1693,17 @@ static int tcp_show_line(char *line, const struct filter *f, int family)
if
(
!
(
f
->
states
&
(
1
<<
state
)))
return
0
;
proc_parse_inet_addr
(
loc
,
rem
,
family
,
&
s
);
proc_parse_inet_addr
(
loc
,
rem
,
family
,
&
s
.
ss
);
if
(
f
->
f
&&
run_ssfilter
(
f
->
f
,
&
s
)
==
0
)
if
(
f
->
f
&&
run_ssfilter
(
f
->
f
,
&
s
.
ss
)
==
0
)
return
0
;
opt
[
0
]
=
0
;
n
=
sscanf
(
data
,
"%x %x:%x %x:%x %x %d %d %u %d %llx %d %d %d %d %d %[^
\n
]
\n
"
,
&
s
.
s
tate
,
&
s
.
wq
,
&
s
.
rq
,
&
s
.
timer
,
&
s
.
timeout
,
&
s
.
retrans
,
&
s
.
uid
,
&
s
.
probes
,
&
s
.
ino
,
&
s
.
refcnt
,
&
s
.
sk
,
&
rto
,
&
ato
,
&
s
.
qack
,
&
s
.
cwnd
,
&
s
.
ssthresh
,
opt
);
&
s
.
s
s
.
state
,
&
s
.
ss
.
wq
,
&
s
.
s
s
.
rq
,
&
s
.
timer
,
&
s
.
timeout
,
&
s
.
retrans
,
&
s
.
ss
.
uid
,
&
s
.
probes
,
&
s
.
ss
.
ino
,
&
s
.
ss
.
refcnt
,
&
s
.
ss
.
sk
,
&
rto
,
&
ato
,
&
s
.
qack
,
&
s
.
cwnd
,
&
s
.
ssthresh
,
opt
);
if
(
n
<
17
)
opt
[
0
]
=
0
;
...
...
@@ -1716,13 +1723,16 @@ static int tcp_show_line(char *line, const struct filter *f, int family)
s
.
ssthresh
=
s
.
ssthresh
==
-
1
?
0
:
s
.
ssthresh
;
s
.
rto
=
s
.
rto
!=
3
*
hz
?
s
.
rto
/
hz
:
0
;
inet_stats_print
(
&
s
,
IPPROTO_TCP
);
inet_stats_print
(
&
s
.
ss
,
IPPROTO_TCP
);
if
(
show_options
)
tcp_timer_print
(
&
s
);
if
(
show_details
)
{
if
(
s
.
uid
)
printf
(
" uid:%u"
,
(
unsigned
)
s
.
uid
);
printf
(
" ino:%u"
,
s
.
ino
);
printf
(
" sk:%llx"
,
s
.
sk
);
if
(
s
.
ss
.
uid
)
printf
(
" uid:%u"
,
(
unsigned
)
s
.
ss
.
uid
);
printf
(
" ino:%u"
,
s
.
ss
.
ino
);
printf
(
" sk:%llx"
,
s
.
s
s
.
s
k
);
if
(
opt
[
0
])
printf
(
" opt:
\"
%s
\"
"
,
opt
);
}
...
...
@@ -1807,6 +1817,8 @@ static void tcp_show_info(const struct nlmsghdr *nlh, struct inet_diag_msg *r,
double
rtt
=
0
;
struct
tcpstat
s
=
{};
s
.
ss
.
state
=
r
->
idiag_state
;
print_skmeminfo
(
tb
,
INET_DIAG_SKMEMINFO
);
if
(
tb
[
INET_DIAG_INFO
])
{
...
...
@@ -1916,7 +1928,7 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol)
{
struct
rtattr
*
tb
[
INET_DIAG_MAX
+
1
];
struct
inet_diag_msg
*
r
=
NLMSG_DATA
(
nlh
);
struct
tcp
stat
s
=
{};
struct
sock
stat
s
=
{};
parse_rtattr
(
tb
,
INET_DIAG_MAX
,
(
struct
rtattr
*
)(
r
+
1
),
nlh
->
nlmsg_len
-
NLMSG_LENGTH
(
sizeof
(
*
r
)));
...
...
@@ -1927,9 +1939,6 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol)
s
.
rport
=
ntohs
(
r
->
id
.
idiag_dport
);
s
.
wq
=
r
->
idiag_wqueue
;
s
.
rq
=
r
->
idiag_rqueue
;
s
.
timer
=
r
->
idiag_timer
;
s
.
timeout
=
r
->
idiag_expires
;
s
.
retrans
=
r
->
idiag_retrans
;
s
.
ino
=
r
->
idiag_inode
;
s
.
uid
=
r
->
idiag_uid
;
s
.
iface
=
r
->
id
.
idiag_if
;
...
...
@@ -1948,6 +1957,15 @@ static int inet_show_sock(struct nlmsghdr *nlh, struct filter *f, int protocol)
inet_stats_print
(
&
s
,
protocol
);
if
(
show_options
)
{
struct
tcpstat
t
=
{};
t
.
timer
=
r
->
idiag_timer
;
t
.
timeout
=
r
->
idiag_expires
;
t
.
retrans
=
r
->
idiag_retrans
;
tcp_timer_print
(
&
t
);
}
if
(
show_details
)
{
if
(
r
->
idiag_uid
)
printf
(
" uid:%u"
,
(
unsigned
)
r
->
idiag_uid
);
...
...
@@ -2292,7 +2310,7 @@ outerr:
static
int
dgram_show_line
(
char
*
line
,
const
struct
filter
*
f
,
int
family
)
{
struct
tcp
stat
s
=
{};
struct
sock
stat
s
=
{};
char
*
loc
,
*
rem
,
*
data
;
char
opt
[
256
];
int
n
;
...
...
@@ -2495,15 +2513,15 @@ static void unix_stats_print(struct unixstat *list, struct filter *f)
}
if
(
f
->
f
)
{
struct
tcpstat
t
st
;
t
st
.
local
.
family
=
AF_UNIX
;
t
st
.
remote
.
family
=
AF_UNIX
;
memcpy
(
t
st
.
local
.
data
,
&
s
->
name
,
sizeof
(
s
->
name
));
struct
sockstat
st
;
st
.
local
.
family
=
AF_UNIX
;
st
.
remote
.
family
=
AF_UNIX
;
memcpy
(
st
.
local
.
data
,
&
s
->
name
,
sizeof
(
s
->
name
));
if
(
strcmp
(
peer
,
"*"
)
==
0
)
memset
(
t
st
.
remote
.
data
,
0
,
sizeof
(
peer
));
memset
(
st
.
remote
.
data
,
0
,
sizeof
(
peer
));
else
memcpy
(
t
st
.
remote
.
data
,
&
peer
,
sizeof
(
peer
));
if
(
run_ssfilter
(
f
->
f
,
&
t
st
)
==
0
)
memcpy
(
st
.
remote
.
data
,
&
peer
,
sizeof
(
peer
));
if
(
run_ssfilter
(
f
->
f
,
&
st
)
==
0
)
continue
;
}
...
...
@@ -2728,14 +2746,14 @@ static int packet_stats_print(struct pktstat *s, const struct filter *f)
char
*
buf
=
NULL
;
if
(
f
->
f
)
{
struct
tcpstat
t
st
;
t
st
.
local
.
family
=
AF_PACKET
;
t
st
.
remote
.
family
=
AF_PACKET
;
t
st
.
rport
=
0
;
t
st
.
lport
=
s
->
iface
;
t
st
.
local
.
data
[
0
]
=
s
->
prot
;
t
st
.
remote
.
data
[
0
]
=
0
;
if
(
run_ssfilter
(
f
->
f
,
&
t
st
)
==
0
)
struct
sockstat
st
;
st
.
local
.
family
=
AF_PACKET
;
st
.
remote
.
family
=
AF_PACKET
;
st
.
rport
=
0
;
st
.
lport
=
s
->
iface
;
st
.
local
.
data
[
0
]
=
s
->
prot
;
st
.
remote
.
data
[
0
]
=
0
;
if
(
run_ssfilter
(
f
->
f
,
&
st
)
==
0
)
return
1
;
}
...
...
@@ -2911,14 +2929,14 @@ static void netlink_show_one(struct filter *f,
SPRINT_BUF
(
prot_name
);
if
(
f
->
f
)
{
struct
tcpstat
t
st
;
t
st
.
local
.
family
=
AF_NETLINK
;
t
st
.
remote
.
family
=
AF_NETLINK
;
t
st
.
rport
=
-
1
;
t
st
.
lport
=
pid
;
t
st
.
local
.
data
[
0
]
=
prot
;
t
st
.
remote
.
data
[
0
]
=
0
;
if
(
run_ssfilter
(
f
->
f
,
&
t
st
)
==
0
)
struct
sockstat
st
;
st
.
local
.
family
=
AF_NETLINK
;
st
.
remote
.
family
=
AF_NETLINK
;
st
.
rport
=
-
1
;
st
.
lport
=
pid
;
st
.
local
.
data
[
0
]
=
prot
;
st
.
remote
.
data
[
0
]
=
0
;
if
(
run_ssfilter
(
f
->
f
,
&
st
)
==
0
)
return
;
}
...
...
@@ -3129,7 +3147,7 @@ static int get_snmp_int(char *proto, char *key, int *result)
/* Get stats from sockstat */
struct
s
ockstat
struct
s
summary
{
int
socks
;
int
tcp_mem
;
...
...
@@ -3148,7 +3166,7 @@ struct sockstat
int
frag6_mem
;
};
static
void
get_sockstat_line
(
char
*
line
,
struct
s
ockstat
*
s
)
static
void
get_sockstat_line
(
char
*
line
,
struct
s
summary
*
s
)
{
char
id
[
256
],
rem
[
256
];
...
...
@@ -3177,7 +3195,7 @@ static void get_sockstat_line(char *line, struct sockstat *s)
&
s
->
tcp_orphans
,
&
s
->
tcp_tws
,
&
s
->
tcp_total
,
&
s
->
tcp_mem
);
}
static
int
get_sockstat
(
struct
s
ockstat
*
s
)
static
int
get_sockstat
(
struct
s
summary
*
s
)
{
char
buf
[
256
];
FILE
*
fp
;
...
...
@@ -3201,7 +3219,7 @@ static int get_sockstat(struct sockstat *s)
static
int
print_summary
(
void
)
{
struct
s
ockstat
s
;
struct
s
summary
s
;
struct
snmpstat
sn
;
if
(
get_sockstat
(
&
s
)
<
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment