Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Which part of the linux is responsible for "forwarding" traffic between interfaces?

I know about "/proc/sys/net/ipv4/ip_forward" but which part of OS, kernel or a module is actually checking this setting and decides whether or not perform the forwarding?

Is kernel sitting there and mindlessly forwards any received packet which is not addressed to this machine to another interface based on routing table?

This is a very fundamental question that I always wanted to deeply understand.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Which part of the linux is responsible for "forwarding" traffic between interfaces?

The IP network stack. All the IP protocols - UDP, TCP, etc - run off the same fundamental routing tools and behaviours. This is also true of IPv6, which has a marginally different implementation but fundamentally the same architecture.

Is kernel sitting there and mindlessly forwards any received packet which is not addressed to this machine to another interface based on routing table?

Yes. Except the "mindlessly" part, where you meant to say, "as designed".

The process is simple: when a machine that confirms to the IP specification receives a packet, it makes some very simple decisions; the basic process is:

  1. Validate that this is a sane packet.
  2. Check if it is destined for a local IP address, and deliver locally if so.
  3. Find the next hop from the routing table.
  4. Send the packet to that next hop, or send an "undeliverable" error.

The ip_forward(...) method is invoked as part of that overall algorithm, and is as simple as you might think. IP is, fundamentally, a very, very simple protocol.

share|improve this answer
    
This is not actually a question of tcp/ip fundamentals. I am sitting here reading through "int ip_forward(struct sk_buff *skb)" function in linux/net/ipv4 and scratching my head why would you want to have this at this very place. –  shayan Feb 3 '12 at 22:32
    
@shayan What's your concern, exactly? Are you saying that it's a bad idea to have IP routing built into the kernel's IP stack? –  Shane Madden Feb 3 '12 at 22:35
    
That was totally not clear from the way you put your question. :) –  Daniel Pittman Feb 3 '12 at 22:35
    
Well, I kept the question in layman terms in the hope of finding a very obvious answer :) The real question is "Is it 100% true to say kernel is the only responsible entity for forwarding"? –  shayan Feb 3 '12 at 22:41
    
@DanielPittman now with your edited answer I can die in peace :) –  shayan Feb 3 '12 at 22:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.