1998-04-23 14:01:15 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- IP Addresses et Cetera for IPv4
|
|
|
|
*
|
|
|
|
* (c) 1998 Martin Mares <mj@ucw.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BIRD_IPV4_H_
|
|
|
|
#define _BIRD_IPV4_H_
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
1998-05-03 16:43:39 +00:00
|
|
|
#include "lib/bitops.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use the structural representation when you want to make sure
|
|
|
|
* nobody unauthorized attempts to handle ip_addr as number.
|
|
|
|
*/
|
|
|
|
|
1998-04-23 14:01:15 +00:00
|
|
|
typedef struct ipv4_addr {
|
|
|
|
u32 addr;
|
|
|
|
} ip_addr;
|
|
|
|
|
|
|
|
#define _I(x) (x).addr
|
1998-05-15 07:56:13 +00:00
|
|
|
#define _MI(x) ((struct ipv4_addr) { x })
|
1998-04-23 14:01:15 +00:00
|
|
|
|
1998-05-03 16:43:39 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
typedef u32 ip_addr;
|
|
|
|
|
|
|
|
#define _I(x) (x)
|
|
|
|
#define _MI(x) (x)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1998-05-15 07:56:13 +00:00
|
|
|
#define BITS_PER_IP_ADDRESS 32
|
|
|
|
|
1998-04-28 14:39:34 +00:00
|
|
|
#define IPA_NONE (_MI(0))
|
1998-04-23 14:01:15 +00:00
|
|
|
|
|
|
|
#define ipa_equal(x,y) (_I(x) == _I(y))
|
1998-05-03 16:43:39 +00:00
|
|
|
#define ipa_nonzero(x) _I(x)
|
1998-04-23 14:01:15 +00:00
|
|
|
#define ipa_and(x,y) _MI(_I(x) & _I(y))
|
|
|
|
#define ipa_or(x,y) _MI(_I(x) | _I(y))
|
|
|
|
#define ipa_not(x) _MI(~_I(x))
|
1998-05-03 16:43:39 +00:00
|
|
|
#define ipa_mkmask(x) _MI(u32_mkmask(x))
|
|
|
|
#define ipa_mklen(x) u32_masklen(_I(x))
|
|
|
|
#define ipa_hash(x) ipv4_hash(_I(x))
|
|
|
|
#define ipa_hton(x) x = _MI(htonl(_I(x)))
|
|
|
|
#define ipa_ntoh(x) x = _MI(ntohl(_I(x)))
|
|
|
|
#define ipa_classify(x) ipv4_classify(_I(x))
|
1998-04-23 14:01:15 +00:00
|
|
|
|
1998-05-03 16:43:39 +00:00
|
|
|
int ipv4_classify(u32);
|
1998-04-23 14:01:15 +00:00
|
|
|
|
1998-05-03 16:43:39 +00:00
|
|
|
/* FIXME: Is this hash function uniformly distributed over standard routing tables? */
|
|
|
|
static inline unsigned ipv4_hash(u32 a)
|
|
|
|
{
|
|
|
|
return a ^ (a >> 16) ^ (a >> 24);
|
|
|
|
}
|
1998-04-23 14:01:15 +00:00
|
|
|
|
|
|
|
#endif
|