Skip to content

tuntap ​

tuntap 的组件名称为 tuntap, 相关内核选项为

ini
# Device Drivers
# -> Network device support
# -> Network core driver support
# -> Universal TUN/TAP device driver support
CONFIG_TUN=y

检查工具为

bash
#!/bin/bash

source ./cmd_utils.sh
source ./kernel_config_utils.sh
source ./net_utils.sh

tuntap_check() {
    if ! kernel_config_check CONFIG_TUN tun; then
        return 1
    fi

    local ifname="dodo"

    netif_delete $ifname

    if ! ${IP_CMD} tuntap add mode tap name $ifname; then
        echo "create tun failed"
        return 1
    fi
    if ! netif_check $ifname; then
        echo "netif not exist: ifname $ifname"
        return 1
    fi

    netif_delete $ifname
    return 0
}

veth ​

veth 的组件名称为 veth, 相关内核选项为

ini
# Device Drivers
# -> Network device support
# -> Network core driver support
# -> Virtual ethernet pair device
CONFIG_VETH=y

检查工具为

bash
#!/bin/bash

source ./cmd_utils.sh
source ./kernel_config_utils.sh
source ./net_utils.sh

veth_check() {
    local is_error=false

    if ! kernel_config_check CONFIG_VETH veth; then
        return 1
    fi

    ifname="dodo"
    peer_ifname="lala"

    netif_delete $ifname
    netif_delete $peer_ifname
    while :
    do
        if ! ${IP_CMD} link add name $ifname type veth peer name $peer_ifname; then
            echo "create veth failed"
            is_error=true
            break
        fi
        if ! netif_check $ifname; then
            echo "netif not exist: ifname $ifname"
            is_error=true
            break
        fi
        if ! netif_check $peer_ifname; then
            echo "netif not exist: peer_ifname $peer_ifname"
            is_error=true
            break
        fi

        if ! ${ETHTOOL_CMD} --show-channels $ifname > /dev/null 2>&1; then
            echo "veth not support multi channels: ifname $ifname"
            is_error=true
            break
        fi
        if ! ${ETHTOOL_CMD} --show-channels $peer_ifname > /dev/null 2>&1; then
            echo "veth not support multi channels: peer_ifname $peer_ifname"
            is_error=true
            break
        fi

        break
    done
    netif_delete $ifname
    netif_delete $peer_ifname
    if [ "$is_error" == "true" ]; then
        return 1
    fi

    return 0
}

veth 网口多队列 ​

veth 网口多队列支持在 Linux v5.15 版本中引入, 相关提交为 4752eeb3d891c27905a8fdf4d80e899c0efd4ec7.

VXLAN ​

VXLAN 的组件名称为 vxlan, 相关内核选项为

ini
# Device Drivers
# -> Network device support
# -> Network core driver support
# -> Virtual eXtensible Local Area Network (VXLAN)
CONFIG_VXLAN=y

检查工具为

bash
#!/bin/bash

source ./cmd_utils.sh
source ./kernel_config_utils.sh
source ./net_utils.sh

vxlan_check() {
    if ! kernel_config_check CONFIG_VXLAN vxlan; then
        return 1
    fi

    ifname="dodo"

    netif_delete $ifname

    if ! ${IP_CMD} link add $ifname type vxlan id 66 group 239.1.1.1 dev lo dstport 4789; then
        echo "create tun failed"
        return 1
    fi
    if ! netif_check $ifname; then
        echo "netif not exist: ifname $ifname"
        return 1
    fi

    netif_delete $ifname
    return 0
}

以太网桥接 ​

以太网桥接的组件名称为 ethernet_bridging, 相关内核选项为

ini
# Networking support
# -> Networking options
# -> 802.1d Ethernet Bridging
CONFIG_BRIDGE=y

检查工具为

bash
#!/bin/bash

source ./cmd_utils.sh
source ./kernel_config_utils.sh
source ./net_utils.sh

ethernet_bridging_check() {
    if ! kernel_config_check CONFIG_BRIDGE bridge; then
        return 1
    fi

    ifname=dodo

    netif_delete $ifname

    if ! ${IP_CMD} link add name $ifname type bridge; then
        echo "create bridge failed"
        return 1
    fi
    if ! netif_check $ifname; then
        echo "netif not exist: ifname $ifname"
        return 1
    fi

    netif_delete $ifname
    return 0
}