make-ip-conf.pl patch (#4, cumulative)

David Scott Page page at cs.utexas.edu
Tue May 21 10:27:37 EDT 2002


Eddie,

Much nicer. Thanks for taking the time to enhance the script. I found
it (and its output) to be a big help in getting started with Click.

You might want to add a comment regarding the command line method to
set $ifs ("Ignore this." would be helpful, but wouldn't satiate my
curiosity).

Enclosed is a patch consisting of a few more miscellaneous changes:
1. Configuration variable $local_host for ToHost.
2. Collect local delivery statements in one place.
3. Remove superfluous (I hope) input port spec from rt and cx.
4. Change classifier discard Print tag to $devname from xx$i.
5. Move comment re ARP update copies to configuration output.
6. Whitespace cleanup (thanks to emacs syntax highlighting)
7. Punctuation.
8. Fix perl warning about my list for "@routes, @invalid_src" declaration.

--
Scott Page

---------------------------------- 8< ------------------------------------
diff -Naur click-20020520/conf/make-ip-conf.pl click-20020520a/conf/make-ip-conf.pl
--- click-20020520/conf/make-ip-conf.pl	Mon May 20 19:09:04 2002
+++ click-20020520a/conf/make-ip-conf.pl	Tue May 21 14:06:53 2002
@@ -20,10 +20,9 @@
 # Make a Click IP router configuration.  This script generates a
 # configuration using PollDevices. You can change it to use
 # FromDevices; see the comment above the $ifs array, below.  The
-# output is intended for the Linux kernel module; however, by
-# replacing "toh :: ToHost\n" with "toh :: Print(toh)->Discard;\n",
-# below, and making the change from PollDevices to FromDevices, the
-# configuration will also work at userlevel.
+# output is intended for the Linux kernel module; however, by making
+# the change from PollDevices to FromDevices, and setting $local_host
+# appropriately, the configuration will also work at userlevel.
 
 # Change this array to suit your router.
 # One line per network interface, containing:
@@ -55,13 +54,18 @@
 my $srts = [ [ "0.0.0.0", "0.0.0.0", "18.26.4.1", "eth0" ]
 	   ];
 
-# Set to 1 if you want the configuration to handle echo requests itself.
+# Set to, e.g., "Print(toh)->Discard" for user-level.
+my $local_host = "ToHost";
+
+# Set to 1 if you want the configuration to handle ICMP echo requests itself.
 my $handle_pings = 0;
 
+# End of configuration.
+
 my $nifs = $#$ifs + 1;
 my $nsrts = $#$srts + 1;
 
-print "// Generated by make-ip-conf.pl\n";
+print "// Generated by make-ip-conf.pl.\n";
 
 my $i;
 for($i = 0; $i < $nifs; $i++){
@@ -70,23 +74,17 @@
            $ifs->[$i]->[2],
            $ifs->[$i]->[4]);
 }
-print "\n";
-
-# ARP updates are copied to each ARPQuerier and the host.
-print "toh :: ToHost;\n";
-printf("arpt :: Tee(%d);\n", $nifs + 1);
-print "arpt[$nifs] -> toh;\n";
 
 # Set up the routing table.
-my @routes, @invalid_src;
+my(@routes, @invalid_src);
 
-# For delivery to the local host
+# For delivery to the local host.
 for($i = 0; $i < $nifs; $i++){
     my $ii = ip2i($ifs->[$i]->[2]);
     my $mask = ip2i($ifs->[$i]->[3]);
 
     push @routes, sprintf("%s/32 0", i2ip($ii));# This host.
-    
+
     my $dirbcast = ($ii & $mask) | ~$mask;	# Directed broadcast.
     push @routes, sprintf("%s/32 0", i2ip($dirbcast));
     push @invalid_src, i2ip($dirbcast);
@@ -95,7 +93,7 @@
     						# Directed broadcast (obsolete).
 }
 
-# For forwarding to connected networks 
+# For forwarding to connected networks.
 for($i = 0; $i < $nifs; $i++){
     my $ii = ip2i($ifs->[$i]->[2]);
     my $mask = ip2i($ifs->[$i]->[3]);
@@ -105,14 +103,14 @@
            $i + 1);
 }
 
