Skip to content

Commit

Permalink
Merge branch 'mpls-build-fix'
Browse files Browse the repository at this point in the history
Roopa Prabhu says:

====================
af_mpls: fix undefined reference to ip6_route_output with CONFIG_IPV6=n

This patch series uses ipv6_stub_impl.ipv6_dst_lookup instead of
ip6_route_output. Follows the vxlan drivers usage of
ipv6_stub_impl.ipv6_dst_lookup.

There is no sk in the af_mpls context from where
ipv6_stub_impl.ipv6_dst_lookup is used. sk appears to be needed
to get the namespace 'net' and is optional otherwise. This patch series
changes ipv6_stub_impl.ipv6_dst_lookup to take net argument. sk remains
optional.

v1 - v2: use IS_BUILTIN

v2 - v3: Use new Kconfig option that depends on (IPV6 || IPV6=n) as
	 suggested by Dave. Also uses IS_ERR as suggested by Thomas.

v3 - v4: Include missed case of (MPLS_ROUTING=y && IPV6=m) reported by
         Dave.

v4 - v5: Use ipv6_stub_impl.ipv6_dst_lookup as suggested by Hannes

v5 - v6: protect against null ipv6_stub by statically declaring
	 a ipv6_dst_lookup NOP func
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jul 31, 2015
2 parents d3aa45c + bf21563 commit 7576012
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 23 deletions.
2 changes: 1 addition & 1 deletion drivers/net/vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
fl6.flowi6_mark = skb->mark;
fl6.flowi6_proto = IPPROTO_UDP;

if (ipv6_stub->ipv6_dst_lookup(sk, &ndst, &fl6)) {
if (ipv6_stub->ipv6_dst_lookup(vxlan->net, sk, &ndst, &fl6)) {
netdev_dbg(dev, "no route to %pI6\n",
&dst->sin6.sin6_addr);
dev->stats.tx_carrier_errors++;
Expand Down
4 changes: 2 additions & 2 deletions include/net/addrconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ struct ipv6_stub {
const struct in6_addr *addr);
int (*ipv6_sock_mc_drop)(struct sock *sk, int ifindex,
const struct in6_addr *addr);
int (*ipv6_dst_lookup)(struct sock *sk, struct dst_entry **dst,
struct flowi6 *fl6);
int (*ipv6_dst_lookup)(struct net *net, struct sock *sk,
struct dst_entry **dst, struct flowi6 *fl6);
void (*udpv6_encap_enable)(void);
void (*ndisc_send_na)(struct net_device *dev, struct neighbour *neigh,
const struct in6_addr *daddr,
Expand Down
3 changes: 2 additions & 1 deletion include/net/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,8 @@ static inline struct sk_buff *ip6_finish_skb(struct sock *sk)
&inet6_sk(sk)->cork);
}

int ip6_dst_lookup(struct sock *sk, struct dst_entry **dst, struct flowi6 *fl6);
int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst,
struct flowi6 *fl6);
struct dst_entry *ip6_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
const struct in6_addr *final_dst);
struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
Expand Down
11 changes: 10 additions & 1 deletion net/ipv6/addrconf_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,16 @@ int inet6addr_notifier_call_chain(unsigned long val, void *v)
}
EXPORT_SYMBOL(inet6addr_notifier_call_chain);

const struct ipv6_stub *ipv6_stub __read_mostly;
static int eafnosupport_ipv6_dst_lookup(struct net *net, struct sock *u1,
struct dst_entry **u2,
struct flowi6 *u3)
{
return -EAFNOSUPPORT;
}

const struct ipv6_stub *ipv6_stub __read_mostly = &(struct ipv6_stub) {
.ipv6_dst_lookup = eafnosupport_ipv6_dst_lookup,
};
EXPORT_SYMBOL_GPL(ipv6_stub);

/* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */
Expand Down
6 changes: 3 additions & 3 deletions net/ipv6/icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ static struct dst_entry *icmpv6_route_lookup(struct net *net,
struct flowi6 fl2;
int err;

err = ip6_dst_lookup(sk, &dst, fl6);
err = ip6_dst_lookup(net, sk, &dst, fl6);
if (err)
return ERR_PTR(err);

Expand Down Expand Up @@ -361,7 +361,7 @@ static struct dst_entry *icmpv6_route_lookup(struct net *net,
if (err)
goto relookup_failed;

err = ip6_dst_lookup(sk, &dst2, &fl2);
err = ip6_dst_lookup(net, sk, &dst2, &fl2);
if (err)
goto relookup_failed;

Expand Down Expand Up @@ -591,7 +591,7 @@ static void icmpv6_echo_reply(struct sk_buff *skb)
else if (!fl6.flowi6_oif)
fl6.flowi6_oif = np->ucast_oif;

err = ip6_dst_lookup(sk, &dst, &fl6);
err = ip6_dst_lookup(net, sk, &dst, &fl6);
if (err)
goto out;
dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), sk, 0);
Expand Down
12 changes: 6 additions & 6 deletions net/ipv6/ip6_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -881,10 +881,9 @@ static struct dst_entry *ip6_sk_dst_check(struct sock *sk,
return dst;
}

