]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Add IPvx prefix PDU types and serialization, create buffer struct
authorpcarana <pc.moreno2099@gmail.com>
Fri, 22 Feb 2019 01:02:38 +0000 (19:02 -0600)
committerpcarana <pc.moreno2099@gmail.com>
Fri, 22 Feb 2019 01:02:38 +0000 (19:02 -0600)
src/rtr/pdu.h
src/rtr/pdu_serializer.c
src/rtr/pdu_serializer.h

index 8d49d2b31ba29ad07355a465b382f85fe176e116..dc9530bbeacd7c62bc310a1493d6cd7c1c20c333 100644 (file)
@@ -10,6 +10,8 @@
 #define RTR_V1 1
 
 #define CACHE_RESPONSE_PDU_TYPE                3
+#define IPV4_PREFIX_PDU_TYPE           4
+#define IPV6_PREFIX_PDU_TYPE           6
 #define END_OF_DATA_PDU_TYPE           7
 
 struct pdu_header {
index a580834288c90116f2871dd5e2dd63ba48535660..524a3df2893eab4480b920499147c4938ed7d88a 100644 (file)
@@ -1,7 +1,21 @@
 #include "pdu_serializer.h"
 
+#include <stdlib.h>
 #include "primitive_writer.h"
 
+void
+init_buffer(struct data_buffer *buffer)
+{
+       buffer->capacity = BUFFER_SIZE;
+       buffer->data = malloc(BUFFER_SIZE);
+}
+
+void
+free_buffer(struct data_buffer *buffer)
+{
+       free(buffer->data);
+}
+
 static size_t
 serialize_pdu_header(struct pdu_header *header, u_int16_t union_value,
     char *buf)
@@ -13,6 +27,7 @@ serialize_pdu_header(struct pdu_header *header, u_int16_t union_value,
        ptr = write_int8(ptr, header->pdu_type);
        ptr = write_int16(ptr, union_value);
        ptr = write_int32(ptr, header->length);
+
        return ptr - buf;
 }
 
@@ -33,15 +48,39 @@ serialize_cache_response_pdu(struct cache_response_pdu *pdu, char *buf)
 size_t
 serialize_ipv4_prefix_pdu(struct ipv4_prefix_pdu *pdu, char *buf)
 {
-       // FIXME Complete me!
-       return 0;
+       size_t head_size;
+       char *ptr;
+
+       head_size = serialize_pdu_header(&pdu->header, pdu->header.reserved, buf);
+
+       ptr = buf + head_size;
+       ptr = write_int8(ptr, pdu->flags);
+       ptr = write_int8(ptr, pdu->prefix_length);
+       ptr = write_int8(ptr, pdu->max_length);
+       ptr = write_int8(ptr, pdu->zero);
+       ptr = write_in_addr(ptr, pdu->ipv4_prefix);
+       ptr = write_int32(ptr, pdu->asn);
+
+       return ptr - buf;
 }
 
 size_t
 serialize_ipv6_prefix_pdu(struct ipv6_prefix_pdu *pdu, char *buf)
 {
-       // FIXME Complete me!
-       return 0;
+       size_t head_size;
+       char *ptr;
+
+       head_size = serialize_pdu_header(&pdu->header, pdu->header.reserved, buf);
+
+       ptr = buf + head_size;
+       ptr = write_int8(ptr, pdu->flags);
+       ptr = write_int8(ptr, pdu->prefix_length);
+       ptr = write_int8(ptr, pdu->max_length);
+       ptr = write_int8(ptr, pdu->zero);
+       ptr = write_in6_addr(ptr, pdu->ipv6_prefix);
+       ptr = write_int32(ptr, pdu->asn);
+
+       return ptr - buf;
 }
 
 size_t
index ef449c4004a7059f84e327d00f37b9ccf3517003..9f99a14045263e80f76cec2ca272291b7ee91433 100644 (file)
@@ -3,7 +3,18 @@
 
 #include "pdu.h"
 
+#define BUFFER_SIZE 32
+
+struct data_buffer {
+       size_t len;
+       size_t capacity;
+       char *data;
+};
+
 __BEGIN_DECLS
+void init_buffer(struct data_buffer *);
+void free_buffer(struct data_buffer *);
+
 size_t serialize_serial_notify_pdu(struct serial_notify_pdu *, char *);
 size_t serialize_cache_response_pdu(struct cache_response_pdu *, char *);
 size_t serialize_ipv4_prefix_pdu(struct ipv4_prefix_pdu *, char *);