Skip to content

Commit b846972

Browse files
ebirgerklassert
authored andcommitted
xfrm: respect ip protocols rules criteria when performing dst lookups
The series in the "fixes" tag added the ability to consider L4 attributes in routing rules. The dst lookup on the outer packet of encapsulated traffic in the xfrm code was not adapted to this change, thus routing behavior that relies on L4 information is not respected. Pass the ip protocol information when performing dst lookups. Fixes: a25724b ("Merge branch 'fib_rules-support-sport-dport-and-proto-match'") Signed-off-by: Eyal Birger <[email protected]> Tested-by: Antony Antony <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent e509996 commit b846972

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

include/net/xfrm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,8 @@ struct xfrm_dst_lookup_params {
356356
xfrm_address_t *saddr;
357357
xfrm_address_t *daddr;
358358
u32 mark;
359+
__u8 ipproto;
360+
union flowi_uli uli;
359361
};
360362

361363
struct net_device;

net/ipv4/xfrm4_policy.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ static struct dst_entry *__xfrm4_dst_lookup(struct flowi4 *fl4,
3030
fl4->flowi4_mark = params->mark;
3131
if (params->saddr)
3232
fl4->saddr = params->saddr->a4;
33+
fl4->flowi4_proto = params->ipproto;
34+
fl4->uli = params->uli;
3335

3436
rt = __ip_route_output_key(params->net, fl4);
3537
if (!IS_ERR(rt))

net/ipv6/xfrm6_policy.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ static struct dst_entry *xfrm6_dst_lookup(const struct xfrm_dst_lookup_params *p
3737
if (params->saddr)
3838
memcpy(&fl6.saddr, params->saddr, sizeof(fl6.saddr));
3939

40+
fl6.flowi4_proto = params->ipproto;
41+
fl6.uli = params->uli;
42+
4043
dst = ip6_route_output(params->net, NULL, &fl6);
4144

4245
err = dst->error;

net/xfrm/xfrm_policy.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,21 @@ static inline struct dst_entry *xfrm_dst_lookup(struct xfrm_state *x,
315315
params.tos = tos;
316316
params.oif = oif;
317317
params.mark = mark;
318+
params.ipproto = x->id.proto;
319+
if (x->encap) {
320+
switch (x->encap->encap_type) {
321+
case UDP_ENCAP_ESPINUDP:
322+
params.ipproto = IPPROTO_UDP;
323+
params.uli.ports.sport = x->encap->encap_sport;
324+
params.uli.ports.dport = x->encap->encap_dport;
325+
break;
326+
case TCP_ENCAP_ESPINTCP:
327+
params.ipproto = IPPROTO_TCP;
328+
params.uli.ports.sport = x->encap->encap_sport;
329+
params.uli.ports.dport = x->encap->encap_dport;
330+
break;
331+
}
332+
}
318333

319334
dst = __xfrm_dst_lookup(family, &params);
320335

0 commit comments

Comments
 (0)