2 * Encrypting tunnel for userv-ipif tunnels, header file
5 * This file is part of ipif, part of userv-utils
7 * Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk>
8 * Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk>
10 * Chancellor Masters and Scholars of the University of Cambridge
11 * Copyright 2010 Tony Finch <fanf@dotat.at>
13 * This is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with userv-utils; if not, see http://www.gnu.org/licenses/.
33 #include <sys/utsname.h>
43 typedef void mes_functype(struct mechdata
**md_r
, int *maxprefix_io
, int *maxsuffix_io
);
44 typedef void mds_functype(struct mechdata
**md_r
);
46 typedef void menc_functype(struct mechdata
*md
, struct buffer
*);
47 typedef const char *mdec_functype(struct mechdata
*md
, struct buffer
*);
51 mes_functype
*encsetup
;
52 mds_functype
*decsetup
;
53 menc_functype
*encode
;
54 mdec_functype
*decode
;
59 extern const struct mechanism
*const mechanismlists
[];
61 /* setup function may call getarg_xxx functions and then
62 * reads/writes key material to/from fd
64 * setup_in function may increase maxprefix and maxsuffix
65 * code functions modify buffer in place
66 * decode function returns 0 meaning packet decoded ok,
67 * "" meaning discard it quietly, or message to print for verbose discard
70 const char *getarg_string(void);
71 unsigned long getarg_ulong(void);
73 #define PROGRAM "udptunnel-forwarder"
74 extern char programid
[];
76 void *buf_append(struct buffer
*buf
, size_t amount
);
77 void *buf_prepend(struct buffer
*buf
, size_t amount
);
78 void *buf_unappend(struct buffer
*buf
, size_t amount
); /* may give 0 */
79 void *buf_unprepend(struct buffer
*buf
, size_t amount
); /* may give 0 */
81 void sysfail(const char *msg
);
82 void fail(const char *msg
);
83 void sysdiag(const char *msg
);
84 void diag(const char *msg
);
86 extern const char *const *argv
;
89 void *xmalloc(size_t sz
);
90 void get_random(void *ptr
, size_t sz
);
91 void random_key(void *ptr
, size_t sz
);
92 void write_must(int fd
, const void *p_in
, int sz
, const char *what
);
93 void read_must(int fd
, void *p_in
, int sz
, const char *what
);
95 void arg_assert_fail(const char *msg
);
96 #define arg_assert(v) (v ? (void)0 : arg_assert_fail(#v))
98 #define XMALLOC(variable) ((variable)= xmalloc(sizeof(*(variable))))
100 #define BUF_UNSOMEEND(var,buf,sz,whichend) \
101 do { var= whichend(buf,sz); if (!var) return "message truncated"; } while(0)
102 #define BUF_UNAPPEND(var,buf,sz) BUF_UNSOMEEND(var,buf,sz,buf_unappend)
103 #define BUF_UNPREPEND(var,buf,sz) BUF_UNSOMEEND(var,buf,sz,buf_unprepend)
105 #define STANDARD_MECHANISMLIST(mechstring,filename) \
106 const struct mechanism mechlist_##filename []= { \
107 STANDARD_MECHANISM(mechstring,filename) \
111 #define STANDARD_MECHANISM(mechstring,mechname) \
112 { mechstring, mes_##mechname, mds_##mechname, menc_##mechname, mdec_##mechname },