flowtop: Simplify flows refresh delay
[netsniff-ng-new.git] / trafgen_proto.h
blob31ac1c8d0aea1c89afff7115cff98a02cf01765e
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_MPLS,
18 PROTO_IP4,
19 PROTO_IP6,
20 PROTO_UDP,
21 PROTO_TCP,
24 enum proto_layer {
25 PROTO_L0, /* invalid layer */
26 PROTO_L2,
27 PROTO_L3,
28 PROTO_L4,
31 struct proto_field {
32 uint32_t id;
33 size_t len;
34 uint32_t shift;
35 uint32_t mask;
36 /* might be negative (e.g. VLAN TPID field) */
37 int16_t offset;
39 bool is_set;
40 uint16_t pkt_offset;
43 struct proto_hdr {
44 enum proto_id id;
45 enum proto_layer layer;
47 struct proto_hdr *next;
48 struct proto_ctx *ctx;
49 uint16_t pkt_offset;
50 struct proto_field *fields;
51 size_t fields_count;
53 void (*header_init)(struct proto_hdr *hdr);
54 void (*header_finish)(struct proto_hdr *hdr);
55 void (*packet_finish)(struct proto_hdr *hdr);
56 void (*set_next_proto)(struct proto_hdr *hdr, enum proto_id pid);
59 extern void protos_init(const char *dev);
60 extern void proto_header_register(struct proto_hdr *hdr);
62 extern struct proto_hdr *proto_header_init(enum proto_id pid);
63 extern void proto_header_finish(struct proto_hdr *hdr);
64 extern void proto_packet_finish(void);
65 extern struct proto_hdr *proto_lower_default_add(struct proto_hdr *hdr,
66 enum proto_id pid);
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 */