On 2016-07-26 at 21:35:18 +0200, Vadim Kochan <[email protected]> wrote:
> Add 'dinc()' function in 'field_expr' rules to be used for dynamically
> incrementing of any specified field:
>
> SYNTAX := dinc() | dinc(inc) | dinc(min, max) | dinc(inc, min, max)
This should definitely follow the same parameter order as the existing
dinc() function!!!
> EXAMPLES:
> { udp(sport=dinc() }
> { udp(sport=dinc(1) }
> { udp(sport=dinc(5, 100, 125) }
> Signed-off-by: Vadim Kochan <[email protected]>
> ---
> trafgen_parser.y | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 51 insertions(+)
>
> diff --git a/trafgen_parser.y b/trafgen_parser.y
> index 58ac999..7872b7c 100644
> --- a/trafgen_parser.y
> +++ b/trafgen_parser.y
> @@ -74,6 +74,7 @@ enum field_expr_type_t {
> FIELD_EXPR_MAC,
> FIELD_EXPR_IP4_ADDR,
> FIELD_EXPR_IP6_ADDR,
> + FIELD_EXPR_INC,
> };
>
> struct proto_field_expr {
> @@ -85,6 +86,7 @@ struct proto_field_expr {
> struct in6_addr ip6_addr;
> long long int number;
> uint8_t bytes[256];
> + struct proto_field_func func;
> } val;
> };
>
> @@ -125,6 +127,12 @@ static inline void __init_new_csum_slot(struct
> packet_dyn *slot)
> slot->slen = 0;
> }
>
> +static inline void __init_new_fields_slot(struct packet_dyn *slot)
> +{
> + slot->fields = NULL;
> + slot->flen = 0;
> +}
> +
> static inline void __setup_new_counter(struct counter *c, uint8_t start,
> uint8_t stop, uint8_t stepping,
> int type)
> @@ -167,6 +175,7 @@ static void realloc_packet(void)
> __init_new_counter_slot(&packet_dyn[packetd_last]);
> __init_new_randomizer_slot(&packet_dyn[packetd_last]);
> __init_new_csum_slot(&packet_dyn[packetd_last]);
> + __init_new_fields_slot(&packet_dyn[packetd_last]);
> }
>
> struct packet *current_packet(void)
> @@ -376,6 +385,19 @@ static void proto_field_set(uint32_t fid)
> field_expr.field = proto_field_by_id(hdr, fid);
> }
>
> +static void proto_field_func_setup(struct proto_field *field, struct
> proto_field_func *func)
> +{
> + struct packet_dyn *pkt_dyn;
> +
> + proto_field_func_add(field->hdr, field->id, func);
> +
> + pkt_dyn = &packet_dyn[packetd_last];
> + pkt_dyn->flen++;
> + pkt_dyn->fields = (struct proto_field **)xrealloc(pkt_dyn->fields,
> pkt_dyn->flen *
> + sizeof(struct proto_field *));
No need to case the return value of xrealloc()
> + pkt_dyn->fields[pkt_dyn->flen - 1] = field;
> +}
> +
> static void proto_field_expr_eval(void)
> {
> struct proto_field *field = field_expr.field;
> @@ -405,6 +427,14 @@ static void proto_field_expr_eval(void)
> (uint8_t *)&field_expr.val.ip6_addr.s6_addr);
> break;
>
> + case FIELD_EXPR_INC:
> + if (field_expr.val.func.min > field_expr.val.func.max)
> + panic("dinc(): min(%u) can't be greater than max(%u)\n",
> + field_expr.val.func.min,
> field_expr.val.func.max);
> +
> + proto_field_func_setup(field, &field_expr.val.func);
> + break;
> +
> case FIELD_EXPR_UNKNOWN:
> default:
> bug();
> @@ -685,6 +715,26 @@ field_expr
> field_expr.val.ip4_addr = $1; }
> | ip6_addr { field_expr.type = FIELD_EXPR_IP6_ADDR;
> field_expr.val.ip6_addr = $1; }
> + | K_DINC '(' ')' { field_expr.type = FIELD_EXPR_INC;
> + field_expr.val.func.type = PROTO_FIELD_FUNC_INC;
> + field_expr.val.func.inc = 1; }
> + | K_DINC '(' number ')'
> + { field_expr.type = FIELD_EXPR_INC;
> + field_expr.val.func.inc = $3; }
> + | K_DINC '(' number delimiter number ')'
> + { field_expr.type = FIELD_EXPR_INC;
> + field_expr.val.func.type = PROTO_FIELD_FUNC_INC;
> + field_expr.val.func.type |= PROTO_FIELD_FUNC_MIN;
> + field_expr.val.func.inc = 1;
> + field_expr.val.func.min = $3;
> + field_expr.val.func.max = $5; }
> + | K_DINC '(' number delimiter number delimiter number ')'
> + { field_expr.type = FIELD_EXPR_INC;
> + field_expr.val.func.type = PROTO_FIELD_FUNC_INC;
> + field_expr.val.func.type |= PROTO_FIELD_FUNC_MIN;
> + field_expr.val.func.inc = $3;
> + field_expr.val.func.min = $5;
> + field_expr.val.func.max = $7; }
> ;
>
> eth_proto
> @@ -1097,6 +1147,7 @@ void cleanup_packets(void)
> for (i = 0; i < dlen; ++i) {
> free(packet_dyn[i].cnt);
> free(packet_dyn[i].rnd);
> + free(packet_dyn[i].fields);
> }
>
> free(packet_dyn);
> --
> 2.6.3
>
--
You received this message because you are subscribed to the Google Groups
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.