aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2017-09-08 19:40:35 -0400
committerDavid S. Miller <davem@davemloft.net>2017-09-09 00:13:09 -0400
commit9beb8bedb05c5f3a353dba62b8fa7cbbb9ec685e (patch)
treea1b746996795ad8ca61eca7380b3bd43e6d750af
parenta010a2f6540ecc39f8701c6f7d35e22992c03fb6 (diff)
bpf: make error reporting in bpf_warn_invalid_xdp_action more clear
Differ between illegal XDP action code and just driver unsupported one to provide better feedback when we throw a one-time warning here. Reason is that with 814abfabef3c ("xdp: add bpf_redirect helper function") not all drivers support the new XDP return code yet and thus they will fall into their 'default' case when checking for return codes after program return, which then triggers a bpf_warn_invalid_xdp_action() stating that the return code is illegal, but from XDP perspective it's not. I decided not to place something like a XDP_ACT_MAX define into uapi i) given we don't have this either for all other program types, ii) future action codes could have further encoding there, which would render such define unsuitable and we wouldn't be able to rip it out again, and iii) we rarely add new action codes. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/uapi/linux/bpf.h4
-rw-r--r--net/core/filter.c6
2 files changed, 7 insertions, 3 deletions
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index ba848b761cfb..43ab5c402f98 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -766,8 +766,8 @@ struct bpf_sock {
766 766
767/* User return codes for XDP prog type. 767/* User return codes for XDP prog type.
768 * A valid XDP program must return one of these defined values. All other 768 * A valid XDP program must return one of these defined values. All other
769 * return codes are reserved for future use. Unknown return codes will result 769 * return codes are reserved for future use. Unknown return codes will
770 * in packet drop. 770 * result in packet drops and a warning via bpf_warn_invalid_xdp_action().
771 */ 771 */
772enum xdp_action { 772enum xdp_action {
773 XDP_ABORTED = 0, 773 XDP_ABORTED = 0,
diff --git a/net/core/filter.c b/net/core/filter.c
index 0848df2cd9bf..3a50a9b021e2 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -3609,7 +3609,11 @@ static bool xdp_is_valid_access(int off, int size,
3609 3609
3610void bpf_warn_invalid_xdp_action(u32 act) 3610void bpf_warn_invalid_xdp_action(u32 act)
3611{ 3611{
3612 WARN_ONCE(1, "Illegal XDP return value %u, expect packet loss\n", act); 3612 const u32 act_max = XDP_REDIRECT;
3613
3614 WARN_ONCE(1, "%s XDP return value %u, expect packet loss!\n",
3615 act > act_max ? "Illegal" : "Driver unsupported",
3616 act);
3613} 3617}
3614EXPORT_SYMBOL_GPL(bpf_warn_invalid_xdp_action); 3618EXPORT_SYMBOL_GPL(bpf_warn_invalid_xdp_action);
3615 3619