1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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;
}
|