Commit a46dc748 authored by David S. Miller's avatar David S. Miller

Merge branch 'macvtap_capture'

Vlad Yasevich says:

====================
Add packet capture support on macvtap device

Change from RFC:
  - moved to the rx_handler approach.

This series adds support for packet capturing on macvtap device.
The initial approach was to simply export the capturing code as
a function from the core network.  While simple, it was not
a very architecturally clean approach.

The new appraoch is to provide macvtap with its rx_handler which can
is attached to the macvtap device itself.   Macvlan will simply requeue
the packet with an updated skb->dev.  BTW, macvlan layer already does this
for macvlan devices.  So, now macvtap and macvlan have almost the
same exact input path.

I've toyed with short-circuting the input path for macvtap by returning
RX_HANDLER_ANOTHER, but that just made the code more complicated and
didn't provide any kind of measurable gain (at least according to
netperf and perf runs on the host).

To see if there was a performance regression, I ran 1, 2 and 4 netperf
STREAM and MAERTS tests agains the VM from both remote host and another
guest on the same system.   The command ran was
    netperf -H $host -t $test -l 20 -i 10 -I 95 -c -C

The numbers I was getting with the new code were consistently very
slightly (1-2%) better then the old code.  I don't consider this
an improvement, but it's not a regression! :)

