DNS (Domain Name Server) routing method, device and equipment for PON (Passive Optical Network) gateway and medium

By setting and using mark marks in the linux kernel layer and application layer of the PON gateway, the problem of inconsistent DNS request routing in multi-WAN environments is solved, and the success rate of DNS routing and network performance is improved. It is suitable for enterprises or home environments with high network requirements.

CN119996306AInactive Publication Date: 2025-05-13SICHUAN TIANYI COMHEART TELECOM
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202510451134.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-11
Publication Date
2025-05-13
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In an environment with multiple Internet WAN connections, inconsistent routing of DNS requests causes DNS queries to fail to return successfully, browsers or other applications cannot access the website, and the success rate of existing DNS routing technologies is low.

Method used

In the linux kernel layer of the PON gateway, the socket option settings function, socket option acquisition function, and packet reception function are encoded, and the mark mark mark of the target WAN connection is set in the application layer, the DNS domain name resolution request is received and the matching situation of the mark mark mark to the target WAN connection is determined, and the matching WAN connection is selected to send the DNS request.

Benefits of technology

By using mark marks to select WAN connections in multi-WAN environments, the success rate of DNS routing is improved, network performance is optimized, bandwidth usage efficiency is improved, network security is enhanced, and network reliability and redundancy is provided.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119996306A_ABST
    Figure CN119996306A_ABST
Patent Text Reader

Abstract

The invention discloses a DNS (Domain Name Server) routing method and device for a PON (Passive Optical Network) gateway, equipment and a medium, relates to the technical field of network communication, and is used for solving the problem of low success rate of the existing DNS routing technology. The method comprises the following steps: in a linux kernel layer of a PON gateway, encoding a socket option setting function, a socket option obtaining function and a data packet receiving function; in a linux application layer of the PON gateway, according to a socket option setting function, a socket option obtaining function and a data packet receiving function, setting a mark of target WAN connection; receiving a DNS domain name resolution request sent by the lower-mounted device to a DNS server; determining whether the mark of the DNS domain name resolution request is matched with the mark of the target WAN connection; and if it is determined that the mark of the DNS domain name resolution request is matched with the mark of the target WAN connection, the target WAN connection is selected to send the DNS domain name resolution request, so that the correct WAN connection can be selected through the mark, and the DNS routing success rate is greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of network communication technology and provides a DNS routing method, device, equipment and medium for a PON gateway. Background Art

[0002] At present, with the popularization of Passive Optical Network (PON) technology in Fiber to the Room (FTTR), more and more users access broadband networks through PON gateways. For PON gateways, voice WAN is often configured to enable wired telephone use; IPTV WAN is configured to enable TV use; TR069 WAN is configured to enable service provider remote control; and Internet WAN is configured to enable user Internet access.

[0003] When users want to access a website online, they need to use the Domain Name System (DNS), which converts domain names into IP addresses so that users can easily access websites, email servers and other services without having to remember the digitized IP addresses. Figure 1 As shown in the figure, in the actual use environment of users, there are often business needs for multiple Internet WANs, such as WAN A and WAN B created by users for Internet access. Based on this, when there are multiple Internet WAN connection networks, DNS selection becomes more complicated because it involves multiple different network connections and potential DNS servers. As a result, the routing inconsistency of DNS requests (DNS routing asymmetry) may occur, resulting in the DNS query may not be successfully returned, and the browser or other applications cannot access the website.

[0004] Therefore, how to improve the success rate of DNS routing has become a problem that needs to be solved urgently. Summary of the invention

[0005] The present application provides a DNS routing method, device, equipment and medium for a PON gateway, which are used to solve the problem of low success rate of existing DNS routing technology.

[0006] On the one hand, a DNS routing method for a PON gateway is provided, the method comprising: In the Linux kernel layer of the PON gateway, the socket option setting function, the socket option obtaining function and the data packet receiving function are encoded; In the Linux application layer of the PON gateway, a mark of the target WAN connection is set according to the socket option setting function, the socket option obtaining function and the data packet receiving function; Receive DNS domain name resolution requests sent by downstream devices to DNS servers; Determine whether the mark of the DNS domain name resolution request matches the mark of the target WAN connection; If it is determined that the mark of the DNS domain name resolution request matches the mark of the target WAN connection, the target WAN connection is selected to send the DNS domain name resolution request.

