LoginSignup
0
0

More than 5 years have passed since last update.

[編集中] Unbound の実装

Last updated at Posted at 2016-01-26

※ まだ調査・検証・編集途中の内容です。誤りが含まれている可能性が高いためご注意ください。

要約

  • socket周り(accept, listen)の実装を知りたいとき
    • "struct comm_point" (util/netevent.h) を見る
    • comm_point_create_[udp|tcp|udp_ancil|raw] で comm_point を作成
  • 外部DNSサーバへの問い合わせの通信制御の実装を知りたいとき
    • "struct outside_network" (services/outside_network.h) を見る
  • クライアントからのDNS問い合わせをどう扱うか知りたいとき
    • "worker_handle_request" (daemon/worker.c) を見る
    • DNS問い合わせが来た時に呼ばれるハンドラ
    • mesh_new_client でモジュールが実行され各プロトコルの処理が行われる
  • 外部DNSサーバへの再帰問い合わせの実装を知りたいとき
    • "iter_handle" (iterator/iterator.c) を見る
    • DNS の再帰問い合わせをしながら状態遷移している
  • 一連の処理の流れを"モジュール (struct module_func_block) "でまとめている
    • iterator, dns64, validator, pythonmod
    • 各モージュールはファクトリーメソッドパターンで利用する (module_factory)

Unbound の主要な動作

  • main
  • ...
  • run_daemon
  • daemon_fork
    • メインスレッドはシグナルハンドリングとリモート・コントロールの制御
    • fork と言っているがプロセスは増えない(スレッドが生成されるだけ)
  • daemon_setup_modules
    • modstack_setup
    • モジュール(再帰問い合わせはDNS64など一連のプロトコル群)の設定
    • 例:iterator (再帰問い合わせ) モジュールを使って名前解決する
  • daemon_start_others
  • ub_thread_create(thread_start)
  • thread_start
  • worker_init
    • listen する socket を作成 (listen_create)
    • 外部DNSへ通信する socket を作成 (outside_network_create)
    • worker->env.send_query = worker_send_query
  • worker_handle_request
    • mesh_new_client でプロトコルの処理が走る

各ライブラリの実装

services/

  • daemon/* で #include して使っている

listen_dnsport.c

  • listen_create
    • DNS query を listen する comm_point を作成する
    • UDP/TCP/SSL/UDPANCIL

outside_network.c

  • outside_network_create
    • 引数が大変にあれ

util/

netevent.c

  • accept_open
    • open accept commpoint
    • comm_point_create_raw() 経由で comm_point_perform_accept() を呼んでいる
  • comm_point_perform_accept
    • accept() して、file descriptor を return

netevent.h

  • struct comm_point
    • Communication point to the network

daemon/

remote.c

  • remote_accept_callback
    • accept 相当(comm_point_perform_accept)

unbound.c

  • run_daemon
    • daemon_open_shared_ports

daemon.c

  • daemon_open_shared_ports
    • DNSサーバへの問い合わせ通信に利用するポートをopenする

Memo

  • mesh_run で module の operate を実行している

モジュールの設定

  • modstack_init
  • modstack_setup
  • modstack_desetup

Todo

  • 図を書く
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0