diff options
Diffstat (limited to 'filter/config.Y')
-rw-r--r-- | filter/config.Y | 126 |
1 files changed, 59 insertions, 67 deletions
diff --git a/filter/config.Y b/filter/config.Y index 84644370..8b5f01e9 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -109,12 +109,59 @@ f_new_pair_set(int fa, int ta, int fb, int tb) static struct f_tree * f_new_tlv_item(u32 type, u32 v1) { - debug("f_new_tlv_item\n"); struct f_tree *t = f_new_tree(); t->right = t; t->from.type = t->to.type = T_TLV; - // t->from.val.tlv = v1; - // t->to.val.tlv = v1; + struct tlv v; + v.type = type; + switch (type) { + case TLV_UDP_DEST_PORT: + v.u.udp_dest_port = v1; + break; + default: + // FIXME error + break; + } + t->from.val.tlv = v; + t->to.val.tlv = v; + return t; +} + +static struct f_tree * +f_new_tlv_remote_ep(u32 asn, struct f_val ep) +{ + struct f_tree *t = f_new_tree(); + t->right = t; + t->from.type = t->to.type = T_TLV; + struct tlv v; + v.type = TLV_REMOTE_ENDPOINT; + v.u.remote_endpoint.asn = asn; + v.u.remote_endpoint.ip = ep.val.ip; + t->from.val.tlv = v; + t->to.val.tlv = v; + return t; +} + +int wg_key_from_base64(void *key, const char *base64); + +static struct f_tree * +f_new_tlv_encap(u32 type, const char *v1) +{ + struct f_tree *t = f_new_tree(); + t->right = t; + t->from.type = t->to.type = T_TLV; + struct tlv v; + v.type = TLV_ENCAPSULATION; + v.u.tunnel_encap.type = type; + // FIXME base64 decode v1 + int len = 32; + v.u.tunnel_encap.data = cfg_alloc(len); + v.u.tunnel_encap.length = len; + // FIXME + wg_key_from_base64(v.u.tunnel_encap.data, v1); +// memcpy(v.u.tunnel_encap.data, v1, len); + t->from.val.tlv = v; + t->to.val.tlv = v; return t; } @@ -327,62 +374,6 @@ f_generate_lc(struct f_inst *t1, struct f_inst *t2, struct f_inst *t3) } static inline struct f_inst * -f_generate_tlv(u16 kind, struct f_inst *tv) -{ - struct f_inst *rv = NULL; - struct tlv tlv; - struct f_val *val; - u32 type; - - debug("f_generate_tlv\n"); - - if (tv->fi_code != FI_CONSTANT_INDIRECT) - cf_error("Can't operate with value of non-constant type in TLV: %d", tv->fi_code); - - val = tv->a1.p; - type = val->type; - - switch (kind) { - case TLV_WIREGUARD: { - if (type == T_STRING) { - tlv.u.peer = val->val.s; - } - else - cf_error("Can't operate with value of non-string type in TLV wireguard constructor"); - break; - } - case TLV_REMOTE_ENDPOINT: { - if (type == T_IP) { - tlv.u.remote_endpoint.ip = val->val.ip; - } - else - cf_error("Can't operate with value of non-IP type in TLV remote endpoint constructor"); - break; - } - case TLV_UDP_DEST_PORT: { - if (type == T_INT) { - tlv.u.udp_dest_port = val->val.i; - } - else - cf_error("Can't operate with value of non-integer type in TLV udp dest port constructor"); - break; - } - default: - cf_error("Invalid TLV kind in constructor"); - }; - - { - NEW_F_VAL; - rv = f_new_inst(FI_CONSTANT_INDIRECT); - rv->a1.p = val; - val->type = T_TLV; - val->val.tlv = tlv; - - return rv; - } -} - -static inline struct f_inst * f_generate_path_mask(struct f_path_mask *t) { for (struct f_path_mask *tt = t; tt; tt = tt->next) { @@ -486,6 +477,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN, PREPEND, FIRST, LAST, LAST_NONAGGREGATED, MATCH, EMPTY, FILTER, WHERE, EVAL, ATTRIBUTE, + TLV, TUNNEL_ENCAP, REMOTE_ENDPOINT, UDP_DEST_PORT, BT_ASSERT, BT_TEST_SUITE, FORMAT) %nonassoc THEN @@ -495,7 +487,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN, %type <fda> dynamic_attr %type <fsa> static_attr %type <f> filter filter_body where_filter -%type <i> type break_command ec_kind tlv_kind +%type <i> type break_command ec_kind %type <i32> cnum %type <e> pair_item ec_item lc_item set_item switch_item set_items switch_items switch_body tlv_item %type <trie> fprefix_set @@ -559,6 +551,7 @@ type: | CLIST { $$ = T_CLIST; } | ECLIST { $$ = T_ECLIST; } | LCLIST { $$ = T_LCLIST; } + | TLV { $$ = T_TLV; } | type SET { switch ($1) { case T_INT: @@ -568,6 +561,7 @@ type: case T_LC: case T_RD: case T_IP: + case T_TLV: $$ = T_SET; break; @@ -780,18 +774,16 @@ lc_item: { $$ = f_new_lc_item($2, $10, $4, $12, $6, $14); } ; -tlv_kind: - WIREGUARD { $$ = TLV_WIREGUARD; } - tlv_item: - '(' tlv_kind ',' term ')' { $$ = f_new_tlv_item($2, $4); } - -// | tlv_item + '(' TUNNEL_ENCAP ',' cnum ',' TEXT ')' { $$ = f_new_tlv_encap($4, $6); } + | '(' UDP_DEST_PORT ',' cnum ')' { $$ = f_new_tlv_item(TLV_UDP_DEST_PORT, $4); } + | '(' REMOTE_ENDPOINT ',' NUM ',' fipa ')' { $$ = f_new_tlv_remote_ep($4, $6); } set_item: pair_item | ec_item | lc_item + | tlv_item | set_atom { $$ = f_new_item($1, $1); } | set_atom DDOT set_atom { $$ = f_new_item($1, $3); } ; @@ -800,6 +792,7 @@ switch_item: pair_item | ec_item | lc_item + | tlv_item | switch_atom { $$ = f_new_item($1, $1); } | switch_atom DDOT switch_atom { $$ = f_new_item($1, $3); } ; @@ -884,7 +877,6 @@ constructor: '(' term ',' term ')' { $$ = f_generate_dpair($2, $4); } | '(' ec_kind ',' term ',' term ')' { $$ = f_generate_ec($2, $4, $6); } | '(' term ',' term ',' term ')' { $$ = f_generate_lc($2, $4, $6); } - | '(' tlv_kind ',' term ')' { $$ = f_generate_tlv($2, $4); } | bgp_path { $$ = f_generate_path_mask($1); } ; |