WO2016188240A1 - 配置多网卡的方法及装置 - Google Patents

配置多网卡的方法及装置 Download PDF

Info

Publication number
WO2016188240A1
WO2016188240A1 PCT/CN2016/078897 CN2016078897W WO2016188240A1 WO 2016188240 A1 WO2016188240 A1 WO 2016188240A1 CN 2016078897 W CN2016078897 W CN 2016078897W WO 2016188240 A1 WO2016188240 A1 WO 2016188240A1
Authority
WO
WIPO (PCT)
Prior art keywords
network
network card
address
routing table
cache list
Prior art date
Application number
PCT/CN2016/078897
Other languages
English (en)
French (fr)
Inventor
陈铭
郭热思
Original Assignee
中兴通讯股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 中兴通讯股份有限公司 filed Critical 中兴通讯股份有限公司
Publication of WO2016188240A1 publication Critical patent/WO2016188240A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/02Topology update or discovery
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/66Arrangements for connecting between networks having differing types of switching systems, e.g. gateways
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/24Multipath
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/54Organization of routing tables
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/74Address processing for routing
    • H04L45/745Address table lookup; Address filtering
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/50Queue scheduling
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming

Definitions

  • the present invention relates to the field of communications, and in particular to a method and apparatus for configuring multiple network cards.
  • the network card has become a common hardware device. It is common for one computer to configure two network cards (one wired network card and one wireless network card). One computer It is also frequent to configure up to three or more network cards.
  • DHCP Dynamic Host Configuration Protocol
  • IP Internet Protocol
  • a route conflict is encountered.
  • the problem for example, the network address that a network card can access when it is wired is not accessible when multiple network cards are wired at the same time. This is because the default gateway of multiple network cards causes confusion in the routing table of the operating system, and a network connection.
  • the present invention provides a method and apparatus for configuring a multiple network card to solve at least the problem of confusion in routing tables of multiple network cards configured by terminals in the related art.
  • a method for configuring a multiple network card including:
  • the method before the network connection socket to be established is bound to the network card, the method includes:
  • the testing the accessible network segment of the network card by using the socket and the configuration information includes:
  • ICMP Internet Control Message Protocol
  • the default gateway of the network card with the higher priority in the network card is the default gateway of the system, where the priority of the wired network card is higher than The priority of the wireless network card, the priority of the fast response network card is higher than the priority of the slow response network card.
  • the testing the accessible network segment of the network card by using the socket and the configuration information includes:
  • the network card performs a TCP handshake confirmation with the proxy server, and after the network card receives the response from the proxy server, confirms that the network card is a network card that can access an important intranet, and adds one to the network card according to the configuration information of the network card.
  • the destination address of the network is a proxy server, and the route is 255.255.255.255.
  • the route is 255.255.255.255.
  • the route is 255.255.255.255.255.
  • the network card with the highest priority in the network card adds a route to the network destination address of the proxy server with a mask of 255.255.255.255, and according to the The NIC configuration DNS address is additionally added to the route whose destination address is DNS address and whose mask is 255.255.255.255.255.
  • the priority of the wired network card is higher than the priority of the wireless network card, and the priority of the network card with fast response speed is higher than the priority of the network card with slow response speed.
  • the method further includes:
  • the character string of the start address of the preset character is parsed, and a route entry is added.
  • the method further includes:
  • the testing the accessible network segment of the network card by using the socket and the configuration information includes:
  • the testing the accessible network segment of the network card by using the socket and the configuration information includes:
  • the route of the network card with the higher priority is added, wherein the priority of the network card with the small network interface number is higher than the network interface number.
  • the priority of the NIC with a large value is the priority of the network card with the small network interface number.
  • At least one of the following is included:
  • the network card wiring event is monitored, and the cache list and the system routing table are updated according to the wiring event.
  • the monitoring the network card IP address configuration modification event, updating the cache list and the system routing table according to the modification event includes:
  • the IP address & subnet mask value of the network card is the same as the original IP address & atomic network mask value, and the subnet mask is the same as the atomic network mask.
  • the default gateway is the same as the original default gateway, but the replacement is performed. In the case of the IP address, the system routing table and the cache list remain unchanged;
  • the IP address & subnet mask value is different from the original IP address & atomic network mask value, or the subnet mask is not the same as the atomic mesh mask, or the default gateway is different from the original default gateway.
  • the network card related entry in the cache list, the established network connection socket is bound to the network card, and the accessible network segment of the network card is tested by using the socket and the configuration information, and the cache is updated. List and the system routing table.
  • the monitoring the network card pull event, updating the cache list and the system routing table according to the pull event :
  • monitoring the network card wiring event, updating the cache list and the system routing table according to the wiring event include:
  • the method after updating the cache list and the system routing table according to the test result, the method includes:
  • the network card that can receive the response is a network card that can access the peer address, and sends an ICMP packet to the peer address using the incremental hop value on each network card that can access the peer address, and receives the ICMP response packet.
  • the peer address related route of different priorities is stored in the cache list;
  • the method after updating the cache list and the system routing table according to the test result, the method includes:
  • an apparatus for configuring a multiple network card including:
  • a matching module configured to match a network connection and a route of the system, establish a cache list, and add the cache list to the system routing table;
  • a binding module configured to bind the established network connection socket to the network card, and test the accessible network segment of the network card by using the socket and the configuration information;
  • an update module configured to update the cache list according to the result of the testing, and further update to the system routing table.
  • the apparatus further comprises at least one of the following:
  • Modifying the monitoring module configured to monitor the NIC IP address configuration modification event, and updating the cache list and the system routing table according to the modification event;
  • the wire pull monitoring module is configured to monitor the network card pull event, and update the cache list and the system routing table according to the pull event;
  • the wiring monitoring module is configured to monitor the network card wiring event, and update the cache list and the system routing table according to the wiring event.
  • the device further includes:
  • the local network connection monitoring module is configured to determine whether the new network connection peer IP address falls within the private address range when the local network connection is detected, and the new network connection peer IP address is determined to fall. In the case of entering the private address range, determining whether the new network connection peer IP address is in a route other than the system default gateway in the system routing table, determining that the new network connection peer IP address is not In the case that the system routing table is in a route other than the system default gateway, copying the newly created network data packet, sending the network connection socket to each monitored network card, and receiving a response, in each The ICMP packet can be sent to the peer end address by using the incremental hop value, and the ICMP response packet is received, and the peer address related route of different priorities is saved in the cache list, according to the The routing of the network card in the cache list and the priority of the network card are summarized, and the route is merged and updated to the system routing table.
  • the device further includes:
  • the network newly established network connection monitoring module is configured to determine whether the IP addresses of the two ends of the newly established network connection fall within the private address range when the new network connection is detected in the network connected to the network card, and determine the new network connection. If the end IP address falls within the private address range, the network connection is monitored whether the new network connection receives a response, and when the response is received, the network card to which the new network connection belongs is determined, in the cache list. The route that presets the specified address of the specific priority is saved, and the route is merged or split and updated to the system routing table according to the route of the network card in the cache list and the priority of the network card.
  • the configuration information of the network card in the system is obtained, the network connection and the route of the system are matched, a cache list is established, and the cache list is added to the routing table of the system, and the established network connection socket is bound to the network connection socket.
  • a network card testing the accessible network segment of the network card by using the socket and the configuration information, updating the cache list according to the result of the test, and the The system routing table solves the confusion of the routing table, thereby achieving the effect of configuring the multi-network card adaptive network in the terminal.
  • FIG. 1 is a flow chart of configuring a multiple network card according to an embodiment of the present invention
  • FIG. 2 is a structural block diagram 1 of a processing apparatus for configuring a multiple network card according to an embodiment of the present invention
  • FIG. 3 is a structural block diagram 2 of a processing apparatus for configuring a multiple network card according to an embodiment of the present invention
  • FIG. 4 is a structural block diagram 3 of a processing apparatus for configuring a multiple network card according to an embodiment of the present invention
  • FIG. 5 is a structural block diagram 4 of a processing apparatus for configuring a multiple network card according to an embodiment of the present invention
  • FIG. 6 is a schematic diagram of a system for configuring a multiple network card according to an embodiment of the present invention.
  • FIG. 7 is a flowchart of a system pre-processing process for configuring a multiple network card according to an embodiment of the present invention
  • FIG. 8 is a flowchart of processing an IP address configuration modification event for configuring multiple network cards according to an embodiment of the present invention
  • FIG. 9 is a flowchart of processing a network card pull-out event processing for configuring multiple network cards according to an embodiment of the present invention.
  • FIG. 10 is a flowchart of processing a network card trunking event for configuring a multiple network card according to an embodiment of the present invention
  • FIG. 11 is a flowchart of a process of configuring a multi-network card to monitor a local new network connection according to an embodiment of the present invention
  • FIG. 12 is a flowchart of a process of configuring a new network connection in a network connected to a network card monitored by a multi-network card according to an embodiment of the present invention
  • FIG. 13 is a flowchart of a probe routing process for configuring multiple network cards according to an embodiment of the present invention.
  • FIG. 1 is a flowchart of configuring a multiple network card according to an embodiment of the present invention. As shown in FIG. 1 , the process includes the following steps:
  • Step S102 acquiring configuration information of the network card in the system
  • Step S104 matching the network connection and routing of the system, establishing a cache list, and adding the cache list to the system In the routing table;
  • Step S106 binding the established network connection socket to the network card, and testing the accessible network segment of the network card by using the socket and the configuration information;
  • Step S108 updating the cache list and the system routing table in the system routing table according to the result of the test.
  • the configuration information of the network card in the system is obtained, the network connection and the route of the system are matched, and a cache list is established.
  • the cache list includes: a destination address subnet mask, a local address, a network card, a response speed, a priority, and a status.
  • adding the cache list to the routing table of the system binding the established network connection socket to the network card, testing the accessible network segment of the network card through the socket and the configuration information, according to the result of the test
  • Updating the cache list and the routing table of the system solves the problem that the routing table of the multi-NIC is configured to be confusing, thereby achieving the effect of configuring the multi-NIC adaptive network of the terminal.
  • the method before the established network connection socket is bound to the network card, the method includes: deleting all the routes except the loopback network card and the virtual network card in the routing table of the system and matching the network connection of the system, without affecting the original
  • the system is used, effectively compatible with VPN and other virtual network cards, which can achieve a perfect transition when the program starts and the system environment changes.
  • the testing the accessible network segment of the network card by using the socket and the configuration information comprises: sending an Internet Control Message Protocol ICMP packet to a specified public network address protocol IP address, and receiving the ICMP response.
  • the packet determines the accessible network card of the public network according to the ICMP response packet, and the default gateway of the network card is the default gateway of the system, wherein, in the case that the network card of the accessible public network is multiple, the network card is confirmed
  • the default gateway of the high-priority network card is the default gateway of the system.
  • the priority of the wired network card is higher than the priority of the wireless network card.
  • the priority of the network card with fast response speed is higher than the priority of the network card with slow response speed. level.
  • the testing the accessible network segment of the network card by using the socket and the configuration information comprises: obtaining an Internet option configuration of the system, and parsing the proxy server if the Internet option is configured with a proxy server.
  • the IP address, the network card and the proxy server perform a TCP handshake confirmation, after the network card receives the response from the proxy server, confirm that the network card is a network card that can access the important intranet, and add a network destination address according to the configuration information of the network card.
  • the route is 255.255.255.255
  • the DNS address is additionally added to the network destination address as the DNS address and the mask is 255.255.255.255.255.
  • the network card is accessible to the important intranet.
  • the NIC with the highest priority in the NIC adds a route to the network destination address of the proxy server with a mask of 255.255.255.255, and adds the DNS address to the network destination address as the DNS address according to the NIC configuration.
  • the route with the mask is 255.255.255.255, wherein the priority of the wired network card is higher than that of the wireless network card.
  • the fast response speed priority NIC is higher than the priority of the slow response of the card.
  • the character string of the start address of the preset character is parsed, and a route entry is added.
  • the ICMP packet is sent to the proxy server by using the incremental hop value on the network card that can access the important intranet, and the ICMP response packet is received, and the IP address of each hop router of the NIC through the gateway to the proxy server is obtained. The address is added according to the priority of the network card and the proxy server.
  • the testing the accessible network segment of the network card by using the socket and the configuration information comprises: merging the same network card according to the route of the network card in the cache list and the priority of the network card Routing, updating the system routing table.
  • the testing the accessible network segment of the network card by using the socket and the configuration information comprises: parsing the IP address and the subnet mask configuration of the network card, and adding a network destination address to the IP address & subnet.
  • Mask value the mask is the subnet mask
  • the network interface is the network card
  • the gateway is the route corresponding to the IP address of the network card.
  • the priority is added. The routing of the network card of the high level, wherein the priority of the network card with a small network interface number is higher than the priority of the network card with a large network interface number.
  • the cache list and the system routing table after updating the cache list and the system routing table according to the test result, at least one of: listening to the network card IP address configuration modification event, updating the cache list and the system routing table according to the modification event, The network card pull-out event is monitored, the cache list and the system routing table are updated according to the pull-wire event, the network card wiring event is monitored, and the cache list and the system routing table are updated according to the connection event.
  • the network card IP address configuration modification event is monitored, and the cache list and the system routing table are updated according to the modification event, including: the IP address & subnet mask value of the network card, and the original IP address & atomic network.
  • the mask value is the same, and the subnet mask is the same as the atomic mesh mask.
  • the default gateway is the same as the original default gateway. If the IP address is replaced, the system routing table and the cache list remain unchanged.
  • the IP address & subnet mask value is different from the original IP address & atomic network mask value, or the subnet mask is not the same as the atomic mesh mask, or the default gateway is different from the original default gateway.
  • the network card related entry in the cache list, the established network connection socket is bound to the network card, and the accessible network segment of the network card is tested by the socket and the configuration information, and the cache list and the system routing table are updated.
  • listening to the network card pull-out event updating the cache list and the system routing table according to the pull-wire event includes: deleting an item related to the extracted network card in the routing table of the system, marking the extracted list in the cache list Line card related item status, merge routes according to the cache list, and update to the system routing table, delete the related items of the extracted network card in the cache list, and close the original network connection original socket.
  • listening to the network card connection event updating the cache list and the system routing table according to the connection event comprises: binding the established network connection socket to the network card, and testing by using the socket and the configuration information.
  • the network segment of the network card updates the cache list in the system routing table.
  • the method includes: when the local network connection is monitored, determining whether the new network connection peer IP address falls within the private address range. When it is determined that the new network connection peer IP address falls within the private address range, it is determined whether the new network connection peer IP address is in a route other than the system default gateway in the system routing table, and the judgment is made. If the new network connection peer IP address is not in the route other than the system default gateway in the system routing table, copy the new network data packet, send the network connection socket to each monitored network card, and receive the response.
  • the network card that can receive the response is a network card that can access the peer address, and sends an ICMP packet to the peer address by using an incremental hop value on each network card that can access the peer address, and receives the ICMP response packet.
  • the peer list address related route with different priorities is stored in the cache list, according to the cache column
  • the method includes: determining whether an IP address at both ends of the newly established network connection falls after monitoring a new network connection in the network connected to the network card.
  • the private address range if it is determined that the IP address of both ends of the newly established network connection falls within the private address range, it is monitored whether the newly established network connection receives a response, and when the response is received, the new network connection is determined.
  • the NIC belongs to the cache list, and the route of the specified priority-specific address is saved in the cache list, and the route is merged or split according to the route of the network card in the cache list and the priority of the network card, and is updated to the routing table of the system.
  • a device for configuring a plurality of network cards is provided, and the device is used to implement the foregoing embodiments and preferred embodiments, and details are not described herein.
  • the term "module” may implement a combination of software and/or hardware of a predetermined function.
  • the apparatus described in the following embodiments is preferably implemented in software, hardware, or a combination of software and hardware, is also possible and contemplated.
  • FIG. 2 is a structural block diagram 1 of a processing apparatus for configuring a multiple network card according to an embodiment of the present invention. As shown in FIG. 2, the device includes:
  • the obtaining module 22 is configured to obtain configuration information of the network card in the system
  • the binding module 26 is configured to bind the socket that establishes the network connection to the network card, and test the accessible network segment of the network card by using the socket and the configuration information;
  • the update module 28 is configured to update the cache list according to the result of the test and further update to the system routing table.
  • the obtaining module 22 acquires configuration information of the network card in the system, and the matching module 24 matches the network connection and routing of the system, and establishes a cache list, where the cache list includes: a destination address subnet mask, a local address, a network card, and a response speed. , priority, and status, and adding the cache list to the system routing table, the binding module 26 binds the socket establishing the network connection to the network card, and tests the network card through the socket and the configuration information.
  • the access network segment, the update module 28 updates the cache list and the system routing table according to the result of the test, and solves the problem that the terminal configures the routing table of the multiple network cards, thereby achieving the effect of configuring the multi-network card adaptive network of the terminal. .
  • FIG. 3 is a structural block diagram 2 of a processing apparatus for configuring a multiple network card according to an embodiment of the present invention. As shown in FIG. 3, in addition to the module of FIG. 2, the device further includes:
  • Modifying the monitoring module 32 configured to listen to the network card IP address configuration modification event, and update the cache list and the system routing table according to the modification event;
  • the cable interception module 34 is configured to monitor the network card pull event, and update the cache list and the system routing table according to the pull event;
  • the wiring monitoring module 36 is configured to monitor the network card wiring event, and update the cache list and the system according to the wiring event Routing table.
  • FIG. 4 is a structural block diagram 3 of a processing apparatus for configuring a multiple network card according to an embodiment of the present invention. As shown in FIG. 4, in addition to the module of FIG. 2, the apparatus further includes:
  • the local network connection monitoring module 42 is configured to determine whether the IP address of the new network connection peer falls within the private address range when the local network connection is monitored, and the IP address of the new network connection peer is determined to fall. In the case of the private address range, it is determined whether the new network connection peer IP address is in a route other than the system default gateway in the system routing table, and it is determined that the new network connection peer IP address is not in the system routing table. In the case of a route other than the default gateway of the system, copy the newly created network packet, send the network connection socket to each monitored network card and receive a response, and use it on each network card that can access the peer address.
  • the incremental hop value sends the ICMP packet to the peer address, and receives the ICMP response packet, and stores the peer-end address-related route of different priorities in the cache list, according to the route of the network card in the cache list and the priority of the network card. Merge the route and update to the system routing table.
  • FIG. 5 is a structural block diagram 4 of a processing apparatus for configuring a multiple network card according to an embodiment of the present invention. As shown in FIG. 5, in addition to the module of FIG. 2, the device further includes:
  • the network newly established network connection monitoring module 52 is configured to determine whether the IP addresses of the two ends of the newly established network connection fall within the private address range when the new network connection is detected in the network connected to the network card, and determine the two ends of the new network connection. If the IP address falls within the private address range, the network connection is monitored to receive a response. When the response is received, the network card to which the new network connection belongs is determined, and the preset specific priority is saved in the cache list. The route of the specified address is merged or split according to the route of the network card in the cache list and the priority of the network card, and is updated to the routing table of the system.
  • a preferred embodiment of the present invention provides a method of automatically configuring a routing table for adaptive network conditions in a multi-NIC operating system.
  • 6 is a schematic diagram of a system for configuring a multiple network card according to an embodiment of the present invention.
  • the method for adaptive network configuration of multiple network cards includes the following steps:
  • the network card that can receive the destination address arrival response is a network card that can access the public network (Internet)
  • its default gateway is the system default gateway. (ie added to the network destination address 0.0.0.0, the route with the mask 0.0.0.0). If there are multiple network cards that can access the Internet, select the wired network card and select the wired network card with the fastest response. The default gateway is the default gateway. If all the network cards that can access the public network are wireless network cards, select the wireless network card with the fastest response, and use the default gateway as the system default gateway. At the same time, according to the wired network card is higher than the wireless network card, the response speed is faster than the response speed.
  • the default gateway related routes of different priorities are saved in the internal cache table of the program.
  • the proxy server IP address is parsed, and the TCPSYN packet is sent to the designated port of the proxy server, and the SYN+ACK packet responded by the proxy server is received, and after receiving the response from the proxy server, the ACK is sent back to the proxy server.
  • Package and FIN package The network card that can receive the response is a network card that can access the important intranet (intranet or LAN), and add a route to the network destination address of the proxy server with a mask of 255.255.255.255 (if there are multiple proxy servers, the routing entry) There can also be more than one).
  • Intranet or LAN If there are multiple network cards that can access the important intranet (intranet or LAN), select the wired network card and select the wired network card with the fastest response. Add a network destination address to the proxy server.
  • the mask is A route of 255.255.255.255. If all the network cards that can access the important intranet (Intranet or LAN) are wireless network cards, select the wireless network card with the fastest response, and add a route to the network destination address proxy server with a mask of 255.255.255.255. .
  • an additional route to the network destination address is a DNS address and the mask is 255.255.255.255.
  • the current system Internet option is also configured with an exception, that is, if the proxy address server is not used for the address at the beginning of the following characters, the exception string is parsed and the corresponding route entry is added, such as parsing to 10.*.*.* or 10.*
  • the route is added to the network destination address is 10.0.0.0, the mask is 255.0.0.0, the network interface is the IP address of the network card that can access the important intranet (intranet or LAN), and the gateway is the gateway IP address corresponding to the network card; Parsing to 192.168.*.* or 192.168.* is added to the route with the network destination address of 192.168.0.0 and the mask of 255.255.0.0.
  • the network interface is the IP address of the network card that can access the important intranet (intranet or LAN).
  • the gateway is the gateway IP address corresponding to the network card.
  • the response speed is faster than the response speed is slow in the internal cache table of the program.
  • Store different priority proxy server related routes and use the same priority as the proxy server route to save the DNS related routes and exceptions in the program internal cache table to resolve the relevant routes and each hop router IP through the gateway to the proxy server.
  • the maximum subnet mask value of the target addresses is resolved (the maximum subnet mask) Value: Set to 1 from the most significant bit, the maximum value of each destination address IP address & the value obtained by the subnet mask).
  • the purpose of the merged route is to tailor the redundancy, improve the efficiency of the system routing table, and infer the approximate range of the network card accessible network segment according to known conditions, so as to facilitate the user's future network operations.
  • the gateway is the local route of the IP address corresponding to the NIC (if there are multiple IP addresses, there may be multiple routing entries).
  • the network card interface number is used for filtering, and only the one with the smallest network interface number serial number is saved.
  • the local related routes of different priorities are stored in the internal cache table of the program according to the network interface number whose value is smaller than the network interface number.
  • FIG. 7 is a flowchart of a system pre-processing process for configuring a multiple network card according to an embodiment of the present invention. As shown in FIG. 7, the process includes the following steps:
  • Step S701 acquiring all network card attributes
  • Step S702 acquiring system proxy settings
  • Step S703 obtaining all network connections
  • Step S704 establishing a cache list
  • Step S705 adding to the system routing table
  • Step S706 deleting a real network card in the system routing table to establish a network connection original (RAW) socket;
  • Step S707 establishing a network connection original (RAW) socket for each real network card
  • Step S708 binding the network card to the network connection original (RAW) socket established by each real network card
  • Step S709 detecting a route
  • step S710 the monitoring starts.
  • NIC IP address configuration modification event processing the steps include:
  • IP address & subnet mask value is the same as the original IP address & atomic network mask value and the subnet mask is the same as the atomic network mask, the default gateway and the original default gateway, only the IP address is replaced, the system The routing table and the program's internal cache table remain unchanged.
  • IP address and subnet mask value are different from the original IP address and the atomic network mask value, the subnet mask is not the same as the atomic mesh mask, or the default gateway is different from the original default gateway.
  • the current NIC related entry in the program internal cache table is different from the original IP address and the atomic network mask value, the subnet mask is not the same as the atomic mesh mask, or the default gateway is different from the original default gateway.
  • FIG. 8 is a flowchart of processing an IP address configuration modification event of a network card according to an embodiment of the present invention. As shown in FIG. 8, the process includes the following steps:
  • step S801 it is determined whether only the IP is replaced, and the subnet has not changed.
  • Step S802 when the determination is yes, the system routing table and the program internal cache table remain unchanged;
  • Step S803 when the determination is no, deleting the current network card related entry in the program internal cache table;
  • Step S804 establishing a network connection original (RAW) socket for the current network card
  • Step S805 binding the network card to the original network (RAW) socket established by the current network card
  • Step S806 detecting a route
  • step S807 the monitoring is started.
  • FIG. 9 is a flowchart of processing a network card pulling event according to an embodiment of the present invention. As shown in FIG. 9, the flow includes the following steps:
  • Step S901 deleting the current network card related entry in the system routing table
  • Step S902 marking the status of the related items of the extracted network card in the internal cache table of the program
  • Step S903 merging the routes according to the program internal cache table, and updating to the system routing table. Adding a priority of the entry in the program internal cache table that conflicts with the item related to the extracted network card to the system routing table;
  • Step S904 deleting the current network card related entry in the program internal cache table
  • step S905 the related network connection original (RAW) socket is closed.
  • NIC plug-in event processing the steps of which include
  • FIG. 10 is a flowchart of processing a network card patching event according to an embodiment of the present invention. As shown in FIG. 10, the process includes the following steps:
  • Step S1001 establishing a network connection original (RAW) socket for the current network card
  • Step S1002 Binding the network card to the original network (RAW) socket established by the current network card;
  • Step S1003 detecting a route
  • step S1004 the monitoring starts.
  • the steps include:
  • the NIC that can receive the response is the NIC that can access the peer address, and add a route to the peer address of the network with the mask of 255.255.255.255. If there are multiple network cards that can access the peer address, select the wired network card and select the wired network card with the fastest response. Add a destination address to the network as the peer address and the mask is 255.255.255.255. routing. If all the network cards that can access the peer address are wireless network cards, select the wireless network card with the fastest response, and add a route with the destination address of the network as the peer address and the mask of 255.255.255.255.
  • the response speed is faster than the response speed.
  • the peer address related routes of different priorities are stored in the internal cache table of the program, and the same priority as the peer address routing is used inside the program.
  • the cache table stores the IP-related routes of each hop router through the gateway to the peer address.
  • FIG. 11 is a flowchart of a process of monitoring a local new network connection according to an embodiment of the present invention. As shown in FIG. 11, the process includes the following steps:
  • Step S1101 determining whether the IP addresses of the two ends of the newly established network connection fall into the private address
  • Step S1102 When it is determined that the IP addresses of the two ends of the newly established network connection fall into the private address, determine whether the new network connection peer IP address is in a route other than the system default gateway in the current system routing table;
  • Step S1103 When it is determined that the new network connection peer IP address is not a route other than the system default gateway in the current system routing table, copy the packet;
  • Step S1104 sending on each network card
  • Step S1106 adding a route according to the wired network card being higher than the wireless network card, and the response speed is faster than the response speed;
  • Step S1107 obtaining all routes ip through which the local to remote ip passes;
  • Step S1109 merging routes in the cache list
  • Step S1110 Add a merge route to the system route.
  • step S1111 the merge route overlay route is deleted in the system route.
  • the steps include:
  • FIG. 12 is a flowchart of processing a new network connection in a network connected to a network card according to an embodiment of the present invention. As shown in FIG. 12, the process includes the following steps:
  • Step S1201 determining whether the IP addresses of the two ends of the newly established network connection fall into the private address
  • Step S1202 Listening to the response when determining that the IP address at both ends of the newly established network connection falls into the private address.
  • Step S1203 to check whether a response is received
  • step S1204 when the response is received, the current listening network card is obtained
  • Step S1205 saving to the cache list
  • Step S1207 adding a merge route to the system route
  • step S1208 the merge route overlay route is deleted in the system route.
  • FIG. 13 is a flowchart of a probe routing process according to an embodiment of the present invention. As shown in FIG. 13, the process includes the following steps:
  • Step S1301 Send an ICMP packet to a designated public network (Internet) IP address.
  • Step S1302 Receive an ICMP response packet.
  • Step S1303 according to the wired network card being higher than the wireless network card, the response speed is faster than the response speed to update the default gateway route;
  • Step S1304 testing the proxy server IP address by using the TCP SYN packet
  • Step S1306 responding to the ACK packet and the FIN packet
  • Step S1307 according to the wired network card being higher than the wireless network card, the response speed is faster than the response speed, and the access (critical intranet) proxy server routing is updated;
  • Step S1309 updating the access (critical intranet) proxy exception route
  • Step S1310 Acquire all routing IPs that are local to the proxy server IP
  • Step S1312 merging routes in the cache list
  • Step S1313 The merge route is updated in the system route.
  • Step S1314 adding a local subnet route according to the network card IP and the mask.
  • the invention adopts a software method, so that the local operating system has the function of automatically adapting the network to multiple network cards.
  • the method uses the principle that does not affect the original system, and is convenient to deploy. It can effectively be compatible with VPN and other virtual network cards, while retaining the original advanced functions of the system such as manual routing configuration, and can achieve a perfect transition when the program starts and the system environment changes.
  • the operating system adopting the method of the invention can meet the requirement of multi-network card connection in the increasingly complex network environment of the current user, and can be applied to the remote mapping of the USB network card redirection.
  • Embodiments of the present invention also provide a storage medium.
  • the foregoing storage medium may be Program code configured to store the method steps for performing the above embodiments:
  • the foregoing storage medium may include, but not limited to, a USB flash drive, a Read-Only Memory (ROM), a Random Access Memory (RAM), a mobile hard disk, and a magnetic memory.
  • ROM Read-Only Memory
  • RAM Random Access Memory
  • a mobile hard disk e.g., a hard disk
  • magnetic memory e.g., a hard disk
  • the processor executes according to the stored program code in the storage medium.
  • the processor executes according to the stored program code in the storage medium.
  • modules or steps of the present invention described above can be implemented by a general-purpose computing device that can be centralized on a single computing device or distributed across a network of multiple computing devices. Alternatively, they may be implemented by program code executable by the computing device such that they may be stored in the storage device by the computing device and, in some cases, may be different from the order herein.
  • the steps shown or described are performed, or they are separately fabricated into individual integrated circuit modules, or a plurality of modules or steps thereof are fabricated as a single integrated circuit module.
  • the invention is not limited to any specific combination of hardware and software.
  • the configuration information of the network card in the system is obtained, the network connection and the route of the system are matched, the cache list is established, and the cache list is added to the routing table of the system, and the established network connection is established.
  • the socket is bound to the network card, and the accessible network segment of the network card is tested through the socket and the configuration information, and the cache list and the system routing table are updated according to the result of the test, and the routing table is confused.
  • the effect of configuring a multi-network card adaptive network in the terminal is achieved.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

