Bug 217763 - [patch] [bsnmpd] MIBIF_ALIAS_SIZE is too low breaking ifXTable
Summary: [patch] [bsnmpd] MIBIF_ALIAS_SIZE is too low breaking ifXTable
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.0-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: Eugene Grosbein
URL:
Keywords: patch-ready
Depends on:
Blocks:
 
Reported: 2017-03-13 17:02 UTC by Eugene Grosbein
Modified: 2018-08-25 10:43 UTC (History)
3 users (show)

See Also:
koobs: mfc-stable11+
eugen: mfc-stable10+


Attachments
make ifAlias dynamic (4.24 KB, patch)
2017-03-13 17:02 UTC, Eugene Grosbein
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eugene Grosbein freebsd_committer freebsd_triage 2017-03-13 17:02:15 UTC
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 */.
Comment 1 Eugene Grosbein freebsd_committer freebsd_triage 2017-05-11 12:46:48 UTC
Hi!

Just notifying you of awaiting PR. Would you like me to commit this myself?
Comment 2 Enji Cooper freebsd_committer freebsd_triage 2017-11-05 20:40:23 UTC
Untaking bsnmp bugs (haven't worked for Isilon for months and have no burning desire to use bsnmp anymore).
Comment 3 Eugene Grosbein freebsd_committer freebsd_triage 2017-11-06 08:24:37 UTC
My PR.
Comment 4 Eugene Grosbein freebsd_committer freebsd_triage 2018-07-26 14:46:41 UTC
Adding harti@ in attempt to get more attention to this.
Comment 5 commit-hook freebsd_committer freebsd_triage 2018-08-18 10:59:29 UTC
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
Comment 6 commit-hook freebsd_committer freebsd_triage 2018-08-25 09:49:12 UTC
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
Comment 7 commit-hook freebsd_committer freebsd_triage 2018-08-25 10:43:02 UTC
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