Re: Reconfigure snmpd listening ports

Craig Small via Net-snmp-coders <[email protected]> Wed, 18 Sep 2024 22:35:05 +1000
Newsgroups gmane.network.net-snmp.devel
Message-ID <CALy8Cw6Z5-6KbKV2QiKyFNSP_2wGLk5fgeOFh4X30o8eXHLyeg@mail.gmail.com>
--===============8548607539714141517==
Content-Type: multipart/alternative; boundary="000000000000e0324c062264094c"

--000000000000e0324c062264094c
Content-Type: text/plain; charset="UTF-8"

On Mon, 16 Sept 2024 at 22:44, Teus Benschop <[email protected]> wrote:

> The daemon kept the same ports open as before editing the snmpd.conf even
> in case some agentaddress entries were removed from snmpd.conf.
>
Some changes to the configuration file can be enabled with a reload or HUP
and some things need a complete restart.

Changing ports is one of those complete restart things.

There might be many reasons for it, but one of them would be that binding
to low ports needs root (or capabilities)
but you can also change to a different user after binding the ports. Once
you're non root, there's no going back
so binding to ports could fail.

Interestingly enough, that "snmpd restarted" message is in
snmpd_reconfig(). Technically it's not restarting.

The port bindings happen in init_master_agent() with the repeated calls in
netsnmp_agent_listen_on()
In theory you could do a bunch of nsap_unregisters then copy that do-while
loop into snmpd_reconfig() but I think the end-result
is something that sort of does what you want but breaks in new interesting
random ways because I'm sure something somewhere
in snmpd assumes the NSAPs (the sockets effectively) remain the same.

If I needed to shift ports around dynamically, I'd approach it from
restarting the daemon and saving the state somehow
or do some funky DNAT/load balancer type thing that moved the ports for me
and left snmpd alone.

--000000000000e0324c062264094c
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto"><div dir=3D"ltr"><div dir=3D"ltr">On Mon, 16 Sept 2024 at=
 22:44, Teus Benschop &lt;<a href=3D"mailto:[email protected]" target=
=3D"_blank" rel=3D"noreferrer">[email protected]</a>&gt; wrote:</div><=
div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"margin=
:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"=
><div dir=3D"ltr">The daemon kept the same ports open as before editing the=
 snmpd.conf even in case some agentaddress entries were removed from snmpd.=
conf.</div></blockquote><div>Some changes to the configuration file can be =
enabled with a reload or HUP and some things need a complete restart.</div>=
<div><br></div><div>Changing ports is one of those complete restart things.=
</div><div><br></div><div>There might be many reasons for it, but one of th=
em would be that binding to low ports needs root (or capabilities)</div><di=
v>but you can also change to a different user after binding the ports. Once=
 you&#39;re non root, there&#39;s no going back</div><div>so binding to por=
ts could fail.<br></div><div><br></div><div>Interestingly enough, that &quo=
t;snmpd restarted&quot; message is in snmpd_reconfig(). Technically it&#39;=
s not restarting.</div><div><br></div><div>The port bindings happen in init=
_master_agent() with the repeated calls in netsnmp_agent_listen_on()</div><=
div>In theory you could do a bunch of nsap_unregisters then copy that do-wh=
ile loop into snmpd_reconfig() but I think the end-result</div><div>is some=
thing that sort of does what you want but breaks in new interesting random =
ways because I&#39;m sure something somewhere</div><div>in snmpd assumes th=
e NSAPs (the sockets effectively) remain the same.</div><div><br></div><div=
>If I needed to shift ports around dynamically, I&#39;d approach it from re=
starting the daemon and saving the state somehow</div><div>or do some funky=
 DNAT/load balancer type thing that moved the ports for me and left snmpd a=
lone.</div></div></div></div>

--000000000000e0324c062264094c--


--===============8548607539714141517==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============8548607539714141517==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

--===============8548607539714141517==--