LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 07-22-2015, 07:50 AM   #1
DaveTheRave
LQ Newbie
 
Registered: Jul 2015
Location: UK
Distribution: Fedora
Posts: 1

Rep: Reputation: Disabled
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.
 
Old 07-26-2015, 02:35 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Normally a NIC driver doesn't need that information. However, the packet will be passed after the ARP resolution so the MAC destination field in the Ethernet header normally contains the MAC address of the destination (in your case the gateway).
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Routing Rhel 5.5 2 Nic with Gateway and without Gateway deboned Linux - Networking 2 06-02-2015 07:17 AM
Packets from IPv6 socket bound to device are routed from other device eitanz Linux - Networking 3 10-12-2014 06:12 PM
Intel i210 or i217 NIC device driver? kebabbert Solaris / OpenSolaris 15 08-13-2014 04:43 PM
NIC/driver issue - eth0: ERROR while getting interface flags: No such device Beck22 Linux - Networking 4 01-17-2009 12:14 PM
How to obtain the MAC adress for your NIC Metablade Linux - Newbie 8 10-11-2005 01:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 07:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration