Skip to content

Commit

Permalink
ipvs: Don't duplicate storage of 32 bit SNMP stats
Browse files Browse the repository at this point in the history
Signed-off-by: Quentin Armitage <quentin@armitage.org.uk>
  • Loading branch information
pqarmitage committed Apr 28, 2024
1 parent 7752c33 commit 930f3b7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 47 deletions.
40 changes: 20 additions & 20 deletions keepalived/check/ipvswrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,16 +842,16 @@ ipvs_update_vs_stats(virtual_server_t *vs, uint16_t af, uint32_t fwmark, union n
return;

/* Update virtual server stats */
vs->stats.conns += serv->stats.conns;
vs->stats.inpkts += serv->stats.inpkts;
vs->stats.outpkts += serv->stats.outpkts;
vs->stats.inbytes += serv->stats.inbytes;
vs->stats.outbytes += serv->stats.outbytes;
vs->stats.cps += serv->stats.cps;
vs->stats.inpps += serv->stats.inpps;
vs->stats.outpps += serv->stats.outpps;
vs->stats.inbps += serv->stats.inbps;
vs->stats.outbps += serv->stats.outbps;
vs->stats.conns += serv->ip_vs_stats.conns;
vs->stats.inpkts += serv->ip_vs_stats.inpkts;
vs->stats.outpkts += serv->ip_vs_stats.outpkts;
vs->stats.inbytes += serv->ip_vs_stats.inbytes;
vs->stats.outbytes += serv->ip_vs_stats.outbytes;
vs->stats.cps += serv->ip_vs_stats.cps;
vs->stats.inpps += serv->ip_vs_stats.inpps;
vs->stats.outpps += serv->ip_vs_stats.outpps;
vs->stats.inbps += serv->ip_vs_stats.inbps;
vs->stats.outbps += serv->ip_vs_stats.outbps;

vs->num_dests = serv->user.num_dests; // Only needed if using old socket interface

Expand Down Expand Up @@ -897,16 +897,16 @@ ipvs_update_rs_stats(virtual_server_t *vs, uint16_t af, uint32_t fwmark, union n
rs->activeconns += dests->user.entrytable[i].user.activeconns;
rs->inactconns += dests->user.entrytable[i].user.inactconns;
rs->persistconns += dests->user.entrytable[i].user.persistconns;
rs->stats.conns += dests->user.entrytable[i].stats.conns;
rs->stats.inpkts += dests->user.entrytable[i].stats.inpkts;
rs->stats.outpkts += dests->user.entrytable[i].stats.outpkts;
rs->stats.inbytes += dests->user.entrytable[i].stats.inbytes;
rs->stats.outbytes += dests->user.entrytable[i].stats.outbytes;
rs->stats.cps += dests->user.entrytable[i].stats.cps;
rs->stats.inpps += dests->user.entrytable[i].stats.inpps;
rs->stats.outpps += dests->user.entrytable[i].stats.outpps;
rs->stats.inbps += dests->user.entrytable[i].stats.inbps;
rs->stats.outbps += dests->user.entrytable[i].stats.outbps;
rs->stats.conns += dests->user.entrytable[i].ip_vs_stats.conns;
rs->stats.inpkts += dests->user.entrytable[i].ip_vs_stats.inpkts;
rs->stats.outpkts += dests->user.entrytable[i].ip_vs_stats.outpkts;
rs->stats.inbytes += dests->user.entrytable[i].ip_vs_stats.inbytes;
rs->stats.outbytes += dests->user.entrytable[i].ip_vs_stats.outbytes;
rs->stats.cps += dests->user.entrytable[i].ip_vs_stats.cps;
rs->stats.inpps += dests->user.entrytable[i].ip_vs_stats.inpps;
rs->stats.outpps += dests->user.entrytable[i].ip_vs_stats.outpps;
rs->stats.inbps += dests->user.entrytable[i].ip_vs_stats.inbps;
rs->stats.outbps += dests->user.entrytable[i].ip_vs_stats.outbps;
}

FREE(dests);
Expand Down
52 changes: 25 additions & 27 deletions keepalived/check/libipvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,23 @@ int ipvs_stop_daemon(ipvs_daemon_t *dm)
}

#ifdef _WITH_SNMP_CHECKER_
#ifdef _WITH_LVS_64BIT_STATS_
static void
ipvs_copy_stats(ip_vs_stats_t *stats_out, const struct ip_vs_stats_user *stats_in)
{
stats_out->conns = stats_in->conns;
stats_out->inpkts = stats_in->inpkts;
stats_out->outpkts = stats_in->outpkts;
stats_out->inbytes = stats_in->inbytes;
stats_out->outbytes = stats_in->outbytes;
stats_out->cps = stats_in->cps;
stats_out->inpps = stats_in->inpps;
stats_out->outpps = stats_in->outpps;
stats_out->inbps = stats_in->inbps;
stats_out->outbps = stats_in->outbps;
}
#endif

