From a442138545cfd50da444522c913871c428e27a31 Mon Sep 17 00:00:00 2001 From: Chris Fiege Date: Sun, 15 Nov 2020 14:41:24 +0100 Subject: [PATCH] gluon-mesh-batman-adv: Do not add local-if to respondd If there are local services running on an interface that sits on top of bat0 these interfaces may be added to the translocal batman-table. Contrary to the bat0-interface itself this entries are not marked with the TT_CLIENT_NOPURGE -flag and are thus added to the client-count reported by respondd. In this case the client-count reported is one too high. This change adds an additional check to the function doing the actual counting. This check makes sure that no local interface is counted as a client. Since respondd only collects data in an interval of minutes (depending on the site's configuration) the additional costs for this check should be negligible. --- .../src/respondd-statistics.c | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/package/gluon-mesh-batman-adv/src/respondd-statistics.c b/package/gluon-mesh-batman-adv/src/respondd-statistics.c index c9394d87..5057709a 100644 --- a/package/gluon-mesh-batman-adv/src/respondd-statistics.c +++ b/package/gluon-mesh-batman-adv/src/respondd-statistics.c @@ -42,6 +42,10 @@ #include #include +#include +#include +#include + #include #include @@ -52,6 +56,7 @@ struct clients_netlink_opts { size_t clients; struct batadv_nlquery_opts query_opts; + struct ifaddrs *ifaddr; }; struct gw_netlink_opts { @@ -257,6 +262,8 @@ static int parse_clients_list_netlink_cb(struct nl_msg *msg, void *arg) struct genlmsghdr *ghdr; struct clients_netlink_opts *opts; uint32_t flags, lastseen; + struct ifaddrs *ifa = NULL; + uint8_t *tt_addr; opts = batadv_container_of(query_opts, struct clients_netlink_opts, query_opts); @@ -286,6 +293,20 @@ static int parse_clients_list_netlink_cb(struct nl_msg *msg, void *arg) if (lastseen > MAX_INACTIVITY) return NL_OK; + // Check if client is a local interface + tt_addr = nla_data(attrs[BATADV_ATTR_TT_ADDRESS]); + for(ifa = opts->ifaddr; ifa != NULL; ifa = ifa->ifa_next) { + if( (ifa->ifa_addr) && (ifa->ifa_addr->sa_family == AF_PACKET)) { + struct sockaddr_ll *s = (struct sockaddr_ll*) ifa->ifa_addr; + if(memcmp(s->sll_addr, tt_addr, ETH_ALEN) == 0) { + // This client is a local interface. + // Do not increment client count + return NL_OK; + } + } + } + + opts->clients++; return NL_OK; @@ -299,10 +320,17 @@ static struct json_object * get_clients(void) { }, }; + if (getifaddrs(& opts.ifaddr) == -1) { + opts.ifaddr = NULL; + } + batadv_genl_query("bat0", BATADV_CMD_GET_TRANSTABLE_LOCAL, parse_clients_list_netlink_cb, NLM_F_DUMP, &opts.query_opts); + if(opts.ifaddr != NULL) { + freeifaddrs(opts.ifaddr); + } struct json_object *ret = json_object_new_object(); json_object_object_add(ret, "total", json_object_new_int(opts.clients));