Difference between revisions of "TIPTransport"

From Ultibo.org
Jump to: navigation, search
(Created page with "Return to Unit IP __TOC__ === Description === ---- ''To be documented'' === Class definitions === ---- <div class="toccolours mw-collapsible mw-collapsed" s...")
(No difference)

Revision as of 03:03, 22 May 2018

Return to Unit IP


Description


To be documented

Class definitions



TIPTransport = class(TNetworkTransport)

constructor Create(AManager:TTransportManager; const AName:String);  
destructor Destroy; override;  
private
FNextIPId:Word;  
FNextIPLock:TMutexHandle;  
 
FARP:TARPTransport;  
FRARP:TRARPTransport;  
FFragments:TIPBuffer;  
 
FHosts:TNetworkList;  
FServs:TNetworkList;  
FProtos:TNetworkList;  
FRoutes:TNetworkList;  
FNetworks:TNetworkList;  
FAddresses:TNetworkList;  
 
FNameservers:TIPNameservers; (Part of TNetworkList)
FNameserverLock:TMutexHandle;  
 
FForwarding:LongWord;  
FDefaultTTL: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 GetNextIPId(AIncrement:Boolean):Word;  
 
function GetIPNameserver(ACount:LongWord):TInAddr;  
 
function GetAdapterConfigType(const AName:String):Word;  
function GetAdapterConfigAddress(const AName:String):TInAddr;  
function GetAdapterConfigNetmask(const AName:String):TInAddr;  
function GetAdapterConfigGateway(const AName:String):TInAddr;  
function GetAdapterConfigServer(const AName:String):TInAddr;  
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:TIPNameservers read FNameservers;  
 
property Forwarding:LongWord read FForwarding write FForwarding;  
property DefaultTTL:LongWord read FDefaultTTL write FDefaultTTL;  
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:TInAddr):Boolean;  
function RemoveNameserver(const AAddress:TInAddr):Boolean;  
 
function GetHostByName(const AName:String; ALock:Boolean):TIPHostEntry;  
function GetHostByAddress(const AAddress:TInAddr; ALock:Boolean):TIPHostEntry;  
function GetHostByNext(APrevious:TIPHostEntry; ALock,AUnlock:Boolean):TIPHostEntry;  
function AddHost(const AAddress:TInAddr; const AName:String; AType:Word; ALock:Boolean):TIPHostEntry;  
function RemoveHost(const AAddress:TInAddr):Boolean;  
procedure FlushHosts(All:Boolean);  
 
function GetRouteByAddress(const AAddress:TInAddr; ALock:Boolean; AState:LongWord):TIPRouteEntry;  
function GetRouteByNetwork(const ANetwork,AAddress:TInAddr; ALock:Boolean; AState:LongWord):TIPRouteEntry;  
function GetRouteByNext(APrevious:TIPRouteEntry; ALock,AUnlock:Boolean; AState:LongWord):TIPRouteEntry;  
function AddRoute(const ANetwork,ANetmask,AGateway,AAddress:TInAddr; AType:Word; ALock:Boolean; AState:LongWord):TIPRouteEntry;  
function RemoveRoute(const ANetwork,AAddress:TInAddr):Boolean;  
procedure FlushRoutes(All:Boolean);  
 
function GetAddressByAddress(const AAddress:TInAddr; ALock:Boolean; AState:LongWord):TIPAddressEntry;  
function GetAddressByNext(APrevious:TIPAddressEntry; ALock,AUnlock:Boolean; AState:LongWord):TIPAddressEntry;  
function AddAddress(const AAddress:TInAddr; AAdapter:TNetworkAdapter; AType:Word; ALock:Boolean; AState:LongWord):TIPAddressEntry;  
function RemoveAddress(const AAddress:TInAddr):Boolean;  
procedure FlushAddresses(All:Boolean);  
 
function GetNetworkByName(const AName:String; ALock:Boolean):TIPNetworkEntry;  
function GetNetworkByAddress(const ANetwork:TInAddr; ALock:Boolean):TIPNetworkEntry;  
function AddNetwork(const AName:String; const ANetwork:TInAddr; ALock:Boolean):TIPNetworkEntry;  
function RemoveNetwork(const AName:String):Boolean;  
 
