netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Phonet: set the pipe handle using setsockopt
@ 2011-11-09 11:20 Hemant Vilas RAMDASI
  2011-11-09 15:00 ` Rémi Denis-Courmont
  0 siblings, 1 reply; 9+ messages in thread
From: Hemant Vilas RAMDASI @ 2011-11-09 11:20 UTC (permalink / raw)
  To: remi.denis-courmont; +Cc: netdev, Dinesh Kumar Sharma, Hemant Ramdasi

From: Dinesh Kumar Sharma <dinesh.sharma@stericsson.com>

This provides flexibility to set the pipe handle
using setsockopt and enable the same.

Signed-off-by: Hemant Ramdasi <hemant.ramdasi@stericsson.com>
Signed-off-by: Dinesh Kumar Sharma <dinesh.sharma@stericsson.com>
---
 include/linux/phonet.h |    2 +
 net/phonet/pep.c       |   86 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 86 insertions(+), 2 deletions(-)

diff --git a/include/linux/phonet.h b/include/linux/phonet.h
index 6fb1384..491caec 100644
--- a/include/linux/phonet.h
+++ b/include/linux/phonet.h
@@ -37,6 +37,8 @@
 #define PNPIPE_ENCAP		1
 #define PNPIPE_IFINDEX		2
 #define PNPIPE_HANDLE		3
+#define PNPIPE_ENABLE		4
+#define PNPIPE_INITSTATE	5
 
 #define PNADDR_ANY		0
 #define PNADDR_BROADCAST	0xFC
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index f17fd84..3109563 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -167,6 +167,12 @@ static int pipe_handler_send_created_ind(struct sock *sk)
 				data, 4, GFP_ATOMIC);
 }
 
+static int pipe_handler_send_enabled_ind(struct sock *sk)
+{
+	return pep_indicate(sk, PNS_PIPE_ENABLED_IND, 0 /* sub-blocks */,
+				NULL, 0, GFP_ATOMIC);
+}
+
 static int pep_accept_conn(struct sock *sk, struct sk_buff *skb)
 {
 	static const u8 data[20] = {
@@ -533,6 +539,17 @@ static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
 	return pipe_handler_send_created_ind(sk);
 }
 
+static int pep_enableresp_rcv(struct sock *sk, struct sk_buff *skb)
+{
+	struct pnpipehdr *hdr = pnp_hdr(skb);
+
+	if (hdr->error_code != PN_PIPE_NO_ERROR)
+		return -ECONNREFUSED;
+
+	return pipe_handler_send_enabled_ind(sk);
+}
+
+
 /* Queue an skb to an actively connected sock.
  * Socket lock must be held. */
 static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
@@ -578,6 +595,28 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
 			sk->sk_state = TCP_CLOSE_WAIT;
 			break;
 		}
+		if (pn->init_enable == PN_PIPE_DISABLE)
+			sk->sk_state = TCP_SYN_RECV;
+		else {
+			sk->sk_state = TCP_ESTABLISHED;
+
+			if (!pn_flow_safe(pn->tx_fc)) {
+				atomic_set(&pn->tx_credits, 1);
+				sk->sk_write_space(sk);
+			}
+			pipe_grant_credits(sk, GFP_ATOMIC);
+
+		}
+		break;
+
+    case PNS_PEP_ENABLE_RESP:
+		if (sk->sk_state != TCP_SYN_SENT)
+			break;
+
+		if (pep_enableresp_rcv(sk, skb)) {
+			sk->sk_state = TCP_CLOSE_WAIT;
+			break;
+		}
 
 		sk->sk_state = TCP_ESTABLISHED;
 		if (!pn_flow_safe(pn->tx_fc)) {
@@ -863,9 +902,27 @@ static int pep_sock_connect(struct sock *sk, struct sockaddr *addr, int len)
 	int err;
 	u8 data[4] = { 0 /* sub-blocks */, PAD, PAD, PAD };
 
-	pn->pipe_handle = 1; /* anything but INVALID_HANDLE */
+	if (pn->pipe_handle == PN_PIPE_INVALID_HANDLE)
+		pn->pipe_handle = 1; /* anything but INVALID_HANDLE */
+
 	err = pipe_handler_request(sk, PNS_PEP_CONNECT_REQ,
-					PN_PIPE_ENABLE, data, 4);
+					pn->init_enable, data, 4);
+
+	if (err) {
+		pn->pipe_handle = PN_PIPE_INVALID_HANDLE;
+		return err;
+	}
+	sk->sk_state = TCP_SYN_SENT;
+	return 0;
+}
+
+static int pep_sock_enable(struct sock *sk, struct sockaddr *addr, int len)
+{
+	struct pep_sock *pn = pep_sk(sk);
+	int err;
+
+	err = pipe_handler_request(sk, PNS_PEP_ENABLE_REQ, PAD,
+				NULL, 0);
 	if (err) {
 		pn->pipe_handle = PN_PIPE_INVALID_HANDLE;
 		return err;
@@ -959,6 +1016,24 @@ static int pep_setsockopt(struct sock *sk, int level, int optname,
 		}
 		goto out_norel;
 
+	case PNPIPE_HANDLE:
+		if (val)
+			pn->pipe_handle = val;
+		else
+			err = -EINVAL;
+		break;
+
+	case PNPIPE_ENABLE:
+		err = pep_sock_enable(sk, NULL, 0);
+		break;
+
+	case PNPIPE_INITSTATE:
+		if ((val == PN_PIPE_DISABLE) || (val == PN_PIPE_ENABLE))
+			pn->init_enable = val;
+		else
+			err = -EINVAL;
+		break;
+
 	default:
 		err = -ENOPROTOOPT;
 	}
@@ -994,6 +1069,13 @@ static int pep_getsockopt(struct sock *sk, int level, int optname,
 			return -EINVAL;
 		break;
 
+	case PNPIPE_ENABLE:
+		if (sk->sk_state != TCP_ESTABLISHED)
+			return -EINVAL;
+		else
+			val = 1;
+		break;
+
 	default:
 		return -ENOPROTOOPT;
 	}
-- 
1.7.4.3

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

* Re: [PATCH] Phonet: set the pipe handle using setsockopt
  2011-11-09 11:20 Hemant Vilas RAMDASI
@ 2011-11-09 15:00 ` Rémi Denis-Courmont
  2011-11-10  9:44   ` Hemant-vilas RAMDASI
  0 siblings, 1 reply; 9+ messages in thread
From: Rémi Denis-Courmont @ 2011-11-09 15:00 UTC (permalink / raw)
  To: ext Hemant Vilas RAMDASI; +Cc: netdev, Dinesh Kumar Sharma

Inline...

Le Mercredi 9 Novembre 2011 16:50:53 ext Hemant Vilas RAMDASI a écrit :
> @@ -863,9 +902,27 @@ static int pep_sock_connect(struct sock *sk, struct
> sockaddr *addr, int len) int err;
>  	u8 data[4] = { 0 /* sub-blocks */, PAD, PAD, PAD };
> 
> -	pn->pipe_handle = 1; /* anything but INVALID_HANDLE */
> +	if (pn->pipe_handle == PN_PIPE_INVALID_HANDLE)
> +		pn->pipe_handle = 1; /* anything but INVALID_HANDLE */
> +
>  	err = pipe_handler_request(sk, PNS_PEP_CONNECT_REQ,
> -					PN_PIPE_ENABLE, data, 4);
> +					pn->init_enable, data, 4);
> +
> +	if (err) {
> +		pn->pipe_handle = PN_PIPE_INVALID_HANDLE;

This undoes the setsockopt() silently. I'm not sure you intend this?

> +		return err;
> +	}
> +	sk->sk_state = TCP_SYN_SENT;
> +	return 0;
> +}
> +
> +static int pep_sock_enable(struct sock *sk, struct sockaddr *addr, int len)
> +{
> +	struct pep_sock *pn = pep_sk(sk);
> +	int err;
> +
> +	err = pipe_handler_request(sk, PNS_PEP_ENABLE_REQ, PAD,
> +				NULL, 0);
>  	if (err) {
>  		pn->pipe_handle = PN_PIPE_INVALID_HANDLE;
>  		return err;
> @@ -959,6 +1016,24 @@ static int pep_setsockopt(struct sock *sk, int level,
> int optname, }
>  		goto out_norel;
> 
> +	case PNPIPE_HANDLE:
> +		if (val)
> +			pn->pipe_handle = val;
> +		else
> +			err = -EINVAL;
> +		break;

Why is zero a special case? What about out-of-range values?

> +
> +	case PNPIPE_ENABLE:
> +		err = pep_sock_enable(sk, NULL, 0);
> +		break;

This is reintroducing the problems with the older code. As far as I know,  
setsockopt() needs to be idempotent, which this does not seem to be?

> +
> +	case PNPIPE_INITSTATE:
> +		if ((val == PN_PIPE_DISABLE) || (val == PN_PIPE_ENABLE))
> +			pn->init_enable = val;
> +		else
> +			err = -EINVAL;
> +		break;

It looks like there is no use-case for init-enabled pipes then, right? How 
about dropping this extra bit of code and assuming connect()ed pipes are 
always init-disabled?

> +
>  	default:
>  		err = -ENOPROTOOPT;
>  	}
> @@ -994,6 +1069,13 @@ static int pep_getsockopt(struct sock *sk, int level,
> int optname, return -EINVAL;
>  		break;
> 
> +	case PNPIPE_ENABLE:
> +		if (sk->sk_state != TCP_ESTABLISHED)
> +			return -EINVAL;
> +		else
> +			val = 1;
> +		break;
> +
>  	default:
>  		return -ENOPROTOOPT;
>  	}
-- 
Rémi Denis-Courmont
http://www.remlab.net/

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

* RE: [PATCH] Phonet: set the pipe handle using setsockopt
  2011-11-09 15:00 ` Rémi Denis-Courmont
