提交 c0ef877b 编写于 作者: P Pavel Emelyanov 提交者: David S. Miller

[NET]: Move sock_valbool_flag to socket.c

The sock_valbool_flag() helper is used in setsockopt to
set or reset some flag on the sock. This helper is required
in the net/socket.c only, so move it there.

Besides, patch two places in sys_setsockopt() that repeat
this helper functionality manually.

Since this is not a bugfix, but a trivial cleanup, I
prepared this patch against net-2.6.25, but it also
applies (with a single offset) to the latest net-2.6.
Signed-off-by: NPavel Emelyanov <xemul@openvz.org>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 de0fa95c
...@@ -1396,14 +1396,6 @@ extern int net_msg_warn; ...@@ -1396,14 +1396,6 @@ extern int net_msg_warn;
lock_sock(sk); \ lock_sock(sk); \
} }
static inline void sock_valbool_flag(struct sock *sk, int bit, int valbool)
{
if (valbool)
sock_set_flag(sk, bit);
else
sock_reset_flag(sk, bit);
}
extern __u32 sysctl_wmem_max; extern __u32 sysctl_wmem_max;
extern __u32 sysctl_rmem_max; extern __u32 sysctl_rmem_max;
......
...@@ -419,6 +419,14 @@ static int sock_bindtodevice(struct sock *sk, char __user *optval, int optlen) ...@@ -419,6 +419,14 @@ static int sock_bindtodevice(struct sock *sk, char __user *optval, int optlen)
return ret; return ret;
} }
static inline void sock_valbool_flag(struct sock *sk, int bit, int valbool)
{
if (valbool)
sock_set_flag(sk, bit);
else
sock_reset_flag(sk, bit);
}
/* /*
* This is meant for all protocols to use and covers goings on * This is meant for all protocols to use and covers goings on
* at the socket level. Everything here is generic. * at the socket level. Everything here is generic.
...@@ -463,11 +471,8 @@ int sock_setsockopt(struct socket *sock, int level, int optname, ...@@ -463,11 +471,8 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
case SO_DEBUG: case SO_DEBUG:
if (val && !capable(CAP_NET_ADMIN)) { if (val && !capable(CAP_NET_ADMIN)) {
ret = -EACCES; ret = -EACCES;
} } else
else if (valbool) sock_valbool_flag(sk, SOCK_DBG, valbool);
sock_set_flag(sk, SOCK_DBG);
else
sock_reset_flag(sk, SOCK_DBG);
break; break;
case SO_REUSEADDR: case SO_REUSEADDR:
sk->sk_reuse = valbool; sk->sk_reuse = valbool;
...@@ -477,10 +482,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname, ...@@ -477,10 +482,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
ret = -ENOPROTOOPT; ret = -ENOPROTOOPT;
break; break;
case SO_DONTROUTE: case SO_DONTROUTE:
if (valbool) sock_valbool_flag(sk, SOCK_LOCALROUTE, valbool);
sock_set_flag(sk, SOCK_LOCALROUTE);
else
sock_reset_flag(sk, SOCK_LOCALROUTE);
break; break;
case SO_BROADCAST: case SO_BROADCAST:
sock_valbool_flag(sk, SOCK_BROADCAST, valbool); sock_valbool_flag(sk, SOCK_BROADCAST, valbool);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册