提交 fe9ef3ce 编写于 作者: N Nikolay Aleksandrov 提交者: David S. Miller

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: NNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 7ef8f65d
......@@ -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)
switch (optname) {
case MRT_VERSION:
val = 0x0305;
break;
case MRT_PIM:
if (!pimsm_enabled())
return -ENOPROTOOPT;
val = mrt->mroute_do_pim;
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 (optname == MRT_VERSION) {
val = 0x0305;
} else if (optname == MRT_PIM) {
if (!pimsm_enabled())
return -ENOPROTOOPT;
val = mrt->mroute_do_pim;
} else {
val = mrt->mroute_do_assert;
}
if (copy_to_user(optval, &val, olr))
return -EFAULT;
return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册