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

This commit is contained in:
kieron 2018-05-10 10:33:37 +00:00
parent b050773dda
commit b03ae36a9a
17 changed files with 126 additions and 32 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.

View File

@ -3,12 +3,14 @@ unit eth2;
interface interface
uses uses
lmemorymanager, util,
tracer, tracer,
nettypes, netutils, nettypes, netutils,
net, net,
netlog, netlog,
console; console;
procedure send(p_data : void; p_len : uint16; p_context : PPacketContext);
procedure registerType(eType : uint16; RecvCB : TRecvCallback); procedure registerType(eType : uint16; RecvCB : TRecvCallback);
procedure register; procedure register;
@ -27,6 +29,27 @@ begin
pop_trace; pop_trace;
end; end;
procedure send(p_data : void; p_len : uint16; p_context : PPacketContext);
var
buffer : void;
hdr : TEthernetHeader;
begin
push_trace('eth2.send');
writeToLogLn(' L2: eth2.send');
if p_context <> nil then begin
buffer:= kalloc(p_len + sizeof(TEthernetHeader));
copyMAC(@p_context^.MAC.Source[0], @hdr.src[0]);
copyMAC(@p_context^.MAC.Destination[0], @hdr.dst[0]);
hdr.EthTypeHi:= 0;
hdr.EthTypeLo:= 1;
memcpy(uint32(@hdr), uint32(buffer), sizeof(TEthernetHeader));
memcpy(uint32(p_data), uint32(buffer+sizeof(TEthernetHeader)), p_len);
net.send(buffer, p_len + sizeof(TEthernetHeader));
kfree(buffer);
end;
end;
procedure recv(p_data : void; p_len : uint16; p_context : PPacketContext); procedure recv(p_data : void; p_len : uint16; p_context : PPacketContext);
var var
Header : PEthernetHeader; Header : PEthernetHeader;

View File

