Skip to content

Commit

Permalink
Got rid of debug code.
Browse files Browse the repository at this point in the history
Improve start/stop regex scripts
  • Loading branch information
biathlon3 committed Jul 16, 2024
1 parent 1411505 commit 28f9eee
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 144 deletions.
43 changes: 1 addition & 42 deletions fw/cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ entry_set_name(TfwCfgEntry *e)

BUG_ON(!e);
BUG_ON(e->name);
//pr_notice("rule=%i",rule);

if (!rule) {
name = e->ftoken;
Expand All @@ -254,7 +253,6 @@ entry_set_name(TfwCfgEntry *e)
}

T_DBG3("set name: %.*s\n", len, name);
//pr_notice("set name: %.*s\n", len, name);

if (!check_identifier(name, len))
return -EINVAL;
Expand All @@ -278,7 +276,6 @@ entry_set_first_token(TfwCfgEntry *e, const char *src, int len)
BUG_ON(e->ftoken);

T_DBG3("set first token: %.*s\n", len, src);
//pr_notice("set first token: %.*s\n", len, src);

if (!src || !len)
return -EINVAL;
Expand Down Expand Up @@ -363,7 +360,6 @@ entry_add_rule_param(const char **param, const char *src, size_t len)
if (!(dst = alloc_and_copy_literal(src, len)))
return -ENOMEM;
*param = dst;
//pr_notice("entry_add_rule_param param=%s\n", dst);
return 0;
}

Expand Down Expand Up @@ -602,7 +598,7 @@ read_next_token(TfwCfgParserState *ps)
TOKEN_REGEX_CI);

/* Special case to differ single equal sign from double one. */
TFSM_COND_MOVE(ps->c == '=', TS_EQSIGN);
TFSM_COND_MOVE(ps->c == '=', TS_EQSIGN);
TFSM_COND_MOVE(ps->c == '~', TS_TILDA);

/* Everything else is not a special character and therefore
Expand Down Expand Up @@ -734,7 +730,6 @@ entry_set_cond(TfwCfgEntry *e, token_t cond_type, const char *src, int len)
int name_len = sizeof(TFW_CFG_RULE_NAME) - 1;
TfwCfgRule *rule = &e->rule;

//pr_notice("entry_set_cond cond_type=%u\n", (unsigned int)cond_type);
BUG_ON(!e->ftoken);
BUG_ON(e->name);

Expand All @@ -754,7 +749,6 @@ entry_set_cond(TfwCfgEntry *e, token_t cond_type, const char *src, int len)
if (!(e->name = alloc_and_copy_literal(name, name_len)))
return -ENOMEM;


switch (cond_type) {
case TOKEN_REGEX:
rule->regex = TFW_REGEX_REGULAR;
Expand All @@ -770,7 +764,6 @@ entry_set_cond(TfwCfgEntry *e, token_t cond_type, const char *src, int len)
break;
}


return 0;
}

Expand Down Expand Up @@ -830,24 +823,19 @@ parse_cfg_entry(TfwCfgParserState *ps)
* condition key for rule; in last three cases predefined rule name is used.
*/
FSM_STATE(PS_START_NEW_ENTRY) {

//pr_notice("FSM_STATE(PS_START_NEW_ENTRY)\n");
entry_reset(&ps->e);
ps->e.line_no = ps->line_no;
ps->e.line = ps->line;

PFSM_COND_MOVE(ps->t == TOKEN_ARROW, PS_RULE_PURE_ACTION);

ps->err = entry_set_first_token(&ps->e, ps->lit, ps->lit_len);
//pr_notice("ps->e.ftoken=%s\n", ps->e.ftoken);
FSM_COND_JMP(ps->err, PS_EXIT);

PFSM_MOVE(PS_PLAIN_OR_RULE);
}

