Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-74713: ipaddress: support reverse pointer generation for network objects #29011

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Forst
Copy link

@Forst Forst commented Oct 17, 2021

Before this change, DNS reverse pointer generation for network objects produced incorrect results, such as:

>>> ipaddress.IPv4Network('192.168.1.0/24').reverse_pointer
'0/24.1.168.192.in-addr.arpa'
>>> ipaddress.IPv6Network('2001:db8:1234::/48').reverse_pointer
'8.4./.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa'

This change introduces a more generalised reverse pointer generation algorithm, suitable for both address and network objects.

The same code above, after applying this change:

>>> ipaddress.IPv4Network('192.168.1.0/24').reverse_pointer
'1.168.192.in-addr.arpa'
>>> ipaddress.IPv6Network('2001:db8:1234::/48').reverse_pointer
'4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa'

Getting a reverse pointer for a network, whose prefix size can't be exactly represented in a reverse pointer record, will raise an exception:

>>> ipaddress.IPv4Network('192.168.1.0/28').reverse_pointer
ipaddress.NetmaskValueError: Reverse pointer cannot be generated for given prefix size
>>> ipaddress.IPv6Network('2001:db8:1234::/50').reverse_pointer
ipaddress.NetmaskValueError: Reverse pointer cannot be generated for given prefix size

My approach is a bit different to other PRs proposed to fix bpo-30528:

  • Mine is a generic (and perhaps more verbose) implementation, suitable both for address and network objects
  • Trying to get a reverse pointer on a prefix size that doesn't align with the reverse pointer granularity will raise an exception

https://bugs.python.org/issue30528

@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@Forst

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Nov 18, 2021
@MaxwellDupre
Copy link
Contributor

Before

ipaddress.IPv6Network('2001:db8:1234::/48').reverse_pointer
'8.4./.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa'

After:

ipaddress.IPv6Network('2001:db8:1234::/48').reverse_pointer
'4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa'

Looks like a few zeros missing!

@Forst
Copy link
Author

Forst commented Mar 6, 2022

Before

>>> ipaddress.IPv6Network('2001:db8:1234::/48').reverse_pointer
'8.4./.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa'

After:

>>> ipaddress.IPv6Network('2001:db8:1234::/48').reverse_pointer
'4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa'

Looks like a few zeros missing!

@MaxwellDupre, I think you may be confusing IPv6Network with IPv6Address:

>>> ipaddress.IPv6Network('2001:db8:1234::/48').reverse_pointer
'4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa'
>>> ipaddress.IPv6Address('2001:db8:1234::').reverse_pointer
'0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa'

For example, if you want to create a DNS zone for a /48 network, you want the zone to be defined as 4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa. The rest of the "missing" hex digits belong to the host address, not the network prefix, those would be written inside the zone file for each host.

If I misunderstood what you meant, please correct me :)

@Forst Forst force-pushed the 30528-ipaddress-network-reverse-pointer branch from e7d455f to d23771e Compare March 6, 2022 12:38
@Forst Forst force-pushed the 30528-ipaddress-network-reverse-pointer branch from d23771e to 556bdf7 Compare April 11, 2022 21:01
@cpython-cla-bot
Copy link

cpython-cla-bot bot commented Apr 11, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

@Forst Forst force-pushed the 30528-ipaddress-network-reverse-pointer branch from 556bdf7 to dd6b08f Compare April 11, 2022 21:09
@Forst Forst changed the title bpo-30528: ipaddress: support reverse pointer generation for network objects gh-issue-74713: ipaddress: support reverse pointer generation for network objects Apr 11, 2022
… networks

Before this change, DNS reverse pointer generation for network objects produced incorrect results, such as:

>>> ipaddress.IPv4Network('192.168.1.0/24').reverse_pointer
'0/24.1.168.192.in-addr.arpa'
>>> ipaddress.IPv6Network('2001:db8:1234::/48').reverse_pointer
'8.4./.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa'

This change introduces a more generalised reverse pointer generation algorithm, suitable for both address and network
objects.

The same code above, after applying this change:

>>> ipaddress.IPv4Network('192.168.1.0/24').reverse_pointer
'1.168.192.in-addr.arpa'
>>> ipaddress.IPv6Network('2001:db8:1234::/48').reverse_pointer
'4.3.2.1.8.b.d.0.1.0.0.2.ip6.arpa'

Getting a reverse pointer for a network, whose prefix size can't be exactly represented in a reverse pointer record,
will raise an exception:

>>> ipaddress.IPv4Network('192.168.1.0/28').reverse_pointer
ipaddress.NetmaskValueError: Reverse pointer cannot be generated for given prefix size
>>> ipaddress.IPv6Network('2001:db8:1234::/50').reverse_pointer
ipaddress.NetmaskValueError: Reverse pointer cannot be generated for given prefix size
@Forst Forst force-pushed the 30528-ipaddress-network-reverse-pointer branch from dd6b08f to 630f24a Compare April 11, 2022 21:12
@Forst Forst changed the title gh-issue-74713: ipaddress: support reverse pointer generation for network objects gh-74713: ipaddress: support reverse pointer generation for network objects Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants