Method and device for distinguishing two ends of TCP (Transmission Control Protocol) connection in microkernel operating system

By analyzing the state transfer process of the TCP connection, the two ends of the TCP connection in the microkernel operating system are identified, which solves the problem of being unable to visually distinguish the TCP connection endpoints in the existing technology and improves the efficiency of development and debugging.

CN118689798AInactive Publication Date: 2024-09-24上海鲲宜软件技术有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410599050.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-14
Publication Date
2024-09-24
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

In existing microkernel operating systems, it is impossible to visually observe the TCP connection state transition process, making it difficult to distinguish whether the two ends of the TCP connection are servers or clients, which in turn affects development and debugging efficiency.

Method used

By obtaining the status information of the TCP connection, determine whether it is an established connection status, obtain the previous status information, and analyze the status transfer process to identify both ends of the TCP connection. The specific method includes determining the server in the SYN_RCVD state and the client in the SYN_SENT state, using the file descriptor allocation table of the network protocol stack to obtain status information, and drawing a TCP state transfer process diagram to identify the special state transfer path.

Benefits of technology

It realizes real-time refreshing of the TCP state transfer process diagram on the terminal, intuitively distinguishing both ends of the TCP connection, reducing the learning cost of development and test engineers when encountering connection interruptions, and improving development and debugging efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118689798A
    Figure CN118689798A
Patent Text Reader

Abstract

The invention relates to a method and device for distinguishing two ends of TCP connection in a microkernel operating system and electronic equipment, and the method comprises the steps: obtaining the state information of the TCP connection, detecting the state information, judging the state of the TCP connection, determining whether the state is an established connection state or not, and when the state of the TCP connection is the established connection state, sending the TCP connection to the microkernel operating system. And obtaining previous state information of the current state information, analyzing a state transition process of the TCP connection according to the previous state information, and identifying two ends of the TCP connection. Through the method, the TCP state transition process diagram can be refreshed in real time at the terminal, and the two ends of the TCP connection are distinguished as the server or the client according to the state transition process of the TCP connection, so that a development and test engineer can more intuitively locate specific problems in the network application development process when encountering problems such as connection interruption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of microkernel operating systems, and in particular to a method, device and electronic device for distinguishing between two ends of a TCP connection in a microkernel operating system. Background Art

[0002] In the existing microkernel operating system, the results output by the tool commands such as netstat and lsof can reflect the specific state of the current TCP connection, but the state transition process of the TCP connection cannot be observed intuitively, so it is impossible to distinguish whether the two ends of the TCP connection are servers or clients from the state transition process. This means that when a connection is interrupted, it is necessary to look back on the TCP finite state machine to obtain the state transition process of the two ends of the TCP connection and then distinguish the two ends of the TCP connection. Engineers can perform related development or debugging based on the two ends of the TCP connection and their state transition process, but when looking back on the TCP finite state machine, other complex instructions are needed, making the overall process of related development or debugging less efficient. Therefore, a method for distinguishing the two ends of a TCP connection based on the state transition process of a TCP connection is needed to improve the efficiency of the overall process of related development or debugging. Summary of the invention

[0003] In view of this, the present application proposes a method for distinguishing the two ends of a TCP connection in a microkernel operating system to solve the problems embodied in the above-mentioned background technology.

[0004] According to one aspect of the present application, a method for distinguishing two ends of a TCP connection in a microkernel operating system is provided, comprising:

[0005] Get the status information of TCP connection;

[0006] Detecting the status information, judging the status of the TCP connection, and determining whether the connection is established;

[0007] When the state of the TCP connection is an established connection state, obtaining the previous state information of the current state information;

[0008] According to the previous state information, the state transfer process of the TCP connection is analyzed to identify the two ends of the TCP connection.

[0009] As an optional implementation scheme of the present application, analyzing the state transfer process of the TCP connection and identifying the two ends of the TCP connection includes:

[0010] When the previous state information is SYN_RCVD, the local end in the TCP connection is obtained as a TCP server;

[0011] When the previous state information is SYN_SENT, it is obtained that the local end in the TCP connection is a TCP client.

[0012] As an optional implementation scheme of the present application, before identifying the two ends of the TCP connection, the method further includes:

[0013] When the local end is a TCP server, determining that the opposite end corresponding to the local end in the TCP connection is a TCP client;

