alfred: Start up alfred without valid interfaces
[feed/routing.git] / alfred / patches / 0002-alfred-Allow-exactly-one-interface-for-secondary-mod.patch
1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Mon, 15 Feb 2021 20:16:15 +0100
3 Subject: alfred: Allow exactly one interface for secondary mode
4
5 A primary alfred daemon allows syncing over more than one interface. But
6 the secondary alfred daemon needs exactly one interface. But the check for
7 this property was insufficient because it allowed paramters like
8 "-i wlan0,asd" when wlan0 is valid and asd is not valid.
9
10 The better solution is to really use the number of interfaces given to
11 alfred instead of the number of interfaces evaluated as "valid".
12
13 Fixes: 67ae5f57eedd ("alfred: Add support for multiple interfaces per master")
14 Signed-off-by: Sven Eckelmann <sven@narfation.org>
15 Forwarded: https://patchwork.open-mesh.org/project/b.a.t.m.a.n./patch/20210215200126.140253-2-sven@narfation.org/
16
17 diff --git a/alfred.h b/alfred.h
18 index 1e2c05835cbfba02ebabefe55afc29f7ef8e12b1..7d6b0b35b5c8b8c3b087589880c390eb035584be 100644
19 --- a/alfred.h
20 +++ b/alfred.h
21 @@ -182,6 +182,7 @@ int unix_sock_req_data_finish(struct globals *globals,
22 int vis_update_data(struct globals *globals);
23 /* netsock.c */
24 int netsock_open_all(struct globals *globals);
25 +size_t netsocket_count_interfaces(struct globals *globals);
26 void netsock_close_all(struct globals *globals);
27 int netsock_set_interfaces(struct globals *globals, char *interfaces);
28 struct interface *netsock_first_interface(struct globals *globals);
29 diff --git a/netsock.c b/netsock.c
30 index 367b20730500a1c24448200a24149b64059f3381..84b0ec3827e491eead997f58b2b8f26c5b18b843 100644
31 --- a/netsock.c
32 +++ b/netsock.c
33 @@ -471,6 +471,17 @@ int netsock_open_all(struct globals *globals)
34 return num_socks;
35 }
36
37 +size_t netsocket_count_interfaces(struct globals *globals)
38 +{
39 + struct interface *interface;
40 + size_t count = 0;
41 +
42 + list_for_each_entry(interface, &globals->interfaces, list)
43 + count++;
44 +
45 + return count;
46 +}
47 +
48 void netsock_reopen(struct globals *globals)
49 {
50 struct interface *interface;
51 diff --git a/server.c b/server.c
52 index efac5ad399df52f8c444711a14bcf4814e38a3bf..eb2bc8aeb787e4bf028c8f9e3a523a18c6992be1 100644
53 --- a/server.c
54 +++ b/server.c
55 @@ -371,6 +371,7 @@ int alfred_server(struct globals *globals)
56 int maxsock, ret, recvs;
57 struct timespec last_check, now, tv;
58 fd_set fds, errfds;
59 + size_t num_interfaces;
60 int num_socks;
61
62 if (create_hashes(globals))
63 @@ -397,7 +398,8 @@ int alfred_server(struct globals *globals)
64 return -1;
65 }
66
67 - if (num_socks > 1 && globals->opmode == OPMODE_SECONDARY) {
68 + num_interfaces = netsocket_count_interfaces(globals);
69 + if (num_interfaces > 1 && globals->opmode == OPMODE_SECONDARY) {
70 fprintf(stderr, "More than one interface specified in secondary mode\n");
71 return -1;
72 }