How do I obtain the gateway ID of a routed packet in my NIC device driver?
Summary: I would like to be able to read the Gateway address for an IP Packet that has been routed to my Network Device.
Note: I am using Linux Kernel 3.18, gcc 4.8.4, glibc 2.9, and compiled for x86.
My routing table looks something like this:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
148.1.1.0 * 255.255.255.0 U 0 0 0 eth0
148.2.1.0 150.1.4.2 255.255.255.0 UG 0 0 0 net0
148.3.1.0 150.1.4.3 255.255.255.0 UG 0 0 0 net0
148.4.1.0 150.1.4.4 255.255.255.0 UG 0 0 0 net0
When I send a packet to 148.2.1.0, the kernel will route it to my NIC driver, and calls the "xmit()" function with "struct sk_buff *skb" and "struct net_device *dev" as parameters.
My question is, how can I determine which gateway was selected, as 3 of them are all pointing at "net0".
The nexthop appears to be available, as in file "linux-3-18/net/ipv4/arp.c", there is an line which says
"paddr = rt_nexthop(skb_rtable(skb), ip_hdr(skb)->daddr);"
However, in my driver, "skb_rtable(skb)" is NULL. The nexthop/gateway must be available/accessible, but I am having difficulties.
In an example from a much earlier kernel (2.4), the gateway is passed in with the "sk_buff", but not in this later Kernel.
Any ideas please??
Last edited by DaveTheRave; 07-22-2015 at 09:22 AM.
|