本发明提供了配置多网卡的方法及装置,其中,该方法包括:获取系统中网卡的配置信息;匹配该系统的网络连接和路由,建立缓存列表,并将该缓存列表添加至该系统路由表中;将建立的网络连接套接字绑定该网卡,通过该套接字和该配置信息测试该网卡的可访问网段;依据该测试的结果更新该缓存列表和该系统路由表。采用上述技术方案,解决了路由表的混乱的问题,进而达到了终端配置多网卡自适应网络的效果。

Description

配置多网卡的方法及装置 技术领域
本发明涉及通信领域,具体而言,涉及一种配置多网卡的方法及装置。
背景技术
在现在计算机硬件成本低廉、大量使用的情况下,网卡已经成了一种常见的硬件设备,一台计算机配置两个网卡(其中一个有线网卡,一个无线网卡)的情况已经很常见,一台计算机配置多达三个及以上的网卡的情况也频繁出现。但普通用户同时使用多个网卡时,如动态主机配置协议(Dynamic Host Configuration Protocol,简称为DHCP)或手动配置网卡网络地址协议(Internet Protocol,简称为IP)及默认网关时,会遇到路由冲突的问题,例如,某个网卡单个接线的时候能访问的网络地址在多个网卡同时接线的时候却访问不了,这是因为多个网卡的默认网关导致操作系统的路由表产生混乱,一个网络连接本来应该走某个网卡发包到对应的网关但是依据混乱的路由表走了另一个网卡发包,导致网络连接不成功。在通用串行总线(Universal Serial Bus,简称为USB)网卡设备重定向(映射)到远程操作系统时,这个混乱的路由表还可能导致用户与远程操作系统的连接断开。目前解决这个问题的方法只能由用户在操作系统中手动添加路由配置路由表来解决,这一解决办法对普通用户来说技术难度偏高,且用起来特别不方便。
针对相关技术中,终端配置多网卡的路由表混乱的问题,目前还没有有效解决方案。
发明内容
本发明提供了一种配置多网卡的方法及装置,以至少解决相关技术中终端配置多网卡的路由表混乱的问题。
根据本发明的一个实施例,提供了一种配置多网卡的方法,包括:
获取系统中网卡的配置信息;
匹配所述系统的网络连接和路由,建立缓存列表,并将所述缓存列表添加至所述系统路由表中;
将建立的网络连接套接字绑定所述网卡,通过所述套接字和所述配置信息测试所述网卡的可访问网段;
依据所述测试的结果更新所述缓存列表和所述系统路由表。
在本发明的实施例中,所述将建立的网络连接套接字绑定所述网卡之前,包括:
删除所述系统路由表中回环网卡,虚拟网卡以及匹配所述系统的网络连接的路由以外的所有路由。
在本发明的实施例中,所述通过所述套接字和所述配置信息测试所述网卡的可访问网段包括:
发送互联网控制报文协议ICMP包至指定公网网络地址协议IP地址,并接收到所述ICMP响应包,依据所述ICMP响应包确定可访问的公网的网卡,以所述网卡的默认网关为所述系统的默认网关;
其中,在所述可访问公网的网卡为多个的情况下,确认所述网卡中优先级高的网卡的默认网关为所述系统的默认网关,其中,有线网卡的所述优先级高于无线网卡的所述优先级,响应速度快的网卡的所述优先级高于响应速度慢的网卡的优先级。
在本发明的实施例中,所述通过所述套接字和所述配置信息测试所述网卡的可访问网段包括:
获取所述系统的Internet选项配置,在所述Internet选项配置有代理服务器的情况下,解析所述代理服务器IP地址;
所述网卡与所述代理服务器进行TCP握手确认,在所述网卡收到所述代理服务器的响应后,确认所述网卡为可访问重要内网的网卡,依据所述网卡的配置信息添加一条到网络目的地址为代理服务器,掩码为255.255.255.255的路由,并依据所述网卡配置DNS地址额外添加到网络目的地址为DNS地址,掩码为255.255.255.255的路由;
在可访问重要内网的所述网卡为多个的情况下,确认所述网卡中优先级高的网卡添加一条到网络目的地址为代理服务器,掩码为255.255.255.255的路由,并依据所述网卡配置DNS地址额外添加到网络目的地址为DNS地址,掩码为255.255.255.255的路由;
其中,有线网卡的所述优先级高于无线网卡的所述优先级,响应速度快的网卡的所述优先级高于响应速度慢的网卡的优先级。
在本发明的实施例中,所述方法还包括:
在所述系统的Internet选项配置预设字符开头地址不使用代理服务器的情况下,解析所述预设字符开头地址的字符串,添加路由条目。
在本发明的实施例中,所述方法还包括:
在可访问重要内网的所述网卡上使用递增的跳值发送ICMP包至代理服务器,并接收ICMP响应包,可得到所述网卡经网关至所述代理服务器的每一跳路由器IP地址;
依据所述网卡与所述代理服务器的所述优先级添加所述每一跳路由器IP地址的路由。
在本发明的实施例中,所述通过所述套接字和所述配置信息测试所述网卡的可访问网段包括:
依据所述缓存列表中的所述网卡的路由及其所述网卡的优先级,合并同一个所述网卡的路由,更新所述系统路由表。
在本发明的实施例中,所述通过所述套接字和所述配置信息测试所述网卡的可访问网段包括:
解析所述网卡的IP地址与子网掩码配置,添加一条网络目的地址为IP地址&子网掩码值,掩码为子网掩码,网络接口为所述网卡,网关为所述网卡对应的IP地址的路由;
在多张所述网卡解析得到的IP地址&子网掩码值相同的,添加优先级高的网卡的路由,其中,网络接口号序号值小的网卡的所述优先级高于网络接口号序号值大的网卡的所述优先级。
在本发明的实施例中,依据所述测试结果更新所述缓存列表和系统路由表之后,包括以下至少之一:
监听所述网卡IP地址配置修改事件,依据所述修改事件更新所述缓存列表和所述系统路由表;
监听所述网卡拔线事件,依据所述拔线事件更新所述缓存列表和所述系统路由表;
监听所述网卡接线事件,依据所述接线事件更新所述缓存列表和所述系统路由表。
在本发明的实施例中,监听所述网卡IP地址配置修改事件,依据所述修改事件更新所述缓存列表和所述系统路由表包括:
在所述网卡的IP地址&子网掩码值,与原IP地址&原子网掩码值相同,并且子网掩码与原子网掩码相同,默认网关与原默认网关相同,只是更换了所述IP地址的情况下,所述系统路由表和所述缓存列表保持不变;
在IP地址&子网掩码值,与原IP地址&原子网掩码值不相同,或者子网掩码与原子网掩码不相同,或者默认网关与原默认网关不相同的情况下,删除所述缓存列表中所述网卡相关条目,将建立的网络连接套接字绑定所述网卡,通过所述套接字和所述配置信息测试所述网卡的可访问网段,更新所述缓存列表和所述系统路由表。
在本发明的实施例中,监听所述网卡拔线事件,依据所述拔线事件更新所述缓存列表和所述系统路由表包括:
删除所述系统路由表中被拔线网卡相关条目;
标记所述缓存列表中所述被拔线网卡相关条目状态;
按照所述缓存列表合并路由,并更新到所述系统路由表;
删除所述缓存列表中所述被拔线网卡相关条目;
关闭相关网络连接原始套接字。
在本发明的实施例中,监听所述网卡接线事件,依据所述接线事件更新所述缓存列表和所述系统路由表包括:
将建立的网络连接套接字绑定所述网卡,通过所述套接字和所述配置信息测试所述网卡的可访问网段,更新所述缓存列表和所述系统路由表。
在本发明的实施例中,依据所述测试结果更新所述缓存列表和所述系统路由表之后,包括:
在监听到本地新建网络连接的情况下,判断所述新建网络连接对端IP地址是否落入私有地址范围内;
在判断所述新建网络连接对端IP地址落入所述私有地址范围内的情况下,判断新建网络连接对端IP地址是否在所述系统路由表中除所述系统默认网关以外的路由中;
在判断所述新建网络连接对端IP地址不是在所述系统路由表中除所述系统默认网关以外的路由中的情况下,复制所述新建网络数据包,发送所述网络连接套接字到每个被监听网卡并接收回应;
能收到响应的网卡为可访问对端地址的网卡,在每张所述可访问对端地址的网卡上使用递增的跳值发送ICMP包至对端地址,并接收所述ICMP响应包,在所述缓存列表中保存不同优先级的所述对端地址相关路由;
根据所述缓存列表中网卡的路由及网卡的优先级,合并所述路由并更新到所述系统路由表。
在本发明的实施例中,依据所述测试结果更新所述缓存列表和所述系统路由表之后,包括:
在监听到所述网卡所接网络中新建网络连接的情况下,判断新建网络连接两端IP地址是否落入私有地址范围内;
在判断所述新建网络连接两端IP地址落入所述私有地址范围内的情况下,监听所述新建网络连接是否收到回应,在监听到收到所述回应时,确定所述新建网络连接所属网卡;
在所述缓存列表中保存预设特定优先级指定地址的路由;
根据所述缓存列表中网卡的路由及网卡的优先级,合并或者拆分路由并更新到所述系统路由表。
根据本发明的另一实施例,提供了一种配置多网卡的装置,包括:
获取模块,设置为获取系统中网卡的配置信息;
匹配模块,设置为匹配所述系统的网络连接和路由,建立缓存列表,并将所述缓存列表添加至所述系统路由表中;
绑定模块,设置为将建立的网络连接套接字绑定到该网卡,通过所述套接字和所述配置信息测试所述网卡的可访问网段;
更新模块,设置为依据所述测试的结果更新所述缓存列表,再进一步更新到所述系统路由表中。
在本发明的实施例中,所述装置还包括以下至少之一:
修改监听模块,设置为监听所述网卡IP地址配置修改事件,依据所述修改事件更新所述缓存列表和所述系统路由表;
拔线监听模块,设置为监听所述网卡拔线事件,依据所述拔线事件更新所述缓存列表和所述系统路由表;
接线监听模块,设置为监听所述网卡接线事件,依据所述接线事件更新所述缓存列表和所述系统路由表。
在本发明的实施例中,所述装置还包括:
本地新建网络连接监听模块,设置为在监听到本地新建网络连接的情况下,判断所述新建网络连接对端IP地址是否落入私有地址范围内,在判断所述新建网络连接对端IP地址落入所述私有地址范围内的情况下,判断新建网络连接对端IP地址是否在所述系统路由表中除所述系统默认网关以外的路由中,在判断所述新建网络连接对端IP地址不是在所述系统路由表中除所述系统默认网关以外的路由中的情况下,复制所述新建网络数据包,发送所述网络连接套接字到每个被监听网卡并接收回应,在每张可访问对端地址的网卡上使用递增的跳值发送ICMP包至对端地址,并接收所述ICMP响应包,在所述缓存列表中保存不同优先级的所述对端地址相关路由,根据所述缓存列表中网卡的路由及网卡的优先级,合并所述路由并更新到所述系统路由表。
在本发明的实施例中,所述装置还包括:
网络新建网络连接监听模块,设置为在监听到所述网卡所接网络中新建网络连接的情况下,判断新建网络连接两端IP地址是否落入私有地址范围内,在判断所述新建网络连接两端IP地址落入所述私有地址范围内的情况下,监听所述新建网络连接是否收到回应,在监听到收到所述回应时,确定所述新建网络连接所属网卡,在所述缓存列表中保存预设特定优先级指定地址的路由,根据所述缓存列表中网卡的路由及网卡的优先级,合并或者拆分路由并更新到所述系统路由表。
通过本发明,采用获取系统中网卡的配置信息,匹配该系统的网络连接和路由,建立缓存列表,并将该缓存列表添加至该系统路由表中,将建立的网络连接套接字绑定该网卡,通过该套接字和该配置信息测试该网卡的可访问网段,依据该测试的结果更新该缓存列表和该 系统路由表,解决了的路由表的混乱的问题,进而达到了终端配置多网卡自适应网络的效果。
附图说明
此处所说明的附图用来提供对本发明的进一步理解,构成本申请的一部分,本发明的示意性实施例及其说明用于解释本发明,并不构成对本发明的不当限定。在附图中:
图1是根据本发明实施例的一种配置多网卡的流程图;
图2是根据本发明实施例的一种配置多网卡的处理装置的结构框图一;
图3是根据本发明实施例的一种配置多网卡的处理装置的结构框图二;
图4是根据本发明实施例的一种配置多网卡的处理装置的结构框图三;
图5是根据本发明实施例的一种配置多网卡的处理装置结构框图四;
图6是根据本发明实施例的一种配置多网卡的系统概要图;
图7是根据本发明实施例的一种配置多网卡的系统预处理处理流程图;
图8是根据本发明实施例的一种配置多网卡的IP地址配置修改事件处理流程图;
图9是根据本发明实施例的一种配置多网卡的网卡拔线事件处理处理流程图;
图10是根据本发明实施例的一种配置多网卡的网卡插线事件处理流程图;
图11是根据本发明实施例的一种配置多网卡的监听到本地新建网络连接处理流程图;
图12是根据本发明实施例的一种配置多网卡的监听到网卡所接网络中新建网络连接处理流程图;
图13是根据本发明实施例的一种配置多网卡的探测路由处理流程图。
具体实施方式
下文中将参考附图并结合实施例来详细说明本发明。需要说明的是,在不冲突的情况下,本申请中的实施例及实施例中的特征可以相互组合。
需要说明的是,本发明的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。
在本实施例中提供了一种配置多网卡的方法,图1是根据本发明实施例的一种配置多网卡的流程图,如图1所示,该流程包括如下步骤:
步骤S102,获取系统中网卡的配置信息;
步骤S104,匹配该系统的网络连接和路由,建立缓存列表,并将该缓存列表添加至该系 统路由表中;
步骤S106,将建立的网络连接套接字绑定该网卡,通过该套接字和该配置信息测试该网卡的可访问网段;
步骤S108,依据该测试的结果更新该系统路由表中的该缓存列表和该系统路由表。
通过上述步骤,获取系统中网卡的配置信息,匹配该系统的网络连接和路由,建立缓存列表,该缓存列表包括:目标地址子网掩码,本地地址,网卡,响应速度,优先级,和状态,并将该缓存列表添加至该系统路由表中,将建立的网络连接套接字绑定该网卡,通过该套接字和该配置信息测试该网卡的可访问网段,依据该测试的结果更新该缓存列表和该系统路由表,解决了终端配置多网卡的路由表混乱的问题,进而达到了终端配置多网卡自适应网络的效果。
在本实施例中,将建立的网络连接套接字绑定该网卡之前,包括:删除该系统路由表中回环网卡和虚拟网卡以及匹配该系统的网络连接的路由以外的所有路由,不影响原系统使用,有效兼容VPN等等虚拟网卡,能在程序启动和系统环境改变时实现完美过渡。
在本实施例中,该通过该套接字和该配置信息测试该网卡的可访问网段包括:发送互联网控制报文协议ICMP包至指定公网网络地址协议IP地址,并接收到该ICMP响应包,依据该ICMP响应包确定可访问的公网的网卡,以该网卡的默认网关为该系统的默认网关,其中,在该可访问公网的网卡为多个的情况下,确认该网卡中优先级高的网卡的默认网关为该系统的默认网关,其中,有线网卡的该优先级高于无线网卡的该优先级,响应速度快的网卡的该优先级高于响应速度慢的网卡的优先级。
在本实施例中,该通过该套接字和该配置信息测试该网卡的可访问网段包括:获取该系统的Internet选项配置,在该Internet选项配置有代理服务器的情况下,解析该代理服务器IP地址,该网卡与该代理服务器进行TCP握手确认,在该网卡收到该代理服务器的响应后,确认该网卡为可访问重要内网的网卡,依据该网卡的配置信息添加一条到网络目的地址为代理服务器,掩码为255.255.255.255的路由,并依据该网卡配置DNS地址额外添加到网络目的地址为DNS地址,掩码为255.255.255.255的路由,在可访问重要内网的该网卡为多个的情况下,确认该网卡中优先级高的网卡添加一条到网络目的地址为代理服务器,掩码为255.255.255.255的路由,并依据该网卡配置DNS地址额外添加到网络目的地址为DNS地址,掩码为255.255.255.255的路由,其中,有线网卡的该优先级高于无线网卡的该优先级,响应速度快的网卡的该优先级高于响应速度慢的网卡的优先级。
在本实施例中,在该系统的Internet选项配置预设字符开头地址不使用代理服务器的情况下,解析该预设字符开头地址的字符串,添加路由条目。
在本实施例中,在可访问重要内网的该网卡上使用递增的跳值发送ICMP包至代理服务器,并接收ICMP响应包,可得到该网卡经网关至该代理服务器的每一跳路由器IP地址,依据该网卡与该代理服务器的该优先级添加该每一跳路由器IP地址的路由。
在本实施例中,该通过该套接字和该配置信息测试该网卡的可访问网段包括:依据该缓存列表中的该网卡的路由及其该网卡的优先级,合并同一个该网卡的路由,更新该系统路由表。
在本实施例中,该通过该套接字和该配置信息测试该网卡的可访问网段包括:解析该网卡的IP地址与子网掩码配置,添加一条网络目的地址为IP地址&子网掩码值,掩码为子网掩码,网络接口为该网卡,网关为该网卡对应的IP地址的路由,在多张该网卡解析得到的IP地址&子网掩码值相同的,添加优先级高的网卡的路由,其中,网络接口号序号值小的网卡的该优先级高于网络接口号序号值大的网卡的该优先级。
在本实施例中,依据该测试结果更新该缓存列表和该系统路由表之后,包括以下至少之一:监听该网卡IP地址配置修改事件,依据该修改事件更新该缓存列表和该系统路由表,监听该网卡拔线事件,依据该拔线事件更新该缓存列表和该系统路由表,监听该网卡接线事件,依据该接线事件更新该缓存列表和该系统路由表。
在本实施例中,监听该网卡IP地址配置修改事件,依据该修改事件更新该缓存列表和该系统路由表包括:在该网卡的IP地址&子网掩码值,与原IP地址&原子网掩码值相同,并且子网掩码与原子网掩码相同,默认网关与原默认网关相同,只是更换了该IP地址的情况下,该系统路由表和该缓存列表保持不变。
在IP地址&子网掩码值,与原IP地址&原子网掩码值不相同,或者子网掩码与原子网掩码不相同,或者默认网关与原默认网关不相同的情况下,删除该缓存列表中该网卡相关条目,将建立的网络连接套接字绑定该网卡,通过该套接字和该配置信息测试该网卡的可访问网段,更新该缓存列表和该系统路由表。
在本实施例中,监听该网卡拔线事件,依据该拔线事件更新该缓存列表和该系统路由表包括:删除该系统路由表中被拔线网卡相关条目,标记该缓存列表中该被拔线网卡相关条目状态,按照该缓存列表合并路由,并更新到该系统路由表,删除该缓存列表中该被拔线网卡相关条目,关闭相关网络连接原始套接字。
在本实施例中,监听该网卡接线事件,依据该接线事件更新该缓存列表和该系统路由表包括:将建立的网络连接套接字绑定该网卡,通过该套接字和该配置信息测试该网卡的可访问网段,更新该系统路由表中的该缓存列表。
在本实施例中,依据该测试结果更新该缓存列表和该系统路由表之后,包括:在监听到本地新建网络连接的情况下,判断该新建网络连接对端IP地址是否落入私有地址范围内,在判断该新建网络连接对端IP地址落入该私有地址范围内的情况下,判断新建网络连接对端IP地址是否在该系统路由表中除该系统默认网关以外的路由中,在判断该新建网络连接对端IP地址不是在该系统路由表中除该系统默认网关以外的路由中的情况下,复制该新建网络数据包,发送该网络连接套接字到每个被监听网卡并接收回应,能收到响应的网卡为可访问对端地址的网卡,在每张该可访问对端地址的网卡上使用递增的跳值发送ICMP包至对端地址,并接收该ICMP响应包,在该缓存列表中保存不同优先级的该对端地址相关路由,根据该缓存列 表中网卡的路由及网卡的优先级,合并该路由并更新到该系统路由表。
在本实施例中,依据该测试结果更新该缓存列表和该系统路由表之后,包括:在监听到该网卡所接网络中新建网络连接的情况下,判断新建网络连接两端IP地址是否落入私有地址范围内,在判断该新建网络连接两端IP地址落入该私有地址范围内的情况下,监听该新建网络连接是否收到回应,在监听到收到该回应时,确定该新建网络连接所属网卡,在该缓存列表中保存预设特定优先级指定地址的路由,根据该缓存列表中网卡的路由及网卡的优先级,合并或者拆分路由并更新到该系统路由表。
在本实施例中还提供了一种配置多网卡的装置,该装置用于实现上述实施例及优选实施方式,已经进行过说明的不再赘述。如以下所使用的,术语“模块”可以实现预定功能的软件和/或硬件的组合。尽管以下实施例所描述的装置较佳地以软件来实现,但是硬件,或者软件和硬件的组合的实现也是可能并被构想的。
图2是根据本发明实施例的一种配置多网卡的处理装置的结构框图一,如图2所示,该装置包括:
获取模块22,设置为获取系统中网卡的配置信息;
匹配模块24,设置为匹配该系统的网络连接和路由,建立缓存列表,并将该缓存列表添加至该系统路由表中;
绑定模块26,设置为将建立网络连接的套接字绑定到该网卡,通过该套接字和该配置信息测试该网卡的可访问网段;
更新模块28,设置为依据该测试的结果更新该缓存列表,再进一步更新到该系统路由表中。
通过上述步骤,获取模块22获取系统中网卡的配置信息,匹配模块24匹配该系统的网络连接和路由,建立缓存列表,该缓存列表包括:目标地址子网掩码,本地地址,网卡,响应速度,优先级,和状态,并将该缓存列表添加至该系统路由表中,绑定模块26将建立网络连接的套接字绑定到该网卡,通过该套接字和该配置信息测试该网卡的可访问网段,更新模块28依据该测试的结果更新该缓存列表和该系统路由表,解决了终端配置多网卡的路由表的混乱的问题,进而达到了终端配置多网卡自适应网络的效果。
图3是根据本发明实施例的一种配置多网卡的处理装置的结构框图二,如图3所示,除了图2的模块外,该装置还包括:
修改监听模块32,设置为监听该网卡IP地址配置修改事件,依据该修改事件更新该缓存列表和该系统路由表;
拔线监听模块34,设置为监听该网卡拔线事件,依据该拔线事件更新该缓存列表和该系统路由表;
接线监听模块36,设置为监听该网卡接线事件,依据该接线事件更新该缓存列表和该系 统路由表。
图4是根据本发明实施例的一种配置多网卡的处理装置的结构框图三,如图4所示,除了图2的模块外,该装置还包括:
本地新建网络连接监听模块42,设置为在监听到本地新建网络连接的情况下,判断该新建网络连接对端IP地址是否落入私有地址范围内,在判断该新建网络连接对端IP地址落入该私有地址范围内的情况下,判断新建网络连接对端IP地址是否在该系统路由表中除该系统默认网关以外的路由中,在判断该新建网络连接对端IP地址不是在该系统路由表中除该系统默认网关以外的路由中的情况下,复制该新建网络数据包,发送该网络连接套接字到每个被监听网卡并接收回应,在每张可访问对端地址的网卡上使用递增的跳值发送ICMP包至对端地址,并接收该ICMP响应包,在该缓存列表中保存不同优先级的该对端地址相关路由,根据该缓存列表中网卡的路由及网卡的优先级,合并该路由并更新到该系统路由表。
图5是根据本发明实施例的一种配置多网卡的处理装置结构框图四,如图5所示,除了图2的模块外,该装置还包括:
网络新建网络连接监听模块52,设置为在监听到该网卡所接网络中新建网络连接的情况下,判断新建网络连接两端IP地址是否落入私有地址范围内,在判断该新建网络连接两端IP地址落入该私有地址范围内的情况下,监听该新建网络连接是否收到回应,在监听到收到该回应时,确定该新建网络连接所属网卡,在该缓存列表中保存预设特定优先级指定地址的路由,根据该缓存列表中网卡的路由及网卡的优先级,合并或者拆分路由并更新到该系统路由表。
下面结合优选实施例和实施方式对本发明进行详细说明。
本发明的优选实施例的提供了一种在多网卡操作系统中自适应网络情况自动配置路由表的方法。图6是根据本发明实施例的一种配置多网卡的系统概要图,
该多网卡自适应网络配置的方法,其步骤包括:
1.系统预处理,其步骤包括:
1)获取当前系统所有网卡属性值(网卡类型、网络接口号或网络接口名等等)及其IP地址与默认网关及DNS配置。
2)获取当前系统Internet选项代理服务器配置。
3)获取当前系统网络连接列表。
4)在程序内部建立一个关于目标地址、子网掩码、网关、本地地址、网卡、响应速度、优先级和状态的缓存列表,针对当前系统网络连接与当前系统路由进行匹配保存进入程序内部缓存列表中同时添加至系统路由表中(即添加到网络连接对端地址,掩码为255.255.255.255的路由)。
5)删除系统路由表中除回环网卡(loopback)和虚拟网卡(如VPN,其路由由虚拟网关相关程序进行维护)相关路由及匹配当前系统网络连接的路由以外的所有路由,其目的为不影响系统当前(网络连接)使用。
6)针对除回环网卡(loopback)和虚拟网卡(如VPN,其路由由虚拟网关相关程序进行维护)以外的每一个网卡,建立网络连接原始(RAW)套接字,绑定(bind)该网卡(IP地址),使当前套接字数据发送到该网卡,并进行以下测试以判断该网卡可访问网段并以此为依据重建系统路由表及保存进入程序内部缓存表中作为后面处理网卡拔插事件及配置修改事件的依据:
a)发送ICMP包至指定公网(Internet)IP地址,并接收ICMP响应包,其中能收到目标地址到达响应的网卡为可访问公网(Internet)的网卡,以其默认网关为系统默认网关(即添加到网络目的地址0.0.0.0,掩码为0.0.0.0的路由)。如果可访问公网(Internet)的网卡有多个,则选择其中的有线网卡,并选择其中响应速度最快的那张有线网卡,以其默认网关为系统默认网关。如果可访问公网(Internet)的网卡全部为无线网卡,则也选择其中响应速度最快的那张无线网卡,以其默认网关为系统默认网关。同时按照有线网卡高于无线网卡,响应速度快高于响应速度慢在程序内部缓存表中保存不同优先级的默认网关相关路由。
b)如果当前系统Internet选项配置有代理服务器,则解析代理服务器IP地址,并发送TCPSYN包至代理服务器指定端口,接收代理服务器响应的SYN+ACK包,得到代理服务器响应后,向代理服务器回复ACK包和FIN包。其中能收到响应的网卡为可访问重要内网(Intranet或LAN)的网卡,添加一条到网络目的地址为代理服务器,掩码为255.255.255.255的路由(如果代理服务器有多个,则路由条目也可以有多条)。如果可访问重要内网(Intranet或LAN)的网卡有多个,则选择其中的有线网卡,并选择其中响应速度最快的那张有线网卡,添加一条到网络目的地址为代理服务器,掩码为255.255.255.255的路由。如果可访问重要内网(Intranet或LAN)的网卡全部为无线网卡,则也选择其中响应速度最快的那张无线网卡,添加一条到网络目的地址为代理服务器,掩码为255.255.255.255的路由。
另外,再依据该网卡配置DNS地址额外添加到网络目的地址为DNS地址,掩码为255.255.255.255的路由。
如果当前系统Internet选项还配置有例外情况,即对于下列字符开头的地址不使用代理服务器,则解析该例外情况字符串,添加相应路由条目,如解析到10.*.*.*或10.*则添加到网络目的地址为10.0.0.0,掩码为255.0.0.0的路由,网络接口为可访问重要内网(Intranet或LAN)的网卡的IP地址,网关为该网卡对应的网关IP地址;如解析到192.168.*.*或192.168.*则添加到网络目的地址为192.168.0.0,掩码为255.255.0.0的路由,网络接口为可访问重要内网(Intranet或LAN)的网卡的IP地址,网关为该网卡对应的网关IP地址。
在每张可访问重要内网(Intranet或LAN)的网卡上使用递增的跳(metric)值发送ICMP包至代理服务器,并接收ICMP响应包,可得到从本地网卡经网关至代理服务器的每一跳路由器IP地址。
同时,按照有线网卡高于无线网卡,响应速度快高于响应速度慢在程序内部缓存表中保 存不同优先级的代理服务器相关路由,并采用与代理服务器路由相同优先级在程序内部缓存表中保存DNS相关路由及例外情况字符串解析所得相关路由和经网关至代理服务器的每一跳路由器IP相关路由。
c)根据程序内部缓存表中已知路由及其优先级,合并路由并更新到系统路由表,即添加合并后的路由并删除原系统路由表中相关路由。路由合并只有来源于同一网卡的路由才能合并,合并前先判断是否私有地址(10.0.0.0-10.255.255.255、172.16.0.0—172.31.255.255、192.168.0.0-192.168.255.255),并判断该路由中目标地址是否落入这三个私有地址段中的某一个,如果有多个目标地址落入某一个私有地址段,则解析这几个目标地址的最大子网掩码值(最大子网掩码值:从最高位bit开始置1,每个目标地址IP地址&该子网掩码得到的值相等的最大数值)。合并路由的目的是裁剪冗余,提升系统路由表使用效率,以及根据已知条件推断该网卡可访问网段大概范围,以利于用户以后的网络操作。
7)针对每一张网卡,解析其IP地址与子网掩码配置,并据此添加一条网络目的地址为IP地址&子网掩码,掩码为子网掩码,网络接口为该网卡,网关为该网卡对应的IP地址的本地路由(如果IP地址有多个,则路由条目也可以有多条)。当多张网卡解析得到的IP地址&子网掩码相同的,根据网卡网络接口号进行筛选,只保存网络接口号序号值最小的那条。
同时,按照网络接口号序号值小的高于网络接口号序号值大的在程序内部缓存表中保存不同优先级的本地相关路由。
8)开始对除回环网卡和虚拟网卡外的每张网卡网络连接的监听,并监听网卡IP地址配置修改事件和网卡拔线接线事件。
图7是根据本发明实施例的一种配置多网卡的系统预处理处理流程图,如图7所示,该流程包括如下步骤:
步骤S701,获取所有网卡属性;
步骤S702,获取系统代理设置;
步骤S703,获取所有网络连接;
步骤S704,建立缓存列表;
步骤S705,添加到系统路由表;
步骤S706,删除系统路由表中真实网卡建立网络连接原始(RAW)套接字;
步骤S707,为每个真实网卡建立网络连接原始(RAW)套接字;
步骤S708,为每个真实网卡建立的网络连接原始(RAW)套接字绑定该网卡;
步骤S709,探测路由;
步骤S710,开始监听。
2.网卡IP地址配置修改事件处理,其步骤包括:
1)当IP地址&子网掩码值与原IP地址&原子网掩码值相同并且子网掩码与原子网掩码相同、默认网关与原默认网关时,即只是更换了IP地址,系统路由表与程序内部缓存表保持不变。
2)在IP地址和子网掩码值,与原IP地址和原子网掩码值不相同,子网掩码与原子网掩码不相同,或者默认网关与原默认网关不相同的情况下,删除程序内部缓存表中当前网卡相关条目。
3)建立网络连接原始(RAW)套接字,绑定(bind)当前网卡(IP地址),使当前套接字数据发送到该网卡,并进行系统预处理中相同的测试更新到程序内部缓存表中。
4)按照程序内部缓存表合并路由,并更新到系统路由表。遇到有冲突的条目先比较优先级,优先级高时删除系统路由表中原条目再添加新条目,优先级低时则不处理。
图8是根据本发明实施例的一种网卡IP地址配置修改事件处理流程图,如图8所示,该流程包括如下步骤:
步骤S801,判断是否只更换了IP,所处子网未变?
步骤S802,在判断为是时,系统路由表与程序内部缓存表保持不变;
步骤S803,在判断为否时,删除程序内部缓存表中当前网卡相关条目;
步骤S804,为当前网卡建立网络连接原始(RAW)套接字;
步骤S805,为当前网卡建立的网络连接原始(RAW)套接字绑定该网卡;
步骤S806,探测路由;
步骤S807,开始监听。
3.网卡拔线(或移除)事件处理,图9是根据本发明实施例的一种网卡拔线事件处理流程图,如图9所示,该流程包括如下步骤:
步骤S901,删除系统路由表中当前网卡相关条目;
步骤S902,标记程序内部缓存表中被拔线网卡相关条目状态;
步骤S903,按照程序内部缓存表合并路由,并更新到系统路由表。将程序内部缓存表中与被拔线网卡相关条目有冲突的条目次一个优先级的添加到系统路由表;
步骤S904,删除程序内部缓存表中当前网卡相关条目;
步骤S905,关闭相关网络连接原始(RAW)套接字。
4.网卡插线事件处理,其步骤包括,
1)建立网络连接原始(RAW)套接字,绑定当前网卡(IP地址),使当前套接字数据发送到该网卡,并进行系统预处理中相同的测试更新到程序内部缓存表中。
2)按照程序内部缓存表合并路由,并更新到系统路由表。遇到有冲突的条目先比较优先级,优先级高时删除系统路由表中原条目再添加新条目,优先级低时则不处理。
图10是根据本发明实施例的一种网卡插线事件处理流程图,如图10所示,该流程包括如下步骤:
步骤S1001,为当前网卡建立网络连接原始(RAW)套接字;
步骤S1002,为当前网卡建立的网络连接原始(RAW)套接字绑定该网卡;
步骤S1003,探测路由;
步骤S1004,开始监听。
5.监听到(本地)新建网络连接的处理,其步骤包括:
1)判断新建网络连接对端IP地址是否落入私有地址(10.0.0.0-10.255.255.255、172.16.0.0—172.31.255.255、192.168.0.0-192.168.255.255)范围内,如果不是,则不处理。
2)判断新建网络连接对端IP地址是否当前系统路由表中除系统默认网关以外的路由中,如果是,则不处理。
3)复制该网络数据包,通过前面建立的每个网络连接原始(RAW)套接字,在每个被监听网卡上进行发送并接收回应,得到响应后,如果复制网络数据包为TCP SYN包则回复ACK包和FIN包。其中能收到响应的网卡为可访问对端地址的网卡,添加一条到网络目的地址为对端地址,掩码为255.255.255.255的路由。如果可访问对端地址的网卡有多个,则选择其中的有线网卡,并选择其中响应速度最快的那张有线网卡,添加一条到网络目的地址为对端地址,掩码为255.255.255.255的路由。如果可访问对端地址的网卡全部为无线网卡,则也选择其中响应速度最快的那张无线网卡,添加一条到网络目的地址为对端地址,掩码为255.255.255.255的路由。
4)在每张可访问对端地址的网卡上使用递增的跳值发送ICMP包至对端地址,并接收ICMP响应包,可得到从本地网卡经网关至对端地址的每一跳路由器IP地址。
5)同时,按照有线网卡高于无线网卡,响应速度快高于响应速度慢在程序内部缓存表中保存不同优先级的对端地址相关路由,并采用与对端地址路由相同优先级在程序内部缓存表中保存经网关至对端地址的每一跳路由器IP相关路由。
6)根据程序内部缓存表中已知路由及其优先级,合并路由并更新到系统路由表,添加合并后的路由并删除原系统路由表中相关路由。
图11是根据本发明实施例的一种监听到本地新建网络连接处理流程图,如图11所示,该流程包括如下步骤:
步骤S1101,判断新建网络连接两端IP地址是否落入私有地址;
步骤S1102,在判断新建网络连接两端IP地址是落入私有地址时,判断新建网络连接对端IP地址是否当前系统路由表中除系统默认网关以外的路由中;
步骤S1103,判断新建网络连接对端IP地址不是当前系统路由表中除系统默认网关以外的路由时,复制包;
步骤S1104,在每张网卡上发送;
步骤S1105,接收响应;
步骤S1106,按有线网卡高于无线网卡,响应速度快高于响应速度慢添加路由;
步骤S1107,获取本地至远程ip所经由的所有路由ip;
步骤S1108,保存到缓存列表;
步骤S1109,缓存列表中合并路由;
步骤S1110,系统路由中添加合并路由;
步骤S1111,系统路由中删除合并路由覆盖路由。
6.监听到(网卡所接网络中)新建网络连接的处理,其步骤包括:
1)判断新建网络连接两端IP地址是否落入私有地址(10.0.0.0-10.255.255.255、172.16.0.0—172.31.255.255、192.168.0.0-192.168.255.255)范围内,如果不是,则不处理。
2)监听该新建网络连接是否收到回应(即回应IP包源地址与目的地址与新建网络连接ip包相反),如果不是,则不处理。
3)判断当前网络连接所属网卡。
4)在程序内部缓存表中保存特定优先级指定地址相关路由(掩码为255.255.255.255,网卡为网络连接所属网卡)。
5)根据程序内部缓存表中已知路由及其优先级,合并(或拆分,即一个大的地址范围拆分成3个小的地址范围,两个属于原网卡,一个属于新网卡)路由并更新到系统路由表,添加合并后的路由并删除原系统路由表中相关路由。
图12是根据本发明实施例的一种监听到网卡所接网络中新建网络连接处理流程图,如图12所示,该流程包括如下步骤:
步骤S1201,判断新建网络连接两端IP地址是否落入私有地址;
步骤S1202,在判断新建网络连接两端IP地址是落入私有地址时,监听回应
步骤S1203,查看是否收到回应
步骤S1204,在收到回应时,获取当前监听网卡;
步骤S1205,保存到缓存列表;
步骤S1206,缓存列表中合并路由;
步骤S1207,系统路由中添加合并路由
步骤S1208,系统路由中删除合并路由覆盖路由。
图13是根据本发明实施例的一种探测路由处理流程图,如图13所示,该流程包括如下步骤:
步骤S1301,发送ICMP包至指定公网(Internet)IP地址;
步骤S1302,接收ICMP响应包;
步骤S1303,按有线网卡高于无线网卡,响应速度快高于响应速度慢更新默认网关路由;
步骤S1304,使用TCP SYN包测试代理服务器IP地址;
步骤S1305,接收TCP响应SYN+ACK包;
步骤S1306,回应ACK包和FIN包;
步骤S1307,按有线网卡高于无线网卡,响应速度快高于响应速度慢更新访问(重要内网)代理服务器路由;
步骤S1308,更新访问(重要内网)DNS服务器路由;
步骤S1309,更新访问(重要内网)代理例外路由;
步骤S1310,获取本地至代理服务器IP所经由的所有路由IP;
步骤S1311,保存到缓存列表;
步骤S1312,缓存列表中合并路由;
步骤S1313,系统路由中更新合并路由;
步骤S1314,根据网卡IP与掩码添加本地子网路由。
本发明采用软件的方法,使得本地操作系统具备多网卡自动适应网络的功能。本方法使用不影响原系统使用的原则,部署方便,可以有效兼容VPN等等虚拟网卡,同时保留手动路由配置等系统原有高级功能,能在程序启动和系统环境改变时实现完美过渡。采用本发明方法的操作系统能够满足当前用户越来越复杂的网络环境下多网卡衔接的需求,并可应用于USB网卡重定向远程映射。
本发明的实施例还提供了一种存储介质。可选地,在本实施例中,上述存储介质可以被 设置为存储用于执行上述实施例的方法步骤的程序代码:
可选地,在本实施例中,上述存储介质可以包括但不限于:U盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。
可选地,在本实施例中,处理器根据存储介质中已存储的程序代码执行…
可选地,在本实施例中,处理器根据存储介质中已存储的程序代码执行…
可选地,本实施例中的具体示例可以参考上述实施例及可选实施方式中所描述的示例,本实施例在此不再赘述。
显然,本领域的技术人员应该明白,上述的本发明的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,可选地,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本发明不限制于任何特定的硬件和软件结合。
以上所述仅为本发明的优选实施例而已,并不用于限制本发明,对于本领域的技术人员来说,本发明可以有各种更改和变化。凡在本发明的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本发明的保护范围之内。
工业实用性
基于本发明实施例提供的上述技术方案,获取系统中网卡的配置信息,匹配该系统的网络连接和路由,建立缓存列表,并将该缓存列表添加至该系统路由表中,将建立的网络连接套接字绑定该网卡,通过该套接字和该配置信息测试该网卡的可访问网段,依据该测试的结果更新该缓存列表和该系统路由表,解决了的路由表的混乱的问题,进而达到了终端配置多网卡自适应网络的效果。

