netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2 0/2] Support for the IOAM insertion frequency
@ 2022-02-02 14:25 Justin Iurman
  2022-02-02 14:25 ` [PATCH net-next v2 1/2] uapi: ioam: Insertion frequency Justin Iurman
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Justin Iurman @ 2022-02-02 14:25 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, yoshfuji, dsahern, justin.iurman

v2:
 - signed -> unsigned (for "k" and "n")
 - keep binary compatibility by moving "k" and "n" at the end of uapi

The insertion frequency is represented as "k/n", meaning IOAM will be
added to {k} packets over {n} packets, with 0 < k <= n and 1 <= {k,n} <=
1000000. Therefore, it provides the following percentages of insertion
frequency: [0.0001% (min) ... 100% (max)].

Not only this solution allows an operator to apply dynamic frequencies
based on the current traffic load, but it also provides some
flexibility, i.e., by distinguishing similar cases (e.g., "1/2" and
"2/4").

"1/2" = Y N Y N Y N Y N ...
"2/4" = Y Y N N Y Y N N ...

Justin Iurman (2):
  uapi: ioam: Insertion frequency
  ipv6: ioam: Insertion frequency in lwtunnel output

 include/uapi/linux/ioam6_iptunnel.h |  9 +++++
 net/ipv6/ioam6_iptunnel.c           | 59 ++++++++++++++++++++++++++++-
 2 files changed, 66 insertions(+), 2 deletions(-)

-- 
2.25.1


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

* [PATCH net-next v2 1/2] uapi: ioam: Insertion frequency
  2022-02-02 14:25 [PATCH net-next v2 0/2] Support for the IOAM insertion frequency Justin Iurman
@ 2022-02-02 14:25 ` Justin Iurman
  2022-02-02 14:25 ` [PATCH net-next v2 2/2] ipv6: ioam: Insertion frequency in lwtunnel output Justin Iurman
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Justin Iurman @ 2022-02-02 14:25 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, yoshfuji, dsahern, justin.iurman

Add the insertion frequency uapi for IOAM lwtunnels.

Signed-off-by: Justin Iurman <justin.iurman@uliege.be>
---
 include/uapi/linux/ioam6_iptunnel.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/uapi/linux/ioam6_iptunnel.h b/include/uapi/linux/ioam6_iptunnel.h
index 829ffdfcacca..38f6a8fdfd34 100644
--- a/include/uapi/linux/ioam6_iptunnel.h
+++ b/include/uapi/linux/ioam6_iptunnel.h
@@ -41,6 +41,15 @@ enum {
 	/* IOAM Trace Header */
 	IOAM6_IPTUNNEL_TRACE,		/* struct ioam6_trace_hdr */
 
+	/* Insertion frequency:
+	 * "k over n" packets (0 < k <= n)
+	 * [0.0001% ... 100%]
+	 */
+#define IOAM6_IPTUNNEL_FREQ_MIN 1
+#define IOAM6_IPTUNNEL_FREQ_MAX 1000000
+	IOAM6_IPTUNNEL_FREQ_K,		/* u32 */
+	IOAM6_IPTUNNEL_FREQ_N,		/* u32 */
+
 	__IOAM6_IPTUNNEL_MAX,
 };
 
-- 
2.25.1


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

* [PATCH net-next v2 2/2] ipv6: ioam: Insertion frequency in lwtunnel output
  2022-02-02 14:25 [PATCH net-next v2 0/2] Support for the IOAM insertion frequency Justin Iurman
  2022-02-02 14:25 ` [PATCH net-next v2 1/2] uapi: ioam: Insertion frequency Justin Iurman
@ 2022-02-02 14:25 ` Justin Iurman
  2022-02-03  3:47 ` [PATCH net-next v2 0/2] Support for the IOAM insertion frequency David Ahern
  2022-02-05  6:10 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: Justin Iurman @ 2022-02-02 14:25 UTC (permalink / raw)
  To: netdev; +Cc: davem, kuba, yoshfuji, dsahern, justin.iurman

Add support for the IOAM insertion frequency inside its lwtunnel output
function. This patch introduces a new (atomic) counter for packets,
based on which the algorithm will decide if IOAM should be added or not.

Default frequency is "1/1" (i.e., applied to all packets) for backward
compatibility. The iproute2 patch is ready and will be submitted as soon
as this one is accepted.

Previous iproute2 command:
ip -6 ro ad fc00::1/128 encap ioam6 [ mode ... ] ...

New iproute2 command:
ip -6 ro ad fc00::1/128 encap ioam6 [ freq k/n ] [ mode ... ] ...