@ -3,11 +3,11 @@ unit arp;
interface interface
uses uses
tracer, tracer, lmemorymanager,
util, lists, console, util, lists, console,
net, nettypes, netutils, net, nettypes, netutils,
netlog, netlog,
eth2; eth2, ipv4;
type type
PARPCacheRecord = ^TARPCacheRecord; PARPCacheRecord = ^TARPCacheRecord;
@ -62,15 +62,57 @@ begin
pop_trace; pop_trace;
end; end;
procedure send(hType : uint16; pType : uint16; op : uint16; p_context : PPacketContext);
var
buf : void;
hdr : PARPHeader;
hSize, pSize : uint8;
begin
push_trace('arp.send');
writeToLogLn(' L3: arp.send');
if p_context <> nil then begin
buf:= kalloc(sizeof(TARPHeader));
hdr:= PARPHeader(buf);
case hType of
$1 : hSize:= 6;
else hSize:= 0;
end;
case pType of
$8000 : pSize:= 4;
else pSize:= 0;
end;
if (hSize > 0) and (pSize > 0) then begin
hdr^.Hardware_Type_Hi:= hType SHR 8;
hdr^.Hardware_Type_Lo:= hType AND $FF;
hdr^.Protocol_Type_Hi:= pType SHR 8;
hdr^.Protocol_Type_Lo:= pType AND $FF;
hdr^.Hardware_Address_Length:= hSize;
hdr^.Protocol_Address_Length:= pSize;
hdr^.Operation_Hi:= op SHR 8;
hdr^.Operation_Lo:= op AND $FF;
copyMAC(@p_context^.MAC.Source[0], @hdr^.Source_Hardware[0]);
copyIPv4(@p_context^.IP.Source[0], @hdr^.Source_Protocol[0]);
copyMAC(@p_context^.MAC.Destination[0], @hdr^.Destination_Hardware[0]);
copyIPv4(@p_context^.IP.Destination[0], @hdr^.Destination_Protocol[0]);
eth2.send(buf, sizeof(TARPHeader), p_context);
end;
kfree(buf);
end;
end;
procedure recv(p_data : void; p_len : uint16; p_context : PPacketContext); procedure recv(p_data : void; p_len : uint16; p_context : PPacketContext);
var var
Header : PARPHeader; Header : PARPHeader;
AHeader : TARPAbstractHeader; AHeader : TARPAbstractHeader;
CacheElement : PARPCacheRecord; CacheElement : PARPCacheRecord;
Merge : boolean;
context : PPacketContext;
begin begin
push_trace('arp.recv'); push_trace('arp.recv');
writeToLogLn(' L3: arp.recv'); writeToLogLn(' L3: arp.recv');
{ Get our converted Header } { Get our converted Header }
Header:= PARPHeader(p_data); Header:= PARPHeader(p_data);
AHeader.Hardware_Type:= (Header^.Hardware_Type_Hi SHL 8) + Header^.Hardware_Type_Lo; AHeader.Hardware_Type:= (Header^.Hardware_Type_Hi SHL 8) + Header^.Hardware_Type_Lo;
@ -82,36 +124,59 @@ begin
copyIPv4(@Header^.Source_Protocol[0], @AHeader.Source_Protocol[0]); copyIPv4(@Header^.Source_Protocol[0], @AHeader.Source_Protocol[0]);
copyMAC(@Header^.Destination_Hardware[0], @AHeader.Destination_Hardware[0]); copyMAC(@Header^.Destination_Hardware[0], @AHeader.Destination_Hardware[0]);
copyIPv4(@Header^.Destination_Protocol[0], @AHeader.Destination_Protocol[0]); copyIPv4(@Header^.Destination_Protocol[0], @AHeader.Destination_Protocol[0]);
case AHeader.Operation of
$1:begin { ARP Request } { Process ARP Packet }
writeToLogLn(' arp.recv.arp.req'); Merge:= false;
end; CacheElement:= findCacheRecordByIP(@AHeader.Source_Protocol[0]);
$2:begin { ARP Reply } if CacheElement <> nil then begin
writeToLogLn(' arp.recv.arp.rep'); copyMAC(@AHeader.Source_Hardware[0], @CacheElement^.MAC[0]);
end; Merge:= true;
$3:begin { RARP Request } end else begin
writeToLogLn(' arp.recv.rarp.req'); if IPEqual(@AHeader.Destination_Protocol[0], @getIPv4Config^.Address[0]) then begin
end; if not Merge then begin
$4:begin { RARP Reply } CacheElement:= PARPCacheRecord(LL_Add(Cache));
writeToLogLn(' arp.recv.rarp.rep'); CopyMAC(@AHeader.Source_Hardware[0], @CacheElement^.MAC[0]);
end; copyIPv4(@AHeader.Source_Protocol[0], @CacheElement^.IP[0]);
$5:begin { DRARP Request } end;
writeToLogLn(' arp.recv.drarp.req'); case AHeader.Operation of
end; $1:begin { ARP Request }
$6:begin { DRARP Reply } writeToLogLn(' arp.recv.arp.req');
writeToLogLn(' arp.recv.drarp.rep'); context:= newPacketContext;
end; //context^.
$7:begin { DRARP Error } copyMAC(@AHeader.Source_Hardware[0], @context^.MAC.Destination[0]);
writeToLogLn(' arp.recv.drarp.err'); copyIPv4(@AHeader.Source_Protocol[0], @context^.IP.Destination[0]);
end; copyMAC(getMAC, @context^.MAC.Source[0]);
$8:begin { InARP Request } copyIPv4(@getIPv4Config^.Address[0], @context^.IP.Source[0]);
writeToLogLn(' arp.recv.inarp.req'); send($1, $8000, $2, context);
end; freePacketContext(context);
$9:begin { InARP Reply } end;
writeToLogLn(' arp.recv.inarp.rep'); $2:begin { ARP Reply }
writeToLogLn(' arp.recv.arp.rep');
end;
$3:begin { RARP Request }
writeToLogLn(' arp.recv.rarp.req');
end;
$4:begin { RARP Reply }
writeToLogLn(' arp.recv.rarp.rep');
end;
$5:begin { DRARP Request }
writeToLogLn(' arp.recv.drarp.req');
end;
$6:begin { DRARP Reply }
writeToLogLn(' arp.recv.drarp.rep');
end;
$7:begin { DRARP Error }
writeToLogLn(' arp.recv.drarp.err');
end;
$8:begin { InARP Request }
writeToLogLn(' arp.recv.inarp.req');
end;
$9:begin { InARP Reply }
writeToLogLn(' arp.recv.inarp.rep');
end;
end;
end; end;
end; end;
pop_trace;
end; end;
procedure register; procedure register;

View File

@ -10,6 +10,7 @@ uses
eth2; eth2;
procedure registerProtocol(Protocol_ID : uint8; recv_callback : TRecvCallback); procedure registerProtocol(Protocol_ID : uint8; recv_callback : TRecvCallback);
function getIPv4Config : PIPv4Configuration;
procedure register; procedure register;
implementation implementation
@ -19,6 +20,11 @@ var
Protocols : Array[0..255] of TRecvCallback; Protocols : Array[0..255] of TRecvCallback;
Config : TIPv4Configuration; Config : TIPv4Configuration;
function getIPv4Config : PIPv4Configuration;
begin
getIPv4Config:= @Config;
end;
procedure recv(p_data : void; p_len : uint16; p_context : PPacketContext); procedure recv(p_data : void; p_len : uint16; p_context : PPacketContext);
var var
Header : PIPV4Header; Header : PIPV4Header;

View File

@ -9,14 +9,14 @@ const
VERSION_SUB = '1'; VERSION_SUB = '1';
REVISION = '677'; REVISION = '677';
RELEASE = 'ia'; RELEASE = 'ia';
LINE_COUNT = 27683; LINE_COUNT = 27777;
FILE_COUNT = 89; FILE_COUNT = 89;
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 = '10/05/18'; COMPILE_DATE = '10/05/18';
COMPILE_TIME = '10:07:09'; COMPILE_TIME = '11:33:11';
implementation implementation