Claims (18)

  1. 一种配置多网卡的方法,包括:
    获取系统中网卡的配置信息;
    匹配所述系统的网络连接和路由,建立缓存列表,并将所述缓存列表添加至所述系统路由表中;
    将建立的网络连接套接字绑定所述网卡,通过所述套接字和所述配置信息测试所述网卡的可访问网段;
    依据所述测试的结果更新所述缓存列表和所述系统路由表。
  2. 根据权利要求1所述的方法,其中,所述将建立的网络连接套接字绑定所述网卡之前,包括:
    删除所述系统路由表中回环网卡,虚拟网卡以及匹配所述系统的网络连接的路由以外的所有路由。
  3. 根据权利要求2所述的方法,其中,所述通过所述套接字和所述配置信息测试所述网卡的可访问网段包括:
    发送互联网控制报文协议ICMP包至指定公网网络地址协议IP地址,并接收到所述ICMP响应包,依据所述ICMP响应包确定可访问的公网的网卡,以所述网卡的默认网关为所述系统的默认网关;
    其中,在所述可访问公网的网卡为多个的情况下,确认所述网卡中优先级高的网卡的默认网关为所述系统的默认网关,其中,有线网卡的所述优先级高于无线网卡的所述优先级,响应速度快的网卡的所述优先级高于响应速度慢的网卡的优先级。
  4. 根据权利要求1所述的方法,其中,所述通过所述套接字和所述配置信息测试所述网卡的可访问网段包括:
    获取所述系统的Internet选项配置,在所述Internet选项配置有代理服务器的情况下,解析所述代理服务器IP地址;
    所述网卡与所述代理服务器进行TCP握手确认,在所述网卡收到所述代理服务器的响应后,确认所述网卡为可访问重要内网的网卡,依据所述网卡的配置信息添加一条到网络目的地址为代理服务器,掩码为255.255.255.255的路由,并依据所述网卡配置DNS地址额外添加到网络目的地址为DNS地址,掩码为255.255.255.255的路由;
    在可访问重要内网的所述网卡为多个的情况下,确认所述网卡中优先级高的网卡添加一条到网络目的地址为代理服务器,掩码为255.255.255.255的路由,并依据所述网卡配置DNS地址额外添加到网络目的地址为DNS地址,掩码为255.255.255.255的路由;
    其中,有线网卡的所述优先级高于无线网卡的所述优先级,响应速度快的网卡的所 述优先级高于响应速度慢的网卡的优先级。
  5. 根据权利要求4所述的方法,其中,包括:
    在所述系统的Internet选项配置预设字符开头地址不使用代理服务器的情况下,解析所述预设字符开头地址的字符串,添加路由条目。
  6. 根据权利要求4所述的方法,其中,包括:
    在可访问重要内网的所述网卡上使用递增的跳值发送ICMP包至代理服务器,并接收ICMP响应包,可得到所述网卡经网关至所述代理服务器的每一跳路由器IP地址;
    依据所述网卡与所述代理服务器的所述优先级添加所述每一跳路由器IP地址的路由。
  7. 根据权利要求4所述的方法,其中,所述通过所述套接字和所述配置信息测试所述网卡的可访问网段包括:
    依据所述缓存列表中的所述网卡的路由及其所述网卡的优先级,合并同一个所述网卡的路由,更新所述系统路由表。
  8. 根据权利要求4所述的方法,其中,所述通过所述套接字和所述配置信息测试所述网卡的可访问网段包括:
    解析所述网卡的IP地址与子网掩码配置,添加一条网络目的地址为IP地址&子网掩码值,掩码为子网掩码,网络接口为所述网卡,网关为所述网卡对应的IP地址的路由;
    在多张所述网卡解析得到的IP地址&子网掩码值相同的,添加优先级高的网卡的路由,其中,网络接口号序号值小的网卡的所述优先级高于网络接口号序号值大的网卡的所述优先级。
  9. 根据权利要求1所述的方法,其中,依据所述测试结果更新所述缓存列表和所述系统路由表之后,所述方法还包括以下至少之一:
    监听所述网卡IP地址配置修改事件,依据所述修改事件更新所述缓存列表和所述系统路由表;
    监听所述网卡拔线事件,依据所述拔线事件更新所述缓存列表和所述系统路由表;
    监听所述网卡接线事件,依据所述接线事件更新所述缓存列表和所述系统路由表。
  10. 根据权利要求9所述的方法,其中,监听所述网卡IP地址配置修改事件,依据所述修改事件更新所述缓存列表和所述系统路由表包括:
    在所述网卡的IP地址&子网掩码值,与原IP地址&原子网掩码值相同,并且子网掩码与原子网掩码相同,默认网关与原默认网关相同,只是更换了所述IP地址的情况下,所述系统路由表和所述缓存列表保持不变;
    在IP地址&子网掩码值,与原IP地址&原子网掩码值不相同,或者子网掩码与原子网掩码不相同,或者默认网关与原默认网关不相同的情况下,删除所述缓存列表中所述网卡相关条目,将建立的网络连接套接字绑定所述网卡,通过所述套接字和所述配置信息测试所述网卡的可访问网段,更新所述缓存列表和所述系统路由表。
  11. 根据权利要求9所述的方法,其中,监听所述网卡拔线事件,依据所述拔线事件更新所述缓存列表和所述系统路由表包括:
    删除所述系统路由表中被拔线网卡相关条目;
    标记所述缓存列表中所述被拔线网卡相关条目状态;
    按照所述缓存列表合并路由,并更新到所述系统路由表;
    删除所述缓存列表中所述被拔线网卡相关条目;
    关闭相关网络连接原始套接字。
  12. 根据权利要求9所述的方法,其中,监听所述网卡接线事件,依据所述接线事件更新所述缓存列表和所述系统路由表包括:
    将建立的网络连接套接字绑定所述网卡,通过所述套接字和所述配置信息测试所述网卡的可访问网段,更新所述缓存列表和所述系统路由表。
  13. 根据权利要求1所述的方法,其中,依据所述测试结果更新所述缓存列表和所述系统路由表之后,包括:
    在监听到本地新建网络连接的情况下,判断所述新建网络连接对端IP地址是否落入私有地址范围内;
    在判断所述新建网络连接对端IP地址落入所述私有地址范围内的情况下,判断新建网络连接对端IP地址是否在所述系统路由表中除所述系统默认网关以外的路由中;
    在判断所述新建网络连接对端IP地址不是在所述系统路由表中除所述系统默认网关以外的路由中的情况下,复制所述新建网络数据包,发送所述网络连接套接字到每个被监听网卡并接收回应;
    能收到响应的网卡为可访问对端地址的网卡,在每张所述可访问对端地址的网卡上使用递增的跳值发送ICMP包至对端地址,并接收所述ICMP响应包,在所述缓存列表中保存不同优先级的所述对端地址相关路由;
    根据所述缓存列表中网卡的路由及网卡的优先级,合并所述路由并更新到所述系统路由表。
  14. 根据权利要求1所述的方法,其中,依据所述测试结果更新所述缓存列表和所述系统路由表之后,包括:
    在监听到所述网卡所接网络中新建网络连接的情况下,判断新建网络连接两端IP地址是否落入私有地址范围内;
    在判断所述新建网络连接两端IP地址落入所述私有地址范围内的情况下,监听所述新建网络连接是否收到回应,在监听到收到所述回应时,确定所述新建网络连接所属网卡;
    在所述缓存列表中保存预设特定优先级指定地址的路由;
    根据所述缓存列表中网卡的路由及网卡的优先级,合并或者拆分路由并更新到所述系统路由表。
  15. 一种配置多网卡的装置,包括:
    获取模块,设置为获取系统中网卡的配置信息;
    匹配模块,设置为匹配所述系统的网络连接和路由,建立缓存列表,并将所述缓存列表添加至所述系统路由表中;
    绑定模块,设置为将建立的网络连接套接字绑定到所述网卡,通过所述套接字和所述配置信息测试所述网卡的可访问网段;
    更新模块,设置为依据所述测试的结果更新所述缓存列表,再进一步更新到所述系统路由表中。
  16. 根据权利要求15所述的装置,其中,所述装置还包括以下至少之一:
    修改监听模块,设置为监听所述网卡IP地址配置修改事件,依据所述修改事件更新所述缓存列表和所述系统路由表;
    拔线监听模块,设置为监听所述网卡拔线事件,依据所述拔线事件更新所述缓存列表和所述系统路由表;
    接线监听模块,设置为监听所述网卡接线事件,依据所述接线事件更新所述缓存列表和所述系统路由表。
  17. 根据权利要求15所述的装置,其中,所述装置还包括:
    本地新建网络连接监听模块,设置为在监听到本地新建网络连接的情况下,判断所述新建网络连接对端IP地址是否落入私有地址范围内,在判断所述新建网络连接对端IP地址落入所述私有地址范围内的情况下,判断新建网络连接对端IP地址是否在所述系统路由表中除所述系统默认网关以外的路由中,在判断所述新建网络连接对端IP地址不是在所述系统路由表中除所述系统默认网关以外的路由中的情况下,复制所述新建网络数据包,发送所述网络连接套接字到每个被监听网卡并接收回应,在每张可访问对端地址的网卡上使用递增的跳值发送ICMP包至对端地址,并接收所述ICMP响应包,在所述缓存列表中保存不同优先级的所述对端地址相关路由,根据所述缓存列表中网卡的路由及 网卡的优先级,合并所述路由并更新到所述系统路由表。
  18. 根据权利要求15所述的装置,其中,所述装置还包括:
    网络新建网络连接监听模块,设置为在监听到所述网卡所接网络中新建网络连接的情况下,判断新建网络连接两端IP地址是否落入私有地址范围内,在判断所述新建网络连接两端IP地址落入所述私有地址范围内的情况下,监听所述新建网络连接是否收到回应,在监听到收到所述回应时,确定所述新建网络连接所属网卡,在所述缓存列表中保存预设特定优先级指定地址的路由,根据所述缓存列表中网卡的路由及网卡的优先级,合并或者拆分路由并更新到所述系统路由表。