@ 2011-11-10  9:44   ` Hemant-vilas RAMDASI
  0 siblings, 0 replies; 9+ messages in thread
From: Hemant-vilas RAMDASI @ 2011-11-10  9:44 UTC (permalink / raw)
  To: Rémi Denis-Courmont
  Cc: netdev@vger.kernel.org, Dinesh Kumar SHARMA (STE)

Remi,

> -----Original Message-----
> From: Rémi Denis-Courmont [mailto:remi.denis-courmont@nokia.com]
> Sent: Wednesday, November 09, 2011 8:31 PM
> To: Hemant-vilas RAMDASI
> Cc: netdev@vger.kernel.org; Dinesh Kumar SHARMA (STE)
> Subject: Re: [PATCH] Phonet: set the pipe handle using setsockopt
> 
> Inline...
> 
> Le Mercredi 9 Novembre 2011 16:50:53 ext Hemant Vilas RAMDASI a écrit :

[...]

> 
> It looks like there is no use-case for init-enabled pipes then, right?
> How
> about dropping this extra bit of code and assuming connect()ed pipes
> are
> always init-disabled?

VT pipes can still be init-enabled.

Regards,
Hemant 

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

* [PATCH] Phonet: set the pipe handle using setsockopt
@ 2011-11-14  7:53 Hemant Vilas RAMDASI
  2011-11-14  9:29 ` Rémi Denis-Courmont
  0 siblings, 1 reply; 9+ messages in thread
