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
5fb421d4
Commit
5fb421d4
authored
Oct 30, 2014
by
vadimk
Committed by
Stephen Hemminger
Nov 29, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ss: Refactor to use macro for define diag nl request
Signed-off-by:
Vadim Kochan
<
vadim4j@gmail.com
>
parent
1b944148
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
39 deletions
+17
-39
misc/ss.c
misc/ss.c
+17
-39
No files found.
misc/ss.c
View file @
5fb421d4
...
...
@@ -41,6 +41,19 @@
#include <linux/packet_diag.h>
#include <linux/netlink_diag.h>
#define DIAG_REQUEST(_req, _r) \
struct { \
struct nlmsghdr nlh; \
_r; \
} _req = { \
.nlh = { \
.nlmsg_type = SOCK_DIAG_BY_FAMILY, \
.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST,\
.nlmsg_seq = 123456, \
.nlmsg_len = sizeof(_req), \
}, \
}
#if HAVE_SELINUX
#include <selinux/selinux.h>
#else
...
...
@@ -1810,10 +1823,7 @@ static int tcpdiag_send(int fd, int protocol, struct filter *f)
static
int
sockdiag_send
(
int
family
,
int
fd
,
int
protocol
,
struct
filter
*
f
)
{
struct
sockaddr_nl
nladdr
;
struct
{
struct
nlmsghdr
nlh
;
struct
inet_diag_req_v2
r
;
}
req
;
DIAG_REQUEST
(
req
,
struct
inet_diag_req_v2
r
);
char
*
bc
=
NULL
;
int
bclen
;
struct
msghdr
msg
;
...
...
@@ -1826,11 +1836,6 @@ static int sockdiag_send(int family, int fd, int protocol, struct filter *f)
memset
(
&
nladdr
,
0
,
sizeof
(
nladdr
));
nladdr
.
nl_family
=
AF_NETLINK
;
req
.
nlh
.
nlmsg_len
=
sizeof
(
req
);
req
.
nlh
.
nlmsg_type
=
SOCK_DIAG_BY_FAMILY
;
req
.
nlh
.
nlmsg_flags
=
NLM_F_ROOT
|
NLM_F_MATCH
|
NLM_F_REQUEST
;
req
.
nlh
.
nlmsg_pid
=
0
;
req
.
nlh
.
nlmsg_seq
=
123456
;
memset
(
&
req
.
r
,
0
,
sizeof
(
req
.
r
));
req
.
r
.
sdiag_family
=
family
;
req
.
r
.
sdiag_protocol
=
protocol
;
...
...
@@ -2592,16 +2597,7 @@ close_it:
static
int
unix_show_netlink
(
struct
filter
*
f
,
FILE
*
dump_fp
)
{
struct
{
struct
nlmsghdr
nlh
;
struct
unix_diag_req
r
;
}
req
;
memset
(
&
req
,
0
,
sizeof
(
req
));
req
.
nlh
.
nlmsg_len
=
sizeof
(
req
);
req
.
nlh
.
nlmsg_type
=
SOCK_DIAG_BY_FAMILY
;
req
.
nlh
.
nlmsg_flags
=
NLM_F_ROOT
|
NLM_F_MATCH
|
NLM_F_REQUEST
;
req
.
nlh
.
nlmsg_seq
=
123456
;
DIAG_REQUEST
(
req
,
struct
unix_diag_req
r
);
req
.
r
.
sdiag_family
=
AF_UNIX
;
req
.
r
.
udiag_states
=
f
->
states
;
...
...
@@ -2793,21 +2789,12 @@ static int packet_show_sock(struct nlmsghdr *nlh, struct filter *f)
static
int
packet_show_netlink
(
struct
filter
*
f
,
FILE
*
dump_fp
)
{
int
fd
;
struct
{
struct
nlmsghdr
nlh
;
struct
packet_diag_req
r
;
}
req
;
DIAG_REQUEST
(
req
,
struct
packet_diag_req
r
);
char
buf
[
16384
];
if
((
fd
=
socket
(
AF_NETLINK
,
SOCK_RAW
,
NETLINK_INET_DIAG
))
<
0
)
return
-
1
;
memset
(
&
req
,
0
,
sizeof
(
req
));
req
.
nlh
.
nlmsg_len
=
sizeof
(
req
);
req
.
nlh
.
nlmsg_type
=
SOCK_DIAG_BY_FAMILY
;
req
.
nlh
.
nlmsg_flags
=
NLM_F_ROOT
|
NLM_F_MATCH
|
NLM_F_REQUEST
;
req
.
nlh
.
nlmsg_seq
=
123456
;
req
.
r
.
sdiag_family
=
AF_PACKET
;
req
.
r
.
pdiag_show
=
PACKET_SHOW_INFO
|
PACKET_SHOW_MEMINFO
|
PACKET_SHOW_FILTER
;
...
...
@@ -3104,16 +3091,7 @@ static int netlink_show_sock(struct nlmsghdr *nlh, struct filter *f)
static
int
netlink_show_netlink
(
struct
filter
*
f
,
FILE
*
dump_fp
)
{
struct
{
struct
nlmsghdr
nlh
;
struct
netlink_diag_req
r
;
}
req
;
memset
(
&
req
,
0
,
sizeof
(
req
));
req
.
nlh
.
nlmsg_len
=
sizeof
(
req
);
req
.
nlh
.
nlmsg_type
=
SOCK_DIAG_BY_FAMILY
;
req
.
nlh
.
nlmsg_flags
=
NLM_F_ROOT
|
NLM_F_MATCH
|
NLM_F_REQUEST
;
req
.
nlh
.
nlmsg_seq
=
123456
;
DIAG_REQUEST
(
req
,
struct
netlink_diag_req
r
);
req
.
r
.
sdiag_family
=
AF_NETLINK
;
req
.
r
.
sdiag_protocol
=
NDIAG_PROTO_ALL
;
...
...
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