Initial commit of unbound role

Change-Id: I0a5f1517e7912d418b7994e17c856338e07a5ae0
diff --git a/filter_plugins/unbound_revdns.py b/filter_plugins/unbound_revdns.py
new file mode 100644
index 0000000..365e55d
--- /dev/null
+++ b/filter_plugins/unbound_revdns.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+
+# SPDX-FileCopyrightText: © 2017-2020 Open Networking Foundation <support@opennetworking.org>
+# SPDX-License-Identifier: Apache-2.0
+
+# unbound_revdns - ansible filter - ipv4 address or cidr and generates a
+# reverse DNS string suitable for use with unbound, which requires them in a
+# slightly unusual format when a RFC1918 address is used with a local-zone
+# definition:
+# https://nlnetlabs.nl/documentation/unbound/unbound.conf/#local-zone
+# https://www.claudiokuenzler.com/blog/699/unbound-dns-not-serving-reverse-lookup-for-internal-addresses-rfc1918
+
+from __future__ import absolute_import
+import netaddr
+
+
+class FilterModule(object):
+    def filters(self):
+        return {
+            "unbound_revdns": self.unbound_revdns,
+        }
+
+    def unbound_revdns(self, var):
+        (o1, o2, o3, o4) = netaddr.IPNetwork(var).network.words
+
+        revdns = "%d.%d.%d.%d.in-addr.arpa." % (o4, o3, o2, o1)
+
+        if o2 == 0 or o1 == 10:
+            revdns = "%d.in-addr.arpa." % (o1)
+        elif (
+            o3 == 0
+            or (o1 == 172 and o2 >= 16 and o2 <= 31)
+            or (o1 == 192 and o2 == 168)
+        ):
+            revdns = "%d.%d.in-addr.arpa." % (o2, o1)
+        elif o4 == 0:
+            revdns = "%d.%d.%d.in-addr.arpa." % (o3, o2, o1)
+
+        return revdns