From 1ec5e43c9aef58e134f570946e280956db4ef189 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Tue, 16 Jun 2020 10:36:09 +0200 Subject: Implement and use recvmsg in igmp --- igmp.c | 11 +++++++++-- uring.c | 20 ++++++++++++++++++++ uring.h | 2 ++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/igmp.c b/igmp.c index 3cabe44..b3d7d2c 100644 --- a/igmp.c +++ b/igmp.c @@ -395,7 +395,13 @@ igmp_read_cb(struct cfg *cfg, struct uring_task *task, int res) if (res < 0 || task->dead) return; - igmp_parse(cfg, igmp, res); + task->tbuf->len = res; + + if (task->addr.storage.ss_family == AF_PACKET || + task->addr.ll.sll_protocol == htons(ETH_P_IP)) + igmp_parse(cfg, igmp, res); + else + fprintf(stderr, "Invalid packet type received\n"); uring_tbuf_read(cfg, &igmp->task, igmp_read_cb); } @@ -550,7 +556,8 @@ igmp_init(struct cfg *cfg) uring_task_init(&igmp->task, "igmp", uring_parent(cfg), igmp_free); uring_task_set_fd(&igmp->task, sfd); uring_task_set_buf(&igmp->task, &igmp->tbuf); - uring_tbuf_read(cfg, &igmp->task, igmp_read_cb); + igmp->task.addr.addrlen = sizeof(igmp->task.addr.ll); + uring_tbuf_recvmsg(cfg, &igmp->task, igmp_read_cb); cfg->igmp = igmp; diff --git a/uring.c b/uring.c index 6c16849..188b101 100644 --- a/uring.c +++ b/uring.c @@ -428,6 +428,26 @@ uring_openat(struct cfg *cfg, struct uring_task *task, const char *path, callbac io_uring_sqe_set_data(sqe, task); } +void +uring_tbuf_recvmsg(struct cfg *cfg, struct uring_task *task, callback_t callback) +{ + struct io_uring_sqe *sqe; + + if (!task->tbuf) { + error("%s: called with no tbuf set\n", __func__); + return; + } + + sqe = get_sqe(cfg, task); + task->tbuf->done = 0; + task->tbuf->len = 0; + task->tbuf->iov.iov_len = sizeof(task->tbuf->buf); + task->tbuf->msg.msg_namelen = task->addr.addrlen; + task->callback = callback; + io_uring_prep_recvmsg(sqe, task->fd, &task->tbuf->msg, 0); + io_uring_sqe_set_data(sqe, task); +} + void uring_tbuf_sendmsg(struct cfg *cfg, struct uring_task *task, callback_t callback) { diff --git a/uring.h b/uring.h index b4160d8..1a4352c 100644 --- a/uring.h +++ b/uring.h @@ -51,6 +51,8 @@ uring_read(struct cfg *cfg, struct uring_task *task, void *buf, size_t len, call void uring_openat(struct cfg *cfg, struct uring_task *task, const char *path, callback_t callback); +void uring_tbuf_recvmsg(struct cfg *cfg, struct uring_task *task, callback_t callback); + void uring_tbuf_sendmsg(struct cfg *cfg, struct uring_task *task, callback_t callback); void uring_connect(struct cfg *cfg, struct uring_task *task, -- cgit v1.2.3