Add a variable offset to vpn_packet_t, drop sptps_packet_t.

The offset value indicates where the actual payload starts, so we can
process both legacy and SPTPS UDP packets without having to do casting
tricks and/or moving memory around.
This commit is contained in:
Guus Sliepen 2014-12-24 22:23:24 +01:00
parent 107d9c7da5
commit 6b92ac505d
14 changed files with 234 additions and 212 deletions

View file

@ -57,6 +57,7 @@ typedef struct node_id_t {
} node_id_t;
typedef short length_t;
typedef uint32_t seqno_t;
#define AF_UNKNOWN 255
@ -84,21 +85,19 @@ typedef union sockaddr_t {
#define SALEN(s) (s.sa_family==AF_INET?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6))
#endif
#define SEQNO(x) ((x)->data + (x)->offset - 4)
#define SRCID(x) ((node_id_t *)((x)->data + (x)->offset - 6))
#define DSTID(x) ((node_id_t *)((x)->data + (x)->offset - 12))
#define DATA(x) ((x)->data + (x)->offset)
#define DEFAULT_PACKET_OFFSET 12
typedef struct vpn_packet_t {
length_t len; /* the actual number of bytes in the `data' field */
length_t len; /* The actual number of valid bytes in the `data' field (including seqno or dstid/srcid) */
length_t offset; /* Offset in the buffer where the packet data starts (righter after seqno or dstid/srcid) */
int priority; /* priority or TOS */
uint32_t seqno; /* 32 bits sequence number (network byte order of course) */
uint8_t data[MAXSIZE];
} vpn_packet_t;
typedef struct sptps_packet_t {
length_t len; /* the actual number of bytes in the `data' field */
int priority; /* priority or TOS */
node_id_t dstid; /* node ID of the final recipient */
node_id_t srcid; /* node ID of the original sender */
char data[MAXSIZE];
} sptps_packet_t;
/* Packet types when using SPTPS */
#define PKT_COMPRESSED 1