aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2024-04-30 16:25:11 +0000
committerMark Johnston <markj@FreeBSD.org>2024-05-09 16:41:22 +0000
commit26406929ca14b616c3de4242d1a7cde0a57ee521 (patch)
tree1af4782d4bca56247d023deefd453ac959bbff29
parent03e9f0cdfac68b11552c62cac1eaa27690fc0d32 (diff)
downloadports-26406929ca14b616c3de4242d1a7cde0a57ee521.tar.gz
ports-26406929ca14b616c3de4242d1a7cde0a57ee521.zip
net-mgmt/net-snmp: Fix the IPV6 MIB implementation
The implementations of var_tcp6() and var_udp6() on FreeBSD don't work and fail to compile. var_tcp6() also makes uses of kmem access, which I'm trying to disable in snmpd. Provide a patch to fix these problems. This has been committed to the 5.9 branch upstream. Readd mibII/ipv6 since it now compiles and works in my manual testing. Also, simply remove the IPV6 option. It has no effect, as --enable-ipv6 is the default. Approved by: zi Sponsored by: Klara, Inc. Sponsored by: Stormshield Differential Revision: https://reviews.freebsd.org/D45030
-rw-r--r--net-mgmt/net-snmp/Makefile16
-rw-r--r--net-mgmt/net-snmp/files/patch-agent_mibgroup_mibII_ipv6.c127
2 files changed, 129 insertions, 14 deletions
diff --git a/net-mgmt/net-snmp/Makefile b/net-mgmt/net-snmp/Makefile
index 9909de70e05f..71ad983bf18d 100644
--- a/net-mgmt/net-snmp/Makefile
+++ b/net-mgmt/net-snmp/Makefile
@@ -17,7 +17,7 @@ LICENSE_FILE= ${WRKSRC}/COPYING
NOT_FOR_ARCHS= mips mips64
NOT_FOR_ARCHS_REASON= SSP is currently broken on MIPS
-OPTIONS_DEFINE= IPV6 MFD_REWRITES PERL PERL_EMBEDDED PYTHON DUMMY TKMIB \
+OPTIONS_DEFINE= MFD_REWRITES PERL PERL_EMBEDDED PYTHON DUMMY TKMIB \
MYSQL AX_SOCKONLY UNPRIVILEGED SMUX DOCS JAIL AX_DISABLE_TRAP \
TLS NEWSYSLOG NOLIBPKG SCTP
OPTIONS_DEFAULT=PERL PERL_EMBEDDED DUMMY SMUX NEWSYSLOG
@@ -54,7 +54,7 @@ CONFIGURE_ARGS+=--enable-shared --enable-internal-md5 \
--with-sys-location="${NET_SNMP_SYS_LOCATION}" \
--with-logfile="${NET_SNMP_LOGFILE}" \
--with-persistent-directory="${NET_SNMP_PERSISTENTDIR}" \
- --with-gnu-ld --without-libwrap \
+ --with-gnu-ld --without-libwrap --enable-ipv6 \
--with-ldflags="-lm -lkvm -ldevstat -L${PKG_PREFIX}/lib -L${LOCALBASE}/lib ${LCRYPTO}"
SUB_FILES= pkg-message
@@ -129,14 +129,6 @@ CONFIGURE_ARGS+=--disable-snmptrapd-subagent
CONFIGURE_ARGS+=--enable-agentx-dom-sock-only
.endif
-.if ${PORT_OPTIONS:MIPV6}
-CONFIGURE_ARGS+=--enable-ipv6
-# --with-transport="UDPIPv6 TCPIPv6" --with-modules=mibII/ipv6"
-PLIST_SUB+= WITH_IPV6=""
-.else
-PLIST_SUB+= WITH_IPV6="@comment "
-.endif
-
.if ${PORT_OPTIONS:MUNPRIVILEGED}
CONFIGURE_ARGS+=--without-root-access
.endif
@@ -153,10 +145,6 @@ NET_SNMP_LOGFILE?= /var/log/snmpd.log
NET_SNMP_PERSISTENTDIR?=/var/net-snmp
NET_SNMP_WITH_MIB_MODULE_LIST+= host disman/event-mib mibII/mta_sendmail mibII/tcpTable ucd-snmp/diskio
-.if ${OPSYS} == FreeBSD
-NET_SNMP_WITHOUT_MIB_MODULE_LIST+= mibII/ipv6
-.endif
-
.if ${PORT_OPTIONS:MSCTP}
NET_SNMP_WITH_MIB_MODULE_LIST+= sctp-mib
.endif
diff --git a/net-mgmt/net-snmp/files/patch-agent_mibgroup_mibII_ipv6.c b/net-mgmt/net-snmp/files/patch-agent_mibgroup_mibII_ipv6.c
new file mode 100644
index 000000000000..ad4ea51fe56a
--- /dev/null
+++ b/net-mgmt/net-snmp/files/patch-agent_mibgroup_mibII_ipv6.c
@@ -0,0 +1,127 @@
+--- agent/mibgroup/mibII/ipv6.c.orig 2023-08-15 20:32:01 UTC
++++ agent/mibgroup/mibII/ipv6.c
+@@ -5,9 +5,6 @@
+
+ #include <net-snmp/net-snmp-config.h>
+ #include <net-snmp/net-snmp-features.h>
+-/* For FreeBSD */
+-#define _WANT_INPCB 1
+-#define _WANT_TCPCB 1
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #ifdef HAVE_SYS_IOCTL_H
+@@ -1513,8 +1510,10 @@ var_udp6(register struct variable * vp,
+ int result;
+ int i, j;
+ caddr_t p;
+-#if defined(openbsd4) || defined(freebsd3)
++#if defined(openbsd4)
+ static struct inpcb in6pcb, savpcb;
++#elif defined(freebsd3)
++ static struct xinpcb in6pcb, savpcb;
+ #else
+ static struct in6pcb in6pcb, savpcb;
+ #endif
+@@ -1614,8 +1613,7 @@ var_udp6(register struct variable * vp,
+ DEBUGMSGTL(("mibII/ipv6", "looping: p=%p\n", p));
+
+ #if defined(freebsd3)
+- /* To do: fill in in6pcb properly. */
+- memset(&in6pcb, 0, sizeof(in6pcb));
++ in6pcb = *(struct xinpcb *) xig;
+ #elif defined(darwin)
+ in6pcb = ((struct xinpcb *) xig)->xi_inp;
+ #else
+@@ -2108,12 +2106,18 @@ var_tcp6(register struct variable * vp,
+ int result;
+ int i, j;
+ caddr_t p;
+-#if defined(openbsd4) || defined(freebsd3)
++#if defined(openbsd4)
+ static struct inpcb in6pcb, savpcb;
++#elif defined(freebsd3)
++ static struct xinpcb in6pcb;
++ static int savstate;
+ #else
+ static struct in6pcb in6pcb, savpcb;
+ #endif
++#if !defined(freebsd3)
+ struct tcpcb tcpcb;
++#endif
++ int state;
+ int found, savnameLen;
+ #if defined(__NetBSD__) && __NetBSD_Version__ >= 106250000 || defined(openbsd4) /*1.6Y*/
+ struct inpcbtable tcbtable;
+@@ -2208,8 +2212,7 @@ var_tcp6(register struct variable * vp,
+ DEBUGMSGTL(("mibII/ipv6", "looping: p=%p\n", p));
+
+ #if defined(freebsd3)
+- /* To do: fill in in6pcb properly. */
+- memset(&in6pcb, 0, sizeof(in6pcb));
++ in6pcb = ((struct xtcpcb *) xig)->xt_inp;
+ #elif defined(dragonfly)
+ in6pcb = xtp->xt_inp;
+ #elif defined(darwin)
+@@ -2294,7 +2297,11 @@ var_tcp6(register struct variable * vp,
+ #endif
+ result = snmp_oid_compare(name, *length, newname, j);
+ if (exact && (result == 0)) {
++#if defined(freebsd3)
++ savstate = ((struct xtcpcb *) xig)->t_state;
++#else
+ memcpy(&savpcb, &in6pcb, sizeof(savpcb));
++#endif
+ savnameLen = j;
+ memcpy(savname, newname, j * sizeof(oid));
+ found++;
+@@ -2305,7 +2312,11 @@ var_tcp6(register struct variable * vp,
+ */
+ if ((savnameLen == 0) ||
+ (snmp_oid_compare(savname, savnameLen, newname, j) > 0)) {
++#if defined(freebsd3)
++ savstate = ((struct xtcpcb *) xig)->t_state;
++#else
+ memcpy(&savpcb, &in6pcb, sizeof(savpcb));
++#endif
+ savnameLen = j;
+ memcpy(savname, newname, j * sizeof(oid));
+ found++;
+@@ -2344,19 +2355,27 @@ var_tcp6(register struct variable * vp,
+ return NULL;
+ *length = savnameLen;
+ memcpy((char *) name, (char *) savname, *length * sizeof(oid));
++#if defined(freebsd3)
++ state = savstate;
++#elif defined(__NetBSD__) && __NetBSD_Version__ >= 999010400
+ memcpy(&in6pcb, &savpcb, sizeof(savpcb));
+-#if defined(__NetBSD__) && __NetBSD_Version__ >= 999010400
+ if (!NETSNMP_KLOOKUP(in6pcb.in6p_pcb.inp_ppcb, (char *) &tcpcb, sizeof(tcpcb))) {
+ DEBUGMSGTL(("mibII/ipv6", "klookup fail for tcb6.tcpcb at %p\n",
+ in6pcb.in6p_pcb.inp_ppcb));
++ found = 0;
++ return NULL;
++ }
++ state = (int)tcpcb.t_state;
+ #else
++ memcpy(&in6pcb, &savpcb, sizeof(savpcb));
+ if (!NETSNMP_KLOOKUP(in6pcb.inp_ppcb, (char *) &tcpcb, sizeof(tcpcb))) {
+ DEBUGMSGTL(("mibII/ipv6", "klookup fail for tcb6.tcpcb at %p\n",
+ in6pcb.inp_ppcb));
+-#endif
+ found = 0;
+ return NULL;
+ }
++ state = (int)tcpcb.t_state;
++#endif
+ *write_method = 0;
+ *var_len = sizeof(long); /* default to 'long' results */
+
+@@ -2368,7 +2387,7 @@ var_tcp6(register struct variable * vp,
+ DEBUGMSGTL(("mibII/ipv6", "magic=%d\n", vp->magic));
+ switch (vp->magic) {
+ case IPV6TCPCONNSTATE:
+- long_return = mapTcpState((int)tcpcb.t_state);
++ long_return = mapTcpState(state);
+ return (u_char *) & long_return;
+ default:
+ break;