1 /*
2     VTun - Virtual Tunnel over TCP/IP network.
3 
4     Copyright (C) 1998-2016  Maxim Krasnyansky <max_mk@yahoo.com>
5 
6     VTun has been derived from VPPP package by Maxim Krasnyansky.
7 
8     This program is free software; you can redistribute it and/or modify
9     it 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,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  */
18 
19 /*
20  * $Id: linkfd.h,v 1.4.2.4 2016/10/01 21:37:39 mtbishop Exp $
21  */
22 
23 #ifndef _LINKFD_H
24 #define _LINKFD_H
25 
26 /* Priority of the process in the link_fd function */
27 /* Never set the priority to -19 without stating a good reason.
28  *#define LINKFD_PRIO -19
29  * Since the likely intent was just to give vtun an edge,
30  * -1 will do nicely.
31  */
32 #define LINKFD_PRIO -1
33 /* Frame alloc/free */
34 #define LINKFD_FRAME_RESERV 128
35 #define LINKFD_FRAME_APPEND 64
36 
lfd_alloc(size_t size)37 static inline void * lfd_alloc(size_t size)
38 {
39      register char * buf;
40 
41      size += LINKFD_FRAME_RESERV + LINKFD_FRAME_APPEND;
42 
43      if( !(buf = malloc(size)) )
44         return NULL;
45 
46      return buf+LINKFD_FRAME_RESERV;
47 }
48 
lfd_realloc(void * buf,size_t size)49 static inline void * lfd_realloc(void *buf, size_t size)
50 {
51      unsigned char *ptr = buf;
52 
53      ptr  -= LINKFD_FRAME_RESERV;
54      size += LINKFD_FRAME_RESERV;
55 
56      if( !(ptr = realloc(ptr, size)) )
57         return NULL;
58 
59      return ptr+LINKFD_FRAME_RESERV;
60 }
61 
lfd_free(void * buf)62 static inline void lfd_free(void *buf)
63 {
64      unsigned char *ptr = buf;
65 
66      free(ptr-LINKFD_FRAME_RESERV);
67 }
68 
69 int linkfd(struct vtun_host *host);
70 
71 /* Module */
72 struct lfd_mod {
73    char *name;
74    int (*alloc)(struct vtun_host *host);
75    int (*encode)(int len, char *in, char **out);
76    int (*avail_encode)(void);
77    int (*decode)(int len, char *in, char **out);
78    int (*avail_decode)(void);
79    int (*free)(void);
80 
81    struct lfd_mod *next;
82    struct lfd_mod *prev;
83 };
84 
85 /* External LINKFD modules */
86 
87 extern struct lfd_mod lfd_zlib;
88 extern struct lfd_mod lfd_lzo;
89 extern struct lfd_mod lfd_encrypt;
90 extern struct lfd_mod lfd_legacy_encrypt;
91 extern struct lfd_mod lfd_shaper;
92 
93 #endif
94