<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ruby.git/lib/ipaddr.rb, branch v3_3_11</title>
<subtitle>The Ruby Programming Language</subtitle>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/'/>
<entry>
<title>[ruby/ipaddr] Bump up v1.2.6</title>
<updated>2023-12-16T05:20:55+00:00</updated>
<author>
<name>Hiroshi SHIBATA</name>
<email>hsbt@ruby-lang.org</email>
</author>
<published>2023-12-16T05:20:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=4fd3c85acdfa942d88d8e9e2ccd17b8030c2c3b2'/>
<id>4fd3c85acdfa942d88d8e9e2ccd17b8030c2c3b2</id>
<content type='text'>
https://github.com/ruby/ipaddr/commit/247459faa5
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/ipaddr/commit/247459faa5
</pre>
</div>
</content>
</entry>
<entry>
<title>Improve performance of include? by 5-10x</title>
<updated>2023-09-23T02:22:25+00:00</updated>
<author>
<name>Hartley McGuire</name>
<email>skipkayhil@gmail.com</email>
</author>
<published>2022-12-14T23:32:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=e581b78ed2d69a47a23deb167ea4a63b5f195fe9'/>
<id>e581b78ed2d69a47a23deb167ea4a63b5f195fe9</id>
<content type='text'>
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 -&gt; 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
```
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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 -&gt; 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
```
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/ipaddr] Consider IPv4-mapped IPv6 addresses private if IPv4 address is private</title>
<updated>2023-06-22T16:40:46+00:00</updated>
<author>
<name>Jeremy Evans</name>
<email>code@jeremyevans.net</email>
</author>
<published>2023-06-22T16:11:03+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=de51a4a13eab2c4c5917de923edde33dfed6f22f'/>
<id>de51a4a13eab2c4c5917de923edde33dfed6f22f</id>
<content type='text'>
Fixes [Bug #19479]

https://github.com/ruby/ipaddr/commit/7faa0768d3
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Fixes [Bug #19479]

https://github.com/ruby/ipaddr/commit/7faa0768d3
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/ipaddr] Bump version to 1.2.5</title>
<updated>2022-12-05T06:32:03+00:00</updated>
<author>
<name>Hiroshi SHIBATA</name>
<email>hsbt@ruby-lang.org</email>
</author>
<published>2022-12-05T06:31:42+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=51cfe70135045536b442648e691e84db7e39b3fb'/>
<id>51cfe70135045536b442648e691e84db7e39b3fb</id>
<content type='text'>
https://github.com/ruby/ipaddr/commit/d92acb3982
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/ipaddr/commit/d92acb3982
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/ipaddr] Improve Ractor-compliance</title>
<updated>2022-09-08T05:09:06+00:00</updated>
<author>
<name>rm155</name>
<email>rohitmenon@verizon.net</email>
</author>
<published>2021-07-20T01:48:33+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=70e6be2b055d78d3c475368d744c423564597f6e'/>
<id>70e6be2b055d78d3c475368d744c423564597f6e</id>
<content type='text'>
https://github.com/ruby/ipaddr/commit/73461724e5
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/ipaddr/commit/73461724e5
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/ipaddr] Bump version to 1.2.4</title>
<updated>2022-02-10T08:18:05+00:00</updated>
<author>
<name>Hiroshi SHIBATA</name>
<email>hsbt@ruby-lang.org</email>
</author>
<published>2022-02-04T09:00:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=52d3e31d274bed09aea6c167efe62e0c2f70eee4'/>
<id>52d3e31d274bed09aea6c167efe62e0c2f70eee4</id>
<content type='text'>
https://github.com/ruby/ipaddr/commit/6edf6ee6c3
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/ipaddr/commit/6edf6ee6c3
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/ipaddr] Fix exception calling `to_range' after `freeze'</title>
<updated>2022-02-10T08:18:05+00:00</updated>
<author>
<name>Espartaco Palma</name>
<email>git@esparta.co</email>
</author>
<published>2021-12-13T09:12:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=9b768012f6bf5b5896d2d34feb69605d4ccc9ca3'/>
<id>9b768012f6bf5b5896d2d34feb69605d4ccc9ca3</id>
<content type='text'>
https://github.com/ruby/ipaddr/commit/77fe1fca0a
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
https://github.com/ruby/ipaddr/commit/77fe1fca0a
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/ipaddr] Ipaddr#native must also coerce `@mask_addr`</title>
<updated>2022-02-10T08:18:05+00:00</updated>
<author>
<name>Jean Boussier</name>
<email>jean.boussier@gmail.com</email>
</author>
<published>2021-12-02T09:56:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=100253c7f0f4d105ae88340a0314506cde69cfd2'/>
<id>100253c7f0f4d105ae88340a0314506cde69cfd2</id>
<content type='text'>
Before it would be left as an IPv6 mask causing `to_range` to fail.

```
&gt;&gt; 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
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Before it would be left as an IPv6 mask causing `to_range` to fail.

```
&gt;&gt; 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
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/ipaddr] Expose IPAddr::VERSION</title>
<updated>2022-02-10T08:18:03+00:00</updated>
<author>
<name>Jean Boussier</name>
<email>jean.boussier@gmail.com</email>
</author>
<published>2021-12-02T09:07:26+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=5221cb4468526a18875c21cff5dee5ac96d9873b'/>
<id>5221cb4468526a18875c21cff5dee5ac96d9873b</id>
<content type='text'>
An almost universal convention for gems is to expose Namespace::VERSION
which makes it much easier when debugging etc.

https://github.com/ruby/ipaddr/commit/587ae6996e
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
An almost universal convention for gems is to expose Namespace::VERSION
which makes it much easier when debugging etc.

https://github.com/ruby/ipaddr/commit/587ae6996e
</pre>
</div>
</content>
</entry>
<entry>
<title>[ruby/ipaddr] Fix include? and ipv4_mapped to allow drb tests to pass</title>
<updated>2021-10-11T04:50:54+00:00</updated>
<author>
<name>Jeremy Evans</name>
<email>code@jeremyevans.net</email>
</author>
<published>2021-10-07T15:02:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.ruby-lang.org/ruby.git/commit/?id=391d6ab4f7c3070d0c46dbd7496255d8269f6c1f'/>
<id>391d6ab4f7c3070d0c46dbd7496255d8269f6c1f</id>
<content type='text'>
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
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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
</pre>
</div>
</content>
</entry>
</feed>
