Search code examples
c++macosnetwork-programmingkernel-extension

How to make interaction kext os x network filter with application?


I am writing network filter kernel extension for os x. I want to call something like callbacks in kext. For example in data_in function when I get a tcp packet I want to call this callback from user application. Application changes this packet and I inject it. How to make this interaction between kext and user application?


Solution

  • First of all, you don't want to block the data_in callback - you should "swallow" the packet, send it to userspace, and when it comes back, re-inject it into the connection.

    There are a few ways of exchanging data with userspace processes. The most convenient way for exchanging network packets is probably the kernel control mechanism, which essentially allows you to open a socket connection between a user program and your kext.

    Apple used to offer sample source code, "tcplognke" that did something extremely similar, but it seems to have disappeared from their own site. Someone kindly appears to have saved it and is offering it for download - looks OK to me right now, but obviously be cautious about downloading stuff from random websites.