SlideShare ist ein Scribd-Unternehmen logo
1 von 50
Downloaden Sie, um offline zu lesen
Fun with Network Interfaces
Shmulik Ladkani
March 2016
This work is licensed under a Creative Commons Attribution 4.0 International License.
On the Menu
● Linux network stack, a (quick) intro
○ What’s this net_device anyway?
○ Programming interfaces
○ Frame reception and transmission
● Logical network interfaces
○ What?
○ Why?
○ Examples
○ Examples
○ Examples
Agenda
● Goals
○ Strengthen foundations
○ Explain interaction of main network stack components
○ Familiarize with building blocks of virtual networks
○ Ease of further research
● Non Goals
○ Mastering device driver programming
○ How network gear operates in detail
○ Specific component deep dive
Disclaimer
● Linux network stack is huge and complex
○ Let’s skip some fine details
Network Stack Intro
Diagram by Arnout Vandecappelle
Network Stack Intro
Take II
Diagram by Jan Engelhardt
Network Stack Intro
Take III
Network Stack Layers
L7
L4
L3
L2
Device-specific L2
network core
ipv4
udptcp icmp igmp gre ipip ...
device drivers
arp ipv6 pppoe ...
usermode app
socket api
Network Core
● Generic functionalities of a network device
● RX
○ Processing of incoming frames
○ Delivery to upper protocols
● TX
○ Queuing
○ Final processing
○ Hand-over to driver’s transmit method
Struct net_device
● Represents a network interface
● One for each network device in the system
○ Either physical device or logical (software) one
Struct net_device
Common properties
● Identified by a ‘name’ and ‘ifindex’
○ Unique to a network namespace
● Has BSD-like ‘flags’
IFF_UP, IFF_LOOPBACK, IFF_POINTOPOINT, IFF_NOARP, IFF_PROMISC...
● Has ‘features’
NETIF_F_SG_BIT, NETIF_F_HW_CSUM_BIT, NETIF_F_GSO_BIT,
NETIF_F_GRO_BIT, NETIF_F_LRO_BIT, NETIF_F_RXHASH_BIT,
NETIF_F_RXCSUM_BIT...
● Has many other fields...
● Holds associated device operations
const struct net_device_ops *netdev_ops;
Struct net_device_ops
● Interface. Defines all device methods
○ Driver implements
● E.g. e1000e_netdev_ops, bcmgenet_netdev_ops …
○ Network-core uses
● Fat interface…
○ 44 methods in v3.4
○ 59 methods in v3.14
○ 68 methods in v4.4
○ Few methods #ifdef protected
○ Some are optional
Struct net_device_ops
Common methods
● ndo_open()
○ Upon device transition to UP state
● ndo_stop()
○ Upon device transition to DOWN state
● ndo_start_xmit()
○ When a packet needs to be transmitted
● ndo_set_features()
○ Update device configuration to new features
● ndo_get_stats()
○ Get device usage statistics
● ndo_set_mac_address()
○ When MAC needs to be changed
● Many more...
Stack’s core interfaces
For device implementers
● napi_schedule()
○ Schedule driver’s poll routine to be called
● netif_receive_skb()
○ Pass a received buffer to network core processing
○ Few other interfaces exist
● netif_stop_queue()
○ Stop upper layer from calling device’s ndo_start_xmit
● netif_wake_queue()
○ Allow upper layer to call device’s ndo_start_xmit
● More...
Frame Reception
__netif_receive_skb_core()
● Deliver to network taps (protocol sniffers)
● Ingress classification and filtering
● VLAN packet handling
● Invoke a specially registered ‘rx_handler’
○ May consume packet
● Deliver to the registered L3 protocol handler
○ No handler? Drop
net_device->rx_handler
● Per device registered function
○ Called internally from ‘__netif_receive_skb_core’
○ Prior delivery to protocol handlers
● Allows special L2 processing during RX
● Semantics
○ At most one registered ‘rx_handler’ per device
○ May consume the packet
● ‘netif_receive_skb’ will not further process it
○ May instruct ‘netif_receive_skb’ to do “another round”
● Notable users
○ bridge, openvswitch, bonding, team, macvlan, macvtap
Frame Transmission
dev_queue_xmit()
● Well, packet is set-up for transmission
○ Yeay! Let’s pass to driver’s ndo_start_xmit() !
○ Wait a minute… literally
● Device has no queue?
○ Final preps & xmit
● Device has a queue?
○ Enqueue the packet
● Using device queueing discipline
○ Kick the queue
○ Will eventually get to “final preps & xmit”
● Synchronously or asynchronously
● According to discipline
Software Network Interfaces
a.k.a logical network interfaces
Software Net Device
● Not associated with a physical NIC
● Provides logical rx/tx functionality
○ By implementing the net_device interface
● Allows special-purpose packet processing
○ Without altering the network stack
Variants of Logical Devices
● Directly operate on specified net device(s)
○ Protocols (vlan, pppoe…)
○ Logical constructs (bridge, bonding, veth, macvlan...)
● Interact with higher network layers
○ IP based tunnels (ipip, gre, sit, l2tp…)
○ UDP based tunnels (vxlan, geneve, l2tp-udp…)
● Other constructs
○ May or may not interact with other net devices
○ lo, ppp, tun/tap, ifb...
Loopback
lo:
Loopback interface
static netdev_tx_t loopback_xmit(struct sk_buff *skb,
struct net_device *dev)
{
...
netif_rx(skb); // eventually gets to netif_receive_skb
}
Every transmitted packet is bounced back for reception
○ Using same device
network core
ipv4
lo
... ipv6 ... ...
VLAN
vlan: (circa 2.4)
802.1q Virtual LAN interface
● Has an underlying “link” net device
struct vlan_dev_priv {
u16 vlan_id;
struct net_device *real_dev;
…
● Xmit method
○ Tags the packet
○ Queues for transmission on the underlying device
vlan_tci = vlan->vlan_id;
vlan_tci |= …
skb = __vlan_hwaccel_put_tag(skb, vlan->vlan_proto, vlan_tci);
skb->dev = vlan->real_dev;
…
ret = dev_queue_xmit(skb);
TUN/TAP
● Device is associated with a usermode fd
○ write(fd) --> device RX
○ device TX --> ready to read(fd)
● Operation mode
○ tun: L3 packets
○ tap: L2 frames
tun/tap: (circa 2.4)
Usermode packet processing
tap0fd
network core
ipv4... ... ...
● Usermode VPN applications
○ Routing to the VPN subnet is directed to tun device
● E.g. 192.168.50.0/24 dev tun0
○ read(tun_fd, buf)
○ encrypt(buf)
○ encapsulate(buf)
○ send(tcp_sock, buf)
TUN use cases
● VM networking
○ Emulator exposes a tap for each VM NIC
○ Emulator traps VM xmit
○ Issues write(tap_fd)
○ Packet arrives at host’s net stack via tap device
TAP use cases
VETH
veth: (circa 2.6.24)
Virtual Ethernet Pair
● Local ethernet “wire”
● Comes as pair of virtual ethernet interfaces
● veth TX --> peer veth RX
○ And vice versa
network core
ipv4... ... ...
veth0 veth1
● Container networking
○ First veth in host’s net namespace
○ Peer veth in container’s net namespace
● Local links of a virtual network
● Network emulation
veth use cases
Bridge
Bridge:
802.1d Ethernet Bridging
● Software L2 forwarding switch
○ Expands the L2 network across various links
○ 802.1q VLAN capable circa 3.9
● Bridge has multiple slave devices (“ports”)
● rx_handler registered on slave devices
○ Picks output devices(s) based on FDB
○ Calls ‘dev_queue_xmit’ on output device
○ Packet consumed! Never enters L3 stack via input device
eth1 eth2eth0
br0
rx_handler() dev_queue_xmit()
● Same / different medium
○ Slave devices present L2 ethernet network
Bridging physical networks
wifi0 ethoa3eth1
br0
bnep0 usbnet1
Bridging virtual networks
VM A VM B
tap1 vxlan0tap0
br0
veth0
Container X
veth1
veth2
Container Y
veth3
tunnel to remote bridge
MACVLAN
MacVLAN: (circa 2.6.32)
MAC Address based VLANs
● Network segmentation based on destination MAC
● Macvlan devices have underlying “lower” device
○ Macvlans on same link have unique MAC addresses
● Macvlan xmit
○ Calls ‘dev_queue_xmit’ on lower device
● rx_handler registered on lower device
○ Look for a macvlan device based on packet’s dest-MAC
○ None found? Return “Pass” (normal processing)
○ Found? Change skb->dev to the macvlan dev, return “Another round”
rx_handler()
eth0
mvlan0 mvlan1 mvlan2
● Network segmentation
○ Where 802.1q VLAN can’t be used
MacVLAN use cases
eth0
eth0_data eth0_voip
54.6.30.15/24 10.0.5.94/16
VoIP Service
Internet Access Service
● Lightweight virtual network
○ For containers / VMs
○ Various operation modes
● MacVTAP (circa 2.6.34)
○ Each device has a tap-like FD interface
MacVLAN use cases
eth0
mvlan0 mvlan1 mvlan2
Container X Container Y Container Z
GRE
ip_gre: (circa 2.2)
GRE Tunnel, IP Based
● Global initialization
○ Register the IPPROTO_GRE transport protocol handler
ipv4
stack ipv6 ...
network core
gre
stack... ... ... ... ...
...
ip_gre: (circa 2.2)
GRE Tunnel, IP Based
● Per device initialization
○ Store tunnel instance parameters
○ E.g. encapsulating iph.saddr, iph.daddr
ipv4
stack ipv6 ...
network core
gre
stack... ... ... ... ...
...
gre0
54.90.24.7
gre1
81.104.12.5
ip_gre device
Transmit method
● Routing to remote subnet directed to gre device
○ E.g. 192.168.50.0/24 dev gre0
● Install the GRE header
● Consult IP routing for output decision
○ Based on tunnel parameters
● Install the encapsulating IP header
● Pass to IP stack for local output
ipv4
stack ipv6 ...
network core
gre
stack... ... ... ... ...
...
gre0 gre1
ip_gre device
Receive path
● Encapsulating packet arrives on a net device
● IP stack invokes the registered transport handler
● GRE handler looks-up for a matching tunnel instance
○ Based on encapsulating IP header fields
● Changes skb->dev to the matched tunnel device
● Skb points to inner packet
● Re-submit to network’s core RX path
ipv4
stack ipv6 ...
network core
gre
stack... ... ... ... ...
...
gre0 gre1
Bonding
bond: (circa 2.2)
Link Aggregation
● Aggregates multiple interfaces into a single “bond”
○ Various operating modes:
Round-robin, active-backup, broadcast, 802.3ad...
● Bond device has multiple “slave” devices
● Bond xmit
○ Calls ‘dev_queue_xmit’ on slave devices(s)
● rx_handler registered on slave devices
○ Changes skb->dev as the bond device, returns “Another round”
eth0 eth1
bond0
rx_handler()
dev_queue_xmit()
● Bandwidth aggregation
● Fault tolerance / HA
● L2 based Load Balancing
See similar ‘team’ driver (circa 3.3)
bond use cases
Summary
● Network stack brief
● net_device abstraction
● Logical network interfaces
○ Many covered!
○ Many others exist (see: ifb, vrf…)
● Questions?
● Contact me!

Weitere ähnliche Inhalte

Was ist angesagt?

The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecture
hugo lu
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
Brendan Gregg
 

Was ist angesagt? (20)

The linux networking architecture
The linux networking architectureThe linux networking architecture
The linux networking architecture
 
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDPDockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
DockerCon 2017 - Cilium - Network and Application Security with BPF and XDP
 
DPDK In Depth
DPDK In DepthDPDK In Depth
DPDK In Depth
 
DevConf 2014 Kernel Networking Walkthrough
DevConf 2014   Kernel Networking WalkthroughDevConf 2014   Kernel Networking Walkthrough
DevConf 2014 Kernel Networking Walkthrough
 
The Basic Introduction of Open vSwitch
The Basic Introduction of Open vSwitchThe Basic Introduction of Open vSwitch
The Basic Introduction of Open vSwitch
 
Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!Understanding eBPF in a Hurry!
Understanding eBPF in a Hurry!
 
Dpdk performance
Dpdk performanceDpdk performance
Dpdk performance
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
 
introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack introduction to linux kernel tcp/ip ptocotol stack
introduction to linux kernel tcp/ip ptocotol stack
 
Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01Library Operating System for Linux #netdev01
Library Operating System for Linux #netdev01
 
Faster packet processing in Linux: XDP
Faster packet processing in Linux: XDPFaster packet processing in Linux: XDP
Faster packet processing in Linux: XDP
 
Tutorial: Using GoBGP as an IXP connecting router
Tutorial: Using GoBGP as an IXP connecting routerTutorial: Using GoBGP as an IXP connecting router
Tutorial: Using GoBGP as an IXP connecting router
 
Linux kernel tracing
Linux kernel tracingLinux kernel tracing
Linux kernel tracing
 
BPF: Tracing and more
BPF: Tracing and moreBPF: Tracing and more
BPF: Tracing and more
 
DPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet ProcessingDPDK & Layer 4 Packet Processing
DPDK & Layer 4 Packet Processing
 
eBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux KerneleBPF - Rethinking the Linux Kernel
eBPF - Rethinking the Linux Kernel
 
Understanding DPDK
Understanding DPDKUnderstanding DPDK
Understanding DPDK
 
Understanding Open vSwitch
Understanding Open vSwitch Understanding Open vSwitch
Understanding Open vSwitch
 
Intel DPDK Step by Step instructions
Intel DPDK Step by Step instructionsIntel DPDK Step by Step instructions
Intel DPDK Step by Step instructions
 
DPDK in Containers Hands-on Lab
DPDK in Containers Hands-on LabDPDK in Containers Hands-on Lab
DPDK in Containers Hands-on Lab
 

Andere mochten auch

Windows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel DevelopersWindows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel Developers
Kernel TLV
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing Landscape
Kernel TLV
 
Interface between kernel and user space
Interface between kernel and user spaceInterface between kernel and user space
Interface between kernel and user space
Susant Sahani
 

Andere mochten auch (20)

FD.IO Vector Packet Processing
FD.IO Vector Packet ProcessingFD.IO Vector Packet Processing
FD.IO Vector Packet Processing
 
WiFi and the Beast
WiFi and the BeastWiFi and the Beast
WiFi and the Beast
 
Userfaultfd and Post-Copy Migration
Userfaultfd and Post-Copy MigrationUserfaultfd and Post-Copy Migration
Userfaultfd and Post-Copy Migration
 
Windows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel DevelopersWindows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel Developers
 
Hardware Probing in the Linux Kernel
Hardware Probing in the Linux KernelHardware Probing in the Linux Kernel
Hardware Probing in the Linux Kernel
 
Specializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network StackSpecializing the Data Path - Hooking into the Linux Network Stack
Specializing the Data Path - Hooking into the Linux Network Stack
 
Switchdev - No More SDK
Switchdev - No More SDKSwitchdev - No More SDK
Switchdev - No More SDK
 
Introduction to DPDK
Introduction to DPDKIntroduction to DPDK
Introduction to DPDK
 
Linux Security Overview
Linux Security OverviewLinux Security Overview
Linux Security Overview
 
Linux Kernel Cryptographic API and Use Cases
Linux Kernel Cryptographic API and Use CasesLinux Kernel Cryptographic API and Use Cases
Linux Kernel Cryptographic API and Use Cases
 
Modern Linux Tracing Landscape
Modern Linux Tracing LandscapeModern Linux Tracing Landscape
Modern Linux Tracing Landscape
 
grsecurity and PaX
grsecurity and PaXgrsecurity and PaX
grsecurity and PaX
 
FreeBSD and Drivers
FreeBSD and DriversFreeBSD and Drivers
FreeBSD and Drivers
 
Linux Locking Mechanisms
Linux Locking MechanismsLinux Locking Mechanisms
Linux Locking Mechanisms
 
Linux Kernel Init Process
Linux Kernel Init ProcessLinux Kernel Init Process
Linux Kernel Init Process
 
DMA Survival Guide
DMA Survival GuideDMA Survival Guide
DMA Survival Guide
 
High Performance Storage Devices in the Linux Kernel
High Performance Storage Devices in the Linux KernelHigh Performance Storage Devices in the Linux Kernel
High Performance Storage Devices in the Linux Kernel
 
Linux Interrupts
Linux InterruptsLinux Interrupts
Linux Interrupts
 
Interface between kernel and user space
Interface between kernel and user spaceInterface between kernel and user space
Interface between kernel and user space
 
Introduction to netlink in linux kernel (english)
Introduction to netlink in linux kernel (english)Introduction to netlink in linux kernel (english)
Introduction to netlink in linux kernel (english)
 

Ähnlich wie Fun with Network Interfaces

Ähnlich wie Fun with Network Interfaces (20)

Linux Network Filtering
Linux Network FilteringLinux Network Filtering
Linux Network Filtering
 
packet traveling (pre cloud)
packet traveling (pre cloud)packet traveling (pre cloud)
packet traveling (pre cloud)
 
Kubernetes from scratch at veepee sysadmins days 2019
Kubernetes from scratch at veepee   sysadmins days 2019Kubernetes from scratch at veepee   sysadmins days 2019
Kubernetes from scratch at veepee sysadmins days 2019
 
Adding IEEE 802.15.4 and 6LoWPAN to an Embedded Linux Device
Adding IEEE 802.15.4 and 6LoWPAN to an Embedded Linux DeviceAdding IEEE 802.15.4 and 6LoWPAN to an Embedded Linux Device
Adding IEEE 802.15.4 and 6LoWPAN to an Embedded Linux Device
 
Twisted
TwistedTwisted
Twisted
 
BGP Services IP Transit vs IP Peering
BGP Services  IP Transit vs IP PeeringBGP Services  IP Transit vs IP Peering
BGP Services IP Transit vs IP Peering
 
Networking in Openstack - Neutron 101
Networking in Openstack - Neutron 101Networking in Openstack - Neutron 101
Networking in Openstack - Neutron 101
 
Banog meetup August 30th, network device property as code
Banog meetup August 30th, network device property as codeBanog meetup August 30th, network device property as code
Banog meetup August 30th, network device property as code
 
Using Mikrotik Switch Features to Improve Your Network
Using Mikrotik Switch Features to Improve Your Network Using Mikrotik Switch Features to Improve Your Network
Using Mikrotik Switch Features to Improve Your Network
 
Run Your Own 6LoWPAN Based IoT Network
Run Your Own 6LoWPAN Based IoT NetworkRun Your Own 6LoWPAN Based IoT Network
Run Your Own 6LoWPAN Based IoT Network
 
Internet Protocol Deep-Dive
Internet Protocol Deep-DiveInternet Protocol Deep-Dive
Internet Protocol Deep-Dive
 
MTCNA Intro to routerOS
MTCNA Intro to routerOSMTCNA Intro to routerOS
MTCNA Intro to routerOS
 
Openstack Networking Internals - first part
Openstack Networking Internals - first partOpenstack Networking Internals - first part
Openstack Networking Internals - first part
 
Network LACP/Bonding/Teaming with Mikrotik
Network LACP/Bonding/Teaming with MikrotikNetwork LACP/Bonding/Teaming with Mikrotik
Network LACP/Bonding/Teaming with Mikrotik
 
Ake hedman why we need to unite and why vscp is a solution to a problem
Ake hedman  why we need to unite and why vscp is a solution to a problemAke hedman  why we need to unite and why vscp is a solution to a problem
Ake hedman why we need to unite and why vscp is a solution to a problem
 
Iot with-the-best & VSCP
Iot with-the-best & VSCPIot with-the-best & VSCP
Iot with-the-best & VSCP
 
[OpenStack Day in Korea 2015] Track 1-6 - 갈라파고스의 이구아나, 인프라에 오픈소스를 올리다. 그래서 보이...
[OpenStack Day in Korea 2015] Track 1-6 - 갈라파고스의 이구아나, 인프라에 오픈소스를 올리다. 그래서 보이...[OpenStack Day in Korea 2015] Track 1-6 - 갈라파고스의 이구아나, 인프라에 오픈소스를 올리다. 그래서 보이...
[OpenStack Day in Korea 2015] Track 1-6 - 갈라파고스의 이구아나, 인프라에 오픈소스를 올리다. 그래서 보이...
 
Demystifying Datacenter Clos
Demystifying Datacenter ClosDemystifying Datacenter Clos
Demystifying Datacenter Clos
 
MTCNA : Intro to RouterOS - Part 1
MTCNA : Intro to RouterOS - Part 1MTCNA : Intro to RouterOS - Part 1
MTCNA : Intro to RouterOS - Part 1
 
Mirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in GoMirko Damiani - An Embedded soft real time distributed system in Go
Mirko Damiani - An Embedded soft real time distributed system in Go
 

Mehr von Kernel TLV

Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
Kernel TLV
 

Mehr von Kernel TLV (13)

Building Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCCBuilding Network Functions with eBPF & BCC
Building Network Functions with eBPF & BCC
 
SGX Trusted Execution Environment
SGX Trusted Execution EnvironmentSGX Trusted Execution Environment
SGX Trusted Execution Environment
 
Fun with FUSE
Fun with FUSEFun with FUSE
Fun with FUSE
 
Kernel Proc Connector and Containers
Kernel Proc Connector and ContainersKernel Proc Connector and Containers
Kernel Proc Connector and Containers
 
Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545Bypassing ASLR Exploiting CVE 2015-7545
Bypassing ASLR Exploiting CVE 2015-7545
 
Present Absence of Linux Filesystem Security
Present Absence of Linux Filesystem SecurityPresent Absence of Linux Filesystem Security
Present Absence of Linux Filesystem Security
 
OpenWrt From Top to Bottom
OpenWrt From Top to BottomOpenWrt From Top to Bottom
OpenWrt From Top to Bottom
 
Make Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance ToolsMake Your Containers Faster: Linux Container Performance Tools
Make Your Containers Faster: Linux Container Performance Tools
 
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
Emerging Persistent Memory Hardware and ZUFS - PM-based File Systems in User ...
 
File Systems: Why, How and Where
File Systems: Why, How and WhereFile Systems: Why, How and Where
File Systems: Why, How and Where
 
KernelTLV Speaker Guidelines
KernelTLV Speaker GuidelinesKernelTLV Speaker Guidelines
KernelTLV Speaker Guidelines
 
Userfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future DevelopmentUserfaultfd: Current Features, Limitations and Future Development
Userfaultfd: Current Features, Limitations and Future Development
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 

Kürzlich hochgeladen

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 

Kürzlich hochgeladen (20)

Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

Fun with Network Interfaces

