mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-27 03:35:38 +00:00
Replaced ip_addr_isbroadcast() macro by function.
Overrides patch #2679, as this must be solved inside ip_addr_isbroadcast(), inspired by BSD.
This commit is contained in:
parent
6434f7efad
commit
10d42c6fa3
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user