[0007] Optionally, the step of encoding a socket option setting function, a socket option acquisition function and a data packet receiving function in the Linux kernel layer of the PON gateway includes: Adding a socket option SO_RCVMARK in the sock_setsockopt() kernel function; wherein the sock_setsockopt() kernel function is used to set the socket option SO_RCVMARK, and SOCK_RCVMARK is used to mark the socket; Adding a socket option SO_RCVMARK in a sock_getsockopt() kernel function; wherein the sock_getsockopt() kernel function is used to obtain the socket option SOCK_RCVMARK; A sock_recv_mark() function is added to the packet_recvmsg() kernel function; wherein the packet_recvmsg() kernel function is used to receive data packets from a network interface, and the sock_recv_mark() function is used to set a mark.

[0008] Optionally, the step of adding the socket option SO_RCVMARK in the sock_setsockopt() kernel function includes: Set the socket option SO_RCVMARK through the sock_setsockopt(fd, SOL_SOCKET, SO_RCVMARK,&opt, sizeof(opt)) kernel function.

[0009] Optionally, the step of setting the mark of the WAN connection in the Linux application layer of the PON gateway according to the socket option setting function, the socket option acquisition function and the data packet receiving function includes: When creating the target WAN connection, setting a mark of the target WAN connection according to ip policy routing; When the downstream device is connected to any LAN port of the PON gateway, any LAN port is bound to the target WAN connection through the port, and a corresponding traffic marking ebtable rule is created.

[0010] Optionally, after marking the data packets coming from any LAN port with a corresponding mark, the method further includes: Create a socket fd; wherein the socket fd is used for dns udp protocol communication, and the address domain of the socket fd is AF_INET, the socket type is SOCK_DGRAM, and the protocol type is 0; Create a socket tcpfd; wherein the socket tcpfd is used for dns tcp protocol communication, and the tcpfd address domain is AF_INET, the socket type is SOCK_STREAM; the protocol type is 0; Set the socket option SOL_SOCKET type to SO_RCVMARK; Bind the socket fd and the socket tcpfd socket to a local address; wherein the local address consists of an IP address and a port number.

[0011] Optionally, the step of receiving a DNS domain name resolution request sent by a downstream device to a DNS server includes: Receive the DNS domain name resolution request of any LAN port through the recvmsg function; According to the traffic marking ebtable rule, obtain the mark of the DNS domain name resolution request.

[0012] Optionally, after determining whether the mark tag of the DNS domain name resolution request matches the mark tag of the target WAN connection, the method further includes: If it is determined that the mark of the DNS domain name resolution request does not match the mark of the target WAN connection, it is determined whether the mark of the DNS domain name resolution request matches the mark of other WAN connections of the PON gateway.

[0013] On the one hand, a DNS routing device for a PON gateway is provided, the device comprising: A kernel layer encoding unit, used for encoding a socket option setting function, a socket option obtaining function and a data packet receiving function in the Linux kernel layer of the PON gateway; An application layer marking unit, used to set a mark of a target WAN connection in the Linux application layer of the PON gateway according to the socket option setting function, the socket option acquisition function and the data packet receiving function; A request receiving unit, used to receive a DNS domain name resolution request sent by a downstream device to a DNS server; a match determination unit, configured to determine whether a mark of the DNS domain name resolution request matches a mark of the target WAN connection; The DNS routing unit is used to select the target WAN connection to send the DNS domain name resolution request if it is determined that the mark of the DNS domain name resolution request matches the mark of the target WAN connection.

[0014] On the one hand, an electronic device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein any one of the above methods is implemented when the processor executes the computer program.

[0015] In one aspect, a storage medium is provided, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, any of the above methods is implemented.

