diff options
author | Varun Prakash <varun@chelsio.com> | 2016-09-13 11:53:58 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-09-15 20:49:19 -0400 |
commit | 95554761d1db54f7c058cc0ed389282ce7361999 (patch) | |
tree | 8e7e3dff132cc78a3d67e14d2fda7dc4ecb5f8f9 | |
parent | 804c2f3e36ef60e6f50e6101ae06b02fbaa14b9a (diff) |
libcxgb,iw_cxgb4,cxgbit: add cxgb_find_route6()
Add cxgb_find_route6() in libcxgb_cm.c to remove
it's duplicate definitions from cxgb4/cm.c and
cxgbit/cxgbit_cm.c.
Signed-off-by: Varun Prakash <varun@chelsio.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/infiniband/hw/cxgb4/cm.c | 70 | ||||
-rw-r--r-- | drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.c | 33 | ||||
-rw-r--r-- | drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.h | 4 | ||||
-rw-r--r-- | drivers/target/iscsi/cxgbit/cxgbit_cm.c | 51 |
4 files changed, 61 insertions, 97 deletions
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c index 02f5e20cd3a3..a08a74839c13 100644 --- a/drivers/infiniband/hw/cxgb4/cm.c +++ b/drivers/infiniband/hw/cxgb4/cm.c | |||
@@ -465,46 +465,6 @@ static struct net_device *get_real_dev(struct net_device *egress_dev) | |||
465 | return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev; | 465 | return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev; |
466 | } | 466 | } |
467 | 467 | ||
468 | static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev) | ||
469 | { | ||
470 | int i; | ||
471 | |||
472 | egress_dev = get_real_dev(egress_dev); | ||
473 | for (i = 0; i < dev->rdev.lldi.nports; i++) | ||
474 | if (dev->rdev.lldi.ports[i] == egress_dev) | ||
475 | return 1; | ||
476 | return 0; | ||
477 | } | ||
478 | |||
479 | static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip, | ||
480 | __u8 *peer_ip, __be16 local_port, | ||
481 | __be16 peer_port, u8 tos, | ||
482 | __u32 sin6_scope_id) | ||
483 | { | ||
484 | struct dst_entry *dst = NULL; | ||
485 | |||
486 | if (IS_ENABLED(CONFIG_IPV6)) { | ||
487 | struct flowi6 fl6; | ||
488 | |||
489 | memset(&fl6, 0, sizeof(fl6)); | ||
490 | memcpy(&fl6.daddr, peer_ip, 16); | ||
491 | memcpy(&fl6.saddr, local_ip, 16); | ||
492 | if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL) | ||
493 | fl6.flowi6_oif = sin6_scope_id; | ||
494 | dst = ip6_route_output(&init_net, NULL, &fl6); | ||
495 | if (!dst) | ||
496 | goto out; | ||
497 | if (!our_interface(dev, ip6_dst_idev(dst)->dev) && | ||
498 | !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) { | ||
499 | dst_release(dst); | ||
500 | dst = NULL; | ||
501 | } | ||
502 | } | ||
503 | |||
504 | out: | ||
505 | return dst; | ||
506 | } | ||
507 | |||
508 | static void arp_failure_discard(void *handle, struct sk_buff *skb) | 468 | static void arp_failure_discard(void *handle, struct sk_buff *skb) |
509 | { | 469 | { |
510 | pr_err(MOD "ARP failure\n"); | 470 | pr_err(MOD "ARP failure\n"); |
@@ -2197,10 +2157,13 @@ static int c4iw_reconnect(struct c4iw_ep *ep) | |||
2197 | iptype = 4; | 2157 | iptype = 4; |
2198 | ra = (__u8 *)&raddr->sin_addr; | 2158 | ra = (__u8 *)&raddr->sin_addr; |
2199 | } else { | 2159 | } else { |
2200 | ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr, | 2160 | ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi, |
2201 | raddr6->sin6_addr.s6_addr, | 2161 | get_real_dev, |
2202 | laddr6->sin6_port, raddr6->sin6_port, 0, | 2162 | laddr6->sin6_addr.s6_addr, |
2203 | raddr6->sin6_scope_id); | 2163 | raddr6->sin6_addr.s6_addr, |
2164 | laddr6->sin6_port, | ||
2165 | raddr6->sin6_port, 0, | ||
2166 | raddr6->sin6_scope_id); | ||
2204 | iptype = 6; | 2167 | iptype = 6; |
2205 | ra = (__u8 *)&raddr6->sin6_addr; | 2168 | ra = (__u8 *)&raddr6->sin6_addr; |
2206 | } | 2169 | } |
@@ -2540,10 +2503,11 @@ static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb) | |||
2540 | , __func__, parent_ep, hwtid, | 2503 | , __func__, parent_ep, hwtid, |
2541 | local_ip, peer_ip, ntohs(local_port), | 2504 | local_ip, peer_ip, ntohs(local_port), |
2542 | ntohs(peer_port), peer_mss); | 2505 | ntohs(peer_port), peer_mss); |
2543 | dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port, | 2506 | dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev, |
2544 | PASS_OPEN_TOS_G(ntohl(req->tos_stid)), | 2507 | local_ip, peer_ip, local_port, peer_port, |
2545 | ((struct sockaddr_in6 *) | 2508 | PASS_OPEN_TOS_G(ntohl(req->tos_stid)), |
2546 | &parent_ep->com.local_addr)->sin6_scope_id); | 2509 | ((struct sockaddr_in6 *) |
2510 | &parent_ep->com.local_addr)->sin6_scope_id); | ||
2547 | } | 2511 | } |
2548 | if (!dst) { | 2512 | if (!dst) { |
2549 | printk(KERN_ERR MOD "%s - failed to find dst entry!\n", | 2513 | printk(KERN_ERR MOD "%s - failed to find dst entry!\n", |
@@ -3339,10 +3303,12 @@ int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) | |||
3339 | __func__, laddr6->sin6_addr.s6_addr, | 3303 | __func__, laddr6->sin6_addr.s6_addr, |
3340 | ntohs(laddr6->sin6_port), | 3304 | ntohs(laddr6->sin6_port), |
3341 | raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port)); | 3305 | raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port)); |
3342 | ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr, | 3306 | ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev, |
3343 | raddr6->sin6_addr.s6_addr, | 3307 | laddr6->sin6_addr.s6_addr, |
3344 | laddr6->sin6_port, raddr6->sin6_port, 0, | 3308 | raddr6->sin6_addr.s6_addr, |
3345 | raddr6->sin6_scope_id); | 3309 | laddr6->sin6_port, |
3310 | raddr6->sin6_port, 0, | ||
3311 | raddr6->sin6_scope_id); | ||
3346 | } | 3312 | } |
3347 | if (!ep->dst) { | 3313 | if (!ep->dst) { |
3348 | printk(KERN_ERR MOD "%s - cannot find route.\n", __func__); | 3314 | printk(KERN_ERR MOD "%s - cannot find route.\n", __func__); |
diff --git a/drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.c b/drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.c index a31841247954..0f0de5b63622 100644 --- a/drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.c +++ b/drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.c | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/tcp.h> | 33 | #include <linux/tcp.h> |
34 | #include <linux/ipv6.h> | 34 | #include <linux/ipv6.h> |
35 | #include <net/route.h> | 35 | #include <net/route.h> |
36 | #include <net/ip6_route.h> | ||
36 | 37 | ||
37 | #include "libcxgb_cm.h" | 38 | #include "libcxgb_cm.h" |
38 | 39 | ||
@@ -114,3 +115,35 @@ cxgb_find_route(struct cxgb4_lld_info *lldi, | |||
114 | return &rt->dst; | 115 | return &rt->dst; |
115 | } | 116 | } |
116 | EXPORT_SYMBOL(cxgb_find_route); | 117 | EXPORT_SYMBOL(cxgb_find_route); |
118 | |||
119 | struct dst_entry * | ||
120 | cxgb_find_route6(struct cxgb4_lld_info *lldi, | ||
121 | struct net_device *(*get_real_dev)(struct net_device *), | ||
122 | __u8 *local_ip, __u8 *peer_ip, __be16 local_port, | ||
123 | __be16 peer_port, u8 tos, __u32 sin6_scope_id) | ||
124 | { | ||
125 | struct dst_entry *dst = NULL; | ||
126 | |||
127 | if (IS_ENABLED(CONFIG_IPV6)) { | ||
128 | struct flowi6 fl6; | ||
129 | |||
130 | memset(&fl6, 0, sizeof(fl6)); | ||
131 | memcpy(&fl6.daddr, peer_ip, 16); | ||
132 | memcpy(&fl6.saddr, local_ip, 16); | ||
133 | if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL) | ||
134 | fl6.flowi6_oif = sin6_scope_id; | ||
135 | dst = ip6_route_output(&init_net, NULL, &fl6); | ||
136 | if (!dst) | ||
137 | goto out; | ||
138 | if (!cxgb_our_interface(lldi, get_real_dev, | ||
139 | ip6_dst_idev(dst)->dev) && | ||
140 | !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) { | ||
141 | dst_release(dst); | ||
142 | dst = NULL; | ||
143 | } | ||
144 | } | ||
145 | |||
146 | out: | ||
147 | return dst; | ||
148 | } | ||
149 | EXPORT_SYMBOL(cxgb_find_route6); | ||
diff --git a/drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.h b/drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.h index fe69161288e5..c4df04a4a323 100644 --- a/drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.h +++ b/drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.h | |||
@@ -43,4 +43,8 @@ struct dst_entry * | |||
43 | cxgb_find_route(struct cxgb4_lld_info *, | 43 | cxgb_find_route(struct cxgb4_lld_info *, |
44 | struct net_device *(*)(struct net_device *), | 44 | struct net_device *(*)(struct net_device *), |
45 | __be32, __be32, __be16, __be16, u8); | 45 | __be32, __be32, __be16, __be16, u8); |
46 | struct dst_entry * | ||
47 | cxgb_find_route6(struct cxgb4_lld_info *, | ||
48 | struct net_device *(*)(struct net_device *), | ||
49 | __u8 *, __u8 *, __be16, __be16, u8, __u32); | ||
46 | #endif | 50 | #endif |
diff --git a/drivers/target/iscsi/cxgbit/cxgbit_cm.c b/drivers/target/iscsi/cxgbit/cxgbit_cm.c index 49b24b93ab12..e961ac4bf5db 100644 --- a/drivers/target/iscsi/cxgbit/cxgbit_cm.c +++ b/drivers/target/iscsi/cxgbit/cxgbit_cm.c | |||
@@ -790,46 +790,6 @@ void _cxgbit_free_csk(struct kref *kref) | |||
790 | kfree(csk); | 790 | kfree(csk); |
791 | } | 791 | } |
792 | 792 | ||
793 | static int | ||
794 | cxgbit_our_interface(struct cxgbit_device *cdev, struct net_device *egress_dev) | ||
795 | { | ||
796 | u8 i; | ||
797 | |||
798 | egress_dev = cxgbit_get_real_dev(egress_dev); | ||
799 | for (i = 0; i < cdev->lldi.nports; i++) | ||
800 | if (cdev->lldi.ports[i] == egress_dev) | ||
801 | return 1; | ||
802 | return 0; | ||
803 | } | ||
804 | |||
805 | static struct dst_entry * | ||
806 | cxgbit_find_route6(struct cxgbit_device *cdev, __u8 *local_ip, __u8 *peer_ip, | ||
807 | __be16 local_port, __be16 peer_port, u8 tos, | ||
808 | __u32 sin6_scope_id) | ||
809 | { | ||
810 | struct dst_entry *dst = NULL; | ||
811 | |||
812 | if (IS_ENABLED(CONFIG_IPV6)) { | ||
813 | struct flowi6 fl6; | ||
814 | |||
815 | memset(&fl6, 0, sizeof(fl6)); | ||
816 | memcpy(&fl6.daddr, peer_ip, 16); | ||
817 | memcpy(&fl6.saddr, local_ip, 16); | ||
818 | if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL) | ||
819 | fl6.flowi6_oif = sin6_scope_id; | ||
820 | dst = ip6_route_output(&init_net, NULL, &fl6); | ||
821 | if (!dst) | ||
822 | goto out; | ||
823 | if (!cxgbit_our_interface(cdev, ip6_dst_idev(dst)->dev) && | ||
824 | !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) { | ||
825 | dst_release(dst); | ||
826 | dst = NULL; | ||
827 | } | ||
828 | } | ||
829 | out: | ||
830 | return dst; | ||
831 | } | ||
832 | |||
833 | static void cxgbit_set_tcp_window(struct cxgbit_sock *csk, struct port_info *pi) | 793 | static void cxgbit_set_tcp_window(struct cxgbit_sock *csk, struct port_info *pi) |
834 | { | 794 | { |
835 | unsigned int linkspeed; | 795 | unsigned int linkspeed; |
@@ -1299,11 +1259,12 @@ cxgbit_pass_accept_req(struct cxgbit_device *cdev, struct sk_buff *skb) | |||
1299 | , __func__, cnp, tid, | 1259 | , __func__, cnp, tid, |
1300 | local_ip, peer_ip, ntohs(local_port), | 1260 | local_ip, peer_ip, ntohs(local_port), |
1301 | ntohs(peer_port), peer_mss); | 1261 | ntohs(peer_port), peer_mss); |
1302 | dst = cxgbit_find_route6(cdev, local_ip, peer_ip, | 1262 | dst = cxgb_find_route6(&cdev->lldi, cxgbit_get_real_dev, |
1303 | local_port, peer_port, | 1263 | local_ip, peer_ip, |
1304 | PASS_OPEN_TOS_G(ntohl(req->tos_stid)), | 1264 | local_port, peer_port, |
1305 | ((struct sockaddr_in6 *) | 1265 | PASS_OPEN_TOS_G(ntohl(req->tos_stid)), |
1306 | &cnp->com.local_addr)->sin6_scope_id); | 1266 | ((struct sockaddr_in6 *) |
1267 | &cnp->com.local_addr)->sin6_scope_id); | ||
1307 | } | 1268 | } |
1308 | if (!dst) { | 1269 | if (!dst) { |
1309 | pr_err("%s - failed to find dst entry!\n", | 1270 | pr_err("%s - failed to find dst entry!\n", |