PCT/CN2016/078897 2016-01-07 2016-04-08 配置多网卡的方法及装置 WO2016188240A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201610008161.4A CN106953795B (zh) 2016-01-07 2016-01-07 配置多网卡的方法及装置
CN201610008161.4 2016-01-07

Publications (1)

Publication Number Publication Date
WO2016188240A1 true WO2016188240A1 (zh) 2016-12-01

Family

ID=57392473

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/078897 WO2016188240A1 (zh) 2016-01-07 2016-04-08 配置多网卡的方法及装置

Country Status (2)

Country Link
CN (1) CN106953795B (zh)
WO (1) WO2016188240A1 (zh)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109104329A (zh) * 2018-07-02 2018-12-28 四川斐讯信息技术有限公司 一种测试路由器与网卡兼容性的系统
CN110134687A (zh) * 2019-05-13 2019-08-16 福建南威软件有限公司 一种通过表字段的动态增改控制清单要素的方法及系统
CN112398936A (zh) * 2020-11-06 2021-02-23 浪潮云信息技术股份公司 一种基于Kubernetes的多网卡容器实现方法及系统
CN113037563A (zh) * 2021-03-26 2021-06-25 山东英信计算机技术有限公司 一种云平台网络优化方法、装置、系统及可读存储介质
CN114928567A (zh) * 2022-02-09 2022-08-19 浙江远望信息股份有限公司 一种基于网络扫描技术的多网卡设备发现的方法
CN115086207A (zh) * 2022-06-14 2022-09-20 深信服科技股份有限公司 一种网卡检测方法、装置及电子设备和存储介质
CN115499346A (zh) * 2022-09-15 2022-12-20 巨擎网络科技(济南)有限公司 一种多网卡的测速方法、装置、设备及介质
WO2023193432A1 (zh) * 2022-04-06 2023-10-12 华为云计算技术有限公司 一种数据转发方法及相关设备

