diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2018-09-28 01:01:24 +0200 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2019-02-28 00:45:07 +0100 |
commit | a3f12874517dc2eee00db10ac06741a91a2e665f (patch) | |
tree | 194a705dea736ae53361e02e1311e2fd10c5ef2b | |
parent | 7b42938143dc02a085a5a63c7d4aa310a6695895 (diff) |
wg: Native function WIPnative/wg-native-function
-rw-r--r-- | proto/wireguard/wireguard.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/proto/wireguard/wireguard.c b/proto/wireguard/wireguard.c index f45796d5..92310def 100644 --- a/proto/wireguard/wireguard.c +++ b/proto/wireguard/wireguard.c @@ -1,6 +1,10 @@ // Based on proto/rip/rip.c #include <stdio.h> + +#include "lib/lists.h" +#include "lib/resource.h" +#include "filter/filter.h" #include "nest/protocol.h" #include "nest/iface.h" #include "sysdep/linux/wireguard.h" @@ -14,6 +18,50 @@ wg_init_entry(void *e_) // debug("wg_init_entry\n"); } + +/* struct symbol { */ +/* struct symbol *next; */ +/* struct sym_scope *scope; */ +/* int class; */ +/* int aux; */ +/* void *aux2; */ +/* void *def; */ +/* char name[1]; */ +/* }; */ + +static struct symbol *wg_arg; + +static struct f_val +wg_foobar(void) +{ + struct f_val *var = wg_arg->def; + debug("**********************foobar**************************%x %x %s %x %x\n", wg_arg->class, var->type, var->val.s, f_rte, f_eattrs); + struct f_val res; + res.type = T_RETURN | T_VOID; + return res; +} + +static void +wg_preconfig(struct protocol *P, struct config *C) +{ + P, C; + debug("preconfig\n"); + struct symbol *sym = cf_get_symbol("foobar"); + struct symbol *res = cf_define_symbol(sym, SYM_FUNCTION_NATIVE, NULL); + cf_push_scope(res); + res->def = wg_foobar; /* body */ + + wg_arg = cf_get_symbol("value"); + struct f_val *val = cfg_alloc(sizeof(struct f_val)); + val->type = T_VOID; + wg_arg = cf_define_symbol(wg_arg, SYM_VARIABLE | T_STRING, val); + wg_arg->aux2 = NULL; + + res->aux2 = wg_arg; /* params */ + + cf_pop_scope(); +} + static void wg_postconfig(struct proto_config *C) { @@ -208,6 +256,7 @@ struct protocol proto_wireguard = { .channel_mask = NB_ANY, .proto_size = sizeof(struct wg_proto), .config_size = sizeof(struct wg_config), + .preconfig = wg_preconfig, .postconfig = wg_postconfig, .init = wg_init, .start = wg_start, |