Saturday, November 28, 2015

Linux Kernel Development II - ARP replicating network driver - part I

Here is the second article in Linux Kernel development series. Majority of this article is from my old blog. I was complaining about scarcity of information on Linux networking in the old article but that was before I read Understanding Linux network internals. I still think similar since some parts of the book is outdated but there are other books I haven't read yet like Rami Rosen's book which may be filling the gap. Also there seems to be a lot more blog posts and wiki articles, like mine, talking about various topics. So if you know how everything works in general, it is quite possible to find information on a specific mechanism or implementation of a concept nowadays.

I will be talking about the fakeARP driver which you can access from GitHub [source]. It is a network driver which replies incoming ARP requests with fake ARP replies. (The link directs you to tutorial tag in Git, development continues on development and master branches. If you are interested you can check out current status too.)

Sunday, November 15, 2015

Thread cancelling caveats in pthreads

This is one of the posts I moved from my previous blog. I am preparing a long article about network drivers in Linux but it seems that it will take some more time. So I am posting this article I wrote a few years ago to keep the blog alive.

Today I will talk about two things I encountered while working with conditional mutexes in pthreads which are somewhat weird.

  1. If a thread gets cancelled while being blocked by pthread_cond_wait(), cancelled thread decides to lock the condition mutex before exiting. (as a result no one else can unlock it)
  2. pthread_cleanup_push() macro doesn't compile if another pthread_cleanup_pop() macro is not included in the same block of code.

If you read the man pages or some mailing list discussions they will convince you that this is the way things should work. But I think they are caveats one should be beware of.