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

Added input_netif to the stored data #7004

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions libraries/ESP8266WiFi/src/include/UdpContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,26 @@ class UdpContext

#endif // !LWIP_IPV6

/*
* Add a netif (by its index) as the multicast interface
*/
void setMulticastInterface(netif* p_pNetIf)
{
#if LWIP_VERSION_MAJOR == 1
udp_set_multicast_netif_addr(_pcb, (p_pNetIf ? ip_2_ip4(p_pNetIf->ip_addr) : ip_addr_any));
Copy link
Collaborator

Choose a reason for hiding this comment

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

ip_2_ip4() is useless with lwIP-1.4

#define ip_2_ip4(x) (x)

#else
udp_set_multicast_netif_index(_pcb, (p_pNetIf ? netif_get_index(p_pNetIf) : 0));
#endif
}

/*
* Allow access to pcb to change eg. options
*/
udp_pcb* pcb(void)
{
return _pcb;
}

void setMulticastTTL(int ttl)
{
#ifdef LWIP_MAYBE_XCC
Expand Down Expand Up @@ -205,6 +225,11 @@ class UdpContext
return (pos <= _rx_buf->len);
}

netif* getInputNetif() const
{
return _currentAddr.input_netif;
}

CONST IPAddress& getRemoteAddress() CONST
{
return _currentAddr.srcaddr;
Expand Down Expand Up @@ -265,7 +290,6 @@ class UdpContext
// ref'ing it to prevent release from the below pbuf_free(deleteme)
pbuf_ref(_rx_buf);
}
// remove the already-consumed head of the chain
Copy link
Collaborator

@d-a-v d-a-v Jan 17, 2020

Choose a reason for hiding this comment

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

Perhaps it has to be replaced by
'remove parts of the pbuf chain that are not anymore "ref"ed'

pbuf_free(deleteme);

_rx_buf_offset = 0;
Expand Down Expand Up @@ -457,8 +481,10 @@ class UdpContext

d-a-v marked this conversation as resolved.
Show resolved Hide resolved
#if LWIP_VERSION_MAJOR == 1
#define TEMPDSTADDR (&current_iphdr_dest)
#define TEMPINPUTNETIF (current_netif)
#else
#define TEMPDSTADDR (ip_current_dest_addr())
#define TEMPINPUTNETIF (ip_current_input_netif())
#endif

// chain this helper pbuf first
Expand Down Expand Up @@ -486,7 +512,7 @@ class UdpContext
return;
}
// construct in place
new(PBUF_ALIGNER(pb_helper->payload)) AddrHelper(srcaddr, TEMPDSTADDR, srcport);
new(PBUF_ALIGNER(pb_helper->payload)) AddrHelper(srcaddr, TEMPDSTADDR, srcport, TEMPINPUTNETIF);
pb_helper->flags = PBUF_HELPER_FLAG; // mark helper pbuf
// chain it
pbuf_cat(_rx_buf, pb_helper);
Expand All @@ -500,6 +526,7 @@ class UdpContext
_currentAddr.srcaddr = srcaddr;
_currentAddr.dstaddr = TEMPDSTADDR;
_currentAddr.srcport = srcport;
_currentAddr.input_netif = TEMPINPUTNETIF;

DEBUGV(":urn %d\r\n", pb->tot_len);
_first_buf_taken = false;
Expand All @@ -512,6 +539,7 @@ class UdpContext
}

#undef TEMPDSTADDR
#undef TEMPINPUTNETIF

}

Expand Down Expand Up @@ -539,10 +567,11 @@ class UdpContext
{
IPAddress srcaddr, dstaddr;
int16_t srcport;
netif* input_netif;

AddrHelper() { }
AddrHelper(const ip_addr_t* src, const ip_addr_t* dst, uint16_t srcport):
srcaddr(src), dstaddr(dst), srcport(srcport) { }
AddrHelper(const ip_addr_t* src, const ip_addr_t* dst, uint16_t srcport, netif* input_netif):
srcaddr(src), dstaddr(dst), srcport(srcport), input_netif(input_netif) { }
};
AddrHelper _currentAddr;

Expand Down
2 changes: 1 addition & 1 deletion libraries/LittleFS/lib/littlefs