summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2016-08-13 02:11:14 +0300
committerTobias Klauser <tklauser@distanz.ch>2016-09-21 09:54:58 +0200
commit8eb426c88c983ae6f81d813b75e8ca9a9a0b07b5 (patch)
tree0abb142d066177c621ec1a9c7ea438776e78c256
parent573b1fff25af70492deb9e59c0b48d77b0c1ed03 (diff)
trafgen: icmpv4: Update csum at runtime if needed
Update csum if any of the ICMPv4 field was changed. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--trafgen_l4.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/trafgen_l4.c b/trafgen_l4.c
index 16346db..89bb252 100644
--- a/trafgen_l4.c
+++ b/trafgen_l4.c
@@ -156,25 +156,37 @@ static void icmpv4_header_init(struct proto_hdr *hdr)
proto_header_fields_add(hdr, icmpv4_fields, array_size(icmpv4_fields));
}
-static void icmpv4_packet_finish(struct proto_hdr *hdr)
+static void icmpv4_csum_update(struct proto_hdr *hdr)
{
struct packet *pkt;
uint16_t csum;
+ if (hdr->is_csum_valid)
+ return;
if (proto_field_is_set(hdr, ICMPV4_CSUM))
return;
- pkt = current_packet();
+ pkt = packet_get(hdr->pkt_id);
+ proto_field_set_default_u16(hdr, ICMPV4_CSUM, 0);
csum = htons(calc_csum(proto_header_ptr(hdr), pkt->len - hdr->pkt_offset));
- proto_field_set_u16(hdr, ICMPV4_CSUM, bswap_16(csum));
+ proto_field_set_default_u16(hdr, ICMPV4_CSUM, bswap_16(csum));
+
+ hdr->is_csum_valid = true;
+}
+
+static void icmpv4_field_changed(struct proto_field *field)
+{
+ field->hdr->is_csum_valid = false;
}
static const struct proto_ops icmpv4_proto_ops = {
.id = PROTO_ICMP4,
.layer = PROTO_L4,
.header_init = icmpv4_header_init,
- .packet_finish = icmpv4_packet_finish,
+ .packet_update = icmpv4_csum_update,
+ .packet_finish = icmpv4_csum_update,
+ .field_changed = icmpv4_field_changed,
};
static struct proto_field icmpv6_fields[] = {