FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
tuntap.c File Reference

TunTap Kernel stack (reverse) punt/inject path. More...

+ Include dependency graph for tuntap.c:

Go to the source code of this file.

Data Structures

struct  subif_address_t
 
struct  tuntap_per_thread_t
 TUNTAP per thread struct. More...
 
struct  tuntap_main_t
 TUNTAP node main state. More...
 
struct  in6_ifreq
 workaround for a known include file bug. More...
 

Functions

static void tuntap_punt_frame (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
 TX the tun/tap frame. More...
 
static void tuntap_nopunt_frame (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
 Free the tun/tap frame. More...
 
static uword tuntap_tx (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
 tuntap_tx More...
 
static uword tuntap_rx (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
 TUNTAP receive node. More...
 
static clib_error_ttuntap_read_ready (clib_file_t *uf)
 Gets called when file descriptor is ready from epoll. More...
 
static clib_error_ttuntap_exit (vlib_main_t *vm)
 Clean up the tun/tap device. More...
 
static clib_error_ttuntap_config (vlib_main_t *vm, unformat_input_t *input)
 CLI function for tun/tap config. More...
 
void tuntap_ip4_add_del_interface_address (ip4_main_t *im, uword opaque, u32 sw_if_index, ip4_address_t *address, u32 address_length, u32 if_address_index, u32 is_delete)
 Add or Del IP4 address to tun/tap interface. More...
 
void tuntap_ip6_add_del_interface_address (ip6_main_t *im, uword opaque, u32 sw_if_index, ip6_address_t *address, u32 address_length, u32 if_address_index, u32 is_delete)
 Add or Del tun/tap interface address. More...
 
 VNET_HW_INTERFACE_CLASS (tuntap_interface_class, static)
 
static u8format_tuntap_interface_name (u8 *s, va_list *args)
 Format tun/tap interface name. More...
 
static uword tuntap_intfc_tx (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
 TX packet out tun/tap. More...
 
 VNET_DEVICE_CLASS (tuntap_dev_class, static)
 
static clib_error_ttuntap_init (vlib_main_t *vm)
 tun/tap node init More...
 

Variables

static vnet_device_class_t tuntap_dev_class
 
static vnet_hw_interface_class_t tuntap_interface_class
 
static tuntap_main_t tuntap_main
 
static vlib_node_registration_t tuntap_tx_node
 (constructor) VLIB_REGISTER_NODE (tuntap_tx_node) More...
 
static char * tuntap_rx_error_strings []
 TUNTAP_RX error strings. More...
 
static vlib_node_registration_t tuntap_rx_node
 (constructor) VLIB_REGISTER_NODE (tuntap_rx_node) More...
 

Detailed Description

TunTap Kernel stack (reverse) punt/inject path.

This driver runs in one of two distinct modes:

  • "punt/inject" mode, where we send pkts not otherwise processed by the forwarding to the Linux kernel stack, and
  • "normal interface" mode, where we treat the Linux kernel stack as a peer.

By default, we select punt/inject mode.

Definition in file tuntap.c.

Function Documentation

◆ format_tuntap_interface_name()

static u8* format_tuntap_interface_name ( u8 s,
va_list *  args 
)
static

Format tun/tap interface name.

Parameters
*s- u8 - formatter string
*args- va_list
Returns
*s - u8 - formatted string

Definition at line 962 of file tuntap.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tuntap_config()

static clib_error_t* tuntap_config ( vlib_main_t vm,
unformat_input_t input 
)
static

CLI function for tun/tap config.

Parameters
*vm- vlib_main_t
*input- unformat_input_t
Returns
error - clib_error_t

Definition at line 486 of file tuntap.c.

+ Here is the call graph for this function:

◆ tuntap_exit()

static clib_error_t* tuntap_exit ( vlib_main_t vm)
static

Clean up the tun/tap device.

Parameters
*vm- vlib_main_t
Returns
error - clib_error_t

Definition at line 436 of file tuntap.c.

+ Here is the call graph for this function:

◆ tuntap_init()

static clib_error_t* tuntap_init ( vlib_main_t vm)
static

tun/tap node init

Parameters
*vm- vlib_main_t
Returns
error - clib_error_t

Definition at line 1013 of file tuntap.c.

+ Here is the call graph for this function:

◆ tuntap_intfc_tx()

static uword tuntap_intfc_tx ( vlib_main_t vm,
vlib_node_runtime_t node,
vlib_frame_t frame 
)
static

TX packet out tun/tap.

Parameters
*vm- vlib_main_t
*node- vlib_node_runtime_t
*frame- vlib_frame_t
Returns
n_buffers - uword - Packets transmitted

Definition at line 981 of file tuntap.c.

+ Here is the call graph for this function:

◆ tuntap_ip4_add_del_interface_address()

void tuntap_ip4_add_del_interface_address ( ip4_main_t im,
uword  opaque,
u32  sw_if_index,
ip4_address_t address,
u32  address_length,
u32  if_address_index,
u32  is_delete 
)

Add or Del IP4 address to tun/tap interface.

Parameters
*im- ip4_main_t
opaque- uword
sw_if_index- u32
*address- ip4_address_t
is_delete- u32

Tuntap disabled, or using a "normal" interface.

See if we already know about this subif

Definition at line 698 of file tuntap.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tuntap_ip6_add_del_interface_address()

void tuntap_ip6_add_del_interface_address ( ip6_main_t im,
uword  opaque,
u32  sw_if_index,
ip6_address_t *  address,
u32  address_length,
u32  if_address_index,
u32  is_delete 
)

Add or Del tun/tap interface address.

Both the v6 interface address API and the way ifconfig displays subinterfaces differ from their v4 counterparts. The code given here seems to work but YMMV.

Parameters
*im- ip6_main_t
opaque- uword
sw_if_index- u32
*address- ip6_address_t
address_length- u32
if_address_index- u32
is_delete- u32

Definition at line 813 of file tuntap.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tuntap_nopunt_frame()

static void tuntap_nopunt_frame ( vlib_main_t vm,
vlib_node_runtime_t node,
vlib_frame_t frame 
)
static

Free the tun/tap frame.

Parameters
*vm- vlib_main_t
*node- vlib_node_runtime_t
*frame- vlib_frame_t

Definition at line 936 of file tuntap.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tuntap_punt_frame()

static void tuntap_punt_frame ( vlib_main_t vm,
vlib_node_runtime_t node,
vlib_frame_t frame 
)
static

TX the tun/tap frame.

Parameters
*vm- vlib_main_t
*node- vlib_node_runtime_t
*frame- vlib_frame_t

Definition at line 920 of file tuntap.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tuntap_read_ready()

static clib_error_t* tuntap_read_ready ( clib_file_t uf)
static

Gets called when file descriptor is ready from epoll.

Parameters
*uf- clib_file_t
Returns
error - clib_error_t

Definition at line 420 of file tuntap.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ tuntap_rx()

static uword tuntap_rx ( vlib_main_t vm,
vlib_node_runtime_t node,
vlib_frame_t frame 
)
static

TUNTAP receive node.

Node Identifier:
tuntap-rx
Parameters
*vm- vlib_main_t
*node- vlib_node_runtime_t
*frame- vlib_frame_t
Returns
rc - uword

Make sure we have some RX buffers.

Allocate RX buffers from end of rx_buffers. Turn them into iovecs to pass to readv.

We should have enough buffers left for an MTU sized packet.

Interface counters for tuntap interface.

Definition at line 241 of file tuntap.c.

+ Here is the call graph for this function:

◆ tuntap_tx()

static uword tuntap_tx ( vlib_main_t vm,
vlib_node_runtime_t node,
vlib_frame_t frame 
)
static

tuntap_tx

Node Identifier:
tuntap-tx

Output node, writes the buffers comprising the incoming frame to the tun/tap device, aka hands them to the Linux kernel stack.

Parameters
*vm- vlib_main_t
*node- vlib_node_runtime_t
*frame- vlib_frame_t
Returns
rc - uword

VLIB buffer chain -> Unix iovec(s).

The normal interface path flattens the buffer chain

Definition at line 147 of file tuntap.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ VNET_DEVICE_CLASS()

VNET_DEVICE_CLASS ( tuntap_dev_class  ,
static   
)
+ Here is the caller graph for this function:

◆ VNET_HW_INTERFACE_CLASS()

VNET_HW_INTERFACE_CLASS ( tuntap_interface_class  ,
static   
)
+ Here is the caller graph for this function:

Variable Documentation

◆ tuntap_dev_class

vnet_device_class_t tuntap_dev_class
static

Definition at line 54 of file tuntap.c.

◆ tuntap_interface_class

vnet_hw_interface_class_t tuntap_interface_class
static

Definition at line 55 of file tuntap.c.

◆ tuntap_main

tuntap_main_t tuntap_main
static
Initial value:
= {
.tun_name = "vnet",
.mtu_bytes = 4096 + 256,
}

Definition at line 125 of file tuntap.c.

◆ tuntap_rx_error_strings

char* tuntap_rx_error_strings[]
static
Initial value:
= {
"unknown packet type",
}

TUNTAP_RX error strings.

Definition at line 394 of file tuntap.c.

◆ tuntap_rx_node

vlib_node_registration_t tuntap_rx_node
static
Initial value:
= {
.function = tuntap_rx,
.name = "tuntap-rx",
.sibling_of = "device-input",
.state = VLIB_NODE_STATE_INTERRUPT,
.vector_size = 4,
.n_errors = 1,
.error_strings = tuntap_rx_error_strings,
}
static uword tuntap_rx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
TUNTAP receive node.
Definition: tuntap.c:241
#define VLIB_NODE_FLAG_TRACE_SUPPORTED
Definition: node.h:305
static char * tuntap_rx_error_strings[]
TUNTAP_RX error strings.
Definition: tuntap.c:394

(constructor) VLIB_REGISTER_NODE (tuntap_rx_node)

Definition at line 399 of file tuntap.c.

◆ tuntap_tx_node

vlib_node_registration_t tuntap_tx_node
static
Initial value:
= {
.function = tuntap_tx,
.name = "tuntap-tx",
.vector_size = 4,
}
static uword tuntap_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
tuntap_tx
Definition: tuntap.c:147

(constructor) VLIB_REGISTER_NODE (tuntap_tx_node)

Definition at line 221 of file tuntap.c.