X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=secnet.git;a=blobdiff_plain;f=transform-common.h;h=f90deef219328ee5233101cbc45b91f088dc0326;hp=b3c70a8d30e3bcc49818547b495276330892521d;hb=ca53592227f187270bfd611e21e63f33d07a9f7e;hpb=92a7d254975db245c3320855515bffc1aebda9e4 diff --git a/transform-common.h b/transform-common.h index b3c70a8..f90deef 100644 --- a/transform-common.h +++ b/transform-common.h @@ -1,7 +1,27 @@ +/* + * This file is part of secnet. + * See README for full list of copyright holders. + * + * secnet is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version d of the License, or + * (at your option) any later version. + * + * secnet is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 3 along with secnet; if not, see + * https://www.gnu.org/licenses/gpl.html. + */ #ifndef TRANSFORM_COMMON_H #define TRANSFORM_COMMON_H +#include "magic.h" + #define KEYED_CHECK do{ \ if (!ti->keyed) { \ *errmsg="transform unkeyed"; \ @@ -9,20 +29,48 @@ } \ }while(0) -#define SEQNUM_CHECK(seqnum, max_skew) do{ \ - uint32_t skew=seqnum-ti->lastrecvseq; \ - if (skew<0x8fffffff) { \ - /* Ok */ \ - ti->lastrecvseq=seqnum; \ - } else if ((0-skew)lastrecvseq; \ + if (skew<0x8fffffff) { \ + /* Ok */ \ + ti->lastrecvseq=seqnum; \ + if (skew < RECVBITMAP_SIZE) \ + ti->recvbitmap <<= skew; \ + else \ + ti->recvbitmap=0; \ + skew=0; \ + } else if ((0-skew)<(p)->max_seq_skew) { \ + /* Ok */ \ + } else { \ + /* Too much skew */ \ + *errmsg="seqnum: too much skew"; \ + return 2; \ + } \ + if ((p)->dedupe) { \ + recvbitmap_type recvbit=(uint32_t)1 << skew; \ + if (ti->recvbitmap & recvbit) { \ + *errmsg="seqnum: duplicate"; \ + return 2; \ + } \ + ti->recvbitmap |= recvbit; \ + } \ }while(0) +#define SEQNUM_KEYED_FIELDS \ + uint32_t sendseq; \ + uint32_t lastrecvseq; \ + recvbitmap_type recvbitmap; /* 1<<0 is lastrecvseq (i.e., most recent) */ \ + bool_t keyed + +#define SEQNUM_KEYED_INIT(initlastrecvseq,initsendseq) \ + (ti->lastrecvseq=(initlastrecvseq), \ + ti->sendseq=(initsendseq), \ + ti->recvbitmap=0, \ + ti->keyed=True) + #define TRANSFORM_VALID \ static bool_t transform_valid(void *sst) \ { \ @@ -40,9 +88,17 @@ free(st); \ } +#define SET_CAPAB_TRANSFORMNUM(def) do{ \ + st->ops.capab_transformnum=dict_read_number(dict, "capab-num", \ + False, "transform", loc, (def)); \ + if (st->ops.capab_transformnum > CAPAB_TRANSFORMNUM_MAX) \ + cfgfatal(loc,"transform","capab-num out of range 0..%d\n", \ + CAPAB_TRANSFORMNUM_MAX); \ + }while(0) + #define TRANSFORM_CREATE_CORE \ struct transform_inst *ti; \ - ti=safe_malloc(sizeof(*ti),"transform_create"); \ + NEW(ti); \ /* mlock XXX */ \ ti->ops.st=ti; \ ti->ops.setkey=transform_setkey; \ @@ -53,4 +109,19 @@ ti->ops.destroy=transform_destroy; \ ti->keyed=False; +#define SEQNUM_PARAMS_FIELDS \ + uint32_t max_seq_skew; \ + bool_t dedupe; + +#define SEQNUM_PARAMS_INIT(dict,p,desc,loc) \ + (p)->max_seq_skew=dict_read_number((dict), "max-sequence-skew", \ + False, (desc), (loc), 10); \ + bool_t can_dedupe=(p)->max_seq_skew < RECVBITMAP_SIZE; \ + (p)->dedupe=dict_read_bool((dict), "dedupe", \ + False,(desc),(loc), can_dedupe); \ + if ((p)->dedupe && !can_dedupe) \ + cfgfatal(loc,"transform", \ + "cannot dedupe with max-sequence-skew>=32"); \ + else (void)0 + #endif /*TRANSFORM_COMMON_H*/