The ‘net_device’ structure A look at the main kernel-object concerned with a Linux system’s network interface controller.

Slides:



Advertisements
Similar presentations
Linux device-driver issues
Advertisements

Computer System Laboratory
Click Router: Hands on Arvind Venkatesan. Acknowledgements Thanks Hema for beautifying the slides!
Devices and Drivers (Chapter 7) Khattab Alhabashi UNIX System Administration.
The Journey of a Packet Through the Linux Network Stack
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
Linux can be generally divided into four major components: 1. KERNEL – OS, ultimate boss The kernel is the core program that runs programs and manages.
Creating a device-file node An introduction to some privileged Linux system-calls (needed for an upcoming programming exercise)
The ‘process’ abstraction
Computer Science 635 Advanced Systems Programming Fall 2007 Professor Allan Cruse.
Timeout for some demos An instructive look at how the Linux Operating System sets up system data-structures.
SiS 315 Graphics Engine Introduction to some capabilities of graphics accelerator hardware.
CS 635 Advanced Systems Programming Spring 2003 Professor Allan B. Cruse University of San Francisco.
Chapter 1 Introduction to Object- Oriented Programming and Problem Solving.
How to make a pseudo-file As a follow-up to our first lab, we examine the steps needed to create our own ‘/proc’ file.
Dynamic visualizations On ‘non-canonical’ keyboard-input and terminal escape-sequences for visualization effects.
A “real” network driver? We want to construct a Linux network device-driver that is able to send and receive packets.
Firewall Lab Zutao Zhu 02/05/2010. Outline Preliminaries getopt LKM /proc filesystem Netfilter.
The kernel’s task list Introduction to process descriptors and their related data-structures for Linux kernel version
Scientific Visualization Using imagery to aid humans in understanding a complicated phenomenon.
Managing physical memory
Kernel Event-Timers Our first look at the Linux kernel’s mechanism for managing its dynamic timers.
Rapid prototyping of LKMs Configuring our Linux systems for the quick creation and use of loadable kernel modules.
CS 635 Advanced Systems Programming Spring 2005 Professor Allan B. Cruse University of San Francisco.
CS 635 Advanced Systems Programming Fall 2007 Professor Allan B. Cruse University of San Francisco.
Adjusting out device-driver Here we complete the job of modifying our ‘nicf.c’ Linux driver to support ‘raw’ packet-transfers.
Looking at kernel objects How a character-mode Linux device driver can be useful in viewing a ‘net_device’ structure.
What’s needed to transmit? A look at the minimum steps required for programming our anchor nic’s to send packets.
A network driver ‘framework’ We construct a ‘skeleton’ module showing just the essential pieces of a Linux network device driver.
Common network diagnostic and configuration utilities A ‘toolkit’ for network users and managers when ‘troubleshooting’ is needed on your network.
Guide To UNIX Using Linux Third Edition
Cambodia-India Entrepreneurship Development Centre - : :.... :-:-
‘C’ LANGUAGE PRESENTATION.  C language was introduced by Dennis Ritchie..  It is a programming language, which can make a interaction between user and.
MBAC 611.  We have been using MS Access to query and modify our databases.  MS Access provides a GUI (Graphical User Interface) that hides much of the.
1 SEEM3460 Tutorial Unix Introduction. 2 Introduction What is Unix? An operation system (OS), similar to Windows, MacOS X Why learn Unix? Greatest Software.
An Introduction to Device Drivers Sarah Diesburg COP 5641 / CIS 4930.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Linux Installation and Administration – Lesson 5 Tutor: George Papamarkos Topic: Devices in Linux.
M1G Introduction to Programming 2 4. Enhancing a class:Room.
An intro to programming. The purpose of writing a program is to solve a problem or take advantage of an opportunity Consists of multiple steps:  Understanding.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Click Router: Hands on Arvind Venkatesan Shivkumar Kalyanaraman.
Ethernet Driver Changes for NET+OS V5.1. Design Changes Resides in bsp\devices\ethernet directory. Source code broken into more C files. Native driver.
Troubleshooting and Performance
Kernel Modules. Kernel Module Pieces of code that can be loaded and unloaded into the kernel upon demand. Compiled as an independent program With appropriate.
Lesson 5—Networking BASICS1 Networking BASICS Protocols and Network Software Unit 2 Lesson 5.
Recent Software Issues L3 Review of SM Software, 28 Oct Recent Software Issues Occasional runs had large numbers of single-event files. INIT message.
Chapter Two Exploring the UNIX File System and File Security.
Linux Routing. Why use Linux as a router? Its cheap. Linux has low hardware requirements. A properly configured P166 Mhz computer would have no problems.
An Introduction to Device Drivers Ted Baker  Andy Wang COP 5641 / CIS 4930.
Implementing ‘noecho’ Programming details regarding the Linux implementation for ‘struct termios’ objects.
CSC414 “Introduction to UNIX/ Linux” Lecture 2. Schedule 1. Introduction to Unix/ Linux 2. Kernel Structure and Device Drivers. 3. System and Storage.
Click Router: Hands on Alex Newman Arvind Venkatesan Shivkumar Kalyanaraman.
Lab 12 Department of Computer Science and Information Engineering National Taiwan University Lab12 – Driver 2014/12/16 1 /21.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 2.
Kernel Modules – Introduction CSC/ECE 573, Sections 001 Fall, 2012.
Chapter 4: server services. The Complete Guide to Linux System Administration2 Objectives Configure network interfaces using command- line and graphical.
Lecture 3: Stateless Packet Filtering. 2 Agenda 1 1 Linux file system - networking sk_buff 2 2 Stateless packet filtering 3 3 About next assignment 4.
Note: Some of the slides are repeated from Introduction to C++
Zero-copy Receive Path in Virtio
sudo ./snull_load Two interfaces created: sn0, sn1
LINUX ADMINISTRATION
Introduction to the Kernel and Device Drivers
An Introduction to Device Drivers
Chapter 2: The Linux System Part 2
CS 6560 Operating System Design
Introduction to computers
CS 6560 Operating System Design Kernel Loadable Modules
Computer System Laboratory
Presentation transcript:

