Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1297241
  • 博文数量: 254
  • 博客积分: 1586
  • 博客等级: 上尉
  • 技术积分: 2295
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-15 16:38
个人简介

linux学习中

文章分类

全部博文(254)

文章存档

2016年(6)

2015年(2)

2014年(74)

2013年(93)

2012年(12)

2011年(2)

2010年(51)

2009年(14)

分类: 嵌入式

2014-11-27 10:14:49

原文地址:http://blog.csdn.net/qianguozheng/article/details/37666829

起因


为了解决客户反映的openwrt系统上不了网的问题,我们对其进行了远程协助,发现ip可以访问,只是域名访问不了,这就帮助我们定位了问题---DNS.


网上搜寻


找到了个有同样的问题,说是域名服务器不能用,同样是20M光纤拨号,真是巧合啊,到网上搜了这个哥们的网名,找到不少,但是最近发表的不多哦,无果,自己看代码查查。


代码分析


从拨号进行找了/lib/netifd脚本,无果,自己看看在线进程,发现竟然存在这么一个进程 netifd, 既然这样,那就看看源代码吧。

至此,又发现了【http://xinliang.me/blog/?p=149】,这位兄弟的博客,绝对是先驱,看他的东西很有条理,学习到了,openwrt下果然是使用ubus类似Linux发行版上的dbus, ubus主要是用于系统进程间通信,关于详情,请访问这个哥的博客。


nfetifd的ubus RPC接口如下:

  1. "font-size:18px;">static struct ubus_method main_object_methods[] = {
  2. { .name = "restart", .handler = netifd_handle_restart },
  3. { .name = "reload", .handler = netifd_handle_reload },
  4. UBUS_METHOD("add_host_route", netifd_add_host_route, route_policy),
  5. { .name = "get_proto_handlers", .handler = netifd_get_proto_handlers },
  6. UBUS_METHOD("add_dynamic", netifd_add_dynamic, dynamic_policy),
  7. };
  8. static struct ubus_object_type main_object_type =
  9. UBUS_OBJECT_TYPE("netifd", main_object_methods);
  10. static struct ubus_object main_object = {
  11. .name = "network",
  12. .type = &main_object_type,
  13. .methods = main_object_methods,
  14. .n_methods = ARRAY_SIZE(main_object_methods),
  15. };

具体注册的对象在下面
  1. "font-size:18px;">root@YSWiFi:/etc/config# ubus list -v
  2. 'dhcp' @8f0c907e
  3. "ipv4leases":{}
  4. "ipv6leases":{}
  5. 'log' @92083360
  6. "read":{"lines":"Integer"}
  7. "write":{"event":"String"}
  8. "color:#000099;">'network' @36acc569
  9. "restart":{}
  10. "reload":{}
  11. "add_host_route":{"target":"String","v6":"Boolean","interface":"String"}
  12. "get_proto_handlers":{}
  13. "add_dynamic":{"name":"String"}
  14. 'network.device' @7b6892b7
  15. "status":{"name":"String"}
  16. "set_alias":{"alias":"Array","device":"String"}
  17. "set_state":{"name":"String","defer":"Boolean"}
  18. 'network.interface' @e62dccc3
  19. "up":{}
  20. "down":{}
  21. "status":{}
  22. "prepare":{}
  23. "dump":{}
  24. "add_device":{"name":"String"}
  25. "remove_device":{"name":"String"}
  26. "notify_proto":{}
  27. "remove":{}
  28. "set_data":{}
  29. 'network.interface.lan' @817ffe0f
  30. "up":{}
  31. "down":{}
  32. "status":{}
  33. "prepare":{}
  34. "dump":{}
  35. "add_device":{"name":"String"}
  36. "remove_device":{"name":"String"}
  37. "notify_proto":{}
  38. "remove":{}
  39. "set_data":{}
  40. 'network.interface.lan2' @137330bd
  41. "up":{}
  42. "down":{}
  43. "status":{}
  44. "prepare":{}
  45. "dump":{}
  46. "add_device":{"name":"String"}
  47. "remove_device":{"name":"String"}
  48. "notify_proto":{}
  49. "remove":{}
  50. "set_data":{}
  51. 'network.interface.loopback' @44806906
  52. "up":{}
  53. "down":{}
  54. "status":{}
  55. "prepare":{}
  56. "dump":{}
  57. "add_device":{"name":"String"}
  58. "remove_device":{"name":"String"}
  59. "notify_proto":{}
  60. "remove":{}
  61. "set_data":{}
  62. 'network.interface.wan' @4ebe9d3b
  63. "up":{}
  64. "down":{}
  65. "status":{}
  66. "prepare":{}
  67. "dump":{}
  68. "add_device":{"name":"String"}
  69. "remove_device":{"name":"String"}
  70. "notify_proto":{}
  71. "remove":{}
  72. "set_data":{}
  73. 'network.wireless' @9a257aa5
  74. "up":{}
  75. "down":{}
  76. "status":{}
  77. "notify":{}
  78. 'service' @582b527e
  79. "set":{"name":"String","script":"String","instances":"Table","triggers":"Array","validate":"Array"}
  80. "add":{"name":"String","script":"String","instances":"Table","triggers":"Array","validate":"Array"}
  81. "list":{"name":"String"}
  82. "delete":{"name":"String","instance":"String"}
  83. "update_start":{"name":"String"}
  84. "update_complete":{"name":"String"}
  85. "event":{"type":"String","data":"Table"}
  86. "validate":{"package":"String","type":"String","service":"String"}
  87. 'system' @d8c56a4b
  88. "board":{}
  89. "info":{}
  90. "upgrade":{}
  91. "watchdog":{"frequency":"Integer","timeout":"Integer","stop":"Boolean"}
  92. "signal":{"pid":"Integer","signum":"Integer"}
  93. root@YSWiFi:/etc/config#

