From: Jesper Dangaard Brouer <brouer@redhat.com>
To: Tomaz Buh <hubber.iskratel@gmail.com>
Cc: xdp-newbies@vger.kernel.org
Subject: Re: MAC addresses and XDP_TX
Date: Wed, 13 Sep 2017 15:51:22 +0200 [thread overview]
Message-ID: <20170913155122.0ced1084@redhat.com> (raw)
In-Reply-To: <CAHALiH5E4N+1m_E=AVnVi5esew7jC7U4mRcfg4YyoooyJdg4ow@mail.gmail.com>
On Wed, 13 Sep 2017 14:56:38 +0200 Tomaz Buh <hubber.iskratel@gmail.com> wrote:
> I'm trying to modify packets within the BPF program and send them to
> another IP address through the same NIC with the XDP_TX call
> (ultimately I'm trying to do a RTP proxy sample).
>
> What I'm missing is the MAC address for the IP, which can be normally
> obtained from the ARP table.
> I can see two solutions for dynamic sending:
> -search the kernel tables for ARP entries,
> -produce ARP reqests and have own ARP table.
>
> Is any of the solutions possible with the current implementation?
> Is there any better solution?
I don't think the kernel have a bpf helper call that can do lookups in
the arptable, and I don't think we need to add it, as via current
facilities we can get the same thing.
The XDP program will need to have a bpf map for maintaining the IP to
MAC-addr mapping, like the the arptable. But the XDP program can
delegate a userspace program to maintain and update this map.
First of all you let ETH_P_ARP return XDP_PASS (like [1]), which cause
the OS/kernel to handle ARP packets.
Second you can register to get rt_netlink notifications when the arp/neigh
table change (group RTNLGRP_NEIGH). Look at how the iproute2 tool[2] does
it, via the tool rtmon or "ip monitor" command (man ip-monitor) like:
$ ip mon neigh
192.168.100.1 dev mlx5p1 lladdr e4:1d:2d:af:60:80 REACHABLE
For the C-code look at ip/ipmonitor.c [3] and e.g. print_neigh() in
ip/ipneigh.c [4].
[1] https://github.com/netoptimizer/prototype-kernel/blob/master/kernel/samples/bpf/xdp_ddos01_blacklist_kern.c#L245-L249
[2] https://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git
[3] https://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git/tree/ip/ipmonitor.c
[4] https://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git/tree/ip/ipneigh.c#n194
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
prev parent reply other threads:[~2017-09-13 13:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-13 12:56 MAC addresses and XDP_TX Tomaz Buh
2017-09-13 13:51 ` Jesper Dangaard Brouer [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=20170913155122.0ced1084@redhat.com \
--to=brouer@redhat.com \
--cc=hubber.iskratel@gmail.com \
--cc=xdp-newbies@vger.kernel.org \
/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.