static int dosequence(keyset *ks, uint32 seq)
{
- uint32 seqbit;
- uint32 n;
-
- if (seq < ks->iseq) {
- a_warn("SYMM replay old-sequence");
- return (-1);
- }
- if (seq >= ks->iseq + KS_SEQWINSZ) {
- n = seq - (ks->iseq + KS_SEQWINSZ - 1);
- if (n < KS_SEQWINSZ)
- ks->iwin >>= n;
- else
- ks->iwin = 0;
- ks->iseq += n;
- }
- seqbit = 1 << (seq - ks->iseq);
- if (ks->iwin & seqbit) {
- a_warn("SYMM replay duplicated-sequence");
- return (-1);
+ switch (seq_check(&ks->iseq, seq)) {
+ case SEQ_OK: break;
+ case SEQ_OLD: a_warn("SYMM replay old-sequence"); return (-1);
+ case SEQ_REPLAY: a_warn("SYMM replay duplicated-sequence"); return (-1);
+ default: abort();
}
- ks->iwin |= seqbit;
return (0);
}
ks->ref = 1;
ks->t_exp = now + T_EXP;
ks->sz_exp = SZ_EXP;
- ks->oseq = ks->iseq = 0;
- ks->iwin = 0;
+ ks->oseq = 0;
+ seq_reset(&ks->iseq);
ks->next = 0;
ks->p = p;
ks->f = KSF_LISTEN;