Difference between revisions of "Unit IPv6"

From Ultibo.org
Jump to: navigation, search
Line 1,181: Line 1,181:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| None documented
 
| None documented
 
|-
 
|-
Line 1,196: Line 1,196:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| Complete packet without Adapter header
 
| Complete packet without Adapter header
 
|-
 
|-
Line 1,208: Line 1,208:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| Complete packet including Transport header
 
| Complete packet including Transport header
 
|-
 
|-
Line 1,220: Line 1,220:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| Complete packet including Transport header
 
| Complete packet including Transport header
 
|-
 
|-
Line 1,232: Line 1,232:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| Complete packet including Transport header
 
| Complete packet including Transport header
 
|-
 
|-
Line 1,244: Line 1,244:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| Complete packet including Transport header
 
| Complete packet including Transport header
 
|-
 
|-
Line 1,256: Line 1,256:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| Complete packet including Transport header
 
| Complete packet including Transport header
 
|-
 
|-
Line 1,268: Line 1,268:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| Complete packet including Transport header
 
| Complete packet including Transport header
 
|-
 
|-

Revision as of 01:20, 24 April 2018

Return to Unit Reference


Description


Ultibo IPv6 (Internet Protocol version 6) unit

To be documented

Constants



IPv6 specific constants IP6_TRANSPORT_*
IP6_TRANSPORT_NAME = 'IPV6';  


IPv6 header IP6_HEADER_*
MIN_IP6_PACKET = 40; Not Counting Adapter Header
MAX_IP6_PACKET = 1500; Not Counting Adapter Header
 
MAX_FRAG_LIFE = 32000; Only wait 32 seconds for the rest of the packet
 
IP6_HEADER_SIZE = 40; SizeOf(TIP6Header); Does Not Allow for Extensions


IPv6 extension header IP6_HEADER_*
See: https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers
 
IP6_HEADER_HOP = 0; Hop-by-hop option header
IP6_HEADER_TCP = 6; Next header is a TCP segment (The payload)
IP6_HEADER_UDP = 17; Next header is a UDP message (The payload)
IP6_HEADER_IPV6 = 41; Next header is a IPv6 packet (IPv6 Encapsulation) (The payload)
IP6_HEADER_ROUTING = 43; Next header is a Routing header
IP6_HEADER_FRAGMENT = 44; Next header is a Fragmentation/reassembly header
IP6_HEADER_GRE = 47; Next header is a GRE header
IP6_HEADER_ESP = 50; Next header is a Encapsulating security payload
IP6_HEADER_AUTH = 51; Next header is a Authentication header
IP6_HEADER_ICMP = 58; Next header is a ICMP for IPv6 message
IP6_HEADER_NONE = 59; There is no next header (Do not process payload)
IP6_HEADER_DEST = 60; Next header is a Destination options header
IP6_HEADER_SCTP = 132; Next header is a SCTP message (The payload)
IP6_HEADER_MOBILITY = 135; Next header is a Mobility header
 
IP6_MTU = MAX_IP6_PACKET;  


Type definitions



IPv6 header

PIP6Header = ^TIP6Header;

TIP6Header = packed record

Note: 40 Bytes
VersionClassLabel:LongWord; Version (4 bits)(Always 6)/Traffic Class (8 bits)/Flow Label (20 bits)
PayloadLength:Word; The size of the payload in octets, including any extension headers (The length is set to zero when a Hop-by-Hop extension header carries a Jumbo Payload option)
NextHeader:Byte; Specifies the type of the next header (When extension headers are present in the packet this field indicates which extension header follows)
HopLimit:Byte; This value is decremented by one at each intermediate node visited by the packet. When the counter reaches 0 the packet is discarded (Replaces the time to live field of IPv4)
SourceIP:TIn6Addr; Source IP
DestIP:TIn6Addr; Destination IP

IPv6 extension header

PIP6ExtensionHeader = ^TIP6ExtensionHeader;

TIP6ExtensionHeader = packed record

Note: 2 Bytes (Common Header of all Extension Headers)
NextHeader:Byte; Specifies the type of the next header (If zero discard the packet)
ExtensionLength:Byte;  

IPv6 pseudo

PIP6Pseudo = ^TIP6Pseudo;

TIP6Pseudo = packed record

