bgpd: debug buffers cleanup and optimization

Just the first change pushes bgp_update_receive() from 6th to ~14th on a
full internet table load profiling session.

* bgp_debug.c: (bgp_update_receive) The attrstr initialization is expensive,
  moved under the debug conditional where it is used and just initialize the
  first char to NULL.
  (bgp_update_default_send) Initialize attrstr needed for bgp_dump_attr().
  Moved some buffers used for printing IP[4|6] addresses under the debug
  conditionals that use them and reduced its size.

Signed-off-by: Jorge Boncompte [DTI2] <jorge@dti2.net>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
Jorge Boncompte [DTI2] 2012-05-07 16:52:53 +00:00 committed by David Lamparter
parent 10f9bf3f20
commit 14542f3eda

View File

@ -149,7 +149,6 @@ bgp_update_packet (struct peer *peer, afi_t afi, safi_t safi)
struct bgp_info *binfo = NULL; struct bgp_info *binfo = NULL;
bgp_size_t total_attr_len = 0; bgp_size_t total_attr_len = 0;
unsigned long pos; unsigned long pos;
char buf[BUFSIZ];
s = peer->work; s = peer->work;
stream_reset (s); stream_reset (s);
@ -199,10 +198,14 @@ bgp_update_packet (struct peer *peer, afi_t afi, safi_t safi)
stream_put_prefix (s, &rn->p); stream_put_prefix (s, &rn->p);
if (BGP_DEBUG (update, UPDATE_OUT)) if (BGP_DEBUG (update, UPDATE_OUT))
zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d", {
peer->host, char buf[INET6_BUFSIZ];
inet_ntop (rn->p.family, &(rn->p.u.prefix), buf, BUFSIZ),
rn->p.prefixlen); zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d",
peer->host,
inet_ntop (rn->p.family, &(rn->p.u.prefix), buf, INET6_BUFSIZ),
rn->p.prefixlen);
}
/* Synchnorize attribute. */ /* Synchnorize attribute. */
if (adj->attr) if (adj->attr)
@ -285,7 +288,6 @@ bgp_withdraw_packet (struct peer *peer, afi_t afi, safi_t safi)
unsigned long pos; unsigned long pos;
bgp_size_t unfeasible_len; bgp_size_t unfeasible_len;
bgp_size_t total_attr_len; bgp_size_t total_attr_len;
char buf[BUFSIZ];
s = peer->work; s = peer->work;
stream_reset (s); stream_reset (s);
@ -324,10 +326,14 @@ bgp_withdraw_packet (struct peer *peer, afi_t afi, safi_t safi)
} }
if (BGP_DEBUG (update, UPDATE_OUT)) if (BGP_DEBUG (update, UPDATE_OUT))
zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d -- unreachable", {
peer->host, char buf[INET6_BUFSIZ];
inet_ntop (rn->p.family, &(rn->p.u.prefix), buf, BUFSIZ),
rn->p.prefixlen); zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d -- unreachable",
peer->host,
inet_ntop (rn->p.family, &(rn->p.u.prefix), buf, INET6_BUFSIZ),
rn->p.prefixlen);
}
peer->scount[afi][safi]--; peer->scount[afi][safi]--;
@ -366,8 +372,6 @@ bgp_default_update_send (struct peer *peer, struct attr *attr,
struct prefix p; struct prefix p;
unsigned long pos; unsigned long pos;
bgp_size_t total_attr_len; bgp_size_t total_attr_len;
char attrstr[BUFSIZ];
char buf[BUFSIZ];
if (DISABLE_BGP_ANNOUNCE) if (DISABLE_BGP_ANNOUNCE)
return; return;
@ -382,9 +386,13 @@ bgp_default_update_send (struct peer *peer, struct attr *attr,
/* Logging the attribute. */ /* Logging the attribute. */
if (BGP_DEBUG (update, UPDATE_OUT)) if (BGP_DEBUG (update, UPDATE_OUT))
{ {
char attrstr[BUFSIZ];
char buf[INET6_BUFSIZ];
attrstr[0] = '\0';
bgp_dump_attr (peer, attr, attrstr, BUFSIZ); bgp_dump_attr (peer, attr, attrstr, BUFSIZ);
zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d %s", zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d %s",
peer->host, inet_ntop(p.family, &(p.u.prefix), buf, BUFSIZ), peer->host, inet_ntop(p.family, &(p.u.prefix), buf, INET6_BUFSIZ),
p.prefixlen, attrstr); p.prefixlen, attrstr);
} }
@ -435,7 +443,6 @@ bgp_default_withdraw_send (struct peer *peer, afi_t afi, safi_t safi)
unsigned long cp; unsigned long cp;
bgp_size_t unfeasible_len; bgp_size_t unfeasible_len;
bgp_size_t total_attr_len; bgp_size_t total_attr_len;
char buf[BUFSIZ];
if (DISABLE_BGP_ANNOUNCE) if (DISABLE_BGP_ANNOUNCE)
return; return;
@ -451,9 +458,13 @@ bgp_default_withdraw_send (struct peer *peer, afi_t afi, safi_t safi)
pos = 0; pos = 0;
if (BGP_DEBUG (update, UPDATE_OUT)) if (BGP_DEBUG (update, UPDATE_OUT))
zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d -- unreachable", {
peer->host, inet_ntop(p.family, &(p.u.prefix), buf, BUFSIZ), char buf[INET6_BUFSIZ];
p.prefixlen);
zlog (peer->log, LOG_DEBUG, "%s send UPDATE %s/%d -- unreachable",
peer->host, inet_ntop(p.family, &(p.u.prefix), buf, INET6_BUFSIZ),
p.prefixlen);
}
s = stream_new (BGP_MAX_PACKET_SIZE); s = stream_new (BGP_MAX_PACKET_SIZE);
@ -1515,7 +1526,6 @@ bgp_update_receive (struct peer *peer, bgp_size_t size)
struct bgp_nlri withdraw; struct bgp_nlri withdraw;
struct bgp_nlri mp_update; struct bgp_nlri mp_update;
struct bgp_nlri mp_withdraw; struct bgp_nlri mp_withdraw;
char attrstr[BUFSIZ] = "";
/* Status must be Established. */ /* Status must be Established. */
if (peer->status != Established) if (peer->status != Established)
@ -1632,6 +1642,9 @@ bgp_update_receive (struct peer *peer, bgp_size_t size)
if (attr_parse_ret == BGP_ATTR_PARSE_WITHDRAW if (attr_parse_ret == BGP_ATTR_PARSE_WITHDRAW
|| BGP_DEBUG (update, UPDATE_IN)) || BGP_DEBUG (update, UPDATE_IN))
{ {
char attrstr[BUFSIZ];
attrstr[0] = '\0';
ret= bgp_dump_attr (peer, &attr, attrstr, BUFSIZ); ret= bgp_dump_attr (peer, &attr, attrstr, BUFSIZ);
int lvl = (attr_parse_ret == BGP_ATTR_PARSE_WITHDRAW) int lvl = (attr_parse_ret == BGP_ATTR_PARSE_WITHDRAW)
? LOG_ERR : LOG_DEBUG; ? LOG_ERR : LOG_DEBUG;
@ -2027,7 +2040,6 @@ bgp_route_refresh_receive (struct peer *peer, bgp_size_t size)
u_int32_t seq; u_int32_t seq;
int psize; int psize;
char name[BUFSIZ]; char name[BUFSIZ];
char buf[BUFSIZ];
int ret; int ret;
if (BGP_DEBUG (normal, NORMAL)) if (BGP_DEBUG (normal, NORMAL))
@ -2097,14 +2109,18 @@ bgp_route_refresh_receive (struct peer *peer, bgp_size_t size)
p_pnt += psize; p_pnt += psize;
if (BGP_DEBUG (normal, NORMAL)) if (BGP_DEBUG (normal, NORMAL))
zlog_debug ("%s rcvd %s %s seq %u %s/%d ge %d le %d%s", {
peer->host, char buf[INET6_BUFSIZ];
(common & ORF_COMMON_PART_REMOVE ? "Remove" : "Add"),
(common & ORF_COMMON_PART_DENY ? "deny" : "permit"), zlog_debug ("%s rcvd %s %s seq %u %s/%d ge %d le %d%s",
orfp.seq, peer->host,
inet_ntop (orfp.p.family, &orfp.p.u.prefix, buf, BUFSIZ), (common & ORF_COMMON_PART_REMOVE ? "Remove" : "Add"),
orfp.p.prefixlen, orfp.ge, orfp.le, (common & ORF_COMMON_PART_DENY ? "deny" : "permit"),
ok ? "" : " MALFORMED"); orfp.seq,
inet_ntop (orfp.p.family, &orfp.p.u.prefix, buf, INET6_BUFSIZ),
orfp.p.prefixlen, orfp.ge, orfp.le,
ok ? "" : " MALFORMED");
}
if (ok) if (ok)
ret = prefix_bgp_orf_set (name, afi, &orfp, ret = prefix_bgp_orf_set (name, afi, &orfp,