kernel module, TCP state, and mbuf question

Cole cole at opteqint.net
Fri May 6 14:11:00 UTC 2011


Hi.

Im currently working on a kernel module to modify data on tcp sessions
leaving and coming into the box. And I have this working. However I've
run into the issue where I am now breaking the TCP state.
When I modify the data in the tcp packets, the size of that data may
change, meaning that I have to then update the packet size and so
forth. Now this works for the first packet with data inside it, but
the rest of the packets leaving on this TCP stream then have the error
where their sequence number is now wrong. i.e. If I modify the data,
and the new data size is then less than that of the original packet,
that means the next sequence number of the out going packet will
actually be higher than it should be, and the other side will think it
has missed a packet somewhere.

In my kernel module I am using pfil_add_hook to hook into the outgoing
packets, and from there I am inspecting and modifying the packets as
needed. My function definition for the function I pass to
pfil_add_hook is the default one as follows:
chkoutput(void *arg, struct mbuf **m, struct ifnet *ifp, int dir,
struct inpcb *inp)

I was wondering if it is possible to somehow get access to the TCP
state for the tcp stream for the mbuf/packet I have received and if I
can modify the th_seq to match my new values, or if I will need to
keep my own state information for any streams I modify and then update
the outgoing packets th_seq values as needed?

Any information or help will be gladly appreciated.

Regards
/Cole


More information about the freebsd-net mailing list