python/pyglue: filter out loopback and linklocal addresses unless all_interfaces...
authorStefan Metzmacher <metze@samba.org>
Fri, 30 Aug 2013 12:59:01 +0000 (14:59 +0200)
committerKarolin Seeger <kseeger@samba.org>
Mon, 2 Sep 2013 07:50:08 +0000 (09:50 +0200)
Bug: https://bugzilla.samba.org/show_bug.cgi?id=10030

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Bjoern Jacke <bj@sernet.de>
(cherry picked from commit 0e6aca40413fb3cfd4300f282204a69743be4a65)

python/pyglue.c

index c21de46798dcf04a2a0f39d962ed817a10835174..802153a9b86165b1d896430a5761a7a24171fab4 100644 (file)
@@ -164,18 +164,59 @@ static PyObject *py_interface_ips(PyObject *self, PyObject *args)
        /* first count how many are not loopback addresses */
        for (ifcount = i = 0; i<count; i++) {
                const char *ip = iface_list_n_ip(ifaces, i);
-               if (!(!all_interfaces && iface_list_same_net(ip, "127.0.0.1", "255.0.0.0"))) {
+
+               if (all_interfaces) {
                        ifcount++;
+                       continue;
+               }
+
+               if (iface_list_same_net(ip, "127.0.0.1", "255.0.0.0")) {
+                       continue;
+               }
+
+               if (iface_list_same_net(ip, "169.254.0.0", "255.255.0.0")) {
+                       continue;
                }
+
+               if (iface_list_same_net(ip, "::1", "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")) {
+                       continue;
+               }
+
+               if (iface_list_same_net(ip, "fe80::", "ffff:ffff:ffff:ffff::")) {
+                       continue;
+               }
+
+               ifcount++;
        }
 
        pylist = PyList_New(ifcount);
        for (ifcount = i = 0; i<count; i++) {
                const char *ip = iface_list_n_ip(ifaces, i);
-               if (!(!all_interfaces && iface_list_same_net(ip, "127.0.0.1", "255.0.0.0"))) {
+
+               if (all_interfaces) {
                        PyList_SetItem(pylist, ifcount, PyString_FromString(ip));
                        ifcount++;
+                       continue;
+               }
+
+               if (iface_list_same_net(ip, "127.0.0.1", "255.0.0.0")) {
+                       continue;
+               }
+
+               if (iface_list_same_net(ip, "169.254.0.0", "255.255.0.0")) {
+                       continue;
                }
+
+               if (iface_list_same_net(ip, "::1", "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")) {
+                       continue;
+               }
+
+               if (iface_list_same_net(ip, "fe80::", "ffff:ffff:ffff:ffff::")) {
+                       continue;
+               }
+
+               PyList_SetItem(pylist, ifcount, PyString_FromString(ip));
+               ifcount++;
        }
        talloc_free(tmp_ctx);
        return pylist;