From: pcarana Date: Fri, 22 Feb 2019 01:02:38 +0000 (-0600) Subject: Add IPvx prefix PDU types and serialization, create buffer struct X-Git-Tag: v0.0.2~52^2~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=197c2c0ae26fcbbaed901e9cba916e5051254497;p=thirdparty%2FFORT-validator.git Add IPvx prefix PDU types and serialization, create buffer struct --- diff --git a/src/rtr/pdu.h b/src/rtr/pdu.h index 8d49d2b3..dc9530bb 100644 --- a/src/rtr/pdu.h +++ b/src/rtr/pdu.h @@ -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 { diff --git a/src/rtr/pdu_serializer.c b/src/rtr/pdu_serializer.c index a5808342..524a3df2 100644 --- a/src/rtr/pdu_serializer.c +++ b/src/rtr/pdu_serializer.c @@ -1,7 +1,21 @@ #include "pdu_serializer.h" +#include #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 diff --git a/src/rtr/pdu_serializer.h b/src/rtr/pdu_serializer.h index ef449c40..9f99a140 100644 --- a/src/rtr/pdu_serializer.h +++ b/src/rtr/pdu_serializer.h @@ -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 *);