Created attachment 180784 [details] make ifAlias dynamic FreeBSD allows to assign descriptions to network interfaces by means of ifconfig(8) utility or kernel API utilized by daemons like net/mpd5. sysctl net.ifdescr_maxlen limits maximum description length to 1024 bytes by default, including terminating zero byte. bsnmpd shows these descriptions with ifAlias OIDs in the ifXTable (MIB-II) but has compiled-in limit MIBIF_ALIAS_SIZE equal to 65 bytes. If an interface has longer description (say, 70 bytes), bsnmpd complains: SIOCGIFDESCR (ng7): too long (70) And no description is returned to interface's ifAlias OID. Nevertheless, bsnmpd allocates a buffer of MIBIF_ALIAS_SIZE bytes to every network interface, is it used or not. Attached patch solves these problems and little more: - bsnmpd's network interface buffers for description/ifAlias now have dynamic size and allocate exact number of bytes; no extra memory allocated for interfaces having no description; - sysctl net.ifdescr_maxlen is used as limit instead of compiled-in MIBIF_ALIAS_SIZE; changes to this sysctl updated without restart of bsnmpd; - no more strlen() calls on every SNMP request for an ifAlias: we calculate actual size of buffer once, store it and use when needed; - corresponding data moved from struct mibif_private to struct mibif just as suggested by a comment: /* this should be made public */.
Hi! Just notifying you of awaiting PR. Would you like me to commit this myself?
Untaking bsnmp bugs (haven't worked for Isilon for months and have no burning desire to use bsnmp anymore).
My PR.
Adding harti@ in attempt to get more attention to this.
A commit references this bug: Author: eugen Date: Sat Aug 18 10:58:46 UTC 2018 New revision: 338013 URL: https://svnweb.freebsd.org/changeset/base/338013 Log: bsnmpd(8): fix and optimize interface description processing * correctly prepare a buffer to obtain interface description from a kernel and truncate long description instead of dropping it altogether and spamming logs; * skip calling strlen() for each description and each SNMP request for MIB-II/ifXTable's ifAlias. * teach bsnmpd to allocate memory dynamically for interface descriptions to decrease memory usage for common case and not to break if long description occurs; PR: 217763 Reviewed by: harti and others MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D16459 Changes: head/contrib/bsnmp/snmp_mibII/mibII.c head/contrib/bsnmp/snmp_mibII/mibII.h head/contrib/bsnmp/snmp_mibII/mibII_interfaces.c head/contrib/bsnmp/snmp_mibII/snmp_mibII.h
A commit references this bug: Author: eugen Date: Sat Aug 25 09:48:18 UTC 2018 New revision: 338310 URL: https://svnweb.freebsd.org/changeset/base/338310 Log: MFC 338013: bsnmpd(8): fix and optimize interface description processing * correctly prepare a buffer to obtain interface description from a kernel and truncate long description instead of dropping it altogether and spamming logs; * skip calling strlen() for each description and each SNMP request for MIB-II/ifXTable's ifAlias. * teach bsnmpd to allocate memory dynamically for interface descriptions to decrease memory usage for common case and not to break if long description occurs; PR: 217763 Reviewed by: harti and others Differential Revision: https://reviews.freebsd.org/D16459 Changes: _U stable/11/ stable/11/contrib/bsnmp/snmp_mibII/mibII.c stable/11/contrib/bsnmp/snmp_mibII/mibII.h stable/11/contrib/bsnmp/snmp_mibII/mibII_interfaces.c stable/11/contrib/bsnmp/snmp_mibII/snmp_mibII.h
A commit references this bug: Author: eugen Date: Sat Aug 25 10:42:45 UTC 2018 New revision: 338311 URL: https://svnweb.freebsd.org/changeset/base/338311 Log: MFC 338013: bsnmpd(8): fix and optimize interface description processing * correctly prepare a buffer to obtain interface description from a kernel and truncate long description instead of dropping it altogether and spamming logs; * skip calling strlen() for each description and each SNMP request for MIB-II/ifXTable's ifAlias. * teach bsnmpd to allocate memory dynamically for interface descriptions to decrease memory usage for common case and not to break if long description occurs; PR: 217763 Reviewed by: harti and others Differential Revision: https://reviews.freebsd.org/D16459 Changes: _U stable/10/ stable/10/contrib/bsnmp/snmp_mibII/mibII.c stable/10/contrib/bsnmp/snmp_mibII/mibII.h stable/10/contrib/bsnmp/snmp_mibII/mibII_interfaces.c stable/10/contrib/bsnmp/snmp_mibII/snmp_mibII.h