CN103428226B - Method and system for communication of user state and inner core - Google Patents

Method and system for communication of user state and inner core Download PDF

Info

Publication number
CN103428226B
CN103428226B CN201310389001.5A CN201310389001A CN103428226B CN 103428226 B CN103428226 B CN 103428226B CN 201310389001 A CN201310389001 A CN 201310389001A CN 103428226 B CN103428226 B CN 103428226B
Authority
CN
China
Prior art keywords
message
main frame
microsoft loopback
loopback adapter
kernel
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
CN201310389001.5A
Other languages
Chinese (zh)
Other versions
CN103428226A (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.)
TIANJIN CP-WORLD INFORMATION TECHNOLOGY Co Ltd
Original Assignee
TIANJIN CP-WORLD INFORMATION TECHNOLOGY 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 TIANJIN CP-WORLD INFORMATION TECHNOLOGY Co Ltd filed Critical TIANJIN CP-WORLD INFORMATION TECHNOLOGY Co Ltd
Priority to CN201310389001.5A priority Critical patent/CN103428226B/en
Publication of CN103428226A publication Critical patent/CN103428226A/en
Application granted granted Critical
Publication of CN103428226B publication Critical patent/CN103428226B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The invention provides a method and system for communication of a user state and an inner core. The method for the communication of the user state and the inner core comprises the steps that a network data structure of a registered interface of a physical network card is obtained in the user state, the name of the registered interface of the physical network card is used for registering a virtual network card interface in the inner core according to the obtained network data structure of the registered interface of the physical network card, the physical network card in the user state is used for receiving mainframe receiving messages needing to be processed by the inner core, the mainframe receiving messages are transmitted to the inner core through a corresponding virtual network interface card, and the mainframe receiving messages processed by the inner core are transmitted to the user state through corresponding virtual network cards, and are sent to the physical network card through the user state. The method and system for the communication of the user state and the inner core can meet sensing requests of the physical network interface states by the user state and the inner core, and meanwhile the switchover problem of message formats of the user state and message formats of the inner core is solved. The system performance loss of information transmission between the user state and the inner core is reduced, the time of information transmission is saved, and efficiency of message transmission and processing is improved.

Description

