summaryrefslogtreecommitdiff
path: root/src/bios_dev_name.c
diff options
context:
space:
mode:
authorStephen Hemminger <shemminger@vyatta.com>2012-03-16 15:41:29 -0700
committerStephen Hemminger <shemminger@vyatta.com>2012-03-16 15:41:29 -0700
commit3dcf4140386b3e63955790d87093521f021bedee (patch)
tree1d1eeb5723da2b0a9c6cc1e848824010c16fc6bb /src/bios_dev_name.c
parent868f348533d99b05782cd8bfedb18b9f91b393bc (diff)
downloadvyatta-biosdevname-3dcf4140386b3e63955790d87093521f021bedee.tar.gz
vyatta-biosdevname-3dcf4140386b3e63955790d87093521f021bedee.zip
Add option to search for device based on pci-id
To support case where device is not in kernel (userspace networking) need a method for finding device by pci-id. Biosdevname was already building the table, this just adds an alternative lookup algorithm.
Diffstat (limited to 'src/bios_dev_name.c')
-rw-r--r--src/bios_dev_name.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/bios_dev_name.c b/src/bios_dev_name.c
index dd47fc3..ae994ab 100644
--- a/src/bios_dev_name.c
+++ b/src/bios_dev_name.c
@@ -24,6 +24,7 @@ static void usage(void)
fprintf(stderr, "Usage: biosdevname [options] [args]...\n");
fprintf(stderr, " Options:\n");
fprintf(stderr, " -i or --interface treat [args] as ethernet devs\n");
+ fprintf(stderr, " --pci-spec treat [args] as PCI specification\n");
fprintf(stderr, " -d or --debug enable debugging\n");
fprintf(stderr, " --policy [physical | all_ethN ]\n");
fprintf(stderr, " --prefix [string] string use for embedded NICs (default='em')\n");
@@ -36,6 +37,12 @@ static void usage(void)
fprintf(stderr, " You must be root to run this, as it must read from /dev/mem.\n");
}
+static void conflict(void)
+{
+ fprintf(stderr, "can't use both interface and pci options\n");
+ exit(1);
+}
+
static int
set_policy(const char *arg)
{
@@ -65,6 +72,7 @@ parse_opts(int argc, char **argv)
{"nopirq", no_argument, 0, 'x'},
{"invm", no_argument, 0, 'V'},
{"smbios", required_argument, 0, 's'},
+ {"pci-spec", no_argument, 0, 'S'},
{0, 0, 0, 0}
};
c = getopt_long(argc, argv,
@@ -77,8 +85,15 @@ parse_opts(int argc, char **argv)
opts.debug = 1;
break;
case 'i':
+ if (opts.usepci)
+ conflict();
opts.interface = 1;
break;
+ case 'S':
+ if (opts.interface)
+ conflict();
+ opts.usepci = 1;
+ break;
case 'p':
opts.namingpolicy = set_policy(optarg);
break;
@@ -172,21 +187,29 @@ int main(int argc, char *argv[])
goto out_cleanup;
}
-
- if (!opts.interface) {
+ if (opts.interface) {
+ for (i=0; i<opts.argc; i++) {
+ name = kern_to_bios(cookie, opts.argv[i]);
+ if (name)
+ printf("%s\n", name);
+ else
+ rc |= 2; /* one or more given devices weren't found */
+ }
+ } else if(opts.usepci) {
+ for (i=0; i<opts.argc; i++) {
+ name = pci_to_bios(cookie, opts.argv[i]);
+ if (name)
+ printf("%s\n", name);
+ else
+ rc |= 2;
+ }
+ } else {
fprintf(stderr, "Unknown device type, try passing an option like -i\n");
rc = 1;
goto out_usage;
}
- for (i=0; i<opts.argc; i++) {
- name = kern_to_bios(cookie, opts.argv[i]);
- if (name) {
- printf("%s\n", name);
- }
- else
- rc |= 2; /* one or more given devices weren't found */
- }
+
goto out_cleanup;
out_usage: