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>
This commit is contained in:
Nikolay Aleksandrov 2015-11-21 15:57:28 +01:00 committed by David S. Miller
parent 7ef8f65df9
commit fe9ef3ce39

View File

@ -1443,29 +1443,29 @@ int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int
if (!mrt)
return -ENOENT;
if (optname != MRT_VERSION &&
optname != MRT_PIM &&
optname != MRT_ASSERT)
return -ENOPROTOOPT;
if (get_user(olr, optlen))
return -EFAULT;
olr = min_t(unsigned int, olr, sizeof(int));
if (olr < 0)
return -EINVAL;
if (put_user(olr, optlen))
return -EFAULT;
if (optname == MRT_VERSION) {
switch (optname) {
case MRT_VERSION:
val = 0x0305;
} else if (optname == MRT_PIM) {
break;
case MRT_PIM:
if (!pimsm_enabled())
return -ENOPROTOOPT;
val = mrt->mroute_do_pim;
} else {
break;
case MRT_ASSERT:
val = mrt->mroute_do_assert;
break;
default:
return -ENOPROTOOPT;
}
if (get_user(olr, optlen))
return -EFAULT;
olr = min_t(unsigned int, olr, sizeof(int));
if (olr < 0)
return -EINVAL;
if (put_user(olr, optlen))
return -EFAULT;
if (copy_to_user(optval, &val, olr))
return -EFAULT;
return 0;