For IP tunnels, resolve the MTU and the dst cookie against the tunnel's inner IP protocol (tun.encap_proto) instead of the flow's l3proto, so the correct header size and route cookie are used when the flow is carried over a tunnel. This is a preliminary patch to support IPv4 over IPv6 and SIT tunnel flowtable offload. Signed-off-by: Lorenzo Bianconi --- net/netfilter/nf_flow_table_core.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c index 0d72dc8ae47a..aa8e3f42b23f 100644 --- a/net/netfilter/nf_flow_table_core.c +++ b/net/netfilter/nf_flow_table_core.c @@ -76,9 +76,10 @@ struct flow_offload *flow_offload_alloc(struct nf_conn *ct) } EXPORT_SYMBOL_GPL(flow_offload_alloc); -static u32 flow_offload_dst_cookie(struct flow_offload_tuple *flow_tuple) +static u32 flow_offload_dst_cookie(struct flow_offload_tuple *flow_tuple, + u8 l3_proto) { - if (flow_tuple->l3proto == NFPROTO_IPV6) + if (l3_proto == NFPROTO_IPV6) return rt6_get_cookie(dst_rt6_info(flow_tuple->dst_cache)); return 0; @@ -100,9 +101,15 @@ static int flow_offload_fill_route(struct flow_offload *flow, { struct flow_offload_tuple *flow_tuple = &flow->tuplehash[dir].tuple; struct dst_entry *dst = nft_route_dst_fetch(route, dir); + u8 l3_proto = flow_tuple->l3proto; int i, j = 0; - switch (flow_tuple->l3proto) { + if (route->tuple[!dir].in.tun.encap_proto) { + /* For IP tunnels we need to consider tunnel IP protocol. */ + l3_proto = route->tuple[!dir].in.tun.encap_proto; + } + + switch (l3_proto) { case NFPROTO_IPV4: flow_tuple->mtu = ip_dst_mtu_maybe_forward(dst, true); break; @@ -130,7 +137,7 @@ static int flow_offload_fill_route(struct flow_offload *flow, if (route->tuple[!dir].in.num_tuns) { flow_tuple->dst_cache = dst; flow_tuple->dst_cookie = - flow_offload_dst_cookie(flow_tuple); + flow_offload_dst_cookie(flow_tuple, l3_proto); } else { dst_release(dst); } @@ -144,7 +151,8 @@ static int flow_offload_fill_route(struct flow_offload *flow, case FLOW_OFFLOAD_XMIT_NEIGH: flow_tuple->ifidx = route->tuple[dir].out.ifindex; flow_tuple->dst_cache = dst; - flow_tuple->dst_cookie = flow_offload_dst_cookie(flow_tuple); + flow_tuple->dst_cookie = flow_offload_dst_cookie(flow_tuple, + l3_proto); break; default: WARN_ON_ONCE(1); -- 2.56.0