Re: MAC addresses and XDP_TX

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 13 Sep 2017 14:56:38 +0200 Tomaz Buh <hubber.iskratel@xxxxxxxxx> 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



[Index of Archives]     [Linux Networking Development]     [Fedora Linux Users]     [Linux SCTP]     [DCCP]     [Gimp]     [Yosemite Campsites]

  Powered by Linux