当前位置:网站首页>【dpdk】10. Dpdk DNS learning notes
【dpdk】10. Dpdk DNS learning notes
2022-04-23 01:51:00 【enchantedovo】
Based on the previously implemented KNI Code , And combine dns Open source library code dpdk-dns The combination of
Reference link :https://blog.csdn.net/yun6853992/article/details/122150555
List of articles
One 、DNS The domain name system
1.DNS effect
DNS(Domain Name System Abbreviation ) It's very simple . Will domain name and ip Mutual mapping , Generally used for domain name resolution , It's based on the domain name IP Address .
- DNS Use udp port 53;
- The hierarchy of domain names : Domain name by “.” division ,eg:
Host name . Subdomains . Top-level domain name . Root domain name, the last one “.” Omit , By default, it is managed by the root ; - Hierarchical query : Enter a web address ( domain name ), First, it looks for the browser cache , then DNS The server is based on the hierarchy of domain names , Hierarchical query .dig Ordered +trace Parameters can show DNS The whole hierarchical query process of .
- DNS The type of record :dns Somewhat type type , To determine the dns Message processing , Such as A Record 、AAAA Record 、CNAME Record 、MX Record 、NS Record 、TXT Record 、SRV Record 、URL forward .
2. Lookup process
Although you only need to return one IP Address , however DNS The query process is very complicated , It's divided into multiple steps .
Tool software dig The whole query process can be displayed .
root@ubuntu:~# dig www.baidu.com
# The first part : Query parameters and statistics
; <<>> DiG 9.10.3-P4-Ubuntu <<>> www.baidu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5575
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
# The second part : Query content
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.baidu.com. IN A
# The third part :DNS The server's reply
# Show www.baidu.com. There is one CNAME Record , as well as www.a.shifen.com. There are two A Record
# 415、146 yes TTL value , Indicates the cache time , namely 415s There is no need to re query
;; ANSWER SECTION:
www.baidu.com. 415 IN CNAME www.a.shifen.com.
www.a.shifen.com. 146 IN A 14.215.177.38
www.a.shifen.com. 146 IN A 14.215.177.39
# The fourth part :DNS Some transmission information of the server
# Results show , This machine DNS Server is 192.168.2.1, The query port is 53(DNS Server default port ), The response length is 101 byte
;; Query time: 2 msec
;; SERVER: 192.168.2.1#53(192.168.2.1)
;; WHEN: Sat Apr 16 01:39:18 PDT 2022
;; MSG SIZE rcvd: 104
If you don't want to see so much , You can use +short Parameters
root@ubuntu:~# dig www.baidu.com +short
www.a.shifen.com.
14.215.177.39
14.215.177.38
The above command only returns www.baidu.com Corresponding 2 individual IP Address ( namely A Record ).
This machine only to its own DNS Server query ,dig The order has a @ Parameters , Show to other DNS The result of the server query .
$ dig @4.2.2.2 www.baidu.com
The command above refers to orientation DNS The server 4.2.2.2 Inquire about .
3. other DNS Tools
(1)host command
host The command can be seen as dig A simplified version of the command , Return all kinds of records of the current request domain name .
$ host github.com
github.com has address 192.30.252.121
github.com mail is handled by 5 ALT2.ASPMX.L.GOOGLE.COM.
github.com mail is handled by 10 ALT4.ASPMX.L.GOOGLE.COM.
github.com mail is handled by 10 ALT3.ASPMX.L.GOOGLE.COM.
github.com mail is handled by 5 ALT1.ASPMX.L.GOOGLE.COM.
github.com mail is handled by 1 ASPMX.L.GOOGLE.COM.
$ host facebook.github.com
facebook.github.com is an alias for github.map.fastly.net.
github.map.fastly.net has address 103.245.222.133
host Commands can also be used for reverse queries , From IP Address query domain name , Equate to dig -x .
$ host 192.30.252.153
153.252.30.192.in-addr.arpa domain name pointer pages.github.com.
(2)nslookup command
nslookup The command is used to query domain name records interactively .
root@ubuntu:~# nslookup www.baidu.com
Server: 192.168.2.1
Address: 192.168.2.1#53
Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 14.215.177.39
Name: www.a.shifen.com
Address: 14.215.177.38
Learn how to resolve from the root domain name ip The process of
root@ubuntu:~$ nslookup
> set type=ns # Set the domain name resolution server record To view the
> . # View the root domain service record
Server: 192.168.0.1
Address: 192.168.0.1#53
Non-authoritative answer: # Intermediate cache Not authoritative
. nameserver = m.root-servers.net.
. nameserver = a.root-servers.net.
. nameserver = l.root-servers.net.
. nameserver = c.root-servers.net.
. nameserver = d.root-servers.net.
. nameserver = k.root-servers.net.
. nameserver = j.root-servers.net.
. nameserver = e.root-servers.net.
. nameserver = g.root-servers.net.
. nameserver = f.root-servers.net.
. nameserver = b.root-servers.net.
. nameserver = i.root-servers.net.
. nameserver = h.root-servers.net.
Authoritative answers can be found from:
a.root-servers.net internet address = 198.41.0.4
b.root-servers.net internet address = 199.9.14.201
c.root-servers.net internet address = 192.33.4.12
d.root-servers.net internet address = 199.7.91.13
e.root-servers.net internet address = 192.203.230.10
f.root-servers.net internet address = 192.5.5.241
g.root-servers.net internet address = 192.112.36.4
h.root-servers.net internet address = 198.97.190.53
i.root-servers.net internet address = 192.36.148.17
j.root-servers.net internet address = 192.58.128.30
k.root-servers.net internet address = 193.0.14.129
l.root-servers.net internet address = 199.7.83.42
m.root-servers.net internet address = 202.12.27.33
a.root-servers.net has AAAA address 2001:503:ba3e::2:30
b.root-servers.net has AAAA address 2001:500:200::b
> set type=a # Set type to a lookup ip
> a.root-servers.net. # View one of the domain name nodes ip
Server: 192.168.0.1
Address: 192.168.0.1#53
Non-authoritative answer:
Name: a.root-servers.net
Address: 198.41.0.4
> server 198.41.0.4 # Set up domain name server
Default server: 198.41.0.4
Address: 198.41.0.4#53
> set type=ns # View the root domain name server
> com. # Request... Under the root domain name server , Check and you will find that you will only go to what we set up server Conduct
Server: 198.41.0.4
Address: 198.41.0.4#53
Non-authoritative answer:
*** Cant find com.: No answer
Authoritative answers can be found from:
com nameserver = a.gtld-servers.net.
com nameserver = b.gtld-servers.net.
com nameserver = c.gtld-servers.net.
com nameserver = d.gtld-servers.net.
com nameserver = e.gtld-servers.net.
com nameserver = f.gtld-servers.net.
com nameserver = g.gtld-servers.net.
com nameserver = h.gtld-servers.net.
com nameserver = i.gtld-servers.net.
com nameserver = j.gtld-servers.net.
com nameserver = k.gtld-servers.net.
com nameserver = l.gtld-servers.net.
com nameserver = m.gtld-servers.net.
a.gtld-servers.net internet address = 192.5.6.30
b.gtld-servers.net internet address = 192.33.14.30
c.gtld-servers.net internet address = 192.26.92.30
d.gtld-servers.net internet address = 192.31.80.30
e.gtld-servers.net internet address = 192.12.94.30
f.gtld-servers.net internet address = 192.35.51.30
g.gtld-servers.net internet address = 192.42.93.30
h.gtld-servers.net internet address = 192.54.112.30
i.gtld-servers.net internet address = 192.43.172.30
j.gtld-servers.net internet address = 192.48.79.30
k.gtld-servers.net internet address = 192.52.178.30
l.gtld-servers.net internet address = 192.41.162.30
m.gtld-servers.net internet address = 192.55.83.30
a.gtld-servers.net has AAAA address 2001:503:a83e::2:30
b.gtld-servers.net has AAAA address 2001:503:231d::2:30
> server 192.5.6.30
Default server: 192.5.6.30
Address: 192.5.6.30#53
> set type=ns # Test an actual domain name
> bilibili.com
Server: 192.5.6.30
Address: 192.5.6.30#53
Non-authoritative answer:
*** Can't find bilibili.com: No answer
Authoritative answers can be found from:
bilibili.com nameserver = ns3.dnsv5.com.
bilibili.com nameserver = ns4.dnsv5.com.
ns3.dnsv5.com internet address = 129.211.176.212
ns3.dnsv5.com internet address = 162.14.18.188
ns3.dnsv5.com internet address = 162.14.24.251
ns3.dnsv5.com internet address = 162.14.25.251
ns3.dnsv5.com internet address = 18.194.2.137
ns3.dnsv5.com internet address = 183.192.201.94
ns3.dnsv5.com internet address = 223.166.151.16
ns3.dnsv5.com has AAAA address 2402:4e00:1430:1102:0:9136:2b2b:ba61
ns3.dnsv5.com internet address = 52.77.238.92
ns3.dnsv5.com internet address = 61.151.180.51
ns4.dnsv5.com internet address = 101.226.220.12
ns4.dnsv5.com internet address = 129.211.176.151
ns4.dnsv5.com internet address = 162.14.24.248
ns4.dnsv5.com internet address = 162.14.25.248
ns4.dnsv5.com internet address = 183.192.164.119
ns4.dnsv5.com internet address = 223.166.151.126
ns4.dnsv5.com has AAAA address 2402:4e00:1020:1264:0:9136:29b6:fc32
ns4.dnsv5.com internet address = 52.198.159.146
ns4.dnsv5.com internet address = 59.36.120.147
> server 129.211.176.212 # Set up com Corresponding top-level domain name server
Default server: 129.211.176.212
Address: 129.211.176.212#53
> set type=a # Set type to a, Find corresponding ip
> www.bilibili.com. # see ip, Find the corresponding content distribution domain name
Server: 129.211.176.212
Address: 129.211.176.212#53
www.bilibili.com canonical name = b.w.bilicdn1.com.
> b.w.bilicdn1.com. # View the corresponding content distribution domain name ip, That's what we need ip
Server: 129.211.176.212
Address: 129.211.176.212#53
Name: b.w.bilicdn1.com
Address: 119.3.211.130
Name: b.w.bilicdn1.com
Address: 119.3.231.166
Name: b.w.bilicdn1.com
Address: 119.3.238.64
Name: b.w.bilicdn1.com
Address: 119.3.229.89
Name: b.w.bilicdn1.com
Address: 119.3.234.165
Name: b.w.bilicdn1.com
Address: 119.3.227.169
What we got here ip Will be returned to our local dns Server and cache , When sending to our browser to enter the domain name , The corresponding procedure , use ip Make an actual request .
(3)whois command
whois The command is used to check the registration of domain names .
$ whois github.com
Two 、DNS Realization
dns Is based on udp Realized .
1. Realize the idea
Reference resources udp Protocol header and dns The head of the agreement , Construct the corresponding head structure , Yes DNS The server makes a data request , You should be able to get the returned ip.
receive( receive udp package )
===> decode_msg( Parsing packets )
===> resolve_query( Look up the table )
===> encode_msg( pack )
===> send( Send back packet )