Families Citing this family (23)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107592209B (zh) * 2016-07-08 2021-04-02 北京奇虎科技有限公司 一种多网卡服务器自动配置ip地址信息的方法和系统
CN107453898A (zh) * 2017-07-21 2017-12-08 郑州云海信息技术有限公司 一种网络系统及其网络配置方法
CN108494679B (zh) * 2018-06-01 2020-01-07 武汉绿色网络信息服务有限责任公司 一种基于Linux系统实现路由器的SSH报文转发方法和装置
CN108718279B (zh) * 2018-06-01 2020-04-28 武汉绿色网络信息服务有限责任公司 一种基于Linux系统实现路由器的portal认证报文转发方法和装置
CN108880885B (zh) * 2018-06-19 2021-09-21 杭州迪普科技股份有限公司 一种报文处理方法及装置
CN110798491B (zh) * 2018-08-01 2022-10-28 北京国双科技有限公司 一种网络访问方法及装置、代理服务器
CN109451085B (zh) * 2018-10-12 2021-08-10 厦门亿联网络技术股份有限公司 一种通过ip地址伪装实现网络隔离的方法及装置
CN109150638A (zh) * 2018-11-01 2019-01-04 郑州云海信息技术有限公司 一种路由管理方法及装置
CN109448351A (zh) * 2018-12-03 2019-03-08 中国水利水电科学研究院 有线网络和无线网络混合通信的方法及装置
CN110138890B (zh) * 2019-05-13 2022-04-05 广州视源电子科技股份有限公司 获取ip地址的方法、装置、计算机设备和存储介质
CN112152927B (zh) * 2019-06-26 2022-09-02 杭州海康威视数字技术股份有限公司 一种报文转发方法、系统及网卡和存储介质
CN110661679B (zh) * 2019-09-06 2021-10-01 苏州浪潮智能科技有限公司 一种测试网卡的方法、装置、计算机存储介质及终端
CN111092934B (zh) * 2019-11-26 2022-06-07 福建天泉教育科技有限公司 更新客户端路由的方法、存储介质
CN111245728A (zh) * 2020-01-10 2020-06-05 华云数据有限公司 具多网卡计算装置的数据报文转发方法及系统
CN111314146B (zh) * 2020-02-25 2023-04-07 杭州涂鸦信息技术有限公司 一种iot设备服务网络切换方法和系统及其设备
CN111405639B (zh) * 2020-03-09 2022-05-13 深圳前海百递网络有限公司 无线网络连接方法、装置、可读存储介质和计算机设备
CN111600741A (zh) * 2020-04-02 2020-08-28 怀来斯达铭数据有限公司 一种设置网卡ip地址的方法及系统
CN111817962B (zh) * 2020-07-01 2022-06-14 厦门立林科技有限公司 一种安卓系统多网卡智能路由的方法
CN112260947B (zh) * 2020-10-21 2022-08-05 北京如影智能科技有限公司 一种网络配置的方法及装置
CN112311625B (zh) * 2020-10-26 2022-05-20 珠海格力电器股份有限公司 网络的管理方法和装置、存储介质、电子装置
CN113098722A (zh) * 2021-04-09 2021-07-09 山东有人物联网股份有限公司 多网卡管理方法、装置及计算机可读存储介质
CN113543146B (zh) * 2021-07-16 2024-02-09 杭州迈冲科技有限公司 基于Android系统的网络共存的控制方法及装置
CN113918326A (zh) * 2021-09-29 2022-01-11 聚好看科技股份有限公司 一种处理请求的方法及装置

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1519742A (zh) * 2003-01-23 2004-08-11 英业达股份有限公司 可均衡负载的网卡测试方法
CN1992732A (zh) * 2005-12-30 2007-07-04 英业达股份有限公司 网卡自动配置系统及方法
CN101917281A (zh) * 2010-06-10 2010-12-15 福建升腾资讯有限公司 一种网卡自动配置方法
US7937499B1 (en) * 2004-07-09 2011-05-03 Oracle America, Inc. Methods and apparatus for dynamically switching between polling and interrupt mode for a ring buffer of a network interface card

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1519742A (zh) * 2003-01-23 2004-08-11 英业达股份有限公司 可均衡负载的网卡测试方法
US7937499B1 (en) * 2004-07-09 2011-05-03 Oracle America, Inc. Methods and apparatus for dynamically switching between polling and interrupt mode for a ring buffer of a network interface card
CN1992732A (zh) * 2005-12-30 2007-07-04 英业达股份有限公司 网卡自动配置系统及方法
CN101917281A (zh) * 2010-06-10 2010-12-15 福建升腾资讯有限公司 一种网卡自动配置方法

