Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gnrc, nanocoap: add optional work-arounds for buggy CoAP servers #20564

Merged
merged 2 commits into from
Apr 25, 2024

Conversation

benpicco
Copy link
Contributor

Contribution description

When working with go-coap we need to add several work-arounds:

Testing procedure

Issues/PRs references

plgd-dev/go-coap#512

If a server has e.g. multiple global IPv6 addresses, it might
respond with a different address that the one it received the request on.

This is against the CoAP spec, but that doesn't stop existing implementations
from doing it.
@github-actions github-actions bot added Area: network Area: Networking Area: CoAP Area: Constrained Application Protocol implementations Area: sys Area: System labels Apr 10, 2024
@benpicco benpicco changed the title gnrc/nanocoap: add optional work-arounds for buggy CoAP servers gnrc, nanocoap: add optional work-arounds for buggy CoAP servers Apr 10, 2024
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 10, 2024
@benpicco benpicco requested a review from bergzand April 10, 2024 10:52
@riot-ci
Copy link

riot-ci commented Apr 10, 2024

Murdock results

✔️ PASSED

13fd806 nanocoap_sock: add option to include token for block-wise

Success Failures Total Runtime
10044 0 10045 14m:32s

Artifacts

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a cursory look at the code, I see that mainly gnrc_sock is touched in the GNRC code. Do other sock implementations also need fixes then?

@benpicco
Copy link
Contributor Author

At a glance it appears as if LWIP does not enforce this in the first place, I didn't test it though.

@miri64
Copy link
Member

miri64 commented Apr 15, 2024

At a glance it appears as if LWIP does not enforce this in the first place, I didn't test it though.

And what about OpenWSN and OpenThread?

@fabian18
Copy link
Contributor

I don´t find where or how it is called but seems like Openthread wants it to match if the socket is connected.
udp6.c

bool Udp::SocketHandle::Matches(const MessageInfo &aMessageInfo) const
{
    bool matches = false;

    VerifyOrExit(GetSockName().mPort == aMessageInfo.GetSockPort(), OT_NOOP);

    VerifyOrExit(aMessageInfo.GetSockAddr().IsMulticast() || GetSockName().GetAddress().IsUnspecified() ||
                     GetSockName().GetAddress() == aMessageInfo.GetSockAddr(),
                 OT_NOOP);

    // Verify source if connected socket
    if (GetPeerName().mPort != 0)
    {
        VerifyOrExit(GetPeerName().mPort == aMessageInfo.GetPeerPort(), OT_NOOP);

        VerifyOrExit(GetPeerName().GetAddress().IsUnspecified() ||
                         GetPeerName().GetAddress() == aMessageInfo.GetPeerAddr(),
                     OT_NOOP);
    }

    matches = true;

exit:
    return matches;
}

@fabian18
Copy link
Contributor

I don´t find where or how it is called

Within the List implementation it is used.

    /**
     * This template method searches within the linked list to find an entry matching a given indicator.
     *
     * The template type `Indicator` specifies the type of @p aIndicator object which is used to match against entries
     * in the list. To check that an entry matches the given indicator, the `Matches()` method is invoked on each
     * `Type` entry in the list. The `Matches()` method should be provided by `Type` class accordingly:
     *
     *     bool Type::Matches(const Indicator &aIndicator) const
     *
     * @param[in]  aIndicator  An indicator to match with entries in the list..
     * @param[out] aPrevEntry  A pointer to output the previous entry on success (when a match is found in the list).
     *                         @p aPrevEntry is set to nullptr if the matching entry is the head of the list. Otherwise
     *                         it is updated to point to the previous entry before the matching entry in the list.
     *
     * @returns A pointer to the matching entry if one is found, or nullptr if no matching entry was found.
     *
     */
    template <typename Inidcator> const Type *FindMatching(const Inidcator &aIndicator, const Type *&aPrevEntry) const
    {
        const Type *entry;

        aPrevEntry = nullptr;

        for (entry = mHead; entry != nullptr; aPrevEntry = entry, entry = entry->GetNext())
        {
            if (entry->Matches(aIndicator))
            {
                break;
            }
        }

        return entry;
    }

@fabian18
Copy link
Contributor

For openwsn it is implemented by RIOT.

pkg/openwsn/sock/openwsn_sock_udp.c::484

    if ((sock->gen_sock.remote.family != AF_UNSPEC) &&
        /* check remote end-point if set */
        ((sock->gen_sock.remote.port != pkt->l4_sourcePortORicmpv6Type) ||
         /* We only have IPv6 for now, so just comparing the whole end point
          * should suffice */
         ((memcmp(&sock->gen_sock.remote.addr, &ipv6_addr_unspecified,
                  sizeof(ipv6_addr_t)) != 0) &&
          (memcmp(&sock->gen_sock.remote.addr, &ep.addr,
                  sizeof(ipv6_addr_t)) != 0)))) {
        openqueue_freePacketBuffer(pkt);
        return -EPROTO;
    }

Copy link
Contributor

@fabian18 fabian18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a workaround I would say it is ok as is, unless @miri64 objects.

@benpicco benpicco added this pull request to the merge queue Apr 24, 2024
Merged via the queue into RIOT-OS:master with commit 9761456 Apr 25, 2024
28 checks passed
@benpicco benpicco deleted the go-coap_workaround branch April 25, 2024 09:04
@mguetschow mguetschow added this to the Release 2024.07 milestone Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CoAP Area: Constrained Application Protocol implementations Area: network Area: Networking Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants