From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 56BE35A0276; Fri, 12 Apr 2024 00:18:00 +0200 (CEST) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH] netlink: Drop point-to-point peer information when we copy addresses Date: Fri, 12 Apr 2024 00:18:00 +0200 Message-ID: <20240411221800.548178-1-sbrivio@redhat.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: GMQ2B32CKWK3KBZZHVC5SR2JPOL6R56Z X-Message-ID-Hash: GMQ2B32CKWK3KBZZHVC5SR2JPOL6R56Z X-MailFrom: sbrivio@passt.top 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: If the template host interface is of type tun, and it's configured with a point-to-point peer address (that's what happens for example with openvpn and '--topology net30'), pasta will copy the peer information onto the namespace interface. But the namespace interface is not actually a point-to-point tunnel, and we won't resolve the peer address via ARP either, so we have to drop this information to get the expected behaviour (traffic regularly sent over our tap interface). Link: https://github.com/containers/podman/issues/22320 Signed-off-by: Stefano Brivio --- netlink.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/netlink.c b/netlink.c index 89c0641..73aaa4b 100644 --- a/netlink.c +++ b/netlink.c @@ -792,8 +792,8 @@ int nl_addr_dup(int s_src, unsigned int ifi_src, seq = nl_send(s_src, &req, RTM_GETADDR, NLM_F_DUMP, sizeof(req)); nl_foreach_oftype(nh, status, s_src, buf, seq, RTM_NEWADDR) { + struct rtattr *rta, *rta_local = NULL; struct ifaddrmsg *ifa; - struct rtattr *rta; size_t na; ifa = (struct ifaddrmsg *)NLMSG_DATA(nh); @@ -804,12 +804,33 @@ int nl_addr_dup(int s_src, unsigned int ifi_src, ifa->ifa_index = ifi_dst; + for (rta = IFA_RTA(ifa), na = IFA_PAYLOAD(nh); RTA_OK(rta, na); + rta = RTA_NEXT(rta, na)) { + if (rta->rta_type == IFA_LOCAL) { + rta_local = rta; + break; + } + } + for (rta = IFA_RTA(ifa), na = IFA_PAYLOAD(nh); RTA_OK(rta, na); rta = RTA_NEXT(rta, na)) { /* Strip label and expiry (cacheinfo) information */ if (rta->rta_type == IFA_LABEL || rta->rta_type == IFA_CACHEINFO) rta->rta_type = IFA_UNSPEC; + + /* Different values for IFA_ADDRESS and IFA_LOCAL mean + * that IFA_LOCAL is the locally configured address, and + * IFA_ADDRESS is the peer address for a point-to-point + * interface. But our namespace interface isn't really a + * point-to-point tunnel, and we can't resolve that peer + * address via ARP: simply drop it, and keep the local + * address. + */ + if (rta->rta_type == IFA_ADDRESS && rta_local) { + memcpy(RTA_DATA(rta), RTA_DATA(rta_local), + RTA_PAYLOAD(rta)); + } } rc = nl_do(s_dst, nh, RTM_NEWADDR, -- 2.43.0