2 #ifndef TRANSFORM_COMMON_H
3 #define TRANSFORM_COMMON_H
7 #define KEYED_CHECK do{ \
9 *errmsg="transform unkeyed"; \
14 #define RECVBITMAP_SIZE 32
15 typedef uint32_t recvbitmap_type;
17 #define SEQNUM_CHECK(seqnum, p) do{ \
18 uint32_t skew=seqnum-ti->lastrecvseq; \
19 if (skew<0x8fffffff) { \
21 ti->lastrecvseq=seqnum; \
22 if (skew < RECVBITMAP_SIZE) \
23 ti->recvbitmap <<= skew; \
27 } else if ((0-skew)<(p)->max_seq_skew) { \
31 *errmsg="seqnum: too much skew"; \
35 recvbitmap_type recvbit=(uint32_t)1 << skew; \
36 if (ti->recvbitmap & recvbit) { \
37 *errmsg="seqnum: duplicate"; \
40 ti->recvbitmap |= recvbit; \
44 #define SEQNUM_KEYED_FIELDS \
46 uint32_t lastrecvseq; \
47 recvbitmap_type recvbitmap; /* 1<<0 is lastrecvseq (i.e., most recent) */ \
50 #define SEQNUM_KEYED_INIT(initlastrecvseq,initsendseq) \
51 (ti->lastrecvseq=(initlastrecvseq), \
52 ti->sendseq=(initsendseq), \
56 #define TRANSFORM_VALID \
57 static bool_t transform_valid(void *sst) \
59 struct transform_inst *ti=sst; \
64 #define TRANSFORM_DESTROY \
65 static void transform_destroy(void *sst) \
67 struct transform_inst *st=sst; \
69 FILLZERO(*st); /* Destroy key material */ \
73 #define SET_CAPAB_TRANSFORMNUM(def) do{ \
74 st->ops.capab_transformnum=dict_read_number(dict, "capab-num", \
75 False, "transform", loc, (def)); \
76 if (st->ops.capab_transformnum > CAPAB_TRANSFORMNUM_MAX) \
77 cfgfatal(loc,"transform","capab-num out of range 0..%d\n", \
78 CAPAB_TRANSFORMNUM_MAX); \
81 #define TRANSFORM_CREATE_CORE \
82 struct transform_inst *ti; \
86 ti->ops.setkey=transform_setkey; \
87 ti->ops.valid=transform_valid; \
88 ti->ops.delkey=transform_delkey; \
89 ti->ops.forwards=transform_forward; \
90 ti->ops.reverse=transform_reverse; \
91 ti->ops.destroy=transform_destroy; \
94 #define SEQNUM_PARAMS_FIELDS \
95 uint32_t max_seq_skew; \
98 #define SEQNUM_PARAMS_INIT(dict,p,desc,loc) \
99 (p)->max_seq_skew=dict_read_number((dict), "max-sequence-skew", \
100 False, (desc), (loc), 10); \
101 bool_t can_dedupe=(p)->max_seq_skew < RECVBITMAP_SIZE; \
102 (p)->dedupe=dict_read_bool((dict), "dedupe", \
103 False,(desc),(loc), can_dedupe); \
104 if ((p)->dedupe && !can_dedupe) \
105 cfgfatal(loc,"transform", \
106 "cannot dedupe with max-sequence-skew>=32"); \
109 #endif /*TRANSFORM_COMMON_H*/