From patchwork Fri Dec 14 21:12:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 153904 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2548174ljp; Fri, 14 Dec 2018 13:12:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/V5T+4jU/PBNKPPEkLX7njkdmr5NUoG1oOoeL9KA70VTs5ncJxWc1zE/fjKDb+YmAxIYITl X-Received: by 2002:a62:cdd:: with SMTP id 90mr4282722pfm.219.1544821967155; Fri, 14 Dec 2018 13:12:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544821967; cv=none; d=google.com; s=arc-20160816; b=vYqyTMIpY2TJTB1Tq/99orjFgIzXUlk+qrsekMjukW770xxYah3iLF5Cd3xwXHLMtV /K2yMQr2bKUGVqoAbpb7yvT66I5Y17NeA/bVeQ93vPSs/2C8gMqyMcoOqG3qhTsYSreA PAJDi8Wgkas6AW+Q0ZiodQyTc6FL8m982aOTXR6zCwWu2KxVReObqpZomAdm/ouqMLSM 5PpY55eRWSqM0XRl0Hfij8MRXven8Hbtu69j96dNoqUzU0d5McZnun8r0nKpMAaaLXio VS6prwqqlDmOb8K+S1iE47utNU6nav3NVTkAQgfk4WFYecJv+dj/zEVVIuYuWWf56mz5 d+hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ayXodJU59wzJNPigsWiwer1kLPrNiQ7AuIEJaBjTXl0=; b=PjS5/i+HPF3yCO2+mX+NwNGk6YjbiQH27QnZLzfzo1gNzP6diqiMF3X4zYwmcjgn+F 08DWV6qsfdaCTEyZXxgzdMRw9XsiVyhyRWjl5cnt2IuYJtWLPVSFTOwaGI04FLsqwRNZ Kr15T9w4X5Gly37W2GXyV2unTWRDo4WixoRQtsRA9tJrPsxlse2nhUx9OhvFC5RO1o1O tPM3AIRi8op8wuAnJmgf9HiVpWJPYjWk1NxdGcAviww5YuN4+Gf8oFMlBbfxHFjR4kjI h4sUkivX+fMqEe25OzO55/tHjMN61HZzXZYHFFVrvTdoaGZqnmpz6pT85N2v/3QNN+bO ol8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IZ7K5eYh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si4635075pgc.85.2018.12.14.13.12.46; Fri, 14 Dec 2018 13:12:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IZ7K5eYh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731109AbeLNVMp (ORCPT + 31 others); Fri, 14 Dec 2018 16:12:45 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:44962 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730757AbeLNVMp (ORCPT ); Fri, 14 Dec 2018 16:12:45 -0500 Received: by mail-lf1-f68.google.com with SMTP id z13so5265448lfe.11 for ; Fri, 14 Dec 2018 13:12:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ayXodJU59wzJNPigsWiwer1kLPrNiQ7AuIEJaBjTXl0=; b=IZ7K5eYhQXgvgeAg4dskOoBR9E57dK95gTN9G1kY6rpSUv14fBp/LO+Ok7aA2XKdEv 8Pge5CEgun+aExl/4ol1Cmlzjm+C3Kk1pOwgedPky7InM/FM6bL5BZ3Pdu3QDYbIu1Wj 6RojxIqvXQur4MvHmep7ovuUHfc4OTrq08tYI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ayXodJU59wzJNPigsWiwer1kLPrNiQ7AuIEJaBjTXl0=; b=owSkd9yNYivMCPlVsZREHuwNwKE3ayFf9XfjL+aqYou5hD0XbVhL+3OgBpv6xT2GEf ZD9CzXcYvQmsYLSTIXnT0Uv/PVMRWVpHGb0XNj7Pq3cj9jcN22bDiXq9PfHz2ieVz21z YoHZz+DvvS09hWUak439XHyzuWZ1/sjukIBhzPobakbPv4YUd3wFzLRQsdEbV3FK2wuZ gdup5kkF/l7d4TuP4fazyO/WJgPbDHOf7lZAh2Kc5zC8MVIXZVtF83SECKopkJODigIH RxZ2Eox2FtHS8LT9MoWnBE6LrIuKDC8mhzagWJlGp5XSDjZKkbwNyNMcBZLoAZhQ2PTV GZow== X-Gm-Message-State: AA+aEWa0W43wAZCrkM1LbhyjcMjN/DlGuoV09Q4zMfvX16TLuk2ElA+i UIN2JLlKp9YxtSIo4AsXKHvZKA== X-Received: by 2002:a19:5f1e:: with SMTP id t30mr2576767lfb.76.1544821963322; Fri, 14 Dec 2018 13:12:43 -0800 (PST) Received: from localhost ([195.238.92.132]) by smtp.gmail.com with ESMTPSA id k68-v6sm1046377ljb.35.2018.12.14.13.12.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Dec 2018 13:12:42 -0800 (PST) From: Sam Protsenko To: James Chapman , "David S. Miller" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Guillaume Nault Subject: [PATCH 1/2] l2tp: Bring back ->flags to struct pppol2tp_session Date: Fri, 14 Dec 2018 23:12:41 +0200 Message-Id: <20181214211242.9721-1-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Flags field will be used in further commits (e.g. for keeping SC_COMP_PROT), so let's bring those back. This commit effectively reverts commit 1998b5ed9c9b ("l2tp: drop ->flags from struct pppol2tp_session"), with some cosmetic changes. Signed-off-by: Sam Protsenko --- net/l2tp/l2tp_ppp.c | 52 +++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 18 deletions(-) -- 2.19.1 diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c index c03c6461f236..145435977b21 100644 --- a/net/l2tp/l2tp_ppp.c +++ b/net/l2tp/l2tp_ppp.c @@ -125,6 +125,7 @@ struct pppol2tp_session { * PPPoX socket */ struct sock *__sk; /* Copy of .sk, for cleanup */ struct rcu_head rcu; /* For asynchronous release */ + int flags; /* accessed by PPPIOCGFLAGS */ }; static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb); @@ -1074,44 +1075,60 @@ static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd, { struct pppol2tp_ioc_stats stats; struct l2tp_session *session; + struct pppol2tp_session *ps; int val; + bool is_tunnel; + + session = sock->sk->sk_user_data; + if (!session) + return -ENOTCONN; + + ps = l2tp_session_priv(session); + is_tunnel = !session->session_id && !session->peer_session_id; switch (cmd) { case PPPIOCGMRU: - case PPPIOCGFLAGS: - session = sock->sk->sk_user_data; - if (!session) - return -ENOTCONN; - /* Not defined for tunnels */ - if (!session->session_id && !session->peer_session_id) + if (is_tunnel) return -ENOSYS; if (put_user(0, (int __user *)arg)) return -EFAULT; break; + case PPPIOCGFLAGS: + /* Not defined for tunnels */ + if (is_tunnel) + return -ENOSYS; - case PPPIOCSMRU: - case PPPIOCSFLAGS: - session = sock->sk->sk_user_data; - if (!session) - return -ENOTCONN; + if (put_user(ps->flags, (int __user *)arg)) + return -EFAULT; + l2tp_info(session, L2TP_MSG_CONTROL, "%s: get flags=%d\n", + session->name, ps->flags); + break; + case PPPIOCSMRU: /* Not defined for tunnels */ - if (!session->session_id && !session->peer_session_id) + if (is_tunnel) return -ENOSYS; if (get_user(val, (int __user *)arg)) return -EFAULT; break; + case PPPIOCSFLAGS: + /* Not defined for tunnels */ + if (is_tunnel) + return -ENOSYS; - case PPPIOCGL2TPSTATS: - session = sock->sk->sk_user_data; - if (!session) - return -ENOTCONN; + if (get_user(val, (int __user *)arg)) + return -EFAULT; + ps->flags = val; + l2tp_info(session, L2TP_MSG_CONTROL, "%s: set flags=%d\n", + session->name, ps->flags); + break; + case PPPIOCGL2TPSTATS: /* Session 0 represents the parent tunnel */ - if (!session->session_id && !session->peer_session_id) { + if (is_tunnel) { u32 session_id; int err; @@ -1136,7 +1153,6 @@ static int pppol2tp_ioctl(struct socket *sock, unsigned int cmd, if (copy_to_user((void __user *)arg, &stats, sizeof(stats))) return -EFAULT; break; - default: return -ENOIOCTLCMD; } From patchwork Fri Dec 14 21:12:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 153905 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2548223ljp; Fri, 14 Dec 2018 13:12:49 -0800 (PST) X-Google-Smtp-Source: AFSGD/U48dvH/cje+iKD986erVJhRAjsxMC195rMYEbz5SrdJ5V0+xxCAAjApPJ1W+0ntJfuimi7 X-Received: by 2002:a62:cdd:: with SMTP id 90mr4282850pfm.219.1544821969582; Fri, 14 Dec 2018 13:12:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544821969; cv=none; d=google.com; s=arc-20160816; b=chmnsS7s3rtzeA6qbnbld7sNLQsLqPD1NQFy2JUfXpRC0nb8zT4rW/sV+AziG+dblW MMBFiAJGeaSJjQJ3T54aS2HN4XSQ+CXZKMdLOEuPFo3/t1lJReOtD4yeM37o4AYMmjaI pCRKrXIMPFZrQyseoYHvjY52GT6udETNZwNLGDmuNYOmDh4zeTdpM4P7JhQPyTrpV73p 9bpxUrGsfwvvGmvAM5iyYtqPrDXhWxvNPTBJvh2N/e4oICeaCpwUK2Ps86WAo9Bd196B OOZ7l5kXoJVJUe3X5cBbvfNzEaor4fUXZEqYsrBahsudzdl3/veyX/ZHIXCJ3dcVPp2X N6GA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tyNnUR4lfp/hoy1rKAT2aYL4FMj9E3HybgGC/oR7mho=; b=J8u5ofWIxWEfJVg3SoFVmJxHhf80YqTTCeToE1OmiRfOhqXxrmS09+pIISoa3dsBeg IZsmAWWgRFdb0wJUpeAGdSS7jyvuyTMrgZ0DbvVePf3RHqazGdCCda4GT2Eg2ij+Hr8f gKJ6Q/BrGi7pgI7UO4dT82QNepfIB+83Jmd4dwTmyleqkRcPBUfopmdPk8kxle4NqWd6 ggC0TUmYeYsZA5FRzFDmNnQeowe6vVwMWxUWDxQBC4/F39g1eZuSbFPjytDPhzAmCIGx POOnXBUQZUmN5u3vUuhfIPOEq1+6flZ1XHcUDgXnqZz5fqRAsJaF43o1MUL+ATcQF9ko 84LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KTTC98pi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y20si4655843plr.106.2018.12.14.13.12.49; Fri, 14 Dec 2018 13:12:49 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KTTC98pi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731212AbeLNVMs (ORCPT + 31 others); Fri, 14 Dec 2018 16:12:48 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:45754 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730956AbeLNVMq (ORCPT ); Fri, 14 Dec 2018 16:12:46 -0500 Received: by mail-lf1-f66.google.com with SMTP id b20so5272590lfa.12 for ; Fri, 14 Dec 2018 13:12:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tyNnUR4lfp/hoy1rKAT2aYL4FMj9E3HybgGC/oR7mho=; b=KTTC98piaTj0WoYaI4cfpgCrMgv52G2aSZ5Cth1Hq8a38qUM7NQyNvnv95AO6a2XSc cAtgsvbmnHavFmJmCLtCJ0Q1Zfi9xQ4R6Nc7qbXDnK40nKiA0p6Qo8k60+peRor/YxXm hwfsX/TO/4ohhNm/F0C7AdcOfaTzsonNjooz8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tyNnUR4lfp/hoy1rKAT2aYL4FMj9E3HybgGC/oR7mho=; b=iem0Lwn0WZbXZdnBJ1W5dFS08cu7k5hFAL58RTpymyPth1tCZbHcj7s0RixcDfnarZ lmA9FwTWozu13XhqgMfKt6CTmxikYzY1CyULL9lDftguG1MO5AFAK65ketmttME9fZI1 8pmW0tZpDD+r+gXANx+Hi1TswyJ5oXp6u2pVP4e6XmVyakY/JNr8XfRqVMJh5LUfsrO7 UNVutILtXc+7TVJRYVzahoJo2z/vXsVkFOkBBfpD7aaq4eR8girlfy7fz0skYcBRuohC f2vRqifvWODeRKsUQK7S7cBtz+d+m6x1gKJOzQjANIaCM+oqq+H5fNXm4yfjtYHoRC6U cj7w== X-Gm-Message-State: AA+aEWYuV3y+PaztzdT+orqNuDmVhhCou9W/Omo7w+pO/uKljQXQeNmS 6pLHdWIFAuQ0kzsZ3mAnuAAJRA== X-Received: by 2002:a19:5782:: with SMTP id l124mr2569905lfb.91.1544821964480; Fri, 14 Dec 2018 13:12:44 -0800 (PST) Received: from localhost ([195.238.92.132]) by smtp.gmail.com with ESMTPSA id u15-v6sm1190636lja.63.2018.12.14.13.12.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Dec 2018 13:12:44 -0800 (PST) From: Sam Protsenko To: James Chapman , "David S. Miller" Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Guillaume Nault Subject: [PATCH 2/2] l2tp: Add Protocol field compression Date: Fri, 14 Dec 2018 23:12:42 +0200 Message-Id: <20181214211242.9721-2-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181214211242.9721-1-semen.protsenko@linaro.org> References: <20181214211242.9721-1-semen.protsenko@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When Protocol Field Compression (PFC) is enabled, the "Protocol" field in PPP packet should be transmitted without leading 0x00. See section 6.5 in RFC 1661 for details. Let's compress protocol field if needed, the same way it's done in drivers/net/ppp/pptp.c. To actually enable PFC, one should issue corresponding ioctl to L2TP driver from user-space, like this: ioctl(fd, PPPIOCGFLAGS, &flags); flags |= SC_COMP_PROT; ioctl(fd, PPPIOCSFLAGS, &flags); It can be done e.g. from pppol2tp plugin (pppd), when pcomp option was negotiated with peer. Of course, we don't compress Protocol field when sending LCP packets. As stated in RFC 1661, section 6.5: The Protocol field is never compressed when sending any LCP packet. This rule guarantees unambiguous recognition of LCP packets. Signed-off-by: Sam Protsenko --- net/l2tp/l2tp_ppp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) -- 2.19.1 diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c index 145435977b21..7860b219af07 100644 --- a/net/l2tp/l2tp_ppp.c +++ b/net/l2tp/l2tp_ppp.c @@ -363,7 +363,10 @@ static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb) struct sock *sk = (struct sock *) chan->private; struct l2tp_session *session; struct l2tp_tunnel *tunnel; + struct pppol2tp_session *ps; int uhlen, headroom; + unsigned char *data; + bool is_lcp; if (sock_flag(sk, SOCK_DEAD) || !(sk->sk_state & PPPOX_CONNECTED)) goto abort; @@ -384,6 +387,15 @@ static int pppol2tp_xmit(struct ppp_channel *chan, struct sk_buff *skb) if (skb_cow_head(skb, headroom)) goto abort_put_sess; + ps = l2tp_session_priv(session); + data = skb->data; + is_lcp = ((data[0] << 8) + data[1]) == PPP_LCP && + data[2] >= 1 && data[2] <= 7; + + /* Compress protocol field if PFC is enabled */ + if ((ps->flags & SC_COMP_PROT) && data[0] == 0x00 && !is_lcp) + __skb_pull(skb, 1); + /* Setup PPP header */ __skb_push(skb, 2); skb->data[0] = PPP_ALLSTATIONS;