static int ip6_dst_lookup_tail(struct sock *sk,
static int ip6_dst_lookup_tail(struct net *net, struct sock *sk,
struct dst_entry **dst, struct flowi6 *fl6)
{
struct net *net = sock_net(sk);
#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
struct neighbour *n;
struct rt6_info *rt;
Expand Down Expand Up @@ -994,10 +993,11 @@ static int ip6_dst_lookup_tail(struct sock *sk,
*
* It returns zero on success, or a standard errno code on error.
*/
int ip6_dst_lookup(struct sock *sk, struct dst_entry **dst, struct flowi6 *fl6)
int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst,
struct flowi6 *fl6)
{
*dst = NULL;
return ip6_dst_lookup_tail(sk, dst, fl6);
return ip6_dst_lookup_tail(net, sk, dst, fl6);
}
EXPORT_SYMBOL_GPL(ip6_dst_lookup);

Expand All @@ -1018,7 +1018,7 @@ struct dst_entry *ip6_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
struct dst_entry *dst = NULL;
int err;

err = ip6_dst_lookup_tail(sk, &dst, fl6);
err = ip6_dst_lookup_tail(sock_net(sk), sk, &dst, fl6);
if (err)
return ERR_PTR(err);
if (final_dst)
Expand Down Expand Up @@ -1052,7 +1052,7 @@ struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,

dst = ip6_sk_dst_check(sk, dst, fl6);

err = ip6_dst_lookup_tail(sk, &dst, fl6);
err = ip6_dst_lookup_tail(sock_net(sk), sk, &dst, fl6);
if (err)
return ERR_PTR(err);
if (final_dst)
Expand Down
41 changes: 33 additions & 8 deletions net/mpls/af_mpls.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
#include <net/ip_fib.h>
#include <net/netevent.h>
#include <net/netns/generic.h>
#include <net/ip6_route.h>
#if IS_ENABLED(CONFIG_IPV6)
#include <net/ipv6.h>
#include <net/addrconf.h>
#endif
#include "internal.h"

#define LABEL_NOT_SPECIFIED (1<<20)
Expand Down Expand Up @@ -331,6 +334,7 @@ static unsigned find_free_label(struct net *net)
return LABEL_NOT_SPECIFIED;
}

#if IS_ENABLED(CONFIG_INET)
static struct net_device *inet_fib_lookup_dev(struct net *net, void *addr)
{
struct net_device *dev = NULL;
Expand All @@ -347,30 +351,49 @@ static struct net_device *inet_fib_lookup_dev(struct net *net, void *addr)

ip_rt_put(rt);

errout:
return dev;
errout:
return ERR_PTR(-ENODEV);
}
#else
static struct net_device *inet_fib_lookup_dev(struct net *net, void *addr)
{
return ERR_PTR(-EAFNOSUPPORT);
}
#endif

#if IS_ENABLED(CONFIG_IPV6)
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;
int err;

if (!ipv6_stub)
return ERR_PTR(-EAFNOSUPPORT);

memset(&fl6, 0, sizeof(fl6));
memcpy(&fl6.daddr, addr, sizeof(struct in6_addr));
dst = ip6_route_output(net, NULL, &fl6);
if (dst->error)
err = ipv6_stub->ipv6_dst_lookup(net, NULL, &dst, &fl6);
if (err)
goto errout;

dev = dst->dev;
dev_hold(dev);

errout:
dst_release(dst);

return dev;

errout:
return ERR_PTR(err);
}
#else
static struct net_device *inet6_fib_lookup_dev(struct net *net, void *addr)
{
return ERR_PTR(-EAFNOSUPPORT);
}
#endif

static struct net_device *find_outdev(struct net *net,
struct mpls_route_config *cfg)
Expand Down Expand Up @@ -425,10 +448,12 @@ static int mpls_route_add(struct mpls_route_config *cfg)
if (cfg->rc_output_labels > MAX_NEW_LABELS)
goto errout;

err = -ENODEV;
dev = find_outdev(net, cfg);
if (!dev)
if (IS_ERR(dev)) {
err = PTR_ERR(dev);
dev = NULL;
goto errout;
}

/* Ensure this is a supported device */
err = -EINVAL;
Expand Down
3 changes: 2 additions & 1 deletion net/tipc/udp_media.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ static int tipc_udp_send_msg(struct net *net, struct sk_buff *skb,
.saddr = src->ipv6,
.flowi6_proto = IPPROTO_UDP
};
err = ipv6_stub->ipv6_dst_lookup(ub->ubsock->sk, &ndst, &fl6);
err = ipv6_stub->ipv6_dst_lookup(net, ub->ubsock->sk, &ndst,
&fl6);
if (err)
goto tx_error;
ttl = ip6_dst_hoplimit(ndst);
Expand Down

0 comments on commit 7576012

Please sign in to comment.