1 #ifndef TRAFGEN_PROTO_H
2 #define TRAFGEN_PROTO_H
27 PROTO_L0
, /* invalid layer */
39 enum proto_layer layer
;
41 void (*header_init
)(struct proto_hdr
*hdr
);
42 void (*header_finish
)(struct proto_hdr
*hdr
);
43 void (*push_sub_header
)(struct proto_hdr
*hdr
, struct proto_hdr
*sub_hdr
);
44 void (*field_changed
)(struct proto_field
*field
);
45 void (*packet_finish
)(struct proto_hdr
*hdr
);
46 void (*packet_update
)(struct proto_hdr
*hdr
);
47 void (*set_next_proto
)(struct proto_hdr
*hdr
, enum proto_id pid
);
51 const struct proto_ops
*ops
;
52 struct proto_hdr
*parent
;
53 struct proto_hdr
**sub_headers
;
54 uint32_t sub_headers_count
;
58 struct proto_field
*fields
;
65 enum proto_field_func_t
{
66 PROTO_FIELD_FUNC_INC
= 1 << 0,
67 PROTO_FIELD_FUNC_MIN
= 1 << 1,
68 PROTO_FIELD_FUNC_RND
= 1 << 2,
71 struct proto_field_func
{
72 enum proto_field_func_t type
;
80 void (*update_field
)(struct proto_field
*field
);
88 /* might be negative (e.g. VLAN TPID field) */
91 struct proto_field_func func
;
94 struct proto_hdr
*hdr
;
97 extern void protos_init(const char *dev
);
98 extern void proto_ops_register(const struct proto_ops
*ops
);
100 extern struct proto_hdr
*proto_header_push(enum proto_id pid
);
101 extern void proto_header_finish(struct proto_hdr
*hdr
);
102 extern void proto_packet_finish(void);
103 extern void proto_packet_update(uint32_t idx
);
105 extern struct proto_hdr
*proto_hdr_push_sub_header(struct proto_hdr
*hdr
, int id
);
106 extern void proto_hdr_move_sub_header(struct proto_hdr
*hdr
, struct proto_hdr
*from
,
107 struct proto_hdr
*to
);
109 extern struct proto_hdr
*proto_lower_default_add(struct proto_hdr
*hdr
,
112 extern struct proto_hdr
*proto_lower_header(struct proto_hdr
*hdr
);
113 extern struct proto_hdr
*proto_upper_header(struct proto_hdr
*hdr
);
114 extern uint8_t *proto_header_ptr(struct proto_hdr
*hdr
);
116 extern void proto_header_fields_add(struct proto_hdr
*hdr
,
117 const struct proto_field
*fields
,
120 extern bool proto_hdr_field_is_set(struct proto_hdr
*hdr
, uint32_t fid
);
121 extern void proto_hdr_field_set_bytes(struct proto_hdr
*hdr
, uint32_t fid
,
122 const uint8_t *bytes
, size_t len
);
123 extern void proto_hdr_field_set_u8(struct proto_hdr
*hdr
, uint32_t fid
, uint8_t val
);
124 extern uint8_t proto_hdr_field_get_u8(struct proto_hdr
*hdr
, uint32_t fid
);
125 extern void proto_hdr_field_set_u16(struct proto_hdr
*hdr
, uint32_t fid
, uint16_t val
);
126 extern uint16_t proto_hdr_field_get_u16(struct proto_hdr
*hdr
, uint32_t fid
);
127 extern void proto_hdr_field_set_u32(struct proto_hdr
*hdr
, uint32_t fid
, uint32_t val
);
128 extern uint32_t proto_hdr_field_get_u32(struct proto_hdr
*hdr
, uint32_t fid
);
130 extern void proto_hdr_field_set_default_bytes(struct proto_hdr
*hdr
, uint32_t fid
,
131 const uint8_t *bytes
, size_t len
);
132 extern void proto_hdr_field_set_default_u8(struct proto_hdr
*hdr
, uint32_t fid
,
134 extern void proto_hdr_field_set_default_u16(struct proto_hdr
*hdr
, uint32_t fid
,
136 extern void proto_hdr_field_set_default_u32(struct proto_hdr
*hdr
, uint32_t fid
,
139 extern void proto_hdr_field_set_be16(struct proto_hdr
*hdr
, uint32_t fid
, uint16_t val
);
140 extern void proto_hdr_field_set_be32(struct proto_hdr
*hdr
, uint32_t fid
, uint32_t val
);
142 extern void proto_hdr_field_set_default_be16(struct proto_hdr
*hdr
, uint32_t fid
,
144 extern void proto_hdr_field_set_default_be32(struct proto_hdr
*hdr
, uint32_t fid
,
147 extern void proto_hdr_field_set_dev_mac(struct proto_hdr
*hdr
, uint32_t fid
);
148 extern void proto_hdr_field_set_default_dev_mac(struct proto_hdr
*hdr
, uint32_t fid
);
150 extern void proto_hdr_field_set_dev_ipv4(struct proto_hdr
*hdr
, uint32_t fid
);
151 extern void proto_hdr_field_set_default_dev_ipv4(struct proto_hdr
*hdr
, uint32_t fid
);
153 extern void proto_hdr_field_set_dev_ipv6(struct proto_hdr
*hdr
, uint32_t fid
);
154 extern void proto_hdr_field_set_default_dev_ipv6(struct proto_hdr
*hdr
, uint32_t fid
);
156 extern void proto_hdr_field_set_string(struct proto_hdr
*hdr
, uint32_t fid
, const char *str
);
157 extern void proto_hdr_field_set_default_string(struct proto_hdr
*hdr
, uint32_t fid
, const char *str
);
159 extern void proto_field_dyn_apply(struct proto_field
*field
);
161 extern struct proto_field
*proto_hdr_field_by_id(struct proto_hdr
*hdr
, uint32_t fid
);
164 extern void proto_field_set_u8(struct proto_field
*field
, uint8_t val
);
165 extern uint8_t proto_field_get_u8(struct proto_field
*field
);
166 extern void proto_field_set_u16(struct proto_field
*field
, uint16_t val
);
167 extern uint16_t proto_field_get_u16(struct proto_field
*field
);
168 extern void proto_field_set_u32(struct proto_field
*field
, uint32_t val
);
169 extern uint32_t proto_field_get_u32(struct proto_field
*field
);
170 extern void proto_field_set_be16(struct proto_field
*field
, uint16_t val
);
171 extern void proto_field_set_be32(struct proto_field
*field
, uint32_t val
);
172 extern void proto_field_set_bytes(struct proto_field
*field
, const uint8_t *bytes
, size_t len
);
173 extern void proto_field_set_string(struct proto_field
*field
, const char *str
);
174 extern void proto_field_set_default_string(struct proto_field
*field
, const char *str
);
176 extern void proto_field_func_add(struct proto_field
*field
,
177 struct proto_field_func
*func
);
179 extern const char *proto_dev_get(void);
181 #endif /* TRAFGEN_PROTO_H */