minor: Cleanups in raw/tcp/udp code by using macros and reducing #ifdefs

This commit is contained in:
Dirk Ziegelmeier 2016-02-24 23:04:25 +01:00
parent 953b7bdd59
commit fd891081c4
3 changed files with 8 additions and 11 deletions

View File

@ -106,7 +106,7 @@ raw_input(struct pbuf *p, struct netif *inp)
/* loop through all raw pcbs until the packet is eaten by one */
/* this allows multiple pcbs to match against the packet by design */
while ((eaten == 0) && (pcb != NULL)) {
if ((pcb->protocol == proto) && (ip_current_is_v6() == IP_IS_V6_VAL(pcb->local_ip)) &&
if ((pcb->protocol == proto) && IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ip_current_dest_addr()) &&
(ip_addr_isany(&pcb->local_ip) ||
ip_addr_cmp(&pcb->local_ip, ip_current_dest_addr()))) {
#if IP_SOF_BROADCAST_RECV

View File

@ -133,10 +133,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
}
/* Don't even process incoming broadcasts/multicasts. */
if (
#if LWIP_IPV4
(!ip_current_is_v6() && ip_addr_isbroadcast(ip_current_dest_addr(), ip_current_netif())) ||
#endif /* LWIP_IPV4 */
if (ip_addr_isbroadcast(ip_current_dest_addr(), ip_current_netif()) ||
ip_addr_ismulticast(ip_current_dest_addr())) {
TCP_STATS_INC(tcp.proterr);
goto dropped;
@ -269,7 +266,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
#endif /* SO_REUSE */
} else
#endif /* LWIP_IPV4 && LWIP_IPV6 */
if (ip_current_is_v6() == IP_IS_V6_VAL(lpcb->local_ip)) {
if (IP_ADDR_PCB_VERSION_MATCH_EXACT(lpcb, ip_current_dest_addr())) {
if (ip_addr_cmp(&lpcb->local_ip, ip_current_dest_addr())) {
/* found an exact match */
break;

View File

@ -147,9 +147,9 @@ again:
* @return 1 on match, 0 otherwise
*/
static u8_t
udp_input_local_match(struct udp_pcb *pcb, struct netif *netif, u8_t broadcast)
udp_input_local_match(struct udp_pcb *pcb, struct netif *inp, u8_t broadcast)
{
LWIP_UNUSED_ARG(netif); /* in IPv6 only case */
LWIP_UNUSED_ARG(inp); /* in IPv6 only case */
LWIP_UNUSED_ARG(broadcast); /* in IPv6 only case */
/* Dual-stack: PCBs listening to any IP type also listen to any IP address */
@ -163,7 +163,7 @@ udp_input_local_match(struct udp_pcb *pcb, struct netif *netif, u8_t broadcast)
}
/* Only need to check PCB if incoming IP version matches PCB IP version */
if(ip_current_is_v6() == IP_IS_V6_VAL(pcb->local_ip)) {
if(IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ip_current_dest_addr())) {
LWIP_ASSERT("UDP PCB: inconsistent local/remote IP versions", IP_IS_V6_VAL(pcb->local_ip) == IP_IS_V6_VAL(pcb->remote_ip));
#if LWIP_IPV4
@ -176,7 +176,7 @@ udp_input_local_match(struct udp_pcb *pcb, struct netif *netif, u8_t broadcast)
{
if(ip4_addr_isany(ip_2_ip4(&pcb->local_ip)) ||
((ip4_current_dest_addr()->addr == IPADDR_BROADCAST)) ||
ip4_addr_netcmp(ip_2_ip4(&pcb->local_ip), ip4_current_dest_addr(), netif_ip4_netmask(netif))) {
ip4_addr_netcmp(ip_2_ip4(&pcb->local_ip), ip4_current_dest_addr(), netif_ip4_netmask(inp))) {
return 1;
}
}