FSM_STATE(PS_PLAIN_OR_RULE) {
//pr_notice("FSM_STATE(PS_PLAIN_OR_RULE)\n");
//pr_notice("ps->e.ftoken=%s\n", ps->e.ftoken);
PFSM_COND_MOVE(ps->t == TOKEN_DEQSIGN ||
ps->t == TOKEN_NEQSIGN ||
ps->t == TOKEN_REGEX ||
Expand All @@ -863,7 +851,6 @@ parse_cfg_entry(TfwCfgParserState *ps)
}

FSM_STATE(PS_PLAIN_OR_LONG_RULE) {
//pr_notice("FSM_STATE(PS_PLAIN_OR_LONG_RULE)\n");
FSM_COND_JMP(ps->t == TOKEN_DEQSIGN ||
ps->t == TOKEN_NEQSIGN ||
ps->t == TOKEN_REGEX ||
Expand All @@ -885,7 +872,6 @@ parse_cfg_entry(TfwCfgParserState *ps)
}

FSM_STATE(PS_LONG_RULE_COND) {
//pr_notice("FSM_STATE(PS_LONG_RULE_COND)\n");
ps->err = entry_add_rule_param(&ps->e.rule.fst_ext,
ps->prev_lit,
ps->prev_lit_len);
Expand All @@ -894,9 +880,6 @@ parse_cfg_entry(TfwCfgParserState *ps)
}

FSM_STATE(PS_RULE_COND) {
//pr_notice("FSM_STATE(PS_RULE_COND) ps->t=%u\n", (unsigned)ps->t);
//pr_notice("ps->e.ftoken=%s\n", ps->e.ftoken);

FSM_COND_JMP(ps->prev_t == TOKEN_REGEX ||
ps->prev_t == TOKEN_REGEX_CI,
PS_STORE_VAL_PREV_REGEX);
Expand All @@ -909,20 +892,17 @@ parse_cfg_entry(TfwCfgParserState *ps)
}

FSM_STATE(PS_RULE_COND_END) {
//pr_notice("FSM_STATE(PS_RULE_COND_END)\n");;
PFSM_COND_JMP_EXIT_ERROR(ps->t != TOKEN_ARROW);
PFSM_MOVE(PS_RULE_ACTION);
}

FSM_STATE(PS_RULE_PURE_ACTION) {
//pr_notice("FSM_STATE(PS_RULE_PURE_ACTION)\n");
ps->err = entry_set_name(&ps->e);
FSM_COND_JMP(ps->err, PS_EXIT);
FSM_JMP(PS_RULE_ACTION);
}

FSM_STATE(PS_RULE_ACTION) {
//pr_notice("FSM_STATE(PS_RULE_ACTION)\n");
PFSM_COND_JMP_EXIT_ERROR(ps->t != TOKEN_LITERAL);
ps->err = entry_add_rule_param(&ps->e.rule.act, ps->lit,
ps->lit_len);
Expand All @@ -931,7 +911,6 @@ parse_cfg_entry(TfwCfgParserState *ps)
}

FSM_STATE(PS_RULE_ACTION_VAL) {
//pr_notice("FSM_STATE(PS_RULE_ACTION_VAL)\n");
FSM_COND_JMP(ps->t == TOKEN_SEMICOLON, PS_SEMICOLON);
PFSM_COND_JMP_EXIT_ERROR(ps->t != TOKEN_EQSIGN);
read_next_token(ps);
Expand Down Expand Up @@ -961,7 +940,6 @@ parse_cfg_entry(TfwCfgParserState *ps)
*/

FSM_STATE(PS_VAL_OR_ATTR) {
//pr_notice("FSM_STATE(PS_VAL_OR_ATTR)\n");
PFSM_COND_MOVE(ps->t == TOKEN_LITERAL, PS_MAYBE_EQSIGN);
FSM_COND_JMP(ps->t == TOKEN_SEMICOLON, PS_SEMICOLON);
FSM_COND_JMP(ps->t == TOKEN_LBRACE, PS_LBRACE);
Expand All @@ -971,23 +949,18 @@ parse_cfg_entry(TfwCfgParserState *ps)
}

FSM_STATE(PS_MAYBE_EQSIGN) {
//pr_notice("FSM_STATE(PS_MAYBE_EQSIGN)\n");
FSM_COND_JMP(ps->t == TOKEN_EQSIGN, PS_STORE_ATTR_PREV);
FSM_JMP(PS_STORE_VAL_PREV);
}

FSM_STATE(PS_STORE_VAL_PREV_REGEX) {
//pr_notice("FSM_STATE(PS_STORE_VAL_PREV_REGEX)\n");
/* name val1 val2;
* ^
* We are here (but still need to store val1)
* and name or condition.
*/
T_DBG3("add value: %.*s\n", ps->prev_lit_len, ps->prev_lit);

//pr_notice("prev value: %.*s\n", ps->prev_lit_len, ps->prev_lit);
//pr_notice("cur value: %.*s\n", ps->lit_len, ps->lit);

if (ps->e.ftoken && !strcmp(ps->e.ftoken, "location")) {
ps->err = entry_set_name(&ps->e);

Expand All @@ -1005,7 +978,6 @@ parse_cfg_entry(TfwCfgParserState *ps)
}

/*If it is not location*/
//pr_notice("ps->e.ftoken=%s\n", ps->e.ftoken);
ps->err = entry_set_cond(&ps->e, ps->prev_t,
ps->lit, ps->lit_len);
FSM_COND_JMP(ps->err, PS_EXIT);
Expand All @@ -1014,22 +986,18 @@ parse_cfg_entry(TfwCfgParserState *ps)
}

FSM_STATE(PS_STORE_VAL_PREV) {
//pr_notice("FSM_STATE(PS_STORE_VAL_PREV)\n");
/* name val1 val2;
* ^
* We are here (but still need to store val1). */
T_DBG3("add value: %.*s\n", ps->prev_lit_len, ps->prev_lit);

//pr_notice("prev value: %.*s\n", ps->prev_lit_len, ps->prev_lit);
//pr_notice("cur value: %.*s\n", ps->lit_len, ps->lit);
ps->err = entry_add_val(&ps->e, ps->prev_lit, ps->prev_lit_len);
FSM_COND_JMP(ps->err, PS_EXIT);

FSM_JMP(PS_VAL_OR_ATTR);
}

FSM_STATE(PS_STORE_ATTR_PREV) {
//pr_notice("FSM_STATE(PS_STORE_ATTR_PREV)\n");
/* name key = val;
* ^
* We are here. */
Expand All @@ -1051,7 +1019,6 @@ parse_cfg_entry(TfwCfgParserState *ps)
}

FSM_STATE(PS_LBRACE) {
//pr_notice("FSM_STATE(PS_LBRACE)\n");
/* Simply exit on '{' leaving nested nodes untouched and
* surrounded with braces. The caller should detect it and parse
* them in a loop. */
Expand All @@ -1060,7 +1027,6 @@ parse_cfg_entry(TfwCfgParserState *ps)
}

FSM_STATE(PS_SEMICOLON) {
//pr_notice("FSM_STATE(PS_SEMICOLON)\n");
/* Simply eat ';'. Don't MOVE because the next character may be
* '\0' and that triggers an error (because we expect more input
* tokens when we do _PFSM_MOVE()). */
Expand All @@ -1069,18 +1035,11 @@ parse_cfg_entry(TfwCfgParserState *ps)
}

FSM_STATE(PS_EXIT) {
//pr_notice("FSM_STATE(PS_EXIT)\n");
/* Cleanup of entry is done in tfw_cfg_parse_mods() */

//pr_notice("ps->e.name=%s\n", ps->e.name);
//pr_notice("ps->e.line=%s\n", ps->e.line);


T_DBG3("pfsm: exit\n");
}
}


/*
* ------------------------------------------------------------------------
* Configuration Parser - TfwCfgSpec helpers.
Expand Down
81 changes: 4 additions & 77 deletions fw/http_match.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,99 +86,29 @@ map_op_to_str_eq_flags(tfw_http_match_op_t op)
[TFW_HTTP_MATCH_O_SUFFIX] = TFW_STR_EQ_DEFAULT,
[TFW_HTTP_MATCH_O_REGEX] = TFW_STR_EQ_REGEX,
[TFW_HTTP_MATCH_O_REGEX_CI] = TFW_STR_EQ_REGEX_CASEI,

};
//pr_notice("map_op_to_str_eq_flags op=%u\n", (unsigned int)op);
BUG_ON(flags_tbl[op] < 0);
return flags_tbl[op];
}

extern int bpf_scan_bytes(const void *, __u32, struct rex_scan_attr *);

extern int bpf_scan_vector(const char *const *buf, const unsigned int *length,
__u32 buf__sz, struct rex_scan_attr *attr);
//extern int bpf_scan_bytes(const void *, __u32, struct rex_scan_attr *);

extern int bpf_scan_tfwstr(const TfwStr *str, struct rex_scan_attr *attr);

void printTfwStr(const TfwStr *arg)
{
/*union {
char *data;
struct tfwstr_t *chunks;
};*/

pr_notice("data= %.*s\n", (int)arg->len, arg->data);
pr_notice("str.len=%lu\n", arg->len);
//struct sk_buff *skb;
pr_notice("str.nchunks=%u\n",arg->nchunks);
pr_notice("str.flags=%u\n",(unsigned)arg->flags);
pr_notice("str.hpack_idx=%u\n",(unsigned)arg->hpack_idx);
pr_notice("str.eolen=%u\n",(unsigned)arg->eolen);
pr_notice("==============================\n");
}

bool
tfw_match_regex(tfw_match_t op, const char *cstr, size_t len, const TfwStr *arg)
{
char sss[100];
//char *data[20];
//unsigned int length[20];
//int i = 0;
bool result;
int r;
//const TfwStr *chunk, *end;

struct rex_scan_attr attr = {};
memcpy(&attr.database_id, cstr, sizeof(unsigned short));

pr_notice("test_regex\n");
pr_notice("attr.database_id=%u", attr.database_id);

tfw_str_to_cstr(arg, sss, 100);
pr_notice("arg=%s len=%u", sss, (unsigned)len);


/* if (arg->nchunks == 1) {
pr_notice("solid string\n");
r = bpf_scan_bytes(arg->data, arg->len, &attr);
}
else*/ {
pr_notice("chunked string\n");

if (!arg->len)
return false;

/* TFW_STR_FOR_EACH_CHUNK(chunk, arg, end) {
printTfwStr(chunk);
data[i] = chunk->data;
length[i] = (unsigned int)chunk->len;
++i;
if (i == 20)
break;
}
//r = bpf_scan_bytes(sss, strlen(sss), &attr);
r = bpf_scan_vector((const char *const *)&data,
(const unsigned int *)&length,
i, &attr);*/

r = bpf_scan_tfwstr(arg, &attr);
}

pr_notice("r=%i\n", r);
r = bpf_scan_tfwstr(arg, &attr);
result = (!r && attr.nr_events && attr.last_event.expression);
if (result)
pr_notice("Expression found in pos=%llu\n number=%u",
attr.last_event.to, attr.last_event.expression);
else
pr_notice("Expression not found!");


pr_notice("========================================================\n");
return result;
}

Expand All @@ -187,8 +117,6 @@ tfw_rule_str_match(const TfwStr *str, const char *cstr,
int cstr_len, tfw_str_eq_flags_t flags,
tfw_http_match_op_t op)
{
//pr_notice("tfw_rule_str_match\n");

if (op == TFW_HTTP_MATCH_O_SUFFIX)
return tfw_str_eq_cstr_off(str, str->len - cstr_len,
cstr, cstr_len, flags);
Expand Down Expand Up @@ -836,7 +764,6 @@ write_regex(const char *arg, int regex)
int len = strlen(arg);
int len1;

//pr_notice("write_regex arg=%s\n", arg);
if (len < sizeof(unsigned short)) {
T_ERR_NL("String of regex too short\n");
return -EINVAL;
Expand Down
2 changes: 0 additions & 2 deletions fw/http_tbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ tfw_cfgop_http_rule(TfwCfgSpec *cs, TfwCfgEntry *e)
action_val = cfg_rule->val;
BUG_ON(!action);

//pr_notice("test_chain_add_rule_str in_val=%s in_arg=%s\n", in_val, in_arg);

if (tfw_http_rule_default_exist(&tfw_chain_entry->match_list)) {
T_ERR_NL("http_tbl: default HTTP rule must be only one and "
"last; chain '%s'\n",
Expand Down
Loading

0 comments on commit 28f9eee

Please sign in to comment.