3
$\begingroup$

I want to know exactly till which layer in the OSI model the 127.0.0.1 (loopback) packet goes till it is returned to the upper layer. I read some where it goes till data link layer. but as i was told data link layer cannot see the ip address then how data link layer decide that the packet has to be send "up" instead of "down".

$\endgroup$
  • 2
    $\begingroup$ Should go somewhere else, probably ServerFault. $\endgroup$ – G. Bach Sep 15 '15 at 19:49
  • 1
    $\begingroup$ @G.Bach Definitely not Server Fault, which is for professionals only (and extremely jealous of that). Since this thing is taught in CS classes and not just in engineering classes, I think the question is ok here. $\endgroup$ – Gilles 'SO- stop being evil' Sep 15 '15 at 20:25
  • 2
    $\begingroup$ I can't understand what you're asking. What do you mean by "till which layer... the packet goes till it is returned to the upper layer"? Or, more generally, by a packet "going till a layer"? $\endgroup$ – David Richerby Sep 15 '15 at 21:47
4
$\begingroup$

When you say "layer", you are probably thinking of the OSI model, also known as the seven-layer model.

However, real TCP/IP implementations don't actually fit the OSI model very well. The OSI model was designed by a standards committee 30 or 40 years ago, based on how the committee members thought network stacks ought to be designed -- but that was before the Internet and without the advantage of the experience we have today.

127.0.0.1 is an IP address, and the loopback functionality of 127.0.0.1 is associated with the IP protocol. The IP protocol can be thought of as most closely associated with the "network layer" (in the OSI model). So, you could say that the answer is "the network layer".

But, it's important to realize that this is a bit of a lie. In real operating systems, there's not necessarily a clean separation between the TCP stack and the IP stack; the two are closely hooked together. So, it's doesn't make sense to ask "the code that does loopback processing -- what layer is it at?". The code that does loopback processing could plausibly be considered part of the TCP/IP stack, and the TCP/IP stack combines elements of the network layer, the transport layer, and the session layer. Loopback processing might also be performed in a separate device driver that, from the operating system's perspective, looks like another device (just like another Ethernet card, but different), so one could even make an argument that the code is really part of the data link layer or physical layer. See how the seven-layer OSI model isn't really adding much insight here? The code is what the code is; trying to attach a label based on one of those seven layers is a human construct, one that in this case isn't a very good match to reality.

It's probably better to think of the OSI model as a plausible vocabulary for talking about network protocols, but it's less helpful when talking about the structure of networking code: the structure of the code doesn't necessarily correlate well to the seven layers of the OSI model.

TL;DR: the OSI model is a lie.

$\endgroup$
  • $\begingroup$ I'm not sure the OSI model is really "a lie". But it's definitely better to view it as a vocabulary for talking about networks, and not as a design template. $\endgroup$ – David Richerby Sep 15 '15 at 21:50
  • $\begingroup$ Basically i am preparing for an exam. and this question may be asked there. the theory which we all read says Data link layer. but i think it should be network layer. now i am confussed which layer i should use. What u suggest for that. $\endgroup$ – Ravi Singh Sep 16 '15 at 15:37
  • 1
    $\begingroup$ @DavidRicherby, it was definitely meant as a design template for networks, but was misguided (it contains layers that make no sense in computer to computer networks, like the whole session layer) and others that are an overengineered "solution" to a non-problem (presentation layer). Its real relevance is in the lower layers (physical, data link), but even there e.g. the IEEE 802 standards subdivide the layers and define different functionality. The TCP/IP model was in fact previous to OSI, and outlived it for 20+ years now. $\endgroup$ – vonbrand Oct 25 '15 at 1:43
1
$\begingroup$

Simple answer: The 127.0.0.1 address is an IP layer concept, so it has to be handed to the IP layer for correct routing and so.

More complex answer: The 127.0.0.1 address might be common enough in practical use that upper layers of the TCP/IP stack in your particular operating system cut corners and handle it specially. Even your application might figure out it is supposed to talk to itself and never touch the TCP/IP stack.

No, the totally misguided (and finally dead and buried) OSI protocol stack has no relevance to any of this.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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