2 * Sequence number / nonce mechanism
6 * encoding: prepend 4 bytes of sequence arithmetic serial number
7 * decoding: check increasingness, or ignore
10 #include <netinet/in.h>
12 #include "forwarder.h"
16 int anyseen; /* decode only */
19 static void mes_sequence(struct mechdata **md_r, int *maxprefix_io, int *maxsuffix_io) {
23 get_random(&md->number,sizeof(md->number));
28 static void mds_sequence(struct mechdata **md_r) {
35 static void menc_sequence(struct mechdata *md, struct buffer *buf) {
37 *(uint32_t*)buf_prepend(buf,4)= htonl(md->number);
40 static const char *mdec_check(struct mechdata *md, struct buffer *buf) {
41 uint32_t *sp, sequence;
43 BUF_UNPREPEND(sp,buf,4);
47 if (sequence - md->number >= 0x800000UL) return "out of order packet";
55 static const char *mdec_skip(struct mechdata *md, struct buffer *buf) {
57 BUF_UNPREPEND(sp,buf,4);
61 const struct mechanism mechlist_sequence[]= {
62 { "nonce", mes_sequence, mds_sequence, menc_sequence, mdec_skip },
63 { "sequence", mes_sequence, mds_sequence, menc_sequence, mdec_check },