diff options
author | Vadim Kochan <vadim4j@gmail.com> | 2016-07-26 22:35:07 +0300 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-08-02 16:11:19 +0200 |
commit | 59e69bf9106e6f085f90cb33ac7241e3ded41767 (patch) | |
tree | 95d82ae7f5205972ff8b74f7f1f4b258138d3e88 /trafgen_proto.c | |
parent | a378db32a6e88a04d839bf2c2f27f62d81986186 (diff) |
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 <vadim4j@gmail.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_proto.c')
-rw-r--r-- | trafgen_proto.c | 13 |
1 files changed, 7 insertions, 6 deletions
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) |