|
From: | Romeo |
Subject: | Re: [lwip-devel] re-bin UDP pcbs on netif_set_ipaddr |
Date: | Fri, 29 Nov 2013 16:43:37 +0400 |
Hey everyone,
we stumbled upon the problem that we create a udp socket and bind it to a netifaddress on startup but then later load a config file that contains the current IP address. We go ahead and set that ip address using netif_set_addr().
What we found was that we couldn't send UDP broadcasts anymore on the old socket because the comparison in udp.c failed:
/* check if UDP PCB local IP address is correct
* this could be an old address if netif->ip_addr has changed */
if (!ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr))) {
/* local_ip doesn't match, drop the packet */
if (q != p) {
/* free the header pbuf */
pbuf_free(q);
q = NULL;
/* p is still referenced by the caller, and will live on */
}
we changed this by introducing the same mechanism that is done for listening tcp_pcbs on ip address change:
Index: Common/Source/LwIP_132/Source/core/netif.c
===================================================================
--- Common/Source/LwIP_132/Source/core/netif.c (revision 13186)
+++ Common/Source/LwIP_132/Source/core/netif.c (working copy)
@@ -309,7 +309,24 @@
}
}
#endif
- snmp_delete_ipaddridx_tree(netif);
+ struct udp_pcb *pcb;
+
+ if(netif && ipaddr) {
+ /* address is actually being changed? */
+ if ((ip_addr_cmp(ipaddr, &(netif->ip_addr))) == 0)
+ {
+ for (pcb = udp_pcbs; pcb != NULL; pcb = pcb->next) {
+ /* PCB bound to current local interface address? */
+ if ((!(ip_addr_isany(&(pcb->local_ip)))) &&
+ (ip_addr_cmp(&(pcb->local_ip), &(netif->ip_addr)))) {
+ /* The PCB is bound to the old ipaddr and
+ * is set to bound to the new one instead */
+ ip_addr_set(&(pcb->local_ip), ipaddr);
+ }
+ }
+ }
+ }
+ snmp_delete_ipaddridx_tree(netif);
snmp_delete_iprteidx_tree(0,netif);
/* set new IP address to netif */
ip_addr_set(&(netif->ip_addr), ipaddr);
is that a feasable solution for you guys or is there a specific reason why you don't rebind UDP sockets on IP address change?
kind regards,
Fabian
_______________________________________________
lwip-devel mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-devel
Roman Savrulin
Phone: +7 (921) 562 40 07
[Prev in Thread] | Current Thread | [Next in Thread] |