From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
To: dev@dpdk.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
Victor Kaplansky <vkaplans@redhat.com>
Subject: [dpdk-dev] [PATCH v3 6/8] vhost: handle VHOST_USER_SEND_RARP request
Date: Fri, 29 Jan 2016 12:58:01 +0800 [thread overview]
Message-ID: <1454043483-24579-7-git-send-email-yuanhan.liu@linux.intel.com> (raw)
In-Reply-To: <1454043483-24579-1-git-send-email-yuanhan.liu@linux.intel.com>
While in former patch we enabled GUEST_ANNOUNCE feature, so that the
guest OS will broadcast a GARP message after migration to notify the
switch about the new location of migrated VM, the thing is that
GUEST_ANNOUNCE is enabled since kernel v3.5 only. For older kernel,
VHOST_USER_SEND_RARP request comes to rescue.
The payload of this new request is the mac address of the migrated VM,
with that, we could construct a RARP message, and then broadcast it
to host interfaces.
That's how this patch works:
- list all interfaces, with the help of SIOCGIFCONF ioctl command
- construct an RARP message and broadcast it
Cc: Thibaut Collet <thibaut.collet@6wind.com>
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
Note that this patch did take effect in my test:
- it indeed updated target vswitch's mac learning table. (with
the "ovs fdb/show bridge" command)
- the ping request packets after migration were indeeded flowed
to the target (but not the source) host's vswitch. (with tcpdump
command)
However, I still saw ping lost. I asked help from Thibaut, the
original author of the VHOST_USER_SEND_RARP request, he suggested
that it might be an issue of my network topo, or ovs settings, which
is likely, regarding to what I observed above.
Anyway, I'd like to send this out, hopefully someone knows what's
wrong there if there any. In the meantime, I will do more debugs.
---
lib/librte_vhost/vhost_user/vhost-net-user.c | 4 +
lib/librte_vhost/vhost_user/vhost-net-user.h | 1 +
lib/librte_vhost/vhost_user/virtio-net-user.c | 125 ++++++++++++++++++++++++++
lib/librte_vhost/vhost_user/virtio-net-user.h | 5 +-
4 files changed, 134 insertions(+), 1 deletion(-)
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c
index 32ad6f6..cb18396 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.c
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.c
@@ -100,6 +100,7 @@ static const char *vhost_message_str[VHOST_USER_MAX] = {
[VHOST_USER_SET_PROTOCOL_FEATURES] = "VHOST_USER_SET_PROTOCOL_FEATURES",
[VHOST_USER_GET_QUEUE_NUM] = "VHOST_USER_GET_QUEUE_NUM",
[VHOST_USER_SET_VRING_ENABLE] = "VHOST_USER_SET_VRING_ENABLE",
+ [VHOST_USER_SEND_RARP] = "VHOST_USER_SEND_RARP",
};
/**
@@ -437,6 +438,9 @@ vserver_message_handler(int connfd, void *dat, int *remove)
case VHOST_USER_SET_VRING_ENABLE:
user_set_vring_enable(ctx, &msg.payload.state);
break;
+ case VHOST_USER_SEND_RARP:
+ user_send_rarp(&msg);
+ break;
default:
break;
diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.h b/lib/librte_vhost/vhost_user/vhost-net-user.h
index 6d252a3..e3bb413 100644
--- a/lib/librte_vhost/vhost_user/vhost-net-user.h
+++ b/lib/librte_vhost/vhost_user/vhost-net-user.h
@@ -67,6 +67,7 @@ typedef enum VhostUserRequest {
VHOST_USER_SET_PROTOCOL_FEATURES = 16,
VHOST_USER_GET_QUEUE_NUM = 17,
VHOST_USER_SET_VRING_ENABLE = 18,
+ VHOST_USER_SEND_RARP = 19,
VHOST_USER_MAX
} VhostUserRequest;
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c
index 0f3b163..cda330d 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.c
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
@@ -34,11 +34,18 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <net/ethernet.h>
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+#include <linux/if_packet.h>
#include <rte_common.h>
#include <rte_log.h>
@@ -413,3 +420,121 @@ user_set_log_base(struct vhost_device_ctx ctx,
return 0;
}
+
+#define RARP_BUF_SIZE 64
+
+static void
+make_rarp_packet(uint8_t *buf, uint8_t *mac)
+{
+ struct ether_header *eth_hdr;
+ struct ether_arp *rarp;
+
+ /* Ethernet header. */
+ eth_hdr = (struct ether_header *)buf;
+ memset(ð_hdr->ether_dhost, 0xff, ETH_ALEN);
+ memcpy(ð_hdr->ether_shost, mac, ETH_ALEN);
+ eth_hdr->ether_type = htons(ETH_P_RARP);
+
+ /* RARP header. */
+ rarp = (struct ether_arp *)(eth_hdr + 1);
+ rarp->ea_hdr.ar_hrd = htons(ARPHRD_ETHER);
+ rarp->ea_hdr.ar_pro = htons(ETHERTYPE_IP);
+ rarp->ea_hdr.ar_hln = ETH_ALEN;
+ rarp->ea_hdr.ar_pln = 4;
+ rarp->ea_hdr.ar_op = htons(ARPOP_RREQUEST);
+
+ memcpy(&rarp->arp_sha, mac, ETH_ALEN);
+ memset(&rarp->arp_spa, 0x00, 4);
+ memcpy(&rarp->arp_tha, mac, 6);
+ memset(&rarp->arp_tpa, 0x00, 4);
+}
+
+
+static void
+send_rarp(const char *ifname, uint8_t *rarp)
+{
+ int fd;
+ struct ifreq ifr;
+ struct sockaddr_ll addr;
+
+ fd = socket(AF_PACKET, SOCK_RAW, 0);
+ if (fd < 0) {
+ perror("socket failed");
+ return;
+ }
+
+ memset(&ifr, 0, sizeof(struct ifreq));
+ strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
+ if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
+ perror("failed to get interface index");
+ close(fd);
+ return;
+ }
+
+ addr.sll_ifindex = ifr.ifr_ifindex;
+ addr.sll_halen = ETH_ALEN;
+
+ if (sendto(fd, rarp, RARP_BUF_SIZE, 0,
+ (const struct sockaddr*)&addr, sizeof(addr)) < 0) {
+ perror("send rarp packet failed");
+ }
+}
+
+
+/*
+ * Broadcast a RARP message to all interfaces, to update
+ * switch's mac table
+ */
+int
+user_send_rarp(struct VhostUserMsg *msg)
+{
+ uint8_t *mac = (uint8_t *)&msg->payload.u64;
+ uint8_t rarp[RARP_BUF_SIZE];
+ struct ifconf ifc = {0, };
+ struct ifreq *ifr;
+ int nr = 16;
+ int fd;
+ uint32_t i;
+
+ RTE_LOG(DEBUG, VHOST_CONFIG,
+ ":: mac: %02x:%02x:%02x:%02x:%02x:%02x\n",
+ mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+
+ make_rarp_packet(rarp, mac);
+
+ /*
+ * Get all interfaces
+ */
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (fd < 0) {
+ perror("failed to create AF_INET socket");
+ return -1;
+ }
+
+again:
+ ifc.ifc_len = sizeof(*ifr) * nr;
+ ifc.ifc_buf = realloc(ifc.ifc_buf, ifc.ifc_len);
+
+ if (ioctl(fd, SIOCGIFCONF, &ifc) < 0) {
+ perror("failed at SIOCGIFCONF");
+ close(fd);
+ return -1;
+ }
+
+ if (ifc.ifc_len == (int)sizeof(struct ifreq) * nr) {
+ /*
+ * current ifc_buf is not big enough to hold
+ * all interfaces; double it and try again.
+ */
+ nr *= 2;
+ goto again;
+ }
+
+ ifr = (struct ifreq *)ifc.ifc_buf;
+ for (i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++)
+ send_rarp(ifr[i].ifr_name, rarp);
+
+ close(fd);
+
+ return 0;
+}
diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.h b/lib/librte_vhost/vhost_user/virtio-net-user.h
index 013cf38..1e9ff9a 100644
--- a/lib/librte_vhost/vhost_user/virtio-net-user.h
+++ b/lib/librte_vhost/vhost_user/virtio-net-user.h
@@ -38,8 +38,10 @@
#include "vhost-net-user.h"
#define VHOST_USER_PROTOCOL_F_MQ 0
+#define VHOST_USER_PROTOCOL_F_RARP 2
-#define VHOST_USER_PROTOCOL_FEATURES (1ULL << VHOST_USER_PROTOCOL_F_MQ)
+#define VHOST_USER_PROTOCOL_FEATURES ((1ULL << VHOST_USER_PROTOCOL_F_MQ) | \
+ (1ULL << VHOST_USER_PROTOCOL_F_RARP))
int user_set_mem_table(struct vhost_device_ctx, struct VhostUserMsg *);
@@ -50,6 +52,7 @@ void user_set_vring_kick(struct vhost_device_ctx, struct VhostUserMsg *);
void user_set_protocol_features(struct vhost_device_ctx ctx,
uint64_t protocol_features);
int user_set_log_base(struct vhost_device_ctx ctx, struct VhostUserMsg *);
+int user_send_rarp(struct VhostUserMsg *);
int user_get_vring_base(struct vhost_device_ctx, struct vhost_vring_state *);
--
1.9.0
next prev parent reply other threads:[~2016-01-29 4:57 UTC|newest]
Thread overview: 98+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-02 3:43 [dpdk-dev] [PATCH 0/4 for 2.3] vhost-user live migration support Yuanhan Liu
2015-12-02 3:43 ` [dpdk-dev] [PATCH 1/4] vhost: handle VHOST_USER_SET_LOG_BASE request Yuanhan Liu
2015-12-02 13:53 ` Panu Matilainen
2015-12-02 14:31 ` Yuanhan Liu
2015-12-02 14:48 ` Panu Matilainen
2015-12-02 15:09 ` Yuanhan Liu
2015-12-02 16:58 ` Panu Matilainen
2015-12-02 17:24 ` Michael S. Tsirkin
2015-12-02 16:38 ` Thomas Monjalon
2015-12-03 1:49 ` Yuanhan Liu
2015-12-06 23:07 ` Thomas Monjalon
2015-12-07 2:00 ` Yuanhan Liu
2015-12-07 2:03 ` Thomas Monjalon
2015-12-07 2:18 ` Yuanhan Liu
2015-12-07 2:49 ` Thomas Monjalon
2015-12-07 6:29 ` Panu Matilainen
2015-12-07 11:28 ` Thomas Monjalon
2015-12-07 11:41 ` Panu Matilainen
2015-12-07 13:55 ` Thomas Monjalon
2015-12-07 16:48 ` Panu Matilainen
2015-12-07 17:47 ` Thomas Monjalon
2015-12-08 5:57 ` Xie, Huawei
2015-12-08 7:25 ` Yuanhan Liu
2015-12-02 3:43 ` [dpdk-dev] [PATCH 2/4] vhost: introduce vhost_log_write Yuanhan Liu
2015-12-02 13:53 ` Victor Kaplansky
2015-12-02 14:39 ` Yuanhan Liu
2015-12-09 3:33 ` Xie, Huawei
2015-12-09 3:42 ` Yuanhan Liu
2015-12-09 5:44 ` Xie, Huawei
2015-12-09 8:41 ` Yuanhan Liu
2015-12-02 3:43 ` [dpdk-dev] [PATCH 3/4] vhost: log vring changes Yuanhan Liu
2015-12-02 14:07 ` Victor Kaplansky
2015-12-02 14:38 ` Yuanhan Liu
2015-12-02 15:58 ` Victor Kaplansky
2015-12-02 16:26 ` Michael S. Tsirkin
2015-12-03 2:31 ` Yuanhan Liu
2015-12-09 2:45 ` Xie, Huawei
2015-12-02 3:43 ` [dpdk-dev] [PATCH 4/4] vhost: enable log_shmfd protocol feature Yuanhan Liu
2015-12-02 14:10 ` [dpdk-dev] [PATCH 0/4 for 2.3] vhost-user live migration support Victor Kaplansky
2015-12-02 14:33 ` Yuanhan Liu
2015-12-09 3:41 ` Xie, Huawei
2015-12-17 3:11 ` [dpdk-dev] [PATCH v2 0/6] " Yuanhan Liu
2015-12-17 3:11 ` [dpdk-dev] [PATCH v2 1/6] vhost: handle VHOST_USER_SET_LOG_BASE request Yuanhan Liu
2015-12-21 15:32 ` Xie, Huawei
2015-12-22 2:25 ` Yuanhan Liu
2015-12-22 2:41 ` Xie, Huawei
2015-12-22 2:55 ` Yuanhan Liu
2015-12-17 3:11 ` [dpdk-dev] [PATCH v2 2/6] vhost: introduce vhost_log_write Yuanhan Liu
2015-12-21 15:06 ` Xie, Huawei
2015-12-22 2:40 ` Yuanhan Liu
2015-12-22 2:45 ` Xie, Huawei
2015-12-22 3:04 ` Yuanhan Liu
2015-12-22 7:02 ` Xie, Huawei
2015-12-22 5:11 ` Peter Xu
2015-12-22 6:09 ` Yuanhan Liu
2015-12-17 3:11 ` [dpdk-dev] [PATCH v2 3/6] vhost: log used vring changes Yuanhan Liu
2015-12-22 6:55 ` Peter Xu
2015-12-22 7:07 ` Xie, Huawei
2015-12-22 7:59 ` Peter Xu
2015-12-22 7:13 ` Yuanhan Liu
2015-12-22 8:01 ` Peter Xu
2015-12-17 3:11 ` [dpdk-dev] [PATCH v2 4/6] vhost: log vring desc buffer changes Yuanhan Liu
2015-12-17 3:12 ` [dpdk-dev] [PATCH v2 5/6] vhost: claim that we support GUEST_ANNOUNCE feature Yuanhan Liu
2015-12-22 8:11 ` Peter Xu
2015-12-22 8:21 ` Yuanhan Liu
2015-12-22 8:24 ` Pavel Fedin
2015-12-17 3:12 ` [dpdk-dev] [PATCH v2 6/6] vhost: enable log_shmfd protocol feature Yuanhan Liu
2015-12-17 12:08 ` [dpdk-dev] [PATCH v2 0/6] vhost-user live migration support Iremonger, Bernard
2015-12-17 12:45 ` Yuanhan Liu
2015-12-21 8:17 ` Pavel Fedin
2016-01-29 4:57 ` [dpdk-dev] [PATCH v3 0/8] " Yuanhan Liu
2016-01-29 4:57 ` [dpdk-dev] [PATCH v3 1/8] vhost: handle VHOST_USER_SET_LOG_BASE request Yuanhan Liu
2016-01-29 4:57 ` [dpdk-dev] [PATCH v3 2/8] vhost: introduce vhost_log_write Yuanhan Liu
2016-02-19 14:26 ` Thomas Monjalon
2016-02-22 6:59 ` Yuanhan Liu
2016-01-29 4:57 ` [dpdk-dev] [PATCH v3 3/8] vhost: log used vring changes Yuanhan Liu
2016-01-29 4:57 ` [dpdk-dev] [PATCH v3 4/8] vhost: log vring desc buffer changes Yuanhan Liu
2016-01-29 4:58 ` [dpdk-dev] [PATCH v3 5/8] vhost: claim that we support GUEST_ANNOUNCE feature Yuanhan Liu
2016-03-11 12:39 ` Olivier MATZ
2016-03-11 13:16 ` Thomas Monjalon
2016-03-11 13:22 ` Olivier MATZ
2016-01-29 4:58 ` Yuanhan Liu [this message]
2016-02-19 6:11 ` [dpdk-dev] [PATCH v3 6/8] vhost: handle VHOST_USER_SEND_RARP request Tan, Jianfeng
2016-02-19 7:03 ` Yuanhan Liu
2016-02-19 8:55 ` Yuanhan Liu
2016-02-22 14:36 ` [dpdk-dev] [PATCH] vhost: broadcast RARP pkt by injecting it to receiving mbuf array Yuanhan Liu
2016-02-24 8:15 ` Qiu, Michael
2016-02-24 8:28 ` Yuanhan Liu
2016-02-25 7:55 ` Qiu, Michael
2016-02-29 15:56 ` Thomas Monjalon
2016-01-29 4:58 ` [dpdk-dev] [PATCH v3 7/8] vhost: enable log_shmfd protocol feature Yuanhan Liu
2016-01-29 4:58 ` [dpdk-dev] [PATCH v3 8/8] vhost: remove duplicate header include Yuanhan Liu
2016-02-01 15:54 ` [dpdk-dev] [PATCH v3 0/8] vhost-user live migration support Iremonger, Bernard
2016-02-02 1:53 ` Yuanhan Liu
2016-02-19 15:01 ` Thomas Monjalon
2016-02-22 7:08 ` Yuanhan Liu
2016-02-22 9:56 ` Thomas Monjalon
2016-02-22 14:24 ` Yuanhan Liu
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=1454043483-24579-7-git-send-email-yuanhan.liu@linux.intel.com \
--to=yuanhan.liu@linux.intel.com \
--cc=dev@dpdk.org \
--cc=mst@redhat.com \
--cc=vkaplans@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).