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=XW3oF7Yt; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 659375A026E for ; Thu, 15 Aug 2024 08:53:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723704794; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JLqR36C0xRO/eW7LQx3A1nF1aTyoHN9uAjnEg0JMaBc=; b=XW3oF7Yti25W/qj/ix+P9b71QLMUCJdgLW0+iC+9+7zoJTwSGtLqBbsTunT7poLu51E3Ee WQ3hHVLLl4TihHk9CEbBskP34r3PSlutWKqsdi6ceIzFEJpfE0wGTbvMlPwTEkepDzfZoh Hh9L+/ugdDZB2a8cj6sM9vOCNkPeqrI= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-vqdGUP76PhSPyVXR-zIpNQ-1; Thu, 15 Aug 2024 02:53:07 -0400 X-MC-Unique: vqdGUP76PhSPyVXR-zIpNQ-1 Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-2d3ce4f35c1so152533a91.1 for ; Wed, 14 Aug 2024 23:53:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723704786; x=1724309586; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=JLqR36C0xRO/eW7LQx3A1nF1aTyoHN9uAjnEg0JMaBc=; b=sV5Gk5A5Qma458f3oVG416JyHufxxN33PRKP0aIs1CDyiUN5Sl6RJHoVOQH57A9QfB S2/Y3Fe4NzVBV6c+7oxaU5ydjrA3CH0VoMFmr1wBU4ACSUZW+YMBWCuKcNHWKccJT638 sUTfLTPfHFofpt0nYXF5SqSOGsnr9tOYBfbBEmkvfSqHT6bNf8DKhmYt5JHSV5g+CNAX oUIoG0nH0kf3ne0T58wMr5ON62iRE3VVIzoyjzz0uZm6u337ymhFnaYzpgxAXxmqLtlw /Wh3Lf7wZzgZzebyKQ+Vf9bz/TMhgicYEkXaOKaAwjo94dO4FcPCnt8Wi1U0aZDwkRiA zmyg== X-Gm-Message-State: AOJu0YwudWmsrV0p/pFNhRdpsDPA+wpSN9SKZVz5/CUZLd2o7sqt6DyZ t634y2dou8IBXmc9V1FWtdSb0UXfNl+Jr0L2VTazoSxxRU+0ZJpQ26751N9aCs5GGVySkoM67YV EdXDzsy0M9B7yXt8ueUkOVt0SqUaXp2HCS1X5kY8XctDfNY4x2A== X-Received: by 2002:a17:90b:1042:b0:2cb:4c30:51bd with SMTP id 98e67ed59e1d1-2d3c3a2a8f4mr3202039a91.19.1723704786230; Wed, 14 Aug 2024 23:53:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5ojmVPFTVnIPoUPjsEQYXah4Mo8T+BqqFHWnZDPVtyXNg1qIIVXm8zDGjK44pZN9Cx3yt9w== X-Received: by 2002:a17:90b:1042:b0:2cb:4c30:51bd with SMTP id 98e67ed59e1d1-2d3c3a2a8f4mr3202016a91.19.1723704785779; Wed, 14 Aug 2024 23:53:05 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d3c87670bbsm717219a91.16.2024.08.14.23.53.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Aug 2024 23:53:05 -0700 (PDT) Date: Thu, 15 Aug 2024 08:53:02 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 5/7] netlink, pasta: Fetch link-local address from namespace interface once it's up Message-ID: <20240815085302.7df90fa6@elisabeth> In-Reply-To: References: <20240814225429.3707908-1-sbrivio@redhat.com> <20240814225429.3707908-6-sbrivio@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: VG7IER26ZC7GDHBNRIUKNUHKMTTDF4RS X-Message-ID-Hash: VG7IER26ZC7GDHBNRIUKNUHKMTTDF4RS X-MailFrom: sbrivio@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 CC: passt-dev@passt.top, Paul Holzinger 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 Thu, 15 Aug 2024 13:04:42 +1000 David Gibson wrote: > On Thu, Aug 15, 2024 at 12:54:27AM +0200, Stefano Brivio wrote: > > As soon as we bring up the interface, the Linux kernel will set up a > > link-local address for it, so we can fetch it and start using right > > away, if we need a link-local address to communicate to the container > > before we see any traffic coming from it. > > > > Signed-off-by: Stefano Brivio > > --- > > netlink.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ > > netlink.h | 1 + > > pasta.c | 7 +++++++ > > 3 files changed, 55 insertions(+) > > > > diff --git a/netlink.c b/netlink.c > > index 4b49de1..3b37087 100644 > > --- a/netlink.c > > +++ b/netlink.c > > @@ -836,6 +836,53 @@ int nl_addr_get(int s, unsigned int ifi, sa_family_t af, > > return status; > > } > > > > +/** > > + * nl_addr_get_ll() - Get first IPv6 link-local address for a given interface > > + * @s: Netlink socket > > + * @ifi: Interface index in outer network namespace > > + * @addr: Link-local address to fill > > + * > > + * Return: 0 on success, negative error code on failure > > + */ > > +int nl_addr_get_ll(int s, unsigned int ifi, void *addr) > > Given this is explicitly for IPv6, I don't see a reason not to use > (struct in6_addr *addr) for greater type safety. I'll change that. > > +{ > > + struct req_t { > > + struct nlmsghdr nlh; > > + struct ifaddrmsg ifa; > > + } req = { > > + .ifa.ifa_family = AF_INET6, > > + .ifa.ifa_index = ifi, > > + }; > > + struct nlmsghdr *nh; > > + bool found = false; > > + char buf[NLBUFSIZ]; > > + ssize_t status; > > + uint32_t seq; > > + > > + seq = nl_send(s, &req, RTM_GETADDR, NLM_F_DUMP, sizeof(req)); > > + nl_foreach_oftype(nh, status, s, buf, seq, RTM_NEWADDR) { > > + struct ifaddrmsg *ifa = (struct ifaddrmsg *)NLMSG_DATA(nh); > > + struct rtattr *rta; > > + size_t na; > > + > > + if (ifa->ifa_index != ifi || ifa->ifa_scope != RT_SCOPE_LINK || > > + found) > > + continue; > > + > > + for (rta = IFA_RTA(ifa), na = IFA_PAYLOAD(nh); RTA_OK(rta, na); > > + rta = RTA_NEXT(rta, na)) { > > + if (rta->rta_type != IFA_ADDRESS) > > + continue; > > + > > + if (!found) { > > + memcpy(addr, RTA_DATA(rta), RTA_PAYLOAD(rta)); > > + found = true; > > + } > > + } > > + } > > + return status; > > +} > > + > > /** > > * nl_add_set() - Set IP addresses for given interface and address family > > * @s: Netlink socket > > diff --git a/netlink.h b/netlink.h > > index 66a44ad..bdfdef0 100644 > > --- a/netlink.h > > +++ b/netlink.h > > @@ -19,6 +19,7 @@ int nl_addr_get(int s, unsigned int ifi, sa_family_t af, > > void *addr, int *prefix_len, void *addr_l); > > int nl_addr_set(int s, unsigned int ifi, sa_family_t af, > > const void *addr, int prefix_len); > > +int nl_addr_get_ll(int s, unsigned int ifi, void *addr); > > int nl_addr_set_ll_nodad(int s, unsigned int ifi); > > int nl_addr_dup(int s_src, unsigned int ifi_src, > > int s_dst, unsigned int ifi_dst, sa_family_t af); > > diff --git a/pasta.c b/pasta.c > > index 838bbb3..cebf54f 100644 > > --- a/pasta.c > > +++ b/pasta.c > > @@ -340,6 +340,13 @@ void pasta_ns_conf(struct ctx *c) > > } > > > > if (c->ifi6) { > > + rc = nl_addr_get_ll(nl_sock_ns, c->pasta_ifi, > > + &c->ip6.addr_ll_seen); > > + if (rc < 0) { > > + die("Can't fetch LL address from namespace: %s", > > + strerror(-rc)); > > Again, we can generally cope with not having an addr_ll_seen > initially, so I think a warn() would make more sense. Of course. I'll fix this as well. -- Stefano