diff options
author | Rémi Denis-Courmont <remi.denis-courmont@nokia.com> | 2010-10-08 00:02:02 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2010-10-08 17:09:10 -0400 |
commit | 03789f26722a15ccfe6f191e9fb3d356f2f18a1e (patch) | |
tree | a55a493a1b4804d0acafad5fd1a4a3b1100f3ff4 /net/phonet | |
parent | 6d8e74ed377dd4cbad7ccc69300f734090e15c05 (diff) |
Phonet: cleanup pipe enable socket option
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 <remi.denis-courmont@nokia.com>
Cc: Kumar Sanghvi <kumar.sanghvi@stericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/phonet')
-rw-r--r-- | net/phonet/pep.c | 72 |
1 files changed, 30 insertions, 42 deletions
diff --git a/net/phonet/pep.c b/net/phonet/pep.c index aa3d8700d213..f818f76d297d 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, | |||
327 | return pn_skb_send(sk, skb, &spn); | 327 | return pn_skb_send(sk, skb, &spn); |
328 | } | 328 | } |
329 | 329 | ||
330 | static int pipe_handler_enable_pipe(struct sock *sk, int cmd) | 330 | static int pipe_handler_enable_pipe(struct sock *sk, int enable) |
331 | { | 331 | { |
332 | int ret; | ||
333 | struct pep_sock *pn = pep_sk(sk); | 332 | struct pep_sock *pn = pep_sk(sk); |
334 | 333 | int utid, req; | |
335 | switch (cmd) { | 334 | |
336 | case PNPIPE_ENABLE: | 335 | if (enable) { |
337 | ret = pipe_handler_send_req(sk, pn->pn_sk.sobject, | 336 | utid = PNS_PIPE_ENABLE_UTID; |
338 | PNS_PIPE_ENABLE_UTID, PNS_PEP_ENABLE_REQ, | 337 | req = PNS_PEP_ENABLE_REQ; |
339 | pn->pipe_handle, GFP_ATOMIC); | 338 | } else { |
340 | break; | 339 | utid = PNS_PIPE_DISABLE_UTID; |
341 | 340 | req = PNS_PEP_DISABLE_REQ; | |
342 | case PNPIPE_DISABLE: | ||
343 | ret = pipe_handler_send_req(sk, pn->pn_sk.sobject, | ||
344 | PNS_PIPE_DISABLE_UTID, PNS_PEP_DISABLE_REQ, | ||
345 | pn->pipe_handle, GFP_ATOMIC); | ||
346 | break; | ||
347 | |||
348 | default: | ||
349 | ret = -EINVAL; | ||
350 | } | 341 | } |
351 | 342 | return pipe_handler_send_req(sk, pn->pn_sk.sobject, utid, req, | |
352 | return ret; | 343 | pn->pipe_handle, GFP_ATOMIC); |
353 | } | 344 | } |
354 | 345 | ||
355 | static int pipe_handler_create_pipe(struct sock *sk, int pipe_handle, int cmd) | 346 | 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, | |||
1187 | break; | 1178 | break; |
1188 | } | 1179 | } |
1189 | 1180 | ||
1190 | case PNPIPE_ENABLE: | ||
1191 | if (pn->pipe_state != PIPE_DISABLED) { | ||
1192 | err = -EFAULT; | ||
1193 | break; | ||
1194 | } | ||
1195 | err = pipe_handler_enable_pipe(sk, PNPIPE_ENABLE); | ||
1196 | break; | ||
1197 | |||
1198 | case PNPIPE_DISABLE: | ||
1199 | if (pn->pipe_state != PIPE_ENABLED) { | ||
1200 | err = -EFAULT; | ||
1201 | break; | ||
1202 | } | ||
1203 | |||
1204 | err = pipe_handler_enable_pipe(sk, PNPIPE_DISABLE); | ||
1205 | break; | ||
1206 | |||
1207 | case PNPIPE_DESTROY: | 1181 | case PNPIPE_DESTROY: |
1208 | if (pn->pipe_state < PIPE_DISABLED) { | 1182 | if (pn->pipe_state < PIPE_DISABLED) { |
1209 | err = -EFAULT; | 1183 | err = -EFAULT; |
@@ -1239,6 +1213,17 @@ static int pep_setsockopt(struct sock *sk, int level, int optname, | |||
1239 | err = 0; | 1213 | err = 0; |
1240 | } | 1214 | } |
1241 | goto out_norel; | 1215 | goto out_norel; |
1216 | |||
1217 | #ifdef CONFIG_PHONET_PIPECTRLR | ||
1218 | case PNPIPE_ENABLE: | ||
1219 | if (pn->pipe_state <= PIPE_IDLE) { | ||
1220 | err = -ENOTCONN; | ||
1221 | break; | ||
1222 | } | ||
1223 | err = pipe_handler_enable_pipe(sk, val); | ||
1224 | break; | ||
1225 | #endif | ||
1226 | |||
1242 | default: | 1227 | default: |
1243 | err = -ENOPROTOOPT; | 1228 | err = -ENOPROTOOPT; |
1244 | } | 1229 | } |
@@ -1264,15 +1249,18 @@ static int pep_getsockopt(struct sock *sk, int level, int optname, | |||
1264 | val = pn->ifindex ? PNPIPE_ENCAP_IP : PNPIPE_ENCAP_NONE; | 1249 | val = pn->ifindex ? PNPIPE_ENCAP_IP : PNPIPE_ENCAP_NONE; |
1265 | break; | 1250 | break; |
1266 | 1251 | ||
1252 | case PNPIPE_IFINDEX: | ||
1253 | val = pn->ifindex; | ||
1254 | break; | ||
1255 | |||
1267 | #ifdef CONFIG_PHONET_PIPECTRLR | 1256 | #ifdef CONFIG_PHONET_PIPECTRLR |
1268 | case PNPIPE_INQ: | 1257 | case PNPIPE_ENABLE: |
1269 | val = pn->pipe_state; | 1258 | if (pn->pipe_state <= PIPE_IDLE) |
1259 | return -ENOTCONN; | ||
1260 | val = pn->pipe_state != PIPE_DISABLED; | ||
1270 | break; | 1261 | break; |
1271 | #endif | 1262 | #endif |
1272 | 1263 | ||
1273 | case PNPIPE_IFINDEX: | ||
1274 | val = pn->ifindex; | ||
1275 | break; | ||
1276 | default: | 1264 | default: |
1277 | return -ENOPROTOOPT; | 1265 | return -ENOPROTOOPT; |
1278 | } | 1266 | } |