Bug 236664 - bsnmpget cannot open 'tc.def'
Summary: bsnmpget cannot open 'tc.def'
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Andrey V. Elsukov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-20 14:25 UTC by Olivier Cochard
Modified: 2019-05-01 09:06 UTC (History)
3 users (show)

See Also:


Attachments
Proposed patch (5.73 KB, patch)
2019-04-03 10:24 UTC, Andrey V. Elsukov
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Cochard freebsd_committer 2019-03-20 14:25:24 UTC
On a 12-RELEASE (same problem on 12-stable and -head), tc.def is not installed.

How to reproduce: Just generate an snmp request (no need to have a server running)

dev:~ % uname -a
FreeBSD dev.bsdrp.net 12.0-RELEASE-p3 FreeBSD 12.0-RELEASE-p3 GENERIC  amd64
dev:~ % bsnmpget -s 127.0.0.1 sysName.0
bsnmpget: cannot open 'tc.def'
bsnmpget: Snmp dialog: Operation timed out


Quick & Dirty fix:
cp /usr/src/contrib/bsnmp/lib/tc.def /usr/share/snmp/defs/


I didn't understand how the Makefile/install file process works to wrote a patch myself.
Comment 1 Ed Maste freebsd_committer 2019-04-01 13:09:24 UTC
tc.def arrived in r216594 "Bring in a SNMP module that allows configuration of SNMPv3 Notification targets."

which added in lib/libbsnmp/libbsnmp/Makefile:

+FILESGROUPS+=   DEFS
+DEFSDIR?=      ${SHAREDIR}/snmp/defs
+DEFS=          tc.def

and reverted in r216605 "Unbreak the build by temprorarily not using include directives"

-FILESGROUPS+=   DEFS
-DEFSDIR?=      ${SHAREDIR}/snmp/defs
-DEFS=          tc.def

r335885 "Update bsnmp to version 1.13" restored

+include "tc.def"

