Subversion Repositories livecd

Rev

Rev 126 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 126 Rev 147
Line 469... Line 469...
469
 
469
 
470
# load network modules, if NFSROOT is set
470
# load network modules, if NFSROOT is set
471
# Urs Beyerle, PSI
471
# Urs Beyerle, PSI
472
#
472
#
473
 
473
 
-
 
474
# network devices found ?
-
 
475
#
-
 
476
found_nic()
-
 
477
{
-
 
478
    found="1"
-
 
479
    for iface in eth0 eth1 eth2 eth3 eth4 eth5; do
-
 
480
	# nic already found ?
-
 
481
	echo $FOUND_IFACE | grep -q $iface 
-
 
482
	if [ $? -ne 0 ]; then
-
 
483
	    ifconfig $iface > /dev/null 2>&1
-
 
484
	    if [ $? -eq 0 ]; then 
-
 
485
		FOUND_IFACE="$FOUND_IFACE $iface"
-
 
486
		found="0"
-
 
487
	    fi
-
 
488
	fi
-
 
489
    done
-
 
490
    return $found
-
 
491
}
-
 
492
 
474
# 1. load network driver defined by kernel parameter nic
493
# 1. load network driver defined by kernel parameter nic
475
#
494
#
476
load_network_module_nic()
495
load_network_module_nic()
477
{
496
{
-
 
497
    NIC="`cmdline_value nic`"
478
    if [ -n "$NIC" ] && [ "$NIC" != "auto" ]; then
498
    if [ -n "$NIC" ]; then
479
	echolog "load module $NIC"
499
	echolog "load module $NIC"
480
	modprobe_module $NIC
500
	modprobe_module $NIC
481
        # FOUND_NIC="yes" # we are not yet sure ;-)
-
 
482
    fi
501
    fi
483
}
502
}
484
 
503
 
485
# 2. detecting network card from pcitable list
-
 
486
#
-
 
487
load_network_module_pcitable()
-
 
488
{
-
 
489
    PCITABLE=/bin/pcitable
-
 
490
    NICS=`lspci -n | awk '/Class 0200/ {print $4}' | tr ':' ' ' \
-
 
491
	| while read x y ; do grep "0x$x.*0x$y" $PCITABLE \
-
 
492
	| awk '$3 !~ /"unknown"/ {print $3}' | tr -d '"' ; done`
-
 
493
    
-
 
494
    if [ -n "$NICS" ]; then
-
 
495
	echolog "found network card(s): $NICS"
-
 
496
	for driver in $NICS; do
-
 
497
	    echolog "load module $driver"
-
 
498
	    modprobe_module $driver
-
 
499
	    FOUND_NIC="$driver"
-
 
500
	done
-
 
501
    fi
-
 
502
}
-
 
503
 
504
 
504
found_nic()
-
 
505
{
-
 
506
    for iface in eth0 eth1 eth2 eth3; do
-
 
507
	ifconfig $iface > /dev/null 2>&1
-
 
508
	if [ $? -eq 0 ]; then  FOUND_NIC="yes"; break; fi
-
 
509
    done
-
 
510
}
-
 
511
 
-
 
512
# 3. probe for more network card drivers, if no ethX devices found
505
# 2. auto probe for network card drivers
513
#
506
#
514
load_network_module_auto()
507
load_network_module_auto()
515
{
508
{
516
    echolog "auto-detection of network driver ..."
509
    echolog "auto-detection of network driver ..."
-
 
510
    FOUND_NICS=""
517
    KERNEL="`uname -r`"
511
    KERNEL="`uname -r`"
518
    NETDRIVERS="`find /lib/modules/$KERNEL/kernel/drivers/net | grep -v mii | grep .ko | cut -d"/" -f8 | cut -d"." -f1 | uniq`"
512
    NETDRIVERS="`find /lib/modules/$KERNEL/kernel/drivers/net | grep -v mii | grep .ko | cut -d"/" -f8 | cut -d"." -f1 | uniq`"
519
    for driver in $NETDRIVERS; do
513
    for driver in $NETDRIVERS; do
520
	modprobe_module $driver > /dev/null 2>&1
514
	modprobe_module $driver > /dev/null 2>&1
521
	for iface in eth0 eth1 eth2 eth3; do
-
 
522
	    ifconfig $iface > /dev/null 2>&1
515
	found_nic
523
	    if [ $? -eq 0 ]; then 
516
	if [ $? -eq 0 ]; then
524
		echolog "load $driver"
517
	    echolog "found network card $driver"
525
		# tr brocken in busybox
518
	    echolog "load module $driver"
526
		# FOUND_NIC="`echo $driver | tr '-' '_'`"
519
	    FOUND_NICS="$FOUND_NICS $driver"
527
		FOUND_NIC="`echo $driver | cut -d"-" -f1`"
-
 
528
		break 2
-
 
529
	    fi
-
 
530
	done
520
	else
531
	rmmod $driver > /dev/null 2>&1
521
	    rmmod $driver > /dev/null 2>&1
-
 
522
	fi
532
    done
523
    done
533
 
524
 
534
    # clean up: remove unused modules until driver "mii"
525
    # clean up: remove unused modules until driver "mii"
535
    LOADED_DRIVERS="`lsmod | grep -v Module | grep -v $FOUND_NIC | cut -d" " -f1`"
526
    LOADED_DRIVERS="`lsmod | grep -v Module | cut -d" " -f1`"
536
    for driver in $LOADED_DRIVERS; do
527
    for driver in $LOADED_DRIVERS; do
537
	[ "$driver" = "mii" ]  && break
528
	[ "$driver" = "mii" ]  && break
538
	[ "$driver" = "ntfs" ] && break
529
	[ "$driver" = "ntfs" ] && break
539
	[ "$driver" = "vfat" ] && break
530
	[ "$driver" = "vfat" ] && break
-
 
531
	do_not_remove=""
-
 
532
	for nic in $FOUND_NICS; do
-
 
533
	    echo $driver | grep -q $nic 
-
 
534
	    [ $? -eq 0 ] && do_not_remove="$driver"
-
 
535
	done
540
	rmmod $driver > /dev/null 2>&1
536
	[ ! $do_not_remove ] && $rmmod $driver > /dev/null 2>&1
541
    done
537
    done
542
}
538
}
543
 
