The default fipvlan output is not really suited for automated
VLAN setup, so add an option '-i' to display the interface
configuration in script-parseable form.

References: bnc#585045

Signed-off-by: Hannes Reinecke <[email protected]>

diff --git a/fipvlan.c b/fipvlan.c
index cc8a785..6f968c4 100644
--- a/fipvlan.c
+++ b/fipvlan.c
@@ -46,6 +46,7 @@
 /* global configuration */
 
 char *exe;
+int print_vlan = 0;
 
 struct iff {
        int ifindex;
@@ -488,11 +489,12 @@ int rtnl_recv(int s)
 
 /* command line arguments */
 
-#define GETOPT_STR "ahv"
+#define GETOPT_STR "ahiv"
 
 static const struct option long_options[] = {
        { "auto", no_argument, NULL, 'a' },
        { "help", no_argument, NULL, 'h' },
+       { "ifname", no_argument, NULL, 'i' },
        { "version", no_argument, NULL, 'v' },
        { NULL, 0, NULL, 0 }
 };
@@ -528,6 +530,9 @@ int parse_cmdline(int argc, char **argv)
                case 'a':
                        automode = 1;
                        break;
+               case 'i':
+                       print_vlan = 1;
+                       break;
                case 'h':
                        help(0);
                        break;
@@ -628,8 +633,11 @@ void print_results()
 {
        struct fcf *fcf;
 
-       if (list_empty(&fcfs)) {
-               printf("No Fibre Channel Forwarders Found\n");
+       if (print_vlan) {
+               list_for_each_entry(fcf, &fcfs, list) {
+                       printf("%s\t%03d\n",
+                              fcf->interface->ifname, fcf->vlan);
+               }
                return;
        }
 
@@ -671,7 +679,7 @@ int main(int argc, char **argv)
 {
        int ps;
        struct iff *iff;
-       int i;
+       int i, retval = 1;
        int automode;
 
        exe = strrchr(argv[0], '/');
@@ -696,17 +704,23 @@ int main(int argc, char **argv)
                log_err("no interfaces to perform discovery on");
                close(ps);
                log_stop();
-               exit(1);
+               return retval;
        }
 
        list_for_each_entry(iff, &interfaces, list)
                fip_send_vlan_request(ps, iff);
 
        recv_loop(ps);
-       print_results();
+       if (!list_empty(&fcfs)) {
+               print_results();
+               retval = 0;
+       } else if (!print_vlan) {
+               log_err("No Fibre Channel Forwarders Found\n");
+       }
+
 
        close(ps);
        log_stop();
-       exit(0);
+       return retval;
 }
 
_______________________________________________
devel mailing list
[email protected]
http://www.open-fcoe.org/mailman/listinfo/devel

Reply via email to