packet: move some common code out of wrapper.c and util.c

This commit is contained in:
Nick Thomas
2013-08-06 14:34:53 +01:00
parent 94b451a1ac
commit 202b77bb57
6 changed files with 80 additions and 75 deletions

View File

@@ -1,18 +1,11 @@
#include "util.h"
#include "rlocs.h"
// We use a TUN device right now so we don't have to care about layer 2 headers
// or complicated, hard scaling stuff. This isn't likely to scale very well.
#include <assert.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
#include "packet.h"
// We use writev() to send the packet, so we don't have to copy the
// unencrypted part.
@@ -25,32 +18,6 @@ typedef struct wrapper {
int same_if;
} wrapper;
struct recv_pkt {
union {
#ifdef __USE_BSD
struct ip ip;
#else
struct iphdr ip;
#endif
struct ip6_hdr ip6;
} hdr;
char payload[IP_MAXPACKET]; /* payload is this - header size, but OK */
};
// It's all our code that uses this. 12 is more than we probably need to
// construct a wrapped packet - just being careful.
//
// initial usage:
// 0 - wrapping ip header, including enc_size
// 1 - encrypted portion of payload, in scratch.
// 2 - unencrypted portion of payload, in recv_pkt
#define MAX_IOVS 12
struct rsp_data {
int count;
struct iovec iovs[MAX_IOVS];
unsigned char scratch[IP_MAXPACKET]; // somewhere easy to put results
};
int wrap_ipv4_packet(struct rlocs* reg, struct recv_pkt* pkt, struct rsp_data* out)
{
@@ -173,7 +140,7 @@ int wrap_ipv6_packet(struct rlocs *reg, struct recv_pkt* pkt, struct rsp_data* o
int main(int argc, char** argv)
{
wrapper wrap;
if ( argc < 4 ) {
warn( "Usage: %s <rloc database> <listen_ifname> <output_ifname>", argv[0] );
return 1;