summaryrefslogtreecommitdiffstats
path: root/include/protocol.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/protocol.h')
-rw-r--r--include/protocol.h35
1 files changed, 29 insertions, 6 deletions
diff --git a/include/protocol.h b/include/protocol.h
index 34ad4a3..38f5aa9 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -23,10 +23,11 @@
#include <errno.h>
-#define E_TLV_OVERFLOW (1 << 0)
+#define E_TLV_OVERFLOW (1 << 0)
#define E_UNKNOWN_TYPE (1 << 1)
-#define E_IVALID_DESCRIPTOR (1 << 2)
-#define END_OF_PACKET (1 << 3)
+#define END_OF_PACKET (1 << 2)
+
+#define TLV_SZ_MAX_RAW (MTU - 64)
/**
* Regular packets contain tlv's defined by tlv_type.
@@ -122,16 +123,38 @@ int get_tlv(struct tlv_parser *parser, struct tlv *ret);
* */
int push_data(struct tlv_packet *packet, enum tlv_type type, char *data);
-
/**
* Resets offset to 0 and set entire buffer to 0.
*/
void clear_data(struct tlv_packet *packet);
+/**
+ * Initialises tlv to sane values.
+ */
+void tlv_init(struct tlv *t);
+
+/**
+ * Frees data held in the tlv structure. The structure itself shall be freed as
+ * needed by calling code.
+ */
+void tlv_destroy(struct tlv *t);
+
+/**
+ * Tells amount of bytes needed to push tlv to a buffer
+ */
+size_t tlv_raw_size(struct tlv *t);
+
+/**
+ * Pushes tlv to buffer as contiguous data. Check tlv size with tlv_raw_size
+ * beforehand. If you don't do that and overflow --- tough tiddy.
+ */
+int tlv_get_raw(struct tlv *t, char *buf);
/**
- * Tells what size of buffer is needed for next tlv.
+ * Pushes data to tlv. Returns E_TLV_OVERFLOW if pushing data would cause the
+ * final size to be greater than TLV_SZ_MAX_RAW. In case of such error the data is left
+ * untouched.
*/
-size_t tlv_data_size(struct tlv_parser *parser);
+int tlv_push(struct tlv *t, const char *data, size_t size);
#endif /* USURPATION_PROTOCOL_H_INCLUDED */