67 lines
1.6 KiB
C
67 lines
1.6 KiB
C
#ifndef _PACKET_H_
|
|
#define _PACKET_H_
|
|
|
|
#include <arpa/inet.h>
|
|
#include <netinet/ip.h>
|
|
#include <netinet/ip6.h>
|
|
#include <netinet/ip_icmp.h>
|
|
|
|
#define IPPROTO_HIDE_EID 99
|
|
|
|
// IP header + IV + tag + block cipher max overhead
|
|
#define WRAP_OVERHEAD 20 + 16 + 16 + 16 + 2
|
|
|
|
#ifndef IP_DF
|
|
#define IP_DF 0x4000 /* dont fragment flag */
|
|
#endif
|
|
|
|
#ifndef IP_MF
|
|
#define IP_MF 0x2000 /* more fragments flag */
|
|
#endif
|
|
|
|
struct packet {
|
|
union {
|
|
struct iphdr ip;
|
|
struct ip6_hdr ip6;
|
|
} hdr;
|
|
char payload[IP_MAXPACKET]; /* payload can be this - header size, but OK */
|
|
};
|
|
|
|
// It's all our code that uses this. 12 is much more than we need to
|
|
// construct a wrapped packet at the moment.
|
|
//
|
|
// 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 3
|
|
struct rsp_data {
|
|
int count;
|
|
struct iovec iovs[MAX_IOVS];
|
|
unsigned char scratch[IP_MAXPACKET * 2]; // somewhere easy to put results
|
|
};
|
|
|
|
|
|
static inline int packet_find_protocol( struct packet *pkt )
|
|
{
|
|
if ( pkt->hdr.ip.version == 0x04 ) {
|
|
return pkt->hdr.ip.protocol;
|
|
}
|
|
|
|
if ( pkt->hdr.ip.version == 0x06 ) {
|
|
return pkt->hdr.ip6.ip6_nxt;
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
void compute_ip_checksum( struct iphdr* pkt );
|
|
|
|
int wrap_packet( struct rlocs *reg, struct packet *pkt, struct rsp_data *frag1, struct rsp_data *frag2 );
|
|
int unwrap_packet( struct rlocs *reg, struct packet *pkt, struct rsp_data *out );
|
|
|
|
struct peer_context *packet_peer_context( struct rlocs *reg, struct packet *pkt, int direction );
|
|
|
|
|
|
#endif
|