Access IP layer


(RefaelF) #1

Hey,

Could anyone please tell me where the IP layer is handled? Inside which file in “go/src/net/”?
I want to be able to access properties such as ip.length, ip.flags and ip.ttl.

Waiting for your reply!


(Jakob Borg) #2

IP is implemented in the operating system. You can however access some lower level options using x/net/ipv4 for example.


(George Calianu) #3

A small observation… Working at low level in the network stack may need privileged rights for execution (eg. root rights on Linux systems). Take care of this aspect otherwise many operations won’t work.


(RefaelF) #4

Thanks for your responses guys,
Just to make sure I asked it in the correct way; I have an http server that among other things, imports https://golang.org/src/net/.
I’d like to print for example the TTL of the incoming requests.

Data has to be passed from the IP layer to the TCP layer and eventually to the application layer, since the source IP address of the requests is also gotten from the IP layer, and is accessible in multiple places throughout the code of the different libraries. So values like TTL (of the source request) should be as well.

So I assumed it would be in one of the files, like ipsock.go, but couldn’t find it there.


(Jakob Borg) #5

TTL and such are indeed IP level concepts, and a HTTP request comes in over TCP. The socket APIs for TCP don’t expose TTL because it has no meaning there - your HTTP request might have been assembled from lots of IP packets all with different TTL values.


(RefaelF) #6

Yup I agree, so let’s say I’d want to change the source code of the native libraries of GO, so that the ttl attribute of each incoming (TCP)-IP request would be printed to the screen for example, where would I be able to do that?


(Jakob Borg) #7

You cannot, because the API that Go itself uses (TCP sockets) does not expose this information. TCP sockets do not have TTL information. This is similar to how you also cannot get the IP packet lengths or source MAC address. It’s simply information from the wrong level of the stack.


(RefaelF) #8

Thanks a lot for the help @calmh !

IP level is out of reach.
So would it be possible to access the TCP level? For example extracting tcp.options or tcp.window_size from a TCP SYN packet?

Or TCP sockets are received as is in GO (at least when using src/net) and the only “low-level” attributes that are accessible are tcp.src_ip and tcp.src_port?