Skip to content

Commit

Permalink
ipv6: ioam: Distinguish input and output for hop-limit
Browse files Browse the repository at this point in the history
This patch anticipates the support for the IOAM insertion inside in-transit
packets, by making a difference between input and output in order to determine
the right value for its hop-limit (inherited from the IPv6 hop-limit).

Input case: happens before ip6_forward, the IPv6 hop-limit is not decremented
yet -> decrement the IOAM hop-limit to reflect the new hop inside the trace.

Output case: happens after ip6_forward, the IPv6 hop-limit has already been
decremented -> keep the same value for the IOAM hop-limit.

Signed-off-by: Justin Iurman <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
IurmanJ authored and davem330 committed Oct 4, 2021
1 parent 9ac9362 commit 52d0378
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion include/net/ioam6.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ static inline struct ioam6_pernet_data *ioam6_pernet(struct net *net)
struct ioam6_namespace *ioam6_namespace(struct net *net, __be16 id);
void ioam6_fill_trace_data(struct sk_buff *skb,
struct ioam6_namespace *ns,
struct ioam6_trace_hdr *trace);
struct ioam6_trace_hdr *trace,
bool is_input);

int ioam6_init(void);
void ioam6_exit(void);
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/exthdrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ static bool ipv6_hop_ioam(struct sk_buff *skb, int optoff)
if (!skb_valid_dst(skb))
ip6_route_input(skb);

ioam6_fill_trace_data(skb, ns, trace);
ioam6_fill_trace_data(skb, ns, trace, true);
break;
default:
break;
Expand Down
11 changes: 6 additions & 5 deletions net/ipv6/ioam6.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ static void __ioam6_fill_trace_data(struct sk_buff *skb,
struct ioam6_namespace *ns,
struct ioam6_trace_hdr *trace,
struct ioam6_schema *sc,
u8 sclen)
u8 sclen, bool is_input)
{
struct __kernel_sock_timeval ts;
u64 raw64;
Expand All @@ -645,7 +645,7 @@ static void __ioam6_fill_trace_data(struct sk_buff *skb,
/* hop_lim and node_id */
if (trace->type.bit0) {
byte = ipv6_hdr(skb)->hop_limit;
if (skb->dev)
if (is_input)
byte--;

raw32 = dev_net(skb_dst(skb)->dev)->ipv6.sysctl.ioam6_id;
Expand Down Expand Up @@ -730,7 +730,7 @@ static void __ioam6_fill_trace_data(struct sk_buff *skb,
/* hop_lim and node_id (wide) */
if (trace->type.bit8) {
byte = ipv6_hdr(skb)->hop_limit;
if (skb->dev)
if (is_input)
byte--;

raw64 = dev_net(skb_dst(skb)->dev)->ipv6.sysctl.ioam6_id_wide;
Expand Down Expand Up @@ -786,7 +786,8 @@ static void __ioam6_fill_trace_data(struct sk_buff *skb,
/* called with rcu_read_lock() */
void ioam6_fill_trace_data(struct sk_buff *skb,
struct ioam6_namespace *ns,
struct ioam6_trace_hdr *trace)
struct ioam6_trace_hdr *trace,
bool is_input)
{
struct ioam6_schema *sc;
u8 sclen = 0;
Expand Down Expand Up @@ -822,7 +823,7 @@ void ioam6_fill_trace_data(struct sk_buff *skb,
return;
}

__ioam6_fill_trace_data(skb, ns, trace, sc, sclen);
__ioam6_fill_trace_data(skb, ns, trace, sc, sclen, is_input);
trace->remlen -= trace->nodelen + sclen;
}

Expand Down

0 comments on commit 52d0378

Please sign in to comment.