Title of Invention

A METHOD FOR FORWARDING MESSAGES IN KERNEL SPACE AT THE RELAY SERVER

Abstract The present invention discloses a relay method, a relay server and a kernel managing module. The relay method comprises: receiving by a relay server a message sent from a source end via a first data channel: judging by the relay server whether a mapping relation between the first and a second data channel has been established in the kernel space, wherein the second data channel is between the relay server and a target end; forwarding by the relay server the message in the kernel space via the second data channel if the mapping relation between the first and second data channel has been established. By adopting the present invention, it is applicable to forward messages in the kernel space, avoid copying messages from the kernel space to the user space in prior art, and execute such operation as switch between the user state and the kernel state, thereby increasing the relaying efficiency of the Relay server.
Full Text Relay Method, Relay server and Kernel Managing Module
Field of the Invention
The present invention relates to Internet technology field, especially to a relay method, a relay server and a kernel managing module.
Background of the Invention
With the rapid development of Internet application, the problem of shortage of public Internet addresses based on Internet Protocol version 4 (IPV4) is becoming very protruding, and thus the Network Address Translators (NAT) technology comes into being, which makes multiple computers in a local area network access the Internet by sharing the same public IP (Internet Protocol) address. But an accompanying problem is that, NAT hides the information of real nodes in the local area network, which makes it unable to communicate between the real nodes inside the local area network and nodes outside the local area network and then heavily limits such network applications as Instant Messaging (IM), Point-to-Point (P2P) and interactive stream media.
In order to solve the problem. Traversal Using Relay NAT (TURN) emerges as the times require. TURN technique make the nodes hided behind NAT communicate with a relay server that has a public IP, and then the relay server forwards the network data, thus NAT is successfully traversed.
At present, TURN technique based on application layer forwarding is already pretty mature. Figure 1 is a flowchart illustrating the implementation of relay in prior art. In the example illustrated in figure 1, Transmission Control Protocol (TCP) is used, and node x (End Point x) having been proces.sed by NAT, which is shortened as EPx, is set as the source end, and application service y is set as the target end whose structure is shown in figure 2. As shown in figure 1, the procedure of relay in prior art comprises the following steps:
At step 101, establish data channel x.
The data channel x is the data channel corresponding to the TCP connection between the EPx and the relay server. In addition, while the data channel x is being