Signed-off-by: Justin Iurman <justin.iurman@uliege.be>
---
 net/ipv6/ioam6_iptunnel.c | 59 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 2 deletions(-)

diff --git a/net/ipv6/ioam6_iptunnel.c b/net/ipv6/ioam6_iptunnel.c
index f90a87389fcc..f6f5b83dd954 100644
--- a/net/ipv6/ioam6_iptunnel.c
+++ b/net/ipv6/ioam6_iptunnel.c
@@ -32,13 +32,25 @@ struct ioam6_lwt_encap {
 	struct ioam6_trace_hdr traceh;
 } __packed;
 
+struct ioam6_lwt_freq {
+	u32 k;
+	u32 n;
+};
+
 struct ioam6_lwt {
 	struct dst_cache cache;
+	struct ioam6_lwt_freq freq;
+	atomic_t pkt_cnt;
 	u8 mode;
 	struct in6_addr tundst;
 	struct ioam6_lwt_encap	tuninfo;
 };
 
+static struct netlink_range_validation freq_range = {
+	.min = IOAM6_IPTUNNEL_FREQ_MIN,
+	.max = IOAM6_IPTUNNEL_FREQ_MAX,
+};
+
 static struct ioam6_lwt *ioam6_lwt_state(struct lwtunnel_state *lwt)
 {
 	return (struct ioam6_lwt *)lwt->data;
@@ -55,6 +67,8 @@ static struct ioam6_trace_hdr *ioam6_lwt_trace(struct lwtunnel_state *lwt)
 }
 
 static const struct nla_policy ioam6_iptunnel_policy[IOAM6_IPTUNNEL_MAX + 1] = {
+	[IOAM6_IPTUNNEL_FREQ_K] = NLA_POLICY_FULL_RANGE(NLA_U32, &freq_range),
+	[IOAM6_IPTUNNEL_FREQ_N] = NLA_POLICY_FULL_RANGE(NLA_U32, &freq_range),
 	[IOAM6_IPTUNNEL_MODE]	= NLA_POLICY_RANGE(NLA_U8,
 						   IOAM6_IPTUNNEL_MODE_MIN,
 						   IOAM6_IPTUNNEL_MODE_MAX),
@@ -96,6 +110,7 @@ static int ioam6_build_state(struct net *net, struct nlattr *nla,
 	struct lwtunnel_state *lwt;
 	struct ioam6_lwt *ilwt;
 	int len_aligned, err;
+	u32 freq_k, freq_n;
 	u8 mode;
 
 	if (family != AF_INET6)
@@ -106,6 +121,23 @@ static int ioam6_build_state(struct net *net, struct nlattr *nla,
 	if (err < 0)
 		return err;
 
+	if ((!tb[IOAM6_IPTUNNEL_FREQ_K] && tb[IOAM6_IPTUNNEL_FREQ_N]) ||
+	    (tb[IOAM6_IPTUNNEL_FREQ_K] && !tb[IOAM6_IPTUNNEL_FREQ_N])) {
+		NL_SET_ERR_MSG(extack, "freq: missing parameter");
+		return -EINVAL;
+	} else if (!tb[IOAM6_IPTUNNEL_FREQ_K] && !tb[IOAM6_IPTUNNEL_FREQ_N]) {
+		freq_k = IOAM6_IPTUNNEL_FREQ_MIN;
+		freq_n = IOAM6_IPTUNNEL_FREQ_MIN;
+	} else {
+		freq_k = nla_get_u32(tb[IOAM6_IPTUNNEL_FREQ_K]);
+		freq_n = nla_get_u32(tb[IOAM6_IPTUNNEL_FREQ_N]);
+
+		if (freq_k > freq_n) {
+			NL_SET_ERR_MSG(extack, "freq: k > n is forbidden");
+			return -EINVAL;
+		}
+	}
+
 	if (!tb[IOAM6_IPTUNNEL_MODE])
 		mode = IOAM6_IPTUNNEL_MODE_INLINE;
 	else
@@ -140,6 +172,10 @@ static int ioam6_build_state(struct net *net, struct nlattr *nla,
 		return err;
 	}
 
+	atomic_set(&ilwt->pkt_cnt, 0);
+	ilwt->freq.k = freq_k;
+	ilwt->freq.n = freq_n;
+
 	ilwt->mode = mode;
 	if (tb[IOAM6_IPTUNNEL_DST])
 		ilwt->tundst = nla_get_in6_addr(tb[IOAM6_IPTUNNEL_DST]);
@@ -263,11 +299,18 @@ static int ioam6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
 	struct in6_addr orig_daddr;
 	struct ioam6_lwt *ilwt;
 	int err = -EINVAL;
+	u32 pkt_cnt;
 
 	if (skb->protocol != htons(ETH_P_IPV6))
 		goto drop;
 
 	ilwt = ioam6_lwt_state(dst->lwtstate);
+
+	/* Check for insertion frequency (i.e., "k over n" insertions) */
+	pkt_cnt = atomic_fetch_inc(&ilwt->pkt_cnt);
+	if (pkt_cnt % ilwt->freq.n >= ilwt->freq.k)
+		goto out;
+
 	orig_daddr = ipv6_hdr(skb)->daddr;
 
 	switch (ilwt->mode) {
@@ -358,6 +401,14 @@ static int ioam6_fill_encap_info(struct sk_buff *skb,
 	struct ioam6_lwt *ilwt = ioam6_lwt_state(lwtstate);
 	int err;
 
+	err = nla_put_u32(skb, IOAM6_IPTUNNEL_FREQ_K, ilwt->freq.k);
+	if (err)
+		goto ret;
+
+	err = nla_put_u32(skb, IOAM6_IPTUNNEL_FREQ_N, ilwt->freq.n);
+	if (err)
+		goto ret;
+
 	err = nla_put_u8(skb, IOAM6_IPTUNNEL_MODE, ilwt->mode);
 	if (err)
 		goto ret;
@@ -379,7 +430,9 @@ static int ioam6_encap_nlsize(struct lwtunnel_state *lwtstate)
 	struct ioam6_lwt *ilwt = ioam6_lwt_state(lwtstate);
 	int nlsize;
 
-	nlsize = nla_total_size(sizeof(ilwt->mode)) +
+	nlsize = nla_total_size(sizeof(ilwt->freq.k)) +
+		  nla_total_size(sizeof(ilwt->freq.n)) +
+		  nla_total_size(sizeof(ilwt->mode)) +
 		  nla_total_size(sizeof(ilwt->tuninfo.traceh));
 
 	if (ilwt->mode != IOAM6_IPTUNNEL_MODE_INLINE)
@@ -395,7 +448,9 @@ static int ioam6_encap_cmp(struct lwtunnel_state *a, struct lwtunnel_state *b)
 	struct ioam6_lwt *ilwt_a = ioam6_lwt_state(a);
 	struct ioam6_lwt *ilwt_b = ioam6_lwt_state(b);
 
-	return (ilwt_a->mode != ilwt_b->mode ||
+	return (ilwt_a->freq.k != ilwt_b->freq.k ||
+		ilwt_a->freq.n != ilwt_b->freq.n ||
+		ilwt_a->mode != ilwt_b->mode ||
 		(ilwt_a->mode != IOAM6_IPTUNNEL_MODE_INLINE &&
 		 !ipv6_addr_equal(&ilwt_a->tundst, &ilwt_b->tundst)) ||
 		trace_a->namespace_id != trace_b->namespace_id);
-- 
2.25.1


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

* Re: [PATCH net-next v2 0/2] Support for the IOAM insertion frequency
  2022-02-02 14:25 [PATCH net-next v2 0/2] Support for the IOAM insertion frequency Justin Iurman
  2022-02-02 14:25 ` [PATCH net-next v2 1/2] uapi: ioam: Insertion frequency Justin Iurman
  2022-02-02 14:25 ` [PATCH net-next v2 2/2] ipv6: ioam: Insertion frequency in lwtunnel output Justin Iurman
@ 2022-02-03  3:47 ` David Ahern
  2022-02-03 10:01   ` Justin Iurman
  2022-02-05  6:10 ` patchwork-bot+netdevbpf
  3 siblings, 1 reply; 6+ messages in thread
From: David Ahern @ 2022-02-03  3:47 UTC (permalink / raw)
  To: Justin Iurman, netdev; +Cc: davem, kuba, yoshfuji, dsahern

On 2/2/22 7:25 AM, Justin Iurman wrote:
> v2:
>  - signed -> unsigned (for "k" and "n")
>  - keep binary compatibility by moving "k" and "n" at the end of uapi
> 
> The insertion frequency is represented as "k/n", meaning IOAM will be
> added to {k} packets over {n} packets, with 0 < k <= n and 1 <= {k,n} <=
> 1000000. Therefore, it provides the following percentages of insertion
> frequency: [0.0001% (min) ... 100% (max)].
> 
> Not only this solution allows an operator to apply dynamic frequencies
> based on the current traffic load, but it also provides some
> flexibility, i.e., by distinguishing similar cases (e.g., "1/2" and
> "2/4").
> 
> "1/2" = Y N Y N Y N Y N ...
> "2/4" = Y Y N N Y Y N N ...
> 

what's the thought process behind this kind of sampling? K consecutive
packets in a row with the trace; N-K consecutive packets without it.

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

* Re: [PATCH net-next v2 0/2] Support for the IOAM insertion frequency
  2022-02-03  3:47 ` [PATCH net-next v2 0/2] Support for the IOAM insertion frequency David Ahern
@ 2022-02-03 10:01   ` Justin Iurman
  0 siblings, 0 replies; 6+ messages in thread
From: Justin Iurman @ 2022-02-03 10:01 UTC (permalink / raw)
  To: David Ahern; +Cc: netdev, davem, kuba, yoshfuji, dsahern

On Feb 3, 2022, at 4:47 AM, David Ahern dsahern@gmail.com wrote:
>> v2:
>>  - signed -> unsigned (for "k" and "n")
>>  - keep binary compatibility by moving "k" and "n" at the end of uapi
>> 
>> The insertion frequency is represented as "k/n", meaning IOAM will be
>> added to {k} packets over {n} packets, with 0 < k <= n and 1 <= {k,n} <=
>> 1000000. Therefore, it provides the following percentages of insertion
>> frequency: [0.0001% (min) ... 100% (max)].
>> 
>> Not only this solution allows an operator to apply dynamic frequencies
>> based on the current traffic load, but it also provides some
>> flexibility, i.e., by distinguishing similar cases (e.g., "1/2" and
>> "2/4").
>> 
>> "1/2" = Y N Y N Y N Y N ...
>> "2/4" = Y Y N N Y Y N N ...
>> 
> 
> what's the thought process behind this kind of sampling? K consecutive
> packets in a row with the trace; N-K consecutive packets without it.

Flexibility. Long story short, it was initially designed with a fixed
"k" (i.e., k=1) so that operators could set the IOAM insertion frequency
to "1/n" (i.e., inject IOAM every n packets). Available frequencies were
100% ("1/1"), 50% ("1/2"), 33% ("1/3"), 25% ("1/4"), etc. By introducing
a non-fixed "k", we wanted to provide flexibility and accuracy to
operators, because you never know... They could require to inject IOAM
in 75% of their traffic, or want to differentiate "1/2" and "2/4", or
whatever). So you can see it as an improved feature of the "1/n" base
frequency. Whether it'll be useful or not, well, I don't know. Again, it
all depends on operators' needs.

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

* Re: [PATCH net-next v2 0/2] Support for the IOAM insertion frequency
  2022-02-02 14:25 [PATCH net-next v2 0/2] Support for the IOAM insertion frequency Justin Iurman
                   ` (2 preceding siblings ...)
  2022-02-03  3:47 ` [PATCH net-next v2 0/2] Support for the IOAM insertion frequency David Ahern
@ 2022-02-05  6:10 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-05  6:10 UTC (permalink / raw)
  To: Justin Iurman; +Cc: netdev, davem, kuba, yoshfuji, dsahern

Hello:

This series was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  2 Feb 2022 15:25:52 +0100 you wrote:
> v2:
>  - signed -> unsigned (for "k" and "n")
>  - keep binary compatibility by moving "k" and "n" at the end of uapi
> 
> The insertion frequency is represented as "k/n", meaning IOAM will be
> added to {k} packets over {n} packets, with 0 < k <= n and 1 <= {k,n} <=
> 1000000. Therefore, it provides the following percentages of insertion
> frequency: [0.0001% (min) ... 100% (max)].
> 
> [...]

Here is the summary with links:
  - [net-next,v2,1/2] uapi: ioam: Insertion frequency
    https://git.kernel.org/netdev/net-next/c/be847673cfff
  - [net-next,v2,2/2] ipv6: ioam: Insertion frequency in lwtunnel output
    https://git.kernel.org/netdev/net-next/c/08731d30e78e

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-02-05  6:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-02 14:25 [PATCH net-next v2 0/2] Support for the IOAM insertion frequency Justin Iurman
2022-02-02 14:25 ` [PATCH net-next v2 1/2] uapi: ioam: Insertion frequency Justin Iurman
2022-02-02 14:25 ` [PATCH net-next v2 2/2] ipv6: ioam: Insertion frequency in lwtunnel output Justin Iurman
2022-02-03  3:47 ` [PATCH net-next v2 0/2] Support for the IOAM insertion frequency David Ahern
2022-02-03 10:01   ` Justin Iurman
2022-02-05  6:10 ` patchwork-bot+netdevbpf

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).