mirror of
https://github.com/paulusmack/ppp.git
synced 2024-11-30 15:03:36 +08:00
Made proxyarp search for the best matching interface (the one with the highest
netmask) instead of the first matching interface.
This commit is contained in:
parent
fcdb3f7ce6
commit
14768a012e
@ -1654,10 +1654,13 @@ static int get_ether_addr (u_int32_t ipaddr,
|
||||
struct ifreq *ifr, *ifend;
|
||||
u_int32_t ina, mask;
|
||||
char *aliasp;
|
||||
struct ifreq ifreq;
|
||||
struct ifreq ifreq, bestifreq;
|
||||
struct ifconf ifc;
|
||||
struct ifreq ifs[MAX_IFS];
|
||||
|
||||
u_int32_t bestmask=0;
|
||||
int found_interface = 0;
|
||||
|
||||
ifc.ifc_len = sizeof(ifs);
|
||||
ifc.ifc_req = ifs;
|
||||
if (ioctl(sock_fd, SIOCGIFCONF, &ifc) < 0) {
|
||||
@ -1699,15 +1702,21 @@ static int get_ether_addr (u_int32_t ipaddr,
|
||||
ip_ntoa(ina), ntohl(mask)));
|
||||
|
||||
if (((ipaddr ^ ina) & mask) != 0)
|
||||
continue;
|
||||
break;
|
||||
continue; /* no match */
|
||||
/* matched */
|
||||
if (mask >= bestmask) {
|
||||
/* Compare using >= instead of > -- it is possible for
|
||||
an interface to have a netmask of 0.0.0.0 */
|
||||
found_interface = 1;
|
||||
bestifreq = ifreq;
|
||||
bestmask = mask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ifr >= ifend)
|
||||
return 0;
|
||||
if (!found_interface) return 0;
|
||||
|
||||
strlcpy(name, ifreq.ifr_name, namelen);
|
||||
strlcpy(name, bestifreq.ifr_name, namelen);
|
||||
|
||||
/* trim off the :1 in eth0:1 */
|
||||
aliasp = strchr(name, ':');
|
||||
@ -1718,14 +1727,14 @@ static int get_ether_addr (u_int32_t ipaddr,
|
||||
/*
|
||||
* Now get the hardware address.
|
||||
*/
|
||||
memset (&ifreq.ifr_hwaddr, 0, sizeof (struct sockaddr));
|
||||
if (ioctl (sock_fd, SIOCGIFHWADDR, &ifreq) < 0) {
|
||||
error("SIOCGIFHWADDR(%s): %m", ifreq.ifr_name);
|
||||
memset (&bestifreq.ifr_hwaddr, 0, sizeof (struct sockaddr));
|
||||
if (ioctl (sock_fd, SIOCGIFHWADDR, &bestifreq) < 0) {
|
||||
error("SIOCGIFHWADDR(%s): %m", bestifreq.ifr_name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy (hwaddr,
|
||||
&ifreq.ifr_hwaddr,
|
||||
&bestifreq.ifr_hwaddr,
|
||||
sizeof (struct sockaddr));
|
||||
|
||||
SYSDEBUG ((LOG_DEBUG,
|
||||
|
Loading…
Reference in New Issue
Block a user