From a3f12874517dc2eee00db10ac06741a91a2e665f Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Fri, 28 Sep 2018 01:01:24 +0200 Subject: wg: Native function WIP --- proto/wireguard/wireguard.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) 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 + +#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, -- cgit v1.2.3