summaryrefslogtreecommitdiff
path: root/trafgen_proto.c
diff options
context:
space:
mode:
Diffstat (limited to 'trafgen_proto.c')
-rw-r--r--trafgen_proto.c50
1 files changed, 33 insertions, 17 deletions
diff --git a/trafgen_proto.c b/trafgen_proto.c
index 62ac831..05fccb2 100644
--- a/trafgen_proto.c
+++ b/trafgen_proto.c
@@ -181,11 +181,10 @@ set_proto:
return current;
}
-static void __proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,
+static void __proto_field_set_bytes(struct proto_field *field,
const uint8_t *bytes, bool is_default,
bool is_be)
{
- struct proto_field *field;
uint8_t *payload, *p8;
uint16_t *p16;
uint32_t *p32;
@@ -193,12 +192,10 @@ static void __proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,
uint16_t v16;
uint8_t v8;
- field = proto_field_by_id(hdr, fid);
-
if (is_default && field->is_set)
return;
- payload = &packet_get(hdr->pkt_id)->payload[field->pkt_offset];
+ payload = &packet_get(field->hdr->pkt_id)->payload[field->pkt_offset];
if (field->len == 1) {
p8 = payload;
@@ -239,7 +236,7 @@ static void __proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,
void proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,
const uint8_t *bytes)
{
- __proto_field_set_bytes(hdr, fid, bytes, false, false);
+ __proto_field_set_bytes(proto_field_by_id(hdr, fid), bytes, false, false);
}
static uint8_t *__proto_field_get_bytes(struct proto_field *field)
@@ -289,47 +286,64 @@ uint32_t proto_field_get_u32(struct proto_hdr *hdr, uint32_t fid)
void proto_field_set_default_bytes(struct proto_hdr *hdr, uint32_t fid,
const uint8_t *bytes)
{
- __proto_field_set_bytes(hdr, fid, bytes, true, false);
+ struct proto_field *field = proto_field_by_id(hdr, fid);
+
+ __proto_field_set_bytes(field, bytes, true, false);
}
void proto_field_set_default_u8(struct proto_hdr *hdr, uint32_t fid, uint8_t val)
{
- __proto_field_set_bytes(hdr, fid, (uint8_t *)&val, true, false);
+ struct proto_field *field = proto_field_by_id(hdr, fid);
+
+ __proto_field_set_bytes(field, (uint8_t *)&val, true, false);
}
void proto_field_set_default_u16(struct proto_hdr *hdr, uint32_t fid, uint16_t val)
{
- __proto_field_set_bytes(hdr, fid, (uint8_t *)&val, true, false);
+ struct proto_field *field = proto_field_by_id(hdr, fid);
+
+ __proto_field_set_bytes(field, (uint8_t *)&val, true, false);
}
void proto_field_set_default_u32(struct proto_hdr *hdr, uint32_t fid, uint32_t val)
{
- __proto_field_set_bytes(hdr, fid, (uint8_t *)&val, true, false);
+ struct proto_field *field = proto_field_by_id(hdr, fid);
+
+ __proto_field_set_bytes(field, (uint8_t *)&val, true, false);
}
void proto_field_set_be16(struct proto_hdr *hdr, uint32_t fid, uint16_t val)
{
- __proto_field_set_bytes(hdr, fid, (uint8_t *)&val, false, true);
+ struct proto_field *field = proto_field_by_id(hdr, fid);
+
+ __proto_field_set_bytes(field, (uint8_t *)&val, false, true);
}
void proto_field_set_be32(struct proto_hdr *hdr, uint32_t fid, uint32_t val)
{
- __proto_field_set_bytes(hdr, fid, (uint8_t *)&val, false, true);
+ struct proto_field *field = proto_field_by_id(hdr, fid);
+
+ __proto_field_set_bytes(field, (uint8_t *)&val, false, true);
}
void proto_field_set_default_be16(struct proto_hdr *hdr, uint32_t fid, uint16_t val)
{
- __proto_field_set_bytes(hdr, fid, (uint8_t *)&val, true, true);
+ struct proto_field *field = proto_field_by_id(hdr, fid);
+
+ __proto_field_set_bytes(field, (uint8_t *)&val, true, true);
}
void proto_field_set_default_be32(struct proto_hdr *hdr, uint32_t fid, uint32_t val)
{
- __proto_field_set_bytes(hdr, fid, (uint8_t *)&val, true, true);
+ struct proto_field *field = proto_field_by_id(hdr, fid);
+
+ __proto_field_set_bytes(field, (uint8_t *)&val, true, true);
}
static void __proto_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid,
bool is_default)
{
+ struct proto_field *field = proto_field_by_id(hdr, fid);
uint8_t mac[ETH_ALEN];
int ret;
@@ -340,7 +354,7 @@ static void __proto_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid,
if (ret < 0)
panic("Could not get device hw address\n");
- __proto_field_set_bytes(hdr, fid, mac, is_default, false);
+ __proto_field_set_bytes(field, mac, is_default, false);
}
void proto_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid)
@@ -356,6 +370,7 @@ void proto_field_set_default_dev_mac(struct proto_hdr *hdr, uint32_t fid)
static void __proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid,
bool is_default)
{
+ struct proto_field *field = proto_field_by_id(hdr, fid);
struct sockaddr_storage ss = { };
struct sockaddr_in *ss4;
int ret;
@@ -370,7 +385,7 @@ static void __proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid,
}
ss4 = (struct sockaddr_in *) &ss;
- __proto_field_set_bytes(hdr, fid, (uint8_t *)&ss4->sin_addr.s_addr, is_default, false);
+ __proto_field_set_bytes(field, (uint8_t *)&ss4->sin_addr.s_addr, is_default, false);
}
void proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid)
@@ -386,6 +401,7 @@ void proto_field_set_default_dev_ipv4(struct proto_hdr *hdr, uint32_t fid)
static void __proto_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid,
bool is_default)
{
+ struct proto_field *field = proto_field_by_id(hdr, fid);
struct sockaddr_storage ss = { };
struct sockaddr_in6 *ss6;
int ret;
@@ -400,7 +416,7 @@ static void __proto_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid,
}
ss6 = (struct sockaddr_in6 *) &ss;
- __proto_field_set_bytes(hdr, fid, (uint8_t *)&ss6->sin6_addr.s6_addr, is_default, false);
+ __proto_field_set_bytes(field, (uint8_t *)&ss6->sin6_addr.s6_addr, is_default, false);
}
void proto_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid)