git-svn-id: https://spexeah.com:8443/svn/Asuro@733 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c

This commit is contained in:
kieron
2018-05-13 10:35:04 +00:00
parent 168eb35b54
commit beb04a225a
36 changed files with 120 additions and 7 deletions

View File

@ -46,6 +46,18 @@ type
UP : Boolean;
end;
{ ICMP }
PICMPHeader = ^TICMPHeader;
TICMPHeader = record
ICMP_Type : uint8;
ICMP_Code : uint8;
ICMP_CHK_Hi : uint8;
ICMP_CHK_Lo : uint8;
Identifier : uint16;
Sequence : uint16;
end;
{ ARP }
TARPAbstractHeader = record
@ -139,10 +151,17 @@ type
{ Constants }
const
{ MACs }
BROADCAST_MAC : Array[0..5] of uint8 = ($FF, $FF, $FF, $FF, $FF, $FF);
NULL_MAC : Array[0..5] of uint8 = ($00, $00, $00, $00, $00, $00);
FORCE_MAC : Array[0..5] of uint8 = ($08, $00, $27, $E6, $3F, $81);
{ ICMP Data }
ICMP_DATA_GENERIC : Array[0..31] of uint8 = ( $61, $62, $63, $64, $65, $66, $67, $68,
$69, $6a, $6b, $6c, $6d, $6e, $6f, $70,
$71, $72, $73, $74, $75, $76, $77, $61,
$62, $63, $64, $65, $66, $67, $68, $69 );
implementation
end.

View File

@ -19,9 +19,46 @@ function newPacketContext : PPacketContext;
procedure freePacketContext(p_context : PPacketContext);
function calculateChecksum(p_data : puint16; p_len : uint16) : uint16;
function verifyChecksum(p_data : puint16; p_len : uint16) : boolean;
function sameSubnetIPv4(ip1, ip2, netmask : puint8) : boolean;
procedure contextMACSwitch(p_context : PPacketContext);
procedure contextIPv4Switch(p_context : PPacketContext);
implementation
function sameSubnetIPv4(ip1, ip2, netmask : puint8) : boolean;
var
_ip1, _ip2, _netmask : puint32;
c1, c2 : uint32;
begin
_ip1:= puint32(ip1);
_ip2:= puint32(ip2);
_netmask:= puint32(netmask);
c1:= _ip1^ AND _netmask^;
c2:= _ip2^ AND _netmask^;
sameSubnetIPv4:= c1 = c2;
end;
procedure contextMACSwitch(p_context : PPacketContext);
var
tmp : TMACAddress;
begin
copyMAC(@p_context^.MAC.Source[0], @tmp[0]);
copyMAC(@p_context^.MAC.Destination[0], @p_context^.MAC.Source[0]);
copyMAC(@tmp[0], @p_context^.MAC.Destination[0]);
end;
procedure contextIPv4Switch(p_context : PPacketContext);
var
tmp : TIPv4Address;
begin
copyIPv4(@p_context^.IP.Source[0], @tmp[0]);
copyIPv4(@p_context^.IP.Destination[0], @p_context^.IP.Source[0]);
copyIPv4(@tmp[0], @p_context^.IP.Destination[0]);
end;
function calculateChecksum(p_data : puint16; p_len : uint16) : uint16;
var
sum : uint32;

View File

@ -21,7 +21,7 @@ procedure writeToLogLn(str : pchar);
implementation
uses
ipv4, arp, eth2, e1000, terminal;
ipv4, arp, eth2, icmp, e1000, terminal;
var
CBSend : TNetSendCallback = nil;
@ -114,6 +114,7 @@ begin
eth2.register;
arp.register;
ipv4.register;
icmp.register;
pop_trace;
end;

View File

@ -10,6 +10,7 @@ uses
lists,
eth2;
procedure send(p_data : void; p_len : uint16; p_context : PPacketContext);
procedure registerProtocol(Protocol_ID : uint8; recv_callback : TRecvCallback);
function getIPv4Config : PIPv4Configuration;
procedure register;

View File

@ -3,9 +3,50 @@ unit icmp;
interface
uses
nettypes, netutils,
ipv4;
nettypes, netutils, ipv4;
procedure register;
implementation
procedure sendResponse(p_context : PPacketContext);
begin
end;
procedure sendRequest(ip : puint8);
begin
end;
procedure recv(p_data : void; p_len : uint16; p_context : PPacketContext);
var
Header : PICMPHeader;
CHK : uint16;
begin
Header:= PICMPHeader(p_data);
case Header^.ICMP_Type of
$08:Begin //Request
contextMACSwitch(p_context);
contextIPv4Switch(p_context);
Header^.ICMP_Type:= 0;
Header^.ICMP_CHK_Hi:= 0;
Header^.ICMP_CHK_Lo:= 0;
CHK:= calculateChecksum(puint16(p_data), sizeof(TICMPHeader));
Header^.ICMP_CHK_Hi:= CHK SHR 8;
Header^.ICMP_CHK_Lo:= CHK AND $FF;
ipv4.send(p_data, p_len, p_context);
end;
$00:begin //Reply
end;
end;
end;
procedure register;
begin
ipv4.registerProtocol($01, @recv);
end;
end.

View File

@ -9,14 +9,14 @@ const
VERSION_SUB = '1';
REVISION = '728';
RELEASE = 'ia';
LINE_COUNT = 28413;
LINE_COUNT = 28526;
FILE_COUNT = 90;
DRIVER_COUNT = 32;
FPC_VERSION = '2.6.4';
NASM_VERSION = '2.10.09';
MAKE_VERSION = '3.81';
COMPILE_DATE = '12/05/18';
COMPILE_TIME = '18:38:28';
COMPILE_DATE = '13/05/18';
COMPILE_TIME = '11:34:48';
implementation

View File

@ -20,7 +20,8 @@ uses
strings,
tracer,
asuro,
serial;
serial,
netutils, nettypes;
type
THaltCallback = procedure();
@ -507,7 +508,20 @@ begin
end;
procedure teapot(Params : PParamList);
var
ip1, ip2, ip3 : pchar;
begin
if paramCount(Params) > 2 then begin
ip1:= getParam(0, Params);
ip2:= getParam(1, Params);
ip3:= getParam(2, Params);
if sameSubnetIPv4(stringToIPv4(ip1), stringToIPv4(ip2), stringToIPv4(ip3)) then begin
console.writeStringlnWND('Same.', getTerminalHWND);
end else begin
console.writeStringlnWND('Different', getTerminalHWND);
end;
end;
terminal.halt(555, @teapot_halt);
end;