2004-11-25 Leon Woestenberg <leon.woestenberg@gmx.net>

* ipv4/ip_addr.h: Renamed ip_addr_maskcmp() to _netcmp() as we are
    comparing network addresses (identifiers), not the network masks
    themselves.
  * ipv4/ip_addr.c: ip_addr_isbroadcast() now checks that the given
    IP address actually belongs to the network of the given interface.
This commit is contained in:
likewise 2004-11-25 13:33:07 +00:00
parent 3488a5c3c4
commit fd49ee3c8d
6 changed files with 10 additions and 8 deletions

View File

@ -85,7 +85,7 @@ ip_route(struct ip_addr *dest)
/* iterate through netifs */
for(netif = netif_list; netif != NULL; netif = netif->next) {
/* network mask matches? */
if (ip_addr_maskcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
/* return netif on which to forward IP packet */
return netif;
}
@ -240,7 +240,7 @@ ip_input(struct pbuf *p, struct netif *inp) {
if (ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr)) ||
/* or broadcast matching this interface network address? */
(ip_addr_isbroadcast(&(iphdr->dest), netif) &&
ip_addr_maskcmp(&(iphdr->dest), &(netif->ip_addr), &(netif->netmask))) ||
ip_addr_netcmp(&(iphdr->dest), &(netif->ip_addr), &(netif->netmask))) ||
/* or restricted broadcast? */
ip_addr_cmp(&(iphdr->dest), IP_ADDR_BROADCAST)) {
LWIP_DEBUGF(IP_DEBUG, ("ip_input: packet accepted on interface %c%c\n",

View File

@ -60,8 +60,10 @@ u8_t ip_addr_isbroadcast(struct ip_addr *addr, struct netif *netif)
/* address matches network interface address exactly? => no broadcast */
else if (addr->addr == netif->ip_addr.addr)
return 0;
/* host identifier bits are all ones? => network broadcast address */
else if ((addr->addr & ~netif->netmask.addr) ==
/* on the same (sub) network and
* host identifier bits are all ones? => network broadcast address */
else if (ip_addr_netcmp(addr->addr, netif->ip_addr.addr, netif->netmask.addr))
&& ((addr->addr & ~netif->netmask.addr) ==
(ip_addr_broadcast.addr & ~netif->netmask.addr))
return 1;
else

View File

@ -77,7 +77,7 @@ ip_route(struct ip_addr *dest)
struct netif *netif;
for(netif = netif_list; netif != NULL; netif = netif->next) {
if (ip_addr_maskcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
if (ip_addr_netcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
return netif;
}
}

View File

@ -35,7 +35,7 @@
int
ip_addr_maskcmp(struct ip_addr *addr1, struct ip_addr *addr2,
ip_addr_netcmp(struct ip_addr *addr1, struct ip_addr *addr2,
struct ip_addr *mask)
{
return((addr1->addr[0] & mask->addr[0]) == (addr2->addr[0] & mask->addr[0]) &&

View File

@ -125,7 +125,7 @@ extern const struct ip_addr ip_addr_broadcast;
* @arg mask network identifier mask
* @return !0 if the network identifiers of both address match
*/
#define ip_addr_maskcmp(addr1, addr2, mask) (((addr1)->addr & \
#define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
(mask)->addr) == \
((addr2)->addr & \
(mask)->addr))

View File

@ -45,7 +45,7 @@ struct ip_addr {
(ipaddr)->addr[2] = htonl(((e & 0xffff) << 16) | (f & 0xffff)); \
(ipaddr)->addr[3] = htonl(((g & 0xffff) << 16) | (h & 0xffff)); } while(0)
int ip_addr_maskcmp(struct ip_addr *addr1, struct ip_addr *addr2,
int ip_addr_netcmp(struct ip_addr *addr1, struct ip_addr *addr2,
struct ip_addr *mask);
int ip_addr_cmp(struct ip_addr *addr1, struct ip_addr *addr2);
void ip_addr_set(struct ip_addr *dest, struct ip_addr *src);