/*  
    Tentun

    Derived from VTun by Max K.

    Copyright (C) 2003 David Gordon davidgordonca@hotmail.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 */

#ifndef _PLUGINS_H
#define _PLUGINS_H

#include "tentun.h"


/* Frame alloc/free */
#define LINKFD_FRAME_RESERV 8

static inline void * plug_alloc(size_t size)
{
     register char * buf;

     size += LINKFD_FRAME_RESERV;

     if( !(buf = malloc(size)) )
        return NULL;

     return buf+LINKFD_FRAME_RESERV; 
}

static inline void * plug_realloc(void *buf, size_t size)
{
     unsigned char *ptr = buf;

     ptr  -= LINKFD_FRAME_RESERV;
     size += LINKFD_FRAME_RESERV;

     if( !(ptr = realloc(ptr, size)) )
        return NULL;

     return ptr+LINKFD_FRAME_RESERV; 
}

static inline void plug_free(void *buf)
{
     unsigned char *ptr = buf;

     free(ptr-LINKFD_FRAME_RESERV);
}

struct plug_mod {
   char *name;
   int (*alloc)(struct tentun_host *host);
   int (*encode)(int len, char *in, char **out);
   int (*avail_encode)(void);
   int (*decode)(int len, char *in, char **out);
   int (*avail_decode)(void);
   int (*free)(void);

   struct plug_mod *next;
   struct plug_mod *prev;
};

/* External plugin modules */

extern struct plug_mod plug_simple_http;
extern struct plug_mod plug_dns;


#endif
