Server BGP access method and device, electronic equipment and readable storage medium

By mounting an eBPF program on the server's logical network interface card (NIC), data packets are redirected to the correct physical NIC based on their destination address. This solves the configuration complexity problem of BGP connections between servers and switches under destacking technology, improving access efficiency and reliability.

CN121940337APending Publication Date: 2026-04-28NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
NETEASE (HANGZHOU) NETWORK CO LTD
Filing Date
2026-01-28
Publication Date
2026-04-28

AI Technical Summary

Technical Problem

In destabilization technology application scenarios, when servers and switches establish BGP connections, existing technologies are incompatible with bonding configurations, resulting in high switch configuration complexity, high maintenance difficulty, and low access efficiency.

Method used

By mounting an eBPF program on the logical network interface card (NIC), the forwarding destination is determined based on the destination address of the data packet, and the data packet is redirected to the correct physical NIC to achieve a BGP connection, thus reducing configuration complexity.

Benefits of technology

While retaining the logical network interface card (NIC), an accurate BGP connection from the server to the switch was achieved, improving access efficiency and reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121940337A_ABST
    Figure CN121940337A_ABST
Patent Text Reader

Abstract

The invention provides a server BGP access method and device, electronic equipment and a readable storage medium, and the method comprises the steps: detecting whether a destination address of a data packet is a switch gateway address or not according to the destination address of the data packet sent by a server; if the destination address of the data packet is the gateway address of the switch, detecting whether the current physical network card is a physical network card transferred to the switch corresponding to the gateway address of the switch based on the destination address through an eBPF program mounted on the current physical network card; and if the current physical network card is not transferred to the physical network card of the switch corresponding to the switch gateway address, redirecting and forwarding the data packet to a target physical network card of the switch corresponding to the switch gateway address, and forwarding the data packet to the corresponding switch through the target physical network card. Therefore, the configuration complexity of accessing the server to the switch is reduced, and the reliability and the access efficiency of accessing the server to the switch are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to server BGP access methods, apparatus, electronic devices, and readable storage media. Background Technology

[0002] In data center networking, to ensure high availability of network devices, switch stacking technology is often used on access layer switches. At least two physical network cards are aggregated on the server side to form a logical network card Bonding. A Border Gateway Protocol (BGP) connection can be established between the server and the switch. However, the reliability of switch stacking technology is generally low, and maintenance and upgrades are difficult. Therefore, destacking technology has begun to be used in data center networking. In scenarios where switch destacking technology is applied, such as how the server establishes a BGP connection with the switch, this has become an urgent problem to be solved.

[0003] In related technologies, network interface card (NIC) bonding is no longer used on servers. Instead, multiple NICs are treated as independent links. In this approach, each NIC on the server needs to be configured with an independent address, which is incompatible with the bonding configurations widely used in current servers and cannot reuse the capabilities already provided by bonding itself. The connection between the server and the switch is changed to multiple Layer 3 links. Compared with the traditional switch virtual interface (SVI) method, which requires configuring different Internet Protocol (IP) addresses for each switch port accessing the server, the switch configuration is more complex and the maintenance is more difficult, resulting in lower server access efficiency. Summary of the Invention

[0004] In view of this, the purpose of this disclosure is to provide a server BGP access method, apparatus, electronic device, and readable storage medium. While retaining the logical network interface card (NIC), eBPF programs are mounted on different physical NICs. During packet forwarding, the eBPF program determines the packet's destination as a switch based on the packet's destination address. If, based on the destination address, the current physical NIC is not the physical NIC of the switch corresponding to the switch's gateway address, the packet is redirected to the target physical NIC of the switch corresponding to the gateway address. The target physical NIC then forwards the packet to the corresponding switch. This allows for accurate BGP connection from the server to the switch while retaining the server's logical NIC, reducing the configuration complexity of server access to the switch and improving the reliability and efficiency of server access to the switch.

[0005] In a first aspect, embodiments of this disclosure provide a server BGP access method, wherein the server establishes a BGP connection with a switch by forwarding data packets through a logical network interface card (NIC); the logical NIC is obtained by aggregating at least two physical NICs; the server BGP access method includes: Based on the destination address of the data packet sent by the server, detect whether the destination address of the data packet is the switch gateway address; If the destination address of the data packet is the switch gateway address, the eBPF program mounted on the current physical network card detects whether the current physical network card is the physical network card of the switch corresponding to the switch gateway address based on the destination address. If the current physical network interface card (NIC) is not the NIC of the switch corresponding to the switch gateway address, the data packet is redirected and forwarded to the target physical NIC of the switch corresponding to the switch gateway address, and then forwarded to the corresponding switch through the target physical NIC.

[0006] Secondly, this disclosure also provides a server BGP access device, wherein the server establishes a BGP connection with a switch by forwarding data packets through a logical network interface card (NIC); the logical NIC is obtained by aggregating at least two physical NICs; the server BGP access device includes: The gateway address detection module is used to detect whether the destination address of the data packet sent by the server is the switch gateway address. The network interface card (NIC) detection module is used to detect, based on the destination address, whether the current physical NIC is a physical NIC that is forwarded to the switch corresponding to the switch gateway address, by using an eBPF program mounted on the current physical NIC if the destination address of the data packet is the switch gateway address. The packet forwarding module is used to redirect and forward the data packet to the target physical network interface card (NIC) of the switch corresponding to the switch gateway address if the current physical network interface card is not the physical NIC of the switch corresponding to the switch gateway address, and then forward the data packet to the corresponding switch through the target physical network interface card.

[0007] Thirdly, embodiments of this disclosure also provide an electronic device, including: a processor, a memory, and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the memory via the bus, and when the machine-readable instructions are executed by the processor, the steps of the server BGP access method described above are performed.

[0008] Fourthly, embodiments of this disclosure also provide a computer-readable storage medium storing a computer program that, when executed by a processor, performs the steps of the server BGP access method described above.

[0009] The server BGP access method, apparatus, electronic device, and readable storage medium provided in this disclosure detect whether the destination address of the data packet sent by the server is a switch gateway address. If the destination address of the data packet is a switch gateway address, the eBPF program mounted on the current physical network card detects whether the current physical network card is a physical network card that forwards data to the switch corresponding to the switch gateway address based on the destination address. If the current physical network card is not a physical network card that forwards data to the switch corresponding to the switch gateway address, the data packet is redirected and forwarded to the target physical network card of the switch corresponding to the switch gateway address, and the data packet is forwarded to the corresponding switch through the target physical network card. In this way, while retaining the logical network interface card (NIC), eBPF programs are mounted on different physical NICs. During packet forwarding, the eBPF program determines the packet's destination as a switch based on the packet's destination address. If the destination address indicates that the current physical NIC is not the one forwarding to the switch corresponding to the switch's gateway address, the packet is redirected to the target physical NIC of the switch corresponding to the gateway address. The target physical NIC then forwards the packet to the corresponding switch. This allows for accurate BGP connections from the server to the switch while retaining the server's logical NIC, reducing the configuration complexity of server access to the switch and improving the reliability and efficiency of server access to the switch.