[0014] When the local end is a TCP client, it is determined that the opposite end corresponding to the local end in the TCP connection is a TCP server.

[0015] As an optional implementation scheme of the present application, obtaining the status information of the TCP connection includes:

[0016] Get the file descriptor allocation table of the network protocol stack;

[0017] According to the file descriptor allocation table, status information of the TCP connection corresponding to the allocated file descriptor is obtained.

[0018] As an optional implementation scheme of the present application, when the timing information does not exceed a preset timing threshold, a TCP state transfer process diagram is drawn.

[0019] As an optional implementation scheme of the present application, obtaining the previous state information of the current state information further includes:

[0020] Judging the state transition process formed by the previous state information and the current state information, and determining whether the state transition process is a preset special state transition path for the TCP connection;

[0021] When it is determined that the state transfer process is a preset special state transfer path, the preset special state transfer path is specially marked in the TCP state transfer process diagram.

[0022] The present application also provides a device for distinguishing two ends of a TCP connection in a microkernel operating system, including:

[0023] A status information acquisition module is used to acquire the status information of the TCP connection;

[0024] A status information detection module is used to detect the status information, judge the status of the TCP connection, and determine whether the connection is established;

[0025] A module for obtaining historical status information, used for obtaining the previous status information of the current status information when the status of the TCP connection is the established connection status;

[0026] The identification module is used to analyze the state transfer process of the TCP connection according to the previous state information and identify the two ends of the TCP connection.

[0027] As an optional implementation scheme of the present application, the identification module is used to analyze the state transfer process of the TCP connection according to the previous state information and identify the two ends of the TCP connection, including:

[0028] An identification server module, used for obtaining that the local end in the TCP connection is a TCP server when the previous state information is SYN_RCVD;

[0029] The client identification module is used to obtain that the local end in the TCP connection is a TCP client when the previous state information is SYN_SENT.

[0030] The present application also provides an electronic device, including:

[0031] processor;

[0032] a memory for storing processor-executable instructions;

[0033] Wherein, the processor is configured to implement the above-mentioned method for distinguishing the two ends of a TCP connection in a microkernel operating system when executing the executable instructions.

[0034] Beneficial effects of this application:

[0035] The present invention obtains the status information of the TCP connection, detects the status information, judges the status of the TCP connection, determines whether it is an established connection state, and when the status of the TCP connection is an established connection state, obtains the previous status information of the current status information, analyzes the state transfer process of the TCP connection according to the previous status information, and identifies the two ends of the TCP connection. The TCP state transfer process diagram can be refreshed in real time at the terminal, and the two ends of the TCP connection can be distinguished as a server or a client according to the state transfer process of the TCP connection, so that when development and test engineers encounter problems such as connection interruption, they can more intuitively locate specific problems in the network application development process, and no longer need to rely on other network utility tools to trace back the finite state machine, thereby reducing the problem of high learning costs for development and test engineers.

[0036] Other features and aspects of the present application will become apparent from the following detailed description of exemplary embodiments with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate exemplary embodiments, features, and aspects of the present application and, together with the description, serve to explain the principles of the present application.

[0038] Figure 1 A flowchart showing a method for distinguishing two ends of a TCP connection in a microkernel operating system according to an embodiment of the present application;

[0039] Figure 2 A flowchart of periodically reading TCP connection status according to an embodiment of the present application is shown;

[0040] Figure 3 A flowchart showing the method of distinguishing two ends of a TCP connection according to an embodiment of the present application is shown;

[0041] Figure 4 The four-tuple of the embodiment of the present application is shown to represent a TCP connection graph;

[0042] Figure 5 A cluster composition diagram of an embodiment of the present application is shown;

[0043] Figure 6 A block diagram of a device for distinguishing between two ends of a TCP connection in a microkernel operating system according to an embodiment of the present application is shown. DETAILED DESCRIPTION

[0044] Various exemplary embodiments, features and aspects of the present application will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.

[0045] Among them, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", "clockwise", "counterclockwise", "axial", "radial", "circumferential" and the like indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present application or simplifying the description, and do not indicate or imply that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present application.

[0046] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.

[0047] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.

[0048] In addition, in order to better illustrate the present application, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present application can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present application.

[0049] The TCP finite state machine is a model used to describe TCP connection establishment, transmission, and disconnection operations. It is based on the principle of finite state machines and implements the behavior of the TCP protocol by defining different TCP states and the transition conditions between states.

