]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/prefix.h
*: use C99 standard fixed-width integer types
[mirror_frr.git] / lib / prefix.h
index bcc2230607802c25d826cacc88d4db56d3b4db37..133264f9998372d5bebba4f40287605af0e98861 100644 (file)
@@ -45,7 +45,7 @@
  * own to simplify internal handling
  */
 struct ethaddr {
-       u_char octet[ETH_ALEN];
+       uint8_t octet[ETH_ALEN];
 } __attribute__((packed));
 
 
@@ -58,15 +58,15 @@ struct ethaddr {
 
 /* EVPN address (RFC 7432) */
 struct evpn_addr {
-       u_char route_type;
-       u_char ip_prefix_length;
+       uint8_t route_type;
+       uint8_t ip_prefix_length;
        struct ethaddr mac;
        uint32_t eth_tag;
        struct ipaddr ip;
 #if 0
   union
   {
-    u_char addr;
+    uint8_t addr;
     struct in_addr v4_addr;
     struct in6_addr v6_addr;
   } ip;
@@ -108,10 +108,10 @@ struct evpn_addr {
 
 /* FRR generic prefix structure. */
 struct prefix {
-       u_char family;
-       u_char prefixlen;
+       uint8_t family;
+       uint8_t prefixlen;
        union {
-               u_char prefix;
+               uint8_t prefix;
                struct in_addr prefix4;
                struct in6_addr prefix6;
                struct {
@@ -119,7 +119,7 @@ struct prefix {
                        struct in_addr adv_router;
                } lp;
                struct ethaddr prefix_eth; /* AF_ETHERNET */
-               u_char val[16];
+               uint8_t val[16];
                uintptr_t ptr;
                struct evpn_addr prefix_evpn; /* AF_EVPN */
        } u __attribute__((aligned(8)));
@@ -127,56 +127,56 @@ struct prefix {
 
 /* IPv4 prefix structure. */
 struct prefix_ipv4 {
-       u_char family;
-       u_char prefixlen;
+       uint8_t family;
+       uint8_t prefixlen;
        struct in_addr prefix __attribute__((aligned(8)));
 };
 
 /* IPv6 prefix structure. */
 struct prefix_ipv6 {
-       u_char family;
-       u_char prefixlen;
+       uint8_t family;
+       uint8_t prefixlen;
        struct in6_addr prefix __attribute__((aligned(8)));
 };
 
 struct prefix_ls {
-       u_char family;
-       u_char prefixlen;
+       uint8_t family;
+       uint8_t 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)));
+       uint8_t family;
+       uint8_t prefixlen;
+       uint8_t val[8] __attribute__((aligned(8)));
 };
 
 /* Prefix for ethernet. */
 struct prefix_eth {
-       u_char family;
-       u_char prefixlen;
+       uint8_t family;
+       uint8_t prefixlen;
        struct ethaddr eth_addr __attribute__((aligned(8))); /* AF_ETHERNET */
 };
 
 /* EVPN prefix structure. */
 struct prefix_evpn {
-       u_char family;
-       u_char prefixlen;
+       uint8_t family;
+       uint8_t prefixlen;
        struct evpn_addr prefix __attribute__((aligned(8)));
 };
 
 /* Prefix for a generic pointer */
 struct prefix_ptr {
-       u_char family;
-       u_char prefixlen;
+       uint8_t family;
+       uint8_t prefixlen;
        uintptr_t prefix __attribute__((aligned(8)));
 };
 
 struct prefix_sg {
-       u_char family;
-       u_char prefixlen;
+       uint8_t family;
+       uint8_t prefixlen;
        struct in_addr src __attribute__((aligned(8)));
        struct in_addr grp;
 };
@@ -235,10 +235,11 @@ static inline void ipv4_addr_copy(struct in_addr *dst,
 }
 #define IPV4_ADDR_COPY(D,S)  ipv4_addr_copy((D), (S))
 
-#define IPV4_NET0(a)    ((((u_int32_t) (a)) & 0xff000000) == 0x00000000)
-#define IPV4_NET127(a)  ((((u_int32_t) (a)) & 0xff000000) == 0x7f000000)
-#define IPV4_LINKLOCAL(a) ((((u_int32_t) (a)) & 0xffff0000) == 0xa9fe0000)
-#define IPV4_CLASS_DE(a)  ((((u_int32_t) (a)) & 0xe0000000) == 0xe0000000)
+#define IPV4_NET0(a) ((((uint32_t)(a)) & 0xff000000) == 0x00000000)
+#define IPV4_NET127(a) ((((uint32_t)(a)) & 0xff000000) == 0x7f000000)
+#define IPV4_LINKLOCAL(a) ((((uint32_t)(a)) & 0xffff0000) == 0xa9fe0000)
+#define IPV4_CLASS_DE(a) ((((uint32_t)(a)) & 0xe0000000) == 0xe0000000)
+#define IPV4_MC_LINKLOCAL(a) ((((uint32_t)(a)) & 0xffffff00) == 0xe0000000)
 
 /* Max bit/byte length of IPv6 address. */
 #define IPV6_MAX_BYTELEN    16
@@ -274,9 +275,9 @@ 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 prefix_bit(const uint8_t *prefix, const uint8_t prefixlen);
 extern unsigned int prefix6_bit(const struct in6_addr *prefix,
-                               const u_char prefixlen);
+                               const uint8_t prefixlen);
 
 extern struct prefix *prefix_new(void);
 extern void prefix_free(struct prefix *);
@@ -309,15 +310,15 @@ 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(DST, SRC)                                        \
+#define PREFIX_COPY(DST, SRC)                                                  \
        *((struct prefix *)(DST)) = *((const struct prefix *)(SRC))
-#define PREFIX_COPY_IPV4(DST, SRC)                                   \
+#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 u_char ip_masklen(struct in_addr);
+extern uint8_t 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);
@@ -379,15 +380,12 @@ static inline int is_default_prefix(const struct prefix *p)
        if (!p)
                return 0;
 
-       if ((p->family == AF_INET) &&
-           (p->u.prefix4.s_addr == INADDR_ANY) &&
-           (p->prefixlen == 0))
+       if ((p->family == AF_INET) && (p->u.prefix4.s_addr == INADDR_ANY)
+           && (p->prefixlen == 0))
                return 1;
 
-       if ((p->family == AF_INET6) &&
-           (p->prefixlen == 0) &&
-           (!memcmp(&p->u.prefix6, &in6addr_any,
-                    sizeof(struct in6_addr))))
+       if ((p->family == AF_INET6) && (p->prefixlen == 0)
+           && (!memcmp(&p->u.prefix6, &in6addr_any, sizeof(struct in6_addr))))
                return 1;
 
        return 0;