[0010] To make the above-mentioned objects, features and advantages of this disclosure more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0011] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings used in the embodiments will be briefly described below. It should be understood that the following drawings only show some embodiments of this disclosure and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0012] Figure 1 A flowchart illustrating a server BGP access method provided in this embodiment of the disclosure; Figure 2 This is a schematic diagram of the server access method in the related technology provided in the embodiments of this disclosure; Figure 3This is a schematic diagram of a server access method including a logical network card provided in an embodiment of this disclosure; Figure 4 This is a schematic diagram of the server BGP access process provided in the embodiments of this disclosure; Figure 5 This is a schematic diagram of the structure of a server BGP access device provided in an embodiment of the present disclosure; Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation

[0013] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. The components of the embodiments of this disclosure described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed disclosure, but merely represents selected embodiments of this disclosure. Based on the embodiments of this disclosure, every other embodiment obtained by those skilled in the art without inventive effort falls within the scope of protection of this disclosure.

[0014] First, the applicable scenarios for this disclosure are introduced. This disclosure can be applied to the field of computer technology.

[0015] In data center networking, to ensure high availability of network devices, access layer switches often employ switch stacking technology. At least two physical network interface cards (NICs) are aggregated on the server side to form a logical NIC bond. The server and the switch can establish a BGP connection and negotiate link aggregation using the LACP protocol, thereby achieving high availability at the server access layer. If the server needs to establish a BGP connection with the switch for route advertising, the corresponding L3 gateway is typically pushed down to the access switch (ASW). The server only needs to establish a BGP connection with the gateway address of the stacked switches, which then becomes the switch's gateway address.

[0016] However, the reliability of switch stacking technology is generally low, and maintenance and upgrades are difficult. Therefore, destacking technology has begun to be used in data center networking. In application scenarios of switch destacking technology, such as how servers establish BGP connections with switches, this has become an urgent problem to be solved.

[0017] In this scenario, the server needs to be modified to perform dual ARP transmission, enabling ARP packets from the two Bonded sub-interfaces to be broadcast to the two access switches. However, simply using dual ARP transmission and the switch's ARP-to-BGP route announcement technology only enables server access. If the server still needs to establish a BGP connection with the switch, traditional technical solutions cannot solve this problem.

[0018] In related technologies, network interface card (NIC) bonding is no longer used on servers. Instead, multiple NICs are treated as independent links. In this approach, each NIC on the server needs to be configured with an independent address, which is incompatible with the bonding configurations widely used in current servers and cannot reuse the capabilities that bonding itself already has. The connection between the server and the switch is changed to multiple Layer 3 links. Compared with the traditional virtual SVI interface of the switch, a different IP address needs to be configured for each switch port connected to the server. The switch configuration is more complex and the maintenance is more difficult, resulting in the problem of low server access efficiency.

[0019] Based on this, the present disclosure provides a server BGP access method to reduce the configuration complexity of the server access switch and improve the reliability and access efficiency of the server access switch.

[0020] Please see Figure 1 , Figure 1 This is a flowchart illustrating a server BGP access method provided in an embodiment of this disclosure. Figure 1 As shown in the embodiments of this disclosure, the server BGP access method includes: S101. Based on the destination address of the data packet sent by the server, detect whether the destination address of the data packet is the switch gateway address.

[0021] S102. If the destination address of the data packet is the switch gateway address, the eBPF program mounted on the current physical network card detects whether the current physical network card is a physical network card that forwards data to the switch corresponding to the switch gateway address based on the destination address.

[0022] S103. If the current physical network card is not the physical network card of the switch corresponding to the switch gateway address, the data packet is redirected and forwarded to the target physical network card of the switch corresponding to the switch gateway address, and then forwarded to the corresponding switch through the target physical network card.

[0023] The server BGP access method provided in this disclosure, while retaining the logical network interface card (NIC), mounts eBPF programs on different physical NICs. When forwarding data packets, the eBPF program determines the forwarding destination of the data packet as a switch based on the destination address. If the destination address indicates that the current physical NIC is not the physical NIC of the switch corresponding to the gateway address of the switch, the data packet is redirected to the target physical NIC of the switch corresponding to the gateway address of the switch. The data packet is then forwarded to the corresponding switch through the target physical NIC. In this way, an accurate BGP connection from the server to the switch can be achieved while retaining the server's logical NIC, reducing the configuration complexity of server access to the switch and improving the reliability and access efficiency of server access to the switch.

[0024] The exemplary steps of the embodiments of this disclosure are described below: S101. Based on the destination address of the data packet sent by the server, detect whether the destination address of the data packet is the switch gateway address.

[0025] In data center networking, to ensure high availability of network devices, switch stacking technology is often used on access layer switches. At least two physical network cards are aggregated on the server side to form a logical network card Bonding. A BGP connection can be established between the server and the switch. However, the reliability of switch stacking technology is generally low, and maintenance and upgrades are difficult. Therefore, destacking technology has begun to be used in data center networking. In application scenarios of switch destacking technology, such as how the server establishes a BGP connection with the switch, this has become an urgent problem to be solved.

[0026] In related technologies, network interface card (NIC) bonding is no longer used on servers. Instead, multiple NICs are treated as independent links. In this approach, each NIC on the server needs to be configured with an independent address, which is incompatible with the bonding configurations widely used in current servers and cannot reuse the capabilities that bonding itself already has. The connection between the server and the switch is changed to multiple Layer 3 links. Compared with the traditional switch SVI interface, a different IP address needs to be configured for each switch port accessing the server. The switch configuration is more complex and the maintenance is more difficult, resulting in the problem of low server access efficiency.

[0027] For example, please refer to Figure 2 , Figure 2 This is a schematic diagram of the server access method in the related technology provided in the embodiments of this disclosure, such as... Figure 2As shown, taking two physical network cards as an example, the server's bonding is discarded, and the two physical network cards are recognized as two independent links. They are connected to a group of two ASWs through equal-cost routing (ECMP). Specifically, the server connects to switch ASW-1 (switch gateway address: 10.1.1.0 / 30) through network card eth0 according to the external network boundary interoperability protocol; the server connects to switch ASW-2 (switch gateway address: 10.1.2.0 / 30) through network card eth1 according to the external network boundary interoperability protocol.

[0028] Based on this, in this embodiment of the disclosure, while retaining the logical network interface card (NIC), eBPF programs are mounted on different physical NICs. When forwarding data packets, the eBPF program determines the forwarding destination of the data packet as a switch based on the destination address of the data packet. If, based on the destination address, it is determined that the current physical NIC is not the physical NIC of the switch corresponding to the gateway address of the switch, the data packet is redirected to the target physical NIC of the switch corresponding to the gateway address of the switch. The data packet is then forwarded to the corresponding switch through the target physical NIC. In this way, an accurate BGP connection from the server to the switch can be achieved while retaining the server's logical NIC, reducing the configuration complexity of server access to the switch and improving the reliability and access efficiency of server access to the switch.

[0029] Here, BGP is a routing protocol used to exchange routing information between routing domains and is widely used in data center networking; NIC Bonding: a driver implemented in the Linux kernel that supports LACP, which can aggregate multiple physical NICs into a single logical NIC to achieve high availability; the switch that the server connects to can be an ASW switch, also called a top-of-rack switch (ToR), used as an access layer switch for server access.