[0016] Compared with the prior art, the beneficial effects of this application are: In the present application, when performing DNS routing, first, the socket option setting function, the socket option acquisition function and the data packet receiving function can be encoded in the Linux kernel layer of the PON gateway; then, the mark of the target WAN connection can be set in the Linux application layer of the PON gateway according to the socket option setting function, the socket option acquisition function and the data packet receiving function; next, the DNS domain name resolution request sent by the downstream device to the DNS server can be received; then, it can be determined whether the mark of the DNS domain name resolution request matches the mark of the target WAN connection; finally, if it is determined that the mark of the DNS domain name resolution request matches the mark of the target WAN connection, the target WAN connection can be selected to send the DNS domain name resolution request.

[0017] Therefore, in the present application, in a multi-WAN environment, the kernel layer is responsible for obtaining and setting the mark tag; the application layer is responsible for using the mark tag provided by the kernel, so that the DNS selects the WAN connection through the mark tag. Therefore, compared with the prior art, the present application can not only select the correct DNS server through DNS resolution to effectively improve the DNS routing success rate, network performance, optimize bandwidth usage, and enhance network security, but also provide higher network reliability and redundancy, which is particularly suitable for enterprises or home environments with high network requirements. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0019] Figure 1 A schematic diagram of an example of a multi-WAN connection provided in an embodiment of the present application; Figure 2 An electronic device provided in an embodiment of the present application; Figure 3 A schematic diagram of a DNS routing method for a PON gateway provided in an embodiment of the present application; Figure 4 A schematic diagram of a DNS routing device for a PON gateway provided in an embodiment of the present application.

[0020] Markings in the figure: 20-DNS routing device of PON gateway, 201-processor, 202-memory, 203-I / O interface, 204-database, 40-DNS routing device of PON gateway, 401-kernel layer encoding unit, 402-application layer marking unit, 403-request receiving unit, 404-matching determination unit, 405-DNS routing unit. DETAILED DESCRIPTION

[0021] In order to make the purpose, technical scheme and advantages of the present application clearer, the technical scheme in the embodiment of the present application will be clearly and completely described below in conjunction with the drawings in the embodiment of the present application. Obviously, the described embodiment is only a part of the embodiment of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application. In the absence of conflict, the embodiments in the present application and the features in the embodiments can be combined with each other arbitrarily. In addition, although the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in an order different from that here.

[0022] At present, with the popularization of Passive Optical Network (PON) technology in Fiber to the Room (FTTR), more and more users access broadband networks through PON gateways. For PON gateways, voice WAN is often configured to enable wired telephone use; IPTV WAN is configured to enable TV use; TR069 WAN is configured to enable service provider remote control; and Internet WAN is configured to enable user Internet access.

[0023] When users want to access a website online, they need to use the Domain Name System (DNS), which converts domain names into IP addresses so that users can easily access websites, email servers and other services without having to remember the digitized IP addresses. Figure 1 As shown in the figure, in the actual use environment of users, there are often business needs for multiple Internet WANs, such as WAN A and WAN B created by users for Internet access. Based on this, when there are multiple Internet WAN connection networks, DNS selection becomes more complicated because it involves multiple different network connections and potential DNS servers. As a result, the routing inconsistency of DNS requests (DNS routing asymmetry) may occur, resulting in the DNS query may not be successfully returned, and the browser or other applications cannot access the website.

[0024] Based on this, an embodiment of the present application provides a DNS routing method for a PON gateway. In the method, first, a socket option setting function, a socket option acquisition function, and a data packet receiving function can be encoded in the Linux kernel layer of the PON gateway; then, a mark tag of a target WAN connection can be set in the Linux application layer of the PON gateway according to the socket option setting function, the socket option acquisition function, and the data packet receiving function; next, a DNS domain name resolution request sent by a downstream device to a DNS server can be received; then, it can be determined whether the mark tag of the DNS domain name resolution request matches the mark tag of the target WAN connection; finally, if it is determined that the mark tag of the DNS domain name resolution request matches the mark tag of the target WAN connection, the target WAN connection can be selected to send the DNS domain name resolution request. Therefore, in the present application, in a multi-WAN environment, the kernel layer is responsible for obtaining and setting the mark tag; the application layer is responsible for using the mark tag provided by the kernel, so that the DNS selects the WAN connection through the mark tag. Therefore, compared with the prior art, the present application can not only select the correct DNS server through DNS resolution to effectively improve the DNS routing success rate, network performance, optimize bandwidth usage, and enhance network security, but also provide higher network reliability and redundancy, which is particularly suitable for enterprises or home environments with high network requirements.

