AUTHORS: Add Erik for his contribution
[netsniff-ng.git] / trafgen_proto.h
blob0267cf6010160880c894b531c77c81495f6b9122
1 #ifndef TRAFGEN_PROTO_I_H
2 #define TRAFGEN_PROTO_I_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_ARP,
16 PROTO_IP4,
17 PROTO_IP6,
18 PROTO_UDP,
19 PROTO_TCP,
22 enum proto_layer {
23 PROTO_L0, /* invalid layer */
24 PROTO_L2,
25 PROTO_L3,
26 PROTO_L4,
29 struct proto_field {
30 uint32_t id;
31 size_t len;
32 uint32_t shift;
33 uint32_t mask;
34 uint16_t offset;
36 bool is_set;
37 uint16_t pkt_offset;
40 struct proto_hdr {
41 enum proto_id id;
42 enum proto_layer layer;
44 struct proto_hdr *next;
45 struct proto_ctx *ctx;
46 uint16_t pkt_offset;
47 struct proto_field *fields;
48 size_t fields_count;
50 void (*header_init)(struct proto_hdr *hdr);
51 void (*header_finish)(struct proto_hdr *hdr);
52 void (*packet_finish)(struct proto_hdr *hdr);
55 extern void protos_init(const char *dev);
56 extern void proto_header_register(struct proto_hdr *hdr);
58 extern void proto_header_init(enum proto_id pid);
59 extern void proto_header_finish(struct proto_hdr *hdr);
60 extern void proto_packet_finish(void);
61 extern void proto_lower_default_add(enum proto_id pid);
63 extern struct proto_hdr *proto_current_header(void);
64 extern struct proto_hdr *proto_lower_header(struct proto_hdr *hdr);
65 extern uint8_t *proto_header_ptr(struct proto_hdr *hdr);
67 extern void proto_header_fields_add(struct proto_hdr *hdr,
68 struct proto_field *fields, size_t count);
70 extern bool proto_field_is_set(struct proto_hdr *hdr, uint32_t fid);
71 extern void proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,
72 uint8_t *bytes);
73 extern void proto_field_set_u8(struct proto_hdr *hdr, uint32_t fid, uint8_t val);
74 extern uint8_t proto_field_get_u8(struct proto_hdr *hdr, uint32_t fid);
75 extern void proto_field_set_u16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
76 extern uint16_t proto_field_get_u16(struct proto_hdr *hdr, uint32_t fid);
77 extern void proto_field_set_u32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
78 extern uint32_t proto_field_get_u32(struct proto_hdr *hdr, uint32_t fid);
80 extern void proto_field_set_default_bytes(struct proto_hdr *hdr, uint32_t fid,
81 uint8_t *bytes);
82 extern void proto_field_set_default_u8(struct proto_hdr *hdr, uint32_t fid,
83 uint8_t val);
84 extern void proto_field_set_default_u16(struct proto_hdr *hdr, uint32_t fid,
85 uint16_t val);
86 extern void proto_field_set_default_u32(struct proto_hdr *hdr, uint32_t fid,
87 uint32_t val);
89 extern void proto_field_set_be16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
90 extern void proto_field_set_be32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
92 extern void proto_field_set_default_be16(struct proto_hdr *hdr, uint32_t fid,
93 uint16_t val);
94 extern void proto_field_set_default_be32(struct proto_hdr *hdr, uint32_t fid,
95 uint32_t val);
97 extern void proto_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid);
98 extern void proto_field_set_default_dev_mac(struct proto_hdr *hdr, uint32_t fid);
100 extern void proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
101 extern void proto_field_set_default_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
103 #endif /* TRAFGEN_PROTO_I_H */