ARMmbed / sal-stack-lwip

LwIP package for mbed
Other
4 stars 14 forks source link

recv_from() returns incorrect remote {ipaddr, port} tuple for udp rx packet data #41

Closed simonqhughes closed 8 years ago

simonqhughes commented 8 years ago

recv_from() returns incorrect remote {ipaddr, port} tuple for udp rx packet data

Problem:

  socket_types.h defines this:

  typedef void (*socket_api_handler_t)(void);

  socket_api.h defines this which uses the handler:

    typedef socket_error_t (*socket_create)(struct socket *socket,
            const socket_address_family_t af, const socket_proto_family_t pf,
            socket_api_handler_t const handler);  

The problem is that the handler had no context argument (better to be void* ctx rather than void), so ctx can be cast to a type to access variable shared between the callback and the mainline code. The disadvantages of this are:

in socket_abstract_test.cpp:
        static struct socket *client_socket;
        static volatile bool client_event_done;
        static volatile bool client_rx_done;
        static volatile bool client_tx_done;
        static volatile struct socket_tx_info client_tx_info;
        static volatile struct socket_event client_event

Reproducing BUG01 Problem:

Traces similar to the following will be captured:

defect_report.txt iotsfw_num_tbd_console_trace.txt

iotsfw_num_tbd_sal_stack_lwip_recv_from_returns_incorrect_sockaddr_info_for_remote ipaddr_port_tupl_20160113_pcapng.txt iotsfw_num_tbd__20160113_pcapng.txt

sal_test_api_h.txt sal_udpserver_py.txt socket_abstract_test_cpp.txt udp_echo_client_orig_cpp.txt

ciarmcom commented 8 years ago

ARM Internal Ref: IOTSFW-1788

bremoran commented 8 years ago

@niklas-arm, I believe you've seen something similar to this. Did you have a fix in mind?

simonqhughes commented 8 years ago

Hi A further observation is that if the udp socket create(), bind(), connect() idiom is used then after the connect the socket is not bound correctly to the interface, but rather the local address is still reported as INADDR_ANY, as shown in the following console trace:

MBED: remote udp server:10.2.203.21:49659
MBED: udp local after bind():0.0.0.0:49153
MBED: udp local after connect():0.0.0.0:49153
MBED: udp_ec_tx_rx_from_test:289 ret!=0 [FAIL]
HOST: Received 32 bytes of data
HOST: Sent 32 bytes of data
 MBED: [FAIL] connect() failed as connected local address (0.0.0.0) doesnt match ethernet i/f ip address 10.2.203.161)

How to reproduce this problem:

Best Simon

bremoran commented 8 years ago

Fixed in #48