lib: Replace 16384 netlink buf by macro
Subsystems (3)
PATCH 1/1 lib: Replace 16384 netlink buf by macro
From: Vadim Kochan <[email protected]>
Replaced hard coded 16384 sized netlink message buffer by NL_BUF(x) macro.
Buffer size can be overrided by -DNLBUF_SIZE.
--- include/libnetlink.h | 6 ++++++ ip/iplink.c | 2 +- lib/libnetlink.c | 8 ++++---- misc/ss.c | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-)
include/libnetlink.h +6 -0
@@ -170,5 +170,11 @@ extern int rtnl_from_file(FILE *, rtnl_filter_t handler,* messages from dump file */ #define NLMSG_TSTAMP 15 +#ifndef NLBUF_SIZE +#define NLBUF_SIZE 16384 +#endif + +#define NL_BUF (b) char b[NLBUF_SIZE] +#endif /* __LIBNETLINK_H__ */
ip/iplink.c +1 -1
@@ -770,7 +770,7 @@ int iplink_get(unsigned int flags, char *name, __u32 filt_mask) {int len;struct iplink_req req; -char answer[16384 ]; +NL_BUF (answer);memset (&req,0 ,sizeof (req));
lib/libnetlink.c +4 -4
@@ -194,7 +194,7 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth, .msg_iov = &iov, .msg_iovlen = 1, }; -char buf[16384 ]; +NL_BUF (buf);int dump_intr =0 ; iov.iov_base = buf;
@@ -317,7 +317,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, .msg_iov = &iov, .msg_iovlen = 1, }; -char buf[16384 ]; +NL_BUF (buf);memset (&nladdr,0 ,sizeof (nladdr)); nladdr.nl_family =AF_NETLINK ;
@@ -432,7 +432,7 @@ int rtnl_listen(struct rtnl_handle *rtnl, .msg_iov = &iov, .msg_iovlen = 1, }; -char buf[16384 ]; +NL_BUF (buf);memset (&nladdr,0 ,sizeof (nladdr)); nladdr.nl_family =AF_NETLINK ;
@@ -498,7 +498,7 @@ int rtnl_from_file(FILE *rtnl, rtnl_filter_t handler, {int status;struct sockaddr_nl nladdr; -char buf[16384 ]; +NL_BUF (buf);struct nlmsghdr *h = (void *)buf;memset (&nladdr,0 ,sizeof (nladdr));
misc/ss.c +1 -1
@@ -2222,7 +2222,7 @@ Exit:static int tcp_show_netlink_file (struct filter *f) {FILE *fp; -char buf[16384 ]; +NL_BUF (buf);if ((fp =fopen (getenv ("TCPDIAG_FILE" ),"r" )) ==NULL ) {perror ("fopen($TCPDIAG_FILE)" );
Signature · 1 line
2.2.2
Quoted 36 lines · Wed, Feb 25, 2015 at 05:04:17PM CET, [email protected] wrote:
From: Vadim Kochan <[email protected]>
Replaced hard coded 16384 sized netlink message buffer by
NL_BUF(x)macro.Buffer size can be overrided by -DNLBUF_SIZE.
Signed-off-by Vadim Kochan <[email protected]>---
include/libnetlink.h | 6 ++++++ ip/iplink.c | 2 +- lib/libnetlink.c | 8 ++++---- misc/ss.c | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-)include/libnetlink.h +6
-0@@ -170,5 +170,11 @@ extern int rtnl_from_file(FILE *, rtnl_filter_t handler,* messages from dump file */ #define NLMSG_TSTAMP 15 +#ifndef NLBUF_SIZE +#define NLBUF_SIZE 16384 +#endif + +#define NL_BUF (b) char b[NLBUF_SIZE] +#endif /* __LIBNETLINK_H__ */ ip/iplink.c +0
-0
ip/iplink.c int iplink_get(unsigned int flags, char *name, __u32 filt_mask) · line 773
Quoted 5 lines
ip/iplink.c +1
-1@@ -770,7 +770,7 @@ int iplink_get(unsigned int flags, char *name, __u32 filt_mask) {int len;struct iplink_req req; -char answer[16384 ]; +NL_BUF (answer);
Why to obfuscate this? "char answer[NLBUF_SIZE];" seems allright...
Quoted 63 lines
ip/iplink.c +0
-0memset (&req,0 ,sizeof (req));lib/libnetlink.c +4
-4@@ -194,7 +194,7 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth, .msg_iov = &iov, .msg_iovlen = 1, }; -char buf[16384 ]; +NL_BUF (buf);int dump_intr =0 ; iov.iov_base = buf;@@ -317,7 +317,7 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer, .msg_iov = &iov, .msg_iovlen = 1, }; -char buf[16384 ]; +NL_BUF (buf);memset (&nladdr,0 ,sizeof (nladdr)); nladdr.nl_family =AF_NETLINK ;@@ -432,7 +432,7 @@ int rtnl_listen(struct rtnl_handle *rtnl, .msg_iov = &iov, .msg_iovlen = 1, }; -char buf[16384 ]; +NL_BUF (buf);memset (&nladdr,0 ,sizeof (nladdr)); nladdr.nl_family =AF_NETLINK ;@@ -498,7 +498,7 @@ int rtnl_from_file(FILE *rtnl, rtnl_filter_t handler, {int status;struct sockaddr_nl nladdr; -char buf[16384 ]; +NL_BUF (buf);struct nlmsghdr *h = (void *)buf;memset (&nladdr,0 ,sizeof (nladdr));misc/ss.c +1
-1@@ -2222,7 +2222,7 @@ Exit:static int tcp_show_netlink_file (struct filter *f) {FILE *fp; -char buf[16384 ]; +NL_BUF (buf);if ((fp =fopen (getenv ("TCPDIAG_FILE" ),"r" )) ==NULL ) {perror ("fopen($TCPDIAG_FILE)" );Signature · 6 lines
2.2.2 -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 32 lines · Jiri Pirko
Quoted 31 lines · Wed, Feb 25, 2015 at 05:04:17PM CET, [email protected] wrote:
From: Vadim Kochan <[email protected]>
Replaced hard coded 16384 sized netlink message buffer by
NL_BUF(x)macro.Buffer size can be overrided by -DNLBUF_SIZE.
Signed-off-by Vadim Kochan <[email protected]>---
include/libnetlink.h | 6 ++++++ ip/iplink.c | 2 +- lib/libnetlink.c | 8 ++++---- misc/ss.c | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-)include/libnetlink.h +6
-0@@ -170,5 +170,11 @@ extern int rtnl_from_file(FILE *, rtnl_filter_t handler,* messages from dump file */ #define NLMSG_TSTAMP 15 +#ifndef NLBUF_SIZE +#define NLBUF_SIZE 16384 +#endif + +#define NL_BUF (b) char b[NLBUF_SIZE] +#endif /* __LIBNETLINK_H__ */
Quoted 13 lines
ip/iplink.c int iplink_get(unsigned int flags, char *name, __u32 filt_mask) · line 773
Quoted 10 lines
ip/iplink.c +1
-1@@ -770,7 +770,7 @@ int iplink_get(unsigned int flags, char *name, __u32 filt_mask) {int len;struct iplink_req req; -char answer[16384 ]; +NL_BUF (answer);Why to obfuscate this? "char answer[NLBUF_SIZE];" seems allright...
Well, I thought that it would be easy to change the netlink buffer type in the future, but may be you're right - "char answer[NLBUF_SIZE];" is more readable anyway.
Thanks,