Note: ?? Bytes (Used by UDP/TCP Checksum)
SourceIP:TIn6Addr; Source IP
DestIP:TIn6Addr; Destination IP
Mbz:Byte; Must Be Zero
Protocol:Byte; IP6 Protocol Type IPPROTO_UDP, IPPROTO_TCP etc
Length:Word; Length of UDP/TCP Header and Data

IPv6 fragment

PIP6Fragment = ^TIP6Fragment;

TIP6Fragment = record

Note: ?? Bytes (Used by Fragment Buffer)
Offset:LongWord; Offset of this Fragment in the Packet
Size:Word; Size of this Fragment
Prev:PIP6Fragment; Pointer to Prev Fragment
Next:PIP6Fragment; Pointer to Next Fragment

IPv6 packet

PIP6Packet = ^TIP6Packet;

TIP6Packet = record

Note: ?? Bytes (Used by Fragment Buffer)
Lock:TMutexHandle; Packet Lock
 
Id:LongWord; IP6 Id
Dest:TIn6Addr; IP6 Dest
Source:TIn6Addr; IP6 Source
 
Data:Pointer; Pointer to Data
Timeout:Int64; Packet Timeout
Total:Word; IP Total Length
Length:Word; IP Header Length
Received:Word; Received Bytes
Prev:PIP6Packet; Pointer to Prev Packet
Next:PIP6Packet; Pointer to Next Packet
First:PIP6Fragment; Pointer to First Fragment
Last:PIP6Fragment; Pointer to Last Fragment


Class definitions



IPv6 buffer

TIP6Buffer = class(TTransportBufferEx)

Note: Different to Socket Buffer.
 
constructor Create(ATransport:TNetworkTransport);  
destructor Destroy; override;  
private
FFirst:PIP6Packet;  
FLast:PIP6Packet;  
 
function GetFragment(APacket:PIP6Packet; AOffset:LongWord; ASize:Word):PIP6Fragment;  
function AddFragment(APacket:PIP6Packet; AOffset:LongWord; ASize:Word):PIP6Fragment;  
function RemoveFragment(APacket:PIP6Packet):Boolean;  
procedure FlushFragments(APacket:PIP6Packet);  
public
function GetPacket(AId:LongWord; const ASource,ADest:TIn6Addr; ALock:Boolean):PIP6Packet;  
function AddPacket(AId:LongWord; const ASource,ADest:TIn6Addr; ALock:Boolean):PIP6Packet;  
function RemovePacket(APacket:PIP6Packet):Boolean;  
function UnlockPacket(APacket:PIP6Packet):Boolean;  
procedure FlushPackets(All:Boolean);  
 
function PutHeader(APacket:PIP6Packet; ABuffer:Pointer; ALength:Word):Boolean;  
function PutFragment(APacket:PIP6Packet; ABuffer:Pointer; AOffset,ASize,AFlags:Word):Boolean;  

IPv6 transport adapter

TIP6TransportAdapter = class(TTransportAdapter)

constructor Create;  
private
Address:TIn6Addr;  
Netmask:TIn6Addr;  
Gateway:TIn6Addr;  
Network:TIn6Addr;  
Directed:TIn6Addr;  
 
Server:TIn6Addr; DHCP Server
LeaseTime:LongWord; DHCP Lease Time
RetryTime:Int64; DHCP Retry Time
ExpiryTime:Int64; DHCP Expiry Time
RenewalTime:Int64; DHCP Renewal Time
RebindingTime:Int64; DHCP Rebinding Time
 
ConfigDefault:Word; BOOTP/DHCP/RARP/STATIC/PSEUDO/LOOPBACK
ConfigAddress:TIn6Addr;  
ConfigNetmask:TIn6Addr;  
ConfigGateway:TIn6Addr;  
ConfigServer:TIn6Addr;  

IPv6 transport binding

TIP6TransportBinding = class(TTransportBinding)

constructor Create;  
public
Address:TIn6Addr;  
Netmask:TIn6Addr;  
Gateway:TIn6Addr;  
Network:TIn6Addr;  
Directed:TIn6Addr;  
 
Server:TIn6Addr; DHCP Server
LeaseTime:LongWord; DHCP Lease Time
RetryTime:Int64; DHCP Retry Time
ExpiryTime:Int64; DHCP Expiry Time
RenewalTime:Int64; DHCP Renewal Time
RebindingTime:Int64; DHCP Rebinding Time
 
