From: Asias He Date: Sun, 17 Jul 2011 08:56:54 +0000 (+0800) Subject: kvm tools: Fill DHCP options with domain name and DNS server IP X-Git-Tag: next-20110824~3^2~101 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=49cf05f22ffdf393f170d17c6e0a9a7926b7f321;p=karo-tx-linux.git kvm tools: Fill DHCP options with domain name and DNS server IP Domain name and DNS server IP address are filled. 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 e645d3f15be9..25865833beed 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 be8b616f0ac6..60c203002a67 100644 --- a/tools/kvm/net/uip/dhcp.c +++ b/tools/kvm/net/uip/dhcp.c @@ -64,3 +64,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; +}