troglobit / mini-snmpd

A minimal SNMP agent implementation
https://troglobit.com/projects/mini-snmpd/
GNU General Public License v2.0
69 stars 36 forks source link

big endian / little endian issue #20

Closed fraviofii closed 4 years ago

fraviofii commented 4 years ago

Hello,

I could compile correctly mini-snmp from git and run on my PC.

Then I cross compiled the same project to a NIOS processor gcc. The compilation was successful and the binary ran on my target board.

But when I tried to capture the information using snmpwalk command remotely, the binary crashes at the target.

I have the following message:

Listening on port 161/udp and 161/tcp
Failed creating PID file: No such file or directory

Failed UDP request from 192.168.100.10:45810: Invalid argument
Failed updating OID '.1.3.6.1.4.1.2021.10.1.5.1': OID not found

The same command on PC works fine.

I believe that this issue is related to little endian and big endian bytes management for TLV parsing.

Does anybody had similar problems and what should I have to do to solve it?

troglobit commented 4 years ago

Interesting, I haven't tried running on a big endurance target yet. I thought Nios was little endian?

Anyway, try hooking up gdb to it. If you don't have gdb (or symbols) you can run gdbserver on your target and use gdb-multiarch from your host to connect to it an load symbols.

fraviofii commented 4 years ago

In fact, I found out that NIOS processor is also little endian.

Now I am checking if this problem can be related to alignment, based on the suggestion of the following link: https://forums.intel.com/s/question/0D50P00003yyJDxSAM/nios-little-endian-or-big-endian?language=pt_br

fraviofii commented 4 years ago

Unfortunately I don't have gdb infrastructure for debugging. The mini-snmpd is running on a separate hardware and I count on log messages for debugging.

I got some progress here. These are my log messages:

updating the MIB (partial)
received 45 bytes from 192.168.100.10:56390 (30 2B 02 01 01 04 04 75 73 65 72 A0 20 02 04 6C 6F 51 5E 02 01 00 02 01 00 30 12 30 10 06 0C 2B 06 01 04 01 81 C3 42 01 03 02 00 05 00)
underflow for element type
Failed UDP request from 192.168.100.10:18140: Invalid argument

Do you have any clue of what is going on?

troglobit commented 4 years ago

Nope, no clue.

I'd still recommend spending time cross compiling gdbserver for your target. It's quite small and has no dependencies. It's time well spent.

fraviofii commented 4 years ago

I found the cause of the problem. The reason is that the client structure is arriving correctly but the software was having problems to access its internal values.

The compiler is very old (nio2-linux-gcc 3.4.6). It didn't understand very well when structs are passed as reference in functions.

The solution was to replace the client, request and response structures as globals and access it directly. Then it worked very well.

In PC (and probably in newer and current version of GCC) it must work correctly.

And regarding gdb server, in the platform that I have here there is no support for gdb :-(

troglobit commented 4 years ago

I see. Oh well, then maybe we can close this issue, right?

fraviofii commented 4 years ago

Yes, absolutely.