summaryrefslogtreecommitdiff
path: root/trafgen_l3.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2016-08-13 02:11:18 +0300
committerTobias Klauser <tklauser@distanz.ch>2016-09-21 09:56:55 +0200
commit553a9c65beeb77072f08e4d8cd876b062dcdb193 (patch)
treebfd6b45eb220a1dc0168ff879780667a58bfd2b8 /trafgen_l3.c
parent88169061a70a2363f503f14e686e2b070e6e63ef (diff)
trafgen: udp: Update csum at runtime if needed
Update UDP csum field at runtime if: 1) UDP field was changed. 2) IPv4/6 source/destination addresses were changed (which is a part of UDP pseudo header), this is handled by IPv4/6 protocols. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_l3.c')
-rw-r--r--trafgen_l3.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/trafgen_l3.c b/trafgen_l3.c
index 9bb0de9..91052a0 100644
--- a/trafgen_l3.c
+++ b/trafgen_l3.c
@@ -46,6 +46,13 @@ static void ipv4_header_init(struct proto_hdr *hdr)
static void ipv4_field_changed(struct proto_field *field)
{
field->hdr->is_csum_valid = false;
+
+ if (field->id == IP4_SADDR || field->id == IP4_DADDR) {
+ struct proto_hdr *upper = proto_upper_header(field->hdr);
+
+ if (upper && upper->ops->id == PROTO_UDP)
+ upper->is_csum_valid = false;
+ }
}
static void ipv4_csum_update(struct proto_hdr *hdr)
@@ -136,6 +143,16 @@ static void ipv6_header_init(struct proto_hdr *hdr)
proto_field_set_default_dev_ipv6(hdr, IP6_SADDR);
}
+static void ipv6_field_changed(struct proto_field *field)
+{
+ if (field->id == IP6_SADDR || field->id == IP6_DADDR) {
+ struct proto_hdr *upper = proto_upper_header(field->hdr);
+
+ if (upper && upper->ops->id == PROTO_UDP)
+ upper->is_csum_valid = false;
+ }
+}
+
#define IPV6_HDR_LEN 40
static void ipv6_packet_finish(struct proto_hdr *hdr)
@@ -171,6 +188,7 @@ static const struct proto_ops ipv6_proto_ops = {
.id = PROTO_IP6,
.layer = PROTO_L3,
.header_init = ipv6_header_init,
+ .field_changed = ipv6_field_changed,
.packet_finish = ipv6_packet_finish,
.set_next_proto = ipv6_set_next_proto,
};