About time delay in kernel threads at LOCAL_OUT netfilter hook

2013-03-20 Thread Rifat Rahman
Hello there,
I am in a situation where I am mangling RTP data in kernel space. I
have written a netfilter module which is responsible for encryption,
padding and ptime modification. The thing is that, encryption, padding
works just fine. Ptime modification involves two steps. When large
packets are incoming to the server (say 60 ptime, 60 bytes of RTP
payload with g729 codec), they are splitted with ptime 20. The SIP
server is Asterisk. When asterisk (the server) is sending packets of
20 ptime, they are merged to the desired big ptime(say 60). All the
things went well. I looked up packets whether checksumming, RTP
timestamping and sequencing is done perfectly. And it is done quite
well. The whole process without large ptime is satisfactory.

The thing is that, after contacting with asterisk mailing list, I came
to know that I have to make some delay before sending each large
packet. But, I am sending packets outside of the box in LOCAL_OUT
hook. I wrote a thread to make queue the packets until some delay
conditions is satisfied. And then trying to send packets from that
thread.

But, eventually what I found is that, if I set delay to zero, then
everything is fine, the packets are queued and sent as expected. But,
if I set delay0, the thread does not send packets. I used
dst_output() in include/linux/dst.h for sending packets. But, this
function works only in LOCAL_OUT hook. When I am adding some delay in
a thread, the thread just misses the hook and the packet is never
sent. I tested that, if I add the delay condition in the target
function, the whole kernel faces the delay, so it is of no help. I
have to do this thing inside a thread. But how to not miss that hook?
Can anyone suggest any work around regarding this?

-- 
Rifat Rahman

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Facing trouble in creating a packet in kernel space

2012-09-25 Thread Rifat Rahman
Hello there,

I need to mangle rtp packets in kernel space. So far I am new in kernel
module programming. I am trying to implement a module for netfilter hooks.
For the first time as exercise, I am trying to write smaller modules. Let
me explain what I am actually doing now.

I have an echo client and server. The server runs on port 6000. Both are on
different machines (May be VMs in bridge filter mode). The client sends udp
message and the server just echoes it back. Let us suppose the client sends
some message as data. Then now I am trying to write a module for the
client machine that will append 12345 after the data so that the server
will get some message12345 and echo it back. Now there are various things
I did faced. I relied on the NF_IP_POST_ROUTING hook.

At first, I copied the data to a temporary storage, and then add 12345 with
that. Then I increase skb-tail using skb_put(). Then I memset()  0 to the
packet data, and copy the temporary storage with that. Then as the
procedure, NF_ACCEPT is returned. There are certain checking points like
the udph-dest == 6000 etc. etc. When I use skb_put(), my system hangs out
after two or three minutes. When I dmesg to be certain that everything goes
right, I find it OK. But, suppose once I send a message like This is a
pretty big message and another time I send small message then I get just
small message12345g message that means, the bigger message is stored
somewhere I don't understand. I tried with skb_add_data() but that works
incorrectly here, I understand it's my fault. I just can't figure it out.

Now, one thing came in my mind, if it's not possible, should I create new
packets for that data appending? I find skb-end - skb-tail is not so big.
But ultimately I have to merge two or three packets into one packet and
then skb_put() will not suffice for me. Then the point comes, I can use
alloc_skb(), skb_reserve(), skb_header_pointer() and other skb manipulation
functions, but I don't understand how can I drop the packet got (should I
return NF_DROP?) and how can I route my created packets in the packet
flowing path? I saw in the xtables_addons for help (file xt_ECHO.c) but
found they used ip_route_me_harder() for it. But the function they used is
quite different, it is their own. Then I need suggestions about how to
route the newly created packet in kernel space. This is the point I am
stuck for a few days. If anyone can help me, I will be highly grateful. I
understand my knowledge is poor about Linux kernel, but I need a definite
way to understand, otherwise the code is not helping me much.

Thanks in advance.

-- 
Rifat Rahman
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies