From 03789f26722a15ccfe6f191e9fb3d356f2f18a1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= Date: Fri, 8 Oct 2010 04:02:02 +0000 Subject: Phonet: cleanup pipe enable socket option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current code works like this: int garbage, status; socklen_t len = sizeof(status); /* enable pipe */ setsockopt(fd, SOL_PNPIPE, PNPIPE_ENABLE, &garbage, sizeof(garbage)); /* disable pipe */ setsockopt(fd, SOL_PNPIPE, PNPIPE_DISABLE, &garbage, sizeof(garbage)); /* get status */ getsockopt(fd, SOL_PNPIPE, PNPIPE_INQ, &status, &len); ...which does not follow the usual socket option pattern. This patch merges all three "options" into a single gettable&settable option, before Linux 2.6.37 gets out: int status; socklen_t len = sizeof(status); /* enable pipe */ status = 1; setsockopt(fd, SOL_PNPIPE, PNPIPE_ENABLE, &status, sizeof(status)); /* disable pipe */ status = 0; setsockopt(fd, SOL_PNPIPE, PNPIPE_ENABLE, &status, sizeof(status)); /* get status */ getsockopt(fd, SOL_PNPIPE, PNPIPE_ENABLE, &status, &len); This also fixes the error code from EFAULT to ENOTCONN. Signed-off-by: RĂ©mi Denis-Courmont Cc: Kumar Sanghvi Signed-off-by: David S. Miller --- net/phonet/pep.c | 72 +++++++++++++++++++++++--------------------------------- 1 file changed, 30 insertions(+), 42 deletions(-) (limited to 'net/phonet') diff --git a/net/phonet/pep.c b/net/phonet/pep.c index aa3d8700d21..f818f76d297 100644 --- a/net/phonet/pep.c +++ b/net/phonet/pep.c @@ -327,29 +327,20 @@ static int pipe_handler_send_ind(struct sock *sk, u16 dobj, u8 utid, return pn_skb_send(sk, skb, &spn); } -static int pipe_handler_enable_pipe(struct sock *sk, int cmd) +static int pipe_handler_enable_pipe(struct sock *sk, int enable) { - int ret; struct pep_sock *pn = pep_sk(sk); - - switch (cmd) { - case PNPIPE_ENABLE: - ret = pipe_handler_send_req(sk, pn->pn_sk.sobject, - PNS_PIPE_ENABLE_UTID, PNS_PEP_ENABLE_REQ, - pn->pipe_handle, GFP_ATOMIC); - break; - - case PNPIPE_DISABLE: - ret = pipe_handler_send_req(sk, pn->pn_sk.sobject, - PNS_PIPE_DISABLE_UTID, PNS_PEP_DISABLE_REQ, - pn->pipe_handle, GFP_ATOMIC); - break; - - default: - ret = -EINVAL; + int utid, req; + + if (enable) { + utid = PNS_PIPE_ENABLE_UTID; + req = PNS_PEP_ENABLE_REQ; + } else { + utid = PNS_PIPE_DISABLE_UTID; + req = PNS_PEP_DISABLE_REQ; } - - return ret; + return pipe_handler_send_req(sk, pn->pn_sk.sobject, utid, req, + pn->pipe_handle, GFP_ATOMIC); } static int pipe_handler_create_pipe(struct sock *sk, int pipe_handle, int cmd) @@ -1187,23 +1178,6 @@ static int pep_setsockopt(struct sock *sk, int level, int optname, break; } - case PNPIPE_ENABLE: - if (pn->pipe_state != PIPE_DISABLED) { - err = -EFAULT; - break; - } - err = pipe_handler_enable_pipe(sk, PNPIPE_ENABLE); - break; - - case PNPIPE_DISABLE: - if (pn->pipe_state != PIPE_ENABLED) { - err = -EFAULT; - break; - } - - err = pipe_handler_enable_pipe(sk, PNPIPE_DISABLE); - break; - case PNPIPE_DESTROY: if (pn->pipe_state < PIPE_DISABLED) { err = -EFAULT; @@ -1239,6 +1213,17 @@ static int pep_setsockopt(struct sock *sk, int level, int optname, err = 0; } goto out_norel; + +#ifdef CONFIG_PHONET_PIPECTRLR + case PNPIPE_ENABLE: + if (pn->pipe_state <= PIPE_IDLE) { + err = -ENOTCONN; + break; + } + err = pipe_handler_enable_pipe(sk, val); + break; +#endif + default: err = -ENOPROTOOPT; } @@ -1264,15 +1249,18 @@ static int pep_getsockopt(struct sock *sk, int level, int optname, val = pn->ifindex ? PNPIPE_ENCAP_IP : PNPIPE_ENCAP_NONE; break; + case PNPIPE_IFINDEX: + val = pn->ifindex; + break; + #ifdef CONFIG_PHONET_PIPECTRLR - case PNPIPE_INQ: - val = pn->pipe_state; + case PNPIPE_ENABLE: + if (pn->pipe_state <= PIPE_IDLE) + return -ENOTCONN; + val = pn->pipe_state != PIPE_DISABLED; break; #endif - case PNPIPE_IFINDEX: - val = pn->ifindex; - break; default: return -ENOPROTOOPT; } -- cgit v1.2.3