ConfigDefault:Word; BOOTP/DHCP/RARP/STATIC/PSEUDO/LOOPBACK
ConfigAddress:TIn6Addr;  
ConfigNetmask:TIn6Addr;  
ConfigGateway:TIn6Addr;  
ConfigServer:TIn6Addr;  

IPv6 transport protocol

TIP6TransportProtocol = class(TTransportProtocol)

private
 
public
 

IPv6 transport filter

TIP6TransportFilter = class(TTransportFilter)

private
 
public
 

IPv6 transport configuration

TIP6TransportConfig = class(TTransportConfig)

private
 
public
 

IPv6 transport

TIP6Transport = class(TNetworkTransport)

constructor Create(AManager:TTransportManager; const AName:String);  
destructor Destroy; override;  
private
FNextIP6Id:Word;  
FNextIP6Lock:TMutexHandle;  
 
FFragments:TIP6Buffer;  
 
FHosts:TNetworkList;  
FServs:TNetworkList;  
FProtos:TNetworkList;  
FRoutes:TNetworkList;  
FNetworks:TNetworkList;  
FAddresses:TNetworkList;  
 
FDefaultAddress:TIn6Addr;  
FLoopbackAddress:TIn6Addr;  
FBroadcastAddress:TIn6Addr;  
FNameservers:TIP6Nameservers; (Part of TNetworkList)
FNameserverLock:TMutexHandle;  
 
FDefaultHopLimit:LongWord;  
FAutoRelease:Boolean;  
 
