diff mbox series

[1/2] l2tp: Bring back ->flags to struct pppol2tp_session

Message ID 20181214211242.9721-1-semen.protsenko@linaro.org
State New
Headers show
Series [1/2] l2tp: Bring back ->flags to struct pppol2tp_session | expand

Commit Message

Sam Protsenko Dec. 14, 2018, 9:12 p.m. UTC
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 <semen.protsenko@linaro.org>

---
 net/l2tp/l2tp_ppp.c | 52 +++++++++++++++++++++++++++++----------------
 1 file changed, 34 insertions(+), 18 deletions(-)

-- 
2.19.1
diff mbox series

Patch

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;
 	}