trafgen: parser: Add syntax for VLAN header creating
[netsniff-ng.git] / trafgen_proto.h
blob996c24ea6a9bf5c43ee8dd347cbd32d33d4566de
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_current_header(void);
68 extern struct proto_hdr *proto_lower_header(struct proto_hdr *hdr);
69 extern uint8_t *proto_header_ptr(struct proto_hdr *hdr);
71 extern void proto_header_fields_add(struct proto_hdr *hdr,
72 const struct proto_field *fields,
73 size_t count);
75 extern bool proto_field_is_set(struct proto_hdr *hdr, uint32_t fid);
76 extern void proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,
77 uint8_t *bytes);
78 extern void proto_field_set_u8(struct proto_hdr *hdr, uint32_t fid, uint8_t val);
79 extern uint8_t proto_field_get_u8(struct proto_hdr *hdr, uint32_t fid);
80 extern void proto_field_set_u16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
81 extern uint16_t proto_field_get_u16(struct proto_hdr *hdr, uint32_t fid);
82 extern void proto_field_set_u32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
83 extern uint32_t proto_field_get_u32(struct proto_hdr *hdr, uint32_t fid);
85 extern void proto_field_set_default_bytes(struct proto_hdr *hdr, uint32_t fid,
86 uint8_t *bytes);
87 extern void proto_field_set_default_u8(struct proto_hdr *hdr, uint32_t fid,
88 uint8_t val);
89 extern void proto_field_set_default_u16(struct proto_hdr *hdr, uint32_t fid,
90 uint16_t val);
91 extern void proto_field_set_default_u32(struct proto_hdr *hdr, uint32_t fid,
92 uint32_t val);
94 extern void proto_field_set_be16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
95 extern void proto_field_set_be32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
97 extern void proto_field_set_default_be16(struct proto_hdr *hdr, uint32_t fid,
98 uint16_t val);
99 extern void proto_field_set_default_be32(struct proto_hdr *hdr, uint32_t fid,
100 uint32_t val);
102 extern void proto_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid);
103 extern void proto_field_set_default_dev_mac(struct proto_hdr *hdr, uint32_t fid);
105 extern void proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
106 extern void proto_field_set_default_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
108 #endif /* TRAFGEN_PROTO_H */