[0025] After introducing the design ideas of the embodiments of the present application, the following briefly introduces the application scenarios to which the technical solutions of the embodiments of the present application can be applied. It should be noted that the application scenarios introduced below are only used to illustrate the embodiments of the present application and are not limited. In the specific implementation process, the technical solutions provided by the embodiments of the present application can be flexibly applied according to actual needs.

[0026] like Figure 1 As shown, an electronic device provided in an embodiment of the present application is provided, and the electronic device may specifically be a DNS routing device 20 of a PON gateway.

[0027] Among them, the DNS routing device 20 of the PON gateway can perform DNS routing in the PON gateway, for example, it can be a personal computer (PC), a server and a laptop. The DNS routing device 20 of the PON gateway may include one or more processors 201, a memory 202, an I / O interface 203 and a database 204. Specifically, the processor 201 may be a central processing unit (CPU), or a digital processing unit, etc. The memory 202 may be a volatile memory (volatile memory), such as a random-access memory (RAM); the memory 202 may also be a non-volatile memory (non-volatile memory), such as a read-only memory, a flash memory (flash memory), a hard disk drive (HDD) or a solid-state drive (SSD); or the memory 202 is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 202 may be a combination of the above memories. The memory 202 may store some program instructions of the DNS routing method of the PON gateway provided in the embodiment of the present application, and these program instructions can be used to implement the steps of the DNS routing method of the PON gateway provided in the embodiment of the present application when executed by the processor 201, so as to solve the problem of low success rate of the existing DNS routing technology. The database 204 may be used to store data such as the DNS domain name resolution request, mark tag, socket option setting function, socket option acquisition function, and data packet receiving function involved in the solution provided in the embodiment of the present application.

[0028] In the embodiment of the present application, the DNS routing device 20 of the PON gateway can obtain the DNS routing instruction through the I / O interface 203, and then the processor 201 of the DNS routing device 20 of the PON gateway will improve the DNS routing success rate according to the program instructions of the DNS routing method of the PON gateway provided by the embodiment of the present application in the memory 202. In addition, data such as the DNS domain name resolution request, mark tag, socket option setting function, socket option acquisition function, and data packet receiving function can also be stored in the database 204.

[0029] Of course, the method provided in the embodiment of the present application is not limited to Figure 2 The application scenarios shown can also be used in other possible application scenarios, and the embodiments of the present application are not limited thereto. Figure 2The functions that can be realized by each device in the application scenario shown will be described in the subsequent method embodiments, and will not be described in detail here. Below, the method of the embodiment of the present application will be introduced in conjunction with the accompanying drawings.

[0030] like Figure 3 As shown, it is a schematic diagram of the DNS routing method of the PON gateway provided in the embodiment of the present application. The method can be implemented based on the linux-5.10.x kernel and the dnsmasq-2.45 open source program, and can be implemented by Figure 1 The method is performed by the DNS routing device 20 of the PON gateway. Specifically, the process of the method is described as follows.

[0031] Step 301: In the Linux kernel layer of the PON gateway, encode a socket option setting function, a socket option obtaining function and a data packet receiving function.

[0032] Specifically, first, you can add the socket option SO_RCVMARK in the sock_setsockopt() kernel function; the sock_setsockopt() kernel function is used to set the socket option SO_RCVMARK, and SOCK_RCVMARK is used to mark the socket. For example, you can set the socket option SO_RCVMARK through the sock_setsockopt(fd, SOL_SOCKET, SO_RCVMARK,&opt, sizeof(opt)) kernel function. Then, when receiving this socket message, the application layer can select the correct DNS resolution path by obtaining the mark information of the message.