[0030] In one alternative implementation, after determining the destination address of the data packet sent by the server, it can be determined whether the data packet needs to be forwarded to the switch based on the destination address. Here, the method for determining whether the data packet needs to be forwarded to the switch based on the destination address can be to query the pre-built eBPF mapping relationship based on the destination address and then make the determination. The construction process of the eBPF mapping relationship will be described below.

[0031] Specifically, the server BGP access method further includes: a1: Identify at least one data packet to be forwarded, and determine the switch gateway address and the physical network card identifier of each data packet.

[0032] a2: Determine the physical network card identifier corresponding to each switch.

[0033] a3: Create an eBPF mapping relationship based on the switch gateway address of each data packet, the actual physical network card identifier of the access, and the physical network card identifier corresponding to each switch.

[0034] In one optional implementation, when the server needs to forward data packets, it has already determined the destination to which the data needs to be forwarded. Since the data packets forwarded to the switch need to be processed in this embodiment, the construction of the eBPF mapping relationship needs to include at least one data packet whose forwarding destination is the switch. That is, the destination address of all data packets included in the eBPF mapping relationship is the switch gateway address (ASW's BGP Peer IP), and the physical network identifier actually accessed by each data packet is determined. Simultaneously, the mapping relationship between the switch gateway address and the accessed physical network interface card (NIC) identifier needs to be configured in the eBPF mapping relationship. Then, based on the switch gateway address of each data packet, the actual accessed physical NIC identifier, and the physical NIC identifier corresponding to each switch, the eBPF mapping relationship is created.

[0035] Here, the data can be stored in key-value pairs in the eBPF mapping relationship. Specifically, in the predefined eBPF mapping relationship, the key is the switch gateway address of the data packet, and the value is the identifier of the network card that the data packet is actually connected to. Taking two switches that need to be connected as an example, the switch gateway addresses corresponding to ASW-1 and ASW-2 of the two access switches are used as the key, and the physical network card identifiers connected to different switches are used as the value in the eBPF mapping relationship.

[0036] Furthermore, the destination address of the data packet can be compared with multiple switch gateway addresses stored in the eBPF mapping relationship to determine whether the data packet needs to be forwarded to the switch.

[0037] Specifically, the destination address of the data packet is determined to be the switch gateway address through the following steps: b1: Traverse the eBPF mapping relationship according to the destination address. If there is a switch gateway address in the eBPF mapping relationship that is consistent with the destination address, determine that the destination address of the data packet is the switch gateway address.

[0038] In one alternative implementation, the server needs to forward data packets through the corresponding physical network interface card (NIC). Therefore, the current physical NIC is the NIC to which the server forwards data packets. Each physical NIC has an eBPF program mounted on it. After determining that the current physical NIC has received the data packet forwarding traffic, the eBPF program can intercept network traffic to detect the destination address of the data packet and perform subsequent forwarding processing.

[0039] Specifically, the eBPF program traverses the eBPF mapping relationship based on the destination address of the parsed data packet and compares it with at least one switch address stored in the eBPF mapping relationship. If it is determined that there is a switch gateway address in the eBPF mapping relationship that matches the destination address, the destination address of the data packet is determined to be the switch gateway address.

[0040] Here, eBPF is a revolutionary kernel technology that allows for the secure and efficient modification of kernel behavior by adding hooks without modifying the kernel source code or loading kernel modules. This capability can be applied to network capability extensions.

[0041] Furthermore, if the destination address of the current data packet is determined to be the switch gateway address, it is necessary to determine whether the current physical network card is capable of forwarding the data packet to the corresponding switch.

[0042] S102. If the destination address of the data packet is the switch gateway address, the eBPF program mounted on the current physical network card detects whether the current physical network card is a physical network card that forwards data to the switch corresponding to the switch gateway address based on the destination address.

[0043] In one optional implementation, the logical network interface card (NIC) determines the physical NIC to which the current data packet should be forwarded by using preset NIC forwarding rules, and then forwards the data packet through the physical NIC.

[0044] For example, the logical network interface card (NIC) can perform a hash calculation on the 5-tuple, determine the physical NIC to forward the current data packet based on the calculated hash value, and forward the data packet through the physical NIC.

[0045] Here, taking two independent switches as an example of a destabilized switch configuration, each with two different switch gateway addresses (BGP Peer IPs) is used for access. These two different BGP Peer IPs are accessed through two different physical network interface cards (NICs) under a Bonding mechanism. When the server attempts to establish a BGP connection with the BGP Peer IPs corresponding to these two different access switches, the traffic distribution strategy driven by the Bonding mechanism cannot be aware of the line topology. This can cause BGP communication traffic to fail to originate from the corresponding physical NIC, resulting in the server failing to establish a BGP connection with the switch.

[0046] For example, please refer to Figure 3 , Figure 3 This is a schematic diagram of a server access method including a logical network card provided in an embodiment of this disclosure, as shown below. Figure 3 As shown, access traffic to the gateway address of switch ASW-1 via the External Border Gateway Protocol (EBGP) needs to exit through the physical network card eth0, while access traffic to the gateway address of switch ASW-2 via the EBGP needs to exit through the physical network card eth1. However, the Bonding driver cannot meet this requirement.

[0047] Therefore, based on the created eBPF mapping relationship, it is necessary to determine whether the physical network card to which the current data packet arrives is a network card that can be forwarded to the correct switch, and to make subsequent forwarding adjustments.

[0048] Specifically, the following steps are used to determine that the current physical network interface card (NIC) is not a physical NIC of the switch that is redirected to the gateway address of the switch: c1: Based on the destination address, traverse the eBPF mapping relationship to determine the target physical network card identifier corresponding to the destination address.

[0049] c2: Detect whether the physical network card corresponding to the target physical network card identifier is consistent with the current physical network card.

[0050] c3: If the physical network card corresponding to the target physical network card identifier is inconsistent with the current physical network card, it is determined that the current physical network card is not the physical network card of the switch that is forwarded to the gateway address of the switch.

[0051] In one optional implementation, the target physical network interface card (NIC) identifier corresponding to the destination address can be determined based on the destination address of the data packet (switch gateway address) and the mapping relationship between the switch gateway address and the physical NIC identifier stored in the eBPF mapping relationship. Then, it can be detected whether the physical NIC corresponding to the target physical NIC identifier is consistent with the current physical NIC. If the two are inconsistent, it is determined that the current physical NIC is not the physical NIC of the switch to be transferred to the switch corresponding to the switch gateway address.

[0052] For example, in the above example, by parsing the destination address of the data packet, it can be seen that the current data packet needs to be forwarded to switch ASW-2. Querying the eBPF mapping relationship, it can be seen that the physical network card to which the data packet should arrive is eth1. However, the current physical network card to which the data packet is forwarded by the server is eth0. The two are not consistent. At this time, it is determined that the current physical network card is not the physical network card of switch ASW-2 corresponding to the switch gateway address.

[0053] Furthermore, after determining that the current physical network card is not the physical network card of the switch corresponding to the switch gateway address, the data packet can be redirected to the corresponding target physical network card to complete the data packet forwarding process to the switch through the target physical network card.

[0054] S103. If the current physical network card is not the physical network card of the switch corresponding to the switch gateway address, the data packet is redirected and forwarded to the target physical network card of the switch corresponding to the switch gateway address, and then forwarded to the corresponding switch through the target physical network card.

[0055] If it is determined that the current physical network card is not the physical network card of the switch corresponding to the gateway address of the switch, the data packet cannot be forwarded to the correct switch through the current physical network card. Therefore, it is necessary to forward the data packet to the target physical network card through redirection (bpf_redirect), and then forward the data packet to the correct switch through the target physical network card.

[0056] In one alternative implementation, after the target physical network card receives the data packet, in order to ensure the accuracy of the process, the destination address of the data packet can be detected again, and forwarded after the destination address is determined to be the switch gateway address.

[0057] Specifically, the step "redirecting and forwarding the data packet to the target physical network interface card of the switch corresponding to the switch gateway address, and forwarding the data packet to the corresponding switch through the target physical network interface card" includes: d1: Redirect the data packet to the target physical network interface card of the switch corresponding to the switch gateway address, and detect whether the destination address of the data packet is the switch gateway address based on the destination address of the data packet.

[0058] d2: If the destination address of the data packet is the switch gateway address, the data packet is forwarded to the corresponding switch through the target physical network card.

[0059] In this embodiment of the disclosure, after receiving a data packet, the target physical network card uses the mounted eBPF program to traverse the eBPF mapping relationship based on the destination address of the data packet. If there is a switch gateway address in the eBPF mapping relationship that matches the destination address, the destination address of the data packet is determined to be the switch gateway address. Then, after matching and determining the target physical network card, the data packet is forwarded to the correct switch through the target physical network card.

[0060] In another alternative implementation, if the data packet is determined to be a redirected data packet, since only data packets forwarded to the switch need to be forwarded through a specific physical network card, when the target physical network card receives the redirected data packet, it can directly forward it without checking whether the destination address is the switch gateway address. This reduces the number of data packet forwarding steps and improves the connection efficiency between the server and the switch.

[0061] Specifically, the step "redirecting and forwarding the data packet to the target physical network interface card of the switch corresponding to the switch gateway address, and forwarding the data packet to the corresponding switch through the target physical network interface card" includes: e1: Add a redirection flag to the data packet and redirect the data packet with the added redirection flag to the target physical network interface card of the switch corresponding to the gateway address of the switch.

[0062] e2: Upon receiving a data packet containing a redirection identifier, the data packet is forwarded to the corresponding switch via the target physical network card.

[0063] In one alternative implementation, after the data packet is redirected, a redirection flag can be added to the data packet. When receiving a data packet, if a data packet containing the redirection flag is received, it is determined that the data packet is redirected to the target physical network card. It is determined that the data packet needs to be forwarded to the corresponding switch through the target physical network card. Therefore, it is not necessary to perform the data packet destination address and physical network card matching detection. The data packet is directly forwarded to the corresponding switch through the target physical network card.

[0064] For example, in the above example, by parsing the destination address of the data packet, it can be seen that the current data packet needs to be forwarded to switch ASW-2. Querying the eBPF mapping relationship, it can be seen that the physical network card to which the data packet should arrive is eth1. However, the current physical network card to which the data packet is forwarded by the server is eth0. It is necessary to use the eBPF program mounted on the physical network card eth0 to redirect the data packet to the physical network card eth1, and then forward the data packet to switch ASW-2 through the physical network card eth1.

[0065] In one alternative implementation, if it is determined that the destination address of the data packet is not the switch gateway address, then the physical network card is no longer used for filtering, and the data packet is forwarded directly.

[0066] Specifically, the server BGP access method further includes: f1: If the destination address of the data packet is not the switch gateway address, the physical network card to forward the data packet is determined by the preset network card forwarding rules, and the data packet is forwarded to the destination address through the physical network card.

[0067] In this embodiment of the disclosure, after receiving a data packet, the destination address of the data packet can be compared with multiple switch gateway addresses stored in the eBPF mapping relationship to determine whether the data packet needs to be forwarded to the switch.

[0068] Specifically, the following steps are used to determine that the destination address of the data packet is not the switch gateway address: g1: Traverse the eBPF mapping relationship according to the destination address. If there is no switch gateway address in the eBPF mapping relationship that matches the destination address, determine that the destination address of the data packet is not a switch gateway address.

[0069] In an alternative implementation, the server also needs to forward data packets through the corresponding physical network interface card (NIC). Therefore, the current physical NIC is the NIC to which the server forwards data packets. Each physical NIC has an eBPF program mounted on it. After determining that the current physical NIC has received the data packet forwarding traffic, the eBPF program can intercept network traffic to detect the destination address of the data packet and perform subsequent forwarding processing.

[0070] Specifically, the eBPF program traverses the eBPF mapping relationship based on the destination address of the parsed data packet and compares it with at least one switch address stored in the eBPF mapping relationship. If it is determined that there is no switch gateway address in the eBPF mapping relationship that matches the destination address, it is determined that the destination address of the data packet is not a switch gateway address.

[0071] Furthermore, if it is determined that the destination address of the current data packet is not the switch gateway address, then the physical network card will no longer be detected and filtered, and the data packet will be forwarded directly to the destination address through the current physical network card.

[0072] In one alternative implementation, if the destination address of the data packet determines that the current physical network card is the physical network card that can forward the data packet to the corresponding switch, the data packet can be directly forwarded through the current physical network card.

[0073] Specifically, the server BGP access method further includes: h1: If the current physical network card is the physical network card of the switch corresponding to the gateway address of the switch, the data packet is forwarded to the corresponding switch through the current physical network card.

[0074] In an alternative implementation, similarly, it is necessary to determine whether the physical network interface card (NIC) to which the current data packet arrives is a NIC that can be forwarded to the correct switch, based on the created eBPF mapping relationship. If it is determined that the physical NIC to which the current data packet arrives is a NIC that can be forwarded to the correct switch, then data forwarding can be performed directly.

[0075] Specifically, the following steps are used to determine whether the current physical network interface card (NIC) is the physical NIC of the switch that is being routed to the gateway address of the switch: i1: Based on the destination address, traverse the eBPF mapping relationship to determine the target physical network card identifier corresponding to the destination address.

[0076] i2: Detect whether the physical network card corresponding to the target physical network card identifier is consistent with the current physical network card.

[0077] i3: If the physical network card corresponding to the target physical network card identifier is the same as the current physical network card, determine that the current physical network card is the physical network card of the switch that is forwarded to the gateway address of the switch.

[0078] In one optional implementation, the target physical network interface card (NIC) identifier corresponding to the destination address can be determined based on the destination address of the data packet (switch gateway address) and the mapping relationship between the switch gateway address and the physical NIC identifier stored in the eBPF mapping relationship. Then, it can be detected whether the physical NIC corresponding to the target physical NIC identifier is consistent with the current physical NIC. If they are consistent, it is determined that the current physical NIC is the physical NIC of the switch that is forwarded to the switch corresponding to the switch gateway address.

[0079] For example, in the above example, by parsing the destination address of the data packet, it can be seen that the current data packet needs to be forwarded to switch ASW-2. Querying the eBPF mapping relationship, it can be seen that the physical network card to which the data packet should arrive is eth1. The current physical network card to which the data packet is forwarded by the server is also eth1. Since the two are consistent, it is determined that the current physical network card is the physical network card of switch ASW-2 corresponding to the switch gateway address.

[0080] In an optional implementation, the scenario of server forwarding data packets can be broadened. That is, the technical solution provided in this disclosure can also be applied to technical scenarios that require forwarding specific data packets through specific physical network cards. Specifically, the physical network card identifiers corresponding to different destination addresses are maintained in the eBPF mapping relationship. When the current network card receives a data packet, the eBPF mapping relationship is queried according to the destination address of the data packet. Based on the physical network card identifier corresponding to the destination address, it is determined whether the current physical network card is the physical network card that forwards the data packet to the destination address. If so, it is forwarded directly; if not, the data packet is redirected to the target physical network card corresponding to the destination address, and then the data packet is forwarded to the corresponding destination address through the target physical network card.

[0081] The server BGP access process in this embodiment will be illustrated below with specific examples: Please see Figure 4 , Figure 4 This is a schematic diagram of the server BGP access process provided in the embodiments of this disclosure, as follows: Figure 4 As shown, an eBPF mapping relationship is created, and the correspondence between the physical network interface card (NIC) and the switch's gateway address is configured in the eBPF mapping relationship; an eBPF program to intercept data packet traffic is mounted on the physical NIC; it checks whether the destination address of the data packet is accessing the switch's gateway address; if not, it sends the packet directly and ends the current process; if so, it checks whether the switch's gateway address matches the currently forwarded physical NIC; if they match, it sends the packet directly and ends the current process; if they do not match, it redirects the packet to the target physical NIC of the switch corresponding to the switch's gateway address, checks whether the destination address of the data packet is accessing the switch's gateway address; if not, it sends the packet directly and ends the current process; if so, it checks whether the switch's gateway address matches the currently forwarded physical NIC; if they match, it sends the packet directly and ends the current process.

[0082] In one optional implementation, the server BGP access process provided in this disclosure can be executed via the following code flow.

[0083] #include<linux / bpf.h> #include<linux / ip.h> #include<linux / if_ether.h> #include<bpf / bpf_helpers.h> #include<bpf / bpf_endian.h> #define ETH_P_ARP 0x0806 #define ETH_P_IP0x0800 #define ETH_P_8021Q 0x8100 #define TC_ACT_OK 0 #define TC_ACT_REDIRECT 7 #define NE_DS_IFINDEX_KEY_PREFIX 0xff000000 #define NE_DS_IFINDEX_KEY(i) (NE_DS_IFINDEX_KEY_PREFIX | (i)) #if DEBUG # define pr_debug(fmt, ...) bpf_printk(fmt, ##__VA_ARGS__) #else # define pr_debug(fmt, ...) #endif #ifndef likely # define likely(X) __builtin_expect(!!(X), 1) #endif #ifndef unlikely # define unlikely(X) __builtin_expect(!!(X), 0) #endif struct vlan_hdr { __be16 h_vlan_TCI; __be16 h_vlan_encapsulated_proto; }; struct { __uint(type, BPF_MAP_TYPE_HASH); __uint(max_entries, 64); __type(key, __u32); __type(value, __u32); } ntes_ds_conf SEC(".maps"); static __always_inline int parse_pkt(struct __sk_buff *skb, int *proto, __u32 *dst_ip4) { void *data = (void *)(long)skb->data; void *data_end = (void *)(long)skb->data_end; struct ethhdr *eth = data; struct vlan_hdr *vlan; void *nw_header; if ((void *)(eth + 1)>data_end) { return -1; } *proto = eth->h_proto; if (unlikely(*proto == bpf_htons(ETH_P_8021Q))) { pr_debug("parse_pkt: vlan packet"); vlan = (struct vlan_hdr *)(eth + 1); if ((void *)(vlan + 1)>data_end) { return -1; } *proto = vlan->h_vlan_encapsulated_proto; nw_header = (void *)(vlan + 1); } else { nw_header = (void *)(eth + 1); } if (likely(*proto == bpf_htons(ETH_P_IP))) { struct iphdr *iph = (struct iphdr *)nw_header; if ((void *)(iph + 1)>data_end) { return -1; } *dst_ip4 = iph->daddr; } return 0; } SEC("classifier") int ne_ds_egress(struct __sk_buff *skb) { __u32 *if_index; __u32 self_index_key; __u32 index_val; __u32 dst_ip4 = 0; int proto; int ret = parse_pkt(skb,&proto,&dst_ip4); if (ret != 0) { pr_debug("ne_ds_egress: parse pkt failed"); return TC_ACT_OK; } pr_debug("ne_ds_egress: proto %d, dst_ip: %pI4", proto,&dst_ip4); if (likely(proto == bpf_htons(ETH_P_IP))) { pr_debug("ne_ds_egress: ip packet"); / * retrieve dest ip affinity ifindex * / if_index = bpf_map_lookup_elem(&ntes_ds_conf,&dst_ip4); / * if not found: bypass * / if (likely(if_index == NULL)) { pr_debug("ne_ds_egress: ip packet bypass"); return TC_ACT_OK; } index_val = bpf_ntohl(*if_index); / * if equal to self: bypass * / if (index_val == skb->ifindex) { pr_debug("ne_ds_egress: ip packet bypass"); return TC_ACT_OK; } pr_debug("ne_ds_egress: should redirect ip to ifindex: %d", index_val); ret = bpf_redirect(index_val, 0); if (ret != TC_ACT_REDIRECT) { bpf_printk("NetEase de-stack: redirect ip failed, ip: %pI4, ifindex:%d, ret: %d",&dst_ip4, skb->ifindex, ret); return TC_ACT_OK; } return TC_ACT_REDIRECT; } return TC_ACT_OK; } char __license[] SEC("license") = "Dual BSD / GPL"; The server BGP access method provided in this disclosure detects whether the destination address of the data packet sent by the server is a switch gateway address. If the destination address of the data packet is a switch gateway address, the eBPF program mounted on the current physical network card detects whether the current physical network card is a physical network card that is forwarded to the switch corresponding to the switch gateway address based on the destination address. If the current physical network card is not a physical network card that is forwarded to the switch corresponding to the switch gateway address, the data packet is redirected and forwarded to the target physical network card of the switch corresponding to the switch gateway address, and the data packet is forwarded to the corresponding switch through the target physical network card. In this way, while retaining the logical network interface card (NIC), eBPF programs are mounted on different physical NICs. During packet forwarding, the eBPF program determines the packet's destination as a switch based on the packet's destination address. If the destination address indicates that the current physical NIC is not the one forwarding to the switch corresponding to the switch's gateway address, the packet is redirected to the target physical NIC of the switch corresponding to the gateway address. The target physical NIC then forwards the packet to the corresponding switch. This allows for accurate BGP connections from the server to the switch while retaining the server's logical NIC, reducing the configuration complexity of server access to the switch and improving the reliability and efficiency of server access to the switch.

[0084] Based on the same inventive concept, this disclosure also provides a server BGP access device corresponding to the server BGP access method. Since the principle of the device in this disclosure for solving the problem is similar to the server BGP access method described above in this disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.

[0085] Please see Figure 5 , Figure 5 This is a schematic diagram of the structure of a server BGP access device provided in an embodiment of this disclosure. Figure 5 As shown, the server BGP access device 500 includes: The gateway address detection module 510 is used to detect whether the destination address of the data packet sent by the server is the gateway address of the switch. The network card detection module 520 is used to detect, based on the destination address, whether the current physical network card is a physical network card that is forwarded to the switch corresponding to the switch gateway address, by using the eBPF program mounted on the current physical network card if the destination address of the data packet is the switch gateway address. The packet forwarding module 530 is used to redirect and forward the data packet to the target physical network interface card of the switch corresponding to the switch gateway address if the current physical network interface card is not the physical network interface card of the switch corresponding to the switch gateway address, and then forward the data packet to the corresponding switch through the target physical network interface card.

[0086] In an optional implementation, the server BGP access device 500 further includes a mapping relationship construction module (not shown in the figure), which is used for: Identify at least one data packet to be forwarded, and determine the switch gateway address and the physical network interface card (NIC) identifier of each data packet. Determine the physical network interface card (NIC) identifier for each switch; Based on the switch gateway address of each data packet, the physical network interface card (NIC) identifier of the actual access, and the physical NIC identifier of each switch, an eBPF mapping relationship is created.

[0087] In an optional implementation, the network interface card (NIC) detection module 520 is used to determine that the destination address of the data packet is the switch gateway address through the following steps: The eBPF mapping relationship is traversed according to the destination address. If a switch gateway address that matches the destination address exists in the eBPF mapping relationship, the destination address of the data packet is determined to be the switch gateway address.

[0088] In an optional implementation, the packet forwarding module 530 is used to determine, through the following steps, that the current physical network interface card (NIC) is not a physical NIC that forwards packets to the switch corresponding to the switch gateway address: Based on the destination address, the eBPF mapping relationship is traversed to determine the target physical network interface identifier corresponding to the destination address; Detect whether the physical network card corresponding to the target physical network card identifier is consistent with the current physical network card; If the physical network card corresponding to the target physical network card identifier is inconsistent with the current physical network card, it is determined that the current physical network card is not the physical network card of the switch that is forwarded to the gateway address of the switch.

[0089] In an optional implementation, when the packet forwarding module 530 is used to redirect and forward the packet to the target physical network interface card (NIC) of the switch corresponding to the switch gateway address, and forwards the packet to the corresponding switch through the target physical NIC, the packet forwarding module 530 is used to: The data packet is redirected and forwarded to the target physical network interface card of the switch corresponding to the switch gateway address, and the destination address of the data packet is detected as the switch gateway address based on the destination address of the data packet. If the destination address of the data packet is the switch gateway address, the data packet is forwarded to the corresponding switch through the target physical network card.

[0090] In an optional implementation, when the packet forwarding module 530 is used to redirect and forward the packet to the target physical network interface card (NIC) of the switch corresponding to the switch gateway address, and forwards the packet to the corresponding switch through the target physical NIC, the packet forwarding module 530 is used to: Add a redirection flag to the data packet, and redirect the data packet with the added redirection flag to the target physical network interface card of the switch corresponding to the switch gateway address; Upon receiving a data packet containing a redirection identifier, the packet is forwarded to the corresponding switch via the target physical network interface card.

[0091] In an optional implementation, the server BGP access device 500 further includes a first direct forwarding module (not shown in the figure), the first direct forwarding module being used for: If the destination address of the data packet is not the switch gateway address, the physical network interface card (NIC) for forwarding the data packet is determined by the preset NIC forwarding rules, and the data packet is forwarded to the destination address through the physical NIC.

[0092] In one optional implementation, the first direct forwarding module is used to determine that the destination address of the data packet is not the switch gateway address through the following steps: If the eBPF mapping relationship is traversed according to the destination address, and there is no switch gateway address in the eBPF mapping relationship that matches the destination address, then the destination address of the data packet is determined to be not a switch gateway address.

[0093] In an optional implementation, the server BGP access device 500 further includes a second direct forwarding module (not shown in the figure), the second direct forwarding module being used for: If the current physical network interface card (NIC) is the NIC of the switch corresponding to the gateway address of the switch, the data packet is forwarded to the corresponding switch through the current physical NIC.

[0094] In one optional implementation, the second direct forwarding module determines that the current physical network interface card (NIC) is the NIC of the switch that forwards to the gateway address of the switch through the following steps: Based on the destination address, the eBPF mapping relationship is traversed to determine the target physical network interface identifier corresponding to the destination address; Detect whether the physical network card corresponding to the target physical network card identifier is consistent with the current physical network card; If the physical network card corresponding to the target physical network card identifier is the same as the current physical network card, then the current physical network card is determined to be the physical network card of the switch that is forwarded to the switch corresponding to the switch gateway address.

[0095] The server BGP access device provided in this embodiment detects whether the destination address of the data packet sent by the server is a switch gateway address. If the destination address of the data packet is a switch gateway address, the eBPF program mounted on the current physical network card detects whether the current physical network card is a physical network card that forwards data to the switch corresponding to the switch gateway address based on the destination address. If the current physical network card is not a physical network card that forwards data to the switch corresponding to the switch gateway address, the data packet is redirected and forwarded to the target physical network card of the switch corresponding to the switch gateway address, and the data packet is forwarded to the corresponding switch through the target physical network card. In this way, while retaining the logical network interface card (NIC), eBPF programs are mounted on different physical NICs. During packet forwarding, the eBPF program determines the packet's destination as a switch based on the packet's destination address. If the destination address indicates that the current physical NIC is not the one forwarding to the switch corresponding to the switch's gateway address, the packet is redirected to the target physical NIC of the switch corresponding to the gateway address. The target physical NIC then forwards the packet to the corresponding switch. This allows for accurate BGP connections from the server to the switch while retaining the server's logical NIC, reducing the configuration complexity of server access to the switch and improving the reliability and efficiency of server access to the switch. Please see Figure 6 , Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Figure 6 As shown, the electronic device 600 includes a processor 610, a memory 620, and a bus 630.

[0096] The memory 620 stores machine-readable instructions executable by the processor 610. When the electronic device 600 is running, the processor 610 communicates with the memory 620 via the bus 630, causing the processor 610 to execute the following instructions during operation: Based on the destination address of the data packet sent by the server, detect whether the destination address of the data packet is the switch gateway address; If the destination address of the data packet is the switch gateway address, the eBPF program mounted on the current physical network card detects whether the current physical network card is the physical network card of the switch corresponding to the switch gateway address based on the destination address. If the current physical network interface card (NIC) is not the NIC of the switch corresponding to the switch gateway address, the data packet is redirected and forwarded to the target physical NIC of the switch corresponding to the switch gateway address, and then forwarded to the corresponding switch through the target physical NIC.

[0097] In one optional implementation, the instructions executed by the processor 610 further include: Identify at least one data packet to be forwarded, and determine the switch gateway address and the physical network interface card (NIC) identifier of each data packet. Determine the physical network interface card (NIC) identifier for each switch; Based on the switch gateway address of each data packet, the physical network interface card (NIC) identifier of the actual access, and the physical NIC identifier of each switch, an eBPF mapping relationship is created.

[0098] In one optional implementation, the processor 610 executes instructions to determine the destination address of the data packet as the switch gateway address through the following steps: The eBPF mapping relationship is traversed according to the destination address. If a switch gateway address that matches the destination address exists in the eBPF mapping relationship, the destination address of the data packet is determined to be the switch gateway address.

[0099] In one optional implementation, the instructions executed by the processor 610 determine, through the following steps, that the current physical network interface card (NIC) is not a NIC that is rerouted to the switch corresponding to the switch gateway address: Based on the destination address, the eBPF mapping relationship is traversed to determine the target physical network interface identifier corresponding to the destination address; Detect whether the physical network card corresponding to the target physical network card identifier is consistent with the current physical network card; If the physical network card corresponding to the target physical network card identifier is inconsistent with the current physical network card, it is determined that the current physical network card is not the physical network card of the switch that is forwarded to the gateway address of the switch.

[0100] In one optional implementation, the instructions executed by the processor 610, wherein redirecting the data packet to the target physical network interface card (NIC) of the switch corresponding to the switch gateway address, and forwarding the data packet to the corresponding switch via the target physical NIC, includes: The data packet is redirected and forwarded to the target physical network interface card of the switch corresponding to the switch gateway address, and the destination address of the data packet is detected as the switch gateway address based on the destination address of the data packet. If the destination address of the data packet is the switch gateway address, the data packet is forwarded to the corresponding switch through the target physical network card.

[0101] In one optional implementation, the instructions executed by the processor 610, wherein redirecting the data packet to the target physical network interface card (NIC) of the switch corresponding to the switch gateway address, and forwarding the data packet to the corresponding switch via the target physical NIC, includes: Add a redirection flag to the data packet, and redirect the data packet with the added redirection flag to the target physical network interface card of the switch corresponding to the switch gateway address; Upon receiving a data packet containing a redirection identifier, the packet is forwarded to the corresponding switch via the target physical network interface card.

[0102] In one optional implementation, the instructions executed by the processor 610 further include: If the destination address of the data packet is not the switch gateway address, the physical network interface card (NIC) for forwarding the data packet is determined by the preset NIC forwarding rules, and the data packet is forwarded to the destination address through the physical NIC.

[0103] In one optional implementation, the processor 610 executes instructions to determine that the destination address of the data packet is not the switch gateway address through the following steps: If the eBPF mapping relationship is traversed according to the destination address, and there is no switch gateway address in the eBPF mapping relationship that matches the destination address, then the destination address of the data packet is determined to be not a switch gateway address.

[0104] In one optional implementation, the instructions executed by the processor 610 further include: If the current physical network interface card (NIC) is the NIC of the switch corresponding to the gateway address of the switch, the data packet is forwarded to the corresponding switch through the current physical NIC.

[0105] In one optional implementation, the instructions executed by the processor 610 determine that the current physical network interface card (NIC) is the physical NIC of the switch that is redirected to the gateway address of the switch through the following steps: Based on the destination address, the eBPF mapping relationship is traversed to determine the target physical network interface identifier corresponding to the destination address; Detect whether the physical network card corresponding to the target physical network card identifier is consistent with the current physical network card; If the physical network card corresponding to the target physical network card identifier is the same as the current physical network card, then the current physical network card is determined to be the physical network card of the switch that is forwarded to the switch corresponding to the switch gateway address.

[0106] By employing the above method, while retaining the logical network interface card (NIC), eBPF programs are mounted on different physical NICs. During packet forwarding, the eBPF program determines the packet's destination as a switch based on the packet's destination address. If the destination address indicates that the current physical NIC is not the one forwarding to the switch corresponding to the gateway address, the packet is redirected to the target physical NIC of the switch corresponding to the gateway address. The target physical NIC then forwards the packet to the corresponding switch. This allows for accurate BGP connections from the server to the switch while retaining the server's logical NIC, reducing the configuration complexity of server access to the switch and improving efficiency. This improves the reliability and efficiency of server access to the switch. Furthermore, after the target physical network interface card (NIC) receives a data packet, to ensure the accuracy of the process, the destination address of the data packet can be checked again. Forwarding is only performed after confirming that the destination address is the switch's gateway address. Additionally, if the data packet is determined to be a redirected packet, since only data packets forwarded to the switch require forwarding through a specific physical NIC, the target physical NIC can directly forward the packet without checking if the destination address is the switch's gateway address. This reduces the number of data packet forwarding steps, thereby improving the connection efficiency between the server and the switch.

[0107] This disclosure also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the following instructions: Based on the destination address of the data packet sent by the server, detect whether the destination address of the data packet is the switch gateway address; If the destination address of the data packet is the switch gateway address, the eBPF program mounted on the current physical network card detects whether the current physical network card is the physical network card of the switch corresponding to the switch gateway address based on the destination address. If the current physical network interface card (NIC) is not the NIC of the switch corresponding to the switch gateway address, the data packet is redirected and forwarded to the target physical NIC of the switch corresponding to the switch gateway address, and then forwarded to the corresponding switch through the target physical NIC.

[0108] In one optional implementation, the instructions executed by the computer-readable storage medium further include: Identify at least one data packet to be forwarded, and determine the switch gateway address and the physical network interface card (NIC) identifier of each data packet. Determine the physical network interface card (NIC) identifier for each switch; Based on the switch gateway address of each data packet, the physical network interface card (NIC) identifier of the actual access, and the physical NIC identifier of each switch, an eBPF mapping relationship is created.

[0109] In one optional implementation, the instructions executed by the computer-readable storage medium determine the destination address of the data packet as the switch gateway address through the following steps: The eBPF mapping relationship is traversed according to the destination address. If a switch gateway address that matches the destination address exists in the eBPF mapping relationship, the destination address of the data packet is determined to be the switch gateway address.

[0110] In one optional implementation, the instructions executed by the computer-readable storage medium determine, through the following steps, that the current physical network interface card (NIC) is not a physical NIC of the switch corresponding to the switch gateway address: Based on the destination address, the eBPF mapping relationship is traversed to determine the target physical network interface identifier corresponding to the destination address; Detect whether the physical network card corresponding to the target physical network card identifier is consistent with the current physical network card; If the physical network card corresponding to the target physical network card identifier is inconsistent with the current physical network card, it is determined that the current physical network card is not the physical network card of the switch that is forwarded to the gateway address of the switch.

[0111] In one optional implementation, the instructions executed by the computer-readable storage medium, wherein redirecting the data packet to the target physical network interface card (NIC) of the switch corresponding to the switch gateway address, and forwarding the data packet to the corresponding switch via the target physical NIC, includes: The data packet is redirected and forwarded to the target physical network interface card of the switch corresponding to the switch gateway address, and the destination address of the data packet is detected as the switch gateway address based on the destination address of the data packet. If the destination address of the data packet is the switch gateway address, the data packet is forwarded to the corresponding switch through the target physical network card.

[0112] In one optional implementation, the instructions executed by the computer-readable storage medium, wherein redirecting the data packet to the target physical network interface card (NIC) of the switch corresponding to the switch gateway address, and forwarding the data packet to the corresponding switch via the target physical NIC, includes: Add a redirection flag to the data packet, and redirect the data packet with the added redirection flag to the target physical network interface card of the switch corresponding to the switch gateway address; Upon receiving a data packet containing a redirection identifier, the packet is forwarded to the corresponding switch via the target physical network interface card.

[0113] In one optional implementation, the instructions executed by the computer-readable storage medium further include: If the destination address of the data packet is not the switch gateway address, the physical network interface card (NIC) for forwarding the data packet is determined by the preset NIC forwarding rules, and the data packet is forwarded to the destination address through the physical NIC.

[0114] In one optional implementation, the instructions executed by the computer-readable storage medium determine that the destination address of the data packet is not the switch gateway address by means of the following steps: If the eBPF mapping relationship is traversed according to the destination address, and there is no switch gateway address in the eBPF mapping relationship that matches the destination address, then the destination address of the data packet is determined to be not a switch gateway address.

[0115] In one optional implementation, the instructions executed by the computer-readable storage medium further include: If the current physical network interface card (NIC) is the NIC of the switch corresponding to the gateway address of the switch, the data packet is forwarded to the corresponding switch through the current physical NIC.

[0116] In one optional implementation, the instructions executed by the computer-readable storage medium determine that the current physical network interface card (NIC) is a physical NIC of the switch connected to the gateway address of the switch through the following steps: Based on the destination address, the eBPF mapping relationship is traversed to determine the target physical network interface identifier corresponding to the destination address; Detect whether the physical network card corresponding to the target physical network card identifier is consistent with the current physical network card; If the physical network card corresponding to the target physical network card identifier is the same as the current physical network card, then the current physical network card is determined to be the physical network card of the switch that is forwarded to the switch corresponding to the switch gateway address.

[0117] By employing the above method, while retaining the logical network interface card (NIC), eBPF programs are mounted on different physical NICs. During packet forwarding, the eBPF program determines the packet's destination as a switch based on the packet's destination address. If the destination address indicates that the current physical NIC is not the one forwarding to the switch corresponding to the gateway address, the packet is redirected to the target physical NIC of the switch corresponding to the gateway address. The target physical NIC then forwards the packet to the corresponding switch. This allows for accurate BGP connections from the server to the switch while retaining the server's logical NIC, reducing the configuration complexity of server access to the switch and improving efficiency. This improves the reliability and efficiency of server access to the switch. Furthermore, after the target physical network interface card (NIC) receives a data packet, to ensure the accuracy of the process, the destination address of the data packet can be checked again. Forwarding is only performed after confirming that the destination address is the switch's gateway address. Additionally, if the data packet is determined to be a redirected packet, since only data packets forwarded to the switch require forwarding through a specific physical NIC, the target physical NIC can directly forward the packet without checking if the destination address is the switch's gateway address. This reduces the number of data packet forwarding steps, thereby improving the connection efficiency between the server and the switch.

[0118] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0119] In the several embodiments provided in this disclosure, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the shown or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.

