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
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index 2c0113d..f5a74d1 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -1381,7 +1381,7 @@
/* remote router-id check. */
if (remote_id.s_addr == 0
- || ntohl (remote_id.s_addr) >= 0xe0000000
+ || IPV4_CLASS_DE (ntohl (remote_id.s_addr))
|| ntohl (peer->local_id.s_addr) == ntohl (remote_id.s_addr))
{
if (BGP_DEBUG (normal, NORMAL))
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index e325f66..6477a7c 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -1812,9 +1812,9 @@
/* IPv4 unicast next hop check. */
if (afi == AFI_IP && safi == SAFI_UNICAST)
{
- /* Next hop must not be 0.0.0.0 nor Class E address. */
+ /* Next hop must not be 0.0.0.0 nor Class D/E address. */
if (new_attr.nexthop.s_addr == 0
- || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
+ || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
{
bgp_attr_unintern (&attr_new);
@@ -2068,11 +2068,11 @@
goto filtered;
}
- /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
+ /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
must not be my own address. */
if (bgp_nexthop_self (afi, &new_attr)
|| new_attr.nexthop.s_addr == 0
- || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
+ || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
{
reason = "martian next-hop;";
goto filtered;
diff --git a/lib/prefix.h b/lib/prefix.h
index 12c0d07..dab4202 100644
--- a/lib/prefix.h
+++ b/lib/prefix.h
@@ -112,7 +112,7 @@
#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