function GetServByName(const AName,AProtocol:String; ALock:Boolean):TIPServEntry;  
function GetServByPort(APort:Word; const AProtocol:String; ALock:Boolean):TIPServEntry;  
function AddServ(const AName,AProtocol:String; APort:Word; ALock:Boolean):TIPServEntry;  
function RemoveServ(const AName,AProtocol:String):Boolean;  
 
function GetProtoByName(const AName:String; ALock:Boolean):TIPProtoEntry;  
function GetProtoByNumber(ANumber:Word; ALock:Boolean):TIPProtoEntry;  
function AddProto(const AName:String; ANumber:Word; ALock:Boolean):TIPProtoEntry;  
function RemoveProto(const AName:String):Boolean;  
 
function CompareLocal(const AAddress:TInAddr):Boolean;  
function CompareDefault(const AAddress:TInAddr):Boolean;  
function CompareLoopback(const AAddress:TInAddr):Boolean;  
function CompareDirected(const AAddress:TInAddr):Boolean;  
function CompareBroadcast(const AAddress:TInAddr):Boolean;  
function CompareMulticast(const AAddress:TInAddr):Boolean;  
function CompareAddress(const AAddress1,AAddress2:TInAddr):Boolean;  
function CompareSubnet(const AAddress,ANetwork,ANetmask:TInAddr):Boolean;  


Function declarations



constructor TIPTransport.Create(AManager:TTransportManager; const AName:String);
Description: To be documented
Note None documented


destructor TIPTransport.Destroy;
Description: To be documented
Note None documented


