summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--igmp.c11
-rw-r--r--uring.c20
-rw-r--r--uring.h2
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
@@ -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;
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,