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

BIN
Asuro.iso

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -46,6 +46,18 @@ type
UP : Boolean; UP : Boolean;
end; 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 } { ARP }
TARPAbstractHeader = record TARPAbstractHeader = record
@ -139,10 +151,17 @@ type
{ Constants } { Constants }
const const
{ MACs }
BROADCAST_MAC : Array[0..5] of uint8 = ($FF, $FF, $FF, $FF, $FF, $FF); 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); 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); 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 implementation
end. end.

View File

@ -19,9 +19,46 @@ function newPacketContext : PPacketContext;
procedure freePacketContext(p_context : PPacketContext); procedure freePacketContext(p_context : PPacketContext);
function calculateChecksum(p_data : puint16; p_len : uint16) : uint16; function calculateChecksum(p_data : puint16; p_len : uint16) : uint16;
function verifyChecksum(p_data : puint16; p_len : uint16) : boolean; 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 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; function calculateChecksum(p_data : puint16; p_len : uint16) : uint16;
var var
sum : uint32; sum : uint32;

View File

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

View File

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

View File

@ -3,9 +3,50 @@ unit icmp;
interface interface
uses uses
nettypes, netutils, nettypes, netutils, ipv4;
ipv4;
procedure register;
implementation 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. end.

View File

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

View File

@ -20,7 +20,8 @@ uses
strings, strings,
tracer, tracer,
asuro, asuro,
serial; serial,
netutils, nettypes;
type type
THaltCallback = procedure(); THaltCallback = procedure();
@ -507,7 +508,20 @@ begin
end; end;
procedure teapot(Params : PParamList); procedure teapot(Params : PParamList);
var
ip1, ip2, ip3 : pchar;
begin 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); terminal.halt(555, @teapot_halt);
end; end;