Commit b558b6c2 authored by Maciej Żenczykowski's avatar Maciej Żenczykowski Committed by Alexei Starovoitov

net-tun: Add type safety to tun_xdp_to_ptr() and tun_ptr_to_xdp()

This reduces likelihood of incorrect use.

Test: builds
Signed-off-by: default avatarMaciej Żenczykowski <maze@google.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200819010710.3959310-1-zenczykowski@gmail.com
parent 37081156
...@@ -225,13 +225,13 @@ bool tun_is_xdp_frame(void *ptr) ...@@ -225,13 +225,13 @@ bool tun_is_xdp_frame(void *ptr)
} }
EXPORT_SYMBOL(tun_is_xdp_frame); EXPORT_SYMBOL(tun_is_xdp_frame);
void *tun_xdp_to_ptr(void *ptr) void *tun_xdp_to_ptr(struct xdp_frame *xdp)
{ {
return (void *)((unsigned long)ptr | TUN_XDP_FLAG); return (void *)((unsigned long)xdp | TUN_XDP_FLAG);
} }
EXPORT_SYMBOL(tun_xdp_to_ptr); EXPORT_SYMBOL(tun_xdp_to_ptr);
void *tun_ptr_to_xdp(void *ptr) struct xdp_frame *tun_ptr_to_xdp(void *ptr)
{ {
return (void *)((unsigned long)ptr & ~TUN_XDP_FLAG); return (void *)((unsigned long)ptr & ~TUN_XDP_FLAG);
} }
......
...@@ -28,8 +28,8 @@ struct tun_xdp_hdr { ...@@ -28,8 +28,8 @@ struct tun_xdp_hdr {
struct socket *tun_get_socket(struct file *); struct socket *tun_get_socket(struct file *);
struct ptr_ring *tun_get_tx_ring(struct file *file); struct ptr_ring *tun_get_tx_ring(struct file *file);
bool tun_is_xdp_frame(void *ptr); bool tun_is_xdp_frame(void *ptr);
void *tun_xdp_to_ptr(void *ptr); void *tun_xdp_to_ptr(struct xdp_frame *xdp);
void *tun_ptr_to_xdp(void *ptr); struct xdp_frame *tun_ptr_to_xdp(void *ptr);
void tun_ptr_free(void *ptr); void tun_ptr_free(void *ptr);
#else #else
#include <linux/err.h> #include <linux/err.h>
...@@ -48,11 +48,11 @@ static inline bool tun_is_xdp_frame(void *ptr) ...@@ -48,11 +48,11 @@ static inline bool tun_is_xdp_frame(void *ptr)
{ {
return false; return false;
} }
static inline void *tun_xdp_to_ptr(void *ptr) static inline void *tun_xdp_to_ptr(struct xdp_frame *xdp)
{ {
return NULL; return NULL;
} }
static inline void *tun_ptr_to_xdp(void *ptr) static inline struct xdp_frame *tun_ptr_to_xdp(void *ptr)
{ {
return NULL; return NULL;
} }
......
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