A kind of method and system of User space and kernel communication
Technical field
The present invention relates to data interaction field, more particularly to the method and system of a kind of User space and kernel communication.
Background technology
In data interaction field, the communication between User space and kernel is a very important research topic.Due to interior The limitation of core state program, most kernel state programs are required for carrying out exchanging and transmission for data with User space, so as to realize being System widely extension and application.
In the prior art, the purpose of User space and kernel communication is mainly realized using following methods:A kind of method is Physical network card is loaded directly into by kernel to drive, the packet sending and receiving at external data end is carried out by physical network card, then by kernel Being sent in User space process by data copy carries out Business Processing;And another kind of method is to load Physical Network using User space Card drives, and by physical network card the transmitting-receiving of message is carried out, and for the main frame message for needing to be forwarded to kernel processes, User space can profit Data are realized with socket (socket) function creation communication chain handle or by process (proc) file system establishment file Interaction.
As described above as can be seen that in the prior art, by the method for kernel loads trawl performance easily ten thousand Cause a large amount of interruption under the impact of Broadcom big flow and consume certain cpu performance (especially for X86 architectural frameworks), separately The outer data copy from kernel state to User space will also result in the loss of certain systematic function;And existing User space loads network interface card The method of driving, although no longer face it is above-mentioned cause CPU disruptions, it also avoid caused by data copy systemic energy loss Consuming, but cannot solve some main frame message traffics process (the such as online dialing of linux kernel, dynamic IP addressing distribution) needs Perceive the problem of actual physics network and network interface state.
The content of the invention
(1) technical problem to be solved
The present invention provides the method and system of a kind of User space and kernel communication, can perceive actual physics network interface Physical state and change without the need for message format in communication process, solving in prior art can carry out thing without network interface The technical problem that reason is perceived.
(2) technical scheme
To solve above-mentioned technical problem, a kind of method that the present invention provides User space and kernel communication, it is characterised in that bag Include:
The network data structure of physical network card registration interface is obtained in User space;
According to the network data structure of the physical network card registration interface for being obtained, registered using the physical network card in kernel The name registration Microsoft Loopback Adapter interface of interface;
Being collected using the physical network card of User space needs the main frame of kernel processes to receive message, and the main frame is received into message Kernel is sent to by corresponding Microsoft Loopback Adapter;
The main frame that kernel processes are completed sends message and is sent to User space by corresponding Microsoft Loopback Adapter, and by described User space is sent to physical network card.
Further,
It is described that main frame reception message is sent to kernel and further includes by corresponding Microsoft Loopback Adapter:
Main frame message is created in User space receive chained list, it is corresponding with the receiving queue in the physical network card, according to connecing The device file handle that the main frame for receiving is received in packet network data structure searches corresponding Microsoft Loopback Adapter, and the main frame is connect Text of receiving telegraph is joined the team to the main frame message and receives chained list, remains subsequently to go out team by the main frame reception message write correspondence void Intend network interface card, be sent to kernel;
And/or,
The main frame transmission message that kernel processes are completed is sent to Physical Network and sticks into one by corresponding Microsoft Loopback Adapter Step includes:
Main frame message is created in User space send chained list, User space corresponding with the transmit queue in the physical network card The corresponding Microsoft Loopback Adapter of device file handle from physical network card interface network data structure, the kernel processes are completed Main frame sends message and reads, and joins the team to the main frame message and sends chained list, remains subsequently to go out team by physical network card transmit queue Send.
Further,
Join the team to main frame message reception chained list and the main frame is received into message write institute described described Before stating correspondence Microsoft Loopback Adapter, also include:The network data of all physics network card interfaces is traveled through using polling mode in User space The main frame message of structural maintenance receives chained list, makes message go out team until the message chained list of corresponding certain Microsoft Loopback Adapter is sky;
And/or,
Create main frame message in User space and send after chained list and in the User space from physical network card interface net described The corresponding Microsoft Loopback Adapter of device file handle in network data structure, the main frame that the kernel processes are completed sends message and reads Before, also include:The device file handle of all Microsoft Loopback Adapters is traveled through using polling mode in User space, until certain equipment text The data that the corresponding Microsoft Loopback Adapter of part handle reads are sky.
Further, the behaviour of team is joined the team and gone out in receiving chained list and main frame message transmission chained list from the main frame message Independently carry out.
Further, the interface physical state of the Microsoft Loopback Adapter of the physical network card and respective name is consistent, Including:The interface physical state of the physical network card is scanned in User space and be issued to kernel, in virtual net described in interior nuclear control The interface physical state of card is consistent with the interface physical state of the physical network card of respective name.
On the other hand, the system that the present invention also provides a kind of User space and kernel communication, including:Physical network card registration sets Standby, Microsoft Loopback Adapter registration equipment, physical network card, user's space, Microsoft Loopback Adapter interface module, Microsoft Loopback Adapter and kernel spacing, its Middle physical network card registration equipment is connected with physical network card, and positioned at user's space, Microsoft Loopback Adapter registration equipment is connected with Microsoft Loopback Adapter, It is connected by Microsoft Loopback Adapter interface module between kernel spacing, user's space and kernel spacing;Wherein:
Physical network card registers equipment, for obtaining the network data structure of physical network card registration interface in user's space, and Sent by Microsoft Loopback Adapter interface module to the Microsoft Loopback Adapter of kernel spacing and register equipment;
Microsoft Loopback Adapter registers equipment, for according to the network data structure of the physical network card registration interface for being obtained, including Nuclear space uses the name registration Microsoft Loopback Adapter interface of physical network card registration interface;
Physical network card, is received message and is forwarded by user's space for collecting the main frame for needing kernel spacing to process, and is sent out The main frame that the Jing kernel spacings received by user's space are disposed is sent to send message;
User's space, for needing what kernel spacing was processed by what physical network card was received by Microsoft Loopback Adapter interface module Main frame receives message and sends to kernel spacing, and by Microsoft Loopback Adapter interface module the main frame that Jing kernel spacings are disposed is received Deliver newspaper and text and sent by physical network card;
Microsoft Loopback Adapter interface module, the main frame for kernel spacing will be needed to process receives message write Microsoft Loopback Adapter and sends To kernel spacing, the main frame that Jing kernel spacings are disposed sends message and reads into user's space from Microsoft Loopback Adapter;
Microsoft Loopback Adapter, the main frame that kernel spacing is processed that needs for receiving the write of Microsoft Loopback Adapter interface module receives message And kernel spacing is forwarded to, the main frame that reception Jing kernel spacings are disposed is sent message and is read by Microsoft Loopback Adapter interface module Go out to be forwarded to user's space;
Kernel spacing, the main frame that kernel spacing is processed that needs for receiving Microsoft Loopback Adapter transmission receives message, is located Reason, and the main frame being disposed transmission message is sent by Microsoft Loopback Adapter.
Further, the user's space also includes:
Main frame message chained list receiver module, the main frame message for creating corresponding with the receiving queue in physical network card connects Chained list is received, the device file handle in packet network data structure is received according to the main frame that physical network card is received, search institute right The main frame message for answering Microsoft Loopback Adapter receives chained list, and the join the team main frame message of main frame reception message is received into chained list;
And/or,
Main frame message chained list sending module, sends out for creating the main frame message corresponding with the transmit queue in physical network card Chained list is sent, the main frame that the kernel processes that user's space reads from Microsoft Loopback Adapter are completed sends message, joins the team and the virtual net The corresponding main frame message of device file handle of card sends chained list, is resent to physical network card transmit queue.
Further, the Microsoft Loopback Adapter interface module also includes:
Microsoft Loopback Adapter message writing module, for being traveled through in the main frame message chained list receiver module by polling mode Main frame message receives chained list, the main frame is received into message and is gone out team and is write corresponding Microsoft Loopback Adapter, until the main frame message Chained list is received for empty stopping;
And/or,
Microsoft Loopback Adapter message read module, for traveling through all Microsoft Loopback Adapters by polling mode, directly sends in the main frame Message reads and sends to main frame message chained list sending module, until the content read from the Microsoft Loopback Adapter is empty stopping.
Further, the operation difference of the Microsoft Loopback Adapter message read module and the Microsoft Loopback Adapter message writing module Independently carry out.
Further, the Microsoft Loopback Adapter is at least one, is deployed in the ethernet layer of kernel spacing, the physical network card Quantity is identical with the Microsoft Loopback Adapter quantity;
The interface physical state of the interface physical state of each physical network card and the Microsoft Loopback Adapter of respective name It is consistent.
(3) beneficial effect
It can be seen that, in the method and system of User space proposed by the present invention and kernel communication, by the Physical Network of User space Data message is received in clamping, and the Microsoft Loopback Adapter (tap) of Jing kernels deployment realizes data interaction with kernel, without the need for kernel loads network interface card Drive to cause and interrupt and consume cpu performance, it is not required that the performance that data carry out loss system is copied from kernel state to User space;And Due to the physical network card interface and number, the title all same of kernel Microsoft Loopback Adapter interface of User space, with one-to-one pass System, can respectively meet the perception demand of User space, kernel for physical network interface state, can enter the behaviour of line interface binding Make, also solve the transfer problem of User space message format and kernel message format.Reduce User space to transmit with kernel information System performance loss, saved the time of information transfer, improve message transmissions and process efficiency.
Description of the drawings
In order to be illustrated more clearly that the embodiment of the present invention or technical scheme of the prior art, below will be to embodiment or existing The accompanying drawing to be used needed for having technology description is briefly described, it should be apparent that, drawings in the following description are these Some bright embodiments, for those of ordinary skill in the art, on the premise of not paying creative work, can be with root Other accompanying drawings are obtained according to these accompanying drawings.
Fig. 1 is the method basic procedure schematic diagram of User space of the present invention and kernel communication;
Fig. 2 is the schematic flow sheet of User space of the present invention and a preferred embodiment of the method for kernel communication;
Fig. 3 is the flow chart that User space of the present invention is interacted with User space in the method for kernel communication with kernel data;
Fig. 4 is the basic structure schematic diagram of User space of the present invention and the system of kernel communication;
Fig. 5 is the structural representation of User space of the present invention and a preferred embodiment of user's space in the system of kernel communication Figure;
Fig. 6 is the data interaction topological diagram of User space of the present invention and the system of kernel communication.
Specific embodiment
To make purpose, technical scheme and the advantage of the embodiment of the present invention clearer, below in conjunction with the embodiment of the present invention In accompanying drawing, the technical scheme in the embodiment of the present invention is clearly and completely described, it is clear that described embodiment is The a part of embodiment of the present invention, rather than the embodiment of whole.Based on the embodiment in the present invention, those of ordinary skill in the art The every other embodiment obtained under the premise of creative work is not made, belongs to the scope of protection of the invention.
A kind of method that the embodiment of the present invention proposes User space and kernel communication, including:
Step 101:The network data structure of physical network card registration interface is obtained in User space.
Step 102:According to the network data structure of the physical network card registration interface for being obtained, in kernel the physics is used The name registration Microsoft Loopback Adapter interface of network interface card registration interface.
Step 103:Being collected using the physical network card of User space needs the main frame of kernel processes to receive message, by the main frame Receive message and kernel is sent to by corresponding Microsoft Loopback Adapter.
Step 104:The main frame that kernel processes are completed sends message and is sent to User space by corresponding Microsoft Loopback Adapter, and Physical network card is sent to by the User space.
It can be seen that, in method of the User space that the embodiment of the present invention is proposed with kernel communication, can be by the thing of User space Reason network interface card receiving data message, and the Microsoft Loopback Adapter of Jing kernels deployment realizes data interaction with kernel, without the need for kernel loads network interface card Drive to cause and interrupt and consume cpu performance, it is not required that the performance that data carry out loss system is copied from kernel state to User space;And Due to the physical network card interface and number, the title all same of kernel Microsoft Loopback Adapter interface of User space, with one-to-one pass System, can respectively meet the perception demand of User space, kernel for physical network interface state, can enter the behaviour of line interface binding Make, also solve the transfer problem of User space message format and kernel message format.Reduce User space to transmit with kernel information System performance loss, saved the time of information transfer, improve message transmissions and process efficiency.
Also, in an embodiment of the present invention, in order to further determine that corresponding Microsoft Loopback Adapter, and to collecting and sending out The message for sending plays a part of sequence buffer, it is preferable that can adopt during main frame reception message is sent to into kernel Following method:
Main frame message is created in User space receive chained list, it is corresponding with the receiving queue in the physical network card, according to connecing The device file handle that the main frame for receiving is received in packet network data structure searches corresponding Microsoft Loopback Adapter, and the main frame is connect Text of receiving telegraph is joined the team to the main frame message and receives chained list, remains subsequently to go out team by the main frame reception message write correspondence void Intend network interface card, be sent to kernel.
In another embodiment of the present invention, receive during the main frame that completes of kernel processes sends message can be with Adopt with the following method:
Main frame message is created in User space send chained list, User space corresponding with the transmit queue in the physical network card The corresponding Microsoft Loopback Adapter of device file handle from physical network card interface network data structure, the kernel processes are completed Main frame sends message and reads, and joins the team to the main frame message and sends chained list, remains subsequently to go out team by physical network card transmit queue Send.
In the practical application of the embodiment of the present invention, the report for needing Jing kernel processes is sent one by one in order to exhaustive ground Text, it is preferable that joining the team to main frame message reception chained list, main frame is received before message write correspondence Microsoft Loopback Adapter, also Can include:In the main frame message that User space is safeguarded using the network data structure that polling mode travels through all physics network card interfaces Chained list is received, makes message go out team until the message chained list of corresponding certain Microsoft Loopback Adapter is sky.
In another embodiment of the present invention, the report that kernel processes are finished is collected one by one at any time in order to exhaustive ground Text, it is preferable that after User space creates main frame message transmission chained list, and in User space from physical network card interface network data The corresponding Microsoft Loopback Adapter of device file handle in structure, the main frame that kernel processes are completed is sent before message reading, may be used also To include:The device file handle of all Microsoft Loopback Adapters is traveled through using polling mode in User space, until certain device file sentence The data that the corresponding Microsoft Loopback Adapter of handle reads are sky.
In another embodiment of the present invention, the process for sending message and collecting message does not conflict, so in user State receives chained list and main frame message and sends from main frame message to be joined the team and goes out the operation of team and can independently carry out in chained list.
In one embodiment of the invention, it is being directed to when some main frame message traffics are processed to perceive actual physics The state of network and network interface, needs carry out corresponding interface physical state aware in kernel, it is preferable that physical network card and The interface physical state of the Microsoft Loopback Adapter of respective name can be consistent.In an actual realization of the embodiment of the present invention In, the interface physical state of the physical network card can be scanned in User space and kernel is issued to, virtual described in interior nuclear control The interface physical state of network interface card is consistent with the interface physical state of the physical network card of respective name.
Below as a example by the process of a message for needing kernel processes is specifically received from User space describing this in detail Bright one embodiment realizes process, and referring to Fig. 2, the processing procedure of the message includes:
Step 201:Kernel is initialized, and configure Microsoft Loopback Adapter can use, dispose Microsoft Loopback Adapter.
In this step, carry out initialization operation to kernel, and due in subsequent step kernel end need using virtual Network interface card receives and dispatches message, communicates with User space, so needing configuration Microsoft Loopback Adapter can use while kernel initialization.
The Microsoft Loopback Adapter of kernel needs to be deployed in ethernet layer, and in this step Microsoft Loopback Adapter can be one or more, Depending on the condition of actual interface, and Microsoft Loopback Adapter can also carry out bridge joint mouth, the binding of link aggregation mouth etc. operation.
Step 202:Initialization operation is carried out to User space, and loads physics trawl performance, complete physical network card initialization Interface is registered.
In this step, physical network card is deployed in User space, for receiving the message at external data end, so need with Family state carries out the drive load of physical network card and initialization interface registration step.
Step 203:Ginseng is entered as function using the interface network data structure (netdev) registered in User space, addition is called Interface function with network equipment title (netdev-name) carry out kernel Microsoft Loopback Adapter initialization and interface registration so that Microsoft Loopback Adapter registration interface is identical with the title of physical network card registration interface, the device file handle (tapfd) that registration is returned It is stored in the netdev of User space.
In this step, the title for ensureing Microsoft Loopback Adapter registration interface using the netdev of physical network card registration interface is needed It is consistent with physical network card, to realize one-to-one relation, so as to the message transmissions in subsequent step and interface physical shape The sensing of state.
The tapfd that the Microsoft Loopback Adapter registration interface of kernel is returned is preserved to the netdev of User space, can be for subsequent step In searched by receiving the netdev of message correspondence tapfd Microsoft Loopback Adapter, to be stored in corresponding Microsoft Loopback Adapter.
Step 204:Create main frame message and receive chained list (user_to_kernel_queue) and main frame message transmission chained list (kernel_to_user_queue) so that corresponding with the reception of physical network card and transmit queue respectively, and by two messages Chained list is stored in the netdev of User space, as shown in Figure 3.
This step can in order to User space be searched according to the netdev for receiving message correspondence tapfd transmitting-receiving queue with Just message is received and dispatched.
Step 205:The message for needing kernel processes for receiving that external data end sends by physical network card.
In User space, the embodiment of the present invention receives the various messages of external data end transmission using physical network card, and bears Duty forwards the message for needing kernel processes.
Step 206:The netdev stored in the PKB form messages that User space is received by physical network card is finding The corresponding tapfd being stored in step 203.
Network data structure netdev in the message for being received can find in step 204 in User space and deposit The transmitting-receiving queue corresponding thereto for entering, it is corresponding with Microsoft Loopback Adapter tapfd.
Step 207:Add Microsoft Loopback Adapter packet sending and receiving function in User space, the message for receiving is joined the team the tap equipment User_to_kernel_queue, see Fig. 3.
The main frame message that the message of kernel processes is joined the team corresponding that needs for receiving is received into chained list, in order to follow-up Corresponding Microsoft Loopback Adapter is write in step and is sent to kernel.
Step 208:Chained list is received using polling mode traversal main frame message, when the corresponding main frame messages of certain tap are received Chained list is not space-time, then gone out team and write the tapfd of the Microsoft Loopback Adapter and hand at kernel by writing (write) function Reason, as shown in Figure 3.
In User space is needed in which can ensure that using polling mode at any time and do not omit to the write of corresponding Microsoft Loopback Adapter The message of core process.So far step, completes the process that whole message is received and is forwarded to kernel.
Step 209:Kernel processes Microsoft Loopback Adapter forwarding need its process message, after being disposed by message send to The tapfd of corresponding Microsoft Loopback Adapter, is shown in Fig. 3.
Kernel is received and after the message that is disposed, and needs to return again to User space, and this communication process is needed also exist for via interior The Microsoft Loopback Adapter of core is received as transfer and sent.
Step 210:The tapfd of all Microsoft Loopback Adapters is traveled through by polling mode in User space, by reading (read) letter Number reads message from Microsoft Loopback Adapter, as shown in Figure 3.
Now equally by the way of poll reading the tapfd of all Microsoft Loopback Adapters, it is ensured that at any time and do not omit Ground reads the message finished via kernel processes.
Step 211:Message is joined the team the corresponding kernel_to_user_queue of the tapfd, then goes out team by user The corresponding physical network card transmit queue of state Jing sends, and sees Fig. 3.
In order to ensure to collect the succession forwarding of message, need that first the message that kernel processes are finished is joined the team corresponding main frame Message sends chained list, sends finally by User space Jing physical network card transmit queues.
So far, then complete the message for finishing kernel processes and be forwarded back to User space and the overall process for sending once again.
More than that certain message for needing kernel processes is forwarded to into kernel from User space, be then disposed return again to The overall process of User space, so far then completes the whole flow process of User space and kernel communication.
In addition, it is necessary to explanation, above-mentioned all flow processs description based on Fig. 2, Fig. 3 is that User space of the present invention and kernel are logical One kind of the method for letter preferably realizes process, in the actual realization of User space of the present invention and the method for kernel communication, can be with Carry out random variation on the basis of flow process shown in Fig. 1 as needed, can select the arbitrary steps in Fig. 2, Fig. 3 to come real Existing, the sequencing of each step can also be adjusted as needed.Such as, in a kind of actual realization, in step 207 can be with Message is not joined the team but the write-in program of direct operation Microsoft Loopback Adapter;For another example, in the actual realization of another kind of the inventive method In, the process of poll can not be traveled through in execution step 208, but adopt other modes.
The system that a kind of User space and kernel communication are also proposed in one embodiment of the present of invention, referring to Fig. 4, the system Including:Physical network card registration equipment 401, Microsoft Loopback Adapter registration equipment 402, physical network card 403, user's space 404, Microsoft Loopback Adapter Interface module 405, Microsoft Loopback Adapter 406 and kernel spacing 407, wherein physical network card register equipment 401 and the phase of physical network card 403 Even, positioned at user's space 404, Microsoft Loopback Adapter registration equipment 402 is connected with Microsoft Loopback Adapter 406, positioned at kernel spacing 407, user It is connected by Microsoft Loopback Adapter interface module 405 between space 404 and kernel spacing 407;Wherein:
Physical network card registers equipment 401, for obtaining the network data structure of physical network card registration interface in user's space, And sent by Microsoft Loopback Adapter interface module to the Microsoft Loopback Adapter registration equipment of kernel spacing;
Microsoft Loopback Adapter registers equipment 401, for according to the network data structure of the physical network card registration interface for being obtained, Kernel spacing uses the name registration Microsoft Loopback Adapter interface of physical network card registration interface;
Physical network card 403, is received message and is forwarded by user's space for collecting the main frame for needing kernel spacing to process, The main frame that the Jing kernel spacings that transmission is received by user's space are disposed sends message;
User's space 404, for being needed what physical network card was received at kernel spacing by Microsoft Loopback Adapter interface module The main frame of reason receives message and sends to kernel spacing, and by Microsoft Loopback Adapter interface module the master that Jing kernel spacings are disposed is received Machine is sent message and is sent by physical network card;
Microsoft Loopback Adapter interface module 405, the main frame for kernel spacing will be needed to process receives message write Microsoft Loopback Adapter Send to kernel spacing, the main frame that Jing kernel spacings are disposed sends message and reads into user's space from Microsoft Loopback Adapter;
Microsoft Loopback Adapter 406, the main frame that kernel spacing is processed that needs for receiving the write of Microsoft Loopback Adapter interface module is received Message is simultaneously forwarded to kernel spacing, and the main frame that reception Jing kernel spacings are disposed sends message and by Microsoft Loopback Adapter interface mould Block reads and is forwarded to user's space;
Kernel spacing 407, the main frame that kernel spacing is processed that needs for receiving Microsoft Loopback Adapter transmission receives message, carries out Process, and the main frame being disposed transmission message is sent by Microsoft Loopback Adapter.
Also, it is in order to further determine that corresponding virtual network card equipment and right in the embodiment of present system The message collected and send plays a part of sequence buffer, it is preferable that as shown in figure 5, user's space 404 can also include:It is main Machine message chained list receiver module 501, for creating the main frame message corresponding with the receiving queue in physical network card chained list is received, The device file handle in packet network data structure is received according to the main frame that physical network card is received, corresponding virtual net is searched The main frame message of card receives chained list, and the main frame reception message main frame message of joining the team is received into chained list.
In another embodiment of the present invention, user's space 404 can also include:Main frame message chained list sending module 502, chained list is sent for creating the main frame message corresponding with the transmit queue in physical network card, by user's space from virtual net The main frame that the kernel processes read in card are completed sends message, main frame corresponding with the device file handle of the Microsoft Loopback Adapter of joining the team Message sends chained list, is resent to physical network card transmit queue.
In the practical application of the embodiment of the present invention, the report for needing Jing kernel processes is sent one by one in order to exhaustive ground Text, it is preferable that Microsoft Loopback Adapter interface module 405 can also include:Microsoft Loopback Adapter message writing module 503, for by poll The main frame message that mode is traveled through in the main frame message chained list receiver module receives chained list, the main frame is received into message and is gone out team and is write Enter corresponding Microsoft Loopback Adapter, until the main frame message receives chained list for empty stopping
In another embodiment of the present invention, the report that kernel processes are finished is collected one by one at any time in order to exhaustive ground Text, it is preferable that Microsoft Loopback Adapter interface module 405 can also include:Microsoft Loopback Adapter message read module 504, for by poll Mode travels through all Microsoft Loopback Adapters, directly the main frame is sent into message and reads and send to main frame message chained list sending module, until The content read from the Microsoft Loopback Adapter is empty stopping.
In another embodiment of the present invention, the process for sending message and collecting message does not conflict, so virtual net The operation of card message read module 504 and Microsoft Loopback Adapter message writing module 503 can be carried out independently.
In one embodiment of the invention, the quantity of physical network card and Microsoft Loopback Adapter according to actual interface and can hold What carrying capacity was determined, so Microsoft Loopback Adapter can include one or more Microsoft Loopback Adapters, the ethernet layer of kernel spacing is deployed in, And physical network card then correspondingly includes one or more physical network cards, as shown in Figure 6.
When processing for some main frame message traffics in order to perceive the state of actual physical network and network interface, need Corresponding interface physical state aware is carried out in kernel, it is preferable that the interface physical state of physical network card and respective name The interface physical state of Microsoft Loopback Adapter can be consistent.
It should be noted that the structure of User space shown in above-mentioned Fig. 4 to Fig. 6 and each embodiment of kernel communication can be with It is used in any combination.
It can be seen that, the embodiment of the present invention has the advantages that:
In method and system of the User space that the embodiment of the present invention is proposed with kernel communication, by the Physical Network of User space Data message is received in clamping, and the Microsoft Loopback Adapter of Jing kernels deployment realizes data interaction with kernel, without the need for kernel loads trawl performance Cause and interrupt and consume cpu performance, it is not required that the performance that data carry out loss system is copied from kernel state to User space;And due to The physical network card interface of User space and number, the title all same of kernel Microsoft Loopback Adapter interface, with one-to-one relation, can To meet the perception demand of User space, kernel for physical network interface state respectively, the operation of line interface binding can be entered, Solve the transfer problem of User space message format and kernel message format.The system for reducing User space and kernel information transmission Performance is lost, and has saved the time of information transfer, improves message transmissions and the efficiency for processing.
Finally it should be noted that:Above example only to illustrate technical scheme, rather than a limitation;Although The present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those within the art that:It still may be used To modify to the technical scheme described in foregoing embodiments, or equivalent is carried out to which part technical characteristic; And these modification or replace, do not make appropriate technical solution essence depart from various embodiments of the present invention technical scheme spirit and Scope.

