]> git.ipfire.org Git - thirdparty/bird.git/blob - lib/ip.h
Finishes add-path.
[thirdparty/bird.git] / lib / ip.h
1 /*
2 * BIRD Internet Routing Daemon -- The Internet Protocol
3 *
4 * (c) 1998 Martin Mares <mj@ucw.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9 #ifndef _BIRD_IP_H_
10 #define _BIRD_IP_H_
11
12 #ifndef IPV6
13 #include "ipv4.h"
14 #else
15 #include "ipv6.h"
16 #endif
17
18 #define ipa_zero(x) (!ipa_nonzero(x))
19 #define ip_is_prefix(a,l) (!ipa_nonzero(ipa_and(a, ipa_not(ipa_mkmask(l)))))
20 #define ipa_in_net(x,n,p) (ipa_zero(ipa_and(ipa_xor((n),(x)),ipa_mkmask(p))))
21 #define net_in_net(n1,l1,n2,l2) (((l1) >= (l2)) && (ipa_zero(ipa_and(ipa_xor((n1),(n2)),ipa_mkmask(l2)))))
22
23 /*
24 * ip_classify() returns either a negative number for invalid addresses
25 * or scope OR'ed together with address type.
26 */
27
28 #define IADDR_INVALID -1
29 #define IADDR_SCOPE_MASK 0xfff
30 #define IADDR_HOST 0x1000
31 #define IADDR_BROADCAST 0x2000
32 #define IADDR_MULTICAST 0x4000
33
34 /*
35 * Address scope
36 */
37
38 #define SCOPE_HOST 0
39 #define SCOPE_LINK 1
40 #define SCOPE_SITE 2
41 #define SCOPE_ORGANIZATION 3
42 #define SCOPE_UNIVERSE 4
43 #define SCOPE_UNDEFINED 5
44
45 char *ip_scope_text(unsigned);
46
47 /*
48 * Network prefixes
49 */
50
51 struct prefix {
52 ip_addr addr;
53 unsigned int len;
54 };
55
56 static inline int ipa_classify_net(ip_addr a)
57 { return ipa_zero(a) ? (IADDR_HOST | SCOPE_UNIVERSE) : ipa_classify(a); }
58
59 /*
60 * Conversions between internal and string representation
61 */
62
63 char *ip_ntop(ip_addr a, char *);
64 char *ip_ntox(ip_addr a, char *);
65 int ip_pton(char *a, ip_addr *o);
66
67 #endif