[0120] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0121] In addition, the functional units in the various embodiments of this disclosure 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.

[0122] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0123] Finally, it should be noted that the above-described embodiments are merely specific implementations of this disclosure, used to illustrate the technical solutions of this disclosure, and not to limit it. The protection scope of this disclosure is not limited thereto. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this disclosure; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this disclosure, and should all be covered within the protection scope of this disclosure. Therefore, the protection scope of this disclosure should be determined by the protection scope of the claims.

Claims

1. A server BGP access method, characterized in that, The server establishes a BGP connection with the switch by forwarding data packets through a logical network interface card. The logical network interface card (NIC) is obtained by aggregating at least two physical NICs; the server BGP access method includes: Based on the destination address of the data packet sent by the server, detect whether the destination address of the data packet is the switch gateway address; If the destination address of the data packet is the switch gateway address, the eBPF program mounted on the current physical network card detects whether the current physical network card is the physical network card of the switch corresponding to the switch gateway address based on the destination address. If the current physical network interface card (NIC) is not the NIC of the switch corresponding to the switch gateway address, the data packet is redirected and forwarded to the target physical NIC of the switch corresponding to the switch gateway address, and then forwarded to the corresponding switch through the target physical NIC.

2. The server BGP access method according to claim 1, characterized in that, The server BGP access method also includes: Identify at least one data packet to be forwarded, and determine the switch gateway address and the physical network interface card (NIC) identifier of each data packet. Determine the physical network interface card (NIC) identifier for each switch; Based on the switch gateway address of each data packet, the physical network interface card (NIC) identifier of the actual access, and the physical NIC identifier of each switch, an eBPF mapping relationship is created.

