Routing and offloading method, device and vehicle
Patent Information
- Application Number
- CN202610808884.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-05
- Publication Date
- 2026-09-01
AI Technical Summary
[0005]本发明提供了一种路由分流方法、装置及车辆,以至少解决相关技术中HAL层的车载关键业务流量无法智能分流的技术问题
[0019]基于上述技术方案,本申请新建目标路由前检索并删除同IP的匹配第二路由,再将新建路由存入路由数据集,可避免统一域名对应IP地址变更时存在多条重复路由条目,防止路由冲突、路由表臃肿。
Smart Images

Figure CN122679097A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of communication technology, specifically to a routing and traffic splitting method, apparatus, and vehicle. Background Technology
[0002] With the rapid development of intelligent connected vehicle technology, intelligent terminal devices such as Android in-vehicle systems and in-vehicle telematics boxes (T-Boxes) need to access multiple different networks simultaneously to meet the network requirements of various business scenarios, including navigation, entertainment, vehicle data reporting, remote control, and intelligent driving. Against this backdrop, how to efficiently and accurately achieve routing and traffic distribution in multi-network environments, ensuring that different service traffic selects the optimal network exit as needed, has become a core issue in the network management of in-vehicle intelligent terminals.
[0003] The current routing and traffic splitting scheme relies on the Domain Name System (DNS) in the Android network framework (Netd) for domain name resolution. It uses the iptables mangle table to match and mark the domain names of application-layer packets in the OUTPUT chain, and then combines policy routing to direct traffic to the specified network interface. This routing identification mechanism depends on the Android application-layer network stack and can only handle network requests initiated by the Android application layer.
[0004] However, in automotive T-Boxes and high-end domain controllers, a large number of critical automotive services (such as vehicle status reporting and remote control command reception) are implemented by applications in the hardware abstraction layer (HAL). These applications often bypass the Android application layer network stack and communicate directly based on the underlying network interface. This results in data packets not going through Netd's DNS resolution process, and therefore cannot be marked and routed by iptables rules. Consequently, the critical automotive service traffic at the HAL layer cannot be intelligently routed and can only use the default route, making it difficult to meet automotive-grade functional safety and service isolation requirements. Summary of the Invention
[0005] This invention provides a routing and traffic splitting method, apparatus, and vehicle to at least solve the technical problem that the on-board critical service traffic at the HAL layer cannot be intelligently split in related technologies.
[0006] In a first aspect, this application provides a routing offloading method, comprising: intercepting DNS query packets at the data link layer; wherein the DNS query packets are used to query the Internet Protocol (IP) address to be accessed based on the domain name to be accessed; the target network interface sending the DNS query packets is a hardware abstraction layer network interface or an application layer network interface; sending the DNS query packets to a DNS server to cause the DNS server to return a DNS response packet; configuring a target route for the target network interface based on the IP address to be accessed and a preset configuration file in the DNS response packet; wherein the target route is used to indicate the routing path from the target network interface to the IP address to be accessed via a first target access point name (APN); the first target APN is an APN assigned to the target network interface; and offloading the packets sent by the target network interface based on the target route.
[0007] Based on the above technical solution, this application intercepts DNS query packets initiated by the hardware abstraction layer network interface and application layer network interface at the data link layer. Based on the IP address to be accessed resolved from the DNS response, the domain name and APN in the preset configuration file, and the mapping relationship between APN and network interface, it dynamically configures a target route pointing to the first target APN for the target network interface. This allows critical business traffic to be transmitted independently through a dedicated APN link, achieving fine-grained routing and distribution of application business traffic across the entire network. This method does not rely on the Android application layer network stack or Netd's DNS resolution process. Therefore, it is applicable to network requests initiated by the Android application layer, as well as routing and distribution of critical in-vehicle services such as vehicle status reporting and remote command reception at the hardware abstraction layer (HAL). It effectively solves the problem that existing routing and distribution schemes cannot intelligently distribute HAL layer services and can only use default routes, meeting the requirements for concurrent access to multiple networks, service isolation, and automotive-grade functional safety in the in-vehicle environment.
[0008] One possible approach involves intercepting DNS query packets sent by the target network interface at the data link layer, including: intercepting DNS query packets using raw sockets created at the data link layer; wherein the raw sockets are bound to each hardware abstraction layer network interface and each application layer network interface to receive data packets sent and received by each hardware abstraction layer network interface and each application layer network interface.
[0009] Based on the above technical solution, this application creates raw sockets at the data link layer that are respectively bound to all hardware abstraction layer network interfaces and application layer network interfaces. By capturing DNS query packets using these raw sockets, it is unaffected by HAL layer services bypassing the upper-layer protocol stack and can simultaneously capture DNS packets sent by both types of interfaces, achieving full-interface DNS packet collection from the link layer. Furthermore, by uniformly binding all target network ports using raw sockets, there is no need to repeatedly configure capture rules for individual network interfaces. This simplifies the deployment and configuration workload of multi-port vehicle T-Boxes and domain controllers, improving the versatility and maintainability of DNS packet capture in multi-interface networking scenarios.
[0010] In one possible approach, a target route is configured for the target network interface based on the IP address to be accessed and a preset configuration file in the DNS response packet. This includes: searching a routing dataset for a first route that matches both the IP address to be accessed and the domain name to be accessed; wherein the routing dataset includes at least one previously created route, and the network interface, APN, domain name, and IP address corresponding to each of the at least one route; if the first route does not exist, creating a target route based on the IP address to be accessed and the preset configuration file; if the first route exists, determining the first route as the target route; and configuring the target route for the target network interface.
[0011] Based on the above technical solution, this application uses a routing dataset containing historical routes and corresponding network interfaces, APNs, domain names, and IP address association information. It prioritizes searching for existing first routes by matching the target IP address with the target domain name. If a match is found, the existing route is directly selected as the target route. Only when no matching route is found is a new target route created based on the target IP address and a preset configuration file, and the interface routing configuration is completed. By using dual verification of domain names and IP addresses to match routes, the accuracy of route selection can be improved. Simultaneously, reusing valid routes avoids the duplication of route entries, reducing redundant entries in the kernel routing table.
[0012] In one possible approach, the aforementioned preset configuration file includes: configuration information for the second target APN and a list of domain names corresponding to the second target APN; the configuration information includes: the type of data packets to be processed; wherein, the second target APN is one of the activated APNs. Based on this, a target route is created based on the IP address to be accessed and the preset configuration file, including: creating a target route based on a first tag corresponding to the DNS response data packet, the IP address to be accessed, and the preset configuration file; wherein, the first tag is used to indicate the type of data packets processed by the first target APN; the first target APN is the APN in the first mapping dataset that matches the domain name to be accessed; the first mapping dataset is a dataset determined based on the preset configuration file, used to characterize the correspondence between APNs and domain names.
[0013] Based on the above technical solution, this application constructs a mapping relationship between domain names and APNs through a preset configuration file, and generates target routes by combining packet type marking and IP address resolution. Only APNs already activated in the system are used for route creation, effectively avoiding invalid route configuration issues. By matching traffic distribution rules across multiple dimensions of domain names, IP addresses, and packet types, the accuracy of vehicle service traffic routing distribution can be significantly improved, avoiding mis-distribution and random traffic assignment. Simultaneously, all service domain names, APNs, and packet type rules are uniformly managed through a configuration file, allowing for policy updates without code modifications. This flexible configuration and easy maintenance enable stable and reliable fine-grained traffic distribution between the application layer and HAL layer.
[0014] In one possible approach, the aforementioned configuration information further includes: the name of the connected network interface, the routing table ID, and the routing table name. Based on this, a target route is created using the first tag corresponding to the DNS response packet, the IP address to be accessed, and a preset configuration file. This includes: determining the routing table ID and routing table name corresponding to the target network interface and the first target APN based on the first tag; determining the target routing table from the routing table set based on the routing table ID and routing table name; wherein the target routing table is used to specify the first target APN for traffic splitting; and creating the target route based on the target network interface, the target routing table, and the IP address to be accessed.
[0015] Based on the above technical solution, this application configures the network interface name, routing table ID, and routing table name in the pre-configured configuration file. It can quickly match the corresponding target network interface and dedicated routing table based on the first tag, and accurately select the independent routing table corresponding to the APN from the routing table set to generate routes. By managing different APN traffic splitting rules through table partitioning, each service route is isolated from the others, preventing interference between different APN routing entries and routing table disorder, improving routing configuration efficiency, ensuring accurate traffic splitting between the HAL layer and application layer according to the predetermined APN and routing table, and enhancing the stability of multi-link traffic splitting in vehicles.
[0016] In one possible approach, sending a DNS query packet to a DNS server to cause the DNS server to return a DNS response packet includes: tagging the DNS query packet with a first tag to obtain a target DNS query packet; sending the target DNS query packet to the DNS server to cause the DNS server to return a DNS response packet carrying the first tag based on a second mapping dataset; wherein the second mapping dataset is a dataset used to characterize the correspondence between domain names and IP addresses.
[0017] Based on the above technical solution, this application pre-marks the DNS query data packet before forwarding it outward. The response data packet returned by the DNS server can carry the first mark synchronously. The network interface and APN configuration information corresponding to the original query are associated with the first mark. The first mark runs through the entire DNS sending and receiving process, eliminating the need to store domain name association information separately. The subsequent routing matching logic facilitates the quick retrieval of the configuration file to generate the corresponding route, thereby improving the accuracy of HAL and application layer multi-service traffic splitting.
[0018] In one possible approach, the above-mentioned route splitting method further includes: if the first route does not exist, searching for a second route in the route dataset that matches the IP address to be accessed; deleting the second route; and, after the target route is created, adding the target route to the route dataset.
[0019] Based on the above technical solution, this application retrieves and deletes matching second routes with the same IP before creating a new target route, and then stores the new route into the routing dataset. This can avoid multiple duplicate route entries when the IP address corresponding to the same domain name changes, and prevent route conflicts and bloated routing tables.
[0020] In one possible approach, the above-mentioned routing method further includes: in response to detecting an APN change in the activated APN set, triggering an update of the configuration information in the preset configuration file; the APN change includes an APN changing from inactive to active, an APN changing from active to inactive, and a change in the network interface connected to the APN; and, if the list of domain names corresponding to the second target APN in the preset configuration file changes, updating the first mapping dataset.
[0021] Based on the above technical solution, this application monitors changes in the set of activated APNs in real time, automatically updating the preset configuration file when APNs are started / stopped or their bound network interfaces are changed. Changes to the domain name list also update the first mapping dataset corresponding to the domain name and APN. This ensures that the configuration and mapping data are consistent with the actual online status of the vehicle's APNs in real time, preventing invalid routes from being generated due to APN status failures or lagging binding relationships.
[0022] Secondly, this application provides a routing splitting device, which includes a processing unit, a communication unit, and a configuration unit.
[0023] The processing unit is used to intercept DNS query packets at the data link layer; wherein, the DNS query packets are used to query the IP address to be accessed based on the domain name to be accessed; the target network interface for sending the DNS query packets is the hardware abstraction layer network interface or the application layer network interface; The communication unit is used to send DNS query packets to the DNS server so that the DNS server returns DNS response packets; The configuration unit is used to configure a target route for the target network interface based on the IP address to be accessed in the DNS response packet and a preset configuration file; wherein, the target route is used to indicate the routing path from the target network interface to the IP address to be accessed via a first target APN; the first target APN is an APN assigned to the target network interface; The communication unit is also used to route and distribute data packets sent from the target network interface based on the target route.
[0024] In one possible approach, the processing unit is specifically configured to: intercept DNS query packets using raw sockets created on the data link layer; wherein the raw sockets are bound to each hardware abstraction layer network interface and each application layer network interface to receive packets sent and received by each hardware abstraction layer network interface and each application layer network interface.
[0025] In one possible approach, the configuration unit is specifically used for: finding a first route in the routing dataset that matches both the IP address to be accessed and the domain name to be accessed; wherein the routing dataset includes at least one previously created route, and the network interface, APN, domain name, and IP address corresponding to each of the at least one route; if the first route does not exist, creating a target route based on the IP address to be accessed and a preset configuration file; if the first route exists, determining the first route as the target route; and configuring the target route for the target network interface.
[0026] In one possible approach, the aforementioned preset configuration file includes: configuration information for the second target APN and a list of domain names corresponding to the second target APN; the configuration information includes: the type of data packets to be processed; wherein, the second target APN is one of the activated APNs. Based on this, the configuration unit is further configured to: create a target route based on a first tag corresponding to the DNS response data packet, the IP address to be accessed, and the preset configuration file; wherein, the first tag is used to indicate the type of data packets processed by the first target APN; the first target APN is an APN in the first mapping dataset that matches the domain name to be accessed; the first mapping dataset is a dataset determined based on the preset configuration file, used to characterize the correspondence between APNs and domain names.
[0027] In one possible approach, the aforementioned configuration information further includes: the name of the connected network interface, the routing table ID, and the routing table name. Based on this, the configuration unit is specifically used to: determine the routing table ID and routing table name corresponding to the target network interface and the first target APN based on the first tag; determine the target routing table from the routing table set based on the routing table ID and routing table name; wherein the target routing table is used to specify the first target APN for traffic splitting; and create a target route based on the target network interface, the target routing table, and the IP address to be accessed.
[0028] In one possible approach, the communication unit is specifically configured to: perform a first tagging process on the DNS query data packet to obtain a target DNS query data packet; send the target DNS query data packet to the DNS server so that the DNS server returns a DNS response data packet carrying the first tag based on a second mapping dataset; wherein the second mapping dataset is a dataset used to characterize the correspondence between domain names and IP addresses.
[0029] In one possible approach, the processing unit is further configured to: if the first route does not exist, search for a second route in the routing dataset that matches the IP address to be accessed; delete the second route; and, after the target route is created, add the target route to the routing dataset.
[0030] In one possible approach, the processing unit is further configured to: in response to monitoring an APN change in the activated APN set, trigger an update of the configuration information in a preset configuration file; the APN change includes an APN changing from inactive to active, an APN changing from active to inactive, and a change in the network interface connected to the APN; and, if the list of domain names corresponding to the second target APN in the preset configuration file changes, update the first mapping dataset.
[0031] Thirdly, this application provides a vehicle that includes the routing and diversion device of the second aspect.
[0032] Fourthly, this application provides an electronic device, including: a processor and a memory, wherein the memory stores at least one computer program, and the at least one computer program is loaded and executed by the processor to implement the routing and traffic splitting method of the first aspect and any possible implementation thereof.
[0033] Fifthly, this application provides a computer-readable storage medium that, when the instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to perform the routing and diversion method described in the first aspect and any possible implementation thereof.
[0034] Sixthly, this application provides a computer program product including computer instructions that, when executed on an electronic device, cause the electronic device to perform the routing and diversion method described in the first aspect and any possible implementation thereof.
[0035] It should be noted that the technical effects of any of the implementation methods in aspects two through six can be found in the technical effects of the corresponding implementation methods in aspect one, and will not be repeated here.
[0036] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description
[0037] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application, and do not constitute an undue limitation of this application.
[0038] Figure 1 This is a schematic diagram of the structure of a routing and traffic splitting system provided in an embodiment of this application; Figure 2 This is a schematic diagram of another routing and traffic splitting system provided in an embodiment of this application; Figure 3 This is a flowchart of a routing and traffic splitting method provided in an embodiment of this application; Figure 4 This is a schematic diagram of the structure of a DNS response data packet provided in an embodiment of this application; Figure 5 This is a block diagram of a routing and traffic splitting device provided in an embodiment of this application; Figure 6 This is a block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0039] To enable those skilled in the art to better understand the technical solutions of this application, the technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.
[0040] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0041] In the embodiments of this application, the words "exemplarily," "for example," or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "exemplarily," "for example," or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the words "exemplarily," "for example," or "for instance" is intended to present the relevant concepts in a specific manner.
[0042] The technical solutions of the embodiments of this application will be described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.
[0043] like Figure 1 As shown in the illustration, a routing and traffic splitting system provided in this application includes: a DNS server 100 and a gateway device 201 and a smart device 202 (also referred to as a subdomain) deployed in a vehicle 200. The DNS server 100 is communicatively connected to the gateway device 201, and the gateway device 201 is communicatively connected to the smart device.
[0044] The DNS server 100 can be a high-performance server providing various services on the internet, a standalone physical server, a server cluster consisting of multiple physical servers, or at least one of the following cloud servers providing basic cloud computing services: cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks, and big data or artificial intelligence platforms. This embodiment of the application does not limit this specific type. Of course, the server can also include other functions to provide more comprehensive and diversified services.
[0045] Gateway device 201 is used to realize communication, control and data processing between the inside and outside of vehicle 200. Gateway device 201 may include, but is not limited to, in-vehicle T-Box, central gateway and domain gateway, and this application does not limit it.
[0046] The intelligent component 202 may include, but is not limited to, electronic control units (ECUs), sensors, and domain controllers (such as intelligent driving domain controllers and intelligent cockpit domain controllers), and this application does not limit it.
[0047] In some embodiments, when an application in smart device 202 needs to access a domain name (hereinafter referred to as the domain name to be accessed), the application constructs and sends a DNS query packet at the data link layer. Gateway device 201 can intercept the packet at the data link layer and, if it determines that the packet is a DNS query packet, send the DNS query packet to DNS server 100. The logic for intercepting the packet remains consistent regardless of whether the DNS query packet originates from the HAL network interface or the application layer network interface. Accordingly, after receiving the DNS query packet from gateway device 201, DNS server 100 can determine the IP address to be accessed corresponding to the domain name to be accessed in the DNS query packet from the second mapping dataset and return a DNS response packet to gateway device 201.
[0048] Based on the above, gateway device 201 can intercept DNS response packets at the data link layer and extract the domain name and IP address to be accessed from the DNS response packets. Then, it searches the preset configuration file for the first target APN corresponding to the domain name to be accessed, as well as the target network interface and target routing table corresponding to the first target APN. Next, it searches the target routing table for the target route corresponding to the IP address to be accessed, configures the target route for the target network interface, and performs routing for data packets sent by the target network interface based on the target route. That is, it routes data packets from the target network interface to the IP address to be accessed via the first target APN, ensuring that data packets matching the IP address to be accessed preferentially follow the target route without affecting the service traffic of other network interfaces.
[0049] In one example, such as Figure 2 As shown in the embodiments of this application, the routing distribution system may include: a DNS service module, a configuration resolution module, a routing management module, an APN status monitoring module, and a main control module. The main control module is communicatively connected to the DNS service module, the configuration resolution module, the routing management module, and the APN status monitoring module, respectively; the DNS service module is communicatively connected to the configuration resolution module and the routing management module, respectively; and the APN status monitoring module is communicatively connected to the routing management module.
[0050] The DNS service module is used to intercept DNS query packets and DNS response packets at the data link layer. When a DNS response packet is intercepted, the domain name and IP address to be accessed are extracted from it; when a DNS query packet is intercepted, the domain name to be accessed is extracted from it.
[0051] The configuration parsing module is used to load and parse the preset configuration file in JSON format, and maintain the mapping relationship between the domain name and APN in the preset configuration file, as well as the configuration information of the APN.
[0052] The routing management module is used for routing table management, IP routing rule configuration, route status tracking, and iptables rule configuration.
[0053] The APN status monitoring module is used to monitor the connection status of each APN and trigger the routing management module to update the routing table when the connection status of an APN changes.
[0054] The main control module is used to coordinate the work of the above modules and manage the thread lifecycle of each module in a unified manner.
[0055] The routing and traffic splitting method provided in this application can be applied to vehicles. Vehicles can also be referred to as vehicles, mobile carriers, electric vehicles (EVs), hybrid electric vehicles (HEVs), plug-in hybrid electric vehicles (PHEVs), fuel cell vehicles (FCVs), autonomous vehicles, intelligent and connected vehicles (ICVs), driverless vehicles, etc.
[0056] In this application, the vehicle can be a sedan, a sport utility vehicle (SUV), a truck, a special vehicle (such as an ambulance, fire truck, police car, etc.), a driverless taxi, a smart connected bus, an autonomous logistics vehicle, an electric truck, etc. Furthermore, this method is also applicable to various special-purpose vehicles, such as agricultural vehicles, mining vehicles, forestry vehicles, airport vehicles, and port vehicles. This application does not impose specific limitations in this regard.
[0057] For ease of understanding, the routing and traffic splitting method provided in the embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0058] like Figure 3 As shown in the embodiments of this application, a routing and traffic splitting method includes: S301. Intercept DNS query packets at the data link layer.
[0059] The DNS query packet is used to query the IP address to be accessed based on the domain name to be accessed; the target network interface for sending the DNS query packet is either the hardware abstraction layer network interface or the application layer network interface.
[0060] Generally, different APNs are associated with different network interfaces. To enable the sending and receiving of traffic from a specific APN, a raw socket (SOCK_RAW) needs to be created at the data link layer and precisely bound to the network interface used by the corresponding APN. That is, in this embodiment, the raw socket needs to be bound to each Hardware Abstraction Layer (HAL) network interface and each Application Layer (AL) network interface to receive data packets sent and received by each HAL network interface and each AAL network interface.
[0061] Raw sockets are low-level network programming interfaces located below the transport layer, primarily used for protocol development or low-level network operations. Examples include defining custom network protocols, performing link-layer packet capture analysis, or fine-grained interception and processing of specific protocol data packets. Compared to standard stream sockets (SOCK_STREAM) and datagram sockets (SOCK_DGRAM), they offer more direct data packet access capabilities.
[0062] In some embodiments, a gateway device can create a raw socket by calling the socket interface to obtain raw data link layer access capabilities. Furthermore, the gateway device can query the currently active APNs and their corresponding network interfaces through the Telephony Abstraction Layer Interface API (TALI API). After the query is complete, the system can bind the raw socket to the specified network interface (i.e., the Hardware Abstraction Layer network interface or the Application Layer network interface) by calling the bind() function, thereby enabling the raw socket to receive all data link layer frames / data packets on the bound network interface.
[0063] Building upon the above, when an application within a smart device needs to access a domain name (hereinafter referred to as the domain name to be accessed), the application constructs and sends a DNS query packet at the data link layer. The gateway device can then use raw sockets created at the data link layer to intercept the DNS query packets on its bound network interface.
[0064] S302. Send the DNS query data packet to the DNS server so that the DNS server returns a DNS response data packet.
[0065] In this embodiment, the gateway device stores preset configuration information. The preset configuration file includes: configuration information of the second target APN and a list of domain names corresponding to the second target APN. The configuration file is based on a Map data structure, constructed with domain name strings as keys and APN configuration information as values, and is used to implement differentiated access control or routing selection based on domain names.
[0066] The configuration information for the second target APN includes: the type of data packets processed (represented by the packet tag value "mark"), the name of the network interface to which the second target APN connects (represented by the network interface index "profileIdx"), the routing table identification (tableID), the routing table name (tableName), and the IP address (ips). The second target APN is one of the active APNs in the set. The index is used to obtain the network interface name corresponding to the APN via the TALI API. The "mark" value is used to set the packet tag value in iptables rules, serving as the basis for matching subsequent routing policies and traffic control, enabling accurate identification and differentiation of traffic.
[0067] In some embodiments, the gateway device can tag the DNS query data packet with a first tag to obtain a target DNS query data packet. Then, the gateway device can extract the domain name to be accessed from the DNS query data packet, find the first target APN corresponding to the domain name to be accessed from preset configuration information, and determine the network interface connected to the first target APN. Afterwards, the gateway device can send the target DNS query data packet carrying the first tag to the DNS server through the network interface connected to the first target APN.
[0068] Accordingly, the DNS server stores a second mapping dataset, which represents the correspondence between domain names and IP addresses. Based on this, the DNS server can extract the domain name to be accessed from the target DNS query packet and determine at least one IP address corresponding to the domain name from the second mapping dataset. Then, the DNS server can send a DNS response packet carrying a first tag to the gateway device through the network interface connected to the first target APN.
[0069] The DNS response packet includes at least: the domain name to be accessed, at least one IP address corresponding to the domain name to be accessed, and a first tag.
[0070] For example, the gateway device performs a first tagging process on the DNS query packet, which may specifically include: the gateway device can use the string module of iptables to perform hexadecimal string matching on the DNS query packet, and convert the domain name string to be accessed into hexadecimal format (such as converting "www.baidu.com" into the corresponding hexadecimal string "7777772e62616964752e636f6d").
[0071] In the iptables mangle table creation, a custom chain (DNS_MARKING chain) is defined. Domain name matching rules are added to the DNS_MARKING chain based on the string module to define rules for marking different domain name packets differently. Simultaneously, redirection rules can be added to the PREROUTING and OUTPUT chains to redirect DNS query packets from the PREROUTING and OUTPUT chains to the DNS_MARKING chain, allowing the DNS query packets to be labeled using the DNS_MARKING chain to obtain the first label.
[0072] For example, to add a domain name matching rule: `iptables -t mangle -I DNS_MARKING 1 -m string--algo bm --hex-string "|7777772e62616964752e636f6d|" --icase -j MARK --set-mark 0xf1f8`, this means using the iptables mangle table to insert a domain name matching rule into the DNS_MARKING chain, marking the DNS query packets for the hexadecimal domain name "7777772e62616964752e636f6d" (i.e., the domain name www.baidu.com, case-insensitive) with the first mark 0xf1f8 (i.e., mark=0xf1f8).
[0073] For example, the redirection rule: `iptables -t mangle -I PREROUTING 1 -p udp --dport 53 -jDNS_MARKING` means that DNS query packets passing through the PREROUTING chain will be sent to the DNS_MARKING chain for tagging / marking processing; the redirection rule: `iptables -t mangle -I OUTPUT 1 -p udp --dport 53 -j DNS_MARKING` means that DNS query packets passing through the OUTPUT 1 chain will be sent to the DNS_MARKING chain for tagging processing.
[0074] Optionally, taking the in-vehicle T-Box system as an example, the APN in this system can include, but is not limited to: private network APN, public network APN, and over-the-air (OTA) APN. Among them, the private network APN is used to carry vehicle data reporting services; the public network APN is used to carry internet solution services; and the OTA APN is used to carry OTA upgrade services.
[0075] Optionally, the default storage and representation format of the configuration file may include JSON, YAML, TOML, etc., and this application does not limit this. Taking a JSON-formatted configuration file as an example, a JSON-formatted configuration file can be represented as follows: { "apn1": { "profileIdx": 1, "mark": "0xf1f8", "tableId": "1100", "tableName": "rt_apn1", "domains": ["server1.example.com", "server2.example.com", "server3.example.com", ..., "server100.example.com"], "ips": [] }; "apn2": { "profileIdx": 2, "mark": "0xf1f9", "tableId": "1200", "tableName": "rt_apn2", "domains": ["www.example.com"], IP address: ["10.0.0.1"] } } The configuration file includes two APNs, aPN1 and aPN2. `profileIdx` represents the index of the network interface corresponding to the APN, `mark` represents the packet marker, `ip` represents the IP address of the APN, `tableId` represents the identifier of the routing table corresponding to the APN, `tableName` represents the name of the routing table corresponding to the APN, and `domains` represents the list of domain names corresponding to the APN. Each APN corresponds to at least one domain name.
[0076] For example, the gateway device searches for the first target APN corresponding to the domain name to be accessed from the preset configuration information. Specifically, this may include: the gateway device can load a preset configuration file in JSON format from apnrule.json, call a JSON parsing library (such as jsoncpp, rapidjson) to parse the preset configuration file, and perform integrity and validity verification on the parsed configuration file. If the verification is successful, the gateway device searches for the first target APN corresponding to the domain name to be accessed from the preset configuration information and determines the network interface connected to the first target APN. If the verification fails, the gateway device determines that the preset configuration file is invalid, records an error log, and terminates the current configuration loading process.
[0077] Optionally, integrity verification includes: verifying the configuration information (profileIdx, mark value, tableId, tableName) of each APN in the preset configuration file and the list of domain names corresponding to each APN. If any required field is missing or of the wrong type, the configuration file is deemed invalid. Validity verification includes: whether profileIdx is within the valid range, whether the mark value conflicts with other APNs, whether tableId conflicts with existing routing tables, and whether tableName conforms to the naming convention.
[0078] For example, based on the domain name to be queried, parsing the preset configuration file yields the following results: APN1 (Private Network APN): profileIdx=1, mark=0xf1f8, tableId=1100, tableName=rt_apn1, with the following domain name list: ["www.baidu.com", "apngw.goodhub.cn"]. APN2 (Public Network APN): profileIdx=2, mark=0xf1f9, tableId=1200, tableName=rt_apn2, with the following domain name list: ["www.example.com", "maps.google.com"]. APN3 (OTA APN): profileIdx=3, mark=0xf1fa, tableId=1300, tableName=rt_apn3, with the following domain name list: ["voice.goodhub.cn", "ota.goodhub.cn"].
[0079] S303. Configure the target route for the target network interface based on the IP address to be accessed and the preset configuration file in the DNS response packet.
[0080] The target route indicates the routing path from the target network interface to the IP address to be accessed via the first target APN; the first target APN is the APN assigned to the target network interface.
[0081] In some embodiments, the gateway device is configured with a routing dataset. Based on this, the gateway device can extract the IP address and domain name to be accessed from the DNS response packet. Then, it searches the routing dataset for a first route that matches both the IP address and the domain name to be accessed. If the first route does not exist, the gateway device can create a target route based on the IP address to be accessed and a preset configuration file; if the first route exists, it is determined as the target route, and the target route is configured for the target network interface.
[0082] Each APN corresponds to a routing table, and each routing table contains a routing dataset. The routing dataset includes at least one previously created route, as well as the network interface, APN, domain name, and IP address corresponding to each route. For example, the routing table format for APN1 is: tableId (1100) and tableName (rt_apn1).
[0083] In one example, the gateway device can determine the APN matching the domain name to be accessed from preset configuration information and then determine the routing table in that APN's configuration information. The routing table contains a routing dataset, that is, it contains at least one route (also called a routing entry). Based on this, the gateway device can search the routing table for the first route that matches the IP address to be accessed. If a routing entry matching the IP address exists, it means the first route exists; if no routing entry matching the IP address exists, it means the first route does not exist.
[0084] In one example, if the first route does not exist, the gateway device can create a target route based on the first tag corresponding to the DNS response packet, the IP address to be accessed, and a preset configuration file. Specifically, the gateway device can look up the first target APN matching the first tag and the domain name to be accessed, the routing table ID and routing table name corresponding to the first target APN, and the target network interface corresponding to the first target APN from the first mapping dataset of the preset configuration information. Then, the gateway device can determine the target routing table from the routing table set based on the routing table ID and routing table name, and create the target route based on the target network interface, the target routing table, and the IP address to be accessed.
[0085] The target routing table is used to specify the first target APN for traffic splitting.
[0086] The first tag is used to indicate the type of data packet processed by the first target APN; the first target APN is the APN in the first mapping dataset that matches the domain name to be accessed; the first mapping dataset is a dataset determined based on a preset configuration file and used to characterize the correspondence between APNs and domain names.
[0087] For example, if the first marker of the DNS response packet is 0xf1f8, check if the routing rule corresponding to 0xf1f8 exists using the command `ip rule show | grep "fwmark 0xf1f8"`. If the routing rule corresponding to 0xf1f8 does not exist, add a new routing rule: `ip rule add fwmark 0xf1f8 table rt_apn1 1100`, which means the apn1 corresponding to the first marker 0xf1f8 and the routing table ID (1100) HE routing table name rt_apn1. After finding the routing table ID (1100) HE and the routing table name rt_apn1 corresponding to apn1, the target routing table is searched in the routing table set rt_tables. Then, a routing entry is created in the target routing table to establish the correspondence between the target network interface and the IP address to be accessed. For example, ip route add 192.168.1.100 / 32 dev ccmni1 table rt_apn1 means that the network interface ccmni1 corresponding to the IP address 192.168.1.100 / 32 to be accessed is added to the routing table rt_apn1; ip route add 192.168.1.101 / 32 dev ccmni1 table rt_apn1 means that the network interface ccmni1 corresponding to the IP address 192.168.1.101 / 32 to be accessed is added to the routing table rt_apn1.
[0088] In this embodiment, a / 32 subnet mask is used to ensure an exact match of a single IP address, and the mapping relationship between IP addresses and routing entries is maintained in the routing table.
[0089] S304. Based on the target route, perform route splitting on the data packets sent by the target network interface.
[0090] In some embodiments, the gateway device can forward data packets from the target network interface of the smart device according to the configured target route, so that the data packets can reach the IP address to be accessed via the first target APN according to the path specified by the target route.
[0091] For example, suppose the gateway device is configured with three APNs: APN1 (private network APN, interface ccmni1) for vehicle data reporting, APN2 (public network APN, interface ccmni2) for internet access, and APN3 (OTA APN, interface ccmni3) for OTA upgrades. When multiple applications access different domain names simultaneously, the gateway device can route the data packets sent from different network interfaces according to the target routes corresponding to the DNS response data packets returned by the DNS server.
[0092] For example, when application A accesses "apngw.goodhub.cn" (private network service), the DNS packet is marked as 0xf1f8, corresponding to routing table rt_apn1, and sent via ccmni1; when application B accesses "www.example.com" (public network service), the DNS packet is marked as 0xf1f9, corresponding to routing to rt_apn2, and sent via ccmni2; when application C accesses "ota.goodhub.cn" (OTA service), the DNS packet is marked as 0xf1fa, corresponding to routing table rt_apn3, and sent via ccmni3. Under this mechanism, the DNS resolution, routing, and outgoing interface of the three service flows are completely isolated and do not affect each other, thus achieving true multi-APN concurrency and service-based traffic distribution.
[0093] Based on the above technical solution, this application intercepts DNS query packets initiated by the hardware abstraction layer network interface and application layer network interface at the data link layer. Based on the IP address to be accessed resolved from the DNS response, the domain name and APN in the preset configuration file, and the mapping relationship between APN and network interface, it dynamically configures a target route pointing to the first target APN for the target network interface. This allows critical business traffic to be transmitted independently through a dedicated APN link, achieving fine-grained routing and distribution of application business traffic across the entire network. This method does not rely on the Android application layer network stack or Netd's DNS resolution process. Therefore, it is applicable to network requests initiated by the Android application layer, as well as routing and distribution of critical in-vehicle services such as vehicle status reporting and remote command reception at the hardware abstraction layer (HAL). It effectively solves the problem that existing routing and distribution schemes cannot intelligently distribute HAL layer services and can only use default routes, meeting the requirements for concurrent access to multiple networks, service isolation, and automotive-grade functional safety in the in-vehicle environment.
[0094] In an optional implementation, in S303 above, the gateway device can intercept DNS response packets at the data link layer, and then configure a target route for the target network interface based on the IP address to be accessed in the DNS response packets and a preset configuration file, using the above method. Specifically, intercepting DNS response packets may include: In some embodiments, the system can create a raw socket by calling the socket interface to obtain raw data link layer access capabilities. Furthermore, the system can query the currently active APNs and their corresponding network interfaces through the TelephonyAbstraction Layer Interface API (TALI API). After the query is complete, the system can bind the raw socket to the specified network interface by calling the bind() function, thereby enabling the raw socket to receive all data link layer frames / data packets on the bound network interface.
[0095] Furthermore, the system is configured with a Berkeley packet filter (BPF), which contains built-in filtering rules for filtering Internet Protocol version 4 (IPv4) / User Datagram Protocol (UDP) packets. Based on this, after the system receives all packets from its bound network interface at the data link layer using raw sockets, the BPF filter can then filter IPv4 / UDP packets (such as DNS response packets) on the network interface according to the filtering rules for subsequent processing.
[0096] The filtering rules include: 1-1. Ethernet Type Verification: Check the Ethernet type field (EtherType) at offset 12 bytes of the data packet and determine if its value is 0x0800 to ensure that only IPv4 protocol data packets are processed and other protocol data packets are filtered out.
[0097] 1-2. Transport layer protocol verification: After confirming that it is an IPv4 packet, further check the protocol field at offset 23 bytes in the IP header to determine whether its value is 17 (i.e., the UDP protocol number), thereby filtering out UDP packets.
[0098] For packets that meet all the above filtering rules, BPF returns a receive instruction and performs subsequent processing; for packets that do not meet the filtering rules, they are discarded directly and a reject instruction is returned.
[0099] In this embodiment, the filtering rules corresponding to BPF are implemented in the form of embedded instructions. Specifically, the BPF filtering instruction sequence includes: The first instruction, {0x28, 0, 0, 0x0000000c}, indicates that 2 bytes of data are loaded from the 12th byte of the Ethernet frame (or data packet), which corresponds to the EtherType field in the Ethernet frame. The second instruction, {0x15, 0, 3, 0x00000800}, compares EtherType with 0x0800. If they are not equal, it jumps to the sixth instruction and returns 0, indicating that the packet is discarded. If they are equal, it means that the current packet is an IPv4 packet, and the subsequent instructions continue to be executed. The third instruction, {0x20, 0, 0, 0x00000017}, indicates that 1 byte of data is loaded from the 23rd byte of the IP header, which corresponds to the IP protocol number field. The fourth instruction, {0x15, 0, 1, 0x00000011}, compares the IP protocol number with 17. If they are not equal, it jumps to the sixth instruction and returns 0; if they are equal, it means that the current data packet is a UDP data packet. The fifth instruction, {0x6, 0, 0, 0x00040000}, indicates that the data packet will be accepted when all the above conditions are met. The sixth instruction, {0x6, 0, 0, 0x00000000}, means that the data packet should be discarded directly if any of the filtering conditions are not met.
[0100] In some embodiments, the system can automatically identify the packet encapsulation format to adapt to the data link layer encapsulation methods used by different network interface drivers. Due to differences in the implementation of different network drivers, the packets received by the raw socket may be in standard Ethernet frame format or pure IP packet format. To achieve automatic identification, after receiving the packet, its starting bytes are first analyzed. If the first 4 bits of the packet are 0x4 and the header length field conforms to the IPv4 protocol specification, the packet is determined to be a pure IP packet without an Ethernet header; if the starting bytes of the packet exhibit typical MAC address characteristics (e.g., conforming to the local area network address distribution pattern), it is determined to be a complete Ethernet frame containing an Ethernet header.
[0101] In some embodiments, the system supports unified monitoring and management of multiple network interfaces in multi-interface concurrent scenarios. Specifically, in multi-interface concurrent scenarios, the system can call multiplexing interfaces such as select() or epoll() to uniformly manage all created raw sockets. When a data packet conforming to the BPF filtering rules arrives on any network interface, the multiplexing mechanism immediately wakes up the application process and triggers the corresponding read operation. This mechanism effectively avoids the resource waste caused by polling and achieves efficient concurrent monitoring of multiple heterogeneous network interfaces.
[0102] Based on the above technical solution, the BPF filter in this application runs in kernel space, has extremely high filtering efficiency, and can handle high-traffic network environments. The BPF filter performs filtering at the data link layer, accepting only IPv4 UDP packets, which greatly reduces the number of packets that need to be processed. For non-DNS packets, they are filtered out at the BPF level and are not passed to user space, thereby improving system performance.
[0103] In one optional implementation, after successfully capturing and filtering IPv4 / UDP packets, the gateway device can perform deep parsing on the packets to identify DNS response packets and extract the queried domain name and its corresponding IP address information from the DNS response packets.
[0104] In some embodiments, the gateway device can first perform DNS protocol resolution on the data packet to obtain the IP header and UDP header. If the UDP port number is 53, the data packet is determined to be a DNS data packet. Then, the response flag (QR flag) field of the data packet is read and verified to determine if the data packet is a DNS response data packet; if QR equals 1, it is a DNS response data packet; if the QR bit is not 1, it is determined to be a non-response data packet and the resolution process is terminated. Afterwards, if the data packet is determined to be a DNS response data packet, the gateway device can extract the query domain name from the question count (qdcount) field of the DNS response data packet. After completing the domain name extraction, the gateway device can traverse the DNS answer records, checking the Type and Class fields of the answer records. When Type=1 (A record) and Class=1 (IN class), the 4-byte IPv4 address is read from the record data field (RDATA) and converted to dotted decimal format (e.g., "192.168.1.1"). In a real network environment, a single domain name may correspond to multiple IPv4 addresses (such as in content delivery networks (CDNs), load balancing, and other scenarios). When the ancount value in the response count (ancount) field is greater than 1 or there are multiple A records for the same domain, the system will extract and return all IPv4 addresses in sequence to ensure the integrity and availability of the resolution results.
[0105] In this embodiment, the domain name uses a DNS label length encoding format: each label is preceded by a length byte, and the label sequence ends with 0x00. If a high-order byte starting with xC0 is encountered, it represents a compressed pointer, and the system needs to jump to the position pointed to by the pointer to continue resolution in order to reconstruct the complete domain name. For example, the byte sequence {0x03 0x77 0x77 0x77 0x05 0x62 0x61 0x69 0x64 0x75 0x03 0x63 0x6f 0x6d 0x00} will be resolved to "www.baidu.com".
[0106] For example, Figure 4 This is a schematic diagram of a DNS response data packet structure provided in an embodiment of this application. Figure 4As shown, the DNS header includes a 12-byte structure, a question section, and a response section. The DNS header includes the ID (16 bits), flags (16 bits), number of questions (16 bits), number of responses (16 bits), number of authoritative records (16 bits), and number of supplementary records (16 bits). The question section includes the queried domain name (QNAME, variable length), query type (QTYPE, 16 bits), and query class (QCLASS, 16 bits). The response section includes the name pointer (16 bits), record type (TYPE, 16 bits), record class (CLASS, 16 bits), time to live (TTL, 32 bits), data length (16 bits), and IP address (32 bits).
[0107] Based on the above technical solution, this application can intercept DNS response packets in real time through raw sockets at the data link layer, without relying on the Android application layer network stack. Regardless of whether the DNS request comes from the Android application layer or the HAL layer, it can be uniformly intercepted and resolved, supporting network data diversion for HAL layer applications and covering network traffic of all applications in the entire system.
[0108] In one alternative implementation, the gateway device may search for a second route that matches the IP address to be accessed in the routing dataset if the first route does not exist, and then delete the second route; and after the target route is created, the target route may be added to the routing dataset.
[0109] In some embodiments, when the DNS resolution result changes, such as when the IP address corresponding to the domain name "www.baidu.com" changes from 192.168.1.100 to 192.168.1.200, the DNS can change the IP address corresponding to the domain name "www.baidu.com" in the first mapping dataset from 192.168.1.100 to 192.168.1.200. At this time, the IP address to be accessed in the DNS response packet returned by the DNS server becomes 192.168.1.200. In this case, the first route may not exist. Therefore, the gateway device can search for a second route matching 192.168.1.100 in the routing dataset, delete the second route, recreate the target route between 192.168.1.100 and www.baidu.com, APN, and network interface, and store the target route in the routing dataset.
[0110] In one optional implementation, the gateway device can monitor the current status of each APN in the activated APN set at a preset monitoring period and compare the current status of each APN with the status of each APN in the previous monitoring period. If an APN change is detected in the activated APN set, the gateway device can trigger an update of the configuration information in a preset configuration file, and, if the list of domain names corresponding to the second target APN in the preset configuration file changes, update the first mapping dataset.
[0111] The changes to APN include APN changing from inactive to active, APN changing from active to inactive, and changes to the network interface to which the APN is connected.
[0112] For example, when the network interface corresponding to APN1 changes from CCMNI1 to CCMNI4, the gateway device can update the mapping relationship between the second target APN1 and the network interface (APN1->CCMNI4). Afterwards, the gateway device can traverse all route entries through CCMNI1 in the routing table rt_apn1 corresponding to APN1. These route entries can be deleted using the `ip route del` command, such as `ip route del 192.168.1.100 / 32 dev ccmni1 table rt_apn1` or `ip route del 192.168.1.101 / 32 dev ccmni1 table rt_apn1`. Afterwards, the gateway device can re-add route entries for all IP addresses mapped to APN1, using the new interface name ccmni1, such as `ip route add 192.168.1.100 / 32dev ccmni4 table rt_apn1` or `ip route add 192.168.1.101 / 32 dev ccmni4 table rt_apn1`. If a default route exists in the routing table, the interface name also needs to be updated.
[0113] For example, when monitoring shows that APN1 has changed from inactive to active, the gateway device can update the configuration information of APN1 and the list of domain names corresponding to APN1 in the preset configuration file, create the routing table corresponding to APN1, and configure routing rules and routing entries.
[0114] For example, when monitoring shows that APN1 has changed from active to inactive (i.e., APN1 has disconnected), the gateway device can record the disconnection status of APN1, pause the configuration of new routing rules for APN1, and retain the existing routing rules and routing entries (so that APN1 can continue to use them after it recovers). When monitoring shows that APN1 has reconnected (i.e., changed from inactive to active), the gateway device can automatically restore the configuration of APN1's routing rules and routing entries.
[0115] For example, if the list of domain names corresponding to the second target APN (such as apn1) changes, the gateway device can update the mapping relationship between apn1 and the changed domain names in the first mapping dataset.
[0116] Based on the above technical solution, this application monitors the APN connection status in real time and automatically updates the routing rules when the APN connection status changes, thereby ensuring the effectiveness of the routing and improving the robustness of the system.
[0117] In one optional implementation, the gateway device supports dynamic updating of routing policies at runtime, enabling hot reloading of routing configurations without restarting processes or interrupting existing connections. Specifically, this includes: 1. Signal Handling Mechanism: The gateway device registers a function to handle the SIGHUP signal. When the administrator modifies the configuration file and sends the SIGHUP signal (kill -HUP), the signal is handled. <pid>When this happens, the gateway device immediately triggers the configuration reload process without needing to restart the service.
[0118] 2. Configuration file reload process: The gateway device reads and parses the new configuration file to obtain the mapping relationship between the new domain name and APN, compares it with the old configuration in memory, identifies the added, deleted, or modified mapping relationship, and performs different operations for different change types: 2-1. Add a new domain name mapping, add the new domain name to the monitoring list, and automatically generate and distribute the corresponding routing rules based on the resolution result after receiving the next DNS response for the domain name; 2-2. Deleting a domain name mapping will clear the iptables marking rules corresponding to the domain name, delete the IP routing cache entries corresponding to the domain name, and completely remove the mapping record of the domain name from the memory data structure. 2-3. Modify domain name mapping (e.g., map a domain name from APN1 to APN2): Delete the iptables rules and routing entries corresponding to the original APN (e.g., APN1), and configure routing rules for the new APN (to take effect after the next DNS response).
[0119] 3. Thread Safety Guarantee: To prevent resource contention between the configuration reload thread and the DNS response processing thread, the system employs a mutex mechanism to protect core data structures (including the domain name mapping table, routing state table, etc.): Before configuration reload begins, a global mutex is acquired first to block potentially concurrent DNS processing flows. Then, while holding the lock, configuration resolution, difference comparison, and routing rule updates are performed. Afterward, the mutex is released after the reload process ends, resuming multi-threaded parallel processing.
[0120] Based on the above technical solutions, this application, through the aforementioned mechanism, enables the system to achieve hot configuration updates while ensuring the integrity of the data structure and the real-time consistency of routing decisions. Furthermore, a mutex is used to protect shared data structures, ensuring data consistency in a multi-threaded environment. The lock is acquired before accessing shared data and released after access is completed, thereby avoiding data races and deadlocks. A memory pool is used to manage frequently allocated and released data structures, effectively reducing memory allocation overhead. A thread pool is used to handle routing configuration tasks, improving the system's concurrent processing capabilities.
[0121] Figure 5 This is a block diagram of a routing and traffic splitting device provided in an embodiment of this application. Figure 5 As shown, the routing and traffic splitting device includes: a processing unit 501, a communication unit 502, and a configuration unit 503.
[0122] Processing unit 501 is used to intercept DNS query packets at the data link layer; wherein, the DNS query packets are used to query the IP address to be accessed based on the domain name to be accessed; the target network interface for sending the DNS query packets is the hardware abstraction layer network interface or the application layer network interface. Communication unit 502 is used to send DNS query data packets to the DNS server so that the DNS server returns DNS response data packets; Configuration unit 503 is used to configure a target route for a target network interface based on the IP address to be accessed in the DNS response packet and a preset configuration file; wherein, the target route is used to indicate the routing path from the target network interface to the IP address to be accessed via a first target APN; the first target APN is an APN assigned to the target network interface; The communication unit 502 is also used to route and distribute data packets sent by the target network interface based on the target route.
[0123] In one possible approach, processing unit 501 is specifically configured to: intercept DNS query packets using raw sockets created on the data link layer; wherein the raw sockets are bound to each hardware abstraction layer network interface and each application layer network interface to receive data packets sent and received by each hardware abstraction layer network interface and each application layer network interface.
[0124] In one possible approach, configuration unit 503 is specifically used to: find a first route in a routing dataset that matches both the IP address to be accessed and the domain name to be accessed; wherein the routing dataset includes at least one previously created route, and the network interface, APN, domain name, and IP address corresponding to each of the at least one route; if the first route does not exist, create a target route based on the IP address to be accessed and a preset configuration file; if the first route exists, determine the first route as the target route; and configure the target route for the target network interface.
[0125] In one possible approach, the aforementioned preset configuration file includes: configuration information of the second target APN and a list of domain names corresponding to the second target APN; the configuration information includes: the type of data packets to be processed; wherein, the second target APN is one of the activated APNs. Based on this, configuration unit 503 is further configured to: create a target route based on a first tag corresponding to the DNS response data packet, the IP address to be accessed, and the preset configuration file; wherein, the first tag is used to indicate the type of data packets processed by the first target APN; the first target APN is an APN in the first mapping dataset that matches the domain name to be accessed; the first mapping dataset is a dataset determined based on the preset configuration file, used to characterize the correspondence between APNs and domain names.
[0126] In one possible approach, the above configuration information further includes: the name of the connected network interface, the routing table ID, and the routing table name. Based on this, the configuration unit 503 is further configured to: determine the routing table ID and routing table name corresponding to the target network interface and the first target APN based on the first tag; determine the target routing table from the routing table set based on the routing table ID and routing table name; wherein the target routing table is used to specify the first target APN for traffic splitting; and create a target route based on the target network interface, the target routing table, and the IP address to be accessed.
[0127] In one possible approach, the communication unit 502 is specifically used to: perform a first tagging process on the DNS query data packet to obtain a target DNS query data packet; send the target DNS query data packet to the DNS server so that the DNS server returns a DNS response data packet carrying the first tag based on a second mapping dataset; wherein, the second mapping dataset is a dataset used to characterize the correspondence between domain names and IP addresses.
[0128] In one possible approach, the processing unit 501 is further configured to: if the first route does not exist, search for a second route in the routing dataset that matches the IP address to be accessed; delete the second route; and, after the target route is created, add the target route to the routing dataset.
[0129] In one possible embodiment, the processing unit 501 is further configured to: in response to detecting an APN change in the activated APN set, trigger an update of the configuration information in the preset configuration file; the APN change includes an APN changing from inactive to active, an APN changing from active to inactive, and a change in the network interface connected to the APN; and, if the list of domain names corresponding to the second target APN in the preset configuration file changes, update the first mapping dataset.
[0130] Regarding the apparatus in the above embodiments, the specific manner in which each step is performed has been described in detail in the embodiments of the routing and traffic splitting method, and will not be elaborated here.
[0131] Figure 6 This is a block diagram of an electronic device provided in an embodiment of this application. For example... Figure 6 As shown, the electronic device includes, but is not limited to, a processor 601 and a memory 602.
[0132] The memory 602 described above is used to store the executable instructions of the processor 601. It is understood that the processor 601 is configured to execute instructions to implement the routing and traffic splitting method in the above embodiments.
[0133] It should be noted that those skilled in the art will understand that Figure 6 The electronic device structure shown does not constitute a limitation on the electronic device; the electronic device may include, but is not limited to, other electronic devices. Figure 6 This may indicate more or fewer components, or a combination of certain components, or a different arrangement of components.
[0134] Processor 601 is the control center of the electronic device. It connects various parts of the electronic device via various interfaces and lines. By running or executing software programs and / or modules stored in memory 602, and by calling data stored in memory 602, it performs various functions and processes data, thereby providing overall monitoring of the electronic device. Processor 601 may include one or more processing units. Processor 601 may integrate an application processor and a modem processor. The application processor mainly handles the operating system, user interface, and applications, while the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into processor 601.
[0135] The memory 602 can be used to store software programs and various data. The memory 602 may primarily include a program storage area and a data storage area. The program storage area may store the operating system, application programs required by at least one functional module (such as deterministic components, integrated components, etc.), etc. Furthermore, the memory 602 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0136] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory 602 including instructions, which can be executed by a processor 601 of an electronic device to implement the methods in the above embodiments.
[0137] In actual implementation, Figure 5 The functions of the processing unit 501, communication unit 502, and configuration unit 503 can all be provided by... Figure 6 The processor 601 calls the computer program stored in the memory 602 to implement the process. The specific execution process can be found in the description of the method section in the previous embodiment, and will not be repeated here.
[0138] Optionally, the computer-readable storage medium may be a non-transitory computer-readable storage medium, such as a read-only memory (ROM), random access memory (RAM), compact disc read-only memory (CD-ROM), magnetic tape, floppy disk, and optical data storage device. In an exemplary embodiment, this application also provides a computer program product including one or more instructions, which can be executed by the processor 601 of an electronic device to perform the methods in the above embodiments.
[0139] It should be noted that when one or more instructions in the computer-readable storage medium or computer program product are executed by the processor of an electronic device, they implement the various processes of the above method embodiments and achieve the same technical effect as the above method. To avoid repetition, they will not be described again here.
[0140] Through the above description of the embodiments, those skilled in the art can clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.
[0141] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another apparatus, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0142] The units described as separate components may or may not be physically separate. A component shown as a unit can be one or more physical units; that is, it can be located in one place or distributed in multiple different locations. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0143] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0144] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, essentially, or the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.
[0145] This application provides a computer program product containing instructions that, when run on a computer, cause the computer to perform the methods described in the above method embodiments.
[0146] This application also provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the method in the method flow shown in the above method embodiments.
[0147] The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium (a non-exhaustive list) include: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, a register, a hard disk, an optical fiber, a portable compact disk read-only memory, an optical storage device, a magnetic storage device, or any suitable combination thereof, or any other form of computer-readable storage medium well known in the art. An exemplary storage medium is coupled to a processor, enabling the processor to read information from and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can reside in an application-specific integrated circuit (ASIC). In embodiments of this application, the computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0148] Since the routing and splitting device, computer-readable storage medium, and computer program product in the embodiments of this application can adopt the above-described method, the technical effects they can achieve can also be referred to the above-described method embodiments. The embodiments of this application will not be repeated here.
[0149] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.< / pid>
Claims
1. A routing and traffic splitting method, characterized in that, The routing and traffic splitting method includes: Intercept DNS query packets at the data link layer; wherein, the DNS query packets are used to query the IP address to be accessed based on the domain name to be accessed; the target network interface for sending the DNS query packets is a hardware abstraction layer network interface or an application layer network interface; The DNS query data packet is sent to the DNS server, so that the DNS server returns a DNS response data packet; Based on the IP address to be accessed and the preset configuration file in the DNS response data packet, a target route is configured for the target network interface; wherein, the target route is used to indicate the routing path from the target network interface to the IP address to be accessed via a first target APN; the first target APN is an APN assigned to the target network interface; Based on the target route, the data packets sent by the target network interface are routed and diverted.
2. The routing method of claim 1, wherein, The interception of DNS query packets sent by the target network interface at the data link layer includes: The DNS query data packet is intercepted using a raw socket created on the data link layer; The original socket is bound to each hardware abstraction layer network interface and each application layer network interface to receive data packets sent and received by each hardware abstraction layer network interface and each application layer network interface.
3. The routing and traffic splitting method according to claim 1, characterized in that, The step of configuring a target route for the target network interface based on the IP address to be accessed and the preset configuration file in the DNS response data packet includes: The first route that matches both the IP address to be accessed and the domain name to be accessed is found in the routing dataset; wherein, the routing dataset includes at least one previously created route, and the network interface, APN, domain name and IP address corresponding to each of the at least one route; If the first route does not exist, the target route is created based on the IP address to be accessed and the preset configuration file; if the first route exists, the first route is determined as the target route. Configure the target route for the target network interface.
4. The routing and traffic splitting method according to claim 3, characterized in that, The preset configuration file includes: configuration information of the second target APN and a list of domain names corresponding to the second target APN; the configuration information includes: the type of data packet to be processed; wherein, the second target APN is one of the activated APNs in the set; The step of creating the target route based on the IP address to be accessed and the preset configuration file includes: The target route is created based on the first tag corresponding to the DNS response packet, the IP address to be accessed, and the preset configuration file; Wherein, the first tag is used to indicate the type of data packet processed by the first target APN; the first target APN is an APN in the first mapping dataset that matches the domain name to be accessed; the first mapping dataset is a dataset determined based on the preset configuration file and used to characterize the correspondence between APNs and domain names.
5. The routing and traffic splitting method according to claim 4, characterized in that, The configuration information also includes: the name of the connected network interface, the routing table ID, and the routing table name; The step of creating the target route based on the first tag corresponding to the DNS response packet, the IP address to be accessed, and the preset configuration file includes: Based on the first tag, determine the routing table ID and routing table name corresponding to the target network interface and the first target APN; Based on the routing table ID and the routing table name, a target routing table is determined from the routing table set; wherein, the target routing table is used to specify the first target APN for traffic splitting; The target route is created based on the target network interface, the target routing table, and the IP address to be accessed.
6. The routing and traffic splitting method according to claim 4, characterized in that, The step of sending the DNS query data packet to the DNS server, so that the DNS server returns a DNS response data packet, includes: The DNS query data packet is tagged with the first mark to obtain the target DNS query data packet; The target DNS query packet is sent to the DNS server, so that the DNS server returns a DNS response packet carrying the first tag based on the second mapping dataset; The second mapping dataset is a dataset used to represent the correspondence between domain names and IP addresses.
7. The routing and traffic splitting method according to claim 3, characterized in that, The routing and traffic splitting method also includes: If the first route does not exist, a second route matching the IP address to be accessed is searched in the route dataset; Delete the second route; Furthermore, after the target route is created, the target route is added to the route dataset.
8. The routing and traffic splitting method according to claim 3, characterized in that, The routing and traffic splitting method also includes: In response to the detection of an APN change in the activated APN set, the configuration information in the preset configuration file is updated; the APN change includes APN changing from inactive to active, APN changing from active to inactive, and changes in the network interface connected to the APN; In addition, if the list of domain names corresponding to the second target APN in the preset configuration file changes, the first mapping dataset is updated.
9. A routing splitting device, characterized in that, The routing and traffic splitting device includes: The processing unit is used to intercept DNS query packets at the data link layer; wherein the DNS query packets are used to query the IP address to be accessed based on the domain name to be accessed; the target network interface for sending the DNS query packets is a hardware abstraction layer network interface or an application layer network interface. A communication unit is configured to send the DNS query data packet to the DNS server, so that the DNS server returns a DNS response data packet; A configuration unit is configured to configure a target route for the target network interface based on the IP address to be accessed in the DNS response data packet and a preset configuration file; wherein the target route is used to indicate a routing path from the target network interface to the IP address to be accessed via a first target APN; the first target APN is an APN assigned to the target network interface; The communication unit is also used to route and distribute data packets sent by the target network interface based on the target route.
10. A vehicle, characterized in that, The vehicle includes the routing and diversion device as described in claim 9.