summaryrefslogtreecommitdiff
path: root/trafgen_proto.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2016-12-18 11:52:47 +0200
committerTobias Klauser <tklauser@distanz.ch>2016-12-21 16:55:28 +0100
commit7925eea97dfbe30b87217c6db9c6326f4eb66324 (patch)
tree5e7278596c4c05f6f338c6e7cef62758ba6210ba /trafgen_proto.c
parentd552107f5ce59a69b43517e4327ed6a4903bf529 (diff)
trafgen: proto: Add proto field only setters/getters
Add proto_field_xxx functions to set/get value via specified proto_field only. It is good to have such API in case if application needs to set/get value for some custom proto_field instance. 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.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/trafgen_proto.c b/trafgen_proto.c
index f862592..e2b80d4 100644
--- a/trafgen_proto.c
+++ b/trafgen_proto.c
@@ -431,6 +431,52 @@ void proto_hdr_field_set_default_dev_ipv6(struct proto_hdr *hdr, uint32_t fid)
__proto_hdr_field_set_dev_ipv6(hdr, fid, true);
}
+void proto_field_set_u8(struct proto_field *field, uint8_t val)
+{
+ __proto_field_set_bytes(field, &val, false, false);
+}
+
+uint8_t proto_field_get_u8(struct proto_field *field)
+{
+ uint8_t val = *__proto_field_get_bytes(field);
+
+ return field_unmask_and_unshift(field, val);
+}
+
+void proto_field_set_u16(struct proto_field *field, uint16_t val)
+{
+ __proto_field_set_bytes(field, (uint8_t *)&val, false, false);
+}
+
+uint16_t proto_field_get_u16(struct proto_field *field)
+{
+ uint16_t val = *(uint16_t *)__proto_field_get_bytes(field);
+
+ return field_unmask_and_unshift(field, be16_to_cpu(val));
+}
+
+void proto_field_set_u32(struct proto_field *field, uint32_t val)
+{
+ __proto_field_set_bytes(field, (uint8_t *)&val, false, false);
+}
+
+uint32_t proto_field_get_u32(struct proto_field *field)
+{
+ uint32_t val = *(uint32_t *)__proto_field_get_bytes(field);
+
+ return field_unmask_and_unshift(field, be32_to_cpu(val));
+}
+
+void proto_field_set_be16(struct proto_field *field, uint16_t val)
+{
+ __proto_field_set_bytes(field, (uint8_t *)&val, false, true);
+}
+
+void proto_field_set_be32(struct proto_field *field, uint32_t val)
+{
+ __proto_field_set_bytes(field, (uint8_t *)&val, false, true);
+}
+
void protos_init(const char *dev)
{
ctx.dev = dev;