From: Hemant Vilas RAMDASI @ 2011-11-14  7:53 UTC (permalink / raw)
  To: netdev-owner
  Cc: netdev, remi.denis-courmont, Dinesh Kumar Sharma, Hemant Ramdasi

From: Dinesh Kumar Sharma <dinesh.sharma@stericsson.com>

This provides flexibility to set the pipe handle
using setsockopt. The pipe can be enabled (if disabled) later
using ioctl.

Signed-off-by: Hemant Ramdasi <hemant.ramdasi@stericsson.com>
Signed-off-by: Dinesh Kumar Sharma <dinesh.sharma@stericsson.com>
---
 include/linux/phonet.h |    3 +
 net/phonet/pep.c       |  105 +++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 98 insertions(+), 10 deletions(-)

diff --git a/include/linux/phonet.h b/include/linux/phonet.h
index 6fb1384..4c00551 100644
--- a/include/linux/phonet.h
+++ b/include/linux/phonet.h
@@ -37,6 +37,8 @@
 #define PNPIPE_ENCAP		1
 #define PNPIPE_IFINDEX		2
 #define PNPIPE_HANDLE		3
+#define PNPIPE_ENABLE		4
+#define PNPIPE_INITSTATE	5
 
 #define PNADDR_ANY		0
 #define PNADDR_BROADCAST	0xFC
@@ -180,6 +182,7 @@ static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn)
 /* Phonet device ioctl requests */
 #ifdef __KERNEL__
 #define SIOCPNGAUTOCONF		(SIOCDEVPRIVATE + 0)
+#define SIOPNPIPE_ENABLE	_IO(SIOCPNGAUTOCONF,   1)
 
 struct if_phonet_autoconf {
 	uint8_t device;
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index f17fd84..48339b9 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -533,6 +533,29 @@ static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
 	return pipe_handler_send_created_ind(sk);
 }
 
