mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-12-26 01:59:53 +03:00
Merge pull request #1125 from Evengard/ppp-ipv6
IPv6 support for the PPP stack
This commit is contained in:
commit
1a8e1385cf
@ -232,12 +232,12 @@ TOKEN_LIST *GetEthListSolaris()
|
||||
lifc.lifc_family = AF_INET;
|
||||
lifc.lifc_flags = 0;
|
||||
lifc.lifc_len = bufsize;
|
||||
lifc.lifc_buf = (char*) buf;
|
||||
lifc.lifc_buf = (char *) buf;
|
||||
if (ioctl(s, SIOCGLIFCONF, (char *)&lifc) >= 0)
|
||||
{
|
||||
for (i = 0; i<numifs; i++)
|
||||
{
|
||||
if(StartWith(buf[i].lifr_name, "lo") == false){
|
||||
if(StartWith(buf[i].lifr_name, "lo") == false) {
|
||||
Add(o, CopyStr(buf[i].lifr_name));
|
||||
}
|
||||
}
|
||||
@ -253,7 +253,7 @@ TOKEN_LIST *GetEthListSolaris()
|
||||
t->NumTokens = LIST_NUM(o);
|
||||
t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);
|
||||
|
||||
for (i = 0;i < LIST_NUM(o);i++)
|
||||
for (i = 0; i < LIST_NUM(o); i++)
|
||||
{
|
||||
char *name = LIST_DATA(o, i);
|
||||
t->Token[i] = name;
|
||||
@ -287,7 +287,7 @@ TOKEN_LIST *GetEthListLinux(bool enum_normal, bool enum_rawip)
|
||||
if (s != INVALID_SOCKET)
|
||||
{
|
||||
n = 0;
|
||||
for (i = 0;;i++)
|
||||
for (i = 0;; i++)
|
||||
{
|
||||
Zero(&ifr, sizeof(ifr));
|
||||
ifr.ifr_ifindex = i;
|
||||
@ -332,7 +332,7 @@ TOKEN_LIST *GetEthListLinux(bool enum_normal, bool enum_rawip)
|
||||
t->NumTokens = LIST_NUM(o) + (enum_rawip ? 1 : 0);
|
||||
t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);
|
||||
|
||||
for (i = 0;i < LIST_NUM(o);i++)
|
||||
for (i = 0; i < LIST_NUM(o); i++)
|
||||
{
|
||||
char *name = LIST_DATA(o, i);
|
||||
t->Token[i] = name;
|
||||
@ -372,9 +372,9 @@ TOKEN_LIST *GetEthListPcap()
|
||||
if(p != NULL)
|
||||
{
|
||||
int datalink = pcap_datalink(p);
|
||||
// Debug("type:%s\n",pcap_datalink_val_to_name(datalink));
|
||||
// Debug("type:%s\n",pcap_datalink_val_to_name(datalink));
|
||||
pcap_close(p);
|
||||
if(datalink == DLT_EN10MB){
|
||||
if(datalink == DLT_EN10MB) {
|
||||
// Enumerate only Ethernet type device
|
||||
Add(o, CopyStr(dev->name));
|
||||
}
|
||||
@ -388,7 +388,7 @@ TOKEN_LIST *GetEthListPcap()
|
||||
t = ZeroMalloc(sizeof(TOKEN_LIST));
|
||||
t->NumTokens = LIST_NUM(o);
|
||||
t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);
|
||||
for (i = 0;i < LIST_NUM(o);i++)
|
||||
for (i = 0; i < LIST_NUM(o); i++)
|
||||
{
|
||||
t->Token[i] = LIST_DATA(o, i);
|
||||
}
|
||||
@ -415,7 +415,7 @@ TOKEN_LIST *GetEthListBpf()
|
||||
struct ifaddrs *ifadr = ifadrs;
|
||||
while(ifadr)
|
||||
{
|
||||
sockadr = (struct sockaddr_dl*)ifadr->ifa_addr;
|
||||
sockadr = (struct sockaddr_dl *)ifadr->ifa_addr;
|
||||
if(sockadr->sdl_family == AF_LINK && sockadr->sdl_type == IFT_ETHER)
|
||||
{
|
||||
// Is this Ethernet device?
|
||||
@ -434,7 +434,7 @@ TOKEN_LIST *GetEthListBpf()
|
||||
t = ZeroMalloc(sizeof(TOKEN_LIST));
|
||||
t->NumTokens = LIST_NUM(o);
|
||||
t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens);
|
||||
for (i = 0;i < LIST_NUM(o);i++)
|
||||
for (i = 0; i < LIST_NUM(o); i++)
|
||||
{
|
||||
t->Token[i] = LIST_DATA(o, i);
|
||||
}
|
||||
@ -1070,7 +1070,7 @@ bool ParseUnixEthDeviceName(char *dst_devname, UINT dst_devname_size, char *src_
|
||||
|
||||
#if defined(BRIDGE_BPF) || defined(BRIDGE_PCAP)
|
||||
// Initialize captured packet data structure
|
||||
struct CAPTUREBLOCK *NewCaptureBlock(UCHAR *data, UINT size){
|
||||
struct CAPTUREBLOCK *NewCaptureBlock(UCHAR *data, UINT size) {
|
||||
struct CAPTUREBLOCK *block = Malloc(sizeof(struct CAPTUREBLOCK));
|
||||
block->Buf = data;
|
||||
block->Size = size;
|
||||
@ -1078,7 +1078,7 @@ struct CAPTUREBLOCK *NewCaptureBlock(UCHAR *data, UINT size){
|
||||
}
|
||||
|
||||
// Free captured packet data structure
|
||||
void FreeCaptureBlock(struct CAPTUREBLOCK *block){
|
||||
void FreeCaptureBlock(struct CAPTUREBLOCK *block) {
|
||||
Free(block);
|
||||
}
|
||||
#endif // BRIDGE_BPF || BRIDGE_PCAP
|
||||
@ -1087,7 +1087,7 @@ void FreeCaptureBlock(struct CAPTUREBLOCK *block){
|
||||
// Callback function to receive arriving packet (Pcap)
|
||||
void PcapHandler(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes)
|
||||
{
|
||||
ETH *e = (ETH*) user;
|
||||
ETH *e = (ETH *) user;
|
||||
struct CAPTUREBLOCK *block;
|
||||
UCHAR *data;
|
||||
|
||||
@ -1096,7 +1096,7 @@ void PcapHandler(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes)
|
||||
block = NewCaptureBlock(data, h->caplen);
|
||||
LockQueue(e->Queue);
|
||||
// Discard arriving packet when queue filled
|
||||
if(e->QueueSize < BRIDGE_MAX_QUEUE_SIZE){
|
||||
if(e->QueueSize < BRIDGE_MAX_QUEUE_SIZE) {
|
||||
InsertQueue(e->Queue, block);
|
||||
e->QueueSize += h->caplen;
|
||||
}
|
||||
@ -1108,7 +1108,7 @@ void PcapHandler(u_char *user, const struct pcap_pkthdr *h, const u_char *bytes)
|
||||
// Relay thread for captured packet (Pcap)
|
||||
void PcapThread(THREAD *thread, void *param)
|
||||
{
|
||||
ETH *e = (ETH*)param;
|
||||
ETH *e = (ETH *)param;
|
||||
pcap_t *p = e->Pcap;
|
||||
int ret;
|
||||
|
||||
@ -1116,8 +1116,8 @@ void PcapThread(THREAD *thread, void *param)
|
||||
NoticeThreadInit(thread);
|
||||
|
||||
// Return -1:Error -2:Terminated externally
|
||||
ret = pcap_loop(p, -1, PcapHandler, (u_char*) e);
|
||||
if(ret == -1){
|
||||
ret = pcap_loop(p, -1, PcapHandler, (u_char *) e);
|
||||
if(ret == -1) {
|
||||
e->Socket = INVALID_SOCKET;
|
||||
pcap_perror(p, "capture");
|
||||
}
|
||||
@ -1181,7 +1181,7 @@ ETH *OpenEthPcap(char *name, bool local, bool tapmode, char *tapaddr)
|
||||
// Relay thread for captured packet (BPF)
|
||||
void BpfThread(THREAD *thread, void *param)
|
||||
{
|
||||
ETH *e = (ETH*)param;
|
||||
ETH *e = (ETH *)param;
|
||||
int fd = e->Socket;
|
||||
int len;
|
||||
int rest; // Rest size in buffer
|
||||
@ -1196,14 +1196,14 @@ void BpfThread(THREAD *thread, void *param)
|
||||
// Notify initialize completed
|
||||
NoticeThreadInit(thread);
|
||||
|
||||
while(1){
|
||||
while(1) {
|
||||
// Determining to exit loop
|
||||
if(e->Socket == INVALID_SOCKET){
|
||||
if(e->Socket == INVALID_SOCKET) {
|
||||
break;
|
||||
}
|
||||
|
||||
rest = read(fd, buf, e->BufSize);
|
||||
if(rest < 0 && errno != EAGAIN){
|
||||
if(rest < 0 && errno != EAGAIN) {
|
||||
// Error
|
||||
close(fd);
|
||||
e->Socket = INVALID_SOCKET;
|
||||
@ -1213,12 +1213,12 @@ void BpfThread(THREAD *thread, void *param)
|
||||
}
|
||||
next = buf;
|
||||
LockQueue(e->Queue);
|
||||
while(rest>0){
|
||||
while(rest>0) {
|
||||
// Cut out a packet
|
||||
hdr = (struct bpf_hdr*)next;
|
||||
hdr = (struct bpf_hdr *)next;
|
||||
|
||||
// Discard arriving packet when queue filled
|
||||
if(e->QueueSize < BRIDGE_MAX_QUEUE_SIZE){
|
||||
if(e->QueueSize < BRIDGE_MAX_QUEUE_SIZE) {
|
||||
data = Malloc(hdr->bh_caplen);
|
||||
Copy(data, next+(hdr->bh_hdrlen), hdr->bh_caplen);
|
||||
block = NewCaptureBlock(data, hdr->bh_caplen);
|
||||
@ -1253,31 +1253,31 @@ ETH *OpenEthBpf(char *name, bool local, bool tapmode, char *tapaddr)
|
||||
struct timeval to;
|
||||
|
||||
// Find unused bpf device and open it
|
||||
do{
|
||||
do {
|
||||
Format(devname, sizeof(devname), "/dev/bpf%d", n++);
|
||||
fd = open (devname, O_RDWR);
|
||||
if(fd<0){
|
||||
if(fd<0) {
|
||||
perror("open");
|
||||
}
|
||||
}while(fd < 0 && errno == EBUSY);
|
||||
} while(fd < 0 && errno == EBUSY);
|
||||
|
||||
// No free bpf device was found
|
||||
if(fd < 0){
|
||||
if(fd < 0) {
|
||||
Debug("BPF: No minor number are free.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Enlarge buffer size
|
||||
n = 524288; // Somehow(In libpcap, this size is 32768)
|
||||
while(true){
|
||||
while(true) {
|
||||
// Specify buffer size
|
||||
ioctl(fd, BIOCSBLEN, &n);
|
||||
|
||||
// Bind to the network device
|
||||
StrCpy(ifr.ifr_name, IFNAMSIZ, name);
|
||||
ret = ioctl(fd, BIOCSETIF, &ifr);
|
||||
if(ret < 0){
|
||||
if(ret == ENOBUFS && n>1500){
|
||||
if(ret < 0) {
|
||||
if(ret == ENOBUFS && n>1500) {
|
||||
// Inappropriate buffer size
|
||||
// Retry with half buffer size
|
||||
// If buffer size is under 1500 bytes, something goes wrong
|
||||
@ -1287,15 +1287,15 @@ ETH *OpenEthBpf(char *name, bool local, bool tapmode, char *tapaddr)
|
||||
Debug("bpf: binding network failed.\n");
|
||||
close(fd);
|
||||
return NULL;
|
||||
}else{
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
bufsize = n;
|
||||
|
||||
// Set to promiscuous mode
|
||||
if(local == false){
|
||||
if (ioctl(fd, BIOCPROMISC, NULL) < 0){
|
||||
if(local == false) {
|
||||
if (ioctl(fd, BIOCPROMISC, NULL) < 0) {
|
||||
printf("bpf: promisc mode failed.\n");
|
||||
close(fd);
|
||||
return NULL;
|
||||
@ -1305,7 +1305,7 @@ ETH *OpenEthBpf(char *name, bool local, bool tapmode, char *tapaddr)
|
||||
|
||||
// Set to immediate mode (Return immediately when packet arrives)
|
||||
n = 1;
|
||||
if (ioctl(fd, BIOCIMMEDIATE, &n) < 0){
|
||||
if (ioctl(fd, BIOCIMMEDIATE, &n) < 0) {
|
||||
Debug("BPF: non-block mode failed.\n");
|
||||
close(fd);
|
||||
return NULL;
|
||||
@ -1313,7 +1313,7 @@ ETH *OpenEthBpf(char *name, bool local, bool tapmode, char *tapaddr)
|
||||
|
||||
// Set receiving self sending packet
|
||||
n = 1;
|
||||
if (ioctl(fd, BIOCGSEESENT, &n) < 0){
|
||||
if (ioctl(fd, BIOCGSEESENT, &n) < 0) {
|
||||
Debug("BPF: see sent mode failed.\n");
|
||||
close(fd);
|
||||
return NULL;
|
||||
@ -1321,7 +1321,7 @@ ETH *OpenEthBpf(char *name, bool local, bool tapmode, char *tapaddr)
|
||||
|
||||
// Header complete mode (Generate whole header of sending packet)
|
||||
n = 1;
|
||||
if (ioctl(fd, BIOCSHDRCMPLT, &n) < 0){
|
||||
if (ioctl(fd, BIOCSHDRCMPLT, &n) < 0) {
|
||||
Debug("BPF: Header complete mode failed.\n");
|
||||
close(fd);
|
||||
return NULL;
|
||||
@ -1330,7 +1330,7 @@ ETH *OpenEthBpf(char *name, bool local, bool tapmode, char *tapaddr)
|
||||
// Set timeout delay to 1 second
|
||||
to.tv_sec = 1;
|
||||
to.tv_usec = 0;
|
||||
if (ioctl(fd, BIOCSRTIMEOUT, &to) < 0){
|
||||
if (ioctl(fd, BIOCSRTIMEOUT, &to) < 0) {
|
||||
Debug("BPF: Read timeout setting failed.\n");
|
||||
close(fd);
|
||||
return NULL;
|
||||
@ -1401,16 +1401,16 @@ ETH *OpenEthBSD(char *name, bool local, bool tapmode, char *tapaddr)
|
||||
|
||||
return e;
|
||||
#else // NO_VLAN
|
||||
return NULL:
|
||||
return NULL:
|
||||
#endif // NO_VLAN
|
||||
}
|
||||
|
||||
#if defined(BRIDGE_BPF)
|
||||
return OpenEthBpf(name, local, tapmode, tapaddr);
|
||||
return OpenEthBpf(name, local, tapmode, tapaddr);
|
||||
#elif defined(BRIDGE_PCAP)
|
||||
return OpenEthPcap(name, local, tapmode, tapaddr);
|
||||
return OpenEthPcap(name, local, tapmode, tapaddr);
|
||||
#else
|
||||
return NULL;
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
#endif // UNIX_BSD
|
||||
@ -1471,7 +1471,7 @@ void CloseEth(ETH *e)
|
||||
WaitThread(e->CaptureThread, INFINITE);
|
||||
ReleaseThread(e->CaptureThread);
|
||||
pcap_close(e->Pcap);
|
||||
while (block = GetNext(e->Queue)){
|
||||
while (block = GetNext(e->Queue)) {
|
||||
Free(block->Buf);
|
||||
FreeCaptureBlock(block);
|
||||
}
|
||||
@ -1488,7 +1488,7 @@ void CloseEth(ETH *e)
|
||||
WaitThread(e->CaptureThread, INFINITE);
|
||||
ReleaseThread(e->CaptureThread);
|
||||
e->Socket = fd; // restore to close after
|
||||
while (block = GetNext(e->Queue)){
|
||||
while (block = GetNext(e->Queue)) {
|
||||
Free(block->Buf);
|
||||
FreeCaptureBlock(block);
|
||||
}
|
||||
@ -1660,8 +1660,8 @@ UINT EthGetPacketLinux(ETH *e, void **data)
|
||||
USHORT vlan_id = 0;
|
||||
|
||||
if (cmsg->cmsg_len < CMSG_LEN(sizeof(struct my_tpacket_auxdata)) ||
|
||||
cmsg->cmsg_level != SOL_PACKET ||
|
||||
cmsg->cmsg_type != MY_PACKET_AUXDATA)
|
||||
cmsg->cmsg_level != SOL_PACKET ||
|
||||
cmsg->cmsg_type != MY_PACKET_AUXDATA)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -1772,14 +1772,14 @@ UINT EthGetPacketPcap(ETH *e, void **data)
|
||||
|
||||
LockQueue(e->Queue);
|
||||
block = GetNext(e->Queue);
|
||||
if(block != NULL){
|
||||
if(block != NULL) {
|
||||
e->QueueSize -= block->Size;
|
||||
}
|
||||
UnlockQueue(e->Queue);
|
||||
|
||||
if(block == NULL){
|
||||
if(block == NULL) {
|
||||
*data = NULL;
|
||||
if(e->Socket == INVALID_SOCKET){
|
||||
if(e->Socket == INVALID_SOCKET) {
|
||||
return INFINITE;
|
||||
}
|
||||
return 0;
|
||||
@ -1802,14 +1802,14 @@ UINT EthGetPacketBpf(ETH *e, void **data)
|
||||
|
||||
LockQueue(e->Queue);
|
||||
block = GetNext(e->Queue);
|
||||
if(block != NULL){
|
||||
if(block != NULL) {
|
||||
e->QueueSize -= block->Size;
|
||||
}
|
||||
UnlockQueue(e->Queue);
|
||||
|
||||
if(block == NULL){
|
||||
if(block == NULL) {
|
||||
*data = NULL;
|
||||
if(e->Socket == INVALID_SOCKET){
|
||||
if(e->Socket == INVALID_SOCKET) {
|
||||
return INFINITE;
|
||||
}
|
||||
return 0;
|
||||
@ -1826,11 +1826,11 @@ UINT EthGetPacketBpf(ETH *e, void **data)
|
||||
{
|
||||
struct bpf_hdr *hdr;
|
||||
|
||||
if(e->Rest<=0){
|
||||
if(e->Rest<=0) {
|
||||
e->Rest = read(e->Socket, e->Buffer, e->BufSize);
|
||||
if(e->Rest < 0){
|
||||
if(e->Rest < 0) {
|
||||
*data = NULL;
|
||||
if(errno != EAGAIN){
|
||||
if(errno != EAGAIN) {
|
||||
// Error
|
||||
return INFINITE;
|
||||
}
|
||||
@ -1840,7 +1840,7 @@ UINT EthGetPacketBpf(ETH *e, void **data)
|
||||
e->Next = e->Buffer;
|
||||
}
|
||||
// Cut out a packet
|
||||
hdr = (struct bpf_hdr*)e->Next;
|
||||
hdr = (struct bpf_hdr *)e->Next;
|
||||
*data = Malloc(hdr->bh_caplen);
|
||||
Copy(*data, e->Next+(hdr->bh_hdrlen), hdr->bh_caplen);
|
||||
|
||||
@ -1864,7 +1864,7 @@ void EthPutPackets(ETH *e, UINT num, void **datas, UINT *sizes)
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0;i < num;i++)
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
EthPutPacket(e, datas[i], sizes[i]);
|
||||
}
|
||||
@ -1910,7 +1910,7 @@ void EthPutPacket(ETH *e, void *data, UINT size)
|
||||
// Send to device
|
||||
#ifdef BRIDGE_PCAP
|
||||
ret = pcap_inject(e->Pcap, data, size);
|
||||
if( ret == -1 ){
|
||||
if( ret == -1 ) {
|
||||
#ifdef _DEBUG
|
||||
pcap_perror(e->Pcap, "inject");
|
||||
#endif // _DEBUG
|
||||
@ -2162,7 +2162,7 @@ LABEL_RETRY:
|
||||
UINTToIP(&original_dest_ip, ip->DstIP);
|
||||
|
||||
if (IsZeroIP(&e->MyPhysicalIPForce) == false && CmpIpAddr(&e->MyPhysicalIPForce, &original_dest_ip) == 0 ||
|
||||
(IsIPMyHost(&original_dest_ip) && IsLocalHostIP(&original_dest_ip) == false && IsHostIPAddress4(&original_dest_ip)))
|
||||
(IsIPMyHost(&original_dest_ip) && IsLocalHostIP(&original_dest_ip) == false && IsHostIPAddress4(&original_dest_ip)))
|
||||
{
|
||||
if (IsZeroIP(&e->MyPhysicalIPForce) && CmpIpAddr(&e->MyPhysicalIP, &original_dest_ip) != 0)
|
||||
{
|
||||
@ -2183,14 +2183,14 @@ LABEL_RETRY:
|
||||
if (p->TypeL4 == L4_TCP)
|
||||
{
|
||||
TCP_HEADER *tcp = p->L4.TCPHeader;
|
||||
/*
|
||||
if (Endian16(tcp->SrcPort) == 80)
|
||||
{
|
||||
IP a, b;
|
||||
UINTToIP(&a, ip->SrcIP);
|
||||
UINTToIP(&b, ip->DstIP);
|
||||
Debug("%r %r %u %u\n", &a, &b, Endian16(tcp->SrcPort), Endian16(tcp->DstPort));
|
||||
}*/
|
||||
/*
|
||||
if (Endian16(tcp->SrcPort) == 80)
|
||||
{
|
||||
IP a, b;
|
||||
UINTToIP(&a, ip->SrcIP);
|
||||
UINTToIP(&b, ip->DstIP);
|
||||
Debug("%r %r %u %u\n", &a, &b, Endian16(tcp->SrcPort), Endian16(tcp->DstPort));
|
||||
}*/
|
||||
|
||||
ok = true;
|
||||
}
|
||||
@ -2226,7 +2226,7 @@ LABEL_RETRY:
|
||||
if (inner_icmp_size >= (sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO)))
|
||||
{
|
||||
ICMP_HEADER *inner_icmp = (ICMP_HEADER *)(((UCHAR *)data) +
|
||||
sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO) + orig_ipv4_header_size);
|
||||
sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO) + orig_ipv4_header_size);
|
||||
|
||||
if (inner_icmp->Type == ICMP_TYPE_ECHO_REQUEST)
|
||||
{
|
||||
@ -2328,8 +2328,8 @@ bool EthProcessIpPacketInnerIpRaw(ETH *e, PKT *p)
|
||||
ARPV4_HEADER *arp = p->L3.ARPv4Header;
|
||||
|
||||
if (Endian16(arp->HardwareType) == ARP_HARDWARE_TYPE_ETHERNET &&
|
||||
Endian16(arp->ProtocolType) == MAC_PROTO_IPV4 &&
|
||||
arp->HardwareSize == 6 && arp->ProtocolType == 4)
|
||||
Endian16(arp->ProtocolType) == MAC_PROTO_IPV4 &&
|
||||
arp->HardwareSize == 6 && arp->ProtocolType == 4)
|
||||
{
|
||||
if (IPToUINT(&e->MyIP) == arp->TargetIP)
|
||||
{
|
||||
@ -2460,8 +2460,8 @@ bool EthProcessIpPacketInnerIpRaw(ETH *e, PKT *p)
|
||||
UINTToIP(&ips, ip);
|
||||
IPToStr(client_ip, sizeof(client_ip), &ips);
|
||||
Debug("IP_RAW: DHCP %s : %s given %s\n",
|
||||
ret.Opcode == DHCP_OFFER ? "DHCP_OFFER" : "DHCP_ACK",
|
||||
client_mac, client_ip);
|
||||
ret.Opcode == DHCP_OFFER ? "DHCP_OFFER" : "DHCP_ACK",
|
||||
client_mac, client_ip);
|
||||
}
|
||||
|
||||
// Build a DHCP option
|
||||
@ -2538,7 +2538,7 @@ bool EthProcessIpPacketInnerIpRaw(ETH *e, PKT *p)
|
||||
udp->DstPort = Endian16(NAT_DHCP_CLIENT_PORT);
|
||||
udp->PacketLength = Endian16(sizeof(UDP_HEADER) + dhcp_packet_size);
|
||||
udp->Checksum = CalcChecksumForIPv4(ipv4->SrcIP, ipv4->DstIP, IP_PROTO_UDP,
|
||||
dhcp, dhcp_packet_size, 0);
|
||||
dhcp, dhcp_packet_size, 0);
|
||||
if (udp->Checksum == 0)
|
||||
{
|
||||
udp->Checksum = 0xffff;
|
||||
@ -2589,14 +2589,14 @@ void EthPutPacketLinuxIpRaw(ETH *e, void *data, UINT size)
|
||||
|
||||
if (p->BroadcastPacket || Cmp(p->MacAddressDest, e->RawIpMyMacAddr, 6) == 0)
|
||||
{
|
||||
if (IsValidUnicastMacAddress(p->MacAddressSrc))
|
||||
if (IsMacUnicast(p->MacAddressSrc))
|
||||
{
|
||||
Copy(e->RawIpYourMacAddr, p->MacAddressSrc, 6);
|
||||
}
|
||||
}
|
||||
|
||||
if (IsZero(e->RawIpYourMacAddr, 6) || IsValidUnicastMacAddress(p->MacAddressSrc) == false ||
|
||||
(p->BroadcastPacket == false && Cmp(p->MacAddressDest, e->RawIpMyMacAddr, 6) != 0))
|
||||
if (IsZero(e->RawIpYourMacAddr, 6) || IsMacUnicast(p->MacAddressSrc) == false ||
|
||||
(p->BroadcastPacket == false && Cmp(p->MacAddressDest, e->RawIpMyMacAddr, 6) != 0))
|
||||
{
|
||||
Free(data);
|
||||
FreePacket(p);
|
||||
@ -2641,7 +2641,7 @@ void EthPutPacketLinuxIpRaw(ETH *e, void *data, UINT size)
|
||||
}
|
||||
|
||||
if (s != NULL && p->L3.IPv4Header->DstIP != 0xffffffff && p->BroadcastPacket == false &&
|
||||
p->L3.IPv4Header->SrcIP == IPToUINT(&e->YourIP))
|
||||
p->L3.IPv4Header->SrcIP == IPToUINT(&e->YourIP))
|
||||
{
|
||||
UCHAR *send_data = p->IPv4PayloadData;
|
||||
UCHAR *head = p->PacketData;
|
||||
@ -2661,8 +2661,8 @@ void EthPutPacketLinuxIpRaw(ETH *e, void *data, UINT size)
|
||||
{
|
||||
p->L4.TCPHeader->Checksum = 0;
|
||||
p->L4.TCPHeader->Checksum = CalcChecksumForIPv4(IPToUINT(&e->MyPhysicalIP),
|
||||
p->L3.IPv4Header->DstIP, IP_PROTO_TCP,
|
||||
p->L4.TCPHeader, p->IPv4PayloadSize, 0);
|
||||
p->L3.IPv4Header->DstIP, IP_PROTO_TCP,
|
||||
p->L4.TCPHeader, p->IPv4PayloadSize, 0);
|
||||
}
|
||||
|
||||
UINTToIP(&dest, p->L3.IPv4Header->DstIP);
|
||||
|
@ -582,6 +582,8 @@ typedef struct IPC_PARAM IPC_PARAM;
|
||||
typedef struct IPC_DHCP_RELEASE_QUEUE IPC_DHCP_RELEASE_QUEUE;
|
||||
typedef struct IPC_MSCHAP_V2_AUTHINFO IPC_MSCHAP_V2_AUTHINFO;
|
||||
typedef struct IPC_SESSION_SHARED_BUFFER_DATA IPC_SESSION_SHARED_BUFFER_DATA;
|
||||
typedef struct IPC_IPV6_ROUTER_ADVERTISEMENT IPC_IPV6_ROUTER_ADVERTISEMENT;
|
||||
typedef struct IPC_DHCPV4_AWAIT IPC_DHCPV4_AWAIT;
|
||||
|
||||
|
||||
// ==============================================================
|
||||
|
918
src/Cedar/IPC.c
918
src/Cedar/IPC.c
File diff suppressed because it is too large
Load Diff
@ -24,6 +24,22 @@
|
||||
#define IPC_LAYER_2 2
|
||||
#define IPC_LAYER_3 3
|
||||
|
||||
// IPv6 constants
|
||||
#define IPC_IPV6_NDT_LIFETIME (30 * 1000) // as per REACHABLE_TIME constant of RFC4861
|
||||
#define IPC_IPV6_NDT_GIVEUPTIME (3 * 1000) // as per MAX_MULTICAST_SOLICIT * RETRANS_TIMER constants of RFC4861
|
||||
#define IPC_IPV6_RA_INTERVAL (2 * 1000) // Windows gets stuck if it is bigger
|
||||
#define IPC_IPV6_RA_MAX_RETRIES 2 // Windows seems to be stuck when it doesn't receive an answer in due time
|
||||
|
||||
// Protocol status
|
||||
#define IPC_PROTO_STATUS_CLOSED 0x0
|
||||
#define IPC_PROTO_STATUS_CONFIG 0x1
|
||||
#define IPC_PROTO_STATUS_CONFIG_WAIT 0x2
|
||||
#define IPC_PROTO_STATUS_OPENED 0x10
|
||||
#define IPC_PROTO_STATUS_REJECTED 0x100
|
||||
|
||||
#define IPC_PROTO_SET_STATUS(ipc, proto, value) ((ipc) != NULL ? ((ipc->proto) = (value)) : 0)
|
||||
#define IPC_PROTO_GET_STATUS(ipc, proto) ((ipc) != NULL ? (ipc->proto) : IPC_PROTO_STATUS_REJECTED)
|
||||
|
||||
// ARP table entry
|
||||
struct IPC_ARP
|
||||
{
|
||||
@ -72,6 +88,15 @@ struct IPC_PARAM
|
||||
UINT Layer;
|
||||
};
|
||||
|
||||
// DHCPv4 response awaiter
|
||||
struct IPC_DHCPV4_AWAIT
|
||||
{
|
||||
bool IsAwaiting;
|
||||
DHCPV4_DATA *DhcpData;
|
||||
UINT TransCode;
|
||||
UINT OpCode;
|
||||
};
|
||||
|
||||
// IPC_ASYNC object
|
||||
struct IPC_ASYNC
|
||||
{
|
||||
@ -111,12 +136,22 @@ struct IPC
|
||||
UCHAR Padding[2];
|
||||
LIST *ArpTable; // ARP table
|
||||
QUEUE *IPv4ReceivedQueue; // IPv4 reception queue
|
||||
UINT IPv4State;
|
||||
IPC_DHCPV4_AWAIT DHCPv4Awaiter;
|
||||
TUBE_FLUSH_LIST *FlushList; // Tube Flush List
|
||||
UCHAR MsChapV2_ServerResponse[20]; // Server response
|
||||
DHCP_CLASSLESS_ROUTE_TABLE ClasslessRoute; // Classless routing table
|
||||
SHARED_BUFFER *IpcSessionSharedBuffer; // A shared buffer between IPC and Session
|
||||
IPC_SESSION_SHARED_BUFFER_DATA *IpcSessionShared; // Shared data between IPC and Session
|
||||
UINT Layer;
|
||||
|
||||
// IPv6 stuff
|
||||
QUEUE *IPv6ReceivedQueue; // IPv6 reception queue
|
||||
UINT IPv6State;
|
||||
LIST *IPv6NeighborTable; // Neighbor Discovery Table
|
||||
LIST *IPv6RouterAdvs; // Router offered prefixes
|
||||
UINT64 IPv6ClientEUI; // The EUI of the client (for the SLAAC autoconf)
|
||||
UINT64 IPv6ServerEUI; // The EUI of the server (from the RA discovery)
|
||||
};
|
||||
|
||||
// MS-CHAPv2 authentication information
|
||||
@ -129,11 +164,20 @@ struct IPC_MSCHAP_V2_AUTHINFO
|
||||
EAP_CLIENT *MsChapV2_EapClient; // EAP client
|
||||
};
|
||||
|
||||
struct IPC_IPV6_ROUTER_ADVERTISEMENT
|
||||
{
|
||||
IP RoutedPrefix;
|
||||
IP RoutedMask;
|
||||
IP RouterAddress;
|
||||
UCHAR RouterMacAddress[6];
|
||||
UCHAR RouterLinkLayerAddress[6];
|
||||
};
|
||||
|
||||
IPC *NewIPC(CEDAR *cedar, char *client_name, char *postfix, char *hubname, char *username, char *password,
|
||||
UINT *error_code, IP *client_ip, UINT client_port, IP *server_ip, UINT server_port,
|
||||
char *client_hostname, char *crypt_name,
|
||||
bool bridge_mode, UINT mss, EAP_CLIENT *eap_client, X *client_certificate,
|
||||
UINT layer);
|
||||
UINT *error_code, IP *client_ip, UINT client_port, IP *server_ip, UINT server_port,
|
||||
char *client_hostname, char *crypt_name,
|
||||
bool bridge_mode, UINT mss, EAP_CLIENT *eap_client, X *client_certificate,
|
||||
UINT layer);
|
||||
IPC *NewIPCByParam(CEDAR *cedar, IPC_PARAM *param, UINT *error_code);
|
||||
IPC *NewIPCBySock(CEDAR *cedar, SOCK *s, void *mac_address);
|
||||
void FreeIPC(IPC *ipc);
|
||||
@ -144,6 +188,7 @@ void IPCSendIPv4(IPC *ipc, void *data, UINT size);
|
||||
BLOCK *IPCRecvL2(IPC *ipc);
|
||||
BLOCK *IPCRecvIPv4(IPC *ipc);
|
||||
void IPCProcessInterrupts(IPC *ipc);
|
||||
void IPCProcessL3EventsIPv4Only(IPC *ipc);
|
||||
void IPCProcessL3Events(IPC *ipc);
|
||||
void IPCProcessL3EventsEx(IPC *ipc, UINT64 now);
|
||||
bool IPCSetIPv4Parameters(IPC *ipc, IP *ip, IP *subnet, IP *gw, DHCP_CLASSLESS_ROUTE_TABLE *rt);
|
||||
@ -151,15 +196,15 @@ IPC_ARP *IPCNewARP(IP *ip, UCHAR *mac_address);
|
||||
void IPCFreeARP(IPC_ARP *a);
|
||||
int IPCCmpArpTable(void *p1, void *p2);
|
||||
void IPCSendIPv4Unicast(IPC *ipc, void *data, UINT size, IP *next_ip);
|
||||
IPC_ARP *IPCSearchArpTable(IPC *ipc, IP *ip);
|
||||
IPC_ARP *IPCSearchArpTable(LIST *arpTable, IP *ip);
|
||||
void IPCSendIPv4WithDestMacAddr(IPC *ipc, void *data, UINT size, UCHAR *dest_mac_addr);
|
||||
void IPCFlushArpTable(IPC *ipc);
|
||||
void IPCFlushArpTableEx(IPC *ipc, UINT64 now);
|
||||
void IPCProcessArp(IPC *ipc, BLOCK *b);
|
||||
void IPCAssociateOnArpTable(IPC *ipc, IP *ip, UCHAR *mac_address);
|
||||
bool IsValidUnicastMacAddress(UCHAR *mac);
|
||||
bool IsValidUnicastIPAddress4(IP *ip);
|
||||
bool IsValidUnicastIPAddressUINT4(UINT ip);
|
||||
|
||||
|
||||
|
||||
DHCPV4_DATA *IPCSendDhcpRequest(IPC *ipc, IP *dest_ip, UINT tran_id, DHCP_OPTION_LIST *opt, UINT expecting_code, UINT timeout, TUBE *discon_poll_tube);
|
||||
BUF *IPCBuildDhcpRequest(IPC *ipc, IP *dest_ip, UINT tran_id, DHCP_OPTION_LIST *opt);
|
||||
BUF *IPCBuildDhcpRequestOptions(IPC *ipc, DHCP_OPTION_LIST *opt);
|
||||
@ -171,6 +216,26 @@ IPC_ASYNC *NewIPCAsync(CEDAR *cedar, IPC_PARAM *param, SOCK_EVENT *sock_event);
|
||||
void IPCAsyncThreadProc(THREAD *thread, void *param);
|
||||
void FreeIPCAsync(IPC_ASYNC *a);
|
||||
|
||||
// IPv6 stuff
|
||||
// Memory management
|
||||
void IPCIPv6Init(IPC *ipc);
|
||||
void IPCIPv6Free(IPC *ipc);
|
||||
// NDT
|
||||
void IPCIPv6AssociateOnNDT(IPC *ipc, IP *ip, UCHAR *mac_address);
|
||||
void IPCIPv6AssociateOnNDTEx(IPC *ipc, IP *ip, UCHAR *mac_address, bool isNeighborAdv);
|
||||
void IPCIPv6FlushNDT(IPC *ipc);
|
||||
void IPCIPv6FlushNDTEx(IPC *ipc, UINT64 now);
|
||||
bool IPCIPv6CheckExistingLinkLocal(IPC *ipc, UINT64 eui);
|
||||
// RA
|
||||
void IPCIPv6AddRouterPrefixes(IPC *ipc, ICMPV6_OPTION_LIST *recvPrefix, UCHAR *macAddress, IP *ip);
|
||||
bool IPCIPv6CheckUnicastFromRouterPrefix(IPC *ipc, IP *ip, IPC_IPV6_ROUTER_ADVERTISEMENT *matchedRA);
|
||||
UINT64 IPCIPv6GetServerEui(IPC *ipc);
|
||||
// Data flow
|
||||
BLOCK *IPCIPv6Recv(IPC *ipc);
|
||||
void IPCIPv6Send(IPC *ipc, void *data, UINT size);
|
||||
void IPCIPv6SendWithDestMacAddr(IPC *ipc, void *data, UINT size, UCHAR *dest_mac_addr);
|
||||
void IPCIPv6SendUnicast(IPC *ipc, void *data, UINT size, IP *next_ip);
|
||||
|
||||
bool ParseAndExtractMsChapV2InfoFromPassword(IPC_MSCHAP_V2_AUTHINFO *d, char *password);
|
||||
|
||||
#endif // IPC_H
|
||||
|
@ -175,7 +175,7 @@ void FreeEraseFileList(LIST *o)
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0;i < LIST_NUM(o);i++)
|
||||
for (i = 0; i < LIST_NUM(o); i++)
|
||||
{
|
||||
ERASE_FILE *f = LIST_DATA(o, i);
|
||||
Free(f->FullPath);
|
||||
@ -200,7 +200,7 @@ void EnumEraseFile(LIST *o, char *dirname)
|
||||
// Enumeration
|
||||
dir = EnumDir(dirname);
|
||||
|
||||
for (i = 0;i < dir->NumFiles;i++)
|
||||
for (i = 0; i < dir->NumFiles; i++)
|
||||
{
|
||||
DIRENT *e = dir->File[i];
|
||||
Format(tmp, sizeof(tmp), "%s/%s", dirname, e->FileName);
|
||||
@ -245,7 +245,7 @@ LIST *GenerateEraseFileList(ERASER *e)
|
||||
o = NewListFast(CompareEraseFile);
|
||||
|
||||
// Scan for each directory
|
||||
for (i = 0;i < sizeof(delete_targets) / sizeof(delete_targets[0]);i++)
|
||||
for (i = 0; i < sizeof(delete_targets) / sizeof(delete_targets[0]); i++)
|
||||
{
|
||||
char dirname[MAX_PATH];
|
||||
Format(dirname, sizeof(dirname), "%s/%s", e->DirName, delete_targets[i]);
|
||||
@ -285,7 +285,7 @@ void EraserMain(ERASER *e)
|
||||
o = GenerateEraseFileList(e);
|
||||
|
||||
// Try to delete one by one in order from oldest file
|
||||
for (i = 0;i < LIST_NUM(o);i++)
|
||||
for (i = 0; i < LIST_NUM(o); i++)
|
||||
{
|
||||
ERASE_FILE *f = LIST_DATA(o, i);
|
||||
|
||||
@ -626,7 +626,7 @@ void EtherIPLog(ETHERIP_SERVER *s, char *name, ...)
|
||||
IPToStr(client_ip, sizeof(client_ip), &s->ClientIP);
|
||||
|
||||
UniFormat(prefix, sizeof(prefix), _UU("LE_PREFIX"), s->Id,
|
||||
server_ip, s->ServerPort, client_ip, s->ClientPort);
|
||||
server_ip, s->ServerPort, client_ip, s->ClientPort);
|
||||
|
||||
va_start(args, name);
|
||||
UniFormatArgs(buf2, sizeof(buf2), _UU(name), args);
|
||||
@ -671,17 +671,17 @@ void IPsecLog(IKE_SERVER *ike, IKE_CLIENT *c, IKE_SA *ike_sa, IPSECSA *ipsec_sa,
|
||||
if (ipsec_sa != NULL)
|
||||
{
|
||||
UniFormat(prefix, sizeof(prefix), _UU("LI_PREFIX_IPSEC"),
|
||||
ipsec_sa->Id, c->Id, client_ip, c->ClientPort, server_ip, c->ServerPort);
|
||||
ipsec_sa->Id, c->Id, client_ip, c->ClientPort, server_ip, c->ServerPort);
|
||||
}
|
||||
else if (ike_sa != NULL)
|
||||
{
|
||||
UniFormat(prefix, sizeof(prefix), _UU("LI_PREFIX_IKE"),
|
||||
ike_sa->Id, c->Id, client_ip, c->ClientPort, server_ip, c->ServerPort);
|
||||
ike_sa->Id, c->Id, client_ip, c->ClientPort, server_ip, c->ServerPort);
|
||||
}
|
||||
else
|
||||
{
|
||||
UniFormat(prefix, sizeof(prefix), _UU("LI_PREFIX_CLIENT"),
|
||||
c->Id, client_ip, c->ClientPort, server_ip, c->ServerPort);
|
||||
c->Id, client_ip, c->ClientPort, server_ip, c->ServerPort);
|
||||
}
|
||||
}
|
||||
|
||||
@ -755,7 +755,7 @@ void WriteHubLog(HUB *h, wchar_t *str)
|
||||
}
|
||||
|
||||
if (syslog_status == SYSLOG_SERVER_AND_HUB_SECURITY_LOG
|
||||
|| syslog_status == SYSLOG_SERVER_AND_HUB_ALL_LOG)
|
||||
|| syslog_status == SYSLOG_SERVER_AND_HUB_ALL_LOG)
|
||||
{
|
||||
SiWriteSysLog(s, "SECURITY_LOG", h->Name, str);
|
||||
}
|
||||
@ -833,7 +833,7 @@ bool PacketLog(HUB *hub, SESSION *src_session, SESSION *dest_session, PKT *packe
|
||||
}
|
||||
|
||||
if (memcmp(hub->HubMacAddr, packet->MacAddressSrc, 6) == 0 ||
|
||||
memcmp(hub->HubMacAddr, packet->MacAddressDest, 6) == 0)
|
||||
memcmp(hub->HubMacAddr, packet->MacAddressDest, 6) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -1027,8 +1027,8 @@ UINT CalcPacketLoggingLevelEx(HUB_LOG *g, PKT *packet)
|
||||
ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP]);
|
||||
|
||||
if (packet->L4.TCPHeader->Flag & TCP_SYN ||
|
||||
packet->L4.TCPHeader->Flag & TCP_RST ||
|
||||
packet->L4.TCPHeader->Flag & TCP_FIN)
|
||||
packet->L4.TCPHeader->Flag & TCP_RST ||
|
||||
packet->L4.TCPHeader->Flag & TCP_FIN)
|
||||
{
|
||||
// TCP SYN LOG
|
||||
ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP_CONN]);
|
||||
@ -1057,10 +1057,10 @@ UINT CalcPacketLoggingLevelEx(HUB_LOG *g, PKT *packet)
|
||||
ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP_CONN]);
|
||||
break;
|
||||
|
||||
case L7_DNS:
|
||||
// DNS request
|
||||
ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP_CONN]);
|
||||
break;
|
||||
case L7_DNS:
|
||||
// DNS request
|
||||
ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP_CONN]);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
@ -1084,8 +1084,8 @@ UINT CalcPacketLoggingLevelEx(HUB_LOG *g, PKT *packet)
|
||||
ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP]);
|
||||
|
||||
if (packet->L4.TCPHeader->Flag & TCP_SYN ||
|
||||
packet->L4.TCPHeader->Flag & TCP_RST ||
|
||||
packet->L4.TCPHeader->Flag & TCP_FIN)
|
||||
packet->L4.TCPHeader->Flag & TCP_RST ||
|
||||
packet->L4.TCPHeader->Flag & TCP_FIN)
|
||||
{
|
||||
// TCP SYN LOG
|
||||
ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP_CONN]);
|
||||
@ -1109,10 +1109,10 @@ UINT CalcPacketLoggingLevelEx(HUB_LOG *g, PKT *packet)
|
||||
ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP_CONN]);
|
||||
break;
|
||||
|
||||
case L7_DNS:
|
||||
// DNS request
|
||||
ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP_CONN]);
|
||||
break;
|
||||
case L7_DNS:
|
||||
// DNS request
|
||||
ret = MAX(ret, g->PacketLogConfig[PACKET_LOG_TCP_CONN]);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
@ -1167,12 +1167,12 @@ char *BuildHttpLogStr(HTTPLOG *h)
|
||||
if (h->Port == 80)
|
||||
{
|
||||
Format(url, sizeof(url), "http://%s%s",
|
||||
h->Hostname, h->Path);
|
||||
h->Hostname, h->Path);
|
||||
}
|
||||
else
|
||||
{
|
||||
Format(url, sizeof(url), "http://%s:%u%s",
|
||||
h->Hostname, h->Port, h->Path);
|
||||
h->Hostname, h->Port, h->Path);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1180,12 +1180,12 @@ char *BuildHttpLogStr(HTTPLOG *h)
|
||||
if (h->Port == 443)
|
||||
{
|
||||
Format(url, sizeof(url), "https://%s/",
|
||||
h->Hostname);
|
||||
h->Hostname);
|
||||
}
|
||||
else
|
||||
{
|
||||
Format(url, sizeof(url), "https://%s:%u/",
|
||||
h->Hostname, h->Port);
|
||||
h->Hostname, h->Port);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1251,7 +1251,7 @@ void MakeSafeLogStr(char *str)
|
||||
}
|
||||
|
||||
if (str[0] == 'h' && str[1] == 't' && str[2] == 't' && str[3] == 'p' &&
|
||||
((str[4] == 's' && str[5] == ':') || (str[4] == ':')))
|
||||
((str[4] == 's' && str[5] == ':') || (str[4] == ':')))
|
||||
{
|
||||
is_http = true;
|
||||
}
|
||||
@ -1259,7 +1259,7 @@ void MakeSafeLogStr(char *str)
|
||||
EnPrintableAsciiStr(str, '?');
|
||||
|
||||
len = StrLen(str);
|
||||
for (i = 0;i < len;i++)
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (str[i] == ',')
|
||||
{
|
||||
@ -1284,6 +1284,7 @@ char *PacketLogParseProc(RECORD *rec)
|
||||
TOKEN_LIST *t;
|
||||
char tmp[MAX_SIZE];
|
||||
bool tcp_conn;
|
||||
UINT i;
|
||||
// Validate arguments
|
||||
if (rec == NULL)
|
||||
{
|
||||
@ -1340,9 +1341,9 @@ char *PacketLogParseProc(RECORD *rec)
|
||||
// ARP request packet
|
||||
t->Token[7] = CopyStr("Request");
|
||||
if (Endian16(p->L3.ARPv4Header->HardwareType) == ARP_HARDWARE_TYPE_ETHERNET &&
|
||||
p->L3.ARPv4Header->HardwareSize == 6 &&
|
||||
Endian16(p->L3.ARPv4Header->ProtocolType) == MAC_PROTO_IPV4 &&
|
||||
p->L3.ARPv4Header->ProtocolSize == 4)
|
||||
p->L3.ARPv4Header->HardwareSize == 6 &&
|
||||
Endian16(p->L3.ARPv4Header->ProtocolType) == MAC_PROTO_IPV4 &&
|
||||
p->L3.ARPv4Header->ProtocolSize == 4)
|
||||
{
|
||||
char src_mac[16];
|
||||
char src_ip[16];
|
||||
@ -1355,7 +1356,7 @@ char *PacketLogParseProc(RECORD *rec)
|
||||
IPToStr(src_ip, sizeof(src_ip), &src_ip_st);
|
||||
IPToStr(dst_ip, sizeof(dst_ip), &dst_ip_st);
|
||||
snprintf(tmp, sizeof(tmp), "Who has %s? Please Tell %s(%s)",
|
||||
dst_ip, src_mac, src_ip);
|
||||
dst_ip, src_mac, src_ip);
|
||||
t->Token[14] = CopyStr(tmp);
|
||||
}
|
||||
break;
|
||||
@ -1364,9 +1365,9 @@ char *PacketLogParseProc(RECORD *rec)
|
||||
// ARP response packet
|
||||
t->Token[7] = CopyStr("Response");
|
||||
if (Endian16(p->L3.ARPv4Header->HardwareType) == ARP_HARDWARE_TYPE_ETHERNET &&
|
||||
p->L3.ARPv4Header->HardwareSize == 6 &&
|
||||
Endian16(p->L3.ARPv4Header->ProtocolType) == MAC_PROTO_IPV4 &&
|
||||
p->L3.ARPv4Header->ProtocolSize == 4)
|
||||
p->L3.ARPv4Header->HardwareSize == 6 &&
|
||||
Endian16(p->L3.ARPv4Header->ProtocolType) == MAC_PROTO_IPV4 &&
|
||||
p->L3.ARPv4Header->ProtocolSize == 4)
|
||||
{
|
||||
char src_mac[16];
|
||||
char src_ip[16];
|
||||
@ -1379,7 +1380,7 @@ char *PacketLogParseProc(RECORD *rec)
|
||||
IPToStr(src_ip, sizeof(src_ip), &src_ip_st);
|
||||
IPToStr(dst_ip, sizeof(dst_ip), &dst_ip_st);
|
||||
snprintf(tmp, sizeof(tmp), "%s has %s",
|
||||
src_mac, src_ip);
|
||||
src_mac, src_ip);
|
||||
t->Token[14] = CopyStr(tmp);
|
||||
}
|
||||
break;
|
||||
@ -1483,9 +1484,9 @@ char *PacketLogParseProc(RECORD *rec)
|
||||
IPToStr32(ip4, sizeof(ip4), p->L7.DHCPv4Header->RelayIP);
|
||||
|
||||
snprintf(tmp, sizeof(tmp),
|
||||
"TransactionId=%u ClientIP=%s YourIP=%s ServerIP=%s RelayIP=%s",
|
||||
Endian32(p->L7.DHCPv4Header->TransactionId),
|
||||
ip1, ip2, ip3, ip4);
|
||||
"TransactionId=%u ClientIP=%s YourIP=%s ServerIP=%s RelayIP=%s",
|
||||
Endian32(p->L7.DHCPv4Header->TransactionId),
|
||||
ip1, ip2, ip3, ip4);
|
||||
|
||||
t->Token[14] = CopyStr(tmp);
|
||||
}
|
||||
@ -1514,26 +1515,26 @@ char *PacketLogParseProc(RECORD *rec)
|
||||
|
||||
{
|
||||
Format(tmp, sizeof(tmp), "InitiatorCookie=%I64u ResponderCookie=%I64u "
|
||||
"Version=0x%x ExchangeType=0x%x Flag=0x%x MessageId=%u MessageSize=%u",
|
||||
Endian64(p->L7.IkeHeader->InitiatorCookie),
|
||||
Endian64(p->L7.IkeHeader->ResponderCookie),
|
||||
p->L7.IkeHeader->Version,
|
||||
p->L7.IkeHeader->ExchangeType,
|
||||
p->L7.IkeHeader->Flag,
|
||||
Endian32(p->L7.IkeHeader->MessageId),
|
||||
Endian32(p->L7.IkeHeader->MessageSize));
|
||||
"Version=0x%x ExchangeType=0x%x Flag=0x%x MessageId=%u MessageSize=%u",
|
||||
Endian64(p->L7.IkeHeader->InitiatorCookie),
|
||||
Endian64(p->L7.IkeHeader->ResponderCookie),
|
||||
p->L7.IkeHeader->Version,
|
||||
p->L7.IkeHeader->ExchangeType,
|
||||
p->L7.IkeHeader->Flag,
|
||||
Endian32(p->L7.IkeHeader->MessageId),
|
||||
Endian32(p->L7.IkeHeader->MessageSize));
|
||||
|
||||
t->Token[14] = CopyStr(tmp);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case L7_DNS:
|
||||
// DNS query
|
||||
t->Token[6] = CopyStr("DNSv4");
|
||||
t->Token[7] = CopyStr("DNS_Query");
|
||||
t->Token[14] = CopyStr(p->DnsQueryHost);
|
||||
break;
|
||||
|
||||
case L7_DNS:
|
||||
// DNS query
|
||||
t->Token[6] = CopyStr("DNSv4");
|
||||
t->Token[7] = CopyStr("DNS_Query");
|
||||
t->Token[14] = CopyStr(p->DnsQueryHost);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Unknown Packet
|
||||
@ -1570,145 +1571,152 @@ char *PacketLogParseProc(RECORD *rec)
|
||||
switch (p->TypeL4)
|
||||
{
|
||||
case L4_ICMPV6:
|
||||
{
|
||||
char info[MAX_SIZE];
|
||||
ICMPV6_HEADER_INFO *icmp = &p->ICMPv6HeaderPacketInfo;
|
||||
ICMPV6_OPTION_LIST *ol = &icmp->OptionList;
|
||||
|
||||
Zero(info, sizeof(info));
|
||||
|
||||
// ICMPv6 packet
|
||||
t->Token[6] = CopyStr("ICMPv6");
|
||||
|
||||
switch (icmp->Type)
|
||||
{
|
||||
char info[MAX_SIZE];
|
||||
ICMPV6_HEADER_INFO *icmp = &p->ICMPv6HeaderPacketInfo;
|
||||
ICMPV6_OPTION_LIST *ol = &icmp->OptionList;
|
||||
case ICMPV6_TYPE_ECHO_REQUEST:
|
||||
// Echo request
|
||||
t->Token[7] = CopyStr("Echo Request");
|
||||
snprintf(tmp, sizeof(tmp), "EchoDataSize=%u ", icmp->EchoDataSize);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
break;
|
||||
|
||||
Zero(info, sizeof(info));
|
||||
case ICMPV6_TYPE_ECHO_RESPONSE:
|
||||
// Echo response
|
||||
t->Token[7] = CopyStr("Echo Reply");
|
||||
snprintf(tmp, sizeof(tmp), "EchoDataSize=%u ", icmp->EchoDataSize);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
break;
|
||||
|
||||
// ICMPv6 packet
|
||||
t->Token[6] = CopyStr("ICMPv6");
|
||||
case ICMPV6_TYPE_ROUTER_SOLICIATION:
|
||||
{
|
||||
ICMPV6_ROUTER_SOLICIATION_HEADER *h = icmp->Headers.RouterSoliciationHeader;
|
||||
// Router Solicitation
|
||||
t->Token[7] = CopyStr("Router Soliciation");
|
||||
|
||||
switch (icmp->Type)
|
||||
if (h != NULL)
|
||||
{
|
||||
case ICMPV6_TYPE_ECHO_REQUEST:
|
||||
// Echo request
|
||||
t->Token[7] = CopyStr("Echo Request");
|
||||
snprintf(tmp, sizeof(tmp), "EchoDataSize=%u ", icmp->EchoDataSize);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
break;
|
||||
|
||||
case ICMPV6_TYPE_ECHO_RESPONSE:
|
||||
// Echo response
|
||||
t->Token[7] = CopyStr("Echo Reply");
|
||||
snprintf(tmp, sizeof(tmp), "EchoDataSize=%u ", icmp->EchoDataSize);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
break;
|
||||
|
||||
case ICMPV6_TYPE_ROUTER_SOLICIATION:
|
||||
{
|
||||
ICMPV6_ROUTER_SOLICIATION_HEADER *h = icmp->Headers.RouterSoliciationHeader;
|
||||
// Router Solicitation
|
||||
t->Token[7] = CopyStr("Router Soliciation");
|
||||
|
||||
if (h != NULL)
|
||||
{
|
||||
// No additional information
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ICMPV6_TYPE_ROUTER_ADVERTISEMENT:
|
||||
{
|
||||
ICMPV6_ROUTER_ADVERTISEMENT_HEADER *h = icmp->Headers.RouterAdvertisementHeader;
|
||||
// Router Advertisement
|
||||
t->Token[7] = CopyStr("Router Advertisement");
|
||||
|
||||
if (h != NULL)
|
||||
{
|
||||
snprintf(tmp, sizeof(tmp), "CurHopLimit=%u "
|
||||
"Flags=0x%02X Lifetime=%u ",
|
||||
h->CurHopLimit, h->Flags, Endian16(h->Lifetime));
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ICMPV6_TYPE_NEIGHBOR_SOLICIATION:
|
||||
{
|
||||
ICMPV6_NEIGHBOR_SOLICIATION_HEADER *h = icmp->Headers.NeighborSoliciationHeader;
|
||||
// Neighbor Solicitation
|
||||
t->Token[7] = CopyStr("Neighbor Soliciation");
|
||||
|
||||
if (h != NULL)
|
||||
{
|
||||
char tmp2[MAX_SIZE];
|
||||
|
||||
IP6AddrToStr(tmp2, sizeof(tmp2), &h->TargetAddress);
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "TargetAddress=%s ",
|
||||
tmp2);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ICMPV6_TYPE_NEIGHBOR_ADVERTISEMENT:
|
||||
{
|
||||
ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER *h = icmp->Headers.NeighborAdvertisementHeader;
|
||||
// Neighbor Advertisement
|
||||
t->Token[7] = CopyStr("Neighbor Advertisement");
|
||||
|
||||
if (h != NULL)
|
||||
{
|
||||
char tmp2[MAX_SIZE];
|
||||
|
||||
IP6AddrToStr(tmp2, sizeof(tmp2), &h->TargetAddress);
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "TargetAddress=%s Flags=0x%02X ",
|
||||
tmp2, h->Flags);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
snprintf(tmp, sizeof(tmp), "Type=%u", icmp->Type);
|
||||
t->Token[7] = CopyStr(tmp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Option data
|
||||
if (ol->SourceLinkLayer != NULL)
|
||||
{
|
||||
char tmp2[MAX_SIZE];
|
||||
BinToStr(tmp2, sizeof(tmp2), ol->SourceLinkLayer->Address, 6);
|
||||
snprintf(tmp, sizeof(tmp), "SourceLinkLayer=%s ", tmp2);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
if (ol->TargetLinkLayer != NULL)
|
||||
{
|
||||
char tmp2[MAX_SIZE];
|
||||
BinToStr(tmp2, sizeof(tmp2), ol->TargetLinkLayer->Address, 6);
|
||||
snprintf(tmp, sizeof(tmp), "TargetLinkLayer=%s ", tmp2);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
if (ol->Prefix != NULL)
|
||||
{
|
||||
char tmp2[MAX_SIZE];
|
||||
IP6AddrToStr(tmp2, sizeof(tmp2), &ol->Prefix->Prefix);
|
||||
snprintf(tmp, sizeof(tmp), "Prefix=%s/%u PrefixFlag=0x%02X ", tmp2,
|
||||
ol->Prefix->SubnetLength, ol->Prefix->Flags);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
if (ol->Mtu != NULL)
|
||||
{
|
||||
snprintf(tmp, sizeof(tmp), "Mtu=%u ", Endian32(ol->Mtu->Mtu));
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
|
||||
Trim(info);
|
||||
|
||||
if (IsEmptyStr(info) == false)
|
||||
{
|
||||
t->Token[14] = CopyStr(info);
|
||||
// No additional information
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ICMPV6_TYPE_ROUTER_ADVERTISEMENT:
|
||||
{
|
||||
ICMPV6_ROUTER_ADVERTISEMENT_HEADER *h = icmp->Headers.RouterAdvertisementHeader;
|
||||
// Router Advertisement
|
||||
t->Token[7] = CopyStr("Router Advertisement");
|
||||
|
||||
if (h != NULL)
|
||||
{
|
||||
snprintf(tmp, sizeof(tmp), "CurHopLimit=%u "
|
||||
"Flags=0x%02X Lifetime=%u ",
|
||||
h->CurHopLimit, h->Flags, Endian16(h->Lifetime));
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ICMPV6_TYPE_NEIGHBOR_SOLICIATION:
|
||||
{
|
||||
ICMPV6_NEIGHBOR_SOLICIATION_HEADER *h = icmp->Headers.NeighborSoliciationHeader;
|
||||
// Neighbor Solicitation
|
||||
t->Token[7] = CopyStr("Neighbor Soliciation");
|
||||
|
||||
if (h != NULL)
|
||||
{
|
||||
char tmp2[MAX_SIZE];
|
||||
|
||||
IP6AddrToStr(tmp2, sizeof(tmp2), &h->TargetAddress);
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "TargetAddress=%s ",
|
||||
tmp2);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ICMPV6_TYPE_NEIGHBOR_ADVERTISEMENT:
|
||||
{
|
||||
ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER *h = icmp->Headers.NeighborAdvertisementHeader;
|
||||
// Neighbor Advertisement
|
||||
t->Token[7] = CopyStr("Neighbor Advertisement");
|
||||
|
||||
if (h != NULL)
|
||||
{
|
||||
char tmp2[MAX_SIZE];
|
||||
|
||||
IP6AddrToStr(tmp2, sizeof(tmp2), &h->TargetAddress);
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "TargetAddress=%s Flags=0x%02X ",
|
||||
tmp2, h->Flags);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
snprintf(tmp, sizeof(tmp), "Type=%u", icmp->Type);
|
||||
t->Token[7] = CopyStr(tmp);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Option data
|
||||
if (ol->SourceLinkLayer != NULL)
|
||||
{
|
||||
char tmp2[MAX_SIZE];
|
||||
BinToStr(tmp2, sizeof(tmp2), ol->SourceLinkLayer->Address, 6);
|
||||
snprintf(tmp, sizeof(tmp), "SourceLinkLayer=%s ", tmp2);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
if (ol->TargetLinkLayer != NULL)
|
||||
{
|
||||
char tmp2[MAX_SIZE];
|
||||
BinToStr(tmp2, sizeof(tmp2), ol->TargetLinkLayer->Address, 6);
|
||||
snprintf(tmp, sizeof(tmp), "TargetLinkLayer=%s ", tmp2);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
for (i = 0; i < ICMPV6_OPTION_PREFIXES_MAX_COUNT; i++)
|
||||
{
|
||||
if (ol->Prefix[i] != NULL)
|
||||
{
|
||||
char tmp2[MAX_SIZE];
|
||||
IP6AddrToStr(tmp2, sizeof(tmp2), &ol->Prefix[i]->Prefix);
|
||||
snprintf(tmp, sizeof(tmp), "Prefix=%s/%u PrefixFlag=0x%02X ", tmp2,
|
||||
ol->Prefix[i]->SubnetLength, ol->Prefix[i]->Flags);
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ol->Mtu != NULL)
|
||||
{
|
||||
snprintf(tmp, sizeof(tmp), "Mtu=%u ", Endian32(ol->Mtu->Mtu));
|
||||
StrCat(info, sizeof(info), tmp);
|
||||
}
|
||||
|
||||
Trim(info);
|
||||
|
||||
if (IsEmptyStr(info) == false)
|
||||
{
|
||||
t->Token[14] = CopyStr(info);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case L4_TCP:
|
||||
// TCP packet
|
||||
tcp_conn = false;
|
||||
@ -1786,26 +1794,26 @@ char *PacketLogParseProc(RECORD *rec)
|
||||
|
||||
{
|
||||
Format(tmp, sizeof(tmp), "InitiatorCookie=%I64u ResponderCookie=%I64u "
|
||||
"Version=0x%x ExchangeType=0x%x Flag=0x%x MessageId=%u MessageSize=%u",
|
||||
Endian64(p->L7.IkeHeader->InitiatorCookie),
|
||||
Endian64(p->L7.IkeHeader->ResponderCookie),
|
||||
p->L7.IkeHeader->Version,
|
||||
p->L7.IkeHeader->ExchangeType,
|
||||
p->L7.IkeHeader->Flag,
|
||||
Endian32(p->L7.IkeHeader->MessageId),
|
||||
Endian32(p->L7.IkeHeader->MessageSize));
|
||||
"Version=0x%x ExchangeType=0x%x Flag=0x%x MessageId=%u MessageSize=%u",
|
||||
Endian64(p->L7.IkeHeader->InitiatorCookie),
|
||||
Endian64(p->L7.IkeHeader->ResponderCookie),
|
||||
p->L7.IkeHeader->Version,
|
||||
p->L7.IkeHeader->ExchangeType,
|
||||
p->L7.IkeHeader->Flag,
|
||||
Endian32(p->L7.IkeHeader->MessageId),
|
||||
Endian32(p->L7.IkeHeader->MessageSize));
|
||||
|
||||
t->Token[14] = CopyStr(tmp);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case L7_DNS:
|
||||
// DNS query
|
||||
t->Token[6] = CopyStr("DNSv6");
|
||||
t->Token[7] = CopyStr("DNS_Query");
|
||||
t->Token[14] = CopyStr(p->DnsQueryHost);
|
||||
break;
|
||||
|
||||
case L7_DNS:
|
||||
// DNS query
|
||||
t->Token[6] = CopyStr("DNSv6");
|
||||
t->Token[7] = CopyStr("DNS_Query");
|
||||
t->Token[14] = CopyStr(p->DnsQueryHost);
|
||||
break;
|
||||
|
||||
default:
|
||||
t->Token[6] = CopyStr("UDPv6");
|
||||
@ -1975,7 +1983,7 @@ char *GenCsvLine(TOKEN_LIST *t)
|
||||
}
|
||||
|
||||
b = NewBuf();
|
||||
for (i = 0;i < t->NumTokens;i++)
|
||||
for (i = 0; i < t->NumTokens; i++)
|
||||
{
|
||||
if (t->Token[i] != NULL)
|
||||
{
|
||||
@ -2019,7 +2027,7 @@ void ReplaceForCsv(char *str)
|
||||
|
||||
len = StrLen(str);
|
||||
|
||||
for (i = 0;i < len;i++)
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
// Convert the comma to underscore
|
||||
if (str[i] == ',')
|
||||
@ -2154,7 +2162,7 @@ void MakeLogFileNameStringFromTick(LOG *g, char *str, UINT size, UINT64 tick, UI
|
||||
if (g->CacheFlag)
|
||||
{
|
||||
if (g->LastTick == tick &&
|
||||
g->LastSwitchType == switch_type)
|
||||
g->LastSwitchType == switch_type)
|
||||
{
|
||||
StrCpy(str, size, g->LastStr);
|
||||
return;
|
||||
@ -2168,12 +2176,12 @@ void MakeLogFileNameStringFromTick(LOG *g, char *str, UINT size, UINT64 tick, UI
|
||||
{
|
||||
case LOG_SWITCH_SECOND: // Secondly basis
|
||||
snprintf(str, size, "_%04u%02u%02u_%02u%02u%02u",
|
||||
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
|
||||
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
|
||||
break;
|
||||
|
||||
case LOG_SWITCH_MINUTE: // Minutely basis
|
||||
snprintf(str, size, "_%04u%02u%02u_%02u%02u",
|
||||
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute);
|
||||
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute);
|
||||
break;
|
||||
|
||||
case LOG_SWITCH_HOUR: // Hourly basis
|
||||
@ -2271,9 +2279,9 @@ bool MakeLogFileName(LOG *g, char *name, UINT size, char *dir, char *prefix, UIN
|
||||
}
|
||||
|
||||
snprintf(name, size, "%s%s%s%s%s.log", dir,
|
||||
StrLen(dir) == 0 ? "" : "/",
|
||||
prefix, tmp, tmp2
|
||||
);
|
||||
StrLen(dir) == 0 ? "" : "/",
|
||||
prefix, tmp, tmp2
|
||||
);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -2533,7 +2541,7 @@ static bool LogThreadWriteGeneral(LOG *log_object, BUF *buffer, IO **io, bool *l
|
||||
LockLog(log_object);
|
||||
{
|
||||
*log_date_changed = MakeLogFileName(log_object, file_name, sizeof(file_name),
|
||||
log_object->DirName, log_object->Prefix, rec->Tick, log_object->SwitchType, log_object->CurrentLogNumber, current_logfile_datename);
|
||||
log_object->DirName, log_object->Prefix, rec->Tick, log_object->SwitchType, log_object->CurrentLogNumber, current_logfile_datename);
|
||||
|
||||
if (*log_date_changed)
|
||||
{
|
||||
@ -2541,12 +2549,12 @@ static bool LogThreadWriteGeneral(LOG *log_object, BUF *buffer, IO **io, bool *l
|
||||
|
||||
log_object->CurrentLogNumber = 0;
|
||||
MakeLogFileName(log_object, file_name, sizeof(file_name),
|
||||
log_object->DirName, log_object->Prefix, rec->Tick, log_object->SwitchType, 0, current_logfile_datename);
|
||||
for (i = 0;;i++)
|
||||
log_object->DirName, log_object->Prefix, rec->Tick, log_object->SwitchType, 0, current_logfile_datename);
|
||||
for (i = 0;; i++)
|
||||
{
|
||||
char tmp[MAX_SIZE];
|
||||
MakeLogFileName(log_object, tmp, sizeof(tmp),
|
||||
log_object->DirName, log_object->Prefix, rec->Tick, log_object->SwitchType, i, current_logfile_datename);
|
||||
log_object->DirName, log_object->Prefix, rec->Tick, log_object->SwitchType, i, current_logfile_datename);
|
||||
|
||||
if (IsFileExists(tmp) == false)
|
||||
{
|
||||
@ -2564,7 +2572,7 @@ static bool LogThreadWriteGeneral(LOG *log_object, BUF *buffer, IO **io, bool *l
|
||||
if (StrCmp(current_file_name, file_name) != 0)
|
||||
{
|
||||
// If a log file is currently opened and writing to another log
|
||||
// file is needed for this time, write the contents of the
|
||||
// file is needed for this time, write the contents of the
|
||||
//buffer and close the log file. Write the contents of the buffer
|
||||
if (*io != NULL)
|
||||
{
|
||||
|
@ -259,13 +259,13 @@ void OvsLog(OPENVPN_SERVER *s, OPENVPN_SESSION *se, OPENVPN_CHANNEL *c, char *na
|
||||
if (c == NULL)
|
||||
{
|
||||
UniFormat(prefix, sizeof(prefix), _UU("LO_PREFIX_SESSION"),
|
||||
se->Id, &se->ClientIp, se->ClientPort, &se->ServerIp, se->ServerPort);
|
||||
se->Id, &se->ClientIp, se->ClientPort, &se->ServerIp, se->ServerPort);
|
||||
}
|
||||
else
|
||||
{
|
||||
UniFormat(prefix, sizeof(prefix), _UU("LO_PREFIX_CHANNEL"),
|
||||
se->Id, &se->ClientIp, se->ClientPort, &se->ServerIp, se->ServerPort,
|
||||
c->KeyId);
|
||||
se->Id, &se->ClientIp, se->ClientPort, &se->ServerIp, se->ServerPort,
|
||||
c->KeyId);
|
||||
}
|
||||
}
|
||||
va_start(args, name);
|
||||
@ -617,10 +617,10 @@ void OvsProceccRecvPacket(OPENVPN_SERVER *s, UDPPACKET *p, UINT protocol)
|
||||
{
|
||||
// Control packet
|
||||
Debug("OvsProceccRecvPacket(): Received control packet. PacketId: %u, OpCode: %u, KeyId: %u, MySessionId: %I64u\n",
|
||||
recv_packet->PacketId, recv_packet->OpCode, recv_packet->KeyId, recv_packet->MySessionId);
|
||||
recv_packet->PacketId, recv_packet->OpCode, recv_packet->KeyId, recv_packet->MySessionId);
|
||||
|
||||
if (recv_packet->OpCode == OPENVPN_P_CONTROL_HARD_RESET_CLIENT_V2 ||
|
||||
recv_packet->OpCode == OPENVPN_P_CONTROL_SOFT_RESET_V1)
|
||||
recv_packet->OpCode == OPENVPN_P_CONTROL_SOFT_RESET_V1)
|
||||
{
|
||||
// Connection request packet
|
||||
if (c != NULL && c->Status == OPENVPN_CHANNEL_STATUS_ESTABLISHED)
|
||||
@ -644,19 +644,19 @@ void OvsProceccRecvPacket(OPENVPN_SERVER *s, UDPPACKET *p, UINT protocol)
|
||||
OvsLog(s, se, c, "LO_NEW_CHANNEL");
|
||||
}
|
||||
}
|
||||
/* else if (recv_packet->OpCode == OPENVPN_P_CONTROL_SOFT_RESET_V1)
|
||||
{
|
||||
// Response to soft reset request packet
|
||||
OPENVPN_PACKET *p;
|
||||
/* else if (recv_packet->OpCode == OPENVPN_P_CONTROL_SOFT_RESET_V1)
|
||||
{
|
||||
// Response to soft reset request packet
|
||||
OPENVPN_PACKET *p;
|
||||
|
||||
p = OvsNewControlPacket(OPENVPN_P_CONTROL_SOFT_RESET_V1, recv_packet->KeyId, se->ServerSessionId,
|
||||
0, NULL, 0, 0, 0, NULL);
|
||||
p = OvsNewControlPacket(OPENVPN_P_CONTROL_SOFT_RESET_V1, recv_packet->KeyId, se->ServerSessionId,
|
||||
0, NULL, 0, 0, 0, NULL);
|
||||
|
||||
OvsSendPacketNow(s, se, p);
|
||||
OvsSendPacketNow(s, se, p);
|
||||
|
||||
OvsFreePacket(p);
|
||||
}
|
||||
*/
|
||||
OvsFreePacket(p);
|
||||
}
|
||||
*/
|
||||
if (c != NULL)
|
||||
{
|
||||
// Delete the send packet list by looking the packet ID in the ACK list of arrived packet
|
||||
@ -668,8 +668,8 @@ void OvsProceccRecvPacket(OPENVPN_SERVER *s, UDPPACKET *p, UINT protocol)
|
||||
InsertIntDistinct(c->AckReplyList, recv_packet->PacketId);
|
||||
|
||||
if ((recv_packet->PacketId > c->MaxRecvPacketId)
|
||||
|| (recv_packet->OpCode == OPENVPN_P_CONTROL_HARD_RESET_CLIENT_V2)
|
||||
|| (recv_packet->OpCode == OPENVPN_P_CONTROL_SOFT_RESET_V1))
|
||||
|| (recv_packet->OpCode == OPENVPN_P_CONTROL_HARD_RESET_CLIENT_V2)
|
||||
|| (recv_packet->OpCode == OPENVPN_P_CONTROL_SOFT_RESET_V1))
|
||||
{
|
||||
c->MaxRecvPacketId = recv_packet->PacketId;
|
||||
|
||||
@ -743,12 +743,12 @@ void OvsDeleteFromSendingControlPacketList(OPENVPN_CHANNEL *c, UINT num_acks, UI
|
||||
}
|
||||
|
||||
o = NewListFast(NULL);
|
||||
for (i = 0;i < num_acks;i++)
|
||||
for (i = 0; i < num_acks; i++)
|
||||
{
|
||||
UINT ack = acks[i];
|
||||
UINT j;
|
||||
|
||||
for (j = 0;j < LIST_NUM(c->SendControlPacketList);j++)
|
||||
for (j = 0; j < LIST_NUM(c->SendControlPacketList); j++)
|
||||
{
|
||||
OPENVPN_CONTROL_PACKET *p = LIST_DATA(c->SendControlPacketList, j);
|
||||
|
||||
@ -759,7 +759,7 @@ void OvsDeleteFromSendingControlPacketList(OPENVPN_CHANNEL *c, UINT num_acks, UI
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0;i < LIST_NUM(o);i++)
|
||||
for (i = 0; i < LIST_NUM(o); i++)
|
||||
{
|
||||
OPENVPN_CONTROL_PACKET *p = LIST_DATA(o, i);
|
||||
|
||||
@ -1119,7 +1119,7 @@ UINT OvsPeekStringFromFifo(FIFO *f, char *str, UINT str_size)
|
||||
|
||||
StrCpy(str, str_size, "");
|
||||
|
||||
for (i = 0;i < MIN(str_size, FifoSize(f));i++)
|
||||
for (i = 0; i < MIN(str_size, FifoSize(f)); i++)
|
||||
{
|
||||
char c = *(((char *)FifoPtr(f)) + i);
|
||||
|
||||
@ -1267,8 +1267,8 @@ void OvsSetupSessionParameters(OPENVPN_SERVER *s, OPENVPN_SESSION *se, OPENVPN_C
|
||||
WriteBuf(b, c->ClientKey.Random1, sizeof(c->ClientKey.Random1));
|
||||
WriteBuf(b, c->ServerKey.Random1, sizeof(c->ServerKey.Random1));
|
||||
Enc_tls1_PRF(b->Buf, b->Size,
|
||||
c->ClientKey.PreMasterSecret, sizeof(c->ClientKey.PreMasterSecret),
|
||||
c->MasterSecret, sizeof(c->MasterSecret));
|
||||
c->ClientKey.PreMasterSecret, sizeof(c->ClientKey.PreMasterSecret),
|
||||
c->MasterSecret, sizeof(c->MasterSecret));
|
||||
FreeBuf(b);
|
||||
|
||||
// Generate an Expansion Key
|
||||
@ -1279,7 +1279,7 @@ void OvsSetupSessionParameters(OPENVPN_SERVER *s, OPENVPN_SESSION *se, OPENVPN_C
|
||||
WriteBufInt64(b, se->ClientSessionId);
|
||||
WriteBufInt64(b, se->ServerSessionId);
|
||||
Enc_tls1_PRF(b->Buf, b->Size, c->MasterSecret, sizeof(c->MasterSecret),
|
||||
c->ExpansionKey, sizeof(c->ExpansionKey));
|
||||
c->ExpansionKey, sizeof(c->ExpansionKey));
|
||||
FreeBuf(b);
|
||||
|
||||
// Set up the encryption algorithm
|
||||
@ -1314,13 +1314,13 @@ void OvsSetupSessionParameters(OPENVPN_SERVER *s, OPENVPN_SESSION *se, OPENVPN_C
|
||||
|
||||
// Generate the response option string
|
||||
Format(c->ServerKey.OptionString, sizeof(c->ServerKey.OptionString),
|
||||
"V4,dev-type %s,link-mtu %u,tun-mtu %u,proto %s,"
|
||||
"cipher %s,auth %s,keysize %u,key-method 2,tls-server",
|
||||
(se->Mode == OPENVPN_MODE_L2 ? "tap" : "tun"),
|
||||
se->LinkMtu,
|
||||
se->TunMtu,
|
||||
c->Proto,
|
||||
cipher_name, md_name, c->CipherEncrypt->KeySize * 8);
|
||||
"V4,dev-type %s,link-mtu %u,tun-mtu %u,proto %s,"
|
||||
"cipher %s,auth %s,keysize %u,key-method 2,tls-server",
|
||||
(se->Mode == OPENVPN_MODE_L2 ? "tap" : "tun"),
|
||||
se->LinkMtu,
|
||||
se->TunMtu,
|
||||
c->Proto,
|
||||
cipher_name, md_name, c->CipherEncrypt->KeySize * 8);
|
||||
|
||||
FreeEntryList(o);
|
||||
|
||||
@ -1482,13 +1482,13 @@ UINT OvsParseKeyMethod2(OPENVPN_KEY_METHOD_2 *ret, UCHAR *data, UINT size, bool
|
||||
{
|
||||
// String
|
||||
if (OvsReadStringFromBuf(b, ret->OptionString, sizeof(ret->OptionString)) &&
|
||||
OvsReadStringFromBuf(b, ret->Username, sizeof(ret->Username)) &&
|
||||
OvsReadStringFromBuf(b, ret->Password, sizeof(ret->Password)))
|
||||
OvsReadStringFromBuf(b, ret->Username, sizeof(ret->Username)) &&
|
||||
OvsReadStringFromBuf(b, ret->Password, sizeof(ret->Password)))
|
||||
{
|
||||
if (!OvsReadStringFromBuf(b, ret->PeerInfo, sizeof(ret->PeerInfo)))
|
||||
{
|
||||
if (!OvsReadStringFromBuf(b, ret->PeerInfo, sizeof(ret->PeerInfo)))
|
||||
{
|
||||
Zero(ret->PeerInfo, sizeof(ret->PeerInfo));
|
||||
}
|
||||
Zero(ret->PeerInfo, sizeof(ret->PeerInfo));
|
||||
}
|
||||
read_size = b->Current;
|
||||
}
|
||||
}
|
||||
@ -1637,7 +1637,7 @@ UINT OvsGetAckReplyList(OPENVPN_CHANNEL *c, UINT *ret)
|
||||
|
||||
num = MIN(LIST_NUM(c->AckReplyList), OPENVPN_MAX_NUMACK);
|
||||
|
||||
for (i = 0;i < num;i++)
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
UINT *v = LIST_DATA(c->AckReplyList, i);
|
||||
|
||||
@ -1651,7 +1651,7 @@ UINT OvsGetAckReplyList(OPENVPN_CHANNEL *c, UINT *ret)
|
||||
ret[i] = *v;
|
||||
}
|
||||
|
||||
for (i = 0;i < LIST_NUM(o);i++)
|
||||
for (i = 0; i < LIST_NUM(o); i++)
|
||||
{
|
||||
UINT *v = LIST_DATA(o, i);
|
||||
|
||||
@ -1682,7 +1682,7 @@ void OvsFreeChannel(OPENVPN_CHANNEL *c)
|
||||
|
||||
ReleaseIntList(c->AckReplyList);
|
||||
|
||||
for (i = 0;i < LIST_NUM(c->SendControlPacketList);i++)
|
||||
for (i = 0; i < LIST_NUM(c->SendControlPacketList); i++)
|
||||
{
|
||||
OPENVPN_CONTROL_PACKET *p = LIST_DATA(c->SendControlPacketList, i);
|
||||
|
||||
@ -1758,7 +1758,7 @@ UINT64 OvsNewServerSessionId(OPENVPN_SERVER *s)
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i = 0;i < LIST_NUM(s->SessionList);i++)
|
||||
for (i = 0; i < LIST_NUM(s->SessionList); i++)
|
||||
{
|
||||
OPENVPN_SESSION *se = LIST_DATA(s->SessionList, i);
|
||||
if (se->ServerSessionId == id)
|
||||
@ -1882,7 +1882,7 @@ BUF *OvsBuildPacket(OPENVPN_PACKET *p)
|
||||
{
|
||||
UINT i;
|
||||
|
||||
for (i = 0;i < num_ack;i++)
|
||||
for (i = 0; i < num_ack; i++)
|
||||
{
|
||||
WriteBufInt(b, (UCHAR)p->AckPacketId[i]);
|
||||
}
|
||||
@ -1970,7 +1970,7 @@ OPENVPN_PACKET *OvsParsePacket(UCHAR *data, UINT size)
|
||||
goto LABEL_ERROR;
|
||||
}
|
||||
|
||||
for (i = 0;i < ret->NumAck;i++)
|
||||
for (i = 0; i < ret->NumAck; i++)
|
||||
{
|
||||
UINT ui;
|
||||
|
||||
@ -2066,7 +2066,7 @@ UINT OvsGetNumSessionByClientIp(OPENVPN_SERVER *s, IP *ip)
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0;i < LIST_NUM(s->SessionList);i++)
|
||||
for (i = 0; i < LIST_NUM(s->SessionList); i++)
|
||||
{
|
||||
OPENVPN_SESSION *se = LIST_DATA(s->SessionList, i);
|
||||
|
||||
@ -2130,7 +2130,7 @@ OPENVPN_SESSION *OvsNewSession(OPENVPN_SERVER *s, IP *server_ip, UINT server_por
|
||||
IPToStr(server_ip_str, sizeof(server_ip_str), server_ip);
|
||||
IPToStr(client_ip_str, sizeof(client_ip_str), client_ip);
|
||||
Debug("OpenVPN New Session: %s:%u -> %s:%u Proto=%u\n", server_ip_str, server_port,
|
||||
client_ip_str, client_port, protocol);
|
||||
client_ip_str, client_port, protocol);
|
||||
|
||||
OvsLog(s, se, NULL, "LO_NEW_SESSION", (protocol == OPENVPN_PROTOCOL_UDP ? "UDP" : "TCP"));
|
||||
|
||||
@ -2159,13 +2159,14 @@ void OvsFreeSession(OPENVPN_SESSION *se)
|
||||
UINTToIP(&dhcp_ip, se->IpcAsync->L3ClientAddressOption.ServerAddress);
|
||||
|
||||
IPCDhcpFreeIP(se->Ipc, &dhcp_ip);
|
||||
IPCProcessL3Events(se->Ipc);
|
||||
IPC_PROTO_SET_STATUS(se->Ipc, IPv6State, IPC_PROTO_STATUS_CLOSED);
|
||||
IPCProcessL3EventsIPv4Only(se->Ipc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Release the channel
|
||||
for (i = 0;i < OPENVPN_NUM_CHANNELS;i++)
|
||||
for (i = 0; i < OPENVPN_NUM_CHANNELS; i++)
|
||||
{
|
||||
OPENVPN_CHANNEL *c = se->Channels[i];
|
||||
|
||||
@ -2225,7 +2226,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
s->Now = Tick64();
|
||||
|
||||
// Process for all sessions
|
||||
for (i = 0;i < LIST_NUM(s->SessionList);i++)
|
||||
for (i = 0; i < LIST_NUM(s->SessionList); i++)
|
||||
{
|
||||
OPENVPN_SESSION *se = LIST_DATA(s->SessionList, i);
|
||||
|
||||
@ -2240,7 +2241,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
}
|
||||
|
||||
// Process received packets
|
||||
for (i = 0;i < LIST_NUM(recv_packet_list);i++)
|
||||
for (i = 0; i < LIST_NUM(recv_packet_list); i++)
|
||||
{
|
||||
UDPPACKET *p = LIST_DATA(recv_packet_list, i);
|
||||
|
||||
@ -2248,7 +2249,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
}
|
||||
|
||||
// Treat for all sessions and all channels
|
||||
for (i = 0;i < LIST_NUM(s->SessionList);i++)
|
||||
for (i = 0; i < LIST_NUM(s->SessionList); i++)
|
||||
{
|
||||
OPENVPN_CHANNEL *latest_channel = NULL;
|
||||
UINT64 max_tick = 0;
|
||||
@ -2259,11 +2260,11 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
{
|
||||
if (se->Mode == OPENVPN_MODE_L3)
|
||||
{
|
||||
IPCProcessL3Events(se->Ipc);
|
||||
IPCProcessL3EventsIPv4Only(se->Ipc);
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0;j < OPENVPN_NUM_CHANNELS;j++)
|
||||
for (j = 0; j < OPENVPN_NUM_CHANNELS; j++)
|
||||
{
|
||||
OPENVPN_CHANNEL *c = se->Channels[j];
|
||||
|
||||
@ -2320,9 +2321,9 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
|
||||
// Return the PUSH_REPLY
|
||||
Format(option_str, sizeof(option_str),
|
||||
"PUSH_REPLY,ping %u,ping-restart %u",
|
||||
(OPENVPN_PING_SEND_INTERVAL / 1000),
|
||||
(OPENVPN_RECV_TIMEOUT / 1000));
|
||||
"PUSH_REPLY,ping %u,ping-restart %u",
|
||||
(OPENVPN_PING_SEND_INTERVAL / 1000),
|
||||
(OPENVPN_RECV_TIMEOUT / 1000));
|
||||
|
||||
if (se->Mode == OPENVPN_MODE_L3)
|
||||
{
|
||||
@ -2344,26 +2345,26 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
ClearStr(ip_defgw, sizeof(ip_defgw));
|
||||
|
||||
IPToStr32(ip_client, sizeof(ip_client),
|
||||
cao->ClientAddress);
|
||||
cao->ClientAddress);
|
||||
|
||||
IPToStr32(ip_subnet_mask, sizeof(ip_subnet_mask),
|
||||
cao->SubnetMask);
|
||||
cao->SubnetMask);
|
||||
|
||||
Format(l3_options, sizeof(l3_options),
|
||||
",topology subnet");
|
||||
",topology subnet");
|
||||
StrCat(option_str, sizeof(option_str), l3_options);
|
||||
|
||||
Format(l3_options, sizeof(l3_options),
|
||||
",ifconfig %s %s",
|
||||
ip_client,
|
||||
ip_subnet_mask);
|
||||
",ifconfig %s %s",
|
||||
ip_client,
|
||||
ip_subnet_mask);
|
||||
StrCat(option_str, sizeof(option_str), l3_options);
|
||||
|
||||
// Domain name
|
||||
if (IsEmptyStr(cao->DomainName) == false)
|
||||
{
|
||||
Format(l3_options, sizeof(l3_options),
|
||||
",dhcp-option DOMAIN %s", cao->DomainName);
|
||||
",dhcp-option DOMAIN %s", cao->DomainName);
|
||||
StrCat(option_str, sizeof(option_str), l3_options);
|
||||
}
|
||||
|
||||
@ -2373,7 +2374,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
char ip_str[64];
|
||||
IPToStr32(ip_str, sizeof(ip_str), cao->DnsServer);
|
||||
Format(l3_options, sizeof(l3_options),
|
||||
",dhcp-option DNS %s", ip_str);
|
||||
",dhcp-option DNS %s", ip_str);
|
||||
StrCat(option_str, sizeof(option_str), l3_options);
|
||||
|
||||
StrCpy(ip_dns1, sizeof(ip_dns1), ip_str);
|
||||
@ -2385,7 +2386,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
char ip_str[64];
|
||||
IPToStr32(ip_str, sizeof(ip_str), cao->DnsServer2);
|
||||
Format(l3_options, sizeof(l3_options),
|
||||
",dhcp-option DNS %s", ip_str);
|
||||
",dhcp-option DNS %s", ip_str);
|
||||
StrCat(option_str, sizeof(option_str), l3_options);
|
||||
|
||||
StrCpy(ip_dns2, sizeof(ip_dns2), ip_str);
|
||||
@ -2397,7 +2398,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
char ip_str[64];
|
||||
IPToStr32(ip_str, sizeof(ip_str), cao->WinsServer);
|
||||
Format(l3_options, sizeof(l3_options),
|
||||
",dhcp-option WINS %s", ip_str);
|
||||
",dhcp-option WINS %s", ip_str);
|
||||
StrCat(option_str, sizeof(option_str), l3_options);
|
||||
|
||||
StrCpy(ip_wins1, sizeof(ip_wins1), ip_str);
|
||||
@ -2409,7 +2410,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
char ip_str[64];
|
||||
IPToStr32(ip_str, sizeof(ip_str), cao->WinsServer2);
|
||||
Format(l3_options, sizeof(l3_options),
|
||||
",dhcp-option WINS %s", ip_str);
|
||||
",dhcp-option WINS %s", ip_str);
|
||||
StrCat(option_str, sizeof(option_str), l3_options);
|
||||
|
||||
StrCpy(ip_wins2, sizeof(ip_wins2), ip_str);
|
||||
@ -2421,7 +2422,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
char ip_str[64];
|
||||
IPToStr32(ip_str, sizeof(ip_str), cao->Gateway);
|
||||
Format(l3_options, sizeof(l3_options),
|
||||
",route-gateway %s,redirect-gateway def1", ip_str);
|
||||
",route-gateway %s,redirect-gateway def1", ip_str);
|
||||
StrCat(option_str, sizeof(option_str), l3_options);
|
||||
|
||||
StrCpy(ip_defgw, sizeof(ip_defgw), ip_str);
|
||||
@ -2442,9 +2443,9 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
IPAnd4(&local_network, &client_ip, &subnet_mask);
|
||||
|
||||
Format(l3_options, sizeof(l3_options),
|
||||
",route %r %r vpn_gateway",
|
||||
&local_network,
|
||||
&cao->SubnetMask);
|
||||
",route %r %r vpn_gateway",
|
||||
&local_network,
|
||||
&cao->SubnetMask);
|
||||
|
||||
StrCat(option_str, sizeof(option_str), l3_options);
|
||||
#endif
|
||||
@ -2454,15 +2455,15 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
if (cao->ClasslessRoute.NumExistingRoutes >= 1)
|
||||
{
|
||||
UINT i;
|
||||
for (i = 0;i < MAX_DHCP_CLASSLESS_ROUTE_ENTRIES;i++)
|
||||
for (i = 0; i < MAX_DHCP_CLASSLESS_ROUTE_ENTRIES; i++)
|
||||
{
|
||||
DHCP_CLASSLESS_ROUTE *r = &cao->ClasslessRoute.Entries[i];
|
||||
|
||||
if (r->Exists)
|
||||
{
|
||||
Format(l3_options, sizeof(l3_options),
|
||||
",route %r %r vpn_gateway",
|
||||
&r->Network, &r->SubnetMask);
|
||||
",route %r %r vpn_gateway",
|
||||
&r->Network, &r->SubnetMask);
|
||||
|
||||
StrCat(option_str, sizeof(option_str), l3_options);
|
||||
}
|
||||
@ -2470,7 +2471,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
}
|
||||
|
||||
OvsLog(s, se, c, "LP_SET_IPV4_PARAM",
|
||||
ip_client, ip_subnet_mask, ip_defgw, ip_dns1, ip_dns2, ip_wins1, ip_wins2);
|
||||
ip_client, ip_subnet_mask, ip_defgw, ip_dns1, ip_dns2, ip_wins1, ip_wins2);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2579,8 +2580,8 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
Debug("RawOut Fifo Size (c=%u): %u\n", c->KeyId, FifoSize(c->SslPipe->RawOut->RecvFifo));
|
||||
|
||||
OvsSendControlPacketWithAutoSplit(c, OPENVPN_P_CONTROL_V1,
|
||||
FifoPtr(c->SslPipe->RawOut->RecvFifo),
|
||||
FifoSize(c->SslPipe->RawOut->RecvFifo));
|
||||
FifoPtr(c->SslPipe->RawOut->RecvFifo),
|
||||
FifoSize(c->SslPipe->RawOut->RecvFifo));
|
||||
|
||||
ReadFifo(c->SslPipe->RawOut->RecvFifo, NULL, FifoSize(c->SslPipe->RawOut->RecvFifo));
|
||||
}
|
||||
@ -2594,7 +2595,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
UINT k;
|
||||
|
||||
// Packet transmission
|
||||
for (k = 0;k < LIST_NUM(c->SendControlPacketList);k++)
|
||||
for (k = 0; k < LIST_NUM(c->SendControlPacketList); k++)
|
||||
{
|
||||
OPENVPN_CONTROL_PACKET *cp = LIST_DATA(c->SendControlPacketList, k);
|
||||
|
||||
@ -2609,7 +2610,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
num = OvsGetAckReplyList(c, acks);
|
||||
|
||||
p = OvsNewControlPacket(cp->OpCode, j, se->ServerSessionId, num, acks,
|
||||
se->ClientSessionId, cp->PacketId, cp->DataSize, cp->Data);
|
||||
se->ClientSessionId, cp->PacketId, cp->DataSize, cp->Data);
|
||||
|
||||
OvsSendPacketNow(s, se, p);
|
||||
|
||||
@ -2628,7 +2629,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
if (num >= 1)
|
||||
{
|
||||
OPENVPN_PACKET *p = OvsNewControlPacket(OPENVPN_P_ACK_V1, j, se->ServerSessionId,
|
||||
num, acks, se->ClientSessionId, 0, 0, NULL);
|
||||
num, acks, se->ClientSessionId, 0, 0, NULL);
|
||||
|
||||
OvsSendPacketNow(s, se, p);
|
||||
|
||||
@ -2656,14 +2657,14 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
}
|
||||
}
|
||||
|
||||
IPCProcessL3Events(se->Ipc);
|
||||
IPCProcessL3EventsIPv4Only(se->Ipc);
|
||||
}
|
||||
|
||||
IPCProcessInterrupts(se->Ipc);
|
||||
}
|
||||
|
||||
// Choose the latest channel in all established channels
|
||||
for (j = 0;j < OPENVPN_NUM_CHANNELS;j++)
|
||||
for (j = 0; j < OPENVPN_NUM_CHANNELS; j++)
|
||||
{
|
||||
OPENVPN_CHANNEL *c = se->Channels[j];
|
||||
|
||||
@ -2733,7 +2734,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
se->NextPingSendTick = s->Now + (UINT64)(OPENVPN_PING_SEND_INTERVAL);
|
||||
|
||||
OvsSendDataPacket(latest_channel, latest_channel->KeyId, ++latest_channel->LastDataPacketId,
|
||||
ping_signature, sizeof(ping_signature));
|
||||
ping_signature, sizeof(ping_signature));
|
||||
//Debug(".");
|
||||
|
||||
AddInterrupt(s->Interrupt, se->NextPingSendTick);
|
||||
@ -2765,7 +2766,7 @@ void OvsRecvPacket(OPENVPN_SERVER *s, LIST *recv_packet_list, UINT protocol)
|
||||
{
|
||||
UINT i;
|
||||
|
||||
for (i = 0;i < LIST_NUM(delete_session_list);i++)
|
||||
for (i = 0; i < LIST_NUM(delete_session_list); i++)
|
||||
{
|
||||
OPENVPN_SESSION *se = LIST_DATA(delete_session_list, i);
|
||||
|
||||
@ -2798,7 +2799,7 @@ void OvsSendPacketNow(OPENVPN_SERVER *s, OPENVPN_SESSION *se, OPENVPN_PACKET *p)
|
||||
if (p->NumAck >= 1)
|
||||
{
|
||||
Debug("Sending ACK Packet IDs (c=%u): ", p->KeyId);
|
||||
for (i = 0;i < p->NumAck;i++)
|
||||
for (i = 0; i < p->NumAck; i++)
|
||||
{
|
||||
Debug("%u ", p->AckPacketId[i]);
|
||||
}
|
||||
@ -2844,14 +2845,14 @@ void OvsSendPacketRawNow(OPENVPN_SERVER *s, OPENVPN_SESSION *se, void *data, UIN
|
||||
}
|
||||
|
||||
u = NewUdpPacket(&se->ServerIp, se->ServerPort, &se->ClientIp, se->ClientPort,
|
||||
data, size);
|
||||
data, size);
|
||||
|
||||
Add(s->SendPacketList, u);
|
||||
}
|
||||
// Create a new OpenVPN control packet
|
||||
OPENVPN_PACKET *OvsNewControlPacket(UCHAR opcode, UCHAR key_id, UINT64 my_channel_id, UINT num_ack,
|
||||
UINT *ack_packet_ids, UINT64 your_channel_id, UINT packet_id,
|
||||
UINT data_size, UCHAR *data)
|
||||
UINT *ack_packet_ids, UINT64 your_channel_id, UINT packet_id,
|
||||
UINT data_size, UCHAR *data)
|
||||
{
|
||||
OPENVPN_PACKET *p = ZeroMalloc(sizeof(OPENVPN_PACKET));
|
||||
UINT i;
|
||||
@ -2861,7 +2862,7 @@ OPENVPN_PACKET *OvsNewControlPacket(UCHAR opcode, UCHAR key_id, UINT64 my_channe
|
||||
p->MySessionId = my_channel_id;
|
||||
p->NumAck = num_ack;
|
||||
|
||||
for (i = 0;i < MIN(num_ack, OPENVPN_MAX_NUMACK);i++)
|
||||
for (i = 0; i < MIN(num_ack, OPENVPN_MAX_NUMACK); i++)
|
||||
{
|
||||
p->AckPacketId[i] = ack_packet_ids[i];
|
||||
}
|
||||
|
@ -12,9 +12,6 @@ void PPPThread(THREAD *thread, void *param)
|
||||
{
|
||||
PPP_SESSION *p = (PPP_SESSION *)param;
|
||||
UINT i;
|
||||
PPP_LCP *c;
|
||||
USHORT us;
|
||||
UINT ui;
|
||||
USHORT next_protocol = 0;
|
||||
bool ret = false;
|
||||
char ipstr1[128], ipstr2[128];
|
||||
@ -32,8 +29,6 @@ void PPPThread(THREAD *thread, void *param)
|
||||
Debug("PPP Initialize");
|
||||
|
||||
PPPSetStatus(p, PPP_STATUS_CONNECTED);
|
||||
p->IPv4_State = PPP_PROTO_STATUS_CLOSED;
|
||||
p->IPv6_State = PPP_PROTO_STATUS_CLOSED;
|
||||
|
||||
p->Eap_Protocol = PPP_UNSPECIFIED;
|
||||
|
||||
@ -53,7 +48,7 @@ void PPPThread(THREAD *thread, void *param)
|
||||
IPToStr(ipstr1, sizeof(ipstr1), &p->ClientIP);
|
||||
IPToStr(ipstr2, sizeof(ipstr2), &p->ServerIP);
|
||||
PPPLog(p, "LP_CONNECTED", p->Postfix, ipstr1, p->ClientHostname, p->ClientPort, ipstr2, p->ServerPort,
|
||||
p->ClientSoftwareName, p->AdjustMss);
|
||||
p->ClientSoftwareName, p->AdjustMss);
|
||||
|
||||
// We need that so we don't time out on connection immediately
|
||||
p->LastRecvTime = Tick64();
|
||||
@ -148,7 +143,7 @@ void PPPThread(THREAD *thread, void *param)
|
||||
if (!receivedPacketProcessed && p->CurrentPacket != NULL && p->CurrentPacket->IsControl && PPP_CODE_IS_RESPONSE(p->CurrentPacket->Protocol, p->CurrentPacket->Lcp->Code) && !PPP_STATUS_IS_UNAVAILABLE(p->PPPStatus))
|
||||
{
|
||||
PPP_PACKET *request = NULL;
|
||||
// Removing from resend list
|
||||
// Removing from resend list
|
||||
for (i = 0; i < LIST_NUM(p->SentReqPacketList); i++)
|
||||
{
|
||||
PPP_REQUEST_RESEND *t = LIST_DATA(p->SentReqPacketList, i);
|
||||
@ -181,7 +176,8 @@ void PPPThread(THREAD *thread, void *param)
|
||||
{
|
||||
UINT64 nowL;
|
||||
// Here client to server
|
||||
if (p->CurrentPacket->Protocol == PPP_PROTOCOL_IP && p->IPv4_State == PPP_PROTO_STATUS_OPENED)
|
||||
if (p->CurrentPacket->Protocol == PPP_PROTOCOL_IP &&
|
||||
IPC_PROTO_GET_STATUS(p->Ipc, IPv4State) == IPC_PROTO_STATUS_OPENED)
|
||||
{
|
||||
receivedPacketProcessed = true;
|
||||
IPCSendIPv4(p->Ipc, p->CurrentPacket->Data, p->CurrentPacket->DataSize);
|
||||
@ -190,10 +186,11 @@ void PPPThread(THREAD *thread, void *param)
|
||||
{
|
||||
Debug("Got IPv4 packet before IPv4 ready!\n");
|
||||
}
|
||||
else if (p->CurrentPacket->Protocol == PPP_PROTOCOL_IPV6 && p->IPv6_State == PPP_PROTO_STATUS_OPENED)
|
||||
else if (p->CurrentPacket->Protocol == PPP_PROTOCOL_IPV6 &&
|
||||
IPC_PROTO_GET_STATUS(p->Ipc, IPv6State) == IPC_PROTO_STATUS_OPENED)
|
||||
{
|
||||
receivedPacketProcessed = true;
|
||||
Debug("IPv6 to be implemented\n");
|
||||
IPCIPv6Send(p->Ipc, p->CurrentPacket->Data, p->CurrentPacket->DataSize);
|
||||
}
|
||||
else if (p->CurrentPacket->Protocol == PPP_PROTOCOL_IPV6)
|
||||
{
|
||||
@ -275,14 +272,14 @@ void PPPThread(THREAD *thread, void *param)
|
||||
// We got to start CHAP when we got no LCP packets from the client on previous iteration
|
||||
// which means we parsed all the client requests and responses
|
||||
Debug("Starting PPP Authentication phase MS-CHAP v2\n");
|
||||
|
||||
|
||||
lcp = BuildMSCHAP2ChallengePacket(p);
|
||||
if (!PPPSendAndRetransmitRequest(p, PPP_PROTOCOL_CHAP, lcp))
|
||||
{
|
||||
PPPSetStatus(p, PPP_STATUS_FAIL);
|
||||
WHERE;
|
||||
}
|
||||
|
||||
|
||||
PPPSetStatus(p, PPP_STATUS_AUTHENTICATING);
|
||||
}
|
||||
|
||||
@ -318,52 +315,98 @@ void PPPThread(THREAD *thread, void *param)
|
||||
if (p->PPPStatus == PPP_STATUS_NETWORK_LAYER)
|
||||
{
|
||||
UINT64 timeBeforeLoop;
|
||||
if (p->DhcpAllocated)
|
||||
if (IPC_PROTO_GET_STATUS(p->Ipc, IPv4State) == IPC_PROTO_STATUS_OPENED)
|
||||
{
|
||||
if (now >= p->DhcpNextRenewTime)
|
||||
if (p->DhcpAllocated)
|
||||
{
|
||||
IP ip;
|
||||
if (now >= p->DhcpNextRenewTime)
|
||||
{
|
||||
IP ip;
|
||||
|
||||
// DHCP renewal procedure
|
||||
p->DhcpNextRenewTime = now + p->DhcpRenewInterval;
|
||||
// DHCP renewal procedure
|
||||
p->DhcpNextRenewTime = now + p->DhcpRenewInterval;
|
||||
|
||||
UINTToIP(&ip, p->ClientAddressOption.ServerAddress);
|
||||
UINTToIP(&ip, p->ClientAddressOption.ServerAddress);
|
||||
|
||||
IPCDhcpRenewIP(p->Ipc, &ip);
|
||||
IPCDhcpRenewIP(p->Ipc, &ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IPCProcessL3Events(p->Ipc);
|
||||
|
||||
|
||||
timeBeforeLoop = Tick64();
|
||||
|
||||
while (true)
|
||||
{
|
||||
UINT64 nowL;
|
||||
BLOCK *b = IPCRecvIPv4(p->Ipc);
|
||||
PPP_PACKET *pp;
|
||||
PPP_PACKET tmp;
|
||||
if (b == NULL)
|
||||
bool no4packets = false;
|
||||
bool no6packets = false;
|
||||
if (IPC_PROTO_GET_STATUS(p->Ipc, IPv4State) == IPC_PROTO_STATUS_OPENED)
|
||||
{
|
||||
break;
|
||||
BLOCK *b = IPCRecvIPv4(p->Ipc);
|
||||
if (b == NULL)
|
||||
{
|
||||
no4packets = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
PPP_PACKET *pp;
|
||||
PPP_PACKET tmp;
|
||||
|
||||
// Since receiving the IP packet, send it to the client by PPP
|
||||
pp = &tmp;
|
||||
pp->IsControl = false;
|
||||
pp->Protocol = PPP_PROTOCOL_IP;
|
||||
pp->Lcp = NULL;
|
||||
pp->Data = b->Buf;
|
||||
pp->DataSize = b->Size;
|
||||
|
||||
PPPSendPacketEx(p, pp, true);
|
||||
|
||||
FreePPPPacketEx(pp, true);
|
||||
Free(b); // Not FreeBlock because freed in FreePPPPacketEx
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
no4packets = true;
|
||||
}
|
||||
|
||||
// Since receiving the IP packet, send it to the client by PPP
|
||||
pp = &tmp;
|
||||
pp->IsControl = false;
|
||||
pp->Protocol = PPP_PROTOCOL_IP;
|
||||
pp->Lcp = NULL;
|
||||
pp->Data = b->Buf;
|
||||
pp->DataSize = b->Size;
|
||||
if (IPC_PROTO_GET_STATUS(p->Ipc, IPv6State) == IPC_PROTO_STATUS_OPENED)
|
||||
{
|
||||
BLOCK *b = IPCIPv6Recv(p->Ipc);
|
||||
if (b == NULL)
|
||||
{
|
||||
no6packets = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
PPP_PACKET *pp;
|
||||
PPP_PACKET tmp;
|
||||
|
||||
PPPSendPacketEx(p, pp, true);
|
||||
// Since receiving the IP packet, send it to the client by PPP
|
||||
pp = &tmp;
|
||||
pp->IsControl = false;
|
||||
pp->Protocol = PPP_PROTOCOL_IPV6;
|
||||
pp->Lcp = NULL;
|
||||
pp->Data = b->Buf;
|
||||
pp->DataSize = b->Size;
|
||||
|
||||
FreePPPPacketEx(pp, true);
|
||||
Free(b);
|
||||
PPPSendPacketEx(p, pp, true);
|
||||
|
||||
FreePPPPacketEx(pp, true);
|
||||
Free(b); // Not FreeBlock because freed in FreePPPPacketEx
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
no6packets = true;
|
||||
}
|
||||
|
||||
// Let's break out of the loop once in a while so we don't get stuck here endlessly
|
||||
nowL = Tick64();
|
||||
if (nowL > timeBeforeLoop + PPP_PACKET_RESEND_INTERVAL)
|
||||
if (nowL > timeBeforeLoop + PPP_PACKET_RESEND_INTERVAL || (no4packets && no6packets))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -398,7 +441,7 @@ void PPPThread(THREAD *thread, void *param)
|
||||
}
|
||||
|
||||
tubes[0] = p->TubeRecv;
|
||||
|
||||
|
||||
if (p->PPPStatus == PPP_STATUS_NETWORK_LAYER && p->Ipc != NULL && IsIPCConnected(p->Ipc))
|
||||
{
|
||||
r = GetNextIntervalForInterrupt(p->Ipc->Interrupt);
|
||||
@ -434,7 +477,7 @@ void PPPThread(THREAD *thread, void *param)
|
||||
|
||||
// Maximum PPP session time of the user reached inspection
|
||||
if (p->UserConnectionTick != 0 && p->UserConnectionTimeout != 0 &&
|
||||
p->UserConnectionTick + p->UserConnectionTimeout <= now)
|
||||
p->UserConnectionTick + p->UserConnectionTimeout <= now)
|
||||
{
|
||||
// User connection time-out occurs
|
||||
PPPLog(p, "LP_USER_TIMEOUT");
|
||||
@ -743,7 +786,7 @@ bool PPPProcessResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req)
|
||||
return PPPProcessIPCPResponsePacket(p, pp, req);
|
||||
break;
|
||||
case PPP_PROTOCOL_IPV6CP:
|
||||
Debug("IPv6CP to be implemented\n");
|
||||
return PPPProcessIPv6CPResponsePacket(p, pp, req);
|
||||
break;
|
||||
case PPP_PROTOCOL_EAP:
|
||||
return PPPProcessEAPResponsePacket(p, pp, req);
|
||||
@ -786,11 +829,11 @@ bool PPPProcessLCPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req
|
||||
USHORT *protocol = pp->Lcp->Data;
|
||||
if (*protocol == PPP_PROTOCOL_IPCP || *protocol == PPP_PROTOCOL_IP)
|
||||
{
|
||||
p->IPv4_State = PPP_PROTO_STATUS_REJECTED;
|
||||
IPC_PROTO_SET_STATUS(p->Ipc, IPv4State, IPC_PROTO_STATUS_REJECTED);
|
||||
}
|
||||
if (*protocol == PPP_PROTOCOL_IPV6CP || *protocol == PPP_PROTOCOL_IPV6)
|
||||
{
|
||||
p->IPv6_State = PPP_PROTO_STATUS_REJECTED;
|
||||
IPC_PROTO_SET_STATUS(p->Ipc, IPv6State, IPC_PROTO_STATUS_REJECTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -864,7 +907,7 @@ bool PPPProcessLCPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req
|
||||
WHERE;
|
||||
return false;
|
||||
}
|
||||
if (opt->DataSize == sizeof(USHORT) && *((USHORT*)(opt->Data)) == Endian16(PPP_LCP_AUTH_EAP))
|
||||
if (opt->DataSize == sizeof(USHORT) && *((USHORT *)(opt->Data)) == Endian16(PPP_LCP_AUTH_EAP))
|
||||
{
|
||||
// Try to request MS-CHAPv2 then
|
||||
if (!isAccepted)
|
||||
@ -877,7 +920,7 @@ bool PPPProcessLCPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req
|
||||
ms_chap_v2_code[2] = PPP_CHAP_ALG_MS_CHAP_V2;
|
||||
|
||||
Copy(&offer, ms_chap_v2_code, sizeof(ms_chap_v2_code));
|
||||
Debug("NACK proto with code = 0x%x, cypher = 0x%x, offered cypher = 0x%x\n", pp->Lcp->Code, *((USHORT*)(opt->Data)), offer);
|
||||
Debug("NACK proto with code = 0x%x, cypher = 0x%x, offered cypher = 0x%x\n", pp->Lcp->Code, *((USHORT *)(opt->Data)), offer);
|
||||
Debug("Request MSCHAPv2\n");
|
||||
Add(c->OptionList, NewPPPOption(PPP_LCP_OPTION_AUTH, &ms_chap_v2_code, sizeof(ms_chap_v2_code)));
|
||||
if (!PPPSendAndRetransmitRequest(p, PPP_PROTOCOL_LCP, c))
|
||||
@ -903,7 +946,7 @@ bool PPPProcessLCPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req
|
||||
PPP_LCP *c = NewPPPLCP(PPP_LCP_CODE_REQ, 0);
|
||||
USHORT proto = Endian16(PPP_LCP_AUTH_PAP);
|
||||
Copy(&offer, t->Data, t->DataSize > sizeof(UINT64) ? sizeof(UINT64) : t->DataSize);
|
||||
Debug("NACK proto with code = 0x%x, cypher = 0x%x, offered cypher = 0x%x\n", pp->Lcp->Code, *((USHORT*)(opt->Data)), offer);
|
||||
Debug("NACK proto with code = 0x%x, cypher = 0x%x, offered cypher = 0x%x\n", pp->Lcp->Code, *((USHORT *)(opt->Data)), offer);
|
||||
Debug("Request PAP\n");
|
||||
Add(c->OptionList, NewPPPOption(PPP_LCP_OPTION_AUTH, &proto, sizeof(USHORT)));
|
||||
if (!PPPSendAndRetransmitRequest(p, PPP_PROTOCOL_LCP, c))
|
||||
@ -919,16 +962,16 @@ bool PPPProcessLCPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req
|
||||
Debug("Setting BEFORE_AUTH from ACK on LCP response parse on CHAP accept\n");
|
||||
PPPSetStatus(p, PPP_STATUS_BEFORE_AUTH);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (opt->DataSize == sizeof(USHORT) && *((USHORT*)(opt->Data)) == Endian16(PPP_LCP_AUTH_PAP))
|
||||
else if (opt->DataSize == sizeof(USHORT) && *((USHORT *)(opt->Data)) == Endian16(PPP_LCP_AUTH_PAP))
|
||||
{
|
||||
// We couldn't agree on auth proto, failing connection
|
||||
if (!isAccepted)
|
||||
{
|
||||
UINT64 offer = 0;
|
||||
Copy(&offer, t->Data, t->DataSize > sizeof(UINT64) ? sizeof(UINT64) : t->DataSize);
|
||||
Debug("NACK proto with code = 0x%x, cypher = 0x%x, offered cypher = 0x%x\n", pp->Lcp->Code, *((USHORT*)(opt->Data)), offer);
|
||||
Debug("NACK proto with code = 0x%x, cypher = 0x%x, offered cypher = 0x%x\n", pp->Lcp->Code, *((USHORT *)(opt->Data)), offer);
|
||||
Debug("Couldn't agree on auth protocol!\n");
|
||||
PPPLog(p, "LP_PAP_MSCHAPV2_REJECTED");
|
||||
PPPSetStatus(p, PPP_STATUS_FAIL);
|
||||
@ -994,7 +1037,7 @@ bool PPPProcessCHAPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *re
|
||||
BinToStr(hex, sizeof(hex), p->MsChapV2_ServerResponse, 20);
|
||||
|
||||
Format(ret_str, sizeof(ret_str),
|
||||
"S=%s", hex);
|
||||
"S=%s", hex);
|
||||
|
||||
WriteBuf(lcp_ret_data, ret_str, StrLen(ret_str));
|
||||
|
||||
@ -1032,7 +1075,7 @@ bool PPPProcessCHAPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *re
|
||||
BinToStr(hex, sizeof(hex), p->MsChapV2_ServerChallenge, 16);
|
||||
|
||||
Format(ret_str, sizeof(ret_str),
|
||||
"E=%u R=0 C=%s V=3", p->MsChapV2_ErrorCode, hex);
|
||||
"E=%u R=0 C=%s V=3", p->MsChapV2_ErrorCode, hex);
|
||||
|
||||
WriteBuf(lcp_ret_data, ret_str, StrLen(ret_str));
|
||||
|
||||
@ -1082,28 +1125,28 @@ bool PPPProcessIPCPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *re
|
||||
if (!PPPGetIPAddressValueFromLCP(pp->Lcp, PPP_IPCP_OPTION_IP, &addrStruct) || pp->Lcp->Code == PPP_LCP_CODE_REJECT || pp->Lcp->Code == PPP_LCP_CODE_CODE_REJECT)
|
||||
{
|
||||
Debug("Unsupported IPCP protocol");
|
||||
p->IPv4_State = PPP_PROTO_STATUS_REJECTED;
|
||||
IPC_PROTO_SET_STATUS(p->Ipc, IPv4State, IPC_PROTO_STATUS_REJECTED);
|
||||
PPPRejectUnsupportedPacketEx(p, pp, true);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// We're dealing either with ACK or NACK
|
||||
addr = IPToUINT(&addrStruct);
|
||||
IPToStr(addrStr, MAX_SIZE, &addrStruct);
|
||||
|
||||
|
||||
if (isAccepted)
|
||||
{
|
||||
Debug("Accepted server IP address of %s\n", addrStr);
|
||||
|
||||
// We already configured client address, now server address is also confirmed, ready for IPv4 data flow
|
||||
if (p->IPv4_State == PPP_PROTO_STATUS_CONFIG)
|
||||
if (IPC_PROTO_GET_STATUS(p->Ipc, IPv4State) == IPC_PROTO_STATUS_CONFIG)
|
||||
{
|
||||
p->IPv4_State = PPP_PROTO_STATUS_CONFIG_WAIT;
|
||||
IPC_PROTO_SET_STATUS(p->Ipc, IPv4State, IPC_PROTO_STATUS_CONFIG_WAIT);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
p->IPv4_State = PPP_PROTO_STATUS_CONFIG;
|
||||
IPC_PROTO_SET_STATUS(p->Ipc, IPv4State, IPC_PROTO_STATUS_CONFIG);
|
||||
|
||||
PPPGetIPAddressValueFromLCP(req->Lcp, PPP_IPCP_OPTION_IP, &prevAddrStruct);
|
||||
prevAddr = IPToUINT(&prevAddrStruct);
|
||||
@ -1115,7 +1158,7 @@ bool PPPProcessIPCPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *re
|
||||
if (prevAddr == Endian32(0xc0000008))
|
||||
{
|
||||
Debug("We already tried the fallback IP of 192.0.0.8, giving up\n");
|
||||
p->IPv4_State = PPP_PROTO_STATUS_REJECTED;
|
||||
IPC_PROTO_SET_STATUS(p->Ipc, IPv4State, IPC_PROTO_STATUS_REJECTED);
|
||||
PPPRejectUnsupportedPacketEx(p, pp, true);
|
||||
return false;
|
||||
}
|
||||
@ -1156,7 +1199,7 @@ bool PPPProcessEAPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req
|
||||
PPPSetStatus(p, PPP_STATUS_BEFORE_AUTH);
|
||||
break;
|
||||
case PPP_EAP_TYPE_NOTIFICATION:
|
||||
// Basically this is just an acknoweldgment that the notification was accepted by the client. Nothing to do here...
|
||||
// Basically this is just an acknoweldgment that the notification was accepted by the client. Nothing to do here...
|
||||
break;
|
||||
case PPP_EAP_TYPE_NAK:
|
||||
/// TODO: implement alternative EAP protocol selection based on received NAK
|
||||
@ -1205,6 +1248,31 @@ bool PPPProcessEAPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req
|
||||
return false;
|
||||
}
|
||||
|
||||
// Process IPv6CP responses
|
||||
bool PPPProcessIPv6CPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req)
|
||||
{
|
||||
bool isAccepted = !PPP_LCP_CODE_IS_NEGATIVE(pp->Lcp->Code);
|
||||
|
||||
// If we got a reject or a NACK, we just reject the whole IPv6 configuration, there is no way we can recover even from a NACK as we can't change the link-local address of an already existing router
|
||||
if (!isAccepted)
|
||||
{
|
||||
Debug("Unsupported IPv6CP protocol");
|
||||
IPC_PROTO_SET_STATUS(p->Ipc, IPv6State, IPC_PROTO_STATUS_REJECTED);
|
||||
PPPRejectUnsupportedPacketEx(p, pp, true);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IPC_PROTO_GET_STATUS(p->Ipc, IPv6State) != IPC_PROTO_STATUS_CONFIG)
|
||||
{
|
||||
Debug("We got an early IPv6CP response, ignoring for now...\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
Debug("Accepted server IPv6CP handshake\n");
|
||||
IPC_PROTO_SET_STATUS(p->Ipc, IPv6State, IPC_PROTO_STATUS_CONFIG_WAIT);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Processes request packets
|
||||
bool PPPProcessRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
@ -1227,8 +1295,7 @@ bool PPPProcessRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
return PPPProcessIPCPRequestPacket(p, pp);
|
||||
break;
|
||||
case PPP_PROTOCOL_IPV6CP:
|
||||
PPPRejectUnsupportedPacketEx(p, pp, true);
|
||||
Debug("IPv6CP to be implemented\n");
|
||||
return PPPProcessIPv6CPRequestPacket(p, pp);
|
||||
break;
|
||||
case PPP_PROTOCOL_EAP:
|
||||
return PPPProcessEAPRequestPacket(p, pp);
|
||||
@ -1265,12 +1332,12 @@ bool PPPProcessLCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
{
|
||||
case PPP_LCP_OPTION_AUTH:
|
||||
t->IsSupported = true;
|
||||
if (t->DataSize == sizeof(USHORT) && *((USHORT*)t->Data) == PPP_LCP_AUTH_EAP && p->AuthProtocol == PPP_UNSPECIFIED)
|
||||
if (t->DataSize == sizeof(USHORT) && *((USHORT *)t->Data) == PPP_LCP_AUTH_EAP && p->AuthProtocol == PPP_UNSPECIFIED)
|
||||
{
|
||||
t->IsAccepted = true;
|
||||
NegotiatedAuthProto = PPP_PROTOCOL_EAP;
|
||||
}
|
||||
else if (t->DataSize == sizeof(USHORT) && *((USHORT*)t->Data) == PPP_LCP_AUTH_PAP && p->AuthProtocol == PPP_UNSPECIFIED)
|
||||
else if (t->DataSize == sizeof(USHORT) && *((USHORT *)t->Data) == PPP_LCP_AUTH_PAP && p->AuthProtocol == PPP_UNSPECIFIED)
|
||||
{
|
||||
t->IsAccepted = true;
|
||||
NegotiatedAuthProto = PPP_PROTOCOL_PAP;
|
||||
@ -1338,7 +1405,7 @@ bool PPPProcessLCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (NegotiatedAuthProto != PPP_UNSPECIFIED)
|
||||
{
|
||||
if (p->AuthProtocol == PPP_UNSPECIFIED)
|
||||
@ -1346,7 +1413,7 @@ bool PPPProcessLCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
p->AuthProtocol = NegotiatedAuthProto;
|
||||
PPPSetStatus(p, PPP_STATUS_BEFORE_AUTH);
|
||||
Debug("Setting BEFORE_AUTH from REQ on LCP request parse\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (NegotiatedMRU != PPP_UNSPECIFIED)
|
||||
{
|
||||
@ -1362,9 +1429,9 @@ bool PPPProcessPAPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
{
|
||||
PPP_LCP *lcp = NewPPPLCP(PPP_PAP_CODE_NAK, pp->Lcp->Id);
|
||||
PPP_PACKET *ret = ZeroMalloc(sizeof(PPP_PACKET));
|
||||
|
||||
|
||||
Debug("Got a PAP request before we're ready for AUTH procedure!\n");
|
||||
|
||||
|
||||
ret->IsControl = true;
|
||||
ret->Protocol = PPP_PROTOCOL_PAP;
|
||||
ret->Lcp = lcp;
|
||||
@ -1453,9 +1520,9 @@ bool PPPProcessPAPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
UINT error_code;
|
||||
|
||||
ipc = NewIPC(p->Cedar, p->ClientSoftwareName, p->Postfix, hub, id, password,
|
||||
&error_code, &p->ClientIP, p->ClientPort, &p->ServerIP, p->ServerPort,
|
||||
p->ClientHostname, p->CryptName, false, p->AdjustMss, NULL, NULL,
|
||||
IPC_LAYER_3);
|
||||
&error_code, &p->ClientIP, p->ClientPort, &p->ServerIP, p->ServerPort,
|
||||
p->ClientHostname, p->CryptName, false, p->AdjustMss, NULL, NULL,
|
||||
IPC_LAYER_3);
|
||||
|
||||
if (ipc != NULL)
|
||||
{
|
||||
@ -1547,9 +1614,8 @@ bool PPPProcessIPCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
bool ok = true;
|
||||
bool processed = false;
|
||||
bool isEmptyIpAddress = false;
|
||||
PPP_LCP *c;
|
||||
|
||||
if (p->IPv4_State == PPP_PROTO_STATUS_REJECTED)
|
||||
if (IPC_PROTO_GET_STATUS(p->Ipc, IPv4State) == IPC_PROTO_STATUS_REJECTED)
|
||||
{
|
||||
Debug("We got an IPCP packet after we had it rejected\n");
|
||||
return PPPRejectUnsupportedPacketEx(p, pp, true);
|
||||
@ -1637,9 +1703,9 @@ bool PPPProcessIPCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
IPToStr32(wins2_str, sizeof(wins2_str), cao.WinsServer2);
|
||||
|
||||
PPPLog(p, "LP_DHCP_INFORM_OK",
|
||||
subnet_str, defgw_str, cao.DomainName,
|
||||
dns1_str, dns2_str, wins1_str, wins2_str,
|
||||
server_ip_str);
|
||||
subnet_str, defgw_str, cao.DomainName,
|
||||
dns1_str, dns2_str, wins1_str, wins2_str,
|
||||
server_ip_str);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1690,8 +1756,8 @@ bool PPPProcessIPCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
t = 1;
|
||||
}
|
||||
|
||||
p->DhcpRenewInterval = (UINT64)t * (UINT64)1000;
|
||||
p->DhcpNextRenewTime = Tick64() + p->DhcpRenewInterval;
|
||||
p->DhcpRenewInterval = (UINT64)t * (UINT64)1000;
|
||||
p->DhcpNextRenewTime = Tick64() + p->DhcpRenewInterval;
|
||||
|
||||
if (true)
|
||||
{
|
||||
@ -1710,9 +1776,9 @@ bool PPPProcessIPCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
IPToStr32(wins2_str, sizeof(wins2_str), cao.WinsServer2);
|
||||
|
||||
PPPLog(p, "LP_DHCP_REQUEST_OK",
|
||||
client_ip_str, subnet_str, defgw_str, cao.DomainName,
|
||||
dns1_str, dns2_str, wins1_str, wins2_str,
|
||||
server_ip_str, cao.LeaseTime);
|
||||
client_ip_str, subnet_str, defgw_str, cao.DomainName,
|
||||
dns1_str, dns2_str, wins1_str, wins2_str,
|
||||
server_ip_str, cao.LeaseTime);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1728,7 +1794,7 @@ bool PPPProcessIPCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
|
||||
// If we already have a configured IP data - send it along
|
||||
if (IsValidUnicastIPAddressUINT4(p->ClientAddressOption.ClientAddress) &&
|
||||
p->ClientAddressOption.SubnetMask != 0 && ok)
|
||||
p->ClientAddressOption.SubnetMask != 0 && ok)
|
||||
{
|
||||
// Success to determine the address
|
||||
UINTToIP(&subnet, p->ClientAddressOption.SubnetMask);
|
||||
@ -1760,7 +1826,7 @@ bool PPPProcessIPCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
IPToStr(wins2_str, sizeof(wins2_str), &res.WinsServer2);
|
||||
|
||||
PPPLog(p, "LP_SET_IPV4_PARAM", client_ip_str, subnet_str,
|
||||
defgw_str, dns1_str, dns2_str, wins1_str, wins2_str);
|
||||
defgw_str, dns1_str, dns2_str, wins1_str, wins2_str);
|
||||
}
|
||||
|
||||
/*// Backporting static configuration received from client - let him use whatever he wants,
|
||||
@ -1808,7 +1874,7 @@ bool PPPProcessIPCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
|
||||
PPPSetIPOptionToLCP(&res, pp->Lcp, true);
|
||||
}
|
||||
|
||||
|
||||
if (PPPRejectLCPOptionsEx(p, pp, processed))
|
||||
{
|
||||
Debug("Rejected IPCP options ID = 0x%x\n", pp->Lcp->Id);
|
||||
@ -1823,7 +1889,7 @@ bool PPPProcessIPCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
|
||||
// We will delay this packet ACK and send the server IP first, then wait for a reparse
|
||||
// it is kind of dirty but fixes issues on some clients (namely VPN Client Pro on Android)
|
||||
if (p->IPv4_State == PPP_PROTO_STATUS_CLOSED && p->ClientAddressOption.ServerAddress != 0 && ok)
|
||||
if (IPC_PROTO_GET_STATUS(p->Ipc, IPv4State) == IPC_PROTO_STATUS_CLOSED && p->ClientAddressOption.ServerAddress != 0 && ok)
|
||||
{
|
||||
PPP_LCP *c = NewPPPLCP(PPP_LCP_CODE_REQ, 0);
|
||||
UINT ui = p->ClientAddressOption.ServerAddress;
|
||||
@ -1834,7 +1900,7 @@ bool PPPProcessIPCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
WHERE;
|
||||
return false;
|
||||
}
|
||||
p->IPv4_State = PPP_PROTO_STATUS_CONFIG;
|
||||
IPC_PROTO_SET_STATUS(p->Ipc, IPv4State, IPC_PROTO_STATUS_CONFIG);
|
||||
if (!processed)
|
||||
{
|
||||
PPPAddNextPacket(p, pp, 1);
|
||||
@ -1843,7 +1909,8 @@ bool PPPProcessIPCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
}
|
||||
|
||||
// We still haven't received any answer from client about server IP, keep waiting...
|
||||
if ((p->IPv4_State == PPP_PROTO_STATUS_CONFIG || p->IPv4_State == PPP_PROTO_STATUS_CLOSED) && !processed)
|
||||
if ((IPC_PROTO_GET_STATUS(p->Ipc, IPv4State) == IPC_PROTO_STATUS_CONFIG ||
|
||||
IPC_PROTO_GET_STATUS(p->Ipc, IPv4State) == IPC_PROTO_STATUS_CLOSED) && !processed)
|
||||
{
|
||||
PPPAddNextPacket(p, pp, 1);
|
||||
return false;
|
||||
@ -1856,9 +1923,9 @@ bool PPPProcessIPCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
}
|
||||
Debug("ACKed IPCP options ID = 0x%x\n", pp->Lcp->Id);
|
||||
|
||||
if (ok && p->IPv4_State == PPP_PROTO_STATUS_CONFIG_WAIT)
|
||||
if (ok && IPC_PROTO_GET_STATUS(p->Ipc, IPv4State) == IPC_PROTO_STATUS_CONFIG_WAIT)
|
||||
{
|
||||
p->IPv4_State = PPP_PROTO_STATUS_OPENED;
|
||||
IPC_PROTO_SET_STATUS(p->Ipc, IPv4State, IPC_PROTO_STATUS_OPENED);
|
||||
Debug("IPv4 OPENED\n");
|
||||
}
|
||||
return ok;
|
||||
@ -1871,6 +1938,116 @@ bool PPPProcessEAPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Process IPv6CP request packets
|
||||
bool PPPProcessIPv6CPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
{
|
||||
UINT i;
|
||||
bool processed = false;
|
||||
if (IPC_PROTO_GET_STATUS(p->Ipc, IPv6State) == IPC_PROTO_STATUS_REJECTED)
|
||||
{
|
||||
Debug("We got an IPv6CP packet after we had it rejected\n");
|
||||
return PPPRejectUnsupportedPacketEx(p, pp, true);
|
||||
}
|
||||
|
||||
for (i = 0; i < LIST_NUM(pp->Lcp->OptionList); i++)
|
||||
{
|
||||
PPP_OPTION *t = LIST_DATA(pp->Lcp->OptionList, i);
|
||||
|
||||
switch (t->Type)
|
||||
{
|
||||
case PPP_IPV6CP_OPTION_EUI:
|
||||
t->IsSupported = true;
|
||||
if (t->DataSize == sizeof(UINT64))
|
||||
{
|
||||
UINT64 newValue = 0;
|
||||
UINT64 value = READ_UINT64(t->Data);
|
||||
if (value != 0 && !IPCIPv6CheckExistingLinkLocal(p->Ipc, value))
|
||||
{
|
||||
t->IsAccepted = true;
|
||||
p->Ipc->IPv6ClientEUI = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
t->IsAccepted = false;
|
||||
GenerateEui64Address6((UCHAR *)&newValue, p->Ipc->MacAddress);
|
||||
if (newValue != value && !IPCIPv6CheckExistingLinkLocal(p->Ipc, newValue))
|
||||
{
|
||||
WRITE_UINT64(t->AltData, newValue);
|
||||
t->AltDataSize = sizeof(UINT64);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
newValue = Rand64();
|
||||
if (!IPCIPv6CheckExistingLinkLocal(p->Ipc, newValue))
|
||||
{
|
||||
WRITE_UINT64(t->AltData, newValue);
|
||||
t->AltDataSize = sizeof(UINT64);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
t->IsSupported = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (PPPRejectLCPOptionsEx(p, pp, processed))
|
||||
{
|
||||
Debug("Rejected IPv6CP options ID = 0x%x\n", pp->Lcp->Id);
|
||||
processed = true;
|
||||
}
|
||||
|
||||
if (PPPNackLCPOptionsEx(p, pp, processed))
|
||||
{
|
||||
Debug("NACKed IPv6CP options ID = 0x%x\n", pp->Lcp->Id);
|
||||
processed = true;
|
||||
}
|
||||
|
||||
if (p->Ipc->IPv6ClientEUI != 0 && IPC_PROTO_GET_STATUS(p->Ipc, IPv6State) == IPC_PROTO_STATUS_CLOSED)
|
||||
{
|
||||
PPP_LCP *c = NewPPPLCP(PPP_LCP_CODE_REQ, 0);
|
||||
UINT64 serverEui = IPCIPv6GetServerEui(p->Ipc);
|
||||
if (serverEui != 0 && serverEui != p->Ipc->IPv6ClientEUI)
|
||||
{
|
||||
Add(c->OptionList, NewPPPOption(PPP_IPV6CP_OPTION_EUI, &serverEui, sizeof(UINT64)));
|
||||
}
|
||||
if (!PPPSendAndRetransmitRequest(p, PPP_PROTOCOL_IPV6CP, c))
|
||||
{
|
||||
PPPSetStatus(p, PPP_STATUS_FAIL);
|
||||
WHERE;
|
||||
return false;
|
||||
}
|
||||
|
||||
IPC_PROTO_SET_STATUS(p->Ipc, IPv6State, IPC_PROTO_STATUS_CONFIG);
|
||||
}
|
||||
|
||||
if (IPC_PROTO_GET_STATUS(p->Ipc, IPv6State) == IPC_PROTO_STATUS_CONFIG && !processed)
|
||||
{
|
||||
PPPAddNextPacket(p, pp, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!PPPAckLCPOptionsEx(p, pp, processed))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Debug("ACKed IPv6CP options ID = 0x%x\n", pp->Lcp->Id);
|
||||
|
||||
if (IPC_PROTO_GET_STATUS(p->Ipc, IPv6State) == IPC_PROTO_STATUS_CONFIG_WAIT)
|
||||
{
|
||||
IPC_PROTO_SET_STATUS(p->Ipc, IPv6State, IPC_PROTO_STATUS_OPENED);
|
||||
Debug("IPv6 OPENED\n");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// LCP option based packets utility
|
||||
bool PPPRejectLCPOptions(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
{
|
||||
@ -2128,7 +2305,7 @@ LABEL_LOOP:
|
||||
|
||||
if (async == false)
|
||||
{
|
||||
d = TubeRecvSync(p->TubeRecv, p->PacketRecvTimeout);
|
||||
d = TubeRecvSync(p->TubeRecv, (UINT)p->PacketRecvTimeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2186,7 +2363,7 @@ PPP_PACKET *PPPGetNextPacket(PPP_SESSION *p)
|
||||
}
|
||||
|
||||
ret = PPPRecvPacket(p, true);
|
||||
|
||||
|
||||
if (ret != NULL && ret->IsControl && ret->Lcp != NULL)
|
||||
{
|
||||
PPP_DELAYED_PACKET *firstRelated = NULL;
|
||||
@ -2241,7 +2418,6 @@ PPP_PACKET *PPPGetNextPacket(PPP_SESSION *p)
|
||||
void PPPAddNextPacket(PPP_SESSION *p, PPP_PACKET *pp, UINT delay)
|
||||
{
|
||||
PPP_DELAYED_PACKET *t = ZeroMalloc(sizeof(PPP_DELAYED_PACKET));
|
||||
UINT i;
|
||||
if (p->CurrentPacket == pp)
|
||||
{
|
||||
p->CurrentPacket = NULL;
|
||||
@ -2262,7 +2438,7 @@ void PPPAddNextPacket(PPP_SESSION *p, PPP_PACKET *pp, UINT delay)
|
||||
Debug("after sorting delayeds end\n");*/
|
||||
}
|
||||
|
||||
int PPPDelayedPacketsComparator(const void *a, const void *b)
|
||||
int PPPDelayedPacketsComparator(void *a, void *b)
|
||||
{
|
||||
PPP_DELAYED_PACKET *first = a;
|
||||
PPP_DELAYED_PACKET *second = b;
|
||||
@ -2308,10 +2484,10 @@ int PPPDelayedPacketsComparator(const void *a, const void *b)
|
||||
char PPPRelatedPacketComparator(PPP_PACKET *a, PPP_PACKET *b)
|
||||
{
|
||||
if (a->IsControl && b->IsControl &&
|
||||
a->Lcp != NULL && b->Lcp != NULL &&
|
||||
a->Protocol == b->Protocol &&
|
||||
PPP_CODE_IS_REQUEST(a->Protocol, a->Lcp->Code) == PPP_CODE_IS_REQUEST(b->Protocol, b->Lcp->Code) &&
|
||||
PPP_CODE_IS_RESPONSE(a->Protocol, a->Lcp->Code) == PPP_CODE_IS_RESPONSE(b->Protocol, b->Lcp->Code))
|
||||
a->Lcp != NULL && b->Lcp != NULL &&
|
||||
a->Protocol == b->Protocol &&
|
||||
PPP_CODE_IS_REQUEST(a->Protocol, a->Lcp->Code) == PPP_CODE_IS_REQUEST(b->Protocol, b->Lcp->Code) &&
|
||||
PPP_CODE_IS_RESPONSE(a->Protocol, a->Lcp->Code) == PPP_CODE_IS_RESPONSE(b->Protocol, b->Lcp->Code))
|
||||
{
|
||||
// The packet is related!
|
||||
if (a->Lcp->Id < b->Lcp->Id)
|
||||
@ -2636,21 +2812,21 @@ bool PPPParseMSCHAP2ResponsePacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
|
||||
// Convert the MS-CHAPv2 data to a password string
|
||||
BinToStr(server_challenge_hex, sizeof(server_challenge_hex),
|
||||
p->MsChapV2_ServerChallenge, sizeof(p->MsChapV2_ServerChallenge));
|
||||
p->MsChapV2_ServerChallenge, sizeof(p->MsChapV2_ServerChallenge));
|
||||
BinToStr(client_challenge_hex, sizeof(client_challenge_hex),
|
||||
p->MsChapV2_ClientChallenge, sizeof(p->MsChapV2_ClientChallenge));
|
||||
p->MsChapV2_ClientChallenge, sizeof(p->MsChapV2_ClientChallenge));
|
||||
BinToStr(client_response_hex, sizeof(client_response_hex),
|
||||
p->MsChapV2_ClientResponse, sizeof(p->MsChapV2_ClientResponse));
|
||||
p->MsChapV2_ClientResponse, sizeof(p->MsChapV2_ClientResponse));
|
||||
BinToStr(eap_client_hex, sizeof(eap_client_hex),
|
||||
&eap_client_ptr, 8);
|
||||
&eap_client_ptr, 8);
|
||||
|
||||
Format(password, sizeof(password), "%s%s:%s:%s:%s:%s",
|
||||
IPC_PASSWORD_MSCHAPV2_TAG,
|
||||
username_tmp,
|
||||
server_challenge_hex,
|
||||
client_challenge_hex,
|
||||
client_response_hex,
|
||||
eap_client_hex);
|
||||
IPC_PASSWORD_MSCHAPV2_TAG,
|
||||
username_tmp,
|
||||
server_challenge_hex,
|
||||
client_challenge_hex,
|
||||
client_response_hex,
|
||||
eap_client_hex);
|
||||
|
||||
if (p->MsChapV2_UseDoubleMsChapV2 && p->EapClient == NULL)
|
||||
{
|
||||
@ -2673,9 +2849,9 @@ bool PPPParseMSCHAP2ResponsePacket(PPP_SESSION *p, PPP_PACKET *pp)
|
||||
{
|
||||
Debug("MSCHAPv2 creating IPC\n");
|
||||
ipc = NewIPC(p->Cedar, p->ClientSoftwareName, p->Postfix, hub, id, password,
|
||||
&error_code, &p->ClientIP, p->ClientPort, &p->ServerIP, p->ServerPort,
|
||||
p->ClientHostname, p->CryptName, false, p->AdjustMss, p->EapClient, NULL,
|
||||
+ IPC_LAYER_3);
|
||||
&error_code, &p->ClientIP, p->ClientPort, &p->ServerIP, p->ServerPort,
|
||||
p->ClientHostname, p->CryptName, false, p->AdjustMss, p->EapClient, NULL,
|
||||
+ IPC_LAYER_3);
|
||||
|
||||
if (ipc != NULL)
|
||||
{
|
||||
@ -2953,7 +3129,7 @@ bool PPPSetIPAddressValueToLCP(PPP_LCP *c, UINT type, IP *ip, bool only_modify)
|
||||
{
|
||||
PPP_OPTION *opt2 = NewPPPOption(type, &ui, 4);
|
||||
UCHAR ipstr[MAX_SIZE];
|
||||
|
||||
|
||||
opt2->IsAccepted = true;
|
||||
opt2->IsSupported = true;
|
||||
Copy(opt2->AltData, opt2->Data, opt2->DataSize);
|
||||
@ -3009,12 +3185,11 @@ bool PPPProcessEAPTlsResponse(PPP_SESSION *p, PPP_EAP *eap_packet, UINT eapTlsSi
|
||||
UCHAR *dataBuffer;
|
||||
UINT dataSize;
|
||||
UINT tlsLength = 0;
|
||||
UINT i;
|
||||
bool isFragmented = false;
|
||||
PPP_LCP *lcp;
|
||||
PPP_EAP *eap;
|
||||
UCHAR flags = PPP_EAP_TLS_FLAG_NONE;
|
||||
UINT64 sizeLeft = 0;
|
||||
UINT sizeLeft = 0;
|
||||
Debug("Got EAP-TLS size=%i\n", eapTlsSize);
|
||||
if (eapTlsSize == 1)
|
||||
{
|
||||
@ -3024,7 +3199,7 @@ bool PPPProcessEAPTlsResponse(PPP_SESSION *p, PPP_EAP *eap_packet, UINT eapTlsSi
|
||||
// We got an ACK to transmit the next fragmented message
|
||||
dataSize = p->Mru1 - 8 - 1 - 1; // Calculating the maximum payload size (without TlsLength)
|
||||
sizeLeft = GetMemSize(p->Eap_TlsCtx.CachedBufferSend);
|
||||
sizeLeft -= p->Eap_TlsCtx.CachedBufferSendPntr - p->Eap_TlsCtx.CachedBufferSend;
|
||||
sizeLeft -= (UINT)(p->Eap_TlsCtx.CachedBufferSendPntr - p->Eap_TlsCtx.CachedBufferSend);
|
||||
|
||||
flags = PPP_EAP_TLS_FLAG_FRAGMENTED; // M flag
|
||||
if (dataSize > sizeLeft)
|
||||
@ -3035,7 +3210,7 @@ bool PPPProcessEAPTlsResponse(PPP_SESSION *p, PPP_EAP *eap_packet, UINT eapTlsSi
|
||||
lcp = BuildEAPTlsRequest(p->Eap_PacketId++, dataSize, flags);
|
||||
eap = lcp->Data;
|
||||
Copy(eap->Tls.TlsDataWithoutLength, p->Eap_TlsCtx.CachedBufferSendPntr, dataSize);
|
||||
p->Eap_TlsCtx.CachedBufferSendPntr += dataSize;
|
||||
p->Eap_TlsCtx.CachedBufferSendPntr += (UINT64)dataSize;
|
||||
|
||||
if (!PPPSendAndRetransmitRequest(p, PPP_PROTOCOL_EAP, lcp))
|
||||
{
|
||||
@ -3082,9 +3257,9 @@ bool PPPProcessEAPTlsResponse(PPP_SESSION *p, PPP_EAP *eap_packet, UINT eapTlsSi
|
||||
PPPParseUsername(p->Cedar, p->Eap_Identity, &d);
|
||||
|
||||
ipc = NewIPC(p->Cedar, p->ClientSoftwareName, p->Postfix, d.HubName, d.UserName, "",
|
||||
&error_code, &p->ClientIP, p->ClientPort, &p->ServerIP, p->ServerPort,
|
||||
p->ClientHostname, p->CryptName, false, p->AdjustMss, NULL, p->Eap_TlsCtx.ClientCert.X,
|
||||
IPC_LAYER_3);
|
||||
&error_code, &p->ClientIP, p->ClientPort, &p->ServerIP, p->ServerPort,
|
||||
p->ClientHostname, p->CryptName, false, p->AdjustMss, NULL, p->Eap_TlsCtx.ClientCert.X,
|
||||
IPC_LAYER_3);
|
||||
|
||||
if (ipc != NULL)
|
||||
{
|
||||
@ -3192,7 +3367,7 @@ bool PPPProcessEAPTlsResponse(PPP_SESSION *p, PPP_EAP *eap_packet, UINT eapTlsSi
|
||||
p->Eap_TlsCtx.CachedBufferRecvPntr = p->Eap_TlsCtx.CachedBufferRecv;
|
||||
}
|
||||
sizeLeft = GetMemSize(p->Eap_TlsCtx.CachedBufferRecv);
|
||||
sizeLeft -= p->Eap_TlsCtx.CachedBufferRecvPntr - p->Eap_TlsCtx.CachedBufferRecv;
|
||||
sizeLeft -= (UINT)(p->Eap_TlsCtx.CachedBufferRecvPntr - p->Eap_TlsCtx.CachedBufferRecv);
|
||||
|
||||
Copy(p->Eap_TlsCtx.CachedBufferRecvPntr, dataBuffer, MIN(sizeLeft, dataSize));
|
||||
|
||||
@ -3206,7 +3381,7 @@ bool PPPProcessEAPTlsResponse(PPP_SESSION *p, PPP_EAP *eap_packet, UINT eapTlsSi
|
||||
dataSize = GetMemSize(p->Eap_TlsCtx.CachedBufferRecv);
|
||||
if (dataSize == MAX_BUFFERING_PACKET_SIZE)
|
||||
{
|
||||
dataSize = p->Eap_TlsCtx.CachedBufferRecvPntr - p->Eap_TlsCtx.CachedBufferRecv;
|
||||
dataSize = (UINT)(p->Eap_TlsCtx.CachedBufferRecvPntr - p->Eap_TlsCtx.CachedBufferRecv);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3415,7 +3590,7 @@ void FreePPPSession(PPP_SESSION *p)
|
||||
|
||||
Free(t);
|
||||
}
|
||||
|
||||
|
||||
ReleaseList(p->SentReqPacketList);
|
||||
|
||||
for (i = 0; i < LIST_NUM(p->DelayedPackets); i++)
|
||||
@ -3425,7 +3600,7 @@ void FreePPPSession(PPP_SESSION *p)
|
||||
|
||||
Free(t);
|
||||
}
|
||||
|
||||
|
||||
ReleaseList(p->DelayedPackets);
|
||||
|
||||
if (p->CurrentPacket != NULL)
|
||||
@ -3684,7 +3859,7 @@ void GenerateNtPasswordHash(UCHAR *dst, char *password)
|
||||
|
||||
tmp = ZeroMalloc(tmp_size);
|
||||
|
||||
for (i = 0;i < len;i++)
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
tmp[i * 2] = password[i];
|
||||
}
|
||||
@ -3852,7 +4027,7 @@ char *MsChapV2DoBruteForce(IPC_MSCHAP_V2_AUTHINFO *d, LIST *password_list)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0;i < LIST_NUM(password_list);i++)
|
||||
for (i = 0; i < LIST_NUM(password_list); i++)
|
||||
{
|
||||
char *s = LIST_DATA(password_list, i);
|
||||
char tmp[MAX_SIZE];
|
||||
@ -3864,7 +4039,7 @@ char *MsChapV2DoBruteForce(IPC_MSCHAP_V2_AUTHINFO *d, LIST *password_list)
|
||||
len = StrLen(tmp);
|
||||
max = Power(2, MIN(len, 9));
|
||||
|
||||
for (j = 0;j < max;j++)
|
||||
for (j = 0; j < max; j++)
|
||||
{
|
||||
SetStrCaseAccordingToBits(tmp, j);
|
||||
if (MsChapV2VerityPassword(d, tmp))
|
||||
|
@ -95,7 +95,7 @@
|
||||
#define PPP_IPCP_OPTION_WINS2 132
|
||||
|
||||
// IPV6CP option type
|
||||
#define PPP_IPV6CP_OPTION_IID 1
|
||||
#define PPP_IPV6CP_OPTION_EUI 1
|
||||
|
||||
// EAP codes
|
||||
#define PPP_EAP_CODE_REQUEST 1
|
||||
@ -135,13 +135,6 @@
|
||||
#define PPP_STATUS_FAIL 0x1000
|
||||
#define PPP_STATUS_AUTH_FAIL 0x1010
|
||||
|
||||
// Protocol status
|
||||
#define PPP_PROTO_STATUS_CLOSED 0x0
|
||||
#define PPP_PROTO_STATUS_CONFIG 0x1
|
||||
#define PPP_PROTO_STATUS_CONFIG_WAIT 0x2
|
||||
#define PPP_PROTO_STATUS_OPENED 0x10
|
||||
#define PPP_PROTO_STATUS_REJECTED 0x100
|
||||
|
||||
#define PPP_UNSPECIFIED 0xFFFF
|
||||
|
||||
//// Type
|
||||
@ -301,8 +294,6 @@ struct PPP_SESSION
|
||||
UCHAR ClientInterfaceId[8]; // Client IPv6CP Interface Identifier
|
||||
|
||||
UINT PPPStatus;
|
||||
UINT IPv4_State;
|
||||
UINT IPv6_State;
|
||||
|
||||
// EAP contexts
|
||||
UINT Eap_Protocol; // Current EAP Protocol used
|
||||
@ -311,7 +302,7 @@ struct PPP_SESSION
|
||||
PPP_EAP_TLS_CONTEXT Eap_TlsCtx; // Context information for EAP TLS. May be possibly reused for EAP TTLS?
|
||||
|
||||
LIST *SentReqPacketList; // Sent requests list
|
||||
|
||||
|
||||
PPP_PACKET *CurrentPacket;
|
||||
LIST *DelayedPackets;
|
||||
|
||||
@ -344,12 +335,14 @@ bool PPPProcessLCPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req
|
||||
bool PPPProcessCHAPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req);
|
||||
bool PPPProcessIPCPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req);
|
||||
bool PPPProcessEAPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req);
|
||||
bool PPPProcessIPv6CPResponsePacket(PPP_SESSION *p, PPP_PACKET *pp, PPP_PACKET *req);
|
||||
// Request packets
|
||||
bool PPPProcessRequestPacket(PPP_SESSION *p, PPP_PACKET *pp);
|
||||
bool PPPProcessLCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp);
|
||||
bool PPPProcessPAPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp);
|
||||
bool PPPProcessIPCPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp);
|
||||
bool PPPProcessEAPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp);
|
||||
bool PPPProcessIPv6CPRequestPacket(PPP_SESSION *p, PPP_PACKET *pp);
|
||||
|
||||
// LCP option based packets utility
|
||||
bool PPPRejectLCPOptions(PPP_SESSION *p, PPP_PACKET *pp);
|
||||
@ -369,7 +362,7 @@ PPP_PACKET *PPPRecvPacket(PPP_SESSION *p, bool async);
|
||||
// Helpers for delaying packets
|
||||
PPP_PACKET *PPPGetNextPacket(PPP_SESSION *p);
|
||||
void PPPAddNextPacket(PPP_SESSION *p, PPP_PACKET *pp, UINT delay);
|
||||
int PPPDelayedPacketsComparator(const void *a, const void *b);
|
||||
int PPPDelayedPacketsComparator(void *a, void *b);
|
||||
char PPPRelatedPacketComparator(PPP_PACKET *a, PPP_PACKET *b);
|
||||
|
||||
// PPP utility functions
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -409,8 +409,6 @@ ARP_ENTRY *SearchArpTable(VH *v, UINT ip);
|
||||
void RefreshArpTable(VH *v);
|
||||
void PollingArpTable(VH *v);
|
||||
void InsertArpTable(VH *v, UCHAR *mac, UINT ip);
|
||||
bool IsMacBroadcast(UCHAR *mac);
|
||||
bool IsMacInvalid(UCHAR *mac);
|
||||
void InitArpWaitTable(VH *v);
|
||||
void FreeArpWaitTable(VH *v);
|
||||
int CompareArpWaitTable(void *p1, void *p2);
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -357,7 +357,7 @@ typedef struct SOCKLIST
|
||||
|
||||
|
||||
// Parameters for timeout thread for Solaris
|
||||
typedef struct SOCKET_TIMEOUT_PARAM{
|
||||
typedef struct SOCKET_TIMEOUT_PARAM {
|
||||
SOCK *sock;
|
||||
CANCEL *cancel;
|
||||
THREAD *thread;
|
||||
@ -651,7 +651,7 @@ struct RUDP_SESSION
|
||||
UINT64 Magic_Disconnect; // Disconnection Signal
|
||||
UINT64 NextSendSeqNo; // Transmission sequence number to be used next
|
||||
UINT64 LastRecvCompleteSeqNo; // Sequence number of receiving complete
|
||||
// (This indicates all segments which have sequence number up to this number are received completely)
|
||||
// (This indicates all segments which have sequence number up to this number are received completely)
|
||||
UCHAR NextIv[SHA1_SIZE]; // IV value to be used next
|
||||
UINT NextKeepAliveInterval; // Interval value of KeepAlive to be used next
|
||||
FIFO *RecvFifo; // Reception FIFO
|
||||
@ -846,7 +846,7 @@ struct CONNECT_TCP_RUDP_PARAM
|
||||
|
||||
#define SSL_DEFAULT_CONNECT_TIMEOUT (15 * 1000) // SSL default timeout
|
||||
|
||||
// Header for TCP Pair
|
||||
// Header for TCP Pair
|
||||
struct TCP_PAIR_HEADER
|
||||
{
|
||||
bool EnableHMac;
|
||||
@ -949,7 +949,7 @@ UINT64 RUDPGetCurrentSendingMinSeqNo(RUDP_SESSION *se);
|
||||
UINT64 RUDPGetCurrentSendingMaxSeqNo(RUDP_SESSION *se);
|
||||
SOCK *ListenRUDP(char *svc_name, RUDP_STACK_INTERRUPTS_PROC *proc_interrupts, RUDP_STACK_RPC_RECV_PROC *proc_rpc_recv, void *param, UINT port, bool no_natt_register, bool over_dns_mode);
|
||||
SOCK *ListenRUDPEx(char *svc_name, RUDP_STACK_INTERRUPTS_PROC *proc_interrupts, RUDP_STACK_RPC_RECV_PROC *proc_rpc_recv, void *param, UINT port, bool no_natt_register, bool over_dns_mode,
|
||||
volatile UINT *natt_global_udp_port, UCHAR rand_port_id, IP *listen_ip);
|
||||
volatile UINT *natt_global_udp_port, UCHAR rand_port_id, IP *listen_ip);
|
||||
SOCK *AcceptRUDP(SOCK *s);
|
||||
void *InitWaitUntilHostIPAddressChanged();
|
||||
void FreeWaitUntilHostIPAddressChanged(void *p);
|
||||
@ -1302,6 +1302,15 @@ void IPAnd4(IP *dst, IP *a, IP *b);
|
||||
bool IsInSameNetwork4(IP *a1, IP *a2, IP *subnet);
|
||||
bool IsInSameNetwork4Standard(IP *a1, IP *a2);
|
||||
|
||||
// Utility functions about IP and MAC address types
|
||||
bool IsValidUnicastIPAddress4(IP *ip);
|
||||
bool IsValidUnicastIPAddressUINT4(UINT ip);
|
||||
bool IsValidUnicastIPAddress6(IP *ip);
|
||||
bool IsMacUnicast(UCHAR *mac);
|
||||
bool IsMacBroadcast(UCHAR *mac);
|
||||
bool IsMacMulticast(UCHAR *mac);
|
||||
bool IsMacInvalid(UCHAR *mac);
|
||||
|
||||
bool ParseIpAndSubnetMask4(char *src, UINT *ip, UINT *mask);
|
||||
bool ParseIpAndSubnetMask46(char *src, IP *ip, IP *mask);
|
||||
bool ParseIpAndMask4(char *src, UINT *ip, UINT *mask);
|
||||
|
@ -84,7 +84,7 @@ ICMP_RESULT *IcmpParseResult(IP *dest_ip, USHORT src_id, USHORT src_seqno, UCHAR
|
||||
ret->Ttl = ipv4->TimeToLive;
|
||||
ret->DataSize = icmp_packet_size - (sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO));
|
||||
ret->Data = Clone(recv_buffer + ip_header_size + sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO),
|
||||
ret->DataSize);
|
||||
ret->DataSize);
|
||||
Copy(&ret->IpAddress, &ip, sizeof(IP));
|
||||
}
|
||||
}
|
||||
@ -123,7 +123,7 @@ ICMP_RESULT *IcmpParseResult(IP *dest_ip, USHORT src_id, USHORT src_seqno, UCHAR
|
||||
ret->Ttl = ipv4->TimeToLive;
|
||||
ret->DataSize = icmp_packet_size - (sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO));
|
||||
ret->Data = Clone(recv_buffer + ip_header_size + sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO),
|
||||
ret->DataSize);
|
||||
ret->DataSize);
|
||||
Copy(&ret->IpAddress, &ip, sizeof(IP));
|
||||
}
|
||||
}
|
||||
@ -540,9 +540,9 @@ bool AdjustTcpMssL3(UCHAR *src, UINT src_size, UINT mss)
|
||||
}
|
||||
|
||||
if (((tcp->Flag & TCP_SYN) == false) ||
|
||||
((tcp->Flag & TCP_RST) ||
|
||||
(tcp->Flag & TCP_PSH) ||
|
||||
(tcp->Flag & TCP_URG)))
|
||||
((tcp->Flag & TCP_RST) ||
|
||||
(tcp->Flag & TCP_PSH) ||
|
||||
(tcp->Flag & TCP_URG)))
|
||||
{
|
||||
// Not a SYN packet
|
||||
return false;
|
||||
@ -591,7 +591,7 @@ bool AdjustTcpMssL3(UCHAR *src, UINT src_size, UINT mss)
|
||||
{
|
||||
// Calculate the TCPv6 checksum
|
||||
tcp->Checksum = CalcChecksumForIPv6(&ip6->SrcAddress, &ip6->DestAddress,
|
||||
IP_PROTO_TCP, tcp, tcp_size, 0);
|
||||
IP_PROTO_TCP, tcp, tcp_size, 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -736,7 +736,7 @@ void VLanInsertTag(void **packet_data, UINT *packet_size, UINT vlan_id, UINT vla
|
||||
USHORT vlan_tpid_ushort;
|
||||
// Validate arguments
|
||||
if (packet_data == NULL || *packet_data == NULL || packet_size == NULL ||
|
||||
*packet_size < 14 || vlan_id == 0)
|
||||
*packet_size < 14 || vlan_id == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -774,7 +774,7 @@ bool VLanRemoveTag(void **packet_data, UINT *packet_size, UINT vlan_id, UINT vla
|
||||
UCHAR *vlan_tpid_uchar;
|
||||
// Validate arguments
|
||||
if (packet_data == NULL || *packet_data == NULL || packet_size == NULL ||
|
||||
*packet_size < 14)
|
||||
*packet_size < 14)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -804,7 +804,7 @@ bool VLanRemoveTag(void **packet_data, UINT *packet_size, UINT vlan_id, UINT vla
|
||||
UINT dest_size = src_size - 4;
|
||||
UINT i;
|
||||
|
||||
for (i = 12;i < dest_size;i++)
|
||||
for (i = 12; i < dest_size; i++)
|
||||
{
|
||||
src_data[i] = src_data[i + 4];
|
||||
}
|
||||
@ -839,10 +839,10 @@ BUF *BuildICMPv6(IPV6_ADDR *src_ip, IPV6_ADDR *dest_ip, UCHAR hop_limit, UCHAR t
|
||||
icmp->Type = type;
|
||||
icmp->Code = code;
|
||||
icmp->Checksum = CalcChecksumForIPv6(src_ip, dest_ip, IP_PROTO_ICMPV6, icmp,
|
||||
sizeof(ICMP_HEADER) + size, 0);
|
||||
sizeof(ICMP_HEADER) + size, 0);
|
||||
|
||||
ret = BuildIPv6(dest_ip, src_ip, id, IP_PROTO_ICMPV6, hop_limit, icmp,
|
||||
sizeof(ICMP_HEADER) + size);
|
||||
sizeof(ICMP_HEADER) + size);
|
||||
|
||||
Free(icmp);
|
||||
|
||||
@ -881,7 +881,45 @@ BUF *BuildICMPv6NeighborSoliciation(IPV6_ADDR *src_ip, IPV6_ADDR *target_ip, UCH
|
||||
WriteBufBuf(b2, b);
|
||||
|
||||
ret = BuildICMPv6(src_ip, target_ip, 255,
|
||||
ICMPV6_TYPE_NEIGHBOR_SOLICIATION, 0, b2->Buf, b2->Size, id);
|
||||
ICMPV6_TYPE_NEIGHBOR_SOLICIATION, 0, b2->Buf, b2->Size, id);
|
||||
|
||||
FreeBuf(b);
|
||||
FreeBuf(b2);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
BUF *BuildICMPv6RouterSoliciation(IPV6_ADDR *src_ip, IPV6_ADDR *target_ip, UCHAR *my_mac_address, UINT id)
|
||||
{
|
||||
ICMPV6_OPTION_LIST opt;
|
||||
ICMPV6_OPTION_LINK_LAYER link;
|
||||
ICMPV6_ROUTER_SOLICIATION_HEADER header;
|
||||
BUF *b;
|
||||
BUF *b2;
|
||||
BUF *ret;
|
||||
|
||||
if (src_ip == NULL || target_ip == NULL || my_mac_address == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Zero(&link, sizeof(link));
|
||||
Copy(link.Address, my_mac_address, 6);
|
||||
|
||||
Zero(&opt, sizeof(opt));
|
||||
opt.SourceLinkLayer = &link;
|
||||
|
||||
b = BuildICMPv6Options(&opt);
|
||||
|
||||
Zero(&header, sizeof(header));
|
||||
|
||||
b2 = NewBuf();
|
||||
|
||||
WriteBuf(b2, &header, sizeof(header));
|
||||
WriteBufBuf(b2, b);
|
||||
|
||||
ret = BuildICMPv6(src_ip, target_ip, 255,
|
||||
ICMPV6_TYPE_ROUTER_SOLICIATION, 0, b2->Buf, b2->Size, id);
|
||||
|
||||
FreeBuf(b);
|
||||
FreeBuf(b2);
|
||||
@ -939,7 +977,7 @@ void BuildAndAddIPv6PacketOptionHeader(BUF *b, IPV6_OPTION_HEADER *opt, UCHAR ne
|
||||
|
||||
// Build an IPv6 packet
|
||||
BUF *BuildIPv6(IPV6_ADDR *dest_ip, IPV6_ADDR *src_ip, UINT id, UCHAR protocol, UCHAR hop_limit, void *data,
|
||||
UINT size)
|
||||
UINT size)
|
||||
{
|
||||
IPV6_HEADER_PACKET_INFO info;
|
||||
IPV6_HEADER ip_header;
|
||||
@ -1020,21 +1058,21 @@ BUF *BuildIPv6PacketHeader(IPV6_HEADER_PACKET_INFO *info, UINT *bytes_before_pay
|
||||
if (info->HopHeader != NULL)
|
||||
{
|
||||
BuildAndAddIPv6PacketOptionHeader(b, info->HopHeader,
|
||||
IPv6GetNextHeaderFromQueue(q), info->HopHeaderSize);
|
||||
IPv6GetNextHeaderFromQueue(q), info->HopHeaderSize);
|
||||
}
|
||||
|
||||
// End point option header
|
||||
if (info->EndPointHeader != NULL)
|
||||
{
|
||||
BuildAndAddIPv6PacketOptionHeader(b, info->EndPointHeader,
|
||||
IPv6GetNextHeaderFromQueue(q), info->EndPointHeaderSize);
|
||||
IPv6GetNextHeaderFromQueue(q), info->EndPointHeaderSize);
|
||||
}
|
||||
|
||||
// Routing header
|
||||
if (info->RoutingHeader != NULL)
|
||||
{
|
||||
BuildAndAddIPv6PacketOptionHeader(b, info->RoutingHeader,
|
||||
IPv6GetNextHeaderFromQueue(q), info->RoutingHeaderSize);
|
||||
IPv6GetNextHeaderFromQueue(q), info->RoutingHeaderSize);
|
||||
}
|
||||
|
||||
// Fragment header
|
||||
@ -1102,6 +1140,7 @@ void BuildICMPv6OptionValue(BUF *b, UCHAR type, void *header_pointer, UINT total
|
||||
BUF *BuildICMPv6Options(ICMPV6_OPTION_LIST *o)
|
||||
{
|
||||
BUF *b;
|
||||
UINT i;
|
||||
// Validate arguments
|
||||
if (o == NULL)
|
||||
{
|
||||
@ -1118,9 +1157,16 @@ BUF *BuildICMPv6Options(ICMPV6_OPTION_LIST *o)
|
||||
{
|
||||
BuildICMPv6OptionValue(b, ICMPV6_OPTION_TYPE_TARGET_LINK_LAYER, o->TargetLinkLayer, sizeof(ICMPV6_OPTION_LINK_LAYER));
|
||||
}
|
||||
if (o->Prefix != NULL)
|
||||
for (i = 0; i < ICMPV6_OPTION_PREFIXES_MAX_COUNT; i++)
|
||||
{
|
||||
BuildICMPv6OptionValue(b, ICMPV6_OPTION_TYPE_PREFIX, o->Prefix, sizeof(ICMPV6_OPTION_PREFIX));
|
||||
if (o->Prefix[i] != NULL)
|
||||
{
|
||||
BuildICMPv6OptionValue(b, ICMPV6_OPTION_TYPE_PREFIX, o->Prefix[i], sizeof(ICMPV6_OPTION_PREFIX));
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (o->Mtu != NULL)
|
||||
{
|
||||
@ -1324,22 +1370,22 @@ PKT *ClonePacket(PKT *p, bool copy_data)
|
||||
Copy(ret->L3.IPv6Header, p->L3.IPv6Header, sizeof(IPV6_HEADER));
|
||||
|
||||
ret->IPv6HeaderPacketInfo.IPv6Header = Clone(p->IPv6HeaderPacketInfo.IPv6Header,
|
||||
sizeof(IPV6_HEADER));
|
||||
sizeof(IPV6_HEADER));
|
||||
|
||||
ret->IPv6HeaderPacketInfo.HopHeader = Clone(p->IPv6HeaderPacketInfo.HopHeader,
|
||||
sizeof(IPV6_OPTION_HEADER));
|
||||
sizeof(IPV6_OPTION_HEADER));
|
||||
|
||||
ret->IPv6HeaderPacketInfo.EndPointHeader = Clone(p->IPv6HeaderPacketInfo.EndPointHeader,
|
||||
sizeof(IPV6_OPTION_HEADER));
|
||||
sizeof(IPV6_OPTION_HEADER));
|
||||
|
||||
ret->IPv6HeaderPacketInfo.RoutingHeader = Clone(p->IPv6HeaderPacketInfo.RoutingHeader,
|
||||
sizeof(IPV6_OPTION_HEADER));
|
||||
sizeof(IPV6_OPTION_HEADER));
|
||||
|
||||
ret->IPv6HeaderPacketInfo.FragmentHeader = Clone(p->IPv6HeaderPacketInfo.FragmentHeader,
|
||||
sizeof(IPV6_FRAGMENT_HEADER));
|
||||
sizeof(IPV6_FRAGMENT_HEADER));
|
||||
|
||||
ret->IPv6HeaderPacketInfo.Payload = Clone(p->IPv6HeaderPacketInfo.Payload,
|
||||
p->IPv6HeaderPacketInfo.PayloadSize);
|
||||
p->IPv6HeaderPacketInfo.PayloadSize);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1359,10 +1405,10 @@ PKT *ClonePacket(PKT *p, bool copy_data)
|
||||
Copy(ret->L4.ICMPHeader, p->L4.ICMPHeader, sizeof(ICMP_HEADER));
|
||||
|
||||
ret->ICMPv6HeaderPacketInfo.Data = Clone(p->ICMPv6HeaderPacketInfo.Data,
|
||||
p->ICMPv6HeaderPacketInfo.DataSize);
|
||||
p->ICMPv6HeaderPacketInfo.DataSize);
|
||||
|
||||
ret->ICMPv6HeaderPacketInfo.EchoData = Clone(p->ICMPv6HeaderPacketInfo.EchoData,
|
||||
p->ICMPv6HeaderPacketInfo.EchoDataSize);
|
||||
p->ICMPv6HeaderPacketInfo.EchoDataSize);
|
||||
|
||||
switch (ret->ICMPv6HeaderPacketInfo.Type)
|
||||
{
|
||||
@ -1372,31 +1418,31 @@ PKT *ClonePacket(PKT *p, bool copy_data)
|
||||
|
||||
case ICMPV6_TYPE_ROUTER_SOLICIATION:
|
||||
ret->ICMPv6HeaderPacketInfo.Headers.RouterSoliciationHeader =
|
||||
Clone(p->ICMPv6HeaderPacketInfo.Headers.RouterSoliciationHeader,
|
||||
sizeof(ICMPV6_ROUTER_SOLICIATION_HEADER));
|
||||
Clone(p->ICMPv6HeaderPacketInfo.Headers.RouterSoliciationHeader,
|
||||
sizeof(ICMPV6_ROUTER_SOLICIATION_HEADER));
|
||||
break;
|
||||
|
||||
case ICMPV6_TYPE_ROUTER_ADVERTISEMENT:
|
||||
ret->ICMPv6HeaderPacketInfo.Headers.RouterAdvertisementHeader =
|
||||
Clone(p->ICMPv6HeaderPacketInfo.Headers.RouterAdvertisementHeader,
|
||||
sizeof(ICMPV6_ROUTER_ADVERTISEMENT_HEADER));
|
||||
Clone(p->ICMPv6HeaderPacketInfo.Headers.RouterAdvertisementHeader,
|
||||
sizeof(ICMPV6_ROUTER_ADVERTISEMENT_HEADER));
|
||||
break;
|
||||
|
||||
case ICMPV6_TYPE_NEIGHBOR_SOLICIATION:
|
||||
ret->ICMPv6HeaderPacketInfo.Headers.NeighborSoliciationHeader =
|
||||
Clone(p->ICMPv6HeaderPacketInfo.Headers.NeighborSoliciationHeader,
|
||||
sizeof(ICMPV6_NEIGHBOR_SOLICIATION_HEADER));
|
||||
Clone(p->ICMPv6HeaderPacketInfo.Headers.NeighborSoliciationHeader,
|
||||
sizeof(ICMPV6_NEIGHBOR_SOLICIATION_HEADER));
|
||||
break;
|
||||
|
||||
case ICMPV6_TYPE_NEIGHBOR_ADVERTISEMENT:
|
||||
ret->ICMPv6HeaderPacketInfo.Headers.NeighborAdvertisementHeader =
|
||||
Clone(p->ICMPv6HeaderPacketInfo.Headers.NeighborAdvertisementHeader,
|
||||
sizeof(ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER));
|
||||
Clone(p->ICMPv6HeaderPacketInfo.Headers.NeighborAdvertisementHeader,
|
||||
sizeof(ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER));
|
||||
break;
|
||||
}
|
||||
|
||||
CloneICMPv6Options(&ret->ICMPv6HeaderPacketInfo.OptionList,
|
||||
&p->ICMPv6HeaderPacketInfo.OptionList);
|
||||
&p->ICMPv6HeaderPacketInfo.OptionList);
|
||||
break;
|
||||
|
||||
case L4_TCP:
|
||||
@ -1427,10 +1473,10 @@ PKT *ClonePacket(PKT *p, bool copy_data)
|
||||
ret->L7.IkeHeader = MallocFast(sizeof(IKE_HEADER));
|
||||
Copy(ret->L7.IkeHeader, p->L7.IkeHeader, sizeof(IKE_HEADER));
|
||||
break;
|
||||
|
||||
case L7_DNS:
|
||||
StrCpy(ret->DnsQueryHost, sizeof(ret->DnsQueryHost), p->DnsQueryHost);
|
||||
break;
|
||||
|
||||
case L7_DNS:
|
||||
StrCpy(ret->DnsQueryHost, sizeof(ret->DnsQueryHost), p->DnsQueryHost);
|
||||
break;
|
||||
}
|
||||
|
||||
// Address data
|
||||
@ -1452,6 +1498,12 @@ PKT *ClonePacket(PKT *p, bool copy_data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Parse the packet but without data layer except for ICMP
|
||||
PKT *ParsePacketUpToICMPv6(UCHAR *buf, UINT size)
|
||||
{
|
||||
return ParsePacketEx5(buf, size, false, 0, true, true, false, true);
|
||||
}
|
||||
|
||||
// Parse the contents of the packet
|
||||
PKT *ParsePacket(UCHAR *buf, UINT size)
|
||||
{
|
||||
@ -1470,6 +1522,10 @@ PKT *ParsePacketEx3(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id, bool b
|
||||
return ParsePacketEx4(buf, size, no_l3, vlan_type_id, bridge_id_as_mac_address, false, false);
|
||||
}
|
||||
PKT *ParsePacketEx4(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id, bool bridge_id_as_mac_address, bool no_http, bool correct_checksum)
|
||||
{
|
||||
return ParsePacketEx5(buf, size, no_l3, vlan_type_id, bridge_id_as_mac_address, no_http, correct_checksum, false);
|
||||
}
|
||||
PKT *ParsePacketEx5(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id, bool bridge_id_as_mac_address, bool no_http, bool correct_checksum, bool no_l3_l4_except_icmpv6)
|
||||
{
|
||||
PKT *p;
|
||||
USHORT vlan_type_id_16;
|
||||
@ -1559,7 +1615,7 @@ PKT *ParsePacketEx4(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id, bool b
|
||||
}
|
||||
|
||||
// Do parse
|
||||
if (ParsePacketL2Ex(p, buf, size, no_l3) == false)
|
||||
if (ParsePacketL2Ex(p, buf, size, no_l3, no_l3_l4_except_icmpv6) == false)
|
||||
{
|
||||
// Parsing failure
|
||||
FreePacket(p);
|
||||
@ -1595,7 +1651,7 @@ PKT *ParsePacketEx4(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id, bool b
|
||||
{
|
||||
TCP_HEADER *tcp = p->L4.TCPHeader;
|
||||
if (tcp != NULL && (tcp->DstPort == port_raw || tcp->DstPort == port_raw2 || tcp->DstPort == port_raw4) &&
|
||||
(!((tcp->Flag & TCP_SYN) || (tcp->Flag & TCP_RST) || (tcp->Flag & TCP_FIN))))
|
||||
(!((tcp->Flag & TCP_SYN) || (tcp->Flag & TCP_RST) || (tcp->Flag & TCP_FIN))))
|
||||
{
|
||||
if (p->PayloadSize >= 1)
|
||||
{
|
||||
@ -1603,7 +1659,7 @@ PKT *ParsePacketEx4(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id, bool b
|
||||
}
|
||||
}
|
||||
if (tcp != NULL && tcp->DstPort == port_raw3 &&
|
||||
(!((tcp->Flag & TCP_SYN) || (tcp->Flag & TCP_RST) || (tcp->Flag & TCP_FIN))))
|
||||
(!((tcp->Flag & TCP_SYN) || (tcp->Flag & TCP_RST) || (tcp->Flag & TCP_FIN))))
|
||||
{
|
||||
if (p->PayloadSize >= 1)
|
||||
{
|
||||
@ -1831,8 +1887,8 @@ HTTPLOG *ParseHttpAccessLog(PKT *pkt)
|
||||
|
||||
// Check whether it starts with the HTTP-specific string
|
||||
if (CmpCaseIgnore(buf, "GET ", 4) != 0 &&
|
||||
CmpCaseIgnore(buf, "HEAD ", 5) != 0 &&
|
||||
CmpCaseIgnore(buf, "POST ", 5) != 0)
|
||||
CmpCaseIgnore(buf, "HEAD ", 5) != 0 &&
|
||||
CmpCaseIgnore(buf, "POST ", 5) != 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@ -1929,7 +1985,7 @@ HTTPLOG *ParseHttpAccessLog(PKT *pkt)
|
||||
|
||||
|
||||
// Layer-2 parsing
|
||||
bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3)
|
||||
bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3, bool no_l3_l4_except_icmpv6)
|
||||
{
|
||||
UINT i;
|
||||
bool b1, b2;
|
||||
@ -1956,7 +2012,7 @@ bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3)
|
||||
p->BroadcastPacket = true;
|
||||
b1 = true;
|
||||
b2 = true;
|
||||
for (i = 0;i < 6;i++)
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
if (p->MacHeader->DestAddress[i] != 0xff)
|
||||
{
|
||||
@ -1994,7 +2050,7 @@ bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3)
|
||||
switch (type_id_16)
|
||||
{
|
||||
case MAC_PROTO_ARPV4: // ARPv4
|
||||
if (no_l3)
|
||||
if (no_l3 || no_l3_l4_except_icmpv6)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -2002,7 +2058,7 @@ bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3)
|
||||
return ParsePacketARPv4(p, buf, size);
|
||||
|
||||
case MAC_PROTO_IPV4: // IPv4
|
||||
if (no_l3)
|
||||
if (no_l3 || no_l3_l4_except_icmpv6)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -2015,7 +2071,7 @@ bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3)
|
||||
return true;
|
||||
}
|
||||
|
||||
return ParsePacketIPv6(p, buf, size);
|
||||
return ParsePacketIPv6(p, buf, size, no_l3_l4_except_icmpv6);
|
||||
|
||||
default: // Unknown
|
||||
if (type_id_16 == p->VlanTypeID)
|
||||
@ -2032,7 +2088,7 @@ bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3)
|
||||
else
|
||||
{
|
||||
// Old IEEE 802.3 frame (payload length of the packet is written in the header)
|
||||
// (It has been used in the BPDU, etc.)
|
||||
// (It has been used in the BPDU, etc.)
|
||||
UINT length = (UINT)type_id_16;
|
||||
LLC_HEADER *llc;
|
||||
|
||||
@ -2354,7 +2410,15 @@ bool ParseICMPv6Options(ICMPV6_OPTION_LIST *o, UCHAR *buf, UINT size)
|
||||
// Prefix Information
|
||||
if (header_total_size >= sizeof(ICMPV6_OPTION_PREFIX))
|
||||
{
|
||||
o->Prefix = (ICMPV6_OPTION_PREFIX *)header_pointer;
|
||||
UINT i;
|
||||
for (i = 0; i < ICMPV6_OPTION_PREFIXES_MAX_COUNT; i++)
|
||||
{
|
||||
if (o->Prefix[i] == NULL)
|
||||
{
|
||||
o->Prefix[i] = (ICMPV6_OPTION_PREFIX *)header_pointer;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2434,10 +2498,10 @@ bool ParseICMPv6(PKT *p, UCHAR *buf, UINT size)
|
||||
}
|
||||
|
||||
icmp_info.Headers.RouterSoliciationHeader =
|
||||
(ICMPV6_ROUTER_SOLICIATION_HEADER *)(((UCHAR *)icmp_info.Data));
|
||||
(ICMPV6_ROUTER_SOLICIATION_HEADER *)(((UCHAR *)icmp_info.Data));
|
||||
|
||||
if (ParseICMPv6Options(&icmp_info.OptionList, ((UCHAR *)icmp_info.Headers.HeaderPointer) + sizeof(ICMPV6_ROUTER_SOLICIATION_HEADER),
|
||||
icmp_info.DataSize - sizeof(ICMPV6_ROUTER_SOLICIATION_HEADER)) == false)
|
||||
icmp_info.DataSize - sizeof(ICMPV6_ROUTER_SOLICIATION_HEADER)) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -2452,10 +2516,10 @@ bool ParseICMPv6(PKT *p, UCHAR *buf, UINT size)
|
||||
}
|
||||
|
||||
icmp_info.Headers.RouterAdvertisementHeader =
|
||||
(ICMPV6_ROUTER_ADVERTISEMENT_HEADER *)(((UCHAR *)icmp_info.Data));
|
||||
(ICMPV6_ROUTER_ADVERTISEMENT_HEADER *)(((UCHAR *)icmp_info.Data));
|
||||
|
||||
if (ParseICMPv6Options(&icmp_info.OptionList, ((UCHAR *)icmp_info.Headers.HeaderPointer) + sizeof(ICMPV6_ROUTER_ADVERTISEMENT_HEADER),
|
||||
icmp_info.DataSize - sizeof(ICMPV6_ROUTER_ADVERTISEMENT_HEADER)) == false)
|
||||
icmp_info.DataSize - sizeof(ICMPV6_ROUTER_ADVERTISEMENT_HEADER)) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -2470,10 +2534,10 @@ bool ParseICMPv6(PKT *p, UCHAR *buf, UINT size)
|
||||
}
|
||||
|
||||
icmp_info.Headers.NeighborSoliciationHeader =
|
||||
(ICMPV6_NEIGHBOR_SOLICIATION_HEADER *)(((UCHAR *)icmp_info.Data));
|
||||
(ICMPV6_NEIGHBOR_SOLICIATION_HEADER *)(((UCHAR *)icmp_info.Data));
|
||||
|
||||
if (ParseICMPv6Options(&icmp_info.OptionList, ((UCHAR *)icmp_info.Headers.HeaderPointer) + sizeof(ICMPV6_NEIGHBOR_SOLICIATION_HEADER),
|
||||
icmp_info.DataSize - sizeof(ICMPV6_NEIGHBOR_SOLICIATION_HEADER)) == false)
|
||||
icmp_info.DataSize - sizeof(ICMPV6_NEIGHBOR_SOLICIATION_HEADER)) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -2488,10 +2552,10 @@ bool ParseICMPv6(PKT *p, UCHAR *buf, UINT size)
|
||||
}
|
||||
|
||||
icmp_info.Headers.NeighborAdvertisementHeader =
|
||||
(ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER *)(((UCHAR *)icmp_info.Data));
|
||||
(ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER *)(((UCHAR *)icmp_info.Data));
|
||||
|
||||
if (ParseICMPv6Options(&icmp_info.OptionList, ((UCHAR *)icmp_info.Headers.HeaderPointer) + sizeof(ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER),
|
||||
icmp_info.DataSize - sizeof(ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER)) == false)
|
||||
icmp_info.DataSize - sizeof(ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER)) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -2508,6 +2572,7 @@ bool ParseICMPv6(PKT *p, UCHAR *buf, UINT size)
|
||||
// Release of the ICMPv6 options
|
||||
void FreeCloneICMPv6Options(ICMPV6_OPTION_LIST *o)
|
||||
{
|
||||
UINT i;
|
||||
// Validate arguments
|
||||
if (o == NULL)
|
||||
{
|
||||
@ -2516,13 +2581,19 @@ void FreeCloneICMPv6Options(ICMPV6_OPTION_LIST *o)
|
||||
|
||||
Free(o->SourceLinkLayer);
|
||||
Free(o->TargetLinkLayer);
|
||||
Free(o->Prefix);
|
||||
|
||||
for (i = 0; i < ICMPV6_OPTION_PREFIXES_MAX_COUNT; i++)
|
||||
{
|
||||
Free(o->Prefix[i]);
|
||||
o->Prefix[i] = NULL;
|
||||
}
|
||||
Free(o->Mtu);
|
||||
}
|
||||
|
||||
// Clone of the ICMPv6 options
|
||||
void CloneICMPv6Options(ICMPV6_OPTION_LIST *dst, ICMPV6_OPTION_LIST *src)
|
||||
{
|
||||
UINT i;
|
||||
// Validate arguments
|
||||
if (dst == NULL || src == NULL)
|
||||
{
|
||||
@ -2533,12 +2604,22 @@ void CloneICMPv6Options(ICMPV6_OPTION_LIST *dst, ICMPV6_OPTION_LIST *src)
|
||||
|
||||
dst->SourceLinkLayer = Clone(src->SourceLinkLayer, sizeof(ICMPV6_OPTION_LINK_LAYER));
|
||||
dst->TargetLinkLayer = Clone(src->TargetLinkLayer, sizeof(ICMPV6_OPTION_LINK_LAYER));
|
||||
dst->Prefix = Clone(src->Prefix, sizeof(ICMPV6_OPTION_PREFIX));
|
||||
for (i = 0; i < ICMPV6_OPTION_PREFIXES_MAX_COUNT; i++)
|
||||
{
|
||||
if (src->Prefix[i] != NULL)
|
||||
{
|
||||
dst->Prefix[i] = Clone(src->Prefix[i], sizeof(ICMPV6_OPTION_PREFIX));
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
dst->Mtu = Clone(src->Mtu, sizeof(ICMPV6_OPTION_MTU));
|
||||
}
|
||||
|
||||
// IPv6 parsing
|
||||
bool ParsePacketIPv6(PKT *p, UCHAR *buf, UINT size)
|
||||
bool ParsePacketIPv6(PKT *p, UCHAR *buf, UINT size, bool no_l3_l4_except_icmpv6)
|
||||
{
|
||||
// Validate arguments
|
||||
if (p == NULL || buf == NULL)
|
||||
@ -2585,9 +2666,17 @@ bool ParsePacketIPv6(PKT *p, UCHAR *buf, UINT size)
|
||||
}
|
||||
|
||||
case IP_PROTO_TCP: // TCP
|
||||
if (no_l3_l4_except_icmpv6)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return ParseTCP(p, buf, size);
|
||||
|
||||
case IP_PROTO_UDP: // UDP
|
||||
if (no_l3_l4_except_icmpv6)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return ParseUDP(p, buf, size);
|
||||
|
||||
default: // Unknown
|
||||
@ -2931,7 +3020,7 @@ bool ParseUDP(PKT *p, UCHAR *buf, UINT size)
|
||||
dst_port = Endian16(p->L4.UDPHeader->DstPort);
|
||||
|
||||
if ((src_port == 67 && dst_port == 68) ||
|
||||
(src_port == 68 && dst_port == 67))
|
||||
(src_port == 68 && dst_port == 67))
|
||||
{
|
||||
if (p->TypeL3 == L3_IPV4)
|
||||
{
|
||||
@ -2941,13 +3030,13 @@ bool ParseUDP(PKT *p, UCHAR *buf, UINT size)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (dst_port == 53)
|
||||
|
||||
if (dst_port == 53)
|
||||
{
|
||||
ParseDNS(p, buf, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
ParseDNS(p, buf, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (src_port == 500 || dst_port == 500 || src_port == 4500 || dst_port == 4500)
|
||||
{
|
||||
@ -2956,8 +3045,8 @@ bool ParseUDP(PKT *p, UCHAR *buf, UINT size)
|
||||
IKE_HEADER *ike_header = (IKE_HEADER *)p->Payload;
|
||||
|
||||
if (ike_header->InitiatorCookie != 0 && ike_header->ResponderCookie == 0 &&
|
||||
(ike_header->ExchangeType == IKE_EXCHANGE_TYPE_MAIN ||
|
||||
ike_header->ExchangeType == IKE_EXCHANGE_TYPE_AGGRESSIVE))
|
||||
(ike_header->ExchangeType == IKE_EXCHANGE_TYPE_MAIN ||
|
||||
ike_header->ExchangeType == IKE_EXCHANGE_TYPE_AGGRESSIVE))
|
||||
{
|
||||
// the IKE connection request packet is found
|
||||
p->TypeL7 = L7_IKECONN;
|
||||
@ -3247,7 +3336,7 @@ BUF *BuildDhcpOptionsBuf(LIST *o)
|
||||
}
|
||||
|
||||
b = NewBuf();
|
||||
for (i = 0;i < LIST_NUM(o);i++)
|
||||
for (i = 0; i < LIST_NUM(o); i++)
|
||||
{
|
||||
DHCP_OPTION *d = LIST_DATA(o, i);
|
||||
UINT current_size = d->Size;
|
||||
@ -3556,7 +3645,7 @@ void BuildClasslessRouteTableStr(char *str, UINT str_size, DHCP_CLASSLESS_ROUTE_
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0;i < MAX_DHCP_CLASSLESS_ROUTE_ENTRIES;i++)
|
||||
for (i = 0; i < MAX_DHCP_CLASSLESS_ROUTE_ENTRIES; i++)
|
||||
{
|
||||
DHCP_CLASSLESS_ROUTE *r = &t->Entries[i];
|
||||
|
||||
@ -3628,7 +3717,7 @@ bool ParseClasslessRouteTableStr(DHCP_CLASSLESS_ROUTE_TABLE *d, char *str)
|
||||
{
|
||||
UINT i;
|
||||
|
||||
for (i = 0;i < t->NumTokens;i++)
|
||||
for (i = 0; i < t->NumTokens; i++)
|
||||
{
|
||||
DHCP_CLASSLESS_ROUTE r;
|
||||
|
||||
@ -3728,7 +3817,7 @@ BUF *DhcpBuildClasslessRouteData(DHCP_CLASSLESS_ROUTE_TABLE *t)
|
||||
|
||||
b = NewBuf();
|
||||
|
||||
for (i = 0;i < MAX_DHCP_CLASSLESS_ROUTE_ENTRIES;i++)
|
||||
for (i = 0; i < MAX_DHCP_CLASSLESS_ROUTE_ENTRIES; i++)
|
||||
{
|
||||
DHCP_CLASSLESS_ROUTE *r = &t->Entries[i];
|
||||
|
||||
@ -3827,7 +3916,7 @@ void DhcpParseClasslessRouteData(DHCP_CLASSLESS_ROUTE_TABLE *t, void *data, UINT
|
||||
Copy(&r.SubnetMask, &mask, sizeof(IP));
|
||||
r.SubnetMaskLen = subnet_mask_len;
|
||||
|
||||
for (i = 0;i < MAX_DHCP_CLASSLESS_ROUTE_ENTRIES;i++)
|
||||
for (i = 0; i < MAX_DHCP_CLASSLESS_ROUTE_ENTRIES; i++)
|
||||
{
|
||||
if (Cmp(&t->Entries[i], &r, sizeof(DHCP_CLASSLESS_ROUTE)) == 0)
|
||||
{
|
||||
@ -3863,7 +3952,7 @@ DHCP_OPTION *GetDhcpOption(LIST *o, UINT id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0;i < LIST_NUM(o);i++)
|
||||
for (i = 0; i < LIST_NUM(o); i++)
|
||||
{
|
||||
DHCP_OPTION *opt = LIST_DATA(o, i);
|
||||
if (opt->Id == id)
|
||||
@ -3891,7 +3980,7 @@ DHCP_CLASSLESS_ROUTE *GetBestClasslessRoute(DHCP_CLASSLESS_ROUTE_TABLE *t, IP *i
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0;i < MAX_DHCP_CLASSLESS_ROUTE_ENTRIES;i++)
|
||||
for (i = 0; i < MAX_DHCP_CLASSLESS_ROUTE_ENTRIES; i++)
|
||||
{
|
||||
DHCP_CLASSLESS_ROUTE *e = &t->Entries[i];
|
||||
|
||||
@ -3921,7 +4010,7 @@ void FreeDhcpOptions(LIST *o)
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0;i < LIST_NUM(o);i++)
|
||||
for (i = 0; i < LIST_NUM(o); i++)
|
||||
{
|
||||
DHCP_OPTION *opt = LIST_DATA(o, i);
|
||||
Free(opt->Data);
|
||||
@ -4040,10 +4129,10 @@ BUF *DhcpModifyIPv4(DHCP_MODIFY_OPTION *m, void *data, UINT size)
|
||||
|
||||
udp->Checksum = 0;
|
||||
udp->Checksum = CalcChecksumForIPv4(p->L3.IPv4Header->SrcIP,
|
||||
p->L3.IPv4Header->DstIP,
|
||||
IP_PROTO_UDP,
|
||||
udp,
|
||||
p->PacketSize - (UINT)(((UCHAR *)udp) - ((UCHAR *)p->PacketData)), 0);
|
||||
p->L3.IPv4Header->DstIP,
|
||||
IP_PROTO_UDP,
|
||||
udp,
|
||||
p->PacketSize - (UINT)(((UCHAR *)udp) - ((UCHAR *)p->PacketData)), 0);
|
||||
}
|
||||
|
||||
FreePacket(p);
|
||||
@ -4127,7 +4216,7 @@ BUF *DhcpModify(DHCP_MODIFY_OPTION *m, void *data, UINT size)
|
||||
// Rebuilding the options list
|
||||
opt_list2 = NewListFast(NULL);
|
||||
|
||||
for (i = 0;i < LIST_NUM(opt_list);i++)
|
||||
for (i = 0; i < LIST_NUM(opt_list); i++)
|
||||
{
|
||||
DHCP_OPTION *o = LIST_DATA(opt_list, i);
|
||||
DHCP_OPTION *o2 = NULL;
|
||||
|
@ -399,12 +399,14 @@ struct ICMPV6_NEIGHBOR_ADVERTISEMENT_HEADER
|
||||
#define ICMPV6_NEIGHBOR_ADVERTISEMENT_FLAG_SOLICITED 0x40 // Solicited flag
|
||||
#define ICMPV6_NEIGHBOR_ADVERTISEMENT_FLAG_OVERWRITE 0x20 // Overwrite flag
|
||||
|
||||
#define ICMPV6_OPTION_PREFIXES_MAX_COUNT 10
|
||||
|
||||
// ICMPv6 option list
|
||||
struct ICMPV6_OPTION_LIST
|
||||
{
|
||||
ICMPV6_OPTION_LINK_LAYER *SourceLinkLayer; // Source link-layer address
|
||||
ICMPV6_OPTION_LINK_LAYER *TargetLinkLayer; // Target link-layer address
|
||||
ICMPV6_OPTION_PREFIX *Prefix; // Prefix Information
|
||||
ICMPV6_OPTION_PREFIX *Prefix[ICMPV6_OPTION_PREFIXES_MAX_COUNT]; // Prefix Information - may be multiple in one request
|
||||
ICMPV6_OPTION_MTU *Mtu; // MTU
|
||||
} GCC_PACKED;
|
||||
|
||||
@ -745,6 +747,8 @@ PKT *ParsePacketEx(UCHAR *buf, UINT size, bool no_l3);
|
||||
PKT *ParsePacketEx2(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id);
|
||||
PKT *ParsePacketEx3(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id, bool bridge_id_as_mac_address);
|
||||
PKT *ParsePacketEx4(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id, bool bridge_id_as_mac_address, bool no_http, bool correct_checksum);
|
||||
PKT *ParsePacketEx5(UCHAR *buf, UINT size, bool no_l3, UINT vlan_type_id, bool bridge_id_as_mac_address, bool no_http, bool correct_checksum, bool no_l3_l4_except_icmpv6);
|
||||
PKT *ParsePacketUpToICMPv6(UCHAR *buf, UINT size);
|
||||
void FreePacket(PKT *p);
|
||||
void FreePacketWithData(PKT *p);
|
||||
void FreePacketIPv4(PKT *p);
|
||||
@ -754,7 +758,7 @@ void FreePacketUDPv4(PKT *p);
|
||||
void FreePacketTCPv4(PKT *p);
|
||||
void FreePacketICMPv4(PKT *p);
|
||||
void FreePacketDHCPv4(PKT *p);
|
||||
bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3);
|
||||
bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3, bool no_l3_l4_except_icmpv6);
|
||||
bool ParsePacketARPv4(PKT *p, UCHAR *buf, UINT size);
|
||||
bool ParsePacketIPv4(PKT *p, UCHAR *buf, UINT size);
|
||||
bool ParsePacketBPDU(PKT *p, UCHAR *buf, UINT size);
|
||||
@ -770,7 +774,7 @@ void FreeClonePacket(PKT *p);
|
||||
|
||||
void CorrectChecksum(PKT *p);
|
||||
|
||||
bool ParsePacketIPv6(PKT *p, UCHAR *buf, UINT size);
|
||||
bool ParsePacketIPv6(PKT *p, UCHAR *buf, UINT size, bool no_l3_l4_except_icmpv6);
|
||||
bool ParsePacketIPv6Header(IPV6_HEADER_PACKET_INFO *info, UCHAR *buf, UINT size);
|
||||
bool ParseIPv6ExtHeader(IPV6_HEADER_PACKET_INFO *info, UCHAR next_header, UCHAR *buf, UINT size);
|
||||
bool ParseICMPv6Options(ICMPV6_OPTION_LIST *o, UCHAR *buf, UINT size);
|
||||
@ -781,11 +785,12 @@ USHORT CalcChecksumForIPv6(IPV6_ADDR *src_ip, IPV6_ADDR *dest_ip, UCHAR protocol
|
||||
BUF *BuildICMPv6Options(ICMPV6_OPTION_LIST *o);
|
||||
void BuildICMPv6OptionValue(BUF *b, UCHAR type, void *header_pointer, UINT total_size);
|
||||
BUF *BuildIPv6(IPV6_ADDR *dest_ip, IPV6_ADDR *src_ip, UINT id, UCHAR protocol, UCHAR hop_limit, void *data,
|
||||
UINT size);
|
||||
UINT size);
|
||||
BUF *BuildIPv6PacketHeader(IPV6_HEADER_PACKET_INFO *info, UINT *bytes_before_payload);
|
||||
UCHAR IPv6GetNextHeaderFromQueue(QUEUE *q);
|
||||
void BuildAndAddIPv6PacketOptionHeader(BUF *b, IPV6_OPTION_HEADER *opt, UCHAR next_header, UINT size);
|
||||
BUF *BuildICMPv6NeighborSoliciation(IPV6_ADDR *src_ip, IPV6_ADDR *target_ip, UCHAR *my_mac_address, UINT id);
|
||||
BUF *BuildICMPv6RouterSoliciation(IPV6_ADDR *src_ip, IPV6_ADDR *target_ip, UCHAR *my_mac_address, UINT id);
|
||||
BUF *BuildICMPv6(IPV6_ADDR *src_ip, IPV6_ADDR *dest_ip, UCHAR hop_limit, UCHAR type, UCHAR code, void *data, UINT size, UINT id);
|
||||
|
||||
bool VLanRemoveTag(void **packet_data, UINT *packet_size, UINT vlan_id, UINT vlan_tpid);
|
||||
|
Loading…
Reference in New Issue
Block a user