From: Prashant Bhole <prashantbhole.linux@xxxxxxxxx> In order to extend the usage of tun_msg_ctl structure, this patch changes the member name from type to cmd. Also following definitions are changed: TUN_MSG_PTR : TUN_CMD_BATCH TUN_MSG_UBUF: TUN_CMD_PACKET Signed-off-by: Prashant Bhole <prashantbhole.linux@xxxxxxxxx> --- drivers/net/tap.c | 9 ++++++--- drivers/net/tun.c | 8 ++++++-- drivers/vhost/net.c | 4 ++-- include/linux/if_tun.h | 6 +++--- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/drivers/net/tap.c b/drivers/net/tap.c index 3ae70c7e6860..01bd260ce60c 100644 --- a/drivers/net/tap.c +++ b/drivers/net/tap.c @@ -1213,9 +1213,10 @@ static int tap_sendmsg(struct socket *sock, struct msghdr *m, struct tap_queue *q = container_of(sock, struct tap_queue, sock); struct tun_msg_ctl *ctl = m->msg_control; struct xdp_buff *xdp; + void *ptr = NULL; int i; - if (ctl && (ctl->type == TUN_MSG_PTR)) { + if (ctl && ctl->cmd == TUN_CMD_BATCH) { for (i = 0; i < ctl->num; i++) { xdp = &((struct xdp_buff *)ctl->ptr)[i]; tap_get_user_xdp(q, xdp); @@ -1223,8 +1224,10 @@ static int tap_sendmsg(struct socket *sock, struct msghdr *m, return 0; } - return tap_get_user(q, ctl ? ctl->ptr : NULL, &m->msg_iter, - m->msg_flags & MSG_DONTWAIT); + if (ctl && ctl->cmd == TUN_CMD_PACKET) + ptr = ctl->ptr; + + return tap_get_user(q, ptr, &m->msg_iter, m->msg_flags & MSG_DONTWAIT); } static int tap_recvmsg(struct socket *sock, struct msghdr *m, diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 0413d182d782..29711671959b 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -2529,11 +2529,12 @@ static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len) struct tun_struct *tun = tun_get(tfile); struct tun_msg_ctl *ctl = m->msg_control; struct xdp_buff *xdp; + void *ptr = NULL; if (!tun) return -EBADFD; - if (ctl && (ctl->type == TUN_MSG_PTR)) { + if (ctl && ctl->cmd == TUN_CMD_BATCH) { struct tun_page tpage; int n = ctl->num; int flush = 0; @@ -2560,7 +2561,10 @@ static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len) goto out; } - ret = tun_get_user(tun, tfile, ctl ? ctl->ptr : NULL, &m->msg_iter, + if (ctl && ctl->cmd == TUN_CMD_PACKET) + ptr = ctl->ptr; + + ret = tun_get_user(tun, tfile, ptr, &m->msg_iter, m->msg_flags & MSG_DONTWAIT, m->msg_flags & MSG_MORE); out: diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 1a2dd53caade..5946d2775bd0 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -462,7 +462,7 @@ static void vhost_tx_batch(struct vhost_net *net, struct msghdr *msghdr) { struct tun_msg_ctl ctl = { - .type = TUN_MSG_PTR, + .cmd = TUN_CMD_BATCH, .num = nvq->batched_xdp, .ptr = nvq->xdp, }; @@ -902,7 +902,7 @@ static void handle_tx_zerocopy(struct vhost_net *net, struct socket *sock) ubuf->desc = nvq->upend_idx; refcount_set(&ubuf->refcnt, 1); msg.msg_control = &ctl; - ctl.type = TUN_MSG_UBUF; + ctl.cmd = TUN_CMD_PACKET; ctl.ptr = ubuf; msg.msg_controllen = sizeof(ctl); ubufs = nvq->ubufs; diff --git a/include/linux/if_tun.h b/include/linux/if_tun.h index 5bda8cf457b6..bdfa671612db 100644 --- a/include/linux/if_tun.h +++ b/include/linux/if_tun.h @@ -11,10 +11,10 @@ #define TUN_XDP_FLAG 0x1UL -#define TUN_MSG_UBUF 1 -#define TUN_MSG_PTR 2 +#define TUN_CMD_PACKET 1 +#define TUN_CMD_BATCH 2 struct tun_msg_ctl { - unsigned short type; + unsigned short cmd; unsigned short num; void *ptr; }; -- 2.21.0