Update to GPLv3+; update copyright notices everywhere.
[userv-utils] / ipif / forwarder.h
CommitLineData
1fb3cba0 1/*
f0e54a99 2 * Encrypting tunnel for userv-ipif tunnels, header file
3 */
4/*
c07be359 5 * This file is part of ipif, part of userv-utils
f0e54a99 6 *
9028e234
IJ
7 * Copyright 1996-2013 Ian Jackson <ijackson@chiark.greenend.org.uk>
8 * Copyright 1998 David Damerell <damerell@chiark.greenend.org.uk>
9 * Copyright 1999,2003
10 * Chancellor Masters and Scholars of the University of Cambridge
11 * Copyright 2010 Tony Finch <fanf@dotat.at>
12 *
f0e54a99 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
9028e234 15 * the Free Software Foundation; either version 3 of the License, or
f0e54a99 16 * (at your option) any later version.
17 *
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.
22 *
23 * You should have received a copy of the GNU General Public License
9028e234 24 * along with userv-utils; if not, see http://www.gnu.org/licenses/.
1fb3cba0 25 */
26
27#ifndef MECHS_H
28#define MECHS_H
29
30#include <stdio.h>
31#include <time.h>
dea61a77 32#include <string.h>
f9e59051 33#include <sys/utsname.h>
1fb3cba0 34
1fb3cba0 35struct buffer {
36 unsigned char *base;
37 unsigned char *start;
38 size_t size;
39};
40
41struct mechdata;
42
43typedef void mes_functype(struct mechdata **md_r, int *maxprefix_io, int *maxsuffix_io);
44typedef void mds_functype(struct mechdata **md_r);
45
46typedef void menc_functype(struct mechdata *md, struct buffer*);
47typedef const char *mdec_functype(struct mechdata *md, struct buffer*);
48
49struct mechanism {
50 const char *name;
51 mes_functype *encsetup;
52 mds_functype *decsetup;
53 menc_functype *encode;
54 mdec_functype *decode;
55};
56
33e8a62b
IJ
57#include "automech.h"
58
1fb3cba0 59extern const struct mechanism *const mechanismlists[];
60
61/* setup function may call getarg_xxx functions and then
62 * reads/writes key material to/from fd
63 *
64 * setup_in function may increase maxprefix and maxsuffix
65 * code functions modify buffer in place
f0e54a99 66 * decode function returns 0 meaning packet decoded ok,
67 * "" meaning discard it quietly, or message to print for verbose discard
1fb3cba0 68 */
69
70const char *getarg_string(void);
71unsigned long getarg_ulong(void);
72
f9e59051 73#define PROGRAM "udptunnel-forwarder"
1fb3cba0 74extern char programid[];
75
76void *buf_append(struct buffer *buf, size_t amount);
77void *buf_prepend(struct buffer *buf, size_t amount);
78void *buf_unappend(struct buffer *buf, size_t amount); /* may give 0 */
79void *buf_unprepend(struct buffer *buf, size_t amount); /* may give 0 */
80
81void sysfail(const char *msg);
82void fail(const char *msg);
83void sysdiag(const char *msg);
84void diag(const char *msg);
85
f9e59051 86extern const char *const *argv;
87
1fb3cba0 88time_t now(void);
89void *xmalloc(size_t sz);
90void get_random(void *ptr, size_t sz);
91void random_key(void *ptr, size_t sz);
f9e59051 92void write_must(int fd, const void *p_in, int sz, const char *what);
93void read_must(int fd, void *p_in, int sz, const char *what);
1fb3cba0 94
95void arg_assert_fail(const char *msg);
96#define arg_assert(v) (v ? (void)0 : arg_assert_fail(#v))
97
98#define XMALLOC(variable) ((variable)= xmalloc(sizeof(*(variable))))
99
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)
104
105#define STANDARD_MECHANISMLIST(mechstring,filename) \
106 const struct mechanism mechlist_##filename []= { \
107 STANDARD_MECHANISM(mechstring,filename) \
108 { 0 } \
109 };
110
111#define STANDARD_MECHANISM(mechstring,mechname) \
112 { mechstring, mes_##mechname, mds_##mechname, menc_##mechname, mdec_##mechname },
113
114#endif