Deleted Added
full compact
cidrexpand (132943) cidrexpand (161389)
1#!/usr/bin/perl -w
2
1#!/usr/bin/perl -w
2
3# $Id: cidrexpand,v 8.4 2002/11/22 21:13:14 ca Exp $
3# $Id: cidrexpand,v 8.4.2.1 2006/08/07 17:22:10 ca Exp $
4#
5# v 0.4
6#
7# 17 July 2000 Derek J. Balling (dredd@megacity.org)
4#
5# v 0.4
6#
7# 17 July 2000 Derek J. Balling (dredd@megacity.org)
8#
8#
9# Acts as a preparser on /etc/mail/access_db to allow you to use address/bit
9# Acts as a preparser on /etc/mail/access_db to allow you to use address/bit
10# notation.
10# notation.
11#
12# If you have two overlapping CIDR blocks with conflicting actions
13# e.g. 10.2.3.128/25 REJECT and 10.2.3.143 ACCEPT
14# make sure that the exceptions to the more general block are specified
15# later in the access_db.
16#
17# the -r flag to makemap will make it "do the right thing"
18#
19# Modifications
20# -------------
21# 26 Jul 2001 Derek Balling (dredd@megacity.org)
22# Now uses Net::CIDR because it makes life a lot easier.
23#
24# 5 Nov 2002 Richard Rognlie (richard@sendmail.com)
25# Added code to deal with the prefix tags that may now be included in
26# the access_db
27#
11#
12# If you have two overlapping CIDR blocks with conflicting actions
13# e.g. 10.2.3.128/25 REJECT and 10.2.3.143 ACCEPT
14# make sure that the exceptions to the more general block are specified
15# later in the access_db.
16#
17# the -r flag to makemap will make it "do the right thing"
18#
19# Modifications
20# -------------
21# 26 Jul 2001 Derek Balling (dredd@megacity.org)
22# Now uses Net::CIDR because it makes life a lot easier.
23#
24# 5 Nov 2002 Richard Rognlie (richard@sendmail.com)
25# Added code to deal with the prefix tags that may now be included in
26# the access_db
27#
28# Added clarification in the notes for what to do if you have
28# Added clarification in the notes for what to do if you have
29# exceptions to a larger CIDR block.
30#
29# exceptions to a larger CIDR block.
30#
31# usage:
31# 3 August 2006
32#
33# Corrected a bug to have it handle the special case of "0.0.0.0/0"
34# since Net::CIDR doesn't handle it properly.
35#
36# usage:
32# cidrexpand < /etc/mail/access | makemap -r hash /etc/mail/access
33#
34#
35# Report bugs to: <dredd@megacity.org>
36#
37
38
39use strict;

--- 27 unchanged lines hidden (view full) ---

67
68 my @new_lefts = expand_network($left);
69 foreach my $nl (@new_lefts)
70 {
71 print "$prefix$nl$space$right\n";
72 }
73 }
74}
37# cidrexpand < /etc/mail/access | makemap -r hash /etc/mail/access
38#
39#
40# Report bugs to: <dredd@megacity.org>
41#
42
43
44use strict;

--- 27 unchanged lines hidden (view full) ---

72
73 my @new_lefts = expand_network($left);
74 foreach my $nl (@new_lefts)
75 {
76 print "$prefix$nl$space$right\n";
77 }
78 }
79}
75
80
76sub expand_network
77{
78 my $left_input = shift;
79 my @rc = ($left_input);
80 my ($network,$mask) = split /\//, $left_input;
81 if (defined $mask)
82 {
81sub expand_network
82{
83 my $left_input = shift;
84 my @rc = ($left_input);
85 my ($network,$mask) = split /\//, $left_input;
86 if (defined $mask)
87 {
88 return (0..255) if $mask == 0;
89
83 my @parts = split /\./, $network;
84 while ($#parts < 3)
85 {
86 push @parts, "0";
87 }
88 my $clean_input = join '.', @parts;
89 $clean_input .= "/$mask";
90 my @octets = Net::CIDR::cidr2octets($clean_input);
91 @rc = @octets;
92 }
93 return @rc;
94}
90 my @parts = split /\./, $network;
91 while ($#parts < 3)
92 {
93 push @parts, "0";
94 }
95 my $clean_input = join '.', @parts;
96 $clean_input .= "/$mask";
97 my @octets = Net::CIDR::cidr2octets($clean_input);
98 @rc = @octets;
99 }
100 return @rc;
101}