[lwip-users] UDP pcb matching

0 views
Skip to first unread message

Bertrand Roussel

unread,
Jul 6, 2011, 4:40:23 AM7/6/11
to lwip-...@nongnu.org
Hi,

I built a DHCP server which can answer different IP address depending on which interface it received the request from.
In udp_input, when looking for a matching PCB, at some point there is a condition that match a PCB if:
* PCB local port and UDP packet dest port are the same
* UDP dest IP is broadcast

This is fine for single interface devices, however if there is multiple interfaces listening on the same port, only the last registered PCB that match get the packet.

I changed the second condition to:
* (UDP dest IP is broadcast) and (PCB local ip and netif local ip are the same)

udp.c @ line 182:
From:
#else  /* IP_SOF_BROADCAST_RECV */
           (broadcast))) {
#endif /* IP_SOF_BROADCAST_RECV */

To:
#else  /* IP_SOF_BROADCAST_RECV */
           (broadcast && ip_addr_cmp(&(pcb->local_ip), &(inp->ip_addr)) ))) {
#endif /* IP_SOF_BROADCAST_RECV */

It should work even when there is only one interface registered.

Bertrand

Kieran Mansley

unread,
Jul 29, 2011, 8:14:02 AM7/29/11
to Mailing list for lwIP users
On Wed, 2011-07-06 at 10:40 +0200, Bertrand Roussel wrote:
> Hi,
>
>
> I built a DHCP server which can answer different IP address depending
> on which interface it received the request from.
> In udp_input, when looking for a matching PCB, at some point there is
> a condition that match a PCB if:
> * PCB local port and UDP packet dest port are the same
> * UDP dest IP is broadcast
>
>
> This is fine for single interface devices, however if there is
> multiple interfaces listening on the same port, only the last
> registered PCB that match get the packet.
>
>
> I changed the second condition to:
> * (UDP dest IP is broadcast) and (PCB local ip and netif local ip are
> the same)

Apologies for the late reply, and thanks for sending in this fix.

Can you clarify what goes wrong in the existing code. Is it that we are
delivering it to one PCB when you're hoping it will got to lots of PCBs?
Or is it that we're delivering it to the wrong PCB?

Getting a bug filed for this on savannah (if it hasn't already) would be
very helpful as otherwise they're likely to get forgotten.

Kieran


_______________________________________________
lwip-users mailing list
lwip-...@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

gold...@gmx.de

unread,
Jul 29, 2011, 11:34:14 AM7/29/11
to Mailing list for lwIP users
Kieran Mansley wrote:
> Apologies for the late reply, and thanks for sending in this fix.
Another example of why bug reports should be sent to the bugtracker, not
to this list (or lwip-devel)!

> Can you clarify what goes wrong in the existing code. Is it that we are
> delivering it to one PCB when you're hoping it will got to lots of PCBs?
> Or is it that we're delivering it to the wrong PCB?
From reading the fix and knowing the code, I guess such broadcasts can
be passed to the wrong pcb if multiple pcbs are bound to the same port
but different local IP. Without the check added in the fix, incoming
broadcast-IP packets for that port are probably sent to the wrong pcb
(the one first in the queue).

> Getting a bug filed for this on savannah (if it hasn't already) would be
> very helpful as otherwise they're likely to get forgotten.
Exactly.

Simon

Reply all
Reply to author
Forward
0 new messages