Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Jan 2006 00:34:58 GMT
From:      "Ilya V. Guy" <ilya@lisgroup.net>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/91731: Patch to net/ipcalc, which adds an opportunity of a finding of the minimal greater network mask.
Message-ID:  <200601130034.k0D0Ywqj033246@www.freebsd.org>
Resent-Message-ID: <200601130040.k0D0e6Oc035412@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         91731
>Category:       ports
>Synopsis:       Patch to net/ipcalc, which adds an opportunity of a finding of the minimal greater network mask.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 13 00:40:05 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Ilya V. Guy
>Release:        5.3-RELEASE
>Organization:
ISP `Lis'
>Environment:
FreeBSD ilya.home.lisgroup.net 5.3-RELEASE FreeBSD 5.3-RELEASE #1: Sat Sep 24 21:35:13 EEST 2005     ilya@ilya.home.lisgroup.net:/usr/obj/usr/src/sys/Ilya  i386
>Description:
Patch to net/ipcalc (ipcalc-0.38), which adds an opportunity of a finding of the minimal greater network mask.

Use:
ipcalc 192.168.2.0 + 192.168.6.0
or
ipcalc -a 192.168.2.0 192.168.6.0
or
ipcalc -agg 192.168.2.0 192.168.6.0

Produce:
aggregate 192.168.2.0 + 192.168.6.0
192.168.0.0/21

>How-To-Repeat:

>Fix:
--- ipcalc      Fri Jan 13 00:58:01 2006
+++ ipcalc.new  Fri Jan 13 02:25:25 2006
@@ -46,6 +46,7 @@
 my $opt_print_only_class = 0;
 my $opt_split       = 0;
 my $opt_deaggregate   = 0;
+my $opt_aggregate   = 0;
 my $opt_version     = 0;
 my $opt_help        = 0;
 my @opt_split_sizes;
@@ -137,8 +138,8 @@
       $address = argton("192.168.1.1");
    }
    
-   # if deaggregate get last address
-   if ($opt_deaggregate) {
+   # if aggregate or deaggregate get last address
+   if ($opt_deaggregate||$opt_aggregate) {
       if (defined $ARGV[1]) {
          $address2 = argton($ARGV[1],0);
       }
@@ -157,6 +158,15 @@
       exit;
    }
 
+   if ($opt_aggregate) {
+      if ($error) {
+         print "$error\n";
+      }
+      print "aggregate ".ntoa($address) . " + " . ntoa($address2)."\n";
+      aggregate($address,$address2);
+      exit;
+   }
+
    # get netmasks
    if (defined $ARGV[1]) {
       $mask1   = argton($ARGV[1],1);
@@ -208,6 +218,9 @@
    if ($opt_deaggregate) {
       deaggregate();
    }
+   if ($opt_aggregate) {
+      aggregate();
+   }
    if ($opt_split) {
       split_network($network,$mask1,$mask2,@opt_split_sizes);
       exit;
@@ -646,6 +659,28 @@
   return 1 << $i;
 }
 
+# Aggregate address range
+# expects: range: (dotted quads)start (dotted quads)end
+
+sub aggregate
+{
+  my $base = shift;
+  my $end  = shift;
+  my $step;
+  my $mask;
+
+  $step=0;
+  while ( ($base != $end) )
+  {
+    $mask = $thirtytwobits-((1<<$step)-1);
+    $base = $base & $mask;
+    $end = $end & $mask;
+    $step++;
+  }
+  my $broadcast = $base | ((~$mask) & $thirtytwobits);
+  deaggregate($base,$broadcast);
+}
+
 # Deaggregate address range
 # expects: range: (dotted quads)start (dotted quads)end
 
@@ -735,6 +770,14 @@
       elsif (/^\-$/) {
          $opt_deaggregate = 1;
       }
+      elsif (/^(.+)\+(.+)$/) {
+         push @arguments,$1;
+         push @arguments,$2;
+         $opt_aggregate = 1;
+      }
+      elsif (/^\+$/) {
+         $opt_aggregate = 1;
+      }
       else {
          push @arguments, $_;
       }
@@ -743,6 +786,10 @@
       @arguments = ($arguments[0],$arguments[2]);
       $opt_deaggregate = 1;
    }
+   if ($#arguments == 2 && $arguments[1] eq '+') {
+      @arguments = ($arguments[0],$arguments[2]);
+      $opt_aggregate = 1;
+   }
    
    
    # workaround for -h 
@@ -785,6 +832,9 @@
        elsif ($opt eq 'r' || $opt eq 'range') {
            $opt_deaggregate =  1;
         }
+       elsif ($opt eq 'a' || $opt eq 'agg') {
+           $opt_aggregate =  1;
+        }
        elsif ($opt eq 's' || $opt eq 'split') {
           $opt_split = 1;
           while (defined $ARGV[0] && $ARGV[0] =~ /^\d+$/) {
@@ -1043,6 +1093,7 @@
  -s --split n1 n2 n3
                Split into networks of size n1, n2, n3.
  -r --range    Deaggregate address range.
+ -a --agg      Aggregate address range.
     --help     Longer help text.
  
 Examples:
@@ -1054,6 +1105,8 @@
 
 
 ipcalc <ADDRESS1> - <ADDRESS2>  deaggregate address range
+
+ipcalc <ADDRESS1> + <ADDRESS2>  aggregate address range
 
 ipcalc <ADDRESS>/<NETMASK> --s a b c
                                 split network to subnets

>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200601130034.k0D0Ywqj033246>