CN108712459B - Protocol message cross-layer communication method and device and electronic equipment - Google Patents

Protocol message cross-layer communication method and device and electronic equipment Download PDF

Info

Publication number
CN108712459B
CN108712459B CN201810292638.5A CN201810292638A CN108712459B CN 108712459 B CN108712459 B CN 108712459B CN 201810292638 A CN201810292638 A CN 201810292638A CN 108712459 B CN108712459 B CN 108712459B
Authority
CN
China
Prior art keywords
protocol
socket
message
protocol message
packet
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201810292638.5A
Other languages
Chinese (zh)
Other versions
CN108712459A (en
Inventor
陈涛
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Forward Industrial Co Ltd
Original Assignee
Shenzhen Forward Industrial Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Forward Industrial Co Ltd filed Critical Shenzhen Forward Industrial Co Ltd
Priority to CN201810292638.5A priority Critical patent/CN108712459B/en
Publication of CN108712459A publication Critical patent/CN108712459A/en
Application granted granted Critical
Publication of CN108712459B publication Critical patent/CN108712459B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/30Definitions, standards or architectural aspects of layered protocol stacks
    • H04L69/32Architecture of open systems interconnection [OSI] 7-layer type protocol stacks, e.g. the interfaces between the data link level and the physical level
    • H04L69/321Interlayer communication protocols or service data unit [SDU] definitions; Interfaces between layers
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/16Implementation or adaptation of Internet protocol [IP], of transmission control protocol [TCP] or of user datagram protocol [UDP]
    • H04L69/161Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields
    • H04L69/162Implementation details of TCP/IP or UDP/IP stack architecture; Specification of modified or new header fields involving adaptations of sockets based mechanisms

Landscapes

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

Abstract

The invention provides a protocol message cross-layer communication method, a device and electronic equipment, which relate to the technical field of communication, and the method comprises the following steps: receiving a protocol message sent to a CPU by a switching chip; judging the protocol type of the protocol message according to the extension information in the protocol message, and storing the protocol message in a buffer area of a corresponding pre-established socket according to the protocol type; the pre-created socket includes: the socket releases a callback function and receives a packet processing callback function; calling a copy function provided by a kernel, and converting the protocol message taken out from the buffer into a user mode space; and calling a packet receiving processing callback function, and reading the protocol message converted into the user mode space. The invention can classify the received protocol message, so that the protocol message can not enter unnecessary kernel processing branches, thereby reducing the waste of system resources, and when a certain protocol message has burst flow, the invention can not influence the cross-layer communication of other protocol messages, thereby improving the safety and reliability of the network.

Description

Protocol message cross-layer communication method and device and electronic equipment
Technical Field
The present invention relates to the field of cross-layer communication technologies, and in particular, to a method and an apparatus for cross-layer communication of a protocol packet, and an electronic device.
Background
The current switch system aims to make the system more stable, efficient and safe. It is therefore divided into a data plane, a control plane, a management plane. The control plane is used for controlling and managing the operation of all network protocols, and providing various network information and forwarding query table items necessary for data processing and forwarding of the data plane. In the mode of separating the data plane from the control plane, the protocol messages in the data plane are all required to be sent to the Linux kernel from the exchange chip through the PCI-E bus, and then are sent to the protocol module of the Linux user space from the Linux kernel. When the protocol module in the Linux user space sends the protocol message, the protocol message needs to be sent into the Linux kernel first, and then is transmitted to the switching chip through the PCI-E bus interface for sending. This cross-layer (kernel and user space) processing is generally two in conventional techniques:
the first is to use the AF _ PACKET two-layer PACKET grabbing technique. Firstly, a virtual interface corresponding to an interface of a switch is established in a kernel, then a protocol message sent to a CPU on the switch is put into a packet receiving queue of the corresponding virtual interface, and a user mode protocol directly receives the message through two-layer packet capturing. When the protocol processing program sends the message, the message is sent to the corresponding kernel virtual interface through two-layer sending, and the protocol message is taken out and sent by a hook function registered in the kernel.
The second is the Netlink socket using kernel and user mode communication. All kernel and user space protocol messages are transmitted via the Netlink socket.
In the conventional cross-layer scheme, the first method uses an AF _ PACKET mode, when a PACKET is received by a protocol module, the PACKET needs to be filtered by itself to filter other PACKETs, and the PACKET is copied and then taken away by the protocol module, but the PACKET still enters other processing branches of a kernel to be processed. And the second method needs to repackage the Netlink head by a message and then send the Netlink head into a user state space through a kernel protocol stack.
No matter which protocol message is used, the waste of computing resources can be caused, and when a protocol message attacks, a large amount of certain protocol messages flow in, and the other protocol messages can also have the condition of packet loss.
Disclosure of Invention
In view of the above, an object of the present invention is to provide a method, an apparatus, and an electronic device for cross-layer communication of protocol packets, which can classify received protocol packets so that the received protocol packets do not enter unnecessary kernel processing branches, thereby reducing waste of system resources, and when a certain protocol packet has a burst traffic, cross-layer communication of other protocol packets is not affected, thereby improving security and reliability of a network.
In a first aspect, an embodiment of the present invention provides a protocol packet cross-layer communication method, where the method includes:
receiving a protocol message sent to a CPU by a switching chip; the protocol message includes: message data information and extension information;
judging the protocol type of the protocol message according to the extension information, and storing the protocol message in a buffer area of a corresponding pre-established socket according to the protocol type; the pre-created socket includes: the socket releases a callback function and receives a packet processing callback function;
calling a copy function provided by a kernel, and converting the protocol message taken out from the buffer into a user mode space;
and calling a packet receiving processing callback function, and reading the protocol message converted into the user mode space.
With reference to the first aspect, an embodiment of the present invention provides a first possible implementation manner of the first aspect, where before receiving a protocol packet sent to a CPU by a switch chip, the method further includes:
judging whether an original socket which is allowed to be used exists;
if yes, judging whether to create an original socket;
if yes, distributing the storage space of the original socket and initializing the original socket; the initialization includes: basic data initialization, protocol family number initialization, socket release callback function initialization and packet receiving processing callback function initialization;
and adding the initialized socket into the socket linked list of the protocol family.
With reference to the first aspect, an embodiment of the present invention provides a second possible implementation manner of the first aspect, where determining a protocol type of a protocol packet according to extension information specifically includes:
extracting two-layer header data of the protocol message from the extended information;
and judging the protocol type of the protocol message according to the destination MAC and type fields of the two-layer header data.
With reference to the first aspect, an embodiment of the present invention provides a third possible implementation manner of the first aspect, where storing a protocol packet in a buffer of a pre-created socket according to a protocol type specifically includes:
traversing a protocol family socket linked list according to the protocol type to find a corresponding target socket;
storing message data information of the protocol message in a first buffer area of a target socket; the first buffer area is a message data part;
storing the extension information of the protocol message in a second buffer area of the target socket; the second buffer is an address option portion.
With reference to the first aspect, an embodiment of the present invention provides a fourth possible implementation manner of the first aspect, where invoking a copy function provided by a kernel, and converting a protocol packet fetched from a buffer to a user state space specifically includes:
calling a copy function provided by the kernel, and copying the extension information of the protocol message to a user mode space;
judging whether the message length in the message data information of the protocol message is larger than the receiving length of the user state space;
if so, carrying out truncation processing on the message data information, and copying the message data information subjected to truncation processing to a user state space;
and if not, copying the message data information to a user mode space.
With reference to the first aspect, an embodiment of the present invention provides a fifth possible implementation manner of the first aspect, where after copying the truncated message data information to the user state space, or after copying the message data information to the user state space, the method further includes:
and setting a receiving timestamp for the message data information copied to the user mode space.
With reference to the first aspect, an embodiment of the present invention provides a sixth possible implementation manner of the first aspect, where invoking a packet receiving processing callback function, and reading a protocol packet converted into a user state space specifically includes:
calling a packet receiving processing callback function through a socket callback function provided by a kernel; the parameters of the socket callback function include: protocol family number, original socket;
and monitoring event triggering by using a select function in the packet receiving callback function, and reading the protocol message converted into the user mode space.
In a second aspect, an embodiment of the present invention provides a protocol packet cross-layer communication apparatus, where the apparatus includes:
a packet receiving module for receiving the protocol message sent by the switching chip; the protocol message includes: message data information and extension information;
the protocol classification module is used for judging the protocol type of the protocol message according to the extension information and storing the protocol message in a buffer area of a corresponding pre-established socket according to the protocol type; the pre-created socket includes: the socket releases a callback function and receives a packet processing callback function;
the protocol family processing module is used for calling a socket release callback function and converting the protocol message taken out from the buffer area into a user mode space;
and the protocol processing module is used for calling a packet receiving processing callback function and reading the protocol message converted into the user mode space.
In a third aspect, an embodiment of the present invention provides an electronic device, which includes a memory and a processor, where the memory stores a computer program that is executable on the processor, and the processor implements the steps of the method according to the first aspect when executing the computer program.
In a fourth aspect, an embodiment of the present invention provides a computer-readable medium having non-volatile program code executable by a processor, where the program code causes the processor to execute the method of the first aspect.
The embodiment of the invention has the following beneficial effects:
the protocol message cross-layer communication method provided by the embodiment of the invention comprises the following steps: receiving a protocol message sent to a CPU by a switching chip; the protocol message includes: message data information and extension information; judging the protocol type of the protocol message according to the extension information, and storing the protocol message in a buffer area of a corresponding pre-established socket according to the protocol type; the pre-created socket includes: the socket releases a callback function and receives a packet processing callback function; calling a copy function provided by a kernel, and converting the protocol message taken out from the buffer into a user mode space; and calling a packet receiving processing callback function, and reading the protocol message converted into the user mode space. The invention can classify the received protocol message, so that the protocol message can not enter unnecessary kernel processing branches, thereby reducing the waste of system resources, and when a certain protocol message has burst flow, the invention can not influence the cross-layer communication of other protocol messages, thereby improving the safety and reliability of the network.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.
Fig. 1 is a flowchart of a protocol packet cross-layer communication method according to an embodiment of the present invention;
fig. 2 is a flowchart of another protocol packet cross-layer communication method according to an embodiment of the present invention;
fig. 3 is a flowchart of another protocol packet cross-layer communication method according to an embodiment of the present invention;
fig. 4 is a flowchart of another protocol packet cross-layer communication method according to an embodiment of the present invention;
fig. 5 is a flowchart of another protocol packet cross-layer communication method according to an embodiment of the present invention;
fig. 6 is a flowchart of another protocol packet cross-layer communication method according to an embodiment of the present invention;
fig. 7 is a flowchart of another protocol packet cross-layer communication method according to an embodiment of the present invention;
fig. 8 is a schematic diagram of a protocol packet cross-layer communication apparatus according to a second embodiment of the present invention;
fig. 9 is a schematic view of an electronic device according to a third embodiment of the present invention.
Detailed Description
To make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The existing cross-layer communication method usually causes the waste of computing resources, and when a protocol message attacks, a large amount of certain protocol messages rush in, which can cause the condition that other protocol messages are lost.
Based on this, embodiments of the present invention provide a method, an apparatus, and an electronic device for cross-layer communication of protocol packets, which can classify received protocol packets so that the received protocol packets do not enter unnecessary kernel processing branches, thereby reducing waste of system resources, and when a certain protocol packet has a burst traffic, cross-layer communication of other protocol packets is not affected, thereby improving security and reliability of a network.
To facilitate understanding of the embodiment, a detailed description is first given to a protocol packet cross-layer communication method disclosed in the embodiment of the present invention.
The first embodiment is as follows:
an embodiment of the present invention provides a protocol packet cross-layer communication method, which is shown in fig. 1 and includes:
s101: receiving a protocol message sent to a CPU by a switching chip; the protocol message includes: message data information and extension information.
When the specific implementation is realized, firstly, a packet receiving module in the kernel receives a protocol message which is sent to the CPU by the switching chip through the PCIE. The protocol message comprises two parts of data information and extension information, wherein the extension information comprises: a layer two header, an interface number, a VLAN ID, etc.
S102: and judging the protocol type of the protocol message according to the extension information, and storing the protocol message in a buffer area of a corresponding pre-established socket according to the protocol type.
Before receiving a protocol message sent to a CPU by a switch chip, an extended protocol number needs to be defined in a kernel, that is, a socket is created in the kernel in advance, and a protocol family is re-registered, where the protocol family mainly includes registration of a socket release callback function and a packet reception processing callback function, and the specific process includes the following steps, as shown in fig. 2:
s201: it is determined whether there is an original socket that is allowed to be used.
Specifically, it is determined whether the user allows to use the RAW SOCKET, i.e. RAW SOCKET, for security control.
If yes, step S202 is executed: it is determined whether an original socket is created.
If not, an error is returned.
After judging whether to create the original socket, if the creation is approved, step S203 is executed: distributing the storage space of the original socket and initializing the original socket; the initialization includes: basic data initialization, protocol family number initialization, socket release callback function initialization and packet reception processing callback function initialization.
Specifically, the whole structure of the struct sock is initialized through a function void sock _ init _ data (struct socket sock, struct sock sk) provided by the kernel, the structure comprises a lot of specific basic data, and in addition, a series of protocol family numbers, a socket release callback function and a packet receiving processing callback function are initialized. After the initialization process is completed, step S204 is performed: and adding the initialized socket into the socket linked list of the protocol family.
Raw sockets, which allow direct access to lower level protocols, such as IP, ICMP, are often used to verify new protocol implementations, or to access new devices deployed in existing services, and can be used to manipulate network layer and transport layer applications because raw sockets can freely control multiple protocols under Windows, enabling control over the transport mechanisms of the network bottom layer. For example, ICMP and IGMP packets to the host may be received via RAW SOCKET, or IP packets that cannot be processed by the TCP/IP stack may be received, or some self-defined header or IP packets of a self-defined protocol may be sent.
The network snooping technique relies heavily on RAW SOCKET, and the original SOCKET is distinguished from the standard SOCKET (the standard SOCKET refers to the streaming SOCKET and the packet SOCKET described above) in that: the original socket can read and write the IP data packet which is not processed by the kernel, the stream socket can only read the data of the TCP protocol, and the data packet socket can only read the data of the UDP protocol. Therefore, the original socket must be used if the other protocol is to be accessed to send data.
In the step S102: according to the extension information, determining the protocol type of the protocol packet specifically includes the following steps, as shown in fig. 3:
s301: and extracting the two-layer header data of the protocol message from the extended information.
S302: and judging the protocol type of the protocol message according to the destination MAC and type fields of the two-layer header data.
In the step S102: according to the protocol type, the protocol packet is stored in a buffer of a pre-created socket, which specifically includes the following steps, as shown in fig. 4:
s401: and traversing the socket linked list of the protocol family according to the protocol type to find the corresponding target socket.
S402: storing message data information of the protocol message in a first buffer area of a target socket; the first buffer is the message data portion.
S403: storing the extension information of the protocol message in a second buffer area of the target socket; the second buffer is an address option portion.
Specifically, after receiving the protocol packet sent by the packet receiving module, the protocol classification module extracts two-layer header data from the extension information of the protocol packet, further determines the protocol type according to the destination MAC and type fields of the two-layer header data, allocates a buffer of the original socket corresponding to the protocol type for the protocol packet, puts the data of the two-layer header of the protocol packet, that is, the packet data information, into the buffer, and puts some extension information (such as the two-layer header, the interface number, and the VLAN ID …) required for protocol calculation into the address option part of the receiving socket. According to different protocol types, traversing corresponding protocol family socket linked lists, finding corresponding target sockets, respectively placing the message data information and the extension information into a first buffer area and a second buffer area of the corresponding sockets, and then placing the socket buffer areas into all socket receiving queues.
In the process of classifying and storing the received protocol messages, the cross-layer communication of each protocol message is supported by an independent protocol family and has different receiving and sending queues, so that the packet loss condition when other protocol messages are subjected to cross-layer communication when the messages are attacked is avoided; the problem that in the existing cross-layer technology, when a certain protocol message has burst flow, cross-layer communication of other protocol messages is influenced is solved, and the safety and reliability of the network are improved. In addition, the process also solves the problem that the message enters unnecessary kernel processing branches in the existing cross-layer communication, so that system resources are unnecessarily wasted.
S103: and calling a copy function provided by the kernel, and converting the protocol message taken out from the buffer into a user mode space.
Specifically, the protocol packet put in the queue in S102 is taken out from the packet receiving queue in a non-blocking manner, and the copy function skb _ copy _ datagram _ iovec provided by the kernel is directly called to convert the packet taken out from the queue into the user state space. The specific conversion process includes the following steps, as shown in fig. 5:
s501: and calling a copy function provided by the kernel, and copying the extension information of the protocol message to a user mode space.
S502: and judging whether the message length in the message data information of the protocol message is greater than the receiving length of the user state space.
If so, go to step S503: and carrying out truncation processing on the message data information, and copying the message data information subjected to truncation processing to a user state space.
If not, step S504 is executed: and copying the message data information to a user mode space.
Specifically, the protocol message is taken out from a receiving queue of the socket in a skb _ recv _ datagram non-blocking mode, and if the protocol message fails to return to the EINVAL, extension information in the protocol message, including L2 header information, entry information and other extension information, is copied to a user space; and then judging whether the message length in the message data information is larger than the user mode receiving address length, if so, performing truncation processing on the message data information, and setting an MSG _ TRUNC mark. The message is then transformed from kernel space to user space using skb _ copy _ datagram _ iovec.
In step S503: after the intercepted message data information is copied to the user state space, or in step S504: after copying the message data information to the user state space, the method further includes the following steps, as shown in fig. 6:
s601: and setting a receiving timestamp for the message data information copied to the user mode space.
Specifically, a receiving timestamp is set for the message through the sock _ recv _ timestamp.
Further, the following steps are executed by the user mode protocol processing module:
s104: and calling a packet receiving processing callback function, and reading the protocol message converted into the user mode space.
The specific process of reading the protocol packet includes the following steps, as shown in fig. 7:
s701: calling a packet receiving processing callback function through a socket callback function provided by a kernel; the parameters of the socket callback function include: protocol family number, raw socket.
S702: and monitoring event triggering by using a select function in the packet receiving callback function, and reading the protocol message converted into the user mode space.
The user mode protocol processing module uses a system to call int socket (int domain, int type, int protocol) to create, wherein the domain parameter is a protocol family number registered in the kernel, the type uses SOCK _ RAW, the protocol is 0, the function finally calls a packet receiving processing callback function registered in the kernel, after a socket corresponding to the protocol family is created, select is used for monitoring reading, and monitoring event triggering is carried out, so that a protocol message converted to the user mode space is read. Wherein the data portion is the data portion with the two-layer header removed. The receive address option part receives the extension information part registered by the callback part for the kernel.
According to the embodiment of the invention, a socket communication principle is fully utilized, a user-mode protocol processing module only needs simple socket creation, and select is used for monitoring and receiving and sending data; and the packet receiving processing callback function in the kernel is realized again, so that other additional unnecessary processing is not performed on the message, and the burden of the kernel is reduced.
The protocol message cross-layer communication method provided by the embodiment of the invention comprises the following steps: receiving a protocol message sent to a CPU by a switching chip; the protocol message includes: message data information and extension information; judging the protocol type of the protocol message according to the extension information, and storing the protocol message in a buffer area of a corresponding pre-established socket according to the protocol type; the pre-created socket includes: the socket releases a callback function and receives a packet processing callback function; calling a copy function provided by a kernel, and converting the protocol message taken out from the buffer into a user mode space; and calling a packet receiving processing callback function, and reading the protocol message converted into the user mode space. The invention can classify the received protocol message, so that the protocol message can not enter unnecessary kernel processing branches, thereby reducing the waste of system resources, and when a certain protocol message has burst flow, the invention can not influence the cross-layer communication of other protocol messages, thereby improving the safety and reliability of the network.
Example two:
an embodiment of the present invention provides a protocol packet cross-layer communication device, as shown in fig. 8, where the device includes: a packet receiving module 81, a protocol classification module 82, a protocol family processing module 83, and a protocol processing module 84.
The packet receiving module 81, the protocol classification module 82, and the protocol family processing module 83 are all modules in a kernel state, and the protocol processing module 84 is a module in a user state. A packet receiving module 81, configured to receive the protocol packet sent by the switch chip; the protocol message includes: message data information and extension information; the protocol classification module 82 is used for judging the protocol type of the protocol message according to the extension information and storing the protocol message in a buffer area of a corresponding pre-established socket according to the protocol type; the pre-created socket includes: the socket releases a callback function and receives a packet processing callback function; the protocol family processing module 83 is configured to call a socket release callback function, and convert a protocol packet taken out of the buffer area into a user state space; and the protocol processing module 84 is configured to call a packet receiving processing callback function, and read a protocol packet converted into a user mode space.
In the protocol message cross-layer communication device provided by the embodiment of the invention, each module has the same technical characteristics as the protocol message cross-layer communication method, so that the functions can be realized. The specific working process of each module in the device refers to the above method embodiment, and is not described herein again.
Example three:
an embodiment of the present invention provides an electronic device, as shown in fig. 9, the electronic device includes: the system comprises a processor 90, a memory 91, a bus 92 and a communication interface 93, wherein the processor 90, the communication interface 93 and the memory 91 are connected through the bus 92; the processor 90 is arranged to execute executable modules, such as computer programs, stored in the memory 91. The steps of the method according to the method embodiment are implemented when the processor executes the computer program.
The memory 91 may include a high-speed Random Access Memory (RAM) and may further include a non-volatile memory (non-volatile memory), such as at least one disk memory. The communication connection between the network element of the system and at least one other network element is realized through at least one communication interface 93 (which may be wired or wireless), and the internet, a wide area network, a local network, a metropolitan area network, and the like can be used.
Bus 92 may be an ISA bus, PCI bus, EISA bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one double-headed arrow is shown in FIG. 9, but this does not indicate only one bus or one type of bus.
The memory 91 is used for storing a program, the processor 90 executes the program after receiving an execution instruction, and the method executed by the apparatus defined by the flow process disclosed in any of the foregoing embodiments of the present invention may be applied to the processor 90, or implemented by the processor 90.
The processor 90 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 90. The Processor 90 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; the device can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components. The various methods, steps and logic blocks disclosed in the embodiments of the present invention may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present invention may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory 91, and the processor 90 reads the information in the memory 91 and performs the steps of the above method in combination with the hardware thereof.
The computer program product of the protocol packet cross-layer communication method provided in the embodiment of the present invention includes a computer-readable storage medium storing a nonvolatile program code executable by a processor, where instructions included in the program code may be used to execute the method described in the foregoing method embodiment, and specific implementation may refer to the method embodiment, which is not described herein again.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the apparatus and the electronic device described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicate orientations or positional relationships based on the orientations or positional relationships shown in the drawings, and are only for convenience of description and simplicity of description, but do not indicate or imply that the device or element being referred to must have a particular orientation, be constructed and operated in a particular orientation, and thus, should not be construed as limiting the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
Finally, it should be noted that: the above-mentioned embodiments are only specific embodiments of the present invention, which are used for illustrating the technical solutions of the present invention and not for limiting the same, and the protection scope of the present invention is not limited thereto, although the present invention is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive the technical solutions described in the foregoing embodiments or equivalent substitutes for some technical features within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (10)

1. A protocol message cross-layer communication method is characterized by comprising the following steps:
receiving a protocol message sent to a CPU by a switching chip; the protocol message includes: message data information and extension information;
judging the protocol type of the protocol message according to the extension information, and storing the protocol message in a pre-established buffer area of a socket corresponding to the protocol type according to the protocol type; the pre-created socket comprises: the socket releases a callback function and receives a packet processing callback function;
calling a copy function provided by a kernel, and converting the protocol message taken out from the buffer into a user mode space;
calling the packet receiving processing callback function, and reading the protocol message converted to the user mode space;
before receiving the protocol message sent to the CPU by the switch chip, the method further includes:
distributing the storage space of the original socket and initializing the original socket;
and adding the initialized socket into a protocol family socket linked list to determine a socket corresponding to the protocol type based on the protocol family socket linked list.
2. The method of claim 1, wherein prior to said receiving the protocol packet sent to the CPU by the switch chip, further comprising:
judging whether an original socket which is allowed to be used exists;
if yes, judging whether to create an original socket;
if yes, distributing the storage space of the original socket and initializing the original socket; the initialization comprises the following steps: basic data initialization, protocol family number initialization, socket release callback function initialization and packet receiving processing callback function initialization;
and adding the initialized socket into the socket linked list of the protocol family.
3. The method according to claim 1, wherein determining a protocol type of the protocol packet according to the extension information specifically includes:
extracting two-layer header data of the protocol message from the extended information;
and judging the protocol type of the protocol message according to the destination MAC and type fields of the two-layer header data.
4. The method according to claim 2, wherein the storing the protocol packet in a buffer of a pre-created socket according to the protocol type specifically includes:
traversing the protocol family socket linked list according to the protocol type to find a corresponding target socket;
storing message data information of the protocol message in a first buffer area of the target socket; the first buffer area is a message data part;
storing extension information of the protocol message in a second buffer area of the target socket; the second buffer is an address option portion.
5. The method according to claim 1, wherein the invoking a copy function provided by a kernel to convert the protocol packet retrieved from the buffer into a user state space specifically comprises:
calling a copy function provided by a kernel, and copying the extension information of the protocol message to a user mode space;
judging whether the message length in the message data information of the protocol message is larger than the receiving length of the user state space;
if so, performing truncation processing on the message data information, and copying the truncated message data information to the user state space;
and if not, copying the message data information to the user mode space.
6. The method according to claim 5, further comprising, after the copying the truncated message data information to the user state space or after the copying the message data information to the user state space:
and setting a receiving time stamp for the message data information copied to the user state space.
7. The method according to claim 2, wherein the invoking the packet reception processing callback function to read the protocol packet converted into the user state space specifically includes:
calling the packet receiving processing callback function through a socket callback function provided by a kernel; the parameters of the socket callback function include: the protocol family number, the raw socket;
and monitoring event triggering by using a select function in the packet receiving callback function, and reading the protocol message converted into the user mode space.
8. A protocol packet cross-layer communication apparatus, the apparatus comprising:
a packet receiving module for receiving the protocol message sent by the switching chip; the protocol message includes: message data information and extension information;
the protocol classification module is used for judging the protocol type of the protocol message according to the extension information and storing the protocol message in a pre-established buffer area of a socket corresponding to the protocol type according to the protocol type; the pre-created socket comprises: the socket releases a callback function and receives a packet processing callback function;
the protocol family processing module is used for calling a copy function provided by the kernel and converting the protocol message taken out from the buffer into a user mode space;
the protocol processing module is used for calling the packet receiving processing callback function and reading the protocol message converted into the user mode space;
the packet receiving module also allocates a storage space of the original socket, initializes the original socket, adds the initialized socket into a protocol family socket linked list, and the protocol classification module determines the socket corresponding to the protocol type based on the protocol family socket linked list.
9. An electronic device comprising a memory, a processor, and a computer program stored on the memory and operable on the processor, wherein the processor implements the steps of the method of any of claims 1 to 7 when executing the computer program.
10. A computer-readable medium having non-volatile program code executable by a processor, wherein the program code causes the processor to perform the method of any of claims 1 to 7.
CN201810292638.5A 2018-03-30 2018-03-30 Protocol message cross-layer communication method and device and electronic equipment Active CN108712459B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810292638.5A CN108712459B (en) 2018-03-30 2018-03-30 Protocol message cross-layer communication method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810292638.5A CN108712459B (en) 2018-03-30 2018-03-30 Protocol message cross-layer communication method and device and electronic equipment

Publications (2)

Publication Number Publication Date
CN108712459A CN108712459A (en) 2018-10-26
CN108712459B true CN108712459B (en) 2021-06-15

Family

ID=63867141

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810292638.5A Active CN108712459B (en) 2018-03-30 2018-03-30 Protocol message cross-layer communication method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN108712459B (en)

Families Citing this family (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111182487B (en) * 2018-11-09 2022-06-03 杭州海康威视数字技术股份有限公司 Data sending method, data receiving method and device
CN109274774A (en) * 2018-11-16 2019-01-25 郑州云海信息技术有限公司 A kind of date storage method, device and computer readable storage medium
CN110061926A (en) * 2019-04-26 2019-07-26 武汉思创易控科技有限公司 A kind of ping method, storage medium, the terminal and server of multiplexing
CN111555950B (en) * 2020-03-26 2022-05-13 厦门网宿有限公司 Message processing method, device, server and storage medium
CN113536305B (en) * 2020-04-17 2022-09-09 武汉瓯越网视有限公司 Method and device for detecting acquisition behavior
CN111586040B (en) * 2020-05-06 2021-02-09 北京中科海讯数字科技股份有限公司 High-performance network data receiving method and system
CN111953568B (en) * 2020-08-19 2022-04-08 杭州迪普科技股份有限公司 Method and device for managing packet loss information
CN114281431A (en) * 2020-09-28 2022-04-05 阿里巴巴集团控股有限公司 Function calling method, device, medium, embedded equipment and operating system
CN112261094B (en) * 2020-10-10 2023-07-21 厦门网宿有限公司 Message processing method and proxy server
CN112769688B (en) * 2020-12-18 2022-07-29 南方电网科学研究院有限责任公司 Method and device for protocol stack adaptation, electronic equipment and storage medium
CN113382014B (en) * 2021-06-23 2022-12-06 中移(杭州)信息技术有限公司 Negotiation processing method, device, terminal equipment and storage medium
CN114928597B (en) * 2022-05-20 2023-07-25 中国联合网络通信集团有限公司 Data transmission method, device and equipment
CN114968893B (en) * 2022-07-27 2022-09-30 井芯微电子技术(天津)有限公司 PCIe message queue scheduling method, system and device based on timestamp
CN116016702A (en) * 2022-12-26 2023-04-25 浪潮云信息技术股份公司 Application observable data acquisition processing method, device and medium
CN115857420B (en) * 2023-03-03 2023-05-12 深圳市综科智控科技开发有限公司 IO mutual control method between industrial control equipment
CN117395329B (en) * 2023-12-13 2024-02-06 井芯微电子技术(天津)有限公司 Method, device and storage medium for receiving and transmitting Ethernet two-layer protocol message

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1700664A (en) * 2005-06-10 2005-11-23 重庆邮电学院 Linux kernel based high-speed network flow measuring unit and flow measuring method
US8539089B2 (en) * 2003-04-23 2013-09-17 Oracle America, Inc. System and method for vertical perimeter protection
US9002970B2 (en) * 2012-07-12 2015-04-07 International Business Machines Corporation Remote direct memory access socket aggregation
CN104580124A (en) * 2013-10-29 2015-04-29 华为技术有限公司 Protocol stack selection method, device and equipment
CN107172009A (en) * 2017-04-06 2017-09-15 烽火通信科技股份有限公司 By sending vlan information on socket to the method for application module

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8539089B2 (en) * 2003-04-23 2013-09-17 Oracle America, Inc. System and method for vertical perimeter protection
CN1700664A (en) * 2005-06-10 2005-11-23 重庆邮电学院 Linux kernel based high-speed network flow measuring unit and flow measuring method
US9002970B2 (en) * 2012-07-12 2015-04-07 International Business Machines Corporation Remote direct memory access socket aggregation
CN104580124A (en) * 2013-10-29 2015-04-29 华为技术有限公司 Protocol stack selection method, device and equipment
CN107172009A (en) * 2017-04-06 2017-09-15 烽火通信科技股份有限公司 By sending vlan information on socket to the method for application module

Also Published As

Publication number Publication date
CN108712459A (en) 2018-10-26

Similar Documents

Publication Publication Date Title
CN108712459B (en) Protocol message cross-layer communication method and device and electronic equipment
US8625431B2 (en) Notifying network applications of receive overflow conditions
US9152593B2 (en) Universal PCI express port
US9019978B2 (en) Port mirroring at a network interface device
US10313380B2 (en) System and method for centralized virtual interface card driver logging in a network environment
EP3275140B1 (en) Technique for achieving low latency in data center network environments
CN103929334A (en) Network abnormity notification method and apparatus
US7987307B2 (en) Interrupt coalescing control scheme
CN108650295A (en) Protocol massages cross-layer communication method device and electronic equipment
JP5968841B2 (en) Network device and processor monitoring method
WO2021128927A1 (en) Message processing method and apparatus, storage medium, and electronic apparatus
US8509228B2 (en) Method and apparatus for prioritizing source MAC address miss processing
JP5957318B2 (en) Network system, information relay device, and packet distribution method
US20080002586A1 (en) End-point based tamper resistant congestion management
CN111970497A (en) Video stream processing method and device, SDN controller and storage medium
US10887282B1 (en) Determining synchronization of filter rules (e.g., on iptable filter tables on Linux kernal) across firewall filter application restarts
CN108595270B (en) Memory resource recovery method and device
WO2021109851A1 (en) Network communication method, apparatus and device, and storage medium
US11405324B1 (en) Packet serial number validation
CN104811391B (en) Data packet processing method and device and server
TWI505675B (en) Network switch and data updating method
CN113556345A (en) Message processing method, device, equipment and medium
US9160688B2 (en) System and method for selective direct memory access
CN112367280B (en) RCPU agent board health detection method and RCPU agent board
US20240089219A1 (en) Packet buffering technologies

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant