diff options
author | Bob Gilligan <gilligan@vyatta.com> | 2010-02-05 09:54:11 -0800 |
---|---|---|
committer | Bob Gilligan <gilligan@vyatta.com> | 2010-02-05 09:54:11 -0800 |
commit | e1971e4774a6ebb5ed33a09bdd60afa2c0534b6f (patch) | |
tree | f4fc5aaccb4d9dac43ae7a825df9006532c1a059 /src/naming_policy.c | |
download | vyatta-biosdevname-e1971e4774a6ebb5ed33a09bdd60afa2c0534b6f.tar.gz vyatta-biosdevname-e1971e4774a6ebb5ed33a09bdd60afa2c0534b6f.zip |
Initial commit.debian/0.1
Diffstat (limited to 'src/naming_policy.c')
-rw-r--r-- | src/naming_policy.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/naming_policy.c b/src/naming_policy.c new file mode 100644 index 0000000..ffa33c8 --- /dev/null +++ b/src/naming_policy.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2006, 2007 Dell, Inc. + * by Matt Domsch <Matt_Domsch@dell.com> + * Licensed under the GNU General Public license, version 2. + */ + +#include <string.h> +#include <stdio.h> +#include <limits.h> +#include "bios_device.h" +#include "naming_policy.h" +#include "libbiosdevname.h" +#include "state.h" + +static void use_all_ethN(const struct libbiosdevname_state *state) +{ + struct bios_device *dev; + unsigned int i=0; + + list_for_each_entry(dev, &state->bios_devices, node) { + if (dev->netdev) + snprintf(dev->bios_name, sizeof(dev->bios_name), "eth%u", i++); + } +} + +static void use_kernel_names(const struct libbiosdevname_state *state) +{ + struct bios_device *dev; + + list_for_each_entry(dev, &state->bios_devices, node) { + if (dev->netdev) + strncpy(dev->bios_name, dev->netdev->kernel_name, sizeof(dev->bios_name)-1); + } +} + + +static void pcmcia_names(struct bios_device *dev) +{ + snprintf(dev->bios_name, sizeof(dev->bios_name), "eth_pccard_%u.%u", + dev->pcmciadev->socket, dev->pcmciadev->function); +} + +static void use_embedded_ethN_slots_names(const struct libbiosdevname_state *state) +{ + struct bios_device *dev; + unsigned int i=0; + + list_for_each_entry(dev, &state->bios_devices, node) { + if (is_pci(dev)) { + if (dev->pcidev->physical_slot == 0) + snprintf(dev->bios_name, sizeof(dev->bios_name), "eth%u", i++); + else if (dev->pcidev->physical_slot < INT_MAX) + snprintf(dev->bios_name, sizeof(dev->bios_name), "eth_s%d_%u", + dev->pcidev->physical_slot, + dev->pcidev->index_in_slot); + else if (dev->pcidev->physical_slot == INT_MAX) + snprintf(dev->bios_name, sizeof(dev->bios_name), "eth_unknown_%u", i++); + } + else if (is_pcmcia(dev)) + pcmcia_names(dev); + } +} + +static void use_all_names(const struct libbiosdevname_state *state) +{ + struct bios_device *dev; + unsigned int i=0; + + list_for_each_entry(dev, &state->bios_devices, node) { + if (is_pci(dev)) { + if (dev->pcidev->physical_slot < INT_MAX) + snprintf(dev->bios_name, sizeof(dev->bios_name), "eth_s%d_%u", + dev->pcidev->physical_slot, + dev->pcidev->index_in_slot); + else + snprintf(dev->bios_name, sizeof(dev->bios_name), "eth_unknown_%u", i++); + } + else if (is_pcmcia(dev)) + pcmcia_names(dev); + } +} + +int assign_bios_network_names(const struct libbiosdevname_state *state, int sort, int policy) +{ + if (sort != nosort) { + switch (policy) { + case all_ethN: + use_all_ethN(state); + break; + case embedded_ethN_slots_names: + use_embedded_ethN_slots_names(state); + break; + case all_names: + use_all_names(state); + break; + case kernelnames: + default: + use_kernel_names(state); + break; + } + } + else + use_kernel_names(state); + + return 0; +} + |