From 826a16efdd760930eb2cb21ae80c49a9d7d096f4 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Mon, 1 Feb 2016 19:01:36 +0200 Subject: 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 Signed-off-by: Tobias Klauser --- trafgen_proto.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'trafgen_proto.c') 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, -- cgit v1.2.3-54-g00ecf