0.0.0.0/0 Zero Length Prefix

109 views
Skip to first unread message

Mark Sullivan

unread,
Jan 10, 2011, 11:40:45 PM1/10/11
to Ruby IPAddress
Networking devices from both Juniper and Cisco (and others) use the
address/prefix of 0.0.0.0/0 to represent ANY in both routing and
access control config (the /0 effectively indicating ignore all bits
so in theory the address could be anything, but I digress). I'm
parsing such configs and was hoping that I could simply do the same
but IPAddress:Prefix32.new raises an exception if the prefix length is
less than 1.

def initialize(num)
unless (1..32).include? num
raise ArgumentError, "Prefix must be in range 1..32, got:
#{num}"
end
super(num)
end

Any reason this particular decision was made not to support a 0 length
mask?

I did try a quick change to the range (allowed) zero, but found the
to_ip didn't respond as I would expect:

ruby-1.9.2-p0 > a = IPAddress::Prefix32.new 0
=> 0

ruby-1.9.2-p0 > a.hostmask
=> "255.255.255.255"

ruby-1.9.2-p0 > a.to_ip
=> "0..."


Cheers

MS

Marco Ceresa

unread,
Jan 12, 2011, 4:13:43 AM1/12/11
to ruby-ip...@googlegroups.com, sulliva...@gmail.com
On Tue, Jan 11, 2011 at 5:40 AM, Mark Sullivan
<sulliva...@gmail.com> wrote:
> Networking devices from both Juniper and Cisco (and others) use the
> address/prefix of 0.0.0.0/0 to represent ANY in both routing and
> access control config (the /0 effectively indicating ignore all bits
> so in theory the address could be anything, but I digress). I'm
> parsing such configs and was hoping that I could simply do the same
> but IPAddress:Prefix32.new raises an exception if the prefix length is
> less than 1.

Hello Mark,

thanks very much for your email.

You are absolutely correct, there is no reason why we shouldn't
support zero length prefixes. I think this is a serious feature
missing.

I will start immediately working on it and I will release a new
version of the library soon.

Regards,
Marco

Kaustubh

unread,
Jul 29, 2014, 1:51:29 AM7/29/14
to ruby-ip...@googlegroups.com, sulliva...@gmail.com
we need a similar fix for Prefix128. Can you please have a look?
https://github.com/bluemonk/ipaddress/pull/48

Thanks in advance,
Kaustubh
Reply all
Reply to author
Forward
0 new messages