From: Asias He <asias.hejun@gmail.com>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: Pekka Enberg <penberg@kernel.org>,
Cyrill Gorcunov <gorcunov@gmail.com>, Ingo Molnar <mingo@elte.hu>,
Prasad Joshi <prasadjoshi124@gmail.com>,
kvm@vger.kernel.org
Subject: Re: [PATCH 05/16] kvm tools: Get domain name and nameserver from host
Date: Mon, 18 Jul 2011 12:48:46 +0800 [thread overview]
Message-ID: <4E23BB2E.7000902@gmail.com> (raw)
In-Reply-To: <1310895376.2393.29.camel@sasha>
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
next prev parent reply other threads:[~2011-07-18 4:50 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` [PATCH 03/16] kvm tools: Add helper to tell if a UDP package is a DHCP package Asias He
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 ` [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 [this message]
2011-07-18 8:27 ` Pekka Enberg
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 ` [PATCH 07/16] kvm tools: Fill all DHCP options Asias He
2011-07-17 8:56 ` [PATCH 08/16] kvm tools: Introduce uip_dhcp_make_pkg() Asias He
2011-07-17 8:56 ` [PATCH 09/16] kvm tools: Introduce uip_tx_do_ipv4_udp_dhcp() Asias He
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 ` [PATCH 11/16] kvm tools: Handle DHCP package in gernal UDP processing path Asias He
2011-07-17 8:57 ` [PATCH 12/16] kvm tools: Introduce --guest-ip option Asias He
2011-07-17 8:57 ` [PATCH 13/16] kvm tools: Introduce --host-mac option Asias He
2011-07-17 8:57 ` [PATCH 14/16] kvm tools: Rename --host-ip-addr to --host-ip Asias He
2011-07-17 8:57 ` [PATCH 15/16] kvm tools: Initialize MAC address for virtio net properly 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
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=4E23BB2E.7000902@gmail.com \
--to=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=levinsasha928@gmail.com \
--cc=mingo@elte.hu \
--cc=penberg@kernel.org \
--cc=prasadjoshi124@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.