]>
git.proxmox.com Git - mirror_frr.git/blob - lib/prefix.h
3 * Copyright (C) 1998 Kunihiro Ishiguro
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #ifndef _ZEBRA_PREFIX_H
24 #define _ZEBRA_PREFIX_H
26 /* IPv4 and IPv6 unified prefix structure. */
34 struct in_addr prefix4
;
36 struct in6_addr prefix6
;
37 #endif /* HAVE_IPV6 */
41 struct in_addr adv_router
;
44 } u
__attribute__ ((aligned (8)));
47 /* IPv4 prefix structure. */
52 struct in_addr prefix
__attribute__ ((aligned (8)));
55 /* IPv6 prefix structure. */
61 struct in6_addr prefix
__attribute__ ((aligned (8)));
63 #endif /* HAVE_IPV6 */
69 struct in_addr id
__attribute__ ((aligned (8)));
70 struct in_addr adv_router
;
73 /* Prefix for routing distinguisher. */
78 u_char val
[8] __attribute__ ((aligned (8)));
81 #ifndef INET_ADDRSTRLEN
82 #define INET_ADDRSTRLEN 16
83 #endif /* INET_ADDRSTRLEN */
85 #ifndef INET6_ADDRSTRLEN
86 #define INET6_ADDRSTRLEN 46
87 #endif /* INET6_ADDRSTRLEN */
90 #define INET6_BUFSIZ 51
91 #endif /* INET6_BUFSIZ */
93 /* Max bit/byte length of IPv4 address. */
94 #define IPV4_MAX_BYTELEN 4
95 #define IPV4_MAX_BITLEN 32
96 #define IPV4_MAX_PREFIXLEN 32
97 #define IPV4_ADDR_CMP(D,S) memcmp ((D), (S), IPV4_MAX_BYTELEN)
98 #define IPV4_ADDR_SAME(D,S) (memcmp ((D), (S), IPV4_MAX_BYTELEN) == 0)
99 #define IPV4_ADDR_COPY(D,S) memcpy ((D), (S), IPV4_MAX_BYTELEN)
101 #define IPV4_NET0(a) ((((u_int32_t) (a)) & 0xff000000) == 0x00000000)
102 #define IPV4_NET127(a) ((((u_int32_t) (a)) & 0xff000000) == 0x7f000000)
104 /* Max bit/byte length of IPv6 address. */
105 #define IPV6_MAX_BYTELEN 16
106 #define IPV6_MAX_BITLEN 128
107 #define IPV6_MAX_PREFIXLEN 128
108 #define IPV6_ADDR_CMP(D,S) memcmp ((D), (S), IPV6_MAX_BYTELEN)
109 #define IPV6_ADDR_SAME(D,S) (memcmp ((D), (S), IPV6_MAX_BYTELEN) == 0)
110 #define IPV6_ADDR_COPY(D,S) memcpy ((D), (S), IPV6_MAX_BYTELEN)
112 /* Count prefix size from mask length */
113 #define PSIZE(a) (((a) + 7) / (8))
115 /* Prefix's family member. */
116 #define PREFIX_FAMILY(p) ((p)->family)
119 int afi2family (int);
120 int family2afi (int);
122 int prefix2str (struct prefix
*, char *, int);
123 int str2prefix (char *, struct prefix
*);
124 struct prefix
*prefix_new ();
125 void prefix_free (struct prefix
*p
);
127 struct prefix_ipv4
*prefix_ipv4_new ();
128 void prefix_ipv4_free ();
129 int str2prefix_ipv4 (char *, struct prefix_ipv4
*);
130 void apply_mask_ipv4 (struct prefix_ipv4
*);
131 int prefix_blen (struct prefix
*);
132 u_char
ip_masklen (struct in_addr
);
133 int prefix_ipv4_any (struct prefix_ipv4
*);
134 void masklen2ip (int, struct in_addr
*);
135 void apply_classful_mask_ipv4 (struct prefix_ipv4
*);
137 char *prefix_family_str (struct prefix
*p
);
138 struct prefix
*sockunion2prefix ();
139 struct prefix
*sockunion2hostprefix ();
142 struct prefix_ipv6
*prefix_ipv6_new ();
143 void prefix_ipv6_free ();
144 struct prefix
*str2routev6 (char *);
145 int str2prefix_ipv6 (char *str
, struct prefix_ipv6
*p
);
146 void apply_mask_ipv6 (struct prefix_ipv6
*p
);
147 void str2in6_addr (char *str
, struct in6_addr
*addr
);
148 void masklen2ip6 (int masklen
, struct in6_addr
*netmask
);
149 int ip6_masklen (struct in6_addr netmask
);
150 #endif /* HAVE_IPV6 */
152 void apply_mask (struct prefix
*);
153 int prefix_match (struct prefix
*n
, struct prefix
*p
);
154 int prefix_same (struct prefix
*, struct prefix
*);
155 int prefix_cmp (struct prefix
*, struct prefix
*);
156 void prefix_copy (struct prefix
*, struct prefix
*);
158 int all_digit (char *);
159 int netmask_str2prefix_str (char *, char *, char *);
161 #endif /* _ZEBRA_PREFIX_H */