Claims (8)

1. a kind of method of User space and kernel communication, it is characterised in that include:
The network data structure of physical network card registration interface is obtained in User space;
According to the network data structure of the physical network card registration interface for being obtained, in kernel the physical network card registration interface is used Name registration Microsoft Loopback Adapter interface;
Being collected using the physical network card of User space needs the main frame of kernel processes to receive message, and main frame reception message is passed through Corresponding Microsoft Loopback Adapter is sent to kernel;
The main frame that kernel processes are completed sends message and is sent to User space by corresponding Microsoft Loopback Adapter, and by the user State is sent to physical network card;
Wherein, the interface physical state of the Microsoft Loopback Adapter of the physical network card and respective name is consistent, including:With Family state scans the interface physical state of the physical network card and is issued to kernel, in the interface thing of Microsoft Loopback Adapter described in interior nuclear control Reason state is consistent with the interface physical state of the physical network card of respective name.
2. the method for User space according to claim 1 and kernel communication, it is characterised in that
It is described that main frame reception message is sent to kernel and further includes by corresponding Microsoft Loopback Adapter:
Main frame message is created in User space receive chained list, it is corresponding with the receiving queue in the physical network card, according to receiving The device file handle that receives in packet network data structure of main frame search corresponding Microsoft Loopback Adapter, the main frame is received and is reported Text is joined the team to the main frame message and receives chained list, remains subsequently to go out team by the main frame reception message write correspondence virtual net Card, is sent to kernel;
And/or,
The main frame transmission message that kernel processes are completed is sent to physical network card and further wraps by corresponding Microsoft Loopback Adapter Include:
Main frame message being created in User space and sending chained list, corresponding with the transmit queue in the physical network card, User space is from thing The corresponding Microsoft Loopback Adapter of device file handle in reason network card interface network data structure, the main frame that the kernel processes are completed Send message to read, join the team to the main frame message and send chained list, remain subsequently to go out team and sent by physical network card transmit queue Go out.
3. the method for User space according to claim 2 and kernel communication, it is characterised in that:
Join the team to main frame message reception chained list and described that main frame reception message write is described right described Before answering Microsoft Loopback Adapter, also include:The network data structure of all physics network card interfaces is traveled through using polling mode in User space The main frame message of maintenance receives chained list, makes message go out team's write Microsoft Loopback Adapter until the message chained list of corresponding certain Microsoft Loopback Adapter is It is empty;
And/or,
Create main frame message in User space and send after chained list and in the User space from physical network card interface network number described According to the corresponding Microsoft Loopback Adapter of device file handle in structure, the main frame that the kernel processes are completed sends message and reads it Before, also include:The device file handle of all Microsoft Loopback Adapters is traveled through using polling mode in User space, until certain device file The data that the corresponding Microsoft Loopback Adapter of handle reads are sky.
4. the method for User space according to claim 3 and kernel communication, it is characterised in that:
The operation that team is joined the team and gone out in receiving chained list and main frame message transmission chained list from the main frame message is independently entered OK.
5. the system of a kind of User space and kernel communication, it is characterised in that include:Physical network card registration equipment, Microsoft Loopback Adapter note Volume equipment, physical network card, user's space, Microsoft Loopback Adapter interface module, Microsoft Loopback Adapter and kernel spacing, wherein physical network card registration Equipment is connected with physical network card, and positioned at user's space, Microsoft Loopback Adapter registration equipment is connected with Microsoft Loopback Adapter, positioned at kernel spacing, It is connected by Microsoft Loopback Adapter interface module between user's space and kernel spacing;Wherein:
Physical network card registers equipment, for obtaining the network data structure of physical network card registration interface in user's space, and passes through Microsoft Loopback Adapter interface module sends to the Microsoft Loopback Adapter of kernel spacing and registers equipment;
Microsoft Loopback Adapter registers equipment, empty in kernel for according to the network data structure of the physical network card registration interface for being obtained Between using physical network card registration interface name registration Microsoft Loopback Adapter interface;
Physical network card, for collect need kernel spacing process main frame receive message and by user's space forward, send by The main frame that the Jing kernel spacings that user's space is received are disposed sends message;
User's space, for by Microsoft Loopback Adapter interface module by physical network card receive need kernel spacing process main frame Receive message to send to kernel spacing, the main frame transmission report that Jing kernel spacings are disposed is received by Microsoft Loopback Adapter interface module Text is simultaneously sent by physical network card;
Microsoft Loopback Adapter interface module, sends to interior for the main frame for needing kernel spacing to process to be received into message write Microsoft Loopback Adapter Nuclear space, the main frame that Jing kernel spacings are disposed sends message and reads into user's space from Microsoft Loopback Adapter;
Microsoft Loopback Adapter, the main frame that kernel spacing is processed that needs for receiving the write of Microsoft Loopback Adapter interface module receives message and turns Kernel spacing is dealt into, the main frame that reception Jing kernel spacings are disposed is sent message and read by Microsoft Loopback Adapter interface module and turned It is dealt into user's space;
Kernel spacing, the main frame that kernel spacing is processed that needs for receiving Microsoft Loopback Adapter transmission receives message, is processed, and The main frame being disposed transmission message is sent by Microsoft Loopback Adapter;
Wherein, the Microsoft Loopback Adapter is at least one, is deployed in the ethernet layer of kernel spacing, the physical network card quantity and institute State Microsoft Loopback Adapter quantity identical;
The interface physical state of each physical network card keeps with the interface physical state of the Microsoft Loopback Adapter of respective name Unanimously.
6. the system of User space according to claim 5 and kernel communication, it is characterised in that the user's space is also wrapped Include:
Main frame message chained list receiver module, for creating the main frame message reception chain corresponding with the receiving queue in physical network card Table, the device file handle in packet network data structure is received according to the main frame that physical network card is received, and is searched corresponding empty The main frame message for intending network interface card receives chained list, and the join the team main frame message of main frame reception message is received into chained list;
And/or,
Main frame message chained list sending module, for creating the main frame message send chain corresponding with the transmit queue in physical network card Table, the main frame that the kernel processes that user's space reads from Microsoft Loopback Adapter are completed sends message, joins the team and the Microsoft Loopback Adapter The corresponding main frame message of device file handle sends chained list, is resent to physical network card transmit queue.
7. the system of User space according to claim 6 and kernel communication, it is characterised in that the Microsoft Loopback Adapter interface mould Block also includes:
Microsoft Loopback Adapter message writing module, for traveling through the main frame in the main frame message chained list receiver module by polling mode Message receives chained list, the main frame is received into message and is gone out team and is write corresponding Microsoft Loopback Adapter, until the main frame message is received Chained list is empty stopping;
And/or,
Microsoft Loopback Adapter message read module, for traveling through all Microsoft Loopback Adapters by polling mode, directly sends message by the main frame Read and send to main frame message chained list sending module, until the content read from the Microsoft Loopback Adapter is empty stopping.
8. the system of User space according to claim 7 and kernel communication, it is characterised in that:The Microsoft Loopback Adapter message is read The operation of delivery block and the Microsoft Loopback Adapter message writing module is independently carried out.
CN201310389001.5A 2013-08-30 2013-08-30 Method and system for communication of user state and inner core Active CN103428226B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310389001.5A CN103428226B (en) 2013-08-30 2013-08-30 Method and system for communication of user state and inner core

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310389001.5A CN103428226B (en) 2013-08-30 2013-08-30 Method and system for communication of user state and inner core

