"Reprint please indicate source: Changuo column http://blog.csdn.net/qianguozheng/article/details/37666829" cause
In order to solve the customer reflects the OPENWRT system can not network problems, we have Remote Assistance, found that IP can be accessed, but the domain name is not accessible, which helps us locate the problem---DNS.
Search Online
Found a similar problem, said that the domain name server can not be used, the same is 20M fiber dialing, is really a coincidence ah, to the internet search the friend of the net name, find a lot, but recently published not much Oh, no fruit, see the code to check.
Code Analysis
From dial-up to find/lib/netifd script, no fruit, look at the online process, and found that there is such a process netifd, since this, then look at the source code.
At this point, and found the "http://xinliang.me/blog/?p=149", the Brother's blog, is definitely a pioneer, to see his things are very organized, learned, OpenWrt is really using ubus similar to the Linux distribution on the Dbus, Ubus is mainly used for system interprocess communication, for more information, please visit this Brother's blog.
The Ubus RPC interface for NFETIFD is as follows:
<span style= "FONT-SIZE:18PX;" >static struct Ubus_method main_object_methods[] = {
. Name = ' Restart ',. Handler = Netifd_handle_restart},
{ . Name = "Reload",. Handler = Netifd_handle_reload},
Ubus_method ("Add_host_route", Netifd_add_host_route, Route_ Policy),
{. Name = "Get_proto_handlers",. Handler = netifd_get_proto_handlers},
Ubus_method ("Add_dynamic", Netifd_add_dynamic, Dynamic_policy),
};
static struct Ubus_object_type Main_object_type =
ubus_object_type ("Netifd", main_object_methods);
static struct Ubus_object Main_object = {
. Name = "Network",
. Type = &main_object_type,
. Methods = Main _object_methods,
. N_methods = Array_size (main_object_methods),
};
</span>
The specific registered object is below
<span style="font-size:18px;">root@YSWiFi:/etc/config# ubus list -v
'dhcp' @8f0c907e
"ipv4leases":{}
"ipv6leases":{}
'log' @92083360
"read":{"lines":"Integer"}
"write":{"event":"String"}
<span style="color:#000099;">'network' @36acc569
"restart":{}
"reload":{}
"add_host_route":{"target":"String","v6":"Boolean","interface":"String"}
"get_proto_handlers":{}
"add_dynamic":{"name":"String"}</span>
'network.device' @7b6892b7
"status":{"name":"String"}
"set_alias":{"alias":"Array","device":"String"}
"set_state":{"name":"String","defer":"Boolean"}
'network.interface' @e62dccc3
"up":{}
"down":{}
"status":{}
"prepare":{}
"dump":{}
"add_device":{"name":"String"}
"remove_device":{"name":"String"}
"notify_proto":{}
"remove":{}
"set_data":{}
'network.interface.lan' @817ffe0f
"up":{}
"down":{}
"status":{}
"prepare":{}
"dump":{}
"add_device":{"name":"String"}
"remove_device":{"name":"String"}
"notify_proto":{}
"remove":{}
"set_data":{}
'network.interface.lan2' @137330bd
"up":{}
"down":{}
"status":{}
"prepare":{}
"dump":{}
"add_device":{"name":"String"}
"remove_device":{"name":"String"}
"notify_proto":{}
"remove":{}
"set_data":{}
'network.interface.loopback' @44806906
"up":{}
"down":{}
"status":{}
"prepare":{}
"dump":{}
"add_device":{"name":"String"}
"remove_device":{"name":"String"}
"notify_proto":{}
"remove":{}
"set_data":{}
'network.interface.wan' @4ebe9d3b
"up":{}
"down":{}
"status":{}
"prepare":{}
"dump":{}
"add_device":{"name":"String"}
"remove_device":{"name":"String"}
"notify_proto":{}
"remove":{}
"set_data":{}
'network.wireless' @9a257aa5
"up":{}
"down":{}
"status":{}
"notify":{}
'service' @582b527e
"set":{"name":"String","script":"String","instances":"Table","triggers":"Array","validate":"Array"}
"add":{"name":"String","script":"String","instances":"Table","triggers":"Array","validate":"Array"}
"list":{"name":"String"}
"delete":{"name":"String","instance":"String"}
"update_start":{"name":"String"}
"update_complete":{"name":"String"}
"event":{"type":"String","data":"Table"}
"validate":{"package":"String","type":"String","service":"String"}
'system' @d8c56a4b
"board":{}
"info":{}
"upgrade":{}
"watchdog":{"frequency":"Integer","timeout":"Integer","stop":"Boolean"}
"signal":{"pid":"Integer","signum":"Integer"}
root@YSWiFi:/etc/config# </span>
In short, the question I'm looking for is how the Resolv.conf.auto is generated, and by whom, the NETIFD updates the status when the WAN is up, and fills in the Resolv.conf.auto file according to the DNS address of the acquired heart.
Netifd.h
<span style= "FONT-SIZE:18PX;" > #ifdef dummy_mode
#define Default_main_path " ./examples"
#define DEFAULT_CONFIG_PATH ". / Config "
#define Default_hotplug_path "./examples/hotplug-cmd "
#define DEFAULT_RESOLV_CONF "./tmp /resolv.conf "
#else
#define Default_main_path" /lib/netifd "
#define Default_config_path NULL/* Use the default set in Libuci */
#define DEFAULT_HOTPLUG_PATH "/sbin/hotplug-call"
<span style = "COLOR: #000099;" > #define DEFAULT_RESOLV_CONF "/tmp/resolv.conf.auto" </span>
#endif </span>
Interface-ip.c
<span style="font-size:18px;">void
interface_write_resolv_conf(void)
{
struct interface *iface;
char *path = alloca(strlen(resolv_conf) + 5);
FILE *f;
uint32_t crcold, crcnew;
sprintf(path, "%s.tmp", resolv_conf);
unlink(path);
f = fopen(path, "w+");
if (!f) {
D(INTERFACE, "Failed to open %s for writing\n", path);
return;
}
vlist_for_each_element(&interfaces, iface, node) {
if (iface->state != IFS_UP)
continue;
if (vlist_simple_empty(&iface->proto_ip.dns_search) &&
vlist_simple_empty(&iface->proto_ip.dns_servers) &&
vlist_simple_empty(&iface->config_ip.dns_search) &&
vlist_simple_empty(&iface->config_ip.dns_servers))
continue;
fprintf(f, "# Interface %s\n", iface->name);
write_resolv_conf_entries(f, &iface->config_ip);
if (!iface->proto_ip.no_dns)
write_resolv_conf_entries(f, &iface->proto_ip);
}
fflush(f);
rewind(f);
crcnew = crc32_file(f);
fclose(f);
crcold = crcnew + 1;
f = fopen(resolv_conf, "r");
if (f) {
crcold = crc32_file(f);
fclose(f);
}
if (crcold == crcnew) {
unlink(path);
} else if (rename(path, resolv_conf) < 0) {
D(INTERFACE, "Failed to replace %s\n", resolv_conf);
unlink(path);
}
}
</span>
Summary:
Although it is not easy to find out where to produce the document, it is difficult to solve it or reproduce it. So I took a compromise to specify that each client's DNS server 8.8.8.8, 8.8.4.4 for Google's DNS server.
"Reprint please indicate the Source: Changuo column http://blog.csdn.net/qianguozheng/article/details/37666829"