[alfred] master: alfred: Cache the TQ values for each originator (e50d18c)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/alfred
On branch : master
>---------------------------------------------------------------
commit e50d18c39f92d414f24c1d04865339bfcf22dc5f
Author: Sven Eckelmann <sven.eckelmann(a)openmesh.com>
Date: Wed May 24 12:32:10 2017 +0200
alfred: Cache the TQ values for each originator
There is a single loop which goes over all servers to find the TQs for each
server. The TQ value doesn't change often and it is relative unlikely that
it is different after some milliseconds. It is therefore not necessary to
re-request the TQ values from the kernel for each server in the server
hash. Instead, the values can be retrieved ones from the kernel during each
sync interval, cached and then retrieved from the cache again.
Signed-off-by: Sven Eckelmann <sven.eckelmann(a)openmesh.com>
[sw: fixed hash initialization error handling]
Signed-off-by: Simon Wunderlich <simon.wunderlich(a)openmesh.com>
>---------------------------------------------------------------
e50d18c39f92d414f24c1d04865339bfcf22dc5f
batadv_query.c | 108 ++++++++++++++++++++++++++++++++++++++++++-------------
batadv_query.h | 14 +++++++-
batadv_querynl.c | 29 +++++----------
batadv_querynl.h | 4 +--
server.c | 17 +++++++--
5 files changed, 121 insertions(+), 51 deletions(-)
diff --git a/batadv_query.c b/batadv_query.c
index e68052b..1123cf5 100644
--- a/batadv_query.c
+++ b/batadv_query.c
@@ -298,8 +298,7 @@ struct ether_addr *translate_mac(const char *mesh_iface,
return mac_result;
}
-static int get_tq_debugfs(const char *mesh_iface, struct ether_addr *mac,
- uint8_t *tq)
+static int get_tq_debugfs(const char *mesh_iface, struct hashtable_t *orig_hash)
{
enum {
orig_mac,
@@ -308,16 +307,13 @@ static int get_tq_debugfs(const char *mesh_iface, struct ether_addr *mac,
orig_tqvalue,
} pos;
char full_path[MAX_PATH + 1];
- static struct ether_addr in_mac;
struct ether_addr *mac_tmp;
FILE *f = NULL;
size_t len = 0;
char *line = NULL;
char *input, *saveptr, *token;
int line_invalid;
- bool found = false;
-
- memcpy(&in_mac, mac, sizeof(in_mac));
+ uint8_t tq;
debugfs_make_path(DEBUG_BATIF_PATH_FMT "/" DEBUG_ORIGINATORS,
mesh_iface, full_path, sizeof(full_path));
@@ -337,8 +333,7 @@ static int get_tq_debugfs(const char *mesh_iface, struct ether_addr *mac,
switch (pos) {
case orig_mac:
mac_tmp = ether_aton(token);
- if (!mac_tmp || memcmp(mac_tmp, &in_mac,
- sizeof(in_mac)) != 0)
+ if (!mac_tmp)
line_invalid = 1;
else
pos = orig_lastseen;
@@ -365,9 +360,8 @@ static int get_tq_debugfs(const char *mesh_iface, struct ether_addr *mac,
line_invalid = 1;
} else {
token[strlen(token) - 1] = '\0';
- *tq = strtol(token, NULL, 10);
- found = true;
- goto out;
+ tq = strtol(token, NULL, 10);
+ orig_hash_add(orig_hash, mac_tmp, tq);
}
break;
}
@@ -377,34 +371,98 @@ static int get_tq_debugfs(const char *mesh_iface, struct ether_addr *mac,
}
}
-out:
if (f)
fclose(f);
free(line);
- if (found)
- return 0;
+ return 0;
+}
+
+static int orig_compare(void *d1, void *d2)
+{
+ struct orig_entry *s1 = d1, *s2 = d2;
+
+ if (memcmp(&s1->mac, &s2->mac, sizeof(s1->mac)) == 0)
+ return 1;
else
- return -ENOENT;
+ return 0;
}
-uint8_t get_tq(const char *mesh_iface, struct ether_addr *mac)
+static int orig_choose(void *d1, int size)
{
- struct ether_addr in_mac;
- uint8_t tq = 0;
+ struct orig_entry *s1 = d1;
+ uint32_t hash = 0;
+ size_t i;
+
+ for (i = 0; i < sizeof(s1->mac); i++) {
+ hash += s1->mac.ether_addr_octet[i];
+ hash += (hash << 10);
+ hash ^= (hash >> 6);
+ }
+
+ hash += (hash << 3);
+ hash ^= (hash >> 11);
+ hash += (hash << 15);
+
+ return hash % size;
+}
+
+struct hashtable_t *orig_hash_new(const char *mesh_iface)
+{
+ struct hashtable_t *orig_hash;
int ret;
- /* input mac has to be copied because it could be in the shared
- * ether_aton buffer
- */
- memcpy(&in_mac, mac, sizeof(in_mac));
+ orig_hash = hash_new(64, orig_compare, orig_choose);
+ if (!orig_hash)
+ return NULL;
enable_net_admin_capability(1);
- ret = get_tq_netlink(mesh_iface, &in_mac, &tq);
+ ret = get_tq_netlink(mesh_iface, orig_hash);
enable_net_admin_capability(0);
+ ret = -EOPNOTSUPP;
if (ret == -EOPNOTSUPP)
- get_tq_debugfs(mesh_iface, &in_mac, &tq);
+ get_tq_debugfs(mesh_iface, orig_hash);
+
+ return orig_hash;
+}
+
+void orig_hash_free(struct hashtable_t *orig_hash)
+{
+ hash_delete(orig_hash, free);
+}
+
+int orig_hash_add(struct hashtable_t *orig_hash, struct ether_addr *mac,
+ uint8_t tq)
+{
+ struct orig_entry *n;
+
+ n = malloc(sizeof(*n));
+ if (!n)
+ return -ENOMEM;
+
+ n->mac = *mac;
+ n->tq = tq;
+
+ if (hash_add(orig_hash, n)) {
+ free(n);
+ return -EEXIST;
+ }
+
+ return 0;
+}
+
+uint8_t get_tq(struct hashtable_t *orig_hash, struct ether_addr *mac)
+{
+ struct orig_entry search = {
+ .mac = *mac,
+ .tq = 0,
+ };
+ struct orig_entry *found;
+
+ found = hash_find(orig_hash, &search);
+ if (!found)
+ return 0;
- return tq;
+ return found->tq;
}
diff --git a/batadv_query.h b/batadv_query.h
index 9aa4f0e..aa4d3f8 100644
--- a/batadv_query.h
+++ b/batadv_query.h
@@ -24,9 +24,21 @@
#include <stdint.h>
#include <netinet/in.h>
+#include "hash.h"
+
+struct orig_entry {
+ struct ether_addr mac;
+ uint8_t tq;
+};
+
struct ether_addr *translate_mac(const char *mesh_iface,
const struct ether_addr *mac);
-uint8_t get_tq(const char *mesh_iface, struct ether_addr *mac);
+
+struct hashtable_t *orig_hash_new(const char *mesh_iface);
+void orig_hash_free(struct hashtable_t *orig_hash);
+int orig_hash_add(struct hashtable_t *orig_hash, struct ether_addr *mac,
+ uint8_t tq);
+uint8_t get_tq(struct hashtable_t *orig_hash, struct ether_addr *mac);
int batadv_interface_check(const char *mesh_iface);
int mac_to_ipv6(const struct ether_addr *mac, alfred_addr *addr);
int ipv6_to_mac(const alfred_addr *addr, struct ether_addr *mac);
diff --git a/batadv_querynl.c b/batadv_querynl.c
index 8dab96e..ba678ae 100644
--- a/batadv_querynl.c
+++ b/batadv_querynl.c
@@ -34,7 +34,9 @@
#include <netlink/genl/ctrl.h>
#include <net/ethernet.h>
+#include "alfred.h"
#include "batman_adv.h"
+#include "batadv_query.h"
#include "netlink.h"
#ifndef __unused
@@ -131,9 +133,7 @@ static const int get_tq_netlink_mandatory[] = {
};
struct get_tq_netlink_opts {
- struct ether_addr mac;
- uint8_t tq;
- bool found;
+ struct hashtable_t *orig_hash;
struct nlquery_opts query_opts;
};
@@ -145,6 +145,7 @@ static int get_tq_netlink_cb(struct nl_msg *msg, void *arg)
struct get_tq_netlink_opts *opts;
struct genlmsghdr *ghdr;
uint8_t *orig;
+ struct ether_addr mac;
uint8_t tq;
opts = container_of(query_opts, struct get_tq_netlink_opts,
@@ -173,40 +174,28 @@ static int get_tq_netlink_cb(struct nl_msg *msg, void *arg)
if (!attrs[BATADV_ATTR_FLAG_BEST])
return NL_OK;
- if (memcmp(&opts->mac, orig, ETH_ALEN) != 0)
- return NL_OK;
-
- opts->tq = tq;
- opts->found = true;
+ memcpy(&mac, orig, sizeof(mac));
+ orig_hash_add(opts->orig_hash, &mac, tq);
opts->query_opts.err = 0;
- return NL_STOP;
+ return NL_OK;
}
-int get_tq_netlink(const char *mesh_iface, const struct ether_addr *mac,
- uint8_t *tq)
+int get_tq_netlink(const char *mesh_iface, struct hashtable_t *orig_hash)
{
struct get_tq_netlink_opts opts = {
- .tq = 0,
- .found = false,
+ .orig_hash = orig_hash,
.query_opts = {
.err = 0,
},
};
int ret;
- memcpy(&opts.mac, mac, ETH_ALEN);
-
ret = netlink_query_common(mesh_iface, BATADV_CMD_GET_ORIGINATORS,
get_tq_netlink_cb, &opts.query_opts);
if (ret < 0)
return ret;
- if (!opts.found)
- return -ENOENT;
-
- *tq = opts.tq;
-
return 0;
}
diff --git a/batadv_querynl.h b/batadv_querynl.h
index 9b93a47..f5c7e38 100644
--- a/batadv_querynl.h
+++ b/batadv_querynl.h
@@ -25,11 +25,11 @@
#include <stdint.h>
struct ether_addr;
+struct hashtable_t;
int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac,
struct ether_addr *mac_out);
-int get_tq_netlink(const char *mesh_iface, const struct ether_addr *mac,
- uint8_t *tq);
+int get_tq_netlink(const char *mesh_iface, struct hashtable_t *orig_hash);
int batadv_interface_check_netlink(const char *mesh_iface);
#endif /* _BATADV_QUERYNL_H */
diff --git a/server.c b/server.c
index 09acb80..852dc34 100644
--- a/server.c
+++ b/server.c
@@ -223,17 +223,26 @@ static void update_server_info(struct globals *globals)
struct hash_it_t *hashit = NULL;
struct interface *interface;
struct ether_addr *macaddr;
+ struct hashtable_t *orig_hash;
/* TQ is not used for master sync mode */
if (globals->opmode == OPMODE_MASTER)
return;
+ if (strcmp(globals->mesh_iface, "none") != 0) {
+ orig_hash = orig_hash_new(globals->mesh_iface);
+ if (!orig_hash) {
+ fprintf(stderr, "Failed to create originator hash\n");
+ return;
+ }
+ }
+
list_for_each_entry(interface, &globals->interfaces, list) {
while (NULL != (hashit = hash_iterate(interface->server_hash,
hashit))) {
struct server *server = hashit->bucket->data;
- if (strcmp(globals->mesh_iface, "none") == 0) {
+ if (!orig_hash) {
server->tq = 255;
continue;
}
@@ -241,14 +250,16 @@ static void update_server_info(struct globals *globals)
macaddr = translate_mac(globals->mesh_iface,
&server->hwaddr);
if (macaddr)
- server->tq = get_tq(globals->mesh_iface,
- macaddr);
+ server->tq = get_tq(orig_hash, macaddr);
else
server->tq = 0;
}
}
set_best_server(globals);
+
+ if (orig_hash)
+ orig_hash_free(orig_hash);
}
static void check_if_socket(struct interface *interface, struct globals *globals)
5 years
[alfred] master: alfred: Cache the global translation table entries (a7bc3d9)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/alfred
On branch : master
>---------------------------------------------------------------
commit a7bc3d9a2b3f12aac5e4a7db8950ebd073ce2c31
Author: Sven Eckelmann <sven.eckelmann(a)openmesh.com>
Date: Wed May 24 12:32:11 2017 +0200
alfred: Cache the global translation table entries
There is a single loop which goes over all servers to find the originator
for each server. The originator usually doesn't change often because alfred
is usually started on the nodes which is already running batman-adv. It is
therefore not necessary to re-request the complete global translation table
from the kernel for each server in the server hash. Instead, the values can
be retrieved ones from the kernel during each sync interval, cached and
then retrieved from the cache again.
Signed-off-by: Sven Eckelmann <sven.eckelmann(a)openmesh.com>
[sw: fixed hash initialization error handling]
Signed-off-by: Simon Wunderlich <simon.wunderlich(a)openmesh.com>
>---------------------------------------------------------------
a7bc3d9a2b3f12aac5e4a7db8950ebd073ce2c31
batadv_query.c | 117 +++++++++++++++++++++++++++++++++++++++++--------------
batadv_query.h | 11 +++++-
batadv_querynl.c | 25 ++++--------
batadv_querynl.h | 3 +-
server.c | 15 +++++--
5 files changed, 118 insertions(+), 53 deletions(-)
diff --git a/batadv_query.c b/batadv_query.c
index 1123cf5..8580f1b 100644
--- a/batadv_query.c
+++ b/batadv_query.c
@@ -193,8 +193,7 @@ int batadv_interface_check(const char *mesh_iface)
}
static int translate_mac_debugfs(const char *mesh_iface,
- const struct ether_addr *mac,
- struct ether_addr *mac_out)
+ struct hashtable_t *tg_hash)
{
enum {
tg_start,
@@ -204,12 +203,12 @@ static int translate_mac_debugfs(const char *mesh_iface,
} pos;
char full_path[MAX_PATH+1];
struct ether_addr *mac_tmp;
+ struct ether_addr mac;
FILE *f = NULL;
size_t len = 0;
char *line = NULL;
char *input, *saveptr, *token;
int line_invalid;
- bool found = false;
debugfs_make_path(DEBUG_BATIF_PATH_FMT "/" DEBUG_TRANSTABLE_GLOBAL,
mesh_iface, full_path, sizeof(full_path));
@@ -235,11 +234,12 @@ static int translate_mac_debugfs(const char *mesh_iface,
break;
case tg_mac:
mac_tmp = ether_aton(token);
- if (!mac_tmp || memcmp(mac_tmp, mac,
- ETH_ALEN) != 0)
+ if (!mac_tmp) {
line_invalid = 1;
- else
+ } else {
+ memcpy(&mac, mac_tmp, sizeof(mac));
pos = tg_via;
+ }
break;
case tg_via:
if (strcmp(token, "via") == 0)
@@ -247,13 +247,10 @@ static int translate_mac_debugfs(const char *mesh_iface,
break;
case tg_originator:
mac_tmp = ether_aton(token);
- if (!mac_tmp) {
+ if (!mac_tmp)
line_invalid = 1;
- } else {
- memcpy(mac_out, mac_tmp, ETH_ALEN);
- found = true;
- goto out;
- }
+ else
+ tg_hash_add(tg_hash, &mac, mac_tmp);
break;
}
@@ -262,40 +259,100 @@ static int translate_mac_debugfs(const char *mesh_iface,
}
}
-out:
if (f)
fclose(f);
free(line);
- if (found)
- return 0;
+ return 0;
+}
+
+static int tg_compare(void *d1, void *d2)
+{
+ struct tg_entry *s1 = d1, *s2 = d2;
+
+ if (memcmp(&s1->mac, &s2->mac, sizeof(s1->mac)) == 0)
+ return 1;
else
- return -ENOENT;
+ return 0;
}
-struct ether_addr *translate_mac(const char *mesh_iface,
- const struct ether_addr *mac)
+static int tg_choose(void *d1, int size)
{
- struct ether_addr in_mac;
- static struct ether_addr out_mac;
- struct ether_addr *mac_result;
+ struct tg_entry *s1 = d1;
+ uint32_t hash = 0;
+ size_t i;
+
+ for (i = 0; i < sizeof(s1->mac); i++) {
+ hash += s1->mac.ether_addr_octet[i];
+ hash += (hash << 10);
+ hash ^= (hash >> 6);
+ }
+
+ hash += (hash << 3);
+ hash ^= (hash >> 11);
+ hash += (hash << 15);
+
+ return hash % size;
+}
+
+struct hashtable_t *tg_hash_new(const char *mesh_iface)
+{
+ struct hashtable_t *tg_hash;
int ret;
- /* input mac has to be copied because it could be in the shared
- * ether_aton buffer
- */
- memcpy(&in_mac, mac, sizeof(in_mac));
- memcpy(&out_mac, mac, sizeof(out_mac));
- mac_result = &out_mac;
+ tg_hash = hash_new(64, tg_compare, tg_choose);
+ if (!tg_hash)
+ return NULL;
enable_net_admin_capability(1);
- ret = translate_mac_netlink(mesh_iface, &in_mac, mac_result);
+ ret = translate_mac_netlink(mesh_iface, tg_hash);
enable_net_admin_capability(0);
+ ret = -EOPNOTSUPP;
if (ret == -EOPNOTSUPP)
- translate_mac_debugfs(mesh_iface, &in_mac, mac_result);
+ translate_mac_debugfs(mesh_iface, tg_hash);
+
+ return tg_hash;
+}
+
+void tg_hash_free(struct hashtable_t *tg_hash)
+{
+ hash_delete(tg_hash, free);
+}
+
+int tg_hash_add(struct hashtable_t *tg_hash, struct ether_addr *mac,
+ struct ether_addr *originator)
+{
+ struct tg_entry *n;
+
+ n = malloc(sizeof(*n));
+ if (!n)
+ return -ENOMEM;
+
+ n->mac = *mac;
+ n->originator = *originator;
+
+ if (hash_add(tg_hash, n)) {
+ free(n);
+ return -EEXIST;
+ }
+
+ return 0;
+}
+
+struct ether_addr *translate_mac(struct hashtable_t *tg_hash,
+ const struct ether_addr *mac)
+{
+ struct tg_entry search = {
+ .mac = *mac,
+ };
+ struct tg_entry *found;
+
+ found = hash_find(tg_hash, &search);
+ if (!found)
+ return 0;
- return mac_result;
+ return &found->originator;
}
static int get_tq_debugfs(const char *mesh_iface, struct hashtable_t *orig_hash)
diff --git a/batadv_query.h b/batadv_query.h
index aa4d3f8..dc2b135 100644
--- a/batadv_query.h
+++ b/batadv_query.h
@@ -31,7 +31,16 @@ struct orig_entry {
uint8_t tq;
};
-struct ether_addr *translate_mac(const char *mesh_iface,
+struct tg_entry {
+ struct ether_addr mac;
+ struct ether_addr originator;
+};
+
+struct hashtable_t *tg_hash_new(const char *mesh_iface);
+void tg_hash_free(struct hashtable_t *tg_hash);
+int tg_hash_add(struct hashtable_t *tg_hash, struct ether_addr *mac,
+ struct ether_addr *originator);
+struct ether_addr *translate_mac(struct hashtable_t *tg_hash,
const struct ether_addr *mac);
struct hashtable_t *orig_hash_new(const char *mesh_iface);
diff --git a/batadv_querynl.c b/batadv_querynl.c
index ba678ae..ca9ee2c 100644
--- a/batadv_querynl.c
+++ b/batadv_querynl.c
@@ -49,8 +49,7 @@ static const int translate_mac_netlink_mandatory[] = {
};
struct translate_mac_netlink_opts {
- struct ether_addr mac;
- bool found;
+ struct hashtable_t *tg_hash;
struct nlquery_opts query_opts;
};
@@ -61,6 +60,8 @@ static int translate_mac_netlink_cb(struct nl_msg *msg, void *arg)
struct nlquery_opts *query_opts = arg;
struct translate_mac_netlink_opts *opts;
struct genlmsghdr *ghdr;
+ struct ether_addr mac_addr;
+ struct ether_addr mac_orig;
uint8_t *addr;
uint8_t *orig;
@@ -90,40 +91,30 @@ static int translate_mac_netlink_cb(struct nl_msg *msg, void *arg)
if (!attrs[BATADV_ATTR_FLAG_BEST])
return NL_OK;
- if (memcmp(&opts->mac, addr, ETH_ALEN) != 0)
- return NL_OK;
-
- memcpy(&opts->mac, orig, ETH_ALEN);
- opts->found = true;
+ memcpy(&mac_addr, addr, sizeof(mac_addr));
+ memcpy(&mac_orig, orig, sizeof(mac_orig));
+ tg_hash_add(opts->tg_hash, &mac_addr, &mac_orig);
opts->query_opts.err = 0;
return NL_STOP;
}
-int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac,
- struct ether_addr *mac_out)
+int translate_mac_netlink(const char *mesh_iface, struct hashtable_t *tg_hash)
{
struct translate_mac_netlink_opts opts = {
- .found = false,
+ .tg_hash = tg_hash,
.query_opts = {
.err = 0,
},
};
int ret;
- memcpy(&opts.mac, mac, ETH_ALEN);
-
ret = netlink_query_common(mesh_iface,
BATADV_CMD_GET_TRANSTABLE_GLOBAL,
translate_mac_netlink_cb, &opts.query_opts);
if (ret < 0)
return ret;
- if (!opts.found)
- return -ENOENT;
-
- memcpy(mac_out, &opts.mac, ETH_ALEN);
-
return 0;
}
diff --git a/batadv_querynl.h b/batadv_querynl.h
index f5c7e38..4b42ed5 100644
--- a/batadv_querynl.h
+++ b/batadv_querynl.h
@@ -27,8 +27,7 @@
struct ether_addr;
struct hashtable_t;
-int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac,
- struct ether_addr *mac_out);
+int translate_mac_netlink(const char *mesh_iface, struct hashtable_t *tg_hash);
int get_tq_netlink(const char *mesh_iface, struct hashtable_t *orig_hash);
int batadv_interface_check_netlink(const char *mesh_iface);
diff --git a/server.c b/server.c
index 852dc34..1e358cf 100644
--- a/server.c
+++ b/server.c
@@ -223,6 +223,7 @@ static void update_server_info(struct globals *globals)
struct hash_it_t *hashit = NULL;
struct interface *interface;
struct ether_addr *macaddr;
+ struct hashtable_t *tg_hash;
struct hashtable_t *orig_hash;
/* TQ is not used for master sync mode */
@@ -230,10 +231,16 @@ static void update_server_info(struct globals *globals)
return;
if (strcmp(globals->mesh_iface, "none") != 0) {
+ tg_hash = tg_hash_new(globals->mesh_iface);
+ if (!globals->data_hash) {
+ fprintf(stderr, "Failed to create translation hash\n");
+ return;
+ }
+
orig_hash = orig_hash_new(globals->mesh_iface);
if (!orig_hash) {
fprintf(stderr, "Failed to create originator hash\n");
- return;
+ goto free_tg_hash;
}
}
@@ -247,8 +254,7 @@ static void update_server_info(struct globals *globals)
continue;
}
- macaddr = translate_mac(globals->mesh_iface,
- &server->hwaddr);
+ macaddr = translate_mac(tg_hash, &server->hwaddr);
if (macaddr)
server->tq = get_tq(orig_hash, macaddr);
else
@@ -260,6 +266,9 @@ static void update_server_info(struct globals *globals)
if (orig_hash)
orig_hash_free(orig_hash);
+free_tg_hash:
+ if (tg_hash)
+ tg_hash_free(tg_hash);
}
static void check_if_socket(struct interface *interface, struct globals *globals)
5 years
[alfred] master: alfred: Check the TQ of master servers before pushing data (551d369)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/alfred
On branch : master
>---------------------------------------------------------------
commit 551d36947b5cb6fe07fd2e5443291454db61a904
Author: Sven Eckelmann <sven.eckelmann(a)openmesh.com>
Date: Wed May 24 12:32:09 2017 +0200
alfred: Check the TQ of master servers before pushing data
The TQ value of the server might have changed dramatically since we
received the last announcement of a master server. This can especially
happen when node (which was previously the best server) moves a lot and its
announcements are lost for a while.
Instead of querying the TQ values of each node when receiving an
announcement, just query the TQ value before new data should be pushed to a
master server.
Signed-off-by: Sven Eckelmann <sven.eckelmann(a)openmesh.com>
Signed-off-by: Simon Wunderlich <simon.wunderlich(a)openmesh.com>
>---------------------------------------------------------------
551d36947b5cb6fe07fd2e5443291454db61a904
alfred.h | 1 -
recv.c | 21 +--------------------
server.c | 36 +++++++++++++++++++++++++++++++++++-
3 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/alfred.h b/alfred.h
index beda1a7..53d8b7a 100644
--- a/alfred.h
+++ b/alfred.h
@@ -153,7 +153,6 @@ extern alfred_addr alfred_mcast;
/* server.c */
int alfred_server(struct globals *globals);
-int set_best_server(struct globals *globals);
void changed_data_type(struct globals *globals, uint8_t arg);
/* client.c */
diff --git a/recv.c b/recv.c
index 8aa512d..12bb3f1 100644
--- a/recv.c
+++ b/recv.c
@@ -268,7 +268,6 @@ process_alfred_announce_master(struct globals *globals,
struct alfred_announce_master_v0 *announce)
{
struct server *server;
- struct ether_addr *macaddr;
struct ether_addr mac;
int ret;
int len;
@@ -296,6 +295,7 @@ process_alfred_announce_master(struct globals *globals,
memcpy(&server->hwaddr, &mac, ETH_ALEN);
memcpy(&server->address, source, sizeof(*source));
+ server->tq = 0;
if (hash_add(interface->server_hash, server)) {
free(server);
@@ -305,25 +305,6 @@ process_alfred_announce_master(struct globals *globals,
clock_gettime(CLOCK_MONOTONIC, &server->last_seen);
- /* TQ is not used for master sync mode */
- if (globals->opmode == OPMODE_MASTER) {
- server->tq = 0;
- return 0;
- }
-
- if (strcmp(globals->mesh_iface, "none") != 0) {
- macaddr = translate_mac(globals->mesh_iface,
- (struct ether_addr *)&server->hwaddr);
- if (macaddr)
- server->tq = get_tq(globals->mesh_iface, macaddr);
- else
- server->tq = 0;
- } else {
- server->tq = 255;
- }
-
- set_best_server(globals);
-
return 0;
}
diff --git a/server.c b/server.c
index 2c4042a..09acb80 100644
--- a/server.c
+++ b/server.c
@@ -113,7 +113,7 @@ static int create_hashes(struct globals *globals)
return 0;
}
-int set_best_server(struct globals *globals)
+static int set_best_server(struct globals *globals)
{
struct hash_it_t *hashit = NULL;
struct server *best_server = NULL;
@@ -218,6 +218,39 @@ static int purge_data(struct globals *globals)
return 0;
}
+static void update_server_info(struct globals *globals)
+{
+ struct hash_it_t *hashit = NULL;
+ struct interface *interface;
+ struct ether_addr *macaddr;
+
+ /* TQ is not used for master sync mode */
+ if (globals->opmode == OPMODE_MASTER)
+ return;
+
+ list_for_each_entry(interface, &globals->interfaces, list) {
+ while (NULL != (hashit = hash_iterate(interface->server_hash,
+ hashit))) {
+ struct server *server = hashit->bucket->data;
+
+ if (strcmp(globals->mesh_iface, "none") == 0) {
+ server->tq = 255;
+ continue;
+ }
+
+ macaddr = translate_mac(globals->mesh_iface,
+ &server->hwaddr);
+ if (macaddr)
+ server->tq = get_tq(globals->mesh_iface,
+ macaddr);
+ else
+ server->tq = 0;
+ }
+ }
+
+ set_best_server(globals);
+}
+
static void check_if_socket(struct interface *interface, struct globals *globals)
{
int sock;
@@ -422,6 +455,7 @@ int alfred_server(struct globals *globals)
sync_data(globals);
} else {
/* send local data to server */
+ update_server_info(globals);
push_local_data(globals);
}
purge_data(globals);
5 years
[alfred] master: alfred: Only query tq of remote master in slave mode (20fb7a6)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/alfred
On branch : master
>---------------------------------------------------------------
commit 20fb7a66a576bac25d216a24b6dfea8bdbb214fb
Author: Sven Eckelmann <sven.eckelmann(a)openmesh.com>
Date: Wed May 24 12:32:08 2017 +0200
alfred: Only query tq of remote master in slave mode
The querying of the originator mac address and tq values of the orignator
address takes significant amount of time. It is therefore better to avoid
the TQ retrieval code when possible.
The TQ will not be used in master mode and it can therefore be skipped
together with the code which tries to find the new best server.
Signed-off-by: Sven Eckelmann <sven.eckelmann(a)openmesh.com>
Signed-off-by: Simon Wunderlich <simon.wunderlich(a)openmesh.com>
>---------------------------------------------------------------
20fb7a66a576bac25d216a24b6dfea8bdbb214fb
recv.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/recv.c b/recv.c
index 3fd964d..8aa512d 100644
--- a/recv.c
+++ b/recv.c
@@ -304,6 +304,13 @@ process_alfred_announce_master(struct globals *globals,
}
clock_gettime(CLOCK_MONOTONIC, &server->last_seen);
+
+ /* TQ is not used for master sync mode */
+ if (globals->opmode == OPMODE_MASTER) {
+ server->tq = 0;
+ return 0;
+ }
+
if (strcmp(globals->mesh_iface, "none") != 0) {
macaddr = translate_mac(globals->mesh_iface,
(struct ether_addr *)&server->hwaddr);
@@ -315,8 +322,7 @@ process_alfred_announce_master(struct globals *globals,
server->tq = 255;
}
- if (globals->opmode == OPMODE_SLAVE)
- set_best_server(globals);
+ set_best_server(globals);
return 0;
}
5 years
[alfred] master: alfred: Move alfred specific netlink code in separate file (576d038)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/alfred
On branch : master
>---------------------------------------------------------------
commit 576d03874e6f342af4881f4615a37d9fe291478a
Author: Sven Eckelmann <sven.eckelmann(a)openmesh.com>
Date: Wed May 24 12:32:07 2017 +0200
alfred: Move alfred specific netlink code in separate file
The vis daemon doesn't require the same set of netlink functions as alfred
daemon. But the netlink.c file is shared between both. Split the file to
avoid a lot of dead code in vis.
Signed-off-by: Sven Eckelmann <sven.eckelmann(a)openmesh.com>
Signed-off-by: Simon Wunderlich <simon.wunderlich(a)openmesh.com>
>---------------------------------------------------------------
576d03874e6f342af4881f4615a37d9fe291478a
Makefile | 1 +
batadv_query.c | 2 +-
netlink.c => batadv_querynl.c | 168 ++----------------------------------
netlink.h => batadv_querynl.h | 29 +------
netlink.c | 195 ------------------------------------------
netlink.h | 7 --
6 files changed, 12 insertions(+), 390 deletions(-)
diff --git a/Makefile b/Makefile
index 3c88e96..4c1c6b5 100755
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,7 @@
# alfred build
BINARY_NAME = alfred
OBJ += batadv_query.o
+OBJ += batadv_querynl.o
OBJ += client.o
OBJ += debugfs.o
OBJ += hash.o
diff --git a/batadv_query.c b/batadv_query.c
index 6ec086b..e68052b 100644
--- a/batadv_query.c
+++ b/batadv_query.c
@@ -34,7 +34,7 @@
#endif
#include <sys/types.h>
-#include "netlink.h"
+#include "batadv_querynl.h"
#include "debugfs.h"
#define DEBUG_BATIF_PATH_FMT "%s/batman_adv/%s"
diff --git a/netlink.c b/batadv_querynl.c
similarity index 53%
copy from netlink.c
copy to batadv_querynl.c
index 1964ab8..8dab96e 100644
--- a/netlink.c
+++ b/batadv_querynl.c
@@ -19,7 +19,7 @@
*
*/
-#include "netlink.h"
+#include "batadv_querynl.h"
#include <stdbool.h>
#include <stddef.h>
@@ -35,168 +35,12 @@
#include <net/ethernet.h>
#include "batman_adv.h"
+#include "netlink.h"
#ifndef __unused
#define __unused __attribute__((unused))
#endif
-struct nla_policy batadv_netlink_policy[NUM_BATADV_ATTR] = {
- [BATADV_ATTR_VERSION] = { .type = NLA_STRING },
- [BATADV_ATTR_ALGO_NAME] = { .type = NLA_STRING },
- [BATADV_ATTR_MESH_IFINDEX] = { .type = NLA_U32 },
- [BATADV_ATTR_MESH_IFNAME] = { .type = NLA_STRING,
- .maxlen = IFNAMSIZ },
- [BATADV_ATTR_MESH_ADDRESS] = { .type = NLA_UNSPEC,
- .minlen = ETH_ALEN,
- .maxlen = ETH_ALEN },
- [BATADV_ATTR_HARD_IFINDEX] = { .type = NLA_U32 },
- [BATADV_ATTR_HARD_IFNAME] = { .type = NLA_STRING,
- .maxlen = IFNAMSIZ },
- [BATADV_ATTR_HARD_ADDRESS] = { .type = NLA_UNSPEC,
- .minlen = ETH_ALEN,
- .maxlen = ETH_ALEN },
- [BATADV_ATTR_ORIG_ADDRESS] = { .type = NLA_UNSPEC,
- .minlen = ETH_ALEN,
- .maxlen = ETH_ALEN },
- [BATADV_ATTR_TPMETER_RESULT] = { .type = NLA_U8 },
- [BATADV_ATTR_TPMETER_TEST_TIME] = { .type = NLA_U32 },
- [BATADV_ATTR_TPMETER_BYTES] = { .type = NLA_U64 },
- [BATADV_ATTR_TPMETER_COOKIE] = { .type = NLA_U32 },
- [BATADV_ATTR_PAD] = { .type = NLA_UNSPEC },
- [BATADV_ATTR_ACTIVE] = { .type = NLA_FLAG },
- [BATADV_ATTR_TT_ADDRESS] = { .type = NLA_UNSPEC,
- .minlen = ETH_ALEN,
- .maxlen = ETH_ALEN },
- [BATADV_ATTR_TT_TTVN] = { .type = NLA_U8 },
- [BATADV_ATTR_TT_LAST_TTVN] = { .type = NLA_U8 },
- [BATADV_ATTR_TT_CRC32] = { .type = NLA_U32 },
- [BATADV_ATTR_TT_VID] = { .type = NLA_U16 },
- [BATADV_ATTR_TT_FLAGS] = { .type = NLA_U32 },
- [BATADV_ATTR_FLAG_BEST] = { .type = NLA_FLAG },
- [BATADV_ATTR_LAST_SEEN_MSECS] = { .type = NLA_U32 },
- [BATADV_ATTR_NEIGH_ADDRESS] = { .type = NLA_UNSPEC,
- .minlen = ETH_ALEN,
- .maxlen = ETH_ALEN },
- [BATADV_ATTR_TQ] = { .type = NLA_U8 },
- [BATADV_ATTR_THROUGHPUT] = { .type = NLA_U32 },
- [BATADV_ATTR_BANDWIDTH_UP] = { .type = NLA_U32 },
- [BATADV_ATTR_BANDWIDTH_DOWN] = { .type = NLA_U32 },
- [BATADV_ATTR_ROUTER] = { .type = NLA_UNSPEC,
- .minlen = ETH_ALEN,
- .maxlen = ETH_ALEN },
- [BATADV_ATTR_BLA_OWN] = { .type = NLA_FLAG },
- [BATADV_ATTR_BLA_ADDRESS] = { .type = NLA_UNSPEC,
- .minlen = ETH_ALEN,
- .maxlen = ETH_ALEN },
- [BATADV_ATTR_BLA_VID] = { .type = NLA_U16 },
- [BATADV_ATTR_BLA_BACKBONE] = { .type = NLA_UNSPEC,
- .minlen = ETH_ALEN,
- .maxlen = ETH_ALEN },
- [BATADV_ATTR_BLA_CRC] = { .type = NLA_U16 },
-};
-
-int missing_mandatory_attrs(struct nlattr *attrs[], const int mandatory[],
- size_t num)
-{
- size_t i;
-
- for (i = 0; i < num; i++)
- if (!attrs[mandatory[i]])
- return -EINVAL;
-
- return 0;
-}
-
-static int nlquery_error_cb(struct sockaddr_nl *nla __unused,
- struct nlmsgerr *nlerr, void *arg)
-{
- struct nlquery_opts *query_opts = arg;
-
- query_opts->err = nlerr->error;
-
- return NL_STOP;
-}
-
-static int nlquery_stop_cb(struct nl_msg *msg, void *arg)
-{
- struct nlmsghdr *nlh = nlmsg_hdr(msg);
- struct nlquery_opts *query_opts = arg;
- int *error = nlmsg_data(nlh);
-
- if (*error)
- query_opts->err = *error;
-
- return NL_STOP;
-}
-
-int netlink_query_common(const char *mesh_iface, uint8_t nl_cmd,
- nl_recvmsg_msg_cb_t callback,
- struct nlquery_opts *query_opts)
-{
- struct nl_sock *sock;
- struct nl_msg *msg;
- struct nl_cb *cb;
- int ifindex;
- int family;
- int ret;
-
- query_opts->err = 0;
-
- sock = nl_socket_alloc();
- if (!sock)
- return -ENOMEM;
-
- ret = genl_connect(sock);
- if (ret < 0) {
- query_opts->err = ret;
- goto err_free_sock;
- }
-
- family = genl_ctrl_resolve(sock, BATADV_NL_NAME);
- if (family < 0) {
- query_opts->err = -EOPNOTSUPP;
- goto err_free_sock;
- }
-
- ifindex = if_nametoindex(mesh_iface);
- if (!ifindex) {
- query_opts->err = -ENODEV;
- goto err_free_sock;
- }
-
- cb = nl_cb_alloc(NL_CB_DEFAULT);
- if (!cb) {
- query_opts->err = -ENOMEM;
- goto err_free_sock;
- }
-
- nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, callback, query_opts);
- nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, nlquery_stop_cb, query_opts);
- nl_cb_err(cb, NL_CB_CUSTOM, nlquery_error_cb, query_opts);
-
- msg = nlmsg_alloc();
- if (!msg) {
- query_opts->err = -ENOMEM;
- goto err_free_cb;
- }
-
- genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, NLM_F_DUMP,
- nl_cmd, 1);
-
- nla_put_u32(msg, BATADV_ATTR_MESH_IFINDEX, ifindex);
- nl_send_auto_complete(sock, msg);
- nlmsg_free(msg);
-
- nl_recvmsgs(sock, cb);
-
-err_free_cb:
- nl_cb_put(cb);
-err_free_sock:
- nl_socket_free(sock);
-
- return query_opts->err;
-}
-
static const int translate_mac_netlink_mandatory[] = {
BATADV_ATTR_TT_ADDRESS,
BATADV_ATTR_ORIG_ADDRESS,
@@ -210,7 +54,7 @@ struct translate_mac_netlink_opts {
static int translate_mac_netlink_cb(struct nl_msg *msg, void *arg)
{
- struct nlattr *attrs[BATADV_ATTR_MAX+1];
+ struct nlattr *attrs[BATADV_ATTR_MAX + 1];
struct nlmsghdr *nlh = nlmsg_hdr(msg);
struct nlquery_opts *query_opts = arg;
struct translate_mac_netlink_opts *opts;
@@ -269,7 +113,7 @@ int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac,
ret = netlink_query_common(mesh_iface,
BATADV_CMD_GET_TRANSTABLE_GLOBAL,
- translate_mac_netlink_cb, &opts.query_opts);
+ translate_mac_netlink_cb, &opts.query_opts);
if (ret < 0)
return ret;
@@ -295,7 +139,7 @@ struct get_tq_netlink_opts {
static int get_tq_netlink_cb(struct nl_msg *msg, void *arg)
{
- struct nlattr *attrs[BATADV_ATTR_MAX+1];
+ struct nlattr *attrs[BATADV_ATTR_MAX + 1];
struct nlmsghdr *nlh = nlmsg_hdr(msg);
struct nlquery_opts *query_opts = arg;
struct get_tq_netlink_opts *opts;
@@ -354,7 +198,7 @@ int get_tq_netlink(const char *mesh_iface, const struct ether_addr *mac,
memcpy(&opts.mac, mac, ETH_ALEN);
ret = netlink_query_common(mesh_iface, BATADV_CMD_GET_ORIGINATORS,
- get_tq_netlink_cb, &opts.query_opts);
+ get_tq_netlink_cb, &opts.query_opts);
if (ret < 0)
return ret;
diff --git a/netlink.h b/batadv_querynl.h
similarity index 59%
copy from netlink.h
copy to batadv_querynl.h
index 1c87695..9b93a47 100644
--- a/netlink.h
+++ b/batadv_querynl.h
@@ -19,38 +19,17 @@
*
*/
-#ifndef _ALFRED_NETLINK_H
-#define _ALFRED_NETLINK_H
+#ifndef _BATADV_QUERYNL_H
+#define _BATADV_QUERYNL_H
-#include <netlink/genl/genl.h>
-#include <netlink/genl/ctrl.h>
-#include <stddef.h>
+#include <stdint.h>
struct ether_addr;
-struct nlquery_opts {
- int err;
-};
-
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
-
-#ifndef container_of
-#define container_of(ptr, type, member) __extension__ ({ \
- const __typeof__(((type *)0)->member) *__pmember = (ptr); \
- (type *)((char *)__pmember - offsetof(type, member)); })
-#endif
-
-int netlink_query_common(const char *mesh_iface, uint8_t nl_cmd,
- nl_recvmsg_msg_cb_t callback,
- struct nlquery_opts *query_opts);
-int missing_mandatory_attrs(struct nlattr *attrs[], const int mandatory[],
- size_t num);
int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac,
struct ether_addr *mac_out);
int get_tq_netlink(const char *mesh_iface, const struct ether_addr *mac,
uint8_t *tq);
int batadv_interface_check_netlink(const char *mesh_iface);
-extern struct nla_policy batadv_netlink_policy[];
-
-#endif /* _ALFRED_NETLINK_H */
+#endif /* _BATADV_QUERYNL_H */
diff --git a/netlink.c b/netlink.c
index 1964ab8..7ef4308 100644
--- a/netlink.c
+++ b/netlink.c
@@ -27,7 +27,6 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
-#include <net/ethernet.h>
#include <net/if.h>
#include <netlink/netlink.h>
#include <netlink/genl/genl.h>
@@ -196,197 +195,3 @@ err_free_sock:
return query_opts->err;
}
-
-static const int translate_mac_netlink_mandatory[] = {
- BATADV_ATTR_TT_ADDRESS,
- BATADV_ATTR_ORIG_ADDRESS,
-};
-
-struct translate_mac_netlink_opts {
- struct ether_addr mac;
- bool found;
- struct nlquery_opts query_opts;
-};
-
-static int translate_mac_netlink_cb(struct nl_msg *msg, void *arg)
-{
- struct nlattr *attrs[BATADV_ATTR_MAX+1];
- struct nlmsghdr *nlh = nlmsg_hdr(msg);
- struct nlquery_opts *query_opts = arg;
- struct translate_mac_netlink_opts *opts;
- struct genlmsghdr *ghdr;
- uint8_t *addr;
- uint8_t *orig;
-
- opts = container_of(query_opts, struct translate_mac_netlink_opts,
- query_opts);
-
- if (!genlmsg_valid_hdr(nlh, 0))
- return NL_OK;
-
- ghdr = nlmsg_data(nlh);
-
- if (ghdr->cmd != BATADV_CMD_GET_TRANSTABLE_GLOBAL)
- return NL_OK;
-
- if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
- genlmsg_len(ghdr), batadv_netlink_policy)) {
- return NL_OK;
- }
-
- if (missing_mandatory_attrs(attrs, translate_mac_netlink_mandatory,
- ARRAY_SIZE(translate_mac_netlink_mandatory)))
- return NL_OK;
-
- addr = nla_data(attrs[BATADV_ATTR_TT_ADDRESS]);
- orig = nla_data(attrs[BATADV_ATTR_ORIG_ADDRESS]);
-
- if (!attrs[BATADV_ATTR_FLAG_BEST])
- return NL_OK;
-
- if (memcmp(&opts->mac, addr, ETH_ALEN) != 0)
- return NL_OK;
-
- memcpy(&opts->mac, orig, ETH_ALEN);
- opts->found = true;
- opts->query_opts.err = 0;
-
- return NL_STOP;
-}
-
-int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac,
- struct ether_addr *mac_out)
-{
- struct translate_mac_netlink_opts opts = {
- .found = false,
- .query_opts = {
- .err = 0,
- },
- };
- int ret;
-
- memcpy(&opts.mac, mac, ETH_ALEN);
-
- ret = netlink_query_common(mesh_iface,
- BATADV_CMD_GET_TRANSTABLE_GLOBAL,
- translate_mac_netlink_cb, &opts.query_opts);
- if (ret < 0)
- return ret;
-
- if (!opts.found)
- return -ENOENT;
-
- memcpy(mac_out, &opts.mac, ETH_ALEN);
-
- return 0;
-}
-
-static const int get_tq_netlink_mandatory[] = {
- BATADV_ATTR_ORIG_ADDRESS,
- BATADV_ATTR_TQ,
-};
-
-struct get_tq_netlink_opts {
- struct ether_addr mac;
- uint8_t tq;
- bool found;
- struct nlquery_opts query_opts;
-};
-
-static int get_tq_netlink_cb(struct nl_msg *msg, void *arg)
-{
- struct nlattr *attrs[BATADV_ATTR_MAX+1];
- struct nlmsghdr *nlh = nlmsg_hdr(msg);
- struct nlquery_opts *query_opts = arg;
- struct get_tq_netlink_opts *opts;
- struct genlmsghdr *ghdr;
- uint8_t *orig;
- uint8_t tq;
-
- opts = container_of(query_opts, struct get_tq_netlink_opts,
- query_opts);
-
- if (!genlmsg_valid_hdr(nlh, 0))
- return NL_OK;
-
- ghdr = nlmsg_data(nlh);
-
- if (ghdr->cmd != BATADV_CMD_GET_ORIGINATORS)
- return NL_OK;
-
- if (nla_parse(attrs, BATADV_ATTR_MAX, genlmsg_attrdata(ghdr, 0),
- genlmsg_len(ghdr), batadv_netlink_policy)) {
- return NL_OK;
- }
-
- if (missing_mandatory_attrs(attrs, get_tq_netlink_mandatory,
- ARRAY_SIZE(get_tq_netlink_mandatory)))
- return NL_OK;
-
- orig = nla_data(attrs[BATADV_ATTR_ORIG_ADDRESS]);
- tq = nla_get_u8(attrs[BATADV_ATTR_TQ]);
-
- if (!attrs[BATADV_ATTR_FLAG_BEST])
- return NL_OK;
-
- if (memcmp(&opts->mac, orig, ETH_ALEN) != 0)
- return NL_OK;
-
- opts->tq = tq;
- opts->found = true;
- opts->query_opts.err = 0;
-
- return NL_STOP;
-}
-
-int get_tq_netlink(const char *mesh_iface, const struct ether_addr *mac,
- uint8_t *tq)
-{
- struct get_tq_netlink_opts opts = {
- .tq = 0,
- .found = false,
- .query_opts = {
- .err = 0,
- },
- };
- int ret;
-
- memcpy(&opts.mac, mac, ETH_ALEN);
-
- ret = netlink_query_common(mesh_iface, BATADV_CMD_GET_ORIGINATORS,
- get_tq_netlink_cb, &opts.query_opts);
- if (ret < 0)
- return ret;
-
- if (!opts.found)
- return -ENOENT;
-
- *tq = opts.tq;
-
- return 0;
-}
-
-static int check_nlcmd_cb(struct nl_msg *msg __unused, void *arg __unused)
-{
- return NL_STOP;
-}
-
-int batadv_interface_check_netlink(const char *mesh_iface)
-{
- struct nlquery_opts opts = {
- .err = 0,
- };
- int ret;
-
- ret = netlink_query_common(mesh_iface, BATADV_CMD_GET_ORIGINATORS,
- check_nlcmd_cb, &opts);
- if (ret < 0)
- return ret;
-
- ret = netlink_query_common(mesh_iface, BATADV_CMD_GET_TRANSTABLE_GLOBAL,
- check_nlcmd_cb, &opts);
- if (ret < 0)
- return ret;
-
- return 0;
-}
diff --git a/netlink.h b/netlink.h
index 1c87695..a4471a1 100644
--- a/netlink.h
+++ b/netlink.h
@@ -26,8 +26,6 @@
#include <netlink/genl/ctrl.h>
#include <stddef.h>
-struct ether_addr;
-
struct nlquery_opts {
int err;
};
@@ -45,11 +43,6 @@ int netlink_query_common(const char *mesh_iface, uint8_t nl_cmd,
struct nlquery_opts *query_opts);
int missing_mandatory_attrs(struct nlattr *attrs[], const int mandatory[],
size_t num);
-int translate_mac_netlink(const char *mesh_iface, const struct ether_addr *mac,
- struct ether_addr *mac_out);
-int get_tq_netlink(const char *mesh_iface, const struct ether_addr *mac,
- uint8_t *tq);
-int batadv_interface_check_netlink(const char *mesh_iface);
extern struct nla_policy batadv_netlink_policy[];
5 years
[linux-merge]linux integration; annotated tag, v4.12-rc3, created. v4.12-rc3
by postmaster@open-mesh.org
The annotated tag, v4.12-rc3 has been created
at 992074ed78d9b1a05d18c656fa16b51f4d25005e (tag)
tagging 5ed02dbb497422bf225783f46e6eadd237d23d6b (commit)
replaces v4.12-rc2
tagged by Linus Torvalds
on Sun May 28 17:20:59 2017 -0700
- Shortlog ------------------------------------------------------------
Linux 4.12-rc3
-----BEGIN PGP SIGNATURE-----
iQEcBAABAgAGBQJZK2lrAAoJEHm+PkMAQRiGm3AH/13F1DlIk05aSXHoDr/idIpR
GMHmk3YF+EuFjsL463Sh6s/SSWmz0Lda8euaoB4wCWvQFX2ZjTE+aOd79XlRiZJQ
OTtLkV9I41eXIJUpEOHia7xZiCsbw+usqcHrm1aBoSh5KKV2iQmEOrnJdibqJVOF
eXUMphNK/zFtAd2bKtQSxkaBnOOqsQUgVQSkr2K9rSg25l0KokFC6c5K5IjLn4x9
QgDY4wmMvHrDz0CtpoqlNM4XqbsDJVrFeZGfg6hlMqSRDeXeg4h3Ol0VfIT496RP
QBdrDb6hWO+HKt9B0M+7Q+8a/Fsw+5dtpqv1W/Wlr0i4CS6euU8NChAmrpkrqGo=
=m5ba
-----END PGP SIGNATURE-----
-----------------------------------------------------------------------
--
linux integration
5 years
[batman-adv] master: batman-adv: Print correct function names in dbg messages (4978390)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit 4978390e544d496157c6836bbf15270e3039e1c3
Author: Sven Eckelmann <sven(a)narfation.org>
Date: Fri May 19 13:02:00 2017 +0200
batman-adv: Print correct function names in dbg messages
The function names in batman-adv changed slightly in the past. But some of
the debug messages were not updated correctly and therefore some messages
were incorrect. To avoid this in the future, these kind of messages should
use __func__ to automatically print the correct function name.
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
>---------------------------------------------------------------
4978390e544d496157c6836bbf15270e3039e1c3
net/batman-adv/bat_iv_ogm.c | 3 +-
net/batman-adv/bridge_loop_avoidance.c | 72 +++++++++++++++++-----------------
net/batman-adv/distributed-arp-table.c | 2 +-
net/batman-adv/routing.c | 4 +-
net/batman-adv/send.c | 6 +--
5 files changed, 45 insertions(+), 42 deletions(-)
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 1f80392..fa8d6b4 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -1022,7 +1022,8 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
u8 tq_avg;
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
- "update_originator(): Searching and updating originator entry of received packet\n");
+ "%s(): Searching and updating originator entry of received packet\n",
+ __func__);
rcu_read_lock();
hlist_for_each_entry_rcu(tmp_neigh_node,
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index d07e89e..67234d1 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -394,7 +394,7 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, u8 *mac,
*/
ether_addr_copy(ethhdr->h_source, mac);
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_send_claim(): CLAIM %pM on vid %d\n", mac,
+ "%s(): CLAIM %pM on vid %d\n", __func__, mac,
batadv_print_vid(vid));
break;
case BATADV_CLAIM_TYPE_UNCLAIM:
@@ -403,7 +403,7 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, u8 *mac,
*/
ether_addr_copy(hw_src, mac);
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_send_claim(): UNCLAIM %pM on vid %d\n", mac,
+ "%s(): UNCLAIM %pM on vid %d\n", __func__, mac,
batadv_print_vid(vid));
break;
case BATADV_CLAIM_TYPE_ANNOUNCE:
@@ -412,7 +412,7 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, u8 *mac,
*/
ether_addr_copy(hw_src, mac);
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_send_claim(): ANNOUNCE of %pM on vid %d\n",
+ "%s(): ANNOUNCE of %pM on vid %d\n", __func__,
ethhdr->h_source, batadv_print_vid(vid));
break;
case BATADV_CLAIM_TYPE_REQUEST:
@@ -423,15 +423,15 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, u8 *mac,
ether_addr_copy(hw_src, mac);
ether_addr_copy(ethhdr->h_dest, mac);
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_send_claim(): REQUEST of %pM to %pM on vid %d\n",
+ "%s(): REQUEST of %pM to %pM on vid %d\n", __func__,
ethhdr->h_source, ethhdr->h_dest,
batadv_print_vid(vid));
break;
case BATADV_CLAIM_TYPE_LOOPDETECT:
ether_addr_copy(ethhdr->h_source, mac);
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_send_claim(): LOOPDETECT of %pM to %pM on vid %d\n",
- ethhdr->h_source, ethhdr->h_dest,
+ "%s(): LOOPDETECT of %pM to %pM on vid %d\n",
+ __func__, ethhdr->h_source, ethhdr->h_dest,
batadv_print_vid(vid));
break;
@@ -509,7 +509,7 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, u8 *orig,
return entry;
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_get_backbone_gw(): not found (%pM, %d), creating new entry\n",
+ "%s(): not found (%pM, %d), creating new entry\n", __func__,
orig, batadv_print_vid(vid));
entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
@@ -605,7 +605,8 @@ static void batadv_bla_answer_request(struct batadv_priv *bat_priv,
int i;
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_answer_request(): received a claim request, send all of our own claims again\n");
+ "%s(): received a claim request, send all of our own claims again\n",
+ __func__);
backbone_gw = batadv_backbone_hash_find(bat_priv,
primary_if->net_dev->dev_addr,
@@ -718,8 +719,8 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
kref_init(&claim->refcount);
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_add_claim(): adding new entry %pM, vid %d to hash ...\n",
- mac, batadv_print_vid(vid));
+ "%s(): adding new entry %pM, vid %d to hash ...\n",
+ __func__, mac, batadv_print_vid(vid));
kref_get(&claim->refcount);
hash_added = batadv_hash_add(bat_priv->bla.claim_hash,
@@ -739,8 +740,8 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
goto claim_free_ref;
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_add_claim(): changing ownership for %pM, vid %d to gw %pM\n",
- mac, batadv_print_vid(vid), backbone_gw->orig);
+ "%s(): changing ownership for %pM, vid %d to gw %pM\n",
+ __func__, mac, batadv_print_vid(vid), backbone_gw->orig);
remove_crc = true;
}
@@ -808,7 +809,7 @@ static void batadv_bla_del_claim(struct batadv_priv *bat_priv,
if (!claim)
return;
- batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla_del_claim(): %pM, vid %d\n",
+ batadv_dbg(BATADV_DBG_BLA, bat_priv, "%s(): %pM, vid %d\n", __func__,
mac, batadv_print_vid(vid));
batadv_hash_remove(bat_priv->bla.claim_hash, batadv_compare_claim,
@@ -848,8 +849,8 @@ static bool batadv_handle_announce(struct batadv_priv *bat_priv, u8 *an_addr,
crc = ntohs(*((__be16 *)(&an_addr[4])));
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "handle_announce(): ANNOUNCE vid %d (sent by %pM)... CRC = %#.4x\n",
- batadv_print_vid(vid), backbone_gw->orig, crc);
+ "%s(): ANNOUNCE vid %d (sent by %pM)... CRC = %#.4x\n",
+ __func__, batadv_print_vid(vid), backbone_gw->orig, crc);
spin_lock_bh(&backbone_gw->crc_lock);
backbone_crc = backbone_gw->crc;
@@ -857,8 +858,8 @@ static bool batadv_handle_announce(struct batadv_priv *bat_priv, u8 *an_addr,
if (backbone_crc != crc) {
batadv_dbg(BATADV_DBG_BLA, backbone_gw->bat_priv,
- "handle_announce(): CRC FAILED for %pM/%d (my = %#.4x, sent = %#.4x)\n",
- backbone_gw->orig,
+ "%s(): CRC FAILED for %pM/%d (my = %#.4x, sent = %#.4x)\n",
+ __func__, backbone_gw->orig,
batadv_print_vid(backbone_gw->vid),
backbone_crc, crc);
@@ -903,8 +904,8 @@ static bool batadv_handle_request(struct batadv_priv *bat_priv,
return true;
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "handle_request(): REQUEST vid %d (sent by %pM)...\n",
- batadv_print_vid(vid), ethhdr->h_source);
+ "%s(): REQUEST vid %d (sent by %pM)...\n",
+ __func__, batadv_print_vid(vid), ethhdr->h_source);
batadv_bla_answer_request(bat_priv, primary_if, vid);
return true;
@@ -940,7 +941,7 @@ static bool batadv_handle_unclaim(struct batadv_priv *bat_priv,
/* this must be an UNCLAIM frame */
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "handle_unclaim(): UNCLAIM %pM on vid %d (sent by %pM)...\n",
+ "%s(): UNCLAIM %pM on vid %d (sent by %pM)...\n", __func__,
claim_addr, batadv_print_vid(vid), backbone_gw->orig);
batadv_bla_del_claim(bat_priv, claim_addr, vid);
@@ -1160,9 +1161,9 @@ static bool batadv_bla_process_claim(struct batadv_priv *bat_priv,
ethhdr);
if (ret == 1)
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_process_claim(): received a claim frame from another group. From: %pM on vid %d ...(hw_src %pM, hw_dst %pM)\n",
- ethhdr->h_source, batadv_print_vid(vid), hw_src,
- hw_dst);
+ "%s(): received a claim frame from another group. From: %pM on vid %d ...(hw_src %pM, hw_dst %pM)\n",
+ __func__, ethhdr->h_source, batadv_print_vid(vid),
+ hw_src, hw_dst);
if (ret < 2)
return !!ret;
@@ -1196,8 +1197,9 @@ static bool batadv_bla_process_claim(struct batadv_priv *bat_priv,
}
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_process_claim(): ERROR - this looks like a claim frame, but is useless. eth src %pM on vid %d ...(hw_src %pM, hw_dst %pM)\n",
- ethhdr->h_source, batadv_print_vid(vid), hw_src, hw_dst);
+ "%s(): ERROR - this looks like a claim frame, but is useless. eth src %pM on vid %d ...(hw_src %pM, hw_dst %pM)\n",
+ __func__, ethhdr->h_source, batadv_print_vid(vid), hw_src,
+ hw_dst);
return true;
}
@@ -1237,8 +1239,8 @@ static void batadv_bla_purge_backbone_gw(struct batadv_priv *bat_priv, int now)
continue;
batadv_dbg(BATADV_DBG_BLA, backbone_gw->bat_priv,
- "bla_purge_backbone_gw(): backbone gw %pM timed out\n",
- backbone_gw->orig);
+ "%s(): backbone gw %pM timed out\n",
+ __func__, backbone_gw->orig);
purge_now:
/* don't wait for the pending request anymore */
@@ -1295,11 +1297,11 @@ static void batadv_bla_purge_claims(struct batadv_priv *bat_priv,
goto skip;
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_purge_claims(): timed out.\n");
+ "%s(): timed out.\n", __func__);
purge_now:
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_purge_claims(): %pM, vid %d\n",
+ "%s(): %pM, vid %d\n", __func__,
claim->addr, claim->vid);
batadv_handle_unclaim(bat_priv, primary_if,
@@ -1851,8 +1853,8 @@ bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,
*/
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "bla_rx(): Unclaimed MAC %pM found. Claim it. Local: %s\n",
- ethhdr->h_source,
+ "%s(): Unclaimed MAC %pM found. Claim it. Local: %s\n",
+ __func__, ethhdr->h_source,
batadv_is_my_client(bat_priv,
ethhdr->h_source, vid) ?
"yes" : "no");
@@ -1978,15 +1980,15 @@ bool batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,
* older than 100 ms to make sure we really
* have a roaming client here.
*/
- batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla_tx(): Roaming client %pM detected. Unclaim it.\n",
- ethhdr->h_source);
+ batadv_dbg(BATADV_DBG_BLA, bat_priv, "%s(): Roaming client %pM detected. Unclaim it.\n",
+ __func__, ethhdr->h_source);
batadv_handle_unclaim(bat_priv, primary_if,
primary_if->net_dev->dev_addr,
ethhdr->h_source, vid);
goto allow;
} else {
- batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla_tx(): Race for claim %pM detected. Drop packet.\n",
- ethhdr->h_source);
+ batadv_dbg(BATADV_DBG_BLA, bat_priv, "%s(): Race for claim %pM detected. Drop packet.\n",
+ __func__, ethhdr->h_source);
goto handled;
}
}
diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index 000ca2f..6930d6b 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -601,7 +601,7 @@ batadv_dat_select_candidates(struct batadv_priv *bat_priv, __be32 ip_dst,
BATADV_DAT_ADDR_MAX);
batadv_dbg(BATADV_DBG_DAT, bat_priv,
- "dat_select_candidates(): IP=%pI4 hash(IP)=%u\n", &ip_dst,
+ "%s(): IP=%pI4 hash(IP)=%u\n", __func__, &ip_dst,
ip_key);
for (select = 0; select < BATADV_DAT_CANDIDATES_NUM; select++)
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index ae9f4d3..f10e3ff 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -985,8 +985,8 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
batadv_orig_node_put(orig_node_gw);
if (is_gw) {
batadv_dbg(BATADV_DBG_BLA, bat_priv,
- "recv_unicast_packet(): Dropped unicast pkt received from another backbone gw %pM.\n",
- orig_addr_gw);
+ "%s(): Dropped unicast pkt received from another backbone gw %pM.\n",
+ __func__, orig_addr_gw);
goto free_skb;
}
}
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index 403df59..d239a9d 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -971,11 +971,11 @@ batadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
if (hard_iface)
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
- "purge_outstanding_packets(): %s\n",
- hard_iface->net_dev->name);
+ "%s(): %s\n",
+ __func__, hard_iface->net_dev->name);
else
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
- "purge_outstanding_packets()\n");
+ "%s()\n", __func__);
/* claim bcast list for free() */
spin_lock_bh(&bat_priv->forw_bcast_list_lock);
5 years, 1 month
[batman-adv] master: batman-adv: Replace a seq_puts() call by seq_putc() in two functions (1e88719)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit 1e88719ce590c69b2586c75d054754a1569ec3d2
Author: Markus Elfring <elfring(a)users.sourceforge.net>
Date: Sat May 6 17:50:13 2017 +0200
batman-adv: Replace a seq_puts() call by seq_putc() in two functions
Two single characters (line breaks) should be put into a sequence.
Thus use the corresponding function "seq_putc".
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring(a)users.sourceforge.net>
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
>---------------------------------------------------------------
1e88719ce590c69b2586c75d054754a1569ec3d2
net/batman-adv/bat_iv_ogm.c | 2 +-
net/batman-adv/bat_v.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 495ba7c..1f80392 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -1944,7 +1944,7 @@ static void batadv_iv_ogm_orig_print(struct batadv_priv *bat_priv,
batadv_iv_ogm_orig_print_neigh(orig_node, if_outgoing,
seq);
- seq_puts(seq, "\n");
+ seq_putc(seq, '\n');
batman_count++;
next:
diff --git a/net/batman-adv/bat_v.c b/net/batman-adv/bat_v.c
index a36c8e7..4e2724c 100644
--- a/net/batman-adv/bat_v.c
+++ b/net/batman-adv/bat_v.c
@@ -400,7 +400,7 @@ static void batadv_v_orig_print(struct batadv_priv *bat_priv,
neigh_node->if_incoming->net_dev->name);
batadv_v_orig_print_neigh(orig_node, if_outgoing, seq);
- seq_puts(seq, "\n");
+ seq_putc(seq, '\n');
batman_count++;
next:
5 years, 1 month
[batman-adv] master: batman-adv: Combine two seq_puts() calls into one call in batadv_nc_nodes_seq_print_text() (82f2fa5)
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
On branch : master
>---------------------------------------------------------------
commit 82f2fa5b637dad468f79f6357173683fac4c1a35
Author: Markus Elfring <elfring(a)users.sourceforge.net>
Date: Sat May 6 17:57:36 2017 +0200
batman-adv: Combine two seq_puts() calls into one call in batadv_nc_nodes_seq_print_text()
A bit of text was put into a sequence by two separate function calls.
Print the same data by a single function call instead.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring(a)users.sourceforge.net>
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
>---------------------------------------------------------------
82f2fa5b637dad468f79f6357173683fac4c1a35
net/batman-adv/network-coding.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/net/batman-adv/network-coding.c b/net/batman-adv/network-coding.c
index e1f6fc7..3604d78 100644
--- a/net/batman-adv/network-coding.c
+++ b/net/batman-adv/network-coding.c
@@ -1935,9 +1935,7 @@ int batadv_nc_nodes_seq_print_text(struct seq_file *seq, void *offset)
list)
seq_printf(seq, "%pM ",
nc_node->addr);
- seq_puts(seq, "\n");
-
- seq_puts(seq, " Outgoing: ");
+ seq_puts(seq, "\n Outgoing: ");
/* For out_nc_node to this orig_node */
list_for_each_entry_rcu(nc_node,
&orig_node->out_coding_list,
5 years, 1 month
[batman-adv] tag 'v2017.1' created
by postmaster@open-mesh.org
Repository : ssh://git@open-mesh.org/batman-adv
New tag : v2017.1
Referencing: a19c10f2ac5bb6e48e52f7401bc25a813bd27d58
5 years, 1 month