Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Sep 2022 18:05:03 +0200
From:      Vincenzo Maffione <vmaffione@freebsd.org>
To:        Kim Shrier <kim@westryn.net>
Cc:        "net@freebsd.org" <net@freebsd.org>, Giuseppe Lettieri <giuseppe.lettieri@unipi.it>
Subject:   Re: Forwarding packets to the host stack in net map lb app
Message-ID:  <CA%2B_eA9jkCYAfTeXho4fNTsqwSCXmxwCuvxkQV3BD_uz9XAAv4w@mail.gmail.com>
In-Reply-To: <CB07794F-4719-4C1D-B64C-05C8335D329F@westryn.net>
References:  <CB07794F-4719-4C1D-B64C-05C8335D329F@westryn.net>

next in thread | previous in thread | raw e-mail | index | archive | help
--0000000000006fd98c05e996b15d
Content-Type: text/plain; charset="UTF-8"

I think you could avoid any modifications to lb(8) and take advantage of
the "multiple pipe groups" feature.
You open two groups,
# lb -i netmap:em0/R -p mon:$N -p fwd:$M [...]
Each group receives all the packets arriving on the RX (NIC) rings of em0.
(I'm pretty sure) this happens without packet copies, i.e. by swapping
netmap slots.

The first group (mon) is for your existing monitor process. The second one
(fwd) would be used for a separate process that handles the host stack:
 - It reads from fwd:$M pipes, selecting only the RX packets that should be
forwarded to the host stack. Selected packets will be forwarded to
netmap:em0^/T. All the other packets are just dropped.
 - it forwards all traffic from netmap:em0^/R to netmap:em0/T (e.g. from
the em0 host RX ring to the em0 TX rings). Keep in mind that lb does not
touch em0 TX rings, so there would not be conflicts. In any case, it is
good practice to have lb only open RX rings (netmap:em0/R).
This second process can probably be a modified version of the netmap
bridge, although you have asymmetric three-party forwarding here (fwd/R -->
netmap:em0^T, netmap:em0^/R --> netmap:em0/T).

The alternative (harder) option would be to actually modify lb(8). You
should probably:
 - open netmap:em0^/R and netmap:em0*/T with separate nmport_open() calls
 - parse the packet before pkt_hdr_hash() to select the RX packets that you
need to forward to the host TX ring, and modify the forwarding logic to
perform this task.
 - modify the logic of the lb poll() loop so that it also performs the
forwarding from host RX rings to NIC TX rings
I'm not sure that you would have any advantages by choosing this path.

Cheers,
  Vincenzo

Il giorno dom 18 set 2022 alle ore 23:47 Kim Shrier <kim@westryn.net> ha
scritto:

> I have a network monitoring program and I am using the lb app from
> netmap to distribute packets to netmap pipes.  The monitor processes
> are successfully receiving packets.
>
> I would like to modify lb to send some packets to the host stack and
> have packets coming from the host stack go out on the monitoring
> ethernet interface.
>
> I am relatively new to using netmap and it is not obvious to me how
> to properly send/receive some packets to the host tx/rx rings while
> still letting the the netmap pipes forward packets to my monitoring
> application.
>
> I have looked at the bridge app from netmap which opens 2 netmap
> ports. It does not seem to me that that would be the right way to
> deal with the host stack in the context of lb.
>
> Should I just process the last tx/rx ring differently from the first ones
> that are forwarding packets to the netmap pipes?
>
> Thanks,
> Kim
>
>
>
>

--0000000000006fd98c05e996b15d
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>I think you could avoid any modifications to lb(8) an=
d take advantage of the &quot;multiple pipe groups&quot; feature.</div><div=
>You open two groups, <br></div><div># lb -i netmap:em0/R -p mon:$N -p fwd:=
$M [...]</div><div>Each group receives all the packets arriving on the RX (=
NIC) rings of em0. (I&#39;m pretty sure) this happens without packet copies=
, i.e. by swapping netmap slots.<br></div><div><br></div><div>The first gro=
up (mon) is for your existing monitor process. The second one (fwd) would b=
e used for a separate process that handles the host stack:</div><div>=C2=A0=
- It reads from fwd:$M pipes, selecting only the RX packets that should be =
forwarded to the host stack. Selected packets will be forwarded to netmap:e=
m0^/T. All the other packets are just dropped.<br></div><div>=C2=A0- it for=
wards all traffic from netmap:em0^/R to netmap:em0/T (e.g. from the em0 hos=
t RX ring to the em0 TX rings). Keep in mind that lb does not touch em0 TX =
rings, so there would not be conflicts. In any case, it is good practice to=
 have lb only open RX rings (netmap:em0/R).</div><div>This second process c=
an probably be a modified version of the netmap bridge, although you have a=
symmetric three-party forwarding here (fwd/R --&gt; netmap:em0^T, netmap:em=
0^/R --&gt; netmap:em0/T).</div><div><br></div><div>The alternative (harder=
) option would be to actually modify lb(8). You should probably:</div><div>=
=C2=A0- open netmap:em0^/R and netmap:em0*/T with separate nmport_open() ca=
lls</div><div>=C2=A0- parse the packet before pkt_hdr_hash() to select the =
RX packets that you need to forward to the host TX ring, and modify the for=
warding logic to perform this task.<br></div><div>=C2=A0- modify the logic =
of the lb poll() loop so that it also performs the forwarding from host RX =
rings to NIC TX rings<br></div><div>I&#39;m not sure that you would have an=
y advantages by choosing this path.</div><div><br></div><div>Cheers,</div><=
div>=C2=A0 Vincenzo</div><br><div class=3D"gmail_quote"><div dir=3D"ltr" cl=
ass=3D"gmail_attr">Il giorno dom 18 set 2022 alle ore 23:47 Kim Shrier &lt;=
<a href=3D"mailto:kim@westryn.net" target=3D"_blank">kim@westryn.net</a>&gt=
; ha scritto:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0p=
x 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I =
have a network monitoring program and I am using the lb app from<br>
netmap to distribute packets to netmap pipes.=C2=A0 The monitor processes<b=
r>
are successfully receiving packets.<br>
<br>
I would like to modify lb to send some packets to the host stack and<br>
have packets coming from the host stack go out on the monitoring<br>
ethernet interface.<br>
<br>
I am relatively new to using netmap and it is not obvious to me how<br>
to properly send/receive some packets to the host tx/rx rings while<br>
still letting the the netmap pipes forward packets to my monitoring<br>
application.<br>
<br>
I have looked at the bridge app from netmap which opens 2 netmap<br>
ports. It does not seem to me that that would be the right way to<br>
deal with the host stack in the context of lb.<br>
<br>
Should I just process the last tx/rx ring differently from the first ones<b=
r>
that are forwarding packets to the netmap pipes?<br>
<br>
Thanks,<br>
Kim<br>
<br>
<br>
<br>
</blockquote></div></div>

--0000000000006fd98c05e996b15d--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CA%2B_eA9jkCYAfTeXho4fNTsqwSCXmxwCuvxkQV3BD_uz9XAAv4w>