Skip to contentSkip to conversation

ip_hdr vs ipip_hdr

DISCUSSION Ricky 2 participants 2 messages Aug 18, 2016

lore
Share & tools
lore

Ricky

author
#0 lore raw

In include/linux/ip.h,

23 static inline struct iphdr *ip_hdr(const struct sk_buff *skb) 24 {
25 return (struct iphdr *)skb_network_header(skb);
26 }
27
28 static inline struct iphdr *inner_ip_hdr(const struct sk_buff *skb) 29 {
30 return (struct iphdr *)skb_inner_network_header(skb);
31 }
32
33 static inline struct iphdr *ipip_hdr(const struct sk_buff *skb) 34 {
35 return (struct iphdr *)skb_transport_header(skb);
36 }
37 #endif /* _LINUX_IP_H */
if I passed in sk_buff to ip_hdr and ipip_hdr

struct iphdr *ip_hdr ip_hdr_net = ip_hdr(skb);
struct iphdr *ip_hdr ip_hdr_trans = ipip_hdr(skb);
Do ip_hdr_net->saddr and ip_hdr_trans->saddr point to the same thing? I tried it on code. It doesn't. It seems that only ip_hdr_net->saddr point to source IP address, which make sense. Because network layer has IP but not on transport layer.

So questions:

(1) what is differences between ip_hdr and ipip_hdr? Why we have them? No documentation whatever to figure it out.

(2) should I use ntohX function to convert ip_hdr member data when accessing them? eg, ip_hdr_net->saddr. -------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20160818/92982c0e/attachment-0001.html

#1 lore raw

Hi Ricky,

ipip in the linux semantics refers usually to IP tunnel, for example:
http://lxr.free-electrons.com/source/net/ipv4/ipip.c

Traffic of ip tunnels is composed from an inner IP header which is encapsulated within a packet which as the external IP header,

Quoted 1 line

(1) what is differences between ip_hdr and ipip_hdr? Why we have them? No ?>documentation whatever to figure it out.

ip_hdr() is the IP header of layer 3, the network

ipip_hdr() is the IP header of layer 4, the transport layer. So this
is the IP header of the internal IP header when you have a tunnel, not the external IP header.

Hope this helps,

Regards,
Rami Rosen

http://ramirose.wix.com/ramirosen

Quoted 43 lines · Ricky

In include/linux/ip.h,

23 static inline struct iphdr *ip_hdr(const struct sk_buff *skb) 24 {
25 return (struct iphdr *)skb_network_header(skb);
26 }
27
28 static inline struct iphdr *inner_ip_hdr(const struct sk_buff *skb) 29 {
30 return (struct iphdr *)skb_inner_network_header(skb);
31 }
32
33 static inline struct iphdr *ipip_hdr(const struct sk_buff *skb) 34 {
35 return (struct iphdr *)skb_transport_header(skb);
36 }
37 #endif /* _LINUX_IP_H */

if I passed in sk_buff to ip_hdr and ipip_hdr

struct iphdr *ip_hdr ip_hdr_net = ip_hdr(skb); struct iphdr *ip_hdr ip_hdr_trans = ipip_hdr(skb);

Do ip_hdr_net->saddr and ip_hdr_trans->saddr point to the same thing? I tried it on code. It doesn't. It seems that only ip_hdr_net->saddr point to source IP address, which make sense. Because network layer has IP but not on transport layer.

So questions:

(1) what is differences between ip_hdr and ipip_hdr? Why we have them? No documentation whatever to figure it out.

(2) should I use ntohX function to convert ip_hdr member data when accessing them? eg, ip_hdr_net->saddr.

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies