> Actually, this might not require any work. Ipv6Address is
> TEXTUAL-CONVENTION, which maps to OCTET_STR, which is 's' on the
> command line.
> Lo and behold, this works:
> 
> $ sudo snmptrap -M +$PWD -m all -v2c -c public fallout ''
> NOTIFICATION-TEST-MIB::demo-notif IF-MIB::linkUp s ::1
> $ echo $?
> 0
> $
> 
> I still think that there should be an extension via an RFC and/or
> net-snmp to add strictness to the data type, but there's nothing
> holding you back from trapping notifications.
> I'll create a patch to improve the documentation though.
> Thanks,
> -Garrett

Hi Garrett,
 
That's not going to work.  :(  If you look at the description of Ipv6Address it 
states that the value of the binary IPv6 address string must be in network byte 
order.  By using a type of "s" and a value of "::1" that's just sending a plain 
old ASCII string (and there is no conversion to network byte order).
 
I was able to figure out how to send an IPv6 address in the trap.
 
First I converted the ASCII ipv6 address string "2001:db8:85a3::8a2e:370:7334" 
to binary using inet_pton.  Then I printed out the hex equivalent, making sure 
that each of the 16 octets used two characters.  That resulted in 
"20010db885a3000000008a2e03707334".  In my custom MIB I added a trap argument 
of syntax InetAddressIPv6 (FROM INET-ADDRESS-MIB).  I didn't use Ipv6Address 
because that seems tied to IPV6-MIB, which has been discontinued.
 
I called snmptrap from the command line and the end of my command was "Ipv6Test 
x 20010db885a3000000008a2e03707334".  I used a type of "x" to indicate that I 
was passing a hex string.
 
My other machine running the snmptrapd server received a trap with an argument 
of "Ipv6Test = STRING: 2001:db8:85a3:0:0:8a2e:370:7334".
 
So it works!  I still feel that there should be a type for snmptrap that lets 
you pass in an IPv6 address of simply "2001:db8:85a3::8a2e:370:7334".  That 
would be consistent with what's allowed for IPv4.
 
BTW, in your example you used the linkUp trap, but that trap doesn't contain 
any IP address agruments!  Also, I'm not sure why you didn't get an error 
because you didn't specify what argument you were sending.  I get the error "s: 
Missing type/value for variable" when I try your command, which makes sense.  
You would need to pass "IF-MIB::linkUp argumentname s ::1".  (If linkUp 
supported an IP address as one of its arguments.)
 
I also got the pass-through support working, but it wasn't as "easy".
 
The problem is that pass-through scripts don't support a type that indicates a 
hex string is being used (like snmptrap allows you to do).  I took Dave's 
suggestion and tried to just pass the binary string value since a pass-through 
type of "string" seems to support octet strings.
 
When I did an snmpwalk I got the following for my test field:
 
Ipv6Test.0 = STRING: 2001:db8:85a3
 
That's only part of the address.  I believe the problem is that since it's 
binary data the 00 is being interpreted as a NULL by the fprintf I'm using to 
write to stdout.  I suppose I could have changed my code to use fwrite to send 
the binary data, but it would quickly get ugly trying to keep track of what 
OIDs were binary data and which ones were not in my custom MIB.  What I really 
needed was a way to continue to send all OID values as printable characters.  I 
needed a way to specify that I was sending hex data, which snmptrap allows you 
to do but pass-through scripts do not.  I actually ended up changing 
pass_persist.c and added a new type of "hex".  My pass through script sends 
"20010db885a3000000008a2e03707334", with a type of "hex".  My change to snmpd 
was to make use of snmp_hex_to_binary(), which is what snmptrap calls to 
translate the "x" type, when it receives this new type of "hex".  I store the 
binary value and mark the type as ASN_OCTET_STR.
 
After that my snmpwalk returned the full value:
 
Ipv6Test.0 = STRING: 2001:db8:85a3:0:0:8a2e:370:7334
 
Sorry for being long winded, but I wanted to outline how I solved this in case 
it would help you or others.                                       
------------------------------------------------------------------------------
10 Tips for Better Web Security
Learn 10 ways to better secure your business today. Topics covered include:
Web security, SSL, hacker attacks & Denial of Service (DoS), private keys,
security Microsoft Exchange, secure Instant Messaging, and much more.
http://www.accelacomm.com/jaw/sfnl/114/51426210/
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to