[0050] A microkernel operating system is an operating system that implements the most basic functions of an operating system in a microkernel. In this architecture, other functions are implemented in user mode outside the kernel state as much as possible. The microkernel is a system software that is located between hardware and various software and provides software with functions such as file control and multitasking control. It is the most basic part of the operating system. However, the microkernel architecture also has some disadvantages, such as low communication efficiency, high development difficulty, complex communication protocols, and complex version control.

[0051] In the network protocol stack, a file descriptor is an abstract representation used to access input / output resources such as open files, network connections, pipes, etc. When an application opens a file or establishes a network connection, the operating system assigns it a unique file descriptor, which the application can then use to perform read and write operations.

[0052] Example 1

[0053] Figure 1 The flowchart of a method for distinguishing the two ends of a TCP connection in a microkernel operating system according to an embodiment of the present application is shown. Through this method, the two ends of a TCP connection and the state transition process can be quickly identified under the architecture of the microkernel operating system, which is convenient for engineers to develop or test underlying network applications. Figure 1 As shown, the flow chart includes:

[0054] S100, obtaining status information of the TCP connection;

[0055] In this embodiment, the information of the TCP connection status is obtained by periodically reading the network protocol stack. Exemplarily, 500ms is used as the timing threshold, and when the timing reaches 500ms, the next cycle of obtaining the status information of the TCP connection is started.

[0056] S200, detecting the state information, judging the state of the TCP connection, and determining whether the connection is established;

[0057] In this embodiment, one end of the two ends of the TCP connection is called the local end, and the other end is called the peer end. In the TCP finite state machine, ESTABLELISHED means that the connection has been established, indicating that there are machines communicating, that is, the two ends of the TCP connection, the local end and the peer end are communicating, and both are in the state of established connection, so when detecting the status information of the TCP connection, it is only necessary to detect the status information of the TCP connection at one end, that is, the local end or the peer end. In this embodiment, the status information of the TCP connection at the local end is detected, and the subsequent explanation is based on the selection of the status information of the TCP connection at the local end.

[0058] S300, when the state of the TCP connection is an established connection state, obtaining the previous state information of the current state information;

[0059] By analyzing the state information of the TCP connection, it is determined whether to obtain the previous state information corresponding to the current state information of the TCP connection. When the state information of the TCP connection at the local end is the established connection state (ESTABLELISHED), the previous state information of the local end can be obtained.

[0060] S400, analyzing the state transfer process of the TCP connection according to the previous state information, and identifying the two ends of the TCP connection.

[0061] The previous state information of the local end and the state information of the TCP connection are the established connection state, and the state transfer path of the local end in the TCP connection is analyzed. The state transfer path can reflect the state transfer process, and then distinguish whether the local end is a TCP server or a TCP client at both ends of the TCP connection.

[0062] As an optional implementation scheme of the present application, in step S400, analyzing the state transfer process of the TCP connection and identifying the two ends of the TCP connection includes:

[0063] S401, when the previous state information is SYN_RCVD, obtaining that the local end in the TCP connection is a TCP server;

[0064] See also Figure 3 In the TCP finite state machine, SYN_RCVD indicates that the connection request of the other party has been received and the state of waiting for confirmation of the connection. In this embodiment, when the TCP connection state of the local end is the established connection state, the state information of the previous TCP connection of the local end is obtained by traversing the database. When the state information of the previous TCP connection of the local end is SYN_RCVD, it is determined that the local end is a TCP server in the TCP connection. The database can use a linked list provided in a commonly used data structure, or can use an advanced dedicated database.

[0065] S402, when the previous state information is SYN_SENT, obtaining that the local end in the TCP connection is a TCP client;

[0066] By traversing the database, the status information of the last TCP connection of the local end is obtained. When the status information of the last TCP connection of the local end is not SYN_RCVD, it is determined that the local end in the TCP connection is a TCP client. TCP server and TCP client are special terms of TCP / IP protocol (Transmission Control Protocol / Internet Protocol).

[0067] Through steps S401 and S402, it is obtained that in this TCP connection, when the state transition process is: SYN_RCVD to ESTABLELISHED, the local end is the TCP server; when the state transition process is: non-SYN_RCVD (i.e. other states except SYN_RCVD) to ESTABLELISHED, the local end is the TCP client.

