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

Improve the textual representation of IPv4-mapped IPv6 addresses #87799

Closed
maxmouchet mannequin opened this issue Mar 26, 2021 · 4 comments
Closed

Improve the textual representation of IPv4-mapped IPv6 addresses #87799

maxmouchet mannequin opened this issue Mar 26, 2021 · 4 comments
Labels
3.13 bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@maxmouchet
Copy link
Mannequin

maxmouchet mannequin commented Mar 26, 2021

BPO 43633
Nosy @opavlyuk, @maxmouchet
PRs
  • gh-87799: Improve the textual representation of IPv4-mapped IPv6 addresses #29345
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2021-03-26.17:34:40.530>
    labels = ['type-feature', 'library']
    title = 'Improve the textual representation of IPv4-mapped IPv6 addresses'
    updated_at = <Date 2021-11-01.12:05:04.773>
    user = 'https://github.com/maxmouchet'

    bugs.python.org fields:

    activity = <Date 2021-11-01.12:05:04.773>
    actor = 'opavlyuk'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2021-03-26.17:34:40.530>
    creator = 'maxmouchet'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 43633
    keywords = ['patch']
    message_count = 2.0
    messages = ['389556', '405434']
    nosy_count = 2.0
    nosy_names = ['opavlyuk', 'maxmouchet']
    pr_nums = ['29345']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue43633'
    versions = []

    @maxmouchet
    Copy link
    Mannequin Author

    maxmouchet mannequin commented Mar 26, 2021

    Python supports IPv4-mapped IPv6 addresses as defined by RFC 4038:
    "the IPv6 address ::FFFF:x.y.z.w represents the IPv4 address x.y.z.w.”

    The current behavior is as follows:

       from ipaddress import ip_address
       addr = ip_address('::ffff:8.8.4.4') # IPv6Address('::ffff:808:404')
       addr.ipv4_mapped # IPv4Address('8.8.4.4')

    Note that the textual representation of the IPv6Address is *not* in IPv4-mapped format.
    It prints ::ffff:808:404 instead of ::ffff:8.8.4.4.
    This is technically correct, but it’s somewhat frustrating as it makes it harder to read IPv4s embedded in IPv6 addresses.

    My proposal would be to check, in __str__, if an IPv6 is an IPv4-mapped, and to return the appropriate representation :

       from ipaddress import ip_address
       addr = ip_address('::ffff:8.8.4.4')
    
       # Current behavior
       str(addr)  # '::ffff:808:404'
       repr(addr) # IPv6Address('::ffff:808:404')
    
       # Proposed behavior
       str(addr)  # '::ffff:8.8.4.4'
       repr(addr) # IPv6Address('::ffff:8.8.4.4')

    A few data points:

    • Julia prints ::ffff:808:404 (current behavior)
    • C (glibc) and ClickHouse prints ::ffff:8.8.4.4 (proposed behavior)

    @maxmouchet maxmouchet mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Mar 26, 2021
    @opavlyuk
    Copy link
    Mannequin

    opavlyuk mannequin commented Nov 1, 2021

    @maxmouchet, thank you for creating the issue.
    For me it makes sense, and RFC 4291 calls such IPv6 text representation approach as "more convenient".

    I'll try to fix this, if you don't mind.
    P.S.: Sorry for providing PR before I asked.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @arhadthedev arhadthedev added the 3.13 bugs and security fixes label May 13, 2023
    asvetlov added a commit that referenced this issue Jul 31, 2023
    …esses (#29345)
    
    Represent IPv4-mapped IPv6 address as x:x:x:x:x:x:d.d.d.d,
    where the 'x's are the hexadecimal values
    of the six high-order 16-bit pieces of the address,
    and the 'd's are the decimal values
    of the four low-order 8-bit pieces of the address
    (standard IPv4 representation).
    
    ---------
    
    Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
    Co-authored-by: Andrew Svetlov <[email protected]>
    @asvetlov
    Copy link
    Contributor

    Done by #29345

    @kellyjonbrazil
    Copy link

    kellyjonbrazil commented Aug 1, 2024

    Are there any tests for the reverse_pointer method? I'm seeing strange results with the new behavior:

    IP Address: ::FFFF:192.168.1.35

    Results in a reverse_pointer of:

    5.3...1...8.6.1...2.9.1.f.f.f.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa

    instead of the old:

    3.2.1.0.8.a.0.c.f.f.f.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa

    I'm not sure which one is more valid or if a pointer record is even relevant in the context of mapped addresses. The original way seems more correct to me if nothing for the fact that there are strange extra dots in the new output.

    (I'll create a new issue for this since this one is closed)

    encukou pushed a commit that referenced this issue Sep 2, 2024
    GH-123419)
    
    Fix functionality that was broken with better textual representation for IPv4-mapped addresses (gh-87799)
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Sep 2, 2024
    …dresses (pythonGH-123419)
    
    Fix functionality that was broken with better textual representation for IPv4-mapped addresses (pythongh-87799)
    (cherry picked from commit 77a2fb4)
    
    Co-authored-by: Bénédikt Tran <[email protected]>
    Yhg1s pushed a commit that referenced this issue Sep 2, 2024
    …ddresses (GH-123419) (#123606)
    
    gh-123409: fix `IPv6Address.reverse_pointer` for IPv4-mapped addresses (GH-123419)
    
    Fix functionality that was broken with better textual representation for IPv4-mapped addresses (gh-87799)
    (cherry picked from commit 77a2fb4)
    
    Co-authored-by: Bénédikt Tran <[email protected]>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.13 bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants