aboutsummaryrefslogtreecommitdiff
path: root/src/ppkt.h
blob: 5772fe8edb681efaed5472fed1385c03e7be78eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef PPKT_H
#define PPKT_H 1

#include <netinet/ip_icmp.h>
#include <stdint.h>
#include <sys/socket.h>

#define PTUNNEL_MAGIC 0xdeadc0de

#define U8_PTYPE_AUTH_REQUEST 0x01u
#define U8_PTYPE_AUTH_RESPONSE 0x02u

enum ptype {
    PTYPE_INVALID = 0,
    PTYPE_AUTH_REQUEST = U8_PTYPE_AUTH_REQUEST,
    PTYPE_AUTH_RESPONSE = U8_PTYPE_AUTH_RESPONSE,
};

struct psock;
struct pdesc;

struct ppkt_auth_request {
    uint32_t magic;
    uint16_t hash_siz;
    uint8_t hash[0];
} __attribute__((__packed__));

struct ppkt_auth_response {
    uint8_t code;
} __attribute__((__packed__));

struct ppkt {
    uint16_t total_size;
    uint8_t type;
    uint8_t data[0];
} __attribute__((__packed__));

struct ppkt_buffer {
    struct iovec iovec[4];
    size_t iovec_used;

    struct icmphdr icmphdr;
    struct ppkt pkt;
    union {
        struct ppkt_auth_request auth_request;
        struct ppkt_auth_response auth_response;
    };
};

enum ptype ppkt_type_to_enum(struct ppkt *);

int ppkt_process_icmp(struct psock *);

int ppkt_process_ppkt(struct psock *);

void ppkt_prepare_auth_request(struct pdesc *, struct ppkt_buffer *, uint8_t *, size_t);

#endif