trafgen: Fix output pcap file name length trimming
[netsniff-ng.git] / trafgen_proto.h
blobd3da9637182815a57a79539f84dcdd1cdb1ca34c
1 #ifndef TRAFGEN_PROTO_H
2 #define TRAFGEN_PROTO_H
4 #include <stddef.h>
5 #include <stdint.h>
6 #include <stdbool.h>
8 #include "trafgen_dev.h"
10 enum proto_id {
11 PROTO_NONE = 0,
12 PROTO_ETH,
13 PROTO_PAUSE,
14 PROTO_PFC,
15 PROTO_VLAN,
16 PROTO_ARP,
17 PROTO_MPLS,
18 PROTO_IP4,
19 PROTO_ICMP4,
20 PROTO_IP6,
21 PROTO_ICMP6,
22 PROTO_UDP,
23 PROTO_TCP,
24 PROTO_DNS,
25 __PROTO_MAX,
28 enum proto_layer {
29 PROTO_L0, /* invalid layer */
30 PROTO_L2,
31 PROTO_L3,
32 PROTO_L4,
33 PROTO_L7,
36 struct proto_field;
37 struct proto_hdr;
39 struct proto_ops {
40 enum proto_id id;
41 enum proto_layer layer;
43 void (*header_init)(struct proto_hdr *hdr);
44 void (*header_finish)(struct proto_hdr *hdr);
45 void (*push_sub_header)(struct proto_hdr *hdr, struct proto_hdr *sub_hdr);
46 void (*field_changed)(struct proto_field *field);
47 void (*packet_finish)(struct proto_hdr *hdr);
48 void (*packet_update)(struct proto_hdr *hdr);
49 void (*set_next_proto)(struct proto_hdr *hdr, enum proto_id pid);
52 struct proto_hdr {
53 const struct proto_ops *ops;
54 struct proto_hdr *parent;
55 struct proto_hdr **sub_headers;
56 uint32_t sub_headers_count;
57 uint16_t pkt_offset;
58 uint32_t pkt_id;
59 uint32_t index;
60 struct proto_field *fields;
61 size_t fields_count;
62 bool is_csum_valid;
63 uint32_t id;
64 size_t len;
67 enum proto_field_func_t {
68 PROTO_FIELD_FUNC_INC = 1 << 0,
69 PROTO_FIELD_FUNC_MIN = 1 << 1,
70 PROTO_FIELD_FUNC_RND = 1 << 2,
73 struct proto_field_func {
74 enum proto_field_func_t type;
75 uint32_t min;
76 uint32_t max;
77 int32_t inc;
78 uint16_t offset;
79 uint32_t val;
80 size_t len;
82 void (*update_field)(struct proto_field *field);
85 struct proto_field {
86 uint32_t id;
87 size_t len;
88 uint32_t shift;
89 uint32_t mask;
90 /* might be negative (e.g. VLAN TPID field) */
91 int16_t offset;
93 struct proto_field_func func;
94 bool is_set;
95 uint16_t pkt_offset;
96 struct proto_hdr *hdr;
99 extern void protos_init(struct dev_io *dev);
100 extern void proto_ops_register(const struct proto_ops *ops);
102 extern struct proto_hdr *proto_header_push(enum proto_id pid);
103 extern void proto_header_finish(struct proto_hdr *hdr);
104 extern void proto_packet_finish(void);
105 extern void proto_packet_update(uint32_t idx);
107 extern struct proto_hdr *proto_hdr_push_sub_header(struct proto_hdr *hdr, int id);
108 extern void proto_hdr_move_sub_header(struct proto_hdr *hdr, struct proto_hdr *from,
109 struct proto_hdr *to);
111 extern struct proto_hdr *proto_lower_default_add(struct proto_hdr *hdr,
112 enum proto_id pid);
114 extern struct proto_hdr *proto_lower_header(struct proto_hdr *hdr);
115 extern struct proto_hdr *proto_upper_header(struct proto_hdr *hdr);
116 extern uint8_t *proto_header_ptr(struct proto_hdr *hdr);
118 extern void proto_header_fields_add(struct proto_hdr *hdr,
119 const struct proto_field *fields,
120 size_t count);
122 extern bool proto_hdr_field_is_set(struct proto_hdr *hdr, uint32_t fid);
123 extern void proto_hdr_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,
124 const uint8_t *bytes, size_t len);
125 extern void proto_hdr_field_set_u8(struct proto_hdr *hdr, uint32_t fid, uint8_t val);
126 extern uint8_t proto_hdr_field_get_u8(struct proto_hdr *hdr, uint32_t fid);
127 extern void proto_hdr_field_set_u16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
128 extern uint16_t proto_hdr_field_get_u16(struct proto_hdr *hdr, uint32_t fid);
129 extern void proto_hdr_field_set_u32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
130 extern uint32_t proto_hdr_field_get_u32(struct proto_hdr *hdr, uint32_t fid);
132 extern void proto_hdr_field_set_default_bytes(struct proto_hdr *hdr, uint32_t fid,
133 const uint8_t *bytes, size_t len);
134 extern void proto_hdr_field_set_default_u8(struct proto_hdr *hdr, uint32_t fid,
135 uint8_t val);
136 extern void proto_hdr_field_set_default_u16(struct proto_hdr *hdr, uint32_t fid,
137 uint16_t val);
138 extern void proto_hdr_field_set_default_u32(struct proto_hdr *hdr, uint32_t fid,
139 uint32_t val);
141 extern void proto_hdr_field_set_be16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
142 extern void proto_hdr_field_set_be32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
144 extern void proto_hdr_field_set_default_be16(struct proto_hdr *hdr, uint32_t fid,
145 uint16_t val);
146 extern void proto_hdr_field_set_default_be32(struct proto_hdr *hdr, uint32_t fid,
147 uint32_t val);
149 extern void proto_hdr_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid);
150 extern void proto_hdr_field_set_default_dev_mac(struct proto_hdr *hdr, uint32_t fid);
152 extern void proto_hdr_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
153 extern void proto_hdr_field_set_default_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
155 extern void proto_hdr_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid);
156 extern void proto_hdr_field_set_default_dev_ipv6(struct proto_hdr *hdr, uint32_t fid);
158 extern void proto_hdr_field_set_string(struct proto_hdr *hdr, uint32_t fid, const char *str);
159 extern void proto_hdr_field_set_default_string(struct proto_hdr *hdr, uint32_t fid, const char *str);
161 extern void proto_field_dyn_apply(struct proto_field *field);
163 extern struct proto_field *proto_hdr_field_by_id(struct proto_hdr *hdr, uint32_t fid);
166 extern void proto_field_set_u8(struct proto_field *field, uint8_t val);
167 extern uint8_t proto_field_get_u8(struct proto_field *field);
168 extern void proto_field_set_u16(struct proto_field *field, uint16_t val);
169 extern uint16_t proto_field_get_u16(struct proto_field *field);
170 extern void proto_field_set_u32(struct proto_field *field, uint32_t val);
171 extern uint32_t proto_field_get_u32(struct proto_field *field);
172 extern void proto_field_set_be16(struct proto_field *field, uint16_t val);
173 extern void proto_field_set_be32(struct proto_field *field, uint32_t val);
174 extern void proto_field_set_bytes(struct proto_field *field, const uint8_t *bytes, size_t len);
175 extern void proto_field_set_string(struct proto_field *field, const char *str);
176 extern void proto_field_set_default_string(struct proto_field *field, const char *str);
178 extern void proto_field_func_add(struct proto_field *field,
179 struct proto_field_func *func);
181 extern struct dev_io *proto_dev_get(void);
183 #endif /* TRAFGEN_PROTO_H */