Results 1 to 1 of 1
Hello everybody,
First of all, sorry for my English
I have changed the ip_forward function in order to add a timer : when a packet comes, it will be delayed ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 03-22-2011 #1Just Joined!
- Join Date
- Mar 2011
- Posts
- 1
How to add threads in ip_forward function
Hello everybody,
First of all, sorry for my English
I have changed the ip_forward function in order to add a timer : when a packet comes, it will be delayed about 1 or 2 seconds. Then, it will be forwarded.
But if an other packet comes when a previous packet is waiting, there will be a problem. So I want to use threads to avoid blocking states.
But I obtained lots of errors and warnings.
Code:#include <linux/types.h> #include <linux/mm.h> #include <linux/skbuff.h> #include <linux/ip.h> #include <linux/icmp.h> #include <linux/netdevice.h> #include <linux/slab.h> #include <net/sock.h> #include <net/ip.h> #include <net/tcp.h> #include <net/udp.h> #include <net/icmp.h> #include <linux/tcp.h> #include <linux/udp.h> #include <linux/netfilter_ipv4.h> #include <net/checksum.h> #include <linux/route.h> #include <net/route.h> #include <net/xfrm.h> #include <linux/init.h> #include <linux/linkage.h> #include <linux/unistd.h> #include <linux/delay.h> #include <linux/kernel.h> #include <linux/sysctl.h> #include <linux/compiler.h> #include <linux/module.h> #include <linux/jiffies.h> #include <linux/list.h> #include <linux/jhash.h> #include <linux/random.h> #include <net/dst.h> #include <net/inetpeer.h> #include <net/inet_frag.h> #include <linux/inet.h> #include <linux/netfilter_ipv4.h> #include <linux/kthread.h> #include <linux/delay.h> #include <linux/time.h> int ip_forward(struct sk_buff *skb) { struct iphdr *iph; /* Our header */ struct rtable *rt; /* Route we use */ struct ip_options * opt = &(IPCB(skb)->opt); struct task_struct *threadIpForward; if (skb_warn_if_lro(skb)) goto drop; if (!xfrm4_policy_check(NULL, XFRM_POLICY_FWD, skb)) goto drop; if (IPCB(skb)->opt.router_alert && ip_call_ra_chain(skb)) return NET_RX_SUCCESS; if (skb->pkt_type != PACKET_HOST) goto drop; skb_forward_csum(skb); /* * According to the RFC, we must first decrease the TTL field. If * that reaches zero, we must reply an ICMP control message telling * that the packet's lifetime expired. */ if (ip_hdr(skb)->ttl <= 1) goto too_many_hops; if (!xfrm4_route_forward(skb)) goto drop; rt = skb_rtable(skb); if (opt->is_strictroute && rt->rt_dst != rt->rt_gateway) goto sr_failed; if (unlikely(skb->len > dst_mtu(&rt->u.dst) && !skb_is_gso(skb) && (ip_hdr(skb)->frag_off & htons(IP_DF))) && !skb->local_df) { IP_INC_STATS(dev_net(rt->u.dst.dev), IPSTATS_MIB_FRAGFAILS); icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(dst_mtu(&rt->u.dst))); goto drop; } /* We are about to mangle packet. Copy it! */ if (skb_cow(skb, LL_RESERVED_SPACE(rt->u.dst.dev)+rt->u.dst.header_len)) goto drop; iph = ip_hdr(skb); /* Decrease ttl after skb cow done */ ip_decrease_ttl(iph); /* * We now generate an ICMP HOST REDIRECT giving the route * we calculated. */ if (rt->rt_flags&RTCF_DOREDIRECT && !opt->srr && !skb_sec_path(skb)) ip_rt_send_redirect(skb); skb->priority = rt_tos2priority(iph->tos); threadIpForward = kthread_run(ip_forward_thread,(skb,5),"IP_FORWARD_THREAD"); return 0; sr_failed: /* * Strict routing permits no gatewaying */ icmp_send(skb, ICMP_DEST_UNREACH, ICMP_SR_FAILED, 0); goto drop; too_many_hops: /* Tell the sender its packet died... */ IP_INC_STATS_BH(dev_net(skb_dst(skb)->dev), IPSTATS_MIB_INHDRERRORS); icmp_send(skb, ICMP_TIME_EXCEEDED, ICMP_EXC_TTL, 0); drop: kfree_skb(skb); return NET_RX_DROP; }
and the ip_forward_thread function is :
Code:int ip_forward_thread(struct sk_buff *skb, int a) { struct rtable *rt; /* Route we use */ delay(1000*a); return NF_HOOK(NFPROTO_IPV4, NF_INET_FORWARD, skb, skb->dev, rt->u.dst.dev, ip_forward_finish); }
net/ipv4/ip_forward.c: In function ‘ip_forward_thread’:
net/ipv4/ip_forward.c:78: error: implicit declaration of function ‘delay’
net/ipv4/ip_forward.c: In function ‘ip_forward’:
net/ipv4/ip_forward.c:144: warning: left-hand operand of comma expression has no effect
net/ipv4/ip_forward.c:144: warning: passing argument 1 of ‘kthread_create’ from incompatible pointer type
include/linux/kthread.h:7: note: expected ‘int (*)(void *)’ but argument is of type ‘int (*)(struct sk_buff *, int)’
net/ipv4/ip_forward.c:144: warning: passing argument 2 of ‘kthread_create’ makes pointer from integer without a cast
include/linux/kthread.h:7: note: expected ‘void *’ but argument is of type ‘int’
Please help me
Thank you for your help


Reply With Quote
