summaryrefslogtreecommitdiffstats
path: root/src/vnet/ip/ip.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/ip/ip.c')
-rw-r--r--src/vnet/ip/ip.c57
1 files changed, 45 insertions, 12 deletions
diff --git a/src/vnet/ip/ip.c b/src/vnet/ip/ip.c
index caa553dd6d7..bd9706b846d 100644
--- a/src/vnet/ip/ip.c
+++ b/src/vnet/ip/ip.c
@@ -63,6 +63,24 @@ ip_is_local (u32 fib_index, ip46_address_t * ip46_address, u8 is_ip4)
return (flags & FIB_ENTRY_FLAG_LOCAL);
}
+void
+ip_copy (ip46_address_t * dst, ip46_address_t * src, u8 is_ip4)
+{
+ if (is_ip4)
+ dst->ip4.as_u32 = src->ip4.as_u32;
+ else
+ clib_memcpy (&dst->ip6, &src->ip6, sizeof (ip6_address_t));
+}
+
+void
+ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
+{
+ if (is_ip4)
+ dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
+ else
+ clib_memcpy (&dst->ip6, (ip6_address_t *) src, sizeof (ip6_address_t));
+}
+
u8
ip_interface_has_address (u32 sw_if_index, ip46_address_t * ip, u8 is_ip4)
{
@@ -97,22 +115,37 @@ ip_interface_has_address (u32 sw_if_index, ip46_address_t * ip, u8 is_ip4)
return 0;
}
-void
-ip_copy (ip46_address_t * dst, ip46_address_t * src, u8 is_ip4)
+void *
+ip_interface_get_first_ip (u32 sw_if_index, u8 is_ip4)
{
- if (is_ip4)
- dst->ip4.as_u32 = src->ip4.as_u32;
- else
- clib_memcpy (&dst->ip6, &src->ip6, sizeof (ip6_address_t));
-}
+ ip_lookup_main_t *lm4 = &ip4_main.lookup_main;
+ ip_lookup_main_t *lm6 = &ip6_main.lookup_main;
+ ip_interface_address_t *ia = 0;
-void
-ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
-{
if (is_ip4)
- dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
+ {
+ /* *INDENT-OFF* */
+ foreach_ip_interface_address (lm4, ia, sw_if_index, 1 /* unnumbered */ ,
+ ({
+ return ip_interface_address_get_address (lm4, ia);
+ }));
+ /* *INDENT-ON* */
+ }
else
- clib_memcpy (&dst->ip6, (ip6_address_t *) src, sizeof (ip6_address_t));
+ {
+ /* *INDENT-OFF* */
+ foreach_ip_interface_address (lm6, ia, sw_if_index, 1 /* unnumbered */ ,
+ ({
+ ip6_address_t *rv;
+ rv = ip_interface_address_get_address (lm6, ia);
+ /* Trying to use a link-local ip6 src address is a fool's errand */
+ if (!ip6_address_is_link_local_unicast (rv))
+ return rv;
+ }));
+ /* *INDENT-ON* */
+ }
+
+ return 0;
}
/*