Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(129)

Issue 13745043: ipaddr-py: New IPv4 netmask/hostmask parser.

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 7 months ago by pmarks
Modified:
10 years, 6 months ago
Reviewers:
Peter Moody
CC:
vklimovs_google.com, ipaddr-py-dev_googlegroups.com
Visibility:
Public.

Description

The previous code checks each octet separately, and then checks if the sequence of octets is nonincreasing. This is insufficient, because it allows nonsensical inputs like "255.128.128.0". The previous code also only partially handles hostmasks (inverted netmasks). "0.255.255.255" becomes /8, but 0.15.255.255 is rejected. The solution is to disregard octets, and interpret the address as a single sequence of bits. Note that this could be trivially extended to support IPv6 netmasks and hostmasks, but those are non-standard. I've also made the CIDR parser more strict, so it rejects anything that's not not a decimal digit, like /+24 Added: - _prefix_from_prefix_string: Parse a number, with bounds checking. - _prefix_from_ip_string: Parse IPv4 netmask/hostmask string. Improved: - _prefix_from_ip_int: Only accept inputs with the bit sequence /1*0*/. Removed: - _ip_string_from_prefix - _is_hostmask - _is_valid_netmask

Patch Set 1 #

Total comments: 6

Patch Set 2 : Tweak comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+147 lines, -124 lines) Patch
M trunk/ipaddr.py View 1 8 chunks +80 lines, -114 lines 0 comments Download
M trunk/ipaddr_test.py View 1 4 chunks +67 lines, -10 lines 0 comments Download

Messages

Total messages: 7
pmarks
10 years, 7 months ago (2013-09-17 18:46:37 UTC) #1
Peter Moody
Thanks much for doing this. If it's not too much trouble, could you include some ...
10 years, 7 months ago (2013-09-20 21:33:39 UTC) #2
Peter Moody
https://codereview.appspot.com/13745043/diff/1/trunk/ipaddr.py File trunk/ipaddr.py (right): https://codereview.appspot.com/13745043/diff/1/trunk/ipaddr.py#newcode922 trunk/ipaddr.py:922: # Try matching a netmask (1*0*). Note that the ...
10 years, 7 months ago (2013-09-20 21:33:45 UTC) #3
pmarks
https://codereview.appspot.com/13745043/diff/1/trunk/ipaddr.py File trunk/ipaddr.py (right): https://codereview.appspot.com/13745043/diff/1/trunk/ipaddr.py#newcode922 trunk/ipaddr.py:922: # Try matching a netmask (1*0*). Note that the ...
10 years, 7 months ago (2013-09-20 22:36:35 UTC) #4
Peter Moody
lgtm
10 years, 7 months ago (2013-09-21 16:32:52 UTC) #5
Peter Moody
On 2013/09/21 16:32:52, Peter Moody wrote: > lgtm applied in 669c0368e3e4 . thanks again!
10 years, 7 months ago (2013-09-21 17:09:57 UTC) #6
pmarks
10 years, 6 months ago (2013-10-02 03:42:14 UTC) #7
On 2013/09/21 17:09:57, Peter Moody wrote:
> On 2013/09/21 16:32:52, Peter Moody wrote:
> > lgtm
> 
> applied in 669c0368e3e4	.
> 
> thanks again!

I just noticed that a similar patch was proposed in this Python bug:
http://bugs.python.org/issue18805
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b