diff options
author | Nikolay Aleksandrov <nikolay@cumulusnetworks.com> | 2015-11-21 09:57:28 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-11-23 15:06:38 -0500 |
commit | fe9ef3ce395d06e4f17e5995ab8455b9627f3306 (patch) | |
tree | e76b51d53a559afc69fe20e66fc4697041c3d4db /net/ipv4/ipmr.c | |
parent | 7ef8f65df976369588fa1b6466668b1b6a26eb3c (diff) |
net: ipmr: make ip_mroute_getsockopt more understandable
Use a switch to determine if optname is correct and set val accordingly.
This produces a much more straight-forward and readable code.
Signed-off-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4/ipmr.c')
-rw-r--r-- | net/ipv4/ipmr.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c index 286ede3716ee..694fecf7838e 100644 --- a/net/ipv4/ipmr.c +++ b/net/ipv4/ipmr.c | |||
@@ -1443,29 +1443,29 @@ int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int | |||
1443 | if (!mrt) | 1443 | if (!mrt) |
1444 | return -ENOENT; | 1444 | return -ENOENT; |
1445 | 1445 | ||
1446 | if (optname != MRT_VERSION && | 1446 | switch (optname) { |
1447 | optname != MRT_PIM && | 1447 | case MRT_VERSION: |
1448 | optname != MRT_ASSERT) | 1448 | val = 0x0305; |
1449 | break; | ||
1450 | case MRT_PIM: | ||
1451 | if (!pimsm_enabled()) | ||
1452 | return -ENOPROTOOPT; | ||
1453 | val = mrt->mroute_do_pim; | ||
1454 | break; | ||
1455 | case MRT_ASSERT: | ||
1456 | val = mrt->mroute_do_assert; | ||
1457 | break; | ||
1458 | default: | ||
1449 | return -ENOPROTOOPT; | 1459 | return -ENOPROTOOPT; |
1460 | } | ||
1450 | 1461 | ||
1451 | if (get_user(olr, optlen)) | 1462 | if (get_user(olr, optlen)) |
1452 | return -EFAULT; | 1463 | return -EFAULT; |
1453 | |||
1454 | olr = min_t(unsigned int, olr, sizeof(int)); | 1464 | olr = min_t(unsigned int, olr, sizeof(int)); |
1455 | if (olr < 0) | 1465 | if (olr < 0) |
1456 | return -EINVAL; | 1466 | return -EINVAL; |
1457 | |||
1458 | if (put_user(olr, optlen)) | 1467 | if (put_user(olr, optlen)) |
1459 | return -EFAULT; | 1468 | return -EFAULT; |
1460 | if (optname == MRT_VERSION) { | ||
1461 | val = 0x0305; | ||
1462 | } else if (optname == MRT_PIM) { | ||
1463 | if (!pimsm_enabled()) | ||
1464 | return -ENOPROTOOPT; | ||
1465 | val = mrt->mroute_do_pim; | ||
1466 | } else { | ||
1467 | val = mrt->mroute_do_assert; | ||
1468 | } | ||
1469 | if (copy_to_user(optval, &val, olr)) | 1469 | if (copy_to_user(optval, &val, olr)) |
1470 | return -EFAULT; | 1470 | return -EFAULT; |
1471 | return 0; | 1471 | return 0; |