Publications (2)

Publication Number Publication Date
CN103428226A CN103428226A (en) 2013-12-04
CN103428226B true CN103428226B (en) 2017-04-19

Family

ID=49652402

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310389001.5A Active CN103428226B (en) 2013-08-30 2013-08-30 Method and system for communication of user state and inner core

Country Status (1)

Country Link
CN (1) CN103428226B (en)

Families Citing this family (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103929418A (en) * 2014-03-28 2014-07-16 汉柏科技有限公司 Wireless Internet access method and system based on network safety equipment
CN105094995B (en) * 2014-05-19 2019-02-12 北京东土科技股份有限公司 Secure communication transmission method and system between a kind of kernel and User space process
CN104123194A (en) * 2014-07-16 2014-10-29 上海斐讯数据通信技术有限公司 Communication structure and method for kernel mode and user mode
CN106101012B (en) * 2016-07-06 2020-05-12 广州海格通信集团股份有限公司 Satellite IP gateway protocol adaptation method
CN108322326B (en) * 2017-06-27 2021-02-26 新华三技术有限公司 Interface state control method, message transmission method and device
CN109842585B (en) * 2017-11-27 2021-04-13 中国科学院沈阳自动化研究所 Network information safety protection unit and protection method for industrial embedded system
CN108306832B (en) * 2018-01-29 2021-07-27 北京启明星辰信息安全技术有限公司 Network traffic shunting method and device
CN109062542A (en) * 2018-03-15 2018-12-21 山东超越数控电子股份有限公司 A kind of method that domestic ten thousand Broadcom realizes network communication
CN109753368B (en) * 2018-12-20 2020-12-04 清华大学 Real-time data sending method and system
CN111147340A (en) * 2019-12-26 2020-05-12 山东超越数控电子股份有限公司 Method, equipment and medium for carrying out networked access on CAN bus interface
CN113301004B (en) * 2020-06-17 2023-05-09 阿里巴巴集团控股有限公司 Data processing method, device, communication method and single-network-card virtual machine
CN114567583A (en) * 2022-02-24 2022-05-31 北京卓越信通电子股份有限公司 Method for transmitting routing message from network card to routing module through kernel
CN114584541A (en) * 2022-03-07 2022-06-03 浪潮云信息技术股份公司 Method for accelerating virtual machine network
CN115002028B (en) * 2022-04-30 2024-02-13 济南浪潮数据技术有限公司 Message processing method, device and medium
CN117395329B (en) * 2023-12-13 2024-02-06 井芯微电子技术(天津)有限公司 Method, device and storage medium for receiving and transmitting Ethernet two-layer protocol message
CN117453299B (en) * 2023-12-25 2024-03-01 南京沁恒微电子股份有限公司 Application state network card driving method and device

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102932174A (en) * 2012-10-25 2013-02-13 华为技术有限公司 Method, device and physical host for managing physical network card

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101409714A (en) * 2008-11-18 2009-04-15 华南理工大学 Firewall system based on virtual machine
CN102497434B (en) * 2011-12-16 2014-11-05 中国科学院计算技术研究所 Establishing method of kernel state virtual network equipment and packet transmitting and receiving methods thereof

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102932174A (en) * 2012-10-25 2013-02-13 华为技术有限公司 Method, device and physical host for managing physical network card

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
虚拟网卡TUN/TAP驱动程序设计原理;麻利辉;《ChinaUnix.Net Linux时代》;20061124;第1-3页 *

Also Published As

Publication number Publication date
CN103428226A (en) 2013-12-04

Similar Documents

Publication Publication Date Title
CN103428226B (en) Method and system for communication of user state and inner core
CN103312601B (en) Data message processing method from user mode to kernel mode
TWI458314B (en) Server system and management method thereof for transferring remote packet to host
CN103902486B (en) System, device and method for implementation of remote direct memory access
CN105511954A (en) Method and device for message processing
CN103139157B (en) A kind of based on the network communication method of socket, Apparatus and system
WO2022032984A1 (en) Mqtt protocol simulation method and simulation device
JP5479709B2 (en) Server-processor hybrid system and method for processing data
WO2014135038A1 (en) Packet transmission method and device based on pcie bus
CN101179392A (en) Method and system for uploading document
CN103051716A (en) Method and system for redirecting network-oriented serial device
CN105190530A (en) Transmitting hardware-rendered graphical data
CN103368777A (en) Data packet processing board and processing method
CN104699654A (en) Interconnection adapting system and method based on CHI on-chip interaction bus and QPI inter-chip interaction bus
CN107454177A (en) The dynamic realizing method of network service
CN108419336B (en) LED light screen control system and implementation method thereof
US9203895B1 (en) System and method for lateral connection between interface devices with bypass of external network
CN103905484B (en) Handle the method and device of hypertext transfer protocol requests
TWI442248B (en) Processor-server hybrid system for processing data
US20140355445A1 (en) Link aggregation based on virtual interfaces of vlans
US20120041998A1 (en) Network Interface for Accelerating XML Processing
TW201251377A (en) NIC data transmission method and system
CN106059927B (en) A kind of automatic reconstructed network routing device of the limited cascade of hub-and-spoke configuration and its network
CN102129663B (en) Processing method for image with unaligned reading address and width and circuit structure
CN103248679A (en) Network message passing method

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
PP01 Preservation of patent right
PP01 Preservation of patent right

Effective date of registration: 20180528

Granted publication date: 20170419