netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2 v2] ss: Refactor to use macro for define diag nl request
@ 2014-10-19  8:01 Vadim Kochan
  2014-10-30 16:39 ` vadim4j
  0 siblings, 1 reply; 2+ messages in thread
From: Vadim Kochan @ 2014-10-19  8:01 UTC (permalink / raw)
  To: netdev; +Cc: Vadim Kochan

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
---
 misc/ss.c | 56 +++++++++++++++++---------------------------------------
 1 file changed, 17 insertions(+), 39 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index 2420b51..d067e5f 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -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
@@ -1795,10 +1808,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;
@@ -1811,11 +1821,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;
@@ -2577,16 +2582,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;
@@ -2778,21 +2774,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[8192];
 
 	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;
 
@@ -3091,16 +3078,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;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH iproute2 v2] ss: Refactor to use macro for define diag nl request
  2014-10-19  8:01 [PATCH iproute2 v2] ss: Refactor to use macro for define diag nl request Vadim Kochan
@ 2014-10-30 16:39 ` vadim4j
  0 siblings, 0 replies; 2+ messages in thread
From: vadim4j @ 2014-10-30 16:39 UTC (permalink / raw)
  To: netdev

On Sun, Oct 19, 2014 at 11:01:36AM +0300, Vadim Kochan wrote:
> Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
> ---
>  misc/ss.c | 56 +++++++++++++++++---------------------------------------
>  1 file changed, 17 insertions(+), 39 deletions(-)
> 
> diff --git a/misc/ss.c b/misc/ss.c
> index 2420b51..d067e5f 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
> @@ -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
> @@ -1795,10 +1808,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;
> @@ -1811,11 +1821,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;
> @@ -2577,16 +2582,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;
> @@ -2778,21 +2774,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[8192];
>  
>  	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;
>  
> @@ -3091,16 +3078,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;
> -- 
> 2.1.0
> 

Please ignore this patch because of conflicts with master, will resend v3.

Regards,

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-10-30 16:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-19  8:01 [PATCH iproute2 v2] ss: Refactor to use macro for define diag nl request Vadim Kochan
2014-10-30 16:39 ` vadim4j

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).