0

I've this script which checks for a veth-pair and setup an ifb device on it, but everytime it says cannot find free ifb device for that particular veth pair.

What could be the problem? Even I tried running modprobe command which by default creates two ifb, then also it throws the same error.

#return 0 if the ifb is free

check_ifb() 
{
    local installed=`nl-qdisc-list -d $1`
    [ -n "$installed" ] && return 1

    return 0
}

setup_ifb() 
{

    for ifb in `ifconfig -a -s|egrep ^ifb|cut -d ' ' -f1`
    do
        check_ifb "$ifb" || continue
        IFB="$ifb"
        break
    done

    if [ -z "IFB" ]
    then
        echo "Unable to find a free ifb device for $vifname"
        exit -1
    fi

    ip link set dev "IFB" up
    
    if [ $? -ne 0 ]
    then
        echo ip link set dev "IFB" up failed
        exit -1
    fi
}

1 Answer 1

2

By default, two ifb interfaces are created when loading the ifb kernel module. This is for obsolete reasons, the same way two dummy interfaces are created when loading the dummy kernel module. Those interfaces are created in the initial network namespace. For example if the system is inside a container or simply a (non initial) network namespace, no ifb interface will exist here.

Don't load the module and hope to get ifb interfaces. Do it the other way around: create an ifb interface, and if needed the kernel module will get loaded anyway. Don't rely anymore on ifconfig which on Linux is now an obsolete tool.

Example:

ip link add name newifbdev type ifb
ip link set dev newifbdev up

You now have an ifb interface called newifbdev up and available for tc-mirred packets.

This would even work inside a user namespace started for example with unshare -U -r -n, despite the inability to manually load the ifb kernel module from such user namespace. If not already loaded, the module will still be indirectly loaded by the creation of the interface (and with default settings, two additional ifb interfaces will also appear in the initial namespace as a side effect).

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .