mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-11-23 01:49:53 +03:00
src/Mayaqua/TcpIp: remove dead code, unused variables and fuctions
found by coverity, cppcheck [src/Mayaqua/TcpIp.c:578]: (style) Variable 'tcp_size' is assigned a value that is never used. [src/Mayaqua/TcpIp.c:1034]: (style) Variable 'has_vlan_tag' is assigned a value that is never used. [src/Mayaqua/TcpIp.c:1996]: (style) Variable 'tcp_header_size' is assigned a value that is never used. [src/Mayaqua/TcpIp.c:127]: (style) The function 'IcmpEchoSend' is never used. [src/Mayaqua/TcpIp.c:2194]: (style) The function 'ParsePacketL2' is never used. [src/Mayaqua/TcpIp.c:251]: (style) The function 'IcmpEchoSendBySocket' is never used.
This commit is contained in:
parent
b029676b67
commit
8ca0ce3efc
@ -122,30 +122,6 @@
|
||||
#include <errno.h>
|
||||
#include <Mayaqua/Mayaqua.h>
|
||||
|
||||
|
||||
// Send an ICMP Echo
|
||||
ICMP_RESULT *IcmpEchoSend(IP *dest_ip, UCHAR ttl, UCHAR *data, UINT size, UINT timeout)
|
||||
{
|
||||
// Validate arguments
|
||||
if (dest_ip == NULL || IsIP4(dest_ip) == false || (size != 0 && data == NULL))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (ttl == 0)
|
||||
{
|
||||
ttl = 127;
|
||||
}
|
||||
|
||||
if (IsIcmpApiSupported())
|
||||
{
|
||||
return IcmpApiEchoSend(dest_ip, ttl, data, size, timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
return IcmpEchoSendBySocket(dest_ip, ttl, data, size, timeout);
|
||||
}
|
||||
}
|
||||
|
||||
// Release the memory for the ICMP response
|
||||
void IcmpFreeResult(ICMP_RESULT *r)
|
||||
{
|
||||
@ -271,138 +247,6 @@ ICMP_RESULT *IcmpParseResult(IP *dest_ip, USHORT src_id, USHORT src_seqno, UCHAR
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Send the ICMP Echo (by a socket)
|
||||
ICMP_RESULT *IcmpEchoSendBySocket(IP *dest_ip, UCHAR ttl, UCHAR *data, UINT size, UINT timeout)
|
||||
{
|
||||
SOCK *s;
|
||||
ICMP_RESULT *ret = NULL;
|
||||
USHORT id;
|
||||
USHORT seq;
|
||||
UINT64 sent_tick;
|
||||
UINT64 recv_tick;
|
||||
// Validate arguments
|
||||
if (dest_ip == NULL || IsIP4(dest_ip) == false || (size != 0 && data == NULL))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (ttl == 0)
|
||||
{
|
||||
ttl = 127;
|
||||
}
|
||||
|
||||
s = NewUDP4(MAKE_SPECIAL_PORT(IP_PROTO_ICMPV4), NULL);
|
||||
if (s != NULL)
|
||||
{
|
||||
// Construction of the ICMP packet
|
||||
UCHAR *send_buffer;
|
||||
UINT send_buffer_size = sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO) + size;
|
||||
ICMP_HEADER *send_icmp_header;
|
||||
ICMP_ECHO *send_icmp_echo;
|
||||
UINT i;
|
||||
|
||||
id = Rand16();
|
||||
if (id == 0)
|
||||
{
|
||||
id = 1;
|
||||
}
|
||||
|
||||
seq = Rand16();
|
||||
if (seq == 0)
|
||||
{
|
||||
seq = 1;
|
||||
}
|
||||
|
||||
send_buffer = ZeroMalloc(send_buffer_size);
|
||||
|
||||
send_icmp_header = (ICMP_HEADER *)send_buffer;
|
||||
send_icmp_header->Type = ICMP_TYPE_ECHO_REQUEST;
|
||||
|
||||
send_icmp_echo = (ICMP_ECHO *)(send_buffer + sizeof(ICMP_HEADER));
|
||||
send_icmp_echo->Identifier = Endian16(id);
|
||||
send_icmp_echo->SeqNo = Endian16(seq);
|
||||
|
||||
Copy(send_buffer + sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO), data, size);
|
||||
|
||||
send_icmp_header->Checksum = IpChecksum(send_buffer, send_buffer_size);
|
||||
|
||||
// Send an ICMP
|
||||
SetTtl(s, ttl);
|
||||
sent_tick = TickHighres64();
|
||||
i = SendTo(s, dest_ip, MAKE_SPECIAL_PORT(IP_PROTO_ICMPV4), send_buffer, send_buffer_size);
|
||||
|
||||
if (i != 0 && i != INFINITE)
|
||||
{
|
||||
// ICMP response received
|
||||
INTERRUPT_MANAGER *interrupt = NewInterruptManager();
|
||||
UINT64 giveup_time = Tick64() + (UINT64)timeout;
|
||||
UINT recv_buffer_size = (sizeof(IPV4_HEADER) + sizeof(ICMP_HEADER) + sizeof(ICMP_ECHO) + size + 64) * 2;
|
||||
UCHAR *recv_buffer = Malloc(recv_buffer_size);
|
||||
|
||||
AddInterrupt(interrupt, giveup_time);
|
||||
|
||||
while (true)
|
||||
{
|
||||
UINT interval = GetNextIntervalForInterrupt(interrupt);
|
||||
IP src_ip;
|
||||
UINT src_port;
|
||||
SOCKSET set;
|
||||
|
||||
InitSockSet(&set);
|
||||
AddSockSet(&set, s);
|
||||
|
||||
Select(&set, interval, NULL, NULL);
|
||||
|
||||
while (true)
|
||||
{
|
||||
Zero(recv_buffer, recv_buffer_size);
|
||||
i = RecvFrom(s, &src_ip, &src_port, recv_buffer, recv_buffer_size);
|
||||
recv_tick = TickHighres64();
|
||||
|
||||
if (i != 0 && i != SOCK_LATER)
|
||||
{
|
||||
ret = IcmpParseResult(dest_ip, id, seq, recv_buffer, i);
|
||||
|
||||
if (ret != NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (interval == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret != NULL)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FreeInterruptManager(interrupt);
|
||||
|
||||
Free(recv_buffer);
|
||||
|
||||
if (ret == NULL)
|
||||
{
|
||||
ret = ZeroMalloc(sizeof(ICMP_RESULT));
|
||||
|
||||
ret->Timeout = true;
|
||||
}
|
||||
}
|
||||
|
||||
Free(send_buffer);
|
||||
ReleaseSock(s);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Get whether the packet is a DHCP packet associated with the specified MAC address
|
||||
bool IsDhcpPacketForSpecificMac(UCHAR *data, UINT size, UCHAR *mac_address)
|
||||
{
|
||||
@ -575,7 +419,6 @@ UINT GetIpHeaderSize(UCHAR *src, UINT src_size)
|
||||
{
|
||||
UCHAR ip_ver;
|
||||
TCP_HEADER *tcp = NULL;
|
||||
UINT tcp_size = 0;
|
||||
IPV4_HEADER *ip = NULL;
|
||||
IPV6_HEADER *ip6 = NULL;
|
||||
// Validate arguments
|
||||
@ -1031,7 +874,6 @@ void VLanInsertTag(void **packet_data, UINT *packet_size, UINT vlan_id, UINT vla
|
||||
// Remove the VLAN tag from the packet
|
||||
bool VLanRemoveTag(void **packet_data, UINT *packet_size, UINT vlan_id, UINT vlan_tpid)
|
||||
{
|
||||
bool has_vlan_tag = false;
|
||||
UCHAR *src_data;
|
||||
UINT src_size;
|
||||
USHORT vlan_tpid_ushort;
|
||||
@ -1993,7 +1835,6 @@ void CorrectChecksum(PKT *p)
|
||||
|
||||
if (tcp != NULL)
|
||||
{
|
||||
UINT tcp_header_size = TCP_GET_HEADER_SIZE(tcp) * 4;
|
||||
USHORT tcp_offloading_checksum1 = CalcChecksumForIPv6(&v6->SrcAddress, &v6->DestAddress, IP_PROTO_TCP, NULL, 0, v6info->PayloadSize);
|
||||
USHORT tcp_offloading_checksum2 = ~tcp_offloading_checksum1;
|
||||
|
||||
@ -2191,10 +2032,6 @@ HTTPLOG *ParseHttpAccessLog(PKT *pkt)
|
||||
|
||||
|
||||
// Layer-2 parsing
|
||||
bool ParsePacketL2(PKT *p, UCHAR *buf, UINT size)
|
||||
{
|
||||
return ParsePacketL2Ex(p, buf, size, false);
|
||||
}
|
||||
bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3)
|
||||
{
|
||||
UINT i;
|
||||
@ -4062,11 +3899,6 @@ void DhcpParseClasslessRouteData(DHCP_CLASSLESS_ROUTE_TABLE *t, void *data, UINT
|
||||
}
|
||||
|
||||
data_len = (subnet_mask_len + 7) / 8;
|
||||
if (data_len > 4)
|
||||
{
|
||||
// Invalid data
|
||||
break;
|
||||
}
|
||||
|
||||
Zero(tmp, sizeof(tmp));
|
||||
if (ReadBuf(b, tmp, data_len) != data_len)
|
||||
|
@ -860,7 +860,6 @@ void FreePacketUDPv4(PKT *p);
|
||||
void FreePacketTCPv4(PKT *p);
|
||||
void FreePacketICMPv4(PKT *p);
|
||||
void FreePacketDHCPv4(PKT *p);
|
||||
bool ParsePacketL2(PKT *p, UCHAR *buf, UINT size);
|
||||
bool ParsePacketL2Ex(PKT *p, UCHAR *buf, UINT size, bool no_l3);
|
||||
bool ParsePacketARPv4(PKT *p, UCHAR *buf, UINT size);
|
||||
bool ParsePacketIPv4(PKT *p, UCHAR *buf, UINT size);
|
||||
@ -909,8 +908,6 @@ UCHAR GetNextByte(BUF *b);
|
||||
|
||||
bool IsDhcpPacketForSpecificMac(UCHAR *data, UINT size, UCHAR *mac_address);
|
||||
|
||||
ICMP_RESULT *IcmpEchoSendBySocket(IP *dest_ip, UCHAR ttl, UCHAR *data, UINT size, UINT timeout);
|
||||
ICMP_RESULT *IcmpEchoSend(IP *dest_ip, UCHAR ttl, UCHAR *data, UINT size, UINT timeout);
|
||||
ICMP_RESULT *IcmpParseResult(IP *dest_ip, USHORT src_id, USHORT src_seqno, UCHAR *recv_buffer, UINT recv_buffer_size);
|
||||
void IcmpFreeResult(ICMP_RESULT *r);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user