From: Donatas Abraitis Date: Fri, 1 Jul 2022 20:26:24 +0000 (+0300) Subject: lib: Allow using IPv4 (Class E) reserved block if enabled X-Git-Tag: base_8.4~273^2~3 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=d80132b13720857913e1e78bf61f25655062c488;p=matthieu%2Ffrr.git lib: Allow using IPv4 (Class E) reserved block if enabled Signed-off-by: Donatas Abraitis --- diff --git a/lib/prefix.c b/lib/prefix.c index 1a3efd32b1..e64b10bf24 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -21,6 +21,7 @@ #include +#include "command.h" #include "prefix.h" #include "ipaddr.h" #include "vty.h" @@ -1386,6 +1387,23 @@ char *evpn_es_df_alg2str(uint8_t df_alg, char *buf, int buf_len) return buf; } +bool ipv4_unicast_valid(const struct in_addr *addr) +{ + in_addr_t ip = ntohl(addr->s_addr); + + if (IPV4_CLASS_D(ip)) + return false; + + if (IPV4_CLASS_E(ip)) { + if (cmd_allow_reserved_ranges_get()) + return true; + else + return false; + } + + return true; +} + printfrr_ext_autoreg_p("EA", printfrr_ea); static ssize_t printfrr_ea(struct fbuf *buf, struct printfrr_eargs *ea, const void *ptr) diff --git a/lib/prefix.h b/lib/prefix.h index f9eef28a0b..6c51186f52 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -382,6 +382,8 @@ static inline void ipv4_addr_copy(struct in_addr *dst, #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_D(a) ((((uint32_t)(a)) & 0xf0000000) == 0xe0000000) +#define IPV4_CLASS_E(a) ((((uint32_t)(a)) & 0xf0000000) == 0xf0000000) #define IPV4_CLASS_DE(a) ((((uint32_t)(a)) & 0xe0000000) == 0xe0000000) #define IPV4_MC_LINKLOCAL(a) ((((uint32_t)(a)) & 0xffffff00) == 0xe0000000) @@ -507,17 +509,7 @@ extern int str_to_esi(const char *str, esi_t *esi); extern char *esi_to_str(const esi_t *esi, char *buf, int size); extern char *evpn_es_df_alg2str(uint8_t df_alg, char *buf, int buf_len); extern void prefix_evpn_hexdump(const struct prefix_evpn *p); - -static inline bool ipv4_unicast_valid(const struct in_addr *addr) -{ - - in_addr_t ip = ntohl(addr->s_addr); - - if (IPV4_CLASS_DE(ip)) - return false; - - return true; -} +extern bool ipv4_unicast_valid(const struct in_addr *addr); static inline int ipv6_martian(const struct in6_addr *addr) {