diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2016-12-18 11:52:49 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-12-21 16:57:53 +0100 |
commit | 647b7b76d63f8c847b17495e6ad24dc3b256899f (patch) | |
tree | 4d4d488a0f65118cdaf45f381277408b9797364a /trafgen_proto.c | |
parent | 44e97b2009dc2bee93f25684b274f458f50ea667 (diff) |
trafgen: parser: Allow to set function at field offset
Extend proto field expression to:
proto_field[{index}:{len}] = {func}
which allows to specify function on the field offset via index
and value length (default is 1 - 1 byte). This rule is optional.
It was needed to keep of proto_field's copies in packet_dyn->fields
instead of original fields which allows to scpecify different functions
on the different parts of same field, also the copy of original
proto_field allows to set custom length/pkt_offset which makes such
field behave as virtual sub-field of the original one with different
length/pkt_offset but point to the same piece of header.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_proto.c')
-rw-r--r-- | trafgen_proto.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/trafgen_proto.c b/trafgen_proto.c index e2b80d4..88e0846 100644 --- a/trafgen_proto.c +++ b/trafgen_proto.c @@ -532,11 +532,11 @@ static inline uint32_t field_inc(struct proto_field *field) static void field_inc_func(struct proto_field *field) { if (field->len == 1) { - proto_hdr_field_set_u8(field->hdr, field->id, field_inc(field)); + proto_field_set_u8(field, field_inc(field)); } else if (field->len == 2) { - proto_hdr_field_set_be16(field->hdr, field->id, field_inc(field)); + proto_field_set_be16(field, field_inc(field)); } else if (field->len == 4) { - proto_hdr_field_set_be32(field->hdr, field->id, field_inc(field)); + proto_field_set_be32(field, field_inc(field)); } else if (field->len > 4) { uint8_t *bytes = __proto_field_get_bytes(field); @@ -554,14 +554,11 @@ static inline uint32_t field_rand(struct proto_field *field) static void field_rnd_func(struct proto_field *field) { if (field->len == 1) { - proto_hdr_field_set_u8(field->hdr, field->id, - (uint8_t) field_rand(field)); + proto_field_set_u8(field, (uint8_t) field_rand(field)); } else if (field->len == 2) { - proto_hdr_field_set_be16(field->hdr, field->id, - (uint16_t) field_rand(field)); + proto_field_set_be16(field, (uint16_t) field_rand(field)); } else if (field->len == 4) { - proto_hdr_field_set_be32(field->hdr, field->id, - (uint32_t) field_rand(field)); + proto_field_set_be32(field, (uint32_t) field_rand(field)); } else if (field->len > 4) { uint8_t *bytes = __proto_field_get_bytes(field); uint32_t i; @@ -571,11 +568,9 @@ static void field_rnd_func(struct proto_field *field) } } -void proto_hdr_field_func_add(struct proto_hdr *hdr, uint32_t fid, - struct proto_field_func *func) +void proto_field_func_add(struct proto_field *field, + struct proto_field_func *func) { - struct proto_field *field = proto_hdr_field_by_id(hdr, fid); - bug_on(!func); field->func.update_field = func->update_field; @@ -588,11 +583,11 @@ void proto_hdr_field_func_add(struct proto_hdr *hdr, uint32_t fid, if (func->type & PROTO_FIELD_FUNC_MIN) field->func.val = func->min; else if (field->len == 1) - field->func.val = proto_hdr_field_get_u8(hdr, fid); + field->func.val = proto_field_get_u8(field); else if (field->len == 2) - field->func.val = proto_hdr_field_get_u16(hdr, fid); + field->func.val = proto_field_get_u16(field); else if (field->len == 4) - field->func.val = proto_hdr_field_get_u32(hdr, fid); + field->func.val = proto_field_get_u32(field); else if (field->len > 4) { uint8_t *bytes = __proto_field_get_bytes(field); |