The Net - Device' Structure: A Look at The Main Kernel-Object Concerned With A Linux System's Network Interface Controller
The Net - Device' Structure: A Look at The Main Kernel-Object Concerned With A Linux System's Network Interface Controller
The Net - Device' Structure: A Look at The Main Kernel-Object Concerned With A Linux System's Network Interface Controller
next prev
lo eth0 eth1
About 90 separate
fields belong to
each net_device
member of this
doubly-linked list
A few examples
struct net_device
{
char name[ IFNAMSIZ ];
int ifindex; \ /* inteface index */
unsigned int mtu; /* maximum transmission unit */
unsigned char dev_addr[ MAX_ADDR_LEN ]; /* hardware address */
void *ip_pointer; /* points to IFs IPv4 specific data */
unsigned int flags;
unsigned long trans_start; /* time (in jiffies) of last transmission */
struct net_device_stats stats; /* a default set of device statistics */
// some function-pointers (i.e., these are virtual functions)
int (*open)( struct net_device * );
int (*stop)( struct net_device * );
int (*hard_start_xmit)( struct sk_buff *, struct net_device * );
int (*get_stats)( struct net_device * );
};
An analogy?
The struct net_device kernel-objects play a
similar role for network device-drivers as is
played by struct file_operations objects with
regard to character device-drivers
struct file_operations struct net_device
open() open()
release() stop()
write() hard_start_xmit()
read() get_stats()
llseek() set_mac_address()
ioctl() do_ioctl()
};
struct sk_buff
Notice that the net_device object also has
a member-field which can hold a pointer to
to a kernel-object of type struct sk_buff
struct sk_buff
skb
packet
data
Kernels header-files
The kernel is written in C (with occasional
uses of some inline assembly language)
All the source-code for our Linux kernel is
in this system directory: </usr/src/linux>
Most header-files are in </include/linux>
Those header-files that are CPU-specific
are in </include/asm>
Our directory tree
/
len += sprintf( buf+len, %s, state[ dev->flags & IFF_UP ] );
In-class exercise #2
Look at the output produced when you
execute the Linux ifconfig program
Choose some added item of information
about our stations network interfaces
(from the ifconfig output) and see if you
can enhance our netdevs.c demo so its
pseudo-file will display that extra item of
information (e.g., dev->stats.tx_bytes)