git.ucc.asn.au
/
tpg
/
acess2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
| inline |
side by side
Kernel - Oops, no compile test
[tpg/acess2.git]
/
Modules
/
IPStack
/
icmp.c
diff --git
a/Modules/IPStack/icmp.c
b/Modules/IPStack/icmp.c
index
3f82f87
..
1603719
100644
(file)
--- a/
Modules/IPStack/icmp.c
+++ b/
Modules/IPStack/icmp.c
@@
-37,25
+37,56
@@
void ICMP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buff
{
tICMPHeader *hdr = Buffer;
-
Log("[ICMP ] hdr->Type = %i", hdr->Type
);
- Log
("[ICMP ] hdr->Code = %i"
, hdr->Code);
-
Log("[ICMP ]
hdr->Checksum = 0x%x", ntohs(hdr->Checksum));
- Log
("[ICMP ]
hdr->ID = 0x%x", ntohs(hdr->ID));
- Log
("[ICMP ]
hdr->Sequence = 0x%x", ntohs(hdr->Sequence));
+
//Log_Debug("ICMPv4", "Length = %i", Length
);
+ Log
_Debug("ICMPv4", "hdr->Type, hdr->Code = %i, %i", hdr->Type
, hdr->Code);
+
//Log_Debug("ICMPv4", "
hdr->Checksum = 0x%x", ntohs(hdr->Checksum));
+ Log
_Debug("ICMPv4", "
hdr->ID = 0x%x", ntohs(hdr->ID));
+ Log
_Debug("ICMPv4", "
hdr->Sequence = 0x%x", ntohs(hdr->Sequence));
switch(hdr->Type)
{
+ // -- 0: Echo Reply
case ICMP_ECHOREPLY:
if(hdr->Code != 0) {
-
Warning("[ICMP ]
Code == %i for ICMP Echo Reply, should be 0", hdr->Code);
+
Log_Warning("ICMPv4", "
Code == %i for ICMP Echo Reply, should be 0", hdr->Code);
return ;
}
- if(hdr->ID != ~hdr->Sequence) {
-
Warning("[ICMP ]
ID and Sequence values do not match");
- return ;
+ if(hdr->ID !=
(Uint16)
~hdr->Sequence) {
+
Log_Warning("ICMPv4", "
ID and Sequence values do not match");
+
//
return ;
}
gICMP_PingSlots[hdr->ID].bArrived = 1;
break;
+
+ // -- 3: Destination Unreachable
+ case ICMP_UNREACHABLE:
+ switch(hdr->Code)
+ {
+ case 3: // Port Unreachable
+ Log_Debug("ICMPv4", "Destination Unreachable (Port Unreachable)");
+ break;
+ default:
+ Log_Debug("ICMPv4", "Destination Unreachable (Code %i)", hdr->Code);
+ break;
+ }
+// IPv4_Unreachable( Interface, hdr->Code, htons(hdr->Length)-sizeof(tICMPHeader), hdr->Data );
+ break;
+
+ // -- 8: Echo Request
+ case ICMP_ECHOREQ:
+ if(hdr->Code != 0) {
+ Log_Warning("ICMPv4", "Code == %i for ICMP Echo Request, should be 0", hdr->Code);
+ return ;
+ }
+ //Log_Debug("ICMPv4", "Replying");
+ hdr->Type = ICMP_ECHOREPLY;
+ hdr->Checksum = 0;
+ hdr->Checksum = htons( IPv4_Checksum( (Uint16*)hdr, Length/2 ) );
+ //Log_Debug("ICMPv4", "Checksum = 0x%04x", hdr->Checksum);
+ IPv4_SendPacket(Interface, *(tIPv4*)Address, 1, ntohs(hdr->Sequence), Length, hdr);
+ break;
+ default:
+ break;
}
}
@@
-66,7
+97,8
@@
void ICMP_GetPacket(tInterface *Interface, void *Address, int Length, void *Buff
*/
int ICMP_Ping(tInterface *Interface, tIPv4 Addr)
{
- //Sint64 ts;
+ Sint64 ts;
+ Sint64 end;
char buf[32] = "\x8\0\0\0\0\0\0\0Acess2 I"
"P/TCP Stack 1.0\0";
tICMPHeader *hdr = (void*)buf;
@@
-78,15
+110,24
@@
int ICMP_Ping(tInterface *Interface, tIPv4 Addr)
{
if(gICMP_PingSlots[i].Interface == NULL) break;
}
- if(
gICMP_PingSlots[i].Interface == NULL)
break;
+ if(
i < PING_SLOTS )
break;
Threads_Yield();
}
gICMP_PingSlots[i].Interface = Interface;
gICMP_PingSlots[i].bArrived = 0;
hdr->ID = i;
hdr->Sequence = ~i;
- hdr->Checksum = htons( IPv4_Checksum(hdr, sizeof(buf)) );
- IPv4_SendPacket(Interface, Addr, 1, i, 32, buf);
+ hdr->Checksum = htons( IPv4_Checksum((Uint16*)hdr, sizeof(buf)/2) );
+
+ ts = now();
+
+ IPv4_SendPacket(Interface, Addr, 1, i, sizeof(buf), buf);
+
+ end = ts + Interface->TimeoutDelay;
+ while( !gICMP_PingSlots[i].bArrived && now() < end) Threads_Yield();
+
+ if(now() > end)
+ return -1;
- return
-1
;
+ return
(int)( now() - ts )
;
}
UCC
git Repository :: git.ucc.asn.au