From ca94b4a2a27f942147a75a5ffd53af8db583d677 Mon Sep 17 00:00:00 2001 From: Juraj Andrassy Date: Sun, 11 Oct 2020 14:40:02 +0200 Subject: [PATCH] EthernetUdp - prevent filtering of received messages by IP and port of sent message --- src/Ethernet.cpp | 2 +- src/EthernetUdp.cpp | 16 ++++++++++++++-- src/EthernetUdp.h | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Ethernet.cpp b/src/Ethernet.cpp index 44863b1..919003d 100644 --- a/src/Ethernet.cpp +++ b/src/Ethernet.cpp @@ -262,7 +262,7 @@ UIPEthernetClass::tick() // uip_len is set to a value > 0. */ if (uip_len > 0) { - EthernetUDP::_send((uip_udp_userdata_t *)(uip_udp_conns[i].appstate)); + EthernetUDP::_send(&uip_udp_conns[i]); } } #endif /* UIP_UDP */ diff --git a/src/EthernetUdp.cpp b/src/EthernetUdp.cpp index b03cd7d..bbfd2ae 100644 --- a/src/EthernetUdp.cpp +++ b/src/EthernetUdp.cpp @@ -90,6 +90,9 @@ UIPUDP::beginPacket(IPAddress ip, uint16_t port) #endif if (_uip_udp_conn) { + // [J.A]: for UDP server, setting ripaddr and rport causes in uIP filtering + // of incoming messages. it would be better to store the IP and port in fields + // and set them only in endPacket(). _uip_udp_conn->rport = htons(port); uip_ipaddr_copy(_uip_udp_conn->ripaddr, &ripaddr); } @@ -170,7 +173,7 @@ UIPUDP::endPacket() uip_udp_periodic_conn(_uip_udp_conn); if (uip_len > 0) { - _send(&appdata); + _send(_uip_udp_conn); return 1; } } @@ -359,7 +362,8 @@ uipudp_appcall(void) { } void -UIPUDP::_send(uip_udp_userdata_t *data) { +UIPUDP::_send(struct uip_udp_conn *uip_udp_conn) { + uip_arp_out(); //add arp if (uip_len == UIP_ARPHDRSIZE) { @@ -373,9 +377,17 @@ UIPUDP::_send(uip_udp_userdata_t *data) { else //arp found ethaddr for ip (otherwise packet is replaced by arp-request) { + uip_udp_userdata_t* data = (uip_udp_userdata_t *)(uip_udp_conn->appstate); UIPEthernetClass::network_send(); data->send = false; data->packet_out = NOBLOCK; + + // [J.A] a listening UDP port in uIP filters received messages + // if rport and ripaddr are set. so we better clear them + uip_udp_conn->rport = 0; + uip_udp_conn->ripaddr[0] = 0; + uip_udp_conn->ripaddr[1] = 0; + #ifdef UIPETHERNET_DEBUG_UDP Serial.print(F("udp, uip_packet to send: ")); Serial.println(UIPEthernetClass::uip_packet); diff --git a/src/EthernetUdp.h b/src/EthernetUdp.h index df7d4bc..43d27ca 100644 --- a/src/EthernetUdp.h +++ b/src/EthernetUdp.h @@ -129,7 +129,7 @@ class EthernetUDP : public UDP friend void uipudp_appcall(void); friend class UIPEthernetClass; - static void _send(uip_udp_userdata_t *data); + static void _send(struct uip_udp_conn *uip_udp_conn); static uint8_t _newBlock(uip_udp_msg_rec_t* blocks); static void _moveBlocks(uip_udp_msg_rec_t* blocks);