NAME
LinkLocal::IPv4::Interface::Cache - IPv4 link-local address caching object.
SYNOPSIS
use LinkLocal::IPv4::Interface::Cache;
# Create a cache file object
my $cache = LinkLocal::IPv4::Interface::Cache->new();
# Get the last IP cached for a given interface
my $last_address = $cache->get_last_ip('eth0');
# Update the cache when an interface has successfully
# configured a link-local address
$cache->cache_this_ip( 'eth0', '169.254.100.150' );
DESCRIPTION
Implementations of the IPv4 link-local protocol stack will always cache the most recent successfully configured IPv4 link-local addresses in cases where the host has some form of persistant storage. In doing so, the next time that implementation begins the address selection process it will read from its address cache first and attempt to use the last successfully configured address it had previously used on that interface. This has two benefits; the first is that address collision and conflict are less likely during the address selection phase and second is that host interfaces will try and first use link-local addresses which have been successfully configured on them in the past which provides a degree of continuity and address stability in the otherwise unmanaged environment.
This caching object wraps an IO::File, the path to which is determined by the OS on which it is run. At present Linux, Solaris, OS X, Windows and the BSD derivatives are supported. Each cache maintains an IPv4 link-local address for each interface which has been successfully configured with one in the past.
ATTRIBUTES
Public Attributes
Private Attributes
_cache
-
The private _cache attribute is an IO::File object which represents the IPv4 link-local address cache for the current implementation. According to the specification, all past successfully configured link-local addresses are cached on an interface by interface basis.
METHODS
Constructors
new
-
This constructor takes no arguments and returns an instance of a link-local address cache file object which contains all of the most recent successfully configured link-local addresses, by interface, on the system.
Public Methods
get_last_ip
-
get_last_ip() is a public method which takes one argument, a network interface device name (such as 'eth0' for example) and it returns the last successfully configured IPv4 link-local address which was configured on that interface or undef if this interface has never been dynamically configured with a link-local address. MooseX::Params::Validate is in effect on all arguments.
cache_this_ip
-
cache_this_ip() is a public method which takes two arguments, a network interface device name (such as 'eth0' for example) and the link-local IPv4 address in dotted-decimal format which is to be cached for that interface as the currently configured IPv4 link-local address but only after it has been successfully probed and configured as per RFC-3927. MooseX::Params::Validate is in effect on all arguments.
Private Methods
_get_hash_from_cache
-
_get_hash_from_cache() is a private method which builds a hash from the current link-local cache file containing the most recent successfully configured IPv4 link-local addresses. The hash is structured in an interface => address key/value format. For example:
eth0 => 169.254.150.120 eth1 => 169.254.134.288
_build_cache
-
This builder method handles the proper initialization of the private _cache attribute, which is iself an IO::File object. It detects the OS on which the implementation is being run and from that, configures the application cache to use the proper location for its environment according to current system type.
_slurp_file
-
_slurp_file() is a method delegate on the getlines() method of an IO::Handle object via IO::File. When called, _slurp_file() returns a list containing the contents of the cache file
_record_ip
-
_record_ip() is a method delegate on the printf() method of an IO::Handle object via IO::File. This delegate is used to update the cache with the new interface/address mapping.
_refresh_cache
-
_refresh_cache() is a method delegate on the seek() method of an IO::Seekable object via IO::File. The _refresh_cache() delegate is used to reset the file pointer so that the stream is at the beginning of the file. This ensures that the next read from the file will have its stream set to the start of the file.
SEE ALSO
Refer to RFC-3927, Dynamic Configuration of IPv4 Link-Local Adresses, the complete text of which can be found in the top level of the package archive.
perl, LinkLocal::IPv4::Interface, MooseX::Params::Validate, IO::File, Try::Tiny, Moose
This project is also hosted on github at: git@github.com:raymroz/LinkLocal--IPv4.git
BUGS
What's a bug???
AUTHOR
Tony Li Xu, <tonylixu@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2010 Ray Mroz, Tony Li Xu
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
10 POD Errors
The following errors were encountered while parsing the POD:
- Around line 193:
You forgot a '=back' before '=head3'
- Around line 195:
'=item' outside of any '=over'
- Around line 197:
You forgot a '=back' before '=head3'
- Around line 199:
'=item' outside of any '=over'
- Around line 211:
You forgot a '=back' before '=head3'
- Around line 213:
'=item' outside of any '=over'
- Around line 219:
You forgot a '=back' before '=head3'
- Around line 221:
'=item' outside of any '=over'
- Around line 236:
You forgot a '=back' before '=head3'
- Around line 238:
'=item' outside of any '=over'