]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Integrated address print lengths
authorJan Moskyto Matejka <mq@ucw.cz>
Fri, 18 Dec 2015 10:57:38 +0000 (11:57 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Sun, 20 Dec 2015 12:47:39 +0000 (13:47 +0100)
Minor changes by Ondrej Santiago Zajicek

lib/ip.h
lib/net.c
lib/net.h
lib/printf.c
nest/iface.c
nest/rt-table.c
proto/ospf/ospf.c
proto/static/static.c

index 1834db4f1cb8f142377167f71775ee817e04b00c..7a31dad0804331859a08f399a7df7db43b7faa47 100644 (file)
--- a/lib/ip.h
+++ b/lib/ip.h
 #define IP4_MAX_PREFIX_LENGTH  32
 #define IP6_MAX_PREFIX_LENGTH  128
 
+#define IP4_MAX_TEXT_LENGTH    15      /* "255.255.255.255" */
+#define IP6_MAX_TEXT_LENGTH    39      /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" */
+#define IPA_MAX_TEXT_LENGTH    39
+
 #define IP4_MIN_MTU            576
 #define IP6_MIN_MTU            1280
 
 #define IP6_HEADER_LENGTH      40
 #define UDP_HEADER_LENGTH      8
 
-#ifdef IPV6
-#define STD_ADDRESS_P_LENGTH 39
-#else
-#define STD_ADDRESS_P_LENGTH 15
-#endif
-
 
 #ifdef DEBUGGING
 
index 56eb16fda1a5d861f10455936d44596211211fd5..b851871adfb961d670dfad2ebd6f0dbaad909fa7 100644 (file)
--- a/lib/net.c
+++ b/lib/net.c
@@ -18,6 +18,13 @@ const u8 net_max_prefix_length[] = {
   [NET_VPN6] = IP4_MAX_PREFIX_LENGTH
 };
 
+const u16 net_max_text_length[] = {
+  [NET_IP4] = 18,      /* "255.255.255.255/32" */
+  [NET_IP6] = 43,      /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */
+  [NET_VPN4] = 40,     /* "4294967296:4294967296 255.255.255.255/32" */
+  [NET_VPN6] = 65,     /* "4294967296:4294967296 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */
+};
+
 
 int
 net_format(const net_addr *N, char *buf, int buflen)
index c9ca349fd4f7d6f72f7933696ca975158d4ad158..ee9b382ec80fe953e7218478d413b17f686d2c05 100644 (file)
--- a/lib/net.h
+++ b/lib/net.h
@@ -68,7 +68,11 @@ typedef union net_addr_union {
 
 
 extern const u16 net_addr_length[];
-extern const u8 net_max_prefix_length[];
+extern const u8  net_max_prefix_length[];
+extern const u16 net_max_text_length[];
+
+#define NET_MAX_TEXT_LENGTH    65
+
 
 #define NET_ADDR_IP4(prefix,pxlen) \
   ((net_addr_ip4) { NET_IP4, pxlen, sizeof(net_addr_ip4), prefix })
@@ -103,6 +107,7 @@ static inline void net_fill_ipa(net_addr *a, ip_addr prefix, uint pxlen)
     net_fill_ip6(a, ipa_to_ip6(prefix), pxlen);
 }
 
+
 static inline ip4_addr net4_prefix(const net_addr *a)
 { return ((net_addr_ip4 *) a)->prefix; }
 
@@ -243,6 +248,3 @@ int net_in_netX(const net_addr *A, const net_addr *N);
 
 
 #endif
-
-
-
index 1a8c2a9069c770e6c7c40f3c11e4371e47a12692..9db5363b7888e7d5916dadd303fc85e8a2087798 100644 (file)
@@ -139,7 +139,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
        u32 x;
        char *str, *start;
        const char *s;
-       char ipbuf[STD_ADDRESS_P_LENGTH+1];
+       char ipbuf[NET_MAX_TEXT_LENGTH+1];
        struct iface *iface;
 
        int flags;              /* flags to number() */
@@ -156,7 +156,7 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
                        *str++ = *fmt;
                        continue;
                }
-                       
+
                /* process flags */
                flags = 0;
                repeat:
@@ -236,12 +236,14 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
                case 'M':
                        s = strerror(va_arg(args, int));
                        goto str;
-               case 'N':
+               case 'N': {
+                       net_addr *n = va_arg(args, net_addr *);
                        if (field_width == 1)
-                               field_width = STD_ADDRESS_P_LENGTH; /* XXXX */
-                       net_format(va_arg(args, net_addr *), ipbuf, sizeof(ipbuf));
+                               field_width = net_max_text_length[n->type];
+                       net_format(n, ipbuf, sizeof(ipbuf));
                        s = ipbuf;
                        goto str;
+                       }
                case 's':
                        s = va_arg(args, char *);
                        if (!s)
