Commit 60a6aa5a authored by Kirill Smelkov's avatar Kirill Smelkov

X Teach ip monitor to also show info about cached (= cloned) routes

parent 1d63d8c6
......@@ -62,22 +62,25 @@ static int accept_msg(const struct sockaddr_nl *who,
if (n->nlmsg_type == RTM_NEWROUTE || n->nlmsg_type == RTM_DELROUTE) {
struct rtmsg *r = NLMSG_DATA(n);
int len = n->nlmsg_len - NLMSG_LENGTH(sizeof(*r));
bool rtcloned = r->rtm_flags & RTM_F_CLONED;
if (len < 0) {
fprintf(stderr, "BUG: wrong nlmsg len %d\n", len);
return -1;
}
if (r->rtm_flags & RTM_F_CLONED)
return 0;
//if (r->rtm_flags & RTM_F_CLONED)
// return 0;
if (r->rtm_family == RTNL_FAMILY_IPMR ||
r->rtm_family == RTNL_FAMILY_IP6MR) {
print_headers(fp, "[MROUTE]", ctrl);
print_headers(fp, rtcloned ? "[MRCACHE]" : "[MROUTE]", ctrl);
print_mroute(who, n, arg);
return 0;
} else {
print_headers(fp, "[ROUTE]", ctrl);
//fprintf(fp, "\n\nRRR\n");
print_headers(fp, rtcloned ? "[RTCAH]" : "[ROUTE]", ctrl);
//fprintf(fp, "X\n");
print_route(who, n, arg);
return 0;
}
......
......@@ -155,8 +155,9 @@ static int filter_nlmsg(struct nlmsghdr *n, struct rtattr **tb, int host_len)
if (r->rtm_family == AF_INET6 && table != RT_TABLE_MAIN)
ip6_multiple_tables = 1;
if (filter.cloned == !(r->rtm_flags&RTM_F_CLONED))
return 0;
// kirr: show cached routes
//if (filter.cloned == !(r->rtm_flags&RTM_F_CLONED))
// return 0;
if (r->rtm_family == AF_INET6 && !ip6_multiple_tables) {
if (filter.tb) {
......@@ -329,6 +330,7 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags);
return 0;
}
//fprintf(fp, "flushb: %p\n", filter.flushb);
if (filter.flushb && n->nlmsg_type != RTM_NEWROUTE)
return 0;
len -= NLMSG_LENGTH(sizeof(*r));
......@@ -342,8 +344,10 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
parse_rtattr(tb, RTA_MAX, RTM_RTA(r), len);
table = rtm_get_table(r, tb);
//fprintf(fp, "R: before filter_nlmsg\n");
if (!filter_nlmsg(n, tb, host_len))
return 0;
//fprintf(fp, "R: after filter_nlmsg\n");
if (filter.flushb) {
struct nlmsghdr *fn;
......
......@@ -1031,12 +1031,21 @@ int inet_get_addr(const char *src, __u32 *dst, struct in6_addr *dst6)
void print_nlmsg_timestamp(FILE *fp, const struct nlmsghdr *n)
{
char *tstr;
//char *tstr;
time_t secs = ((__u32*)NLMSG_DATA(n))[0];
long usecs = ((__u32*)NLMSG_DATA(n))[1];
#if 0
/* verbose timestamp on separate line */
tstr = asctime(localtime(&secs));
tstr[strlen(tstr)-1] = 0;
fprintf(fp, "Timestamp: %s %lu us\n", tstr, usecs);
#else
/* short timestamp on the same line as prefix */
char tshort[40];
strftime(tshort, sizeof(tshort), "%Y-%m-%dT%H:%M:%S", localtime(&secs));
fprintf(fp, "[%s.%06ld] ", tshort, usecs);
#endif
}
static int on_netns(char *nsname, void *arg)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment