diff mbox series

[iproute2-next,1/2] Add support for the IOAM insertion frequency

Message ID 20220205155208.22531-2-justin.iurman@uliege.be (mailing list archive)
State Accepted
Commit 8908cb25711ebd1c3bf084bc9fb2f4fba3587d9a
Delegated to: David Ahern
Headers show
Series [iproute2-next,1/2] Add support for the IOAM insertion frequency | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Justin Iurman Feb. 5, 2022, 3:52 p.m. UTC
This patch adds support for the IOAM insertion frequency by introducing
a new parameter "freq". The expected value is "k/n", see the patchset
description for more details.

Signed-off-by: Justin Iurman <justin.iurman@uliege.be>
---
 ip/iproute_lwtunnel.c | 69 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 67 insertions(+), 2 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org Feb. 10, 2022, 6:10 p.m. UTC | #1
Hello:

This series was applied to iproute2/iproute2-next.git (main)
by David Ahern <dsahern@kernel.org>:

On Sat,  5 Feb 2022 16:52:07 +0100 you wrote:
> This patch adds support for the IOAM insertion frequency by introducing
> a new parameter "freq". The expected value is "k/n", see the patchset
> description for more details.
> 
> Signed-off-by: Justin Iurman <justin.iurman@uliege.be>
> ---
>  ip/iproute_lwtunnel.c | 69 +++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 67 insertions(+), 2 deletions(-)

Here is the summary with links:
  - [iproute2-next,1/2] Add support for the IOAM insertion frequency
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=8908cb25711e
  - [iproute2-next,2/2] Update documentation
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=ff14875e9d77

You are awesome, thank you!
diff mbox series

Patch

diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
index b05dffc6..f4192229 100644
--- a/ip/iproute_lwtunnel.c
+++ b/ip/iproute_lwtunnel.c
@@ -242,12 +242,20 @@  static void print_encap_ioam6(FILE *fp, struct rtattr *encap)
 {
 	struct rtattr *tb[IOAM6_IPTUNNEL_MAX + 1];
 	struct ioam6_trace_hdr *trace;
+	__u32 freq_k, freq_n;
 	__u8 mode;
 
 	parse_rtattr_nested(tb, IOAM6_IPTUNNEL_MAX, encap);
-	if (!tb[IOAM6_IPTUNNEL_MODE] || !tb[IOAM6_IPTUNNEL_TRACE])
+	if (!tb[IOAM6_IPTUNNEL_MODE] || !tb[IOAM6_IPTUNNEL_TRACE] ||
+	    !tb[IOAM6_IPTUNNEL_FREQ_K] || !tb[IOAM6_IPTUNNEL_FREQ_N])
 		return;
 
+	freq_k = rta_getattr_u32(tb[IOAM6_IPTUNNEL_FREQ_K]);
+	freq_n = rta_getattr_u32(tb[IOAM6_IPTUNNEL_FREQ_N]);
+
+	print_uint(PRINT_ANY, "freqk", "freq %u", freq_k);
+	print_uint(PRINT_ANY, "freqn", "/%u ", freq_n);
+
 	mode = rta_getattr_u8(tb[IOAM6_IPTUNNEL_MODE]);
 	if (!tb[IOAM6_IPTUNNEL_DST] && mode != IOAM6_IPTUNNEL_MODE_INLINE)
 		return;
@@ -919,6 +927,31 @@  out:
 	return ret;
 }
 
+static int parse_ioam6_freq(char *buf, __u32 *freq_k, __u32 *freq_n)
+{
+	char *s;
+	int i;
+
+	s = buf;
+	for (i = 0; *s; *s++ == '/' ? i++ : *s);
+	if (i != 1)
+		return 1;
+
+	s = strtok(buf, "/");
+	if (!s || get_u32(freq_k, s, 10))
+		return 1;
+
+	s = strtok(NULL, "/");
+	if (!s || get_u32(freq_n, s, 10))
+		return 1;
+
+	s = strtok(NULL, "/");
+	if (s)
+		return 1;
+
+	return 0;
+}
+
 static int parse_encap_ioam6(struct rtattr *rta, size_t len, int *argcp,
 			     char ***argvp)
 {
@@ -927,9 +960,39 @@  static int parse_encap_ioam6(struct rtattr *rta, size_t len, int *argcp,
 	struct ioam6_trace_hdr *trace;
 	char **argv = *argvp;
 	__u32 trace_type = 0;
+	__u32 freq_k, freq_n;
+	char buf[16] = {0};
 	inet_prefix addr;
 	__u8 mode;
 
+	if (strcmp(*argv, "freq") != 0) {
+		freq_k = IOAM6_IPTUNNEL_FREQ_MIN;
+		freq_n = IOAM6_IPTUNNEL_FREQ_MIN;
+	} else {
+		NEXT_ARG();
+
+		if (strlen(*argv) > sizeof(buf) - 1)
+			invarg("Invalid frequency (too long)", *argv);
+
+		strncpy(buf, *argv, sizeof(buf));
+
+		if (parse_ioam6_freq(buf, &freq_k, &freq_n))
+			invarg("Invalid frequency (malformed)", *argv);
+
+		if (freq_k < IOAM6_IPTUNNEL_FREQ_MIN ||
+		    freq_k > IOAM6_IPTUNNEL_FREQ_MAX)
+			invarg("Out of bound \"k\" frequency", *argv);
+
+		if (freq_n < IOAM6_IPTUNNEL_FREQ_MIN ||
+		    freq_n > IOAM6_IPTUNNEL_FREQ_MAX)
+			invarg("Out of bound \"n\" frequency", *argv);
+
+		if (freq_k > freq_n)
+			invarg("Frequency with k > n is forbidden", *argv);
+
+		NEXT_ARG();
+	}
+
 	if (strcmp(*argv, "mode") != 0) {
 		mode = IOAM6_IPTUNNEL_MODE_INLINE;
 	} else {
@@ -1020,7 +1083,9 @@  static int parse_encap_ioam6(struct rtattr *rta, size_t len, int *argcp,
 	trace->namespace_id = htons(trace_ns);
 	trace->remlen = (__u8)(trace_size / 4);
 
-	if (rta_addattr8(rta, len, IOAM6_IPTUNNEL_MODE, mode) ||
+	if (rta_addattr32(rta, len, IOAM6_IPTUNNEL_FREQ_K, freq_k) ||
+	    rta_addattr32(rta, len, IOAM6_IPTUNNEL_FREQ_N, freq_n) ||
+	    rta_addattr8(rta, len, IOAM6_IPTUNNEL_MODE, mode) ||
 	    (mode != IOAM6_IPTUNNEL_MODE_INLINE &&
 	     rta_addattr_l(rta, len, IOAM6_IPTUNNEL_DST, &addr.data, addr.bytelen)) ||
 	    rta_addattr_l(rta, len, IOAM6_IPTUNNEL_TRACE, trace, sizeof(*trace))) {