From 59e69bf9106e6f085f90cb33ac7241e3ded41767 Mon Sep 17 00:00:00 2001 From: Vadim Kochan Date: Tue, 26 Jul 2016 22:35:07 +0300 Subject: trafgen: proto: Reference to packet from struct proto_hdr Using of current_packet() is not possible for dynamically updated fields so we need to keep the packet index in proto_hdr struct to reference the correct packet. Signed-off-by: Vadim Kochan Signed-off-by: Tobias Klauser --- trafgen_proto.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'trafgen_proto.c') diff --git a/trafgen_proto.c b/trafgen_proto.c index cb0c6ae..e5b1ad3 100644 --- a/trafgen_proto.c +++ b/trafgen_proto.c @@ -49,7 +49,7 @@ struct proto_hdr *proto_lower_header(struct proto_hdr *hdr) uint8_t *proto_header_ptr(struct proto_hdr *hdr) { - return ¤t_packet()->payload[hdr->pkt_offset]; + return &packet_get(hdr->pkt_id)->payload[hdr->pkt_offset]; } static struct proto_hdr *proto_header_by_id(enum proto_id id) @@ -81,7 +81,7 @@ static void proto_fields_realloc(struct proto_hdr *hdr, size_t count) void proto_header_fields_add(struct proto_hdr *hdr, const struct proto_field *fields, size_t count) { - struct packet *pkt = current_packet(); + struct packet *pkt = packet_get(hdr->pkt_id); struct proto_field *f; int i; @@ -99,6 +99,7 @@ void proto_header_fields_add(struct proto_hdr *hdr, f->shift = fields[i].shift; f->mask = fields[i].mask; f->pkt_offset = hdr->pkt_offset + fields[i].offset; + f->hdr = hdr; if (f->pkt_offset + f->len > pkt->len) { hdr->len += f->len; @@ -135,6 +136,8 @@ struct proto_hdr *proto_header_init(enum proto_id pid) new_hdr = xmalloc(sizeof(*new_hdr)); memcpy(new_hdr, hdr, sizeof(*new_hdr)); + new_hdr->pkt_id = current_packet_id(); + if (new_hdr->header_init) new_hdr->header_init(new_hdr); @@ -187,7 +190,7 @@ static void __proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid, if (is_default && field->is_set) return; - payload = ¤t_packet()->payload[field->pkt_offset]; + payload = &packet_get(hdr->pkt_id)->payload[field->pkt_offset]; if (field->len == 1) { p8 = payload; @@ -232,9 +235,7 @@ void proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid, uint8_t *bytes) static uint8_t *__proto_field_get_bytes(struct proto_field *field) { - struct packet *pkt = current_packet(); - - return &pkt->payload[field->pkt_offset]; + return &packet_get(field->hdr->pkt_id)->payload[field->pkt_offset]; } void proto_field_set_u8(struct proto_hdr *hdr, uint32_t fid, uint8_t val) -- cgit v1.2.3-54-g00ecf