]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
netns_ifaddrs: handle IFLA_STATS{64} correctly 2663/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 30 Sep 2018 10:25:27 +0000 (12:25 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 30 Sep 2018 10:29:19 +0000 (12:29 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
configure.ac
src/include/netns_ifaddrs.c
src/include/netns_ifaddrs.h
src/lxc/macro.h

index ac15c1fef34096f072bbe48be92a6fbc19c98f0e..cbd6dbb7bf37c9e9716b1ce55b6072ed743f9036 100644 (file)
@@ -676,6 +676,9 @@ AC_CHECK_FUNCS([strlcat],
        AC_DEFINE(HAVE_STRLCAT,1,[Have strlcat]),
        AM_CONDITIONAL(HAVE_STRLCAT, false))
 
+# HAVE_STRUCT_RTNL_LINK_STATS64={0,1}
+AC_CHECK_TYPES([struct rtnl_link_stats64], [], [], [[#include <linux/if_link.h>]])
+
 # Check for some libraries
 AX_PTHREAD
 AC_SEARCH_LIBS(clock_gettime, [rt])
index f108ea8c058cda950e2bcaf980ae8cbc49b0671a..855d716078ddbe93ceb761bbc8c6e566eaefff60 100644 (file)
@@ -177,7 +177,11 @@ static int nl_msg_to_ifaddr(void *pctx, bool *netnsid_aware, struct nlmsghdr *h)
 #pragma GCC diagnostic ignored "-Wcast-align"
                for (rta = __NLMSG_RTA(h, sizeof(*ifi)); __NLMSG_RTAOK(rta, h);
                     rta = __RTA_NEXT(rta)) {
+#if HAVE_STRUCT_RTNL_LINK_STATS64
+                       if (rta->rta_type != IFLA_STATS64)
+#else
                        if (rta->rta_type != IFLA_STATS)
+#endif
                                continue;
 
                        stats_len = __RTA_DATALEN(rta);
@@ -226,11 +230,19 @@ static int nl_msg_to_ifaddr(void *pctx, bool *netnsid_aware, struct nlmsghdr *h)
                                            __RTA_DATA(rta), __RTA_DATALEN(rta),
                                            ifi->ifi_index, ifi->ifi_type);
                                break;
+#if HAVE_STRUCT_RTNL_LINK_STATS64
+                       case IFLA_STATS64:
+                               ifs->ifa.ifa_stats_type = IFLA_STATS64;
+                               memcpy(&ifs->ifa.ifa_stats64, __RTA_DATA(rta),
+                                      __RTA_DATALEN(rta));
+                               break;
+#else
                        case IFLA_STATS:
-                               ifs->ifa.ifa_data = (void *)(ifs + 1);
-                               memcpy(ifs->ifa.ifa_data, __RTA_DATA(rta),
+                               ifs->ifa.ifa_stats_type = IFLA_STATS;
+                               memcpy(&ifs->ifa.ifa_stats32, __RTA_DATA(rta),
                                       __RTA_DATALEN(rta));
                                break;
+#endif
                        case IFLA_MTU:
                                memcpy(&ifs->ifa.ifa_mtu, __RTA_DATA(rta),
                                       sizeof(int));
index bfecbc099bb0ef4ba87d00ada70544e2c0bdfb2a..4ab7f46c7548884612c6530072ef5d70cc5642b2 100644 (file)
@@ -6,6 +6,7 @@ extern "C" {
 #endif
 
 #include <features.h>
+#include <linux/if_link.h>
 #include <linux/types.h>
 #include <netinet/in.h>
 #include <stdbool.h>
@@ -37,8 +38,10 @@ struct netns_ifaddrs {
                struct sockaddr *ifu_dstaddr;
        } ifa_ifu;
 
-       /* If you don't know what this is for don't touch it. */
-       void *ifa_data;
+       /* These fields are not present struct ifaddrs. */
+       int ifa_stats_type;
+       struct rtnl_link_stats ifa_stats32;
+       struct rtnl_link_stats64 ifa_stats64;
 };
 
 #define __ifa_broadaddr ifa_ifu.ifu_broadaddr
index 471e34f4e36f46b5fb00de55c67ce28c067024ad..baee5ae8a429d19e67c374dab588865f0c88a681 100644 (file)
@@ -283,6 +283,13 @@ extern int __build_bug_on_failed;
 #define IFA_TARGET_NETNSID 10
 #endif
 
+#ifndef IFLA_STATS
+#define IFLA_STATS 7
+#endif
+
+#ifndef IFLA_STATS64
+#define IFLA_STATS64 23
+#endif
 
 #ifndef RTM_NEWNSID
 #define RTM_NEWNSID 88