从 Python 绑定重置 net-snmp 库的所有全局内部状态

发布于 2024-09-27 22:27:06 字数 593 浏览 10 评论 0原文

我正在尝试为这个硬件+软件测试主题创建自动化集成测试,该测试主题运行 SNMP 代理作为它的命令接口。我们的测试设置如下所示:我们使用 Fitnesse 作为测试运行程序,并使用 PyFit 来使用 Python 编写测试。然后,我们使用带有 Python 绑定的 netsnmp 来发送 SNMP 命令。这效果非常好。

然而,当我尝试运行一个套件时,SNMP 代理(测试对象)会重新启动(通常在不同的模拟时间),这使得 netsnmp 的内部出现各种有趣的错误。

事实证明,netsnmp 库中存储了很多全局状态,例如社区和上下文名称,以及有问题的 EngineTime 和 EngineBootCnt,它们用于防止 SNMP v3 中的重放攻击。这会导致代理拒绝我的 snmp 命令。

我的问题是如何以重置内部全局状态的方式重新初始化 netsnmp 库(从 Python 绑定)? Python 绑定中的 netsnmp.Session 对象确实采用参数 EngineTime 和 EngineBoots 并将它们设置为 0 应该重置它们,但实际上它似乎并没有这样做。我也不知道是否还有其他全局状态需要重置。

我现在认为我需要重写测试以使用纯 python snmp 库 pysnmp,但我希望避免它。

I'm trying to create automated integration tests for this hardware+software test subject which runs a SNMP agent as it's command interface. Our test setup looks like this: We're using Fitnesse as a test runner and PyFit to be able to write the tests in Python. We then use netsnmp with Python bindings to send SNMP commands. This works pretty well.

However, when I try to run a suite the SNMP agent (the test subject) is restarted (and usually at a different simulated time) which makes the internals of netsnmp get all sorts of interesting errors.

Turns out there is a lot of global state stored inside the netsnmp library like community and context names and problematically EngineTime and EngineBootCnt, which is used to prevent replay attacks in SNMP v3. This causes the agent to reject my snmp commands.

My problems is how do I reinitialise the netsnmp library (from the Python bindings) in a way that the internal global state are reset? The netsnmp.Session object in the Python bindings do take the parameter EngineTime and EngineBoots and setting them to 0 should reset them, but actually it doesn't seem to do that. I also do not know if there is other global state in there which needs to be reset.

I'm at a point where I think I need to rewrite the tests to use the pure python snmp library pysnmp, but I was hoping to avoid it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏日浅笑〃 2024-10-04 22:27:06

engineTime 和 engineBoots 值可能会让您感到困惑,因为 SNMPv3 要求它们不能倒退。如果您有一个从头开始重新启动的代理,并且不增加其靴子计数(这是非法的,但在测试中我可以明白您为什么要这样做),那么您需要重置靴子和时间的内部概念。

但是,将它们设置为 0 和 0 不会有帮助,因为它会假设这些是默认值。相反,您应该将其中之一更改为“1”,这将触发覆盖子句以实际使用这些值。将时间设置为 1 并尝试一下,我认为它会起作用(如果不起作用,请将它们都设置为 1 并尝试)。

The engineTime and engineBoots values are probably what is messing you up because SNMPv3 requires they not go backwards. If you have an agent that is restarting from scratch and not incrementing it's boots count (which is illegal, but under tests I could see why you'd be doing that) then you'd need to reset the internal notion of boots and time.

However, setting them to 0 and 0 won't help because it'll assume those are defaults. You should, instead, change one of them to '1' which should trigger the override clause to actually use the values. Set the time to 1 and try it and I think it'll work (and if it doesn't, set them both to 1 instead and try that).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文