diff --git a/include/kerndat.h b/include/kerndat.h index b9ae74931..e76b0d2cc 100644 --- a/include/kerndat.h +++ b/include/kerndat.h @@ -24,6 +24,7 @@ struct kerndat_s { bool has_memfd; bool has_fdinfo_lock; unsigned long task_size; + bool ipv6; }; extern struct kerndat_s kdat; diff --git a/kerndat.c b/kerndat.c index dab56bacc..5b9df83d9 100644 --- a/kerndat.c +++ b/kerndat.c @@ -333,6 +333,21 @@ out: return exit_code; } +static int get_ipv6() +{ + if (access("/proc/sys/net/ipv6", F_OK) < 0) { + if (errno == ENOENT) { + pr_debug("ipv6 is disabled\n"); + kdat.ipv6 = false; + return 0; + } + pr_perror("Unable to access /proc/sys/net/ipv6"); + return -1; + } + kdat.ipv6 = true; + return 0; +} + int kerndat_init(void) { int ret; @@ -348,6 +363,8 @@ int kerndat_init(void) ret = kerndat_fdinfo_has_lock(); if (!ret) ret = get_task_size(); + if (!ret) + ret = get_ipv6(); kerndat_lsm(); @@ -371,6 +388,8 @@ int kerndat_init_rst(void) ret = kerndat_has_memfd_create(); if (!ret) ret = get_task_size(); + if (!ret) + ret = get_ipv6(); kerndat_lsm(); diff --git a/net.c b/net.c index cca5ef884..7c42178b2 100644 --- a/net.c +++ b/net.c @@ -25,6 +25,8 @@ #include "pstree.h" #include "string.h" #include "sysctl.h" +#include "kerndat.h" + #include "protobuf.h" #include "protobuf/netdev.pb-c.h" @@ -641,10 +643,8 @@ static inline int dump_route(struct cr_imgset *fds) return -1; /* If ipv6 is disabled, "ip -6 route dump" dumps all routes */ - if (access("/proc/sys/net/ipv6/", F_OK)) { - pr_debug("ipv6 is disabled\n"); + if (!kdat.ipv6) return 0; - } img = img_from_set(fds, CR_FD_ROUTE6); if (run_ip_tool("-6", "route", "save", -1, img_raw_fd(img), 0))