Cited By (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109104329A (zh) * 2018-07-02 2018-12-28 四川斐讯信息技术有限公司 一种测试路由器与网卡兼容性的系统
CN109104329B (zh) * 2018-07-02 2023-11-07 深圳市速速优科技有限公司 一种测试路由器与网卡兼容性的系统
CN110134687A (zh) * 2019-05-13 2019-08-16 福建南威软件有限公司 一种通过表字段的动态增改控制清单要素的方法及系统
CN112398936A (zh) * 2020-11-06 2021-02-23 浪潮云信息技术股份公司 一种基于Kubernetes的多网卡容器实现方法及系统
CN112398936B (zh) * 2020-11-06 2023-03-28 浪潮云信息技术股份公司 一种基于Kubernetes的多网卡容器实现方法及系统
CN113037563A (zh) * 2021-03-26 2021-06-25 山东英信计算机技术有限公司 一种云平台网络优化方法、装置、系统及可读存储介质
CN114928567A (zh) * 2022-02-09 2022-08-19 浙江远望信息股份有限公司 一种基于网络扫描技术的多网卡设备发现的方法
CN114928567B (zh) * 2022-02-09 2023-08-29 浙江远望信息股份有限公司 一种基于网络扫描技术的多网卡设备发现的方法
WO2023193432A1 (zh) * 2022-04-06 2023-10-12 华为云计算技术有限公司 一种数据转发方法及相关设备
CN115086207A (zh) * 2022-06-14 2022-09-20 深信服科技股份有限公司 一种网卡检测方法、装置及电子设备和存储介质
CN115499346A (zh) * 2022-09-15 2022-12-20 巨擎网络科技(济南)有限公司 一种多网卡的测速方法、装置、设备及介质
CN115499346B (zh) * 2022-09-15 2024-04-26 巨擎网络科技(济南)有限公司 一种多网卡的测速方法、装置、设备及介质

Also Published As

Publication number Publication date
CN106953795A (zh) 2017-07-14
CN106953795B (zh) 2020-07-31

Similar Documents

Publication Publication Date Title
WO2016188240A1 (zh) 配置多网卡的方法及装置
US10659354B2 (en) Processing data packets using a policy based network path
EP3401783B1 (en) Method and apparatus for determining virtual machine migration
US8261339B2 (en) Dynamic network tunnel endpoint selection
US10341131B2 (en) Avoiding unknown unicast floods resulting from MAC address table overflows
US10178068B2 (en) Translating network attributes of packets in a multi-tenant environment
US20200068005A1 (en) Transferring files between computer nodes on different networks
EP3285159A1 (en) Access method and device for random access memories, control chip and storage medium
CN109561164B (zh) Nat表项的管理方法、装置及nat设备
CN104811473A (zh) 一种创建虚拟非易失性存储介质的方法、系统及管理系统
JP2019097133A (ja) 通信監視システム及び通信監視方法
CN113038594B (zh) Mesh扩展设备网络管理注册方法和装置
US9749262B2 (en) Packet processing method and forwarding element
WO2016034006A1 (zh) 一种报文发送方法及接入设备
JP6056857B2 (ja) 通信制御装置及び通信制御方法
US20150256620A1 (en) Information processing apparatus, information processing system, information processing method and recording medium recording information processing program
JP6605149B2 (ja) 共有端末の検出方法及びその装置
CN115865816A (zh) 一种网络负载均衡方法及装置
CN111711710B (zh) 访问MongoDB复制集集群的方法、装置、设备及存储介质
CN108011989B (zh) 一种重定向方法及装置
CN108848033B (zh) 一种规避路由冲突的方法、装置及存储介质
CN108712316B (zh) 一种虚拟机的接入配置方法、装置和系统
JP6256471B2 (ja) 通信装置、通信方法、及びプログラム
JP2012222461A (ja) ネットワークシステム
JP5147769B2 (ja) 端末検出方法、端末検出プログラム、および端末検出装置

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16799129

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16799129

Country of ref document: EP

Kind code of ref document: A1