[0068] As an optional implementation scheme of the present application, before identifying the two ends of the TCP connection, the method further includes:

[0069] When the local end is a TCP server, determining that the opposite end corresponding to the local end in the TCP connection is a TCP client;

[0070] In this embodiment, when the local end is a TCP server, the opposite end is determined to be a TCP client according to the mutually exclusive relationship between the TCP server and the TCP client.

[0071] When the local end is a TCP client, it is determined that the opposite end corresponding to the local end in the TCP connection is a TCP server.

[0072] According to the mutual exclusion characteristic, when the local end is a TCP client, the other end is determined to be a TCP server.

[0073] There are two situations: the first is that when the local end is a TCP server, the state transfer process of the local end is: SYN_RCVD-ESTABLELISHED; the other end is a TCP client, and the state transfer process of the other end is non-SYN_RCVD (that is, other states except SYN_RCVD)-ESTABLELISHED.

[0074] The second is that when the local end is a TCP client, the state transfer process of the local end is non-SYN_RCVD (that is, other states except SYN_RCVD) - ESTABLELISHED; the other end is a TCP server, and the state transfer process of the other end is SYN_RCVD-ESTABLELISHED.

[0075] Furthermore, in a TCP connection, there is only one of the above two situations. According to which of the two situations is met, it can be distinguished that the two ends of a TCP connection are TCP servers or TCP clients.

[0076] As an optional implementation scheme of the present application, obtaining the status information of the TCP connection includes:

[0077] Get the file descriptor allocation table of the network protocol stack;

[0078] In this embodiment, the file descriptors of the local end and the peer end are allocated by the network protocol stack. Before actively closing this port, the file descriptor is generally not reused. For example, the network protocol stack allocates file descriptor (fd, filedescriptor) = 3 to the local end. If it is not closed (fd = 3), it will apply for fd from the network protocol stack. If the file descriptor does not reach the limit, it will start to allocate from fd = 4.

[0079] According to the file descriptor allocation table, status information of the TCP connection corresponding to the allocated file descriptor is obtained.

[0080] According to the file descriptor allocation table, all file descriptors corresponding to the local end are traversed, and the member variables of the socket structure corresponding to the file descriptor are read through the interface (i.e., function) provided by the network protocol stack, wherein the member so_state, socket state represents the state bit of the socket, and the state bit reflects the state information, i.e., the state information of the TCP connection. After obtaining the state information of the TCP connection, the state information of the TCP connection is saved in the database. Since the file descriptor is not fixed, the state information of the TCP connection is also not fixed. After obtaining the state information of the TCP connection for multiple times and recording it in the database, the database not only saves the state information of the current TCP connection, but also saves the state information of the historical TCP connection.

[0081] It should be noted that when it is necessary to obtain the status information of the TCP connection based on the peer end, the method of obtaining the status information of the TCP connection is the same as the method of obtaining the status information of the TCP connection based on the local end.

[0082] As an optional implementation scheme of the present application, before detecting the status information, the method further includes:

[0083] Get timing information;

[0084] See also Figure 2 , after obtaining the status information of the TCP connection and reading it, it is also necessary to record the status information of the TCP connection to the database. Because when looking back at the TCP finite state machine, taking the local end as an example, based on the current status information of the local TCP connection and the previous status information, it is determined whether the local end is a TCP server or a TCP client. After reading and recording the status information of the TCP connection, the current status information of the local TCP connection may change and change to the historical status information of the TCP connection. It can also be said that when looking back at the TCP finite state machine, the current status information of the TCP connection loses its timeliness, so the judgment of whether the local end is a TCP server or a TCP client is inaccurate. Therefore, after reading the information on the TCP connection status, start timing the time, see Figure 2 , a timer can be used for timing. After the status information of all TCP connections is saved in the database, the timing is ended and the timing information is generated.

[0085] When the timing information exceeds a preset timing threshold, the state information of the TCP connection is obtained again.

[0086] In this embodiment, the preset timing threshold is 500ms. When the timing information exceeds 500ms, it means that the status information of the current TCP connection has lost its timeliness, and it is necessary to traverse all the file descriptors corresponding to the local end according to the file descriptor allocation table again to obtain the status information of the TCP connections of all local ends. The preset timing threshold can achieve periodic reading of the file descriptor allocation table of the network protocol stack, and then obtain the status information of the TCP connection running in the current operating system.

