Commit ebf9e8e6 authored by Martin KaFai Lau's avatar Martin KaFai Lau Committed by Alexei Starovoitov

bpf: Embed kernel CONFIG check into the if statement in bpf_setsockopt

This patch moves the "#ifdef CONFIG_XXX" check into the "if/else"
statement itself.  The change is done for the bpf_setsockopt()
function only.  It will make the latter patches easier to follow
without the surrounding ifdef macro.
Reviewed-by: default avatarStanislav Fomichev <sdf@google.com>
Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/r/20220817061758.4178374-1-kafai@fb.comSigned-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parent 2b5a2ecb
...@@ -5116,8 +5116,7 @@ static int __bpf_setsockopt(struct sock *sk, int level, int optname, ...@@ -5116,8 +5116,7 @@ static int __bpf_setsockopt(struct sock *sk, int level, int optname,
default: default:
ret = -EINVAL; ret = -EINVAL;
} }
#ifdef CONFIG_INET } else if (IS_ENABLED(CONFIG_INET) && level == SOL_IP) {
} else if (level == SOL_IP) {
if (optlen != sizeof(int) || sk->sk_family != AF_INET) if (optlen != sizeof(int) || sk->sk_family != AF_INET)
return -EINVAL; return -EINVAL;
...@@ -5138,8 +5137,7 @@ static int __bpf_setsockopt(struct sock *sk, int level, int optname, ...@@ -5138,8 +5137,7 @@ static int __bpf_setsockopt(struct sock *sk, int level, int optname,
default: default:
ret = -EINVAL; ret = -EINVAL;
} }
#if IS_ENABLED(CONFIG_IPV6) } else if (IS_ENABLED(CONFIG_IPV6) && level == SOL_IPV6) {
} else if (level == SOL_IPV6) {
if (optlen != sizeof(int) || sk->sk_family != AF_INET6) if (optlen != sizeof(int) || sk->sk_family != AF_INET6)
return -EINVAL; return -EINVAL;
...@@ -5160,8 +5158,7 @@ static int __bpf_setsockopt(struct sock *sk, int level, int optname, ...@@ -5160,8 +5158,7 @@ static int __bpf_setsockopt(struct sock *sk, int level, int optname,
default: default:
ret = -EINVAL; ret = -EINVAL;
} }
#endif } else if (IS_ENABLED(CONFIG_INET) && level == SOL_TCP &&
} else if (level == SOL_TCP &&
sk->sk_prot->setsockopt == tcp_setsockopt) { sk->sk_prot->setsockopt == tcp_setsockopt) {
if (optname == TCP_CONGESTION) { if (optname == TCP_CONGESTION) {
char name[TCP_CA_NAME_MAX]; char name[TCP_CA_NAME_MAX];
...@@ -5253,7 +5250,6 @@ static int __bpf_setsockopt(struct sock *sk, int level, int optname, ...@@ -5253,7 +5250,6 @@ static int __bpf_setsockopt(struct sock *sk, int level, int optname,
ret = -EINVAL; ret = -EINVAL;
} }
} }
#endif
} else { } else {
ret = -EINVAL; ret = -EINVAL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment