From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VBDK/ZR0; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id DE6D65A004E for ; Thu, 23 Jan 2025 12:49:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737632950; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=H+eJSyX5YxsxJEynpG7G4o5FE9jheDSxBwPQ807h6WM=; b=VBDK/ZR0etc+OBe5+W9D1VCFFqoRyohqz/j3Q0SsYimDd4cc0EFSYjKyYfO5iUbzrP/E2y 0voAncU1Rh6E08N5Ba0O9OQChHUZ/LE1JpuZB5BOCJcc5Ui8cBbLvS2nmBsEkSPNHNarMh Do5kVwgRGsv5XMsom+HJxaYNeTaZnes= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-619-KwVs6bXLOZ-pTx9ioA9jqg-1; Thu, 23 Jan 2025 06:49:09 -0500 X-MC-Unique: KwVs6bXLOZ-pTx9ioA9jqg-1 X-Mimecast-MFC-AGG-ID: KwVs6bXLOZ-pTx9ioA9jqg Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-38639b4f19cso540220f8f.0 for ; Thu, 23 Jan 2025 03:49:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737632948; x=1738237748; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=H+eJSyX5YxsxJEynpG7G4o5FE9jheDSxBwPQ807h6WM=; b=AN6Il+SadUYnu/r/faIsCxol5RzvAs7kVkeTR2/m+wGiHiUZRLHLdV7JSHQIp9y87n zVGqeYVRJVTH4Oszdcr6NlSkfudPEWo/KX9XucxoytAqhDW782zXZkuduWMVHqjdeQmA a/9moulEPSq0iyUWpy228qSQ75cLrjfy+fft4+cJ0CIG5ztUlTfQxpXmXf24sHFMWrS9 PHx7Erh3KGKk8Y8VPTmyWADFa2rC0T7sqEmBhWDL0Wu5TR5Noq5MnrzavdSh33fpc0qG CByWX6fYWInXjGpidj+QLDwN5zNizQpj1oP3N2fh116J2sCdMwdQ+LxtaVoCY48q2abO csWg== X-Forwarded-Encrypted: i=1; AJvYcCWSH2N1WVcDV5svKdjYfb6/wcymjhY1SrqMrdIQ0JaeUQ9kX7zO8g4eTiEnw77ZdlV0mqhvuUY9m+o=@passt.top X-Gm-Message-State: AOJu0YzQx7ZkxifgxBl71JypsQcqk0gyGY1p0Ts3MYEAowBs1Pk/ch1W ZaBnJJU9dLZe/uhCwlLQWjS6mHahYqmDPd1Zv5KW+sDmLXsampXShUQt/phjMovM8zQAbfZT4tc pm8cypbpACX36ZHoa0IKKZ0g1t6Y4r4la3YJB5AiVoJCv6wX64TxBvRZqOg== X-Gm-Gg: ASbGncuQzmanYGEkkg1AuLY4ZGNjkw+7ys2cUxRhsl/AItSyUyr+nVjnCdzxHx2wwDF df8jDOHdbiKaUVb4uQHNtJLGCeiUntJX56Ro3huJDMU8vHVeyaha6euZdSqjarQT6nf2ZcPChey 8Xccx3BO01TwUInO1GLcr71dxBMbgIZFNv2rMHdd4TnbkkvmiiD1tkFdU7p+J1XbiXuzUSCKH54 cPnQ5yyeXn+AqPuYhrZTDAK9mAAI16hf5qcADsksh/Cde1k2QfeXTsFIQPqtJxxX8TvqTE0m6g= X-Received: by 2002:a5d:47a3:0:b0:382:3959:f429 with SMTP id ffacd0b85a97d-38bf5649664mr23460686f8f.5.1737632948053; Thu, 23 Jan 2025 03:49:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHCoM5cB5UyKqEhGotAuTUl/bnDPVv2BgsN+2LDiveHxyDtfiM15UuWL/2z0RgkFL1eUHO+yQ== X-Received: by 2002:a5d:47a3:0:b0:382:3959:f429 with SMTP id ffacd0b85a97d-38bf5649664mr23460670f8f.5.1737632947670; Thu, 23 Jan 2025 03:49:07 -0800 (PST) Received: from [192.168.188.25] ([80.243.52.133]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38bf32754f5sm19273609f8f.79.2025.01.23.03.49.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Jan 2025 03:49:07 -0800 (PST) Message-ID: <07aa7b5d-27b9-4494-88db-d675b7489f68@redhat.com> Date: Thu, 23 Jan 2025 12:49:06 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] netlink: Skip loopback interface while looking for a template To: Stefano Brivio , passt-dev@passt.top References: <20250123080548.1410738-1-sbrivio@redhat.com> From: Paul Holzinger In-Reply-To: <20250123080548.1410738-1-sbrivio@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: VIngHC0kMoSeK5Iifmh38k0aduliHWWnddCcnPJKYmA_1737632948 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: HEZG5SUDOBPKKYIXH2MMZLTAG2PMPIPC X-Message-ID-Hash: HEZG5SUDOBPKKYIXH2MMZLTAG2PMPIPC X-MailFrom: pholzing@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 23/01/2025 09:05, Stefano Brivio wrote: > There might be reasons to have routes on the loopback interface, for > example Any-IP/AnyIP routes as implemented by Linux kernel commit > ab79ad14a2d5 ("ipv6: Implement Any-IP support for IPv6."). > > If we use the loopback interface as a template, though, we'll pick > 'lo' (typically) as interface name for our tap interface, but we'll > already have an interface called 'lo' in the target namespace, and as > we TUNSETIFF on it, we'll fail with EINVAL, because it's not a tap > interface. > > Skip the loopback interface while looking for a template interface or, > more accurately, skip the interface with index 1. > > Strictly speaking, we should fetch interface flags via RTM_GETLINK > instead, and check for IFF_LOOPBACK, but interleaving that request > while we're iterating over routes is unnecessarily complicated. I think hard coding 1 is fine but I think there is also the IFF_LOOPBACK flag that could be used instead. From strace: ifi_index=if_nametoindex("lo"), ifi_flags=IFF_UP|IFF_LOOPBACK|IFF_RUNNING|IFF_LOWER_UP > > Link: https://www.reddit.com/r/podman/comments/1i6pj7u/starting_pod_without_external_network/ > Signed-off-by: Stefano Brivio > --- > netlink.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/netlink.c b/netlink.c > index 0407692..37d8b5b 100644 > --- a/netlink.c > +++ b/netlink.c > @@ -297,6 +297,10 @@ unsigned int nl_get_ext_if(int s, sa_family_t af) > if (!thisifi) > continue; /* No interface for this route */ > > + /* Skip 'lo': we should test IFF_LOOPBACK, but keep it simple */ > + if (thisifi == 1) > + continue; > + > /* Skip routes to link-local addresses */ > if (af == AF_INET && dst && > IN4_IS_PREFIX_LINKLOCAL(dst, rtm->rtm_dst_len)) -- Paul Holzinger