diff options
author | Jan Moskyto Matejka <mq@ucw.cz> | 2015-12-16 10:43:58 +0100 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2015-12-20 12:53:40 +0100 |
commit | aedd3a6babbaf35becb7770f73f30b20b464393f (patch) | |
tree | d7467562405c9b41d82e00b9e994406ff9c625ae /lib/net.c | |
parent | 5e173e9f631913f68cf38d57a69c3ce6faf60d1e (diff) |
Implemented missing prefix manipulation functions
Diffstat (limited to 'lib/net.c')
-rw-r--r-- | lib/net.c | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -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); +} |