Port dnsmasq to Android

Source: Internet
Author: User
Tags nameserver

Author: codejoker 9/26/2009

 

Dnsmaqs
It is a lightweight and easy-to-configure DNS proxy and DHCP service software that can provide DNS (or DHCP) Services for a small network. this article describes how to port it to the Android platform.

 

1. Purpose

A. when multi-PDP is implemented, multiple virtual network devices (NICS) in the mobile phone connect to different networks, and different networks may have different DNS servers. therefore, a separate DNS proxy is required to centrally manage DNS queries.

B. if you use a mobile phone as a Wi-Fi AP, you need to use the DHCP service to allocate IP addresses, gateways, and other network parameters.

C. at&t tests require mobile phones to provide a complete DNS cache mechanism, while the Android platform only provides a simple mechanism. For details, refer to the comments in the Code:

Bionic/libc/NetBSD/resolv/res_cache.c

It is only used to cache DNS answers for a maximum of config_seconds seconds
In order to reduce DNS traffic. It is not supposed to be a full DNS cache,
Since we plan to implement that in the future in a dedicated process running
On the system.

Note that its design is kept simple very intentionally, I. e .:

-It takes raw DNS query packet data as input, and returns raw DNS
Answer packet data as output

(This means that two similar queries that encode the DNS name
Differently will be treated distinctly ).

-The ttls of answer RRS are ignored. Our DNS resolver library does not use
Them anyway, but it means that records with a TTL smaller
Config_seconds will be kept in the cache anyway.

This is bad, but we absolutely want to avoid parsing the answer packets
(And shoshould be solved by the later full DNS cache process ).

-The implementation is just a (query-data) => (answer-data) hash table
With a trivial least-recently-used expiration policy.

Doing this keeps the code simple and avoids to deal with a lot of things
That a full DNS cache is expected to do.

2. Transplant preparation


A. Download the android source code
B. Download The dnsmaqs source code (this article downloads: dnsmasq-2.50.tar.gz)
Http://www.thekelleys.org.uk/dnsmasq/

 

3. Porting steps


A. decompress the dnsmaqs source code directory to the <Android>/external/dnsmaqs directory.
B. Compile the Android. mk file for dnsmaqs

Local_path: = $ (call my-DIR)
Include $ (clear_vars)

Local_src_files: =/
Src/BPF. c/
Src/cache. c/
Src/platform. c/
Src/DHCP. c/
Src/dnsmasq. c/
Src/forward. c/
Src/helper. c/
Src/lease. c/
Src/log. c/
Src/Netlink. c/
Src/network. c/
Src/option. c/
Src/rfc1035.c/
Src/rfc2131.c/
Src/TFTP. c/
Src/util. c

Local_c_includes: =/
Bionic/libc/private/

$ (Local_path)/src/

Local_cflags: =-dandroid_change

Local_module_path: = $ (target_out_optional_executables)
Local_module_tags: = user
Local_module: = dnsmasq

Include $ (build_executable)

C. Compile dnsmasq
C.1 set the compiling environment

# Cd <Android>
# Source build/envsetup. Sh
# Tapas

C.2 compile dnsmasq

# Make dnsmasq

D. correct compilation errors
In order that the modified Code will not pollute the open source code, we recommend that you include the modification in the android_change macro.
And define the macro In the Android. mk file.

4. Test


A. Upload the compiled dnsmasq executable file to your mobile phone.

# ADB push dnsmasq/tmp

B. Activate the GPRS connection of the mobile phone.

C. Modify system properties to send the application's DNS request to 127.0.0.1, that is, dnsmasq.

# Setprop net. dns1 127.0.0.1
# Setprop net. dns2 127.0.0.1

D. log on to the mobile phone to test DNS resolution. The resolution should fail.

# Ping-C 2 g.cn

E. Create the resolv. conf file and upload it to the/ET/directory on the mobile phone.

Nameserver 221.130.33.52
Nameserver 221.130.33.60

F. log on to the mobile phone and run dnsmasq as the root user.

# ADB Shell
# Tmp/dnsmasq-d

G. Test DNS resolution again. The resolution should be successful.

# Ping-C 2 g.cn

H. Test ended

5. Conclusion:


A. the dependency on dnsmasq is relatively small, and migration is relatively simple. The Android. mk file is written at the core, and the compilation error is corrected.
B. The above is only the first step of transplantation. If you want to implement DNS management, you need to modify the code, so we will not introduce it here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.