Started work on DHCP.
git-svn-id: https://spexeah.com:8443/svn/Asuro@926 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
parent
861f65abe0
commit
29f986a8e4
@ -189,6 +189,132 @@ type
|
|||||||
end;
|
end;
|
||||||
PUDPPseudoHeader = ^TUDPPseudoHeader;
|
PUDPPseudoHeader = ^TUDPPseudoHeader;
|
||||||
|
|
||||||
|
{ DHCP }
|
||||||
|
TDHCPHeader = packed record
|
||||||
|
Message_Type : uint8;
|
||||||
|
Hardware_Type : uint8;
|
||||||
|
Hardware_Address_Length : uint8;
|
||||||
|
Hops : uint8;
|
||||||
|
Transaction_ID : uint32;
|
||||||
|
Seconds_Elapsed : uint16;
|
||||||
|
Bootp_Flags : uint16;
|
||||||
|
Client_IP : TIPv4Address;
|
||||||
|
Your_IP : TIPv4Address;
|
||||||
|
Server_IP : TIPV4Header;
|
||||||
|
Relay_Agent_IP : TIPV4Header;
|
||||||
|
Client_MAC : TMACAddress;
|
||||||
|
Padding : Array[0..9] of uint8;
|
||||||
|
Server_Hostname : Array[0..63] of uint8;
|
||||||
|
Boot_File : Array[0..127] of uint8;
|
||||||
|
Magic_Cookie : Array[0..3] of uint8;
|
||||||
|
Option_start : char;
|
||||||
|
end;
|
||||||
|
PDHCPHeader = ^TDHCPHeader;
|
||||||
|
TDHCPOpCode = (
|
||||||
|
//BootTP Vendor Information Extensions
|
||||||
|
PAD:= 0,
|
||||||
|
SUBNET_MASK:= 1,
|
||||||
|
TIME_OFFSET:= 2,
|
||||||
|
ROUTER:= 3,
|
||||||
|
TIME_SERVER:= 4,
|
||||||
|
NAME_SERVER:= 5,
|
||||||
|
DNS_SERVER:= 6,
|
||||||
|
LOG_SERVER:= 7,
|
||||||
|
COOKIE_SERVER:= 8,
|
||||||
|
LPR_SERVER:= 9,
|
||||||
|
IMPRESS_SERVER:= 10,
|
||||||
|
RESOURCE_LOCATION_SERVER:= 11,
|
||||||
|
HOST_NAME:= 12,
|
||||||
|
BOOT_FILE_SIZE:= 13,
|
||||||
|
MERIT_DUMP_FILE:= 14,
|
||||||
|
DOMAIN_NAME:= 15,
|
||||||
|
SWAP_SERVER:= 16,
|
||||||
|
ROOT_PATH:= 17,
|
||||||
|
EXTENSIONS_PATH:= 18,
|
||||||
|
END_VENDOR_OPTIONS:= 255,
|
||||||
|
//IP Layer Parameters Per Host
|
||||||
|
IP_FORWARDING:= 19,
|
||||||
|
NONLOCAL_SOURCE_ROUTING:= 20,
|
||||||
|
POLICY_FILTER:= 21,
|
||||||
|
MAXIMUM_DATAGRAM_REASSEMBLY_SIZE:= 22,
|
||||||
|
DEFAULT_IP_TTL:= 23,
|
||||||
|
PATH_MTU_AGING_TIMEOUT:= 24,
|
||||||
|
PATH_MTU_PLATEAU_TABLE:= 25,
|
||||||
|
//IP Layer Parameters Per Interface
|
||||||
|
INTERFACE_MTU:= 26,
|
||||||
|
ALL_SUBNETS_ARE_LOCAL:= 27,
|
||||||
|
BROADCAST_ADDRESS:= 28,
|
||||||
|
PERFORM_MASK_DISCOVERY:= 29,
|
||||||
|
MASK_SUPPLIER:= 30,
|
||||||
|
PERFORM_ROUTER_DISCOVERY:= 31,
|
||||||
|
ROUTER_SOLICITATION_ADDRESS:= 32,
|
||||||
|
STATIC_ROUTE:= 33,
|
||||||
|
//Link Layer Parameters Per Interface
|
||||||
|
TRAILER_ENCAPSULATION_OPTION:= 34,
|
||||||
|
ARP_CACHE_TIMEOUT:= 35,
|
||||||
|
ETHERNET_ENCAPSULATION:= 36,
|
||||||
|
//TCP Parameters
|
||||||
|
TCP_DEFAULT_TTL:= 37,
|
||||||
|
TCP_KEEPALIVE_INTERVAL:= 38,
|
||||||
|
TCP_KEEPALIVE_GARBAGE:= 39,
|
||||||
|
//Application and Service Parameters
|
||||||
|
NETWORK_INFORMATION_SERVICE_DOMAIN:= 40,
|
||||||
|
NETWORK_INFORMATION_SERVERS:= 41,
|
||||||
|
NTP_SERVERS:= 42,
|
||||||
|
VENDOR_SPECIFIC_INFORMATION:= 43,
|
||||||
|
NETBIOS_OVER_TCP_NAME_SERVER:= 44,
|
||||||
|
NETBIOS_OVER_TCP_DATAGRAM_DISTRIBUTION_SERVER:= 45,
|
||||||
|
NETBIOS_OVER_TCP_NODE_TYPE:= 46,
|
||||||
|
NETBIOS_OVER_TCP_SCOPE:= 47,
|
||||||
|
X_WINDOW_SYSTEM_FONT_SERVER:= 48,
|
||||||
|
X_WINDOW_SYSTEM_DISPLAY_MANAGER:= 49,
|
||||||
|
NETWORK_INFORMATION_SERVICE_PLUS_DOMAIN:= 64,
|
||||||
|
NETWORK_INFORMATION_SERVICE_PLUS_SERVERS:= 65,
|
||||||
|
MOBILE_IP_HOME_AGENT:= 68,
|
||||||
|
SMTP_SERVER:= 69,
|
||||||
|
POP3_SERVER:= 70,
|
||||||
|
NNTP_SERVER:= 71,
|
||||||
|
DEFAULT_WWW_SERVER:= 72,
|
||||||
|
DEFAULT_FINGER_SERVER:= 73,
|
||||||
|
DEFAULT_IRC_SERVER:= 74,
|
||||||
|
STREETTALK_SERVER:= 75,
|
||||||
|
STDA_SERVER:= 76,
|
||||||
|
//DHCP Extensions
|
||||||
|
REQUESTED_IP_ADDRESS:= 50,
|
||||||
|
IP_ADDRESS_LEASE_TIME:= 51,
|
||||||
|
OPTION_OVERLOAD:= 52,
|
||||||
|
DHCP_MESSAGE_TYPE:= 53,
|
||||||
|
SERVER_IDENTIFIER:= 54,
|
||||||
|
PARAMETER_REQUEST_LIST:= 55,
|
||||||
|
MESSAGE:= 56,
|
||||||
|
MAXIMUM_DHCP_MESSAGE_SIZE:= 57,
|
||||||
|
RENEWAL_T1_TIME_VALUE:= 58,
|
||||||
|
REBINDING_T2_TIME_VALUE:= 59,
|
||||||
|
VENDOR_CLASS_IDENTIFIER:= 60,
|
||||||
|
CLIENT_IDENTIFIER:= 61,
|
||||||
|
TFTP_SERVER_NAME:= 66,
|
||||||
|
BOOTFILE_NAME:= 67,
|
||||||
|
//Misc
|
||||||
|
RELAY_AGENT_INFORMATION:= 82,
|
||||||
|
NDS_SERVERS:= 85,
|
||||||
|
NDS_TREE_NAME:= 86,
|
||||||
|
NDS_CONTEXT:= 87,
|
||||||
|
POSIX_TIMEZONE:= 100,
|
||||||
|
TZ_TIMEZONE:= 101,
|
||||||
|
DOMAIN_SEARCH:= 119,
|
||||||
|
CLASSLESS_STATIC_ROUTE:= 121
|
||||||
|
);
|
||||||
|
TDHCPMessageType = (
|
||||||
|
DISCOVER := 1,
|
||||||
|
OFFER := 2,
|
||||||
|
REQUEST := 3,
|
||||||
|
DECLINE := 4,
|
||||||
|
PACK := 5,
|
||||||
|
NAK := 6,
|
||||||
|
RELEASE := 7,
|
||||||
|
INFORM := 8
|
||||||
|
);
|
||||||
|
|
||||||
{ Callback Types }
|
{ Callback Types }
|
||||||
|
|
||||||
TNetSendCallback = function(p_data : void; p_len : uint16) : sint32;
|
TNetSendCallback = function(p_data : void; p_len : uint16) : sint32;
|
||||||
@ -197,6 +323,9 @@ type
|
|||||||
{ Constants }
|
{ Constants }
|
||||||
|
|
||||||
const
|
const
|
||||||
|
{ DHCP Magic }
|
||||||
|
DHCP_MAGIC : Array[0..3] of uint8 = ($63, $82, $53, $63);
|
||||||
|
|
||||||
{ MACs }
|
{ 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);
|
||||||
|
@ -26,7 +26,12 @@ procedure writeToLogLn(str : pchar);
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
ipv4, arp, eth2, icmp, e1000, terminal, udp;
|
terminal,
|
||||||
|
e1000, //dev
|
||||||
|
eth2, //L2
|
||||||
|
arp, ipv4, //L3
|
||||||
|
icmp, tcp, udp, //L4
|
||||||
|
dhcp; //L5
|
||||||
|
|
||||||
var
|
var
|
||||||
CBSend : TNetSendCallback = nil;
|
CBSend : TNetSendCallback = nil;
|
||||||
@ -116,11 +121,16 @@ end;
|
|||||||
procedure init;
|
procedure init;
|
||||||
begin
|
begin
|
||||||
push_trace('net.init');
|
push_trace('net.init');
|
||||||
|
//l2
|
||||||
eth2.register;
|
eth2.register;
|
||||||
|
//l3
|
||||||
arp.register;
|
arp.register;
|
||||||
ipv4.register;
|
ipv4.register;
|
||||||
|
//l4
|
||||||
icmp.register;
|
icmp.register;
|
||||||
udp.register;
|
udp.register;
|
||||||
|
//l5
|
||||||
|
dhcp.register;
|
||||||
pop_trace;
|
pop_trace;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -13,9 +13,6 @@ uses
|
|||||||
ipv4, netlog, net,
|
ipv4, netlog, net,
|
||||||
util;
|
util;
|
||||||
|
|
||||||
var
|
|
||||||
Ports : Array[0..65535] of PUDPBindContext;
|
|
||||||
|
|
||||||
procedure register();
|
procedure register();
|
||||||
function bind(bindContext : PUDPBindContext) : TUDPError;
|
function bind(bindContext : PUDPBindContext) : TUDPError;
|
||||||
function unbind(bindContext : PUDPBindContext) : TUDPError;
|
function unbind(bindContext : PUDPBindContext) : TUDPError;
|
||||||
@ -26,6 +23,9 @@ implementation
|
|||||||
uses
|
uses
|
||||||
console, terminal;
|
console, terminal;
|
||||||
|
|
||||||
|
var
|
||||||
|
Ports : Array[0..65535] of PUDPBindContext;
|
||||||
|
|
||||||
function CalculateChecksum(p_data : void; p_len : uint16; udpContext : PUDPSendContext) : uint16;
|
function CalculateChecksum(p_data : void; p_len : uint16; udpContext : PUDPSendContext) : uint16;
|
||||||
var
|
var
|
||||||
pseudoBuffer : void;
|
pseudoBuffer : void;
|
||||||
@ -59,7 +59,7 @@ begin
|
|||||||
pseudoBuffer:= kalloc(sizeof(TUDPPseudoHeader) + pseudoSize);
|
pseudoBuffer:= kalloc(sizeof(TUDPPseudoHeader) + pseudoSize);
|
||||||
pseudoBuffer8:= puint8(pseudoBuffer);
|
pseudoBuffer8:= puint8(pseudoBuffer);
|
||||||
pseudoBuffer16:= puint16(pseudoBuffer);
|
pseudoBuffer16:= puint16(pseudoBuffer);
|
||||||
pseudoBuffer32:= puint32(pseudoBuffer32);
|
pseudoBuffer32:= puint32(pseudoBuffer);
|
||||||
pseudoHeader:= PUDPPseudoHeader(pseudoBuffer);
|
pseudoHeader:= PUDPPseudoHeader(pseudoBuffer);
|
||||||
copyIPv4(puint8(@udpContext^.context^.IP.Source[0]), puint8(@pseudoBuffer8[0]));
|
copyIPv4(puint8(@udpContext^.context^.IP.Source[0]), puint8(@pseudoBuffer8[0]));
|
||||||
copyIPv4(puint8(@udpContext^.context^.IP.Destination[0]), puint8(@pseudoBuffer8[4]));
|
copyIPv4(puint8(@udpContext^.context^.IP.Destination[0]), puint8(@pseudoBuffer8[4]));
|
||||||
@ -74,30 +74,24 @@ begin
|
|||||||
pseudoHeader^.Source_IP:= switchendian32(pseudoHeader^.Source_IP);
|
pseudoHeader^.Source_IP:= switchendian32(pseudoHeader^.Source_IP);
|
||||||
pseudoHeader^.Destination_IP:= switchendian32(pseudoHeader^.Destination_IP);
|
pseudoHeader^.Destination_IP:= switchendian32(pseudoHeader^.Destination_IP);
|
||||||
|
|
||||||
//writehexln(pseudoHeader^.Source_IP);
|
|
||||||
//writehexln(pseudoHeader^.Destination_IP);
|
|
||||||
//writehexln(pseudoHeader^.Protocol);
|
|
||||||
//writehexln(pseudoHeader^.Length);
|
|
||||||
//writehexln(pseudoHeader^.UDP_Source);
|
|
||||||
//writehexln(pseudoHeader^.UDP_Destination);
|
|
||||||
//writehexln(pseudoHeader^.UDP_Length);
|
|
||||||
|
|
||||||
Checksum_u:= 0;
|
Checksum_u:= 0;
|
||||||
|
|
||||||
for i:=0 to (SizeOf(TUDPPseudoHeader) div 2)-1 do begin
|
for i:=0 to (SizeOf(TUDPPseudoHeader) div 2)-1 do begin
|
||||||
//writestring('+ ');
|
|
||||||
//writehexln(pseudoBuffer16[i]);
|
|
||||||
Checksum_u:= Checksum_u + pseudoBuffer16[i];
|
Checksum_u:= Checksum_u + pseudoBuffer16[i];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
for i:=(SizeOf(TUDPPseudoHeader) div 2) to ((pseudoSize + SizeOf(TUDPPseudoHeader)) div 2) - 1 do begin
|
for i:=(SizeOf(TUDPPseudoHeader) div 2) to ((pseudoSize + SizeOf(TUDPPseudoHeader)) div 2) - 1 do begin
|
||||||
//writestring('- ');
|
|
||||||
//ritehexln( switchendian16(pseudoBuffer16[i]));
|
|
||||||
Checksum_u:= Checksum_u + switchendian16(pseudoBuffer16[i]);
|
Checksum_u:= Checksum_u + switchendian16(pseudoBuffer16[i]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Checksum_f:= Checksum_u AND $FFFF;
|
Checksum_f:= Checksum_u AND $FFFF;
|
||||||
Checksum_c:= (Checksum_u AND $FFFF0000) SHR 16;
|
Checksum_c:= (Checksum_u AND $FFFF0000) SHR 16;
|
||||||
Checksum_f:= Checksum_f + Checksum_c;
|
Checksum_f:= Checksum_f + Checksum_c;
|
||||||
Checksum_f:= not Checksum_f;
|
Checksum_f:= not Checksum_f;
|
||||||
CalculateChecksum:= Checksum_f;
|
CalculateChecksum:= Checksum_f;
|
||||||
|
|
||||||
|
kfree(pseudoBuffer);
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure send(p_data : void; p_len : uint16; udpContext : PUDPSendContext);
|
procedure send(p_data : void; p_len : uint16; udpContext : PUDPSendContext);
|
||||||
@ -255,31 +249,18 @@ begin
|
|||||||
for i:=0 to 65535 do begin
|
for i:=0 to 65535 do begin
|
||||||
Ports[i]:= nil;
|
Ports[i]:= nil;
|
||||||
end;
|
end;
|
||||||
//context:= PUDPBindContext(kalloc(sizeof(TUDPBindContext)));
|
//writestring('[TestBind] ');
|
||||||
//context^.Port:= 22294;
|
//SendContext:= PUDPSendContext(kalloc(SizeOf(TUDPSendContext)));
|
||||||
//context^.Callback:= @TestRecv;
|
//BindContext:= PUDPBindContext(kalloc(SizeOf(TUDPBindContext)));
|
||||||
//context^.UID:= 4398724;
|
//PacketContext:= PPacketContext(kalloc(SizeOf(TPacketContext)));
|
||||||
//r:= bind(context);
|
//SendContext^.DstPort:= 10;
|
||||||
writestring('[TestBind] ');
|
//SendContext^.Socket:= BindContext;
|
||||||
//case r of
|
//SendContext^.Context:= PacketContext;
|
||||||
// tueOK:writestringln('22294 bind OK');
|
//BindContext^.Port:= 20;
|
||||||
// tuePortInUse:writestringln('22294 port in use');
|
//copyIPv4(puint8(@UDPT_S_IP[0]), puint8(@PacketContext^.IP.Source[0]));
|
||||||
// tueGenericError:writestringln('22294 generic error');
|
//copyIPv4(puint8(@UDPT_D_IP[0]), puint8(@PacketContext^.IP.Destination[0]));
|
||||||
// tuePortRestricted:writestringln('22294 restricted');
|
//Checksum:= CalculateChecksum(void(@UDPT_DATA[0]), 2, SendContext);
|
||||||
//end;
|
//writehexln(Checksum);
|
||||||
|
|
||||||
SendContext:= PUDPSendContext(kalloc(SizeOf(TUDPSendContext)));
|
|
||||||
BindContext:= PUDPBindContext(kalloc(SizeOf(TUDPBindContext)));
|
|
||||||
PacketContext:= PPacketContext(kalloc(SizeOf(TPacketContext)));
|
|
||||||
SendContext^.DstPort:= 10;
|
|
||||||
SendContext^.Socket:= BindContext;
|
|
||||||
SendContext^.Context:= PacketContext;
|
|
||||||
BindContext^.Port:= 20;
|
|
||||||
copyIPv4(puint8(@UDPT_S_IP[0]), puint8(@PacketContext^.IP.Source[0]));
|
|
||||||
copyIPv4(puint8(@UDPT_D_IP[0]), puint8(@PacketContext^.IP.Destination[0]));
|
|
||||||
|
|
||||||
Checksum:= CalculateChecksum(void(@UDPT_DATA[0]), 2, SendContext);
|
|
||||||
writehexln(Checksum);
|
|
||||||
//while true do begin end;
|
//while true do begin end;
|
||||||
|
|
||||||
ipv4.registerProtocol($11, @ProcessPacket);
|
ipv4.registerProtocol($11, @ProcessPacket);
|
||||||
|
55
src/driver/net/l5/dhcp.pas
Normal file
55
src/driver/net/l5/dhcp.pas
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
unit dhcp;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
lmemorymanager, console,
|
||||||
|
nettypes, netutils, udp, netlog, net,
|
||||||
|
util, rand, lists;
|
||||||
|
|
||||||
|
type
|
||||||
|
TDHCPOptions = PLinkedListBase;
|
||||||
|
PDHCPOptions = ^PLinkedListBase;
|
||||||
|
TDHCPOption = record
|
||||||
|
Opcode : TDHCPOpCode;
|
||||||
|
Size : uint32;
|
||||||
|
Value : void;
|
||||||
|
Header_Location : void;
|
||||||
|
Reverse_Endian : boolean;
|
||||||
|
end;
|
||||||
|
PDHCPOption = ^TDHCPOption;
|
||||||
|
|
||||||
|
procedure register();
|
||||||
|
procedure DHCPDiscover();
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
var
|
||||||
|
XID : uint32;
|
||||||
|
Socket : PUDPBindContext;
|
||||||
|
|
||||||
|
procedure processPacket(p_data : void; p_len : uint16; context : PUDPPacketContext);
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure DHCPDiscover();
|
||||||
|
begin
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure register();
|
||||||
|
begin
|
||||||
|
console.outputln('DHCP', 'Register begin.');
|
||||||
|
Socket:= PUDPBindContext(Kalloc(sizeof(TUDPBindContext)));
|
||||||
|
Socket^.Port:= 68;
|
||||||
|
Socket^.Callback:= @processPacket;
|
||||||
|
Socket^.UID:= rand32;
|
||||||
|
case UDP.bind(Socket) of
|
||||||
|
tueOK:console.outputln('DHCP', 'Successfully bound port 68.');
|
||||||
|
else console.outputln('DHCP', 'Failed to bind port 68.');
|
||||||
|
end;
|
||||||
|
console.outputln('DHCP', 'Register end.');
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
@ -12,10 +12,15 @@ implementation
|
|||||||
var
|
var
|
||||||
next : uint32 = 1;
|
next : uint32 = 1;
|
||||||
|
|
||||||
function rand32 : uint32;
|
function rand : uint32;
|
||||||
begin
|
begin
|
||||||
next:= next * 1103515245 + 12345;
|
next:= next * 1103515245 + 12345;
|
||||||
rand32:= (next div 65536) mod 32768;
|
rand:= (next div 65536) mod 32768;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function rand32 : uint32;
|
||||||
|
begin
|
||||||
|
rand32:= (rand SHL 16) AND rand;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function rand16 : uint16;
|
function rand16 : uint16;
|
||||||
|
@ -241,6 +241,10 @@ begin
|
|||||||
|
|
||||||
tracer.push_trace('kmain.END');
|
tracer.push_trace('kmain.END');
|
||||||
|
|
||||||
|
writehexln(rand.rand32);
|
||||||
|
writehexln(rand.rand32);
|
||||||
|
writehexln(rand.rand32);
|
||||||
|
|
||||||
tracer.push_trace('kmain.TICK');
|
tracer.push_trace('kmain.TICK');
|
||||||
while true do begin
|
while true do begin
|
||||||
tracer.push_trace('kmain.RedrawWindows');
|
tracer.push_trace('kmain.RedrawWindows');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user