summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgp_attr.c2
-rw-r--r--bgpd/bgp_debug.c8
-rw-r--r--bgpd/bgp_ecommunity.c2
-rw-r--r--bgpd/bgp_mplsvpn.c16
-rw-r--r--bgpd/bgp_msg_read.c4
-rw-r--r--bgpd/bgp_nexthop.c6
-rw-r--r--bgpd/bgp_route.c42
-rw-r--r--bgpd/bgp_vty.c4
-rw-r--r--bgpd/bgpd.c4
-rw-r--r--lib/Makefile.am4
-rw-r--r--lib/filter.c24
-rw-r--r--lib/if.c6
-rw-r--r--lib/log.c8
-rw-r--r--lib/log.h1
-rw-r--r--lib/memtypes.c1
-rw-r--r--lib/pthread_safe.c124
-rw-r--r--lib/pthread_safe.h32
-rw-r--r--lib/qlib_init.c3
-rw-r--r--lib/sockunion.c4
19 files changed, 224 insertions, 71 deletions
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 5e7536ae..393a22dd 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -464,7 +464,7 @@ attr_show_all_iterator (struct hash_backet *backet, struct vty *vty)
struct attr *attr = backet->data;
vty_out (vty, "attr[%ld] nexthop %s%s", attr->refcnt,
- inet_ntoa (attr->nexthop), VTY_NEWLINE);
+ safe_inet_ntoa (attr->nexthop), VTY_NEWLINE);
}
void
diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c
index 3e3042a7..6ebd24ca 100644
--- a/bgpd/bgp_debug.c
+++ b/bgpd/bgp_debug.c
@@ -180,7 +180,7 @@ bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size)
return 0;
if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_NEXT_HOP)))
- snprintf (buf, size, "nexthop %s", inet_ntoa (attr->nexthop));
+ snprintf (buf, size, "nexthop %s", safe_inet_ntoa (attr->nexthop));
if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGIN)))
snprintf (buf + strlen (buf), size - strlen (buf), ", origin %s",
@@ -223,11 +223,11 @@ bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size)
if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
snprintf (buf + strlen (buf), size - strlen (buf), ", aggregated by %u %s",
attr->extra->aggregator_as,
- inet_ntoa (attr->extra->aggregator_addr));
+ safe_inet_ntoa (attr->extra->aggregator_addr));
if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)))
snprintf (buf + strlen (buf), size - strlen (buf), ", originator %s",
- inet_ntoa (attr->extra->originator_id));
+ safe_inet_ntoa (attr->extra->originator_id));
if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_CLUSTER_LIST)))
{
@@ -236,7 +236,7 @@ bgp_dump_attr (struct peer *peer, struct attr *attr, char *buf, size_t size)
snprintf (buf + strlen (buf), size - strlen (buf), ", clusterlist");
for (i = 0; i < attr->extra->cluster->length / 4; i++)
snprintf (buf + strlen (buf), size - strlen (buf), " %s",
- inet_ntoa (attr->extra->cluster->list[i]));
+ safe_inet_ntoa (attr->extra->cluster->list[i]));
}
if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AS_PATH)))
diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c
index 8d5fa741..605875a9 100644
--- a/bgpd/bgp_ecommunity.c
+++ b/bgpd/bgp_ecommunity.c
@@ -708,7 +708,7 @@ ecommunity_ecom2str (struct ecommunity *ecom, int format)
eip.val |= (*pnt++);
len = sprintf (str_buf + str_pnt, "%s%s:%d", prefix,
- inet_ntoa (eip.ip), eip.val);
+ safe_inet_ntoa (eip.ip), eip.val);
str_pnt += len;
first = 0;
}
diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c
index 206844f9..8682424c 100644
--- a/bgpd/bgp_mplsvpn.c
+++ b/bgpd/bgp_mplsvpn.c
@@ -146,10 +146,10 @@ bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
#if 0
if (type == RD_TYPE_AS)
zlog_info ("prefix %ld:%ld:%ld:%s/%d", label, rd_as.as, rd_as.val,
- inet_ntoa (p.u.prefix4), p.prefixlen);
+ safe_inet_ntoa (p.u.prefix4), p.prefixlen);
else if (type == RD_TYPE_IP)
- zlog_info ("prefix %ld:%s:%ld:%s/%d", label, inet_ntoa (rd_ip.ip),
- rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
+ zlog_info ("prefix %ld:%s:%ld:%s/%d", label, safe_inet_ntoa (rd_ip.ip),
+ rd_ip.val, safe_inet_ntoa (p.u.prefix4), p.prefixlen);
#endif /* 0 */
if (pnt + psize > lim)
@@ -271,7 +271,7 @@ prefix_rd2str (struct prefix_rd *prd, char *buf, size_t size)
else if (type == RD_TYPE_IP)
{
decode_rd_ip (pnt + 2, &rd_ip);
- snprintf (buf, size, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
+ snprintf (buf, size, "%s:%d", safe_inet_ntoa (rd_ip.ip), rd_ip.val);
return buf;
}
@@ -342,7 +342,7 @@ show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd)
if (header)
{
vty_out (vty, "BGP table version is 0, local router ID is %s%s",
- inet_ntoa (bgp->router_id), VTY_NEWLINE);
+ safe_inet_ntoa (bgp->router_id), VTY_NEWLINE);
vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
VTY_NEWLINE);
vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
@@ -373,7 +373,7 @@ show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd)
if (type == RD_TYPE_AS)
vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
else if (type == RD_TYPE_IP)
- vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
+ vty_out (vty, "%s:%d", safe_inet_ntoa (rd_ip.ip), rd_ip.val);
vty_out (vty, "%s", VTY_NEWLINE);
rd_header = 0;
@@ -448,7 +448,7 @@ bgp_show_mpls_vpn (struct vty *vty, struct prefix_rd *prd, enum bgp_show_type ty
else
{
vty_out (vty, "BGP table version is 0, local router ID is %s%s",
- inet_ntoa (bgp->router_id), VTY_NEWLINE);
+ safe_inet_ntoa (bgp->router_id), VTY_NEWLINE);
vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
VTY_NEWLINE);
vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
@@ -480,7 +480,7 @@ bgp_show_mpls_vpn (struct vty *vty, struct prefix_rd *prd, enum bgp_show_type ty
if (type == RD_TYPE_AS)
vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
else if (type == RD_TYPE_IP)
- vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
+ vty_out (vty, "%s:%d", safe_inet_ntoa (rd_ip.ip), rd_ip.val);
vty_out (vty, "%s", VTY_NEWLINE);
rd_header = 0;
diff --git a/bgpd/bgp_msg_read.c b/bgpd/bgp_msg_read.c
index 9b02fddc..48227364 100644
--- a/bgpd/bgp_msg_read.c
+++ b/bgpd/bgp_msg_read.c
@@ -355,7 +355,7 @@ bgp_msg_open_receive (bgp_connection connection, bgp_size_t body_size)
" holdtime %d, id %s",
connection->host, version,
open_recv->my_as, open_recv->holdtime,
- inet_ntoa (remote_id));
+ safe_inet_ntoa (remote_id));
/* Peer BGP version check. */
if (version != BGP_VERSION_4)
@@ -375,7 +375,7 @@ bgp_msg_open_receive (bgp_connection connection, bgp_size_t body_size)
(open_recv->bgp_id == connection->session->open_send->bgp_id))
{
zlog_debug ("%s rcv OPEN, multicast or our id %s",
- connection->host, inet_ntoa (remote_id)) ;
+ connection->host, safe_inet_ntoa (remote_id)) ;
bgp_msg_noms_o_bad_id(notification, open_recv->bgp_id) ;
goto reject ;
} ;
diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c
index 32dae086..faf4e7a6 100644
--- a/bgpd/bgp_nexthop.c
+++ b/bgpd/bgp_nexthop.c
@@ -1193,10 +1193,10 @@ DEFUN (show_ip_bgp_scan,
{
if (bnc->valid)
vty_out (vty, " %s valid [IGP metric %d]%s",
- inet_ntoa (rn->p.u.prefix4), bnc->metric, VTY_NEWLINE);
+ safe_inet_ntoa (rn->p.u.prefix4), bnc->metric, VTY_NEWLINE);
else
vty_out (vty, " %s invalid%s",
- inet_ntoa (rn->p.u.prefix4), VTY_NEWLINE);
+ safe_inet_ntoa (rn->p.u.prefix4), VTY_NEWLINE);
}
#ifdef HAVE_IPV6
@@ -1224,7 +1224,7 @@ DEFUN (show_ip_bgp_scan,
rn;
rn = bgp_route_next (rn))
if (rn->info != NULL)
- vty_out (vty, " %s/%d%s", inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
+ vty_out (vty, " %s/%d%s", safe_inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
VTY_NEWLINE);
#ifdef HAVE_IPV6
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 5ca89b06..3e2b54a3 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -3076,7 +3076,7 @@ bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
*/
zlog (peer->log, LOG_ERR,
"IPv4 unicast NLRI is multicast address %s",
- inet_ntoa (p.u.prefix4));
+ safe_inet_ntoa (p.u.prefix4));
return -1;
}
@@ -5715,9 +5715,9 @@ route_vty_out (struct vty *vty, struct prefix *p,
{
if (safi == SAFI_MPLS_VPN)
vty_out (vty, "%-16s",
- inet_ntoa (attr->extra->mp_nexthop_global_in));
+ safe_inet_ntoa (attr->extra->mp_nexthop_global_in));
else
- vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
+ vty_out (vty, "%-16s", safe_inet_ntoa (attr->nexthop));
}
#ifdef HAVE_IPV6
else if (p->family == AF_INET6)
@@ -5778,9 +5778,9 @@ route_vty_out_tmp (struct vty *vty, struct prefix *p,
{
if (safi == SAFI_MPLS_VPN)
vty_out (vty, "%-16s",
- inet_ntoa (attr->extra->mp_nexthop_global_in));
+ safe_inet_ntoa (attr->extra->mp_nexthop_global_in));
else
- vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
+ vty_out (vty, "%-16s", safe_inet_ntoa (attr->nexthop));
}
#ifdef HAVE_IPV6
else if (p->family == AF_INET6)
@@ -5851,9 +5851,9 @@ route_vty_out_tag (struct vty *vty, struct prefix *p,
{
if (safi == SAFI_MPLS_VPN)
vty_out (vty, "%-16s",
- inet_ntoa (attr->extra->mp_nexthop_global_in));
+ safe_inet_ntoa (attr->extra->mp_nexthop_global_in));
else
- vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
+ vty_out (vty, "%-16s", safe_inet_ntoa (attr->nexthop));
}
#ifdef HAVE_IPV6
else if (p->family == AF_INET6)
@@ -6015,7 +6015,7 @@ route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
vty_out (vty, ", (aggregated by %u %s)",
attr->extra->aggregator_as,
- inet_ntoa (attr->extra->aggregator_addr));
+ safe_inet_ntoa (attr->extra->aggregator_addr));
if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
vty_out (vty, ", (Received from a RR-client)");
if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
@@ -6030,8 +6030,8 @@ route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
if (p->family == AF_INET)
{
vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
- inet_ntoa (attr->extra->mp_nexthop_global_in) :
- inet_ntoa (attr->nexthop));
+ safe_inet_ntoa (attr->extra->mp_nexthop_global_in) :
+ safe_inet_ntoa (attr->nexthop));
}
#ifdef HAVE_IPV6
else
@@ -6047,7 +6047,7 @@ route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
{
vty_out (vty, " from %s ",
p->family == AF_INET ? "0.0.0.0" : "::");
- vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
+ vty_out (vty, "(%s)", safe_inet_ntoa(bgp->router_id));
}
else
{
@@ -6057,7 +6057,7 @@ route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
- vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
+ vty_out (vty, " (%s)", safe_inet_ntoa (attr->extra->originator_id));
else
vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
}
@@ -6131,7 +6131,7 @@ route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
assert (attr->extra);
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
vty_out (vty, " Originator: %s",
- inet_ntoa (attr->extra->originator_id));
+ safe_inet_ntoa (attr->extra->originator_id));
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
{
@@ -6139,7 +6139,7 @@ route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
vty_out (vty, ", Cluster list: ");
for (i = 0; i < attr->extra->cluster->length / 4; i++)
vty_out (vty, "%s ",
- inet_ntoa (attr->extra->cluster->list[i]));
+ safe_inet_ntoa (attr->extra->cluster->list[i]));
}
vty_out (vty, "%s", VTY_NEWLINE);
}
@@ -6366,7 +6366,7 @@ bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router
if (header)
{
- vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
+ vty_out (vty, "BGP table version is 0, local router ID is %s%s", safe_inet_ntoa (*router_id), VTY_NEWLINE);
vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
if (type == bgp_show_type_dampend_paths
@@ -9630,7 +9630,7 @@ show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
PEER_STATUS_DEFAULT_ORIGINATE))
{
- vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
+ vty_out (vty, "BGP table version is 0, local router ID is %s%s", safe_inet_ntoa (bgp->router_id), VTY_NEWLINE);
vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
@@ -9647,7 +9647,7 @@ show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
{
if (header1)
{
- vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
+ vty_out (vty, "BGP table version is 0, local router ID is %s%s", safe_inet_ntoa (bgp->router_id), VTY_NEWLINE);
vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
header1 = 0;
@@ -9671,7 +9671,7 @@ show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
{
if (header1)
{
- vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
+ vty_out (vty, "BGP table version is 0, local router ID is %s%s", safe_inet_ntoa (bgp->router_id), VTY_NEWLINE);
vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
header1 = 0;
@@ -11546,7 +11546,7 @@ bgp_config_write_network (struct vty *vty, struct bgp *bgp,
/* Natural mask is not display. */
}
else
- vty_out (vty, " mask %s", inet_ntoa (netmask));
+ vty_out (vty, " mask %s", safe_inet_ntoa (netmask));
}
else
{
@@ -11584,7 +11584,7 @@ bgp_config_write_network (struct vty *vty, struct bgp *bgp,
masklen2ip (p->prefixlen, &netmask);
vty_out (vty, " aggregate-address %s %s",
inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
- inet_ntoa (netmask));
+ safe_inet_ntoa (netmask));
}
else
{
@@ -11626,7 +11626,7 @@ bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
if ((bdistance = rn->info) != NULL)
{
vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
- inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
+ safe_inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
bdistance->access_list ? bdistance->access_list : "",
VTY_NEWLINE);
}
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 5452640b..272edfd9 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -6714,7 +6714,7 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi)
/* Usage summary and header */
vty_out (vty,
"BGP router identifier %s, local AS number %u%s",
- inet_ntoa (bgp->router_id), bgp->as, VTY_NEWLINE);
+ safe_inet_ntoa (bgp->router_id), bgp->as, VTY_NEWLINE);
ents = bgp_table_count (bgp->rib[afi][safi]);
vty_out (vty, "RIB entries %ld, using %s of memory%s", ents,
@@ -8062,7 +8062,7 @@ bgp_show_rsclient_summary (struct vty *vty, struct bgp *bgp,
{
vty_out (vty,
"Route Server's BGP router identifier %s%s",
- inet_ntoa (bgp->router_id), VTY_NEWLINE);
+ safe_inet_ntoa (bgp->router_id), VTY_NEWLINE);
vty_out (vty,
"Route Server's local AS number %u%s", bgp->as,
VTY_NEWLINE);
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 4a1faa19..2ea4d798 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -4500,7 +4500,7 @@ bgp_config_write (struct vty *vty)
/* BGP router ID. */
if (CHECK_FLAG (bgp->config, BGP_CONFIG_ROUTER_ID))
- vty_out (vty, " bgp router-id %s%s", inet_ntoa (bgp->router_id),
+ vty_out (vty, " bgp router-id %s%s", safe_inet_ntoa (bgp->router_id),
VTY_NEWLINE);
/* BGP log-neighbor-changes. */
@@ -4526,7 +4526,7 @@ bgp_config_write (struct vty *vty)
/* BGP cluster ID. */
if (CHECK_FLAG (bgp->config, BGP_CONFIG_CLUSTER_ID))
- vty_out (vty, " bgp cluster-id %s%s", inet_ntoa (bgp->cluster_id),
+ vty_out (vty, " bgp cluster-id %s%s", safe_inet_ntoa (bgp->cluster_id),
VTY_NEWLINE);
/* Confederation identifier*/
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 7d97bfcb..9f21a377 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -14,7 +14,7 @@ libzebra_la_SOURCES = \
zclient.c sockopt.c smux.c md5.c if_rmap.c keychain.c privs.c \
sigevent.c pqueue.c jhash.c memtypes.c workqueue.c symtab.c heap.c \
qtime.c qpthreads.c mqueue.c qpselect.c qtimers.c qpnexus.c \
- command_queue.c qlib_init.c
+ command_queue.c qlib_init.c pthread_safe.c
BUILT_SOURCES = memtypes.h route_types.h
@@ -32,7 +32,7 @@ pkginclude_HEADERS = \
workqueue.h route_types.h symtab.h heap.h \
qtime.h qpthreads.h mqueue.h qpselect.h qtimers.h qpnexus.h \
command_queue.h qlib_init.h qafi_safi.h \
- confirm.h miyagi.h
+ confirm.h miyagi.h pthread_safe.h
EXTRA_DIST = regex.c regex-gnu.h memtypes.awk route_types.awk route_types.txt
diff --git a/lib/filter.c b/lib/filter.c
index 57109854..a607cb4e 100644
--- a/lib/filter.c
+++ b/lib/filter.c
@@ -1620,9 +1620,9 @@ filter_show (struct vty *vty, const char *name, afi_t afi)
vty_out (vty, " any%s", VTY_NEWLINE);
else
{
- vty_out (vty, " %s", inet_ntoa (filter->addr));
+ vty_out (vty, " %s", safe_inet_ntoa (filter->addr));
if (filter->addr_mask.s_addr != 0)
- vty_out (vty, ", wildcard bits %s", inet_ntoa (filter->addr_mask));
+ vty_out (vty, ", wildcard bits %s", safe_inet_ntoa (filter->addr_mask));
vty_out (vty, "%s", VTY_NEWLINE);
}
}
@@ -1663,9 +1663,9 @@ filter_show (struct vty *vty, const char *name, afi_t afi)
vty_out (vty, " any%s", VTY_NEWLINE);
else
{
- vty_out (vty, " %s", inet_ntoa (filter->addr));
+ vty_out (vty, " %s", safe_inet_ntoa (filter->addr));
if (filter->addr_mask.s_addr != 0)
- vty_out (vty, ", wildcard bits %s", inet_ntoa (filter->addr_mask));
+ vty_out (vty, ", wildcard bits %s", safe_inet_ntoa (filter->addr_mask));
vty_out (vty, "%s", VTY_NEWLINE);
}
}
@@ -1735,21 +1735,21 @@ config_write_access_cisco (struct vty *vty, struct filter *mfilter)
if (filter->addr_mask.s_addr == 0xffffffff)
vty_out (vty, " any");
else if (filter->addr_mask.s_addr == 0)
- vty_out (vty, " host %s", inet_ntoa (filter->addr));
+ vty_out (vty, " host %s", safe_inet_ntoa (filter->addr));
else
{
- vty_out (vty, " %s", inet_ntoa (filter->addr));
- vty_out (vty, " %s", inet_ntoa (filter->addr_mask));
+ vty_out (vty, " %s", safe_inet_ntoa (filter->addr));
+ vty_out (vty, " %s", safe_inet_ntoa (filter->addr_mask));
}
if (filter->mask_mask.s_addr == 0xffffffff)
vty_out (vty, " any");
else if (filter->mask_mask.s_addr == 0)
- vty_out (vty, " host %s", inet_ntoa (filter->mask));
+ vty_out (vty, " host %s", safe_inet_ntoa (filter->mask));
else
{
- vty_out (vty, " %s", inet_ntoa (filter->mask));
- vty_out (vty, " %s", inet_ntoa (filter->mask_mask));
+ vty_out (vty, " %s", safe_inet_ntoa (filter->mask));
+ vty_out (vty, " %s", safe_inet_ntoa (filter->mask_mask));
}
vty_out (vty, "%s", VTY_NEWLINE);
}
@@ -1759,9 +1759,9 @@ config_write_access_cisco (struct vty *vty, struct filter *mfilter)
vty_out (vty, " any%s", VTY_NEWLINE);
else
{
- vty_out (vty, " %s", inet_ntoa (filter->addr));
+ vty_out (vty, " %s", safe_inet_ntoa (filter->addr));
if (filter->addr_mask.s_addr != 0)
- vty_out (vty, " %s", inet_ntoa (filter->addr_mask));
+ vty_out (vty, " %s", safe_inet_ntoa (filter->addr_mask));
vty_out (vty, "%s", VTY_NEWLINE);
}
}
diff --git a/lib/if.c b/lib/if.c
index d14cfb93..c9a9b335 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -611,7 +611,7 @@ DEFUN (show_address,
p = ifc->address;
if (p->family == AF_INET)
- vty_out (vty, "%s/%d%s", inet_ntoa (p->u.prefix4), p->prefixlen,
+ vty_out (vty, "%s/%d%s", safe_inet_ntoa (p->u.prefix4), p->prefixlen,
VTY_NEWLINE);
}
}
@@ -807,7 +807,7 @@ ifaddr_ipv4_add (struct in_addr *ifaddr, struct interface *ifp)
{
route_unlock_node (rn);
zlog_info ("ifaddr_ipv4_add(): address %s is already added",
- inet_ntoa (*ifaddr));
+ safe_inet_ntoa (*ifaddr));
return;
}
rn->info = ifp;
@@ -827,7 +827,7 @@ ifaddr_ipv4_delete (struct in_addr *ifaddr, struct interface *ifp)
if (! rn)
{
zlog_info ("ifaddr_ipv4_delete(): can't find address %s",
- inet_ntoa (*ifaddr));
+ safe_inet_ntoa (*ifaddr));
return;
}
rn->info = NULL;
diff --git a/lib/log.c b/lib/log.c
index f6231974..bc4ed1ff 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -1235,14 +1235,6 @@ mes_lookup (const struct message *meslist, int max, int index, const char *none)
return none;
}
-/* Wrapper around strerror to handle case where it returns NULL. */
-const char *
-safe_strerror(int errnum)
-{
- const char *s = strerror(errnum);
- return (s != NULL) ? s : "Unknown error";
-}
-
struct zebra_desc_table
{
unsigned int type;
diff --git a/lib/log.h b/lib/log.h
index 6ab1b37c..ae573804 100644
--- a/lib/log.h
+++ b/lib/log.h
@@ -26,6 +26,7 @@
#define _ZEBRA_LOG_H
#include <syslog.h>
+#include "pthread_safe.h"
/* Here is some guidance on logging levels to use:
*
diff --git a/lib/memtypes.c b/lib/memtypes.c
index f8f541de..2f2ac239 100644
--- a/lib/memtypes.c
+++ b/lib/memtypes.c
@@ -42,6 +42,7 @@ struct memory_list memory_list_lib[] =
{ MTYPE_QTIMER, "qtimer timer" },
{ MTYPE_QPN_NEXUS, "qtn nexus" },
{ MTYPE_MARSHAL, "marshalled commands" },
+ { MTYPE_TSD, "Thread specific data" },
{ MTYPE_VTY, "VTY" },
{ MTYPE_VTY_OUT_BUF, "VTY output buffer" },
{ MTYPE_VTY_HIST, "VTY history" },
diff --git a/lib/pthread_safe.c b/lib/pthread_safe.c
new file mode 100644
index 00000000..a8da3a71
--- /dev/null
+++ b/lib/pthread_safe.c
@@ -0,0 +1,124 @@
+/* Quagga Pthreads support -- thread safe versions of standard functions
+ * Copyright (C) 2009 Chris Hall (GMCH), Highwayman
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/* We use thread specific storeage to provide buufers for the _r versions
+ * of standard functions, so that the callers don't need to provide
+ * their own. The contents of a buffer will remain intact until another
+ * safe_ function is called on the same thread
+ */
+
+#include "pthread_safe.h"
+#include "qpthreads.h"
+#include "memory.h"
+
+#include <pthread.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+
+/* prototypes */
+static void destructor(void* data);
+static char * thread_buff(void);
+
+static pthread_key_t tsd_key;
+static const int buff_size = 1024;
+
+/* Module initialization, before any threads have been created */
+void
+safe_init_r(void)
+{
+ if (qpthreads_enabled)
+ {
+ int status;
+ status = pthread_key_create(&tsd_key, destructor);
+ if (status != 0)
+ zabort("Can't create thread specific data key");
+ }
+}
+
+/* Clean up */
+void
+safe_finish(void)
+{
+ if (qpthreads_enabled)
+ pthread_key_delete(tsd_key);
+}
+
+static void
+destructor(void* data)
+{
+ XFREE(MTYPE_TSD, data);
+}
+
+/* Thread safe version of strerror. Never returns NULL.
+ * Contents of result remains intact until another call of
+ * a safe_ function.
+ */
+const char *
+safe_strerror(int errnum)
+{
+ static const char * unknown = "Unknown error";
+ if (qpthreads_enabled)
+ {
+ char * buff = thread_buff();
+ int ret = strerror_r(errnum, buff, buff_size);
+
+ return (ret >= 0)
+ ? buff
+ : unknown;
+ }
+ else
+ {
+ const char *s = strerror(errnum);
+ return (s != NULL)
+ ? s
+ : unknown;
+ }
+}
+
+const char *
+safe_inet_ntoa (struct in_addr in)
+{
+ if (qpthreads_enabled)
+ return inet_ntop(AF_INET, &in, thread_buff(), buff_size);
+ else
+ return inet_ntoa(in);
+}
+
+/* Return the thread's buffer */
+static char *
+thread_buff(void)
+{
+ int ret;
+ char * buff = pthread_getspecific(tsd_key);
+ if (buff == NULL)
+ {
+ buff = XMALLOC(MTYPE_TSD, buff_size);
+ ret = pthread_setspecific(tsd_key, buff);
+ if (ret != 0)
+ zabort("Can't set thread specific data");
+ }
+
+ return buff;
+}
diff --git a/lib/pthread_safe.h b/lib/pthread_safe.h
new file mode 100644
index 00000000..81adc668
--- /dev/null
+++ b/lib/pthread_safe.h
@@ -0,0 +1,32 @@
+/* Quagga Pthreads support -- thread safe versions of standard functions
+ * Copyright (C) 2009 Chris Hall (GMCH), Highwayman
+ *
+ * This file is part of GNU Zebra.
+ *
+ * GNU Zebra is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * GNU Zebra is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Zebra; see the file COPYING. If not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef PTHREAD_SAFE_H_
+#define PTHREAD_SAFE_H_
+
+#include <netinet/in.h>
+
+extern void safe_init_r(void);
+extern void safe_finish(void);
+extern const char * safe_strerror(int errnum);
+extern const char * safe_inet_ntoa (struct in_addr in);
+
+#endif /* PTHREAD_SAFE_H_ */
diff --git a/lib/qlib_init.c b/lib/qlib_init.c
index 67391395..400b34fc 100644
--- a/lib/qlib_init.c
+++ b/lib/qlib_init.c
@@ -26,6 +26,7 @@
#include "thread.h"
#include "privs.h"
#include "mqueue.h"
+#include "pthread_safe.h"
/*==============================================================================
* Quagga Library Initialise/Closedown
@@ -77,12 +78,14 @@ qlib_init_second_stage(int pthreads)
thread_init_r();
zprivs_init_r();
mqueue_initialise();
+ safe_init_r();
}
void
qexit(int exit_code)
{
+ safe_finish();
zprivs_finish();
thread_finish();
memory_finish();
diff --git a/lib/sockunion.c b/lib/sockunion.c
index bfcadc96..479adc3e 100644
--- a/lib/sockunion.c
+++ b/lib/sockunion.c
@@ -322,7 +322,7 @@ sockunion_log (union sockunion *su)
switch (su->sa.sa_family)
{
case AF_INET:
- snprintf (buf, SU_ADDRSTRLEN, "%s", inet_ntoa (su->sin.sin_addr));
+ snprintf (buf, SU_ADDRSTRLEN, "%s", safe_inet_ntoa (su->sin.sin_addr));
break;
#ifdef HAVE_IPV6
case AF_INET6:
@@ -642,7 +642,7 @@ sockunion_print (union sockunion *su)
switch (su->sa.sa_family)
{
case AF_INET:
- printf ("%s\n", inet_ntoa (su->sin.sin_addr));
+ printf ("%s\n", safe_inet_ntoa (su->sin.sin_addr));
break;
#ifdef HAVE_IPV6
case AF_INET6: