All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] batctl: Dynamically select header format in netlink_print_neighbors
@ 2024-09-10  3:27 noahbpeterson1997
  2024-09-10  8:44 ` Sven Eckelmann
  0 siblings, 1 reply; 3+ messages in thread
From: noahbpeterson1997 @ 2024-09-10  3:27 UTC (permalink / raw)
  To: b.a.t.m.a.n

The netlink_print_neighbors() function previously used a static header format, which did not account for variations between the neighbor list output from different BATMAN routing algorithms (BATMAN_IV vs. BATMAN_V).

This patch introduces a dynamic header selection mechanism that adjusts the output format based on the active routing algorithm:
- For BATMAN_IV, the header is set to "IF             Neighbor              last-seen".
- For BATMAN_V, it changes to "         Neighbor   last-seen      speed           IF".

This change ensures that the table header output in `batctl n` is accurate for both BATMAN routing algorithms.
Signed-off-by: Noah Peterson <noahbpeterson1997@gmail.com>
---
 neighbors.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/neighbors.c b/neighbors.c
index 3102b0e..f34952b 100644
--- a/neighbors.c
+++ b/neighbors.c
@@ -6,6 +6,7 @@
  * License-Filename: LICENSES/preferred/GPL-2.0
  */
 
+#include <errno.h>
 #include <net/if.h>
 #include <netinet/if_ether.h>
 #include <netlink/netlink.h>
@@ -119,9 +120,28 @@ static int netlink_print_neighbors(struct state *state, char *orig_iface,
 				   int read_opts, float orig_timeout,
 				   float watch_interval)
 {
+	char *header = NULL;
+	char *info_header;
+
+	/* only parse routing algorithm name */
+	last_err = -EINVAL;
+	info_header = netlink_get_info(state, BATADV_CMD_GET_ORIGINATORS, NULL);
+	free(info_header);
+
+	if (strlen(algo_name_buf) == 0)
+		return last_err;
+
+	if (!strcmp("BATMAN_IV", algo_name_buf))
+		header = "IF             Neighbor              last-seen\n";
+	if (!strcmp("BATMAN_V", algo_name_buf))
+		header = "         Neighbor   last-seen      speed           IF\n";
+
+	if (!header)
+		return -EINVAL;
+
 	return netlink_print_common(state, orig_iface, read_opts,
 				    orig_timeout, watch_interval,
-				    "IF             Neighbor              last-seen\n",
+				    header,
 				    BATADV_CMD_GET_NEIGHBORS,
 				    neighbors_callback);
 }

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] batctl: Dynamically select header format in netlink_print_neighbors
  2024-09-10  3:27 [PATCH v2] batctl: Dynamically select header format in netlink_print_neighbors noahbpeterson1997
@ 2024-09-10  8:44 ` Sven Eckelmann
  2024-09-20 17:19   ` noahbpeterson1997
  0 siblings, 1 reply; 3+ messages in thread
From: Sven Eckelmann @ 2024-09-10  8:44 UTC (permalink / raw)
  To: noahbpeterson1997; +Cc: b.a.t.m.a.n

[-- Attachment #1: Type: text/plain, Size: 2638 bytes --]

On Tuesday, 10 September 2024 05:27:14 CEST noahbpeterson1997@gmail.com wrote:

You must have a proper "From:" in your patch mail - not only your mail 
address. And it should match your Signed-off-by line.

> The netlink_print_neighbors() function previously used a static header format, which did not account for variations between the neighbor list output from different BATMAN routing algorithms (BATMAN_IV vs. BATMAN_V).
> 
> This patch introduces a dynamic header selection mechanism that adjusts the output format based on the active routing algorithm:
> - For BATMAN_IV, the header is set to "IF             Neighbor              last-seen".
> - For BATMAN_V, it changes to "         Neighbor   last-seen      speed           IF".

Please don't use overlong lines in the commit message. We normally use the 75 
chars per line limit from Linux's checkpatch.

> 
> This change ensures that the table header output in `batctl n` is accurate for both BATMAN routing algorithms.
> Signed-off-by: Noah Peterson <noahbpeterson1997@gmail.com>

Newline missing between your commit message and the Sob line.

> ---

Changelog for v2 is missing. You can use tools like b4 [1] to improve your 
patch workflow.

>  neighbors.c | 22 +++++++++++++++++++++-
>  1 file changed, 21 insertions(+), 1 deletion(-)
> diff --git a/neighbors.c b/neighbors.c
> index 3102b0e..f34952b 100644
> --- a/neighbors.c
> +++ b/neighbors.c
> @@ -6,6 +6,7 @@
>   * License-Filename: LICENSES/preferred/GPL-2.0
>   */
>  
> +#include <errno.h>
>  #include <net/if.h>
>  #include <netinet/if_ether.h>
>  #include <netlink/netlink.h>
> @@ -119,9 +120,28 @@ static int netlink_print_neighbors(struct state *state, char *orig_iface,
>  				   int read_opts, float orig_timeout,
>  				   float watch_interval)
>  {
> +	char *header = NULL;
> +	char *info_header;
> +
> +	/* only parse routing algorithm name */
> +	last_err = -EINVAL;
> +	info_header = netlink_get_info(state, BATADV_CMD_GET_ORIGINATORS, NULL);
> +	free(info_header);
> +
> +	if (strlen(algo_name_buf) == 0)
> +		return last_err;
> +
> +	if (!strcmp("BATMAN_IV", algo_name_buf))
> +		header = "IF             Neighbor              last-seen\n";
> +	if (!strcmp("BATMAN_V", algo_name_buf))
> +		header = "         Neighbor   last-seen      speed           IF\n";
> +
> +	if (!header)
> +		return -EINVAL;
> +
>  	return netlink_print_common(state, orig_iface, read_opts,
>  				    orig_timeout, watch_interval,
> -				    "IF             Neighbor              last-seen\n",
> +				    header,
>  				    BATADV_CMD_GET_NEIGHBORS,
>  				    neighbors_callback);
>  }
> 

[1] https://b4.docs.kernel.org/


[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] batctl: Dynamically select header format in netlink_print_neighbors
  2024-09-10  8:44 ` Sven Eckelmann
@ 2024-09-20 17:19   ` noahbpeterson1997
  0 siblings, 0 replies; 3+ messages in thread
From: noahbpeterson1997 @ 2024-09-20 17:19 UTC (permalink / raw)
  To: b.a.t.m.a.n

Hello!

I have submitted a v3 of this patch, I believe this time with all of the necessary parts, testing with the proper diff and patching tools, and submitting using git send-email. Let me know if this one is up to the expected standard.

These are my very first kernel patches. I thank you for your patience and handholding :)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-09-20 17:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-10  3:27 [PATCH v2] batctl: Dynamically select header format in netlink_print_neighbors noahbpeterson1997
2024-09-10  8:44 ` Sven Eckelmann
2024-09-20 17:19   ` noahbpeterson1997

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.