Skip to content

Commit adfc2fd

Browse files
Florian Westphalklassert
authored andcommitted
xfrm: replay: avoid replay indirection
Add and use xfrm_replay_check helper instead of indirection. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent 25cfb8b commit adfc2fd

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

include/net/xfrm.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,6 @@ struct km_event {
306306
};
307307

308308
struct xfrm_replay {
309-
int (*check)(struct xfrm_state *x,
310-
struct sk_buff *skb,
311-
__be32 net_seq);
312309
int (*overflow)(struct xfrm_state *x, struct sk_buff *skb);
313310
};
314311

@@ -1719,6 +1716,7 @@ static inline int xfrm_policy_id2dir(u32 index)
17191716

17201717
#ifdef CONFIG_XFRM
17211718
void xfrm_replay_advance(struct xfrm_state *x, __be32 net_seq);
1719+
int xfrm_replay_check(struct xfrm_state *x, struct sk_buff *skb, __be32 net_seq);
17221720
void xfrm_replay_notify(struct xfrm_state *x, int event);
17231721
int xfrm_replay_recheck(struct xfrm_state *x, struct sk_buff *skb, __be32 net_seq);
17241722

net/xfrm/xfrm_input.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)
612612
goto drop_unlock;
613613
}
614614

615-
if (x->repl->check(x, skb, seq)) {
615+
if (xfrm_replay_check(x, skb, seq)) {
616616
XFRM_INC_STATS(net, LINUX_MIB_XFRMINSTATESEQERROR);
617617
goto drop_unlock;
618618
}

net/xfrm/xfrm_replay.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ static int xfrm_replay_overflow(struct xfrm_state *x, struct sk_buff *skb)
118118
return err;
119119
}
120120

121-
static int xfrm_replay_check(struct xfrm_state *x,
122-
struct sk_buff *skb, __be32 net_seq)
121+
static int xfrm_replay_check_legacy(struct xfrm_state *x,
122+
struct sk_buff *skb, __be32 net_seq)
123123
{
124124
u32 diff;
125125
u32 seq = ntohl(net_seq);
@@ -507,6 +507,21 @@ static int xfrm_replay_check_esn(struct xfrm_state *x,
507507
return -EINVAL;
508508
}
509509

510+
int xfrm_replay_check(struct xfrm_state *x,
511+
struct sk_buff *skb, __be32 net_seq)
512+
{
513+
switch (x->repl_mode) {
514+
case XFRM_REPLAY_MODE_LEGACY:
515+
break;
516+
case XFRM_REPLAY_MODE_BMP:
517+
return xfrm_replay_check_bmp(x, skb, net_seq);
518+
case XFRM_REPLAY_MODE_ESN:
519+
return xfrm_replay_check_esn(x, skb, net_seq);
520+
}
521+
522+
return xfrm_replay_check_legacy(x, skb, net_seq);
523+
}
524+
510525
static int xfrm_replay_recheck_esn(struct xfrm_state *x,
511526
struct sk_buff *skb, __be32 net_seq)
512527
{
@@ -532,7 +547,7 @@ int xfrm_replay_recheck(struct xfrm_state *x,
532547
return xfrm_replay_recheck_esn(x, skb, net_seq);
533548
}
534549

535-
return xfrm_replay_check(x, skb, net_seq);
550+
return xfrm_replay_check_legacy(x, skb, net_seq);
536551
}
537552

538553
static void xfrm_replay_advance_esn(struct xfrm_state *x, __be32 net_seq)
@@ -723,32 +738,26 @@ static int xfrm_replay_overflow_offload_esn(struct xfrm_state *x, struct sk_buff
723738
}
724739

725740
static const struct xfrm_replay xfrm_replay_legacy = {
726-
.check = xfrm_replay_check,
727741
.overflow = xfrm_replay_overflow_offload,
728742
};
729743

730744
static const struct xfrm_replay xfrm_replay_bmp = {
731-
.check = xfrm_replay_check_bmp,
732745
.overflow = xfrm_replay_overflow_offload_bmp,
733746
};
734747

735748
static const struct xfrm_replay xfrm_replay_esn = {
736-
.check = xfrm_replay_check_esn,
737749
.overflow = xfrm_replay_overflow_offload_esn,
738750
};
739751
#else
740752
static const struct xfrm_replay xfrm_replay_legacy = {
741-
.check = xfrm_replay_check,
742753
.overflow = xfrm_replay_overflow,
743754
};
744755

745756
static const struct xfrm_replay xfrm_replay_bmp = {
746-
.check = xfrm_replay_check_bmp,
747757
.overflow = xfrm_replay_overflow_bmp,
748758
};
749759

750760
static const struct xfrm_replay xfrm_replay_esn = {
751-
.check = xfrm_replay_check_esn,
752761
.overflow = xfrm_replay_overflow_esn,
753762
};
754763
#endif

0 commit comments

Comments
 (0)