@@ -287,17 +289,18 @@ int bvsnprintf(char *buf, int size, const char *fmt, va_list args)
                        continue;
 
                /* IP address */
-               case 'I':
+               case 'I': {
+                       ip_addr a = va_arg(args, ip_addr);
                        if (flags & SPECIAL)
-                               ipa_ntox(va_arg(args, ip_addr), ipbuf);
+                               ipa_ntox(a, ipbuf);
                        else {
-                               ipa_ntop(va_arg(args, ip_addr), ipbuf);
+                               ipa_ntop(a, ipbuf);
                                if (field_width == 1)
-                                       field_width = STD_ADDRESS_P_LENGTH;
+                                       field_width = (ipa_is_ip4(a) ? IP4_MAX_TEXT_LENGTH : IP6_MAX_TEXT_LENGTH);
                        }
                        s = ipbuf;
                        goto str;
-
+                       }
                /* Interface scope after link-local IP address */
                case 'J':
                        iface = va_arg(args, struct iface *);
index 5d3c0e609a5752b17266bf2be8db88b0862f3eda..3eaa5ebd4c43f2d947d2fd3d0ab435cc5e17bc16 100644 (file)
@@ -742,7 +742,7 @@ iface_patts_equal(list *a, list *b, int (*comp)(struct iface_patt *, struct ifac
 static void
 if_show_addr(struct ifa *a)
 {
-  byte opp[STD_ADDRESS_P_LENGTH + 16];
+  byte opp[IPA_MAX_TEXT_LENGTH + 16];
 
   if (ipa_nonzero(a->opposite))
     bsprintf(opp, ", opposite %I", a->opposite);
@@ -793,7 +793,7 @@ void
 if_show_summary(void)
 {
   struct iface *i;
-  byte addr[STD_ADDRESS_P_LENGTH + 16];
+  byte addr[IPA_MAX_TEXT_LENGTH + 16];
 
   cli_msg(-2005, "interface state address");
   WALK_LIST(i, iface_list)
index 6ac659a8c5f7e1a5e23f481d28cc3ecd679170ad..7eedec41587fbdcad9bb0d9c0397a98dbc58dbb5 100644 (file)
@@ -220,7 +220,7 @@ rte_mergable(rte *pri, rte *sec)
 static void
 rte_trace(struct proto *p, rte *e, int dir, char *msg)
 {
-  byte via[STD_ADDRESS_P_LENGTH+32];
+  byte via[IPA_MAX_TEXT_LENGTH+32];
 
   rt_format_via(e, via);
   log(L_TRACE "%s %c %s %N %s", p->name, dir, msg, e->net->n.addr, via);
@@ -2383,7 +2383,8 @@ rt_format_via(rte *e, byte *via)
 static void
 rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, ea_list *tmpa)
 {
-  byte via[STD_ADDRESS_P_LENGTH+32], from[STD_ADDRESS_P_LENGTH+8];
+  byte via[IPA_MAX_TEXT_LENGTH+32];
+  byte from[IPA_MAX_TEXT_LENGTH+8];
   byte tm[TM_DATETIME_BUFFER_SIZE], info[256];
   rta *a = e->attrs;
   int primary = (e->net->routes == e);
@@ -2424,7 +2425,7 @@ static void
 rt_show_net(struct cli *c, net *n, struct rt_show_data *d)
 {
   rte *e, *ee;
-  byte ia[STD_ADDRESS_P_LENGTH+8];
+  byte ia[NET_MAX_TEXT_LENGTH+1];
   struct ea_list *tmpa;
   struct announce_hook *a = NULL;
   int first = 1;
index cdc62d0a7b2bd3f6bf58d65c77d1c35c973b39dd..983f76f13bdd6ec9352f2f675319186a1587eb89 100644 (file)
@@ -1094,7 +1094,7 @@ static inline void
 show_lsa_external(struct top_hash_entry *he, int ospf2)
 {
   struct ospf_lsa_ext_local rt;
-  char str_via[STD_ADDRESS_P_LENGTH + 8] = "";
+  char str_via[IPA_MAX_TEXT_LENGTH + 8] = "";
   char str_tag[16] = "";
 
   if (he->lsa_type == LSA_T_EXT)
index bc5f104fcb4766249168b51f4b77a05c729f15fa..809c29fbb85c4b9ede7ae7e49919e853ec82be8c 100644 (file)
@@ -643,7 +643,7 @@ struct protocol proto_static = {
 static void
 static_show_rt(struct static_route *r)
 {
-  byte via[STD_ADDRESS_P_LENGTH + 16];
+  byte via[IPA_MAX_TEXT_LENGTH + 25];
 
   switch (r->dest)
     {