* [FFmpeg-devel] [PATCH 2/4] lavf/udp: log net errors to proper contexts rather than NULL
2022-01-10 16:51 [FFmpeg-devel] [PATCH 1/4] lavf/udp: do not return an uninitialized value from udp_open() Anton Khirnov
@ 2022-01-10 16:51 ` Anton Khirnov
2022-01-10 16:51 ` [FFmpeg-devel] [PATCH 3/4] lavf/network: log ff_socket() " Anton Khirnov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Anton Khirnov @ 2022-01-10 16:51 UTC (permalink / raw)
To: ffmpeg-devel
---
libavformat/udp.c | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/libavformat/udp.c b/libavformat/udp.c
index 180d96a988..d1195ceca9 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -159,12 +159,13 @@ static const AVClass udplite_context_class = {
};
static int udp_set_multicast_ttl(int sockfd, int mcastTTL,
- struct sockaddr *addr)
+ struct sockaddr *addr,
+ void *logctx)
{
#ifdef IP_MULTICAST_TTL
if (addr->sa_family == AF_INET) {
if (setsockopt(sockfd, IPPROTO_IP, IP_MULTICAST_TTL, &mcastTTL, sizeof(mcastTTL)) < 0) {
- ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_TTL)");
+ ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IP_MULTICAST_TTL)");
return ff_neterrno();
}
}
@@ -172,7 +173,7 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL,
#if defined(IPPROTO_IPV6) && defined(IPV6_MULTICAST_HOPS)
if (addr->sa_family == AF_INET6) {
if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastTTL, sizeof(mcastTTL)) < 0) {
- ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS)");
+ ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IPV6_MULTICAST_HOPS)");
return ff_neterrno();
}
}
@@ -180,7 +181,8 @@ static int udp_set_multicast_ttl(int sockfd, int mcastTTL,
return 0;
}
-static int udp_join_multicast_group(int sockfd, struct sockaddr *addr,struct sockaddr *local_addr)
+static int udp_join_multicast_group(int sockfd, struct sockaddr *addr,
+ struct sockaddr *local_addr, void *logctx)
{
#ifdef IP_ADD_MEMBERSHIP
if (addr->sa_family == AF_INET) {
@@ -192,7 +194,7 @@ static int udp_join_multicast_group(int sockfd, struct sockaddr *addr,struct soc
else
mreq.imr_interface.s_addr = INADDR_ANY;
if (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) {
- ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IP_ADD_MEMBERSHIP)");
+ ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IP_ADD_MEMBERSHIP)");
return ff_neterrno();
}
}
@@ -205,7 +207,7 @@ static int udp_join_multicast_group(int sockfd, struct sockaddr *addr,struct soc
//TODO: Interface index should be looked up from local_addr
mreq6.ipv6mr_interface = 0;
if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
- ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IPV6_ADD_MEMBERSHIP)");
+ ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IPV6_ADD_MEMBERSHIP)");
return ff_neterrno();
}
}
@@ -213,7 +215,8 @@ static int udp_join_multicast_group(int sockfd, struct sockaddr *addr,struct soc
return 0;
}
-static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr,struct sockaddr *local_addr)
+static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr,
+ struct sockaddr *local_addr, void *logctx)
{
#ifdef IP_DROP_MEMBERSHIP
if (addr->sa_family == AF_INET) {
@@ -225,7 +228,7 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr,struct so
else
mreq.imr_interface.s_addr = INADDR_ANY;
if (setsockopt(sockfd, IPPROTO_IP, IP_DROP_MEMBERSHIP, (const void *)&mreq, sizeof(mreq)) < 0) {
- ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IP_DROP_MEMBERSHIP)");
+ ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IP_DROP_MEMBERSHIP)");
return -1;
}
}
@@ -238,7 +241,7 @@ static int udp_leave_multicast_group(int sockfd, struct sockaddr *addr,struct so
//TODO: Interface index should be looked up from local_addr
mreq6.ipv6mr_interface = 0;
if (setsockopt(sockfd, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, &mreq6, sizeof(mreq6)) < 0) {
- ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(IPV6_DROP_MEMBERSHIP)");
+ ff_log_net_error(logctx, AV_LOG_ERROR, "setsockopt(IPV6_DROP_MEMBERSHIP)");
return -1;
}
}
@@ -272,9 +275,9 @@ static int udp_set_multicast_sources(URLContext *h,
include ? MCAST_JOIN_SOURCE_GROUP : MCAST_BLOCK_SOURCE,
(const void *)&mreqs, sizeof(mreqs)) < 0) {
if (include)
- ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(MCAST_JOIN_SOURCE_GROUP)");
+ ff_log_net_error(h, AV_LOG_ERROR, "setsockopt(MCAST_JOIN_SOURCE_GROUP)");
else
- ff_log_net_error(NULL, AV_LOG_ERROR, "setsockopt(MCAST_BLOCK_SOURCE)");
+ ff_log_net_error(h, AV_LOG_ERROR, "setsockopt(MCAST_BLOCK_SOURCE)");
return ff_neterrno();
}
}
@@ -352,7 +355,7 @@ static int udp_socket_create(URLContext *h, struct sockaddr_storage *addr,
else
udp_fd = ff_socket(res->ai_family, SOCK_DGRAM, 0);
if (udp_fd != -1) break;
- ff_log_net_error(NULL, AV_LOG_ERROR, "socket");
+ ff_log_net_error(h, AV_LOG_ERROR, "socket");
}
if (udp_fd < 0)
@@ -825,7 +828,7 @@ static int udp_open(URLContext *h, const char *uri, int flags)
if (s->is_multicast) {
if (h->flags & AVIO_FLAG_WRITE) {
/* output */
- if ((ret = udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr)) < 0)
+ if ((ret = udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr, h)) < 0)
goto fail;
}
if (h->flags & AVIO_FLAG_READ) {
@@ -838,7 +841,8 @@ static int udp_open(URLContext *h, const char *uri, int flags)
s->filters.nb_include_addrs, 1)) < 0)
goto fail;
} else {
- if ((ret = udp_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr,(struct sockaddr *)&s->local_addr_storage)) < 0)
+ if ((ret = udp_join_multicast_group(udp_fd, (struct sockaddr *)&s->dest_addr,
+ (struct sockaddr *)&s->local_addr_storage, h)) < 0)
goto fail;
}
if (s->filters.nb_exclude_addrs) {
@@ -1083,7 +1087,8 @@ static int udp_close(URLContext *h)
#endif
if (s->is_multicast && (h->flags & AVIO_FLAG_READ))
- udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr,(struct sockaddr *)&s->local_addr_storage);
+ udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr,
+ (struct sockaddr *)&s->local_addr_storage, h);
#if HAVE_PTHREAD_CANCEL
if (s->thread_started) {
int ret;
--
2.33.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread
* [FFmpeg-devel] [PATCH 3/4] lavf/network: log ff_socket() errors to proper contexts rather than NULL
2022-01-10 16:51 [FFmpeg-devel] [PATCH 1/4] lavf/udp: do not return an uninitialized value from udp_open() Anton Khirnov
2022-01-10 16:51 ` [FFmpeg-devel] [PATCH 2/4] lavf/udp: log net errors to proper contexts rather than NULL Anton Khirnov
@ 2022-01-10 16:51 ` Anton Khirnov
2022-01-10 16:51 ` [FFmpeg-devel] [PATCH 4/4] lavf/network: log ff_listen() " Anton Khirnov
2022-01-10 17:51 ` [FFmpeg-devel] [PATCH 1/4] lavf/udp: do not return an uninitialized value from udp_open() James Almer
3 siblings, 0 replies; 5+ messages in thread
From: Anton Khirnov @ 2022-01-10 16:51 UTC (permalink / raw)
To: ffmpeg-devel
---
libavformat/network.c | 8 ++++----
libavformat/network.h | 2 +-
libavformat/sctp.c | 2 +-
libavformat/tcp.c | 2 +-
libavformat/udp.c | 4 ++--
libavformat/unix.c | 2 +-
6 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/libavformat/network.c b/libavformat/network.c
index 0f5a575f77..c3d9f82551 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -180,7 +180,7 @@ static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout,
return ret;
}
-int ff_socket(int af, int type, int proto)
+int ff_socket(int af, int type, int proto, void *logctx)
{
int fd;
@@ -193,14 +193,14 @@ int ff_socket(int af, int type, int proto)
#if HAVE_FCNTL
if (fd != -1) {
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
- av_log(NULL, AV_LOG_DEBUG, "Failed to set close on exec\n");
+ av_log(logctx, AV_LOG_DEBUG, "Failed to set close on exec\n");
}
#endif
}
#ifdef SO_NOSIGPIPE
if (fd != -1) {
if (setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &(int){1}, sizeof(int))) {
- av_log(NULL, AV_LOG_WARNING, "setsockopt(SO_NOSIGPIPE) failed\n");
+ av_log(logctx, AV_LOG_WARNING, "setsockopt(SO_NOSIGPIPE) failed\n");
}
}
#endif
@@ -363,7 +363,7 @@ static int start_connect_attempt(struct ConnectionAttempt *attempt,
*ptr = ai->ai_next;
- attempt->fd = ff_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+ attempt->fd = ff_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol, h);
if (attempt->fd < 0)
return ff_neterrno();
attempt->deadline_us = av_gettime_relative() + timeout_ms * 1000;
diff --git a/libavformat/network.h b/libavformat/network.h
index 71347e815b..d76166faf6 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -305,7 +305,7 @@ int ff_listen_connect(int fd, const struct sockaddr *addr,
int ff_http_match_no_proxy(const char *no_proxy, const char *hostname);
-int ff_socket(int domain, int type, int protocol);
+int ff_socket(int domain, int type, int protocol, void *logctx);
void ff_log_net_error(void *ctx, int level, const char* prefix);
diff --git a/libavformat/sctp.c b/libavformat/sctp.c
index 9a80e9b015..b8e23653d2 100644
--- a/libavformat/sctp.c
+++ b/libavformat/sctp.c
@@ -220,7 +220,7 @@ static int sctp_open(URLContext *h, const char *uri, int flags)
cur_ai = ai;
restart:
- fd = ff_socket(cur_ai->ai_family, SOCK_STREAM, IPPROTO_SCTP);
+ fd = ff_socket(cur_ai->ai_family, SOCK_STREAM, IPPROTO_SCTP, h);
if (fd < 0) {
ret = ff_neterrno();
goto fail;
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 1c19aed887..84d40a1e11 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -175,7 +175,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
while (cur_ai && fd < 0) {
fd = ff_socket(cur_ai->ai_family,
cur_ai->ai_socktype,
- cur_ai->ai_protocol);
+ cur_ai->ai_protocol, h);
if (fd < 0) {
ret = ff_neterrno();
cur_ai = cur_ai->ai_next;
diff --git a/libavformat/udp.c b/libavformat/udp.c
index d1195ceca9..83c042d079 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -351,9 +351,9 @@ static int udp_socket_create(URLContext *h, struct sockaddr_storage *addr,
goto fail;
for (res = res0; res; res=res->ai_next) {
if (s->udplite_coverage)
- udp_fd = ff_socket(res->ai_family, SOCK_DGRAM, IPPROTO_UDPLITE);
+ udp_fd = ff_socket(res->ai_family, SOCK_DGRAM, IPPROTO_UDPLITE, h);
else
- udp_fd = ff_socket(res->ai_family, SOCK_DGRAM, 0);
+ udp_fd = ff_socket(res->ai_family, SOCK_DGRAM, 0, h);
if (udp_fd != -1) break;
ff_log_net_error(h, AV_LOG_ERROR, "socket");
}
diff --git a/libavformat/unix.c b/libavformat/unix.c
index 38016dbafe..e668744580 100644
--- a/libavformat/unix.c
+++ b/libavformat/unix.c
@@ -69,7 +69,7 @@ static int unix_open(URLContext *h, const char *filename, int flags)
s->addr.sun_family = AF_UNIX;
av_strlcpy(s->addr.sun_path, filename, sizeof(s->addr.sun_path));
- if ((fd = ff_socket(AF_UNIX, s->type, 0)) < 0)
+ if ((fd = ff_socket(AF_UNIX, s->type, 0, h)) < 0)
return ff_neterrno();
if (s->timeout < 0 && h->rw_timeout)
--
2.33.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread
* [FFmpeg-devel] [PATCH 4/4] lavf/network: log ff_listen() errors to proper contexts rather than NULL
2022-01-10 16:51 [FFmpeg-devel] [PATCH 1/4] lavf/udp: do not return an uninitialized value from udp_open() Anton Khirnov
2022-01-10 16:51 ` [FFmpeg-devel] [PATCH 2/4] lavf/udp: log net errors to proper contexts rather than NULL Anton Khirnov
2022-01-10 16:51 ` [FFmpeg-devel] [PATCH 3/4] lavf/network: log ff_socket() " Anton Khirnov
@ 2022-01-10 16:51 ` Anton Khirnov
2022-01-10 17:51 ` [FFmpeg-devel] [PATCH 1/4] lavf/udp: do not return an uninitialized value from udp_open() James Almer
3 siblings, 0 replies; 5+ messages in thread
From: Anton Khirnov @ 2022-01-10 16:51 UTC (permalink / raw)
To: ffmpeg-devel
---
libavformat/network.c | 6 +++---
libavformat/network.h | 3 ++-
libavformat/tcp.c | 2 +-
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/libavformat/network.c b/libavformat/network.c
index c3d9f82551..246ffd406d 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -208,12 +208,12 @@ int ff_socket(int af, int type, int proto, void *logctx)
}
int ff_listen(int fd, const struct sockaddr *addr,
- socklen_t addrlen)
+ socklen_t addrlen, void *logctx)
{
int ret;
int reuse = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse))) {
- av_log(NULL, AV_LOG_WARNING, "setsockopt(SO_REUSEADDR) failed\n");
+ av_log(logctx, AV_LOG_WARNING, "setsockopt(SO_REUSEADDR) failed\n");
}
ret = bind(fd, addr, addrlen);
if (ret)
@@ -247,7 +247,7 @@ int ff_listen_bind(int fd, const struct sockaddr *addr,
socklen_t addrlen, int timeout, URLContext *h)
{
int ret;
- if ((ret = ff_listen(fd, addr, addrlen)) < 0)
+ if ((ret = ff_listen(fd, addr, addrlen, h)) < 0)
return ret;
if ((ret = ff_accept(fd, timeout, h)) < 0)
return ret;
diff --git a/libavformat/network.h b/libavformat/network.h
index d76166faf6..71c49a73fb 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -271,7 +271,8 @@ int ff_listen_bind(int fd, const struct sockaddr *addr,
* @param addrlen Third argument of bind().
* @return 0 on success or an AVERROR on failure.
*/
-int ff_listen(int fd, const struct sockaddr *addr, socklen_t addrlen);
+int ff_listen(int fd, const struct sockaddr *addr, socklen_t addrlen,
+ void *logctx);
/**
* Poll for a single connection on the passed file descriptor.
diff --git a/libavformat/tcp.c b/libavformat/tcp.c
index 84d40a1e11..a11ccbb913 100644
--- a/libavformat/tcp.c
+++ b/libavformat/tcp.c
@@ -188,7 +188,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags)
if (s->listen == 2) {
// multi-client
- if ((ret = ff_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen)) < 0)
+ if ((ret = ff_listen(fd, cur_ai->ai_addr, cur_ai->ai_addrlen, h)) < 0)
goto fail1;
} else if (s->listen == 1) {
// single client
--
2.33.0
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [FFmpeg-devel] [PATCH 1/4] lavf/udp: do not return an uninitialized value from udp_open()
2022-01-10 16:51 [FFmpeg-devel] [PATCH 1/4] lavf/udp: do not return an uninitialized value from udp_open() Anton Khirnov
` (2 preceding siblings ...)
2022-01-10 16:51 ` [FFmpeg-devel] [PATCH 4/4] lavf/network: log ff_listen() " Anton Khirnov
@ 2022-01-10 17:51 ` James Almer
3 siblings, 0 replies; 5+ messages in thread
From: James Almer @ 2022-01-10 17:51 UTC (permalink / raw)
To: ffmpeg-devel
On 1/10/2022 1:51 PM, Anton Khirnov wrote:
> ---
> libavformat/udp.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/udp.c b/libavformat/udp.c
> index b8b0e19609..180d96a988 100644
> --- a/libavformat/udp.c
> +++ b/libavformat/udp.c
> @@ -739,8 +739,10 @@ static int udp_open(URLContext *h, const char *uri, int flags)
> /* XXX: fix av_url_split */
> if (hostname[0] == '\0' || hostname[0] == '?') {
> /* only accepts null hostname if input */
> - if (!(flags & AVIO_FLAG_READ))
> + if (!(flags & AVIO_FLAG_READ)) {
> + ret = AVERROR(EINVAL);
> goto fail;
> + }
> } else {
> if ((ret = ff_udp_set_remote_url(h, uri)) < 0)
> goto fail;
> @@ -750,8 +752,10 @@ static int udp_open(URLContext *h, const char *uri, int flags)
> s->local_port = port;
>
> udp_fd = udp_socket_create(h, &my_addr, &len, s->localaddr);
> - if (udp_fd < 0)
> + if (udp_fd < 0) {
> + ret = AVERROR(EIO);
> goto fail;
> + }
>
> s->local_addr_storage=my_addr; //store for future multicast join
LGTM.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 5+ messages in thread