3.8. network

3.8.1. NAME

network - Guardian Digital WebTool module interface to networking.

3.8.2. SYNOPSIS

use network;
my $network  = new network();

3.8.3. DESCRIPTION

This Guardian Digital WebTool module provides an interface to manipulating networking. This module allows you to manage physical interfaces, virtual interfaces, /etc/host entries, the system hostname, nameservers in /etc/resolv.conf, and static/default routes.

3.8.4. METHODS

new()

This constructor sets initial values for parameters. It includs getting host name from system, listing hosts which contains IP addresses as keys and hostname as their repective values and from resolv.conf hash containing key value pair, where value will be array reference of all values corresponding to perticular key. First key-value pair will be nameserver and ip address pair.

Example Usage:

my $network  = new network();
$hostname    = $network->{'conf_hostname'};
$host1       = $network->{'conf_hosts'}->{$ip_address1};
$host2       = $network->{'conf_hosts'}->{$ip_address2};
$ipaddr      = $network->{'conf_resolv'}->{$nameserver};

host_add($)

This function is used to add an entry(host) to /etc/hosts. It receives a hash reference containing IP address and domain name of host.

Example Usage:

$host = {
      'address' => $address,
      'value'   => $value
}  
$network->host_add($host);

host_delete($)

This function is used to delete an entry(host) from /etc/hosts. It receives IP address of host to be deleted as argument.

Example Usage:

$network->host_delete($hostip);

host_get($)

This function is used to get host information as key-value pairs(address and hostname) from /etc/hosts. It receives IP address of host as argument.

Example Usage:

$network->host_get($host);
$address    = $host->['address'};
$hostname   = $host->{'value'};

interface_create($)

Basically this function creates an entry in /etc/network/interfaces. It receives interface hash reference which contains information like type, address and netmask. Depending on the type(static,dynamic,virtual) network and broadcast address is generated and all these information is written into configuration file. And after that interface is brought up.

Example Usage:

if ($type eq 'static') {
   $i->{'address'}   = $in{'static_address'};
   $i->{'netmask'}   = $in{'static_netmask'};
}
elsif ($type eq 'virtual') {
   $i->{'address'}   = $in{'virtual_address'};
   $i->{'netmask'}   = $in{'virtual_netmask'};
   $i->{'attach'}    = $in{'input_virtual_attach'};
}
my $iface  = $network->interface_create($i);

interface_delete($)

Basically this function is used to delete an interface entry from /etc/network/interfaces file. It receives interface name as argument.

Example Usage:

$network->interface_delete($interface);

interface_get($)

This function is used to get an detail information about some interface. Interface name is passed as argument to this function.

Example Usage:

my $interface  = $self->interface_get($interface);

interfaces_list()

This function reads through the /etc/network/interfaces file, and returns a hash reference of all interface details depending on their properties.

Example Usage:

my $interfaces = $network->interfaces_list();
foreach my $if (sort keys %{$interfaces}) {
  my $iface   = $interfaces->{$if}->{'iface'};
  my $address = $interfaces->{$if}->{'address'};
  my $netmask = $interfaces->{$if}->{'netmask'};
  my $type    = $interfaces->{$if}->{'type'};
}

default_route_create($)

This function is used to create a default route, add an entry in /etc/network/interfaces file, it receives route as hash reference containing information like device and default gateway. see example.

Example Usage:

$network->default_route_create({
        'device'        => $in{'default_device'},
        'gateway'       => $in{'default_gateway'},
});

default_route_delete($)

This function is used to delete default route entry from /etc/network/interfaces file, it receives device(interface) name as argument.

Example Usage:

$network->default_route_delete($default_device);

route_create($)

This function is used to add static route to /etc/network/interfaces file, it receives hash reference containing device and gateway values as argument.

Example Usage:

my $i  = {
    'device'        => $in{'device'},
    'network'       => $in{'network'},
    'netmask'       => $in{'netmask'},
    'gateway'       => ($in{'gateway'}) ? $in{'gateway'} : undef,
};
$network->route_create($i);

route_delete($$$)

This function is used to delete a static route from /etc/network/interfaces file, it receives three arguments- device, network and netmask.

Example Usage:

$network->route_delete($device, $network, $netmask);

route_get($$$)

This function is used to get a static route information from /etc/network/interfaces file, it receives three arguments- device, network and netmask.

Example Usage:

$network->route_get($device, $network, $netmask);

ifdown($)

This function is used to bring down the provided interface.

Example Usage:

$postfix->ifdown($iface);

ifup($)

This function is used to bring up the provided interface.

Example Usage:

$postfix->ifup($iface);

restart_networking()

This function is used restart the network service.

Example Usage:

$network->restart_networking();

make_broadcast($)

This function is used to get broadcast address. It requires ip address and netmask to be passed as arguments.

Example Usage:

my $broadcast = make_broadcast($address, $netmask);

make_network($)

This function is used to get network address. It requires ip address and netmask to be passed as arguments.

Example Usage:

my $network  = make_network($address, $netmask);

write_pump_conf($)

This function writes /etc/pump.conf file. If argument received is not null then it writes 'nodns' in file.

Example Usage:

write_pump_conf($dynamic_dns);

set_hostname($)

This function sets the hostname of the system. It receives hostname as argument.

Example Usage:

$network->set_hostname($hostname);

set_resolv($)

This function receives hash reference containing values of search and servers. Ultimately it writes out those values in /etc/resolv.conf. See example.

Example Usage:

$network->set_resolv({
        'search'        => \@dns_search,
        'servers'       => \@dns_servers,
});

mask2cidr($)

This function converts netmask to cidr. It receives netmask as argument.

Example Usage:

my $cidr = $network->mask2cidr($netmask);

cidr2mask($)

This function converts cidr to netmask. It receives cidr as argument.

Example Usage:

my $netmask = $network->cidr2mask($cidr);

3.8.5. AUTHORS

Ryan W. Maple <ryan@guardiandigital.com>

3.8.6. COPYRIGHT AND LICENSE

Copyright Guardian Digital, Inc., All Rights Reserved