built_in: Include stddef.h to avoid redefinition of offsetof() macro
[netsniff-ng.git] / trafgen_proto.h
blob10ded79156ae8f7e3efea8acddc8e467c90a0a6d
1 #ifndef TRAFGEN_PROTO_H
2 #define TRAFGEN_PROTO_H
4 #include <stddef.h>
5 #include <stdint.h>
6 #include <stdbool.h>
8 struct proto_ctx {
9 const char *dev;
12 enum proto_id {
13 PROTO_NONE,
14 PROTO_ETH,
15 PROTO_VLAN,
16 PROTO_ARP,
17 PROTO_IP4,
18 PROTO_IP6,
19 PROTO_UDP,
20 PROTO_TCP,
23 enum proto_layer {
24 PROTO_L0, /* invalid layer */
25 PROTO_L2,
26 PROTO_L3,
27 PROTO_L4,
30 struct proto_field {
31 uint32_t id;
32 size_t len;
33 uint32_t shift;
34 uint32_t mask;
35 /* might be negative (e.g. VLAN TPID field) */
36 int16_t offset;
38 bool is_set;
39 uint16_t pkt_offset;
42 struct proto_hdr {
43 enum proto_id id;
44 enum proto_layer layer;
46 struct proto_hdr *next;
47 struct proto_ctx *ctx;
48 uint16_t pkt_offset;
49 struct proto_field *fields;
50 size_t fields_count;
52 void (*header_init)(struct proto_hdr *hdr);
53 void (*header_finish)(struct proto_hdr *hdr);
54 void (*packet_finish)(struct proto_hdr *hdr);
55 void (*set_next_proto)(struct proto_hdr *hdr, enum proto_id pid);
58 extern void protos_init(const char *dev);
59 extern void proto_header_register(struct proto_hdr *hdr);
61 extern struct proto_hdr *proto_header_init(enum proto_id pid);
62 extern void proto_header_finish(struct proto_hdr *hdr);
63 extern void proto_packet_finish(void);
64 extern struct proto_hdr *proto_lower_default_add(struct proto_hdr *hdr,
65 enum proto_id pid);
67 extern struct proto_hdr *proto_lower_header(struct proto_hdr *hdr);
68 extern uint8_t *proto_header_ptr(struct proto_hdr *hdr);
70 extern void proto_header_fields_add(struct proto_hdr *hdr,
71 const struct proto_field *fields,
72 size_t count);
74 extern bool proto_field_is_set(struct proto_hdr *hdr, uint32_t fid);
75 extern void proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,
76 uint8_t *bytes);
77 extern void proto_field_set_u8(struct proto_hdr *hdr, uint32_t fid, uint8_t val);
78 extern uint8_t proto_field_get_u8(struct proto_hdr *hdr, uint32_t fid);
79 extern void proto_field_set_u16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
80 extern uint16_t proto_field_get_u16(struct proto_hdr *hdr, uint32_t fid);
81 extern void proto_field_set_u32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
82 extern uint32_t proto_field_get_u32(struct proto_hdr *hdr, uint32_t fid);
84 extern void proto_field_set_default_bytes(struct proto_hdr *hdr, uint32_t fid,
85 uint8_t *bytes);
86 extern void proto_field_set_default_u8(struct proto_hdr *hdr, uint32_t fid,
87 uint8_t val);
88 extern void proto_field_set_default_u16(struct proto_hdr *hdr, uint32_t fid,
89 uint16_t val);
90 extern void proto_field_set_default_u32(struct proto_hdr *hdr, uint32_t fid,
91 uint32_t val);
93 extern void proto_field_set_be16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
94 extern void proto_field_set_be32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
96 extern void proto_field_set_default_be16(struct proto_hdr *hdr, uint32_t fid,
97 uint16_t val);
98 extern void proto_field_set_default_be32(struct proto_hdr *hdr, uint32_t fid,
99 uint32_t val);
101 extern void proto_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid);
102 extern void proto_field_set_default_dev_mac(struct proto_hdr *hdr, uint32_t fid);
104 extern void proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
105 extern void proto_field_set_default_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
107 #endif /* TRAFGEN_PROTO_H */