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