[0033] In actual application, the following lines of code can be used to implement the setting of socket options: #define SO_RCVMARK 101 enum sock_flags { SOCK_RCVMARK, / * for recvmsg get SKB MARK * / } sock_setsockopt() { ... case SO_RCVMARK: sock_valbool_flag(sk, SOCK_RCVMARK, valbool); break; ... } Then, the socket option SO_RCVMARK can be added in the sock_getsockopt() kernel function; wherein the sock_getsockopt() kernel function is used to obtain the socket option SOCK_RCVMARK.

[0034] In actual application, the following lines of code can be used to obtain socket options: sock_getsockopt(){ ... case SO_RCVMARK: v.val = sock_flag(sk, SOCK_RCVMARK); break; ... } Finally, you can add the sock_recv_mark() function to the packet_recvmsg() kernel function; the packet_recvmsg() kernel function is a function in the Linux kernel that is mainly used to receive packets from a network interface. It is usually related to network drivers and protocol stacks, especially when using AF_PACKET sockets (i.e., raw data link layer sockets). Specifically, packet_recvmsg receives data from a specified network interface and passes the data to the caller through a given buffer. The packet_recvmsg() kernel function is very important when dealing with the network layer, link layer, and getting and sending packets through raw sockets. The sock_recv_mark() function is used to set the mark.

[0035] In actual application, the following lines of code can be used to implement the setting of the mark tag: packet_recvmsg(){ ... sock_recv_mark(msg,sk,skb); ... } void sock_recv_mark(struct msghdr *msg, struct sock *sk, struct sk_buff *skb) { if (sock_flag(sk, SOCK_RCVMARK)&&skb) put_cmsg(msg, SOL_SOCKET, SO_RCVMARK, sizeof(__u32),&skb->mark); } Among them, if (sock_flag(sk, SOCK_RCVMARK)&&skb) is used to determine whether the received socket flag is SOCK_RCVMARK; put_cmsg() is used to add &skb->mark to the message msg with the socket layer option SOL_SOCKET and type SO_RCVMARK.

[0036] Step 302: In the Linux application layer of the PON gateway, a mark of the target WAN connection is set according to a socket option setting function, a socket option obtaining function and a data packet receiving function.

[0037] Specifically, in the Linux application layer of the PON gateway, first, when creating a target WAN connection, you can set the mark of the target WAN connection according to the IP policy routing. For example, create a mark of 0x2000 for WAN1 and 0x4000 for WAN2. Then, implement the mark through IP policy routing. The command line is as follows: ip ru add from all fwmark 0x2000 lookup 512 ip ru add from all fwmark 0x4000 lookup 513 Then, when the downstream device is connected to any LAN port of the PON gateway, any LAN port is bound to the target WAN connection through the port, and the corresponding traffic marking ebtable rule is created. For example, the PON gateway has 4 LAN ports. When our downstream device is connected to the LAN1 port, then LAN1 can be bound to WAN1 through port binding. At this time, an ebtable rule will be created to mark all data flows coming from LAN1 with 0x2000. The command line is as follows: Bridge chain: BROUTING, entries: 2, policy: ACCEPT -i eth0.2.0 -j mark --mark-or 0x2000 --mark-target CONTINUE Next, you can create a socket fd, where the socket fd is used for DNS UDP protocol communication, and the address domain of the socket fd is AF_INET, the socket type is SOCK_DGRAM, and the protocol type is 0. The command line is as follows: fd = socket(AF_INET, SOCK_DGRAM, 0); / / used for dns udp protocol communication Then, you can create a socket tcpfd, where the socket tcpfd is used for DNS TCP protocol communication, and the tcpfd address domain is AF_INET, the socket type is SOCK_STREAM, and the protocol type is 0. The command line is as follows: tcpfd = socket(AF_INET, SOCK_STREAM, 0); / / used for dns tcp protocol communication Next, you can set the socket option SOL_SOCKET type to SO_RCVMARK. The command line is as follows: int opt ​​= 1; setsockopt(fd, SOL_SOCKET, SO_RCVMARK,&opt, sizeof(opt)); setsockopt(tcpfd, SOL_SOCKET, SO_RCVMARK,&opt, sizeof(opt)); Finally, you can bind the socket fd and socket tcpfd to the local address, where the local address consists of an IP address and a port number. The command line is as follows: union mysockaddr addr; memset(&addr, 0, sizeof(addr)); addr.in.sin_family = AF_INET; addr.in.sin_addr.s_addr = INADDR_ANY; addr.in.sin_port = htons(53); bind(fd, (struct sockaddr *)&addr, sa_len(&addr)); bind(tcpfd, (struct sockaddr *)&addr, sa_len(&addr)); Step 303: Receive a DNS domain name resolution request sent by a downstream device to a DNS server.