statements without addressing the build infrastructure
Comment 2 Andrey V. Elsukov freebsd_committer 2019-04-02 12:54:39 UTC
It seems I applied the similar patch in r345797.
Comment 3 Olivier Cochard freebsd_committer 2019-04-02 17:12:28 UTC
(In reply to Andrey V. Elsukov from comment #2)

I've just tried your commit: Do you know if the new error message ("Bad file descriptor") in place of "operation timed out" is a normal one ?
Because the previous message seems more useful.

Previous:

olivier@srv:~ % uname -a
FreeBSD netboot-f.oca.netflix.net 13.0-CURRENT FreeBSD 13.0-CURRENT r345549 GENERIC-NODEBUG  amd64
olivier@srv:~ % bsnmpget -s 127.0.0.1 sysName.0
bsnmpget: cannot open 'tc.def'
bsnmpget: Snmp dialog: Operation timed out


New:
olivier@srv:~ % uname -a
FreeBSD netboot-f.oca.netflix.net 13.0-CURRENT FreeBSD 13.0-CURRENT r345805 GENERIC-NODEBUG  amd64
olivier@srv:~ % bsnmpget -s 127.0.0.1 sysName.0
bsnmpget: Failed to open snmp session: Bad file descriptor
Comment 4 Andrey V. Elsukov freebsd_committer 2019-04-02 17:40:53 UTC
(In reply to Olivier Cochard from comment #3)
> New:
> olivier@srv:~ % uname -a
> FreeBSD netboot-f.oca.netflix.net 13.0-CURRENT FreeBSD 13.0-CURRENT r345805
> GENERIC-NODEBUG  amd64
> olivier@srv:~ % bsnmpget -s 127.0.0.1 sysName.0
> bsnmpget: Failed to open snmp session: Bad file descriptor

It seems now all parts of server specification string become required. I'll take a look at this.
Comment 5 Andrey V. Elsukov freebsd_committer 2019-04-03 10:24:41 UTC
Created attachment 203341 [details]
Proposed patch

Hi Olivier, can you try this patch?
I modified the parser code to be more smart and be able automatically fill needed fields if they were omitted.

Hari, can you take a look at this too?
Comment 6 Andrey V. Elsukov freebsd_committer 2019-04-03 11:20:10 UTC
With this patch you can able do:

# make -C lib/libbsnmp/
# make -C lib/libbsnmp/ install
# bsnmpget -s 127.1 sysName.0
sysName.0 = test15.yandex.net
# bsnmpget -s "udp::127.1" sysName.0
sysName.0 = test15.yandex.net
# bsnmpget -s "udp::public@127.1" sysName.0
sysName.0 = test15.yandex.net
# bsnmpget -s "udp::public@127.1:161" sysName.0
sysName.0 = test15.yandex.net
# bsnmpget -s "udp::[::1]" sysName.0
sysName.0 = test15.yandex.net
# bsnmpget -s "udp6::[::1]" sysName.0
sysName.0 = test15.yandex.net
# bsnmpget -s "[fe80::1%lo0]" sysName.0
sysName.0 = test15.yandex.net
...
Comment 7 Olivier Cochard freebsd_committer 2019-04-03 12:25:06 UTC
Patch tested and working great!
Comment 8 commit-hook freebsd_committer 2019-04-03 12:48:28 UTC
A commit references this bug:

Author: ae
Date: Wed Apr  3 12:47:49 UTC 2019
New revision: 345843
URL: https://svnweb.freebsd.org/changeset/base/345843

Log:
  Follow the declared behaviour that specifies server string format in
  bsnmpclient(3).

  snmp_parse_server() function accepts string where some fields can be
  omitted: [trans::][community@][server][:port]

  "trans" field can be "udp", "udp6", "dgram" and "stream".
  "community" can be empty string, if it is omitted, the default value
  will be used. For read_community it is "public", for write_comminity
  it is "private". "server" field can be hostname, IPv4 address or IPv6
  address. IPv6 address should be specified in brackets "[]".
  If port is omitted, the default value "snmp" will be used for "udp"
  and "udp6" transports. So, now for bsnmpget(1) and bsnmwalk(1) it is
  not required to specify all fields in argument of '-s' option. E.g.

    # bsnmpget -s 127.1 sysName.0
    # bsnmpget -s "udp::127.1" sysName.0
    # bsnmpget -s "udp::public@127.1" sysName.0
    # bsnmpget -s "udp::public@127.1:161" sysName.0
    # bsnmpget -s "udp::[::1]" sysName.0
    # bsnmpget -s "udp6::[::1]" sysName.0
    # bsnmpget -s "[fe80::1%lo0]" sysName.0

  PR:		236664
  Reported by:	olivier
  MFC after:	1 month

Changes:
  head/contrib/bsnmp/lib/snmpclient.c
Comment 9 commit-hook freebsd_committer 2019-05-01 09:06:18 UTC
A commit references this bug:

Author: ae
Date: Wed May  1 09:05:49 UTC 2019
New revision: 346988
URL: https://svnweb.freebsd.org/changeset/base/346988

Log:
  MFC r345843:
    Follow the declared behaviour that specifies server string format in
    bsnmpclient(3).

    snmp_parse_server() function accepts string where some fields can be
    omitted: [trans::][community@][server][:port]

    "trans" field can be "udp", "udp6", "dgram" and "stream".
    "community" can be empty string, if it is omitted, the default value
    will be used. For read_community it is "public", for write_comminity
    it is "private". "server" field can be hostname, IPv4 address or IPv6
    address. IPv6 address should be specified in brackets "[]".
    If port is omitted, the default value "snmp" will be used for "udp"
    and "udp6" transports. So, now for bsnmpget(1) and bsnmwalk(1) it is
    not required to specify all fields in argument of '-s' option. E.g.

      # bsnmpget -s 127.1 sysName.0
      # bsnmpget -s "udp::127.1" sysName.0
      # bsnmpget -s "udp::public@127.1" sysName.0
      # bsnmpget -s "udp::public@127.1:161" sysName.0
      # bsnmpget -s "udp::[::1]" sysName.0
      # bsnmpget -s "udp6::[::1]" sysName.0
      # bsnmpget -s "[fe80::1%lo0]" sysName.0

    PR:		236664
    Reported by:	olivier

Changes:
_U  stable/12/
  stable/12/contrib/bsnmp/lib/snmpclient.c