diff options
author | Pravin B Shelar <pshelar@ovn.org> | 2016-03-24 09:30:57 -0700 |
---|---|---|
committer | Pravin B Shelar <pshelar@ovn.org> | 2016-03-24 09:30:57 -0700 |
commit | ec6c537986b4c7dc852575107e32184b33d974e8 (patch) | |
tree | 462ea495258de0f76666414d0c96108f1cc71fb9 /lib | |
parent | 6b6e13293e825dc69937615f42fc99eb023c9086 (diff) | |
download | openvswitch-ec6c537986b4c7dc852575107e32184b33d974e8.tar.gz |
sflow: use ovs route API to get source IP address.
Signed-off-by: Pravin B Shelar <pshelar@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ovs-router.c | 33 | ||||
-rw-r--r-- | lib/ovs-router.h | 1 | ||||
-rw-r--r-- | lib/route-table-bsd.c | 15 | ||||
-rw-r--r-- | lib/route-table-stub.c | 8 | ||||
-rw-r--r-- | lib/route-table.c | 8 | ||||
-rw-r--r-- | lib/route-table.h | 6 |
6 files changed, 42 insertions, 29 deletions
diff --git a/lib/ovs-router.c b/lib/ovs-router.c index 82923ff26..0d52bf935 100644 --- a/lib/ovs-router.c +++ b/lib/ovs-router.c @@ -69,6 +69,24 @@ ovs_router_entry_cast(const struct cls_rule *cr) } } +static bool +ovs_router_lookup_fallback(const struct in6_addr *ip6_dst, char output_bridge[], + struct in6_addr *src6, struct in6_addr *gw6) +{ + ovs_be32 src; + + if (!route_table_fallback_lookup(ip6_dst, output_bridge, gw6)) { + return false; + } + if (netdev_get_in4_by_name(output_bridge, (struct in_addr *)&src)) { + return false; + } + if (src6) { + in6_addr_set_mapped_ipv4(src6, src); + } + return true; +} + bool ovs_router_lookup(const struct in6_addr *ip6_dst, char output_bridge[], struct in6_addr *src, struct in6_addr *gw) @@ -87,20 +105,7 @@ ovs_router_lookup(const struct in6_addr *ip6_dst, char output_bridge[], } return true; } - return false; -} - -bool -ovs_router_lookup4(ovs_be32 ip_dst, char output_bridge[], ovs_be32 *gw) -{ - struct in6_addr ip6_dst = in6_addr_mapped_ipv4(ip_dst); - struct in6_addr gw6; - - if (ovs_router_lookup(&ip6_dst, output_bridge, NULL, &gw6)) { - *gw = in6_addr_get_mapped_ipv4(&gw6); - return true; - } - return route_table_fallback_lookup(ip_dst, output_bridge, gw); + return ovs_router_lookup_fallback(ip6_dst, output_bridge, src, gw); } static void diff --git a/lib/ovs-router.h b/lib/ovs-router.h index 9ac61ce60..9cb7509b2 100644 --- a/lib/ovs-router.h +++ b/lib/ovs-router.h @@ -27,7 +27,6 @@ extern "C" { bool ovs_router_lookup(const struct in6_addr *ip_dst, char out_dev[], struct in6_addr *src, struct in6_addr *gw); -bool ovs_router_lookup4(ovs_be32 ip_dst, char out_dev[], ovs_be32 *gw); void ovs_router_init(void); void ovs_router_insert(const struct in6_addr *ip_dst, uint8_t plen, const char output_bridge[], const struct in6_addr *gw); diff --git a/lib/route-table-bsd.c b/lib/route-table-bsd.c index 76a8d3d97..34d42cfab 100644 --- a/lib/route-table-bsd.c +++ b/lib/route-table-bsd.c @@ -44,8 +44,10 @@ VLOG_DEFINE_THIS_MODULE(route_table_bsd); #endif bool -route_table_fallback_lookup(ovs_be32 ip, char name[], ovs_be32 *gw) +route_table_fallback_lookup(const struct in6_addr *ip6_dst, char name[], + struct in6_addr *gw6) { + ovs_be32 ip; struct { struct rt_msghdr rtm; char space[512]; @@ -62,6 +64,11 @@ route_table_fallback_lookup(ovs_be32 ip, char name[], ovs_be32 *gw) bool got_ifp = false; unsigned int retry_count = 5; /* arbitrary */ + if (!IN6_IS_ADDR_V4MAPPED(ip6_dst)) { + return false; + } + ip = in6_addr_get_mapped_ipv4(ip6_dst); + VLOG_DBG("looking route up for " IP_FMT " pid %" PRIuMAX, IP_ARGS(ip), (uintmax_t)pid); @@ -142,7 +149,7 @@ retry: return false; } - *gw = 0; + *gw6 = in6addr_any; sa = (struct sockaddr *)(rtm + 1); for (i = 1; i; i <<= 1) { if (rtm->rtm_addrs & i) { @@ -160,8 +167,8 @@ retry: const struct sockaddr_in *sin_dst = ALIGNED_CAST(struct sockaddr_in *, sa); - *gw = sin_dst->sin_addr.s_addr; - VLOG_DBG("got gateway " IP_FMT, IP_ARGS(*gw)); + in6_addr_set_mapped_ipv4(gw6, sin_dst->sin_addr.s_addr); + VLOG_DBG("got gateway " IP_FMT, IP_ARGS(sin_dst->sin_addr.s_addr)); } #if defined(__FreeBSD__) sa = (struct sockaddr *)((char *)sa + SA_SIZE(sa)); diff --git a/lib/route-table-stub.c b/lib/route-table-stub.c index 70b1a3d1c..dd0b096d4 100644 --- a/lib/route-table-stub.c +++ b/lib/route-table-stub.c @@ -19,11 +19,11 @@ #include "route-table.h" bool -route_table_fallback_lookup(ovs_be32 ip_dst OVS_UNUSED, - char output_bridge[] OVS_UNUSED, - ovs_be32 *gw) +route_table_fallback_lookup(const struct in6_addr *ip6_dst OVS_UNUSED, + char name[] OVS_UNUSED, + struct in6_addr *gw6) { - *gw = 0; + *gw6 = in6addr_any; return false; } diff --git a/lib/route-table.c b/lib/route-table.c index 649b65623..f45f9fdbf 100644 --- a/lib/route-table.c +++ b/lib/route-table.c @@ -308,11 +308,11 @@ route_map_clear(void) } bool -route_table_fallback_lookup(ovs_be32 ip_dst OVS_UNUSED, - char output_bridge[] OVS_UNUSED, - ovs_be32 *gw) +route_table_fallback_lookup(const struct in6_addr *ip6_dst OVS_UNUSED, + char name[] OVS_UNUSED, + struct in6_addr *gw6) { - *gw = 0; + *gw6 = in6addr_any; return false; } diff --git a/lib/route-table.h b/lib/route-table.h index 54d77f416..3a02d737a 100644 --- a/lib/route-table.h +++ b/lib/route-table.h @@ -20,6 +20,7 @@ #include <sys/types.h> #include <sys/socket.h> #include <net/if.h> +#include <netinet/in.h> #include <stdbool.h> #include <stdint.h> @@ -29,6 +30,7 @@ uint64_t route_table_get_change_seq(void); void route_table_init(void); void route_table_run(void); void route_table_wait(void); -bool route_table_fallback_lookup(ovs_be32, char [], ovs_be32 *); - +bool route_table_fallback_lookup(const struct in6_addr *ip6_dst, + char name[], + struct in6_addr *gw6); #endif /* route-table.h */ |