Browse code

Replacing netstat with ip route

Kumar Kaushik authored on 2015/09/18 07:36:39
Showing 2 changed files
... ...
@@ -1,6 +1,6 @@
1 1
 Name:           cloud-init
2 2
 Version:        0.7.6
3
-Release:        5%{?dist}
3
+Release:        6%{?dist}
4 4
 Summary:        Cloud instance init scripts
5 5
 Group:          System Environment/Base
6 6
 License:        GPLv3
... ...
@@ -12,6 +12,7 @@ Source1:        cloud-photon.cfg
12 12
 Patch0:         photon-distro.patch
13 13
 Patch1:         cloud-init-log.patch
14 14
 Patch2:         vca-admin-pwd.patch
15
+Patch3:         remove-netstat.patch
15 16
 
16 17
 BuildRequires:  python2
17 18
 BuildRequires:  python2-libs
... ...
@@ -36,6 +37,7 @@ ssh keys and to let the user run various scripts.
36 36
 %patch0 -p1
37 37
 %patch1 -p1
38 38
 %patch2 -p1
39
+%patch3 -p1
39 40
 
40 41
 find systemd -name cloud*.service | xargs sed -i s/StandardOutput=journal+console/StandardOutput=journal/g
41 42
 
... ...
@@ -94,6 +96,8 @@ fi
94 94
 
95 95
 
96 96
 %changelog
97
+* Thu Sep 17 2015 Kumar Kaushik <kaushikk@vmware.com>
98
+- Removing netstat and replacing with ip route.
97 99
 * Tue Aug 11 2015 Kumar Kaushik <kaushikk@vmware.com>
98 100
 - VCA initial password issue fix.
99 101
 * Thu Jun 25 2015 Kumar Kaushik <kaushikk@vmware.com>
100 102
new file mode 100644
... ...
@@ -0,0 +1,114 @@
0
+diff -ru cloud-init-0.7.6/cloudinit/netinfo.py cloud-init-0.7.6-modify/cloudinit/netinfo.py
1
+--- cloud-init-0.7.6/cloudinit/netinfo.py	2014-10-10 08:26:25.000000000 -0700
2
+@@ -93,49 +93,50 @@
3
+ 
4
+     return devs
5
+ 
6
+-
7
+ def route_info():
8
+-    (route_out, _err) = util.subp(["netstat", "-rn"])
9
++    (route_out, _err) = util.subp(["ip", "route"])
10
+     routes = []
11
+-    entries = route_out.splitlines()[1:]
12
++    entries = route_out.splitlines()
13
+     for line in entries:
14
+         if not line:
15
+             continue
16
+         toks = line.split()
17
+-
18
+-        # FreeBSD shows 6 items in the routing table:
19
+-        #  Destination  Gateway    Flags Refs    Use  Netif Expire
20
+-        #  default      10.65.0.1  UGS      0  34920 vtnet0
21
+-        #
22
+-        # Linux netstat shows 2 more:
23
+-        #  Destination  Gateway    Genmask  Flags MSS Window irtt Iface
24
+-        #  0.0.0.0      10.65.0.1  0.0.0.0  UG      0 0         0 eth0
25
+-        if (len(toks) < 6 or toks[0] == "Kernel" or
26
+-                toks[0] == "Destination" or toks[0] == "Internet" or
27
+-                toks[0] == "Internet6" or toks[0] == "Routing"):
28
+-            continue
29
+-
30
+-        if len(toks) < 8:
31
+-            toks.append("-")
32
+-            toks.append("-")
33
+-            toks[7] = toks[5]
34
+-            toks[5] = "-"
35
++        dest = toks[0].split('/')
36
++        listlen = len(dest)
37
++        if listlen == 1:
38
++            subnet = "32"
39
++        else:
40
++            subnet = dest[1]
41
++        if toks[0] == "default":
42
++            gat = toks[2]
43
++            mask = "0.0.0.0"
44
++            dest[0] = "0.0.0.0"
45
++            dev = toks[4]
46
++            df = "yes"
47
++        else:
48
++            gat = "0.0.0.0"
49
++            dev = toks[2]
50
++            df = "no"
51
++
52
++            if subnet == "32":
53
++                mask = "255.255.255.255"
54
++            if subnet == "24":
55
++                mask = "255.255.255.0"
56
++            if subnet == "16":
57
++                mask = "255.255.0.0"
58
++            if subnet == "8":
59
++                mask = "255.0.0.0"
60
+ 
61
+         entry = {
62
+-            'destination': toks[0],
63
+-            'gateway': toks[1],
64
+-            'genmask': toks[2],
65
+-            'flags': toks[3],
66
+-            'metric': toks[4],
67
+-            'ref': toks[5],
68
+-            'use': toks[6],
69
+-            'iface': toks[7],
70
++            'destination': dest[0],
71
++            'gateway': gat,
72
++            'genmask': mask,
73
++            'iface': dev,
74
++            'DefGateway': df,
75
+         }
76
+-
77
+         routes.append(entry)
78
+     return routes
79
+ 
80
+-
81
+ def getgateway():
82
+     routes = []
83
+     try:
84
+@@ -143,11 +144,10 @@
85
+     except:
86
+         pass
87
+     for r in routes:
88
+-        if r['flags'].find("G") >= 0:
89
++        if r['DefGateway'] == "yes":
90
+             return "%s[%s]" % (r['gateway'], r['iface'])
91
+     return None
92
+ 
93
+-
94
+ def netdev_pformat():
95
+     lines = []
96
+     try:
97
+@@ -177,13 +177,13 @@
98
+         routes = None
99
+     if routes is not None:
100
+         fields = ['Route', 'Destination', 'Gateway',
101
+-                  'Genmask', 'Interface', 'Flags']
102
++                  'Genmask', 'Interface', 'IsDefaultGateway']
103
+         tbl = PrettyTable(fields)
104
+         for (n, r) in enumerate(routes):
105
+             route_id = str(n)
106
+             tbl.add_row([route_id, r['destination'],
107
+                         r['gateway'], r['genmask'],
108
+-                        r['iface'], r['flags']])
109
++                        r['iface'], r['DefGateway']])
110
+         route_s = tbl.get_string()
111
+         max_len = len(max(route_s.splitlines(), key=len))
112
+         header = util.center("Route info", "+", max_len)