+static int pep_enableresp_rcv(struct sock *sk, struct sk_buff *skb)
+{
+	struct pnpipehdr *hdr = pnp_hdr(skb);
+
+	if (hdr->error_code != PN_PIPE_NO_ERROR)
+		return -ECONNREFUSED;
+
+	return pep_indicate(sk, PNS_PIPE_ENABLED_IND, 0 /* sub-blocks */,
+		NULL, 0, GFP_ATOMIC);
+
+}
+
+static void pipe_start_flow_control(struct sock *sk)
+{
+	struct pep_sock *pn = pep_sk(sk);
+
+	if (!pn_flow_safe(pn->tx_fc)) {
+		atomic_set(&pn->tx_credits, 1);
+		sk->sk_write_space(sk);
+	}
+	pipe_grant_credits(sk, GFP_ATOMIC);
+}
+
 /* Queue an skb to an actively connected sock.
  * Socket lock must be held. */
 static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
@@ -578,13 +601,25 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
 			sk->sk_state = TCP_CLOSE_WAIT;
 			break;
 		}
+		if (pn->init_enable == PN_PIPE_DISABLE)
+			sk->sk_state = TCP_SYN_RECV;
+		else {
+			sk->sk_state = TCP_ESTABLISHED;
+			pipe_start_flow_control(sk);
+		}
+		break;
 
-		sk->sk_state = TCP_ESTABLISHED;
-		if (!pn_flow_safe(pn->tx_fc)) {
-			atomic_set(&pn->tx_credits, 1);
-			sk->sk_write_space(sk);
+	case PNS_PEP_ENABLE_RESP:
+		if (sk->sk_state != TCP_SYN_SENT)
+			break;
+
+		if (pep_enableresp_rcv(sk, skb)) {
+			sk->sk_state = TCP_CLOSE_WAIT;
+			break;
 		}
-		pipe_grant_credits(sk, GFP_ATOMIC);
+
+		sk->sk_state = TCP_ESTABLISHED;
+		pipe_start_flow_control(sk);
 		break;
 
 	case PNS_PEP_DISCONNECT_RESP:
@@ -863,14 +898,31 @@ static int pep_sock_connect(struct sock *sk, struct sockaddr *addr, int len)
 	int err;
 	u8 data[4] = { 0 /* sub-blocks */, PAD, PAD, PAD };
 
-	pn->pipe_handle = 1; /* anything but INVALID_HANDLE */
+	if (pn->pipe_handle == PN_PIPE_INVALID_HANDLE)
+		pn->pipe_handle = 1; /* anything but INVALID_HANDLE */
+
 	err = pipe_handler_request(sk, PNS_PEP_CONNECT_REQ,
-					PN_PIPE_ENABLE, data, 4);
-	if (err) {
-		pn->pipe_handle = PN_PIPE_INVALID_HANDLE;
+				pn->init_enable, data, 4);
+	if (err)
 		return err;
-	}
+
+	sk->sk_state = TCP_SYN_SENT;
+
+	return 0;
+}
+
+static int pep_sock_enable(struct sock *sk, struct sockaddr *addr, int len)
+{
+	int err;
+
+	err = pipe_handler_request(sk, PNS_PEP_ENABLE_REQ, PAD,
+				NULL, 0);
+
+	if (err)
+		return err;
+
 	sk->sk_state = TCP_SYN_SENT;
+
 	return 0;
 }
 
@@ -894,6 +946,16 @@ static int pep_ioctl(struct sock *sk, int cmd, unsigned long arg)
 			answ = 0;
 		release_sock(sk);
 		return put_user(answ, (int __user *)arg);
+		break;
+
+	case SIOPNPIPE_ENABLE:
+		if (sk->sk_state == TCP_SYN_SENT)
+			return -EBUSY;
+		else if (sk->sk_state == TCP_ESTABLISHED)
+			return -EISCONN;
+		else
+			return pep_sock_enable(sk, NULL, 0);
+		break;
 	}
 
 	return -ENOIOCTLCMD;
@@ -959,6 +1021,18 @@ static int pep_setsockopt(struct sock *sk, int level, int optname,
 		}
 		goto out_norel;
 
+	case PNPIPE_HANDLE:
+		if ((sk->sk_state == TCP_CLOSE) &&
+			(val >= 0) && (val < PN_PIPE_INVALID_HANDLE))
+			pn->pipe_handle = val;
+		else
+			err = -EINVAL;
+		break;
+
+	case PNPIPE_INITSTATE:
+		pn->init_enable = !!val;
+		break;
+
 	default:
 		err = -ENOPROTOOPT;
 	}
