* [PATCH net-next] mpls: make RTA_OIF optional
@ 2015-07-21 16:16 Roopa Prabhu
2015-07-22 5:27 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Roopa Prabhu @ 2015-07-21 16:16 UTC (permalink / raw)
To: ebiederm; +Cc: davem, rshearma, netdev
From: Roopa Prabhu <roopa@cumulusnetworks.com>
If user did not specify an oif, try and get it from the via address.
If failed to get device, return with -ENODEV.
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
---
net/mpls/af_mpls.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 66 insertions(+), 1 deletion(-)
diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index 1f93a59..4cd3789 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -15,6 +15,7 @@
#include <net/ip_fib.h>
#include <net/netevent.h>
#include <net/netns/generic.h>
+#include <net/ip6_route.h>
#include "internal.h"
#define LABEL_NOT_SPECIFIED (1<<20)
@@ -327,6 +328,70 @@ static unsigned find_free_label(struct net *net)
return LABEL_NOT_SPECIFIED;
}
+static struct net_device *inet_fib_lookup_dev(struct net *net, void *addr)
+{
+ struct net_device *dev = NULL;
+ struct rtable *rt;
+ struct in_addr daddr;
+
+ memcpy(&daddr, addr, sizeof(struct in_addr));
+ rt = ip_route_output(net, daddr.s_addr, 0, 0, 0);
+ if (IS_ERR(rt))
+ goto errout;
+
+ dev = rt->dst.dev;
+ dev_hold(dev);
+
+ ip_rt_put(rt);
+
+errout:
+ return dev;
+}
+
+static struct net_device *inet6_fib_lookup_dev(struct net *net, void *addr)
+{
+ struct net_device *dev = NULL;
+ struct dst_entry *dst;
+ struct flowi6 fl6;
+
+ memset(&fl6, 0, sizeof(fl6));
+ memcpy(&fl6.daddr, addr, sizeof(struct in6_addr));
+ dst = ip6_route_output(net, NULL, &fl6);
+ if (dst->error)
+ goto errout;
+
+ dev = dst->dev;
+ dev_hold(dev);
+
+errout:
+ dst_release(dst);
+
+ return dev;
+}
+
+static struct net_device *find_outdev(struct net *net,
+ struct mpls_route_config *cfg)
+{
+ struct net_device *dev = NULL;
+
+ if (!cfg->rc_ifindex) {
+ switch (cfg->rc_via_table) {
+ case NEIGH_ARP_TABLE:
+ dev = inet_fib_lookup_dev(net, cfg->rc_via);
+ break;
+ case NEIGH_ND_TABLE:
+ dev = inet6_fib_lookup_dev(net, cfg->rc_via);
+ break;
+ case NEIGH_LINK_TABLE:
+ break;
+ }
+ } else {
+ dev = dev_get_by_index(net, cfg->rc_ifindex);
+ }
+
+ return dev;
+}
+
static int mpls_route_add(struct mpls_route_config *cfg)
{
struct mpls_route __rcu **platform_label;
@@ -358,7 +423,7 @@ static int mpls_route_add(struct mpls_route_config *cfg)
goto errout;
err = -ENODEV;
- dev = dev_get_by_index(net, cfg->rc_ifindex);
+ dev = find_outdev(net, cfg);
if (!dev)
goto errout;
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] mpls: make RTA_OIF optional
2015-07-21 16:16 [PATCH net-next] mpls: make RTA_OIF optional Roopa Prabhu
@ 2015-07-22 5:27 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2015-07-22 5:27 UTC (permalink / raw)
To: roopa; +Cc: ebiederm, rshearma, netdev
From: Roopa Prabhu <roopa@cumulusnetworks.com>
Date: Tue, 21 Jul 2015 09:16:24 -0700
> From: Roopa Prabhu <roopa@cumulusnetworks.com>
>
> If user did not specify an oif, try and get it from the via address.
> If failed to get device, return with -ENODEV.
>
> Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-07-22 5:27 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-21 16:16 [PATCH net-next] mpls: make RTA_OIF optional Roopa Prabhu
2015-07-22 5:27 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).