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
;
71 void (*update_field
)(struct proto_field
*field
);
79 /* might be negative (e.g. VLAN TPID field) */
82 struct proto_field_func func
;
85 struct proto_hdr
*hdr
;
88 extern void protos_init(const char *dev
);
89 extern void proto_ops_register(const struct proto_ops
*ops
);
91 extern struct proto_hdr
*proto_header_push(enum proto_id pid
);
92 extern void proto_header_finish(struct proto_hdr
*hdr
);
93 extern void proto_packet_finish(void);
94 extern void proto_packet_update(uint32_t idx
);
96 extern struct proto_hdr
*proto_lower_default_add(struct proto_hdr
*hdr
,
99 extern struct proto_hdr
*proto_lower_header(struct proto_hdr
*hdr
);
100 extern struct proto_hdr
*proto_upper_header(struct proto_hdr
*hdr
);
101 extern uint8_t *proto_header_ptr(struct proto_hdr
*hdr
);
103 extern void proto_header_fields_add(struct proto_hdr
*hdr
,
104 const struct proto_field
*fields
,
107 extern bool proto_hdr_field_is_set(struct proto_hdr
*hdr
, uint32_t fid
);
108 extern void proto_hdr_field_set_bytes(struct proto_hdr
*hdr
, uint32_t fid
,
109 const uint8_t *bytes
);
110 extern void proto_hdr_field_set_u8(struct proto_hdr
*hdr
, uint32_t fid
, uint8_t val
);
111 extern uint8_t proto_hdr_field_get_u8(struct proto_hdr
*hdr
, uint32_t fid
);
112 extern void proto_hdr_field_set_u16(struct proto_hdr
*hdr
, uint32_t fid
, uint16_t val
);
113 extern uint16_t proto_hdr_field_get_u16(struct proto_hdr
*hdr
, uint32_t fid
);
114 extern void proto_hdr_field_set_u32(struct proto_hdr
*hdr
, uint32_t fid
, uint32_t val
);
115 extern uint32_t proto_hdr_field_get_u32(struct proto_hdr
*hdr
, uint32_t fid
);
117 extern void proto_hdr_field_set_default_bytes(struct proto_hdr
*hdr
, uint32_t fid
,
118 const uint8_t *bytes
);
119 extern void proto_hdr_field_set_default_u8(struct proto_hdr
*hdr
, uint32_t fid
,
121 extern void proto_hdr_field_set_default_u16(struct proto_hdr
*hdr
, uint32_t fid
,
123 extern void proto_hdr_field_set_default_u32(struct proto_hdr
*hdr
, uint32_t fid
,
126 extern void proto_hdr_field_set_be16(struct proto_hdr
*hdr
, uint32_t fid
, uint16_t val
);
127 extern void proto_hdr_field_set_be32(struct proto_hdr
*hdr
, uint32_t fid
, uint32_t val
);
129 extern void proto_hdr_field_set_default_be16(struct proto_hdr
*hdr
, uint32_t fid
,
131 extern void proto_hdr_field_set_default_be32(struct proto_hdr
*hdr
, uint32_t fid
,
134 extern void proto_hdr_field_set_dev_mac(struct proto_hdr
*hdr
, uint32_t fid
);
135 extern void proto_hdr_field_set_default_dev_mac(struct proto_hdr
*hdr
, uint32_t fid
);
137 extern void proto_hdr_field_set_dev_ipv4(struct proto_hdr
*hdr
, uint32_t fid
);
138 extern void proto_hdr_field_set_default_dev_ipv4(struct proto_hdr
*hdr
, uint32_t fid
);
140 extern void proto_hdr_field_set_dev_ipv6(struct proto_hdr
*hdr
, uint32_t fid
);
141 extern void proto_hdr_field_set_default_dev_ipv6(struct proto_hdr
*hdr
, uint32_t fid
);
143 extern void proto_field_dyn_apply(struct proto_field
*field
);
145 extern void proto_hdr_field_func_add(struct proto_hdr
*hdr
, uint32_t fid
,
146 struct proto_field_func
*func
);
148 extern struct proto_field
*proto_hdr_field_by_id(struct proto_hdr
*hdr
, uint32_t fid
);
151 extern void proto_field_set_u8(struct proto_field
*field
, uint8_t val
);
152 extern uint8_t proto_field_get_u8(struct proto_field
*field
);
153 extern void proto_field_set_u16(struct proto_field
*field
, uint16_t val
);
154 extern uint16_t proto_field_get_u16(struct proto_field
*field
);
155 extern void proto_field_set_u32(struct proto_field
*field
, uint32_t val
);
156 extern uint32_t proto_field_get_u32(struct proto_field
*field
);
157 extern void proto_field_set_be16(struct proto_field
*field
, uint16_t val
);
158 extern void proto_field_set_be32(struct proto_field
*field
, uint32_t val
);
160 #endif /* TRAFGEN_PROTO_H */