Skip to contentSkip to conversation

alfred: introduce 'server status' IPC call

PATCH In review Marek Lindner 2 participants 4 messages Feb 20, 2022 – Feb 21, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 alfred: introduce 'server status' IPC call

The 'server status' call exports the 'mode' as well as interface status via IPC. Both parameters can be modified at runtime via the IPC and as such, the current configuration is dynamic and not necessarily obvious.

The server status 'request' and 'reply' packet types are added to allow the IPC client to initiate the status retrieval. The server will respond with the 'reply' message.

The information is encapsulated in TLV data chunks allowing for future backward compatible extension of the server status call.

---
v4:
- buffer safety checks in server code
- move tlv type definitions into packet header
- version checks for sub tlv
v3:
- close client socket at the end of unix_sock_server_status()

 alfred.h     |   5 +++
 client.c     | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++
 main.c       |   9 +++-
 man/alfred.8 |   3 ++
 packet.h     |  68 +++++++++++++++++++++++++++++
 unix_sock.c  | 106 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 310 insertions(+), 1 deletion(-)
alfred.h +5 -0
index 9ab92a2..598d38b 100644
@@ -33,6 +33,9 @@
 #define FIXED_TLV_LEN(__tlv_type) \
 	htons(sizeof(__tlv_type) - sizeof(__tlv_type.header))
 