[0038] Specifically, in the Linux application layer of the PON gateway, the recvmsg function can be used to receive the DNS domain name resolution request of any LAN port; then, the mark of the DNS domain name resolution request can be obtained according to the traffic mark ebtable rule. That is, the LAN-side DNS domain name resolution request can be received through the recvmsg function, and the data flow mark skb_mark can be obtained; at this time, the mark value obtained from the LAN1 port is 0x2000. The command line is as follows: recvmsg(listen->fd,&msg, 0); if (cmptr->cmsg_level == SOL_SOCKET&&cmptr->cmsg_type == SO_RCVMARK) { skb_mark = *((unsigned int*)CMSG_DATA(cmptr)); } Step 304: Determine whether the mark of the DNS domain name resolution request matches the mark of the target WAN connection.

[0039] That is, in the Linux application layer of the PON gateway, the received skb_mark can be used to compare the marks of the created WAN connection to see if they match. The command line is as follows: if(skb_mark == serv->mark){ sendto(fd, (char *)header, plen, 0,&start->addr.sa, sa_len(&start->addr)) } Among them, start->addr.sa is the DNS resolution address corresponding to the WAN connection.

[0040] Step 305: If it is determined that the mark of the DNS domain name resolution request matches the mark of the target WAN connection, the target WAN connection is selected to send the DNS domain name resolution request.

[0041] That is, in the Linux application layer of the PON gateway, if it is determined that the mark tag of the DNS domain name resolution request matches the mark tag of the target WAN connection, the DNS resolution address of the corresponding WAN connection is called to send the DNS domain name resolution request.

[0042] On the contrary, if it is determined that the mark of the DNS domain name resolution request does not match the mark of the target WAN connection, it can be determined whether the mark of the DNS domain name resolution request matches the mark of other WAN connections of the PON gateway.

[0043] In summary, in the embodiment of the present application, in a multi-WAN environment, IP policy routing and traffic marking (EBtable setting mark mark) can be used to select different Internet connection paths. Therefore, compared with the prior art, the present application can not only select the correct DNS server through DNS resolution to effectively improve the DNS routing success rate, network performance, optimize bandwidth usage, and enhance network security, but also provide higher network reliability and redundancy, which is particularly suitable for enterprises or home environments with high network requirements.

[0044] Based on the same inventive concept, the embodiment of the present application provides a DNS routing device 40 for a PON gateway, such as Figure 4 As shown, the DNS routing device 40 of the PON gateway includes: The kernel layer encoding unit 401 is used to encode the socket option setting function, the socket option acquisition function and the data packet receiving function in the Linux kernel layer of the PON gateway; The application layer marking unit 402 is used to set the mark of the target WAN connection according to the socket option setting function, the socket option acquisition function and the data packet receiving function in the Linux application layer of the PON gateway; The request receiving unit 403 is used to receive a DNS domain name resolution request sent by a downstream device to a DNS server; A match determination unit 404, configured to determine whether a mark in the DNS domain name resolution request matches a mark in the target WAN connection; The DNS routing unit 405 is configured to select a target WAN connection to send the DNS domain name resolution request if it is determined that the mark of the DNS domain name resolution request matches the mark of the target WAN connection.

