chiark / gitweb /
netlink: Remove a newline from p-t-p startup message
[secnet.git] / transform-common.h
1
2 #ifndef TRANSFORM_COMMON_H
3 #define TRANSFORM_COMMON_H
4
5 #include "magic.h"
6
7 #define KEYED_CHECK do{                         \
8         if (!ti->keyed) {                       \
9             *errmsg="transform unkeyed";        \
10             return 1;                           \
11         }                                       \
12     }while(0)
13
14 #define SEQNUM_CHECK(seqnum, max_skew) do{      \
15         uint32_t skew=seqnum-ti->lastrecvseq;   \
16         if (skew<0x8fffffff) {                  \
17             /* Ok */                            \
18             ti->lastrecvseq=seqnum;             \
19         } else if ((0-skew)<max_skew) { \
20             /* Ok */                            \
21         } else {                                \
22             /* Too much skew */                 \
23             *errmsg="seqnum: too much skew";    \
24             return 2;                           \
25         }                                       \
26     }while(0)
27
28 #define TRANSFORM_VALID                         \
29     static bool_t transform_valid(void *sst)    \
30     {                                           \
31         struct transform_inst *ti=sst;          \
32                                                 \
33         return ti->keyed;                       \
34     }
35
36 #define TRANSFORM_DESTROY                               \
37     static void transform_destroy(void *sst)            \
38     {                                                   \
39         struct transform_inst *st=sst;                  \
40                                                         \
41         FILLZERO(*st); /* Destroy key material */       \
42         free(st);                                       \
43     }
44
45 #define SET_CAPAB_TRANSFORMNUM(def) do{                                 \
46         st->ops.capab_transformnum=dict_read_number(dict, "capab-num",  \
47                                      False, "transform", loc, def);     \
48         if (st->ops.capab_transformnum > CAPAB_TRANSFORMNUM_MAX)        \
49             cfgfatal(loc,"transform","capab-num out of range 0..%d\n",  \
50                      CAPAB_TRANSFORMNUM_MAX);                           \
51     }while(0)
52
53 #define TRANSFORM_CREATE_CORE                           \
54         struct transform_inst *ti;                      \
55         ti=safe_malloc(sizeof(*ti),"transform_create"); \
56         /* mlock XXX */                                 \
57         ti->ops.st=ti;                                  \
58         ti->ops.setkey=transform_setkey;                \
59         ti->ops.valid=transform_valid;                  \
60         ti->ops.delkey=transform_delkey;                \
61         ti->ops.forwards=transform_forward;             \
62         ti->ops.reverse=transform_reverse;              \
63         ti->ops.destroy=transform_destroy;              \
64         ti->keyed=False;
65
66 #endif /*TRANSFORM_COMMON_H*/