@@ -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;
@@ -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;
+}
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(-)