"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/arp.c" between
dnsmasq-2.80.tar.gz and dnsmasq-2.81.tar.xz

About: Dnsmasq is a lightweight caching DNS forwarder and DHCP server.

arp.c  (dnsmasq-2.80):arp.c  (dnsmasq-2.81.tar.xz)
/* dnsmasq is Copyright (c) 2000-2018 Simon Kelley /* dnsmasq is Copyright (c) 2000-2020 Simon Kelley
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 dated June, 1991, or the Free Software Foundation; version 2 dated June, 1991, or
(at your option) version 3 dated 29 June, 2007. (at your option) version 3 dated 29 June, 2007.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
skipping to change at line 31 skipping to change at line 31
#define ARP_MARK 0 #define ARP_MARK 0
#define ARP_FOUND 1 /* Confirmed */ #define ARP_FOUND 1 /* Confirmed */
#define ARP_NEW 2 /* Newly created */ #define ARP_NEW 2 /* Newly created */
#define ARP_EMPTY 3 /* No MAC addr */ #define ARP_EMPTY 3 /* No MAC addr */
struct arp_record { struct arp_record {
unsigned short hwlen, status; unsigned short hwlen, status;
int family; int family;
unsigned char hwaddr[DHCP_CHADDR_MAX]; unsigned char hwaddr[DHCP_CHADDR_MAX];
struct all_addr addr; union all_addr addr;
struct arp_record *next; struct arp_record *next;
}; };
static struct arp_record *arps = NULL, *old = NULL, *freelist = NULL; static struct arp_record *arps = NULL, *old = NULL, *freelist = NULL;
static time_t last = 0; static time_t last = 0;
static int filter_mac(int family, char *addrp, char *mac, size_t maclen, void *p armv) static int filter_mac(int family, char *addrp, char *mac, size_t maclen, void *p armv)
{ {
struct arp_record *arp; struct arp_record *arp;
(void)parmv; (void)parmv;
if (maclen > DHCP_CHADDR_MAX) if (maclen > DHCP_CHADDR_MAX)
return 1; return 1;
#ifndef HAVE_IPV6
if (family != AF_INET)
return 1;
#endif
/* Look for existing entry */ /* Look for existing entry */
for (arp = arps; arp; arp = arp->next) for (arp = arps; arp; arp = arp->next)
{ {
if (family != arp->family || arp->status == ARP_NEW) if (family != arp->family || arp->status == ARP_NEW)
continue; continue;
if (family == AF_INET) if (family == AF_INET)
{ {
if (arp->addr.addr.addr4.s_addr != ((struct in_addr *)addrp)->s_addr) if (arp->addr.addr4.s_addr != ((struct in_addr *)addrp)->s_addr)
continue; continue;
} }
#ifdef HAVE_IPV6
else else
{ {
if (!IN6_ARE_ADDR_EQUAL(&arp->addr.addr.addr6, (struct in6_addr *)addrp )) if (!IN6_ARE_ADDR_EQUAL(&arp->addr.addr6, (struct in6_addr *)addrp))
continue; continue;
} }
#endif
if (arp->status == ARP_EMPTY) if (arp->status == ARP_EMPTY)
{ {
/* existing address, was negative. */ /* existing address, was negative. */
arp->status = ARP_NEW; arp->status = ARP_NEW;
arp->hwlen = maclen; arp->hwlen = maclen;
memcpy(arp->hwaddr, mac, maclen); memcpy(arp->hwaddr, mac, maclen);
} }
else if (arp->hwlen == maclen && memcmp(arp->hwaddr, mac, maclen) == 0) else if (arp->hwlen == maclen && memcmp(arp->hwaddr, mac, maclen) == 0)
/* Existing entry matches - confirm. */ /* Existing entry matches - confirm. */
skipping to change at line 105 skipping to change at line 98
else if (!(arp = whine_malloc(sizeof(struct arp_record)))) else if (!(arp = whine_malloc(sizeof(struct arp_record))))
return 1; return 1;
arp->next = arps; arp->next = arps;
arps = arp; arps = arp;
arp->status = ARP_NEW; arp->status = ARP_NEW;
arp->hwlen = maclen; arp->hwlen = maclen;
arp->family = family; arp->family = family;
memcpy(arp->hwaddr, mac, maclen); memcpy(arp->hwaddr, mac, maclen);
if (family == AF_INET) if (family == AF_INET)
arp->addr.addr.addr4.s_addr = ((struct in_addr *)addrp)->s_addr; arp->addr.addr4.s_addr = ((struct in_addr *)addrp)->s_addr;
#ifdef HAVE_IPV6
else else
memcpy(&arp->addr.addr.addr6, addrp, IN6ADDRSZ); memcpy(&arp->addr.addr6, addrp, IN6ADDRSZ);
#endif
} }
return 1; return 1;
} }
/* If in lazy mode, we cache absence of ARP entries. */ /* If in lazy mode, we cache absence of ARP entries. */
int find_mac(union mysockaddr *addr, unsigned char *mac, int lazy, time_t now) int find_mac(union mysockaddr *addr, unsigned char *mac, int lazy, time_t now)
{ {
struct arp_record *arp, *tmp, **up; struct arp_record *arp, *tmp, **up;
int updated = 0; int updated = 0;
skipping to change at line 136 skipping to change at line 127
/* addr == NULL -> just make cache up-to-date */ /* addr == NULL -> just make cache up-to-date */
if (!addr) if (!addr)
return 0; return 0;
for (arp = arps; arp; arp = arp->next) for (arp = arps; arp; arp = arp->next)
{ {
if (addr->sa.sa_family != arp->family) if (addr->sa.sa_family != arp->family)
continue; continue;
if (arp->family == AF_INET && if (arp->family == AF_INET &&
arp->addr.addr.addr4.s_addr != addr->in.sin_addr.s_addr) arp->addr.addr4.s_addr != addr->in.sin_addr.s_addr)
continue; continue;
#ifdef HAVE_IPV6
if (arp->family == AF_INET6 && if (arp->family == AF_INET6 &&
!IN6_ARE_ADDR_EQUAL(&arp->addr.addr.addr6, &addr->in6.sin6_addr)) !IN6_ARE_ADDR_EQUAL(&arp->addr.addr6, &addr->in6.sin6_addr))
continue; continue;
#endif
/* Only accept positive entries unless in lazy mode. */ /* Only accept positive entries unless in lazy mode. */
if (arp->status != ARP_EMPTY || lazy || updated) if (arp->status != ARP_EMPTY || lazy || updated)
{ {
if (mac && arp->hwlen != 0) if (mac && arp->hwlen != 0)
memcpy(mac, arp->hwaddr, arp->hwlen); memcpy(mac, arp->hwaddr, arp->hwlen);
return arp->hwlen; return arp->hwlen;
} }
} }
} }
skipping to change at line 205 skipping to change at line 194
if (arp) if (arp)
{ {
arp->next = arps; arp->next = arps;
arps = arp; arps = arp;
arp->status = ARP_EMPTY; arp->status = ARP_EMPTY;
arp->family = addr->sa.sa_family; arp->family = addr->sa.sa_family;
arp->hwlen = 0; arp->hwlen = 0;
if (addr->sa.sa_family == AF_INET) if (addr->sa.sa_family == AF_INET)
arp->addr.addr.addr4.s_addr = addr->in.sin_addr.s_addr; arp->addr.addr4.s_addr = addr->in.sin_addr.s_addr;
#ifdef HAVE_IPV6
else else
memcpy(&arp->addr.addr.addr6, &addr->in6.sin6_addr, IN6ADDRSZ); memcpy(&arp->addr.addr6, &addr->in6.sin6_addr, IN6ADDRSZ);
#endif
} }
return 0; return 0;
} }
int do_arp_script_run(void) int do_arp_script_run(void)
{ {
struct arp_record *arp; struct arp_record *arp;
/* Notify any which went, then move to free list */ /* Notify any which went, then move to free list */
 End of changes. 15 change blocks. 
23 lines changed or deleted 10 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)