Added proto_upper_header() function to fetch upper proto header.

It will be used by IPv4/IPv6 proto header to notify UDP/TCP proto
headers to invalidate L4 csum when L3 pseudo header field was changed.

Signed-off-by: Vadim Kochan <vadi...@gmail.com>
---
 trafgen_proto.c | 12 ++++++++++++
 trafgen_proto.h |  1 +
 2 files changed, 13 insertions(+)

diff --git a/trafgen_proto.c b/trafgen_proto.c
index b0a198f..f4b2828 100644
--- a/trafgen_proto.c
+++ b/trafgen_proto.c
@@ -40,6 +40,18 @@ struct proto_hdr *proto_lower_header(struct proto_hdr *hdr)
        return headers[hdr->index - 1];
 }
 
+struct proto_hdr *proto_upper_header(struct proto_hdr *hdr)
+{
+       struct packet *pkt = packet_get(hdr->pkt_id);
+       struct proto_hdr **headers = &pkt->headers[0];
+       size_t headers_count = pkt->headers_count;
+
+       if (hdr->index == headers_count - 1)
+               return NULL;
+
+       return headers[hdr->index + 1];
+}
+
 uint8_t *proto_header_ptr(struct proto_hdr *hdr)
 {
        return &packet_get(hdr->pkt_id)->payload[hdr->pkt_offset];
diff --git a/trafgen_proto.h b/trafgen_proto.h
index f9f4e13..577a230 100644
--- a/trafgen_proto.h
+++ b/trafgen_proto.h
@@ -95,6 +95,7 @@ extern struct proto_hdr *proto_lower_default_add(struct 
proto_hdr *hdr,
                                                 enum proto_id pid);
 
 extern struct proto_hdr *proto_lower_header(struct proto_hdr *hdr);
+extern struct proto_hdr *proto_upper_header(struct proto_hdr *hdr);
 extern uint8_t *proto_header_ptr(struct proto_hdr *hdr);
 
 extern void proto_header_fields_add(struct proto_hdr *hdr,
-- 
2.9.2

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to netsniff-ng+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to