diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2016-12-18 11:52:45 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-12-21 16:54:47 +0100 |
commit | d084e7ab35438619bfd414ab9a605c64e6e83817 (patch) | |
tree | 696ee9c75a29a9f39127773922c359245ce0dea6 | |
parent | d7ef402f03369f1c1c1bd302edad449e0f7bf37d (diff) |
trafgen: proto: Change __proto_field_set_bytes(...) to take struct proto_field
Change __proto_field_set_bytes(...) function to take struct proto_field
instead of doing lookup by hdr & fid.
It is needed to able use this function with some custom
modified struct proto_field (len, pkt_offset).
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r-- | trafgen_proto.c | 50 |
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) |