  • 1. Fun with Network Interfaces Shmulik Ladkani March 2016 This work is licensed under a Creative Commons Attribution 4.0 International License.
  • 2. On the Menu ● Linux network stack, a (quick) intro ○ What’s this net_device anyway? ○ Programming interfaces ○ Frame reception and transmission ● Logical network interfaces ○ What? ○ Why? ○ Examples ○ Examples ○ Examples
  • 3. Agenda ● Goals ○ Strengthen foundations ○ Explain interaction of main network stack components ○ Familiarize with building blocks of virtual networks ○ Ease of further research ● Non Goals ○ Mastering device driver programming ○ How network gear operates in detail ○ Specific component deep dive
  • 4. Disclaimer ● Linux network stack is huge and complex ○ Let’s skip some fine details
  • 6. Diagram by Arnout Vandecappelle
  • 8. Diagram by Jan Engelhardt
  • 10. Network Stack Layers L7 L4 L3 L2 Device-specific L2 network core ipv4 udptcp icmp igmp gre ipip ... device drivers arp ipv6 pppoe ... usermode app socket api
  • 11. Network Core ● Generic functionalities of a network device ● RX ○ Processing of incoming frames ○ Delivery to upper protocols ● TX ○ Queuing ○ Final processing ○ Hand-over to driver’s transmit method
  • 12. Struct net_device ● Represents a network interface ● One for each network device in the system ○ Either physical device or logical (software) one
  • 13. Struct net_device Common properties ● Identified by a ‘name’ and ‘ifindex’ ○ Unique to a network namespace ● Has BSD-like ‘flags’ IFF_UP, IFF_LOOPBACK, IFF_POINTOPOINT, IFF_NOARP, IFF_PROMISC... ● Has ‘features’ NETIF_F_SG_BIT, NETIF_F_HW_CSUM_BIT, NETIF_F_GSO_BIT, NETIF_F_GRO_BIT, NETIF_F_LRO_BIT, NETIF_F_RXHASH_BIT, NETIF_F_RXCSUM_BIT... ● Has many other fields... ● Holds associated device operations const struct net_device_ops *netdev_ops;
  • 14. Struct net_device_ops ● Interface. Defines all device methods ○ Driver implements ● E.g. e1000e_netdev_ops, bcmgenet_netdev_ops … ○ Network-core uses ● Fat interface… ○ 44 methods in v3.4 ○ 59 methods in v3.14 ○ 68 methods in v4.4 ○ Few methods #ifdef protected ○ Some are optional
  • 15. Struct net_device_ops Common methods ● ndo_open() ○ Upon device transition to UP state ● ndo_stop() ○ Upon device transition to DOWN state ● ndo_start_xmit() ○ When a packet needs to be transmitted ● ndo_set_features() ○ Update device configuration to new features ● ndo_get_stats() ○ Get device usage statistics ● ndo_set_mac_address() ○ When MAC needs to be changed ● Many more...
  • 16. Stack’s core interfaces For device implementers ● napi_schedule() ○ Schedule driver’s poll routine to be called ● netif_receive_skb() ○ Pass a received buffer to network core processing ○ Few other interfaces exist ● netif_stop_queue() ○ Stop upper layer from calling device’s ndo_start_xmit ● netif_wake_queue() ○ Allow upper layer to call device’s ndo_start_xmit ● More...
  • 17. Frame Reception __netif_receive_skb_core() ● Deliver to network taps (protocol sniffers) ● Ingress classification and filtering ● VLAN packet handling ● Invoke a specially registered ‘rx_handler’ ○ May consume packet ● Deliver to the registered L3 protocol handler ○ No handler? Drop
  • 18. net_device->rx_handler ● Per device registered function ○ Called internally from ‘__netif_receive_skb_core’ ○ Prior delivery to protocol handlers ● Allows special L2 processing during RX ● Semantics ○ At most one registered ‘rx_handler’ per device ○ May consume the packet ● ‘netif_receive_skb’ will not further process it ○ May instruct ‘netif_receive_skb’ to do “another round” ● Notable users ○ bridge, openvswitch, bonding, team, macvlan, macvtap
  • 19. Frame Transmission dev_queue_xmit() ● Well, packet is set-up for transmission ○ Yeay! Let’s pass to driver’s ndo_start_xmit() ! ○ Wait a minute… literally ● Device has no queue? ○ Final preps & xmit ● Device has a queue? ○ Enqueue the packet ● Using device queueing discipline ○ Kick the queue ○ Will eventually get to “final preps & xmit” ● Synchronously or asynchronously ● According to discipline
  • 20. Software Network Interfaces a.k.a logical network interfaces
  • 21. Software Net Device ● Not associated with a physical NIC ● Provides logical rx/tx functionality ○ By implementing the net_device interface ● Allows special-purpose packet processing ○ Without altering the network stack
  • 22. Variants of Logical Devices ● Directly operate on specified net device(s) ○ Protocols (vlan, pppoe…) ○ Logical constructs (bridge, bonding, veth, macvlan...) ● Interact with higher network layers ○ IP based tunnels (ipip, gre, sit, l2tp…) ○ UDP based tunnels (vxlan, geneve, l2tp-udp…) ● Other constructs ○ May or may not interact with other net devices ○ lo, ppp, tun/tap, ifb...
  • 24. lo: Loopback interface static netdev_tx_t loopback_xmit(struct sk_buff *skb, struct net_device *dev) { ... netif_rx(skb); // eventually gets to netif_receive_skb } Every transmitted packet is bounced back for reception ○ Using same device network core ipv4 lo ... ipv6 ... ...
  • 25. VLAN
  • 26. vlan: (circa 2.4) 802.1q Virtual LAN interface ● Has an underlying “link” net device struct vlan_dev_priv { u16 vlan_id; struct net_device *real_dev; … ● Xmit method ○ Tags the packet ○ Queues for transmission on the underlying device vlan_tci = vlan->vlan_id; vlan_tci |= … skb = __vlan_hwaccel_put_tag(skb, vlan->vlan_proto, vlan_tci); skb->dev = vlan->real_dev; … ret = dev_queue_xmit(skb);
  • 28. ● Device is associated with a usermode fd ○ write(fd) --> device RX ○ device TX --> ready to read(fd) ● Operation mode ○ tun: L3 packets ○ tap: L2 frames tun/tap: (circa 2.4) Usermode packet processing tap0fd network core ipv4... ... ...
  • 29. ● Usermode VPN applications ○ Routing to the VPN subnet is directed to tun device ● E.g. 192.168.50.0/24 dev tun0 ○ read(tun_fd, buf) ○ encrypt(buf) ○ encapsulate(buf) ○ send(tcp_sock, buf) TUN use cases
  • 30. ● VM networking ○ Emulator exposes a tap for each VM NIC ○ Emulator traps VM xmit ○ Issues write(tap_fd) ○ Packet arrives at host’s net stack via tap device TAP use cases
  • 31. VETH
  • 32. veth: (circa 2.6.24) Virtual Ethernet Pair ● Local ethernet “wire” ● Comes as pair of virtual ethernet interfaces ● veth TX --> peer veth RX ○ And vice versa network core ipv4... ... ... veth0 veth1
  • 33. ● Container networking ○ First veth in host’s net namespace ○ Peer veth in container’s net namespace ● Local links of a virtual network ● Network emulation veth use cases
  • 35. Bridge: 802.1d Ethernet Bridging ● Software L2 forwarding switch ○ Expands the L2 network across various links ○ 802.1q VLAN capable circa 3.9 ● Bridge has multiple slave devices (“ports”) ● rx_handler registered on slave devices ○ Picks output devices(s) based on FDB ○ Calls ‘dev_queue_xmit’ on output device ○ Packet consumed! Never enters L3 stack via input device eth1 eth2eth0 br0 rx_handler() dev_queue_xmit()
  • 36. ● Same / different medium ○ Slave devices present L2 ethernet network Bridging physical networks wifi0 ethoa3eth1 br0 bnep0 usbnet1
  • 37. Bridging virtual networks VM A VM B tap1 vxlan0tap0 br0 veth0 Container X veth1 veth2 Container Y veth3 tunnel to remote bridge
  • 39. MacVLAN: (circa 2.6.32) MAC Address based VLANs ● Network segmentation based on destination MAC ● Macvlan devices have underlying “lower” device ○ Macvlans on same link have unique MAC addresses ● Macvlan xmit ○ Calls ‘dev_queue_xmit’ on lower device ● rx_handler registered on lower device ○ Look for a macvlan device based on packet’s dest-MAC ○ None found? Return “Pass” (normal processing) ○ Found? Change skb->dev to the macvlan dev, return “Another round” rx_handler() eth0 mvlan0 mvlan1 mvlan2
  • 40. ● Network segmentation ○ Where 802.1q VLAN can’t be used MacVLAN use cases eth0 eth0_data eth0_voip 54.6.30.15/24 10.0.5.94/16 VoIP Service Internet Access Service
  • 41. ● Lightweight virtual network ○ For containers / VMs ○ Various operation modes ● MacVTAP (circa 2.6.34) ○ Each device has a tap-like FD interface MacVLAN use cases eth0 mvlan0 mvlan1 mvlan2 Container X Container Y Container Z
  • 42. GRE
  • 43. ip_gre: (circa 2.2) GRE Tunnel, IP Based ● Global initialization ○ Register the IPPROTO_GRE transport protocol handler ipv4 stack ipv6 ... network core gre stack... ... ... ... ... ...
  • 44. ip_gre: (circa 2.2) GRE Tunnel, IP Based ● Per device initialization ○ Store tunnel instance parameters ○ E.g. encapsulating iph.saddr, iph.daddr ipv4 stack ipv6 ... network core gre stack... ... ... ... ... ... gre0 54.90.24.7 gre1 81.104.12.5
  • 45. ip_gre device Transmit method ● Routing to remote subnet directed to gre device ○ E.g. 192.168.50.0/24 dev gre0 ● Install the GRE header ● Consult IP routing for output decision ○ Based on tunnel parameters ● Install the encapsulating IP header ● Pass to IP stack for local output ipv4 stack ipv6 ... network core gre stack... ... ... ... ... ... gre0 gre1
  • 46. ip_gre device Receive path ● Encapsulating packet arrives on a net device ● IP stack invokes the registered transport handler ● GRE handler looks-up for a matching tunnel instance ○ Based on encapsulating IP header fields ● Changes skb->dev to the matched tunnel device ● Skb points to inner packet ● Re-submit to network’s core RX path ipv4 stack ipv6 ... network core gre stack... ... ... ... ... ... gre0 gre1
  • 48. bond: (circa 2.2) Link Aggregation ● Aggregates multiple interfaces into a single “bond” ○ Various operating modes: Round-robin, active-backup, broadcast, 802.3ad... ● Bond device has multiple “slave” devices ● Bond xmit ○ Calls ‘dev_queue_xmit’ on slave devices(s) ● rx_handler registered on slave devices ○ Changes skb->dev as the bond device, returns “Another round” eth0 eth1 bond0 rx_handler() dev_queue_xmit()
  • 49. ● Bandwidth aggregation ● Fault tolerance / HA ● L2 based Load Balancing See similar ‘team’ driver (circa 3.3) bond use cases
  • 50. Summary ● Network stack brief ● net_device abstraction ● Logical network interfaces ○ Many covered! ○ Many others exist (see: ifb, vrf…) ● Questions? ● Contact me!