From patchwork Tue Dec 1 14:31:50 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 10940 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (Client CN "mail01.haj.ipfire.org", Issuer "YR1" (not verified)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4jf3Hs4TCzz3www for ; Tue, 01 Dec 2026 14:32:09 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [IPv6:2001:678:b28::201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (Client CN "mail02.haj.ipfire.org", Issuer "YE2" (not verified)) by mail01.ipfire.org (Postfix) with ESMTPS id 4jf3Hr0rYRz7P8 for ; Tue, 01 Dec 2026 14:32:08 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [IPv6:::1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4jf3Hq3nYcz2xsW for ; Tue, 01 Dec 2026 14:32:07 +0000 (UTC) X-Original-To: development@lists.ipfire.org Received: from mail01.ipfire.org (mail01.haj.ipfire.org [IPv6:2001:678:b28::25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (Client CN "mail01.haj.ipfire.org", Issuer "YR1" (not verified)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4jf3Hm4SfSz2y0C for ; Tue, 01 Dec 2026 14:32:04 +0000 (UTC) Received: from mout-b-203.mailbox.org (mout-b-203.mailbox.org [IPv6:2001:67c:2050:102:465::203]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bit raw public key) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.mailbox.org", Issuer "Thawte TLS RSA CA G1" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4jf3Hk1fZ2z71B for ; Tue, 01 Dec 2026 14:32:02 +0000 (UTC) Authentication-Results: mail01.ipfire.org; dkim=pass header.d=mandelbit.com header.s=MBO0001 header.b=wxRJDWBn; dmarc=none; spf=pass (mail01.ipfire.org: domain of antonio@mandelbit.com designates 2001:67c:2050:102:465::203 as permitted sender) smtp.mailfrom=antonio@mandelbit.com ARC-Seal: i=1; a=rsa-sha256; d=lists.ipfire.org; s=202003rsa; cv=none; t=1796135524; b=dj0fhvWUHdNnWxZWTmBlrj8RAJzpa1eq0FF+f/cdMUeeqZr+LWHDuApltrzkwRnfjaHSQy sc++IkYGGHzz4A48cF99QTL7/Y6Mu+4J0nqCcm2gR3H+AjXA9s5Wif8D9eeN/axkAEAU7B TcYLf59hMAmcyIibUiNDOtzTPxs7YxtAIm1v65IwRNfhsfN/IuxtsQzFXIpGoyERhWdFPz VUmNPpOXQm5cgBMtyaYRnyk1DuToDioR7tRNsMt16wvcPRTTPhhN2zEVUCqvF0+N35MMx6 HwCoaBDcuEbcnrsZtdPY8pxHjx03awh5FjwjxHpuTJqF8xM7tJqsTLSnRhrExg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1796135524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rVJjT+XLzyKrMPoib3hu1Br6xURvlEz6djZChAUDduc=; b=AAY9hb8J1ufflfdv5YEFeUZ40UH3cPJLZPxmpEyhY+Z2HKFIpVacmMQ9jqNPntnfx0NsZr 4BNNvCNBuBhNZX0xa7ZwQ+wYKQ08qmKP5kOiwLuJz98UnYsU918vhioNrIca852MujvNq+ SC6aFJL2xDsLCDX9lB4iwQLeX40c6IYbdjdqkdlZ5E6EkbZc49VamnytRvdCeyVsvAzf7t /uIggbvjhYzJHL5Bs1bR3y77WQBywss72H56f50lKhdSQkUd//uijNdS/6K8js6lGC1Xzl pSjZdZ7YPhmw0OZX2w7XgpEaNL1Y6RKSMLZTpEPjZxGYPlgDINAkvj48DS6htg== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=pass header.d=mandelbit.com header.s=MBO0001 header.b=wxRJDWBn; dmarc=none; spf=pass (mail01.ipfire.org: domain of antonio@mandelbit.com designates 2001:67c:2050:102:465::203 as permitted sender) smtp.mailfrom=antonio@mandelbit.com Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA512) (No client certificate requested) by mout-b-203.mailbox.org (Postfix) with ESMTPS id 4jf3Hg45LmzLmK4; Tue, 01 Dec 2026 15:31:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1796135519; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rVJjT+XLzyKrMPoib3hu1Br6xURvlEz6djZChAUDduc=; b=wxRJDWBndD63M5qrB15SiFUoRmujsRA88yT765HmJwxCrQkFKddGF9sPbcAwzrcRqaIVsd IxhudbQ6X2lQE4kSWPOmMWXXbdstYD8QcpXORjPuwu0ZUAw7Vsf062bm6MCNiepDhzx3Ba 79FpgAnk1BWvux1uhDOBcO3BeJ/xYi9C4QLYRw5MpRPhhJTlMPLx+WwmuNW9E/ReQbz9Ho 1bJZ72C8dPfGA94C88EXKEIwvQ/gGEi4ddI65+bZs/lqDbzU1+rUjv6nopjbKl9iia2jjZ 9usQejK8/pAJyU4hJKVaLXx4j3oWI5ZLWNHKHY3/AksFbDk7ST+b21BHKeethA== From: Antonio Quartulli To: development@lists.ipfire.org Cc: Antonio Quartulli Subject: [PATCH 1/4] network-functions.pl: Add ip_address_is_global() Date: Tue, 1 Dec 2026 15:31:50 +0100 Message-ID: <20261201143155.1798388-2-antonio@mandelbit.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201143155.1798388-1-antonio@mandelbit.com> References: <20261201143155.1798388-1-antonio@mandelbit.com> Precedence: list List-Id: List-Subscribe: , List-Unsubscribe: , List-Post: List-Help: Sender: Mail-Followup-To: MIME-Version: 1.0 X-Rspamd-Action: no action X-Spamd-Result: default: False [-5.10 / 11.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM(-3.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_SPF_ALLOW(-0.20)[+ip6:2001:67c:2050::/48]; R_DKIM_ALIGNED(-0.10)[strict]; RCVD_IN_DNSWL_LOW(-0.10)[2001:67c:2050:b231:465::102:received]; R_DKIM_ALLOW(-0.10)[mandelbit.com:s=MBO0001]; MIME_GOOD(-0.10)[text/plain]; TO_DN_SOME(0.00)[]; IP_REPUTATION_HAM(0.00)[asn: 199118(-0.35),country: DE(-0.01),ip: 2001:67c:2050:102::(0.00)]; DMARC_NA(0.00)[mandelbit.com]; RCPT_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; MX_INFLIGHT(0.00)[mxext3.mailbox.org]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[mandelbit.com:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; DKIM_REPUTATION(0.00)[0]; RCVD_COUNT_ONE(0.00)[1]; ASN(0.00)[asn:199118,ipnet:2001:67c:2050::/48,country:DE]; FROM_HAS_DN(0.00)[] X-Rspamd-Server: mail01.haj.ipfire.org X-Rspamd-Queue-Id: 4jf3Hk1fZ2z71B Returns whether an IPv4 address can be reached from the Internet, based on the IANA special-purpose address registry. Signed-off-by: Antonio Quartulli --- config/cfgroot/network-functions.pl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl index a90655305..9f37c490f 100644 --- a/config/cfgroot/network-functions.pl +++ b/config/cfgroot/network-functions.pl @@ -425,6 +425,23 @@ sub ip_address_in_range($$) { return (($ipaddress_bin >= $ipstart_bin) && ($ipaddress_bin <= $ipend_bin)); } +# Returns true if the IPv4 address can be reached from the Internet, i.e. it +# isn't in any of the special-purpose ranges that aren't globally reachable +# (based on the IANA registry). +sub ip_address_is_global($) { + my $address = shift; + + return 0 unless (&check_ip_address($address)); + + foreach my $network ("0.0.0.0/8", "10.0.0.0/8", "100.64.0.0/10", "127.0.0.0/8", + "169.254.0.0/16", "172.16.0.0/12", "192.0.0.0/24", "192.0.2.0/24", "192.168.0.0/16", + "198.18.0.0/15", "198.51.100.0/24", "203.0.113.0/24", "240.0.0.0/4") { + return 0 if (&ip_address_in_network($address, $network)); + } + + return 1; +} + sub check_port { $_ = $_[0]; @@ -1022,6 +1039,18 @@ sub testsuite() { $result = &ip_address_in_range("192.168.30.21", "192.168.30.10", "192.168.30.20"); assert('ip_address_in_range("192.168.30.21", "192.168.30.10", "192.168.30.20")', !$result); + # Check &ip_address_is_global() + foreach my $address ("81.3.27.37", "8.8.8.8", "1.0.0.0", "100.63.255.255", "100.128.0.0", + "169.253.255.255", "172.15.255.255", "172.32.0.0", "224.0.0.1", "239.255.255.255") { + assert("ip_address_is_global(\"$address\")", &ip_address_is_global($address)); + } + + foreach my $address ("10.1.2.3", "172.16.0.0", "172.31.255.255", "192.168.1.1", "100.64.0.0", + "100.127.255.255", "127.0.0.1", "169.254.0.0", "169.254.255.255", "0.255.255.255", + "192.0.2.1", "198.18.0.1", "240.0.0.0", "255.255.255.255", "a.b.c.d", "") { + assert("!ip_address_is_global(\"$address\")", !&ip_address_is_global($address)); + } + # Check &get_prefix() $result = &get_prefix("192.168.0.0/24"); assert('get_prefix("192.168.0.0/24")', $result == 24);