diff options
Diffstat (limited to 'lib/prefix.h')
-rw-r--r-- | lib/prefix.h | 86 |
1 files changed, 68 insertions, 18 deletions
diff --git a/lib/prefix.h b/lib/prefix.h index 5f1ff05c..ca7ee687 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -17,7 +17,7 @@ * You should have received a copy of the GNU General Public License * along with GNU Zebra; see the file COPYING. If not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. + * 02111-1307, USA. */ #ifndef _ZEBRA_PREFIX_H @@ -25,6 +25,12 @@ #include "sockunion.h" +#ifndef Inline +#define Inline static inline +#endif + +typedef const union sockunion* const_sockunion ; + /* * A struct prefix contains an address family, a prefix length, and an * address. This can represent either a 'network prefix' as defined @@ -37,16 +43,16 @@ /* IPv4 and IPv6 unified prefix structure. */ struct prefix { - u_char family; - u_char prefixlen; - union + sa_family_t family; + u_char prefixlen; + union { u_char prefix; struct in_addr prefix4; #ifdef HAVE_IPV6 struct in6_addr prefix6; #endif /* HAVE_IPV6 */ - struct + struct { struct in_addr id; struct in_addr adv_router; @@ -58,36 +64,66 @@ struct prefix /* IPv4 prefix structure. */ struct prefix_ipv4 { - u_char family; - u_char prefixlen; + sa_family_t family; + u_char prefixlen; struct in_addr prefix __attribute__ ((aligned (8))); }; +CONFIRM(offsetof(struct prefix_ipv4, family) + == offsetof(struct prefix, family)) ; +CONFIRM(offsetof(struct prefix_ipv4, prefixlen) + == offsetof(struct prefix, prefixlen)) ; +CONFIRM(offsetof(struct prefix_ipv4, prefix) + == offsetof(struct prefix, u.prefix4)) ; +CONFIRM(sizeof(struct prefix_ipv4) <= sizeof(struct prefix)) ; /* IPv6 prefix structure. */ #ifdef HAVE_IPV6 struct prefix_ipv6 { - u_char family; - u_char prefixlen; + sa_family_t family; + u_char prefixlen; struct in6_addr prefix __attribute__ ((aligned (8))); }; +CONFIRM(offsetof(struct prefix_ipv6, family) + == offsetof(struct prefix, family)) ; +CONFIRM(offsetof(struct prefix_ipv6, prefixlen) + == offsetof(struct prefix, prefixlen)) ; +CONFIRM(offsetof(struct prefix_ipv6, prefix) + == offsetof(struct prefix, u.prefix6)) ; +CONFIRM(sizeof(struct prefix_ipv6) <= sizeof(struct prefix)) ; #endif /* HAVE_IPV6 */ struct prefix_ls { - u_char family; - u_char prefixlen; + sa_family_t family; + u_char prefixlen; struct in_addr id __attribute__ ((aligned (8))); struct in_addr adv_router; }; +CONFIRM(offsetof(struct prefix_ls, family) + == offsetof(struct prefix, family)) ; +CONFIRM(offsetof(struct prefix_ls, prefixlen) + == offsetof(struct prefix, prefixlen)) ; +CONFIRM(offsetof(struct prefix_ls, id) + == offsetof(struct prefix, u.lp.id)) ; +CONFIRM(offsetof(struct prefix_ls, adv_router) + == offsetof(struct prefix, u.lp.adv_router)) ; +CONFIRM(sizeof(struct prefix_ls) <= sizeof(struct prefix)) ; /* Prefix for routing distinguisher. */ struct prefix_rd { - u_char family; - u_char prefixlen; - u_char val[8] __attribute__ ((aligned (8))); + sa_family_t family; + u_char prefixlen; + u_char val[8] __attribute__ ((aligned (8))); }; +CONFIRM(offsetof(struct prefix_rd, family) + == offsetof(struct prefix, family)) ; +CONFIRM(offsetof(struct prefix_rd, prefixlen) + == offsetof(struct prefix, prefixlen)) ; +CONFIRM(offsetof(struct prefix_rd, val) + == offsetof(struct prefix, u.val)) ; +CONFIRM(sizeof(struct prefix_rd) <= sizeof(struct prefix)) ; #ifndef INET_ADDRSTRLEN #define INET_ADDRSTRLEN 16 @@ -156,12 +192,14 @@ extern int prefix2str (const struct prefix *, char *, int); extern int prefix_match (const struct prefix *, const struct prefix *); extern int prefix_same (const struct prefix *, const struct prefix *); extern int prefix_cmp (const struct prefix *, const struct prefix *); +extern int prefix_common_bits (const struct prefix *, const struct prefix *); extern void prefix_copy (struct prefix *dest, const struct prefix *src); extern void apply_mask (struct prefix *); -extern struct prefix *sockunion2prefix (const union sockunion *dest, - const union sockunion *mask); -extern struct prefix *sockunion2hostprefix (const union sockunion *); +extern struct prefix *sockunion2prefix (const_sockunion dest, + const_sockunion mask); +extern struct prefix *sockunion2hostprefix (const_sockunion src); +extern void prefix2sockunion (const struct prefix *, union sockunion *); extern struct prefix_ipv4 *prefix_ipv4_new (void); extern void prefix_ipv4_free (struct prefix_ipv4 *); @@ -171,6 +209,12 @@ extern void apply_mask_ipv4 (struct prefix_ipv4 *); #define PREFIX_COPY_IPV4(DST, SRC) \ *((struct prefix_ipv4 *)(DST)) = *((const struct prefix_ipv4 *)(SRC)); +Inline void +prefix_copy_ipv4(struct prefix* dst, struct prefix* src) +{ + *dst = *src ; +} ; + extern int prefix_ipv4_any (const struct prefix_ipv4 *); extern void apply_classful_mask_ipv4 (struct prefix_ipv4 *); @@ -193,7 +237,13 @@ extern int str2prefix_ipv6 (const char *, struct prefix_ipv6 *); extern void apply_mask_ipv6 (struct prefix_ipv6 *); #define PREFIX_COPY_IPV6(DST, SRC) \ - *((struct prefix_ipv6 *)(DST)) = *((const struct prefix_ipv6 *)(SRC)); + *((struct prefix_ipv6 *)(DST)) = *((const struct prefix_ipv6 *)(SRC)); + +Inline void +prefix_copy_ipv6(struct prefix* dst, struct prefix* src) +{ + *dst = *src ; +} ; extern int ip6_masklen (struct in6_addr); extern void masklen2ip6 (int, struct in6_addr *); |