539
 
-
 
540
# 3. detecting network card from pcitable list
-
 
541
#
-
 
542
load_network_module_pcitable()
-
 
543
{
-
 
544
    PCITABLE=/bin/pcitable
-
 
545
    NICS=`lspci -n | awk '/Class 0200/ {print $4}' | tr ':' ' ' \
-
 
546
	| while read x y ; do grep "0x$x.*0x$y" $PCITABLE \
-
 
547
	| awk '$3 !~ /"unknown"/ {print $3}' | tr -d '"' ; done`
-
 
548
    
-
 
549
    if [ -n "$NICS" ]; then
-
 
550
	echolog "found network card(s): $NICS"
-
 
551
	for driver in $NICS; do
-
 
552
	    echolog "load module $driver"
-
 
553
	    modprobe_module $driver
-
 
554
	done
-
 
555
    fi
-
 
556
}
-
 
557
 
544
# 4. ask the user for a network driver
558
# 4. ask the user for a network driver
545
#
559
#
546
load_network_module_ask()
560
load_network_module_ask()
547
{
561
{
548
    echo "ERROR: No network card detected!"
562
    echo "ERROR: No network card detected!"
Line 556... Line 570...
556
 
570
 
557
# Try to find a network driver
571
# Try to find a network driver
558
#
572
#
559
load_network_modules()
573
load_network_modules()
560
{
574
{
561
    # mii maybe need by NIC
575
    # mii maybe need by NIC driver
562
    echolog "load module mii"
-
 
563
    modprobe_module mii
576
    modprobe_module mii
564
 
577
 
565
    FOUND_NIC=""
578
    FOUND_IFACE=""
566
    NIC="`cmdline_value nic`"
-
 
567
    load_network_module_nic
579
    load_network_module_nic
568
    [ "$NIC" != "auto" ] && load_network_module_pcitable
580
    found_nic || load_network_module_auto
569
    found_nic
-
 
570
    [ -z $FOUND_NIC ] && load_network_module_auto
581
    found_nic || load_network_module_pcitable
571
    [ -z $FOUND_NIC ] && load_network_module_ask
582
    found_nic || load_network_module_ask
572
 
583
 
573
    # remove mii, if not needed
584
    # remove mii, if not needed
574
    rmmod mii > /dev/null 2>&1
585
    rmmod mii > /dev/null 2>&1
575
}
586
}
576
 
587
 
-
 
588
 
577
# get DHCP lease
589
# get DHCP lease
578
# Urs Beyerle, PSI
590
# Urs Beyerle, PSI
579
#
591
#
580
get_dhcp_lease()
592
get_dhcp_lease()
581
{
593
{
582
    # create /dev/urandom (needed by udhcpc)
594
    # create /dev/urandom (needed by udhcpc)
583
    mknod /dev/urandom c 1 9
595
    mknod /dev/urandom c 1 9
-
 
596
 
584
    for iface in eth0 eth0 eth1 eth1; do
597
    for iface in eth0 eth1 eth2 eth3 eth4 eth5; do
-
 
598
	# interface up ?
-
 
599
	ifconfig $iface > /dev/null 2>&1
-
 
600
	if [ $? -eq 0 ]; then
-
 
601
	    # try twice to get dhcp lease
-
 
602
	    for i in 1 2; do
585
	echolog "Try to get DHCP lease on $iface"
603
		echolog "${i}. Try to get DHCP lease on $iface"
586
	udhcpc --now --quit --interface=$iface --script=/bin/udhcpc.script
604
		udhcpc --now --quit --interface=$iface --script=/bin/udhcpc.script
587
	[ $? -eq 0 ] && return
605
		[ $? -eq 0 ] && return
588
	echo "ERROR: couldn't get DHCP lease, trying again"
606
		echo "ERROR: couldn't get DHCP lease on $iface."
-
 
607
	    done
-
 
608
	fi
589
    done
609
    done
590
    echo "ERROR: can't get DHCP lease on eth0 and eth1"
-
 
591
}
610
}
592
 
611