3. The server BGP access method according to claim 2, characterized in that, The destination address of the data packet is determined to be the switch gateway address through the following steps: The eBPF mapping relationship is traversed according to the destination address. If a switch gateway address that matches the destination address exists in the eBPF mapping relationship, the destination address of the data packet is determined to be the switch gateway address.

4. The server BGP access method according to claim 2, characterized in that, The following steps are used to determine if the current physical network interface card (NIC) is not a NIC that is redirected to the switch corresponding to the switch gateway address: Based on the destination address, the eBPF mapping relationship is traversed to determine the target physical network interface identifier corresponding to the destination address; Detect whether the physical network card corresponding to the target physical network card identifier is consistent with the current physical network card; If the physical network card corresponding to the target physical network card identifier is inconsistent with the current physical network card, it is determined that the current physical network card is not the physical network card of the switch that is forwarded to the gateway address of the switch.

5. The server BGP access method according to claim 1, characterized in that, The step of redirecting and forwarding the data packet to the target physical network interface card (NIC) of the switch corresponding to the switch gateway address, and forwarding the data packet to the corresponding switch through the target physical NIC, includes: The data packet is redirected and forwarded to the target physical network interface card of the switch corresponding to the switch gateway address, and the destination address of the data packet is detected as the switch gateway address based on the destination address of the data packet. If the destination address of the data packet is the switch gateway address, the data packet is forwarded to the corresponding switch through the target physical network card.

