diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2017-07-29 12:46:07 +0300 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2017-08-10 09:03:29 +0200 |
commit | d55874b960a8663cc86284fad4d0472ff37b7a7e (patch) | |
tree | 986e609f494dc1047d6b50b6ffc10da17b03f370 /trafgen_proto.c | |
parent | a5a6c39b90b1d12d67b5c166cf873a99faf0a05a (diff) |
trafgen: Get packet from proto_hdr if possible
Replace using current_packet() by new proto_hdr_packet(hdr)
function to obtain packet directly from header. This is more
generic and flexible way, because it guarantees that packet really
belongs to the header, which in case in current_packet() is not right
because it means getting of last allocated packet.
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.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/trafgen_proto.c b/trafgen_proto.c index c2cbffb..1d978e3 100644 --- a/trafgen_proto.c +++ b/trafgen_proto.c @@ -30,6 +30,11 @@ static struct ctx ctx; static const struct proto_ops *registered_ops[__PROTO_MAX]; +struct packet *proto_hdr_packet(struct proto_hdr *hdr) +{ + return packet_get(hdr->pkt_id); +} + struct proto_hdr *proto_lower_header(struct proto_hdr *hdr) { struct packet *pkt = packet_get(hdr->pkt_id); @@ -266,12 +271,13 @@ void proto_hdr_move_sub_header(struct proto_hdr *hdr, struct proto_hdr *from, struct proto_hdr *proto_lower_default_add(struct proto_hdr *upper, enum proto_id pid) { + struct packet *pkt = proto_hdr_packet(upper); + size_t headers_count = pkt->headers_count; struct proto_hdr *current; - size_t headers_count = current_packet()->headers_count; const struct proto_ops *ops; if (headers_count > 0) { - current = current_packet()->headers[headers_count - 1]; + current = pkt->headers[headers_count - 1]; ops = current->ops; if (ops->layer >= proto_ops_by_id(pid)->layer) |