dfilter: Rename "range" to "slice"

The word range is used for different things with different
meanings and that is confusing. Avoid using "range" in code to
mean "slice".

A range is one or more intervals with a lower and upper bound.

A slice is a range applied to a bytes field.

Replace range with slice wherever appropriate. This usage of
"slice" instead of range is generally correct and consistent in
the documentation.
This commit is contained in:
João Valverde 2022-04-11 20:06:49 +01:00 committed by A Wireshark GitLab Utility
parent d517feee74
commit c0170dad42
7 changed files with 48 additions and 47 deletions

View File

@ -41,7 +41,7 @@ dfvm_opcode_tostr(dfvm_opcode_t code)
case ALL_ZERO: return "ALL_ZERO";
case ANY_CONTAINS: return "ANY_CONTAINS";
case ANY_MATCHES: return "ANY_MATCHES";
case MK_RANGE: return "MK_RANGE";
case MK_SLICE: return "MK_SLICE";
case MK_BITWISE_AND: return "MK_BITWISE_AND";
case MK_MINUS: return "MK_MINUS";
case DFVM_ADD: return "DFVM_ADD";
@ -332,8 +332,9 @@ dfvm_dump_str(wmem_allocator_t *alloc, dfilter_t *df, gboolean print_references)
}
break;
case MK_RANGE:
wmem_strbuf_append_printf(buf, "%05d MK_RANGE\t\t%s[%s] -> %s\n",
case MK_SLICE:
arg3 = insn->arg3;
wmem_strbuf_append_printf(buf, "%05d MK_SLICE\t\t%s[%s] -> %s\n",
id, arg1_str, arg3_str, arg2_str);
break;
@ -789,10 +790,10 @@ free_register_overhead(dfilter_t* df)
}
/* Takes the list of fvalue_t's in a register, uses fvalue_slice()
* to make a new list of fvalue_t's (which are ranges, or byte-slices),
* to make a new list of fvalue_t's (which are byte-slices),
* and puts the new list into a new register. */
static void
mk_range(dfilter_t *df, dfvm_value_t *from_arg, dfvm_value_t *to_arg,
mk_slice(dfilter_t *df, dfvm_value_t *from_arg, dfvm_value_t *to_arg,
dfvm_value_t *drange_arg)
{
GSList *from_list, *to_list;
@ -1101,8 +1102,8 @@ dfvm_apply(dfilter_t *df, proto_tree *tree)
stack_pop(df, arg1);
break;
case MK_RANGE:
mk_range(df, arg1, arg2, arg3);
case MK_SLICE:
mk_slice(df, arg1, arg2, arg3);
break;
case ALL_EQ:

View File

@ -67,7 +67,7 @@ typedef enum {
ALL_ZERO,
ANY_CONTAINS,
ANY_MATCHES,
MK_RANGE,
MK_SLICE,
MK_BITWISE_AND,
MK_MINUS,
DFVM_ADD,

View File

@ -176,7 +176,7 @@ dfw_append_read_reference(dfwork_t *dfw, header_field_info *hfinfo)
/* returns register number */
static dfvm_value_t *
dfw_append_mk_range(dfwork_t *dfw, stnode_t *node, GSList **jumps_ptr)
dfw_append_mk_slice(dfwork_t *dfw, stnode_t *node, GSList **jumps_ptr)
{
stnode_t *entity;
dfvm_insn_t *insn;
@ -184,7 +184,7 @@ dfw_append_mk_range(dfwork_t *dfw, stnode_t *node, GSList **jumps_ptr)
entity = sttype_range_entity(node);
insn = dfvm_insn_new(MK_RANGE);
insn = dfvm_insn_new(MK_SLICE);
val1 = gen_entity(dfw, entity, jumps_ptr);
insn->arg1 = dfvm_value_ref(val1);
reg_val = dfvm_value_new_register(dfw->next_register++);
@ -450,8 +450,8 @@ gen_entity(dfwork_t *dfw, stnode_t *st_arg, GSList **jumps_ptr)
else if (e_type == STTYPE_FVALUE) {
val = dfvm_value_new_fvalue(stnode_steal_data(st_arg));
}
else if (e_type == STTYPE_RANGE) {
val = dfw_append_mk_range(dfw, st_arg, jumps_ptr);
else if (e_type == STTYPE_SLICE) {
val = dfw_append_mk_slice(dfw, st_arg, jumps_ptr);
}
else if (e_type == STTYPE_FUNCTION) {
val = dfw_append_function(dfw, st_arg, jumps_ptr);

View File

@ -122,7 +122,7 @@ atom(A) ::= FIELD(F). { A = F; }
atom(A) ::= REFERENCE(F). { A = F; }
entity(E) ::= atom(A). { E = A; }
entity(E) ::= range(R). { E = R; }
entity(E) ::= slice(R). { E = R; }
entity(E) ::= function(F). { E = F; }
arithmetic_expr(T) ::= entity(N).
@ -289,11 +289,11 @@ set_element(N) ::= set_entity(X) DOTDOT set_entity(Y).
N = g_slist_append(N, Y);
}
/* Ranges */
/* Slices */
range(R) ::= entity(E) LBRACKET range_node_list(L) RBRACKET.
slice(R) ::= entity(E) LBRACKET range_node_list(L) RBRACKET.
{
R = stnode_new(STTYPE_RANGE, NULL, NULL, NULL);
R = stnode_new(STTYPE_SLICE, NULL, NULL, NULL);
sttype_range_set(R, E, L);
/* Delete the list, but not the drange_nodes that

View File

@ -516,14 +516,14 @@ check_exists(dfwork_t *dfw, stnode_t *st_arg1)
stnode_todisplay(st_arg1));
break;
case STTYPE_RANGE:
case STTYPE_SLICE:
/*
* XXX - why not? Shouldn't "eth[3:2]" mean
* "check whether the 'eth' field is present and
* has at least 2 bytes starting at an offset of
* 3"?
*/
FAIL(dfw, st_arg1, "You cannot test whether a range is present.");
FAIL(dfw, st_arg1, "You cannot test whether a slice is present.");
break;
case STTYPE_FUNCTION:
@ -545,7 +545,7 @@ check_exists(dfwork_t *dfw, stnode_t *st_arg1)
}
static void
check_drange_sanity(dfwork_t *dfw, stnode_t *st, ftenum_t lhs_ftype)
check_slice_sanity(dfwork_t *dfw, stnode_t *st, ftenum_t lhs_ftype)
{
stnode_t *entity1;
header_field_info *hfinfo1;
@ -572,9 +572,9 @@ check_drange_sanity(dfwork_t *dfw, stnode_t *st, ftenum_t lhs_ftype)
FAIL(dfw, entity1, "Return value of function \"%s\" is a %s and cannot be converted into a sequence of bytes.",
sttype_function_name(entity1), ftype_pretty_name(ftype1));
}
} else if (stnode_type_id(entity1) == STTYPE_RANGE) {
} else if (stnode_type_id(entity1) == STTYPE_SLICE) {
/* Should this be rejected instead? */
check_drange_sanity(dfw, entity1, lhs_ftype);
check_slice_sanity(dfw, entity1, lhs_ftype);
} else {
FAIL(dfw, entity1, "Range is not supported for entity %s",
stnode_todisplay(entity1));
@ -592,7 +592,7 @@ convert_to_bytes(stnode_t *arg)
drange_node_set_start_offset(rn, 0);
drange_node_set_to_the_end(rn);
stnode_replace(arg, STTYPE_RANGE, NULL);
stnode_replace(arg, STTYPE_SLICE, NULL);
sttype_range_set1(arg, entity1, rn);
}
@ -709,8 +709,8 @@ again:
fvalue = dfilter_fvalue_from_charconst(dfw, ftype1, st_arg2);
stnode_replace(st_arg2, STTYPE_FVALUE, fvalue);
}
else if (type2 == STTYPE_RANGE) {
check_drange_sanity(dfw, st_arg2, ftype1);
else if (type2 == STTYPE_SLICE) {
check_slice_sanity(dfw, st_arg2, ftype1);
if (!is_bytes_type(ftype1)) {
if (!ftype_can_slice(ftype1)) {
FAIL(dfw, st_arg1, "\"%s\" is a %s and cannot be converted into a sequence of bytes.",
@ -758,7 +758,7 @@ again:
}
static void
check_relation_LHS_RANGE(dfwork_t *dfw, test_op_t st_op,
check_relation_LHS_SLICE(dfwork_t *dfw, test_op_t st_op,
FtypeCanFunc can_func _U_,
gboolean allow_partial_value,
stnode_t *st_node _U_,
@ -771,7 +771,7 @@ check_relation_LHS_RANGE(dfwork_t *dfw, test_op_t st_op,
LOG_NODE(st_node);
check_drange_sanity(dfw, st_arg1, FT_NONE);
check_slice_sanity(dfw, st_arg1, FT_NONE);
again:
type2 = stnode_type_id(st_arg2);
@ -811,8 +811,8 @@ again:
fvalue = dfilter_fvalue_from_charconst(dfw, FT_BYTES, st_arg2);
stnode_replace(st_arg2, STTYPE_FVALUE, fvalue);
}
else if (type2 == STTYPE_RANGE) {
check_drange_sanity(dfw, st_arg2, FT_BYTES);
else if (type2 == STTYPE_SLICE) {
check_slice_sanity(dfw, st_arg2, FT_BYTES);
}
else if (type2 == STTYPE_FUNCTION) {
ftype2 = check_function(dfw, st_arg2, FT_BYTES);
@ -910,8 +910,8 @@ again:
fvalue = dfilter_fvalue_from_charconst(dfw, ftype1, st_arg2);
stnode_replace(st_arg2, STTYPE_FVALUE, fvalue);
}
else if (type2 == STTYPE_RANGE) {
check_drange_sanity(dfw, st_arg2, ftype1);
else if (type2 == STTYPE_SLICE) {
check_slice_sanity(dfw, st_arg2, ftype1);
if (!is_bytes_type(ftype1)) {
if (!ftype_can_slice(ftype1)) {
FAIL(dfw, st_arg1, "Function \"%s\" is a %s and cannot be converted into a sequence of bytes.",
@ -980,8 +980,8 @@ check_relation_LHS_ARITHMETIC(dfwork_t *dfw, test_op_t st_op _U_,
else if (entity_type == STTYPE_FUNCTION) {
check_relation_LHS_FUNCTION(dfw, st_op, can_func, allow_partial_value, st_node, entity, st_arg2);
}
else if (entity_type == STTYPE_RANGE) {
check_relation_LHS_RANGE(dfw, st_op, can_func, allow_partial_value, st_node, entity, st_arg2);
else if (entity_type == STTYPE_SLICE) {
check_relation_LHS_SLICE(dfw, st_op, can_func, allow_partial_value, st_node, entity, st_arg2);
}
else if (entity_type == STTYPE_ARITHMETIC) {
check_relation_LHS_ARITHMETIC(dfw, st_op, can_func, allow_partial_value, st_node, entity, st_arg2);
@ -1007,8 +1007,8 @@ check_relation(dfwork_t *dfw, test_op_t st_op,
check_relation_LHS_FIELD(dfw, st_op, can_func,
allow_partial_value, st_node, st_arg1, st_arg2);
break;
case STTYPE_RANGE:
check_relation_LHS_RANGE(dfw, st_op, can_func,
case STTYPE_SLICE:
check_relation_LHS_SLICE(dfw, st_op, can_func,
allow_partial_value, st_node, st_arg1, st_arg2);
break;
case STTYPE_FUNCTION:
@ -1043,8 +1043,8 @@ check_relation_contains(dfwork_t *dfw, stnode_t *st_node,
check_relation_LHS_FUNCTION(dfw, TEST_OP_CONTAINS, ftype_can_contains,
TRUE, st_node, st_arg1, st_arg2);
break;
case STTYPE_RANGE:
check_relation_LHS_RANGE(dfw, TEST_OP_CONTAINS, ftype_can_contains,
case STTYPE_SLICE:
check_relation_LHS_SLICE(dfw, TEST_OP_CONTAINS, ftype_can_contains,
TRUE, st_node, st_arg1, st_arg2);
break;
default:
@ -1092,8 +1092,8 @@ check_relation_matches(dfwork_t *dfw, stnode_t *st_node,
check_relation_LHS_FUNCTION(dfw, TEST_OP_MATCHES, ftype_can_matches,
TRUE, st_node, st_arg1, st_arg2);
break;
case STTYPE_RANGE:
check_relation_LHS_RANGE(dfw, TEST_OP_MATCHES, ftype_can_matches,
case STTYPE_SLICE:
check_relation_LHS_SLICE(dfw, TEST_OP_MATCHES, ftype_can_matches,
TRUE, st_node, st_arg1, st_arg2);
break;
default:
@ -1128,8 +1128,8 @@ check_relation_in(dfwork_t *dfw, stnode_t *st_node _U_,
node_left = nodelist->data;
/* Don't let a range on the RHS affect the LHS field. */
if (stnode_type_id(node_left) == STTYPE_RANGE) {
FAIL(dfw, node_left, "A range may not appear inside a set.");
if (stnode_type_id(node_left) == STTYPE_SLICE) {
FAIL(dfw, node_left, "A slice may not appear inside a set.");
break;
}
@ -1231,8 +1231,8 @@ check_arithmetic_entity(dfwork_t *dfw, stnode_t *st_arg, ftenum_t lhs_ftype)
else if (type == STTYPE_FUNCTION) {
ftype = check_function(dfw, st_arg, lhs_ftype);
}
else if (type == STTYPE_RANGE) {
check_drange_sanity(dfw, st_arg, lhs_ftype);
else if (type == STTYPE_SLICE) {
check_slice_sanity(dfw, st_arg, lhs_ftype);
ftype = FT_BYTES;
}

View File

@ -140,16 +140,16 @@ sttype_range_drange(stnode_t *node)
void
sttype_register_range(void)
{
static sttype_t range_type = {
STTYPE_RANGE,
"RANGE",
static sttype_t slice_type = {
STTYPE_SLICE,
"SLICE",
range_new,
range_free,
range_dup,
range_tostr
};
sttype_register(&range_type);
sttype_register(&slice_type);
}
/*

View File

@ -30,7 +30,7 @@ typedef enum {
STTYPE_CHARCONST,
STTYPE_FIELD,
STTYPE_FVALUE,
STTYPE_RANGE,
STTYPE_SLICE,
STTYPE_RANGE_NODE,
STTYPE_FUNCTION,
STTYPE_SET,