summaryrefslogtreecommitdiff
path: root/trafgen_proto.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2016-08-13 02:11:10 +0300
committerTobias Klauser <tklauser@distanz.ch>2016-09-21 09:50:06 +0200
commite7dd63060e448bf6667c92a3b774cec0feeff452 (patch)
treec00b4dfe777d74b60cf6c4f6141a45c0a3176f48 /trafgen_proto.c
parent6197f02044e2fe6689b52dad0a0c75bdc0eb185b (diff)
trafgen: proto: Update field value at runtime
Add basic infrastructure for update proto field value at runtime by dynamic field function. Extended 'struct packet_dyn' with proto fields which has dynamically changing values at runtime. Added 'field_changed' callback for proto header which may be used for check if csum updating is needed. This callback is called after field was changed at runtime. Added 'packet_update' callback to let proto header know when to apply final proto header changes at runtime (e.g. - csum update). 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.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/trafgen_proto.c b/trafgen_proto.c
index d976c14..96fd6da 100644
--- a/trafgen_proto.c
+++ b/trafgen_proto.c
@@ -409,6 +409,19 @@ void protos_init(const char *dev)
protos_l4_init();
}
+void proto_packet_update(uint32_t idx)
+{
+ struct packet *pkt = packet_get(idx);
+ ssize_t i;
+
+ for (i = pkt->headers_count - 1; i >= 0; i--) {
+ struct proto_hdr *hdr = pkt->headers[i];
+
+ if (hdr->ops->packet_update)
+ hdr->ops->packet_update(hdr);
+ }
+}
+
void proto_packet_finish(void)
{
struct proto_hdr **headers = current_packet()->headers;
@@ -424,3 +437,22 @@ void proto_packet_finish(void)
ops->packet_finish(hdr);
}
}
+
+void proto_field_func_add(struct proto_hdr *hdr, uint32_t fid,
+ struct proto_field_func *func)
+{
+ struct proto_field *field = proto_field_by_id(hdr, fid);
+
+ bug_on(!func);
+
+ field->func.update_field = func->update_field;
+}
+
+void proto_field_dyn_apply(struct proto_field *field)
+{
+ if (field->func.update_field)
+ field->func.update_field(field);
+
+ if (field->hdr->ops->field_changed)
+ field->hdr->ops->field_changed(field);
+}