All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Cindy Lu <lulu@redhat.com>
Cc: mst@redhat.com, jasowang@redhat.com, zhangckid@gmail.com,
	lizhijian@fujitsu.com, jmarcin@redhat.com, qemu-devel@nongnu.org
Subject: Re: [RFC v4 0/5] net/filter: Add AF_PACKET support for vhost-net
Date: Wed, 8 Apr 2026 13:16:41 +0100	[thread overview]
Message-ID: <adZHKW40HajoCzAk@redhat.com> (raw)
In-Reply-To: <20260407050818.2249570-1-lulu@redhat.com>

On Tue, Apr 07, 2026 at 01:05:47PM +0800, Cindy Lu wrote:
> Hi, All
> 
> This series wires AF_PACKET-backed packet capture and inject support into
> the existing socket chardev backend so filter-redirector can keep using exist
> process
> 
> Example Usage
> =============
>   Users are expected to create the AF_PACKET socket in userspace, bind it
>   to the target tap device, and then pass the resulting fd to QEMU via
>   the existing FD_PLACEHOLDER mechanism.
> 
>   Creating such a socket requires CAP_NET_RAW (or running as root).  A
>   typical setup looks like:
> 
>       sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW,
>                            socket.htons(ETH_P_ALL))
>       sock.bind((ifname, ETH_P_ALL))

While FD passing is certainly desirable, and indeed required, for
libvirt to manage QEMU, IMHO, the QIOChannelSocket should be made
capable of opening AF_PACKET sockets explicitly too.

I generally only consider "FD" passing for QIOCHannelSocket to be
supported for address families that we can explicitly open - we
shouldn't have address familys that are only supported via FD
passing

> 
>   The bound fd can then be passed to QEMU with:
> 
>       -chardev socket,...,fd=${FD_PLACEHOLDER},...
> 
> Primary VM (mirror incoming packets to secondary via chardev socket):
> 
>   -netdev "tap,id=net0,ifname=${TAP}...vhost=on"
>   -device "${VIRTIO_NET_DEVICE}"
>   -chardev "socket,id=chain_out,fd=${FD_PLACEHOLDER},af-packet-mode=capture"
>   -chardev "socket,id=mirror0,host=${MIRROR_HOST},port=${MIRROR_PORT},reconnect-ms=${MIRROR_RECONNECT_MS}"
>   -object "filter-redirector,id=r1,netdev=net0,queue=tx,indev=chain_out,status=on,vnet_hdr_support=off,position=head"
>   -object "filter-redirector,id=r1_mirror,netdev=net0,queue=tx,outdev=mirror0,status=on,vnet_hdr_support=off,insert=behind"
> 
> Secondary VM (receive mirrored packets):
> 
>   -netdev "tap,id=net0,ifname=${TAP}...vhost=on"
>   -device "${VIRTIO_NET_DEVICE}"
>   -chardev "socket,id=red0,host=${MIRROR_BIND_HOST},port=${MIRROR_PORT},server=on,wait=off"
>   -chardev "socket,id=chain_in,fd=${FD_PLACEHOLDER},af-packet-mode=inject"
>   -object "filter-redirector,id=r1,netdev=net0,queue=tx,indev=red0,status=off,vnet_hdr_support=off,position=head"
>   -object "filter-redirector,id=r1_inject,netdev=net0,queue=tx,outdev=chain_in,status=off,vnet_hdr_support=off,position=id=r1,insert=behind"
> 
> 
> changset
> ===========
> change in v2: 
> 1. add support for filter-buffer 
> 2. remove the in_netdev and out_netdev for AF_PACKET bind port, now only use netdev 
> when the vhost=on start use AF_PACKET to capture and inject, when use vhost=off will use
> the existing code
> 3. add CAP_NET_RAW check
> 4. address the comment 
> 
> change in v3: 
> 1. reuse the exist Capture/inject process 
> 
> change in v4: 
> 1.move the capture/inject to chardev 
> 2.move the create/bind socket to user script
> 
> Testing
> =======
> - Tested with vhost=on/off TAP device on x86_64
> 
> 
> 
> Cindy Lu (5):
>   net/filter: allow filters on vhost netdevs
>   chardev/socket: add AF_PACKET initialization
>   io/channel-socket: tolerate AF_PACKET getpeername
>   chardev/socket: add AF_PACKET inject path
>   chardev/socket: add AF_PACKET capture path
> 
>  chardev/char-socket.c         | 385 +++++++++++++++++++++++++++++++++-
>  chardev/char.c                |   3 +
>  include/chardev/char-socket.h |  13 ++
>  io/channel-socket.c           |   6 +-
>  net/filter.c                  |   6 -
>  qapi/char.json                |  23 +-
>  qemu-options.hx               |   5 +-
>  7 files changed, 429 insertions(+), 12 deletions(-)
> 
> -- 
> 2.52.0
> 
> 

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



      parent reply	other threads:[~2026-04-08 18:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-07  5:05 [RFC v4 0/5] net/filter: Add AF_PACKET support for vhost-net Cindy Lu
2026-04-07  5:05 ` [RFC v4 1/5] net/filter: allow filters on vhost netdevs Cindy Lu
2026-04-07  5:05 ` [RFC v4 2/5] chardev/socket: add AF_PACKET initialization Cindy Lu
2026-04-07  5:05 ` [RFC v4 3/5] io/channel-socket: tolerate AF_PACKET getpeername Cindy Lu
2026-04-08 12:00   ` Daniel P. Berrangé
2026-04-07  5:05 ` [RFC v4 4/5] chardev/socket: add AF_PACKET inject path Cindy Lu
2026-04-08 12:07   ` Daniel P. Berrangé
2026-04-07  5:05 ` [RFC v4 5/5] chardev/socket: add AF_PACKET capture path Cindy Lu
2026-04-08 12:13   ` Daniel P. Berrangé
2026-04-08 12:16 ` Daniel P. Berrangé [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=adZHKW40HajoCzAk@redhat.com \
    --to=berrange@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=jmarcin@redhat.com \
    --cc=lizhijian@fujitsu.com \
    --cc=lulu@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=zhangckid@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.