Solved

looping

Posted on 2012-04-04
9
396 Views
Last Modified: 2012-04-06
Hi I am writing a kernel module.

I need a continuous loop that will look for tcp traffic and read from skb to store each source ip address from ip_hdr->saddr into an array

I can get it to read packets one at a time but I need it to loop, but when I try to implement a continuous loop the system crashes/hangs.

Can anyone offer any advice/possible fixes?

Cheers
0
Comment
Question by:codey-06
  • 5
  • 3
9 Comments
 
LVL 8

Expert Comment

by:Anthony2000
ID: 37805980
Here is an example of using a thread in the kernel module.

http://www.scs.ch/~frey/linux/kernelthreads.html

I think your problem might be that your loop is running and using all available kernel/process time. Thus, giving the result of maybe locking up your machine. Is that what is happening?
0
 

Author Comment

by:codey-06
ID: 37806049
Hi yes you are correct, the loop is using up all the kernel resources.  Is there a quick fix?
0
 
LVL 8

Expert Comment

by:Anthony2000
ID: 37806134
Have you tried some kind of sleep (I cannot remember the API call). This may give the OS and other processes time to run.
0
 

Author Comment

by:codey-06
ID: 37806580
Thank you. If anyone could offer a bit more help it would be very much appreciated?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 33

Assisted Solution

by:sarabande
sarabande earned 250 total points
ID: 37810387
if you added an infinite or time consuming loop into a kernel module that was needed by others you were blocking all those activities dependent on those calls and the system hangs and some processes would crash or fail because of timeouts. so, the first thing you need is to start a thread where you would add the loop and the normal kernel function could proceed. of course you may not create a new thread for every call but use one thread for all requests. in the thread you would run an infinite loop and at end of loop you should add a call to usleep which would make that the thread waits a little and so other processes and threads could be scheduled by the os. the usleep takes microseconds as argument and i would use at least 1000 (1 millisecond) to not slow down the rest of the system cause that also would depend on your other actions made in the loop.

Sara
0
 
LVL 8

Assisted Solution

by:Anthony2000
Anthony2000 earned 250 total points
ID: 37814353
Here is another related article.

http://www.linuxjournal.com/article/8144
0
 
LVL 8

Accepted Solution

by:
Anthony2000 earned 250 total points
ID: 37814357
Also, if you are not familiar with this book, its also a good reference.

http://lwn.net/Kernel/LDD3/
0
 
LVL 8

Expert Comment

by:Anthony2000
ID: 37814383
Also, take a look at the functions:
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout (signed long timeout);

See chapter 7 of the book link I provided.
0
 

Author Closing Comment

by:codey-06
ID: 37815593
Brilliant thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now