Skip to content

Commit 2d15551

Browse files
author
Vadim Averin
committed
Add GetSubnetByMask
1 parent 7e15c10 commit 2d15551

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

ydb/library/yql/udfs/common/ip_base/lib/ip_base_udf.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,17 @@ namespace {
335335
return valueBuilder->NewString(SerializeAddress(beg));
336336
}
337337

338+
SIMPLE_UDF(TGetSubnetByMask, char*(TAutoMapString, TAutoMapString)) {
339+
const auto refBase = args[0].AsStringRef();
340+
const auto refMask = args[1].AsStringRef();
341+
TIpv6Address addrBase = DeserializeAddress(refBase);
342+
TIpv6Address addrMask = DeserializeAddress(refMask);
343+
if (addrBase.Type() != addrMask.Type()) {
344+
ythrow yexception() << "Base and mask differ in length";
345+
}
346+
return valueBuilder->NewString(SerializeAddress(TIpv6Address(ui128(addrBase) & ui128(addrMask), addrBase.Type())));
347+
}
348+
338349
#define EXPORTED_IP_BASE_UDF \
339350
TFromString, \
340351
TSubnetFromString, \
@@ -345,5 +356,6 @@ namespace {
345356
TIsEmbeddedIPv4, \
346357
TConvertToIPv6, \
347358
TGetSubnet, \
348-
TSubnetMatch
359+
TSubnetMatch, \
360+
TGetSubnetByMask
349361
}

0 commit comments

Comments
 (0)