diff --git a/daemon/kernel.c b/daemon/kernel.c index 8f257323f..a69723949 100644 --- a/daemon/kernel.c +++ b/daemon/kernel.c @@ -644,8 +644,8 @@ void kernel_cleanup_pollers(void) { } -__attribute__((nonnull(1, 2, 3))) -static ssize_t kernel_sendmsg(socket_t *s, const endpoint_t *dst, struct uring_req_sendmsg *req) +__attribute__((nonnull(1, 2))) +static ssize_t kernel_sendmsg(socket_t *s, struct uring_req_sendmsg *req) { size_t skblen = 0; for (size_t i = 0; i < req->mh.msg_iovlen; i++) @@ -719,7 +719,11 @@ static ssize_t kernel_sendmsg(socket_t *s, const endpoint_t *dst, struct uring_r slot->steps[0].offset = fill; slot->steps[0].length = skblen; - dst->address.family->endpoint2kernel(&metaslot->dst, dst); + // bit of a detour... + endpoint_t dst; + endpoint_parse_sockaddr_storage(&dst, &req->ss); + + dst.address.family->endpoint2kernel(&metaslot->dst, &dst); s->local.address.family->endpoint2kernel(&metaslot->src, &s->local); metaslot->tos = s->tos; diff --git a/daemon/media_player.c b/daemon/media_player.c index 457738767..eef732f7f 100644 --- a/daemon/media_player.c +++ b/daemon/media_player.c @@ -367,7 +367,7 @@ static bool __send_timer_send_1(struct rtp_header *rh, struct packet_stream *sin .msg_iovlen = 1, }; req->buf = bufferpool_ref(cp->s.s); - uring_methods.sendmsg(&sink_fd->socket, &sink->endpoint, &req->req); + uring_sendmsg(&sink_fd->socket, &sink->endpoint, &req->req); if (sink->call->recording && (rtpe_config.rec_egress || rtpe_config.rec_both)) { // fill in required members diff --git a/daemon/stun.c b/daemon/stun.c index df74c9690..1d474cdc1 100644 --- a/daemon/stun.c +++ b/daemon/stun.c @@ -707,7 +707,7 @@ int stun_binding_request(const endpoint_t *dst, uint32_t transaction[3], str *pw fingerprint(&r->req.mh, &r->fp); output_finish_src(&r->req.mh); - uring_methods.sendmsg(sock, dst, &r->req); + uring_sendmsg(sock, dst, &r->req); return 0; } diff --git a/lib/socket.c b/lib/socket.c index 61496055f..85aaa7754 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -202,7 +202,7 @@ static bool __ip6_sockaddr2endpoint(endpoint_t *ep, const void *p) { ep->port = ntohs(sin->sin6_port); return true; } -void endpoint_parse_sockaddr_storage(endpoint_t *ep, struct sockaddr_storage *sa) { +void endpoint_parse_sockaddr_storage(endpoint_t *ep, const struct sockaddr_storage *sa) { if (sa->ss_family == AF_INET) __ip4_sockaddr2endpoint(ep, sa); else if (sa->ss_family == AF_INET6) diff --git a/lib/socket.h b/lib/socket.h index c7f95c157..5f651948b 100644 --- a/lib/socket.h +++ b/lib/socket.h @@ -307,7 +307,7 @@ bool endpoint_parse_any(endpoint_t *, const char *); // address (ip) optional bool sockaddr_getaddrinfo_alt(sockaddr_t *a, sockaddr_t *a2, const char *s); bool endpoint_parse_any_getaddrinfo_alt(endpoint_t *d, endpoint_t *d2, const char *s); // address (ip or hostname) optional INLINE bool endpoint_parse_any_getaddrinfo(endpoint_t *d, const char *s); -void endpoint_parse_sockaddr_storage(endpoint_t *, struct sockaddr_storage *); +void endpoint_parse_sockaddr_storage(endpoint_t *, const struct sockaddr_storage *); void kernel2endpoint(endpoint_t *ep, const struct re_address *ra); unsigned int sockaddr_hash(const sockaddr_t *); diff --git a/lib/uring.c b/lib/uring.c index df94291a0..9d39b1022 100644 --- a/lib/uring.c +++ b/lib/uring.c @@ -45,13 +45,9 @@ struct poller_req { }; }; -__attribute__((nonnull(1, 2, 3))) -static ssize_t __socket_sendmsg(socket_t *s, const endpoint_t *e, struct uring_req_sendmsg *r) +__attribute__((nonnull(1, 2))) +static ssize_t __socket_sendmsg(socket_t *s, struct uring_req_sendmsg *r) { - s->family->endpoint2sockaddr(&r->ss, e); - r->mh.msg_name = &r->ss; - r->mh.msg_namelen = s->family->sockaddr_size; - ssize_t ret = socket_sendmsg_direct(s, &r->mh); uring_req_release(&r->req); return ret; @@ -93,14 +89,11 @@ struct uring_buffer_req { static __thread struct io_uring rtpe_uring; -__attribute__((nonnull(1, 2, 3))) -static ssize_t __uring_sendmsg(socket_t *s, const endpoint_t *e, struct uring_req_sendmsg *r) +__attribute__((nonnull(1, 2))) +static ssize_t __uring_sendmsg(socket_t *s, struct uring_req_sendmsg *r) { struct io_uring_sqe *sqe = io_uring_get_sqe(&rtpe_uring); assert(sqe != NULL); - s->family->endpoint2sockaddr(&r->ss, e); - r->mh.msg_name = &r->ss; - r->mh.msg_namelen = s->family->sockaddr_size; io_uring_sqe_set_data(sqe, r); io_uring_prep_sendmsg(sqe, s->fd, &r->mh, 0); diff --git a/lib/uring.h b/lib/uring.h index 4708340be..b3435c0f8 100644 --- a/lib/uring.h +++ b/lib/uring.h @@ -20,8 +20,8 @@ struct uring_req_sendmsg { }; struct uring_methods { - ssize_t (*sendmsg)(socket_t *, const endpoint_t *, struct uring_req_sendmsg *) - __attribute__((nonnull(1, 2, 3))); + ssize_t (*sendmsg)(socket_t *, struct uring_req_sendmsg *) + __attribute__((nonnull(1, 2))); unsigned int (*thread_loop)(void); void (*free)(struct uring_req *); @@ -38,6 +38,21 @@ INLINE void uring_req_release(struct uring_req *r) { r->handler(r, 0, 0); } +__attribute__((nonnull(1, 2, 3))) +INLINE void uring_sendmsg_prepare(socket_t *s, const endpoint_t *e, struct uring_req_sendmsg *r) { + s->family->endpoint2sockaddr(&r->ss, e); + r->mh.msg_name = &r->ss; + r->mh.msg_namelen = s->family->sockaddr_size; +} + +__attribute__((nonnull(1, 2, 3))) +INLINE ssize_t uring_sendmsg(socket_t *s, const endpoint_t *e, struct uring_req_sendmsg *r) { + uring_sendmsg_prepare(s, e, r); + + return uring_methods.sendmsg(s, r); +} + + #define uring_alloc_sendmsg(sv, fn) ({ \ __typeof__(sv) __ret = uring_methods.__alloc_req((sv), sizeof(*(sv))); \ memset(sv, 0, sizeof(*(sv))); \