summaryrefslogtreecommitdiff
path: root/trafgen_proto.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2016-02-01 19:01:36 +0200
committerTobias Klauser <tklauser@distanz.ch>2016-02-02 16:54:47 +0100
commit826a16efdd760930eb2cb21ae80c49a9d7d096f4 (patch)
tree510678994d09274375dec50ac20818924aececcf /trafgen_proto.c
parent88b359d2aa7e3a2bcbe166ca39d93cfd7e04ef08 (diff)
trafgen: proto: Add set_next_proto callback to struct proto_hdr
Add set_next_proto callback to proto_hdr struct to allow lower protocol set next protocol id by enum proto_id. Extended proto_lower_default_add(...) function to take upper protocol to delegate it's id to lower protocol to set next protocol field. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_proto.c')
-rw-r--r--trafgen_proto.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/trafgen_proto.c b/trafgen_proto.c
index 37cbab6..c6b9e2e 100644
--- a/trafgen_proto.c
+++ b/trafgen_proto.c
@@ -155,18 +155,27 @@ void proto_header_finish(struct proto_hdr *hdr)
hdr->header_finish(hdr);
}
-struct proto_hdr *proto_lower_default_add(enum proto_id pid)
+struct proto_hdr *proto_lower_default_add(struct proto_hdr *hdr,
+ enum proto_id pid)
{
+ struct proto_hdr *current;
+
if (headers_count > 0) {
- struct proto_hdr *current = proto_current_header();
+ current = proto_current_header();
if (current->layer >= proto_header_by_id(pid)->layer)
- return current;
+ goto set_proto;
if (current->id == pid)
- return current;
+ goto set_proto;
}
- return proto_header_init(pid);
+ current = proto_header_init(pid);
+
+set_proto:
+ if (current->set_next_proto)
+ current->set_next_proto(current, hdr->id);
+
+ return current;
}
static void __proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,