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 1 commit
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
51 changes: 30 additions & 21 deletions libraries/ESP8266WiFi/src/include/UdpContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,23 @@ class UdpContext

#endif // !LWIP_IPV6

/*
* Add a netif (by its index) as the multicast interface
*/
void setMulticastInterface(netif* p_pNetIf)
{
uint8_t mcast_ifindex = (p_pNetIf ? netif_get_index(p_pNetIf) : 0);
udp_set_multicast_netif_index(_pcb, mcast_ifindex);
}

/*
* 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 +222,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 +287,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 @@ -441,24 +462,13 @@ class UdpContext
const ip_addr_t *srcaddr, u16_t srcport)
{
(void) upcb;
// check receive pbuf chain depth
{
pbuf* p;
int count = 0;
for (p = _rx_buf; p && ++count < rxBufMaxDepth*2; p = p->next);
if (p)
{
// pbuf chain too deep, dropping
pbuf_free(pb);
DEBUGV(":udr\r\n");
return;
}
}

d-a-v marked this conversation as resolved.
Show resolved Hide resolved
#if LWIP_VERSION_MAJOR == 1
#define TEMPDSTADDR (&current_iphdr_dest)
#define TEMPINPUTNETIF todo
#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 +496,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 +510,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 +523,7 @@ class UdpContext
}

#undef TEMPDSTADDR
#undef TEMPINPUTNETIF

}

Expand Down Expand Up @@ -539,16 +551,13 @@ 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;

// rx pbuf depth barrier (counter of buffered UDP received packets)
// keep it small
static constexpr int rxBufMaxDepth = 4;
};


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