]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/prefix.h
*: reindent
[mirror_frr.git] / lib / prefix.h
index 549798e92e10338cc5955a5cbb98d2b01f357c98..ce13dcfa0a71a1f9c4f055502d47780eb526ac78 100644 (file)
 #define _ZEBRA_PREFIX_H
 
 #ifdef SUNOS_5
-# include <sys/ethernet.h>
+#include <sys/ethernet.h>
 #else
-# ifdef GNU_LINUX
-#  include <net/ethernet.h>
-# else
-#  include <netinet/if_ether.h>
-# endif
+#ifdef GNU_LINUX
+#include <net/ethernet.h>
+#else
+#include <netinet/if_ether.h>
+#endif
 #endif
 #include "sockunion.h"
 #include "ipaddr.h"
  * own to simplify internal handling
  */
 struct ethaddr {
-    u_char octet[ETHER_ADDR_LEN];
-} __attribute__ ((packed));
+       u_char octet[ETHER_ADDR_LEN];
+} __attribute__((packed));
 
 
-/* length is the number of valuable bits of prefix structure 
+/* length is the number of valuable bits of prefix structure
 * 18 bytes is current length in structure, if address is ipv4
 * 30 bytes is in case of ipv6
 */
@@ -60,13 +60,12 @@ struct ethaddr {
 #define PREFIX_LEN_ROUTE_TYPE_5_IPV6 (30*8)
 
 /* EVPN address (RFC 7432) */
-struct evpn_addr
-{
-  u_char route_type;
-  u_char ip_prefix_length;
-  struct ethaddr mac;
-  uint32_t eth_tag;
-  struct ipaddr ip;
+struct evpn_addr {
+       u_char route_type;
+       u_char ip_prefix_length;
+       struct ethaddr mac;
+       uint32_t eth_tag;
+       struct ipaddr ip;
 #if 0
   union
   {
@@ -100,89 +99,78 @@ struct evpn_addr
 #endif
 
 /* IPv4 and IPv6 unified prefix structure. */
-struct prefix
-{
-  u_char family;
-  u_char prefixlen;
-  union 
-  {
-    u_char prefix;
-    struct in_addr prefix4;
-    struct in6_addr prefix6;
-    struct 
-    {
-      struct in_addr id;
-      struct in_addr adv_router;
-    } lp;
-    struct ethaddr prefix_eth; /* AF_ETHERNET */
-    u_char val[8];
-    uintptr_t ptr;
-    struct evpn_addr prefix_evpn;
-  } u __attribute__ ((aligned (8)));
+struct prefix {
+       u_char family;
+       u_char prefixlen;
+       union {
+               u_char prefix;
+               struct in_addr prefix4;
+               struct in6_addr prefix6;
+               struct {
+                       struct in_addr id;
+                       struct in_addr adv_router;
+               } lp;
+               struct ethaddr prefix_eth; /* AF_ETHERNET */
+               u_char val[8];
+               uintptr_t ptr;
+               struct evpn_addr prefix_evpn;
+       } u __attribute__((aligned(8)));
 };
 
 /* IPv4 prefix structure. */
-struct prefix_ipv4
-{
-  u_char family;
-  u_char prefixlen;
-  struct in_addr prefix __attribute__ ((aligned (8)));
+struct prefix_ipv4 {
+       u_char family;
+       u_char prefixlen;
+       struct in_addr prefix __attribute__((aligned(8)));
 };
 
 /* IPv6 prefix structure. */
-struct prefix_ipv6
-{
-  u_char family;
-  u_char prefixlen;
-  struct in6_addr prefix __attribute__ ((aligned (8)));
+struct prefix_ipv6 {
+       u_char family;
+       u_char prefixlen;
+       struct in6_addr prefix __attribute__((aligned(8)));
 };
 
-struct prefix_ls
-{
-  u_char family;
-  u_char prefixlen;
-  struct in_addr id __attribute__ ((aligned (8)));
-  struct in_addr adv_router;
+struct prefix_ls {
+       u_char family;
+       u_char prefixlen;
+       struct in_addr id __attribute__((aligned(8)));
+       struct in_addr adv_router;
 };
 
 /* Prefix for routing distinguisher. */
-struct prefix_rd
-{
-  u_char family;
-  u_char prefixlen;
-  u_char val[8] __attribute__ ((aligned (8)));
+struct prefix_rd {
+       u_char family;
+       u_char prefixlen;
+       u_char val[8] __attribute__((aligned(8)));
 };
 
 /* Prefix for ethernet. */
-struct prefix_eth
-{
-  u_char family;
-  u_char prefixlen;
-  struct ethaddr eth_addr __attribute__ ((aligned (8))); /* AF_ETHERNET */
+struct prefix_eth {
+       u_char family;
+       u_char prefixlen;
+       struct ethaddr eth_addr __attribute__((aligned(8))); /* AF_ETHERNET */
 };
 
 /* EVPN prefix structure. */
-struct prefix_evpn
-{
-  u_char family;
-  u_char prefixlen;
-  struct evpn_addr prefix __attribute__ ((aligned (8)));
+struct prefix_evpn {
+       u_char family;
+       u_char prefixlen;
+       struct evpn_addr prefix __attribute__((aligned(8)));
 };
 
 /* Prefix for a generic pointer */
-struct prefix_ptr
-{
-  u_char family;
-  u_char prefixlen;
-  uintptr_t prefix __attribute__ ((aligned (8)));
+struct prefix_ptr {
+       u_char family;
+       u_char prefixlen;
+       uintptr_t prefix __attribute__((aligned(8)));
 };
 
-struct prefix_sg
-{
-  u_char family;
-  u_char prefixlen;
-  struct in_addr src __attribute__ ((aligned (8)));
-  struct in_addr grp;
+struct prefix_sg {
+       u_char family;
+       u_char prefixlen;
+       struct in_addr src __attribute__((aligned(8)));
+       struct in_addr grp;
 };
 
 /* helper to get type safety/avoid casts on calls
@@ -190,21 +178,19 @@ struct prefix_sg
  * side, which strips type safety since the cast will accept any pointer
  * type.)
  */
-union prefixptr
-{
-  struct prefix *p;
-  struct prefix_ipv4 *p4;
-  struct prefix_ipv6 *p6;
-  struct prefix_evpn *evp;
-} __attribute__ ((transparent_union));
-
-union prefixconstptr
-{
-  const struct prefix *p;
-  const struct prefix_ipv4 *p4;
-  const struct prefix_ipv6 *p6;
-  const struct prefix_evpn *evp;
-} __attribute__ ((transparent_union));
+union prefixptr {
+       struct prefix *p;
+       struct prefix_ipv4 *p4;
+       struct prefix_ipv6 *p6;
+       struct prefix_evpn *evp;
+} __attribute__((transparent_union));
+
+union prefixconstptr {
+       const struct prefix *p;
+       const struct prefix_ipv4 *p4;
+       const struct prefix_ipv6 *p6;
+       const struct prefix_evpn *evp;
+} __attribute__((transparent_union));
 
 #ifndef INET_ADDRSTRLEN
 #define INET_ADDRSTRLEN 16
@@ -262,115 +248,118 @@ union prefixconstptr
 
 /* Prototypes. */
 extern int str2family(const char *);
-extern int afi2family (afi_t);
-extern afi_t family2afi (int);
+extern int afi2family(afi_t);
+extern afi_t family2afi(int);
 extern const char *safi2str(safi_t safi);
 extern const char *afi2str(afi_t afi);
 
 /* Check bit of the prefix. */
-extern unsigned int prefix_bit (const u_char *prefix, const u_char prefixlen);
-extern unsigned int prefix6_bit (const struct in6_addr *prefix, const u_char prefixlen);
+extern unsigned int prefix_bit(const u_char *prefix, const u_char prefixlen);
+extern unsigned int prefix6_bit(const struct in6_addr *prefix,
+                               const u_char prefixlen);
 
-extern struct prefix *prefix_new (void);
-extern void prefix_free (struct prefix *);
-extern const char *prefix_family_str (const struct prefix *);
-extern int prefix_blen (const struct prefix *);
-extern int str2prefix (const char *, struct prefix *);
+extern struct prefix *prefix_new(void);
+extern void prefix_free(struct prefix *);
+extern const char *prefix_family_str(const struct prefix *);
+extern int prefix_blen(const struct prefix *);
+extern int str2prefix(const char *, struct prefix *);
 
 #define PREFIX2STR_BUFFER  PREFIX_STRLEN
 
-extern const char *prefix2str (union prefixconstptr, char *, int);
-extern int prefix_match (const struct prefix *, const struct prefix *);
-extern int prefix_match_network_statement (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 *, struct prefix *p);
-extern void prefix2sockunion (const struct prefix *, union sockunion *);
-
-extern int str2prefix_eth (const char *, struct prefix_eth *);
-
-extern struct prefix_ipv4 *prefix_ipv4_new (void);
-extern void prefix_ipv4_free (struct prefix_ipv4 *);
-extern int str2prefix_ipv4 (const char *, struct prefix_ipv4 *);
-extern void apply_mask_ipv4 (struct prefix_ipv4 *);
-
-#define PREFIX_COPY_IPV4(DST, SRC)     \
+extern const char *prefix2str(union prefixconstptr, char *, int);
+extern int prefix_match(const struct prefix *, const struct prefix *);
+extern int prefix_match_network_statement(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 *,
+                                          struct prefix *p);
+extern void prefix2sockunion(const struct prefix *, union sockunion *);
+
+extern int str2prefix_eth(const char *, struct prefix_eth *);
+
+extern struct prefix_ipv4 *prefix_ipv4_new(void);
+extern void prefix_ipv4_free(struct prefix_ipv4 *);
+extern int str2prefix_ipv4(const char *, struct prefix_ipv4 *);
+extern void apply_mask_ipv4(struct prefix_ipv4 *);
+
+#define PREFIX_COPY_IPV4(DST, SRC)                                             \
        *((struct prefix_ipv4 *)(DST)) = *((const struct prefix_ipv4 *)(SRC));
 
-extern int prefix_ipv4_any (const struct prefix_ipv4 *);
-extern void apply_classful_mask_ipv4 (struct prefix_ipv4 *);
+extern int prefix_ipv4_any(const struct prefix_ipv4 *);
+extern void apply_classful_mask_ipv4(struct prefix_ipv4 *);
 
-extern u_char ip_masklen (struct in_addr);
-extern void masklen2ip (const int, struct in_addr *);
+extern u_char ip_masklen(struct in_addr);
+extern void masklen2ip(const int, struct in_addr *);
 /* returns the network portion of the host address */
-extern in_addr_t ipv4_network_addr (in_addr_t hostaddr, int masklen);
+extern in_addr_t ipv4_network_addr(in_addr_t hostaddr, int masklen);
 /* given the address of a host on a network and the network mask length,
  * calculate the broadcast address for that network;
  * special treatment for /31: returns the address of the other host
  * on the network by flipping the host bit */
-extern in_addr_t ipv4_broadcast_addr (in_addr_t hostaddr, int masklen);
+extern in_addr_t ipv4_broadcast_addr(in_addr_t hostaddr, int masklen);
 
-extern int netmask_str2prefix_str (const char *, const char *, char *);
+extern int netmask_str2prefix_str(const char *, const char *, char *);
 
-extern struct prefix_ipv6 *prefix_ipv6_new (void);
-extern void prefix_ipv6_free (struct prefix_ipv6 *);
-extern int str2prefix_ipv6 (const char *, struct prefix_ipv6 *);
-extern void apply_mask_ipv6 (struct prefix_ipv6 *);
+extern struct prefix_ipv6 *prefix_ipv6_new(void);
+extern void prefix_ipv6_free(struct prefix_ipv6 *);
+extern int str2prefix_ipv6(const char *, struct prefix_ipv6 *);
+extern void apply_mask_ipv6(struct prefix_ipv6 *);
 
-#define PREFIX_COPY_IPV6(DST, SRC)     \
+#define PREFIX_COPY_IPV6(DST, SRC)                                             \
        *((struct prefix_ipv6 *)(DST)) = *((const struct prefix_ipv6 *)(SRC));
 
-extern int ip6_masklen (struct in6_addr);
-extern void masklen2ip6 (const int, struct in6_addr *);
+extern int ip6_masklen(struct in6_addr);
+extern void masklen2ip6(const int, struct in6_addr *);
 
-extern const char *inet6_ntoa (struct in6_addr);
+extern const char *inet6_ntoa(struct in6_addr);
 
 extern int prefix_str2mac(const char *str, struct ethaddr *mac);
 extern char *prefix_mac2str(const struct ethaddr *mac, char *buf, int size);
 
-static inline int ipv6_martian (struct in6_addr *addr)
+static inline int ipv6_martian(struct in6_addr *addr)
 {
-  struct in6_addr localhost_addr;
+       struct in6_addr localhost_addr;
 
-  inet_pton (AF_INET6, "::1", &localhost_addr);
+       inet_pton(AF_INET6, "::1", &localhost_addr);
 
-  if (IPV6_ADDR_SAME(&localhost_addr, addr))
-    return 1;
+       if (IPV6_ADDR_SAME(&localhost_addr, addr))
+               return 1;
 
-  return 0;
+       return 0;
 }
 
-extern int all_digit (const char *);
+extern int all_digit(const char *);
 
 /* NOTE: This routine expects the address argument in network byte order. */
-static inline int ipv4_martian (struct in_addr *addr)
+static inline int ipv4_martian(struct in_addr *addr)
 {
-  in_addr_t ip = ntohl(addr->s_addr);
+       in_addr_t ip = ntohl(addr->s_addr);
 
-  if (IPV4_NET0(ip) || IPV4_NET127(ip) || IPV4_CLASS_DE(ip)) {
-    return 1;
-  }
-  return 0;
+       if (IPV4_NET0(ip) || IPV4_NET127(ip) || IPV4_CLASS_DE(ip)) {
+               return 1;
+       }
+       return 0;
 }
 
-static inline int
-is_default_prefix (struct prefix *p)
+static inline int is_default_prefix(struct prefix *p)
 {
-  if (!p)
-    return 0;
+       if (!p)
+               return 0;
 
-  if (((p->family == AF_INET) && (p->u.prefix4.s_addr == INADDR_ANY))
-      || ((p->family == AF_INET6) &&
-          !memcmp(&p->u.prefix6, &in6addr_any, sizeof (struct in6_addr))))
-    return 1;
+       if (((p->family == AF_INET) && (p->u.prefix4.s_addr == INADDR_ANY))
+           || ((p->family == AF_INET6)
+               && !memcmp(&p->u.prefix6, &in6addr_any,
+                          sizeof(struct in6_addr))))
+               return 1;
 
-  return 0;
+       return 0;
 }
 
 #endif /* _ZEBRA_PREFIX_H */