2. Test ideas
- Use it directly udp socket api Make a data request , Structural compliance dns The structure data of the protocol can ;
- Parse the received udp Reply message data . Get what you need ip that will do .
3、 ... and 、 Two open source DNS Realization
1.dnspod-sr
# Compile and run
root@ubuntu:/root/dnspod-sr-master/src# ./dnspod-sr
[DBG:] dnspod-sr is successfully running now!!
[DBG:] max_ele_size is 1000000 - 1808
[DBG:] server may contain 332730 useful records
[DBG:] hash_table_size is 65536
[DBG:] we have 10 hash tables
[DBG:] we have 2 fetchers,2 quizzers
Use... In another environment dig Command to test ,dns The server has the function of learning
root@ubuntu:/home/root# dig @192.168.105.143 www.bilibili.com
; <<>> DiG 9.10.3-P4-Ubuntu <<>> @192.168.105.143 www.bilibili.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8662
;; flags: qr ra; QUERY: 1, ANSWER: 8, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;www.bilibili.com. IN A
;; ANSWER SECTION:
www.bilibili.com. 214 IN CNAME b.w.bilicdn1.com.
b.w.bilicdn1.com. 104 IN A 120.92.113.99
b.w.bilicdn1.com. 104 IN A 120.92.108.182
b.w.bilicdn1.com. 104 IN A 120.92.83.126
b.w.bilicdn1.com. 104 IN A 120.92.82.179
b.w.bilicdn1.com. 104 IN A 120.92.211.159
b.w.bilicdn1.com. 104 IN A 120.131.2.207
b.w.bilicdn1.com. 104 IN A 120.92.78.97
;; Query time: 2951 msec
;; SERVER: 192.168.105.143#53(192.168.105.143)
;; WHEN: Sat Dec 25 16:50:18 CST 2021
;; MSG SIZE rcvd: 173
Use dnsperf Test performance :
# install dnsperf https://gitee.com/mirrors_DNS-OARC/dnsperf?_from=gitee_search
# Pay attention to the first way Installation of version package , I reported an error when installing with the source code
# Installation package download address https://www.dns-oarc.net/tools/dnsperf
tar -xvf dnsperf-2.9.0.tar.gz
cd dnsperf-2.9.0
./configure
make
make install
# Write a configuration file as follows
root@ubuntu:/root/dnsperf-2.9.0# cat testfile
www.baidu.com A
www.bilibili.com A
# Perform the test , Can analyze the results
./src/dnsperf -d testfile -s 192.168.105.143 -c10000 -q10000 -l60
2.simpleDNS
download :https://github.com/mwarning/SimpleDNS.git
Start the code executable , use dig Request to view :
#dig @192.168.105.143 -p 9000 foo.bar.com A
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 8362
;; flags: qr; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;foo.bar.com. IN A
;; ANSWER SECTION:
foo.bar.com. 3600 IN A 192.168.1.1 # This is the domain name written in the test code (foo.bar.com) Corresponding ip
;; Query time: 0 msec
;; SERVER: 192.168.105.143#9000(192.168.105.143)
;; WHEN: Sat Dec 25 22:07:24 CST 2021
;; MSG SIZE rcvd: 56
Four 、dpdk-dns
1. Ideas
- Use dpdk Provided interface , To take over udp The data of , Yes dns Relevant requests are processed by agreement ;
- Reference resources simpleDNS Logic , Existing dpdk Handle arp,udp, tcp Based on the logic of , increase udp When the message ,dns Processing of relevant data ;
- Reference resources simpleDNS The logic in the is used for business processing and returns .
2. Turn on KNI Postback
kni Be able to carry on tx Send the data back to the kernel for processing , But you can't get the data looped back from the kernel , namely kni Conduct rx But I can't receive data . At this time, loop back processing is required :
Method 1 : Go to “/sys/devices/virtual/net/%s/carrier” Write in 1, Open the loop .
Method 2 : Insert KNI Module time , take carrier Set to on
root@ubuntu:~/share# cd dpdk/
root@ubuntu:~/share/dpdk# cd x86_64-native-linux-gcc/kmod/
root@ubuntu:~/share/dpdk/x86_64-native-linux-gcc/kmod# ls
igb_uio.ko rte_kni.ko
root@ubuntu:~/share/dpdk/x86_64-native-linux-gcc/kmod# insmod rte_kni.ko carrier=on
Method 3 : Call in code rte_kni_update_link, Dynamically enable the function of sending back data .
3.dns Data processing
if (UDP_PORT == ntohs(udp_hdr->dest_port))
{
#if ENABLE_DNS
g_src_ip = ip_hdr->dst_addr;
g_dest_ip == ip_hdr->src_addr;
g_src_port = ntohs(udp_hdr->dst_port);
g_dest_port = ntohs(udp_hdr->src_port);
rte_memcpy(g_dest_mac_addr, ehdr->s_addr.addr_bytes, RTE_ETHER_ADDR_LEN);
// udp userdata
uint16_t length = ntohs(udp_hdr->dgram_len);
uint16_t nbytes = length - sizeof(struct rte_udp_hdr);
uint8_t *data = (uint8_t *)(udp_hdr + 1);
// decode_msg
free_questions(msg.questions);
free_resource_records(msg.answers);
free_resource_records(msg.authorities);
free_resource_records(msg.additionals);
memset(&msg, 0, sizeof(struct Message));
decode_msg(&msg, data, nbytes);
// resolve_query
resolve_query(&msg);
// encode_msg
uint8_t *p = data;
encode_msg(&msg, &p);
// send_udp_pkt
int len = p - data;
do_send_udp(pktmbuf_pool, data, len);
版权声明
本文为[enchantedovo]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220909004992.html
边栏推荐
- .NET单元测试第一篇:常见.NET单元测试框架有哪些?
- 使用代理IP是需要注意什么?
- Makefile文件是什麼?
- JSP基础知识总结
- NPM yarn startup error [resolved]
- Rôles attributs personnels Abréviations
- Server 2019 the available memory of the server is half of the actual memory
- Batch multiple files into one hex
- 2022 melting welding and thermal cutting operation certificate examination question simulation examination platform operation
- 2022.4.10-----leetcode. eight hundred and four
猜你喜欢
![[hands on learning] network depth v2.1 Sequence model](/img/51/0de4c7972a99151007a8f27f351c83.png)
[hands on learning] network depth v2.1 Sequence model

Solve the problem when installing MySQL

What businesses use physical servers?

W801/W800-wifi-socket开发(一)-UDP

The leader / teacher asks to fill in the EXCEL form document. How to edit the word / Excel file on the mobile phone and fill in the Excel / word electronic document?

2022 crane driver (limited to bridge crane) examination question bank and online simulation examination

RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton dimensio

Shardingsphere introduction and sub table usage

2022 melting welding and thermal cutting operation certificate examination question simulation examination platform operation

How can e-procurement become a value-added function in the supply chain?
随机推荐
[leetcode daily question] 396 Rotation function
W801/W800-wifi-socket开发(一)-UDP
一些使用代理IP的小技巧。
Use Xdebug breakpoint debugging in postman
PID精讲
What are the common proxy IP problems?
Jerry's CPU performance test [chapter]
Error in face detection and signature of Tencent cloud interface
MySQL basic record
LSF的使用方法总结
【动手学深度学习V2】循环神经网络-1.序列模型
How can e-procurement become a value-added function in the supply chain?
How to write the resume of Software Test Engineer so that HR can see it?
How to choose a good dial-up server?
Analyze the advantages and disadvantages of tunnel proxy IP.
客户端项目管理经常面临的挑战
What is an API interface?
C语言中如何“指名道姓”的进行初始化
2022第六季完美童模 IPA国民赛领跑元宇宙赛道
什么是布尔类型?