1 #ifndef TRAFGEN_PROTO_H
2 #define TRAFGEN_PROTO_H
8 #include "trafgen_dev.h"
29 PROTO_L0
, /* invalid layer */
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
);
53 const struct proto_ops
*ops
;
54 struct proto_hdr
*parent
;
55 struct proto_hdr
**sub_headers
;
56 uint32_t sub_headers_count
;
60 struct proto_field
*fields
;
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
;
82 void (*update_field
)(struct proto_field
*field
);
90 /* might be negative (e.g. VLAN TPID field) */
93 struct proto_field_func func
;
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
,
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
,
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
,
136 extern void proto_hdr_field_set_default_u16(struct proto_hdr
*hdr
, uint32_t fid
,
138 extern void proto_hdr_field_set_default_u32(struct proto_hdr
*hdr
, uint32_t fid
,
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
,
146 extern void proto_hdr_field_set_default_be32(struct proto_hdr
*hdr
, uint32_t fid
,
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 */