Embodiment
For the purpose, technical scheme and the advantage that make the embodiment of the invention clearer, below in conjunction with the accompanying drawing in the embodiment of the invention, technical scheme in the embodiment of the invention is clearly and completely described, obviously, described embodiment is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, those of ordinary skills belong to the scope of protection of the invention not making the every other embodiment that obtains under the creative work prerequisite.
Fig. 1 is the flow chart of flow processing method embodiment one of the present invention, and as shown in Figure 1, the present embodiment provides a kind of flow processing method, can specifically comprise the steps:
Step 101 is obtained all inflows in the portable terminal and is flowed out corresponding application identities and the data packet length of packet of protocol stack by the Hook Function of setting up in the kernel spacing.
The present embodiment is specially processing based on each flow of using in the portable terminal of linux system, sets up a Hook Function in IP stack, under the netfilter of this Hook Function carry in the linux kernel space.Particularly, the portable terminal of indication specifically refers to mobile phone or has the smart mobile phone of multiple application function in the present embodiment.In linux system; kernel spacing is any event that occurs in linux kernel inside; a part of kernel software of system is independent of common applications; reside on the protected memory headroom; all authorities that have access hardware devices, and user's space is relative with kernel spacing refer to outside at linux kernel or occur in any event of linux kernel outside; application program operates on the user's space, and it is access kernel space and hardware device directly.Netfilter is the cover fire compartment wall framework that Linux makes up in kernel spacing, and it can be used for extracting the packet of kernel spacing, and with the information guidance that extracts in other spaces.Be illustrated in figure 2 as the configuration diagram of netfilter among the flow processing method embodiment one of the present invention, the working point of netfilter framework on linux kernel IPv4 protocol stack comprises INPUT, OUTPUT, FORWARD, PRE_ROUTING and POST_ROUTING.Wherein, send to the data packet stream of the machine through PRE_ROUTING and INPUT, the data packet stream that is sent by the machine is through OUTPUT and POST_ROUTING, and the data packet stream of being transmitted by the machine is through PRE_ROUTING and POST_ROUTING.IPtables is that the Linux fire compartment wall is in the hypervisor of user's space.
This step is from INPUT and two working points of OUTPUT, the framework that provides based on netfilter, expand a Hook Function that is embedded in the protocol stack, for example, can be specifically form by following code realize the carry that newly-increased Hook Function is ordered at the NF_IP_PRE_ROUTING of netfilter framework in the kernel spacing in the present embodiment:
Static?struct?nf_hook_ops?imp2_ops={
.hook=get_count,
.hooknum=NF_IP_PRE_ROUTING,
};
The present embodiment is followed the tracks of processing by this Hook Function to the packet of all inflows in the portable terminal and outflow protocol stack, can specifically be configured by the circulation rule to packet on IPtables, so that the packet of all inflows and outflow protocol stack is all processed through this Hook Function.For example, can be as follows with the circulation rule configuration: iptables-t COUNTER-A OUTPUT and iptables-tCOUNTER-A INPUT, wherein, COUNTER be Hook Function.This step is by carrying out Function Extension to netfilter, in protocol stack, set up a Hook Function, come to follow the tracks of and record in the packet of linux kernel circulating in the portable terminal, from the packet that gets access to, extract its corresponding application identities UID and process identification (PID) PID, and the data packet length of each packet.Because UID respectively uses corresponding unique identification in the linux system, then Hook Function can be distinguished according to the UID that extracts the packet of different application from different packets.
Step 102, application identities and data packet length that described packet is corresponding send to user's space.
In kernel spacing, get access to the packet that flows into and flow out protocol stack by Hook Function, and after packet analysis got access to its corresponding UID and data packet length, UID and data packet length that this packet is corresponding sent to user's space by kernel spacing.Can specifically send to user's space by netlink UID and data packet length that packet is corresponding, wherein, netlink is the distinctive communication mechanism based on socket (socket) DLL (dynamic link library) of linux system.
Step 103, each is used the flow that produces and adds up in to described portable terminal at the described user's space application identities corresponding according to described packet and data packet length.
After the UID that each packet is corresponding and data packet length send to user's space, in user's space, can carry out the book of final entry to it according to each packet corresponding UID and data packet length.In the database of user's space, preserved the respectively total length of data packets of correspondence of paid-in types of applications, when the new packet information that at every turn receives from kernel spacing, the data packet length that identical UID is corresponding is added on the data with existing packet length of this UID in the database, because different UID represent respectively the different application in the portable terminal, then can realize the statistics to the corresponding data packet length of different application, and then realize the flow that different on-line modules in the portable terminal produce is added up.
As from the foregoing, the present embodiment is expanded by the framework to netfilter, in protocol stack, set up Hook Function, realize each network traffics that have the application of network resource request to produce in the portable terminal are added up, for the user provides the most detailed data traffic data.The flow processing method that the present embodiment provides is in conjunction with the realization of upper layer application, can also show the flow details for the user from many aspects, as reflecting each flow situation that is applied in each time period in conjunction with practice, can also reflect in conjunction with the tariff information of the operator flow rate to each application; The flow analysis data that can also provide each to use are for the exploitation of each application and the performance design of system provide service.
The present embodiment provides a kind of flow processing method, obtain all inflows in the portable terminal and flow out corresponding UID and the data packet length of packet of protocol stack by the Hook Function of setting up in the kernel spacing, and the UID that packet is corresponding and data packet length send to user's space by kernel spacing, in user's space according to UID corresponding to packet and data packet length to each is used the flow that produces and adds up in the portable terminal; The present embodiment has been realized the flow that the portable terminal based on (SuSE) Linux OS produces is added up, and can provide comprehensive, detailed data on flows for the user, has strengthened initiative and the flexibility of user to the control of each on-line module in the portable terminal.
Fig. 3 is the flow chart of flow processing method embodiment two of the present invention, and as shown in Figure 3, the present embodiment provides a kind of flow processing method, and the present embodiment can comprise the steps:
Step 301 is obtained all inflows in the portable terminal and is flowed out corresponding application identities and the data packet length of packet of protocol stack by the Hook Function of setting up in the kernel spacing, and this step can be similar with above-mentioned steps 101, repeats no more herein.
Step 302, application identities and data packet length that described packet is corresponding send to user's space, and this step can be similar with above-mentioned steps 102, repeats no more herein.
Step 303, each is used the flow that produces and adds up in to described portable terminal at the described user's space application identities corresponding according to described packet and data packet length, and this step can be similar with above-mentioned steps 103, repeats no more herein.
Step 304, kernel spacing receives the application identities from control information and the application to be controlled of described user's space.
By the Hook Function set up to portable terminal in all inflows and the packet that flows out protocol stack follow the tracks of and record, and at user's space each is used after flow that online produces adds up in to portable terminal according to the application identities of the packet that obtains and data packet length, the user can also control the internet behavior that the user use each to use in the present embodiment.The user can send to kernel spacing with the UID of application to be controlled and concrete control information by user's space according to the actual operating position of portable terminal.Kernel spacing receives from the corresponding control information of user's space and the UID of application to be controlled, wherein, and the application that the user of being applied as to be controlled need to control its internet behavior.
Step 305 uses the internet behavior of described application to control according to the application identities of described control information and application to be controlled to the user by described Hook Function.
After kernel spacing receives the UID of control information that user's space sends and application to be controlled, can be controlled the packet under this application by the UID of the Hook Function in the kernel spacing according to this control information and application to be controlled, namely realize using the internet behavior of each application to control to the user.
Particularly, the control information that user's space sends in the step 304 is for forbidding or when allowing the user to use certain application access network, step 305 can specifically comprise: all abandoned or reservation process according to the described control information packet that described application identities is corresponding by described Hook Function, to forbid or to allow the user to use described application online.The present embodiment describes as an example of the cell phone system of Android example, and in this cell phone system, different application is to there being different UID.When the user need to forbid certain application access network, the user was by consisting of the UID of corresponding control information and this application in user's space, and the control information of this moment is used this application access network for forbidding the user.Kernel spacing is after receiving this control information and UID, and the Hook Function in the kernel spacing carries out whole discard processing according to this control information packet that this UID is corresponding, to realize forbidding that the user uses the function of this application online.Because the Hook Function in the kernel spacing all filters the packet of all inflows and outflow protocol stack, then the present embodiment carries out discard processing by this Hook Function with the packet of using, and just the user can be used the function of this application access network forbid.Similarly, when the user need to allow certain forbidden application again during accesses network, the user is by consisting of the UID of corresponding control information and this application in user's space, and the control information of this moment is for allowing the user to use this application access network.Kernel spacing is after receiving this control information and UID, Hook Function in the kernel spacing carries out whole reservation process according to this control information packet that this UID is corresponding, namely no longer abandon packet corresponding to this UID, to realize the allowing user to use the function of this application online, no longer its internet behavior is controlled.
Further, the step 304 in the present embodiment can be specially: when judging that default restrictive condition reaches the restrictive condition threshold value in described user's space, kernel spacing receives the application identities from control information and the application to be controlled of described user's space.Be that the user can come to use the internet behavior of application to control to the user according to some default restrictive condition, restrictive condition herein can be specially signal strength signal intensity, the portable terminal of portable terminal battery electric quantity, use the corresponding surf time, use in the corresponding surfing flow.When restrictive condition was the signal strength signal intensity of portable terminal, the user can arrange according to the actual conditions of the portable terminal signal strength signal intensity to portable terminal, and a signal strength signal intensity higher limit and a signal strength signal intensity lower limit can be set.When the signal strength signal intensity of portable terminal is lower than this signal strength signal intensity lower limit, send the UID of corresponding control information and application to be controlled to kernel spacing, control information this moment also can be used this application access network for forbidding the user, then step 305 is specially: according to this control information packet corresponding to this UID carried out whole discard processing by the Hook Function in the kernel spacing, realization uses the online ability of this application to control to the user, and namely limited subscriber uses this application that network is conducted interviews when the signal strength signal intensity of portable terminal is hanged down.When the signal strength signal intensity of portable terminal is higher than this signal strength signal intensity higher limit, send the UID of corresponding control information and application to be controlled to kernel spacing, control information this moment also can be used this application access network for allowing the user, then step 305 is specially: according to this control information packet corresponding to this UID carried out reservation process by the Hook Function in the kernel spacing, to allow the user to use this application access network, namely when the signal strength signal intensity of portable terminal is higher, allow the user to use to use network is conducted interviews.When restrictive condition was the battery electric quantity of portable terminal, the user also can arrange according to the actual conditions of the portable terminal battery electric quantity to portable terminal, and a battery electric quantity higher limit and a battery electric quantity lower limit can be set.When the battery electric quantity of portable terminal is lower than this battery electric quantity lower limit, send the UID of corresponding control information and application to be controlled to kernel spacing, control information this moment also can be for forbidding this application access network, then step 305 is specially: according to this control information packet corresponding to this UID carried out whole discard processing by the Hook Function in the kernel spacing, realization uses the online ability of this application to control to the user, and namely limited subscriber uses application that network is conducted interviews when the battery electric quantity of portable terminal hangs down.When the battery electric quantity of portable terminal is higher than this battery electric quantity higher limit, send the UID of corresponding control information and application to be controlled to kernel spacing, control information this moment also can allow this application access network for the user uses, then step 305 is specially: according to this control information packet corresponding to this UID carried out reservation process by the Hook Function in the kernel spacing, to allow the user to use this application access network, namely when the battery electric quantity of portable terminal is higher, allow the user to use to use network is conducted interviews.When restrictive condition is when using the surfing flow of corresponding surf time or application correspondence, similar to the above to the control of online ability corresponding to application in the portable terminal, repeat no more herein.
Perhaps, the present embodiment not only can use the internet behavior of application to control to the user, can also control using corresponding concrete speed of surfing the Internet, step 305 can specifically comprise: by described Hook Function according to described control information, packet within the unit interval that described application identities is corresponding carries out the part discard processing, to control the described corresponding speed of surfing the Internet of using.When the user need to limit speed of surfing the Internet corresponding to certain application, the user was by consisting of the UID of corresponding control information and this application in user's space, and control information at this moment is restricted to certain rate value for using corresponding speed of surfing the Internet.Kernel spacing is after receiving this control information and UID, and the Hook Function in the kernel spacing is according to this control information, and packet within the unit interval that this UID is corresponding carries out the part discard processing, has reached the purpose that limited subscriber uses this application to surf the Net.Because Hook Function can be in real time all packets of this application is carried out filtration treatment, in the time need to limiting speed of surfing the Internet corresponding to this application, as its speed of surfing the Internet is restricted to 30kB/s, the size of supposing each bag is 1500bytes, then represent 20 bags of per second parsing, when then Hook Function filters packet corresponding to this UID in kernel spacing, its partial data bag can be carried out discard processing, in each second 20 packets are carried out reservation process, namely realize to use corresponding networking speed and be restricted to 30kB/s.
Further, the step 304 in the present embodiment can be specially: when judging that default restrictive condition reaches the restrictive condition threshold value in described user's space, kernel spacing receives the application identities from control information and the application to be controlled of described user's space.Be that the user can come to limit using corresponding speed of surfing the Internet according to some default restrictive condition, restrictive condition herein can be specially signal strength signal intensity, the portable terminal of portable terminal battery electric quantity, use the corresponding surf time, use in the corresponding surfing flow.When restrictive condition was the signal strength signal intensity of portable terminal, the user can arrange according to the actual conditions of the portable terminal signal strength signal intensity to portable terminal, and a signal strength signal intensity higher limit and a signal strength signal intensity lower limit can be set.When the signal strength signal intensity of portable terminal is lower than this signal strength signal intensity lower limit, send the UID of corresponding control information and application to be controlled to kernel spacing, control information this moment can be for limiting speed of surfing the Internet corresponding to this application, then step 305 is specially: according to this control information packet corresponding to this UID carried out the part discard processing by the Hook Function in the kernel spacing, realization is controlled speed of surfing the Internet corresponding to this application, and namely corresponding speed of surfing the Internet is used in restriction when the signal strength signal intensity of portable terminal is hanged down.When the signal strength signal intensity of portable terminal is higher than this signal strength signal intensity higher limit, send the UID of corresponding control information and application to be controlled to kernel spacing, control information this moment also can be used this application access network for allowing the user, then step 305 is specially: according to this control information packet corresponding to this UID carried out reservation process by the Hook Function in the kernel spacing, to allow the user to use this application access network, namely when the signal strength signal intensity of portable terminal is higher, no longer control using corresponding speed of surfing the Internet.When restrictive condition is the surfing flow of the battery electric quantity of portable terminal, the surf time of using correspondence or application correspondence, similar to the above to the control of using corresponding networking speed in the portable terminal, repeat no more herein.
As from the foregoing, the present embodiment not only can for the user provides detailed data traffic data, can also be controlled for the user provides abundant packet circulation on the aspect of Linux protocol stack.The each side such as flow that the user can produce from signal strength signal intensity, the battery electric quantity of equipment, the memory space of equipment, current network conditions, the application of equipment arrange, and come to use the online ability of application to control to the user.The present embodiment combines thorough flow control and detailed flow analysis, can improve to greatest extent user's use impression, all internet behaviors in the portable terminal allow the user really can become the owner that each is used, so that all can be inquired about and control by the user.
The present embodiment provides a kind of flow processing method, obtain all inflows in the portable terminal and flow out corresponding UID and the data packet length of packet of protocol stack by the Hook Function of setting up in the kernel spacing, and UID and the data packet length of packet sent to user's space by kernel spacing, UID and data packet length according to packet in user's space are added up the flow that each application in the portable terminal produces, and internet behavior and online ability that the user uses each to use are controlled according to the control information that user's space sends by Hook Function; The present embodiment has been realized the flow that the portable terminal based on (SuSE) Linux OS produces is added up, and internet behavior and online ability that the user uses each to use controlled, can for the user provides the data on flows of extensive and abundant circulation control, strengthen initiative and the flexibility of user to the control of each on-line module in the portable terminal.
One of ordinary skill in the art will appreciate that: all or part of step that realizes said method embodiment can be finished by the relevant hardware of program command, aforesaid program can be stored in the computer read/write memory medium, this program is carried out the step that comprises said method embodiment when carrying out; And aforesaid storage medium comprises: the various media that can be program code stored such as ROM, RAM, magnetic disc or CD.
Fig. 4 is the structural representation of flow processing unit embodiment one of the present invention, and as shown in Figure 4, the present embodiment provides a kind of flow processing unit, and the present embodiment can specifically be carried out each step among the said method embodiment one, repeats no more herein.The flow processing unit that the present embodiment provides can comprise acquisition module 401, sending module 402 and statistical module 403.Wherein, acquisition module 401 is used for obtaining all inflows in the portable terminal and flowing out corresponding application identities and the data packet length of packet of protocol stack by the Hook Function that kernel spacing is set up.Sending module 402 is used for application identities and the data packet length that described packet is corresponding and sends to user's space.Statistical module 403 is used for each flow of using generation of described portable terminal being added up according to described packet corresponding application identities and data packet length at described user's space.
Fig. 5 is the structural representation of flow processing unit embodiment two of the present invention, and as shown in Figure 5, the present embodiment provides a kind of flow processing unit, and the present embodiment can specifically be carried out each step among the said method embodiment two, repeats no more herein.The flow processing unit that the present embodiment provides can also comprise receiver module 501 and control module 502 on the basis of above-mentioned embodiment shown in Figure 4.Wherein, receiver module 501 is used for receiving the application identities from control information and the application to be controlled of described user's space.Control module 502 is used for using the internet behavior of described application to control according to the application identities of described control information and application to be controlled to the user by described Hook Function.
Particularly, receiver module 501 can also specifically be used for when when described user's space judges that default restrictive condition reaches the restrictive condition threshold value, receives the application identities from control information and the application to be controlled of described user's space.Control module 502 can comprise the first control unit 512.The first control unit 512 is used for being abandoned or reservation process according to the described control information packet that described application identities is corresponding by described Hook Function, to forbid or to allow the user to use described application online.Perhaps, control module 502 can comprise the second control unit 522.The second control unit 522 is used for by described Hook Function according to described control information, and packet within the unit interval that described application identities is corresponding carries out the part discard processing, to control the described corresponding speed of surfing the Internet of using.
The present embodiment provides a kind of flow processing unit, obtain all inflows in the portable terminal and flow out corresponding UID and the data packet length of packet of protocol stack by the Hook Function of setting up in the kernel spacing, and UID and the data packet length of packet sent to user's space by kernel spacing, UID and data packet length according to packet in user's space are added up the flow that each application in the portable terminal produces, and internet behavior and online ability that the user uses each to use are controlled according to the control information that user's space sends by Hook Function; The present embodiment has been realized the flow that the portable terminal based on (SuSE) Linux OS produces is added up, and internet behavior and online ability that the user uses each to use controlled, can for the user provides the data on flows of extensive and abundant circulation control, strengthen initiative and the flexibility of user to the control of each on-line module in the portable terminal.
The present embodiment also provides a kind of portable terminal, can comprise above-mentioned Fig. 4 or flow processing unit shown in Figure 5, and the portable terminal in the present embodiment is specially mobile phone, is preferably the smart mobile phone with multiple application function.
It should be noted that at last: above embodiment only in order to technical scheme of the present invention to be described, is not intended to limit; Although with reference to previous embodiment the present invention is had been described in detail, those of ordinary skill in the art is to be understood that: it still can be made amendment to the technical scheme that aforementioned each embodiment puts down in writing, and perhaps part technical characterictic wherein is equal to replacement; And these modifications or replacement do not make the essence of appropriate technical solution break away from the spirit and scope of various embodiments of the present invention technical scheme.