1 #ifndef TRAFGEN_PROTO_H
2 #define TRAFGEN_PROTO_H
8 #include "trafgen_dev.h"
31 PROTO_L0
, /* invalid layer */
43 enum proto_layer layer
;
45 void (*header_init
)(struct proto_hdr
*hdr
);
46 void (*header_finish
)(struct proto_hdr
*hdr
);
47 void (*push_sub_header
)(struct proto_hdr
*hdr
, struct proto_hdr
*sub_hdr
);
48 void (*field_changed
)(struct proto_field
*field
);
49 void (*packet_finish
)(struct proto_hdr
*hdr
);
50 void (*packet_update
)(struct proto_hdr
*hdr
);
51 void (*set_next_proto
)(struct proto_hdr
*hdr
, enum proto_id pid
);
52 enum proto_id (*get_next_proto
)(struct proto_hdr
*hdr
);
56 const struct proto_ops
*ops
;
57 struct proto_hdr
*parent
;
58 struct proto_hdr
**sub_headers
;
59 uint32_t sub_headers_count
;
63 struct proto_field
*fields
;
70 enum proto_field_func_t
{
71 PROTO_FIELD_FUNC_INC
= 1 << 0,
72 PROTO_FIELD_FUNC_MIN
= 1 << 1,
73 PROTO_FIELD_FUNC_RND
= 1 << 2,
76 struct proto_field_func
{
77 enum proto_field_func_t type
;
85 void (*update_field
)(struct proto_field
*field
);
93 /* might be negative (e.g. VLAN TPID field) */
96 struct proto_field_func func
;
99 struct proto_hdr
*hdr
;
102 extern void protos_init(struct dev_io
*dev
);
103 extern void proto_ops_register(const struct proto_ops
*ops
);
105 struct proto_hdr
*proto_packet_apply(enum proto_id pid
, struct packet
*pkt
);
106 extern struct proto_hdr
*proto_header_push(enum proto_id pid
);
107 extern void proto_header_finish(struct proto_hdr
*hdr
);
108 extern void proto_packet_finish(void);
109 extern void proto_packet_update(uint32_t idx
);
111 extern enum proto_id
proto_hdr_get_next_proto(struct proto_hdr
*hdr
);
112 extern struct packet
*proto_hdr_packet(struct proto_hdr
*hdr
);
113 extern struct proto_hdr
*proto_hdr_push_sub_header(struct proto_hdr
*hdr
, int id
);
114 extern void proto_hdr_move_sub_header(struct proto_hdr
*hdr
, struct proto_hdr
*from
,
115 struct proto_hdr
*to
);
117 extern struct proto_hdr
*proto_lower_default_add(struct proto_hdr
*hdr
,
120 extern struct proto_hdr
*packet_last_header(struct packet
*pkt
);
121 extern struct proto_hdr
*proto_lower_header(struct proto_hdr
*hdr
);
122 extern struct proto_hdr
*proto_upper_header(struct proto_hdr
*hdr
);
123 extern uint8_t *proto_header_ptr(struct proto_hdr
*hdr
);
125 extern void proto_header_fields_add(struct proto_hdr
*hdr
,
126 const struct proto_field
*fields
,
129 extern bool proto_hdr_field_is_set(struct proto_hdr
*hdr
, uint32_t fid
);
130 extern uint8_t *proto_hdr_field_get_bytes(struct proto_hdr
*hdr
, uint32_t fid
);
131 extern void proto_hdr_field_set_bytes(struct proto_hdr
*hdr
, uint32_t fid
,
132 const uint8_t *bytes
, size_t len
);
133 extern void proto_hdr_field_set_u8(struct proto_hdr
*hdr
, uint32_t fid
, uint8_t val
);
134 extern uint8_t proto_hdr_field_get_u8(struct proto_hdr
*hdr
, uint32_t fid
);
135 extern void proto_hdr_field_set_u16(struct proto_hdr
*hdr
, uint32_t fid
, uint16_t val
);
136 extern uint16_t proto_hdr_field_get_u16(struct proto_hdr
*hdr
, uint32_t fid
);
137 extern void proto_hdr_field_set_u32(struct proto_hdr
*hdr
, uint32_t fid
, uint32_t val
);
138 extern uint32_t proto_hdr_field_get_u32(struct proto_hdr
*hdr
, uint32_t fid
);
139 extern uint32_t proto_hdr_field_get_be32(struct proto_hdr
*hdr
, uint32_t fid
);
141 extern void proto_hdr_field_set_default_bytes(struct proto_hdr
*hdr
, uint32_t fid
,
142 const uint8_t *bytes
, size_t len
);
143 extern void proto_hdr_field_set_default_u8(struct proto_hdr
*hdr
, uint32_t fid
,
145 extern void proto_hdr_field_set_default_u16(struct proto_hdr
*hdr
, uint32_t fid
,
147 extern void proto_hdr_field_set_default_u32(struct proto_hdr
*hdr
, uint32_t fid
,
150 extern void proto_hdr_field_set_be16(struct proto_hdr
*hdr
, uint32_t fid
, uint16_t val
);
151 extern void proto_hdr_field_set_be32(struct proto_hdr
*hdr
, uint32_t fid
, uint32_t val
);
153 extern void proto_hdr_field_set_default_be16(struct proto_hdr
*hdr
, uint32_t fid
,
155 extern void proto_hdr_field_set_default_be32(struct proto_hdr
*hdr
, uint32_t fid
,
158 extern void proto_hdr_field_set_dev_mac(struct proto_hdr
*hdr
, uint32_t fid
);
159 extern void proto_hdr_field_set_default_dev_mac(struct proto_hdr
*hdr
, uint32_t fid
);
161 extern void proto_hdr_field_set_dev_ipv4(struct proto_hdr
*hdr
, uint32_t fid
);
162 extern void proto_hdr_field_set_default_dev_ipv4(struct proto_hdr
*hdr
, uint32_t fid
);
164 extern void proto_hdr_field_set_dev_ipv6(struct proto_hdr
*hdr
, uint32_t fid
);
165 extern void proto_hdr_field_set_default_dev_ipv6(struct proto_hdr
*hdr
, uint32_t fid
);
167 extern void proto_hdr_field_set_string(struct proto_hdr
*hdr
, uint32_t fid
, const char *str
);
168 extern void proto_hdr_field_set_default_string(struct proto_hdr
*hdr
, uint32_t fid
, const char *str
);
170 extern void proto_field_dyn_apply(struct proto_field
*field
);
172 extern struct proto_field
*proto_hdr_field_by_id(struct proto_hdr
*hdr
, uint32_t fid
);
175 extern void proto_field_set_u8(struct proto_field
*field
, uint8_t val
);
176 extern uint8_t proto_field_get_u8(struct proto_field
*field
);
177 extern void proto_field_set_u16(struct proto_field
*field
, uint16_t val
);
178 extern uint16_t proto_field_get_u16(struct proto_field
*field
);
179 extern void proto_field_set_u32(struct proto_field
*field
, uint32_t val
);
180 extern uint32_t proto_field_get_u32(struct proto_field
*field
);
181 extern uint32_t proto_field_get_be32(struct proto_field
*field
);
182 extern void proto_field_set_be16(struct proto_field
*field
, uint16_t val
);
183 extern void proto_field_set_be32(struct proto_field
*field
, uint32_t val
);
184 extern void proto_field_set_bytes(struct proto_field
*field
, const uint8_t *bytes
, size_t len
);
185 extern void proto_field_set_string(struct proto_field
*field
, const char *str
);
186 extern void proto_field_set_default_string(struct proto_field
*field
, const char *str
);
188 extern void proto_field_func_add(struct proto_field
*field
,
189 struct proto_field_func
*func
);
191 extern struct dev_io
*proto_dev_get(void);
193 #endif /* TRAFGEN_PROTO_H */