+#define FIXED_TLV_LEN_PTR(__tlv_type) \
+	htons(sizeof(*__tlv_type) - sizeof(__tlv_type->header))
+
 enum data_source {
 	SOURCE_LOCAL = 0,
 	SOURCE_FIRST_HAND = 1,
@@ -93,6 +96,7 @@ enum clientmode {
 	CLIENT_MODESWITCH,
 	CLIENT_CHANGE_INTERFACE,
 	CLIENT_CHANGE_BAT_IFACE,
+	CLIENT_SERVER_STATUS,
 };
 
 struct interface {
@@ -155,6 +159,7 @@ int alfred_client_set_data(struct globals *globals);
 int alfred_client_modeswitch(struct globals *globals);
 int alfred_client_change_interface(struct globals *globals);
 int alfred_client_change_bat_iface(struct globals *globals);
+int alfred_client_server_status(struct globals *globals);
 /* recv.c */
 int recv_alfred_packet(struct globals *globals, struct interface *interface,
 		       int recv_sock);
client.c +120 -0

123 lines not on this page · raw message

main.c +8 -1
index d40a0cc..68d6efd 100644
@@ -38,6 +38,7 @@ static void alfred_usage(void)
 	printf("                   secondary          switch daemon to mode secondary\n");
 	printf("  -I, --change-interface [interface]  change to the specified interface(s)\n");
 	printf("  -B, --change-bat-iface [interface]  change to the specified batman-adv interface\n");
+	printf("  -S, --server-status                 request server status info such as mode & interfaces\n");
 	printf("\n");
 	printf("server mode options:\n");
 	printf("  -i, --interface                     specify the interface (or comma separated list of interfaces) to listen on\n");
@@ -162,6 +163,7 @@ static struct globals *alfred_init(int argc, char *argv[])
 		{"modeswitch",		required_argument,	NULL,	'M'},
 		{"change-interface",	required_argument,	NULL,	'I'},
 		{"change-bat-iface",	required_argument,	NULL,	'B'},
+		{"server-status",	required_argument,	NULL,	'S'},
 		{"unix-path",		required_argument,	NULL,	'u'},
 		{"update-command",	required_argument,	NULL,	'c'},
 		{"version",		no_argument,		NULL,	'v'},
@@ -196,7 +198,7 @@ static struct globals *alfred_init(int argc, char *argv[])
 
 	time_random_seed();
 
-	while ((opt = getopt_long(argc, argv, "ms:r:hi:b:vV:M:I:B:u:dc:p:4:f", long_options,
+	while ((opt = getopt_long(argc, argv, "ms:r:hi:b:vV:M:I:B:Su:dc:p:4:f", long_options,
 				  &opt_ind)) != -1) {
 		switch (opt) {
 		case 'r':
@@ -258,6 +260,9 @@ static struct globals *alfred_init(int argc, char *argv[])
 			globals->clientmode = CLIENT_CHANGE_BAT_IFACE;
 			globals->mesh_iface = strdup(optarg);
 			break;
+		case 'S':
+			globals->clientmode = CLIENT_SERVER_STATUS;
+			break;
 		case 'u':
 			globals->unix_path = optarg;
 			break;
@@ -321,6 +326,8 @@ int main(int argc, char *argv[])
 		return alfred_client_change_interface(globals);
 	case CLIENT_CHANGE_BAT_IFACE:
 		return alfred_client_change_bat_iface(globals);
+	case CLIENT_SERVER_STATUS:
+		return alfred_client_server_status(globals);
 	}
 
 	return 0;
man/alfred.8 +3 -0
index 74814e0..cf0eafc 100644
@@ -94,6 +94,9 @@ Change the alfred server to use the new \fBinterface\fP(s)
 .TP
 \fB\-B\fP, \fB\-\-change\-bat\-iface\fP \fIinterface\fP
 Change the alfred server to use the new \fBbatman-adv interface\fP
+.TP
+\fB\-S\fP, \fB\-\-server\-status\fP
+Request server status information such as mode & interfaces\fP
 .
 .SH SERVER OPTIONS
 .TP
packet.h +68 -0

80 lines not on this page · raw message

unix_sock.c +106 -0

118 lines not on this page · raw message

Signature · 1 line
2.32.0.rc0
#1 lore raw

alfred.h line 38

Quoted 11 lines · On Sunday, 20 February 2022 19:36:14 CET Marek Lindner wrote:
alfred.h +3 -0
index 9ab92a2..598d38b 100644
@@ -33,6 +33,9 @@
 #define FIXED_TLV_LEN(__tlv_type) \
        htons(sizeof(__tlv_type) - sizeof(__tlv_type.header))
 
+#define FIXED_TLV_LEN_PTR(__tlv_type) \
+       htons(sizeof(*__tlv_type) - sizeof(__tlv_type->header))
+

This doesn't apply on master. And also doesn't make a lot of sense, because you can now just use FIXED_TLV_LEN(*whatever). So I have dropped this part and applied the rest.

Btw. good that you've spotted some prints to stderr which should actually be to stdout. You only missed it for "mode: unknown". I have also fixed this.

Kind regards,
Sven

#2 lore raw
Quoted 9 lines · On Monday, 21 February 2022 10:14:18 CET Sven Eckelmann wrote:
Quoted 8 lines · On Sunday, 20 February 2022 19:36:14 CET Marek Lindner wrote:
alfred.h +0 -0
index 9ab92a2..598d38b 100644
@@ -33,6 +33,9 @@
 #define FIXED_TLV_LEN(__tlv_type) \
 htons(sizeof(__tlv_type) - sizeof(__tlv_type.header))
 
Quoted 7 lines

alfred.h line 38

Quoted 3 lines
alfred.h +3 -0
+#define FIXED_TLV_LEN_PTR(__tlv_type) \
+       htons(sizeof(*__tlv_type) - sizeof(__tlv_type->header))
+

This doesn't apply on master. And also doesn't make a lot of sense, because you can now just use FIXED_TLV_LEN(*whatever). So I have dropped this part and applied the rest.

Your proposal did no compile and the master branch now also does not compile on ipq40xx:

unix_sock.c: In function 'unix_sock_server_status':
alfred.h:34:46: error: 'status_op_mode' is a pointer; did you mean to use '->'?
htons(sizeof(__tlv_type) - sizeof(__tlv_type.header))

Quoted 2 lines

Btw. good that you've spotted some prints to stderr which should actually be to stdout. You only missed it for "mode: unknown".

The alfred server running not in primary and not in secondary mode was stderr worthy for me. But I also don't feel strongly about this.

Cheers,
Marek

#3 lore raw
Quoted 6 lines · On Tuesday, 22 February 2022 00:19:43 CET Marek Lindner wrote:

Your proposal did no compile and the master branch now also does not compile on ipq40xx:

unix_sock.c: In function 'unix_sock_server_status':
alfred.h:34:46: error: 'status_op_mode' is a pointer; did you mean to use '->'?
htons(sizeof(__tlv_type) - sizeof(__tlv_type.header))

Are you sure you are using the master branch? Because the macro looks quite
different to what you are showing here. See
https://git.open-mesh.org/alfred.git/blob/5a7d28b1866d1ba13f570551cea177187f9e54ff:/alfred.h#l33
and the commit
https://git.open-mesh.org/alfred.git/commit/f9cf9d22c8bdc8c675c5080d9a26a21082aa1d77 which changed the macro.

Kind regards,
Sven