diff --git a/src/core/ipv4/icmp.c b/src/core/ipv4/icmp.c index d62ca00f..a335f558 100644 --- a/src/core/ipv4/icmp.c +++ b/src/core/ipv4/icmp.c @@ -72,9 +72,8 @@ icmp_input(struct pbuf *p, struct netif *inp) code = *(((u8_t *)p->payload)+1); switch (type) { case ICMP_ECHO: - if (((inp->flags & NETIF_FLAG_BROADCAST) && - ip_addr_isbroadcast(&iphdr->dest, &inp->netmask)) || - ip_addr_ismulticast(&iphdr->dest)) { + /* broadcast or multicast destination address? */ + if (ip_addr_isbroadcast(&iphdr->dest, inp) || ip_addr_ismulticast(&iphdr->dest)) { LWIP_DEBUGF(ICMP_DEBUG, ("Smurf.\n")); ICMP_STATS_INC(icmp.err); pbuf_free(p); diff --git a/src/core/ipv4/ip.c b/src/core/ipv4/ip.c index b1d84f6b..957adb26 100644 --- a/src/core/ipv4/ip.c +++ b/src/core/ipv4/ip.c @@ -241,7 +241,7 @@ ip_input(struct pbuf *p, struct netif *inp) { /* unicast to this interface address? */ if (ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr)) || /* or broadcast matching this interface network address? */ - (ip_addr_isbroadcast(&(iphdr->dest), &(netif->netmask)) && + (ip_addr_isbroadcast(&(iphdr->dest), netif) && ip_addr_maskcmp(&(iphdr->dest), &(netif->ip_addr), &(netif->netmask))) || /* or restricted broadcast? */ ip_addr_cmp(&(iphdr->dest), IP_ADDR_BROADCAST)) { @@ -274,7 +274,7 @@ ip_input(struct pbuf *p, struct netif *inp) { LWIP_DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: packet not for us.\n")); #if IP_FORWARD /* non-broadcast packet? */ - if (!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask))) { + if (!ip_addr_isbroadcast(&(iphdr->dest), inp)) { /* try to forward IP packet on (other) interfaces */ ip_forward(p, iphdr, inp); } @@ -349,8 +349,8 @@ ip_input(struct pbuf *p, struct netif *inp) { break; default: /* send ICMP destination protocol unreachable unless is was a broadcast */ - if (!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask)) && - !ip_addr_ismulticast(&(iphdr->dest))) { + if (!ip_addr_isbroadcast(&(iphdr->dest), inp) && + !ip_addr_ismulticast(&(iphdr->dest))) { p->payload = iphdr; icmp_dest_unreach(p, ICMP_DUR_PROTO); } diff --git a/src/core/ipv4/ip_addr.c b/src/core/ipv4/ip_addr.c index 7e5e9985..53618ed2 100644 --- a/src/core/ipv4/ip_addr.c +++ b/src/core/ipv4/ip_addr.c @@ -41,27 +41,25 @@ const struct ip_addr ip_addr_broadcast = { 0xffffffffUL }; * as it does not support non-broadcast interfaces. * lwip-devel 18-2-2004 */ -#if 0 +#if 1 /* replaces macro in ip_addr.h */ #include "lwip/netif.h" -bool ip_addr_isbroadcast(ip_addr *addr1, struct netif *netif) - -bool ip_addr_isbroadcast(addr1, netif) +u8_t ip_addr_isbroadcast(struct ip_addr *addr, netif) { /* all ones (broadcast) or all zeroes (old skool broadcast) */ - if (addr1->addr == ip_addr_broadcast.ip_addr) || - addr1->addr == ip_addr_any.ip_addr)) + if (addr->addr == ip_addr_broadcast.ip_addr) || + addr->addr == ip_addr_any.ip_addr)) return 1; /* no broadcast support on this network interface * we cannot proceed matching against broadcast addresses */ else if (netif->flags &= NETIF_FLAG_BROADCAST == 0) return 0; - /* address matches network interface address exactly? */ - else if (netif->ip_addr.addr == addr1->addr) + /* address matches network interface address exactly? => no broadcast */ + else if (addr->addr == netif->ip_addr.addr) return 0; - /* host identifier bits are all ones? => broadcast address */ - else if (~netif->netmask.addr & addr1->addr == - ~netif->netmask.addr & ip_addr_broadcast.ip_addr) + /* host identifier bits are all ones? => network broadcast address */ + else if (addr->addr & ~netif->netmask.addr == + ip_addr_broadcast.ip_addr & ~netif->netmask.addr) return 1; else return 0; diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index 45628fb8..687fa14b 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -130,9 +130,8 @@ tcp_input(struct pbuf *p, struct netif *inp) } /* Don't even process incoming broadcasts/multicasts. */ - if (((inp->flags & NETIF_FLAG_BROADCAST) && - ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask))) || - ip_addr_ismulticast(&(iphdr->dest))) { + if (ip_addr_isbroadcast(&(iphdr->dest), inp) || + ip_addr_ismulticast(&(iphdr->dest))) { pbuf_free(p); return; } diff --git a/src/core/udp.c b/src/core/udp.c index 4f318133..1078514d 100644 --- a/src/core/udp.c +++ b/src/core/udp.c @@ -309,11 +309,10 @@ udp_input(struct pbuf *p, struct netif *inp) LWIP_DEBUGF(UDP_DEBUG | DBG_TRACE, ("udp_input: not for us.\n")); /* No match was found, send ICMP destination port unreachable unless - destination address was broadcast/multicast. */ + destination address was broadcast/multicast. */ - if (!((inp->flags & NETIF_FLAG_BROADCAST) && - ip_addr_isbroadcast(&iphdr->dest, &inp->netmask)) && - !ip_addr_ismulticast(&iphdr->dest)) { + if (!ip_addr_isbroadcast(&iphdr->dest, inp) && + !ip_addr_ismulticast(&iphdr->dest)) { /* adjust pbuf pointer */ p->payload = iphdr; diff --git a/src/include/ipv4/lwip/ip_addr.h b/src/include/ipv4/lwip/ip_addr.h index 6b142eec..0f66a935 100644 --- a/src/include/ipv4/lwip/ip_addr.h +++ b/src/include/ipv4/lwip/ip_addr.h @@ -110,10 +110,14 @@ extern const struct ip_addr ip_addr_broadcast; #define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0) +u8_t ip_addr_isbroadcast(ip_addr *addr1, struct netif *netif); + +#if 0 /* replaced by function in ip_addr.c */ #define ip_addr_isbroadcast(addr1, mask) (((((addr1)->addr) & ~((mask)->addr)) == \ (0xffffffff & ~((mask)->addr))) || \ ((addr1)->addr == 0xffffffff) || \ ((addr1)->addr == 0x00000000)) +#endif #define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000)) == ntohl(0xe0000000)) diff --git a/src/netif/etharp.c b/src/netif/etharp.c index 8d34923b..2c17a942 100644 --- a/src/netif/etharp.c +++ b/src/netif/etharp.c @@ -646,8 +646,7 @@ etharp_output(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q) ARP table. */ /* destination IP address is an IP broadcast address? */ - if (ip_addr_isany(ipaddr) || - ip_addr_isbroadcast(ipaddr, &(netif->netmask))) { + if (ip_addr_isany(ipaddr) || ip_addr_isbroadcast(ipaddr, netif)) { /* broadcast on Ethernet also */ dest = (struct eth_addr *)ðbroadcast; } diff --git a/src/netif/ethernetif.c b/src/netif/ethernetif.c index f024661d..b2a8315a 100644 --- a/src/netif/ethernetif.c +++ b/src/netif/ethernetif.c @@ -210,8 +210,7 @@ ethernetif_output(struct netif *netif, struct pbuf *p, multicasts are special, all other addresses are looked up in the ARP table. */ queryaddr = ipaddr; - if (ip_addr_isany(ipaddr) || - ip_addr_isbroadcast(ipaddr, &(netif->netmask))) { + if (ip_addr_isany(ipaddr) || ip_addr_isbroadcast(ipaddr, netif)) { dest = (struct eth_addr *)ðbroadcast; } else if (ip_addr_ismulticast(ipaddr)) { /* Hash IP multicast address to MAC address. */