openbmc / phosphor-net-ipmid

Network IPMI server
Apache License 2.0
9 stars 11 forks source link

Support for incoming packets with the broadcast IP address #18

Open Kostr opened 3 years ago

Kostr commented 3 years ago

Recently ASF ping/pong message support have been merged to the repo (https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-net-ipmid/+/40982). This commit was created in response to the issue https://github.com/openbmc/phosphor-net-ipmid/issues/15 that I've submitted. This commit successfully added support for ASF ping/pong messages with the direct IP. Hovewer in my case I was getting messages with the IP set to broadcast and because of that it didn't solve my particular problem.

Through the debug I've discovered the source of the problem. Code in the Channel.read() function (https://github.com/openbmc/phosphor-net-ipmid/blob/29086950c2300fe8bd5791896b1209a31a1c93e6/socket_channel.hpp#L167) fills pktinfoX structures with the info from the incoming packet and use it later in the outgoing packet. But we can't use it as it is if the IP address in the incoming packet was set to broadcast. This would lead to fail of sendmsg function (https://github.com/openbmc/phosphor-net-ipmid/blob/29086950c2300fe8bd5791896b1209a31a1c93e6/socket_channel.hpp#L224) So in my case I had to add some code in the end of Channel.read() function.

// Setup source address with Local address in case
// header destination address in the received packet was broadcast
if (pktinfo4) {
    if ((*pktinfo4).ipi_addr.s_addr == 0xffffffff) {
        (*pktinfo4).ipi_addr.s_addr = (*pktinfo4).ipi_spec_dst.s_addr;
        if (pktinfo6) {
            (*pktinfo6).ipi6_addr.s6_addr32[3] = (*pktinfo4).ipi_spec_dst.s_addr;
        }
    }
}

I don't really know if there is a better solution to this problem but it have solved my issue. Also it seems to be a more general problem that is not related directly to ASF Ping/Pong support so I've decided to create a separate issue for it.

If my change is a valid approach I can make a patch to gerrit. If it is not, how to properly solve this?