ipif: move #include of automech.h down so that it has definition of struct mechanism
[userv-utils] / ipif / forwarder.h
CommitLineData
1fb3cba0 1/*
f0e54a99 2 * Encrypting tunnel for userv-ipif tunnels, header file
3 */
4/*
c07be359 5 * Copyright (C) 2000,2003 Ian Jackson
6 * This file is part of ipif, part of userv-utils
f0e54a99 7 *
8 * This is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with userv-utils; if not, write to the Free Software
20 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1fb3cba0 21 */
22
23#ifndef MECHS_H
24#define MECHS_H
25
26#include <stdio.h>
27#include <time.h>
dea61a77 28#include <string.h>
f9e59051 29#include <sys/utsname.h>
1fb3cba0 30
1fb3cba0 31struct buffer {
32 unsigned char *base;
33 unsigned char *start;
34 size_t size;
35};
36
37struct mechdata;
38
39typedef void mes_functype(struct mechdata **md_r, int *maxprefix_io, int *maxsuffix_io);
40typedef void mds_functype(struct mechdata **md_r);
41
42typedef void menc_functype(struct mechdata *md, struct buffer*);
43typedef const char *mdec_functype(struct mechdata *md, struct buffer*);
44
45struct mechanism {
46 const char *name;
47 mes_functype *encsetup;
48 mds_functype *decsetup;
49 menc_functype *encode;
50 mdec_functype *decode;
51};
52
d09170cc
IJ
53#include "automech.h"
54
1fb3cba0 55extern const struct mechanism *const mechanismlists[];
56
57/* setup function may call getarg_xxx functions and then
58 * reads/writes key material to/from fd
59 *
60 * setup_in function may increase maxprefix and maxsuffix
61 * code functions modify buffer in place
f0e54a99 62 * decode function returns 0 meaning packet decoded ok,
63 * "" meaning discard it quietly, or message to print for verbose discard
1fb3cba0 64 */
65
66const char *getarg_string(void);
67unsigned long getarg_ulong(void);
68
f9e59051 69#define PROGRAM "udptunnel-forwarder"
1fb3cba0 70extern char programid[];
71
72void *buf_append(struct buffer *buf, size_t amount);
73void *buf_prepend(struct buffer *buf, size_t amount);
74void *buf_unappend(struct buffer *buf, size_t amount); /* may give 0 */
75void *buf_unprepend(struct buffer *buf, size_t amount); /* may give 0 */
76
77void sysfail(const char *msg);
78void fail(const char *msg);
79void sysdiag(const char *msg);
80void diag(const char *msg);
81
f9e59051 82extern const char *const *argv;
83
1fb3cba0 84time_t now(void);
85void *xmalloc(size_t sz);
86void get_random(void *ptr, size_t sz);
87void random_key(void *ptr, size_t sz);
f9e59051 88void write_must(int fd, const void *p_in, int sz, const char *what);
89void read_must(int fd, void *p_in, int sz, const char *what);
1fb3cba0 90
91void arg_assert_fail(const char *msg);
92#define arg_assert(v) (v ? (void)0 : arg_assert_fail(#v))
93
94#define XMALLOC(variable) ((variable)= xmalloc(sizeof(*(variable))))
95
96#define BUF_UNSOMEEND(var,buf,sz,whichend) \
97 do { var= whichend(buf,sz); if (!var) return "message truncated"; } while(0)
98#define BUF_UNAPPEND(var,buf,sz) BUF_UNSOMEEND(var,buf,sz,buf_unappend)
99#define BUF_UNPREPEND(var,buf,sz) BUF_UNSOMEEND(var,buf,sz,buf_unprepend)
100
101#define STANDARD_MECHANISMLIST(mechstring,filename) \
102 const struct mechanism mechlist_##filename []= { \
103 STANDARD_MECHANISM(mechstring,filename) \
104 { 0 } \
105 };
106
107#define STANDARD_MECHANISM(mechstring,mechname) \
108 { mechstring, mes_##mechname, mds_##mechname, menc_##mechname, mdec_##mechname },
109
110#endif