Commit 980f4568 authored by Julian Wiedmann's avatar Julian Wiedmann Committed by David S. Miller

s390/qeth: extract helper for route validation

As follow-up to commit 0cd6783d ("s390/qeth: check dst entry before use"),
consolidate the dst_check() logic into a single helper and add a wrapper
around the cast type selection.
Signed-off-by: default avatarJulian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c097cc92
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <net/dst.h>
#include <net/ip6_fib.h>
#include <net/ipv6.h> #include <net/ipv6.h>
#include <net/if_inet6.h> #include <net/if_inet6.h>
#include <net/addrconf.h> #include <net/addrconf.h>
...@@ -877,6 +879,17 @@ static inline int qeth_get_ether_cast_type(struct sk_buff *skb) ...@@ -877,6 +879,17 @@ static inline int qeth_get_ether_cast_type(struct sk_buff *skb)
return RTN_UNICAST; return RTN_UNICAST;
} }
static inline struct dst_entry *qeth_dst_check_rcu(struct sk_buff *skb, int ipv)
{
struct dst_entry *dst = skb_dst(skb);
struct rt6_info *rt;
rt = (struct rt6_info *) dst;
if (dst)
dst = dst_check(dst, (ipv == 6) ? rt6_get_cookie(rt) : 0);
return dst;
}
static inline void qeth_rx_csum(struct qeth_card *card, struct sk_buff *skb, static inline void qeth_rx_csum(struct qeth_card *card, struct sk_buff *skb,
u8 flags) u8 flags)
{ {
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include <net/route.h> #include <net/route.h>
#include <net/ipv6.h> #include <net/ipv6.h>
#include <net/ip6_route.h> #include <net/ip6_route.h>
#include <net/ip6_fib.h>
#include <net/iucv/af_iucv.h> #include <net/iucv/af_iucv.h>
#include <linux/hashtable.h> #include <linux/hashtable.h>
...@@ -1878,26 +1877,17 @@ static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) ...@@ -1878,26 +1877,17 @@ static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
return rc; return rc;
} }
static int qeth_l3_get_cast_type(struct sk_buff *skb) static int qeth_l3_get_cast_type_rcu(struct sk_buff *skb, struct dst_entry *dst,
int ipv)
{ {
int ipv = qeth_get_ip_version(skb);
struct neighbour *n = NULL; struct neighbour *n = NULL;
struct dst_entry *dst;
rcu_read_lock();
dst = skb_dst(skb);
if (dst) {
struct rt6_info *rt = (struct rt6_info *) dst;
dst = dst_check(dst, (ipv == 6) ? rt6_get_cookie(rt) : 0);
if (dst) if (dst)
n = dst_neigh_lookup_skb(dst, skb); n = dst_neigh_lookup_skb(dst, skb);
}
if (n) { if (n) {
int cast_type = n->type; int cast_type = n->type;
rcu_read_unlock();
neigh_release(n); neigh_release(n);
if ((cast_type == RTN_BROADCAST) || if ((cast_type == RTN_BROADCAST) ||
(cast_type == RTN_MULTICAST) || (cast_type == RTN_MULTICAST) ||
...@@ -1905,7 +1895,6 @@ static int qeth_l3_get_cast_type(struct sk_buff *skb) ...@@ -1905,7 +1895,6 @@ static int qeth_l3_get_cast_type(struct sk_buff *skb)
return cast_type; return cast_type;
return RTN_UNICAST; return RTN_UNICAST;
} }
rcu_read_unlock();
/* no neighbour (eg AF_PACKET), fall back to target's IP address ... */ /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */
switch (ipv) { switch (ipv) {
...@@ -1923,6 +1912,20 @@ static int qeth_l3_get_cast_type(struct sk_buff *skb) ...@@ -1923,6 +1912,20 @@ static int qeth_l3_get_cast_type(struct sk_buff *skb)
} }
} }
static int qeth_l3_get_cast_type(struct sk_buff *skb)
{
int ipv = qeth_get_ip_version(skb);
struct dst_entry *dst;
int cast_type;
rcu_read_lock();
dst = qeth_dst_check_rcu(skb, ipv);
cast_type = qeth_l3_get_cast_type_rcu(skb, dst, ipv);
rcu_read_unlock();
return cast_type;
}
static u8 qeth_l3_cast_type_to_flag(int cast_type) static u8 qeth_l3_cast_type_to_flag(int cast_type)
{ {
if (cast_type == RTN_MULTICAST) if (cast_type == RTN_MULTICAST)
...@@ -1987,27 +1990,17 @@ static void qeth_l3_fill_header(struct qeth_qdio_out_q *queue, ...@@ -1987,27 +1990,17 @@ static void qeth_l3_fill_header(struct qeth_qdio_out_q *queue,
} }
rcu_read_lock(); rcu_read_lock();
dst = skb_dst(skb); dst = qeth_dst_check_rcu(skb, ipv);
if (ipv == 4) { if (ipv == 4) {
struct rtable *rt; struct rtable *rt = (struct rtable *) dst;
if (dst)
dst = dst_check(dst, 0);
rt = (struct rtable *) dst;
*((__be32 *) &hdr->hdr.l3.next_hop.ipv4.addr) = (rt) ? *((__be32 *) &hdr->hdr.l3.next_hop.ipv4.addr) = (rt) ?
rt_nexthop(rt, ip_hdr(skb)->daddr) : rt_nexthop(rt, ip_hdr(skb)->daddr) :
ip_hdr(skb)->daddr; ip_hdr(skb)->daddr;
} else { } else {
/* IPv6 */ /* IPv6 */
struct rt6_info *rt; struct rt6_info *rt = (struct rt6_info *) dst;
if (dst) {
rt = (struct rt6_info *) dst;
dst = dst_check(dst, rt6_get_cookie(rt));
}
rt = (struct rt6_info *) dst;
if (rt && !ipv6_addr_any(&rt->rt6i_gateway)) if (rt && !ipv6_addr_any(&rt->rt6i_gateway))
l3_hdr->next_hop.ipv6_addr = rt->rt6i_gateway; l3_hdr->next_hop.ipv6_addr = rt->rt6i_gateway;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment