2015-11-05 11:48:52 +00:00
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "lib/ip.h"
|
|
|
|
#include "lib/net.h"
|
2016-12-07 14:36:15 +00:00
|
|
|
#include "lib/flowspec.h"
|
2015-11-05 11:48:52 +00:00
|
|
|
|
2015-12-11 14:35:37 +00:00
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
const char * const net_label[] = {
|
2016-12-07 14:36:15 +00:00
|
|
|
[NET_IP4] = "ipv4",
|
|
|
|
[NET_IP6] = "ipv6",
|
|
|
|
[NET_VPN4] = "vpn4",
|
|
|
|
[NET_VPN6] = "vpn6",
|
|
|
|
[NET_ROA4] = "roa4",
|
|
|
|
[NET_ROA6] = "roa6",
|
2018-01-22 20:09:29 +00:00
|
|
|
[NET_FLOW4] = "flow4",
|
|
|
|
[NET_FLOW6] = "flow6",
|
|
|
|
[NET_MREQ4] = "mreq4",
|
|
|
|
[NET_MREQ6] = "mreq6",
|
|
|
|
[NET_MGRP4] = "mgrp4",
|
|
|
|
[NET_MGRP6] = "mgrp6",
|
2016-03-02 13:37:18 +00:00
|
|
|
[NET_MPLS] = "mpls",
|
2016-01-26 10:48:58 +00:00
|
|
|
};
|
|
|
|
|
2015-11-05 11:48:52 +00:00
|
|
|
const u16 net_addr_length[] = {
|
2016-12-07 14:36:15 +00:00
|
|
|
[NET_IP4] = sizeof(net_addr_ip4),
|
|
|
|
[NET_IP6] = sizeof(net_addr_ip6),
|
|
|
|
[NET_VPN4] = sizeof(net_addr_vpn4),
|
|
|
|
[NET_VPN6] = sizeof(net_addr_vpn6),
|
|
|
|
[NET_ROA4] = sizeof(net_addr_roa4),
|
|
|
|
[NET_ROA6] = sizeof(net_addr_roa6),
|
2018-01-22 20:09:29 +00:00
|
|
|
[NET_FLOW4] = 0,
|
|
|
|
[NET_FLOW6] = 0,
|
|
|
|
[NET_MREQ4] = sizeof(net_addr_mreq4),
|
|
|
|
[NET_MREQ6] = sizeof(net_addr_mreq6),
|
|
|
|
[NET_MGRP4] = sizeof(net_addr_mgrp4),
|
|
|
|
[NET_MGRP6] = sizeof(net_addr_mgrp6),
|
2016-03-02 13:37:18 +00:00
|
|
|
[NET_MPLS] = sizeof(net_addr_mpls),
|
2015-12-07 15:24:18 +00:00
|
|
|
};
|
2015-11-05 11:48:52 +00:00
|
|
|
|
2015-12-11 14:35:37 +00:00
|
|
|
const u8 net_max_prefix_length[] = {
|
2016-12-07 14:36:15 +00:00
|
|
|
[NET_IP4] = IP4_MAX_PREFIX_LENGTH,
|
|
|
|
[NET_IP6] = IP6_MAX_PREFIX_LENGTH,
|
|
|
|
[NET_VPN4] = IP4_MAX_PREFIX_LENGTH,
|
|
|
|
[NET_VPN6] = IP6_MAX_PREFIX_LENGTH,
|
|
|
|
[NET_ROA4] = IP4_MAX_PREFIX_LENGTH,
|
|
|
|
[NET_ROA6] = IP6_MAX_PREFIX_LENGTH,
|
2018-01-22 20:09:29 +00:00
|
|
|
[NET_FLOW4] = IP4_MAX_PREFIX_LENGTH,
|
|
|
|
[NET_FLOW6] = IP6_MAX_PREFIX_LENGTH,
|
|
|
|
[NET_MREQ4] = IP4_MAX_PREFIX_LENGTH,
|
|
|
|
[NET_MREQ6] = IP6_MAX_PREFIX_LENGTH,
|
|
|
|
[NET_MGRP4] = IP4_MAX_PREFIX_LENGTH,
|
|
|
|
[NET_MGRP6] = IP6_MAX_PREFIX_LENGTH,
|
2016-03-02 13:37:18 +00:00
|
|
|
[NET_MPLS] = 0,
|
2015-12-11 14:35:37 +00:00
|
|
|
};
|
|
|
|
|
2015-12-18 10:57:38 +00:00
|
|
|
const u16 net_max_text_length[] = {
|
2016-12-07 14:36:15 +00:00
|
|
|
[NET_IP4] = 18, /* "255.255.255.255/32" */
|
|
|
|
[NET_IP6] = 43, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */
|
|
|
|
[NET_VPN4] = 40, /* "4294967296:4294967296 255.255.255.255/32" */
|
|
|
|
[NET_VPN6] = 65, /* "4294967296:4294967296 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */
|
|
|
|
[NET_ROA4] = 34, /* "255.255.255.255/32-32 AS4294967295" */
|
|
|
|
[NET_ROA6] = 60, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128-128 AS4294967295" */
|
2018-01-22 20:09:29 +00:00
|
|
|
[NET_FLOW4] = 0, /* "flow4 { ... }" */
|
|
|
|
[NET_FLOW6] = 0, /* "flow6 { ... }" */
|
|
|
|
[NET_MREQ4] = 15, /* "255.255.255.255" */
|
|
|
|
[NET_MREQ6] = 39, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" */
|
2018-02-22 15:51:43 +00:00
|
|
|
[NET_MGRP4] = 20, /* "(*, 255.255.255.255)" */
|
|
|
|
[NET_MGRP6] = 44, /* "(*, ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff)" */
|
2016-03-02 13:37:18 +00:00
|
|
|
[NET_MPLS] = 7, /* "1048575" */
|
2015-12-18 10:57:38 +00:00
|
|
|
};
|
|
|
|
|
2015-12-11 14:35:37 +00:00
|
|
|
|
2017-03-13 12:50:32 +00:00
|
|
|
int
|
|
|
|
rd_format(const u64 rd, char *buf, int buflen)
|
|
|
|
{
|
|
|
|
switch (rd >> 48)
|
|
|
|
{
|
2017-03-28 15:35:32 +00:00
|
|
|
case 0: return bsnprintf(buf, buflen, "%u:%u", (u32) (rd >> 32), (u32) rd);
|
|
|
|
case 1: return bsnprintf(buf, buflen, "%I4:%u", ip4_from_u32(rd >> 16), (u32) (rd & 0xffff));
|
|
|
|
case 2: if (((u32) (rd >> 16)) >> 16)
|
|
|
|
return bsnprintf(buf, buflen, "%u:%u", (u32) (rd >> 16), (u32) (rd & 0xffff));
|
|
|
|
else
|
|
|
|
return bsnprintf(buf, buflen, "2:%u:%u", (u32) (rd >> 16), (u32) (rd & 0xffff));
|
2017-03-13 12:50:32 +00:00
|
|
|
default: return bsnprintf(buf, buflen, "X:%08x:%08x", (u32) (rd >> 32), (u32) rd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-07 15:24:18 +00:00
|
|
|
int
|
2015-11-05 11:48:52 +00:00
|
|
|
net_format(const net_addr *N, char *buf, int buflen)
|
|
|
|
{
|
|
|
|
net_addr_union *n = (void *) N;
|
2016-02-09 13:53:29 +00:00
|
|
|
buf[0] = 0;
|
2015-11-05 11:48:52 +00:00
|
|
|
|
|
|
|
switch (n->n.type)
|
|
|
|
{
|
|
|
|
case NET_IP4:
|
2015-12-29 16:12:47 +00:00
|
|
|
return bsnprintf(buf, buflen, "%I4/%d", n->ip4.prefix, n->ip4.pxlen);
|
2015-11-05 11:48:52 +00:00
|
|
|
case NET_IP6:
|
2015-12-29 16:12:47 +00:00
|
|
|
return bsnprintf(buf, buflen, "%I6/%d", n->ip6.prefix, n->ip6.pxlen);
|
2015-11-05 11:48:52 +00:00
|
|
|
case NET_VPN4:
|
2016-02-09 13:53:29 +00:00
|
|
|
{
|
2017-03-13 12:50:32 +00:00
|
|
|
int c = rd_format(n->vpn4.rd, buf, buflen);
|
2017-03-14 16:18:50 +00:00
|
|
|
ADVANCE(buf, buflen, c);
|
2017-03-13 12:50:32 +00:00
|
|
|
return bsnprintf(buf, buflen, " %I4/%d", n->vpn4.prefix, n->vpn4.pxlen);
|
2016-02-09 13:53:29 +00:00
|
|
|
}
|
2015-11-05 11:48:52 +00:00
|
|
|
case NET_VPN6:
|
2016-02-09 13:53:29 +00:00
|
|
|
{
|
2017-03-13 12:50:32 +00:00
|
|
|
/* XXX: RD format is specified for VPN4; not found any for VPN6, reusing the same as for VPN4 */
|
|
|
|
int c = rd_format(n->vpn6.rd, buf, buflen);
|
2017-03-14 16:18:50 +00:00
|
|
|
ADVANCE(buf, buflen, c);
|
2017-03-13 12:50:32 +00:00
|
|
|
return bsnprintf(buf, buflen, " %I6/%d", n->vpn6.prefix, n->vpn6.pxlen);
|
2016-02-09 13:53:29 +00:00
|
|
|
}
|
2016-01-07 17:17:16 +00:00
|
|
|
case NET_ROA4:
|
2016-01-14 09:03:50 +00:00
|
|
|
return bsnprintf(buf, buflen, "%I4/%u-%u AS%u", n->roa4.prefix, n->roa4.pxlen, n->roa4.max_pxlen, n->roa4.asn);
|
2016-01-07 17:17:16 +00:00
|
|
|
case NET_ROA6:
|
2016-01-14 09:03:50 +00:00
|
|
|
return bsnprintf(buf, buflen, "%I6/%u-%u AS%u", n->roa6.prefix, n->roa6.pxlen, n->roa6.max_pxlen, n->roa6.asn);
|
2016-12-07 14:36:15 +00:00
|
|
|
case NET_FLOW4:
|
|
|
|
return flow4_net_format(buf, buflen, &n->flow4);
|
|
|
|
case NET_FLOW6:
|
|
|
|
return flow6_net_format(buf, buflen, &n->flow6);
|
2016-05-27 00:40:17 +00:00
|
|
|
case NET_MREQ4:
|
2018-01-22 20:09:29 +00:00
|
|
|
return bsnprintf(buf, buflen, "%I4", n->mreq4.grp);
|
2016-05-27 00:40:17 +00:00
|
|
|
case NET_MREQ6:
|
2018-01-22 20:09:29 +00:00
|
|
|
return bsnprintf(buf, buflen, "%I6", n->mreq6.grp);
|
|
|
|
case NET_MGRP4:
|
2018-02-22 15:51:43 +00:00
|
|
|
return bsnprintf(buf, buflen, "(*, %I4)", n->mgrp4.grp);
|
2016-05-27 00:40:17 +00:00
|
|
|
case NET_MGRP6:
|
2018-02-22 15:51:43 +00:00
|
|
|
return bsnprintf(buf, buflen, "(*, %I6)", n->mgrp6.grp);
|
2016-03-02 13:37:18 +00:00
|
|
|
case NET_MPLS:
|
|
|
|
return bsnprintf(buf, buflen, "%u", n->mpls.label);
|
2015-11-05 11:48:52 +00:00
|
|
|
}
|
2015-12-07 15:24:18 +00:00
|
|
|
|
2016-02-09 13:53:29 +00:00
|
|
|
bug("unknown network type");
|
2015-12-07 15:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ip_addr
|
|
|
|
net_pxmask(const net_addr *a)
|
|
|
|
{
|
|
|
|
switch (a->type)
|
|
|
|
{
|
|
|
|
case NET_IP4:
|
|
|
|
case NET_VPN4:
|
2016-01-07 17:17:16 +00:00
|
|
|
case NET_ROA4:
|
2016-12-07 14:36:15 +00:00
|
|
|
case NET_FLOW4:
|
2016-05-27 00:40:17 +00:00
|
|
|
case NET_MREQ4:
|
|
|
|
case NET_MGRP4:
|
2015-12-07 15:24:18 +00:00
|
|
|
return ipa_from_ip4(ip4_mkmask(net4_pxlen(a)));
|
|
|
|
|
|
|
|
case NET_IP6:
|
|
|
|
case NET_VPN6:
|
2016-01-07 17:17:16 +00:00
|
|
|
case NET_ROA6:
|
2016-12-07 14:36:15 +00:00
|
|
|
case NET_FLOW6:
|
2016-05-27 00:40:17 +00:00
|
|
|
case NET_MREQ6:
|
|
|
|
case NET_MGRP6:
|
2015-12-07 15:24:18 +00:00
|
|
|
return ipa_from_ip6(ip6_mkmask(net6_pxlen(a)));
|
|
|
|
|
2016-03-02 13:37:18 +00:00
|
|
|
case NET_MPLS:
|
2015-12-07 15:24:18 +00:00
|
|
|
default:
|
|
|
|
return IPA_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-16 09:25:12 +00:00
|
|
|
int
|
|
|
|
net_compare(const net_addr *a, const net_addr *b)
|
2015-12-07 15:24:18 +00:00
|
|
|
{
|
2015-12-16 09:25:12 +00:00
|
|
|
if (a->type != b->type)
|
|
|
|
return uint_cmp(a->type, b->type);
|
2015-12-07 15:24:18 +00:00
|
|
|
|
2015-12-16 09:25:12 +00:00
|
|
|
switch (a->type)
|
|
|
|
{
|
|
|
|
case NET_IP4:
|
|
|
|
return net_compare_ip4((const net_addr_ip4 *) a, (const net_addr_ip4 *) b);
|
|
|
|
case NET_IP6:
|
|
|
|
return net_compare_ip6((const net_addr_ip6 *) a, (const net_addr_ip6 *) b);
|
|
|
|
case NET_VPN4:
|
|
|
|
return net_compare_vpn4((const net_addr_vpn4 *) a, (const net_addr_vpn4 *) b);
|
|
|
|
case NET_VPN6:
|
|
|
|
return net_compare_vpn6((const net_addr_vpn6 *) a, (const net_addr_vpn6 *) b);
|
2016-01-07 17:17:16 +00:00
|
|
|
case NET_ROA4:
|
|
|
|
return net_compare_roa4((const net_addr_roa4 *) a, (const net_addr_roa4 *) b);
|
|
|
|
case NET_ROA6:
|
|
|
|
return net_compare_roa6((const net_addr_roa6 *) a, (const net_addr_roa6 *) b);
|
2016-12-07 14:36:15 +00:00
|
|
|
case NET_FLOW4:
|
|
|
|
return net_compare_flow4((const net_addr_flow4 *) a, (const net_addr_flow4 *) b);
|
|
|
|
case NET_FLOW6:
|
|
|
|
return net_compare_flow6((const net_addr_flow6 *) a, (const net_addr_flow6 *) b);
|
2016-05-27 00:40:17 +00:00
|
|
|
case NET_MREQ4:
|
2018-01-22 20:09:29 +00:00
|
|
|
return net_compare_mreq4((const net_addr_mreq4 *) a, (const net_addr_mreq4 *) b);
|
|
|
|
case NET_MREQ6:
|
|
|
|
return net_compare_mreq6((const net_addr_mreq6 *) a, (const net_addr_mreq6 *) b);
|
2016-05-27 00:40:17 +00:00
|
|
|
case NET_MGRP4:
|
|
|
|
return net_compare_mgrp4((const net_addr_mgrp4 *) a, (const net_addr_mgrp4 *) b);
|
|
|
|
case NET_MGRP6:
|
|
|
|
return net_compare_mgrp6((const net_addr_mgrp6 *) a, (const net_addr_mgrp6 *) b);
|
2016-03-02 13:37:18 +00:00
|
|
|
case NET_MPLS:
|
|
|
|
return net_compare_mpls((const net_addr_mpls *) a, (const net_addr_mpls *) b);
|
2015-12-16 09:25:12 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2015-12-07 15:24:18 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
#define NET_HASH(a,t) net_hash_##t((const net_addr_##t *) a)
|
|
|
|
|
|
|
|
u32
|
|
|
|
net_hash(const net_addr *n)
|
|
|
|
{
|
|
|
|
switch (n->type)
|
|
|
|
{
|
|
|
|
case NET_IP4: return NET_HASH(n, ip4);
|
|
|
|
case NET_IP6: return NET_HASH(n, ip6);
|
|
|
|
case NET_VPN4: return NET_HASH(n, vpn4);
|
|
|
|
case NET_VPN6: return NET_HASH(n, vpn6);
|
|
|
|
case NET_ROA4: return NET_HASH(n, roa4);
|
|
|
|
case NET_ROA6: return NET_HASH(n, roa6);
|
2016-12-07 14:36:15 +00:00
|
|
|
case NET_FLOW4: return NET_HASH(n, flow4);
|
|
|
|
case NET_FLOW6: return NET_HASH(n, flow6);
|
2018-01-22 20:09:29 +00:00
|
|
|
case NET_MREQ4: return NET_HASH(n, mreq4);
|
|
|
|
case NET_MREQ6: return NET_HASH(n, mreq6);
|
|
|
|
case NET_MGRP4: return NET_HASH(n, mgrp4);
|
|
|
|
case NET_MGRP6: return NET_HASH(n, mgrp6);
|
2017-04-05 14:16:04 +00:00
|
|
|
case NET_MPLS: return NET_HASH(n, mpls);
|
2016-12-07 13:11:28 +00:00
|
|
|
default: bug("invalid type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-04-05 14:16:04 +00:00
|
|
|
#define NET_VALIDATE(a,t) net_validate_##t((const net_addr_##t *) a)
|
|
|
|
|
2015-12-07 15:24:18 +00:00
|
|
|
int
|
2017-04-05 14:16:04 +00:00
|
|
|
net_validate(const net_addr *n)
|
2015-12-07 15:24:18 +00:00
|
|
|
{
|
2017-04-05 14:16:04 +00:00
|
|
|
switch (n->type)
|
2015-12-07 15:24:18 +00:00
|
|
|
{
|
2017-04-05 14:16:04 +00:00
|
|
|
case NET_IP4: return NET_VALIDATE(n, ip4);
|
|
|
|
case NET_IP6: return NET_VALIDATE(n, ip6);
|
|
|
|
case NET_VPN4: return NET_VALIDATE(n, vpn4);
|
|
|
|
case NET_VPN6: return NET_VALIDATE(n, vpn6);
|
|
|
|
case NET_ROA4: return NET_VALIDATE(n, roa4);
|
|
|
|
case NET_ROA6: return NET_VALIDATE(n, roa6);
|
|
|
|
case NET_FLOW4: return NET_VALIDATE(n, flow4);
|
|
|
|
case NET_FLOW6: return NET_VALIDATE(n, flow6);
|
2018-01-22 20:09:29 +00:00
|
|
|
case NET_MREQ4: return NET_VALIDATE(n, mreq4);
|
|
|
|
case NET_MREQ6: return NET_VALIDATE(n, mreq6);
|
|
|
|
case NET_MGRP4: return NET_VALIDATE(n, mgrp4);
|
|
|
|
case NET_MGRP6: return NET_VALIDATE(n, mgrp6);
|
2017-04-05 14:16:04 +00:00
|
|
|
case NET_MPLS: return NET_VALIDATE(n, mpls);
|
|
|
|
default: return 0;
|
2015-12-07 15:24:18 +00:00
|
|
|
}
|
2015-11-05 11:48:52 +00:00
|
|
|
}
|
|
|
|
|
2015-12-16 09:43:58 +00:00
|
|
|
void
|
|
|
|
net_normalize(net_addr *N)
|
|
|
|
{
|
|
|
|
net_addr_union *n = (void *) N;
|
|
|
|
|
|
|
|
switch (n->n.type)
|
|
|
|
{
|
|
|
|
case NET_IP4:
|
|
|
|
case NET_VPN4:
|
2016-01-07 17:17:16 +00:00
|
|
|
case NET_ROA4:
|
2016-12-07 14:36:15 +00:00
|
|
|
case NET_FLOW4:
|
2015-12-16 09:43:58 +00:00
|
|
|
return net_normalize_ip4(&n->ip4);
|
|
|
|
|
|
|
|
case NET_IP6:
|
|
|
|
case NET_VPN6:
|
2016-01-07 17:17:16 +00:00
|
|
|
case NET_ROA6:
|
2016-12-07 14:36:15 +00:00
|
|
|
case NET_FLOW6:
|
2015-12-16 09:43:58 +00:00
|
|
|
return net_normalize_ip6(&n->ip6);
|
2016-03-02 13:37:18 +00:00
|
|
|
|
2018-01-22 20:09:29 +00:00
|
|
|
case NET_MREQ4:
|
|
|
|
case NET_MREQ6:
|
|
|
|
case NET_MGRP4:
|
|
|
|
case NET_MGRP6:
|
2016-03-02 13:37:18 +00:00
|
|
|
case NET_MPLS:
|
|
|
|
return;
|
2015-12-16 09:43:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 11:48:52 +00:00
|
|
|
int
|
|
|
|
net_classify(const net_addr *N)
|
|
|
|
{
|
|
|
|
net_addr_union *n = (void *) N;
|
|
|
|
|
|
|
|
switch (n->n.type)
|
|
|
|
{
|
|
|
|
case NET_IP4:
|
|
|
|
case NET_VPN4:
|
2016-01-07 17:17:16 +00:00
|
|
|
case NET_ROA4:
|
2016-12-07 14:36:15 +00:00
|
|
|
case NET_FLOW4:
|
2018-01-22 20:09:29 +00:00
|
|
|
case NET_MREQ4:
|
|
|
|
case NET_MGRP4:
|
2015-11-05 11:48:52 +00:00
|
|
|
return ip4_zero(n->ip4.prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip4_classify(n->ip4.prefix);
|
|
|
|
|
|
|
|
case NET_IP6:
|
|
|
|
case NET_VPN6:
|
2016-01-07 17:17:16 +00:00
|
|
|
case NET_ROA6:
|
2016-12-07 14:36:15 +00:00
|
|
|
case NET_FLOW6:
|
2016-05-27 00:40:17 +00:00
|
|
|
case NET_MREQ6:
|
|
|
|
case NET_MGRP6:
|
2015-12-07 15:24:18 +00:00
|
|
|
return ip6_zero(n->ip6.prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip6_classify(&n->ip6.prefix);
|
2016-03-02 13:37:18 +00:00
|
|
|
|
2016-03-04 11:55:50 +00:00
|
|
|
case NET_MPLS:
|
|
|
|
return IADDR_HOST | SCOPE_UNIVERSE;
|
2015-11-05 11:48:52 +00:00
|
|
|
}
|
2015-12-07 15:24:18 +00:00
|
|
|
|
2015-12-21 16:17:21 +00:00
|
|
|
return IADDR_INVALID;
|
2015-11-05 11:48:52 +00:00
|
|
|
}
|
2015-12-16 09:43:58 +00:00
|
|
|
|
|
|
|
int
|
2015-12-21 16:17:21 +00:00
|
|
|
ipa_in_netX(const ip_addr a, const net_addr *n)
|
2015-12-16 09:43:58 +00:00
|
|
|
{
|
2015-12-21 16:17:21 +00:00
|
|
|
switch (n->type)
|
2015-12-16 09:43:58 +00:00
|
|
|
{
|
|
|
|
case NET_IP4:
|
|
|
|
case NET_VPN4:
|
2016-01-07 17:17:16 +00:00
|
|
|
case NET_ROA4:
|
2016-12-07 14:36:15 +00:00
|
|
|
case NET_FLOW4:
|
2015-12-21 16:17:21 +00:00
|
|
|
if (!ipa_is_ip4(a)) return 0;
|
|
|
|
return ip4_zero(ip4_and(ip4_xor(ipa_to_ip4(a), net4_prefix(n)),
|
|
|
|
ip4_mkmask(net4_pxlen(n))));
|
2015-12-16 09:43:58 +00:00
|
|
|
|
|
|
|
case NET_IP6:
|
|
|
|
case NET_VPN6:
|
2016-01-07 17:17:16 +00:00
|
|
|
case NET_ROA6:
|
2016-12-07 14:36:15 +00:00
|
|
|
case NET_FLOW6:
|
2015-12-21 16:17:21 +00:00
|
|
|
if (ipa_is_ip4(a)) return 0;
|
|
|
|
return ip6_zero(ip6_and(ip6_xor(ipa_to_ip6(a), net6_prefix(n)),
|
|
|
|
ip6_mkmask(net6_pxlen(n))));
|
2015-12-16 09:43:58 +00:00
|
|
|
|
2016-05-27 00:40:17 +00:00
|
|
|
case NET_MREQ4:
|
|
|
|
case NET_MGRP4:
|
|
|
|
if (!ipa_is_ip4(a)) return 0;
|
2018-01-22 20:09:29 +00:00
|
|
|
return ip4_equal(ipa_to_ip4(a), net4_prefix(n));
|
|
|
|
|
2016-05-27 00:40:17 +00:00
|
|
|
case NET_MREQ6:
|
|
|
|
case NET_MGRP6:
|
|
|
|
if (ipa_is_ip4(a)) return 0;
|
2018-01-22 20:09:29 +00:00
|
|
|
return ip6_equal(ipa_to_ip6(a), net6_prefix(n));
|
2016-05-27 00:40:17 +00:00
|
|
|
|
2016-03-02 13:37:18 +00:00
|
|
|
case NET_MPLS:
|
2015-12-21 16:17:21 +00:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2015-12-16 09:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-12-21 16:17:21 +00:00
|
|
|
net_in_netX(const net_addr *a, const net_addr *n)
|
2015-12-16 09:43:58 +00:00
|
|
|
{
|
2015-12-21 16:17:21 +00:00
|
|
|
if (a->type != n->type)
|
2015-12-16 09:43:58 +00:00
|
|
|
return 0;
|
|
|
|
|
2015-12-21 16:17:21 +00:00
|
|
|
return (net_pxlen(n) <= net_pxlen(a)) && ipa_in_netX(net_prefix(a), n);
|
2015-12-16 09:43:58 +00:00
|
|
|
}
|
2017-12-10 12:18:36 +00:00
|
|
|
|
|
|
|
#define CHECK_NET(T,S) \
|
|
|
|
({ if (sizeof(T) != S) die("sizeof %s is %d/%d", #T, (int) sizeof(T), S); })
|
|
|
|
|
|
|
|
void
|
|
|
|
net_init(void)
|
|
|
|
{
|
|
|
|
CHECK_NET(net_addr, 24);
|
|
|
|
CHECK_NET(net_addr_ip4, 8);
|
|
|
|
CHECK_NET(net_addr_ip6, 20);
|
|
|
|
CHECK_NET(net_addr_vpn4, 16);
|
|
|
|
CHECK_NET(net_addr_vpn6, 32);
|
|
|
|
CHECK_NET(net_addr_roa4, 16);
|
|
|
|
CHECK_NET(net_addr_roa6, 28);
|
|
|
|
CHECK_NET(net_addr_flow4, 8);
|
|
|
|
CHECK_NET(net_addr_flow6, 20);
|
2018-01-22 20:09:29 +00:00
|
|
|
CHECK_NET(net_addr_mreq4, 12);
|
|
|
|
CHECK_NET(net_addr_mreq6, 24);
|
|
|
|
CHECK_NET(net_addr_mgrp4, 8);
|
|
|
|
CHECK_NET(net_addr_mgrp6, 20);
|
2017-12-10 12:18:36 +00:00
|
|
|
CHECK_NET(net_addr_mpls, 8);
|
|
|
|
}
|