[0045] Optionally, the kernel layer encoding unit 401 is further used for: Add the socket option SO_RCVMARK in the sock_setsockopt() kernel function; the sock_setsockopt() kernel function is used to set the socket option SO_RCVMARK, and SOCK_RCVMARK is used to mark the socket; Add the socket option SO_RCVMARK in the sock_getsockopt() kernel function; where the sock_getsockopt() kernel function is used to obtain the socket option SOCK_RCVMARK; Add the sock_recv_mark() function in the packet_recvmsg() kernel function; the packet_recvmsg() kernel function is used to receive data packets from the network interface, and the sock_recv_mark() function is used to set the mark.

[0046] Optionally, the kernel layer encoding unit 401 is further used for: Set the socket option SO_RCVMARK through the sock_setsockopt(fd, SOL_SOCKET, SO_RCVMARK,&opt, sizeof(opt)) kernel function.

[0047] Optionally, the application layer marking unit 402 is further configured to: When creating a target WAN connection, set the mark of the target WAN connection according to the IP policy routing; When the downstream device is connected to any LAN port of the PON gateway, any LAN port is bound to the target WAN connection through the port, and the corresponding traffic marking ebtable rules are created.

[0048] Optionally, the application layer marking unit 402 is further configured to: Create a socket fd; where the socket fd is used for DNS UDP protocol communication, and the address domain of the socket fd is AF_INET, the socket type is SOCK_DGRAM, and the protocol type is 0; Create a socket tcpfd; the socket tcpfd is used for DNS TCP protocol communication, and the tcpfd address domain is AF_INET, the socket type is SOCK_STREAM; the protocol type is 0; Set the socket option SOL_SOCKET type to SO_RCVMARK; Binds socket fd and socket tcpfd to the local address; the local address consists of an IP address and a port number.

[0049] Optionally, the application layer marking unit 402 is further configured to: Receive the DNS domain name resolution request from any LAN port through the recvmsg function; According to the traffic marking ebtable rules, obtain the mark of the DNS domain name resolution request.

[0050] Optionally, the DNS routing unit 405 is further configured to: If it is determined that the mark of the DNS domain name resolution request does not match the mark of the target WAN connection, it is determined whether the mark of the DNS domain name resolution request matches the mark of other WAN connections of the PON gateway.

[0051] The DNS routing device 40 of the PON gateway can be used to perform Figure 3 The method executed in the embodiment shown in the figure, therefore, the functions that can be realized by each functional module of the DNS routing device 40 of the PON gateway can be referred to. Figure 3 The description of the illustrated embodiment is not repeated in detail.

[0052] In some possible implementations, various aspects of the method provided in the present application may also be implemented in the form of a program part, which includes a program code. When the program part is run on a computer device, the program code is used to enable the computer device to execute the steps of the method according to various exemplary embodiments of the present application described above in this specification. For example, the computer device may execute the following steps: Figure 3 The method performed in the illustrated embodiment.

[0053] Those skilled in the art can understand that all or part of the steps of the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above method embodiment are executed; and the aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, read-only memory (ROM), random access memory (RAM), magnetic disks or optical disks. Alternatively, if the above integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent part, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or in other words, the part that contributes to the prior art can be embodied in the form of a software part, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the methods described in various embodiments of the present invention. And the aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROM, RAM, magnetic disks or optical disks.

[0054] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.

[0055] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A DNS routing method for a PON gateway, characterized in that: The method comprises: In the Linux kernel layer of the PON gateway, the socket option setting function, the socket option obtaining function and the data packet receiving function are encoded; In the Linux application layer of the PON gateway, a mark of the target WAN connection is set according to the socket option setting function, the socket option obtaining function and the data packet receiving function; Receive DNS domain name resolution requests sent by downstream devices to DNS servers; Determine whether the mark of the DNS domain name resolution request matches the mark of the target WAN connection; If it is determined that the mark of the DNS domain name resolution request matches the mark of the target WAN connection, the target WAN connection is selected to send the DNS domain name resolution request.

