Skip to content

Commit 9dcc71e

Browse files
Sridhar Samudraladavem330
authored andcommitted
vxlan: Bypass encapsulation if the destination is local
This patch bypasses vxlan encapsulation if the destination vxlan endpoint is a local device. Changes since v1: added missing check for vxlan_find_vni() failure Signed-off-by: Sridhar Samudrala <sri@us.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c4637cd commit 9dcc71e

1 file changed

Lines changed: 43 additions & 16 deletions

File tree

‎drivers/net/vxlan.c‎

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,36 @@ static int handle_offloads(struct sk_buff *skb)
912912
return 0;
913913
}
914914

915+
/* Bypass encapsulation if the destination is local */
916+
static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan,
917+
struct vxlan_dev *dst_vxlan)
918+
{
919+
struct pcpu_tstats *tx_stats = this_cpu_ptr(src_vxlan->dev->tstats);
920+
struct pcpu_tstats *rx_stats = this_cpu_ptr(dst_vxlan->dev->tstats);
921+
922+
skb->pkt_type = PACKET_HOST;
923+
skb->encapsulation = 0;
924+
skb->dev = dst_vxlan->dev;
925+
__skb_pull(skb, skb_network_offset(skb));
926+
927+
if (dst_vxlan->flags & VXLAN_F_LEARN)
928+
vxlan_snoop(skb->dev, INADDR_LOOPBACK, eth_hdr(skb)->h_source);
929+
930+
u64_stats_update_begin(&tx_stats->syncp);
931+
tx_stats->tx_packets++;
932+
tx_stats->tx_bytes += skb->len;
933+
u64_stats_update_end(&tx_stats->syncp);
934+
935+
if (netif_rx(skb) == NET_RX_SUCCESS) {
936+
u64_stats_update_begin(&rx_stats->syncp);
937+
rx_stats->rx_packets++;
938+
rx_stats->rx_bytes += skb->len;
939+
u64_stats_update_end(&rx_stats->syncp);
940+
} else {
941+
skb->dev->stats.rx_dropped++;
942+
}
943+
}
944+
915945
static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
916946
struct vxlan_rdst *rdst, bool did_rsc)
917947
{
@@ -922,7 +952,6 @@ static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
922952
struct vxlanhdr *vxh;
923953
struct udphdr *uh;
924954
struct flowi4 fl4;
925-
unsigned int pkt_len = skb->len;
926955
__be32 dst;
927956
__u16 src_port, dst_port;
928957
u32 vni;
@@ -935,22 +964,8 @@ static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
935964

936965
if (!dst) {
937966
if (did_rsc) {
938-
__skb_pull(skb, skb_network_offset(skb));
939-
skb->ip_summed = CHECKSUM_NONE;
940-
skb->pkt_type = PACKET_HOST;
941-
942967
/* short-circuited back to local bridge */
943-
if (netif_rx(skb) == NET_RX_SUCCESS) {
944-
struct pcpu_tstats *stats = this_cpu_ptr(dev->tstats);
945-
946-
u64_stats_update_begin(&stats->syncp);
947-
stats->tx_packets++;
948-
stats->tx_bytes += pkt_len;
949-
u64_stats_update_end(&stats->syncp);
950-
} else {
951-
dev->stats.tx_errors++;
952-
dev->stats.tx_aborted_errors++;
953-
}
968+
vxlan_encap_bypass(skb, vxlan, vxlan);
954969
return NETDEV_TX_OK;
955970
}
956971
goto drop;
@@ -997,6 +1012,18 @@ static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
9971012
goto tx_error;
9981013
}
9991014

1015+
/* Bypass encapsulation if the destination is local */
1016+
if (rt->rt_flags & RTCF_LOCAL) {
1017+
struct vxlan_dev *dst_vxlan;
1018+
1019+
ip_rt_put(rt);
1020+
dst_vxlan = vxlan_find_vni(dev_net(dev), vni);
1021+
if (!dst_vxlan)
1022+
goto tx_error;
1023+
vxlan_encap_bypass(skb, vxlan, dst_vxlan);
1024+
return NETDEV_TX_OK;
1025+
}
1026+
10001027
memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
10011028
IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
10021029
IPSKB_REROUTED);

0 commit comments

Comments
 (0)