[0087] It should be noted that the specific value of the preset timing threshold is determined by the user according to actual conditions and is not limited here.

[0088] As an optional implementation scheme of the present application, when the timing information does not exceed a preset timing threshold, a TCP state transfer process diagram is drawn.

[0089] When the timing information does not exceed 500ms, the terminal graphics library is used to draw the TCP state transition process diagram of the local end or the opposite end and print it to a terminal device in real time. Further, the state transition path of the TCP connection of the local end or the opposite end can be analyzed, and then the local end is identified as a TCP server or a TCP client, so as to obtain the opposite end as a TCP client or a TCP server. Among them, the terminal graphics library can use libcurse, or it can be replaced by a newer pixel-based graphics terminal library, depending on user needs, which is not limited here.

[0090] As an optional implementation scheme of the present application, obtaining the previous state information of the current state information further includes:

[0091] Judging the state transition process formed by the previous state information and the current state information, and determining whether the state transition process is a preset special state transition path for the TCP connection;

[0092] Taking the state information of the local TCP connection as an example, the previous state information of the local TCP connection is obtained by traversing the database, and the state transition process formed by the current state information and the previous state information is judged to determine whether the state transition process is a special state transition path. In addition, the traversal database will also obtain the state information of other TCP connections and their corresponding previous state information, and judge the state transition process of other TCP connections to determine whether it is a special state transition path.

[0093] When it is determined that the state transfer process is a preset special state transfer path, the preset special state transfer path is specially marked in the TCP state transfer process diagram.

[0094] When a special state transition path is confirmed, the special state transition path is specially marked when the TCP state transition process diagram is drawn in real time. The special mark can be regular bold, underline or italic, etc. The user can choose according to the actual situation, and it is not limited here.

[0095] In this embodiment, there are seven special state transition paths in total, which are subdivided into a special state transition path belonging to the client, a special state transition path belonging to the server, and a special state transition path belonging to both the client and the server.

[0096] Special state transfer path belonging to the client:

[0097] SYN_SENT->CLOSE: The client attempts to connect to the server, but the server sends a RST to the client. Finally, the client connection fails.

[0098] FIN_WAIT_1->TIME_WAIT: The client in FIN_WAIT_1 state directly receives the ACKFIN message from the server (instead of receiving the ACK message first). At this time, the server has no message to send when the client requests to disconnect.

[0099] Special state transition path belonging to the server:

[0100] LISTEN->SYN_SENT: The server actively initiates a connection request to the client.

[0101] SYN_RCVD->LISTEN: The server receives the RST message from the client (indicating that the client requests to re-establish the connection), and the server returns to the listen state.

[0102] SYN_RCVD->FIN_WAIT_1: The server actively sends a FIN message to the client in an attempt to end the connection.

[0103] Special state transfer paths belonging to the client and the server:

[0104] SYN_SENT->SYN_RCVD: The client and server simultaneously initiate connection requests to each other.

[0105] FIN_WAIT_1->CLOSING: The client and server simultaneously initiate a connection closing request to each other.

[0106] Other state transition paths other than the special state transition path are regarded as normal state transitions of the server and the client, and are not specially marked. The normal state transition is the normal change process of the TCP connection.

[0107] In actual network applications, there are usually multiple servers and clients in a cluster, and the TCP connection between the server and the client is not a one-to-one connection relationship, that is, the server can establish TCP connections with multiple clients. Next, we will take a small cluster as an example to illustrate the application process of the above method.

[0108] For details, see Figure 5 , take a cluster with a server (which can be regarded as a server, and is referred to as a server in the following to avoid confusion) and three clients as an example, see Figure 4 ,according to Figure 4The four-tuple in the TCP connection uniquely identifies a TCP connection. The four-tuple includes: the IP address of the server, the port that the server listens on, the IP address of the client that initiates the connection request, and the port that the client initiates the connection request. In actual network applications, a server process usually listens to a fixed IP address: port tuple, while there can be many clients that initiate connection requests.

[0109] In the quadruple of a TCP connection, if any element is different from the quadruple of an existing TCP connection in the network protocol stack, it is regarded as a new connection.

