1 #ifndef TRAFGEN_PROTO_H
2 #define TRAFGEN_PROTO_H
26 PROTO_L0
, /* invalid layer */
37 enum proto_layer layer
;
39 void (*header_init
)(struct proto_hdr
*hdr
);
40 void (*header_finish
)(struct proto_hdr
*hdr
);
41 void (*field_changed
)(struct proto_field
*field
);
42 void (*packet_finish
)(struct proto_hdr
*hdr
);
43 void (*packet_update
)(struct proto_hdr
*hdr
);
44 void (*set_next_proto
)(struct proto_hdr
*hdr
, enum proto_id pid
);
48 const struct proto_ops
*ops
;
52 struct proto_field
*fields
;
58 enum proto_field_func_t
{
59 PROTO_FIELD_FUNC_INC
= 1 << 0,
60 PROTO_FIELD_FUNC_MIN
= 1 << 1,
61 PROTO_FIELD_FUNC_RND
= 1 << 2,
64 struct proto_field_func
{
65 enum proto_field_func_t type
;
73 void (*update_field
)(struct proto_field
*field
);
81 /* might be negative (e.g. VLAN TPID field) */
84 struct proto_field_func func
;
87 struct proto_hdr
*hdr
;
90 extern void protos_init(const char *dev
);
91 extern void proto_ops_register(const struct proto_ops
*ops
);
93 extern struct proto_hdr
*proto_header_push(enum proto_id pid
);
94 extern void proto_header_finish(struct proto_hdr
*hdr
);
95 extern void proto_packet_finish(void);
96 extern void proto_packet_update(uint32_t idx
);
98 extern struct proto_hdr
*proto_lower_default_add(struct proto_hdr
*hdr
,
101 extern struct proto_hdr
*proto_lower_header(struct proto_hdr
*hdr
);
102 extern struct proto_hdr
*proto_upper_header(struct proto_hdr
*hdr
);
103 extern uint8_t *proto_header_ptr(struct proto_hdr
*hdr
);
105 extern void proto_header_fields_add(struct proto_hdr
*hdr
,
106 const struct proto_field
*fields
,
109 extern bool proto_hdr_field_is_set(struct proto_hdr
*hdr
, uint32_t fid
);
110 extern void proto_hdr_field_set_bytes(struct proto_hdr
*hdr
, uint32_t fid
,
111 const uint8_t *bytes
);
112 extern void proto_hdr_field_set_u8(struct proto_hdr
*hdr
, uint32_t fid
, uint8_t val
);
113 extern uint8_t proto_hdr_field_get_u8(struct proto_hdr
*hdr
, uint32_t fid
);
114 extern void proto_hdr_field_set_u16(struct proto_hdr
*hdr
, uint32_t fid
, uint16_t val
);
115 extern uint16_t proto_hdr_field_get_u16(struct proto_hdr
*hdr
, uint32_t fid
);
116 extern void proto_hdr_field_set_u32(struct proto_hdr
*hdr
, uint32_t fid
, uint32_t val
);
117 extern uint32_t proto_hdr_field_get_u32(struct proto_hdr
*hdr
, uint32_t fid
);
119 extern void proto_hdr_field_set_default_bytes(struct proto_hdr
*hdr
, uint32_t fid
,
120 const uint8_t *bytes
);
121 extern void proto_hdr_field_set_default_u8(struct proto_hdr
*hdr
, uint32_t fid
,
123 extern void proto_hdr_field_set_default_u16(struct proto_hdr
*hdr
, uint32_t fid
,
125 extern void proto_hdr_field_set_default_u32(struct proto_hdr
*hdr
, uint32_t fid
,
128 extern void proto_hdr_field_set_be16(struct proto_hdr
*hdr
, uint32_t fid
, uint16_t val
);
129 extern void proto_hdr_field_set_be32(struct proto_hdr
*hdr
, uint32_t fid
, uint32_t val
);
131 extern void proto_hdr_field_set_default_be16(struct proto_hdr
*hdr
, uint32_t fid
,
133 extern void proto_hdr_field_set_default_be32(struct proto_hdr
*hdr
, uint32_t fid
,
136 extern void proto_hdr_field_set_dev_mac(struct proto_hdr
*hdr
, uint32_t fid
);
137 extern void proto_hdr_field_set_default_dev_mac(struct proto_hdr
*hdr
, uint32_t fid
);
139 extern void proto_hdr_field_set_dev_ipv4(struct proto_hdr
*hdr
, uint32_t fid
);
140 extern void proto_hdr_field_set_default_dev_ipv4(struct proto_hdr
*hdr
, uint32_t fid
);
142 extern void proto_hdr_field_set_dev_ipv6(struct proto_hdr
*hdr
, uint32_t fid
);
143 extern void proto_hdr_field_set_default_dev_ipv6(struct proto_hdr
*hdr
, uint32_t fid
);
145 extern void proto_field_dyn_apply(struct proto_field
*field
);
147 extern struct proto_field
*proto_hdr_field_by_id(struct proto_hdr
*hdr
, uint32_t fid
);
150 extern void proto_field_set_u8(struct proto_field
*field
, uint8_t val
);
151 extern uint8_t proto_field_get_u8(struct proto_field
*field
);
152 extern void proto_field_set_u16(struct proto_field
*field
, uint16_t val
);
153 extern uint16_t proto_field_get_u16(struct proto_field
*field
);
154 extern void proto_field_set_u32(struct proto_field
*field
, uint32_t val
);
155 extern uint32_t proto_field_get_u32(struct proto_field
*field
);
156 extern void proto_field_set_be16(struct proto_field
*field
, uint16_t val
);
157 extern void proto_field_set_be32(struct proto_field
*field
, uint32_t val
);
158 extern void proto_field_set_bytes(struct proto_field
*field
, const uint8_t *bytes
);
160 extern void proto_field_func_add(struct proto_field
*field
,
161 struct proto_field_func
*func
);
163 extern const char *proto_dev_get(void);
165 #endif /* TRAFGEN_PROTO_H */