b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [PATCH 2/4] alfred: Allow exactly one interface for secondary mode
Date: Mon, 15 Feb 2021 21:01:24 +0100	[thread overview]
Message-ID: <20210215200126.140253-2-sven@narfation.org> (raw)
In-Reply-To: <20210215200126.140253-1-sven@narfation.org>

A primary alfred daemon allows syncing over more than one interface. But
the secondary alfred daemon needs exactly one interface. But the check for
this property was insufficient because it allowed paramters like
"-i wlan0,asd" when wlan0 is valid and asd is not valid.

The better solution is to really use the number of interfaces given to
alfred instead of the number of interfaces evaluated as "valid".

Fixes: 67ae5f57eedd ("alfred: Add support for multiple interfaces per master")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 alfred.h  |  1 +
 netsock.c | 11 +++++++++++
 server.c  |  4 +++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/alfred.h b/alfred.h
index 1e2c058..7d6b0b3 100644
--- a/alfred.h
+++ b/alfred.h
@@ -182,6 +182,7 @@ int unix_sock_req_data_finish(struct globals *globals,
 int vis_update_data(struct globals *globals);
 /* netsock.c */
 int netsock_open_all(struct globals *globals);
+size_t netsocket_count_interfaces(struct globals *globals);
 void netsock_close_all(struct globals *globals);
 int netsock_set_interfaces(struct globals *globals, char *interfaces);
 struct interface *netsock_first_interface(struct globals *globals);
diff --git a/netsock.c b/netsock.c
index 367b207..84b0ec3 100644
--- a/netsock.c
+++ b/netsock.c
@@ -471,6 +471,17 @@ int netsock_open_all(struct globals *globals)
 	return num_socks;
 }
 
+size_t netsocket_count_interfaces(struct globals *globals)
+{
+	struct interface *interface;
+	size_t count = 0;
+
+	list_for_each_entry(interface, &globals->interfaces, list)
+		count++;
+
+	return count;
+}
+
 void netsock_reopen(struct globals *globals)
 {
 	struct interface *interface;
diff --git a/server.c b/server.c
index efac5ad..eb2bc8a 100644
--- a/server.c
+++ b/server.c
@@ -371,6 +371,7 @@ int alfred_server(struct globals *globals)
 	int maxsock, ret, recvs;
 	struct timespec last_check, now, tv;
 	fd_set fds, errfds;
+	size_t num_interfaces;
 	int num_socks;
 
 	if (create_hashes(globals))
@@ -397,7 +398,8 @@ int alfred_server(struct globals *globals)
 		return -1;
 	}
 
-	if (num_socks > 1 && globals->opmode == OPMODE_SECONDARY) {
+	num_interfaces = netsocket_count_interfaces(globals);
+	if (num_interfaces > 1 && globals->opmode == OPMODE_SECONDARY) {
 		fprintf(stderr, "More than one interface specified in secondary mode\n");
 		return -1;
 	}
-- 
2.30.0


  reply	other threads:[~2021-02-15 20:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-15 20:01 [PATCH 1/4] alfred: Show error message for invalid batadv interface Sven Eckelmann
2021-02-15 20:01 ` Sven Eckelmann [this message]
2021-02-15 20:01 ` [PATCH 3/4] alfred: Save global mode flags in bitfield Sven Eckelmann
2021-02-15 20:01 ` [PATCH 4/4] alfred: Allow start of server without valid interface Sven Eckelmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210215200126.140253-2-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).