summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJan Moskyto Matejka <mq@ucw.cz>2015-12-16 10:43:58 +0100
committerOndrej Zajicek (work) <santiago@crfreenet.org>2015-12-20 12:53:40 +0100
commitaedd3a6babbaf35becb7770f73f30b20b464393f (patch)
treed7467562405c9b41d82e00b9e994406ff9c625ae /lib
parent5e173e9f631913f68cf38d57a69c3ce6faf60d1e (diff)
Implemented missing prefix manipulation functions
Diffstat (limited to 'lib')
-rw-r--r--lib/net.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/net.c b/lib/net.c
index e2765995..56eb16fd 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -96,6 +96,23 @@ net_validate(const net_addr *N)
}
}
+void
+net_normalize(net_addr *N)
+{
+ net_addr_union *n = (void *) N;
+
+ switch (n->n.type)
+ {
+ case NET_IP4:
+ case NET_VPN4:
+ return net_normalize_ip4(&n->ip4);
+
+ case NET_IP6:
+ case NET_VPN6:
+ return net_normalize_ip6(&n->ip6);
+ }
+}
+
int
net_classify(const net_addr *N)
{
@@ -114,3 +131,31 @@ net_classify(const net_addr *N)
return 0;
}
+
+int
+ipa_in_netX(const ip_addr A, const net_addr *N)
+{
+ switch (N->type)
+ {
+ case NET_IP4:
+ case NET_VPN4:
+ if (!ipa_is_ip4(A)) return 0;
+ break;
+
+ case NET_IP6:
+ case NET_VPN6:
+ if (ipa_is_ip4(A)) return 0;
+ break;
+ }
+
+ return ipa_zero(ipa_and(ipa_xor(A, net_prefix(N)), ipa_mkmask(net_pxlen(N))));
+}
+
+int
+net_in_netX(const net_addr *A, const net_addr *N)
+{
+ if (A->type != N->type)
+ return 0;
+
+ return (net_pxlen(N) <= net_pxlen(A)) && ipa_in_netX(net_prefix(A), N);
+}