You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(14) |
Nov
(315) |
Dec
(298) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(254) |
Feb
(467) |
Mar
(430) |
Apr
(345) |
May
(406) |
Jun
(336) |
Jul
(313) |
Aug
(265) |
Sep
(433) |
Oct
(462) |
Nov
(387) |
Dec
(232) |
2002 |
Jan
(352) |
Feb
(556) |
Mar
(463) |
Apr
(500) |
May
(557) |
Jun
(337) |
Jul
(317) |
Aug
(279) |
Sep
(273) |
Oct
(354) |
Nov
(267) |
Dec
(347) |
2003 |
Jan
(351) |
Feb
(445) |
Mar
(520) |
Apr
(665) |
May
(499) |
Jun
(393) |
Jul
(304) |
Aug
(425) |
Sep
(262) |
Oct
(329) |
Nov
(220) |
Dec
(174) |
2004 |
Jan
(365) |
Feb
(479) |
Mar
(515) |
Apr
(522) |
May
(214) |
Jun
(471) |
Jul
(292) |
Aug
(341) |
Sep
(243) |
Oct
(446) |
Nov
(294) |
Dec
(147) |
2005 |
Jan
(171) |
Feb
(209) |
Mar
(218) |
Apr
(321) |
May
(233) |
Jun
(534) |
Jul
(268) |
Aug
(345) |
Sep
(498) |
Oct
(557) |
Nov
(459) |
Dec
(238) |
2006 |
Jan
(288) |
Feb
(180) |
Mar
(151) |
Apr
(113) |
May
(164) |
Jun
(277) |
Jul
(160) |
Aug
(383) |
Sep
(221) |
Oct
(404) |
Nov
(358) |
Dec
(163) |
2007 |
Jan
(293) |
Feb
(175) |
Mar
(202) |
Apr
(155) |
May
(427) |
Jun
(484) |
Jul
(414) |
Aug
(125) |
Sep
(131) |
Oct
(160) |
Nov
(79) |
Dec
(70) |
2008 |
Jan
(133) |
Feb
(115) |
Mar
(158) |
Apr
(194) |
May
(197) |
Jun
(230) |
Jul
(146) |
Aug
(68) |
Sep
(93) |
Oct
(53) |
Nov
(95) |
Dec
(69) |
2009 |
Jan
(81) |
Feb
(162) |
Mar
(215) |
Apr
(216) |
May
(78) |
Jun
(131) |
Jul
(61) |
Aug
(176) |
Sep
(127) |
Oct
(28) |
Nov
(83) |
Dec
(94) |
2010 |
Jan
(100) |
Feb
(187) |
Mar
(320) |
Apr
(161) |
May
(194) |
Jun
(142) |
Jul
(129) |
Aug
(139) |
Sep
(239) |
Oct
(202) |
Nov
(139) |
Dec
(196) |
2011 |
Jan
(195) |
Feb
(191) |
Mar
(201) |
Apr
(127) |
May
(84) |
Jun
(126) |
Jul
(101) |
Aug
(237) |
Sep
(123) |
Oct
(104) |
Nov
(197) |
Dec
(114) |
2012 |
Jan
(65) |
Feb
(85) |
Mar
(129) |
Apr
(84) |
May
(94) |
Jun
(83) |
Jul
(89) |
Aug
(85) |
Sep
(89) |
Oct
(73) |
Nov
(34) |
Dec
(38) |
2013 |
Jan
(89) |
Feb
(30) |
Mar
(25) |
Apr
(18) |
May
(20) |
Jun
(45) |
Jul
(74) |
Aug
(37) |
Sep
(72) |
Oct
(30) |
Nov
(67) |
Dec
(24) |
2014 |
Jan
(23) |
Feb
(16) |
Mar
(40) |
Apr
(37) |
May
(12) |
Jun
(18) |
Jul
(30) |
Aug
(26) |
Sep
(24) |
Oct
(32) |
Nov
(15) |
Dec
(33) |
2015 |
Jan
(15) |
Feb
(45) |
Mar
(21) |
Apr
(24) |
May
(22) |
Jun
(7) |
Jul
(57) |
Aug
(17) |
Sep
(16) |
Oct
(3) |
Nov
(8) |
Dec
(13) |
2016 |
Jan
(7) |
Feb
(14) |
Mar
(40) |
Apr
(8) |
May
(10) |
Jun
(6) |
Jul
(8) |
Aug
(10) |
Sep
(19) |
Oct
(20) |
Nov
(45) |
Dec
(10) |
2017 |
Jan
(10) |
Feb
(12) |
Mar
(3) |
Apr
(17) |
May
(41) |
Jun
(21) |
Jul
(13) |
Aug
(13) |
Sep
(7) |
Oct
(23) |
Nov
(10) |
Dec
(23) |
2018 |
Jan
(45) |
Feb
(3) |
Mar
(57) |
Apr
(107) |
May
(173) |
Jun
(47) |
Jul
(28) |
Aug
(26) |
Sep
(38) |
Oct
(56) |
Nov
(22) |
Dec
(11) |
2019 |
Jan
(37) |
Feb
(8) |
Mar
(7) |
Apr
(29) |
May
(32) |
Jun
(5) |
Jul
(21) |
Aug
(31) |
Sep
(38) |
Oct
(8) |
Nov
(13) |
Dec
(10) |
2020 |
Jan
(9) |
Feb
(33) |
Mar
(14) |
Apr
(4) |
May
(16) |
Jun
(11) |
Jul
(14) |
Aug
(50) |
Sep
(24) |
Oct
(3) |
Nov
(14) |
Dec
(13) |
2021 |
Jan
(18) |
Feb
(15) |
Mar
(12) |
Apr
(9) |
May
(9) |
Jun
(8) |
Jul
(6) |
Aug
(7) |
Sep
(26) |
Oct
(17) |
Nov
(6) |
Dec
(2) |
2022 |
Jan
(3) |
Feb
(11) |
Mar
(7) |
Apr
(15) |
May
(5) |
Jun
(4) |
Jul
(29) |
Aug
(6) |
Sep
(7) |
Oct
|
Nov
(4) |
Dec
(1) |
2023 |
Jan
|
Feb
|
Mar
|
Apr
(10) |
May
(3) |
Jun
(5) |
Jul
(3) |
Aug
(10) |
Sep
(10) |
Oct
(7) |
Nov
(2) |
Dec
(4) |
2024 |
Jan
(22) |
Feb
(5) |
Mar
(11) |
Apr
(20) |
May
(16) |
Jun
(9) |
Jul
(14) |
Aug
(5) |
Sep
(7) |
Oct
(4) |
Nov
(3) |
Dec
|
2025 |
Jan
(6) |
Feb
(6) |
Mar
(14) |
Apr
(2) |
May
|
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Bill F. <fe...@us...> - 2018-11-06 16:04:05
|
Hi Bart, My main question is, what's the advantage of storing the IPv4/IPv6 address as a string and a port number, instead of as a sockaddr_*? I.e., why use netsnmp_ep_str? Is the API change here ok? Are we assuming that nobody ever calls netsnmp_foo_transport() directly? Should there be an #ifdef in patch 5 to make the interface name optional, both in the struct and the parser, for platforms that don't support it? Is it better to return a parse error on the address that includes interface name, or a "failed to open socket" without much more information? Given your proposed code structure, I imagine that we could add network namespaces to netsnmp_ep too - this basically ends up using "socketat( /* magic */, family, type, protocol )" instead of socket() to create the socket, and the magic can be derived from what we store in ep. I don't have a strong opinion about which this code should go in. Bill On Sun, Oct 28, 2018 at 5:19 PM Bart Van Assche <bva...@ac...> wrote: > Hello, > > As you may have noticed multiple people asked to add SO_BINDTODEVICE > support > to Net-SNMP. This patch series adds such support by allowing to specify the > name of the network interface to bind a Net-SNMP endpoint to as > "@<interface name>". An example: > > agent/snmpd -Mmibs -f -Lo -c .../snmpd.conf udp6:localhost@lo:1161 -r > apps/snmpwalk -Mmibs -v2c -cpublic udp6:localhost:1161 .1 > > The reason I'm posting this patch series on the Net-SNMP mailing list is to > gather feedback about this patch series. Does everyone agree with the code > changes in this patch series? If so, on which branch(es) should these > patches > be applied? Master only or v5.8 and master? > > See also: > * Add SO_BINDTODEVICE support > (https://sourceforge.net/p/net-snmp/patches/1296/). > * Add Linux VRF support (https://sourceforge.net/p/net-snmp/patches/1376/ > ). > > Thanks, > > Bart. > > Bart Van Assche (6): > libsnmp/transports: Introduce netsnmp_parse_ep_str() > libsnmp/transports: Introduce netsnmp_sockaddr_in3() and > netsnmp_sockaddr_in6_3() > libsnmp/transports: Change multiple sockaddr_in* arguments into > netsnmp_ep > configure: Add a test for SO_BINDTODEVICE > libsnmp/transports: Add support for interface binding > testing/fulltests/unit-tests: Add netsnmp_parse_ep_str() unit test > > configure | 34 +++ > configure.d/config_os_misc4 | 15 ++ > include/net-snmp/library/snmpDTLSUDPDomain.h | 4 +- > include/net-snmp/library/snmpIPBaseDomain.h | 36 +++ > include/net-snmp/library/snmpIPv4BaseDomain.h | 7 + > include/net-snmp/library/snmpIPv6BaseDomain.h | 5 + > include/net-snmp/library/snmpTCPDomain.h | 4 +- > include/net-snmp/library/snmpTCPIPv6Domain.h | 4 +- > include/net-snmp/library/snmpUDPDomain.h | 8 +- > .../net-snmp/library/snmpUDPIPv4BaseDomain.h | 12 +- > include/net-snmp/library/snmpUDPIPv6Domain.h | 11 +- > .../net-snmp/library/snmpUDPsharedDomain.h | 6 +- > include/net-snmp/net-snmp-config.h.in | 3 + > snmplib/transports/snmpDTLSUDPDomain.c | 36 +-- > snmplib/transports/snmpIPBaseDomain.c | 114 +++++++++ > snmplib/transports/snmpIPv4BaseDomain.c | 118 +++------ > snmplib/transports/snmpIPv6BaseDomain.c | 238 ++++-------------- > snmplib/transports/snmpTCPDomain.c | 24 +- > snmplib/transports/snmpTCPIPv6Domain.c | 23 +- > snmplib/transports/snmpUDPDomain.c | 22 +- > snmplib/transports/snmpUDPIPv4BaseDomain.c | 58 +++-- > snmplib/transports/snmpUDPIPv6Domain.c | 70 +++--- > snmplib/transports/snmpUDPsharedDomain.c | 90 ++++--- > testing/fulltests/support/clib_build | 1 + > .../T022netsnmp_parse_ep_str_clib.c | 55 ++++ > win32/libsnmp/Makefile.in | 1 + > win32/libsnmp_dll/Makefile.in | 1 + > 27 files changed, 561 insertions(+), 439 deletions(-) > create mode 100644 include/net-snmp/library/snmpIPBaseDomain.h > create mode 100644 snmplib/transports/snmpIPBaseDomain.c > create mode 100644 > testing/fulltests/unit-tests/T022netsnmp_parse_ep_str_clib.c > > -- > 2.19.1 > > |
From: Bart V. A. <bva...@ac...> - 2018-11-03 01:22:24
|
Hello Sam, Thanks for having tested this code! Bart. On 11/2/18 9:53 AM, Sam Tannous wrote: > Hi Bart, > > I've merged/tested your patches and they work fine. I'm ok with '@' > as the separator and this is a much cleaner (not to mention more > portable and complete) > patch than mine. Thanks for doing this. > --Sam Tannous > > On Sun, Oct 28, 2018 at 5:19 PM Bart Van Assche <bva...@ac... > <mailto:bva...@ac...>> wrote: > > Hello, > > As you may have noticed multiple people asked to add SO_BINDTODEVICE > support > to Net-SNMP. This patch series adds such support by allowing to > specify the > name of the network interface to bind a Net-SNMP endpoint to as > "@<interface name>". An example: > > Thanks, > > Bart. > |
From: Sam T. <sta...@cu...> - 2018-11-02 17:21:48
|
Hi Bart, I've merged/tested your patches and they work fine. I'm ok with '@' as the separator and this is a much cleaner (not to mention more portable and complete) patch than mine. Thanks for doing this. --Sam Tannous On Sun, Oct 28, 2018 at 5:19 PM Bart Van Assche <bva...@ac...> wrote: > Hello, > > As you may have noticed multiple people asked to add SO_BINDTODEVICE > support > to Net-SNMP. This patch series adds such support by allowing to specify the > name of the network interface to bind a Net-SNMP endpoint to as > "@<interface name>". An example: > > Thanks, > > Bart. > > |
From: Mark C. <ma...@ma...> - 2018-11-01 15:09:39
|
I am having problems with getting proxying to work on net-snmp version 5.8 that I built for Windows 10. I followed the proxy guidelines at http://net-snmp.sourceforge.net/wiki/index.php/Snmpd_proxy and set up the attached snmpd.conf file where I am using test.net-snmp.org as the "switch" in the example. Note that I am proxying the entire tree of test.net-snmp.org to 1.4 as well as using context to proxy the entire tree, using the instructions in the proxy documentation page. Proxying the entire tree works as expected: C:\Users\markw>snmpgetnext -v 2c -c public localhost 1.4 iso.4.6.1.2.1.1.1.0 = STRING: "test.net-snmp.org" I attached proxy-entire-tree.txt for the snmpd debug output. Proxying using contexts does not work as expected: C:\Users\markw>snmpgetnext -v 2c -c cmty_myswitch localhost 1.3 Timeout: No Response from localhost. I attached proxy-using-context-mapping.txt for the snmpd debug output. Any ideas of what I'm doing wrong? Thanks. Mark. |
From: Pushpa T. <pus...@gm...> - 2018-10-31 05:21:28
|
Thank you Bart. I will check. Regards, Pushpa.T On Tue, Oct 30, 2018 at 10:34 AM Bart Van Assche <bva...@ac...> wrote: > On 10/29/18 9:34 PM, Pushpa Thimmaiah wrote: > > Thank you. I will verify. Does the patch works for IPv6 too? > > Oops, I had overlooked that your example uses an IPv6 client address. > Can you verify whether the following (untested) patch helps (checked > in yesterday on the v5.8 and master branches): > > commit 9b637efe809c490fdcaf30d1af20b4cbaef76e3e > Author: Bart Van Assche <bva...@ac...> > Date: Sat Oct 27 20:34:21 2018 -0700 > > libsnmp/transports: Fix netsnmp_udp6_transport() > > Only create a transport object if parsing the client address succeeded > instead of creating a transport object when parsing the client address > failed. > > Fixes: 5d8372341594 ("shared transport + udp shared domain") > > diff --git a/snmplib/transports/snmpUDPIPv6Domain.c > b/snmplib/transports/snmpUDPIPv6Domain.c > index 4d9f65eb9d19..7a3b1db15c67 100644 > --- a/snmplib/transports/snmpUDPIPv6Domain.c > +++ b/snmplib/transports/snmpUDPIPv6Domain.c > @@ -460,14 +460,16 @@ netsnmp_udp6_transport(const struct sockaddr_in6 > *addr, int local) > { > if (!local) { > const char *client_socket; > + > client_socket = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, > > NETSNMP_DS_LIB_CLIENT_ADDR); > if (client_socket) { > struct sockaddr_in6 client_addr; > - if(!netsnmp_sockaddr_in6_2(&client_addr, client_socket, > NULL)) { > - return netsnmp_udp6_transport_with_source(addr, local, > - &client_addr); > - } > + > + if (!netsnmp_sockaddr_in6_2(&client_addr, client_socket, > NULL)) > + return NULL; > + return netsnmp_udp6_transport_with_source(addr, local, > + &client_addr); > } > } > return netsnmp_udp6_transport_with_source(addr, local, NULL); > |
From: Denis H. <den...@gm...> - 2018-10-31 04:18:30
|
On Tue, Oct 30, 2018 at 11:31:59PM +0000, Roedersheimer, Drew A. wrote: > > From: Denis Hainsworth <den...@gm...> > > Sent: Tuesday, October 30, 2018 7:57 AM > > To: net...@li... > > Subject: EXTERNAL: Re: 5.7.3 | snmptrap not populating EngineBoots or EngineTime for snmp v3 traps > > > > Just a note to anyone that might run into this. I was interested in all the > > evidence that snmptrap/d used to process boots/time correctly for v3 and so built > > 5.1.4.2 and found that snmptrap in that version does in fact correctly set boots/time > > based on the -Z command line argument and if -Z is not used it does use uptime as coded. > > > > I also confirmed that snmptrapd from 5.1.4.2 actually checks those values while 5.7.3 > > does not which is probably why most people dont care because they are probably using both > > binaries so even if snmptrap isnt setting the values snmptrapd is ignoring them anyway so > > it just works. > > > > No clue yet when it broke or how easy it might be to fix. > > > > -denis > > > This interested me for selfish reasons, so I investigated it. It appears that the local cache > of SNMP engine ID/boot/time is not getting updated from the switches supplied at the command > line. When the message is sent out, there is no entry in the cache, so default values of 0 > are used. > > I have pinned down the regression to this commit: > > commit 0dd182f682b6f6cbb18b948718238750ca3404e4 > Author: Robert Story <rs...@us...> > Date: Thu Jun 2 23:14:07 2005 +0000 > > delay SNMPv3 EngineID probe until needed > > > > I have also tested a patch for this that seems to work. I'd be interested in the developers' > opinions, as I'm not sure this is the best location for the fix or if I missed something. > > Patch is against v5.8: > > diff -urN old-5.8/apps/snmptrap.c new-5.8/apps/snmptrap.c > --- old-5.8/apps/snmptrap.c 2018-07-16 09:33:40.000000000 -0500 > +++ new-5.8/apps/snmptrap.c 2018-10-30 18:25:26.652014237 -0500 > @@ -214,6 +214,9 @@ > session.engineBoots = 1; > if (session.engineTime == 0) /* not really correct, */ > session.engineTime = get_uptime(); /* but it'll work. Sort of. */ > + > + set_enginetime(session.securityEngineID, session.securityEngineIDLen, > + session.engineBoots, session.engineTime, TRUE); > } > > ss = snmp_add(&session, > > > > > Denis: can you easily test this patch with your system? Thanks Drew! Yeah it seems fix snmptrap which was my primary concern. -denis |
From: Roedersheimer, D. A. <Dre...@le...> - 2018-10-30 23:32:07
|
> From: Denis Hainsworth <den...@gm...> > Sent: Tuesday, October 30, 2018 7:57 AM > To: net...@li... > Subject: EXTERNAL: Re: 5.7.3 | snmptrap not populating EngineBoots or EngineTime for snmp v3 traps > > Just a note to anyone that might run into this. I was interested in all the > evidence that snmptrap/d used to process boots/time correctly for v3 and so built > 5.1.4.2 and found that snmptrap in that version does in fact correctly set boots/time > based on the -Z command line argument and if -Z is not used it does use uptime as coded. > > I also confirmed that snmptrapd from 5.1.4.2 actually checks those values while 5.7.3 > does not which is probably why most people dont care because they are probably using both > binaries so even if snmptrap isnt setting the values snmptrapd is ignoring them anyway so > it just works. > > No clue yet when it broke or how easy it might be to fix. > > -denis This interested me for selfish reasons, so I investigated it. It appears that the local cache of SNMP engine ID/boot/time is not getting updated from the switches supplied at the command line. When the message is sent out, there is no entry in the cache, so default values of 0 are used. I have pinned down the regression to this commit: commit 0dd182f682b6f6cbb18b948718238750ca3404e4 Author: Robert Story <rs...@us...> Date: Thu Jun 2 23:14:07 2005 +0000 delay SNMPv3 EngineID probe until needed I have also tested a patch for this that seems to work. I'd be interested in the developers' opinions, as I'm not sure this is the best location for the fix or if I missed something. Patch is against v5.8: diff -urN old-5.8/apps/snmptrap.c new-5.8/apps/snmptrap.c --- old-5.8/apps/snmptrap.c 2018-07-16 09:33:40.000000000 -0500 +++ new-5.8/apps/snmptrap.c 2018-10-30 18:25:26.652014237 -0500 @@ -214,6 +214,9 @@ session.engineBoots = 1; if (session.engineTime == 0) /* not really correct, */ session.engineTime = get_uptime(); /* but it'll work. Sort of. */ + + set_enginetime(session.securityEngineID, session.securityEngineIDLen, + session.engineBoots, session.engineTime, TRUE); } ss = snmp_add(&session, Denis: can you easily test this patch with your system? -Drew |
From: Denis H. <den...@gm...> - 2018-10-30 12:57:09
|
Just a note to anyone that might run into this. I was interested in all the evidence that snmptrap/d used to process boots/time correctly for v3 and so built 5.1.4.2 and found that snmptrap in that version does in fact correctly set boots/time based on the -Z command line argument and if -Z is not used it does use uptime as coded. I also confirmed that snmptrapd from 5.1.4.2 actually checks those values while 5.7.3 does not which is probably why most people dont care because they are probably using both binaries so even if snmptrap isnt setting the values snmptrapd is ignoring them anyway so it just works. No clue yet when it broke or how easy it might be to fix. -denis On Sat, Oct 27, 2018 at 04:06:49PM -0400, Denis Hainsworth wrote: > so i was hoping to use snmptrap to send snmp v3 traps because it is > simple and already written. However I have some NMS systems that are > pretty stringent about checking EngineBoots and EngineTime even for > traps (I'm not using Inform). So far the nms always reports "message > received outside time window" . Checking the snmp packets with tshark I > can see that both EngineBoots and EngineTime are always zero. > > Looking at the snmptrap code it looks like by default it should be > setting Boots to 1 and Time to "uptime" IF you don't pass specific > values via -V on the command line. Throwing in some printfs I can see > that the session struct is in fact populated with these values. > > I got lost following snmp_add and snmp_pdu_create but from what I can > tell the session attributes for Boots and Time are never actually used > to set the same in the raw pdu and thus all we get are zeros. > > Was curious if someone who knew the code better could confirm this is a > bug and not some obvious miss on my part. Given how snmptrap is > written I don't think it is supposed to get any data from a running > agent (I'm trying to avoid running one) or from the persistent snmp conf > files that other methods like agentx etc would use. > > I also skimmed through the mail archives and found what looked like > similar questions in the past but without anyone addressing why setting > the Boot and Time attributes via -V for snmptrap should not work. > > -denis > -- > __________________________ > Denis Alan Hainsworth > den...@gm... -- __________________________ Denis Alan Hainsworth den...@gm... |
From: Bart V. A. <bva...@ac...> - 2018-10-30 05:04:35
|
On 10/29/18 9:34 PM, Pushpa Thimmaiah wrote: > Thank you. I will verify. Does the patch works for IPv6 too? Oops, I had overlooked that your example uses an IPv6 client address. Can you verify whether the following (untested) patch helps (checked in yesterday on the v5.8 and master branches): commit 9b637efe809c490fdcaf30d1af20b4cbaef76e3e Author: Bart Van Assche <bva...@ac...> Date: Sat Oct 27 20:34:21 2018 -0700 libsnmp/transports: Fix netsnmp_udp6_transport() Only create a transport object if parsing the client address succeeded instead of creating a transport object when parsing the client address failed. Fixes: 5d8372341594 ("shared transport + udp shared domain") diff --git a/snmplib/transports/snmpUDPIPv6Domain.c b/snmplib/transports/snmpUDPIPv6Domain.c index 4d9f65eb9d19..7a3b1db15c67 100644 --- a/snmplib/transports/snmpUDPIPv6Domain.c +++ b/snmplib/transports/snmpUDPIPv6Domain.c @@ -460,14 +460,16 @@ netsnmp_udp6_transport(const struct sockaddr_in6 *addr, int local) { if (!local) { const char *client_socket; + client_socket = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_CLIENT_ADDR); if (client_socket) { struct sockaddr_in6 client_addr; - if(!netsnmp_sockaddr_in6_2(&client_addr, client_socket, NULL)) { - return netsnmp_udp6_transport_with_source(addr, local, - &client_addr); - } + + if (!netsnmp_sockaddr_in6_2(&client_addr, client_socket, NULL)) + return NULL; + return netsnmp_udp6_transport_with_source(addr, local, + &client_addr); } } return netsnmp_udp6_transport_with_source(addr, local, NULL); |
From: Pushpa T. <pus...@gm...> - 2018-10-30 04:34:39
|
Hi Bart, Thank you. I will verify. Does the patch works for IPv6 too? Regards, Pushpa. T On Tue, Oct 30, 2018 at 4:27 AM Bart Van Assche <bva...@ac...> wrote: > On Mon, 2018-10-29 at 09:52 +0530, Pushpa Thimmaiah wrote: > > Hi All, > I am using option 'clientAddr' with IPv6 address and noticed that it is > not working. > so I applied patch > https://sourceforge.net/p/net-snmp/mailman/message/33064273/ on 5.7.3 but > It seems not working. > Kindly let me know if I am missing any configurations. > > Eg: > linux machine has ipv6 '2002::2054' and sends trap using > 'clientAddr=2002::2056' > There is no IPv6 '2002::2056' and trap sent out via '2002::2054'. I have > expected it to fail when it doesnot find 2002::2056. > > *snmp trap sender:* > /home/# /tmp/snmptrap -Dall -v 3 *--clientAddr="2002::2056"* -n "" -u > testigmv6 -l authNoPriv -a MD5 -A mypassword -e 0x80001f880300b0a > e123548 udp6:[2002::2045]:162 "" .1.3.6.1.4.1.8072.2.3.1 > .1.3.6.1.4.1.8072.2.1.1 i 444 > /home# > > *Trap Receiver shows:* > usm: USM processing begun... > usm: match on user testigmv6 > usm: Verification succeeded. > usm: USM processing completed. > 2018-10-29 09:43:59 UDP/IPv6: [2002::2054]:50455 [UDP/IPv6: [*2002::2054* > ]:50455]: > DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (89119) 0:14:51.19 > SNMPv2-MIB::snmpTrapOID.0 = OID: > NET-SNMP-EXAMPLES-MIB::netSnmpExampleNotification > NET-SNMP-EXAMPLES-MIB::netSnmpExampleInteger = INTEGER: 444 > > > Please retest with the Net-SNMP master branch. That branch includes the > patch shown below. > > $ git branch --contains cc45578c2fa0b94f776 > > * master > > $ git show cc45578c2fa0b94f776 > > commit cc45578c2fa0b94f7762057ee3b8a0b795c497ff > > Author: Bill Fenner <fe...@gm...> > > Date: Sun May 6 13:05:55 2018 +0000 > > > snmpd: BUG: 2864: use clientaddr properly > > The code parsed out the address from the clientaddr spec, > > then used the return value wrong and only respected it > > if it existed but didn't parse properly. > > > diff --git a/snmplib/transports/snmpUDPIPv4BaseDomain.c b/snmplib/transports/snmpUDPIPv4BaseDomain.c > > index 37d8e33b47c7..433eb809bb91 100644 > > --- a/snmplib/transports/snmpUDPIPv4BaseDomain.c > > +++ b/snmplib/transports/snmpUDPIPv4BaseDomain.c > > @@ -367,7 +367,7 @@ netsnmp_udpipv4base_transport(const struct sockaddr_in *addr, int local) > > rc = netsnmp_sockaddr_in2(&client_addr, client_socket, NULL); > > if (client_address != client_socket) > > free(client_address); > > - if(!rc) { > > + if(rc) { > > if (!uses_port || !have_port) /* if port isn't from string, */ > > client_addr.sin_port = 0; /* ... clear it */ > > return netsnmp_udpipv4base_transport_with_source(addr, local, > > > Thanks, > > Bart. > > |
From: Bart V. A. <bva...@ac...> - 2018-10-29 22:57:07
|
On Mon, 2018-10-29 at 09:52 +0530, Pushpa Thimmaiah wrote: > Hi All, > I am using option 'clientAddr' with IPv6 address and noticed that it is not working. > so I applied patch https://sourceforge.net/p/net-snmp/mailman/message/33064273/ on 5.7.3 but It seems not working. > Kindly let me know if I am missing any configurations. > > Eg: > linux machine has ipv6 '2002::2054' and sends trap using 'clientAddr=2002::2056' > There is no IPv6 '2002::2056' and trap sent out via '2002::2054'. I have expected it to fail when it doesnot find 2002::2056. > > snmp trap sender: > /home/# /tmp/snmptrap -Dall -v 3 --clientAddr="2002::2056" -n "" -u testigmv6 -l authNoPriv -a MD5 -A mypassword -e 0x80001f880300b0a > e123548 udp6:[2002::2045]:162 "" .1.3.6.1.4.1.8072.2.3.1 .1.3.6.1.4.1.8072.2.1.1 i 444 > /home# > > Trap Receiver shows: > usm: USM processing begun... > usm: match on user testigmv6 > usm: Verification succeeded. > usm: USM processing completed. > 2018-10-29 09:43:59 UDP/IPv6: [2002::2054]:50455 [UDP/IPv6: [2002::2054]:50455]: > DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (89119) 0:14:51.19 SNMPv2-MIB::snmpTrapOID.0 = OID: NET-SNMP-EXAMPLES-MIB::netSnmpExampleNotification NET-SNMP-EXAMPLES- > MIB::netSnmpExampleInteger = INTEGER: 444 Please retest with the Net-SNMP master branch. That branch includes the patch shown below. $ git branch --contains cc45578c2fa0b94f776* master $ git show cc45578c2fa0b94f776commit cc45578c2fa0b94f7762057ee3b8a0b795c497ffAuthor: Bill Fenner <fe...@gm...>Date: Sun May 6 13:05:55 2018 +0000 snmpd: BUG: 2864: use clientaddr properly The code parsed out the address from the clientaddr spec, then used the return value wrong and only respected it if it existed but didn't parse properly. diff --git a/snmplib/transports/snmpUDPIPv4BaseDomain.c b/snmplib/transports/snmpUDPIPv4BaseDomain.cindex 37d8e33b47c7..433eb809bb91 100644--- a/snmplib/transports/snmpUDPIPv4BaseDomain.c+++ b/snmplib/transports/snmpUDPIPv4BaseDomain.c@@ -367,7 +367,7 @@ netsnmp_udpipv4base_transport(const struct sockaddr_in *addr, int local) rc = netsnmp_sockaddr_in2(&client_addr, client_socket, NULL); if (client_address != client_socket) free(client_address);- if(!rc) {+ if(rc) { if (!uses_port || !have_port) /* if port isn't from string, */ client_addr.sin_port = 0; /* ... clear it */ return netsnmp_udpipv4base_transport_with_source(addr, local, Thanks, Bart. |
From: Mark C. <ma...@ma...> - 2018-10-29 13:34:29
|
On Sun, Oct 28, 2018 at 7:30 PM Bart Van Assche <bva...@ac...> wrote: > On 10/23/18 6:00 AM, Mark Christiansen wrote: > > Does anybody have ideas of what could be going wrong here? > > > > I built net-SNMP 5.8 for my Windows 10 machine. I set up my snmpd.conf > > file as shown below where I added the same users as I have on my > > Linux machine called aurelius. I get the following responses when I run > > snmpgetnext for the two servers: > > > > C:\Users\markw>snmpgetnext -v 3 -l authPriv -u user3 -a MD5 -A > > user3password -x DES -X user3encryption aurelius .1.3 > > SNMPv2-MIB::sysDescr.0 = STRING: Linux aurelius 3.13.0-40-generic > > #69-Ubuntu SMP Thu Nov 13 17:56:26 UTC 2014 i686 > > > > C:\Users\markw>snmpgetnext -v 3 -l authPriv -u user3 -a MD5 -A > > user3password -x DES -X user3encryption localhost .1.3 > > snmpgetnext: Decryption error > > The behavior of the encryption code should be consistent on Windows and > Linux, at least if both have been compiled with the same encryption > support (OpenSSL or internal). Adding appropriate debug flags at the > agent and client side will probably provide a better insight in what's > going on. Flags that probably will yield interesting information are -d > and -D > > netsnmp_udp_parse_security,netsnmp_udp6_parse_security,netsnmp_unix_parse_security,tls,tsm. > > Thanks, Bart. Okay, I ran the following on my Linux box using net-snmp version 5.7.2 for a baseline of what I can expect to happen. markwc@aurelius ~$ snmpgetnext -v 2c -u user1 -c public localhost .1.3 iso.3.6.1.2.1.1.1.0 = STRING: "Linux aurelius 3.13.0-40-generic #69-Ubuntu SMP Thu Nov 13 17:56:26 UTC 2014 i686" markwc@aurelius ~$ snmpgetnext -v 3 -l auth -u user2 -a MD5 -A user2password localhost .1.3 iso.3.6.1.2.1.1.1.0 = STRING: "Linux aurelius 3.13.0-40-generic #69-Ubuntu SMP Thu Nov 13 17:56:26 UTC 2014 i686" markwc@aurelius ~$ snmpgetnext -v 3 -l authPriv -u user3 -a MD5 -A user3password -x DES -X user3encryption localhost .1.3 iso.3.6.1.2.1.1.1.0 = STRING: "Linux aurelius 3.13.0-40-generic #69-Ubuntu SMP Thu Nov 13 17:56:26 UTC 2014 i686" Then I ran the following on my Windows box with my 5.8 that I built to access my Linux box. C:\Users\markw>snmpgetnext -v 2c -c public -u user1 aurelius .1.3 SNMPv2-MIB::sysDescr.0 = STRING: Linux aurelius 3.13.0-40-generic #69-Ubuntu SMP Thu Nov 13 17:56:26 UTC 2014 i686 C:\Users\markw>snmpgetnext -v 3 -l auth -u user2 -a MD5 -A user2password aurelius .1.3 SNMPv2-MIB::sysDescr.0 = STRING: Linux aurelius 3.13.0-40-generic #69-Ubuntu SMP Thu Nov 13 17:56:26 UTC 2014 i686 C:\Users\markw>snmpgetnext -v 3 -l authPriv -u user3 -a MD5 -A user3password -x DES -X user3encryption aurelius .1.3 SNMPv2-MIB::sysDescr.0 = STRING: Linux aurelius 3.13.0-40-generic #69-Ubuntu SMP Thu Nov 13 17:56:26 UTC 2014 i686 Finally I ran the following on my Windows box to access the local server: C:\Users\markw>snmpgetnext -v 2c -c public -u user1 localhost .1.3 SNMPv2-MIB::sysDescr.0 = STRING: Windows DESKTOP-6FJOPTT 10.0.17134 Windows 10 Enterprise Intel64 Family 6 Model 26 Stepping 4 C:\Users\markw>snmpgetnext -v 3 -l auth -u user2 -a MD5 -A user2password localhost .1.3 SNMPv2-MIB::sysDescr.0 = STRING: Windows DESKTOP-6FJOPTT 10.0.17134 Windows 10 Enterprise Intel64 Family 6 Model 26 Stepping 4 C:\Users\markw>snmpgetnext -v 3 -l authPriv -u user3 -a MD5 -A user3password -x DES -X user3encryption localhost .1.3 snmpgetnext: Decryption error The attached file contains the output of snmpd for the Windows box calls to snmpgetnext using the debug options you gave me. I do not know expected debug outputs. Do we have a guide for that or is there something you can tell me by looking at the output? Also, how can I know for sure if I built it to use OpenSSL? Does the fact that that snmpgetnext works for the version 3 SNMP when talking to the Linux box indicate that? Thanks. Mark. |
From: Pushpa T. <pus...@gm...> - 2018-10-29 04:22:50
|
Hi All, I am using option 'clientAddr' with IPv6 address and noticed that it is not working. so I applied patch https://sourceforge.net/p/net-snmp/mailman/message/33064273/ on 5.7.3 but It seems not working. Kindly let me know if I am missing any configurations. Eg: linux machine has ipv6 '2002::2054' and sends trap using 'clientAddr=2002::2056' There is no IPv6 '2002::2056' and trap sent out via '2002::2054'. I have expected it to fail when it doesnot find 2002::2056. *snmp trap sender:* /home/# /tmp/snmptrap -Dall -v 3 *--clientAddr="2002::2056"* -n "" -u testigmv6 -l authNoPriv -a MD5 -A mypassword -e 0x80001f880300b0a e123548 udp6:[2002::2045]:162 "" .1.3.6.1.4.1.8072.2.3.1 .1.3.6.1.4.1.8072.2.1.1 i 444 /home# *Trap Receiver shows:* usm: USM processing begun... usm: match on user testigmv6 usm: Verification succeeded. usm: USM processing completed. 2018-10-29 09:43:59 UDP/IPv6: [2002::2054]:50455 [UDP/IPv6: [*2002::2054* ]:50455]: DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (89119) 0:14:51.19 SNMPv2-MIB::snmpTrapOID.0 = OID: NET-SNMP-EXAMPLES-MIB::netSnmpExampleNotification NET-SNMP-EXAMPLES-MIB::netSnmpExampleInteger = INTEGER: 444 Thank you, Pushpa T |
From: Bart V. A. <bva...@ac...> - 2018-10-29 01:30:24
|
On 10/23/18 6:00 AM, Mark Christiansen wrote: > Does anybody have ideas of what could be going wrong here? > > I built net-SNMP 5.8 for my Windows 10 machine. I set up my snmpd.conf > file as shown below where I added the same users as I have on my > Linux machine called aurelius. I get the following responses when I run > snmpgetnext for the two servers: > > C:\Users\markw>snmpgetnext -v 3 -l authPriv -u user3 -a MD5 -A > user3password -x DES -X user3encryption aurelius .1.3 > SNMPv2-MIB::sysDescr.0 = STRING: Linux aurelius 3.13.0-40-generic > #69-Ubuntu SMP Thu Nov 13 17:56:26 UTC 2014 i686 > > C:\Users\markw>snmpgetnext -v 3 -l authPriv -u user3 -a MD5 -A > user3password -x DES -X user3encryption localhost .1.3 > snmpgetnext: Decryption error The behavior of the encryption code should be consistent on Windows and Linux, at least if both have been compiled with the same encryption support (OpenSSL or internal). Adding appropriate debug flags at the agent and client side will probably provide a better insight in what's going on. Flags that probably will yield interesting information are -d and -D netsnmp_udp_parse_security,netsnmp_udp6_parse_security,netsnmp_unix_parse_security,tls,tsm. Bart. |
From: Mark C. <ma...@ma...> - 2018-10-28 21:36:39
|
It would be really nice to get an answer to my question that I posted last Tuesday. I've compiled net-snmp for windows configured to use openSSL. My version 3 access to my remote server aurelius works but it doesn't work with my local server. What have I done wrong in building net-snmp for windows or what am I doing wrong in my snmpd configuration? Thanks. Mark. On Tue, Oct 23, 2018 at 7:00 AM Mark Christiansen <ma...@ma...> wrote: > Does anybody have ideas of what could be going wrong here? > > I built net-SNMP 5.8 for my Windows 10 machine. I set up my snmpd.conf > file as shown below where I added the same users as I have on my > Linux machine called aurelius. I get the following responses when I run > snmpgetnext for the two servers: > > C:\Users\markw>snmpgetnext -v 3 -l authPriv -u user3 -a MD5 -A > user3password -x DES -X user3encryption aurelius .1.3 > SNMPv2-MIB::sysDescr.0 = STRING: Linux aurelius 3.13.0-40-generic > #69-Ubuntu SMP Thu Nov 13 17:56:26 UTC 2014 i686 > > C:\Users\markw>snmpgetnext -v 3 -l authPriv -u user3 -a MD5 -A > user3password -x DES -X user3encryption localhost .1.3 > snmpgetnext: Decryption error > > Thanks. > Mark. > > ########################################################################### > # > # snmpd.conf > # > # - created by the snmpconf configuration program > # > ########################################################################### > # SECTION: Access Control Setup > # > # This section defines who is allowed to talk to your running > # snmp agent. > > # rwuser: a SNMPv3 read-write user > # arguments: user [noauth|auth|priv] [restriction_oid] > > rwuser private > > # rouser: a SNMPv3 read-only user > # arguments: user [noauth|auth|priv] [restriction_oid] > > rouser public > > # rocommunity: a SNMPv1/SNMPv2c read-only access community name > # arguments: community [default|hostname|network/bits] [oid] > > rocommunity public > > # rwcommunity: a SNMPv1/SNMPv2c read-write access community name > # arguments: community [default|hostname|network/bits] [oid] > > rwcommunity private > > ########################################################################### > # Same user configuration I have on aurelius > ########################################################################### > > createUser user1 > createUser user2 MD5 user2password > createUser user3 MD5 user3password DES user3encryption > > rouser user1 noauth 1.3.6.1.2.1.1 > rouser user2 auth 1.3.6.1.2.1 > rwuser user3 priv 1.3.6.1.2.1 > > > -- Aim for brevity while avoiding jargon. ~ Edsger Dijkstra <https://about.me/markwc?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=gmail_api> Mark Christiansen about.me/markwc <https://about.me/markwc?promo=email_sig&utm_source=product&utm_medium=email_sig&utm_campaign=gmail_api> |
From: Bart V. A. <bva...@ac...> - 2018-10-28 21:31:22
|
Introduce functions for converting Net-SNMP endpoint definitions into struct netsnmp_ep. Calls to these functions will be added in a later patch. --- include/net-snmp/library/snmpIPBaseDomain.h | 18 +++++++++++ include/net-snmp/library/snmpIPv4BaseDomain.h | 5 +++ include/net-snmp/library/snmpIPv6BaseDomain.h | 3 ++ snmplib/transports/snmpIPv4BaseDomain.c | 26 ++++++++++++--- snmplib/transports/snmpIPv6BaseDomain.c | 32 +++++++++++++------ 5 files changed, 70 insertions(+), 14 deletions(-) diff --git a/include/net-snmp/library/snmpIPBaseDomain.h b/include/net-snmp/library/snmpIPBaseDomain.h index fb79a9365c4e..6eaf37ac4253 100644 --- a/include/net-snmp/library/snmpIPBaseDomain.h +++ b/include/net-snmp/library/snmpIPBaseDomain.h @@ -1,6 +1,24 @@ #ifndef _SNMPIPBASEDOMAIN_H_ #define _SNMPIPBASEDOMAIN_H_ +#include <net-snmp/types.h> + +/** + * SNMP endpoint specification. + * @a: Address family, network address and port number. + * @iface: Network interface name in ASCII format. May be empty. + */ +struct netsnmp_ep { + union { + struct sockaddr_in sin; +#if defined(NETSNMP_TRANSPORT_UDPIPV6_DOMAIN) || \ + defined(NETSNMP_TRANSPORT_TCPIPV6_DOMAIN) + struct sockaddr_in6 sin6; +#endif + } a; + char iface[16]; +}; + /** * SNMP endpoint with the network name in ASCII format. * @addr: Network address or host name as an ASCII string. diff --git a/include/net-snmp/library/snmpIPv4BaseDomain.h b/include/net-snmp/library/snmpIPv4BaseDomain.h index 71804e3b1d72..536bf5bfe3d6 100644 --- a/include/net-snmp/library/snmpIPv4BaseDomain.h +++ b/include/net-snmp/library/snmpIPv4BaseDomain.h @@ -15,6 +15,8 @@ config_require(IPBase) extern "C" { #endif + struct netsnmp_ep; + /* * Prototypes */ @@ -36,6 +38,9 @@ extern "C" { int remote_port); int netsnmp_sockaddr_in2(struct sockaddr_in *addr, const char *inpeername, const char *default_target); + int + netsnmp_sockaddr_in3(struct netsnmp_ep *ep, + const char *inpeername, const char *default_target); #ifdef __cplusplus } diff --git a/include/net-snmp/library/snmpIPv6BaseDomain.h b/include/net-snmp/library/snmpIPv6BaseDomain.h index 2f44e6a1b088..ac4c84ebe1af 100644 --- a/include/net-snmp/library/snmpIPv6BaseDomain.h +++ b/include/net-snmp/library/snmpIPv6BaseDomain.h @@ -30,6 +30,9 @@ extern "C" { const char *default_target); int netsnmp_sockaddr_in6(struct sockaddr_in6 *addr, const char *inpeername, int remote_port); + int + netsnmp_sockaddr_in6_3(struct netsnmp_ep *ep, + const char *inpeername, const char *default_target); #ifdef __cplusplus } diff --git a/snmplib/transports/snmpIPv4BaseDomain.c b/snmplib/transports/snmpIPv4BaseDomain.c index 003e53a49e45..d8537fbdc912 100644 --- a/snmplib/transports/snmpIPv4BaseDomain.c +++ b/snmplib/transports/snmpIPv4BaseDomain.c @@ -57,19 +57,34 @@ int netsnmp_sockaddr_in2(struct sockaddr_in *addr, const char *inpeername, const char *default_target) { + struct netsnmp_ep ep; + int ret; + + ret = netsnmp_sockaddr_in3(&ep, inpeername, default_target); + if (ret == 0) + return 0; + *addr = ep.a.sin; + return ret; +} + +int +netsnmp_sockaddr_in3(struct netsnmp_ep *ep, + const char *inpeername, const char *default_target) +{ + struct sockaddr_in *addr = &ep->a.sin; struct netsnmp_ep_str ep_str; int ret; - if (addr == NULL) { + if (ep == NULL) { return 0; } DEBUGMSGTL(("netsnmp_sockaddr_in", "addr %p, inpeername \"%s\", default_target \"%s\"\n", - addr, inpeername ? inpeername : "[NIL]", + ep, inpeername ? inpeername : "[NIL]", default_target ? default_target : "[NIL]")); - memset(addr, 0, sizeof(struct sockaddr_in)); + memset(ep, 0, sizeof(*ep)); addr->sin_addr.s_addr = htonl(INADDR_ANY); addr->sin_family = AF_INET; addr->sin_port = htons((u_short)SNMP_PORT); @@ -82,8 +97,9 @@ netsnmp_sockaddr_in2(struct sockaddr_in *addr, if (port != 0) { ep_str.port = port; } else if (default_target != NULL) { - netsnmp_sockaddr_in2(addr, default_target, NULL); - strlcpy(ep_str.addr, inet_ntoa(addr->sin_addr), sizeof(ep_str.addr)); + netsnmp_sockaddr_in3(ep, default_target, NULL); + strlcpy(ep_str.addr, inet_ntoa(addr->sin_addr), + sizeof(ep_str.addr)); ep_str.port = ntohs(addr->sin_port); } } diff --git a/snmplib/transports/snmpIPv6BaseDomain.c b/snmplib/transports/snmpIPv6BaseDomain.c index 600bc602428b..8e2fb8c86dd3 100644 --- a/snmplib/transports/snmpIPv6BaseDomain.c +++ b/snmplib/transports/snmpIPv6BaseDomain.c @@ -248,18 +248,33 @@ int netsnmp_sockaddr_in6_2(struct sockaddr_in6 *addr, const char *inpeername, const char *default_target) { + struct netsnmp_ep ai; + int ret; + + ret = netsnmp_sockaddr_in6_3(&ai, inpeername, default_target); + if (ret == 0) + return 0; + *addr = ai.a.sin6; + return ret; +} + +int +netsnmp_sockaddr_in6_3(struct netsnmp_ep *ep, + const char *inpeername, const char *default_target) +{ + struct sockaddr_in6 *addr = &ep->a.sin6; char debug_addr[INET6_ADDRSTRLEN]; - if (addr == NULL) { + if (ep == NULL) { return 0; } - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", - "addr %p, peername \"%s\", default_target \"%s\"\n", - addr, inpeername ? inpeername : "[NIL]", + DEBUGMSGTL(("netsnmp_sockaddr_in6", + "ep %p, peername \"%s\", default_target \"%s\"\n", + ep, inpeername ? inpeername : "[NIL]", default_target ? default_target : "[NIL]")); - memset(addr, 0, sizeof(struct sockaddr_in6)); + memset(ep, 0, sizeof(*ep)); addr->sin6_family = AF_INET6; addr->sin6_addr = in6addr_any; addr->sin6_port = htons((u_short)SNMP_PORT); @@ -270,7 +285,7 @@ netsnmp_sockaddr_in6_2(struct sockaddr_in6 *addr, if (port != 0) addr->sin6_port = htons((u_short)port); else if (default_target != NULL) - netsnmp_sockaddr_in6_2(addr, default_target, NULL); + netsnmp_sockaddr_in6_3(ep, default_target, NULL); } if (inpeername != NULL) { @@ -297,13 +312,12 @@ netsnmp_sockaddr_in6_2(struct sockaddr_in6 *addr, if (ep_str.port) addr->sin6_port = htons(ep_str.port); } - } else { - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", "NULL peername")); + DEBUGMSGTL(("netsnmp_sockaddr_in6", "NULL peername")); return 0; } - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", "return { AF_INET6, [%s]:%hu }\n", + DEBUGMSGTL(("netsnmp_sockaddr_in6", "return { AF_INET6, [%s]:%hu }\n", inet_ntop(AF_INET6, &addr->sin6_addr, debug_addr, sizeof(debug_addr)), ntohs(addr->sin6_port))); return 1; -- 2.19.1 |
From: Bart V. A. <bva...@ac...> - 2018-10-28 21:25:12
|
Make this change for all internal transport functions that will need the network interface information. This patch does not change any functionality. --- include/net-snmp/library/snmpDTLSUDPDomain.h | 4 +- include/net-snmp/library/snmpTCPDomain.h | 4 +- include/net-snmp/library/snmpTCPIPv6Domain.h | 4 +- include/net-snmp/library/snmpUDPDomain.h | 8 +- .../net-snmp/library/snmpUDPIPv4BaseDomain.h | 12 +-- include/net-snmp/library/snmpUDPIPv6Domain.h | 11 +-- .../net-snmp/library/snmpUDPsharedDomain.h | 6 +- snmplib/transports/snmpDTLSUDPDomain.c | 36 ++++---- snmplib/transports/snmpIPv6BaseDomain.c | 6 +- snmplib/transports/snmpTCPDomain.c | 17 ++-- snmplib/transports/snmpTCPIPv6Domain.c | 17 ++-- snmplib/transports/snmpUDPDomain.c | 22 ++--- snmplib/transports/snmpUDPIPv4BaseDomain.c | 45 ++++++---- snmplib/transports/snmpUDPIPv6Domain.c | 57 ++++++------ snmplib/transports/snmpUDPsharedDomain.c | 90 +++++++++---------- 15 files changed, 177 insertions(+), 162 deletions(-) diff --git a/include/net-snmp/library/snmpDTLSUDPDomain.h b/include/net-snmp/library/snmpDTLSUDPDomain.h index 97c5d58f31a2..5a60eeea0c22 100644 --- a/include/net-snmp/library/snmpDTLSUDPDomain.h +++ b/include/net-snmp/library/snmpDTLSUDPDomain.h @@ -19,8 +19,8 @@ extern "C" { NETSNMP_IMPORT oid netsnmpDTLSUDPDomain[7]; NETSNMP_IMPORT size_t netsnmpDTLSUDPDomain_len; -netsnmp_transport *netsnmp_dtlsudp_transport(const struct sockaddr_in *addr, - int local); +netsnmp_transport * +netsnmp_dtlsudp_transport(const struct netsnmp_ep *ep, int local); /* diff --git a/include/net-snmp/library/snmpTCPDomain.h b/include/net-snmp/library/snmpTCPDomain.h index 44c62e6994d4..a7bf42e56463 100644 --- a/include/net-snmp/library/snmpTCPDomain.h +++ b/include/net-snmp/library/snmpTCPDomain.h @@ -25,8 +25,8 @@ extern "C" { #define TRANSPORT_DOMAIN_TCP_IP 1,3,6,1,2,1,100,1,5 NETSNMP_IMPORT oid netsnmp_snmpTCPDomain[]; -netsnmp_transport *netsnmp_tcp_transport(const struct sockaddr_in *addr, - int local); +netsnmp_transport * +netsnmp_tcp_transport(const struct netsnmp_ep *ep, int local); /* * "Constructor" for transport domain object. diff --git a/include/net-snmp/library/snmpTCPIPv6Domain.h b/include/net-snmp/library/snmpTCPIPv6Domain.h index 5499900314df..afab8e084029 100644 --- a/include/net-snmp/library/snmpTCPIPv6Domain.h +++ b/include/net-snmp/library/snmpTCPIPv6Domain.h @@ -23,8 +23,8 @@ extern "C" { #define TRANSPORT_DOMAIN_TCP_IPV6 1,3,6,1,2,1,100,1,6 NETSNMP_IMPORT oid netsnmp_TCPIPv6Domain[]; -netsnmp_transport *netsnmp_tcp6_transport(const struct sockaddr_in6 *addr, - int local); +netsnmp_transport * +netsnmp_tcp6_transport(const struct netsnmp_ep *ep, int local); /* * "Constructor" for transport domain object. diff --git a/include/net-snmp/library/snmpUDPDomain.h b/include/net-snmp/library/snmpUDPDomain.h index 9cd203aa8f7c..5cc8b68b6f88 100644 --- a/include/net-snmp/library/snmpUDPDomain.h +++ b/include/net-snmp/library/snmpUDPDomain.h @@ -24,14 +24,14 @@ extern "C" { config_require(UDPIPv4Base) #include <net-snmp/library/snmpUDPIPv4BaseDomain.h> -netsnmp_transport *netsnmp_udp_transport(const struct sockaddr_in *addr, - int local); +netsnmp_transport * +netsnmp_udp_transport(const struct netsnmp_ep *ep, int local); netsnmp_transport *netsnmp_udp_create_tspec(netsnmp_tdomain_spec *tspec); netsnmp_transport * -netsnmp_udp_transport_with_source(const struct sockaddr_in *addr, int local, - const struct sockaddr_in *src_addr); +netsnmp_udp_transport_with_source(const struct netsnmp_ep *ep, int local, + const struct netsnmp_ep *src_addr); #define C2SE_ERR_SUCCESS 0 #define C2SE_ERR_MISSING_ARG -1 diff --git a/include/net-snmp/library/snmpUDPIPv4BaseDomain.h b/include/net-snmp/library/snmpUDPIPv4BaseDomain.h index 60bd3218303c..ff6e16362562 100644 --- a/include/net-snmp/library/snmpUDPIPv4BaseDomain.h +++ b/include/net-snmp/library/snmpUDPIPv4BaseDomain.h @@ -29,20 +29,20 @@ extern "C" { * Prototypes */ - netsnmp_transport *netsnmp_udpipv4base_transport(const struct sockaddr_in *addr, - int local); + netsnmp_transport * + netsnmp_udpipv4base_transport(const struct netsnmp_ep *ep, int local); netsnmp_transport * - netsnmp_udpipv4base_transport_with_source(const struct sockaddr_in *addr, + netsnmp_udpipv4base_transport_with_source(const struct netsnmp_ep *ep, int local, - const struct sockaddr_in *src_addr); + const struct netsnmp_ep *src_addr); netsnmp_transport * netsnmp_udpipv4base_tspec_transport(netsnmp_tdomain_spec *tspec); /** internal functions for derivatives of udpipv4base */ netsnmp_transport * - netsnmp_udpipv4base_transport_init(const struct sockaddr_in *addr, + netsnmp_udpipv4base_transport_init(const struct netsnmp_ep *ep, int local); int @@ -50,7 +50,7 @@ extern "C" { int netsnmp_udpipv4base_transport_bind(netsnmp_transport *t, - const struct sockaddr_in *addr, + const struct netsnmp_ep *ep, int flags); void diff --git a/include/net-snmp/library/snmpUDPIPv6Domain.h b/include/net-snmp/library/snmpUDPIPv6Domain.h index 39ed0df796f7..883bfdbd8f47 100644 --- a/include/net-snmp/library/snmpUDPIPv6Domain.h +++ b/include/net-snmp/library/snmpUDPIPv6Domain.h @@ -29,24 +29,25 @@ config_require(UDPBase) #define TRANSPORT_DOMAIN_UDP_IPV6 1,3,6,1,2,1,100,1,2 NETSNMP_IMPORT oid netsnmp_UDPIPv6Domain[]; -netsnmp_transport *netsnmp_udp6_transport(const struct sockaddr_in6 *addr, +netsnmp_transport *netsnmp_udp6_transport(const struct netsnmp_ep *ep, int local); netsnmp_transport * -netsnmp_udp6_transport_with_source(const struct sockaddr_in6 *addr, int local, - const struct sockaddr_in6 *src_addr); +netsnmp_udp6_transport_with_source(const struct netsnmp_ep *ep, int local, + const struct netsnmp_ep *src_addr); /** internal functions for derivatives of udpipv6 */ netsnmp_transport * - netsnmp_udp6_transport_init(const struct sockaddr_in6 *addr, int local); + netsnmp_udp6_transport_init(const struct netsnmp_ep *ep, int local); int netsnmp_udp6_transport_socket(int flags); int netsnmp_udp6_transport_bind(netsnmp_transport *t, - const struct sockaddr_in6 *addr, int flags); + const struct netsnmp_ep *ep, + int flags); void netsnmp_udp6_transport_get_bound_addr(netsnmp_transport *t); diff --git a/include/net-snmp/library/snmpUDPsharedDomain.h b/include/net-snmp/library/snmpUDPsharedDomain.h index 3a57ca5e0be7..3df9c9a24925 100644 --- a/include/net-snmp/library/snmpUDPsharedDomain.h +++ b/include/net-snmp/library/snmpUDPsharedDomain.h @@ -33,13 +33,13 @@ extern "C" { */ void netsnmp_udpshared_ctor(void); - netsnmp_transport *netsnmp_udpshared_transport(const struct sockaddr_in *addr, + netsnmp_transport *netsnmp_udpshared_transport(const struct netsnmp_ep *ep, int local); netsnmp_transport * - netsnmp_udpshared_transport_with_source(const struct sockaddr_in *addr, + netsnmp_udpshared_transport_with_source(const struct netsnmp_ep *ep, int local, - const struct sockaddr_in *src_addr); + const struct netsnmp_ep *src_addr); #ifdef __cplusplus } diff --git a/snmplib/transports/snmpDTLSUDPDomain.c b/snmplib/transports/snmpDTLSUDPDomain.c index 7a8663def58d..ca311276ac6d 100644 --- a/snmplib/transports/snmpDTLSUDPDomain.c +++ b/snmplib/transports/snmpDTLSUDPDomain.c @@ -23,6 +23,7 @@ netsnmp_feature_require(cert_util) netsnmp_feature_require(sockaddr_size) +#include <net-snmp/library/snmpIPBaseDomain.h> #include <net-snmp/library/snmpDTLSUDPDomain.h> #include <net-snmp/library/snmpUDPIPv6Domain.h> #include <net-snmp/library/snmp_assert.h> @@ -1494,13 +1495,14 @@ _transport_common(netsnmp_transport *t, int local) } netsnmp_transport * -netsnmp_dtlsudp_transport(const struct sockaddr_in *addr, int local) +netsnmp_dtlsudp_transport(const struct netsnmp_ep *ep, int local) { + const struct sockaddr_in *addr = &ep->a.sin; netsnmp_transport *t = NULL; DEBUGTRACETOK("dtlsudp"); - t = netsnmp_udp_transport(addr, local); + t = netsnmp_udp_transport(ep, local); if (NULL == t) return NULL; @@ -1532,13 +1534,14 @@ netsnmp_dtlsudp6_fmtaddr(netsnmp_transport *t, const void *data, int len) */ netsnmp_transport * -netsnmp_dtlsudp6_transport(const struct sockaddr_in6 *addr, int local) +netsnmp_dtlsudp6_transport(const struct netsnmp_ep *ep, int local) { + const struct sockaddr_in6 *addr = &ep->a.sin6; netsnmp_transport *t = NULL; DEBUGTRACETOK("dtlsudp"); - t = netsnmp_udp6_transport(addr, local); + t = netsnmp_udp6_transport(ep, local); if (NULL == t) return NULL; @@ -1565,19 +1568,16 @@ netsnmp_transport * netsnmp_dtlsudp_create_tstring(const char *str, int isserver, const char *default_target) { -#ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN - struct sockaddr_in6 addr6; -#endif - struct sockaddr_in addr; + struct netsnmp_ep ep; netsnmp_transport *t; _netsnmpTLSBaseData *tlsdata; char buf[SPRINT_MAX_LEN], *cp; - if (netsnmp_sockaddr_in2(&addr, str, default_target)) - t = netsnmp_dtlsudp_transport(&addr, isserver); + if (netsnmp_sockaddr_in3(&ep, str, default_target)) + t = netsnmp_dtlsudp_transport(&ep, isserver); #ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN - else if (netsnmp_sockaddr_in6_2(&addr6, str, default_target)) - t = netsnmp_dtlsudp6_transport(&addr6, isserver); + else if (netsnmp_sockaddr_in6_3(&ep, str, default_target)) + t = netsnmp_dtlsudp6_transport(&ep, isserver); #endif else return NULL; @@ -1603,14 +1603,14 @@ netsnmp_dtlsudp_create_tstring(const char *str, int isserver, netsnmp_transport * netsnmp_dtlsudp_create_ostring(const void *o, size_t o_len, int local) { - struct sockaddr_in sin; - struct sockaddr_in6 sin6; + struct netsnmp_ep ep; - if (netsnmp_ipv4_ostring_to_sockaddr(&sin, o, o_len)) - return netsnmp_dtlsudp_transport(&sin, local); + memset(&ep, 0, sizeof(ep)); + if (netsnmp_ipv4_ostring_to_sockaddr(&ep.a.sin, o, o_len)) + return netsnmp_dtlsudp_transport(&ep, local); #ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN - else if (netsnmp_ipv6_ostring_to_sockaddr(&sin6, o, o_len)) - return netsnmp_dtlsudp6_transport(&sin6, local); + else if (netsnmp_ipv6_ostring_to_sockaddr(&ep.a.sin6, o, o_len)) + return netsnmp_dtlsudp6_transport(&ep, local); #endif else return NULL; diff --git a/snmplib/transports/snmpIPv6BaseDomain.c b/snmplib/transports/snmpIPv6BaseDomain.c index 8e2fb8c86dd3..c2baacc5d42c 100644 --- a/snmplib/transports/snmpIPv6BaseDomain.c +++ b/snmplib/transports/snmpIPv6BaseDomain.c @@ -248,13 +248,13 @@ int netsnmp_sockaddr_in6_2(struct sockaddr_in6 *addr, const char *inpeername, const char *default_target) { - struct netsnmp_ep ai; + struct netsnmp_ep ep; int ret; - ret = netsnmp_sockaddr_in6_3(&ai, inpeername, default_target); + ret = netsnmp_sockaddr_in6_3(&ep, inpeername, default_target); if (ret == 0) return 0; - *addr = ai.a.sin6; + *addr = ep.a.sin6; return ret; } diff --git a/snmplib/transports/snmpTCPDomain.c b/snmplib/transports/snmpTCPDomain.c index a753b93b6803..ac9b66a16fd5 100644 --- a/snmplib/transports/snmpTCPDomain.c +++ b/snmplib/transports/snmpTCPDomain.c @@ -1,6 +1,7 @@ #include <net-snmp/net-snmp-config.h> #include <net-snmp/types.h> +#include <net-snmp/library/snmpIPBaseDomain.h> #include <net-snmp/library/snmpTCPDomain.h> #include <stdio.h> @@ -149,8 +150,9 @@ netsnmp_tcp_accept(netsnmp_transport *t) */ netsnmp_transport * -netsnmp_tcp_transport(const struct sockaddr_in *addr, int local) +netsnmp_tcp_transport(const struct netsnmp_ep *ep, int local) { + const struct sockaddr_in *addr = &ep->a.sin; netsnmp_transport *t = NULL; netsnmp_udp_addr_pair *addr_pair = NULL; int rc = 0; @@ -308,10 +310,10 @@ netsnmp_transport * netsnmp_tcp_create_tstring(const char *str, int local, const char *default_target) { - struct sockaddr_in addr; + struct netsnmp_ep ep; - if (netsnmp_sockaddr_in2(&addr, str, default_target)) { - return netsnmp_tcp_transport(&addr, local); + if (netsnmp_sockaddr_in3(&ep, str, default_target)) { + return netsnmp_tcp_transport(&ep, local); } else { return NULL; } @@ -322,10 +324,11 @@ netsnmp_tcp_create_tstring(const char *str, int local, netsnmp_transport * netsnmp_tcp_create_ostring(const void *o, size_t o_len, int local) { - struct sockaddr_in sin; + struct netsnmp_ep ep; - if (netsnmp_ipv4_ostring_to_sockaddr(&sin, o, o_len)) - return netsnmp_tcp_transport(&sin, local); + memset(&ep, 0, sizeof(ep)); + if (netsnmp_ipv4_ostring_to_sockaddr(&ep.a.sin, o, o_len)) + return netsnmp_tcp_transport(&ep, local); return NULL; } diff --git a/snmplib/transports/snmpTCPIPv6Domain.c b/snmplib/transports/snmpTCPIPv6Domain.c index 8ff782f5270e..cdff5fab6843 100644 --- a/snmplib/transports/snmpTCPIPv6Domain.c +++ b/snmplib/transports/snmpTCPIPv6Domain.c @@ -3,6 +3,7 @@ #ifdef NETSNMP_TRANSPORT_TCPIPV6_DOMAIN #include <net-snmp/types.h> +#include <net-snmp/library/snmpIPBaseDomain.h> #include <net-snmp/library/snmpTCPIPv6Domain.h> #include <stdio.h> @@ -140,8 +141,9 @@ netsnmp_tcp6_accept(netsnmp_transport *t) */ netsnmp_transport * -netsnmp_tcp6_transport(const struct sockaddr_in6 *addr, int local) +netsnmp_tcp6_transport(const struct netsnmp_ep *ep, int local) { + const struct sockaddr_in6 *addr = &ep->a.sin6; netsnmp_transport *t = NULL; int rc = 0; int socket_initialized = 0; @@ -312,10 +314,10 @@ netsnmp_transport * netsnmp_tcp6_create_tstring(const char *str, int local, const char *default_target) { - struct sockaddr_in6 addr; + struct netsnmp_ep ep; - if (netsnmp_sockaddr_in6_2(&addr, str, default_target)) { - return netsnmp_tcp6_transport(&addr, local); + if (netsnmp_sockaddr_in6_3(&ep, str, default_target)) { + return netsnmp_tcp6_transport(&ep, local); } else { return NULL; } @@ -334,10 +336,11 @@ netsnmp_tcp6_create_tstring(const char *str, int local, netsnmp_transport * netsnmp_tcp6_create_ostring(const void *o, size_t o_len, int local) { - struct sockaddr_in6 sin6; + struct netsnmp_ep ep; - if (netsnmp_ipv6_ostring_to_sockaddr(&sin6, o, o_len)) - return netsnmp_tcp6_transport(&sin6, local); + memset(&ep, 0, sizeof(ep)); + if (netsnmp_ipv6_ostring_to_sockaddr(&ep.a.sin6, o, o_len)) + return netsnmp_tcp6_transport(&ep, local); return NULL; } diff --git a/snmplib/transports/snmpUDPDomain.c b/snmplib/transports/snmpUDPDomain.c index 779105b0f6ec..4ea942097aff 100644 --- a/snmplib/transports/snmpUDPDomain.c +++ b/snmplib/transports/snmpUDPDomain.c @@ -17,6 +17,7 @@ #include <net-snmp/net-snmp-config.h> #include <net-snmp/types.h> +#include <net-snmp/library/snmpIPBaseDomain.h> #include <net-snmp/library/snmpUDPDomain.h> #include <net-snmp/library/snmpUDPIPv4BaseDomain.h> @@ -157,11 +158,11 @@ netsnmp_udp_transport_base(netsnmp_transport *t) * the remote address to send things to. */ netsnmp_transport * -netsnmp_udp_transport(const struct sockaddr_in *addr, int local) +netsnmp_udp_transport(const struct netsnmp_ep *ep, int local) { netsnmp_transport *t = NULL; - t = netsnmp_udpipv4base_transport(addr, local); + t = netsnmp_udpipv4base_transport(ep, local); if (NULL != t) { netsnmp_udp_transport_base(t); } @@ -175,13 +176,13 @@ netsnmp_udp_transport(const struct sockaddr_in *addr, int local) * to send from. */ netsnmp_transport * -netsnmp_udp_transport_with_source(const struct sockaddr_in *addr, int local, - const struct sockaddr_in *src_addr) +netsnmp_udp_transport_with_source(const struct netsnmp_ep *ep, int local, + const struct netsnmp_ep *src_addr) { netsnmp_transport *t = NULL; - t = netsnmp_udpipv4base_transport_with_source(addr, local, src_addr); + t = netsnmp_udpipv4base_transport_with_source(ep, local, src_addr); if (NULL != t) { netsnmp_udp_transport_base(t); } @@ -606,9 +607,9 @@ netsnmp_transport * netsnmp_udp_create_tstring(const char *str, int local, const char *default_target) { - struct sockaddr_in addr; + struct netsnmp_ep addr; - if (netsnmp_sockaddr_in2(&addr, str, default_target)) { + if (netsnmp_sockaddr_in3(&addr, str, default_target)) { return netsnmp_udp_transport(&addr, local); } else { return NULL; @@ -629,10 +630,11 @@ netsnmp_udp_create_tspec(netsnmp_tdomain_spec *tspec) netsnmp_transport * netsnmp_udp_create_ostring(const void *o, size_t o_len, int local) { - struct sockaddr_in sin; + struct netsnmp_ep ep; - if (netsnmp_ipv4_ostring_to_sockaddr(&sin, o, o_len)) - return netsnmp_udp_transport(&sin, local); + memset(&ep, 0, sizeof(ep)); + if (netsnmp_ipv4_ostring_to_sockaddr(&ep.a.sin, o, o_len)) + return netsnmp_udp_transport(&ep, local); return NULL; } diff --git a/snmplib/transports/snmpUDPIPv4BaseDomain.c b/snmplib/transports/snmpUDPIPv4BaseDomain.c index 433eb809bb91..7f8b68108d6d 100644 --- a/snmplib/transports/snmpUDPIPv4BaseDomain.c +++ b/snmplib/transports/snmpUDPIPv4BaseDomain.c @@ -13,6 +13,7 @@ #include <net-snmp/net-snmp-config.h> #include <net-snmp/types.h> +#include <net-snmp/library/snmpIPBaseDomain.h> #include <net-snmp/library/snmpUDPIPv4BaseDomain.h> #include <stddef.h> @@ -72,9 +73,10 @@ int netsnmp_udpipv4_sendto(int fd, const struct in_addr *srcip, int if_index, #endif /* HAVE_IP_PKTINFO || HAVE_IP_RECVDSTADDR */ netsnmp_transport * -netsnmp_udpipv4base_transport_init(const struct sockaddr_in *addr, int local) +netsnmp_udpipv4base_transport_init(const struct netsnmp_ep *ep, int local) { netsnmp_transport *t; + const struct sockaddr_in *addr = &ep->a.sin; u_char *addr_ptr; if (addr == NULL || addr->sin_family != AF_INET) { @@ -152,8 +154,10 @@ netsnmp_udpipv4base_transport_socket(int flags) int netsnmp_udpipv4base_transport_bind(netsnmp_transport *t, - const struct sockaddr_in *addr, int flags) + const struct netsnmp_ep *ep, + int flags) { + const struct sockaddr_in *addr = &ep->a.sin; #if defined(HAVE_IP_PKTINFO) || defined(HAVE_IP_RECVDSTADDR) int sockopt = 1; #endif @@ -247,20 +251,20 @@ netsnmp_udpipv4base_transport_get_bound_addr(netsnmp_transport *t) } netsnmp_transport * -netsnmp_udpipv4base_transport_with_source(const struct sockaddr_in *addr, +netsnmp_udpipv4base_transport_with_source(const struct netsnmp_ep *ep, int local, - const struct sockaddr_in *src_addr) + const struct netsnmp_ep *src_addr) { netsnmp_transport *t = NULL; - const struct sockaddr_in *bind_addr; + const struct netsnmp_ep *bind_addr; int rc, flags = 0; - t = netsnmp_udpipv4base_transport_init(addr, local); + t = netsnmp_udpipv4base_transport_init(ep, local); if (NULL == t) return NULL; if (local) { - bind_addr = addr; + bind_addr = ep; flags |= NETSNMP_TSPEC_LOCAL; #ifndef NETSNMP_NO_SYSTEMD @@ -288,7 +292,7 @@ netsnmp_udpipv4base_transport_with_source(const struct sockaddr_in *addr, if (NULL == bind_addr) return t; - rc = netsnmp_udpipv4base_transport_bind(t, bind_addr, flags); + rc = netsnmp_udpipv4base_transport_bind(t, ep, flags); if (rc) { netsnmp_transport_free(t); t = NULL; @@ -302,7 +306,7 @@ netsnmp_udpipv4base_transport_with_source(const struct sockaddr_in *addr, netsnmp_transport * netsnmp_udpipv4base_tspec_transport(netsnmp_tdomain_spec *tspec) { - struct sockaddr_in addr; + struct netsnmp_ep addr; int local; if (NULL == tspec) @@ -311,15 +315,17 @@ netsnmp_udpipv4base_tspec_transport(netsnmp_tdomain_spec *tspec) local = tspec->flags & NETSNMP_TSPEC_LOCAL; /** get address from target */ - if (!netsnmp_sockaddr_in2(&addr, tspec->target, tspec->default_target)) + if (!netsnmp_sockaddr_in3(&addr, tspec->target, tspec->default_target)) return NULL; if (NULL != tspec->source) { - struct sockaddr_in src_addr, *srcp = &src_addr; + struct netsnmp_ep src_addr; + /** get sockaddr from source */ - if (!netsnmp_sockaddr_in2(&src_addr, tspec->source, NULL)) + if (!netsnmp_sockaddr_in3(&src_addr, tspec->source, NULL)) return NULL; - return netsnmp_udpipv4base_transport_with_source(&addr, local, srcp); + return netsnmp_udpipv4base_transport_with_source(&addr, local, + &src_addr); } else { /** if no source and we do not want any default client address */ if (tspec->flags & NETSNMP_TSPEC_NO_DFTL_CLIENT_ADDR) @@ -332,7 +338,8 @@ netsnmp_udpipv4base_tspec_transport(netsnmp_tdomain_spec *tspec) } netsnmp_transport * -netsnmp_udpipv4base_transport(const struct sockaddr_in *addr, int local) +netsnmp_udpipv4base_transport(const struct netsnmp_ep *ep, + int local) { if (!local) { /* @@ -344,7 +351,7 @@ netsnmp_udpipv4base_transport(const struct sockaddr_in *addr, int local) client_socket = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_CLIENT_ADDR); if (client_socket) { - struct sockaddr_in client_addr; + struct netsnmp_ep client_addr; char *client_address = NETSNMP_REMOVE_CONST(char *,client_socket); int have_port, rc; int uses_port = @@ -364,16 +371,16 @@ netsnmp_udpipv4base_transport(const struct sockaddr_in *addr, int local) strcat(client_address, ":0"); have_port = 1; } - rc = netsnmp_sockaddr_in2(&client_addr, client_socket, NULL); + rc = netsnmp_sockaddr_in3(&client_addr, client_socket, NULL); if (client_address != client_socket) free(client_address); if(rc) { if (!uses_port || !have_port) /* if port isn't from string, */ - client_addr.sin_port = 0; /* ... clear it */ - return netsnmp_udpipv4base_transport_with_source(addr, local, + client_addr.a.sin.sin_port = 0; /* ... clear it */ + return netsnmp_udpipv4base_transport_with_source(ep, local, &client_addr); } } } - return netsnmp_udpipv4base_transport_with_source(addr, local, NULL); + return netsnmp_udpipv4base_transport_with_source(ep, local, NULL); } diff --git a/snmplib/transports/snmpUDPIPv6Domain.c b/snmplib/transports/snmpUDPIPv6Domain.c index 7a3b1db15c67..1f8c3765f21d 100644 --- a/snmplib/transports/snmpUDPIPv6Domain.c +++ b/snmplib/transports/snmpUDPIPv6Domain.c @@ -6,6 +6,7 @@ */ #include <net-snmp/net-snmp-config.h> +#include <net-snmp/library/snmpIPBaseDomain.h> #include <net-snmp/library/snmpUDPIPv6Domain.h> #include <net-snmp/library/system.h> @@ -191,8 +192,9 @@ netsnmp_udp6_send(netsnmp_transport *t, const void *buf, int size, */ netsnmp_transport * -netsnmp_udp6_transport_init(const struct sockaddr_in6 *addr, int flags) +netsnmp_udp6_transport_init(const struct netsnmp_ep *ep, int flags) { + const struct sockaddr_in6 *addr = &ep->a.sin6; netsnmp_transport *t = NULL; int local = flags & NETSNMP_TSPEC_LOCAL; u_char *addr_ptr; @@ -274,9 +276,10 @@ netsnmp_udp6_transport_init(const struct sockaddr_in6 *addr, int flags) int netsnmp_udp6_transport_bind(netsnmp_transport *t, - const struct sockaddr_in6 *addr, + const struct netsnmp_ep *ep, int flags) { + const struct sockaddr_in6 *addr = &ep->a.sin6; int local = flags & NETSNMP_TSPEC_LOCAL; int rc = 0; @@ -368,7 +371,7 @@ netsnmp_udp6_transport_get_bound_addr(netsnmp_transport *t) netsnmp_transport * netsnmp_udpipv6base_tspec_transport(netsnmp_tdomain_spec *tspec) { - struct sockaddr_in6 addr; + struct netsnmp_ep ep; int local; if (NULL == tspec) @@ -377,40 +380,40 @@ netsnmp_udpipv6base_tspec_transport(netsnmp_tdomain_spec *tspec) local = tspec->flags & NETSNMP_TSPEC_LOCAL; /** get address from target */ - if (!netsnmp_sockaddr_in6_2(&addr, tspec->target, tspec->default_target)) + if (!netsnmp_sockaddr_in6_3(&ep, tspec->target, tspec->default_target)) return NULL; if (NULL != tspec->source) { - struct sockaddr_in6 src_addr, *srcp = &src_addr; + struct netsnmp_ep src_addr; + /** get sockaddr from source */ - if (!netsnmp_sockaddr_in6_2(&src_addr, tspec->source, NULL)) + if (!netsnmp_sockaddr_in6_3(&src_addr, tspec->source, NULL)) return NULL; - return netsnmp_udp6_transport_with_source(&addr, local, srcp); + return netsnmp_udp6_transport_with_source(&ep, local, &src_addr); } else { /** if no source and we do not want any default client address */ if (tspec->flags & NETSNMP_TSPEC_NO_DFTL_CLIENT_ADDR) - return netsnmp_udp6_transport_with_source(&addr, local, - NULL); + return netsnmp_udp6_transport_with_source(&ep, local, NULL); } /** no source and default client address ok */ - return netsnmp_udp6_transport(&addr, local); + return netsnmp_udp6_transport(&ep, local); } netsnmp_transport * -netsnmp_udp6_transport_with_source(const struct sockaddr_in6 *addr, int local, - const struct sockaddr_in6 *src_addr) +netsnmp_udp6_transport_with_source(const struct netsnmp_ep *ep, + int local, const struct netsnmp_ep *src_addr) { netsnmp_transport *t = NULL; - const struct sockaddr_in6 *bind_addr; + const struct netsnmp_ep *bind_addr; int rc, flags = 0; - t = netsnmp_udp6_transport_init(addr, local); + t = netsnmp_udp6_transport_init(ep, local); if (NULL == t) return NULL; if (local) { - bind_addr = addr; + bind_addr = ep; flags |= NETSNMP_TSPEC_LOCAL; #ifndef NETSNMP_NO_SYSTEMD @@ -456,7 +459,7 @@ netsnmp_udp6_transport_with_source(const struct sockaddr_in6 *addr, int local, */ netsnmp_transport * -netsnmp_udp6_transport(const struct sockaddr_in6 *addr, int local) +netsnmp_udp6_transport(const struct netsnmp_ep *ep, int local) { if (!local) { const char *client_socket; @@ -464,15 +467,14 @@ netsnmp_udp6_transport(const struct sockaddr_in6 *addr, int local) client_socket = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_CLIENT_ADDR); if (client_socket) { - struct sockaddr_in6 client_addr; + struct netsnmp_ep client_addr; - if (!netsnmp_sockaddr_in6_2(&client_addr, client_socket, NULL)) + if (!netsnmp_sockaddr_in6_3(&client_addr, client_socket, NULL)) return NULL; - return netsnmp_udp6_transport_with_source(addr, local, - &client_addr); + return netsnmp_udp6_transport_with_source(ep, local, &client_addr); } } - return netsnmp_udp6_transport_with_source(addr, local, NULL); + return netsnmp_udp6_transport_with_source(ep, local, NULL); } @@ -924,10 +926,10 @@ netsnmp_transport * netsnmp_udp6_create_tstring(const char *str, int local, const char *default_target) { - struct sockaddr_in6 addr; + struct netsnmp_ep ep; - if (netsnmp_sockaddr_in6_2(&addr, str, default_target)) { - return netsnmp_udp6_transport(&addr, local); + if (netsnmp_sockaddr_in6_3(&ep, str, default_target)) { + return netsnmp_udp6_transport(&ep, local); } else { return NULL; } @@ -954,10 +956,11 @@ netsnmp_udp6_create_tspec(netsnmp_tdomain_spec *tspec) netsnmp_transport * netsnmp_udp6_create_ostring(const void *o, size_t o_len, int local) { - struct sockaddr_in6 sin6; + struct netsnmp_ep ep; - if (netsnmp_ipv6_ostring_to_sockaddr(&sin6, o, o_len)) - return netsnmp_udp6_transport(&sin6, local); + memset(&ep, 0, sizeof(ep)); + if (netsnmp_ipv6_ostring_to_sockaddr(&ep.a.sin6, o, o_len)) + return netsnmp_udp6_transport(&ep, local); return NULL; } diff --git a/snmplib/transports/snmpUDPsharedDomain.c b/snmplib/transports/snmpUDPsharedDomain.c index dfc1c07018de..8169954211c0 100644 --- a/snmplib/transports/snmpUDPsharedDomain.c +++ b/snmplib/transports/snmpUDPsharedDomain.c @@ -9,6 +9,7 @@ #include <net-snmp/net-snmp-config.h> #include <net-snmp/types.h> +#include <net-snmp/library/snmpIPBaseDomain.h> #include <net-snmp/library/snmpUDPsharedDomain.h> #include <stddef.h> @@ -189,11 +190,11 @@ _transport_common(netsnmp_transport *t) } netsnmp_transport * -netsnmp_udpshared_transport(const struct sockaddr_in *addr, int local) +netsnmp_udpshared_transport(const struct netsnmp_ep *ep, int local) { netsnmp_transport *t = NULL; - t = netsnmp_udp_transport(addr, local); + t = netsnmp_udp_transport(ep, local); if (NULL == t) return NULL; @@ -203,9 +204,9 @@ netsnmp_udpshared_transport(const struct sockaddr_in *addr, int local) } netsnmp_transport * -netsnmp_udpshared_transport_with_source(const struct sockaddr_in *addr, +netsnmp_udpshared_transport_with_source(const struct netsnmp_ep *ep, int flags, - const struct sockaddr_in *src_addr) + const struct netsnmp_ep *src_addr) { netsnmp_transport *t = NULL, *b = NULL; int local = flags & NETSNMP_TSPEC_LOCAL; @@ -213,7 +214,7 @@ netsnmp_udpshared_transport_with_source(const struct sockaddr_in *addr, DEBUGMSGTL(("udpshared:create", "from addr with source\n")); /** init common parts of parent transport */ - t = netsnmp_udpipv4base_transport_init(addr, local); + t = netsnmp_udpipv4base_transport_init(ep, local); if (NULL == t) return NULL; @@ -237,7 +238,7 @@ netsnmp_udpshared_transport_with_source(const struct sockaddr_in *addr, /** if no base transport found, create one */ if (NULL == b) { - b = netsnmp_udp_transport_with_source(addr, local, src_addr); + b = netsnmp_udp_transport_with_source(ep, local, src_addr); if (NULL == b) { netsnmp_transport_free(t); return NULL; @@ -271,11 +272,11 @@ netsnmp_udpshared_transport_with_source(const struct sockaddr_in *addr, * the remote address to send things to. */ netsnmp_transport * -netsnmp_udpshared6_transport(const struct sockaddr_in6 *addr, int local) +netsnmp_udpshared6_transport(const struct netsnmp_ep *ep, int local) { netsnmp_transport *t = NULL; - t = netsnmp_udp6_transport(addr, local); + t = netsnmp_udp6_transport(ep, local); if (NULL != t) t = _transport_common(t); @@ -283,9 +284,9 @@ netsnmp_udpshared6_transport(const struct sockaddr_in6 *addr, int local) } netsnmp_transport * -netsnmp_udpshared6_transport_with_source(const struct sockaddr_in6 *addr6, +netsnmp_udpshared6_transport_with_source(const struct netsnmp_ep *ep, int flags, - const struct sockaddr_in6 *src_addr6) + const struct netsnmp_ep *src_addr6) { netsnmp_transport *t = NULL, *b = NULL; int local = flags & NETSNMP_TSPEC_LOCAL; @@ -293,7 +294,7 @@ netsnmp_udpshared6_transport_with_source(const struct sockaddr_in6 *addr6, DEBUGMSGTL(("udpshared:create", "from addr6 with source\n")); /** init common parts of parent transport */ - t = netsnmp_udp6_transport_init(addr6, local); + t = netsnmp_udp6_transport_init(ep, local); if (NULL == t) return NULL; @@ -317,7 +318,7 @@ netsnmp_udpshared6_transport_with_source(const struct sockaddr_in6 *addr6, /** if no base transport found, create one */ if (NULL == b) { - b = netsnmp_udp6_transport_with_source(addr6, local, src_addr6); + b = netsnmp_udp6_transport_with_source(ep, local, src_addr6); if (NULL == b) { netsnmp_transport_free(t); return NULL; @@ -346,16 +347,16 @@ netsnmp_udpshared6_transport_with_source(const struct sockaddr_in6 *addr6, netsnmp_transport * netsnmp_udpshared_create_ostring(const void *o, size_t o_len, int local) { - struct sockaddr_in sin; - struct sockaddr_in6 sin6; + struct netsnmp_ep ep; DEBUGMSGTL(("udpshared:create", "from ostring\n")); - if (netsnmp_ipv4_ostring_to_sockaddr(&sin, o, o_len)) - return netsnmp_udpshared_transport(&sin, local); + memset(&ep, 0, sizeof(ep)); + if (netsnmp_ipv4_ostring_to_sockaddr(&ep.a.sin, o, o_len)) + return netsnmp_udpshared_transport(&ep, local); #ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN - else if (netsnmp_ipv6_ostring_to_sockaddr(&sin6, o, o_len)) - return netsnmp_udpshared6_transport(&sin6, local); + else if (netsnmp_ipv6_ostring_to_sockaddr(&ep.a.sin6, o, o_len)) + return netsnmp_udpshared6_transport(&ep, local); #endif return NULL; } @@ -364,19 +365,16 @@ netsnmp_transport * netsnmp_udpshared_create_tstring(const char *str, int isserver, const char *default_target) { -#ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN - struct sockaddr_in6 addr6; -#endif - struct sockaddr_in addr; + struct netsnmp_ep ep; netsnmp_transport *t; DEBUGMSGTL(("udpshared:create", "from tstring %s\n", str)); - if (netsnmp_sockaddr_in2(&addr, str, default_target)) - t = netsnmp_udpshared_transport(&addr, isserver); + if (netsnmp_sockaddr_in3(&ep, str, default_target)) + t = netsnmp_udpshared_transport(&ep, isserver); #ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN - else if (netsnmp_sockaddr_in6_2(&addr6, str, default_target)) - t = netsnmp_udpshared6_transport(&addr6, isserver); + else if (netsnmp_sockaddr_in6_3(&ep, str, default_target)) + t = netsnmp_udpshared6_transport(&ep, isserver); #endif else return NULL; @@ -385,68 +383,66 @@ netsnmp_udpshared_create_tstring(const char *str, int isserver, } static netsnmp_transport * -_tspec_v4(struct sockaddr_in *addr, netsnmp_tdomain_spec *tspec) +_tspec_v4(const struct netsnmp_ep *ep, netsnmp_tdomain_spec *tspec) { int local = tspec->flags & NETSNMP_TSPEC_LOCAL; if (NULL != tspec->source) { - struct sockaddr_in src_addr, *srcp = &src_addr; + struct netsnmp_ep src_addr; + /** get sockaddr from source */ - if (!netsnmp_sockaddr_in2(&src_addr, tspec->source, NULL)) + if (!netsnmp_sockaddr_in3(&src_addr, tspec->source, NULL)) return NULL; - return netsnmp_udpshared_transport_with_source(addr, local, srcp); + return netsnmp_udpshared_transport_with_source(ep, local, &src_addr); } else { /** if no source and we do not want any default client address */ if (tspec->flags & NETSNMP_TSPEC_NO_DFTL_CLIENT_ADDR) - return netsnmp_udpshared_transport_with_source(addr, local, NULL); + return netsnmp_udpshared_transport_with_source(ep, local, NULL); } /** no source and default client address ok */ - return netsnmp_udpshared_transport(addr, local); + return netsnmp_udpshared_transport(ep, local); } #ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN static netsnmp_transport * -_tspec_v6(struct sockaddr_in6 *addr, netsnmp_tdomain_spec *tspec) +_tspec_v6(const struct netsnmp_ep *ep, netsnmp_tdomain_spec *tspec) { int local = tspec->flags & NETSNMP_TSPEC_LOCAL; if (NULL != tspec->source) { - struct sockaddr_in6 src_addr, *srcp = &src_addr; + struct netsnmp_ep src_addr; + /** get sockaddr from source */ - if (!netsnmp_sockaddr_in6_2(&src_addr, tspec->source, NULL)) + if (!netsnmp_sockaddr_in6_3(&src_addr, tspec->source, NULL)) return NULL; - return netsnmp_udpshared6_transport_with_source(addr, local, srcp); + return netsnmp_udpshared6_transport_with_source(ep, local, &src_addr); } else { /** if no source and we do not want any default client address */ if (tspec->flags & NETSNMP_TSPEC_NO_DFTL_CLIENT_ADDR) - return netsnmp_udpshared6_transport_with_source(addr, local, NULL); + return netsnmp_udpshared6_transport_with_source(ep, local, NULL); } /** no source and default client address ok */ - return netsnmp_udpshared6_transport(addr, local); + return netsnmp_udpshared6_transport(ep, local); } #endif /* NETSNMP_TRANSPORT_UDPIPV6_DOMAIN */ netsnmp_transport * netsnmp_udpshared_create_tspec(netsnmp_tdomain_spec *tspec) { -#ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN - struct sockaddr_in6 addr6; -#endif - struct sockaddr_in addr; + struct netsnmp_ep ep; DEBUGMSGTL(("udpshared:create", "from tspec\n")); if (NULL == tspec) return NULL; - if (netsnmp_sockaddr_in2(&addr, tspec->target, tspec->default_target)) - return _tspec_v4(&addr, tspec); + if (netsnmp_sockaddr_in3(&ep, tspec->target, tspec->default_target)) + return _tspec_v4(&ep, tspec); #ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN - else if (netsnmp_sockaddr_in6_2(&addr6, tspec->target, - tspec->default_target)) - return _tspec_v6(&addr6, tspec); + else if (netsnmp_sockaddr_in6_3(&ep, tspec->target, tspec->default_target)) + return _tspec_v6(&ep, tspec); #endif return NULL; -- 2.19.1 |
From: Bart V. A. <bva...@ac...> - 2018-10-28 21:22:43
|
--- include/net-snmp/library/snmpIPBaseDomain.h | 2 + snmplib/transports/snmpIPBaseDomain.c | 41 +++++++++++++++++++-- snmplib/transports/snmpIPv4BaseDomain.c | 2 + snmplib/transports/snmpIPv6BaseDomain.c | 2 + snmplib/transports/snmpTCPDomain.c | 7 ++++ snmplib/transports/snmpTCPIPv6Domain.c | 6 +++ snmplib/transports/snmpUDPIPv4BaseDomain.c | 13 ++++++- snmplib/transports/snmpUDPIPv6Domain.c | 13 ++++++- 8 files changed, 79 insertions(+), 7 deletions(-) diff --git a/include/net-snmp/library/snmpIPBaseDomain.h b/include/net-snmp/library/snmpIPBaseDomain.h index 6eaf37ac4253..635c748ac930 100644 --- a/include/net-snmp/library/snmpIPBaseDomain.h +++ b/include/net-snmp/library/snmpIPBaseDomain.h @@ -26,9 +26,11 @@ struct netsnmp_ep { */ struct netsnmp_ep_str { char addr[64]; + char iface[16]; uint16_t port; }; int netsnmp_parse_ep_str(struct netsnmp_ep_str *ep_str, const char *endpoint); +int netsnmp_bindtodevice(int fd, const char *iface); #endif /* _SNMPIPBASEDOMAIN_H_ */ diff --git a/snmplib/transports/snmpIPBaseDomain.c b/snmplib/transports/snmpIPBaseDomain.c index ac94ba73840d..ea0a291c8529 100644 --- a/snmplib/transports/snmpIPBaseDomain.c +++ b/snmplib/transports/snmpIPBaseDomain.c @@ -3,6 +3,7 @@ #include <net-snmp/library/system.h> #include <net-snmp/library/snmpIPBaseDomain.h> #include <ctype.h> +#include <errno.h> #include <stdlib.h> static int isnumber(const char *cp) @@ -23,7 +24,7 @@ static int isnumber(const char *cp) */ int netsnmp_parse_ep_str(struct netsnmp_ep_str *ep_str, const char *endpoint) { - char *dup, *cp, *addrstr = NULL, *portstr = NULL; + char *dup, *cp, *addrstr = NULL, *iface = NULL, *portstr = NULL; unsigned port; if (!endpoint) @@ -46,9 +47,16 @@ int netsnmp_parse_ep_str(struct netsnmp_ep_str *ep_str, const char *endpoint) } else { goto invalid; } - } else if (*cp != ':') { + } else if (*cp != '@' && *cp != ':') { addrstr = cp; - cp = strrchr(cp, ':'); + cp = strchr(addrstr, '@'); + if (!cp) + cp = strrchr(addrstr, ':'); + } + if (cp && *cp == '@') { + *cp = '\0'; + iface = cp + 1; + cp = strchr(cp + 1, ':'); } if (cp && *cp == ':') { *cp++ = '\0'; @@ -62,6 +70,8 @@ int netsnmp_parse_ep_str(struct netsnmp_ep_str *ep_str, const char *endpoint) if (addrstr) strlcpy(ep_str->addr, addrstr, sizeof(ep_str->addr)); + if (iface) + strlcpy(ep_str->iface, iface, sizeof(ep_str->iface)); if (portstr) { port = atoi(portstr); if (port > 0 && port <= 0xffff) @@ -77,3 +87,28 @@ invalid: free(dup); return 0; } + +int netsnmp_bindtodevice(int fd, const char *iface) +{ + /* If no interface name has been specified, report success. */ + if (!iface || iface[0] == '\0') + return 0; + +#ifdef HAVE_SO_BINDTODEVICE + /* + * +1 to work around the Linux kernel bug that the passed in name is not + * '\0'-terminated. + */ + int ifacelen = strlen(iface) + 1; + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, iface, ifacelen); + if (ret < 0) + snmp_log(LOG_ERR, "Binding socket to interface %s failed: %s\n", iface, + strerror(errno)); + return ret; +#else + errno = EINVAL; + return -1; +#endif +} diff --git a/snmplib/transports/snmpIPv4BaseDomain.c b/snmplib/transports/snmpIPv4BaseDomain.c index d8537fbdc912..c3f2671cbe98 100644 --- a/snmplib/transports/snmpIPv4BaseDomain.c +++ b/snmplib/transports/snmpIPv4BaseDomain.c @@ -108,6 +108,8 @@ netsnmp_sockaddr_in3(struct netsnmp_ep *ep, if (netsnmp_parse_ep_str(&ep_str, inpeername)) { if (ep_str.port) addr->sin_port = htons(ep_str.port); + if (ep_str.iface[0]) + strlcpy(ep->iface, ep_str.iface, sizeof(ep->iface)); if (strcmp(ep_str.addr, "255.255.255.255") == 0 ) { /* * The explicit broadcast address hack diff --git a/snmplib/transports/snmpIPv6BaseDomain.c b/snmplib/transports/snmpIPv6BaseDomain.c index c2baacc5d42c..1a87ee97767e 100644 --- a/snmplib/transports/snmpIPv6BaseDomain.c +++ b/snmplib/transports/snmpIPv6BaseDomain.c @@ -309,6 +309,8 @@ netsnmp_sockaddr_in6_3(struct netsnmp_ep *ep, !netsnmp_resolve_v6_hostname(&addr->sin6_addr, ep_str.addr)) return 0; } + if (ep_str.iface[0]) + strlcpy(ep->iface, ep_str.iface, sizeof(ep->iface)); if (ep_str.port) addr->sin6_port = htons(ep_str.port); } diff --git a/snmplib/transports/snmpTCPDomain.c b/snmplib/transports/snmpTCPDomain.c index ac9b66a16fd5..cfe6b13d75de 100644 --- a/snmplib/transports/snmpTCPDomain.c +++ b/snmplib/transports/snmpTCPDomain.c @@ -227,6 +227,13 @@ netsnmp_tcp_transport(const struct netsnmp_ep *ep, int local) sizeof(opt)); if (!socket_initialized) { + rc = netsnmp_bindtodevice(t->sock, ep->iface); + if (rc != 0) { + DEBUGMSGTL(("netsnmp_tcpbase", + "failed to bind to iface %s: %s\n", + ep->iface, strerror(errno))); + goto err; + } rc = bind(t->sock, (const struct sockaddr *)addr, sizeof(*addr)); if (rc != 0) goto err; diff --git a/snmplib/transports/snmpTCPIPv6Domain.c b/snmplib/transports/snmpTCPIPv6Domain.c index cdff5fab6843..47bf5747840b 100644 --- a/snmplib/transports/snmpTCPIPv6Domain.c +++ b/snmplib/transports/snmpTCPIPv6Domain.c @@ -231,6 +231,12 @@ netsnmp_tcp6_transport(const struct netsnmp_ep *ep, int local) setsockopt(t->sock, SOL_SOCKET, SO_REUSEADDR, (void *)&opt, sizeof(opt)); if (!socket_initialized) { + rc = netsnmp_bindtodevice(t->sock, ep->iface); + if (rc != 0) { + DEBUGMSGTL(("netsnmp_tcp6", "failed to bind to iface %s: %s\n", + ep->iface, strerror(errno))); + goto err; + } rc = bind(t->sock, (const struct sockaddr *)addr, sizeof(*addr)); if (rc != 0) goto err; diff --git a/snmplib/transports/snmpUDPIPv4BaseDomain.c b/snmplib/transports/snmpUDPIPv4BaseDomain.c index 7f8b68108d6d..eb30ea99f7ec 100644 --- a/snmplib/transports/snmpUDPIPv4BaseDomain.c +++ b/snmplib/transports/snmpUDPIPv4BaseDomain.c @@ -208,16 +208,25 @@ netsnmp_udpipv4base_transport_bind(netsnmp_transport *t, t->sock, str)); free(str); } + rc = netsnmp_bindtodevice(t->sock, ep->iface); + if (rc != 0) { + DEBUGMSGTL(("netsnmp_udpbase", "failed to bind to iface %s: %s\n", + ep->iface, strerror(errno))); + goto err; + } rc = bind(t->sock, (const struct sockaddr *)addr, sizeof(*addr)); if ( rc != 0 ) { DEBUGMSGTL(("netsnmp_udpbase", "failed to bind for clientaddr: %d %s\n", errno, strerror(errno))); - netsnmp_socketbase_close(t); - return 1; + goto err; } return 0; + +err: + netsnmp_socketbase_close(t); + return 1; } void diff --git a/snmplib/transports/snmpUDPIPv6Domain.c b/snmplib/transports/snmpUDPIPv6Domain.c index 1f8c3765f21d..083edf099253 100644 --- a/snmplib/transports/snmpUDPIPv6Domain.c +++ b/snmplib/transports/snmpUDPIPv6Domain.c @@ -312,15 +312,24 @@ netsnmp_udp6_transport_bind(netsnmp_transport *t, t->sock, str)); free(str); } + rc = netsnmp_bindtodevice(t->sock, ep->iface); + if (rc != 0) { + DEBUGMSGTL(("netsnmp_udp6", "failed to bind to iface %s: %s\n", + ep->iface, strerror(errno))); + goto err; + } rc = bind(t->sock, (const struct sockaddr *)addr, sizeof(*addr)); if (rc != 0) { DEBUGMSGTL(("netsnmp_udp6", "failed to bind for clientaddr: %d %s\n", errno, strerror(errno))); - netsnmp_socketbase_close(t); - return -1; + goto err; } return 0; + +err: + netsnmp_socketbase_close(t); + return -1; } int -- 2.19.1 |
From: Bart V. A. <bva...@ac...> - 2018-10-28 21:19:59
|
--- testing/fulltests/support/clib_build | 1 + .../T022netsnmp_parse_ep_str_clib.c | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 testing/fulltests/unit-tests/T022netsnmp_parse_ep_str_clib.c diff --git a/testing/fulltests/support/clib_build b/testing/fulltests/support/clib_build index f94bebd02e36..3ae4dc9b5b7f 100755 --- a/testing/fulltests/support/clib_build +++ b/testing/fulltests/support/clib_build @@ -15,6 +15,7 @@ cat >>"$2.c" <<EOF #include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-includes.h> #include <net-snmp/library/large_fd_set.h> +#include <net-snmp/library/snmpIPBaseDomain.h> /* testing specific header */ #include <net-snmp/library/testing.h> diff --git a/testing/fulltests/unit-tests/T022netsnmp_parse_ep_str_clib.c b/testing/fulltests/unit-tests/T022netsnmp_parse_ep_str_clib.c new file mode 100644 index 000000000000..7f06746ad299 --- /dev/null +++ b/testing/fulltests/unit-tests/T022netsnmp_parse_ep_str_clib.c @@ -0,0 +1,55 @@ +/* + * HEADER Testing netsnmp_parse_ep_str() + */ + +struct one_test_data { + const char *in; + int res; + struct netsnmp_ep_str expected; +}; + +static struct one_test_data test_data[] = { + { "9999", 1, { "", "", 9999 } }, + { ":777", 1, { "", "", 777 } }, + { "hostname:777", 1, { "hostname", "", 777 } }, + { "hostname", 1, { "hostname", "", 0 } }, + { "1.2.3.4", 1, { "1.2.3.4", "", 0 } }, + { "hostname@if", 1, { "hostname", "if", 0 } }, + { "hostname@if:833", 1, { "hostname", "if", 833 } }, + { "[hostname]@if:833", 1, { "hostname", "if", 833 } }, + { "[hostname]?", 0, { } }, + { "[hostname", 0, { } }, + { "@if:844", 1, { "", "if", 844 } }, + { "[::1]", 1, { "::1", "", 0 } }, + { "[::1]:2", 1, { "::1", "", 2 } }, + { "[::1]@if:2", 1, { "::1", "if", 2 } }, + { "[::1]:2@if", 0, { } }, +}; + +SOCK_STARTUP; + +{ + int i; + + for (i = 0; i < sizeof(test_data) / sizeof(test_data[0]); i++) { + const struct one_test_data *p = &test_data[i]; + struct netsnmp_ep_str ep_str; + int res; + + memset(&ep_str, 0, sizeof(ep_str)); + res = netsnmp_parse_ep_str(&ep_str, p->in); + OKF(res == p->res, ("%s: return value %d <> %d", p->in, res, p->res)); + if (res && p->res) { + OKF(strcmp(ep_str.addr, p->expected.addr) == 0, + ("%s: network address %s <> %s", p->in, ep_str.addr, + p->expected.addr)); + OKF(strcmp(ep_str.iface, p->expected.iface) == 0, + ("%s: network interface %s <> %s", p->in, ep_str.iface, + p->expected.iface)); + OKF(ep_str.port == p->expected.port, + ("%s: port %d <> %d", p->in, ep_str.port, p->expected.port)); + } + } +} + +SOCK_CLEANUP; -- 2.19.1 |
From: Bart V. A. <bva...@ac...> - 2018-10-28 21:19:50
|
Hello, As you may have noticed multiple people asked to add SO_BINDTODEVICE support to Net-SNMP. This patch series adds such support by allowing to specify the name of the network interface to bind a Net-SNMP endpoint to as "@<interface name>". An example: agent/snmpd -Mmibs -f -Lo -c .../snmpd.conf udp6:localhost@lo:1161 -r apps/snmpwalk -Mmibs -v2c -cpublic udp6:localhost:1161 .1 The reason I'm posting this patch series on the Net-SNMP mailing list is to gather feedback about this patch series. Does everyone agree with the code changes in this patch series? If so, on which branch(es) should these patches be applied? Master only or v5.8 and master? See also: * Add SO_BINDTODEVICE support (https://sourceforge.net/p/net-snmp/patches/1296/). * Add Linux VRF support (https://sourceforge.net/p/net-snmp/patches/1376/). Thanks, Bart. Bart Van Assche (6): libsnmp/transports: Introduce netsnmp_parse_ep_str() libsnmp/transports: Introduce netsnmp_sockaddr_in3() and netsnmp_sockaddr_in6_3() libsnmp/transports: Change multiple sockaddr_in* arguments into netsnmp_ep configure: Add a test for SO_BINDTODEVICE libsnmp/transports: Add support for interface binding testing/fulltests/unit-tests: Add netsnmp_parse_ep_str() unit test configure | 34 +++ configure.d/config_os_misc4 | 15 ++ include/net-snmp/library/snmpDTLSUDPDomain.h | 4 +- include/net-snmp/library/snmpIPBaseDomain.h | 36 +++ include/net-snmp/library/snmpIPv4BaseDomain.h | 7 + include/net-snmp/library/snmpIPv6BaseDomain.h | 5 + include/net-snmp/library/snmpTCPDomain.h | 4 +- include/net-snmp/library/snmpTCPIPv6Domain.h | 4 +- include/net-snmp/library/snmpUDPDomain.h | 8 +- .../net-snmp/library/snmpUDPIPv4BaseDomain.h | 12 +- include/net-snmp/library/snmpUDPIPv6Domain.h | 11 +- .../net-snmp/library/snmpUDPsharedDomain.h | 6 +- include/net-snmp/net-snmp-config.h.in | 3 + snmplib/transports/snmpDTLSUDPDomain.c | 36 +-- snmplib/transports/snmpIPBaseDomain.c | 114 +++++++++ snmplib/transports/snmpIPv4BaseDomain.c | 118 +++------ snmplib/transports/snmpIPv6BaseDomain.c | 238 ++++-------------- snmplib/transports/snmpTCPDomain.c | 24 +- snmplib/transports/snmpTCPIPv6Domain.c | 23 +- snmplib/transports/snmpUDPDomain.c | 22 +- snmplib/transports/snmpUDPIPv4BaseDomain.c | 58 +++-- snmplib/transports/snmpUDPIPv6Domain.c | 70 +++--- snmplib/transports/snmpUDPsharedDomain.c | 90 ++++--- testing/fulltests/support/clib_build | 1 + .../T022netsnmp_parse_ep_str_clib.c | 55 ++++ win32/libsnmp/Makefile.in | 1 + win32/libsnmp_dll/Makefile.in | 1 + 27 files changed, 561 insertions(+), 439 deletions(-) create mode 100644 include/net-snmp/library/snmpIPBaseDomain.h create mode 100644 snmplib/transports/snmpIPBaseDomain.c create mode 100644 testing/fulltests/unit-tests/T022netsnmp_parse_ep_str_clib.c -- 2.19.1 |
From: Bart V. A. <bva...@ac...> - 2018-10-28 21:15:15
|
--- configure | 34 +++++++++++++++++++++++++++ configure.d/config_os_misc4 | 15 ++++++++++++ include/net-snmp/net-snmp-config.h.in | 3 +++ 3 files changed, 52 insertions(+) diff --git a/configure b/configure index 282631f4266e..fe05c50374f0 100755 --- a/configure +++ b/configure @@ -31462,6 +31462,40 @@ And this can be very slow." >&2;} ;; esac +# Check whether SO_BINDTODEVICE is available. +# + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SO_BINDTODEVICE" >&5 +$as_echo_n "checking for SO_BINDTODEVICE... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include <sys/types.h> +#include <sys/socket.h> + +int +main () +{ + +return SO_BINDTODEVICE + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + +$as_echo "#define HAVE_SO_BINDTODEVICE 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + # Check whether struct in_pktinfo.ipi_spec_dst is available. # diff --git a/configure.d/config_os_misc4 b/configure.d/config_os_misc4 index 2899bb8adb98..9a4542274d14 100644 --- a/configure.d/config_os_misc4 +++ b/configure.d/config_os_misc4 @@ -318,6 +318,21 @@ And this can be very slow.]) ;; esac +# Check whether SO_BINDTODEVICE is available. +# + +AC_MSG_CHECKING([for SO_BINDTODEVICE]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([ +#include <sys/types.h> +#include <sys/socket.h> +], [ +return SO_BINDTODEVICE +])], +[AC_DEFINE([HAVE_SO_BINDTODEVICE], [1], + [Define to 1 if SO_BINDTODEVICE is available]) + AC_MSG_RESULT([yes])], +[AC_MSG_RESULT([no])]) + # Check whether struct in_pktinfo.ipi_spec_dst is available. # diff --git a/include/net-snmp/net-snmp-config.h.in b/include/net-snmp/net-snmp-config.h.in index e34af9f7e6e2..90e005d53f51 100644 --- a/include/net-snmp/net-snmp-config.h.in +++ b/include/net-snmp/net-snmp-config.h.in @@ -831,6 +831,9 @@ /* Define to 1 if the system has the type `socklen_t'. */ #undef HAVE_SOCKLEN_T +/* Define to 1 if SO_BINDTODEVICE is available */ +#undef HAVE_SO_BINDTODEVICE + /* Define to 1 if you have the `srand' function. */ #undef HAVE_SRAND -- 2.19.1 |
From: Bart V. A. <bva...@ac...> - 2018-10-28 21:10:37
|
The only functional change in this patch is that it is now allowed to surround IPv4 addresses and hostnames with square brackets in transport endpoint definitions. --- include/net-snmp/library/snmpIPBaseDomain.h | 16 ++ include/net-snmp/library/snmpIPv4BaseDomain.h | 2 + include/net-snmp/library/snmpIPv6BaseDomain.h | 2 + snmplib/transports/snmpIPBaseDomain.c | 79 +++++++ snmplib/transports/snmpIPv4BaseDomain.c | 92 ++------ snmplib/transports/snmpIPv6BaseDomain.c | 204 ++---------------- win32/libsnmp/Makefile.in | 1 + win32/libsnmp_dll/Makefile.in | 1 + 8 files changed, 134 insertions(+), 263 deletions(-) create mode 100644 include/net-snmp/library/snmpIPBaseDomain.h create mode 100644 snmplib/transports/snmpIPBaseDomain.c diff --git a/include/net-snmp/library/snmpIPBaseDomain.h b/include/net-snmp/library/snmpIPBaseDomain.h new file mode 100644 index 000000000000..fb79a9365c4e --- /dev/null +++ b/include/net-snmp/library/snmpIPBaseDomain.h @@ -0,0 +1,16 @@ +#ifndef _SNMPIPBASEDOMAIN_H_ +#define _SNMPIPBASEDOMAIN_H_ + +/** + * SNMP endpoint with the network name in ASCII format. + * @addr: Network address or host name as an ASCII string. + * @port: Port number in host byte format. + */ +struct netsnmp_ep_str { + char addr[64]; + uint16_t port; +}; + +int netsnmp_parse_ep_str(struct netsnmp_ep_str *ep_str, const char *endpoint); + +#endif /* _SNMPIPBASEDOMAIN_H_ */ diff --git a/include/net-snmp/library/snmpIPv4BaseDomain.h b/include/net-snmp/library/snmpIPv4BaseDomain.h index cb6a4585cf48..71804e3b1d72 100644 --- a/include/net-snmp/library/snmpIPv4BaseDomain.h +++ b/include/net-snmp/library/snmpIPv4BaseDomain.h @@ -9,6 +9,8 @@ #include <net-snmp/library/snmp_transport.h> +config_require(IPBase) + #ifdef __cplusplus extern "C" { #endif diff --git a/include/net-snmp/library/snmpIPv6BaseDomain.h b/include/net-snmp/library/snmpIPv6BaseDomain.h index 5c7d11cfd560..2f44e6a1b088 100644 --- a/include/net-snmp/library/snmpIPv6BaseDomain.h +++ b/include/net-snmp/library/snmpIPv6BaseDomain.h @@ -7,6 +7,8 @@ #include <netinet/in.h> #endif +config_require(IPBase) + #include <net-snmp/library/snmp_transport.h> #ifdef __cplusplus diff --git a/snmplib/transports/snmpIPBaseDomain.c b/snmplib/transports/snmpIPBaseDomain.c new file mode 100644 index 000000000000..ac94ba73840d --- /dev/null +++ b/snmplib/transports/snmpIPBaseDomain.c @@ -0,0 +1,79 @@ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/types.h> +#include <net-snmp/library/system.h> +#include <net-snmp/library/snmpIPBaseDomain.h> +#include <ctype.h> +#include <stdlib.h> + +static int isnumber(const char *cp) +{ + while (isdigit((uint8_t)*cp)) + cp++; + return *cp == '\0'; +} + +/** + * Parse a Net-SNMP endpoint name. + * @ep_str: Parsed endpoint name. + * @endpoint: Endpoint specification in the format [<address>]:[<port>] or + * <port>. + * + * Only overwrite those fields of *@ep_str that have been set in + * @endpoint. Returns 1 upon success and 0 upon failure. + */ +int netsnmp_parse_ep_str(struct netsnmp_ep_str *ep_str, const char *endpoint) +{ + char *dup, *cp, *addrstr = NULL, *portstr = NULL; + unsigned port; + + if (!endpoint) + return 0; + + dup = strdup(endpoint); + if (!dup) + return 0; + + cp = dup; + if (isnumber(cp)) { + portstr = cp; + } else { + if (*cp == '[') { + addrstr = cp + 1; + cp = strchr(cp, ']'); + if (cp) { + cp[0] = '\0'; + cp++; + } else { + goto invalid; + } + } else if (*cp != ':') { + addrstr = cp; + cp = strrchr(cp, ':'); + } + if (cp && *cp == ':') { + *cp++ = '\0'; + portstr = cp; + if (!isnumber(cp)) + goto invalid; + } else if (cp && *cp) { + goto invalid; + } + } + + if (addrstr) + strlcpy(ep_str->addr, addrstr, sizeof(ep_str->addr)); + if (portstr) { + port = atoi(portstr); + if (port > 0 && port <= 0xffff) + ep_str->port = port; + else + goto invalid; + } + + free(dup); + return 1; + +invalid: + free(dup); + return 0; +} diff --git a/snmplib/transports/snmpIPv4BaseDomain.c b/snmplib/transports/snmpIPv4BaseDomain.c index 37ef72d4ed42..003e53a49e45 100644 --- a/snmplib/transports/snmpIPv4BaseDomain.c +++ b/snmplib/transports/snmpIPv4BaseDomain.c @@ -4,6 +4,7 @@ #include <net-snmp/net-snmp-config.h> #include <net-snmp/types.h> +#include <net-snmp/library/snmpIPBaseDomain.h> #include <net-snmp/library/snmpIPv4BaseDomain.h> #include <net-snmp/library/snmp_assert.h> @@ -56,6 +57,7 @@ int netsnmp_sockaddr_in2(struct sockaddr_in *addr, const char *inpeername, const char *default_target) { + struct netsnmp_ep_str ep_str; int ret; if (addr == NULL) { @@ -72,106 +74,42 @@ netsnmp_sockaddr_in2(struct sockaddr_in *addr, addr->sin_family = AF_INET; addr->sin_port = htons((u_short)SNMP_PORT); + memset(&ep_str, 0, sizeof(ep_str)); { int port = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DEFAULT_PORT); if (port != 0) { - addr->sin_port = htons((u_short)port); - } else if (default_target != NULL) + ep_str.port = port; + } else if (default_target != NULL) { netsnmp_sockaddr_in2(addr, default_target, NULL); - } - - if (inpeername != NULL && *inpeername != '\0') { - const char *host, *port; - char *peername = NULL; - char *cp; - /* - * Duplicate the peername because we might want to mank around with - * it. - */ - - peername = strdup(inpeername); - if (peername == NULL) { - return 0; - } - - /* - * Try and extract an appended port number. - */ - cp = strchr(peername, ':'); - if (cp != NULL) { - *cp = '\0'; - port = cp + 1; - host = peername; - } else { - host = NULL; - port = peername; + strlcpy(ep_str.addr, inet_ntoa(addr->sin_addr), sizeof(ep_str.addr)); + ep_str.port = ntohs(addr->sin_port); } + } - /* - * Try to convert the user port specifier - */ - if (port && *port == '\0') - port = NULL; - - if (port != NULL) { - long int l; - char* ep; - - DEBUGMSGTL(("netsnmp_sockaddr_in", "check user service %s\n", - port)); - - l = strtol(port, &ep, 10); - if (ep != port && *ep == '\0' && 0 <= l && l <= 0x0ffff) - addr->sin_port = htons((u_short)l); - else { - if (host == NULL) { - DEBUGMSGTL(("netsnmp_sockaddr_in", - "servname not numeric, " - "check if it really is a destination)\n")); - host = port; - port = NULL; - } else { - DEBUGMSGTL(("netsnmp_sockaddr_in", - "servname not numeric\n")); - free(peername); - return 0; - } - } - } - - /* - * Try to convert the user host specifier - */ - if (host && *host == '\0') - host = NULL; - - if (host != NULL) { - DEBUGMSGTL(("netsnmp_sockaddr_in", - "check destination %s\n", host)); - - - if (strcmp(peername, "255.255.255.255") == 0 ) { + if (inpeername && *inpeername != '\0') { + if (netsnmp_parse_ep_str(&ep_str, inpeername)) { + if (ep_str.port) + addr->sin_port = htons(ep_str.port); + if (strcmp(ep_str.addr, "255.255.255.255") == 0 ) { /* * The explicit broadcast address hack */ DEBUGMSGTL(("netsnmp_sockaddr_in", "Explicit UDP broadcast\n")); addr->sin_addr.s_addr = INADDR_NONE; } else { - ret = - netsnmp_gethostbyname_v4(peername, &addr->sin_addr.s_addr); + ret = netsnmp_gethostbyname_v4(ep_str.addr, + &addr->sin_addr.s_addr); if (ret < 0) { DEBUGMSGTL(("netsnmp_sockaddr_in", "couldn't resolve hostname\n")); - free(peername); return 0; } DEBUGMSGTL(("netsnmp_sockaddr_in", "hostname (resolved okay)\n")); } } - free(peername); } /* diff --git a/snmplib/transports/snmpIPv6BaseDomain.c b/snmplib/transports/snmpIPv6BaseDomain.c index b1c1afce3ded..600bc602428b 100644 --- a/snmplib/transports/snmpIPv6BaseDomain.c +++ b/snmplib/transports/snmpIPv6BaseDomain.c @@ -15,6 +15,7 @@ #ifdef NETSNMP_ENABLE_IPV6 #include <net-snmp/types.h> +#include <net-snmp/library/snmpIPBaseDomain.h> #include <net-snmp/library/snmpIPv6BaseDomain.h> #include <net-snmp/library/system.h> #include <net-snmp/library/snmp_assert.h> @@ -247,9 +248,7 @@ int netsnmp_sockaddr_in6_2(struct sockaddr_in6 *addr, const char *inpeername, const char *default_target) { - char *cp = NULL, *peername = NULL; char debug_addr[INET6_ADDRSTRLEN]; - int portno; if (addr == NULL) { return 0; @@ -275,205 +274,38 @@ netsnmp_sockaddr_in6_2(struct sockaddr_in6 *addr, } if (inpeername != NULL) { - /* - * Duplicate the peername because we might want to mank around with - * it. - */ - - peername = strdup(inpeername); - if (peername == NULL) { - return 0; - } - - cp = peername; - if (*cp == ':') cp++; - portno = atoi(cp); - while (*cp && isdigit((unsigned char) *cp)) cp++; - if (!*cp && portno != 0) { - /* - * Okay, it looks like JUST a port number. - */ - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", "totally numeric: %d\n", - portno)); - addr->sin6_port = htons((u_short)portno); - goto resolved; - } - - /* - * See if it is an IPv6 address covered with square brackets. Also check - * for an appended :port. - */ - if (*peername == '[') { - cp = strchr(peername, ']'); - if (cp != NULL) { - /* - * See if it is an IPv6 link-local address with interface - * name as <zone_id>, like fe80::1234%eth0. - * Please refer to the internet draft, IPv6 Scoped Address Architecture - * http://www.ietf.org/internet-drafts/draft-ietf-ipngwg-scoping-arch-04.txt - * - */ - char *scope_id; -#if HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID - unsigned int if_index = 0; -#endif - *cp = '\0'; - scope_id = strchr(peername + 1, '%'); - if (scope_id != NULL) { - *scope_id = '\0'; -#if HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID - if_index = netsnmp_if_nametoindex(scope_id + 1); -#endif - } - if (*(cp + 1) == ':') { - portno = atoi(cp+2); - if (portno != 0 && - inet_pton(AF_INET6, peername + 1, - (void *) &(addr->sin6_addr))) { - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", - "IPv6 address with port suffix :%d\n", - portno)); - if (portno > 0 && portno <= 0xffff) { - addr->sin6_port = htons((u_short)portno); - } else { - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", "invalid port number: %d", portno)); - free(peername); - return 0; - } - -#if defined(HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID) - addr->sin6_scope_id = if_index; -#endif - goto resolved; - } - } else { - if (inet_pton - (AF_INET6, peername + 1, - (void *) &(addr->sin6_addr))) { - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", - "IPv6 address with square brackets\n")); - portno = ntohs(addr->sin6_port); - if (portno == 0) - portno = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, - NETSNMP_DS_LIB_DEFAULT_PORT); - if (portno <= 0) - portno = SNMP_PORT; - addr->sin6_port = htons((u_short)portno); + struct netsnmp_ep_str ep_str; + + memset(&ep_str, 0, sizeof(ep_str)); + if (netsnmp_parse_ep_str(&ep_str, inpeername)) { + DEBUGMSGTL(("netsnmp_sockaddr_in6_2", "split: [%s]:%d", + ep_str.addr, ep_str.port)); + if (ep_str.addr[0]) { + char *scope_id; + + scope_id = strchr(ep_str.addr, '%'); + if (scope_id) { + *scope_id = '0'; #if defined(HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID) - addr->sin6_scope_id = if_index; -#endif - goto resolved; - } - } - if (scope_id != NULL) { - *scope_id = '%'; - } - *cp = ']'; - } - } - - cp = strrchr(peername, ':'); - if (cp != NULL) { - char *scope_id; -#if HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID - unsigned int if_index = 0; -#endif - *cp = '\0'; - scope_id = strchr(peername + 1, '%'); - if (scope_id != NULL) { - *scope_id = '\0'; -#if HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID - if_index = netsnmp_if_nametoindex(scope_id + 1); + addr->sin6_scope_id = netsnmp_if_nametoindex(scope_id + 1); #endif - } - portno = atoi(cp + 1); - if (portno != 0 && - inet_pton(AF_INET6, peername, - (void *) &(addr->sin6_addr))) { - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", - "IPv6 address with port suffix :%d\n", - atoi(cp + 1))); - if (portno > 0 && portno <= 0xffff) { - addr->sin6_port = htons((u_short)portno); - } else { - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", "invalid port number: %d", portno)); - free(peername); - return 0; } - -#if defined(HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID) - addr->sin6_scope_id = if_index; -#endif - goto resolved; - } - if (scope_id != NULL) { - *scope_id = '%'; - } - *cp = ':'; - } - - /* - * See if it is JUST an IPv6 address. - */ - if (inet_pton(AF_INET6, peername, (void *) &(addr->sin6_addr))) { - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", "just IPv6 address\n")); - goto resolved; - } - - /* - * Well, it must be a hostname then, possibly with an appended :port. - * Sort that out first. - */ - - cp = strrchr(peername, ':'); - if (cp != NULL) { - *cp = '\0'; - portno = atoi(cp + 1); - if (portno != 0) { - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", - "hostname(?) with port suffix :%d\n", - portno)); - if (portno > 0 && portno <= 0xffff) { - addr->sin6_port = htons((u_short)portno); - } else { - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", "invalid port number: %d", portno)); - free(peername); + if (!inet_pton(AF_INET6, ep_str.addr, &addr->sin6_addr) && + !netsnmp_resolve_v6_hostname(&addr->sin6_addr, ep_str.addr)) return 0; - } - - } else { - /* - * No idea, looks bogus but we might as well pass the full thing to - * the name resolver below. - */ - *cp = ':'; - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", - "hostname(?) with embedded ':'?\n")); } - /* - * Fall through. - */ + if (ep_str.port) + addr->sin6_port = htons(ep_str.port); } - if (peername[0] == '\0') { - DEBUGMSGTL(("netsnmp_sockaddr_in6_2", "empty hostname\n")); - free(peername); - return 0; - } - if (!netsnmp_resolve_v6_hostname(&addr->sin6_addr, peername)) { - free(peername); - return 0; - } } else { DEBUGMSGTL(("netsnmp_sockaddr_in6_2", "NULL peername")); return 0; } - resolved: DEBUGMSGTL(("netsnmp_sockaddr_in6_2", "return { AF_INET6, [%s]:%hu }\n", inet_ntop(AF_INET6, &addr->sin6_addr, debug_addr, sizeof(debug_addr)), ntohs(addr->sin6_port))); - free(peername); return 1; } diff --git a/win32/libsnmp/Makefile.in b/win32/libsnmp/Makefile.in index d5e173e9a124..88d24533abf6 100644 --- a/win32/libsnmp/Makefile.in +++ b/win32/libsnmp/Makefile.in @@ -55,6 +55,7 @@ LIB32_OBJS= \ "$(INTDIR)\snmp-tc.obj" \ "$(INTDIR)\snmp.obj" \ "$(INTDIR)\snmpCallbackDomain.obj" \ + "$(INTDIR)\snmpIPBaseDomain.obj" \ "$(INTDIR)\snmpIPv4BaseDomain.obj" \ "$(INTDIR)\snmpSocketBaseDomain.obj" \ "$(INTDIR)\snmpTCPBaseDomain.obj" \ diff --git a/win32/libsnmp_dll/Makefile.in b/win32/libsnmp_dll/Makefile.in index 3d05633b8856..bd36672dcdf4 100644 --- a/win32/libsnmp_dll/Makefile.in +++ b/win32/libsnmp_dll/Makefile.in @@ -55,6 +55,7 @@ LINK32_OBJS= \ "$(INTDIR)\snmp-tc.obj" \ "$(INTDIR)\snmp.obj" \ "$(INTDIR)\snmpCallbackDomain.obj" \ + "$(INTDIR)\snmpIPBaseDomain.obj" \ "$(INTDIR)\snmpIPv4BaseDomain.obj" \ "$(INTDIR)\snmpSocketBaseDomain.obj" \ "$(INTDIR)\snmpTCPBaseDomain.obj" \ -- 2.19.1 |
From: Nishikant D. <nis...@gm...> - 2018-10-27 20:49:40
|
Hi, In the example code in README.thread under Single API use http://www.net-snmp.org/docs/README.thread.html 1) Can an snmp_pdu be cloned and sent to multiple sessions? 2) If we are getting data in a loop, can we create SNMP PDU attach them to snmp_session created before the loop and release memory of snmp_session and close void * sessp after the loop? In short can the same snmp_session and void *sessp be used for multiple PDUs? Or we have to allocate both snmp_session and void *sessp for each PDU? netsnmp_session *session = (netsnmp_session *) malloc (sizeof(netsnmp_session); snmp_sess_init(session); void *sessp = snmp_sess_add(session, netsnmp_client, NULL, NULL); while (data) { ...create pdu ...Attach data to pdu if (0 == snmp_sess_send(sessp, pdu)) { snmp_sess_error(sessp, &liberr, &syserr, &errstr); printf("SNMP write error %s.\n", errstr); free(errstr); return 0; } } snmp_sess_close(sessp); Best Regards, Nishikant Deshmukh |
From: Denis H. <den...@gm...> - 2018-10-27 20:07:01
|
so i was hoping to use snmptrap to send snmp v3 traps because it is simple and already written. However I have some NMS systems that are pretty stringent about checking EngineBoots and EngineTime even for traps (I'm not using Inform). So far the nms always reports "message received outside time window" . Checking the snmp packets with tshark I can see that both EngineBoots and EngineTime are always zero. Looking at the snmptrap code it looks like by default it should be setting Boots to 1 and Time to "uptime" IF you don't pass specific values via -V on the command line. Throwing in some printfs I can see that the session struct is in fact populated with these values. I got lost following snmp_add and snmp_pdu_create but from what I can tell the session attributes for Boots and Time are never actually used to set the same in the raw pdu and thus all we get are zeros. Was curious if someone who knew the code better could confirm this is a bug and not some obvious miss on my part. Given how snmptrap is written I don't think it is supposed to get any data from a running agent (I'm trying to avoid running one) or from the persistent snmp conf files that other methods like agentx etc would use. I also skimmed through the mail archives and found what looked like similar questions in the past but without anyone addressing why setting the Boot and Time attributes via -V for snmptrap should not work. -denis -- __________________________ Denis Alan Hainsworth den...@gm... |
From: Mark C. <ma...@ma...> - 2018-10-27 15:05:21
|
On Fri, Oct 26, 2018 at 4:48 PM Magnus Fromreide <ma...@ly...> wrote: > On Mon, Oct 22, 2018 at 02:35:49PM +0000, Thibault Bartolone via > Net-snmp-coders wrote: > > > I'm going to keep wasting my time searching, because you could not spend > 1 hour to provide a crystal clear documentation. > > It would be helpful if you mentioned which part of the documentation you > found unhelpful and what you wish to see instead. > > For me it would be helpful if the snmpd proxy documentation at the following link used test.net-snmp.org for the proxied device. That would allow me to see proxy working with a known device before trying to proxy our own devices. http://net-snmp.sourceforge.net/wiki/index.php/Snmpd_proxy Mark. |