Running 'perf record' on the host didn't show any new hot spots
and cpu utilization stayed about the same.  This was better
then I expected from simply looking at the code.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 70f56132 2f6a1b66
...@@ -120,7 +120,7 @@ static int macvlan_broadcast_one(struct sk_buff *skb, ...@@ -120,7 +120,7 @@ static int macvlan_broadcast_one(struct sk_buff *skb,
struct net_device *dev = vlan->dev; struct net_device *dev = vlan->dev;
if (local) if (local)
return vlan->forward(dev, skb); return dev_forward_skb(dev, skb);
skb->dev = dev; skb->dev = dev;
if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast)) if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast))
...@@ -128,7 +128,7 @@ static int macvlan_broadcast_one(struct sk_buff *skb, ...@@ -128,7 +128,7 @@ static int macvlan_broadcast_one(struct sk_buff *skb,
else else
skb->pkt_type = PACKET_MULTICAST; skb->pkt_type = PACKET_MULTICAST;
return vlan->receive(skb); return netif_rx(skb);
} }
static u32 macvlan_hash_mix(const struct macvlan_dev *vlan) static u32 macvlan_hash_mix(const struct macvlan_dev *vlan)
...@@ -251,7 +251,7 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb) ...@@ -251,7 +251,7 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
skb->dev = dev; skb->dev = dev;
skb->pkt_type = PACKET_HOST; skb->pkt_type = PACKET_HOST;
ret = vlan->receive(skb); ret = netif_rx(skb);
out: out:
macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, 0); macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, 0);
...@@ -803,10 +803,7 @@ static int macvlan_validate(struct nlattr *tb[], struct nlattr *data[]) ...@@ -803,10 +803,7 @@ static int macvlan_validate(struct nlattr *tb[], struct nlattr *data[])
} }
int macvlan_common_newlink(struct net *src_net, struct net_device *dev, int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[], struct nlattr *tb[], struct nlattr *data[])
int (*receive)(struct sk_buff *skb),
int (*forward)(struct net_device *dev,
struct sk_buff *skb))
{ {
struct macvlan_dev *vlan = netdev_priv(dev); struct macvlan_dev *vlan = netdev_priv(dev);
struct macvlan_port *port; struct macvlan_port *port;
...@@ -848,8 +845,6 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev, ...@@ -848,8 +845,6 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
vlan->lowerdev = lowerdev; vlan->lowerdev = lowerdev;
vlan->dev = dev; vlan->dev = dev;
vlan->port = port; vlan->port = port;
vlan->receive = receive;
vlan->forward = forward;
vlan->set_features = MACVLAN_FEATURES; vlan->set_features = MACVLAN_FEATURES;
vlan->mode = MACVLAN_MODE_VEPA; vlan->mode = MACVLAN_MODE_VEPA;
...@@ -894,9 +889,7 @@ EXPORT_SYMBOL_GPL(macvlan_common_newlink); ...@@ -894,9 +889,7 @@ EXPORT_SYMBOL_GPL(macvlan_common_newlink);
static int macvlan_newlink(struct net *src_net, struct net_device *dev, static int macvlan_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[]) struct nlattr *tb[], struct nlattr *data[])
{ {
return macvlan_common_newlink(src_net, dev, tb, data, return macvlan_common_newlink(src_net, dev, tb, data);
netif_rx,
dev_forward_skb);
} }
void macvlan_dellink(struct net_device *dev, struct list_head *head) void macvlan_dellink(struct net_device *dev, struct list_head *head)
......
...@@ -70,6 +70,11 @@ static const struct proto_ops macvtap_socket_ops; ...@@ -70,6 +70,11 @@ static const struct proto_ops macvtap_socket_ops;
#define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO) #define RX_OFFLOADS (NETIF_F_GRO | NETIF_F_LRO)
#define TAP_FEATURES (NETIF_F_GSO | NETIF_F_SG) #define TAP_FEATURES (NETIF_F_GSO | NETIF_F_SG)
static struct macvlan_dev *macvtap_get_vlan_rcu(const struct net_device *dev)
{
return rcu_dereference(dev->rx_handler_data);
}
/* /*
* RCU usage: * RCU usage:
* The macvtap_queue and the macvlan_dev are loosely coupled, the * The macvtap_queue and the macvlan_dev are loosely coupled, the
...@@ -271,24 +276,27 @@ static void macvtap_del_queues(struct net_device *dev) ...@@ -271,24 +276,27 @@ static void macvtap_del_queues(struct net_device *dev)
sock_put(&qlist[j]->sk); sock_put(&qlist[j]->sk);
} }
/* static rx_handler_result_t macvtap_handle_frame(struct sk_buff **pskb)
* Forward happens for data that gets sent from one macvlan
* endpoint to another one in bridge mode. We just take
* the skb and put it into the receive queue.
*/
static int macvtap_forward(struct net_device *dev, struct sk_buff *skb)
{ {
struct macvlan_dev *vlan = netdev_priv(dev); struct sk_buff *skb = *pskb;
struct macvtap_queue *q = macvtap_get_queue(dev, skb); struct net_device *dev = skb->dev;
struct macvlan_dev *vlan;
struct macvtap_queue *q;
netdev_features_t features = TAP_FEATURES; netdev_features_t features = TAP_FEATURES;
vlan = macvtap_get_vlan_rcu(dev);
if (!vlan)
return RX_HANDLER_PASS;
q = macvtap_get_queue(dev, skb);
if (!q) if (!q)
goto drop; return RX_HANDLER_PASS;
if (skb_queue_len(&q->sk.sk_receive_queue) >= dev->tx_queue_len) if (skb_queue_len(&q->sk.sk_receive_queue) >= dev->tx_queue_len)
goto drop; goto drop;
skb->dev = dev; skb_push(skb, ETH_HLEN);
/* Apply the forward feature mask so that we perform segmentation /* Apply the forward feature mask so that we perform segmentation
* according to users wishes. This only works if VNET_HDR is * according to users wishes. This only works if VNET_HDR is
* enabled. * enabled.
...@@ -320,22 +328,13 @@ static int macvtap_forward(struct net_device *dev, struct sk_buff *skb) ...@@ -320,22 +328,13 @@ static int macvtap_forward(struct net_device *dev, struct sk_buff *skb)
wake_up: wake_up:
wake_up_interruptible_poll(sk_sleep(&q->sk), POLLIN | POLLRDNORM | POLLRDBAND); wake_up_interruptible_poll(sk_sleep(&q->sk), POLLIN | POLLRDNORM | POLLRDBAND);
return NET_RX_SUCCESS; return RX_HANDLER_CONSUMED;
drop: drop:
/* Count errors/drops only here, thus don't care about args. */
macvlan_count_rx(vlan, 0, 0, 0);
kfree_skb(skb); kfree_skb(skb);
return NET_RX_DROP; return RX_HANDLER_CONSUMED;
}
/*
* Receive is for data from the external interface (lowerdev),
* in case of macvtap, we can treat that the same way as
* forward, which macvlan cannot.
*/
static int macvtap_receive(struct sk_buff *skb)
{
skb_push(skb, ETH_HLEN);
return macvtap_forward(skb->dev, skb);
} }
static int macvtap_get_minor(struct macvlan_dev *vlan) static int macvtap_get_minor(struct macvlan_dev *vlan)
...@@ -385,6 +384,8 @@ static int macvtap_newlink(struct net *src_net, ...@@ -385,6 +384,8 @@ static int macvtap_newlink(struct net *src_net,
struct nlattr *data[]) struct nlattr *data[])
{ {
struct macvlan_dev *vlan = netdev_priv(dev); struct macvlan_dev *vlan = netdev_priv(dev);
int err;
INIT_LIST_HEAD(&vlan->queue_list); INIT_LIST_HEAD(&vlan->queue_list);
/* Since macvlan supports all offloads by default, make /* Since macvlan supports all offloads by default, make
...@@ -392,16 +393,20 @@ static int macvtap_newlink(struct net *src_net, ...@@ -392,16 +393,20 @@ static int macvtap_newlink(struct net *src_net,
*/ */
vlan->tap_features = TUN_OFFLOADS; vlan->tap_features = TUN_OFFLOADS;
err = netdev_rx_handler_register(dev, macvtap_handle_frame, vlan);
if (err)
return err;
/* Don't put anything that may fail after macvlan_common_newlink /* Don't put anything that may fail after macvlan_common_newlink
* because we can't undo what it does. * because we can't undo what it does.
*/ */
return macvlan_common_newlink(src_net, dev, tb, data, return macvlan_common_newlink(src_net, dev, tb, data);
macvtap_receive, macvtap_forward);
} }
static void macvtap_dellink(struct net_device *dev, static void macvtap_dellink(struct net_device *dev,
struct list_head *head) struct list_head *head)
{ {
netdev_rx_handler_unregister(dev);
macvtap_del_queues(dev); macvtap_del_queues(dev);
macvlan_dellink(dev, head); macvlan_dellink(dev, head);
} }
...@@ -725,9 +730,8 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m, ...@@ -725,9 +730,8 @@ static ssize_t macvtap_get_user(struct macvtap_queue *q, struct msghdr *m,
skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG; skb_shinfo(skb)->tx_flags |= SKBTX_SHARED_FRAG;
} }
if (vlan) { if (vlan) {
local_bh_disable(); skb->dev = vlan->dev;
macvlan_start_xmit(skb, vlan->dev); dev_queue_xmit(skb);
local_bh_enable();
} else { } else {
kfree_skb(skb); kfree_skb(skb);
} }
......
...@@ -69,8 +69,6 @@ struct macvlan_dev { ...@@ -69,8 +69,6 @@ struct macvlan_dev {
netdev_features_t set_features; netdev_features_t set_features;
enum macvlan_mode mode; enum macvlan_mode mode;
u16 flags; u16 flags;
int (*receive)(struct sk_buff *skb);
int (*forward)(struct net_device *dev, struct sk_buff *skb);
/* This array tracks active taps. */ /* This array tracks active taps. */
struct macvtap_queue __rcu *taps[MAX_MACVTAP_QUEUES]; struct macvtap_queue __rcu *taps[MAX_MACVTAP_QUEUES];
/* This list tracks all taps (both enabled and disabled) */ /* This list tracks all taps (both enabled and disabled) */
...@@ -103,10 +101,7 @@ static inline void macvlan_count_rx(const struct macvlan_dev *vlan, ...@@ -103,10 +101,7 @@ static inline void macvlan_count_rx(const struct macvlan_dev *vlan,
extern void macvlan_common_setup(struct net_device *dev); extern void macvlan_common_setup(struct net_device *dev);
extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev, extern int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[], struct nlattr *tb[], struct nlattr *data[]);
int (*receive)(struct sk_buff *skb),
int (*forward)(struct net_device *dev,
struct sk_buff *skb));
extern void macvlan_count_rx(const struct macvlan_dev *vlan, extern void macvlan_count_rx(const struct macvlan_dev *vlan,
unsigned int len, bool success, unsigned int len, bool success,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment