Skip to contentSkip to conversation

Refactoring for monitoring utils

PATCH New Vadim Kochan 1 participant 3 messages Jan 13, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Refactoring for monitoring utils

From: Vadim Kochan <[email protected]>

This series is just about refactoring for bridge/ip/rtmon monitoring tools.

Changes:
1) Added #define for nlmsg_type = 15 which is used for log timestamp within nlmsg for monitoring tools.

2) Using one function to print timestamp from nlmsg for ip/bridge monitor tools.

Vadim Kochan (2):
Add define for nlmsg_types with timestamp
Use one func to print timestamp from nlmsg

 bridge/monitor.c     | 18 +++---------------
 include/libnetlink.h |  4 ++++
 include/utils.h      |  2 ++
 ip/ipmonitor.c       |  9 ++-------
 ip/rtmon.c           |  2 +-
 lib/utils.c          | 10 ++++++++++
 6 files changed, 22 insertions(+), 23 deletions(-)
Signature · 1 line
2.1.3
#1 lore raw

PATCH 1/2 Add define for nlmsg_types with timestamp

From: Vadim Kochan <[email protected]>

Add #define for nlmsg_type = 15

---
 bridge/monitor.c     | 4 +---
 include/libnetlink.h | 4 ++++
 ip/ipmonitor.c       | 2 +-
 ip/rtmon.c           | 2 +-
 4 files changed, 7 insertions(+), 5 deletions(-)
bridge/monitor.c +1 -3
index 76e7d47..f00e0a6 100644
@@ -74,14 +74,12 @@ static int accept_msg(const struct sockaddr_nl *who,
 			fprintf(fp, "[MDB]");
 		return print_mdb(who, n, arg);
 
-	case 15:
+	case NLMSG_TSTAMP:
 		return show_mark(fp, n);
 
 	default:
 		return 0;
 	}
-
-
 }
 
 int do_monitor(int argc, char **argv)
include/libnetlink.h +4 -0
index de7c85f..d081e54 100644
@@ -158,5 +158,9 @@ extern int rtnl_from_file(FILE *, rtnl_filter_t handler,
 #define NDTA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndtmsg))
 #endif
 
+/* User defined nlmsg_type which is used mostly for logging netlink
+ * messages from dump file */
+#define NLMSG_TSTAMP	15
+
 #endif /* __LIBNETLINK_H__ */
 
ip/ipmonitor.c +1 -1
index 4708e54..f40daac 100644
@@ -125,7 +125,7 @@ static int accept_msg(const struct sockaddr_nl *who,
 		print_netconf(who, n, arg);
 		return 0;
 	}
-	if (n->nlmsg_type == 15) {
+	if (n->nlmsg_type == NLMSG_TSTAMP) {
 		char *tstr;
 		time_t secs = ((__u32*)NLMSG_DATA(n))[0];
 		long usecs = ((__u32*)NLMSG_DATA(n))[1];
ip/rtmon.c +1 -1
index 9227eac..ff685e5 100644
@@ -34,7 +34,7 @@ static void write_stamp(FILE *fp)
 	struct nlmsghdr *n1 = (void*)buf;
 	struct timeval tv;
 
-	n1->nlmsg_type = 15;
+	n1->nlmsg_type = NLMSG_TSTAMP;
 	n1->nlmsg_flags = 0;
 	n1->nlmsg_seq = 0;
 	n1->nlmsg_pid = 0;
Signature · 1 line
2.1.3
#2 lore raw

PATCH 2/2 Use one func to print timestamp from nlmsg

In reply to Vadim Kochan

From: Vadim Kochan <[email protected]>

---
 bridge/monitor.c | 14 ++------------
 include/utils.h  |  2 ++
 ip/ipmonitor.c   |  7 +------
 lib/utils.c      | 10 ++++++++++
 4 files changed, 15 insertions(+), 18 deletions(-)
bridge/monitor.c +2 -12
index f00e0a6..9e1ed48 100644
@@ -35,17 +35,6 @@ static void usage(void)
 	exit(-1);
 }
 
-static int show_mark(FILE *fp, const struct nlmsghdr *n)
-{
-	char *tstr;
-	time_t secs = ((__u32*)NLMSG_DATA(n))[0];
-	long usecs = ((__u32*)NLMSG_DATA(n))[1];
-	tstr = asctime(localtime(&secs));
-	tstr[strlen(tstr)-1] = 0;
-	fprintf(fp, "Timestamp: %s %lu us\n", tstr, usecs);
-	return 0;
-}
-
 static int accept_msg(const struct sockaddr_nl *who,
 		      struct nlmsghdr *n, void *arg)
 {
@@ -75,7 +64,8 @@ static int accept_msg(const struct sockaddr_nl *who,
 		return print_mdb(who, n, arg);
 
 	case NLMSG_TSTAMP:
-		return show_mark(fp, n);
+		print_nlmsg_timestamp(fp, n);
+		return 0;
 
 	default:
 		return 0;
include/utils.h +2 -0
index eecbc39..e1fe7cf 100644
@@ -148,6 +148,7 @@ static inline __u32 nl_mgrp(__u32 group)
 
 
 int print_timestamp(FILE *fp);
+void print_nlmsg_timestamp(FILE *fp, const struct nlmsghdr *n);
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 
@@ -160,4 +161,5 @@ struct iplink_req;
 int iplink_parse(int argc, char **argv, struct iplink_req *req,
 		char **name, char **type, char **link, char **dev,
 		int *group, int *index);
+
 #endif /* __UTILS_H__ */
ip/ipmonitor.c +1 -6
index f40daac..5ec8f41 100644
@@ -126,12 +126,7 @@ static int accept_msg(const struct sockaddr_nl *who,
 		return 0;
 	}
 	if (n->nlmsg_type == NLMSG_TSTAMP) {
-		char *tstr;
-		time_t secs = ((__u32*)NLMSG_DATA(n))[0];
-		long usecs = ((__u32*)NLMSG_DATA(n))[1];
-		tstr = asctime(localtime(&secs));
-		tstr[strlen(tstr)-1] = 0;
-		fprintf(fp, "Timestamp: %s %lu us\n", tstr, usecs);
+		print_nlmsg_timestamp(fp, n);
 		return 0;
 	}
 	if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP &&
lib/utils.c +10 -0
index 64915f3..f65ceaa 100644
@@ -868,3 +868,13 @@ int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6)
 	else
 		return inet_pton(AF_INET, src, dst);
 }
+
+void print_nlmsg_timestamp(FILE *fp, const struct nlmsghdr *n)
+{
+	char *tstr;
+	time_t secs = ((__u32*)NLMSG_DATA(n))[0];
+	long usecs = ((__u32*)NLMSG_DATA(n))[1];
+	tstr = asctime(localtime(&secs));
+	tstr[strlen(tstr)-1] = 0;
+	fprintf(fp, "Timestamp: %s %lu us\n", tstr, usecs);
+}
Signature · 1 line
2.1.3