Fix behavior of ipa_opposite().

It was giving wrong results on /30 networks.
This commit is contained in:
Martin Mares 2008-08-25 11:19:49 +00:00
parent 6c36c4b66b
commit 057021df0d
4 changed files with 5 additions and 4 deletions

View file

@ -153,13 +153,14 @@ int ipa_classify(ip_addr x) { DUMMY }
/** /**
* ipa_opposite - return address of point-to-point neighbor * ipa_opposite - return address of point-to-point neighbor
* @x: IP address of our end of the link * @x: IP address of our end of the link
* @pxlen: network prefix length
* *
* ipa_opposite() returns an address of the opposite end of a numbered * ipa_opposite() returns an address of the opposite end of a numbered
* point-to-point link. * point-to-point link.
* *
* This function is available in IPv4 version only. * This function is available in IPv4 version only.
*/ */
ip_addr ipa_opposite(ip_addr x) { DUMMY } ip_addr ipa_opposite(ip_addr x, int pxlen) { DUMMY }
/** /**
* ipa_class_mask - guess netmask according to address class * ipa_class_mask - guess netmask according to address class

View file

@ -53,7 +53,7 @@ typedef u32 ip_addr;
#define ipa_hton(x) x = _MI(htonl(_I(x))) #define ipa_hton(x) x = _MI(htonl(_I(x)))
#define ipa_ntoh(x) x = _MI(ntohl(_I(x))) #define ipa_ntoh(x) x = _MI(ntohl(_I(x)))
#define ipa_classify(x) ipv4_classify(_I(x)) #define ipa_classify(x) ipv4_classify(_I(x))
#define ipa_opposite(x) _MI(_I(x) ^ 1) #define ipa_opposite(x,len) _MI(_I(x) ^ (len == 30 ? 3 : 1))
#define ipa_class_mask(x) _MI(ipv4_class_mask(_I(x))) #define ipa_class_mask(x) _MI(ipv4_class_mask(_I(x)))
#define ipa_from_u32(x) _MI(x) #define ipa_from_u32(x) _MI(x)
#define ipa_to_u32(x) _I(x) #define ipa_to_u32(x) _I(x)

View file

@ -377,7 +377,7 @@ nl_parse_addr(struct nlmsghdr *h)
ifa.brd = ipa_or(ifa.ip, ipa_not(netmask)); ifa.brd = ipa_or(ifa.ip, ipa_not(netmask));
#ifndef IPV6 #ifndef IPV6
if (i->ifa_prefixlen == BITS_PER_IP_ADDRESS - 2) if (i->ifa_prefixlen == BITS_PER_IP_ADDRESS - 2)
ifa.opposite = ipa_opposite(ifa.ip); ifa.opposite = ipa_opposite(ifa.ip, i->ifa_prefixlen);
if ((ifi->flags & IF_BROADCAST) && a[IFA_BROADCAST]) if ((ifi->flags & IF_BROADCAST) && a[IFA_BROADCAST])
{ {
memcpy(&xbrd, RTA_DATA(a[IFA_BROADCAST]), sizeof(xbrd)); memcpy(&xbrd, RTA_DATA(a[IFA_BROADCAST]), sizeof(xbrd));

View file

@ -140,7 +140,7 @@ scan_ifs(struct ifreq *r, int cnt)
if (a.pxlen < 30) if (a.pxlen < 30)
i.flags |= IF_MULTIACCESS; i.flags |= IF_MULTIACCESS;
else else
a.opposite = ipa_opposite(a.ip); a.opposite = ipa_opposite(a.ip, a.pxlen);
} }
else else
a.brd = a.opposite; a.brd = a.opposite;