-# For remaining broadcast addresses
+# For remaining broadcast addresses.
 push @routes, "255.255.255.255/32 0.0.0.0 0";	# Limited broadcast.
 push @invalid_src, "255.255.255.255";
 
 push @routes, "0.0.0.0/32 0";			# Limited broadcast (obsolete).
 
-# For forwarding to static routes
-for ($i = 0; $i < $nsrts; $i++) {
+# For forwarding to static routes.
+for($i = 0; $i < $nsrts; $i++) {
     my $ii = ip2i($srts->[$i]->[0]);
     my $mask = ip2i($srts->[$i]->[1]);
     my $gw = $srts->[$i]->[2];
@@ -127,12 +125,14 @@
         $gw, $out + 1);
 }
 
-print "\n// Shared input path and routing table\n";
+print "\n// Shared IP input path and routing table.\n";
 print "ip :: Strip(14);\n";
 print "rt :: StaticIPLookup(\n\t", join(",\n\t", @routes), ");\n";
-print "ip -> CheckIPHeader(", join(' ', @invalid_src), ") -> rt;\n\n";
+print "ip -> CheckIPHeader(", join(' ', @invalid_src), ") -> rt;\n";
 
-# Link level devices, classification, and ARP.
+# Link-level devices, classification, and ARP.
+print "\n// ARP updates are copied to each ARPQuerier and the host.\n";
+printf("arpt :: Tee(%d);\n", $nifs + 1);
 for($i = 0; $i < $nifs; $i++){
     my $devname = $ifs->[$i]->[0];
     my $ip = $ifs->[$i]->[2];
@@ -141,21 +141,23 @@
     my $fromdevice = ($ifs->[$i]->[1] ? "PollDevice" : "FromDevice");
     print <<"EOD;";
 
-// Input and output paths for $devname
+// Input and output paths for $devname.
 c$i :: Classifier(12/0806 20/0001, 12/0806 20/0002, 12/0800, -);
-$fromdevice($devname) -> [0]c$i;
+$fromdevice($devname) -> c$i;
 out$i :: Queue(200) -> todevice$i :: ToDevice($devname);
 c$i\[0] -> ar$i :: ARPResponder($ip $ena) -> out$i;
 arpq$i :: ARPQuerier($ip, $ena) -> out$i;
 c$i\[1] -> arpt;
 arpt[$i] -> [1]arpq$i;
 c$i\[2] -> Paint($paint) -> ip;
-c$i\[3] -> Print(xx$i) -> Discard;
+c$i\[3] -> Print($devname) -> Discard;
 EOD;
 }
 
 # Local delivery path.
-print "\n// Local delivery\n";
+print "\n// Local delivery.\n";
+print "toh :: $local_host;\n";
+print "arpt[$nifs] -> toh;\n";
 if ($handle_pings) {
     print <<"EOD;";
 rt[0] -> IPReassembler -> ping_ipc :: IPClassifier(icmp type echo, -);
@@ -173,7 +175,7 @@
     my $devname = $ifs->[$i]->[0];
     print <<"EOD;";
 
-// Forwarding path for $devname
+// Forwarding path for $devname.
 rt[$i1] -> DropBroadcasts
     -> cp$i :: PaintTee($i1)
     -> gio$i :: IPGWOptions($ipa)
@@ -181,13 +183,14 @@
     -> dt$i :: DecIPTTL
     -> fr$i :: IPFragmenter(1500)
     -> [0]arpq$i;
-dt$i\[1] -> ICMPError($ipa, 11, 0) -> [0]rt;
-fr$i\[1] -> ICMPError($ipa, 3, 4) -> [0]rt;
-gio$i\[1] -> ICMPError($ipa, 12, 1) -> [0]rt;
-cp$i\[1] -> ICMPError($ipa, 5, 1) -> [0]rt;
+dt$i\[1] -> ICMPError($ipa, 11, 0) -> rt;
+fr$i\[1] -> ICMPError($ipa, 3, 4) -> rt;
+gio$i\[1] -> ICMPError($ipa, 12, 1) -> rt;
+cp$i\[1] -> ICMPError($ipa, 5, 1) -> rt;
 EOD;
 }
 
+
 sub ip2i {
     my($ip) = @_;
     my @a = split(/\./, $ip);
@@ -202,4 +205,3 @@
     my $d = $i & 0xff;
     return sprintf("%d.%d.%d.%d", $a, $b, $c, $d);
 }
-






More information about the click mailing list