[v6ops] gai_wrap.py

Brian E Carpenter <brian.e.carpenter@gmail.com> Mon, 16 May 2022 04:39 UTC

Return-Path: <brian.e.carpenter@gmail.com>
X-Original-To: v6ops@ietfa.amsl.com
Delivered-To: v6ops@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 5D931C2740DF for <v6ops@ietfa.amsl.com>; Sun, 15 May 2022 21:39:46 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.097
X-Spam-Level:
X-Spam-Status: No, score=-2.097 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_BLOCKED=0.001, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zniMa5jmEn1E for <v6ops@ietfa.amsl.com>; Sun, 15 May 2022 21:39:45 -0700 (PDT)
Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 0079AC2B5514 for <v6ops@ietf.org>; Sun, 15 May 2022 21:39:44 -0700 (PDT)
Received: by mail-pf1-x42c.google.com with SMTP id y41so12972633pfw.12 for <v6ops@ietf.org>; Sun, 15 May 2022 21:39:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:from:subject:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=n26fu56WsoG5+yZA4SvsGWmlJoYQvjJaEgI1i/sB6os=; b=LcmHzWpQdNq1zRlyMAcOofQLBJBCsL+hUvlzde4bvl0upvNEJQdd3wxCTgd+VT+vWY QcvmRvK0Tv+BQoBQ8+f4Ip7mfktKSvxOjTX+XICJuDAKlfigqfnuLNYSVIBhRv/XTkNz t2hni+ilbKi1WU5Gi3m9UaFTHhlw8qxCippJhoD69hYmqf9IcFITZdkPvgZKcJVeE/gW ObzR6YujS2QKiFVYykWxacLq3edUQnd4DLotbpLC1FAYjppDhvCNLWvKQ2rLYbYYzYfc W2KTXlXPU0tAOyjXd0Otrkhwabcshs6wiIiv2aqxVI8vxvYcUADmvflTpsCMSebzYKhS UeGQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=n26fu56WsoG5+yZA4SvsGWmlJoYQvjJaEgI1i/sB6os=; b=gIqIguVr53l9K+MYCLBLWU85CRiIHDBH5pbSGT3YH1YNM5muJZONBVdybSOgtLKk/G 4IvLCAXNlBkMDX40IkxpRrprQoAJIlNjKNTPpqQMRkWaQMXOe3HSecUm39khBBv5n7gC RPuRqEyntTDjvNTPpqrxwEAK/c8hLZtEyCxNGlbLnB5Coqsrncgi5O9z8k34zjhGHKSU /0Ns4i4Le6ncBwYDb5kKOWnXUWwqYNUVciyJZFQMgIjCleCilVe5m9Z+0QP7yPPeoLAW YC1XVqjYNoQm69xKBENXbPQKAQN2xg9GmpNWaH9ppdu6YCu+RI3Po4Rn6BTujpY6o0LN nKsw==
X-Gm-Message-State: AOAM531FW/A/hqPkTuBPQOiwfzxzOaEHqvQauhRqdza5PBqLqQmge7pb QPG55yT1LG8W6nt9W2OGp/yoHQ6mXWyW0Q==
X-Google-Smtp-Source: ABdhPJxBy83u8hHTGSsjsS/9WnmPxMMVjXypXnIOWnC86Pmcx7Lu4P/l2yncUNt+zIdsz6TfyLY34A==
X-Received: by 2002:a05:6a00:198f:b0:50d:bf61:3de9 with SMTP id d15-20020a056a00198f00b0050dbf613de9mr15713932pfl.16.1652675984093; Sun, 15 May 2022 21:39:44 -0700 (PDT)
Received: from ?IPv6:2406:e003:1005:b501:80b2:5c79:2266:e431? ([2406:e003:1005:b501:80b2:5c79:2266:e431]) by smtp.gmail.com with ESMTPSA id i9-20020a632209000000b003db7de758besm5867140pgi.5.2022.05.15.21.39.41 for <v6ops@ietf.org> (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 15 May 2022 21:39:42 -0700 (PDT)
To: IPv6 Operations <v6ops@ietf.org>
From: Brian E Carpenter <brian.e.carpenter@gmail.com>
Message-ID: <a00b74d1-a483-997d-1812-49ddeb58311a@gmail.com>
Date: Mon, 16 May 2022 16:39:37 +1200
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"; format="flowed"
Content-Language: en-US
Content-Transfer-Encoding: 7bit
Archived-At: <https://mailarchive.ietf.org/arch/msg/v6ops/W1-I0RDb3F2F5B8CEx_bpYsXdRk>
Subject: [v6ops] gai_wrap.py
X-BeenThere: v6ops@ietf.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: v6ops discussion list <v6ops.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/v6ops>, <mailto:v6ops-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/v6ops/>
List-Post: <mailto:v6ops@ietf.org>
List-Help: <mailto:v6ops-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/v6ops>, <mailto:v6ops-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 16 May 2022 04:39:46 -0000

Another toy for ULA users, but only for those coding in Python.

This module provides a wrapper for getaddrinfo(). It does
*exactly* what getaddrinfo() normally does, but it re-sorts
the answers to achieve the same result as indicated by
RFC 6724 section 10.6, *regardless* of the settings in
the host operating system.

To do this, it determines and caches any ULA /48 prefixes
in which the host has at least one address configured;
the cache will be refreshed if more than 60 seconds old.

(Yes, this assumes that if a host has a ULA address, the
corresponding /48 is alive and well.)

Tested on Windows 10 and Linux 5.4.0.

https://github.com/becarpenter/misc/blob/main/gai_wrap.py

Put it in your Python path and do "from gai_wrap import getaddrinfo"

Bugs and comments welcome.

Regards
    Brian Carpenter