Skip to content

Commit a9e527e

Browse files
Rolf ManderscheidRoland Dreier
authored andcommitted
IPoIB: improve IPv4/IPv6 to IB mcast mapping functions
An IPoIB subnet on an IB fabric that spans multiple IB subnets can't use link-local scope in multicast GIDs. The existing routines that map IP/IPv6 multicast addresses into IB link-level addresses hard-code the scope to link-local, and they also leave the partition key field uninitialised. This patch adds a parameter (the link-level broadcast address) to the mapping routines, allowing them to initialise both the scope and the P_Key appropriately, and fixes up the call sites. The next step will be to add a way to configure the scope for an IPoIB interface. Signed-off-by: Rolf Manderscheid <rvm@obsidianresearch.com> Signed-off-by: Roland Dreier <rolandd@cisco.com>
1 parent 755807a commit a9e527e

6 files changed

Lines changed: 16 additions & 17 deletions

File tree

‎drivers/infiniband/core/cma.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,11 +2610,9 @@ static void cma_set_mgid(struct rdma_id_private *id_priv,
26102610
/* IPv6 address is an SA assigned MGID. */
26112611
memcpy(mgid, &sin6->sin6_addr, sizeof *mgid);
26122612
} else {
2613-
ip_ib_mc_map(sin->sin_addr.s_addr, mc_map);
2613+
ip_ib_mc_map(sin->sin_addr.s_addr, dev_addr->broadcast, mc_map);
26142614
if (id_priv->id.ps == RDMA_PS_UDP)
26152615
mc_map[7] = 0x01; /* Use RDMA CM signature */
2616-
mc_map[8] = ib_addr_get_pkey(dev_addr) >> 8;
2617-
mc_map[9] = (unsigned char) ib_addr_get_pkey(dev_addr);
26182616
*mgid = *(union ib_gid *) (mc_map + 4);
26192617
}
26202618
}

‎drivers/infiniband/ulp/ipoib/ipoib_multicast.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,10 +788,6 @@ void ipoib_mcast_restart_task(struct work_struct *work)
788788

789789
memcpy(mgid.raw, mclist->dmi_addr + 4, sizeof mgid);
790790

791-
/* Add in the P_Key */
792-
mgid.raw[4] = (priv->pkey >> 8) & 0xff;
793-
mgid.raw[5] = priv->pkey & 0xff;
794-
795791
mcast = __ipoib_mcast_find(dev, &mgid);
796792
if (!mcast || test_bit(IPOIB_MCAST_FLAG_SENDONLY, &mcast->flags)) {
797793
struct ipoib_mcast *nmcast;

‎include/net/if_inet6.h‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,21 @@ static inline void ipv6_arcnet_mc_map(const struct in6_addr *addr, char *buf)
269269
buf[0] = 0x00;
270270
}
271271

272-
static inline void ipv6_ib_mc_map(struct in6_addr *addr, char *buf)
272+
static inline void ipv6_ib_mc_map(const struct in6_addr *addr,
273+
const unsigned char *broadcast, char *buf)
273274
{
275+
unsigned char scope = broadcast[5] & 0xF;
276+
274277
buf[0] = 0; /* Reserved */
275278
buf[1] = 0xff; /* Multicast QPN */
276279
buf[2] = 0xff;
277280
buf[3] = 0xff;
278281
buf[4] = 0xff;
279-
buf[5] = 0x12; /* link local scope */
282+
buf[5] = 0x10 | scope; /* scope from broadcast address */
280283
buf[6] = 0x60; /* IPv6 signature */
281284
buf[7] = 0x1b;
282-
buf[8] = 0; /* P_Key */
283-
buf[9] = 0;
285+
buf[8] = broadcast[8]; /* P_Key */
286+
buf[9] = broadcast[9];
284287
memcpy(buf + 10, addr->s6_addr + 6, 10);
285288
}
286289
#endif

‎include/net/ip.h‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,20 +266,22 @@ static inline void ip_eth_mc_map(__be32 naddr, char *buf)
266266
* Leave P_Key as 0 to be filled in by driver.
267267
*/
268268

269-
static inline void ip_ib_mc_map(__be32 naddr, char *buf)
269+
static inline void ip_ib_mc_map(__be32 naddr, const unsigned char *broadcast, char *buf)
270270
{
271271
__u32 addr;
272+
unsigned char scope = broadcast[5] & 0xF;
273+
272274
buf[0] = 0; /* Reserved */
273275
buf[1] = 0xff; /* Multicast QPN */
274276
buf[2] = 0xff;
275277
buf[3] = 0xff;
276278
addr = ntohl(naddr);
277279
buf[4] = 0xff;
278-
buf[5] = 0x12; /* link local scope */
280+
buf[5] = 0x10 | scope; /* scope from broadcast address */
279281
buf[6] = 0x40; /* IPv4 signature */
280282
buf[7] = 0x1b;
281-
buf[8] = 0; /* P_Key */
282-
buf[9] = 0;
283+
buf[8] = broadcast[8]; /* P_Key */
284+
buf[9] = broadcast[9];
283285
buf[10] = 0;
284286
buf[11] = 0;
285287
buf[12] = 0;

‎net/ipv4/arp.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ int arp_mc_map(__be32 addr, u8 *haddr, struct net_device *dev, int dir)
211211
ip_tr_mc_map(addr, haddr);
212212
return 0;
213213
case ARPHRD_INFINIBAND:
214-
ip_ib_mc_map(addr, haddr);
214+
ip_ib_mc_map(addr, dev->broadcast, haddr);
215215
return 0;
216216
default:
217217
if (dir) {

‎net/ipv6/ndisc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ int ndisc_mc_map(struct in6_addr *addr, char *buf, struct net_device *dev, int d
337337
ipv6_arcnet_mc_map(addr, buf);
338338
return 0;
339339
case ARPHRD_INFINIBAND:
340-
ipv6_ib_mc_map(addr, buf);
340+
ipv6_ib_mc_map(addr, dev->broadcast, buf);
341341
return 0;
342342
default:
343343
if (dir) {

0 commit comments

Comments
 (0)