Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[Solved]How permanently add a dummy card?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
Chili0_
n00b
n00b


Joined: 09 Oct 2017
Posts: 71

PostPosted: Thu Dec 09, 2021 9:24 am    Post subject: [Solved]How permanently add a dummy card? Reply with quote

Hi,

I add a device with:
Code:

$ sudo ip link add name loop0 type dummy


but after reboot, the loop0 device lost, my question is how add the device permanently? I use openrc.

Thanks
_________________
Regards.


Last edited by Chili0_ on Fri Dec 10, 2021 1:01 pm; edited 1 time in total
Back to top
View user's profile Send private message
Chili0_
n00b
n00b


Joined: 09 Oct 2017
Posts: 71

PostPosted: Fri Dec 10, 2021 1:01 pm    Post subject: Reply with quote

A init.d script solve the problem.

Code:

#!/sbin/openrc-run

SHDIR="/lib/netifrc/sh"
MODULESDIR="/lib/netifrc/net"

[ -z "${IN_BACKGROUND}" ] && IN_BACKGROUND="NO"

# shellcheck disable=SC2034
description="Configures network interfaces."

# Handy var so we don't have to embed new lines everywhere for array splitting
__IFS="
"

#  Set the INIT to be openrc if this file is called directly
: "${INIT:=openrc}"

if [ -f "$SHDIR/functions.sh" ]; then
    # shellcheck disable=SC1090
    . "$SHDIR/functions.sh"
else
    echo "$SHDIR/functions.sh missing. Exiting"
    exit 1
fi

# Create per-interface nettree ordering, avoids race conditions and allows
# per-interface custom modules.
MODULESLIST="${RC_SVCDIR}/nettree$(get_interface)"

depend()
{
    local IFACE IFVAR
    IFACE=$(get_interface)
    IFVAR=$(shell_var "${IFACE}")

    if [ "$RC_UNAME" = Linux ] && [ "$IFACE" != lo ]; then
        need sysfs
        after modules
    fi
    after bootmisc
    keyword -jail -prefix -vserver

    case "${IFACE}" in
        lo|lo0) ;;
        *)
            after net.lo net.lo0 dbus
            need localmount
            provide net
            ;;
    esac

    if [ "$(command -v "depend_${IFVAR}")" = "depend_${IFVAR}" ]; then
        "depend_${IFVAR}"
    fi

    local dep prov
    for dep in need use before after provide keyword; do
        eval prov=\$rc_${dep}_${IFVAR}
        if [ -n "${prov}" ]; then
            "${dep}" "${prov}"
            ewarn "rc_${dep}_${IFVAR} is deprecated."
            ewarn "Please use rc_net_${IFVAR}_${dep} instead."
        fi
    done
}

start()
{
  ip link add lo1 type dummy
  ifconfig lo1 127.0.0.2 netmask 255.0.0.0
  echo "net.lo1 127.0.0.2 created."
}

stop()
{
  ip link del lo2
  echo "net.lo1 127.0.0.2 removed."

}



depend part copied from net.lo, btw net.lo and net.lo0 is the same thing. the dummy name should avoid name lo0.
_________________
Regards.
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1578

PostPosted: Fri Dec 10, 2021 3:10 pm    Post subject: Reply with quote

Using the script "start()" as an example:

Just create a symlink with net.lo1 to net.lo and put this in /etc/conf.d/net:

Code:
modules_lo1="dummy"
config_lo1="127.0.0.2/8"



This avoids your "stop" typo as well :wink:
Back to top
View user's profile Send private message
Chili0_
n00b
n00b


Joined: 09 Oct 2017
Posts: 71

PostPosted: Tue Dec 14, 2021 6:10 am    Post subject: Reply with quote

grknight wrote:
Using the script "start()" as an example:

Just create a symlink with net.lo1 to net.lo and put this in /etc/conf.d/net:

Code:
modules_lo1="dummy"
config_lo1="127.0.0.2/8"



This avoids your "stop" typo as well :wink:


Thanks, I tried with:

Code:
ln -s /etc/init.d/net.lo /etc/init.d/net.lo2


and,

/etc/conf.d/net
Code:
modules_lo2="dummy"
config_lo2="127.0.0.2/8"


But I got the following error:

Code:
$ sudo /etc/init.d/net.lo2 start
Password:
 * Caching service dependencies ...                                       [ ok ]
 * Bringing up interface lo2
 *   ERROR: interface lo2 does not exist
 *   Ensure that you have loaded the correct kernel module for your hardware
 * ERROR: net.lo2 failed to start

