Skip to content

Commit acaf7df

Browse files
Rémi Denis-Courmontdavem330
authored andcommitted
Phonet: provide pipe socket option to retrieve the pipe identifier
User-space sometimes needs this information. In particular, the GPRS context or the AT commands pipe setups may use the pipe handle as a reference. This removes the settable pipe handle with CONFIG_PHONET_PIPECTRLR. It did not handle error cases correctly. Furthermore, the kernel *could* implement a smart scheme for allocating handles (if ever needed), but userspace really cannot. Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f7ae8d5 commit acaf7df

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

‎Documentation/networking/phonet.txt‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ The pipe protocol provides two socket options at the SOL_PNPIPE level:
181181
interface index of the network interface created by PNPIPE_ENCAP,
182182
or zero if encapsulation is off.
183183

184+
PNPIPE_HANDLE is a read-only integer value. It contains the underlying
185+
identifier ("pipe handle") of the pipe. This is only defined for
186+
socket descriptors that are already connected or being connected.
187+
184188

185189
Phonet Pipe-controller Implementation
186190
-------------------------------------
@@ -199,9 +203,6 @@ between itself and a remote pipe-end point (e.g. modem).
199203

200204
The implementation adds socket options at SOL_PNPIPE level:
201205

202-
PNPIPE_PIPE_HANDLE
203-
It accepts an integer argument for setting value of pipe handle.
204-
205206
PNPIPE_ENABLE accepts one integer value (int). If set to zero, the pipe
206207
is disabled. If the value is non-zero, the pipe is enabled. If the pipe
207208
is not (yet) connected, ENOTCONN is error is returned.

‎include/linux/phonet.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
/* Socket options for SOL_PNPIPE level */
3737
#define PNPIPE_ENCAP 1
3838
#define PNPIPE_IFINDEX 2
39-
#define PNPIPE_PIPE_HANDLE 3
39+
#define PNPIPE_HANDLE 3
4040
#define PNPIPE_ENABLE 4
4141
/* unused slot */
4242

‎net/phonet/pep.c‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ static int pep_sock_connect(struct sock *sk, struct sockaddr *addr, int len)
853853

854854
pn->pn_sk.dobject = pn_sockaddr_get_object(spn);
855855
pn->pn_sk.resource = pn_sockaddr_get_resource(spn);
856+
pn->pipe_handle = 1; /* anything but INVALID_HANDLE */
856857
return pipe_handler_request(sk, PNS_PEP_CONNECT_REQ,
857858
PN_PIPE_DISABLE, data, 4);
858859
}
@@ -909,14 +910,6 @@ static int pep_setsockopt(struct sock *sk, int level, int optname,
909910

910911
lock_sock(sk);
911912
switch (optname) {
912-
#ifdef CONFIG_PHONET_PIPECTRLR
913-
case PNPIPE_PIPE_HANDLE:
914-
if (val) {
915-
pn->pipe_handle = val;
916-
break;
917-
}
918-
#endif
919-
920913
case PNPIPE_ENCAP:
921914
if (val && val != PNPIPE_ENCAP_IP) {
922915
err = -EINVAL;
@@ -982,6 +975,12 @@ static int pep_getsockopt(struct sock *sk, int level, int optname,
982975
val = pn->ifindex;
983976
break;
984977

978+
case PNPIPE_HANDLE:
979+
val = pn->pipe_handle;
980+
if (val == PN_PIPE_INVALID_HANDLE)
981+
return -EINVAL;
982+
break;
983+
985984
#ifdef CONFIG_PHONET_PIPECTRLR
986985
case PNPIPE_ENABLE:
987986
val = sk->sk_state == TCP_ESTABLISHED;

0 commit comments

Comments
 (0)