[0110] Assume that the connection between the server and client 1 is TCP connection 1, the connection with client 2 is TCP connection 2, and the connection with client 3 is TCP connection 3. Figure 2 , start reading the connection status information of all TCP connections in the cluster, and start timing at the same time. That is, read the status information of TCP connection 1, TCP connection 2, and TCP connection 3. And record the above status information in the database, and end the timing after recording. When the timing information does not exceed 500ms, draw the state transition process diagram of TCP connection 1, TCP connection 2, and TCP connection 3. Assuming that the status information of TCP connection 2 is an established connection, traverse the database to find the previous state information of TCP connection 2. At this time, by traversing the database, the previous state information of TCP connection 1 and TCP connection 3 can be obtained at the same time. Assuming that the changes in the previous state information and the current state information of TCP connection 1 constitute a special state transition path, the special state transition path is marked when drawing the state transition diagram of TCP connection 1. Similarly, when no TCP connection is in the established connection state, there is no need to traverse the database, and there is no need to update the state transition process diagram of any TCP connection. Wait until the actual time exceeds 500ms to start the next cycle of reading the state information of the TCP connection, and re-read the state information of TCP connection 1, TCP connection 2, and TCP connection 3.

[0111] See also Figure 3 When traversing the database to find the previous state information of TCP connection 2, whether the local end is a server or a client is determined based on whether the previous state information of TCP connection 2 is SYN_RCVD. In this example, in the actual process of cluster work, the user only knows that a TCP connection consists of a local end and a peer end, but does not know whether the local end is a server or a client. At this time, based on the previous state information of any established TCP connection 1, TCP connection 2, and TCP connection 3, it can be determined whether the local end is a server or a client.

[0112] Through the above method, the TCP state transfer process diagram can be refreshed in real time on the terminal, and the two ends of the TCP connection can be distinguished as servers or clients according to the state transfer process of the TCP connection. When development and test engineers encounter problems such as connection interruptions, they can more intuitively locate specific problems in the network application development process, and no longer need to rely on other network utility tools to trace back the finite state machine, thereby reducing the high learning cost of development and test engineers.

[0113] Example 2

[0114] Based on the same principle as the above method, a device for distinguishing the two ends of a TCP connection in a microkernel operating system is also proposed, see Figure 6 , a device 100 for distinguishing two ends of a TCP connection in a microkernel operating system according to an embodiment of the present disclosure includes:

[0115] The status information acquisition module 110 is used to acquire the status information of the TCP connection;

[0116] The status information detection module 120 is used to detect the status information, judge the status of the TCP connection, and determine whether the connection is established;

[0117] The module 130 for obtaining historical status information is used to obtain the previous status information of the current status information when the status of the TCP connection is the established connection status;

[0118] The identification module 140 is used to analyze the state transfer process of the TCP connection according to the previous state information and identify the two ends of the TCP connection.

[0119] As an optional implementation scheme of the present application, the identification module is used to analyze the state transfer process of the TCP connection according to the previous state information and identify the two ends of the TCP connection, including:

[0120] An identification server module, used for obtaining that the local end in the TCP connection is a TCP server when the previous state information is SYN_RCVD;

[0121] The client identification module is used to obtain that the local end in the TCP connection is a TCP client when the previous state information is SYN_SENT.

[0122] Obviously, those skilled in the art should understand that all or part of the processes in the above-mentioned embodiment method can be implemented by instructing the relevant hardware through a computer program. The program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned control methods. The modules or steps of the present invention can be implemented by a general-purpose computing device. They can be concentrated on a single computing device or distributed on a network composed of multiple computing devices. Optionally, they can be implemented by program codes executable by computing devices, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules respectively, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the present invention is not limited to any specific combination of hardware and software.