@@ -994,6 +1068,17 @@ static int pep_getsockopt(struct sock *sk, int level, int optname,
 			return -EINVAL;
 		break;
 
+	case PNPIPE_ENABLE:
+		if (sk->sk_state == TCP_ESTABLISHED)
+			val = 1;
+		else
+			val = 0;
+		break;
+
+	case PNPIPE_INITSTATE:
+		val = pn->init_enable;
+		break;
+
 	default:
 		return -ENOPROTOOPT;
 	}
-- 
1.7.4.3

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

* Re: [PATCH] Phonet: set the pipe handle using setsockopt
  2011-11-14  7:53 [PATCH] Phonet: set the pipe handle using setsockopt Hemant Vilas RAMDASI
@ 2011-11-14  9:29 ` Rémi Denis-Courmont
  2011-11-14 10:36   ` Hemant-vilas RAMDASI
  0 siblings, 1 reply; 9+ messages in thread
From: Rémi Denis-Courmont @ 2011-11-14  9:29 UTC (permalink / raw)
  To: ext Hemant Vilas RAMDASI, netdev

Le Lundi 14 Novembre 2011 13:23:30 ext Hemant Vilas RAMDASI a écrit :
> From: Dinesh Kumar Sharma <dinesh.sharma@stericsson.com>
> 
> This provides flexibility to set the pipe handle
> using setsockopt. The pipe can be enabled (if disabled) later
> using ioctl.
> 
> Signed-off-by: Hemant Ramdasi <hemant.ramdasi@stericsson.com>
> Signed-off-by: Dinesh Kumar Sharma <dinesh.sharma@stericsson.com>
> ---
>  include/linux/phonet.h |    3 +
>  net/phonet/pep.c       |  105
> +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 98
> insertions(+), 10 deletions(-)
> 
> diff --git a/include/linux/phonet.h b/include/linux/phonet.h
> index 6fb1384..4c00551 100644
> --- a/include/linux/phonet.h
> +++ b/include/linux/phonet.h
> @@ -37,6 +37,8 @@
>  #define PNPIPE_ENCAP		1
>  #define PNPIPE_IFINDEX		2
>  #define PNPIPE_HANDLE		3
> +#define PNPIPE_ENABLE		4
> +#define PNPIPE_INITSTATE	5
> 
>  #define PNADDR_ANY		0
>  #define PNADDR_BROADCAST	0xFC
> @@ -180,6 +182,7 @@ static inline __u8 pn_sockaddr_get_resource(const struct
> sockaddr_pn *spn) /* Phonet device ioctl requests */
>  #ifdef __KERNEL__
>  #define SIOCPNGAUTOCONF		(SIOCDEVPRIVATE + 0)
> +#define SIOPNPIPE_ENABLE	_IO(SIOCPNGAUTOCONF,   1)

Does this even work? I am not an expert on this, but I would think that 
device-private controls are routed to the network device, not the socket. In 
any case, it does not seem right.

