mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-06 06:39:46 +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);
|
code = *(((u8_t *)p->payload)+1);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ICMP_ECHO:
|
case ICMP_ECHO:
|
||||||
if (((inp->flags & NETIF_FLAG_BROADCAST) &&
|
/* broadcast or multicast destination address? */
|
||||||
ip_addr_isbroadcast(&iphdr->dest, &inp->netmask)) ||
|
if (ip_addr_isbroadcast(&iphdr->dest, inp) || ip_addr_ismulticast(&iphdr->dest)) {
|
||||||
ip_addr_ismulticast(&iphdr->dest)) {
|
|
||||||
LWIP_DEBUGF(ICMP_DEBUG, ("Smurf.\n"));
|
LWIP_DEBUGF(ICMP_DEBUG, ("Smurf.\n"));
|
||||||
ICMP_STATS_INC(icmp.err);
|
ICMP_STATS_INC(icmp.err);
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
|
@ -241,7 +241,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
|
|||||||
/* unicast to this interface address? */
|
/* unicast to this interface address? */
|
||||||
if (ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr)) ||
|
if (ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr)) ||
|
||||||
/* or broadcast matching this interface network address? */
|
/* 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))) ||
|
ip_addr_maskcmp(&(iphdr->dest), &(netif->ip_addr), &(netif->netmask))) ||
|
||||||
/* or restricted broadcast? */
|
/* or restricted broadcast? */
|
||||||
ip_addr_cmp(&(iphdr->dest), IP_ADDR_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"));
|
LWIP_DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: packet not for us.\n"));
|
||||||
#if IP_FORWARD
|
#if IP_FORWARD
|
||||||
/* non-broadcast packet? */
|
/* 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 */
|
/* try to forward IP packet on (other) interfaces */
|
||||||
ip_forward(p, iphdr, inp);
|
ip_forward(p, iphdr, inp);
|
||||||
}
|
}
|
||||||
@ -349,7 +349,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* send ICMP destination protocol unreachable unless is was a broadcast */
|
/* send ICMP destination protocol unreachable unless is was a broadcast */
|
||||||
if (!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask)) &&
|
if (!ip_addr_isbroadcast(&(iphdr->dest), inp) &&
|
||||||
!ip_addr_ismulticast(&(iphdr->dest))) {
|
!ip_addr_ismulticast(&(iphdr->dest))) {
|
||||||
p->payload = iphdr;
|
p->payload = iphdr;
|
||||||
icmp_dest_unreach(p, ICMP_DUR_PROTO);
|
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.
|
* as it does not support non-broadcast interfaces.
|
||||||
* lwip-devel 18-2-2004
|
* lwip-devel 18-2-2004
|
||||||
*/
|
*/
|
||||||
#if 0
|
#if 1 /* replaces macro in ip_addr.h */
|
||||||
#include "lwip/netif.h"
|
#include "lwip/netif.h"
|
||||||
|
|
||||||
bool ip_addr_isbroadcast(ip_addr *addr1, struct netif *netif)
|
u8_t ip_addr_isbroadcast(struct ip_addr *addr, netif)
|
||||||
|
|
||||||
bool ip_addr_isbroadcast(addr1, netif)
|
|
||||||
{
|
{
|
||||||
/* all ones (broadcast) or all zeroes (old skool broadcast) */
|
/* all ones (broadcast) or all zeroes (old skool broadcast) */
|
||||||
if (addr1->addr == ip_addr_broadcast.ip_addr) ||
|
if (addr->addr == ip_addr_broadcast.ip_addr) ||
|
||||||
addr1->addr == ip_addr_any.ip_addr))
|
addr->addr == ip_addr_any.ip_addr))
|
||||||
return 1;
|
return 1;
|
||||||
/* no broadcast support on this network interface
|
/* no broadcast support on this network interface
|
||||||
* we cannot proceed matching against broadcast addresses */
|
* we cannot proceed matching against broadcast addresses */
|
||||||
else if (netif->flags &= NETIF_FLAG_BROADCAST == 0)
|
else if (netif->flags &= NETIF_FLAG_BROADCAST == 0)
|
||||||
return 0;
|
return 0;
|
||||||
/* address matches network interface address exactly? */
|
/* address matches network interface address exactly? => no broadcast */
|
||||||
else if (netif->ip_addr.addr == addr1->addr)
|
else if (addr->addr == netif->ip_addr.addr)
|
||||||
return 0;
|
return 0;
|
||||||
/* host identifier bits are all ones? => broadcast address */
|
/* host identifier bits are all ones? => network broadcast address */
|
||||||
else if (~netif->netmask.addr & addr1->addr ==
|
else if (addr->addr & ~netif->netmask.addr ==
|
||||||
~netif->netmask.addr & ip_addr_broadcast.ip_addr)
|
ip_addr_broadcast.ip_addr & ~netif->netmask.addr)
|
||||||
return 1;
|
return 1;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -130,8 +130,7 @@ tcp_input(struct pbuf *p, struct netif *inp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Don't even process incoming broadcasts/multicasts. */
|
/* Don't even process incoming broadcasts/multicasts. */
|
||||||
if (((inp->flags & NETIF_FLAG_BROADCAST) &&
|
if (ip_addr_isbroadcast(&(iphdr->dest), inp) ||
|
||||||
ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask))) ||
|
|
||||||
ip_addr_ismulticast(&(iphdr->dest))) {
|
ip_addr_ismulticast(&(iphdr->dest))) {
|
||||||
pbuf_free(p);
|
pbuf_free(p);
|
||||||
return;
|
return;
|
||||||
|
@ -311,8 +311,7 @@ udp_input(struct pbuf *p, struct netif *inp)
|
|||||||
/* No match was found, send ICMP destination port unreachable unless
|
/* 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) &&
|
if (!ip_addr_isbroadcast(&iphdr->dest, inp) &&
|
||||||
ip_addr_isbroadcast(&iphdr->dest, &inp->netmask)) &&
|
|
||||||
!ip_addr_ismulticast(&iphdr->dest)) {
|
!ip_addr_ismulticast(&iphdr->dest)) {
|
||||||
|
|
||||||
/* adjust pbuf pointer */
|
/* adjust pbuf pointer */
|
||||||
|
@ -110,10 +110,14 @@ extern const struct ip_addr ip_addr_broadcast;
|
|||||||
|
|
||||||
#define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0)
|
#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)) == \
|
#define ip_addr_isbroadcast(addr1, mask) (((((addr1)->addr) & ~((mask)->addr)) == \
|
||||||
(0xffffffff & ~((mask)->addr))) || \
|
(0xffffffff & ~((mask)->addr))) || \
|
||||||
((addr1)->addr == 0xffffffff) || \
|
((addr1)->addr == 0xffffffff) || \
|
||||||
((addr1)->addr == 0x00000000))
|
((addr1)->addr == 0x00000000))
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ip_addr_ismulticast(addr1) (((addr1)->addr & ntohl(0xf0000000)) == ntohl(0xe0000000))
|
#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. */
|
ARP table. */
|
||||||
|
|
||||||
/* destination IP address is an IP broadcast address? */
|
/* destination IP address is an IP broadcast address? */
|
||||||
if (ip_addr_isany(ipaddr) ||
|
if (ip_addr_isany(ipaddr) || ip_addr_isbroadcast(ipaddr, netif)) {
|
||||||
ip_addr_isbroadcast(ipaddr, &(netif->netmask))) {
|
|
||||||
/* broadcast on Ethernet also */
|
/* broadcast on Ethernet also */
|
||||||
dest = (struct eth_addr *)ðbroadcast;
|
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
|
multicasts are special, all other addresses are looked up in the
|
||||||
ARP table. */
|
ARP table. */
|
||||||
queryaddr = ipaddr;
|
queryaddr = ipaddr;
|
||||||
if (ip_addr_isany(ipaddr) ||
|
if (ip_addr_isany(ipaddr) || ip_addr_isbroadcast(ipaddr, netif)) {
|
||||||
ip_addr_isbroadcast(ipaddr, &(netif->netmask))) {
|
|
||||||
dest = (struct eth_addr *)ðbroadcast;
|
dest = (struct eth_addr *)ðbroadcast;
|
||||||
} else if (ip_addr_ismulticast(ipaddr)) {
|
} else if (ip_addr_ismulticast(ipaddr)) {
|
||||||
/* Hash IP multicast address to MAC address. */
|
/* Hash IP multicast address to MAC address. */
|
||||||
|
Loading…
Reference in New Issue
Block a user