From: Asias He Date: Sun, 17 Jul 2011 08:56:55 +0000 (+0800) Subject: kvm tools: Fill all DHCP options X-Git-Tag: next-20110824~3^2~100 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=68f823a6e1add21f5930ee43b62a2c670d940a1e;p=karo-tx-linux.git kvm tools: Fill all DHCP options The following DHCP options are filled. - MSG_TYPE - SERVER_ID - LEASE_TIME - SUBMASK - ROUTER - DNS_SERVER - DOMAIN_NAME Signed-off-by: Asias He Signed-off-by: Pekka Enberg --- diff --git a/tools/kvm/include/kvm/uip.h b/tools/kvm/include/kvm/uip.h index 25865833beed..e6b12853223d 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 60c203002a67..b4df37f39ceb 100644 --- a/tools/kvm/net/uip/dhcp.c +++ b/tools/kvm/net/uip/dhcp.c @@ -91,3 +91,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; +}