> 
>  struct if_phonet_autoconf {
>  	uint8_t device;
> diff --git a/net/phonet/pep.c b/net/phonet/pep.c
> index f17fd84..48339b9 100644
> --- a/net/phonet/pep.c
> +++ b/net/phonet/pep.c
> @@ -533,6 +533,29 @@ static int pep_connresp_rcv(struct sock *sk, struct
> sk_buff *skb) return pipe_handler_send_created_ind(sk);
>  }
> 
> +static int pep_enableresp_rcv(struct sock *sk, struct sk_buff *skb)
> +{
> +	struct pnpipehdr *hdr = pnp_hdr(skb);
> +
> +	if (hdr->error_code != PN_PIPE_NO_ERROR)
> +		return -ECONNREFUSED;
> +
> +	return pep_indicate(sk, PNS_PIPE_ENABLED_IND, 0 /* sub-blocks */,
> +		NULL, 0, GFP_ATOMIC);
> +
> +}
> +
> +static void pipe_start_flow_control(struct sock *sk)
> +{
> +	struct pep_sock *pn = pep_sk(sk);
> +
> +	if (!pn_flow_safe(pn->tx_fc)) {
> +		atomic_set(&pn->tx_credits, 1);
> +		sk->sk_write_space(sk);
> +	}
> +	pipe_grant_credits(sk, GFP_ATOMIC);
> +}
> +
>  /* Queue an skb to an actively connected sock.
>   * Socket lock must be held. */
>  static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
> @@ -578,13 +601,25 @@ static int pipe_handler_do_rcv(struct sock *sk, struct
> sk_buff *skb) sk->sk_state = TCP_CLOSE_WAIT;
>  			break;
>  		}
> +		if (pn->init_enable == PN_PIPE_DISABLE)
> +			sk->sk_state = TCP_SYN_RECV;
> +		else {
> +			sk->sk_state = TCP_ESTABLISHED;
> +			pipe_start_flow_control(sk);
> +		}
> +		break;
> 
> -		sk->sk_state = TCP_ESTABLISHED;
> -		if (!pn_flow_safe(pn->tx_fc)) {
> -			atomic_set(&pn->tx_credits, 1);
> -			sk->sk_write_space(sk);
> +	case PNS_PEP_ENABLE_RESP:
> +		if (sk->sk_state != TCP_SYN_SENT)
> +			break;
> +
> +		if (pep_enableresp_rcv(sk, skb)) {
> +			sk->sk_state = TCP_CLOSE_WAIT;
> +			break;
>  		}
> -		pipe_grant_credits(sk, GFP_ATOMIC);
> +
> +		sk->sk_state = TCP_ESTABLISHED;
> +		pipe_start_flow_control(sk);
>  		break;
> 
>  	case PNS_PEP_DISCONNECT_RESP:
> @@ -863,14 +898,31 @@ static int pep_sock_connect(struct sock *sk, struct
> sockaddr *addr, int len) int err;
>  	u8 data[4] = { 0 /* sub-blocks */, PAD, PAD, PAD };
> 
> -	pn->pipe_handle = 1; /* anything but INVALID_HANDLE */
> +	if (pn->pipe_handle == PN_PIPE_INVALID_HANDLE)
> +		pn->pipe_handle = 1; /* anything but INVALID_HANDLE */
> +
>  	err = pipe_handler_request(sk, PNS_PEP_CONNECT_REQ,
> -					PN_PIPE_ENABLE, data, 4);
> -	if (err) {
> -		pn->pipe_handle = PN_PIPE_INVALID_HANDLE;

The current backlog functions assume that pipe_handle = PN_PIPE_INVALID_HANDLE 
if the socket is not yet connected. That's why the old code would clear the 
pipe_handle always on error.

So it is not that simple.

> +				pn->init_enable, data, 4);
> +	if (err)
>  		return err;
> -	}
> +
> +	sk->sk_state = TCP_SYN_SENT;
> +
> +	return 0;
> +}
> +
> +static int pep_sock_enable(struct sock *sk, struct sockaddr *addr, int len)
> +{
> +	int err;
> +
> +	err = pipe_handler_request(sk, PNS_PEP_ENABLE_REQ, PAD,
> +				NULL, 0);
> +
> +	if (err)
> +		return err;
> +
>  	sk->sk_state = TCP_SYN_SENT;
> +
>  	return 0;
>  }
> 
> @@ -894,6 +946,16 @@ static int pep_ioctl(struct sock *sk, int cmd, unsigned
> long arg) answ = 0;
>  		release_sock(sk);
>  		return put_user(answ, (int __user *)arg);
> +		break;
> +
> +	case SIOPNPIPE_ENABLE:
> +		if (sk->sk_state == TCP_SYN_SENT)
> +			return -EBUSY;
> +		else if (sk->sk_state == TCP_ESTABLISHED)
> +			return -EISCONN;
> +		else
> +			return pep_sock_enable(sk, NULL, 0);
> +		break;
>  	}

I strongly suspect insufficient locking here.

> 
>  	return -ENOIOCTLCMD;
> @@ -959,6 +1021,18 @@ static int pep_setsockopt(struct sock *sk, int level,
> int optname, }
>  		goto out_norel;
> 
> +	case PNPIPE_HANDLE:
> +		if ((sk->sk_state == TCP_CLOSE) &&
> +			(val >= 0) && (val < PN_PIPE_INVALID_HANDLE))
> +			pn->pipe_handle = val;
> +		else
> +			err = -EINVAL;
> +		break;

Same problem regarding pipe_handle as above.

> +
> +	case PNPIPE_INITSTATE:
> +		pn->init_enable = !!val;
> +		break;
> +
>  	default:
>  		err = -ENOPROTOOPT;
>  	}
> @@ -994,6 +1068,17 @@ static int pep_getsockopt(struct sock *sk, int level,
> int optname, return -EINVAL;
>  		break;
> 
> +	case PNPIPE_ENABLE:
> +		if (sk->sk_state == TCP_ESTABLISHED)
> +			val = 1;
> +		else
> +			val = 0;
> +		break;

Do you still need this read-only option?

> +
> +	case PNPIPE_INITSTATE:
> +		val = pn->init_enable;
> +		break;
> +
>  	default:
>  		return -ENOPROTOOPT;
>  	}
-- 
Rémi Denis-Courmont
http://www.remlab.net/

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

