From 81cce0185e23b6ecd2ab98ab34182901226bcf9e Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Tue, 28 Apr 2009 14:28:00 -0700 Subject: [cleanup] Use correct buffer size for inet_ntop() Don't need big buffer 1024 to hold IPV4 (INET_ADDRSTRLEN) or IPv6 (INET6_ADDRSTRLEN) message. --- zebra/interface.c | 4 ++-- zebra/redistribute.c | 10 ++++++---- zebra/zebra_rib.c | 34 +++++++++++++++++----------------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/zebra/interface.c b/zebra/interface.c index 9cbbf937..3e4867c4 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -1513,7 +1513,6 @@ if_config_write (struct vty *vty) { struct listnode *node; struct interface *ifp; - char buf[BUFSIZ]; for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { @@ -1543,10 +1542,11 @@ if_config_write (struct vty *vty) { if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) { + char buf[INET6_ADDRSTRLEN]; p = ifc->address; vty_out (vty, " ip%s address %s/%d", p->family == AF_INET ? "" : "v6", - inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), + inet_ntop (p->family, &p->u.prefix, buf, sizeof(buf)), p->prefixlen); if (ifc->label) diff --git a/zebra/redistribute.c b/zebra/redistribute.c index b7bd5674..a8107aeb 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -369,13 +369,14 @@ zebra_interface_address_add_update (struct interface *ifp, struct listnode *node, *nnode; struct zserv *client; struct prefix *p; - char buf[BUFSIZ]; if (IS_ZEBRA_DEBUG_EVENT) { + char buf[INET6_ADDRSTRLEN]; + p = ifc->address; zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s/%d on %s", - inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), + inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN), p->prefixlen, ifc->ifp->name); } @@ -394,13 +395,14 @@ zebra_interface_address_delete_update (struct interface *ifp, struct listnode *node, *nnode; struct zserv *client; struct prefix *p; - char buf[BUFSIZ]; if (IS_ZEBRA_DEBUG_EVENT) { + char buf[INET6_ADDRSTRLEN]; + p = ifc->address; zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s/%d on %s", - inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ), + inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN), p->prefixlen, ifc->ifp->name); } diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 19e3c0cd..e2108fcb 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1874,8 +1874,8 @@ rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, struct rib *fib = NULL; struct rib *same = NULL; struct nexthop *nexthop; - char buf1[BUFSIZ]; - char buf2[BUFSIZ]; + char buf1[INET_ADDRSTRLEN]; + char buf2[INET_ADDRSTRLEN]; /* Lookup table. */ table = vrf_table (AFI_IP, SAFI_UNICAST, 0); @@ -1887,7 +1887,7 @@ rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, if (IS_ZEBRA_DEBUG_KERNEL && gate) zlog_debug ("rib_delete_ipv4(): route delete %s/%d via %s ifindex %d", - inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ), + inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN), p->prefixlen, inet_ntoa (*gate), ifindex); @@ -1900,13 +1900,13 @@ rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, { if (gate) zlog_debug ("route %s/%d via %s ifindex %d doesn't exist in rib", - inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ), + inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN), p->prefixlen, - inet_ntop (AF_INET, gate, buf2, BUFSIZ), + inet_ntop (AF_INET, gate, buf2, INET_ADDRSTRLEN), ifindex); else zlog_debug ("route %s/%d ifindex %d doesn't exist in rib", - inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ), + inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN), p->prefixlen, ifindex); } @@ -1966,14 +1966,14 @@ rib_delete_ipv4 (int type, int flags, struct prefix_ipv4 *p, { if (gate) zlog_debug ("route %s/%d via %s ifindex %d type %d doesn't exist in rib", - inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ), + inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN), p->prefixlen, - inet_ntop (AF_INET, gate, buf2, BUFSIZ), + inet_ntop (AF_INET, gate, buf2, INET_ADDRSTRLEN), ifindex, type); else zlog_debug ("route %s/%d ifindex %d type %d doesn't exist in rib", - inet_ntop (AF_INET, &p->prefix, buf1, BUFSIZ), + inet_ntop (AF_INET, &p->prefix, buf1, INET_ADDRSTRLEN), p->prefixlen, ifindex, type); @@ -2429,8 +2429,8 @@ rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p, struct rib *fib = NULL; struct rib *same = NULL; struct nexthop *nexthop; - char buf1[BUFSIZ]; - char buf2[BUFSIZ]; + char buf1[INET6_ADDRSTRLEN]; + char buf2[INET6_ADDRSTRLEN]; /* Apply mask. */ apply_mask_ipv6 (p); @@ -2448,13 +2448,13 @@ rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p, { if (gate) zlog_debug ("route %s/%d via %s ifindex %d doesn't exist in rib", - inet_ntop (AF_INET6, &p->prefix, buf1, BUFSIZ), + inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN), p->prefixlen, - inet_ntop (AF_INET6, gate, buf2, BUFSIZ), + inet_ntop (AF_INET6, gate, buf2, INET6_ADDRSTRLEN), ifindex); else zlog_debug ("route %s/%d ifindex %d doesn't exist in rib", - inet_ntop (AF_INET6, &p->prefix, buf1, BUFSIZ), + inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN), p->prefixlen, ifindex); } @@ -2514,14 +2514,14 @@ rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p, { if (gate) zlog_debug ("route %s/%d via %s ifindex %d type %d doesn't exist in rib", - inet_ntop (AF_INET6, &p->prefix, buf1, BUFSIZ), + inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN), p->prefixlen, - inet_ntop (AF_INET6, gate, buf2, BUFSIZ), + inet_ntop (AF_INET6, gate, buf2, INET6_ADDRSTRLEN), ifindex, type); else zlog_debug ("route %s/%d ifindex %d type %d doesn't exist in rib", - inet_ntop (AF_INET6, &p->prefix, buf1, BUFSIZ), + inet_ntop (AF_INET6, &p->prefix, buf1, INET6_ADDRSTRLEN), p->prefixlen, ifindex, type); -- cgit v1.2.1