Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 7407 - /etc/init.d/net.eth0 alias handling
Summary: /etc/init.d/net.eth0 alias handling
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Games (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: Martin Schlemmer (RETIRED)
URL:
Whiteboard:
Keywords:
: 8030 9128 11893 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-09-03 03:53 UTC by Take Vos
Modified: 2003-03-16 13:43 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Take Vos 2002-09-03 03:53:59 UTC
With the current way aliases are handled it is not easy 
adding ip with different netmasks/broadcasts. 
Also it is setup differently for the primary ip number. 
 
I have made (not tested) a piece of code which would use the iface_eth0_0 
variables in /etc/conf.d/net which are handled the same as the primary 
setting iface_eth0. 
 
Here is the code: 
    if [ -n "$(eval echo \$\{iface_${IFACE}_0\})" ] 
    then 
        local num=0 
 
        ebegin "  Adding aliases" 
        while true 
        do 
	    local iface_args="$(eval echo \$\{iface_${IFACE}_${num}\})" 
 
            if [ -n "${iface_args}" ] 
            then 
                ebegin "    ${IFACE}:${num}" 
                /sbin/ifconfig ${IFACE}:${num} ${iface_args} >/dev/null 
                num=$((num + 1)) 
                eend 0 
 
                num=$((num + 1) 
            else 
                break 
            fi 
        done 
    fi 
 
Hope this helps.
Comment 1 Take Vos 2002-09-03 03:58:54 UTC
I see ipv6 numbers can be handled the same way 
Maybe iface_eth0 should be renamed inet4_eth0 or inet_eth0 
for consistancy. 
Comment 2 Martin Schlemmer (RETIRED) gentoo-dev 2002-09-03 13:37:34 UTC
Without trying to be offensive, net.eth0 is already too complex for my
taste.  It should be a generic scipt that works for *most* people.  If
you need more, it is CONFIG_PROTECTed, and thus wont get overwritten.

As for the inet4* stuff .. it will be considered, but changing it at
this stage of the game could result in confusion, and breakage.
Comment 3 Take Vos 2002-09-03 16:17:38 UTC
I agree with you about the complexity of the net.eth0 script 
When writing net.sit1 (ipv6 tunneling) I came to the conclusion that 
I was duplicating things from net.eth0. 
 
I don't think changing the way aliasing works would cause much of a problem, 
you could add my piece of code to the original one, as it uses different 
settings from /etc/conf.d/net. The put warning marks when it enters the 
original settings. And add comments to /etc/conf.d/net. 
 
I would like to take a shot at refactoring the net scripts, so that we can get 
a consistant and easy configuration for the different protocols, keep a 
temporary compatibility with the old configuration, and make the scripts 
simple. 
 
 
Comment 4 Martin Schlemmer (RETIRED) gentoo-dev 2002-09-03 16:53:30 UTC
To be honest, I thought about it again after posting last message.  There
is a better solution than the current.


---------------------------new alias code-----------------------------------
    if [ -n "$(eval echo \$\{alias_${IFACE}\})" ]
    then
        local x=""
        local num=0
        local aliasbcast=""
        local aliasnmask=""

        ebegin "  Adding aliases"
        for x in $(eval echo \$\{alias_${IFACE}\})
        do
            aliasbcast="$(eval echo \$\{broadcast_${IFACE}\} \| awk \'\{ print
\$${num} \}\')"
            if [ -n "${aliasbcast}" ]
            then
                aliasbcast="broadcast ${aliasbcast}"
            fi

            aliasnmask="$(eval echo \$\{netmask_${IFACE}\} \| awk \'\{ print
\$${num} \}\')"
            if [ -n "${aliasnmask}" ]
            then
                aliasnmask="netmask ${aliasnmask}"
            fi

            ebegin "    ${IFACE}:${num}"
            /sbin/ifconfig ${IFACE}:${num} ${x} \
                ${aliasbcast} ${aliasnmask} >/dev/null
            num=$((num + 1))
            eend 0
        done
        save_options "alias" "$(eval echo \$\{alias_${IFACE}\})"
    fi
------------------------------------------------------------------------------

thus you alias config could look like follow:

-------------------------------------------------------
alias_eth0="10.0.0.23 192.168.0.33"
broadcast_eth0="10.0.0.255 192.168.0.255"
netmask_eth0="255.0.0.0 255.255.255.0"
-------------------------------------------------------

If broadcast_eth? or netmask_eth? is null, $aliasbcast $aliasnmask will
be null as well, and it should work as without giving them as args.

Comments welcome.
Comment 5 SpanKY gentoo-dev 2002-09-17 13:18:14 UTC
*** Bug 8030 has been marked as a duplicate of this bug. ***
Comment 6 naanyaar2000 2002-09-17 15:33:02 UTC
The awk bits above:
awk \'\{ print \$${num} \}\'

should actually be:
awk \'\{ print \$$((num+1)) \}\'

Otherwise, it will not work for multiple aliases bound to the same interface 
($0 == full record).
Comment 7 Martin Schlemmer (RETIRED) gentoo-dev 2002-09-17 15:40:10 UTC
True, thanks.
Comment 8 Erwann CORVELLEC 2002-10-10 06:08:10 UTC
The above bug ($num) is a show stopper !
It appeared on one of my production server and some daemons didn't start anymore
(bind address didn't exist)...
Please correct this ASAP !
Comment 9 Martin Schlemmer (RETIRED) gentoo-dev 2002-10-12 14:07:40 UTC
It is on CVS.  Ill do a new baselayout still this weekend.  Edit it by
hand for now, thanks.
Comment 10 Thilo Bangert (RETIRED) (RETIRED) gentoo-dev 2002-10-15 11:22:26 UTC
*** Bug 9128 has been marked as a duplicate of this bug. ***
Comment 11 Martin Schlemmer (RETIRED) gentoo-dev 2002-12-10 12:31:49 UTC
*** Bug 11893 has been marked as a duplicate of this bug. ***
Comment 12 Michael Cohen (RETIRED) gentoo-dev 2003-01-15 23:00:44 UTC
... still having problems with this on  baselayout 1.8.5.8 
Comment 13 Martin Schlemmer (RETIRED) gentoo-dev 2003-01-19 17:40:08 UTC
Explain ?  Attach your net.eth0 please.
Comment 14 SpanKY gentoo-dev 2003-01-27 13:42:02 UTC
*** Bug 14636 has been marked as a duplicate of this bug. ***
Comment 15 Martin Schlemmer (RETIRED) gentoo-dev 2003-03-16 13:43:51 UTC
I dont see a problem.  Reopen if you actually want to explain your problem,
and needed info.