/[mdap]/lib/MDAP/ChangeIP.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /lib/MDAP/ChangeIP.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 79 - (hide annotations)
Sun Nov 18 16:25:26 2007 UTC (16 years, 5 months ago) by dpavlin
File size: 1433 byte(s)
 r119@brr:  dpavlin | 2007-11-18 17:25:21 +0100
 guess network mask which got required in firmware 7.x

1 dpavlin 49 package MDAP::ChangeIP;
2 dpavlin 47
3     use strict;
4     use warnings;
5    
6 dpavlin 49 use Module::Pluggable;
7 dpavlin 58 use MDAP;
8 dpavlin 47
9     my $serial2ip = {
10 dpavlin 54 'CP0636JT3SH' => '192.168.1.242;10.0.0.1',
11     'CP0644JTHJ4' => '192.168.1.243;10.0.0.2',
12     'CP0624BH55U' => '192.168.1.244;10.0.0.3',
13 dpavlin 47 };
14    
15     sub check {
16 dpavlin 49 my ( $self, $h ) = @_;
17 dpavlin 47
18     my $serial = $h->{'_PROD_SERIAL_NBR'} || die "no serial?";
19     my $ip_list = $h->{'IP_LIST'} || die "no IP_LIST";
20    
21     if ( my $ip = $serial2ip->{$serial} ) {
22 dpavlin 49 if ( $ip eq $ip_list ) {
23 dpavlin 58 once "OK ",__PACKAGE__," $serial $ip_list";
24 dpavlin 49 return;
25     }
26 dpavlin 47
27     warn "## change_ip $serial ",
28     $h->{'_VARIANT_FRIENDLY_NAME'}, " ",
29     $h->{'_BOARD_NAME'}, " ",
30     $h->{'_BUILD'}, " ",
31 dpavlin 58 "IP $ip_list -> $ip\n" if $debug;
32    
33 dpavlin 47 my $ip_status;
34     $ip_status->{$_}-- foreach ( split(/;/, $ip_list ) );
35     $ip_status->{$_}++ foreach ( split(/;/, $ip ) );
36     foreach my $current_ip ( sort { $ip_status->{$b} <=> $ip_status->{$a} } keys %$ip_status ) {
37     if ( $ip_status->{$current_ip} < 0 ) {
38 dpavlin 58 warn "-- remove IP $current_ip\n" if $debug;
39 dpavlin 47 return "ip ipdelete addr=$current_ip";
40     } elsif ( $ip_status->{$current_ip} > 0 ) {
41 dpavlin 79 my $mask = '';
42     $mask = '/8' if $current_ip =~ m/^10\./;
43     $mask = '/24' if $current_ip =~ m/^192\.168\./;
44     warn "++ add IP $current_ip$mask\n" if $debug;
45     return "ip ipadd intf=LocalNetwork addr=$current_ip$mask";
46 dpavlin 47 }
47     }
48     return;
49     } else {
50 dpavlin 58 once "ERROR: can't find serial2ip mapping for $serial IP $ip_list";
51 dpavlin 47 return;
52     }
53     }
54    
55 dpavlin 51 1;

  ViewVC Help
Powered by ViewVC 1.1.26