[0123] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment method can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned control methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory (Flash Memory), a hard disk (Hard Disk Drive, abbreviated as: HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.

[0124] Example 3

[0125] Furthermore, an electronic device is proposed, comprising:

[0126] processor;

[0127] a memory for storing processor-executable instructions;

[0128] Wherein, the processor is configured to implement the method for distinguishing the two ends of a TCP connection in a microkernel operating system described in Example 1 when executing the executable instructions.

[0129] The electronic device of the embodiment of the present disclosure includes a processor and a memory for storing processor executable instructions, wherein the processor is configured to implement any of the above-mentioned methods for distinguishing two ends of a TCP connection in a microkernel operating system when executing the executable instructions.

[0130] It should be noted that the number of processors may be one or more. At the same time, the electronic device of the embodiment of the present disclosure may also include an input device and an output device. The processor, memory, input device, and output device may be connected via a bus or in other ways, which are not specifically limited here.

[0131] The memory is a computer-readable storage medium for the method for distinguishing the two ends of a TCP connection in a microkernel operating system, and can be used to store software programs, computer executable programs, and various modules, such as: the program or module corresponding to the method for distinguishing the two ends of a TCP connection in a microkernel operating system of an embodiment of the present disclosure. The processor executes various functional applications and data processing of the electronic device by running the software program or module stored in the memory.

[0132] The input device can be used to receive input numbers or signals. The signal can be a key signal related to user settings and function control of the device / terminal / server. The output device can include a display device such as a display screen.

[0133] The embodiments of the present application have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A method for distinguishing the two ends of a TCP connection in a microkernel operating system. It is characterized in that include: Get the status information of TCP connection; Detecting the status information, judging the status of the TCP connection, and determining whether the connection is established; When the state of the TCP connection is an established connection state, obtaining the previous state information of the current state information; According to the previous state information, the state transfer process of the TCP connection is analyzed to identify the two ends of the TCP connection.

2. The method for distinguishing two ends of a TCP connection in a microkernel operating system according to claim 1, It is characterized in that Analyzing the state transfer process of the TCP connection and identifying the two ends of the TCP connection includes: When the previous state information is SYN_RCVD, the local end in the TCP connection is obtained as a TCP server; When the previous state information is SYN_SENT, it is obtained that the local end in the TCP connection is a TCP client.

3. The method for distinguishing two ends of a TCP connection in a microkernel operating system according to claim 2, It is characterized in that Before identifying the two ends of the TCP connection, the method further includes: When the local end is a TCP server, determining that the opposite end corresponding to the local end in the TCP connection is a TCP client; When the local end is a TCP client, it is determined that the opposite end corresponding to the local end in the TCP connection is a TCP server.

4. The method for distinguishing two ends of a TCP connection in a microkernel operating system according to claim 1, It is characterized in that Get the status information of the TCP connection, including: Get the file descriptor allocation table of the network protocol stack; According to the file descriptor allocation table, status information of the TCP connection corresponding to the allocated file descriptor is obtained.

5. The method for distinguishing two ends of a TCP connection in a microkernel operating system according to claim 1, It is characterized in that Before detecting the status information, the method further includes: Get timing information; When the timing information exceeds a preset timing threshold, the state information of the TCP connection is obtained again.

6. The method for distinguishing two ends of a TCP connection in a microkernel operating system according to claim 5, It is characterized in that When the timing information does not exceed the preset timing threshold, a TCP state transfer process diagram is drawn.

7. The method for distinguishing two ends of a TCP connection in a microkernel operating system according to claim 6, It is characterized in that Acquiring the previous state information of the current state information also includes: Judging the state transition process formed by the previous state information and the current state information, and determining whether the state transition process is a preset special state transition path for the TCP connection; When it is determined that the state transfer process is a preset special state transfer path, the preset special state transfer path is specially marked in the TCP state transfer process diagram.

8. A device for distinguishing the two ends of a TCP connection in a microkernel operating system. It is characterized in that include: A status information acquisition module is used to acquire the status information of the TCP connection; A status information detection module is used to detect the status information, judge the status of the TCP connection, and determine whether the connection is established; A module for obtaining historical status information, used for obtaining the previous status information of the current status information when the status of the TCP connection is the established connection status; The identification module is used to analyze the state transfer process of the TCP connection according to the previous state information and identify the two ends of the TCP connection.

9. The device for distinguishing two ends of a TCP connection in a microkernel operating system according to claim 8, It is characterized in that The identification module is used to analyze the state transfer process of the TCP connection according to the previous state information and identify the two ends of the TCP connection, including: An identification server module, used for obtaining that the local end in the TCP connection is a TCP server when the previous state information is SYN_RCVD; The client identification module is used to obtain that the local end in the TCP connection is a TCP client when the previous state information is SYN_SENT.

10. An electronic device, It is characterized in that include: processor; a memory for storing processor-executable instructions; Wherein, the processor is configured to implement the method for distinguishing two ends of a TCP connection in a microkernel operating system as described in any one of claims 1-7 when executing the executable instructions.