[erlang-bugs] bind_to is ignored in snmpm_net_if

Raimo Niskanen raimo+erlang-bugs@REDACTED
Tue Sep 30 12:25:34 CEST 2014


On Mon, Sep 29, 2014 at 01:29:54PM +0400, Pavel Baturko wrote:
> Hi,
> 
> I'm looking into erlang snmp manager code because my manager stops working
> when I updated erlang from 17.1 to 17.3.
> 
> The problem is that in otp/lib/snmp/src/manager/snmpm_net_if.erl (github
> erlang/otp, branch maint) in function socket_params parameter BindTo is
> ignored in case of Family==inet and init
> :get_argument(snmp_fd)==error:
> 
> socket_params(Domain, {IpAddr, IpPort}, BindTo, CommonSocketOpts) ->
>     ...
>     case Family of
>     inet ->
>         case init:get_argument(snmp_fd) of
>         {ok, [[FdStr]]} ->
>             ...
>         error ->
>             {IpPort, [{ip, IpAddr} | SocketOpts]} <<<<<<<< *
>         end;
>     _ ->
>         ...
>     end.
> 
> *: here ip option is added regardless of BindTo argument.
> 
> in other cases branches this option is utilized.
> 
> When address option is not specified in manager.conf snmp manager uses
> 127.0.0.1 as default and socket is binding to 127.0.0.1. After that all
> gen_upd:send fails with einval.

Yes that is a bug.  Thank you for reporting it.
You can try this patch:

diff --git a/lib/snmp/src/manager/snmpm_net_if.erl b/lib/snmp/src/manager/snmpm_net_if.erl
index cb72871..b4cc165 100644
--- a/lib/snmp/src/manager/snmpm_net_if.erl
+++ b/lib/snmp/src/manager/snmpm_net_if.erl
@@ -319,7 +319,7 @@ socket_open(IpPort, SocketOpts) ->
 	    Socket
     end.
 
-socket_params(Domain, {IpAddr, IpPort}, BindTo, CommonSocketOpts) ->
+socket_params(Domain, {IpAddr, IpPort} = Addr, BindTo, CommonSocketOpts) ->
     Family = snmp_conf:tdomain_to_family(Domain),
     SocketOpts =
 	case Family of
@@ -340,15 +340,18 @@ socket_params(Domain, {IpAddr, IpPort}, BindTo, CommonSocketOpts) ->
 			    {0, [{fd, Fd} | SocketOpts]}
 		    end;
 		error ->
-		    {IpPort, [{ip, IpAddr} | SocketOpts]}
+		    socket_params(SocketOpts, Addr, BindTo)
 	    end;
 	_ ->
-	    case BindTo of
-		true ->
-		    {IpPort, [{ip, IpAddr} | SocketOpts]};
-		_ ->
-		    {IpPort, SocketOpts}
-	    end
+	    socket_params(SocketOpts, Addr, BindTo)
+    end.
+%%
+socket_params(SocketOpts, {IpAddr, IpPort}, BindTo) ->
+    case BindTo of
+	true ->
+	    {IpPort, [{ip, IpAddr} | SocketOpts]};
+	_ ->
+	    {IpPort, SocketOpts}
     end.
 
 common_socket_opts(Opts) ->


Best Regards
/ Raimo Niskanen, Erlang/OTP

> 
> Thanks,
> Pavel

> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://erlang.org/mailman/listinfo/erlang-bugs


-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-bugs mailing list