The ‘net_device’ structure A look at the main kernel-object concerned with a Linux system’s network interface controller

‘data consolidation’ Experienced software developers usually employ a ‘locality of reference’ strategy to simplify design and maintenance of code This principle says: Things which logically are related should be kept together Accordingly, all the information that the system needs to keep track of about a network interface is put into a single struct

‘struct net_device’ lo nextprev dev_base_head struct net_device eth0 struct net_device eth1 struct net_device About 90 separate fields belong to each ‘net_device’ member of this doubly-linked list

A few examples… struct net_device { charname[ IFNAMSIZ ]; intifindex;\ /* inteface index */ unsigned intmtu; /* maximum transmission unit */ unsigned chardev_addr[ MAX_ADDR_LEN ]; /* hardware address */ void*ip_pointer; /* points to IF’s IPv4 specific data */ unsigned intflags; unsigned longtrans_start; /* time (in jiffies) of last transmission */ struct net_device_statsstats; /* 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… This analogy isn’t perfect (i.e., key differences) open() release() write() read() llseek() ioctl() … open() stop() hard_start_xmit() get_stats() set_mac_address() do_ioctl() … struct file_operations struct net_device

‘struct net_device_stats’ Notice that the ‘net_device’ object contains a sub-structure for storing device statistics struct net_device_stats { unsigned longrx_packets;/* total packets received */ unsigned longtx_packets;/* total packets transmitted */ unsigned longrx_bytes;/* total bytes received */ unsigned longtx_bytes;/* total bytes transmitted */ unsigned longrx_errors;/* bad packets received */ unsigned longtx_errors;/* packet transmit problems */ … };

‘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’ packet data skb struct sk_buff

Kernel’s 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: Most header-files are in Those header-files that are CPU-specific are in

Our directory tree… / sbinbinusrhome ifconfig … lsmod insmod rmmod … ping … cat echo ls vi dmesg … src include linuxasm netdevice.h if.h … module.h pci.h … web cruse … io.h uaccess.h unistd.h … our course demos cs686 linux

This is the header-file where you will find the ‘struct net_device’ definition (and the ‘struct net_device_stats’ definition as well) And if you want to see how ‘struct sk_buff’ is defined, then look in NOTE: The kernel developers often move structure-definitions to different headers in new versions of the kernel source-code

Our ‘netdevs.c’ module We can create a Loadable Kernel Module that lets us see current information stored in the kernel’s data-structures Our example-module ‘netdevs.c’ does this It needs a special command-sequence to be compiled, then a special command to be installed as a ‘live’ add-on our running Linux operating system’s kernel

‘mmake.cpp’ You can download this utility-program from our cs686 website and compile it with g++, like this: $ cp /home/web/cruse/cs686/mmake.cpp. $ g++ mmake.cpp –o mmake Then you can use it to automate the steps required for compiling an LKM, like this: $./mmake netdevs

‘/sbin/insmod’ When you have compiled our ‘netdevs.c’ source-file, you will have a kernel-object file named ‘netdevs.ko’ and you can use the ‘insmod’ command to install it: $ /sbin/insmod netdevs.ko When it is installed, this LKM creates a pseudo-file (in the ‘/proc’ directory) that you can send to your screen with ‘cat’: $ cat /proc/netdevs

‘/sbin/rmmod’ If you decide you would like to modify the output from your ‘/proc/netdevs’ file, you can remove ‘netdevs.ko’ from the kernel, edit the module’s source-code, recompile the ‘netdevs.c’ file with ‘mmake’, and then install the new version of ‘netdevs.ko’: $ /sbin/rmmod netdevs.ko

In-class exercise #1 Modify the output shown by ‘/proc/netdevs’ so that the current state of each interface (i.e., UP or DOWN) will get displayed HINT: The kernel uses a status-bit in the ‘flags’ field of a ‘struct net_device’ object to keep track of whether the device is now ‘up’ or ‘down’ (compare ‘/sbin/ifconfig –a) Look in the header-file to find out how bits of the ‘flags’ field are used

Two coding approaches… One way to write your solution for in-class exercise #1 is to add a line like this: But a different solution which produces the same effect avoids the ‘if-else’ construct: if ( dev->flags & IFF_UP ) len += sprintf( buf+len, “UP” ); elselen += sprintf( buf+len, “DOWN “ ); char*state[ 2 ] = { “DOWN”, “UP” };// an array of string-pointers … 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 station’s network interfaces (from the ‘ifconfig’ output) and see if you can enhance our ‘netdevs.c’ demo so it’s pseudo-file will display that extra item of information (e.g., dev->stats.tx_bytes)