_________________
Regards.
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1578

PostPosted: Tue Dec 14, 2021 1:40 pm    Post subject: Reply with quote

Oops, seems I missed one setting:

Code:
modules_lo2="dummy"
config_lo2="127.0.0.2/8"
type_lo2="dummy"
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3103

PostPosted: Tue Dec 14, 2021 8:38 pm    Post subject: Reply with quote

Quote:
config_lo2="127.0.0.2/8"

Man, this is sooo wrong.

At this point you have a conflict there and your routing table is a mess.
This is the same network as the default loopback. Except that it's not, because they are not connected to any device that would bridge them.

Why? Because /8 means your network prefix is 8 bits long. 8 bits only covers the first octet in an IP address. The first octet in both cases is 127.
Why do you want to have another loopback?
Why assign it to the same network?
How are you going to direct traffic to the other interface?
You do know you can just use any IP starting with 127 on that one loopback, don't you? You don't even have to explicitly assign the other IPs to this interface to use them, it operates in a promiscuous mode even if flags don't suggest it. Oh, and if you do actually want to do that, you can assign multiple IP addresses to a single interface too.
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1578

PostPosted: Tue Dec 14, 2021 8:50 pm    Post subject: Reply with quote

szatox wrote:
Quote:
config_lo2="127.0.0.2/8"

Man, this is sooo wrong.

At this point you have a conflict there and your routing table is a mess.
This is the same network as the default loopback. Except that it's not, because they are not connected to any device that would bridge them.

Why? Because /8 means your network prefix is 8 bits long. 8 bits only covers the first octet in an IP address. The first octet in both cases is 127.
Why do you want to have another loopback?
Why assign it to the same network?
How are you going to direct traffic to the other interface?
You do know you can just use any IP starting with 127 on that one loopback, don't you? You don't even have to explicitly assign the other IPs to this interface to use them, it operates in a promiscuous mode even if flags don't suggest it. Oh, and if you do actually want to do that, you can assign multiple IP addresses to a single interface too.


I'll agree with everything here. My advice was to solve the OP even if it might be wrong.

Unfortunately, the final point given in this reply is difficult in modern times with OpenRC as it comes with the loopback script hardcoded to 127.0.0.1/8.
Sure one could modify it, as long as you merge in changes all of the time, or else add with a new script/local.d if nothing depended too early.
Back to top
View user's profile Send private message
Chili0_
n00b
n00b


Joined: 09 Oct 2017
Posts: 71

PostPosted: Wed Dec 15, 2021 2:04 am    Post subject: Reply with quote

Thanks you all, Learned a lot.

The reason I want another dummy net adapter is because of the port conflicts by two different service, and one service depends on the other, for some reason I can not modify the port, also need to create the dummy adapter early.
_________________
Regards.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3103

PostPosted: Wed Dec 15, 2021 5:08 pm    Post subject: Reply with quote

Can you modify IP address these services bind to? Maybe it would be enough?
You can also assign multiple IP addresses to a single interface - though as mentioned earlier - with lo it should not be necessary. But you can do that, and you can do that in netifrc conf[/glep]ig file.
Back to top
View user's profile Send private message
grknight
Retired Dev
Retired Dev


Joined: 20 Feb 2015
Posts: 1578

PostPosted: Wed Dec 15, 2021 5:37 pm    Post subject: Reply with quote

szatox wrote:
Can you modify IP address these services bind to? Maybe it would be enough?
You can also assign multiple IP addresses to a single interface - though as mentioned earlier - with lo it should not be necessary. But you can do that, and you can do that in netifrc conf[/glep]ig file.


By default, netifrc no longer controls the lo interface so its config is not used. Recent versions moved away to the loopback script provided by sys-apps/openrc itself.

One could always reverse that choice but must take caution when doing so preferably over a reboot.

Edit: every rebuild of OpenRC will restore the loopback script. So, it would be fun to manage. I cannot say what consequences of having 2 scripts controlling lo interface would be.
Back to top
View user's profile Send private message
Chili0_
n00b
n00b


Joined: 09 Oct 2017
Posts: 71

PostPosted: Thu Dec 23, 2021 5:10 am    Post subject: Reply with quote

Just learned, in fact , it doesn’t need to create a dummy card for local ports conflicts. Just use any address within 127.0.0.0/8, it is always there. :)
_________________
Regards.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum