-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathveip.h
115 lines (101 loc) · 3.06 KB
/
veip.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Copyright (c) 2012,2013 Open Cloud Demonstration Experiments Taskforce.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
// Copyright(C) 2012, Open Cloud Demonstration Experiments Taskforce.
//
// veip.h 0.1
//
// VEIP header files.
//
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <net/ethernet.h>
#include <netinet/ip.h>
#include <netinet/if_ether.h>
#include <netdb.h>
#include <time.h>
// Linux dependent
#ifdef LINUX
#include <linux/if.h>
#include <netpacket/packet.h>
#ifndef ETHERTYPE_IPV6
#define ETHERTYPE_IPV6 ETH_P_IPV6
#endif
#ifndef ETHERTYPE_VLAN
#define ETHERTYPE_VLAN ETH_P_8021Q
#endif
#endif
// BSD dependent
#ifdef BSD
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#define VEIP 59999 // VEIP port number, unofficial
#define CNTL 60001 // VEIP-GW control port, unofficial
#define MAX_PEER_NUM 32 // max veip peer number
#define LINLEN 128 // max line length of CLI or LOG
#define BUFS 2048 // buf size for test
#define PORT 6111 // UDP port for test
// ARP Table buffer (like mbuf)
struct abuf { // address buffer
struct abuf * a_next;
struct abuf * nxtbuf;
time_t tm; // access time.
//in_addr_t vp_gw; // remote gateway ip addr]
// shoud be union, remote gw and local dev like below
union {
in_addr_t vp_gw; // remote gateway in ip addr
char * device; // local device name like 'eth0'
} target;
in_addr_t ip; // dst ip address
u_char eha[ETHER_ADDR_LEN]; // dst ethernet address
u_char pad[2]; // 32 bit boundary.
};
// VEIP header
struct vphdr {
u_short vp_frg; // fragment field
#define NO_FRGMNT 0x1000 // no fragment packet
#define FRAG_STRT 0x2000 // fragmented start packet
#define FRAG_STOP 0x4000 // fragmented stop packet
#define ADDR_RSOL 0x8000 // address resolution packet
#define OFST_MASK 0x0FFF // offset mask
u_short vp_len; // payload length excluding hdr
u_short vp_id; // veip ID
u_short vp_pad; // reserved, 32 bit boundary
};
// Packet buffer
struct pbuf { // packet buffer
struct pbuf * p_next; // next buf
char * vp_pkt; // veip packet including inner ethernet frame
time_t tm; // access time. shoud be usec
struct vphdr vphdr; // index
};
// VEIP-GW remote Peer with sending packet
struct vpeer {
char * name; // peer name;
in_addr_t vp_gw; // IP address in 32bit u_int.
int sock; // sockdet descriptor to send packet.
};