summaryrefslogtreecommitdiff
path: root/trafgen_proto.h
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2017-06-01 13:12:28 +0300
committerTobias Klauser <tklauser@distanz.ch>2017-06-02 09:15:27 +0200
commit9d5e303a998e4618d492c9d0befb09e3cd3d746b (patch)
tree8ed2c72a573cad5acf92b62f4f0048c9cff251c4 /trafgen_proto.h
parenta2524f2bc9c0e8651221ba88b6013db55cec0190 (diff)
trafgen: l7: Add DNS header generation API
Add trafgen_l7.c module with DNS proto header generation with support of filling DNS query/answer/authority/additional sections as sub headers. Introcuded new concept as 'sub header' which is needed to easy handle DNS sections which might be added on-demand, and to simplify using sub-header as regular header with a fields, offset, etc. There is a parent header which contains array of pointers of sub-headers, and the array is ordered as they are located in the parent header. The sub-headers mostly encapsulated by the parent header which 'knows' the semantic of them. The new proto_hdr->push_sub_header(...) callback was added to tell the parent header to push the sub-header's fields, sub-header also may have proto_ops which must be filled by the parent. This sub-header concept might be used in the future if it will be needed to support DHCP, WLAN headers. There are 4 kinds of DNS sub-headers - query, answer, authority, additional. 'id' of each sub-header is used to only differentiate these types of sections. These sections have strict order inside DNS header, and there was added the proto_hdr_move_sub_header(...) to sort them in required order. Actually there are only 2 proto_hdr's which describes 4 DNS sections - query & rrecord, because rrecord covers another 3 - answer, auhority, additional which have the same layout. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'trafgen_proto.h')
-rw-r--r--trafgen_proto.h19
1 files changed, 17 insertions, 2 deletions
diff --git a/trafgen_proto.h b/trafgen_proto.h
index 94eb4e7..f3d07ba 100644
--- a/trafgen_proto.h
+++ b/trafgen_proto.h
@@ -19,6 +19,7 @@ enum proto_id {
PROTO_ICMP6,
PROTO_UDP,
PROTO_TCP,
+ PROTO_DNS,
__PROTO_MAX,
};
@@ -27,6 +28,7 @@ enum proto_layer {
PROTO_L2,
PROTO_L3,
PROTO_L4,
+ PROTO_L7,
};
struct proto_field;
@@ -38,6 +40,7 @@ struct proto_ops {
void (*header_init)(struct proto_hdr *hdr);
void (*header_finish)(struct proto_hdr *hdr);
+ void (*push_sub_header)(struct proto_hdr *hdr, struct proto_hdr *sub_hdr);
void (*field_changed)(struct proto_field *field);
void (*packet_finish)(struct proto_hdr *hdr);
void (*packet_update)(struct proto_hdr *hdr);
@@ -46,12 +49,16 @@ struct proto_ops {
struct proto_hdr {
const struct proto_ops *ops;
+ struct proto_hdr *parent;
+ struct proto_hdr **sub_headers;
+ uint32_t sub_headers_count;
uint16_t pkt_offset;
uint32_t pkt_id;
uint32_t index;
struct proto_field *fields;
size_t fields_count;
bool is_csum_valid;
+ uint32_t id;
size_t len;
};
@@ -95,6 +102,10 @@ extern void proto_header_finish(struct proto_hdr *hdr);
extern void proto_packet_finish(void);
extern void proto_packet_update(uint32_t idx);
+extern struct proto_hdr *proto_hdr_push_sub_header(struct proto_hdr *hdr, int id);
+extern void proto_hdr_move_sub_header(struct proto_hdr *hdr, struct proto_hdr *from,
+ struct proto_hdr *to);
+
extern struct proto_hdr *proto_lower_default_add(struct proto_hdr *hdr,
enum proto_id pid);
@@ -142,6 +153,9 @@ extern void proto_hdr_field_set_default_dev_ipv4(struct proto_hdr *hdr, uint32_t
extern void proto_hdr_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid);
extern void proto_hdr_field_set_default_dev_ipv6(struct proto_hdr *hdr, uint32_t fid);
+extern void proto_hdr_field_set_string(struct proto_hdr *hdr, uint32_t fid, const char *str);
+extern void proto_hdr_field_set_default_string(struct proto_hdr *hdr, uint32_t fid, const char *str);
+
extern void proto_field_dyn_apply(struct proto_field *field);
extern struct proto_field *proto_hdr_field_by_id(struct proto_hdr *hdr, uint32_t fid);
@@ -155,8 +169,9 @@ extern void proto_field_set_u32(struct proto_field *field, uint32_t val);
extern uint32_t proto_field_get_u32(struct proto_field *field);
extern void proto_field_set_be16(struct proto_field *field, uint16_t val);
extern void proto_field_set_be32(struct proto_field *field, uint32_t val);
-extern void proto_field_set_bytes(struct proto_field *field, const uint8_t *bytes,
- size_t len);
+extern void proto_field_set_bytes(struct proto_field *field, const uint8_t *bytes, size_t len);
+extern void proto_field_set_string(struct proto_field *field, const char *str);
+extern void proto_field_set_default_string(struct proto_field *field, const char *str);
extern void proto_field_func_add(struct proto_field *field,
struct proto_field_func *func);