]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[netdevice] Add "linktype" setting 1180/head
authorPavel Krotkiy <porsh@nebius.com>
Wed, 3 Apr 2024 11:52:56 +0000 (12:52 +0100)
committerMichael Brown <mcb30@ipxe.org>
Wed, 3 Apr 2024 11:53:46 +0000 (12:53 +0100)
Add a new setting to provide access to the link layer protocol type
from scripts.  This can be useful in order to skip configuring
interfaces based on their link layer protocol or, conversely,
configure only selected interface types (Ethernet, IPoIB, etc.)

Example script:

    set idx:int32 0
    :loop
    isset ${net${idx}/mac} || exit 0
    iseq ${net${idx}/linktype} IPoIB && goto try_next ||
    autoboot net${idx} ||
    :try_next
    inc idx && goto loop

Signed-off-by: Pavel Krotkiy <porsh@nebius.com>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/settings.h
src/net/netdev_settings.c

index 424188deb5eafc611213b0de23f363c2b61a321e..0301da12e9b8eff6088e7d77c81ccc29e5d5129c 100644 (file)
@@ -471,6 +471,8 @@ mac_setting __setting ( SETTING_NETDEV, mac );
 extern const struct setting
 busid_setting __setting ( SETTING_NETDEV, busid );
 extern const struct setting
+linktype_setting __setting ( SETTING_NETDEV, linktype );
+extern const struct setting
 user_class_setting __setting ( SETTING_HOST_EXTRA, user-class );
 extern const struct setting
 vendor_class_setting __setting ( SETTING_HOST_EXTRA, vendor-class );
index fb98663ca0edc1d4b4e8eddd43c6190e52537cea..080b6d2a5b20c3df067fb72bd26a5ed950d5f867 100644 (file)
@@ -65,6 +65,11 @@ const struct setting busid_setting __setting ( SETTING_NETDEV, busid ) = {
        .description = "Bus ID",
        .type = &setting_type_hex,
 };
+const struct setting linktype_setting __setting ( SETTING_NETDEV, linktype ) = {
+       .name = "linktype",
+       .description = "Link-layer type",
+       .type = &setting_type_string,
+};
 const struct setting chip_setting __setting ( SETTING_NETDEV, chip ) = {
        .name = "chip",
        .description = "Chip",
@@ -219,6 +224,22 @@ static int netdev_fetch_busid ( struct net_device *netdev, void *data,
        return sizeof ( dhcp_desc );
 }
 
+/**
+ * Fetch link layer type 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_linktype ( struct net_device *netdev, void *data,
+                                  size_t len ) {
+       const char *linktype = netdev->ll_protocol->name;
+
+       strncpy ( data, linktype, len );
+       return strlen ( linktype );
+}
+
 /**
  * Fetch chip setting
  *
@@ -281,6 +302,7 @@ static struct netdev_setting_operation netdev_setting_operations[] = {
        { &bustype_setting, NULL, netdev_fetch_bustype },
        { &busloc_setting, NULL, netdev_fetch_busloc },
        { &busid_setting, NULL, netdev_fetch_busid },
+       { &linktype_setting, NULL, netdev_fetch_linktype },
        { &chip_setting, NULL, netdev_fetch_chip },
        { &ifname_setting, NULL, netdev_fetch_ifname },
 };