21 #include <linux/export.h>
33 seq_hi = replay_esn->
seq_hi;
98 struct net *
net = xs_net(x);
104 xfrm_audit_state_replay_overflow(x, skb);
109 if (xfrm_aevent_is_on(net))
116 static int xfrm_replay_check(
struct xfrm_state *x,
122 if (!x->
props.replay_window)
131 diff = x->
replay.seq - seq;
132 if (diff >=
min_t(
unsigned int, x->
props.replay_window,
133 sizeof(x->
replay.bitmap) * 8)) {
134 x->
stats.replay_window++;
138 if (x->
replay.bitmap & (1
U << diff)) {
145 xfrm_audit_state_replay(x, skb, net_seq);
154 if (!x->
props.replay_window)
157 if (seq > x->
replay.seq) {
158 diff = seq - x->
replay.seq;
159 if (diff < x->props.replay_window)
165 diff = x->
replay.seq - seq;
166 x->
replay.bitmap |= (1
U << diff);
169 if (xfrm_aevent_is_on(xs_net(x)))
177 struct net *net = xs_net(x);
183 xfrm_audit_state_replay_overflow(x, skb);
188 if (xfrm_aevent_is_on(net))
195 static int xfrm_replay_check_bmp(
struct xfrm_state *x,
198 unsigned int bitnr,
nr;
214 x->
stats.replay_window++;
226 bitnr = bitnr & 0x1F;
227 if (replay_esn->
bmp[nr] & (1
U << bitnr))
235 xfrm_audit_state_replay(x, skb, net_seq);
241 unsigned int bitnr,
nr,
i;
250 if (seq > replay_esn->
seq) {
251 diff = seq - replay_esn->
seq;
254 for (i = 1; i < diff; i++) {
257 bitnr = bitnr & 0x1F;
258 replay_esn->
bmp[nr] &= ~(1
U << bitnr);
262 for (i = 0; i <=
nr; i++)
263 replay_esn->
bmp[i] = 0;
267 replay_esn->
seq = seq;
269 diff = replay_esn->
seq -
seq;
278 bitnr = bitnr & 0x1F;
279 replay_esn->
bmp[
nr] |= (1
U << bitnr);
281 if (xfrm_aevent_is_on(xs_net(x)))
285 static void xfrm_replay_notify_bmp(
struct xfrm_state *x,
int event)
316 xfrm_replay_state_esn_len(replay_esn)) == 0) {
325 xfrm_replay_state_esn_len(replay_esn));
339 struct net *net = xs_net(x);
348 if (replay_esn->
oseq_hi == 0) {
351 xfrm_audit_state_replay_overflow(x, skb);
357 if (xfrm_aevent_is_on(net))
364 static int xfrm_replay_check_esn(
struct xfrm_state *x,
367 unsigned int bitnr,
nr;
385 if (
likely(top >= wsize - 1)) {
387 if (
likely(seq > top) || seq < bottom)
391 if (
likely(seq > top && seq < bottom))
394 diff = ~seq + top + 1;
398 x->
stats.replay_window++;
410 bitnr = bitnr & 0x1F;
411 if (replay_esn->
bmp[nr] & (1
U << bitnr))
419 xfrm_audit_state_replay(x, skb, net_seq);
423 static int xfrm_replay_recheck_esn(
struct xfrm_state *x,
428 x->
stats.replay_window++;
432 return xfrm_replay_check_esn(x, skb, net_seq);
437 unsigned int bitnr,
nr,
i;
445 seq =
ntohl(net_seq);
448 wrap = seq_hi - replay_esn->
seq_hi;
450 if ((!wrap && seq > replay_esn->
seq) || wrap > 0) {
452 diff = seq - replay_esn->
seq;
454 diff = ~replay_esn->
seq + seq + 1;
456 if (diff < replay_esn->replay_window) {
457 for (i = 1; i < diff; i++) {
460 bitnr = bitnr & 0x1F;
461 replay_esn->
bmp[nr] &= ~(1
U << bitnr);
465 for (i = 0; i <=
nr; i++)
466 replay_esn->
bmp[i] = 0;
470 replay_esn->
seq = seq;
475 diff = replay_esn->
seq -
seq;
484 bitnr = bitnr & 0x1F;
485 replay_esn->
bmp[
nr] |= (1
U << bitnr);
487 if (xfrm_aevent_is_on(xs_net(x)))
492 .advance = xfrm_replay_advance,
493 .check = xfrm_replay_check,
494 .recheck = xfrm_replay_check,
495 .notify = xfrm_replay_notify,
496 .overflow = xfrm_replay_overflow,
500 .advance = xfrm_replay_advance_bmp,
501 .check = xfrm_replay_check_bmp,
502 .recheck = xfrm_replay_check_bmp,
503 .notify = xfrm_replay_notify_bmp,
504 .overflow = xfrm_replay_overflow_bmp,
508 .advance = xfrm_replay_advance_esn,
509 .check = xfrm_replay_check_esn,
510 .recheck = xfrm_replay_recheck_esn,
511 .notify = xfrm_replay_notify_bmp,
512 .overflow = xfrm_replay_overflow_esn,
528 x->
repl = &xfrm_replay_esn;
530 x->
repl = &xfrm_replay_bmp;
532 x->
repl = &xfrm_replay_legacy;