Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp5081400rwe; Tue, 18 Apr 2023 01:36:34 -0700 (PDT) X-Google-Smtp-Source: AKy350ZGQRDV2XODbsIYaYnfklXq7Vp3YYjoMrM+8ffxN4aoF22j0rZo6h6zU1RsSOktL48OqJAP X-Received: by 2002:a17:90a:fe05:b0:246:ee10:cb5d with SMTP id ck5-20020a17090afe0500b00246ee10cb5dmr1469493pjb.14.1681806993864; Tue, 18 Apr 2023 01:36:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681806993; cv=none; d=google.com; s=arc-20160816; b=MW2Ri/B5Ro3RdFshv6WnHvTuF+yeV3BjT4F5rai7gJJwJqUopyKX2Qrh2ZHTqoy4eR k/D7pJK4HqACezkYpOwdLGcTz5voFqOOZllNAMJ45xr46qIWdrEV/ECHJL8UqEF3nIaW KPOyTm6fuxRvKqmKdDjjOC9hBo24IAfN2budNhiZcqifAknZvDRFY6uRnU38AVv4wcCk +q4UxAcUlZmKgyOIGjeDrtmzpLk54n6dYPPnFV4G3jXTNhdVmG3uwuvr0Kn3CBNHf8AV aa1G7b/jfH0JjM9o4IMA/COzRLPPn0hmSQd6QMM6pNfYgcFXjMNEpvx7YQ7yCKBiKqEr 13XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date:dkim-signature; bh=Rv7GgXtXE5BwsWMierc+FyeJxK2YpNxYqQW013L/+7M=; b=0VsjFLiTNaOhau3W0Tm6ouA2EZ9vOYwNP+3E8IgopIqwLXNGKrb51EWeLHjhcETDvc iCEbZvD6cOuXSh3OnJtr8S8grGrDPSI99CEu6B+n38jA6mOSduhyoXGW4n6DZ6o69Jcl Y5bQ/1H7DbNjGFv7TfJRcwIvVU09Ha4hCcJHlYmbat0H/iwS3LvrzsLkI1bTnmBtYApK zreTqkebXZLFrC5ZbIX/C1k/z0ufet6j3UTz3XLny82LOj5X3gLfRkMdSAZNbjO4RdaA qBrdqeJpXUvxYWatRNrXA5rYOtyfMX72XkrWPe/Z9HE0nXcm+AZjLhDzMVnRfeZAg2RZ 8pnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=drLh909B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a6-20020a631a46000000b0051b10b20ceasi14290215pgm.893.2023.04.18.01.36.22; Tue, 18 Apr 2023 01:36:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=drLh909B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbjDRIff (ORCPT + 99 others); Tue, 18 Apr 2023 04:35:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230364AbjDRIfd (ORCPT ); Tue, 18 Apr 2023 04:35:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF0207EFC for ; Tue, 18 Apr 2023 01:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681806851; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Rv7GgXtXE5BwsWMierc+FyeJxK2YpNxYqQW013L/+7M=; b=drLh909BPNjahjto+qKA+tz0ULFsWTYhIoqw79+aMM+XLn2E4XSo/GYl7Mj7L79PGWWsSs /3ktgQJMgw0WAeaGxPvzHJN6FUbicIcchB14YHNfEZhvfhA5PLdX1gpgPD4JcAD2kvKbe/ 2V5RsI/MZys5iDTF/xxk5uJ374WEWuA= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-316-WtixZ95ROMmTUbYAZ0pntQ-1; Tue, 18 Apr 2023 04:34:08 -0400 X-MC-Unique: WtixZ95ROMmTUbYAZ0pntQ-1 Received: by mail-wm1-f71.google.com with SMTP id l20-20020a05600c4f1400b003f0a04fe9b9so6130536wmq.7 for ; Tue, 18 Apr 2023 01:34:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681806847; x=1684398847; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Rv7GgXtXE5BwsWMierc+FyeJxK2YpNxYqQW013L/+7M=; b=RBb+svMJHNaSyOiKIhLArLAf4v1yNl+Xyz/knD5KSizWRzO+AChC0oeb1oESduYEzW c+l2RLHCx/lz7foCrRlgW5Dpch4FO1BkAsV53Gg42wruWcJNV3IZQy2T3H077bCZi/RQ sn7NPxg8v8/5aFd6RzDjlon3c8Mm/kZzUxjnRyEkhzH6PJZkZmyMd1xA1a72LpEX43JN YM5+0MV0X+lRADmnCNsE/CbABIeCuEc1+/tHcXTo8BWn+G/gH77SyAlS/182Tr3/aQB8 vvOM5/8YVA344Z+ARjffZeso9pGnIMAZCY09/8Bza+WBPvzUJ58G2Rzspu1bTi87gumy rjjg== X-Gm-Message-State: AAQBX9dikTjQPVoCTB/dGy/eUYBG/5KUFqDNH1Rybhuqe2PKUEZe1azQ /WPy7dik1gkBJmErLgDS6o6/z9mz+Kfm/P3NNDO1GbqH1IbLTgFUW+AUUxuMjbRHorvZGsd2BWL waVKefOkKMfgaqPjcwPxwJyykFS8uHNx3 X-Received: by 2002:a1c:cc05:0:b0:3ef:d8c6:4bc0 with SMTP id h5-20020a1ccc05000000b003efd8c64bc0mr12024308wmb.40.1681806847534; Tue, 18 Apr 2023 01:34:07 -0700 (PDT) X-Received: by 2002:a1c:cc05:0:b0:3ef:d8c6:4bc0 with SMTP id h5-20020a1ccc05000000b003efd8c64bc0mr12024293wmb.40.1681806847207; Tue, 18 Apr 2023 01:34:07 -0700 (PDT) Received: from debian ([92.62.32.42]) by smtp.gmail.com with ESMTPSA id c7-20020a05600c0a4700b003ef4cd057f5sm18266803wmq.4.2023.04.18.01.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Apr 2023 01:34:06 -0700 (PDT) Date: Tue, 18 Apr 2023 10:34:03 +0200 From: Guillaume Nault To: Samuel Thibault , James Chapman , tparkin@katalix.com, edumazet@google.com, davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, corbet@lwn.net, netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] PPPoL2TP: Add more code snippets Message-ID: References: <20230416220704.xqk4q6uwjbujnqpv@begin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230416220704.xqk4q6uwjbujnqpv@begin> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 17, 2023 at 12:07:04AM +0200, Samuel Thibault wrote: > The existing documentation was not telling that one has to create a PPP > channel and a PPP interface to get PPPoL2TP data offloading working. > > Also, tunnel switching was not described, so that people were thinking > it was not supported, while it actually is. > > Signed-off-by: Samuel Thibault > > --- > Documentation/networking/l2tp.rst | 59 ++++++++++++++++++++++++++++++++++++-- > 1 file changed, 56 insertions(+), 3 deletions(-) > > --- a/Documentation/networking/l2tp.rst > +++ b/Documentation/networking/l2tp.rst > @@ -387,11 +387,12 @@ Sample userspace code: > - Create session PPPoX data socket:: > > struct sockaddr_pppol2tp sax; > - int fd; > + int ret; > > /* Note, the tunnel socket must be bound already, else it > * will not be ready > */ > + int session_fd = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP); Please declare session_fd with the other variables. Also, check the return value of the socket() call. > sax.sa_family = AF_PPPOX; > sax.sa_protocol = PX_PROTO_OL2TP; > sax.pppol2tp.fd = tunnel_fd; > @@ -406,12 +407,64 @@ Sample userspace code: > /* session_fd is the fd of the session's PPPoL2TP socket. > * tunnel_fd is the fd of the tunnel UDP / L2TPIP socket. > */ > - fd = connect(session_fd, (struct sockaddr *)&sax, sizeof(sax)); > - if (fd < 0 ) { > + ret = connect(session_fd, (struct sockaddr *)&sax, sizeof(sax)); > + if (ret < 0 ) { Now you also need to close session_fd. > return -errno; > } > return 0; > > + - Create PPP channel:: > + > + int chindx; > + ret = ioctl(session_fd, PPPIOCGCHAN, &chindx); > + if (ret < 0) > + return -errno; > + > + int ppp_chan_fd = open("/dev/ppp", O_RDWR); > + > + ret = ioctl(ppp_chan_fd, PPPIOCATTCHAN, &chindx); > + if (ret < 0) > + return -errno; > + > +Non-data PPP frames will be available for read on `ppp_chan_fd`. > + > + - Create PPP interface:: > + > + int ppp_if_fd = open("/dev/ppp", O_RDWR); Check for errors please. > + > + int ifunit; Also, keep kernel style formatting: * All variable declarations in one block (ordered from longest to shortest line). * New line between variable declarations and code. > + ret = ioctl(ppp_if_fd, PPPIOCNEWUNIT, &ifunit); You need to initialise ifunit first. Use -1 to let the kernel pick a free unit index. > + if (ret < 0) > + return -errno; > + > + ret = ioctl(ppp_chan_fd, PPPIOCCONNECT, ifunit); > + if (ret < 0) > + return -errno; > + > +The ppp interface can then be configured as usual with SIOCSIFMTU, > +SIOCSIFADDR, SIOCSIFDSTADDR, SIOCSIFNETMASK, and activated by setting IFF_UP > +with SIOCSIFFLAGS > + > + - Tunnel switching is supported by bridging channels:: This is a PPP feature not an L2TP one. PPPIOCBRIDGECHAN's description belongs to Documentation/networking/ppp_generic.rst, where it's already documented. If documentation needs to be improved, that should be done there. If necessary, you can link to ppp_generic.rst here. Also, calling this feature 'tunnel switching' is misleading. Switching happens between L2TP sessions (or more generally between any PPP transports), not between L2TP tunnels (which are just L2TP session multiplexers).