OSDN Git Service

The net-list command is added.
authorniwa-hideyuki <niwa.hideyuki@jp.fujitsu.com>
Sun, 1 Feb 2015 13:10:28 +0000 (22:10 +0900)
committerniwa-hideyuki <niwa.hideyuki@jp.fujitsu.com>
Sun, 1 Feb 2015 13:10:28 +0000 (22:10 +0900)
lxcf/Makefile
lxcf/cmd/net-add
lxcf/lib/lxcf-net-list [new file with mode: 0755]

index 5a1d024..cd85c31 100644 (file)
@@ -150,6 +150,7 @@ install_lib_lxcf: .prepare
        install -m 755 lib/lxcf-net-del $(DESTDIR)$(libdir)/lxcf/lxcf-net-del
        install -m 755 lib/lxcf-net-gateway $(DESTDIR)$(libdir)/lxcf/lxcf-net-gateway
        install -m 755 lib/lxcf-net-route $(DESTDIR)$(libdir)/lxcf/lxcf-net-route
+       install -m 755 lib/lxcf-net-list $(DESTDIR)$(libdir)/lxcf/lxcf-net-list
        install -m 755 lib/lxcf-net-ipv4 $(DESTDIR)$(libdir)/lxcf/lxcf-net-ipv4
 
 install_sbin_lxcf: .prepare
@@ -211,6 +212,7 @@ install_sbin_lxcf: .prepare
        install -m 755 cmd/net-del $(DESTDIR)$(libdir)/lxcf/sbin/net-del
        install -m 755 cmd/net-gateway $(DESTDIR)$(libdir)/lxcf/sbin/net-gateway
        install -m 755 cmd/net-route $(DESTDIR)$(libdir)/lxcf/sbin/net-route
+       install -m 755 cmd/net-list $(DESTDIR)$(libdir)/lxcf/sbin/net-list
 
 install_conf: .prepare
        install -m 644 conf/helpfile.txt $(DESTDIR)$(libdir)/lxcf/helpfile.txt
index 8711be0..6593f47 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/bash
-# copyright (C) 2014 FUJITSU LIMITED All Rights Reserved
+# copyright (C) 2015 FUJITSU LIMITED All Rights Reserved
 
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
diff --git a/lxcf/lib/lxcf-net-list b/lxcf/lib/lxcf-net-list
new file mode 100755 (executable)
index 0000000..80e8b27
--- /dev/null
@@ -0,0 +1,83 @@
+
+#!/bin/bash
+# copyright (C) 2015 FUJITSU LIMITED All Rights Reserved
+
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2
+# of the License.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
+# 02110-1301, USA.
+
+# check distro
+DISTRO=`/usr/lib64/lxcf/lxcf-distro`
+
+# check root
+if [ ${EUID:-${UID}} != 0 ]; then
+    echo "error: Because you are not root, you cannot execute this command. "
+    exit 1
+fi
+
+usage()
+{
+       echo "usage: net-list [ -b ] [ -v ]"
+}
+
+# check options
+FLG_B=0 
+FLG_V=0 
+
+while getopts bv OPT ; do
+  case $OPT in
+  b) FLG_B=1 ;;
+  v) FLG_V=1 ;;
+  esac
+done
+shift $((OPTIND - 1))
+
+list_br()
+{
+       brctl show
+}
+
+list_veth()
+{
+       ip a show
+}
+
+# check args
+if [ $FLG_B -eq 1 ]; then
+       if [ $# -ne 0 ]; then
+               usage
+               exit -1
+       else
+               list_br
+       fi
+fi
+if [ $FLG_V -eq 1 ]; then
+       if [ $# -ne 0 ]; then
+               usage
+               exit -1
+       else
+               list_veth
+       fi
+fi
+
+if [ $# -ne 0 ]; then
+       usage
+       exit -1
+fi
+
+ip a show | egrep -e "^[1-9]" -e inet | \
+  awk '{if (($1 == "inet") || ($1 == "inet6")){printf " %s",$2}else{printf "\n%s ",$2}}END{print}'
+
+
+exit 0