* RE: [PATCH] Phonet: set the pipe handle using setsockopt
  2011-11-14  9:29 ` Rémi Denis-Courmont
@ 2011-11-14 10:36   ` Hemant-vilas RAMDASI
  2011-11-16  6:30     ` Rémi Denis-Courmont
  0 siblings, 1 reply; 9+ messages in thread
From: Hemant-vilas RAMDASI @ 2011-11-14 10:36 UTC (permalink / raw)
  To: Rémi Denis-Courmont, netdev@vger.kernel.org,
	netdev-owner@vger.kernel.org

Remi,

> -----Original Message-----
> From: Rémi Denis-Courmont [mailto:remi.denis-courmont@nokia.com]
> Sent: Monday, November 14, 2011 3:00 PM
> To: Hemant-vilas RAMDASI; netdev@vger.kernel.org
> Subject: Re: [PATCH] Phonet: set the pipe handle using setsockopt
> > @@ -180,6 +182,7 @@ static inline __u8 pn_sockaddr_get_resource(const
> struct
> > sockaddr_pn *spn) /* Phonet device ioctl requests */
> >  #ifdef __KERNEL__
> >  #define SIOCPNGAUTOCONF		(SIOCDEVPRIVATE + 0)
> > +#define SIOPNPIPE_ENABLE	_IO(SIOCPNGAUTOCONF,   1)
> 
> Does this even work? I am not an expert on this, but I would think that
> device-private controls are routed to the network device, not the
> socket. In
> any case, it does not seem right.
> 
Yes, it works. The ioctl is routed to per-socket functions.

> > @@ -863,14 +898,31 @@ static int pep_sock_connect(struct sock *sk,
> struct
> > sockaddr *addr, int len) int err;
> >  	u8 data[4] = { 0 /* sub-blocks */, PAD, PAD, PAD };
> >
> > -	pn->pipe_handle = 1; /* anything but INVALID_HANDLE */
> > +	if (pn->pipe_handle == PN_PIPE_INVALID_HANDLE)
> > +		pn->pipe_handle = 1; /* anything but INVALID_HANDLE */
> > +
> >  	err = pipe_handler_request(sk, PNS_PEP_CONNECT_REQ,
> > -					PN_PIPE_ENABLE, data, 4);
> > -	if (err) {
> > -		pn->pipe_handle = PN_PIPE_INVALID_HANDLE;
> 
> The current backlog functions assume that pipe_handle =
> PN_PIPE_INVALID_HANDLE
> if the socket is not yet connected. That's why the old code would clear
> the
> pipe_handle always on error.
Ok..I think clearing pipe-handle on connect error should take care of this.
User-space need to set the handle again.
> 
> So it is not that simple.
> 
> > @@ -894,6 +946,16 @@ static int pep_ioctl(struct sock *sk, int cmd,
> unsigned
> > +	case SIOPNPIPE_ENABLE:
> > +		if (sk->sk_state == TCP_SYN_SENT)
> > +			return -EBUSY;
> > +		else if (sk->sk_state == TCP_ESTABLISHED)
> > +			return -EISCONN;
> > +		else
> > +			return pep_sock_enable(sk, NULL, 0);
> > +		break;
> >  	}
> 
> I strongly suspect insufficient locking here.
Ok..
> 
> >
> >  	return -ENOIOCTLCMD;
> > @@ -959,6 +1021,18 @@ static int pep_setsockopt(struct sock *sk, int
> level,
> > int optname, }
> >  		goto out_norel;
> >
> > +	case PNPIPE_HANDLE:
> > +		if ((sk->sk_state == TCP_CLOSE) &&
> > +			(val >= 0) && (val < PN_PIPE_INVALID_HANDLE))
> > +			pn->pipe_handle = val;
> > +		else
> > +			err = -EINVAL;
> > +		break;
> 
> Same problem regarding pipe_handle as above.
I think locking already exists..

> > @@ -994,6 +1068,17 @@ static int pep_getsockopt(struct sock *sk, int
> level,
> > int optname, return -EINVAL;
> >  		break;
> >
> > +	case PNPIPE_ENABLE:
> > +		if (sk->sk_state == TCP_ESTABLISHED)
> > +			val = 1;
> > +		else
> > +			val = 0;
> > +		break;
> 
> Do you still need this read-only option?
Yes.

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

* Re: [PATCH] Phonet: set the pipe handle using setsockopt
  2011-11-14 10:36   ` Hemant-vilas RAMDASI
