From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 89CAB194147 for ; Mon, 20 Jan 2025 10:45:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737369903; cv=none; b=ZJxfxbBo4H4vTfc1ZVd5BDseAuu5Mj9B/8QE6b6ZYS2+FesEect6t9Q8q0p/Y6ihSHniML4bl2qAuARUN8VsXrZzBn3T55MycvCvCOznBzD0AcTq/XwSJohwbpXYalx07Wzs9ITAo5U1Puo8jE7R4AsZaVClNrtLwgZ9+pmE8eI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737369903; c=relaxed/simple; bh=ZwbFzqUySg04g+J61JRhojFx9CIb7wZjgIo/yIp/HTQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=VDpdNPg9Jk2f66UFdovXnIXLb9+O35vU2O8M+KpLxMVEiKfOlOJye6e0kvDIM8Sx1NBu2rPHGjuvklWK/TApVjZL10zTttsl+tmC8LKF7PqIcHsctV43Fzv7hWOY11zAJ7/7f4O31R6Q+B9v5qNNBLuE5gBScC29gcSynQpVgpg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=openvpn.net; spf=pass smtp.mailfrom=openvpn.com; dkim=pass (2048-bit key) header.d=openvpn.net header.i=@openvpn.net header.b=LYhlgR6B; arc=none smtp.client-ip=209.85.208.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=openvpn.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=openvpn.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=openvpn.net header.i=@openvpn.net header.b="LYhlgR6B" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5d9837f201aso9879629a12.0 for ; Mon, 20 Jan 2025 02:45:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvpn.net; s=google; t=1737369900; x=1737974700; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=MqJKhy5kLhVFaIapkuvUo4we5xGxARCqFNLks0rY808=; b=LYhlgR6BIwi3ZDKDRQgrcAx77TQYkzUXmCikHLqXmIqiUJkscHdT5aiGYA28wYObz8 xBNXoIa61BzTJAuC/nJsgFsi4msRNtB5it/E0WO9A29kbRCi+SyQsc6sG2sOxmvjX1Ia tjVVULZZWt2fWbu13nMVIXaHQO6A5AQsKGggmStk21SjZbIflrePkDP5JaWmLkwiFznh ehchGjkjZQUhPTNYpdK8THBCjKSD6d6OJEFK8m1fInPgYd4ZKRT5uqXPYen9aAnCRWkU FEbn38q18yoXs4tLBXi9FnKmTj9ZqRI4BwSZE50Y62eJ+8FW09NlWRzl5fhbacTBbWMk rIUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737369900; x=1737974700; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=MqJKhy5kLhVFaIapkuvUo4we5xGxARCqFNLks0rY808=; b=JCFEKJMUg6eoLiraN+SBPiJW3AwgYmR+BwrDJF194HHKuK0C6ppRZr6THSpI1ktnNR yVUhb02dGMjQ0J/Axo8LtOiQ4sTyx4JLS+7/mB99pk/QtQ8TzxIfjYs2KvNUMy+BcTWg LluBk+NLzjLedvq6uofCp1yIdtgnoX8X6AiXnACgCR1W1+dYZ4t4UnRqoGW0/ucijFUQ MI3oeFX4JbNt3IksEBkZ4PwgG+5/F7t1ObhSQmNUuCiYKV4ZQGNS4NOpIRAOXplXGZJZ dNT9DhRRC+neVN6RUBNC2iVpNVtciLyA29xvRaWsDGHb21ZqPEAzkkOAqJDlTc3qn49X 4iwA== X-Forwarded-Encrypted: i=1; AJvYcCUIeTwoAhhdxwfOH16KmERjOoqCOC1TwrDCk9Gt1ETDRZ+oj09lP2BTLabTbSUGvlfZe+Dh10iewN+X/ro=@vger.kernel.org X-Gm-Message-State: AOJu0YxJDBBItDwXxuuvFF3o9TlmMkSaZnMt0kgtD0z0Wqmc0Kyzllp6 KIW69fqm9AXlnnybBWmMlNJP6+LV68y4WQ0o4KKFBtq0cIFOug9oaFwM9bSd1js= X-Gm-Gg: ASbGncu5OVvM6UbqqnCaDF1q6+d9+dCT7AMaM1yhob6LJnaHyhL20Zcy1y6xLK6EDTk xsOv7nQb3gn57oszy+zEWdFXzYaBL0PloGCH/D28pC6CdewqPvTY4ez7HbiPiWtYFArERLMwgK9 Mvk1k4fmy+Pc4qQD80jPURomg64iSRkvb2qv8OosbaoW5dsVc1A2/agAtlwIpx1v6YRjk+DQcRW 9KbY05ZXGGik36amUegHq5klI1KZN4OWY7TIcT5dde7+UT28BJ+gRz7xeZkdPFZpLpoKbA8C9t8 SmvJ9Jjxg9qhAb4qs/3P3F+/+4sPCeeV X-Google-Smtp-Source: AGHT+IF3fRbQ2Fvy6yFQwmK5hjjFl8KNGcFaD5RvsN+jHayRTJvYfGjls6RNCvLX8y/OMC3QbGKYMg== X-Received: by 2002:a17:906:f887:b0:ab3:9aba:ce7d with SMTP id a640c23a62f3a-ab39abad4c6mr784865566b.1.1737369899687; Mon, 20 Jan 2025 02:44:59 -0800 (PST) Received: from ?IPV6:2001:67c:2fbc:1:113d:ece6:3d2f:3a40? ([2001:67c:2fbc:1:113d:ece6:3d2f:3a40]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ab384f2903esm602969066b.109.2025.01.20.02.44.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Jan 2025 02:44:59 -0800 (PST) Message-ID: <94e44fdb-314c-41b0-8091-cff5789735b2@openvpn.net> Date: Mon, 20 Jan 2025 11:45:55 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net-next v18 20/25] ovpn: implement peer add/get/dump/delete via netlink To: ryazanov.s.a@gmail.com, Sabrina Dubroca Cc: netdev@vger.kernel.org, Eric Dumazet , Jakub Kicinski , Paolo Abeni , Donald Hunter , Shuah Khan , Andrew Lunn , Simon Horman , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Xiao Liang References: <20250113-b4-ovpn-v18-0-1f00db9c2bd6@openvpn.net> <20250113-b4-ovpn-v18-20-1f00db9c2bd6@openvpn.net> <33710520-5f4f-4d33-a28d-99dc64afc9c3@openvpn.net> Content-Language: en-US From: Antonio Quartulli Autocrypt: addr=antonio@openvpn.net; keydata= xsFNBFN3k+ABEADEvXdJZVUfqxGOKByfkExNpKzFzAwHYjhOb3MTlzSLlVKLRIHxe/Etj13I X6tcViNYiIiJxmeHAH7FUj/yAISW56lynAEt7OdkGpZf3HGXRQz1Xi0PWuUINa4QW+ipaKmv voR4b1wZQ9cZ787KLmu10VF1duHW/IewDx9GUQIzChqQVI3lSHRCo90Z/NQ75ZL/rbR3UHB+ EWLIh8Lz1cdE47VaVyX6f0yr3Itx0ZuyIWPrctlHwV5bUdA4JnyY3QvJh4yJPYh9I69HZWsj qplU2WxEfM6+OlaM9iKOUhVxjpkFXheD57EGdVkuG0YhizVF4p9MKGB42D70pfS3EiYdTaKf WzbiFUunOHLJ4hyAi75d4ugxU02DsUjw/0t0kfHtj2V0x1169Hp/NTW1jkqgPWtIsjn+dkde dG9mXk5QrvbpihgpcmN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OlfRufuDrWwAv+em2uOT BnRX9nFx9kPSO42TkFK55Dr5EDeBO3v33recscuB8VVN5xvh0GV57Qre+9sJrEq7Es9W609a +M0yRJWJEjFnMa/jsGZ+QyLD5QTL6SGuZ9gKI3W1SfFZOzV7hHsxPTZ6 Organization: OpenVPN Inc. In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 20/01/2025 11:09, Sabrina Dubroca wrote: > 2025-01-19, 14:12:05 +0100, Antonio Quartulli wrote: >> On 17/01/2025 18:12, Sabrina Dubroca wrote: >>> 2025-01-17, 13:59:35 +0100, Antonio Quartulli wrote: >>>> On 17/01/2025 12:48, Sabrina Dubroca wrote: >>>>> 2025-01-13, 10:31:39 +0100, Antonio Quartulli wrote: >>>>>> int ovpn_nl_peer_new_doit(struct sk_buff *skb, struct genl_info *info) >>>>>> { >>>>>> - return -EOPNOTSUPP; >>>>>> + struct nlattr *attrs[OVPN_A_PEER_MAX + 1]; >>>>>> + struct ovpn_priv *ovpn = info->user_ptr[0]; >>>>>> + struct ovpn_socket *ovpn_sock; >>>>>> + struct socket *sock = NULL; >>>>>> + struct ovpn_peer *peer; >>>>>> + u32 sockfd, peer_id; >>>>>> + int ret; >>>>>> + >>>>>> + /* peers can only be added when the interface is up and running */ >>>>>> + if (!netif_running(ovpn->dev)) >>>>>> + return -ENETDOWN; >>>>> >>>>> Since we're not under rtnl_lock here, the device could go down while >>>>> we're creating this peer, and we may end up with a down device that >>>>> has a peer anyway. >>>> >>>> hmm, indeed. This means we must hold the rtnl_lock to prevent ending up in >>>> an inconsistent state. >>>> >>>>> >>>>> I'm not sure what this (and the peer flushing on NETDEV_DOWN) is >>>>> trying to accomplish. Is it a problem to keep peers when the netdevice >>>>> is down? >>>> >>>> This is the result of my discussion with Sergey that started in v23 5/23: >>>> >>>> https://lore.kernel.org/r/netdev/20241029-b4-ovpn-v11-5-de4698c73a25@openvpn.net/ >>>> >>>> The idea was to match operational state with actual connectivity to peer(s). >>>> >>>> Originally I wanted to simply kee the carrier always on, but after further >>>> discussion (including the meaning of the openvpn option --persist-tun) we >>>> agreed on following the logic where an UP device has a peer connected (logic >>>> is slightly different between MP and P2P). >>>> >>>> I am not extremely happy with the resulting complexity, but it seemed to be >>>> blocker for Sergey. >>> >>> [after re-reading that discussion with Sergey] >>> >>> I don't understand why "admin does 'ip link set tun0 down'" means "we >>> should get rid of all peers. For me the carrier situation goes the >>> other way: no peer, no carrier (as if I unplugged the cable from my >>> ethernet card), and it's independent of what the user does (ip link >>> set XXX up/down). You have that with netif_carrier_{on,off}, but >>> flushing peers when the admin does "ip link set tun0 down" is separate >>> IMO. >> >> The reasoning was "the user is asking the VPN to go down - it should be >> assumed that from that moment on no VPN traffic whatsoever should flow in >> either direction". >> Similarly to when you bring an Eth interface dwn - the phy link goes down as >> well. >> >> Does it make sense? > > I'm not sure. If I turn the ovpn interface down for a second, the > peers are removed. Will they come back when I bring the interface back > up? That'd have to be done by userspace (which could also watch for > the DOWN events and tell the kernel to flush the peers) - but some of > the peers could have timed out in the meantime. > > If I set the VPN interface down, I expect no packets flowing through > that interface (dropping the peers isn't necessary for that), but all > non-data (key exchange etc sent by openvpn's userspace) should still > go through, and IMO peer keepalive fits in that "non-data" category. This was my original thought too and my original proposal followed this idea :-) However Sergey had a strong opinion about "the user expect no traffic whatsoever". I'd be happy about going again with your proposed approach, but I need to be sure that on the next revision nobody will come asking to revert this logic again :( > > > What does openvpn currently do if I do > ip link set tun0 down ; sleep 5 ; ip link set tun0 up > with a tuntap interface? I think nothing happens, because userspace doesn't monitor the netdev status. Therefore, unless tun closed the socket (which I think it does only when the interface is destroyed), userspace does not even realize that the interface went down. Regards, > -- Antonio Quartulli OpenVPN Inc.