build: configure: Add option to enable debug symbols
[netsniff-ng.git] / trafgen_proto.h
blob9716aa27845f1eea26517d728513e10ea17aac11
1 #ifndef TRAFGEN_PROTO_H
2 #define TRAFGEN_PROTO_H
4 #include <stddef.h>
5 #include <stdint.h>
6 #include <stdbool.h>
8 enum proto_id {
9 PROTO_NONE = 0,
10 PROTO_ETH,
11 PROTO_VLAN,
12 PROTO_ARP,
13 PROTO_MPLS,
14 PROTO_IP4,
15 PROTO_ICMP4,
16 PROTO_IP6,
17 PROTO_ICMP6,
18 PROTO_UDP,
19 PROTO_TCP,
20 __PROTO_MAX,
23 enum proto_layer {
24 PROTO_L0, /* invalid layer */
25 PROTO_L2,
26 PROTO_L3,
27 PROTO_L4,
30 struct proto_hdr;
32 struct proto_ops {
33 enum proto_id id;
34 enum proto_layer layer;
36 void (*header_init)(struct proto_hdr *hdr);
37 void (*header_finish)(struct proto_hdr *hdr);
38 void (*packet_finish)(struct proto_hdr *hdr);
39 void (*set_next_proto)(struct proto_hdr *hdr, enum proto_id pid);
42 struct proto_hdr {
43 const struct proto_ops *ops;
44 uint16_t pkt_offset;
45 uint32_t pkt_id;
46 struct proto_field *fields;
47 size_t fields_count;
48 size_t len;
51 struct proto_field {
52 uint32_t id;
53 size_t len;
54 uint32_t shift;
55 uint32_t mask;
56 /* might be negative (e.g. VLAN TPID field) */
57 int16_t offset;
59 bool is_set;
60 uint16_t pkt_offset;
61 struct proto_hdr *hdr;
64 extern void protos_init(const char *dev);
65 extern void proto_ops_register(const struct proto_ops *ops);
67 extern struct proto_hdr *proto_header_push(enum proto_id pid);
68 extern void proto_header_finish(struct proto_hdr *hdr);
69 extern void proto_packet_finish(void);
70 extern struct proto_hdr *proto_lower_default_add(struct proto_hdr *hdr,
71 enum proto_id pid);
73 extern struct proto_hdr *proto_lower_header(struct proto_hdr *hdr);
74 extern uint8_t *proto_header_ptr(struct proto_hdr *hdr);
76 extern void proto_header_fields_add(struct proto_hdr *hdr,
77 const struct proto_field *fields,
78 size_t count);
80 extern bool proto_field_is_set(struct proto_hdr *hdr, uint32_t fid);
81 extern void proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,
82 const uint8_t *bytes);
83 extern void proto_field_set_u8(struct proto_hdr *hdr, uint32_t fid, uint8_t val);
84 extern uint8_t proto_field_get_u8(struct proto_hdr *hdr, uint32_t fid);
85 extern void proto_field_set_u16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
86 extern uint16_t proto_field_get_u16(struct proto_hdr *hdr, uint32_t fid);
87 extern void proto_field_set_u32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
88 extern uint32_t proto_field_get_u32(struct proto_hdr *hdr, uint32_t fid);
90 extern void proto_field_set_default_bytes(struct proto_hdr *hdr, uint32_t fid,
91 const uint8_t *bytes);
92 extern void proto_field_set_default_u8(struct proto_hdr *hdr, uint32_t fid,
93 uint8_t val);
94 extern void proto_field_set_default_u16(struct proto_hdr *hdr, uint32_t fid,
95 uint16_t val);
96 extern void proto_field_set_default_u32(struct proto_hdr *hdr, uint32_t fid,
97 uint32_t val);
99 extern void proto_field_set_be16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
100 extern void proto_field_set_be32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
102 extern void proto_field_set_default_be16(struct proto_hdr *hdr, uint32_t fid,
103 uint16_t val);
104 extern void proto_field_set_default_be32(struct proto_hdr *hdr, uint32_t fid,
105 uint32_t val);
107 extern void proto_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid);
108 extern void proto_field_set_default_dev_mac(struct proto_hdr *hdr, uint32_t fid);
110 extern void proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
111 extern void proto_field_set_default_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
113 extern void proto_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid);
114 extern void proto_field_set_default_dev_ipv6(struct proto_hdr *hdr, uint32_t fid);
116 #endif /* TRAFGEN_PROTO_H */