netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ipx: implement shutdown()
@ 2014-02-08 23:04 Sabrina Dubroca
  2014-02-08 23:17 ` Sabrina Dubroca
  0 siblings, 1 reply; 2+ messages in thread
From: Sabrina Dubroca @ 2014-02-08 23:04 UTC (permalink / raw)
  To: acme; +Cc: davem, netdev, 00cpxxx, Sabrina Dubroca

IPX doesn't implement shutdown, which poses a problem to some users:

https://bugzilla.kernel.org/show_bug.cgi?id=67841

This patch is heavily based on the shutdown implementation for unix
sockets.

Reported-by: Bruno Jesus <00cpxxx@gmail.com>
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
 net/ipx/af_ipx.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/net/ipx/af_ipx.c b/net/ipx/af_ipx.c
index 994e28b..1df57ca 100644
--- a/net/ipx/af_ipx.c
+++ b/net/ipx/af_ipx.c
@@ -1383,6 +1383,7 @@ static int ipx_release(struct socket *sock)
 		goto out;
 
 	lock_sock(sk);
+	sk->sk_shutdown = SHUTDOWN_MASK;
 	if (!sock_flag(sk, SOCK_DEAD))
 		sk->sk_state_change(sk);
 
@@ -1806,8 +1807,11 @@ static int ipx_recvmsg(struct kiocb *iocb, struct socket *sock,
 
 	skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
 				flags & MSG_DONTWAIT, &rc);
-	if (!skb)
+	if (!skb) {
+		if (rc == -EAGAIN && (sk->sk_shutdown & RCV_SHUTDOWN))
+			rc = 0;
 		goto out;
+	}
 
 	ipx 	= ipx_hdr(skb);
 	copied 	= ntohs(ipx->ipx_pktsize) - sizeof(struct ipxhdr);
@@ -1937,6 +1941,28 @@ static int ipx_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long
 }
 #endif
 
+static int ipx_shutdown(struct socket *sock, int mode)
+{
+	struct sock *sk = sock->sk;
+
+	printk(KERN_INFO "IPX: shutting down %d\n", mode);
+	if (mode < SHUT_RD || mode > SHUT_RDWR)
+		return -EINVAL;
+	/* This maps:
+	 * SHUT_RD   (0) -> RCV_SHUTDOWN  (1)
+	 * SHUT_WR   (1) -> SEND_SHUTDOWN (2)
+	 * SHUT_RDWR (2) -> SHUTDOWN_MASK (3)
+	 */
+	++mode;
+
+	lock_sock(sk);
+	sk->sk_shutdown |= mode;
+	release_sock(sk);
+	sk->sk_state_change(sk);
+	printk(KERN_INFO "IPX: socket shut down\n");
+
+	return 0;
+}
 
 /*
  * Socket family declarations
@@ -1963,7 +1989,7 @@ static const struct proto_ops ipx_dgram_ops = {
 	.compat_ioctl	= ipx_compat_ioctl,
 #endif
 	.listen		= sock_no_listen,
-	.shutdown	= sock_no_shutdown, /* FIXME: support shutdown */
+	.shutdown	= ipx_shutdown,
 	.setsockopt	= ipx_setsockopt,
 	.getsockopt	= ipx_getsockopt,
 	.sendmsg	= ipx_sendmsg,
-- 
1.8.5.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ipx: implement shutdown()
  2014-02-08 23:04 [PATCH] ipx: implement shutdown() Sabrina Dubroca
@ 2014-02-08 23:17 ` Sabrina Dubroca
  0 siblings, 0 replies; 2+ messages in thread
From: Sabrina Dubroca @ 2014-02-08 23:17 UTC (permalink / raw)
  To: acme; +Cc: davem, netdev, 00cpxxx

2014-02-09, 00:04:29 +0100, Sabrina Dubroca wrote:
> +static int ipx_shutdown(struct socket *sock, int mode)
> +{
> +	struct sock *sk = sock->sk;
> +
> +	printk(KERN_INFO "IPX: shutting down %d\n", mode);
> +	if (mode < SHUT_RD || mode > SHUT_RDWR)
> +		return -EINVAL;
> +	/* This maps:
> +	 * SHUT_RD   (0) -> RCV_SHUTDOWN  (1)
> +	 * SHUT_WR   (1) -> SEND_SHUTDOWN (2)
> +	 * SHUT_RDWR (2) -> SHUTDOWN_MASK (3)
> +	 */
> +	++mode;
> +
> +	lock_sock(sk);
> +	sk->sk_shutdown |= mode;
> +	release_sock(sk);
> +	sk->sk_state_change(sk);
> +	printk(KERN_INFO "IPX: socket shut down\n");
> +
> +	return 0;
> +}

Sorry, I sent the version with the debugging in. I'll resend a clean one.

-- 
Sabrina

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-02-08 23:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-08 23:04 [PATCH] ipx: implement shutdown() Sabrina Dubroca
2014-02-08 23:17 ` Sabrina Dubroca

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).