bind 架构

这个系列的文章大多源于网络和自己的总结。关于bind分析的文章网络不是很多,由于我的水平有限,错误在所难免。欢迎大家批评指正。

博客中大部分的函数调用关系图来自
http://www.sourcecodebrowser.com/

BIND官方网站
https://www.isc.org/downloads/bind/

BIND and DNS

源引bind官网中的叙述。
The DNS protocols are part of the core Internet standards. They specify the process by which one computer can find another computer on the basis of its name. The BIND software distribution contains all of the software necessary for asking and answering name service questions.

The BIND software distribution has three parts:

  1. Domain Name Resolver

A resolver is a program that resolves questions about names by sending those questions to appropriate servers and responding appropriately to the servers’ replies. In the most common application, a web browser uses a local stub resolver library on the same computer to look up names in the DNS. That stub resolver is part of the operating system. (Many operating system distributions use the BIND resolver library.) The stub resolver usually will forward queries to a caching resolver, a server or group of servers on the network dedicated to DNS services. Those resolvers will send queries to one or multiple authoritative servers in order to find the IP address for that DNS name.

  1. Domain Name Authority server

An authoritative DNS server answers requests from resolvers, using information about the domain names it is authoritative for. You can provide DNS services on the Internet by installing this software on a server and giving it information about your domain names.

  1. Tools

We include a number of diagnostic and operational tools. Some of them, such as the popular DIG tool, are not specific to BIND and can be used with any DNS server.

概述

本篇主要介绍bind实现的架构不涉及具体细节分析。后续会不断完善。
1.Bind中的socket采用的是epoll模型
2.Bind业务处理主要要关注一个run函数和isc_app_run函数
3.Bind运行主要是两个线程和一个do while循环,这三部分构成了bind的核心代码。

主函数

bind 启动代码位于 bin/named main.c

main()
{
    ...
    setup();//初始化工作

    / * Start things running and then wait for a shutdown request or reload. */
    do {
           result = isc_app_run(); //启动APP
           if (result == ISC_R_RELOAD) {
                 ns_server_reloadwanted(ns_g_server); //如果重启加载
           } else if (result != ISC_R_SUCCESS) {
                 ....
                 result = ISC_R_SUCCESS;
          }
       } while (result != ISC_R_SUCCESS);
       ...
}
  1. 在setup函数里初始化配置相关,比较庞杂,这里主要关注create_managers里,有两个重要的函数isc_taskmgr_createisc_socketmgr_create2这两个函数分别起两个线程,分别是run和watcher。分别处理任务队列。和监听socket管理相关。
  2. 这个do while循环,主要是result = isc_app_run();这个函数实际上等待各种结束程序信号,处理业务,如果需要重启服务调用ns_server_reloadwanted。
  3. run主要执行的代码是dispatch(manager),dispath主要执行的是(event->ev_action)( (isc_task_t *)task,event);处理事件相关
  4. watch主要执行的代码是result = watch_fd(manager, fd, msg);在watch_fd中,关键代码是epoll_ctl(manager->epoll_fd, EPOLL_CTL_ADD, fd, &event),这里重新注册epoll事件,然后epoll_wait再等待,而后再处理,如此反复。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值