mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-17 08:38:42 +00:00
Added ipa_class_mask() which guesses netmask for classful addressing.
For pure A/B/C class addresses it just returns the class netmask, for subnets it tries to guess subnet mask. Please make sure the address you pass to this function is really a valid host address (i.e., call ipa_validate() first).
This commit is contained in:
parent
28a9a189d7
commit
786d0bb9e7
17
lib/ipv4.c
17
lib/ipv4.c
@ -43,11 +43,26 @@ ip_ntop(ip_addr a, char *b)
|
|||||||
(x & 0xff));
|
(x & 0xff));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
ip_ntox(ip_addr a, char *b)
|
ip_ntox(ip_addr a, char *b)
|
||||||
{
|
{
|
||||||
return b + bsprintf(b, "%08x", _I(a));
|
return b + bsprintf(b, "%08x", _I(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32
|
||||||
|
ipv4_class_mask(u32 a)
|
||||||
|
{
|
||||||
|
u32 m;
|
||||||
|
|
||||||
|
if (a < 0x80000000)
|
||||||
|
m = 0xff000000;
|
||||||
|
if (a < 0xc0000000)
|
||||||
|
m = 0xffff0000;
|
||||||
|
else
|
||||||
|
m = 0xffffff00;
|
||||||
|
while (a & ~m)
|
||||||
|
m |= m >> 1;
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -54,8 +54,10 @@ typedef u32 ip_addr;
|
|||||||
#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) _MI(_I(x) ^ 1)
|
||||||
|
#define ipa_class_mask(x) x = _MI(ipv4_class_mask(_I(x)))
|
||||||
|
|
||||||
int ipv4_classify(u32);
|
int ipv4_classify(u32);
|
||||||
|
u32 ipv4_class_mask(u32);
|
||||||
|
|
||||||
/* FIXME: Is this hash function uniformly distributed over standard routing tables? */
|
/* FIXME: Is this hash function uniformly distributed over standard routing tables? */
|
||||||
static inline unsigned ipv4_hash(u32 a)
|
static inline unsigned ipv4_hash(u32 a)
|
||||||
|
Loading…
Reference in New Issue
Block a user