LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-08-2014, 03:30 AM   #1
kikilinux
Member
 
Registered: Sep 2012
Posts: 126

Rep: Reputation: Disabled
Question edit packets before forwarding in a linux router


Hi
I have a linux box which i have installed a bird router on it.
My linux box acts as a router now.
I need to edit the packets before forwarding, specifically editing Identification field of IPv4 packet for IP traceback purposes.
how can i perform this ?
any suggestion would be greatly appreciated.

best
 
Old 04-08-2014, 04:30 PM   #2
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,889

Rep: Reputation: 163Reputation: 163
You can add a hook in netfilter.
 
Old 04-09-2014, 05:24 AM   #3
kikilinux
Member
 
Registered: Sep 2012
Posts: 126

Original Poster
Rep: Reputation: Disabled
Dear nini09
Very thanks to answer but can you explain more and how (a little more help) ?
Can I add this functionality to the existing hook in Netfilter or it is better to add another hook in Netfilter?
If u don't have time to explain more i will solve my problem alone.

best

Last edited by kikilinux; 04-09-2014 at 05:29 AM.
 
Old 04-09-2014, 05:42 AM   #4
kikilinux
Member
 
Registered: Sep 2012
Posts: 126

Original Poster
Rep: Reputation: Disabled
Hi again
I found this function at http://www.cs.fsu.edu/~baker/devices...inetpeer.h#L42 website :
static inline __u16 inet_getid(struct inet_peer *p, int more)
Is it logical to modify this function to create our custom IP ID field?

best

Last edited by kikilinux; 04-09-2014 at 06:19 AM.
 
Old 04-09-2014, 03:51 PM   #5
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,889

Rep: Reputation: 163Reputation: 163
Following link is good example.
http://fcns.eu/2010/02/15/netfilter-hooks/
 
1 members found this post helpful.
Old 04-11-2014, 07:00 AM   #6
kikilinux
Member
 
Registered: Sep 2012
Posts: 126

Original Poster
Rep: Reputation: Disabled
Dear nini09
Maybe this is the last question on this thread.
If i choose netfilter hook to edit IP ID does it has the minimum effect on router performance?
Does it exist another way to perform the similar work with lesser performance effects than netfilter hook?

best
 
Old 04-11-2014, 03:36 PM   #7
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,889

Rep: Reputation: 163Reputation: 163
If the NIC support checksum offload, effect should be very tiny. But if no checksum offload support on the NIC, it could affect performance because checksum has be calculate checksum again after IP id is changed.
 
Old 04-13-2014, 01:57 PM   #8
kikilinux
Member
 
Registered: Sep 2012
Posts: 126

Original Poster
Rep: Reputation: Disabled
but every router has to decrease TTL and recalculate checksum ...
 
Old 04-14-2014, 03:32 PM   #9
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,889

Rep: Reputation: 163Reputation: 163
Yes, the checksum is recalculated after TTL is decreased. It is expensive action and can be avoided.
If you can trace kernel code to find out where the TTL is modified and adding your hook before TTL is changed, your recalculation can be avoided.
 
Old 04-14-2014, 04:17 PM   #10
kikilinux
Member
 
Registered: Sep 2012
Posts: 126

Original Poster
Rep: Reputation: Disabled
Dear nini09
Because in routers the packets must be forwarded and not Destined to router itself can i use my netfilter hook
in :
"ip_forward.c" file
in :
"int ip_forward(struct sk_buff *skb)" function
right before bellow line ??
return NF_HOOK(PF_INET, NF_IP_FORWARD, skb, skb->dev, rt->u.dst.dev,ip_forward_finish);
 
Old 04-15-2014, 03:36 PM   #11
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,889

Rep: Reputation: 163Reputation: 163
Yes, you can do like that.
 
Old 05-12-2014, 03:10 AM   #12
kikilinux
Member
 
Registered: Sep 2012
Posts: 126

Original Poster
Rep: Reputation: Disabled
Hi again
I have this code which i have access to every field of ip header except option field.
how can i access to option field or create option field and append it to ip header ?

static unsigned int hook_func(unsigned int hooknum,
struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct iphdr *ip_header;
struct tcphdr *tcp_header;

ip_header = ip_hdr(skb);

//ip_header = (struct iphdr *)skb_network_header(skb);
skb_set_transport_header(skb, ip_header->ihl * 4);
tcp_header = (struct tcphdr *)skb_transport_header(skb);

return NF_ACCEPT;
}
 
Old 05-12-2014, 03:26 PM   #13
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,889

Rep: Reputation: 163Reputation: 163
It is easy to access IP option field if ip header is got. IP option is after IP header, just shifting 20 bytes.
It is difficult to create a new option. The IP and MAC header have to be shifted at first and then a new option can be added.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting Wake-On-LAN Magic Packets from one bridge/subnet to another on a Linux-Router baedamichi Linux - Newbie 2 04-05-2014 04:31 AM
Linux as a router for SCTP and UDP packets gg18 Linux - Newbie 1 11-25-2011 10:45 AM
packets not routed properly after setting up linux machine as router sundar3350 Linux - Networking 3 08-16-2010 06:04 AM
Linux Router Drops Packets lineman60 Linux - Networking 2 06-17-2008 08:26 PM
Forwarding of broadcasts packets on a Linux router zoshr Linux - Networking 2 03-13-2007 08:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration