IPAddr.new and IPAddr#zone_id= only accepted \w characters after %, so zone IDs for interfaces such as eth0.100 (VLAN) or br-lan raised InvalidAddressError. RFC 6874 defines ZoneID as unreserved characters (ALPHA, DIGIT, -, ., _, ~), which is also what Resolv::IPv6 accepts (%[-0-9A-Za-z._~]+). Use the same character class in both places.
https://github.com/ruby/ipaddr/commit/8aaee2fa0c
Returns the binary representation of the address value as a string of
"0" and "1" characters, right adjusted to the address size (32
characters for IPv4, 128 for IPv6).
https://github.com/ruby/ipaddr/commit/63beaa749e
IPAddr.new("[2001:db8::]/32") is currently accepted and treated the
same as IPAddr.new("2001:db8::/32"). However, square brackets are a
delimiter for embedding an address in a larger syntax such as
host:port (RFC 5952 section 6), and no notation is defined for a
prefix length after the closing bracket.
Print a warning for this form, saying that it will raise
IPAddr::InvalidAddressError in a future version. The result is
unchanged for now. "[2001:db8::]" and "2001:db8::/32" are not
affected.
https://github.com/ruby/ipaddr/commit/a540d51a31
IPAddr#to_s ran its zero-compression and IPv4-tail regexps on the
output of #to_string, which already ends with the zone ID. That had
two effects for IPv6 addresses with a zone ID:
* Anchored patterns no longer matched, so "::%eth0" was printed as
"::0%eth0", and "::ffff:192.168.1.2%eth0" as
"::ffff:c0a8:102%eth0" instead of using the dotted IPv4 tail.
* The leading-zero stripping also applied to the zone ID, so
"fe80::1%0ab" was printed as "fe80::1%ab", naming a different zone.
Build the compressed form from the bare address and append the zone ID
at the end.
https://github.com/ruby/ipaddr/commit/6c406450ae
private?, link_local?, multicast?, link_local_multicast? only compare
the masked address (`@addr`) against each address block's network
address, and never check whether the receiver's prefix is at least
as long as the address block's prefix. As a result, a network whose
prefix is shorter than the address block (e.g. 192.168.0.0/15, a
supernet of the private 192.168.0.0/16 address block) is wrongly
reported as true.
IPAddr.new("192.168.0.0/15").private?
# => true # expected false
Add a prefix length check to the existing address comparison,
ensuring that the receiver's network is fully contained within the
target address block.
https://github.com/ruby/ipaddr/commit/dfa97a86e1
The IPv4 branch matches 224.0.0.0/24, the Local Network Control Block,
but the IPv4-mapped branch masked with 0xffff0000, which is a /16, even
though its comment says /24. So an address was classified differently
depending on whether it arrived as 224.0.1.1 or ::ffff:224.0.1.1, which
is the form a dual-stack AF_INET6 socket hands you.
The other predicates in the family already use the same mask on both
branches.
https://github.com/ruby/ipaddr/commit/eebe5b237d
This adds the following predicate methods to IPAddr objects:
* `#multicast?`: whether the ip address is multicast
* `#link_local_multicast?`: whether the ip address is a link-local
multicast
it also alias `IPAddr#link_local?` as `IPAddr#link_local_unicast?`,
which is more accurate (whether the original should be deprecated is
probably a separate discussion).
https://github.com/ruby/ipaddr/commit/332ae1ffbf
`IPAddr.ntop` takes the binary representation of an IP address, whose
length should be 4 or 16 *bytes* (not characters/codepoints).
The current implementation accepts strings in any encoding, but for
some values in non-BINARY encoding, it fails proper length check and
raises an `AddressFamilyError`. Since passing strings in a multibyte
encoding has never worked correctly for years, this patch makes it an
explicit error with an `InvalidAddressError`.
Fixes: https://github.com/ruby/ipaddr/issues/56https://github.com/ruby/ipaddr/commit/a33fd14d4a
Rails uses IPAddr#include? to evaluate what it should use as the
client's remote ip by filtering potential ips against a trusted list
of internal ips. In a _very_ minimal app, #include? was showing up in
a profile as ~1% of request time.
The issue is that #include? was converting itself and the other value
passed in to ranges of IPAddr. This mean as a worst case (where other is
a non-IPAddr, like a String) then there would be 5 IPAddr instances
created (other -> IPAddr, and two each for the conversions to ranges).
However, wrapping the begin and end values as IPAddr is not needed
because they are necessarily fixed addresses already.
This patch extracts the logic for getting the begin_addr and end_addr
from the #to_range method so that they can be used in #include? without
having to instantiate so many IPAddr.
Benchmark:
```ruby
net1 = IPAddr.new("192.168.2.0/24")
net2 = IPAddr.new("192.168.2.100")
net3 = IPAddr.new("192.168.3.0")
net4 = IPAddr.new("192.168.2.0/16")
Benchmark.ips do |x|
x.report("/24 includes address") { net1.include? net2 }
x.report("/24 not includes address") { net1.include? net3 }
x.report("/16 includes /24") { net4.include? net1 }
x.report("/24 not includes /16") { net1.include? net4 }
x.compare!
end
```
Before:
```
Comparison:
/24 not includes /16: 175041.3 i/s
/24 not includes address: 164933.2 i/s - 1.06x (± 0.00) slower
/16 includes /24: 163881.9 i/s - 1.07x (± 0.00) slower
/24 includes address: 163558.4 i/s - 1.07x (± 0.00) slower
```
After:
```
Comparison:
/24 not includes /16: 2588364.9 i/s
/24 not includes address: 1474650.7 i/s - 1.76x (± 0.00) slower
/16 includes /24: 1461351.0 i/s - 1.77x (± 0.00) slower
/24 includes address: 1425463.5 i/s - 1.82x (± 0.00) slower
```
Before it would be left as an IPv6 mask causing `to_range` to fail.
```
>> IPAddr.new("::2").native.to_range
/opt/rubies/3.0.3/lib/ruby/3.0.0/ipaddr.rb:479:in `set': invalid address (IPAddr::InvalidAddressError)
```
https://github.com/ruby/ipaddr/commit/af485192f3
include? should return false if comparing an IPv4 address to an IPv6
address.
ipv4_mapped needs to set the correct netmask on the mapped
addresses.
https://github.com/ruby/ipaddr/commit/da22ef8e6c
It would be nice to use Range#cover? here, but it doesn't work
correctly before Ruby 2.6. Switch to manual checks of the beginning
of end of the ranges.
Fixes Ruby Bug 14119
https://github.com/ruby/ipaddr/commit/f45630da31
These are supported by Ruby's socket library if the operating system
supports zone indentifiers, so they should be supported by ipaddr.
See RFCs 4007 and 6874 for additional information.
Implements Ruby Feature #10911https://github.com/ruby/ipaddr/commit/09a6408fb2
Instead of raising a new exception with a modified message, just
use the correct message to begin with. This avoids the issue with
both exceptions being displayed at error exit.
https://github.com/ruby/ipaddr/commit/09edfd4a7f
- Enable frozen_string_literal and do a bit of code cleanup
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66432 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
If uplevel keyword is given, the warning message is prepended
with caller file and line information and the string "warning: ".
The use of the uplevel keyword makes Kernel#warn format output
similar to how rb_warn formats output.
This patch modifies net/ftp and net/imap to use Kernel#warn
instead of $stderr.puts or $stderr.printf, since they are used
for printing warnings.
This makes lib/cgi/core and tempfile use $stderr.puts instead of
warn for debug logging, since they are used for debug printing
and not for warning.
This does not modify bundler, rubygems, or rdoc, as those are
maintained outside of ruby and probably wish to remain backwards
compatible with older ruby versions.
rb_warn_m code is originally from nobu, but I've changed it
so that it only includes the path and lineno from uplevel
(not the method), and also prepends the string "warning: ",
to make it more similar to rb_warn.
From: Jeremy Evans code@jeremyevans.net
Signed-off-by: Urabe Shyouhei shyouhei@ruby-lang.org
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e