From 88b359d2aa7e3a2bcbe166ca39d93cfd7e04ef08 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Mon, 1 Feb 2016 19:01:35 +0200 Subject: trafgen: proto: Simplify getting lower protocol after init Change proto_header_init(...) and proto_lower_default_add(...) functions to return struct proto_hdr * to do not call proto_current_header(...) after, so it makes more sense to get struct proto_hdr * right after initializing protocol by id. Signed-off-by: Vadim Kochan Signed-off-by: Tobias Klauser --- trafgen_proto.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'trafgen_proto.c') diff --git a/trafgen_proto.c b/trafgen_proto.c index 3cbf34e..37cbab6 100644 --- a/trafgen_proto.c +++ b/trafgen_proto.c @@ -131,7 +131,7 @@ bool proto_field_is_set(struct proto_hdr *hdr, uint32_t fid) return field ? field->is_set : false; } -void proto_header_init(enum proto_id pid) +struct proto_hdr *proto_header_init(enum proto_id pid) { struct proto_hdr *hdr = proto_header_by_id(pid); struct proto_hdr *new_hdr; @@ -146,6 +146,7 @@ void proto_header_init(enum proto_id pid) new_hdr->header_init(new_hdr); headers[headers_count++] = new_hdr; + return new_hdr; } void proto_header_finish(struct proto_hdr *hdr) @@ -154,16 +155,18 @@ void proto_header_finish(struct proto_hdr *hdr) hdr->header_finish(hdr); } -void proto_lower_default_add(enum proto_id pid) +struct proto_hdr *proto_lower_default_add(enum proto_id pid) { if (headers_count > 0) { - if (proto_current_header()->layer >= proto_header_by_id(pid)->layer) - return; - if (proto_current_header()->id == pid) - return; + struct proto_hdr *current = proto_current_header(); + + if (current->layer >= proto_header_by_id(pid)->layer) + return current; + if (current->id == pid) + return current; } - proto_header_init(pid); + return proto_header_init(pid); } static void __proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid, -- cgit v1.2.3-54-g00ecf