pkgsrc-WIP-changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
py-netsnmp-cffi: fix handling of sockaddrs on *BSD systems.
Module Name: pkgsrc-wip
Committed By: Havard Eidnes <he%NetBSD.org@localhost>
Pushed By: he
Date: Fri Apr 25 18:00:22 2025 +0200
Changeset: 272ce06b1b2a70a0618104236fe1bd7e26b3ccd1
Modified Files:
py-netsnmp-cffi/Makefile
py-netsnmp-cffi/distinfo
py-netsnmp-cffi/patches/patch-src_netsnmpy_netsnmp__ffi.py
Added Files:
py-netsnmp-cffi/patches/patch-src_netsnmp_trapsession.py
Log Message:
py-netsnmp-cffi: fix handling of sockaddrs on *BSD systems.
Fix from working on https://github.com/Uninett/netsnmp-cffi/issues/3.
To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=272ce06b1b2a70a0618104236fe1bd7e26b3ccd1
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
diffstat:
py-netsnmp-cffi/Makefile | 2 +-
py-netsnmp-cffi/distinfo | 3 +-
.../patches/patch-src_netsnmp_trapsession.py | 62 ++++++++++++++++++++++
.../patches/patch-src_netsnmpy_netsnmp__ffi.py | 22 +++++++-
4 files changed, 86 insertions(+), 3 deletions(-)
diffs:
diff --git a/py-netsnmp-cffi/Makefile b/py-netsnmp-cffi/Makefile
index 15e116d192..dd86d3c8f5 100644
--- a/py-netsnmp-cffi/Makefile
+++ b/py-netsnmp-cffi/Makefile
@@ -2,7 +2,7 @@
DISTNAME= netsnmp-cffi-0.1.1
PKGNAME= ${PYPKGPREFIX}-${DISTNAME}
-PKGREVISION= 1
+PKGREVISION= 2
CATEGORIES= net
MASTER_SITES= ${MASTER_SITE_GITHUB:=Uninett/}
GITHUB_PROJECT= netsnmp-cffi
diff --git a/py-netsnmp-cffi/distinfo b/py-netsnmp-cffi/distinfo
index e51023e1f2..d05a2099a0 100644
--- a/py-netsnmp-cffi/distinfo
+++ b/py-netsnmp-cffi/distinfo
@@ -3,4 +3,5 @@ $NetBSD$
BLAKE2s (netsnmp-cffi-0.1.1.tar.gz) = 10d75260cfca2be08f73f7ff0e8726a3eec2b351a6a6c8f136d0a4ddea087d37
SHA512 (netsnmp-cffi-0.1.1.tar.gz) = 1f0be1e2af13364f3b93c7dc26e2f78d57e9f9120185fe4b85251e4b0a7417117a83dd3626abd2874a6b1ce99cbd1d7e42198b1159bd7b715b51084a9e121311
Size (netsnmp-cffi-0.1.1.tar.gz) = 38212 bytes
-SHA1 (patch-src_netsnmpy_netsnmp__ffi.py) = de719c36fecb5e9c48011e0ed88c424123498b21
+SHA1 (patch-src_netsnmp_trapsession.py) = 7293de0f01b9c59b82d92c8d5ec11b060ecd6900
+SHA1 (patch-src_netsnmpy_netsnmp__ffi.py) = 7e8129335e25b07c5d8daccd311964aedc02a547
diff --git a/py-netsnmp-cffi/patches/patch-src_netsnmp_trapsession.py b/py-netsnmp-cffi/patches/patch-src_netsnmp_trapsession.py
new file mode 100644
index 0000000000..d179d7d8d7
--- /dev/null
+++ b/py-netsnmp-cffi/patches/patch-src_netsnmp_trapsession.py
@@ -0,0 +1,62 @@
+$NetBSD$
+
+Add patch to handle sockaddr layout on BSD*s.
+
+--- src/netsnmpy/trapsession.py.orig 2025-04-25 09:15:29.422003201 +0000
++++ src/netsnmpy/trapsession.py
+@@ -1,6 +1,7 @@
+ """SNMP Trap session handling"""
+
+ import logging
++import platform
+ from ipaddress import ip_address
+ from socket import AF_INET, AF_INET6, inet_ntop
+ from typing import Optional, Protocol
+@@ -36,10 +37,18 @@ _lib = _netsnmp.lib
+ _log = logging.getLogger(__name__)
+
+ # Local constants
++SOCKADDR_OFFSET = 1 if "BSD" in platform.system() else 0
+ IPADDR_SIZE = 4
+ IP6ADDR_SIZE = 16
+-IPADDR_OFFSET = 4
+-IP6ADDR_OFFSET = 8
++IPADDR_OFFSET = 0
++IP6ADDR_OFFSET = _ffi.sizeof("uint32_t") # sin6_flowinfo
++if "BSD" in platform.platform():
++ SOCKADDR_TYPE = "bsd_sockaddr_in"
++ SA_FAILY_TYPE = "uint8_t"
++else:
++ SOCKADDR_TYPE = "linux_sockaddr_in"
++ SA_FAMILY_TYPE = "unsigned short"
++SOCKADDR_DATA_OFFSET = _ffi.offsetof(SOCKADDR_TYPE, "sa_data")
+
+ OBJID_SNMP_TRAPS = OID(".1.3.6.1.6.3.1.1.5")
+ OBJID_SNMP_TRAP_OID = OID(".1.3.6.1.6.3.1.1.4.1.0")
+@@ -248,18 +257,19 @@ class SNMPTrap:
+ if pdu.transport_data_length <= 1:
+ return
+
+- # peek the first two bytes of the pdu's opaque transport data to determine
+- # socket address family (we are assuming the transport_data is a sockaddr_in
+- # or sockaddr_in6 structure and accessing it naughtily here)
+- family_p = _ffi.cast("unsigned short*", pdu.transport_data)
+- family = family_p[0]
++ # peek the first part of the pdu's opaque transport data to determine socket
++ # address family (we are assuming the transport_data is a sockaddr_in or
++ # sockaddr_in6 structure and accessing it naughtily here. sockaddr
++ # definitions vary between platforms, further complicating this).
++ sockaddr = _ffi.cast(f"{SOCKADDR_TYPE}*", pdu.transport_data)
++ family = sockaddr[0].sa_family
+ if family not in (AF_INET, AF_INET6):
+ return
+
+ addr_size, offset = (
+- (IPADDR_SIZE, IPADDR_OFFSET)
++ (IPADDR_SIZE, SOCKADDR_DATA_OFFSET + IPADDR_OFFSET)
+ if family == AF_INET
+- else (IP6ADDR_SIZE, IP6ADDR_OFFSET)
++ else (IP6ADDR_SIZE, SOCKADDR_DATA_OFFSET + IP6ADDR_OFFSET)
+ )
+
+ buffer = _ffi.cast("char*", pdu.transport_data)
diff --git a/py-netsnmp-cffi/patches/patch-src_netsnmpy_netsnmp__ffi.py b/py-netsnmp-cffi/patches/patch-src_netsnmpy_netsnmp__ffi.py
index 2a1b8f9c6f..2d8d9c2733 100644
--- a/py-netsnmp-cffi/patches/patch-src_netsnmpy_netsnmp__ffi.py
+++ b/py-netsnmp-cffi/patches/patch-src_netsnmpy_netsnmp__ffi.py
@@ -3,9 +3,29 @@ $NetBSD$
Provide a hook to replace correct type for time_t and suseconds_t.
See pre-configure target.
+Also handle the difference in sockaddr layout on Linux & BSDs.
+
--- src/netsnmpy/netsnmp_ffi.py.orig 2025-02-19 13:40:58.000000000 +0000
+++ src/netsnmpy/netsnmp_ffi.py
-@@ -20,9 +20,11 @@ typedef unsigned short u_short;
+@@ -12,6 +12,17 @@ typedef struct _callback_data {
+ void *reserved;
+ unsigned long session_id;
+ } _callback_data;
++typedef struct linux_sockaddr_in {
++ unsigned short sa_family;
++ unsigned short sa_port;
++ char sa_data[14];
++} linux_sockaddr_in;
++typedef struct bsd_sockaddr_in {
++ uint8_t sa_len;
++ uint8_t sa_family;
++ unsigned short sa_port;
++ char sa_data[14];
++} bsd_sockaddr_in;
+ """
+ _CDEF = f"""
+ /* Typedefs and structs we will be needing access to */
+@@ -20,9 +31,11 @@ typedef unsigned short u_short;
typedef unsigned char u_char;
typedef unsigned int u_int;
typedef unsigned long oid;
Home |
Main Index |
Thread Index |
Old Index