@ 2011-11-16  6:30     ` Rémi Denis-Courmont
  2011-11-16  8:46       ` Hemant-vilas RAMDASI
  0 siblings, 1 reply; 9+ messages in thread
From: Rémi Denis-Courmont @ 2011-11-16  6:30 UTC (permalink / raw)
  To: netdev@vger.kernel.org

Le Lundi 14 Novembre 2011 11:36:12 ext Hemant-vilas RAMDASI a écrit :
 > > sockaddr_pn *spn) /* Phonet device ioctl requests */
> > > 
> > >  #ifdef __KERNEL__
> > >  #define SIOCPNGAUTOCONF		(SIOCDEVPRIVATE + 0)
> > > 
> > > +#define SIOPNPIPE_ENABLE	_IO(SIOCPNGAUTOCONF,   1)
> > 
> > Does this even work? I am not an expert on this, but I would think that
> > device-private controls are routed to the network device, not the
> > socket. In
> > any case, it does not seem right.
> 
> Yes, it works. The ioctl is routed to per-socket functions.

Even if it works, sockets are probably not supposed to use the device-private 
ioctl() range, are they?

And why is this inside __KERNEL__ ?

> > > @@ -994,6 +1068,17 @@ static int pep_getsockopt(struct sock *sk, int
> > 
> > level,
> > 
> > > int optname, return -EINVAL;
> > > 
> > >  		break;
> > > 
> > > +	case PNPIPE_ENABLE:
> > > +		if (sk->sk_state == TCP_ESTABLISHED)
> > > +			val = 1;
> > > +		else
> > > +			val = 0;
> > > +		break;
> > 
> > Do you still need this read-only option?
> 
> Yes.

Why and how?

-- 
Rémi Denis-Courmont
http://www.remlab.net/

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

* RE: [PATCH] Phonet: set the pipe handle using setsockopt
  2011-11-16  6:30     ` Rémi Denis-Courmont
@ 2011-11-16  8:46       ` Hemant-vilas RAMDASI
  2011-11-16 10:15         ` Rémi Denis-Courmont
  0 siblings, 1 reply; 9+ messages in thread
From: Hemant-vilas RAMDASI @ 2011-11-16  8:46 UTC (permalink / raw)
  To: Rémi Denis-Courmont, netdev@vger.kernel.org

Remi,

> > > > +#define SIOPNPIPE_ENABLE	_IO(SIOCPNGAUTOCONF,   1)
> > >
> > > Does this even work? I am not an expert on this, but I would think
> that
> > > device-private controls are routed to the network device, not the
> > > socket. In
> > > any case, it does not seem right.
> >
> > Yes, it works. The ioctl is routed to per-socket functions.
> 
> Even if it works, sockets are probably not supposed to use the device-
> private
> ioctl() range, are they?
> 
> And why is this inside __KERNEL__ ?
Ok..We move it.

> > > Do you still need this read-only option?
> >
> > Yes.
> 
> Why and how?
This is needed for user to poll pipe-state.

Regards,
Hemant

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

* Re: [PATCH] Phonet: set the pipe handle using setsockopt
  2011-11-16  8:46       ` Hemant-vilas RAMDASI
@ 2011-11-16 10:15         ` Rémi Denis-Courmont
  0 siblings, 0 replies; 9+ messages in thread
From: Rémi Denis-Courmont @ 2011-11-16 10:15 UTC (permalink / raw)
  To: netdev@vger.kernel.org

Le Mercredi 16 Novembre 2011 09:46:07 ext Hemant-vilas RAMDASI a écrit :
> > Why and how?
> 
> This is needed for user to poll pipe-state.

The pipe state is already exposed with poll() for all that user space should 
ever need to care about.

Polling state with getsockopt would probably break power management anyway.

-- 
Rémi Denis-Courmont
http://www.remlab.net/

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

end of thread, other threads:[~2011-11-16 10:15 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-14  7:53 [PATCH] Phonet: set the pipe handle using setsockopt Hemant Vilas RAMDASI
2011-11-14  9:29 ` Rémi Denis-Courmont
2011-11-14 10:36   ` Hemant-vilas RAMDASI
2011-11-16  6:30     ` Rémi Denis-Courmont
2011-11-16  8:46       ` Hemant-vilas RAMDASI
2011-11-16 10:15         ` Rémi Denis-Courmont
  -- strict thread matches above, loose matches on Subject: below --
2011-11-09 11:20 Hemant Vilas RAMDASI
2011-11-09 15:00 ` Rémi Denis-Courmont
2011-11-10  9:44   ` Hemant-vilas RAMDASI

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).