summaryrefslogtreecommitdiff
path: root/lib/net.c
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2023-10-15 16:04:36 +0200
committerMaria Matejka <mq@ucw.cz>2024-03-25 14:15:30 +0100
commit08571b20598c58877e1565403d970efc2b90dba6 (patch)
tree0471beb4512650ff31f179ba375757f4f9400e01 /lib/net.c
parentb95dc8f29f18eb177f91fdc4bf0716fac9b15366 (diff)
ASPA: basic data structures and Static protocol support
Diffstat (limited to 'lib/net.c')
-rw-r--r--lib/net.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/net.c b/lib/net.c
index 289a4297..76bb3e80 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -16,6 +16,7 @@ const char * const net_label[] = {
[NET_FLOW6] = "flow6",
[NET_IP6_SADR]= "ipv6-sadr",
[NET_MPLS] = "mpls",
+ [NET_ASPA] = "aspa",
};
const u16 net_addr_length[] = {
@@ -29,6 +30,7 @@ const u16 net_addr_length[] = {
[NET_FLOW6] = 0,
[NET_IP6_SADR]= sizeof(net_addr_ip6_sadr),
[NET_MPLS] = sizeof(net_addr_mpls),
+ [NET_ASPA] = sizeof(net_addr_aspa),
};
const u8 net_max_prefix_length[] = {
@@ -42,6 +44,7 @@ const u8 net_max_prefix_length[] = {
[NET_FLOW6] = IP6_MAX_PREFIX_LENGTH,
[NET_IP6_SADR]= IP6_MAX_PREFIX_LENGTH,
[NET_MPLS] = 0,
+ [NET_ASPA] = 0,
};
const u16 net_max_text_length[] = {
@@ -55,6 +58,7 @@ const u16 net_max_text_length[] = {
[NET_FLOW6] = 0, /* "flow6 { ... }" */
[NET_IP6_SADR]= 92, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128 from ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128" */
[NET_MPLS] = 7, /* "1048575" */
+ [NET_ASPA] = 10, /* "4294967295" */
};
/* There should be no implicit padding in net_addr structures */
@@ -69,6 +73,7 @@ STATIC_ASSERT(sizeof(net_addr_flow4) == 8);
STATIC_ASSERT(sizeof(net_addr_flow6) == 20);
STATIC_ASSERT(sizeof(net_addr_ip6_sadr) == 40);
STATIC_ASSERT(sizeof(net_addr_mpls) == 8);
+STATIC_ASSERT(sizeof(net_addr_aspa) == 8);
int
@@ -123,6 +128,8 @@ net_format(const net_addr *N, char *buf, int buflen)
return bsnprintf(buf, buflen, "%I6/%d from %I6/%d", n->ip6_sadr.dst_prefix, n->ip6_sadr.dst_pxlen, n->ip6_sadr.src_prefix, n->ip6_sadr.src_pxlen);
case NET_MPLS:
return bsnprintf(buf, buflen, "%u", n->mpls.label);
+ case NET_ASPA:
+ return bsnprintf(buf, buflen, "%u", n->aspa.asn);
}
bug("unknown network type");
@@ -147,6 +154,7 @@ net_pxmask(const net_addr *a)
return ipa_from_ip6(ip6_mkmask(net6_pxlen(a)));
case NET_MPLS:
+ case NET_ASPA:
default:
return IPA_NONE;
}
@@ -180,6 +188,8 @@ net_compare(const net_addr *a, const net_addr *b)
return net_compare_ip6_sadr((const net_addr_ip6_sadr *) a, (const net_addr_ip6_sadr *) b);
case NET_MPLS:
return net_compare_mpls((const net_addr_mpls *) a, (const net_addr_mpls *) b);
+ case NET_ASPA:
+ return net_compare_aspa((const net_addr_aspa *) a, (const net_addr_aspa *) b);
}
return 0;
}
@@ -201,6 +211,7 @@ net_hash(const net_addr *n)
case NET_FLOW6: return NET_HASH(n, flow6);
case NET_IP6_SADR: return NET_HASH(n, ip6_sadr);
case NET_MPLS: return NET_HASH(n, mpls);
+ case NET_ASPA: return NET_HASH(n, aspa);
default: bug("invalid type");
}
}
@@ -223,6 +234,7 @@ net_validate(const net_addr *n)
case NET_FLOW6: return NET_VALIDATE(n, flow6);
case NET_IP6_SADR: return NET_VALIDATE(n, ip6_sadr);
case NET_MPLS: return NET_VALIDATE(n, mpls);
+ case NET_ASPA: return NET_VALIDATE(n, aspa);
default: return 0;
}
}
@@ -250,6 +262,7 @@ net_normalize(net_addr *N)
return net_normalize_ip6_sadr(&n->ip6_sadr);
case NET_MPLS:
+ case NET_ASPA:
return;
}
}
@@ -277,6 +290,7 @@ net_classify(const net_addr *N)
return ip6_zero(n->ip6_sadr.dst_prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip6_classify(&n->ip6_sadr.dst_prefix);
case NET_MPLS:
+ case NET_ASPA:
return IADDR_HOST | SCOPE_UNIVERSE;
}
@@ -310,6 +324,7 @@ ipa_in_netX(const ip_addr a, const net_addr *n)
ip6_mkmask(net6_pxlen(n))));
case NET_MPLS:
+ case NET_ASPA:
default:
return 0;
}