summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--trafgen_parser.y13
-rw-r--r--trafgen_proto.c5
-rw-r--r--trafgen_proto.h1
3 files changed, 12 insertions, 7 deletions
diff --git a/trafgen_parser.y b/trafgen_parser.y
index 40cd311..5a61a3f 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -425,20 +425,19 @@ static void proto_field_expr_eval(void)
if (field_expr.type & FIELD_EXPR_NUMB) {
if (field->len == 1)
- proto_hdr_field_set_u8(hdr, field->id, field_expr.val.number);
+ proto_field_set_u8(field, field_expr.val.number);
else if (field->len == 2)
- proto_hdr_field_set_be16(hdr, field->id, field_expr.val.number);
+ proto_field_set_be16(field, field_expr.val.number);
else if (field->len == 4)
- proto_hdr_field_set_be32(hdr, field->id, field_expr.val.number);
+ proto_field_set_be32(field, field_expr.val.number);
else
panic("Invalid value length %zu, can be 1,2 or 4\n", field->len);
} else if (field_expr.type & FIELD_EXPR_MAC) {
- proto_hdr_field_set_bytes(hdr, field->id, field_expr.val.mac);
+ proto_field_set_bytes(field, field_expr.val.mac);
} else if (field_expr.type & FIELD_EXPR_IP4_ADDR) {
- proto_hdr_field_set_u32(hdr, field->id, field_expr.val.ip4_addr.s_addr);
+ proto_field_set_u32(field, field_expr.val.ip4_addr.s_addr);
} else if (field_expr.type & FIELD_EXPR_IP6_ADDR) {
- proto_hdr_field_set_bytes(hdr, field->id,
- (uint8_t *)&field_expr.val.ip6_addr.s6_addr);
+ proto_field_set_bytes(field, (uint8_t *)&field_expr.val.ip6_addr.s6_addr);
} else if ((field_expr.type & FIELD_EXPR_INC) ||
(field_expr.type & FIELD_EXPR_RND)) {
diff --git a/trafgen_proto.c b/trafgen_proto.c
index 5fd9e1c..b802a3a 100644
--- a/trafgen_proto.c
+++ b/trafgen_proto.c
@@ -477,6 +477,11 @@ void proto_field_set_be32(struct proto_field *field, uint32_t val)
__proto_field_set_bytes(field, (uint8_t *)&val, false, true);
}
+void proto_field_set_bytes(struct proto_field *field, const uint8_t *bytes)
+{
+ __proto_field_set_bytes(field, bytes, false, false);
+}
+
void protos_init(const char *dev)
{
ctx.dev = dev;
diff --git a/trafgen_proto.h b/trafgen_proto.h
index d863287..56e7271 100644
--- a/trafgen_proto.h
+++ b/trafgen_proto.h
@@ -155,6 +155,7 @@ extern void proto_field_set_u32(struct proto_field *field, uint32_t val);
extern uint32_t proto_field_get_u32(struct proto_field *field);
extern void proto_field_set_be16(struct proto_field *field, uint16_t val);
extern void proto_field_set_be32(struct proto_field *field, uint32_t val);
+extern void proto_field_set_bytes(struct proto_field *field, const uint8_t *bytes);
extern void proto_field_func_add(struct proto_field *field,
struct proto_field_func *func);