#ifdef LIBIPVS_USE_NL
#ifdef _WITH_LVS_64BIT_STATS_
static int ipvs_parse_stats64(ip_vs_stats_t *stats, struct nlattr *nla)
Expand Down Expand Up @@ -1033,7 +1050,7 @@ static int ipvs_services_parse_cb(struct nl_msg *msg, void *arg)
} else if (svc_attrs[IPVS_SVC_ATTR_STATS])
#endif
{
if (ipvs_parse_stats(&(get->user.entrytable[0].stats),
if (ipvs_parse_stats64(&(get->user.entrytable[0].ip_vs_stats),
svc_attrs[IPVS_SVC_ATTR_STATS]) != 0)
return -1;
}
Expand Down Expand Up @@ -1113,13 +1130,13 @@ static int ipvs_dests_parse_cb(struct nl_msg *msg, void *arg)

#ifdef _WITH_LVS_64BIT_STATS_
if (dest_attrs[IPVS_DEST_ATTR_STATS64]) {
if (ipvs_parse_stats64(&(d->user.entrytable[i].stats),
if (ipvs_parse_stats64(&(d->user.entrytable[i].ip_vs_stats),
dest_attrs[IPVS_DEST_ATTR_STATS64]) != 0)
return -1;
} else if (dest_attrs[IPVS_DEST_ATTR_STATS])
#endif
{
if (ipvs_parse_stats(&(d->user.entrytable[i].stats),
if (ipvs_parse_stats(&(d->user.entrytable[i].ip_vs_stats),
dest_attrs[IPVS_DEST_ATTR_STATS]) != 0)
return -1;
}
Expand All @@ -1130,29 +1147,6 @@ static int ipvs_dests_parse_cb(struct nl_msg *msg, void *arg)
}
#endif /* LIBIPVS_USE_NL */

#ifdef _WITH_LVS_64BIT_STATS_
static void
ipvs_copy_stats(ip_vs_stats_t *stats_out, const struct ip_vs_stats_user *stats_in)
{
stats_out->conns = stats_in->conns;
stats_out->inpkts = stats_in->inpkts;
stats_out->outpkts = stats_in->outpkts;
stats_out->inbytes = stats_in->inbytes;
stats_out->outbytes = stats_in->outbytes;
stats_out->cps = stats_in->cps;
stats_out->inpps = stats_in->inpps;
stats_out->outpps = stats_in->outpps;
stats_out->inbps = stats_in->inbps;
stats_out->outbps = stats_in->outbps;
}
#else
static void
ipvs_copy_stats(ip_vs_stats_t *stats_out, const ip_vs_stats_user *stats_in)
{
*stats_out = *stats_in;
}
#endif

struct ip_vs_get_dests_app *ipvs_get_dests(__u32 fwmark, __u16 af, __u16 protocol, union nf_inet_addr *addr, __u16 port, unsigned num_dests)
{
struct ip_vs_get_dests_app *d;
Expand Down Expand Up @@ -1246,7 +1240,9 @@ struct ip_vs_get_dests_app *ipvs_get_dests(__u32 fwmark, __u16 af, __u16 protoco
d->user.entrytable[i].user = dk->entrytable[i];
d->user.entrytable[i].af = AF_INET;
d->user.entrytable[i].nf_addr.ip = d->user.entrytable[i].user.addr;
ipvs_copy_stats(&d->user.entrytable[i].stats, &dk->entrytable[i].stats);
#ifdef _WITH_LVS_64BIT_STATS_
ipvs_copy_stats(&d->user.entrytable[i].ip_vs_stats, &dk->entrytable[i].stats);
#endif
}
FREE(dk);
return d;
Expand Down Expand Up @@ -1332,7 +1328,9 @@ ipvs_get_service(__u32 fwmark, __u16 af, __u16 protocol, union nf_inet_addr *add
svc->af = AF_INET;
svc->nf_addr.ip = svc->user.addr;
svc->pe_name[0] = '\0';
#ifdef _WITH_LVS_64BIT_STATS_
ipvs_copy_stats(&svc->stats, &svc->user.stats);
#endif

return svc;
out_err:
Expand Down
6 changes: 6 additions & 0 deletions keepalived/include/ip_vs.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ struct ip_vs_stats64 {
__u64 outbps; /* current out byte rate */
};
typedef struct ip_vs_stats64 ip_vs_stats_t;
#define ip_vs_stats stats
#else
typedef struct ip_vs_stats_user ip_vs_stats_t;
#define ip_vs_stats user.stats
#endif

struct ip_vs_service_app {
Expand All @@ -68,15 +70,19 @@ struct ip_vs_dest_app {

struct ip_vs_service_entry_app {
struct ip_vs_service_entry user;
#ifdef _WITH_LVS_64BIT_STATS_
ip_vs_stats_t stats;
#endif
uint16_t af;
union nf_inet_addr nf_addr;
char pe_name[IP_VS_PENAME_MAXLEN + 1];
};

struct ip_vs_dest_entry_app {
struct ip_vs_dest_entry user;
#ifdef _WITH_LVS_64BIT_STATS_
ip_vs_stats_t stats;
#endif
uint16_t af;
union nf_inet_addr nf_addr;

Expand Down

0 comments on commit 930f3b7

Please sign in to comment.