From e8c2ddd8dd3019c3741489418f4f183870cfde2a Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Wed, 30 Nov 2016 04:07:40 +0000 Subject: [PATCH] Suggestions --- src/netlink.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/src/netlink.c b/src/netlink.c index 7373f0a6..ddae5f26 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -392,31 +392,29 @@ static int link_filter_cb(const struct nlmsghdr *nlh, #if HAVE_TCA_STATS2 static int qos_attr_cb(const struct nlattr *attr, void *data) { - struct qos_stats *qdisc = (struct qos_stats *)data; - struct gnet_stats_basic *bs = qdisc->bs; - struct gnet_stats_queue *qs = qdisc->qs; + struct qos_stats *q_stats = (struct qos_stats *)data; /* skip unsupported attribute in user-space */ if (mnl_attr_type_valid(attr, TCA_STATS_MAX) < 0) return MNL_CB_OK; if (mnl_attr_get_type(attr) == TCA_STATS_BASIC) { - if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*bs)) < 0) { + if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*q_stats->bs)) < 0) { ERROR("netlink plugin: qos_attr_cb: TCA_STATS_BASIC mnl_attr_validate2 " "failed."); return MNL_CB_ERROR; } - bs = mnl_attr_get_payload(attr); + q_stats->bs = mnl_attr_get_payload(attr); return MNL_CB_OK; } if (mnl_attr_get_type(attr) == TCA_STATS_QUEUE) { - if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*qs)) < 0) { + if (mnl_attr_validate2(attr, MNL_TYPE_UNSPEC, sizeof(*q_stats->qs)) < 0) { ERROR("netlink plugin: qos_attr_cb: TCA_STATS_QUEUE mnl_attr_validate2 " "failed."); return MNL_CB_ERROR; } - qs = mnl_attr_get_payload(attr); + q_stats->qs = mnl_attr_get_payload(attr); return MNL_CB_OK; } @@ -509,11 +507,9 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) { #if HAVE_TCA_STATS2 mnl_attr_for_each(attr, nlh, sizeof(*tm)) { - struct gnet_stats_basic *bs = NULL; - struct gnet_stats_queue *qs = NULL; struct qos_stats q_stats; - q_stats.bs = bs; - q_stats.qs = qs; + + memset(&q_stats, 0x0, sizeof(q_stats)); if (mnl_attr_get_type(attr) != TCA_STATS2) continue; @@ -526,7 +522,7 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) { mnl_attr_parse_nested(attr, qos_attr_cb, &q_stats); - if (bs != NULL || qs != NULL) { + if (q_stats.bs != NULL || q_stats.qs != NULL) { char type_instance[DATA_MAX_NAME_LEN]; stats_submitted = 1; @@ -534,12 +530,12 @@ static int qos_filter_cb(const struct nlmsghdr *nlh, void *args) { ssnprintf(type_instance, sizeof(type_instance), "%s-%s", tc_type, tc_inst); - if (bs != NULL) { - submit_one(dev, "ipt_bytes", type_instance, bs->bytes); - submit_one(dev, "ipt_packets", type_instance, bs->packets); + if (q_stats.bs != NULL) { + submit_one(dev, "ipt_bytes", type_instance, q_stats.bs->bytes); + submit_one(dev, "ipt_packets", type_instance, q_stats.bs->packets); } - if (qs != NULL) { - submit_one(dev, "if_tx_dropped", type_instance, qs->drops); + if (q_stats.qs != NULL) { + submit_one(dev, "if_tx_dropped", type_instance, q_stats.qs->drops); } } -- 2.11.0