Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIB-II: Check for presence of /proc/net/if_inet6 file. #190

Open
jridky opened this issue Oct 1, 2020 · 4 comments
Open

MIB-II: Check for presence of /proc/net/if_inet6 file. #190

jridky opened this issue Oct 1, 2020 · 4 comments

Comments

@jridky
Copy link
Contributor

jridky commented Oct 1, 2020

Recently, I've received complains from our customers, why is snmpd logging ERROR messages about failing opening of /proc/net/if_inet6 file on systems, where IPv6 support is intentionally disabled.

After closer look to the source code I've found, snmpd is just trying to open /proc/net/if_inet6, but when it fails, it doesn't check, whether the failure was due of lack of access rights or due of missing /proc/net/if_inet6 file.

I believe, following patch can be beneficial for users, which are using net-snmp package build with --enable-ipv6 option on systems without actual IPv6 capabilities and don't want to be bothered with error message about if_inet6 file open failure.

What is your opinion on this solution? Any comment is welcome.

diff -urNp a/agent/mibgroup/ip-mib/data_access/ipaddress_linux.c b/agent/mibgroup/ip-mib/data_access/ipaddress_linux.c
--- a/agent/mibgroup/ip-mib/data_access/ipaddress_linux.c	2020-09-29 14:08:09.742478965 +0200
+++ b/agent/mibgroup/ip-mib/data_access/ipaddress_linux.c	2020-10-01 14:20:25.575174851 +0200
@@ -19,6 +19,7 @@
 
 #include <errno.h>
 #include <sys/ioctl.h>
+#include <sys/stat.h>
 
 netsnmp_feature_require(prefix_info)
 netsnmp_feature_require(find_prefix_info)
@@ -234,7 +235,18 @@ _load_v6(netsnmp_container *container, i
 
 #define PROCFILE "/proc/net/if_inet6"
     if (!(in = fopen(PROCFILE, "r"))) {
-        NETSNMP_LOGONCE((LOG_ERR, "ipaddress_linux: could not open " PROCFILE));
+
+        /* 
+         * If PROCFILE exists, but isn't readable, file ERROR message.
+         * Otherwise log nothing, due of IPv6 support on this machine is
+         * intentionaly disabled/unavailable.
+         */
+
+        struct stat filestat;
+
+        if(stat(PROCFILE, &filestat) == 0){
+            NETSNMP_LOGONCE((LOG_ERR, "ipaddress_linux: could not open " PROCFILE));
+        }
         return -2;
     }
@jridky
Copy link
Contributor Author

jridky commented Oct 13, 2020

Or maybe, is there way how to set proper flag to load_flags variable e.g. from snmpd.conf file?

@jridky
Copy link
Contributor Author

jridky commented Nov 9, 2020

@bvanassche any suggestion?

bvanassche pushed a commit that referenced this issue Nov 10, 2020
…onally

See also #190
[ bvanassche: modified variable names and source code comment ]
@bvanassche
Copy link
Contributor

A slightly modified patch has been applied. Please take a look.

@jridky
Copy link
Contributor Author

jridky commented Nov 10, 2020

Looks good. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants