diff options
-rw-r--r-- | igmp.c | 11 | ||||
-rw-r--r-- | uring.c | 20 | ||||
-rw-r--r-- | uring.h | 2 |
3 files changed, 31 insertions, 2 deletions
@@ -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; @@ -429,6 +429,26 @@ uring_openat(struct cfg *cfg, struct uring_task *task, const char *path, callbac } 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) { struct io_uring_sqe *sqe; @@ -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, |