function PacketHandler(AHandle:THandle; ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean;  
function FragmentHandler(ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean;  
 
function CheckFragment(ABuffer:Pointer):Boolean;  
 
function GetNextIP6Id(AIncrement:Boolean):Word;  
 
function GetIP6Nameserver(ACount:LongWord):TIn6Addr;  
 
function GetAdapterConfigType(const AName:String):Word;  
function GetAdapterConfigAddress(const AName:String):TIn6Addr;  
function GetAdapterConfigNetmask(const AName:String):TIn6Addr;  
function GetAdapterConfigGateway(const AName:String):TIn6Addr;  
function GetAdapterConfigServer(const AName:String):TIn6Addr;  
protected
function FilterPacket(ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean; override;  
function ForwardPacket(AAdapter:TTransportAdapter; ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean; override;  
public
property Nameservers:TIP6Nameservers read FNameservers;  
 
property DefaultHopLimit:LongWord read FDefaultHopLimit write FDefaultHopLimit;  
 
property AutoRelease:Boolean read FAutoRelease write FAutoRelease;  
 
function AddAdapter(AAdapter:TNetworkAdapter; AConfigType:Word; AAddress,ANetmask,AGateway,AServer:Pointer):Boolean; override;  
function RemoveAdapter(AAdapter:TNetworkAdapter):Boolean; override;  
 
function AddProtocol(AProtocol:Word; APacketHandler:TTransportPacketHandler; AControlHandler:TTransportControlHandler):THandle; override;  
function RemoveProtocol(AHandle:THandle; AProtocol:Word):Boolean; override;  
 
function AddFilter(AProtocol:Word; AFilterHandler:TTransportFilterHandler):THandle; override;  
function RemoveFilter(AHandle:THandle; AProtocol:Word):Boolean; override;  
 
function AddConfig(AConfigType:Word; AConfigAuto:Boolean; AConfigHandler:TTransportConfigHandler):THandle; override;  
function RemoveConfig(AHandle:THandle; AConfigType:Word):Boolean; override;  
 
function SendPacket(ASocket:TTransportSocket; ASource,ADest:Pointer; APacket:PPacketFragment; ASize,AFlags:Integer):Integer; override;  
function SendControl(ASource,ADest:Pointer; AProtocol,ACommand,ACode:Word; AAddress,AData:Pointer; ASize:Integer):Boolean; override;  
 
function GetSockOpt(ASocket:TTransportSocket; ALevel,AOptName:Integer; AOptValue:PChar; var AOptLength:Integer):Integer; override;  
function SetSockOpt(ASocket:TTransportSocket; ALevel,AOptName:Integer; AOptValue:PChar; AOptLength:Integer):Integer; override;  
 
function StartTransport:Boolean; override;  
function StopTransport:Boolean; override;  
function ProcessTransport:Boolean; override;  
 
function BindTransport(AAdapter:TNetworkAdapter):Boolean; override;  
function UnbindTransport(AAdapter:TNetworkAdapter):Boolean; override;  
 
function AddNameserver(const AAddress:TIn6Addr):Boolean;  
function RemoveNameserver(const AAddress:TIn6Addr):Boolean;  
 
function GetHostByName(const AName:String; ALock:Boolean):TIP6HostEntry;  
function GetHostByAddress(const AAddress:TIn6Addr; ALock:Boolean):TIP6HostEntry;  
function GetHostByNext(APrevious:TIP6HostEntry; ALock,AUnlock:Boolean):TIP6HostEntry;  
function AddHost(const AAddress:TIn6Addr; const AName:String; AType:Word; ALock:Boolean):TIP6HostEntry;  
function RemoveHost(const AAddress:TIn6Addr):Boolean;  
procedure FlushHosts(All:Boolean);  
 
function GetRouteByAddress(const AAddress:TIn6Addr; ALock:Boolean; AState:LongWord):TIP6RouteEntry;  
function GetRouteByNetwork(const ANetwork,AAddress:TIn6Addr; ALock:Boolean; AState:LongWord):TIP6RouteEntry;  
function GetRouteByNext(APrevious:TIP6RouteEntry; ALock,AUnlock:Boolean; AState:LongWord):TIP6RouteEntry;  
function AddRoute(const ANetwork,ANetmask,AGateway,AAddress:TIn6Addr; AType:Word; ALock:Boolean; AState:LongWord):TIP6RouteEntry;  
function RemoveRoute(const ANetwork,AAddress:TIn6Addr):Boolean;  
procedure FlushRoutes(All:Boolean);  
 
function GetAddressByAddress(const AAddress:TIn6Addr; ALock:Boolean; AState:LongWord):TIP6AddressEntry;  
function GetAddressByNext(APrevious:TIP6AddressEntry; ALock,AUnlock:Boolean; AState:LongWord):TIP6AddressEntry;  
function AddAddress(const AAddress:TIn6Addr; AType:Word; AAdapter:TNetworkAdapter; ALock:Boolean; AState:LongWord):TIP6AddressEntry;  
function RemoveAddress(const AAddress:TIn6Addr):Boolean;  
procedure FlushAddresses(All:Boolean);  
 
function GetNetworkByName(const AName:String; ALock:Boolean):TIP6NetworkEntry;  
function GetNetworkByAddress(const ANetwork:TIn6Addr; ALock:Boolean):TIP6NetworkEntry;  
function AddNetwork(const AName:String; const ANetwork:TIn6Addr; ALock:Boolean):TIP6NetworkEntry;  
function RemoveNetwork(const AName:String):Boolean;  
 
function GetServByName(const AName,AProtocol:String; ALock:Boolean):TIP6ServEntry;  
function GetServByPort(APort:Word; const AProtocol:String; ALock:Boolean):TIP6ServEntry;  
function AddServ(const AName,AProtocol:String; APort:Word; ALock:Boolean):TIP6ServEntry;  
function RemoveServ(const AName,AProtocol:String):Boolean;  
 
function GetProtoByName(const AName:String; ALock:Boolean):TIP6ProtoEntry;  
function GetProtoByNumber(ANumber:Word; ALock:Boolean):TIP6ProtoEntry;  
function AddProto(const AName:String; ANumber:Word; ALock:Boolean):TIP6ProtoEntry;  
function RemoveProto(const AName:String):Boolean;  
 
function CompareLocal(const AAddress:TIn6Addr):Boolean;  
function CompareDefault(const AAddress:TIn6Addr):Boolean;  
function CompareLoopback(const AAddress:TIn6Addr):Boolean;  
function CompareDirected(const AAddress:TIn6Addr):Boolean;  
function CompareBroadcast(const AAddress:TIn6Addr):Boolean;  
function CompareMulticast(const AAddress:TIn6Addr):Boolean;  
function CompareAddress(const AAddress1,AAddress2:TIn6Addr):Boolean;  
function CompareSubnet(const AAddress,ANetwork,ANetmask:TIn6Addr):Boolean;  

IPv6 state

TIP6State = class(TTransportState)

constructor Create;  
private
FLocalAddress:TIn6Addr;  
FRemoteAddress:TIn6Addr;  
 
procedure SetLocalAddress(const ALocalAddress:TIn6Addr);  
procedure SetRemoteAddress(const ARemoteAddress:TIn6Addr);  
public
property LocalAddress:TIn6Addr read FLocalAddress write SetLocalAddress;  
property RemoteAddress:TIn6Addr read FRemoteAddress write SetRemoteAddress;  

IPv6 options

TIP6Options = class(TTransportOptions)

constructor Create;  
destructor Destroy; override;  
private
FHopLimit:Byte; Hop Limit
 
procedure SetHopLimit(AHopLimit:Byte);  
public
property HopLimit:Byte read FHopLimit write SetHopLimit;  

IPv6 host entry

TIP6HostEntry = class(THostEntry)

constructor Create;  
private
FAddresses:array[0..MAX_HOST_ALIASES - 1] of TIn6Addr;  
 
function GetAddress:TIn6Addr;  
procedure SetAddress(const AAddress:TIn6Addr);  
function GetAddresses(Index:Integer):TIn6Addr;  
public
property Address:TIn6Addr read GetAddress write SetAddress;  
property Addresses[Index:Integer]:TIn6Addr read GetAddresses;  
 
function FindAddress(const AAddress:TIn6Addr):Boolean;  
 
function AddAddress(const AAddress:TIn6Addr):Boolean;  
function RemoveAddress(const AAddress:TIn6Addr):Boolean;  

IPv6 route entry

TIP6RouteEntry = class(TRouteEntry)

constructor Create;  
private
FNetwork:TIn6Addr;  
FNetmask:TIn6Addr;  
FGateway:TIn6Addr;  
FAddress:TIn6Addr;  
 
procedure SetNetwork(const ANetwork:TIn6Addr);  
procedure SetNetmask(const ANetmask:TIn6Addr);  
procedure SetGateway(const AGateway:TIn6Addr);  
procedure SetAddress(const AAddress:TIn6Addr);  
public
property Network:TIn6Addr read FNetwork write SetNetwork;  
property Netmask:TIn6Addr read FNetmask write SetNetmask;  
property Gateway:TIn6Addr read FGateway write SetGateway;  
property Address:TIn6Addr read FAddress write SetAddress;  

IPv6 address entry

TIP6AddressEntry = class(TAddressEntry)

Note: Used for secondary addresses.
 
constructor Create;  
private
FAddress:TIn6Addr;  
 
procedure SetAddress(const AAddress:TIn6Addr);  
public
property Address:TIn6Addr read FAddress write SetAddress;  

IPv6 network entry

TIP6NetworkEntry = class(TNetworkEntry)

constructor Create;  
private
FNetwork:TIn6Addr;  
 
procedure SetNetwork(const ANetwork:TIn6Addr);  
public
property Network:TIn6Addr read FNetwork write SetNetwork;  

IPv6 service entry

TIP6ServEntry = class(TServEntry)

constructor Create;  
private
 
public
 

IPv6 protocol entry

TIP6ProtoEntry = class(TProtoEntry)

constructor Create;  
private
 
public
 


Public variables


None defined

Function declarations



Initialization functions

procedure IP6Init;
Description: To be documented
Note None documented


IPv6 functions

function CheckIP6(ABuffer:Pointer):Boolean;
Description: Verify that the packet is a valid IP6 packet
Buffer Complete packet without Adapter header


function GetIP6Protocol(ABuffer:Pointer):Byte;
Description: To be documented
Buffer Complete packet including Transport header


function GetIP6HeaderOffset(ABuffer:Pointer):Word;
Description: Return Start of the IP6 Header (Start of Packet)
Buffer Complete packet including Transport header


function GetIP6HeaderLength(ABuffer:Pointer):Word;
Description: Return Size of IP6 Header (Including Options)
Buffer Complete packet including Transport header


function GetIP6DataOffset(ABuffer:Pointer):Word;
Description: Return Start of IP6 Packet Data (Length of IP6 Header)
Buffer Complete packet including Transport header


function GetIP6DataLength(ABuffer:Pointer):Word;
Description: Return Size of IP6 Packet Data (IP6 TotalLength - IP6 Header)
Buffer Complete packet including Transport header


function ChecksumIP6(ABuffer:Pointer; AOffset,ALength:Word):Word;
Description: Validate the IP6 Header and Options Checksum on Receive
Buffer Complete packet including Transport header


Return to Unit Reference