简单来说,我想找的问题,就是resolv.conf.auto是如何产生的,是由谁产生的, 在wan口up的时候netifd进行会更新状态,根据获得的心的DNS地址填写这个resolv.conf.auto文件。

netifd.h

  1. "font-size:18px;">#ifdef DUMMY_MODE
  2. #define DEFAULT_MAIN_PATH "./examples"
  3. #define DEFAULT_CONFIG_PATH "./config"
  4. #define DEFAULT_HOTPLUG_PATH "./examples/hotplug-cmd"
  5. #define DEFAULT_RESOLV_CONF "./tmp/resolv.conf"
  6. #else
  7. #define DEFAULT_MAIN_PATH "/lib/netifd"
  8. #define DEFAULT_CONFIG_PATH NULL /* use the default set in libuci */
  9. #define DEFAULT_HOTPLUG_PATH "/sbin/hotplug-call"
  10. "color:#000099;">#define DEFAULT_RESOLV_CONF "/tmp/resolv.conf.auto"
  11. #endif


interface-ip.c

  1. "font-size:18px;">void
  2. interface_write_resolv_conf(void)
  3. {
  4. struct interface *iface;
  5. charchar *path = alloca(strlen(resolv_conf) + 5);
  6. FILEFILE *f;
  7. uint32_t crcold, crcnew;
  8. sprintf(path, "%s.tmp", resolv_conf);
  9. unlink(path);
  10. f = fopen(path, "w+");
  11. if (!f) {
  12. D(INTERFACE, "Failed to open %s for writing\n", path);
  13. return;
  14. }
  15. vlist_for_each_element(&interfaces, iface, node) {
  16. if (iface->state != IFS_UP)
  17. continue;
  18. if (vlist_simple_empty(&iface->proto_ip.dns_search) &&
  19. vlist_simple_empty(&iface->proto_ip.dns_servers) &&
  20. vlist_simple_empty(&iface->config_ip.dns_search) &&
  21. vlist_simple_empty(&iface->config_ip.dns_servers))
  22. continue;
  23. fprintf(f, "# Interface %s\n", iface->name);
  24. write_resolv_conf_entries(f, &iface->config_ip);
  25. if (!iface->proto_ip.no_dns)
  26. write_resolv_conf_entries(f, &iface->proto_ip);
  27. }
  28. fflush(f);
  29. rewind(f);
  30. crcnew = crc32_file(f);
  31. fclose(f);
  32. crcold = crcnew + 1;
  33. f = fopen(resolv_conf, "r");
  34. if (f) {
  35. crcold = crc32_file(f);
  36. fclose(f);
  37. }
  38. if (crcold == crcnew) {
  39. unlink(path);
  40. } else if (rename(path, resolv_conf) < 0) {
  41. D(INTERFACE, "Failed to replace %s\n", resolv_conf);
  42. unlink(path);
  43. }
  44. }



总结:


虽然找到了在哪里生产的文件,要一下子解决或者是重现这个问题可不容易。所以我采取了一种折中的方法,指定每个客户端的DNS服务器为google的DNS服务器8.8.8.8 , 8.8.4.4.



阅读(2527) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~