2. The method according to claim 1, characterized in that The step of encoding a socket option setting function, a socket option acquisition function and a data packet receiving function in the Linux kernel layer of the PON gateway comprises: Adding a socket option SO_RCVMARK in the sock_setsockopt() kernel function; wherein the sock_setsockopt() kernel function is used to set the socket option SO_RCVMARK, and SOCK_RCVMARK is used to mark the socket; Adding a socket option SO_RCVMARK in a sock_getsockopt() kernel function; wherein the sock_getsockopt() kernel function is used to obtain the socket option SOCK_RCVMARK; A sock_recv_mark() function is added to the packet_recvmsg() kernel function; wherein the packet_recvmsg() kernel function is used to receive data packets from a network interface, and the sock_recv_mark() function is used to set a mark.

3. The method according to claim 2, characterized in that The step of adding the socket option SO_RCVMARK in the sock_setsockopt() kernel function comprises: Set the socket option SO_RCVMARK through the sock_setsockopt(fd, SOL_SOCKET, SO_RCVMARK, &opt, sizeof(opt)) kernel function.

4. The method according to claim 1, characterized in that The step of setting the mark of the WAN connection in the Linux application layer of the PON gateway according to the socket option setting function, the socket option acquisition function and the data packet receiving function comprises: When creating the target WAN connection, setting a mark of the target WAN connection according to ip policy routing; When the downstream device is connected to any LAN port of the PON gateway, any LAN port is bound to the target WAN connection through the port, and a corresponding traffic marking ebtable rule is created.

5. The method according to claim 4, characterized in that After marking the data packets coming from any LAN port with a corresponding mark, the method further comprises: Create a socket fd; wherein the socket fd is used for dns udp protocol communication, and the address domain of the socket fd is AF_INET, the socket type is SOCK_DGRAM, and the protocol type is 0; Create a socket tcpfd; wherein the socket tcpfd is used for dns tcp protocol communication, and the tcpfd address domain is AF_INET, the socket type is SOCK_STREAM; the protocol type is 0; Set the socket option SOL_SOCKET type to SO_RCVMARK; Bind the socket fd and the socket tcpfd socket to a local address; wherein the local address consists of an IP address and a port number.

6. The method according to claim 4, characterized in that The step of receiving a DNS domain name resolution request sent by a downstream device to a DNS server includes: Receive the DNS domain name resolution request of any LAN port through the recvmsg function; According to the traffic marking ebtable rule, obtain the mark of the DNS domain name resolution request.

7. The method according to claim 1, characterized in that After determining whether the mark of the DNS domain name resolution request matches the mark of the target WAN connection, the method further includes: If it is determined that the mark of the DNS domain name resolution request does not match the mark of the target WAN connection, it is determined whether the mark of the DNS domain name resolution request matches the mark of other WAN connections of the PON gateway.

8. A DNS routing device for a PON gateway, characterized in that: The device comprises: A kernel layer encoding unit, used for encoding a socket option setting function, a socket option obtaining function and a data packet receiving function in the Linux kernel layer of the PON gateway; An application layer marking unit, used to set a mark of a target WAN connection in the Linux application layer of the PON gateway according to the socket option setting function, the socket option acquisition function and the data packet receiving function; A request receiving unit, used to receive a DNS domain name resolution request sent by a downstream device to a DNS server; a match determination unit, configured to determine whether a mark of the DNS domain name resolution request matches a mark of the target WAN connection; The DNS routing unit is used to select the target WAN connection to send the DNS domain name resolution request if it is determined that the mark of the DNS domain name resolution request matches the mark of the target WAN connection.

9. An electronic device, characterized in that: The device comprises: A memory for storing program instructions; A processor is used to call the program instructions stored in the memory, and execute any method according to claims 1-7 according to the obtained program instructions.

10. A storage medium, characterized in that: The storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute any one of the methods of claims 1-7.

Citation Information

Patent Citations

  • Delegation forwarding method for domain name system (DNS) data package

    CN103095608A

  • Main / standby switching method and system for DNS proxy server

    CN110445641A

  • Business automatic classification method, device, and system in GPON system

    WO2016062103A1