From patchwork Sat Sep 22 21:53:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 10453 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:1286:0:0:0:0:0 with SMTP id 6-v6csp932094jap; Sat, 22 Sep 2018 14:54:11 -0700 (PDT) X-Google-Smtp-Source: ACcGV62rJPNOlb9c4mha6DTgrlgBCUd0/sMxgsPeFvxCx8pu+t0KCCTfY9vKk95DdCJqdlD5GJya X-Received: by 2002:adf:d149:: with SMTP id b9-v6mr3180416wri.17.1537653251352; Sat, 22 Sep 2018 14:54:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537653251; cv=none; d=google.com; s=arc-20160816; b=CSTz9eWqpMyQi7kXgKzbgHjqcpyaAM/JDk/8a7vmypWbKPE0yX4Miu8/zCbibiakYm 4pE3T1CLTj2+xG2mkYVw2LfeYu73kWYLvN//mkL2ha42VNRwdEuHobnJo+sgpdyZceGB LR7j9/qVYzRi8M5zp2PNcRuUInfTgP5GB6NxQh/WuGrb2372yx7dYSU/HnPh94C4mnEm fpj022WUO+ElnDhLnOEVRzjNuU/j3CGZkHCTJxN8s0vg1LZoGGvKge0+16Vb6p02F28y S0nT3QOh7LheEwOoHywpBLEw8OvXZYyBGAEhsifprdwyPWofB6zSpUQQfV2eDBdYkA3s QLqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=nY2L59PGxdg4uPPBvNTK5SZKmfD/ow9tVj7UWjN6c4o=; b=RDaJu1AImiWcBEg1kYAL4+2qvGsaV0uSwxxeYIO/8T/209Nm+TamvcSir7XxGfK+Bk rdU3B6Jt/Ntpd2E8GDLEMkgm/HxYVmAoVJPEgj+rOFCL7SwR1J3n+GAoM03qGEdcVg/d W0GNswEkA+HmUVQyfqXNROdgDWE5kPeuWaeleorxfszehQ77hyOZbluTmDXHPep9xaMS LnHPm/c1XKqH/ACl2lBJHhyt7kXyngoldX3T3v4OfHOXUCOQLdRMKXFkwjIKiDjVdJ7V fxfE7Blwn3umNf4DaTxO1anW6EoH6DHLSVDGbxQsL9A1O4zI2/9+zH8HmJ3ztIJ/o1IQ 3few== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s132-v6si2922610wmd.60.2018.09.22.14.54.10; Sat, 22 Sep 2018 14:54:11 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D4E0F68A6D4; Sun, 23 Sep 2018 00:53:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4D06268A617 for ; Sun, 23 Sep 2018 00:53:23 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 40793E11BA; Sat, 22 Sep 2018 23:53:38 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8J9BRk8TKM2p; Sat, 22 Sep 2018 23:53:37 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 69738E04A9; Sat, 22 Sep 2018 23:53:37 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 22 Sep 2018 23:53:25 +0200 Message-Id: <20180922215328.18053-4-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180922215328.18053-1-cus@passwd.hu> References: <20180922215328.18053-1-cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 4/7] avformat/udp: add support for generic source filtering X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This allows getting data only from a specific source IP. This is useful not only for unicast but for multicast as well because multicast source subscriptions do not act as source filters for the incoming packets. Signed-off-by: Marton Balint --- doc/protocols.texi | 8 ++++---- libavformat/udp.c | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/doc/protocols.texi b/doc/protocols.texi index fad6c44c24..7173bb173a 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -1569,12 +1569,12 @@ For receiving, this gives the benefit of only receiving packets from the specified peer address/port. @item sources=@var{address}[,@var{address}] -Only receive packets sent to the multicast group from one of the -specified sender IP addresses. +Only receive packets sent from the specified addresses. In case of multicast, +also subscribe to multicast traffic coming from these addresses only. @item block=@var{address}[,@var{address}] -Ignore packets sent to the multicast group from the specified -sender IP addresses. +Ignore packets sent from the specified addresses. In case of multicast, also +exclude the source addresses in the multicast subscription. @item fifo_size=@var{units} Set the UDP receiving circular buffer size, expressed as a number of diff --git a/libavformat/udp.c b/libavformat/udp.c index 427128c431..5944c10a40 100644 --- a/libavformat/udp.c +++ b/libavformat/udp.c @@ -458,13 +458,15 @@ static void *circular_buffer_task_rx( void *_URLContext) } while(1) { int len; + struct sockaddr_storage addr; + socklen_t addr_len; pthread_mutex_unlock(&s->mutex); /* Blocking operations are always cancellation points; see "General Information" / "Thread Cancelation Overview" in Single Unix. */ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old_cancelstate); - len = recv(s->udp_fd, s->tmp+4, sizeof(s->tmp)-4, 0); + len = recvfrom(s->udp_fd, s->tmp+4, sizeof(s->tmp)-4, 0, (struct sockaddr *)&addr, &addr_len); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old_cancelstate); pthread_mutex_lock(&s->mutex); if (len < 0) { @@ -474,6 +476,8 @@ static void *circular_buffer_task_rx( void *_URLContext) } continue; } + if (ff_ip_check_source_lists(&addr, &s->filters)) + continue; AV_WL32(s->tmp, len); if(av_fifo_space(s->fifo) < len + 4) { @@ -926,6 +930,8 @@ static int udp_read(URLContext *h, uint8_t *buf, int size) { UDPContext *s = h->priv_data; int ret; + struct sockaddr_storage addr; + socklen_t addr_len; #if HAVE_PTHREAD_CANCEL int avail, nonblock = h->flags & AVIO_FLAG_NONBLOCK; @@ -976,9 +982,12 @@ static int udp_read(URLContext *h, uint8_t *buf, int size) if (ret < 0) return ret; } - ret = recv(s->udp_fd, buf, size, 0); - - return ret < 0 ? ff_neterrno() : ret; + ret = recvfrom(s->udp_fd, buf, size, 0, (struct sockaddr *)&addr, &addr_len); + if (ret < 0) + return ff_neterrno(); + if (ff_ip_check_source_lists(&addr, &s->filters)) + return AVERROR(EINTR); + return ret; } static int udp_write(URLContext *h, const uint8_t *buf, int size)