* [PATCH 01/16] kvm tools: Introduce uip_udp_make_pkg()
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
@ 2011-07-17 8:56 ` Asias He
2011-07-17 8:56 ` [PATCH 02/16] kvm tools: Introduce struct uip_dhcp Asias He
` (15 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:56 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
This helper cooks a ethernet package and virtio header for UDP.
This patch also makes uip_udp_socket_thread() shorter.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/include/kvm/uip.h | 1 +
tools/kvm/net/uip/udp.c | 100 +++++++++++++++++++++++-------------------
2 files changed, 56 insertions(+), 45 deletions(-)
diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h
index 18849d2..8333004 100644
--- a/tools/kvm/include/kvm/uip.h
+++ b/tools/kvm/include/kvm/uip.h
@@ -289,4 +289,5 @@ struct uip_buf *uip_buf_get_used(struct uip_info *info);
struct uip_buf *uip_buf_get_free(struct uip_info *info);
struct uip_buf *uip_buf_clone(struct uip_tx_arg *arg);
+int uip_udp_make_pkg(struct uip_info *info, struct uip_udp_socket *sk, struct uip_buf *buf, u8 *payload, int payload_len);
#endif /* KVM__UIP_H */
diff --git a/tools/kvm/net/uip/udp.c b/tools/kvm/net/uip/udp.c
index 5f9d7a4..fcd5018 100644
--- a/tools/kvm/net/uip/udp.c
+++ b/tools/kvm/net/uip/udp.c
@@ -98,18 +98,66 @@ static int uip_udp_socket_send(struct uip_udp_socket *sk, struct uip_udp *udp)
return 0;
}
+int uip_udp_make_pkg(struct uip_info *info, struct uip_udp_socket *sk, struct uip_buf *buf, u8* payload, int payload_len)
+{
+ struct uip_eth *eth2;
+ struct uip_udp *udp2;
+ struct uip_ip *ip2;
+
+ /*
+ * Cook a ethernet frame
+ */
+ udp2 = (struct uip_udp *)(buf->eth);
+ eth2 = (struct uip_eth *)buf->eth;
+ ip2 = (struct uip_ip *)(buf->eth);
+
+ eth2->src = info->host_mac;
+ eth2->dst = info->guest_mac;
+ eth2->type = htons(UIP_ETH_P_IP);
+
+ ip2->vhl = UIP_IP_VER_4 | UIP_IP_HDR_LEN;
+ ip2->tos = 0;
+ ip2->id = 0;
+ ip2->flgfrag = 0;
+ ip2->ttl = UIP_IP_TTL;
+ ip2->proto = UIP_IP_P_UDP;
+ ip2->csum = 0;
+
+ ip2->sip = sk->dip;
+ ip2->dip = sk->sip;
+ udp2->sport = sk->dport;
+ udp2->dport = sk->sport;
+
+ udp2->len = htons(payload_len + uip_udp_hdrlen(udp2));
+ udp2->csum = 0;
+
+ if (payload)
+ memcpy(udp2->payload, payload, payload_len);
+
+ ip2->len = udp2->len + htons(uip_ip_hdrlen(ip2));
+ ip2->csum = uip_csum_ip(ip2);
+ udp2->csum = uip_csum_udp(udp2);
+
+ /*
+ * virtio_net_hdr
+ */
+ buf->vnet_len = sizeof(struct virtio_net_hdr);
+ memset(buf->vnet, 0, buf->vnet_len);
+
+ buf->eth_len = ntohs(ip2->len) + uip_eth_hdrlen(&ip2->eth);
+
+ return 0;
+}
+
static void *uip_udp_socket_thread(void *p)
{
struct epoll_event events[UIP_UDP_MAX_EVENTS];
struct uip_udp_socket *sk;
struct uip_info *info;
- struct uip_eth *eth2;
- struct uip_udp *udp2;
struct uip_buf *buf;
- struct uip_ip *ip2;
+ int payload_len;
u8 *payload;
int nfds;
- int ret;
int i;
info = p;
@@ -127,8 +175,8 @@ static void *uip_udp_socket_thread(void *p)
for (i = 0; i < nfds; i++) {
sk = events[i].data.ptr;
- ret = recvfrom(sk->fd, payload, UIP_MAX_UDP_PAYLOAD, 0, NULL, NULL);
- if (ret < 0)
+ payload_len = recvfrom(sk->fd, payload, UIP_MAX_UDP_PAYLOAD, 0, NULL, NULL);
+ if (payload_len < 0)
continue;
/*
@@ -136,45 +184,7 @@ static void *uip_udp_socket_thread(void *p)
*/
buf = uip_buf_get_free(info);
- /*
- * Cook a ethernet frame
- */
- udp2 = (struct uip_udp *)(buf->eth);
- eth2 = (struct uip_eth *)buf->eth;
- ip2 = (struct uip_ip *)(buf->eth);
-
- eth2->src = info->host_mac;
- eth2->dst = info->guest_mac;
- eth2->type = htons(UIP_ETH_P_IP);
-
- ip2->vhl = UIP_IP_VER_4 | UIP_IP_HDR_LEN;
- ip2->tos = 0;
- ip2->id = 0;
- ip2->flgfrag = 0;
- ip2->ttl = UIP_IP_TTL;
- ip2->proto = UIP_IP_P_UDP;
- ip2->csum = 0;
- ip2->sip = sk->dip;
- ip2->dip = sk->sip;
-
- udp2->sport = sk->dport;
- udp2->dport = sk->sport;
- udp2->len = htons(ret + uip_udp_hdrlen(udp2));
- udp2->csum = 0;
-
- memcpy(udp2->payload, payload, ret);
-
- ip2->len = udp2->len + htons(uip_ip_hdrlen(ip2));
- ip2->csum = uip_csum_ip(ip2);
- udp2->csum = uip_csum_udp(udp2);
-
- /*
- * virtio_net_hdr
- */
- buf->vnet_len = sizeof(struct virtio_net_hdr);
- memset(buf->vnet, 0, buf->vnet_len);
-
- buf->eth_len = ntohs(ip2->len) + uip_eth_hdrlen(&ip2->eth);
+ uip_udp_make_pkg(info, sk, buf, payload, payload_len);
/*
* Send data received from socket to guest
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 02/16] kvm tools: Introduce struct uip_dhcp
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
2011-07-17 8:56 ` [PATCH 01/16] kvm tools: Introduce uip_udp_make_pkg() Asias He
@ 2011-07-17 8:56 ` Asias He
2011-07-17 8:56 ` [PATCH 03/16] kvm tools: Add helper to tell if a UDP package is a DHCP package Asias He
` (14 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:56 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
struct uip_dhcp is used to present DHCP package
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/include/kvm/uip.h | 27 +++++++++++++++++++++++++++
1 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h
index 8333004..c414267 100644
--- a/tools/kvm/include/kvm/uip.h
+++ b/tools/kvm/include/kvm/uip.h
@@ -29,6 +29,12 @@
#define UIP_TCP_FLAG_ACK 16
#define UIP_TCP_FLAG_URG 32
+#define UIP_DHCP_VENDOR_SPECIFIC_LEN 312
+#define UIP_DHCP_MACPAD_LEN 10
+#define UIP_DHCP_HOSTNAME_LEN 64
+#define UIP_DHCP_FILENAME_LEN 128
+#define UIP_DHCP_MAGIC_COOKIE_LEN 4
+#define UIP_DHCP_OPTION_LEN (UIP_DHCP_VENDOR_SPECIFIC_LEN - UIP_DHCP_MAGIC_COOKIE_LEN)
/*
* IP package maxium len == 64 KBytes
* IP header == 20 Bytes
@@ -126,6 +132,27 @@ struct uip_pseudo_hdr {
u16 len;
} __attribute__((packed));
+struct uip_dhcp {
+ struct uip_udp udp;
+ u8 msg_type;
+ u8 hardware_type;
+ u8 hardware_len;
+ u8 hops;
+ u32 id;
+ u16 time;
+ u16 flg;
+ u32 client_ip;
+ u32 your_ip;
+ u32 server_ip;
+ u32 agent_ip;
+ struct uip_eth_addr client_mac;
+ u8 pad[UIP_DHCP_MACPAD_LEN];
+ u8 server_hostname[UIP_DHCP_HOSTNAME_LEN];
+ u8 boot_filename[UIP_DHCP_FILENAME_LEN];
+ u32 magic_cookie;
+ u8 option[UIP_DHCP_OPTION_LEN];
+} __attribute__((packed));
+
struct uip_info {
struct list_head udp_socket_head;
struct list_head tcp_socket_head;
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 03/16] kvm tools: Add helper to tell if a UDP package is a DHCP package
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
2011-07-17 8:56 ` [PATCH 01/16] kvm tools: Introduce uip_udp_make_pkg() Asias He
2011-07-17 8:56 ` [PATCH 02/16] kvm tools: Introduce struct uip_dhcp Asias He
@ 2011-07-17 8:56 ` Asias He
2011-07-17 8:56 ` [PATCH 04/16] kvm tools: Add helpers to tell the type of a DHCP message Asias He
` (13 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:56 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
This patch checks:
- sport and dport
- magic cookie
to detemine whether a UDP package is a DHCP package.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/Makefile | 1 +
tools/kvm/include/kvm/uip.h | 4 ++++
tools/kvm/net/uip/dhcp.c | 17 +++++++++++++++++
3 files changed, 22 insertions(+), 0 deletions(-)
create mode 100644 tools/kvm/net/uip/dhcp.c
diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile
index 5d04377..b5c5516 100644
--- a/tools/kvm/Makefile
+++ b/tools/kvm/Makefile
@@ -61,6 +61,7 @@ OBJS += net/uip/tcp.o
OBJS += net/uip/udp.o
OBJS += net/uip/buf.o
OBJS += net/uip/csum.o
+OBJS += net/uip/dhcp.o
OBJS += kvm-cmd.o
OBJS += mptable.o
OBJS += rbtree.o
diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h
index c414267..7c84dea 100644
--- a/tools/kvm/include/kvm/uip.h
+++ b/tools/kvm/include/kvm/uip.h
@@ -30,9 +30,12 @@
#define UIP_TCP_FLAG_URG 32
#define UIP_DHCP_VENDOR_SPECIFIC_LEN 312
+#define UIP_DHCP_PORT_SERVER 67
+#define UIP_DHCP_PORT_CLIENT 68
#define UIP_DHCP_MACPAD_LEN 10
#define UIP_DHCP_HOSTNAME_LEN 64
#define UIP_DHCP_FILENAME_LEN 128
+#define UIP_DHCP_MAGIC_COOKIE 0x63825363
#define UIP_DHCP_MAGIC_COOKIE_LEN 4
#define UIP_DHCP_OPTION_LEN (UIP_DHCP_VENDOR_SPECIFIC_LEN - UIP_DHCP_MAGIC_COOKIE_LEN)
/*
@@ -317,4 +320,5 @@ struct uip_buf *uip_buf_get_free(struct uip_info *info);
struct uip_buf *uip_buf_clone(struct uip_tx_arg *arg);
int uip_udp_make_pkg(struct uip_info *info, struct uip_udp_socket *sk, struct uip_buf *buf, u8 *payload, int payload_len);
+bool uip_udp_is_dhcp(struct uip_udp *udp);
#endif /* KVM__UIP_H */
diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c
new file mode 100644
index 0000000..af0407f
--- /dev/null
+++ b/tools/kvm/net/uip/dhcp.c
@@ -0,0 +1,17 @@
+#include "kvm/uip.h"
+
+bool uip_udp_is_dhcp(struct uip_udp *udp)
+{
+ struct uip_dhcp *dhcp;
+
+ if (ntohs(udp->sport) != UIP_DHCP_PORT_CLIENT ||
+ ntohs(udp->dport) != UIP_DHCP_PORT_SERVER)
+ return false;
+
+ dhcp = (struct uip_dhcp *)udp;
+
+ if (ntohl(dhcp->magic_cookie) != UIP_DHCP_MAGIC_COOKIE)
+ return false;
+
+ return true;
+}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 04/16] kvm tools: Add helpers to tell the type of a DHCP message
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (2 preceding siblings ...)
2011-07-17 8:56 ` [PATCH 03/16] kvm tools: Add helper to tell if a UDP package is a DHCP package Asias He
@ 2011-07-17 8:56 ` Asias He
2011-07-17 8:56 ` [PATCH 05/16] kvm tools: Get domain name and nameserver from host Asias He
` (12 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:56 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
If DHCP DISCOVER or DHCP REQUEST is found, reply with DHCP OFFER or DHCP
ACK respectively.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/include/kvm/uip.h | 6 ++++++
tools/kvm/net/uip/dhcp.c | 14 ++++++++++++++
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h
index 7c84dea..6534c7f 100644
--- a/tools/kvm/include/kvm/uip.h
+++ b/tools/kvm/include/kvm/uip.h
@@ -38,6 +38,12 @@
#define UIP_DHCP_MAGIC_COOKIE 0x63825363
#define UIP_DHCP_MAGIC_COOKIE_LEN 4
#define UIP_DHCP_OPTION_LEN (UIP_DHCP_VENDOR_SPECIFIC_LEN - UIP_DHCP_MAGIC_COOKIE_LEN)
+#define UIP_DHCP_DISCOVER 1
+#define UIP_DHCP_OFFER 2
+#define UIP_DHCP_REQUEST 3
+#define UIP_DHCP_ACK 5
+#define UIP_DHCP_TAG_MSG_TYPE 53
+#define UIP_DHCP_TAG_MSG_TYPE_LEN 1
/*
* IP package maxium len == 64 KBytes
* IP header == 20 Bytes
diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c
index af0407f..0a6293a 100644
--- a/tools/kvm/net/uip/dhcp.c
+++ b/tools/kvm/net/uip/dhcp.c
@@ -1,5 +1,19 @@
#include "kvm/uip.h"
+static inline bool uip_dhcp_is_discovery(struct uip_dhcp *dhcp)
+{
+ return (dhcp->option[2] == UIP_DHCP_DISCOVER &&
+ dhcp->option[1] == UIP_DHCP_TAG_MSG_TYPE_LEN &&
+ dhcp->option[0] == UIP_DHCP_TAG_MSG_TYPE);
+}
+
+static inline bool uip_dhcp_is_request(struct uip_dhcp *dhcp)
+{
+ return (dhcp->option[2] == UIP_DHCP_REQUEST &&
+ dhcp->option[1] == UIP_DHCP_TAG_MSG_TYPE_LEN &&
+ dhcp->option[0] == UIP_DHCP_TAG_MSG_TYPE);
+}
+
bool uip_udp_is_dhcp(struct uip_udp *udp)
{
struct uip_dhcp *dhcp;
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 05/16] kvm tools: Get domain name and nameserver from host
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (3 preceding siblings ...)
2011-07-17 8:56 ` [PATCH 04/16] kvm tools: Add helpers to tell the type of a DHCP message Asias He
@ 2011-07-17 8:56 ` Asias He
2011-07-17 9:36 ` Sasha Levin
2011-07-17 8:56 ` [PATCH 06/16] kvm tools: Fill DHCP options with domain name and DNS server IP Asias He
` (11 subsequent siblings)
16 siblings, 1 reply; 21+ messages in thread
From: Asias He @ 2011-07-17 8:56 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
This patch get domain name and nameserver information from host config
file /etc/resolv.conf.
Guest can obtain DNS information through DHCP.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/include/kvm/uip.h | 6 ++++++
tools/kvm/net/uip/dhcp.c | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h
index 6534c7f..e645d3f 100644
--- a/tools/kvm/include/kvm/uip.h
+++ b/tools/kvm/include/kvm/uip.h
@@ -42,6 +42,8 @@
#define UIP_DHCP_OFFER 2
#define UIP_DHCP_REQUEST 3
#define UIP_DHCP_ACK 5
+#define UIP_DHCP_MAX_DNS_SERVER_NR 3
+#define UIP_DHCP_MAX_DOMAIN_NAME_LEN 256
#define UIP_DHCP_TAG_MSG_TYPE 53
#define UIP_DHCP_TAG_MSG_TYPE_LEN 1
/*
@@ -178,6 +180,8 @@ struct uip_info {
int buf_free_nr;
int buf_used_nr;
u32 host_ip;
+ u32 dns_ip[UIP_DHCP_MAX_DNS_SERVER_NR];
+ char *domain_name;
u32 buf_nr;
};
@@ -327,4 +331,6 @@ struct uip_buf *uip_buf_clone(struct uip_tx_arg *arg);
int uip_udp_make_pkg(struct uip_info *info, struct uip_udp_socket *sk, struct uip_buf *buf, u8 *payload, int payload_len);
bool uip_udp_is_dhcp(struct uip_udp *udp);
+
+int uip_dhcp_get_dns(struct uip_info *info);
#endif /* KVM__UIP_H */
diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c
index 0a6293a..9321cdc 100644
--- a/tools/kvm/net/uip/dhcp.c
+++ b/tools/kvm/net/uip/dhcp.c
@@ -1,5 +1,7 @@
#include "kvm/uip.h"
+#include <arpa/inet.h>
+
static inline bool uip_dhcp_is_discovery(struct uip_dhcp *dhcp)
{
return (dhcp->option[2] == UIP_DHCP_DISCOVER &&
@@ -29,3 +31,35 @@ bool uip_udp_is_dhcp(struct uip_udp *udp)
return true;
}
+
+int uip_dhcp_get_dns(struct uip_info *info)
+{
+ char key[256], val[256];
+ struct in_addr addr;
+ int ret = -1;
+ int n = 0;
+ FILE *fp;
+ u32 ip;
+
+ fp = fopen("/etc/resolv.conf", "r");
+ if (!fp)
+ goto out;
+
+ while (!feof(fp)) {
+ fscanf(fp, "%s %s\n", key, val);
+ if (strncmp("domain", key, 6) == 0)
+ info->domain_name = strndup(val, UIP_DHCP_MAX_DOMAIN_NAME_LEN);
+ else if (strncmp("nameserver", key, 10) == 0) {
+ if (!inet_aton(val, &addr))
+ continue;
+ ip = ntohl(addr.s_addr);
+ if (n < UIP_DHCP_MAX_DNS_SERVER_NR)
+ info->dns_ip[n++] = ip;
+ ret = 0;
+ }
+ }
+
+out:
+ fclose(fp);
+ return ret;
+}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH 05/16] kvm tools: Get domain name and nameserver from host
2011-07-17 8:56 ` [PATCH 05/16] kvm tools: Get domain name and nameserver from host Asias He
@ 2011-07-17 9:36 ` Sasha Levin
2011-07-18 4:48 ` Asias He
0 siblings, 1 reply; 21+ messages in thread
From: Sasha Levin @ 2011-07-17 9:36 UTC (permalink / raw)
To: Asias He; +Cc: Pekka Enberg, Cyrill Gorcunov, Ingo Molnar, Prasad Joshi, kvm
On Sun, 2011-07-17 at 16:56 +0800, Asias He wrote:
> This patch get domain name and nameserver information from host config
> file /etc/resolv.conf.
>
> Guest can obtain DNS information through DHCP.
>
> Signed-off-by: Asias He <asias.hejun@gmail.com>
> ---
Seeing this after this patch:
cc1: warnings being treated as errors
net/uip/dhcp.c: In function 'uip_dhcp_get_dns':
net/uip/dhcp.c:49:9: error: ignoring return value of 'fscanf', declared
with attribute warn_unused_result
make: *** [net/uip/dhcp.o] Error 1
> tools/kvm/include/kvm/uip.h | 6 ++++++
> tools/kvm/net/uip/dhcp.c | 34 ++++++++++++++++++++++++++++++++++
> 2 files changed, 40 insertions(+), 0 deletions(-)
>
> diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h
> index 6534c7f..e645d3f 100644
> --- a/tools/kvm/include/kvm/uip.h
> +++ b/tools/kvm/include/kvm/uip.h
> @@ -42,6 +42,8 @@
> #define UIP_DHCP_OFFER 2
> #define UIP_DHCP_REQUEST 3
> #define UIP_DHCP_ACK 5
> +#define UIP_DHCP_MAX_DNS_SERVER_NR 3
> +#define UIP_DHCP_MAX_DOMAIN_NAME_LEN 256
> #define UIP_DHCP_TAG_MSG_TYPE 53
> #define UIP_DHCP_TAG_MSG_TYPE_LEN 1
> /*
> @@ -178,6 +180,8 @@ struct uip_info {
> int buf_free_nr;
> int buf_used_nr;
> u32 host_ip;
> + u32 dns_ip[UIP_DHCP_MAX_DNS_SERVER_NR];
> + char *domain_name;
> u32 buf_nr;
> };
>
> @@ -327,4 +331,6 @@ struct uip_buf *uip_buf_clone(struct uip_tx_arg *arg);
>
> int uip_udp_make_pkg(struct uip_info *info, struct uip_udp_socket *sk, struct uip_buf *buf, u8 *payload, int payload_len);
> bool uip_udp_is_dhcp(struct uip_udp *udp);
> +
> +int uip_dhcp_get_dns(struct uip_info *info);
> #endif /* KVM__UIP_H */
> diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c
> index 0a6293a..9321cdc 100644
> --- a/tools/kvm/net/uip/dhcp.c
> +++ b/tools/kvm/net/uip/dhcp.c
> @@ -1,5 +1,7 @@
> #include "kvm/uip.h"
>
> +#include <arpa/inet.h>
> +
> static inline bool uip_dhcp_is_discovery(struct uip_dhcp *dhcp)
> {
> return (dhcp->option[2] == UIP_DHCP_DISCOVER &&
> @@ -29,3 +31,35 @@ bool uip_udp_is_dhcp(struct uip_udp *udp)
>
> return true;
> }
> +
> +int uip_dhcp_get_dns(struct uip_info *info)
> +{
> + char key[256], val[256];
> + struct in_addr addr;
> + int ret = -1;
> + int n = 0;
> + FILE *fp;
> + u32 ip;
> +
> + fp = fopen("/etc/resolv.conf", "r");
> + if (!fp)
> + goto out;
> +
> + while (!feof(fp)) {
> + fscanf(fp, "%s %s\n", key, val);
> + if (strncmp("domain", key, 6) == 0)
> + info->domain_name = strndup(val, UIP_DHCP_MAX_DOMAIN_NAME_LEN);
> + else if (strncmp("nameserver", key, 10) == 0) {
> + if (!inet_aton(val, &addr))
> + continue;
> + ip = ntohl(addr.s_addr);
> + if (n < UIP_DHCP_MAX_DNS_SERVER_NR)
> + info->dns_ip[n++] = ip;
> + ret = 0;
> + }
> + }
> +
> +out:
> + fclose(fp);
> + return ret;
> +}
--
Sasha.
^ permalink raw reply [flat|nested] 21+ messages in thread* Re: [PATCH 05/16] kvm tools: Get domain name and nameserver from host
2011-07-17 9:36 ` Sasha Levin
@ 2011-07-18 4:48 ` Asias He
2011-07-18 8:27 ` Pekka Enberg
0 siblings, 1 reply; 21+ messages in thread
From: Asias He @ 2011-07-18 4:48 UTC (permalink / raw)
To: Sasha Levin; +Cc: Pekka Enberg, Cyrill Gorcunov, Ingo Molnar, Prasad Joshi, kvm
On 07/17/2011 05:36 PM, Sasha Levin wrote:
> On Sun, 2011-07-17 at 16:56 +0800, Asias He wrote:
>> This patch get domain name and nameserver information from host config
>> file /etc/resolv.conf.
>>
>> Guest can obtain DNS information through DHCP.
>>
>> Signed-off-by: Asias He <asias.hejun@gmail.com>
>> ---
>
> Seeing this after this patch:
>
> cc1: warnings being treated as errors
> net/uip/dhcp.c: In function 'uip_dhcp_get_dns':
> net/uip/dhcp.c:49:9: error: ignoring return value of 'fscanf', declared
> with attribute warn_unused_result
> make: *** [net/uip/dhcp.o] Error 1
Yup. We need to check the return value of 'fscanf'.
My gcc (4.6.1) does not catch this by default, I guess we need to enable
this explicitly in our Makefile.
>> tools/kvm/include/kvm/uip.h | 6 ++++++
>> tools/kvm/net/uip/dhcp.c | 34 ++++++++++++++++++++++++++++++++++
>> 2 files changed, 40 insertions(+), 0 deletions(-)
>>
>> diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h
>> index 6534c7f..e645d3f 100644
>> --- a/tools/kvm/include/kvm/uip.h
>> +++ b/tools/kvm/include/kvm/uip.h
>> @@ -42,6 +42,8 @@
>> #define UIP_DHCP_OFFER 2
>> #define UIP_DHCP_REQUEST 3
>> #define UIP_DHCP_ACK 5
>> +#define UIP_DHCP_MAX_DNS_SERVER_NR 3
>> +#define UIP_DHCP_MAX_DOMAIN_NAME_LEN 256
>> #define UIP_DHCP_TAG_MSG_TYPE 53
>> #define UIP_DHCP_TAG_MSG_TYPE_LEN 1
>> /*
>> @@ -178,6 +180,8 @@ struct uip_info {
>> int buf_free_nr;
>> int buf_used_nr;
>> u32 host_ip;
>> + u32 dns_ip[UIP_DHCP_MAX_DNS_SERVER_NR];
>> + char *domain_name;
>> u32 buf_nr;
>> };
>>
>> @@ -327,4 +331,6 @@ struct uip_buf *uip_buf_clone(struct uip_tx_arg *arg);
>>
>> int uip_udp_make_pkg(struct uip_info *info, struct uip_udp_socket *sk, struct uip_buf *buf, u8 *payload, int payload_len);
>> bool uip_udp_is_dhcp(struct uip_udp *udp);
>> +
>> +int uip_dhcp_get_dns(struct uip_info *info);
>> #endif /* KVM__UIP_H */
>> diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c
>> index 0a6293a..9321cdc 100644
>> --- a/tools/kvm/net/uip/dhcp.c
>> +++ b/tools/kvm/net/uip/dhcp.c
>> @@ -1,5 +1,7 @@
>> #include "kvm/uip.h"
>>
>> +#include <arpa/inet.h>
>> +
>> static inline bool uip_dhcp_is_discovery(struct uip_dhcp *dhcp)
>> {
>> return (dhcp->option[2] == UIP_DHCP_DISCOVER &&
>> @@ -29,3 +31,35 @@ bool uip_udp_is_dhcp(struct uip_udp *udp)
>>
>> return true;
>> }
>> +
>> +int uip_dhcp_get_dns(struct uip_info *info)
>> +{
>> + char key[256], val[256];
>> + struct in_addr addr;
>> + int ret = -1;
>> + int n = 0;
>> + FILE *fp;
>> + u32 ip;
>> +
>> + fp = fopen("/etc/resolv.conf", "r");
>> + if (!fp)
>> + goto out;
>> +
>> + while (!feof(fp)) {
>> + fscanf(fp, "%s %s\n", key, val);
>> + if (strncmp("domain", key, 6) == 0)
>> + info->domain_name = strndup(val, UIP_DHCP_MAX_DOMAIN_NAME_LEN);
>> + else if (strncmp("nameserver", key, 10) == 0) {
>> + if (!inet_aton(val, &addr))
>> + continue;
>> + ip = ntohl(addr.s_addr);
>> + if (n < UIP_DHCP_MAX_DNS_SERVER_NR)
>> + info->dns_ip[n++] = ip;
>> + ret = 0;
>> + }
>> + }
>> +
>> +out:
>> + fclose(fp);
>> + return ret;
>> +}
>
>
--
Best Regards,
Asias He
^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH 06/16] kvm tools: Fill DHCP options with domain name and DNS server IP
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (4 preceding siblings ...)
2011-07-17 8:56 ` [PATCH 05/16] kvm tools: Get domain name and nameserver from host Asias He
@ 2011-07-17 8:56 ` Asias He
2011-07-17 8:56 ` [PATCH 07/16] kvm tools: Fill all DHCP options Asias He
` (10 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:56 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
Domain name and DNS server IP address are filled.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/include/kvm/uip.h | 4 ++++
tools/kvm/net/uip/dhcp.c | 27 +++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h
index e645d3f..2586583 100644
--- a/tools/kvm/include/kvm/uip.h
+++ b/tools/kvm/include/kvm/uip.h
@@ -46,6 +46,10 @@
#define UIP_DHCP_MAX_DOMAIN_NAME_LEN 256
#define UIP_DHCP_TAG_MSG_TYPE 53
#define UIP_DHCP_TAG_MSG_TYPE_LEN 1
+#define UIP_DHCP_TAG_DNS_SERVER 6
+#define UIP_DHCP_TAG_DNS_SERVER_LEN 4
+#define UIP_DHCP_TAG_DOMAIN_NAME 15
+
/*
* IP package maxium len == 64 KBytes
* IP header == 20 Bytes
diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c
index 9321cdc..79ddd00 100644
--- a/tools/kvm/net/uip/dhcp.c
+++ b/tools/kvm/net/uip/dhcp.c
@@ -63,3 +63,30 @@ out:
fclose(fp);
return ret;
}
+
+static int uip_dhcp_fill_option_name_and_server(struct uip_info *info, u8 *opt, int i)
+{
+ u8 domain_name_len;
+ u32 *addr;
+ int n;
+
+ if (info->domain_name) {
+ domain_name_len = strlen(info->domain_name);
+ opt[i++] = UIP_DHCP_TAG_DOMAIN_NAME;
+ opt[i++] = domain_name_len;
+ memcpy(&opt[i], info->domain_name, domain_name_len);
+ i += domain_name_len;
+ }
+
+ for (n = 0; n < UIP_DHCP_MAX_DNS_SERVER_NR; n++) {
+ if (info->dns_ip[n] == 0)
+ continue;
+ opt[i++] = UIP_DHCP_TAG_DNS_SERVER;
+ opt[i++] = UIP_DHCP_TAG_DNS_SERVER_LEN;
+ addr = (u32 *)&opt[i];
+ *addr = htonl(info->dns_ip[n]);
+ i += UIP_DHCP_TAG_DNS_SERVER_LEN;
+ }
+
+ return i;
+}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 07/16] kvm tools: Fill all DHCP options
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (5 preceding siblings ...)
2011-07-17 8:56 ` [PATCH 06/16] kvm tools: Fill DHCP options with domain name and DNS server IP Asias He
@ 2011-07-17 8:56 ` Asias He
2011-07-17 8:56 ` [PATCH 08/16] kvm tools: Introduce uip_dhcp_make_pkg() Asias He
` (9 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:56 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
The following DHCP options are filled.
- MSG_TYPE
- SERVER_ID
- LEASE_TIME
- SUBMASK
- ROUTER
- DNS_SERVER
- DOMAIN_NAME
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/include/kvm/uip.h | 12 ++++++++++++
tools/kvm/net/uip/dhcp.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 0 deletions(-)
diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h
index 2586583..e6b1285 100644
--- a/tools/kvm/include/kvm/uip.h
+++ b/tools/kvm/include/kvm/uip.h
@@ -37,6 +37,7 @@
#define UIP_DHCP_FILENAME_LEN 128
#define UIP_DHCP_MAGIC_COOKIE 0x63825363
#define UIP_DHCP_MAGIC_COOKIE_LEN 4
+#define UIP_DHCP_LEASE_TIME 0x00003840
#define UIP_DHCP_OPTION_LEN (UIP_DHCP_VENDOR_SPECIFIC_LEN - UIP_DHCP_MAGIC_COOKIE_LEN)
#define UIP_DHCP_DISCOVER 1
#define UIP_DHCP_OFFER 2
@@ -46,9 +47,18 @@
#define UIP_DHCP_MAX_DOMAIN_NAME_LEN 256
#define UIP_DHCP_TAG_MSG_TYPE 53
#define UIP_DHCP_TAG_MSG_TYPE_LEN 1
+#define UIP_DHCP_TAG_SERVER_ID 54
+#define UIP_DHCP_TAG_SERVER_ID_LEN 4
+#define UIP_DHCP_TAG_LEASE_TIME 51
+#define UIP_DHCP_TAG_LEASE_TIME_LEN 4
+#define UIP_DHCP_TAG_SUBMASK 1
+#define UIP_DHCP_TAG_SUBMASK_LEN 4
+#define UIP_DHCP_TAG_ROUTER 3
+#define UIP_DHCP_TAG_ROUTER_LEN 4
#define UIP_DHCP_TAG_DNS_SERVER 6
#define UIP_DHCP_TAG_DNS_SERVER_LEN 4
#define UIP_DHCP_TAG_DOMAIN_NAME 15
+#define UIP_DHCP_TAG_END 255
/*
* IP package maxium len == 64 KBytes
@@ -183,6 +193,8 @@ struct uip_info {
int udp_epollfd;
int buf_free_nr;
int buf_used_nr;
+ u32 guest_ip;
+ u32 guest_netmask;
u32 host_ip;
u32 dns_ip[UIP_DHCP_MAX_DNS_SERVER_NR];
char *domain_name;
diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c
index 79ddd00..42e354c 100644
--- a/tools/kvm/net/uip/dhcp.c
+++ b/tools/kvm/net/uip/dhcp.c
@@ -90,3 +90,45 @@ static int uip_dhcp_fill_option_name_and_server(struct uip_info *info, u8 *opt,
return i;
}
+static int uip_dhcp_fill_option(struct uip_info *info, struct uip_dhcp *dhcp, int reply_msg_type)
+{
+ int i = 0;
+ u32 *addr;
+ u8 *opt;
+
+ opt = dhcp->option;
+
+ opt[i++] = UIP_DHCP_TAG_MSG_TYPE;
+ opt[i++] = UIP_DHCP_TAG_MSG_TYPE_LEN;
+ opt[i++] = reply_msg_type;
+
+ opt[i++] = UIP_DHCP_TAG_SERVER_ID;
+ opt[i++] = UIP_DHCP_TAG_SERVER_ID_LEN;
+ addr = (u32 *)&opt[i];
+ *addr = htonl(info->host_ip);
+ i += UIP_DHCP_TAG_SERVER_ID_LEN;
+
+ opt[i++] = UIP_DHCP_TAG_LEASE_TIME;
+ opt[i++] = UIP_DHCP_TAG_LEASE_TIME_LEN;
+ addr = (u32 *)&opt[i];
+ *addr = htonl(UIP_DHCP_LEASE_TIME);
+ i += UIP_DHCP_TAG_LEASE_TIME_LEN;
+
+ opt[i++] = UIP_DHCP_TAG_SUBMASK;
+ opt[i++] = UIP_DHCP_TAG_SUBMASK_LEN;
+ addr = (u32 *)&opt[i];
+ *addr = htonl(info->guest_netmask);
+ i += UIP_DHCP_TAG_SUBMASK_LEN;
+
+ opt[i++] = UIP_DHCP_TAG_ROUTER;
+ opt[i++] = UIP_DHCP_TAG_ROUTER_LEN;
+ addr = (u32 *)&opt[i];
+ *addr = htonl(info->host_ip);
+ i += UIP_DHCP_TAG_ROUTER_LEN;
+
+ i = uip_dhcp_fill_option_name_and_server(info, opt, i);
+
+ opt[i++] = UIP_DHCP_TAG_END;
+
+ return 0;
+}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 08/16] kvm tools: Introduce uip_dhcp_make_pkg()
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (6 preceding siblings ...)
2011-07-17 8:56 ` [PATCH 07/16] kvm tools: Fill all DHCP options Asias He
@ 2011-07-17 8:56 ` Asias He
2011-07-17 8:56 ` [PATCH 09/16] kvm tools: Introduce uip_tx_do_ipv4_udp_dhcp() Asias He
` (8 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:56 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
This patch cooks a DHCP package.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/net/uip/dhcp.c | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c
index 42e354c..612e024 100644
--- a/tools/kvm/net/uip/dhcp.c
+++ b/tools/kvm/net/uip/dhcp.c
@@ -132,3 +132,25 @@ static int uip_dhcp_fill_option(struct uip_info *info, struct uip_dhcp *dhcp, in
return 0;
}
+
+static int uip_dhcp_make_pkg(struct uip_info *info, struct uip_udp_socket *sk, struct uip_buf *buf, u8 reply_msg_type)
+{
+ struct uip_dhcp *dhcp;
+
+ dhcp = (struct uip_dhcp *)buf->eth;
+
+ dhcp->msg_type = 2;
+ dhcp->client_ip = 0;
+ dhcp->your_ip = htonl(info->guest_ip);
+ dhcp->server_ip = htonl(info->host_ip);
+ dhcp->agent_ip = 0;
+
+ uip_dhcp_fill_option(info, dhcp, reply_msg_type);
+
+ sk->sip = htonl(info->guest_ip);
+ sk->dip = htonl(info->host_ip);
+ sk->sport = htons(UIP_DHCP_PORT_CLIENT);
+ sk->dport = htons(UIP_DHCP_PORT_SERVER);
+
+ return 0;
+}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 09/16] kvm tools: Introduce uip_tx_do_ipv4_udp_dhcp()
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (7 preceding siblings ...)
2011-07-17 8:56 ` [PATCH 08/16] kvm tools: Introduce uip_dhcp_make_pkg() Asias He
@ 2011-07-17 8:56 ` Asias He
2011-07-17 8:56 ` [PATCH 10/16] kvm tools: Get DNS information from host in uip_init() Asias He
` (7 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:56 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
uip_tx_do_ipv4_udp_dhcp() is used to handle DHCP packages from guest.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/include/kvm/uip.h | 4 ++++
tools/kvm/net/uip/dhcp.c | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h
index e6b1285..344ec09 100644
--- a/tools/kvm/include/kvm/uip.h
+++ b/tools/kvm/include/kvm/uip.h
@@ -29,6 +29,8 @@
#define UIP_TCP_FLAG_ACK 16
#define UIP_TCP_FLAG_URG 32
+#define UIP_BOOTP_VENDOR_SPECIFIC_LEN 64
+#define UIP_BOOTP_MAX_PAYLOAD_LEN 300
#define UIP_DHCP_VENDOR_SPECIFIC_LEN 312
#define UIP_DHCP_PORT_SERVER 67
#define UIP_DHCP_PORT_CLIENT 68
@@ -38,6 +40,7 @@
#define UIP_DHCP_MAGIC_COOKIE 0x63825363
#define UIP_DHCP_MAGIC_COOKIE_LEN 4
#define UIP_DHCP_LEASE_TIME 0x00003840
+#define UIP_DHCP_MAX_PAYLOAD_LEN (UIP_BOOTP_MAX_PAYLOAD_LEN - UIP_BOOTP_VENDOR_SPECIFIC_LEN + UIP_DHCP_VENDOR_SPECIFIC_LEN)
#define UIP_DHCP_OPTION_LEN (UIP_DHCP_VENDOR_SPECIFIC_LEN - UIP_DHCP_MAGIC_COOKIE_LEN)
#define UIP_DHCP_DISCOVER 1
#define UIP_DHCP_OFFER 2
@@ -328,6 +331,7 @@ int uip_tx(struct iovec *iov, u16 out, struct uip_info *info);
int uip_rx(struct iovec *iov, u16 in, struct uip_info *info);
int uip_init(struct uip_info *info);
+int uip_tx_do_ipv4_udp_dhcp(struct uip_tx_arg *arg);
int uip_tx_do_ipv4_icmp(struct uip_tx_arg *arg);
int uip_tx_do_ipv4_tcp(struct uip_tx_arg *arg);
int uip_tx_do_ipv4_udp(struct uip_tx_arg *arg);
diff --git a/tools/kvm/net/uip/dhcp.c b/tools/kvm/net/uip/dhcp.c
index 612e024..865b376 100644
--- a/tools/kvm/net/uip/dhcp.c
+++ b/tools/kvm/net/uip/dhcp.c
@@ -154,3 +154,41 @@ static int uip_dhcp_make_pkg(struct uip_info *info, struct uip_udp_socket *sk, s
return 0;
}
+
+int uip_tx_do_ipv4_udp_dhcp(struct uip_tx_arg *arg)
+{
+ struct uip_udp_socket sk;
+ struct uip_dhcp *dhcp;
+ struct uip_info *info;
+ struct uip_buf *buf;
+ u8 reply_msg_type;
+
+ dhcp = (struct uip_dhcp *)arg->eth;
+
+ if (uip_dhcp_is_discovery(dhcp))
+ reply_msg_type = UIP_DHCP_OFFER;
+ else if (uip_dhcp_is_request(dhcp))
+ reply_msg_type = UIP_DHCP_ACK;
+ else
+ return -1;
+
+ buf = uip_buf_clone(arg);
+ info = arg->info;
+
+ /*
+ * Cook DHCP pkg
+ */
+ uip_dhcp_make_pkg(info, &sk, buf, reply_msg_type);
+
+ /*
+ * Cook UDP pkg
+ */
+ uip_udp_make_pkg(info, &sk, buf, NULL, UIP_DHCP_MAX_PAYLOAD_LEN);
+
+ /*
+ * Send data received from socket to guest
+ */
+ uip_buf_set_used(info, buf);
+
+ return 0;
+}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 10/16] kvm tools: Get DNS information from host in uip_init()
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (8 preceding siblings ...)
2011-07-17 8:56 ` [PATCH 09/16] kvm tools: Introduce uip_tx_do_ipv4_udp_dhcp() Asias He
@ 2011-07-17 8:56 ` Asias He
2011-07-17 8:56 ` [PATCH 11/16] kvm tools: Handle DHCP package in gernal UDP processing path Asias He
` (6 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:56 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
Use uip_dhcp_get_dns() in uip_init() to get DNS information from host
for DHCP.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/net/uip/core.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/tools/kvm/net/uip/core.c b/tools/kvm/net/uip/core.c
index 7a4b824..2e7603c 100644
--- a/tools/kvm/net/uip/core.c
+++ b/tools/kvm/net/uip/core.c
@@ -184,5 +184,7 @@ int uip_init(struct uip_info *info)
info->buf_free_nr = buf_nr;
info->buf_used_nr = 0;
+ uip_dhcp_get_dns(info);
+
return 0;
}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 11/16] kvm tools: Handle DHCP package in gernal UDP processing path
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (9 preceding siblings ...)
2011-07-17 8:56 ` [PATCH 10/16] kvm tools: Get DNS information from host in uip_init() Asias He
@ 2011-07-17 8:56 ` Asias He
2011-07-17 8:57 ` [PATCH 12/16] kvm tools: Introduce --guest-ip option Asias He
` (5 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:56 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
DHCP packages are handled by the hypervisor, they are not sent to remote
servers. In contrast, all other non-DHCP UDP packages are sent to remote
servers.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/net/uip/udp.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/tools/kvm/net/uip/udp.c b/tools/kvm/net/uip/udp.c
index fcd5018..39c2b57 100644
--- a/tools/kvm/net/uip/udp.c
+++ b/tools/kvm/net/uip/udp.c
@@ -210,6 +210,11 @@ int uip_tx_do_ipv4_udp(struct uip_tx_arg *arg)
ip = (struct uip_ip *)(arg->eth);
info = arg->info;
+ if (uip_udp_is_dhcp(udp)) {
+ uip_tx_do_ipv4_udp_dhcp(arg);
+ return 0;
+ }
+
/*
* Find socket we have allocated before, otherwise allocate one
*/
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 12/16] kvm tools: Introduce --guest-ip option
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (10 preceding siblings ...)
2011-07-17 8:56 ` [PATCH 11/16] kvm tools: Handle DHCP package in gernal UDP processing path Asias He
@ 2011-07-17 8:57 ` Asias He
2011-07-17 8:57 ` [PATCH 13/16] kvm tools: Introduce --host-mac option Asias He
` (4 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:57 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
The --guest-ip option tells which IP address to give guest through DHCP.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/builtin-run.c | 8 ++++++++
tools/kvm/include/kvm/virtio-net.h | 5 +++--
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 8b7d08b..01a1de2 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -45,6 +45,7 @@
#define DEFAULT_CONSOLE "serial"
#define DEFAULT_NETWORK "user"
#define DEFAULT_HOST_ADDR "192.168.33.1"
+#define DEFAULT_GUEST_ADDR "192.168.33.15"
#define DEFAULT_GUEST_MAC "00:15:15:15:15:15"
#define DEFAULT_SCRIPT "none"
@@ -68,6 +69,7 @@ static const char *console;
static const char *kvm_dev;
static const char *network;
static const char *host_ip_addr;
+static const char *guest_ip;
static const char *guest_mac;
static const char *script;
static const char *guest_name;
@@ -164,6 +166,8 @@ static const struct option options[] = {
"Network to use"),
OPT_STRING('\0', "host-ip-addr", &host_ip_addr, "a.b.c.d",
"Assign this address to the host side networking"),
+ OPT_STRING('\0', "guest-ip", &guest_ip, "a.b.c.d",
+ "Assign this address to the guest side networking"),
OPT_STRING('\0', "guest-mac", &guest_mac, "aa:bb:cc:dd:ee:ff",
"Assign this address to the guest side NIC"),
OPT_STRING('\0', "tapscript", &script, "Script path",
@@ -542,6 +546,9 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
if (!host_ip_addr)
host_ip_addr = DEFAULT_HOST_ADDR;
+ if (!guest_ip)
+ guest_ip = DEFAULT_GUEST_ADDR;
+
if (!guest_mac)
guest_mac = DEFAULT_GUEST_MAC;
@@ -647,6 +654,7 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
if (strncmp(network, "none", 4)) {
net_params.host_ip = host_ip_addr;
+ net_params.guest_ip = guest_ip;
net_params.kvm = kvm;
net_params.script = script;
sscanf(guest_mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
diff --git a/tools/kvm/include/kvm/virtio-net.h b/tools/kvm/include/kvm/virtio-net.h
index e93e8e4..9ff0e15 100644
--- a/tools/kvm/include/kvm/virtio-net.h
+++ b/tools/kvm/include/kvm/virtio-net.h
@@ -4,10 +4,11 @@
struct kvm;
struct virtio_net_parameters {
- struct kvm *kvm;
+ const char *guest_ip;
const char *host_ip;
- char guest_mac[6];
const char *script;
+ char guest_mac[6];
+ struct kvm *kvm;
int mode;
};
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 13/16] kvm tools: Introduce --host-mac option
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (11 preceding siblings ...)
2011-07-17 8:57 ` [PATCH 12/16] kvm tools: Introduce --guest-ip option Asias He
@ 2011-07-17 8:57 ` Asias He
2011-07-17 8:57 ` [PATCH 14/16] kvm tools: Rename --host-ip-addr to --host-ip Asias He
` (3 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:57 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
The --host-mac option sets up MAC address of host.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/builtin-run.c | 14 ++++++++++++++
tools/kvm/include/kvm/virtio-net.h | 1 +
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 01a1de2..12cf75b 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -47,6 +47,7 @@
#define DEFAULT_HOST_ADDR "192.168.33.1"
#define DEFAULT_GUEST_ADDR "192.168.33.15"
#define DEFAULT_GUEST_MAC "00:15:15:15:15:15"
+#define DEFAULT_HOST_MAC "00:01:01:01:01:01"
#define DEFAULT_SCRIPT "none"
#define MB_SHIFT (20)
@@ -71,6 +72,7 @@ static const char *network;
static const char *host_ip_addr;
static const char *guest_ip;
static const char *guest_mac;
+static const char *host_mac;
static const char *script;
static const char *guest_name;
static bool single_step;
@@ -168,6 +170,8 @@ static const struct option options[] = {
"Assign this address to the host side networking"),
OPT_STRING('\0', "guest-ip", &guest_ip, "a.b.c.d",
"Assign this address to the guest side networking"),
+ OPT_STRING('\0', "host-mac", &host_mac, "aa:bb:cc:dd:ee:ff",
+ "Assign this address to the host side NIC"),
OPT_STRING('\0', "guest-mac", &guest_mac, "aa:bb:cc:dd:ee:ff",
"Assign this address to the guest side NIC"),
OPT_STRING('\0', "tapscript", &script, "Script path",
@@ -552,6 +556,9 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
if (!guest_mac)
guest_mac = DEFAULT_GUEST_MAC;
+ if (!host_mac)
+ host_mac = DEFAULT_HOST_MAC;
+
if (!script)
script = DEFAULT_SCRIPT;
@@ -664,6 +671,13 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
net_params.guest_mac+3,
net_params.guest_mac+4,
net_params.guest_mac+5);
+ sscanf(host_mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
+ net_params.host_mac,
+ net_params.host_mac+1,
+ net_params.host_mac+2,
+ net_params.host_mac+3,
+ net_params.host_mac+4,
+ net_params.host_mac+5);
if (!strncmp(network, "user", 4))
net_params.mode = NET_MODE_USER;
diff --git a/tools/kvm/include/kvm/virtio-net.h b/tools/kvm/include/kvm/virtio-net.h
index 9ff0e15..c30deb8 100644
--- a/tools/kvm/include/kvm/virtio-net.h
+++ b/tools/kvm/include/kvm/virtio-net.h
@@ -8,6 +8,7 @@ struct virtio_net_parameters {
const char *host_ip;
const char *script;
char guest_mac[6];
+ char host_mac[6];
struct kvm *kvm;
int mode;
};
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 14/16] kvm tools: Rename --host-ip-addr to --host-ip
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (12 preceding siblings ...)
2011-07-17 8:57 ` [PATCH 13/16] kvm tools: Introduce --host-mac option Asias He
@ 2011-07-17 8:57 ` Asias He
2011-07-17 8:57 ` [PATCH 15/16] kvm tools: Initialize MAC address for virtio net properly Asias He
` (2 subsequent siblings)
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:57 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
This patch makes the network options more consistent.
We are having:
--host-ip
--host-mac
--guest-ip
--guest-mac
now.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/builtin-run.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 12cf75b..af2e089 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -69,7 +69,7 @@ static const char *image_filename[MAX_DISK_IMAGES];
static const char *console;
static const char *kvm_dev;
static const char *network;
-static const char *host_ip_addr;
+static const char *host_ip;
static const char *guest_ip;
static const char *guest_mac;
static const char *host_mac;
@@ -166,7 +166,7 @@ static const struct option options[] = {
OPT_GROUP("Networking options:"),
OPT_STRING('n', "network", &network, "user, tap, none",
"Network to use"),
- OPT_STRING('\0', "host-ip-addr", &host_ip_addr, "a.b.c.d",
+ OPT_STRING('\0', "host-ip", &host_ip, "a.b.c.d",
"Assign this address to the host side networking"),
OPT_STRING('\0', "guest-ip", &guest_ip, "a.b.c.d",
"Assign this address to the guest side networking"),
@@ -547,8 +547,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
else
active_console = CONSOLE_8250;
- if (!host_ip_addr)
- host_ip_addr = DEFAULT_HOST_ADDR;
+ if (!host_ip)
+ host_ip = DEFAULT_HOST_ADDR;
if (!guest_ip)
guest_ip = DEFAULT_GUEST_ADDR;
@@ -660,8 +660,8 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
network = DEFAULT_NETWORK;
if (strncmp(network, "none", 4)) {
- net_params.host_ip = host_ip_addr;
net_params.guest_ip = guest_ip;
+ net_params.host_ip = host_ip;
net_params.kvm = kvm;
net_params.script = script;
sscanf(guest_mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 15/16] kvm tools: Initialize MAC address for virtio net properly
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (13 preceding siblings ...)
2011-07-17 8:57 ` [PATCH 14/16] kvm tools: Rename --host-ip-addr to --host-ip Asias He
@ 2011-07-17 8:57 ` Asias He
2011-07-17 8:57 ` [PATCH 16/16] kvm tools: Initialize MAC and IP address for uip properly Asias He
2011-07-18 10:20 ` [PATCH 00/16] Implement DHCP support for user mode network Pekka Enberg
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:57 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
- Drop static initialization
- Move the initializtion out of tap init
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/virtio/net.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index f4ba79a..af9b740 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -82,7 +82,6 @@ static struct net_dev ndev = {
.mutex = PTHREAD_MUTEX_INITIALIZER,
.config = {
- .mac = {0x00, 0x15, 0x15, 0x15, 0x15, 0x15},
.status = VIRTIO_NET_S_LINK_UP,
},
.host_features = 1UL << VIRTIO_NET_F_MAC
@@ -318,13 +317,10 @@ static struct ioport_operations virtio_net_io_ops = {
static bool virtio_net__tap_init(const struct virtio_net_parameters *params)
{
int sock = socket(AF_INET, SOCK_STREAM, 0);
- int i, pid, status, offload, hdr_len;
+ int pid, status, offload, hdr_len;
struct sockaddr_in sin = {0};
struct ifreq ifr;
- for (i = 0 ; i < 6 ; i++)
- ndev.config.mac[i] = params->guest_mac[i];
-
ndev.tap_fd = open("/dev/net/tun", O_RDWR);
if (ndev.tap_fd < 0) {
pr_warning("Unable to open /dev/net/tun");
@@ -459,6 +455,9 @@ void virtio_net__init(const struct virtio_net_parameters *params)
ndev.base_addr = net_base_addr;
pci__register(&pci_header, dev);
+ for (i = 0 ; i < 6 ; i++)
+ ndev.config.mac[i] = params->guest_mac[i];
+
ndev.mode = params->mode;
if (ndev.mode == NET_MODE_TAP) {
virtio_net__tap_init(params);
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* [PATCH 16/16] kvm tools: Initialize MAC and IP address for uip properly
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (14 preceding siblings ...)
2011-07-17 8:57 ` [PATCH 15/16] kvm tools: Initialize MAC address for virtio net properly Asias He
@ 2011-07-17 8:57 ` Asias He
2011-07-18 10:20 ` [PATCH 00/16] Implement DHCP support for user mode network Pekka Enberg
16 siblings, 0 replies; 21+ messages in thread
From: Asias He @ 2011-07-17 8:57 UTC (permalink / raw)
To: Pekka Enberg
Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm,
Asias He
- Drop static initialization
- Use {host,guet}_{ip,mac} to initialize
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/virtio/net.c | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/tools/kvm/virtio/net.c b/tools/kvm/virtio/net.c
index af9b740..739f157 100644
--- a/tools/kvm/virtio/net.c
+++ b/tools/kvm/virtio/net.c
@@ -93,9 +93,6 @@ static struct net_dev ndev = {
| 1UL << VIRTIO_NET_F_GUEST_TSO4
| 1UL << VIRTIO_NET_F_GUEST_TSO6,
.info = {
- .host_mac.addr = {0x00, 0x01, 0x01, 0x01, 0x01, 0x01},
- .guest_mac.addr = {0x00, 0x15, 0x15, 0x15, 0x15, 0x15},
- .host_ip = 0xc0a82101,
.buf_nr = 20,
}
};
@@ -455,14 +452,20 @@ void virtio_net__init(const struct virtio_net_parameters *params)
ndev.base_addr = net_base_addr;
pci__register(&pci_header, dev);
- for (i = 0 ; i < 6 ; i++)
- ndev.config.mac[i] = params->guest_mac[i];
+ for (i = 0 ; i < 6 ; i++) {
+ ndev.config.mac[i] = params->guest_mac[i];
+ ndev.info.guest_mac.addr[i] = params->guest_mac[i];
+ ndev.info.host_mac.addr[i] = params->host_mac[i];
+ }
ndev.mode = params->mode;
if (ndev.mode == NET_MODE_TAP) {
virtio_net__tap_init(params);
ndev.ops = &tap_ops;
} else {
+ ndev.info.host_ip = ntohl(inet_addr(params->host_ip));
+ ndev.info.guest_ip = ntohl(inet_addr(params->guest_ip));
+ ndev.info.guest_netmask = ntohl(inet_addr("255.255.255.0"));
uip_init(&ndev.info);
ndev.ops = &uip_ops;
}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 21+ messages in thread* Re: [PATCH 00/16] Implement DHCP support for user mode network
2011-07-17 8:56 [PATCH 00/16] Implement DHCP support for user mode network Asias He
` (15 preceding siblings ...)
2011-07-17 8:57 ` [PATCH 16/16] kvm tools: Initialize MAC and IP address for uip properly Asias He
@ 2011-07-18 10:20 ` Pekka Enberg
16 siblings, 0 replies; 21+ messages in thread
From: Pekka Enberg @ 2011-07-18 10:20 UTC (permalink / raw)
To: Asias He; +Cc: Cyrill Gorcunov, Ingo Molnar, Sasha Levin, Prasad Joshi, kvm
On Sun, 2011-07-17 at 16:56 +0800, Asias He wrote:
> This patch set implements DHCP support for user mode network.
>
> This patch set complements the "Implement user mode network for kvm
> tools" patch set and makes the Zero-Configuration Network happen.
>
> To use this:
> No configuration is needed in host side, just enable DHCP in your guest OS.
Woohoo! This is super-cool feature, Asias. Applied!
Pekka
^ permalink raw reply [flat|nested] 21+ messages in thread