summaryrefslogtreecommitdiff
path: root/lib/net.c
diff options
context:
space:
mode:
authorJan Moskyto Matejka <mq@ucw.cz>2016-03-02 14:37:18 +0100
committerJan Moskyto Matejka <mq@ucw.cz>2016-12-22 13:35:16 +0100
commit33ad6e0188b56f682a012ca1b782812c96285d51 (patch)
tree75621c4a90508f543fba762592c2e57ecad6e677 /lib/net.c
parentec5e5d23faa482495c84163c4ae38d9a31bdc00f (diff)
MPLS: added net_addr_mpls variant of net_addr
Diffstat (limited to 'lib/net.c')
-rw-r--r--lib/net.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/net.c b/lib/net.c
index f283e79f..91a4474a 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -13,7 +13,8 @@ const char * const net_label[] = {
[NET_ROA4] = "roa4",
[NET_ROA6] = "roa6",
[NET_FLOW4] = "flow4",
- [NET_FLOW6] = "flow6"
+ [NET_FLOW6] = "flow6",
+ [NET_MPLS] = "mpls",
};
const u16 net_addr_length[] = {
@@ -24,7 +25,8 @@ const u16 net_addr_length[] = {
[NET_ROA4] = sizeof(net_addr_roa4),
[NET_ROA6] = sizeof(net_addr_roa6),
[NET_FLOW4] = 0,
- [NET_FLOW6] = 0
+ [NET_FLOW6] = 0,
+ [NET_MPLS] = sizeof(net_addr_mpls),
};
const u8 net_max_prefix_length[] = {
@@ -35,7 +37,8 @@ const u8 net_max_prefix_length[] = {
[NET_ROA4] = IP4_MAX_PREFIX_LENGTH,
[NET_ROA6] = IP6_MAX_PREFIX_LENGTH,
[NET_FLOW4] = IP4_MAX_PREFIX_LENGTH,
- [NET_FLOW6] = IP6_MAX_PREFIX_LENGTH
+ [NET_FLOW6] = IP6_MAX_PREFIX_LENGTH,
+ [NET_MPLS] = 0,
};
const u16 net_max_text_length[] = {
@@ -46,7 +49,8 @@ const u16 net_max_text_length[] = {
[NET_ROA4] = 34, /* "255.255.255.255/32-32 AS4294967295" */
[NET_ROA6] = 60, /* "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128-128 AS4294967295" */
[NET_FLOW4] = 0, /* "flow4 { ... }" */
- [NET_FLOW6] = 0 /* "flow6 { ... }" */
+ [NET_FLOW6] = 0, /* "flow6 { ... }" */
+ [NET_MPLS] = 7, /* "1048575" */
};
@@ -73,6 +77,8 @@ net_format(const net_addr *N, char *buf, int buflen)
return flow4_net_format(buf, buflen, &n->flow4);
case NET_FLOW6:
return flow6_net_format(buf, buflen, &n->flow6);
+ case NET_MPLS:
+ return bsnprintf(buf, buflen, "%u", n->mpls.label);
}
return 0;
@@ -95,6 +101,7 @@ net_pxmask(const net_addr *a)
case NET_FLOW6:
return ipa_from_ip6(ip6_mkmask(net6_pxlen(a)));
+ case NET_MPLS:
default:
return IPA_NONE;
}
@@ -124,6 +131,8 @@ net_compare(const net_addr *a, const net_addr *b)
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);
+ case NET_MPLS:
+ return net_compare_mpls((const net_addr_mpls *) a, (const net_addr_mpls *) b);
}
return 0;
}
@@ -165,6 +174,9 @@ net_validate(const net_addr *N)
case NET_FLOW6:
return net_validate_ip6((net_addr_ip6 *) N);
+ case NET_MPLS:
+ return net_validate_mpls((net_addr_mpls *) N);
+
default:
return 0;
}
@@ -188,6 +200,9 @@ net_normalize(net_addr *N)
case NET_ROA6:
case NET_FLOW6:
return net_normalize_ip6(&n->ip6);
+
+ case NET_MPLS:
+ return;
}
}
@@ -209,6 +224,8 @@ net_classify(const net_addr *N)
case NET_ROA6:
case NET_FLOW6:
return ip6_zero(n->ip6.prefix) ? (IADDR_HOST | SCOPE_UNIVERSE) : ip6_classify(&n->ip6.prefix);
+
+ /* classify probably not needed for NET_MPLS */
}
return IADDR_INVALID;
@@ -235,6 +252,7 @@ ipa_in_netX(const ip_addr a, const net_addr *n)
return ip6_zero(ip6_and(ip6_xor(ipa_to_ip6(a), net6_prefix(n)),
ip6_mkmask(net6_pxlen(n))));
+ case NET_MPLS:
default:
return 0;
}