1 #ifndef TRAFGEN_PROTO_H
2 #define TRAFGEN_PROTO_H
24 PROTO_L0
, /* invalid layer */
35 enum proto_layer layer
;
37 void (*header_init
)(struct proto_hdr
*hdr
);
38 void (*header_finish
)(struct proto_hdr
*hdr
);
39 void (*field_changed
)(struct proto_field
*field
);
40 void (*packet_finish
)(struct proto_hdr
*hdr
);
41 void (*packet_update
)(struct proto_hdr
*hdr
);
42 void (*set_next_proto
)(struct proto_hdr
*hdr
, enum proto_id pid
);
46 const struct proto_ops
*ops
;
50 struct proto_field
*fields
;
56 enum proto_field_func_t
{
57 PROTO_FIELD_FUNC_INC
= 1 << 0,
58 PROTO_FIELD_FUNC_MIN
= 1 << 1,
59 PROTO_FIELD_FUNC_RND
= 1 << 2,
62 struct proto_field_func
{
63 enum proto_field_func_t type
;
69 void (*update_field
)(struct proto_field
*field
);
77 /* might be negative (e.g. VLAN TPID field) */
80 struct proto_field_func func
;
83 struct proto_hdr
*hdr
;
86 extern void protos_init(const char *dev
);
87 extern void proto_ops_register(const struct proto_ops
*ops
);
89 extern struct proto_hdr
*proto_header_push(enum proto_id pid
);
90 extern void proto_header_finish(struct proto_hdr
*hdr
);
91 extern void proto_packet_finish(void);
92 extern void proto_packet_update(uint32_t idx
);
94 extern struct proto_hdr
*proto_lower_default_add(struct proto_hdr
*hdr
,
97 extern struct proto_hdr
*proto_lower_header(struct proto_hdr
*hdr
);
98 extern struct proto_hdr
*proto_upper_header(struct proto_hdr
*hdr
);
99 extern uint8_t *proto_header_ptr(struct proto_hdr
*hdr
);
101 extern void proto_header_fields_add(struct proto_hdr
*hdr
,
102 const struct proto_field
*fields
,
105 extern bool proto_field_is_set(struct proto_hdr
*hdr
, uint32_t fid
);
106 extern void proto_field_set_bytes(struct proto_hdr
*hdr
, uint32_t fid
,
107 const uint8_t *bytes
);
108 extern void proto_field_set_u8(struct proto_hdr
*hdr
, uint32_t fid
, uint8_t val
);
109 extern uint8_t proto_field_get_u8(struct proto_hdr
*hdr
, uint32_t fid
);
110 extern void proto_field_set_u16(struct proto_hdr
*hdr
, uint32_t fid
, uint16_t val
);
111 extern uint16_t proto_field_get_u16(struct proto_hdr
*hdr
, uint32_t fid
);
112 extern void proto_field_set_u32(struct proto_hdr
*hdr
, uint32_t fid
, uint32_t val
);
113 extern uint32_t proto_field_get_u32(struct proto_hdr
*hdr
, uint32_t fid
);
115 extern void proto_field_set_default_bytes(struct proto_hdr
*hdr
, uint32_t fid
,
116 const uint8_t *bytes
);
117 extern void proto_field_set_default_u8(struct proto_hdr
*hdr
, uint32_t fid
,
119 extern void proto_field_set_default_u16(struct proto_hdr
*hdr
, uint32_t fid
,
121 extern void proto_field_set_default_u32(struct proto_hdr
*hdr
, uint32_t fid
,
124 extern void proto_field_set_be16(struct proto_hdr
*hdr
, uint32_t fid
, uint16_t val
);
125 extern void proto_field_set_be32(struct proto_hdr
*hdr
, uint32_t fid
, uint32_t val
);
127 extern void proto_field_set_default_be16(struct proto_hdr
*hdr
, uint32_t fid
,
129 extern void proto_field_set_default_be32(struct proto_hdr
*hdr
, uint32_t fid
,
132 extern void proto_field_set_dev_mac(struct proto_hdr
*hdr
, uint32_t fid
);
133 extern void proto_field_set_default_dev_mac(struct proto_hdr
*hdr
, uint32_t fid
);
135 extern void proto_field_set_dev_ipv4(struct proto_hdr
*hdr
, uint32_t fid
);
136 extern void proto_field_set_default_dev_ipv4(struct proto_hdr
*hdr
, uint32_t fid
);
138 extern void proto_field_set_dev_ipv6(struct proto_hdr
*hdr
, uint32_t fid
);
139 extern void proto_field_set_default_dev_ipv6(struct proto_hdr
*hdr
, uint32_t fid
);
141 extern void proto_field_dyn_apply(struct proto_field
*field
);
143 extern void proto_field_func_add(struct proto_hdr
*hdr
, uint32_t fid
,
144 struct proto_field_func
*func
);
146 #endif /* TRAFGEN_PROTO_H */