function TIPTransport.PacketHandler(AHandle:THandle; ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean;
Description: Process a packet received by an Adapter
Handle The Handle of the Transport Adapter the packet was received from
Source The source hardware address of the received packet (Set by Adapter)
Dest The destination hardware address of the received packet (Set by Adapter)
Packet The received packet (The complete packet without Adapter header)
Size The size of the received packet in bytes
Broadcast True if the destination address is a broadcast address
Note The first protocol handler to accept the packet causes processing to cease


function TIPTransport.FragmentHandler(ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean;
Description: Process a received fragment by adding it to the buffer and if completed process the packet
Source The source IP address of the received fragment (Set by Packet Handler)
Dest The destination IP address of the received fragment (Set by Packet Handler)
Packet The received fragment (The complete packet without Adapter header)
Size The size of the received fragment in bytes
Broadcast True if the destination address is a broadcast address


function TIPTransport.CheckFragment(ABuffer:Pointer):Boolean;
Description: Check if a packet is a fragment and return True if it is
Buffer The packet to check (The complete packet without Adapter header)


function TIPTransport.GetNextIPId(AIncrement:Boolean):Word;
Description: Get the next IP packet id number
Increment If True increment the next id


function TIPTransport.GetIPNameserver(ACount:LongWord):TInAddr;
Description: Get the nameserver address from the network settings
Note None documented


function TIPTransport.GetAdapterConfigType(const AName:String):Word;
Description: Get the adapter config type from the network settings
Note None documented


function TIPTransport.GetAdapterConfigAddress(const AName:String):TInAddr;
Description: Get the adapter address from the network settings
Note None documented


function TIPTransport.GetAdapterConfigNetmask(const AName:String):TInAddr;
Description: Get the adapter netmask from the network settings
Note None documented


function TIPTransport.GetAdapterConfigGateway(const AName:String):TInAddr;
Description: Get the adapter gateway from the network settings
Note None documented


function TIPTransport.GetAdapterConfigServer(const AName:String):TInAddr;
Description: Get the adapter server from the network settings
Note None documented


function TIPTransport.FilterPacket(ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean;
Description: Filter a received packet
Source The source IP address of the received fragment (Set by Packet or Fragment Handler)
Dest The destination IP address of the received fragment (Set by Packet or Fragment Handler)
Packet The received packet (The complete packet without Adapter header)
Size The size of the received packet in bytes
Broadcast True if the destination address is a broadcast address
Note If Filter returns True the Packet should be discarded

The first filter handler to reject the packet causes filtering to cease


function TIPTransport.ForwardPacket(AAdapter:TTransportAdapter; ASource,ADest,APacket:Pointer; ASize:Integer; ABroadcast:Boolean):Boolean;
Description: Forward a received packet
Adapter The adapter the packet was received on
Source The source IP address of the received fragment (Set by Packet Handler)
Dest The destination IP address of the received fragment (Set by Packet Handler)
Packet The received packet (The complete packet without Adapter header)
Size The size of the received packet in bytes
Broadcast True if the destination address is a broadcast address
Note Caller must hold Adapter lock


function TIPTransport.AddAdapter(AAdapter:TNetworkAdapter; AConfigType:Word; AAddress,ANetmask,AGateway,AServer:Pointer):Boolean;
Description: Add an adapter to this transport
Adapter The adapter to add
ConfigType The configuration type to use for configuring the adapter (eg CONFIG_TYPE_AUTO)
Address The transport address to use for this adapter (or nil if supplied during configuration)
Netmask The transport netmask to use for this adapter (or nil if supplied during configuration)
Gateway The transport default gateway to use for this adapter (or nil if supplied during configuration)
Server The transport configuration server to use for this adapter (or nil if supplied during configuration)


function TIPTransport.RemoveAdapter(AAdapter:TNetworkAdapter):Boolean;
Description: Remove an adapter from this transport
Adapter The adapter to remove


function TIPTransport.AddProtocol(AProtocol:Word; APacketHandler:TTransportPacketHandler; AControlHandler:TTransportControlHandler):THandle;
Description: Add a protocol to this transport
Protocol The protocol type to add
PacketHandler Packet handler to call on matching protocol type
ControlHandler Control handler to call on error condition


function TIPTransport.RemoveProtocol(AHandle:THandle; AProtocol:Word):Boolean;
Description: Remove a protocol from this transport
Handle Handle of the protocol to remove
Protocol The protocol type to remove


function TIPTransport.AddFilter(AProtocol:Word; AFilterHandler:TTransportFilterHandler):THandle;
Description: Add a filter to this transport
Protocol The protocol type of the filter to add
FilterHandler Filter handler to call on matching protocol type


function TIPTransport.RemoveFilter(AHandle:THandle; AProtocol:Word):Boolean;
Description: Remove a filter from this transport
Handle Handle of the filter to remove
Protocol The protocol type of the filter to remove


function TIPTransport.AddConfig(AConfigType:Word; AConfigAuto:Boolean; AConfigHandler:TTransportConfigHandler):THandle;
Description: Add a config to this transport
ConfigType The config type to add
ConfigAuto True if this config supports auto configuration type
ConfigHandler Config handler to call on matching config type


function TIPTransport.RemoveConfig(AHandle:THandle; AConfigType:Word):Boolean;
Description: Remove a config from this transport
Handle Handle of the config to remove
ConfigType The config type to remove


function TIPTransport.SendPacket(ASocket:TTransportSocket; ASource,ADest:Pointer; APacket:PPacketFragment; ASize,AFlags:Integer):Integer;
Description: Send a Packet by adding the Transport Header and other details to the Data
Socket The socket to use for sending the packet
Source The source IP address of the packet
Dest The destination IP address of the packet
Packet The packet data to send
Size The size of the packet data in bytes
Flags Any transport specific flags for sending
Note Caller must hold the Socket lock


function TIPTransport.SendControl(ASource,ADest:Pointer; AProtocol,ACommand,ACode:Word; AAddress,AData:Pointer; ASize:Integer):Boolean;
Description: To be documented
Note The first control handler to accept the packet causes sending to cease


function TIPTransport.GetSockOpt(ASocket:TTransportSocket; ALevel,AOptName:Integer; AOptValue:PChar; var AOptLength:Integer):Integer;
Description: BSD compatible Get Socket Option
Socket The socket to get the option from
Level The protocol level for the option
OptName The name of the option to get
OptValue The value of the option
OptLength The length of the option
Note Caller must hold the Socket lock


function TIPTransport.SetSockOpt(ASocket:TTransportSocket; ALevel,AOptName:Integer; AOptValue:PChar; AOptLength:Integer):Integer;
Description: BSD compatible Set Socket Option
Socket The socket to set the option for
Level The protocol level for the option
OptName The name of the option to set
OptValue The value of the option
OptLength The length of the option
Note Caller must hold the Socket lock


function TIPTransport.StartTransport:Boolean;
Description: Start this transport ready for sending and receiving
Note None documented


function TIPTransport.StopTransport:Boolean;
Description: Stop this transport ready for removal
Note None documented


function TIPTransport.ProcessTransport:Boolean;
Description: Process periodic tasks for this transport
Note None documented


function TIPTransport.BindTransport(AAdapter:TNetworkAdapter):Boolean;
Description: Bind this transport to an adapter if appropriate
Adapter The adapter to bind to


function TIPTransport.UnbindTransport(AAdapter:TNetworkAdapter):Boolean;
Description: Unbind this transport from an adapter if appropriate
Adapter The adapter to unbind from


function TIPTransport.AddNameserver(const AAddress:TInAddr):Boolean;
Description: Add a nameserver IP address to the list of available nameservers
Address The IP address to add


function TIPTransport.RemoveNameserver(const AAddress:TInAddr):Boolean;
Description: Remove a nameserver IP address from the list of available nameservers
Address The IP address to remove


function TIPTransport.GetHostByName(const AName:String; ALock:Boolean):TIPHostEntry;
Description: Find the name in the host cache
Name The name to find
Lock If True then lock the found entry before returning


function TIPTransport.GetHostByAddress(const AAddress:TInAddr; ALock:Boolean):TIPHostEntry;
Description: Find the IP address in the host cache
Address The IP address to find
Lock If True then lock the found entry before returning


function TIPTransport.GetHostByNext(APrevious:TIPHostEntry; ALock,AUnlock:Boolean):TIPHostEntry;
Description: To be documented
Note None documented


function TIPTransport.AddHost(const AAddress:TInAddr; const AName:String; AType:Word; ALock:Boolean):TIPHostEntry;
Description: Add an IP address and name to the host cache
Address The IP address of the entry to add
Name The name of the entry to add
Type The type of the added entry (eg HOST_TYPE_DYNAMIC)
Lock If True then lock the added entry before returning


function TIPTransport.RemoveHost(const AAddress:TInAddr):Boolean;
Description: Remove an IP address from the host cache
Address The IP address to remove


procedure TIPTransport.FlushHosts(All:Boolean);
Description: Flush hosts from the host cache
All If True flush all hosts, otherwise flush expired hosts


function TIPTransport.GetRouteByAddress(const AAddress:TInAddr; ALock:Boolean; AState:LongWord):TIPRouteEntry;
Description: Find the IP route in the route cache
Address The IP address to find the route for
Lock If True then lock the found entry before returning


function TIPTransport.GetRouteByNetwork(const ANetwork,AAddress:TInAddr; ALock:Boolean; AState:LongWord):TIPRouteEntry;
Description: Find the IP network and address in the route cache
Network The network address of the entry to find
Address The IP address of the entry to find
Lock If True then lock the found entry before returning


function TIPTransport.GetRouteByNext(APrevious:TIPRouteEntry; ALock,AUnlock:Boolean; AState:LongWord):TIPRouteEntry;
Description: To be documented
Note None documented


function TIPTransport.AddRoute(const ANetwork,ANetmask,AGateway,AAddress:TInAddr; AType:Word; ALock:Boolean; AState:LongWord):TIPRouteEntry;
Description: Add an IP route to the route cache
Network The network address of the entry to add
Netmask The netmask of the entry to add
Gateway The gateway of the entry to add
Address The IP address of the entry to add
Type The type of the added entry (eg ROUTE_TYPE_DYNAMIC)
Lock If True then lock the added entry before returning


function TIPTransport.RemoveRoute(const ANetwork,AAddress:TInAddr):Boolean;
Description: Remove an IP route from the route cache
Network The network address of the entry to remove
Address The IP address of the entry to remove


procedure TIPTransport.FlushRoutes(All:Boolean);
Description: Flush routes from the route cache
All If True flush all routes, otherwise flush expired routes


function TIPTransport.GetAddressByAddress(const AAddress:TInAddr; ALock:Boolean; AState:LongWord):TIPAddressEntry;
Description: Find the IP address in the address cache
Address The IP address to find
Lock If True then lock the found entry before returning


function TIPTransport.GetAddressByNext(APrevious:TIPAddressEntry; ALock,AUnlock:Boolean; AState:LongWord):TIPAddressEntry;
Description: To be documented
Note None documented


function TIPTransport.AddAddress(const AAddress:TInAddr; AAdapter:TNetworkAdapter; AType:Word; ALock:Boolean; AState:LongWord):TIPAddressEntry;
Description: Add an IP address to the address cache
Address The IP address to add
Adapter The adapter the address is on
Type The type of the added entry (eg ADDRESS_TYPE_PRIMARY)
Lock If True then lock the added entry before returning
Note The handling of Secondary addresses should probably change in future to use a Binding type mechanism (eg AddBinding/RemoveBinding)


function TIPTransport.RemoveAddress(const AAddress:TInAddr):Boolean;
Description: Remove an IP address from the address cache
Address The IP address to remove


procedure TIPTransport.FlushAddresses(All:Boolean);
Description: Flush addresses from the adresses cache
All If True flush all addresses, otherwise flush invalid addresses


function TIPTransport.GetNetworkByName(const AName:String; ALock:Boolean):TIPNetworkEntry;
Description: Find the name in the network cache
Name The name to find
Lock If True then lock the found entry before returning


function TIPTransport.GetNetworkByAddress(const ANetwork:TInAddr; ALock:Boolean):TIPNetworkEntry;
Description: Find the network address in the network cache
Network The network address to find
Lock If True then lock the found entry before returning


function TIPTransport.AddNetwork(const AName:String; const ANetwork:TInAddr; ALock:Boolean):TIPNetworkEntry;
Description: Add a network address and name to the network cache
Name The name of the entry to add
Network The network address of the entry to add
Lock If True then lock the added entry before returning


function TIPTransport.RemoveNetwork(const AName:String):Boolean;
Description: Remove a network from the network cache
Name The name of the network to remove


function TIPTransport.GetServByName(const AName,AProtocol:String; ALock:Boolean):TIPServEntry;
Description: Find the name in the service cache
Name The name to find
Protocol The protocol to find
Lock If True then lock the found entry before returning


function TIPTransport.GetServByPort(APort:Word; const AProtocol:String; ALock:Boolean):TIPServEntry;
Description: Find the port in the service cache
Port The port to find
Protocol The protocol to find
Lock If True then lock the found entry before returning


function TIPTransport.AddServ(const AName,AProtocol:String; APort:Word; ALock:Boolean):TIPServEntry;
Description: Add a service to the service cache
Name The name of the entry to add
Protocol The protocol of the entry to add
Port The port of the entry to add
Lock If True then lock the added entry before returning


function TIPTransport.RemoveServ(const AName,AProtocol:String):Boolean;
Description: Remove a service from the service cache
Name The name of the entry to remove
Protocol The protocol of the entry to remove


function TIPTransport.GetProtoByName(const AName:String; ALock:Boolean):TIPProtoEntry;
Description: Find the name in the protocol cache
Name The name to find
Lock If True then lock the found entry before returning


function TIPTransport.GetProtoByNumber(ANumber:Word; ALock:Boolean):TIPProtoEntry;
Description: Find the protocol number in the protocol cache
Number The protocol number to find
Lock If True then lock the found entry before returning


function TIPTransport.AddProto(const AName:String; ANumber:Word; ALock:Boolean):TIPProtoEntry;
Description: Add a protocol to the protocol cache
Name The name of the entry to add
Number The protocol number of the entry to add
Lock If True then lock the added entry before returning


function TIPTransport.RemoveProto(const AName:String):Boolean;
Description: Remove a protocol from the protocol cache
Name The name of the entry to remove


function TIPTransport.CompareLocal(const AAddress:TInAddr):Boolean;
Description: Compare the supplied address with the local IP addresses
Note None documented


function TIPTransport.CompareDefault(const AAddress:TInAddr):Boolean;
Description: Compare the supplied address with the default IP address
Note None documented


function TIPTransport.CompareLoopback(const AAddress:TInAddr):Boolean;
Description: Compare the supplied address with the loopback IP address
Note None documented


function TIPTransport.CompareDirected(const AAddress:TInAddr):Boolean;
Description: Compare the supplied address with the directed broadcast IP addresses
Note None documented


function TIPTransport.CompareBroadcast(const AAddress:TInAddr):Boolean;
Description: Compare the supplied address with the broadcast IP address
Note None documented


function TIPTransport.CompareMulticast(const AAddress:TInAddr):Boolean;
Description: Compare the supplied address with the multicast IP address
Note None documented


function TIPTransport.CompareAddress(const AAddress1,AAddress2:TInAddr):Boolean;
Description: Compare the supplied addresses to see if they are the same
Note None documented


function TIPTransport.CompareSubnet(const AAddress,ANetwork,ANetmask:TInAddr):Boolean;
Description: Compare the supplied address to see if it is in the supplied subnet
Note None documented


Return to Unit Reference