eslablished, relay server may perform necessary access authenlication upon EPx.
When EPx needs to relay dala to the application service y, step 102 will be executed.
Al step 102, EPx direclly send a message to (he relay seiver via the dala channel x.
Al step 103, the relay server, after receiving (he message, analyzes the header of the message.
The relay server analyzes the header of this message, and can got tlie IP address of the application service y and the information of the port through which the application service y receives this message.
Al step 104, according to the IP address of the application service y and the information of the port through which the application service y receives this message, the relay server establishes the data channel y corresponding to the TCP connection between the relay server and the application service y.
Further, the mapping relation between the data channel y and the data channel x needs to be established the after data channel y is established, and then step 105 is executed.
At step 105, the relay server forwards the message via the data channel y.
In addition, when the application service y needs to respond to the message, the application service y sends a response message via the data channel y. After the relay server receives the response message at application layer, according to the mapping relation between the data channel y and the data channel x, it directly forwards the response message via the data channel x.
In addition, when EPx wants to terminate relaying messages, EPx will shut down data channel x directly, so the current data relay is ended.
It can be seen from the above that, in prior art, the information interaction between EPx and application service y is implemented by the relay server through forwarding messages at application layer. However, as shown in figure 2, in prior art, while the relay server forwards the messages at application layer, it is unavoidable to copy the messages from the kernel space to the user space, and to perform the switch between the user state and the kernel state. In this way, computing resources will be greatly wasted, which decreases the relaying efficiency of the relay server.

Summary of the Invention
The present invention discloses a relay method, a relay server and a kernel managing module to increase the relaying efficiency of the relay server.
A relay method provided by an embodiment of the present invention comprises:
receiving, by a relay server, a message sent from a source end via a first data channel;
judging, by the relay server, whether a mapping relation between the first data channel and a second data channel has been established in the kernel space, wherein the second data channel is between the relay server and a target end;
forwarding, by the relay server, the message in the kernel space via (he second data channel if the mapping relation between the first data channel and the second data channel has been established.
Wherein the method further comprises:
establishing, in the kernel space, the mapping relationship between the first data channel and the .second data channel in the kernel space if Judging that there is no mapping relationship between the first data channel and the second data channel.
Wherein the relay server, through the kernel control primitive, instructs the kernel of the relay server to establish the mapping relationship between the first data channel and the second data channel.
Wherein the forwarding the message in the kernel space via the second data channel comprises:
taking IP address information of the relay server as source address information of the message in the kernel space;
taking IP address information of the target end as target address information of the message in the kernel space;
forwarding the message whose source and target address information are modified to the target end via the second data channel in the kernel space.
Wherein the method further comprises:
receiving, by the relay server, a response message sent from the target end via the

second data channel;
judging, by the relay server, whether the mapping relation between the first data channel and the second data channel has been established in the kernel space;
forwarding, by the relay server, the response message in the kernel space via the first data channel if the mapping relation between the first data channel and the second data channel has been established. .
Wherein the forwarding the response message in the kernel space via the first data channel comprises:
taking IP address information of the relay server as source address information of the response message in the kernel space;
taking IP address information of the source end as target address information of the response message in the kernel space;
forwarding the response message whose source and target address information are modified to the source end via the first data channel in the kernel space.
Wherein the method further comprises when the source end needs to terminate forwarding messages:
sending, by the source end, a session terminate request to the relay server;
removing, by the relay server, the mapping relation between the first data channel and the second data channel in the kernel space upon receiving the session terminate request;
closing, by the relay server, the first data channel and Ihc second data channel respectively.
A relay server provided by an embodiment of the present invention comprises an application managing module and a kernel managing module; wherein:
the application managing module is adapted to manage a first data channel between a source end and the relay server and a second data channel between the relay server and a target end, and to trigger the kernel managing module to establish a mapping relation between the first data channel and the second data channel;
the kernel managing module is adapted to establish the mapping relation between the first data channel and the second data channel in the kernel space when triggered by the application managing module, and to judge whether the mapping relation between the

first data channel and the second data channel has been established when receiving a message, and if so, forward the message in the kernel space.
Wherein the server further comprises:
a request receiving module, adapted to receive a session terminate request sent by the source end which needs to terminate forwarding messages and send a termination notification to the kernel managing module;
wherein the kernel managing module removes the mapping relation between the first data channel and the second data channel in the kernel space after receiving the termination notification and close the first data channel and second data channel respectively.
A kernel managing module provided by an embodiment of the present invention comprises:
a mapping establishing unit, adapted to establish a mapping relation between a first data channel and a second data channel in the kernel space, wherein the first data channel is the data channel between a source end and a relay server, and the second data channel is the data channel between the relay server and a target end;
a judging unit, adapted to judge whether the mapping establishing unit has established the mapping relation between the first data channel and the second data channel in the kernel space upon receiving the message, and if so, send a forward notification;
a sending unit, adapted to forward the message in the kernel space upon receiving the forward notification.
Wherein the sending unit comprises:
a modifying subunit, adapted to take IP address information of the relay server as source address information of the message in the kernel space and take IP address information of the target end as target address information of the message in the kernel space;
a sending subunit, adapted to forward the message whose source and target address information are modified to the target end in the kernel space via the second data channel.
Wherein the module further comprises:

a removing unit, adapted to remove the mapping relation helwcen (he first data channel and the second data channel in the kernel space when the source end wants to lerminale forwarding iriessages and close the first dala channel and the second data channel respectively.
It can be seen from the above embodiments (hat, after the kernel managing module receives a message, if it is confirmed thai the mapping relation between the first data channel and the second data channel has been established, (he kernel managing module directly forward the message in the kernel space, so as lo avoid such operation as copying messages from the kernel space to the user space in prior art, as well as lo execute the switch operation between the user state and the kernel slate, so as to save a large amount of computing resources, and thus increase the relaying efficiency of the relay server.
Brief description of the drawings
Figure I is a flowchart illustrating the procedure for implementing relay in prior art.
Figure 2 is a diagram illustrating the structure of implementing relay in prior art.
Figure 3 is a flowchart illustrating the relay method in an embodiment of the present invention.
Figure 4 is a diagram illustrating the structure of the relay server in an embodiment of the present invention.
Figure 5 is a diagram illustrating the structure of the kernel managing module in an embodiment of the present invention.
Detailed description of the invention
In consideration of the prior art that the relay server forwarding messages at application layer will lead to the switch between the user state and the kernel state and then it is unavoidable to copy messages from the kernel space to the user space, an embodiment of the present invention provides a relay method that can solve various problems in prior art. The specific implementation comprises: while receiving the message, a kernel managing module in a relay server judges whether the mapping relation between a first data channel and a second data channel has been established, and if so, forwards the message in the kernel space. In this way, direct message forwarding in

kernel space is implemented, and thus the relaying efficiency of the relay server is increased.
The first data channel is the data channel between the source end and the relay server: the second data channel is the data channel between the relay server and the target end.
In addition, the kernel managing module forwards the message in the kernel space, so that it is guaranteed that relay server only controls and manages the data channels on the application layer, without the need to perform such actions on the application layer in prior art as copying the message from the kernel space to the user space as well as switching between the user state and the kernel state, so as to effectively release resources oi' the relay server on the application layer, and direct message forwarding in the kernel space is implemented, and thus increase the relaying efficiency of the relay server.
The present invention will be further described in detail hereinafter with reference to the drawings and embodiments.
Figure 3 is a flowchart illustrating the relay method in an embodiment of the present invention. In this embodiment, assuming that the source end and relay server are connected via a TCP connection while the target end and relay server are connected via a TCP connection, as shown in figure 3, when the kernel managing module receives the message, the procedure may comprise the following steps:
At step 301, the kernel managing module Judges whether the mapping relation between the first data channel and the second data channel is already established, and if yes, step 302 will be executed; otherwise, step 303 will be executed.
In this embodiment, before step 301 is executed, the following steps are usually comprised:
At Al, establish the data channel corresponding to the TCP connection between the source end and the relay server.
Here, the data channel conesponding to the TCP connection between the source end and the relay server is the first data channel. In addition, in this embodiment, while establishing the first data channel, the relay server may perform necessary access authentication upon the source end, and the specific access authentication method is similar to that of the prior art, and is not to be illustrated hereby.

At A2, establish the data channel corresponding to the TCP connection between the relay server and the target end.
Here, the data channel conesponding to the TCP connection between the relay server and the target end is the second data channel.
In addition, the mapping relation between the first data channel and the second data channel is established by the kernel managing module upon the trigger of the kernel control primitive sent by the relay server through the application layer. Preferably, while establishing the mapping relation between the first data channel and the second data channel, the kernel managing module maintains the information of IP addresses corresponding to the source end and target end respectively.
In this embodiment, the source end may be a node having been processed by NAT, and accordingly, the target end is the application service end. Therefore, in practical application, before executing Al, the step of establishing a first signaling channel corresponding to the TCP connection between the source end and relay server may be established. In addition, while establishing the first signaling channel, the relay server in this embodiment can perform necessary access authentication upon the source end, and the specific access authentication method is similar to that in the prior art, and thus is not illustrated hereby. Then AI is executed. Preferably, after the first data channel is established, the first channel identifier X con'esponding to the first data channel, the IP address information oi' the target end to which the message is to be forwarded as well as the port through which the target end will receive the message are all sent to the relay server through the first signaling channel; and the relay server can establish the mapping relation between the first data channel and the second data channel according to the first channel identifier X, so that the first data channel can transfer the message according to the control signaling sent by the first signaling channel.
In this way, in the step A2, the second data channel corresponding to the TCP connection between the relay server and the target end may be established according to the IP address information of the target end as well as Ihe port through which the target end receives the message.
Besides, in this embodiment, both the source end and target end may be nodes having been processed by NAT. In such a case, before the first data channel is established

in step Al, the following steps are usually comprised;
At step All, establish the first signaling channel corresponding to the TCP connection between the source end and the relay server.
Here, before the first signaling channel is established, Ihe relay server in this embodiment can perform necessary access authentication upon the source end, and the specific access authentication method is similar in the prior art, thus is not to be illustrated hereby.
At step A12, e,stablish the second signaling channel corresponding to the TCP connection between the relay server and the target end.
Here, when the second signaling channel is established, the relay server in this embodiment can perform necessary access authentication upon the source end, and the specific access authentication method is similar to that in the prior art, thus is not to be illustrated hereby.
After that, the step Al is executed and, after the first data channel is established, the first channel identifier X and the identity information of the target end are sent to the relay server through the first signaling channel, the relay server establishes the mapping relation between the first signaling channel and itself according to the first channel identifier X, finds out the second signaling channel corresponding to the target end according to the identity information of the target end, and notifies the target end of a communication request through the second signaling channel. In this way, in the above step A2, after the target end has received the communication request, the second data channel corresponding to the TCP connection between the target end and the relay server is established.
In addition, in order to make the present invention applicable, after the step A2 in embodiment of the present invention, the second channel identifier Y corresponding to the second data channel is also fed back to the source end. After that, for the convenience of establishing the mapping relation between the second data channel and the second signaling channel, the target end further needs to send the .second channel identifier Y coiTesponding to the second data channel to the relay server, and according to the second channel identifier Y, the relay server establishes the mapping relation between the second data channel and the .second signaling channel so that the sub.scquent operations can be
10

executed.
Al step 302, the kernel managing module forwards Ihc message in the kernel space.
In (his embodiment, when the message is sent by (lie source end through (he first data channel, the step 302 may comprise:
Al step B 1, the kernel managing module lakes Ihc IP address information of the relay server as the source address information of the message.
Since the message is .sent by ihe source end through the first data channel, the source address information of the message was obviously (he IP address information of the source end. after the step Bl is executed in this embodiment, Ihe target end can make sure the message is from the relay .server. Since the message is sent by the source end through the first data channel and needs lo be forwarded by the relay server, the target address information of the message was the IP address information of the relay server before the step B2 is executed.
At step B2, the kernel managing module takes the IP address information of the target end as the target IP address information of the message.
Here, the kernel managing module, according to the IP address information maintained by itself, directly takes the IP address information of the target end as the target IP address information of the message.
At step B3, the kernel managing module forwards the modified message to the target end through the second data channel in the kernel space.
It can be seen that, through the above-mentioned method, it is implemented to forward messages in kernel space, without the operation of copying the message in the u.ser space and the kernel space in prior art, thereby avoiding the switch between the user state and the kernel state, .saving computing resources and increasing the relaying efficiency of the relay server.
At step 303, forward the message by the relay server.
In addition, in this embodiment, when the target end responds to the message forwarded by the relay server, or when the target end sends the message to be forwarded, it is applicable to forward the message in the kernel space by a means similar to the forwarding operation mentioned above, which is not be illustrated hereby.

Moreover, in this embodiment, when the source end needs to terminate relaying messages, the step 304 will be executed.
At step 304, the source end sends a session terminate request to the relay server through the first signaling channel.
At step 305, after receiving the session terminate request, the relay server instructs the kernel managing module to remove the mapping relation between the first data channel and the second data channel; and closes the said first data channel and second data channel respectively.
Specifically, after receiving the session terminate request, the relay server instructs the kernel managing module through the kernel control primitive to lemove the mapping relation between the first data channel and the second data channel. So far, the action of the source end terminating relaying message is finished.
In an embodiment of the present invention provides a kind of relay server corresponding to the relay method mentioned above. Figure 4 is a diagram illustrating the structure of the relay server in an embodiment of the present invention. This diagram is merely an example, which should not unduly limit the scope of the claims. One of ordinary skill in the art would recognize many variations, alternatives, and modifications. As shown in figure 4, the relay .server comprises: the application managing module 401 and the kernel managing module 402.
Here, the application managing module 401 is u.sed to manage the first data channel between the source end and the relay server as well as the second data channel between the relay server and the target end, and to trigger the kernel managing module 402 to establish the mapping relation between the first data channel and the second data channel.
The kernel managing module 402 is used to establish the mapping relation between the first data channel and the second data channel upon the trigger of the application managing module 401, and to judge if the mapping relation between the first data channel and the second data channel is already established when receiving the message, and if so, forward the message in the kernel space.
In addition, the relay .server may comprises: the request receiving module 403.
Here, the request receiving module 403 is used to, when the source end needs to
12

terminate forwarding messages, receive the session terminate request sent by the source end, and send a termination notification to the kernel managing module 402.
The kernel managing module 402 is used to remove the mapping relation between the first data channel and the second data channel which have been established after receiving the termination notification, and to close the first data channel and second data channel respectively.
In practical application, the kernel managing module may have more than one kind of structures, and figure 5 shows one structure of the kernel managing module. As shown in figure 5, the kernel managing module comprises: the mapping establishing unit 501, the judging unit 502 and the sending unit 503.
Here, the mapping establishing unit 501 is used to establish the mapping relation between the first data channel and the second data channel. The first data channel is the data channel between the source end and the relay server, while the second data channel is the data channel between the relay server and the target end.
The judging unit 502 is used to, when receiving the message, judge whether the mapping establishing unit 501 has established the mapping relation between the first data channel and the second data channel, and if so, send forward notification to the sending unit 503.
The sending unit 503 is used to forward the message in the kernel space after receiving the forward notification,
In addition, the .sending unit 503 may comprise the modifying subunit 5031 and the sending subunit 5032.
Here, the modifying subunit 5031 is used to, when (he message is sent by the source end through the first data channel, take the IP address information of the relay server as the source address information of the message, and take the IP address information of the target end as the target IP address information of the message.
The sending subunit 5032 is used to forward the modified message to the target end in the kernel space through the second data channel.
Besides, the kernel managing module may also comprise the removing unit 504.
Here, the removing unit 504 is used to, when the source end wants to terminate
13

forwarding messages, remove the mapping relation between the i'irst data channel and the second data channel which has been established, and close the first data channel and the second data channel respectively.
In the embodiment of the present invention, specific operations performed by units inside the kernel managing module can be the same as thai described by the method shown in figure 3. Each unit can be either a physical functional unit or a software functional unit, and each unit can be further divided or a plurality of units can be combined together. For specific implementation, those skilled in this field may refer to practical conditions, which is not to be illustrated here.
As can be seen that, in the embodiment of the present invention, when the kernel managing module receives the message, if the kernel managing module confirms that the mapping relation between the first data channel and the second data channel has been established, it will forward the message in the kernel space, so that the message can be forwarded in the kernel space, which avoids to copy messages from the kernel space to the user space as made in prior art and also avoids switch between the user state and the kernel state. Therefore, a large amount of computing resources can be saved, and further the relaying efficiency of the relay server is increased.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features di.sclosed herein.


We claim:
1. A relay method, comprising:
receiving, by a relay server, a message sent from a source end via a first data channel;
judging, by the relay server, whether a mapping relation belween the first data channel and a second data channel has been established in (he kernel space, wherein the second data channel is belween the relay server and a target end;
forwarding, by the relay server, the message in the kernel space via the second data channel if the mapping relation between the first dala channel and Ihe second data channel has been established.
2. The method of claim 1, further comprising:
establishing, in the kernel space, the mapping relationship between the first data channel and the second data channel in the kernel space if judging that there is no mapping relationship between the first data channel and the second data channel,
3. The method of claim 2, wherein the relay server, through the kernel control primitive, instructs the kernel of the relay server to establish the mapping relationship between the first data channel and the second data channel.
4. The method of claim 1 or 2, wherein the forwarding the message in the kernel space via the second data channel comprises:
taking IP address information of the relay server as source address information of the message in the kernel space;
taking IP address information of the target end as target address information of the message in the kernel space;
forwarding the message whose source and target address information are modified to the target end via the second data channel in the kernel space.
5. The method of claim 1, further comprising:
receiving, by the relay server, a response message sent from the target end via the second data channel;
judging, by the relay server, whether the mapping relation between the first data
i(?

channel and the second data channel has been established in the kernel space;
forwarding, by the relay server, the response message in the kernel space via the first data channel if the mapping relation between the first data channel and the second data channel has been established. .
6. The method of claim 4, wherein the forwarding the response message in the kernel
space via the first data channel comprises:
taking IP address information of the relay server as source address information of the response message in the kernel space;
taking IP address information of the source end as target address information of the response message in the kernel space;
forwarding the response message whose source and target address information are modified to the source end via the first data channel in the kernel space.
7. The method of claim 1, further comprising when the source end needs to tcrininate
forwarding messages:
sending, by the source end, a session terminate request lo the relay server;
removing, by the relay server, the mapping relation between the first data channel and the second data channel in (he kernel space upon receiving the session terminate re(|uest;
closing, by the relay server, the first data channel and the second data channel respectively.
8. A relay server, comprising an application managing module and a kernel managing
module; wherein:
the application managing module is adapted to manage a first data channel between a source end and the relay server and a second data channel between the relay server and a target end, and to trigger the kernel managing module to establish a mapping relation between the first data channel and the second data channel;
the kernel managing module is adapted to establish the mapping relation between the first data channel and the second data channel in the kernel space when triggered by the application managing module, and to judge whether the mapping relation between the first data channel and the second data channel has been established when receiving a message, and if so, forward the message in the kernel space.
16

r
j
9. The server of claim 8, further comprising:
a request receiving module, adapted to receive a session terminate request sent by the source end which needs to terminate forwarding messages and send a termination notification to the kernel managing module;
wherein the kernel managing module removes the mapping relation between the first data channel and the second data channel in the kernel space after receiving the termination notification and close the first data channel and second data channel respectively.
10. A kernel managing module, comprising:
a mapping establishing unit, adapted to establish a mapping relation between a first data channel and a second data channel in the kernel space, wherein the first data channel is the data channel between a source end and a relay server, and the second data channel is the data channel between the relay server and a target end;
a judging unit, adapted to judge whether the mapping establishing unit has established the mapping relation between the first data channel and the second data channel in the kernel space upon receiving the message, and if so, send a forward notification;
a sending unit, adapted to forward the message in the kernel space upon receiving the forward notification.
11. The module of claim 10, wherein the sending unit comprises:
a modifying subunit, adapted to take IP address information of the relay server as source address information of the message in the kernel space and take IP address information of the target end as target address information of the message in the kernel space;
a sending subunit, adapted to forward the message whose source and target address information are modified to the target end in the kernel space via tlie second data channel.
12. The module of claim 10, further comprising:
a removing unit, adapted to remove the mapping relation between the first data channel and the second data channel in the kernel space when the source end wants to terminate forwarding messages and close the first data channel and the second data channel respectively.


Documents:

http://ipindiaonline.gov.in/patentsearch/GrantedSearch/viewdoc.aspx?id=noC3DZraRSZg+4nrYAZ89g==&loc=egcICQiyoj82NGgGrC5ChA==


Patent Number 278363
Indian Patent Application Number 825/CHE/2009
PG Journal Number 53/2016
Publication Date 23-Dec-2016
Grant Date 21-Dec-2016
Date of Filing 08-Apr-2009
Name of Patentee TENCENT TECHNOLOGY (SHENZHEN ) COMPANY LIMITED
Applicant Address 4/F, EAST 2 BLOCK, SEG PARK, ZHENXING ROAD, FUTIAN DISTRICT, SHENZHEN, GUANGDONG 518044
Inventors:
# Inventor's Name Inventor's Address
1 FAN, HUAHENG, 4/F, EAST 2 BLOCK, SEG PARK, ZHENXING ROAD, FUTIAN DISTRICT, SHENZHEN, GUANGDONG 518044
PCT International Classification Number H04L 12/56
PCT International Application Number N/A
PCT International Filing date
PCT Conventions:
# PCT Application Number Date of Convention Priority Country
1 200810089936.0 2008-04-09 China