6. The server BGP access method according to claim 1, characterized in that, The step of redirecting and forwarding the data packet to the target physical network interface card (NIC) of the switch corresponding to the switch gateway address, and forwarding the data packet to the corresponding switch through the target physical NIC, includes: Add a redirection flag to the data packet, and redirect the data packet with the added redirection flag to the target physical network interface card of the switch corresponding to the switch gateway address; Upon receiving a data packet containing a redirection identifier, the packet is forwarded to the corresponding switch via the target physical network interface card.

7. The server BGP access method according to claim 2, characterized in that, The server BGP access method also includes: If the destination address of the data packet is not the switch gateway address, the physical network interface card (NIC) for forwarding the data packet is determined by the preset NIC forwarding rules, and the data packet is forwarded to the destination address through the physical NIC.

8. A server BGP access device, characterized in that, The server establishes a BGP connection with the switch by forwarding data packets through a logical network interface card. The logical network interface card (NIC) is obtained by aggregating at least two physical NICs; the server BGP access device includes: The gateway address detection module is used to detect whether the destination address of the data packet sent by the server is the switch gateway address. The network interface card (NIC) detection module is used to detect, based on the destination address, whether the current physical NIC is a physical NIC that is forwarded to the switch corresponding to the switch gateway address, by using an eBPF program mounted on the current physical NIC if the destination address of the data packet is the switch gateway address. The packet forwarding module is used to redirect and forward the data packet to the target physical network interface card (NIC) of the switch corresponding to the switch gateway address if the current physical network interface card is not the physical NIC of the switch corresponding to the switch gateway address, and then forward the data packet to the corresponding switch through the target physical network interface card.

9. An electronic device, characterized in that, include: The device includes a processor, a storage medium, and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of the server BGP access method as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the steps of the server BGP access method as described in any one of claims 1 to 7.