From bc3443ebf032b5fcc9e0ccb94641e4e899cd17d8 Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Thu, 22 Sep 2011 12:48:14 +0400 Subject: bgpd: improve NEXT_HOP attribute checks (BZ#680) * lib/prefix.h * IPV4_CLASS_DE(): new helper macro * bgp_attr.c * bgp_attr_nexthop(): add check for "partial" bit, refresh flag error reporting, explain meaning of RFC4271 section 6.3 and implement it Conflicts: bgpd/bgp_attr.c --- lib/prefix.h | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/prefix.h') diff --git a/lib/prefix.h b/lib/prefix.h index 5f1ff05c..1cb91b2a 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -112,6 +112,7 @@ struct prefix_rd #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) /* Max bit/byte length of IPv6 address. */ #define IPV6_MAX_BYTELEN 16 -- cgit v1.2.1 From 17e52061bacec93e84324b23382e5ec61e1f16d0 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 2 Feb 2010 20:16:35 +0100 Subject: lib: prefix2sockunion, prefix_common_bits helper functions prefix2sockunion converts a struct prefix* to a union sockunion *; prefix_common_bits counts the number of common bits in the prefix's address part. --- lib/prefix.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/prefix.h') diff --git a/lib/prefix.h b/lib/prefix.h index 1cb91b2a..54f47c71 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -157,12 +157,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 void prefix2sockunion (const struct prefix *, union sockunion *); extern struct prefix_ipv4 *prefix_ipv4_new (void); extern void prefix_ipv4_free (struct prefix_ipv4 *); -- cgit v1.2.1 From 9663386f16e6285a322747514527fdf1d19788e4 Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Sat, 8 Oct 2011 18:15:21 +0400 Subject: lib: make masklen2ip() safer and faster --- lib/prefix.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/prefix.h') diff --git a/lib/prefix.h b/lib/prefix.h index 54f47c71..675f94d4 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -178,7 +178,7 @@ 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 (int, 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); /* given the address of a host on a network and the network mask length, -- cgit v1.2.1 From 21f569e37d62e3c1de6e41a4e5667c0e28279bb8 Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Mon, 17 Oct 2011 21:11:10 +0400 Subject: lib: make masklen2ip6() safer and faster --- lib/prefix.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/prefix.h') diff --git a/lib/prefix.h b/lib/prefix.h index 675f94d4..12c0d07e 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -199,7 +199,7 @@ extern void apply_mask_ipv6 (struct prefix_ipv6 *); *((struct prefix_ipv6 *)(DST)) = *((const struct prefix_ipv6 *)(SRC)); extern int ip6_masklen (struct in6_addr); -extern void masklen2ip6 (int, struct in6_addr *); +extern void masklen2ip6 (const int, struct in6_addr *); extern void str2in6_addr (const char *, struct in6_addr *); extern const char *inet6_ntoa (struct in6_addr); -- cgit v1.2.1 From 733cd9e5792648de50da3c00805aacb51cb27048 Mon Sep 17 00:00:00 2001 From: Denis Ovsienko Date: Sat, 17 Dec 2011 19:39:30 +0400 Subject: bgpd: justify checks for IPv4 class D/E * lib/prefix.h * IPV4_CLASS_DE(): make consistent with counterpart macros * bgp_packet.c * bgp_open_receive(): test using macro instead of ">=" * bgp_route.c * bgp_update_rsclient(): idem * bgp_update_main(): idem --- lib/prefix.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/prefix.h') diff --git a/lib/prefix.h b/lib/prefix.h index 12c0d07e..dab4202e 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -112,7 +112,7 @@ struct prefix_rd #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) +#define IPV4_CLASS_DE(a) ((((u_int32_t) (a)) & 0xe0000000) == 0xe0000000) /* Max bit/byte length of IPv6 address. */ #define IPV6_MAX_BYTELEN 16 -- cgit v1.2.1 From f63f06da2e7be6b17c72dd6110aae179f42f3700 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Fri, 8 Apr 2011 12:44:43 +0100 Subject: general: remove inline qualifiers and move in-header functions to objects * (general) Move functions in headers into files, to be compiled into shared object files. Remove inline qualifier from functions. Let the compiler do the work. --- lib/prefix.h | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'lib/prefix.h') diff --git a/lib/prefix.h b/lib/prefix.h index dab4202e..7f0d3607 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -128,26 +128,14 @@ struct prefix_rd /* Prefix's family member. */ #define PREFIX_FAMILY(p) ((p)->family) -/* Check bit of the prefix. */ -static inline unsigned int -prefix_bit (const u_char *prefix, const u_char prefixlen) -{ - unsigned int offset = prefixlen / 8; - unsigned int shift = 7 - (prefixlen % 8); - - return (prefix[offset] >> shift) & 1; -} - -static inline unsigned int -prefix6_bit (const struct in6_addr *prefix, const u_char prefixlen) -{ - return prefix_bit((const u_char *) &prefix->s6_addr, prefixlen); -} - /* Prototypes. */ extern int afi2family (afi_t); extern afi_t family2afi (int); +/* 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 struct prefix *prefix_new (void); extern void prefix_free (struct prefix *); extern const char *prefix_family_str (const struct prefix *); -- cgit v1.2.1