The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 807 - File: showthread.php PHP 7.3.15 (Linux)
File Line Function
/showthread.php 807 errorHandler->error





Post Reply 
 
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
skip unplugged network cards
2016-01-05, 15:39 (This post was last modified: 2016-01-05 15:40 by silver310.)
Post: #1
skip unplugged network cards
Hi, so after working with iPXE for the last few months and having a working environment the only thing that bugged me is having to wait for ipxe to try and configure every NIC that is present even if it's not connected.
So after getting a hint on the IRC channel i managed to make some modifications to the code and write a startup script that will skip unplugged NICs.

Note: only after I finished this i discovered that undionly or snponly doesn't have this issue, since they only use the NIC that made the actual PXE boot, but undionly downloads a little slower (300Mb took 2 seconds with ipxe.kkkpxe and 6 seconds with undionly, snponly vs ipxe.efi both download at the same rate)

So I figured I'll explain how to accomplish this so maybe it'll help others.

First of all some code needs to be added in net/netdev_settings.c and include/ipxe/settings.h.

netdev_settings.c:
find the following comment /** Network device predefined settings */
below it add:
Code:
const struct setting link_setting __setting ( SETTING_NETDEV, link ) = {
        .name = "link",
        .description = "Link status",
        .type = &setting_type_uint32,
};

add the following function (i added it before store MAC settings)
Code:
/**
* Fetch link setting
*
* @v netdev        Network device
* @v data        Buffer to fill with setting data
* @v len        Length of buffer
* @ret len        Length of setting data, or negative error
*/
static int netdev_fetch_link ( struct net_device *netdev, void *data,
                   size_t len ) {
    uint32_t link = netdev->link_rc;
    
    if ( len > sizeof ( link ) )
        len = sizeof ( link );

    memcpy ( data, &link, len );
    return sizeof ( link );
}

find the following comment /** Network device settings */ and below it add
Code:
{ &link_setting, NULL, netdev_fetch_link },

in settings.h somewhere between lines 420-460 add the following
Code:
extern const struct setting
link_setting __setting ( SETTING_NETDEV, link );

with those changes I can compile without any errors, now for the startup script (the script embedded with ipxe when building) I use the following one:
Code:
#!ipxe

set i:int8 0

:loop
set net-link:string ${net${i}/link}
iseq ${net-link} 0x0 && ifconf --configurator dhcp net${i} && goto boot || ifclose net${i}
inc i
iseq ${i} 10 || goto loop

:boot
chain http://192.168.0.1/boot/boot.ipxe || exit

:exit
echo Something went wrong, restart and try again

Now if you have multiple NICs or ports that are not connected, iPXE with skip those and only boot using the one that is up.

My knowledge with C isn't all that great, so I'm pretty sure the code can be made batter, with those changes when you write "echo ${net0/link}" you'll get either 0x0 (link up) or a sequence of numbers (like 0x141215) meaning link is down, this can probably be changes to show "Up" or "Down, but for me the current state is fine.

PS.
I've tried using ipxe.pxe and couldn't even get a 100mb link, max is 10mb, and at that speed booting is extremely slow, would love to find out why.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
skip unplugged network cards - silver310 - 2016-01-05 15:39



User(s) browsing this thread: 1 Guest(s)