From 0705a1c5658c2682c915007f466f55d2a8f7ec14 Mon Sep 17 00:00:00 2001 From: Pavel Tvrdik Date: Thu, 30 Jun 2016 15:04:49 +0200 Subject: [PATCH] Add a hint for an invalid IP prefix bird> eval 200.210.220.0/16 Invalid IPv4 prefix 200.210.220.0/16, maybe you wanted 200.210.0.0/16 bird> eval 1000:2000::/8 Invalid IPv6 prefix 1000:2000::/8, maybe you wanted 1000::/8 --- conf/confbase.Y | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/conf/confbase.Y b/conf/confbase.Y index 47ee07ce..e7fd1677 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -187,17 +187,24 @@ pxlen4: net_ip4_: IP4 pxlen4 { net_fill_ip4(&($$), $1, $2); - if (!net_validate_ip4((net_addr_ip4 *) &($$))) - cf_error("Invalid IPv4 prefix"); + + net_addr_ip4 *n = (void *) &($$); + if (!net_validate_ip4(n)) + cf_error("Invalid IPv4 prefix %I4/%d, maybe you wanted %I4/%d", + n->prefix, n->pxlen, ip4_and(n->prefix, ip4_mkmask(n->pxlen)), n->pxlen); }; net_ip6_: IP6 '/' NUM { - net_fill_ip6(&($$), $1, $3); if ($3 < 0 || $3 > IP6_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %d", $3); - if (!net_validate_ip6((net_addr_ip6 *) &($$))) - cf_error("Invalid IPv6 prefix"); + + net_fill_ip6(&($$), $1, $3); + + net_addr_ip6 *n = (void *) &($$); + if (!net_validate_ip6(n)) + cf_error("Invalid IPv6 prefix %I6/%d, maybe you wanted %I6/%d", + n->prefix, n->pxlen, ip6_and(n->prefix, ip6_mkmask(n->pxlen)), n->pxlen); }; net_vpn4_: VPN_RD net_ip4_