Commit 8d00e202 authored by David S. Miller's avatar David S. Miller

Merge branch 'tipc-multicast-through-replication'

Jon Maloy says:

====================
tipc: emulate multicast through replication

TIPC multicast messages are currently distributed via L2 broadcast
or IP multicast to all nodes in the cluster, irrespective of the
number of real destinations of the message.

In this series we introduce an option to transport messages via
replication ("replicast") across a selected number of unicast links,
instead of relying on the underlying media. This option is used when
true broadcast/multicast is not supported by the media, or when the
number of true destinations is much smaller than the cluster size.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents a5e8c070 01fd12bb
/* /*
* include/uapi/linux/tipc.h: Header for TIPC socket interface * include/uapi/linux/tipc.h: Header for TIPC socket interface
* *
* Copyright (c) 2003-2006, Ericsson AB * Copyright (c) 2003-2006, 2015-2016 Ericsson AB
* Copyright (c) 2005, 2010-2011, Wind River Systems * Copyright (c) 2005, 2010-2011, Wind River Systems
* All rights reserved. * All rights reserved.
* *
...@@ -220,7 +220,7 @@ struct sockaddr_tipc { ...@@ -220,7 +220,7 @@ struct sockaddr_tipc {
#define TIPC_DESTNAME 3 /* destination name */ #define TIPC_DESTNAME 3 /* destination name */
/* /*
* TIPC-specific socket option values * TIPC-specific socket option names
*/ */
#define TIPC_IMPORTANCE 127 /* Default: TIPC_LOW_IMPORTANCE */ #define TIPC_IMPORTANCE 127 /* Default: TIPC_LOW_IMPORTANCE */
...@@ -229,6 +229,8 @@ struct sockaddr_tipc { ...@@ -229,6 +229,8 @@ struct sockaddr_tipc {
#define TIPC_CONN_TIMEOUT 130 /* Default: 8000 (ms) */ #define TIPC_CONN_TIMEOUT 130 /* Default: 8000 (ms) */
#define TIPC_NODE_RECVQ_DEPTH 131 /* Default: none (read only) */ #define TIPC_NODE_RECVQ_DEPTH 131 /* Default: none (read only) */
#define TIPC_SOCK_RECVQ_DEPTH 132 /* Default: none (read only) */ #define TIPC_SOCK_RECVQ_DEPTH 132 /* Default: none (read only) */
#define TIPC_MCAST_BROADCAST 133 /* Default: TIPC selects. No arg */
#define TIPC_MCAST_REPLICAST 134 /* Default: TIPC selects. No arg */
/* /*
* Maximum sizes of TIPC bearer-related names (including terminating NULL) * Maximum sizes of TIPC bearer-related names (including terminating NULL)
......
/* /*
* net/tipc/bcast.c: TIPC broadcast code * net/tipc/bcast.c: TIPC broadcast code
* *
* Copyright (c) 2004-2006, 2014-2015, Ericsson AB * Copyright (c) 2004-2006, 2014-2016, Ericsson AB
* Copyright (c) 2004, Intel Corporation. * Copyright (c) 2004, Intel Corporation.
* Copyright (c) 2005, 2010-2011, Wind River Systems * Copyright (c) 2005, 2010-2011, Wind River Systems
* All rights reserved. * All rights reserved.
...@@ -39,9 +39,8 @@ ...@@ -39,9 +39,8 @@
#include "socket.h" #include "socket.h"
#include "msg.h" #include "msg.h"
#include "bcast.h" #include "bcast.h"
#include "name_distr.h"
#include "link.h" #include "link.h"
#include "node.h" #include "name_table.h"
#define BCLINK_WIN_DEFAULT 50 /* bcast link window size (default) */ #define BCLINK_WIN_DEFAULT 50 /* bcast link window size (default) */
#define BCLINK_WIN_MIN 32 /* bcast minimum link window size */ #define BCLINK_WIN_MIN 32 /* bcast minimum link window size */
...@@ -54,12 +53,20 @@ const char tipc_bclink_name[] = "broadcast-link"; ...@@ -54,12 +53,20 @@ const char tipc_bclink_name[] = "broadcast-link";
* @inputq: data input queue; will only carry SOCK_WAKEUP messages * @inputq: data input queue; will only carry SOCK_WAKEUP messages
* @dest: array keeping number of reachable destinations per bearer * @dest: array keeping number of reachable destinations per bearer
* @primary_bearer: a bearer having links to all broadcast destinations, if any * @primary_bearer: a bearer having links to all broadcast destinations, if any
* @bcast_support: indicates if primary bearer, if any, supports broadcast
* @rcast_support: indicates if all peer nodes support replicast
* @rc_ratio: dest count as percentage of cluster size where send method changes
* @bc_threshold: calculated drom rc_ratio; if dests > threshold use broadcast
*/ */
struct tipc_bc_base { struct tipc_bc_base {
struct tipc_link *link; struct tipc_link *link;
struct sk_buff_head inputq; struct sk_buff_head inputq;
int dests[MAX_BEARERS]; int dests[MAX_BEARERS];
int primary_bearer; int primary_bearer;
bool bcast_support;
bool rcast_support;
int rc_ratio;
int bc_threshold;
}; };
static struct tipc_bc_base *tipc_bc_base(struct net *net) static struct tipc_bc_base *tipc_bc_base(struct net *net)
...@@ -69,7 +76,20 @@ static struct tipc_bc_base *tipc_bc_base(struct net *net) ...@@ -69,7 +76,20 @@ static struct tipc_bc_base *tipc_bc_base(struct net *net)
int tipc_bcast_get_mtu(struct net *net) int tipc_bcast_get_mtu(struct net *net)
{ {
return tipc_link_mtu(tipc_bc_sndlink(net)); return tipc_link_mtu(tipc_bc_sndlink(net)) - INT_H_SIZE;
}
void tipc_bcast_disable_rcast(struct net *net)
{
tipc_bc_base(net)->rcast_support = false;
}
static void tipc_bcbase_calc_bc_threshold(struct net *net)
{
struct tipc_bc_base *bb = tipc_bc_base(net);
int cluster_size = tipc_link_bc_peers(tipc_bc_sndlink(net));
bb->bc_threshold = 1 + (cluster_size * bb->rc_ratio / 100);
} }
/* tipc_bcbase_select_primary(): find a bearer with links to all destinations, /* tipc_bcbase_select_primary(): find a bearer with links to all destinations,
...@@ -79,9 +99,10 @@ static void tipc_bcbase_select_primary(struct net *net) ...@@ -79,9 +99,10 @@ static void tipc_bcbase_select_primary(struct net *net)
{ {
struct tipc_bc_base *bb = tipc_bc_base(net); struct tipc_bc_base *bb = tipc_bc_base(net);
int all_dests = tipc_link_bc_peers(bb->link); int all_dests = tipc_link_bc_peers(bb->link);
int i, mtu; int i, mtu, prim;
bb->primary_bearer = INVALID_BEARER_ID; bb->primary_bearer = INVALID_BEARER_ID;
bb->bcast_support = true;
if (!all_dests) if (!all_dests)
return; return;
...@@ -93,7 +114,7 @@ static void tipc_bcbase_select_primary(struct net *net) ...@@ -93,7 +114,7 @@ static void tipc_bcbase_select_primary(struct net *net)
mtu = tipc_bearer_mtu(net, i); mtu = tipc_bearer_mtu(net, i);
if (mtu < tipc_link_mtu(bb->link)) if (mtu < tipc_link_mtu(bb->link))
tipc_link_set_mtu(bb->link, mtu); tipc_link_set_mtu(bb->link, mtu);
bb->bcast_support &= tipc_bearer_bcast_support(net, i);
if (bb->dests[i] < all_dests) if (bb->dests[i] < all_dests)
continue; continue;
...@@ -103,6 +124,9 @@ static void tipc_bcbase_select_primary(struct net *net) ...@@ -103,6 +124,9 @@ static void tipc_bcbase_select_primary(struct net *net)
if ((i ^ tipc_own_addr(net)) & 1) if ((i ^ tipc_own_addr(net)) & 1)
break; break;
} }
prim = bb->primary_bearer;
if (prim != INVALID_BEARER_ID)
bb->bcast_support = tipc_bearer_bcast_support(net, prim);
} }
void tipc_bcast_inc_bearer_dst_cnt(struct net *net, int bearer_id) void tipc_bcast_inc_bearer_dst_cnt(struct net *net, int bearer_id)
...@@ -170,42 +194,128 @@ static void tipc_bcbase_xmit(struct net *net, struct sk_buff_head *xmitq) ...@@ -170,42 +194,128 @@ static void tipc_bcbase_xmit(struct net *net, struct sk_buff_head *xmitq)
__skb_queue_purge(&_xmitq); __skb_queue_purge(&_xmitq);
} }
/* tipc_bcast_xmit - deliver buffer chain to all nodes in cluster static void tipc_bcast_select_xmit_method(struct net *net, int dests,
* and to identified node local sockets struct tipc_mc_method *method)
{
struct tipc_bc_base *bb = tipc_bc_base(net);
unsigned long exp = method->expires;
/* Broadcast supported by used bearer/bearers? */
if (!bb->bcast_support) {
method->rcast = true;
return;
}
/* Any destinations which don't support replicast ? */
if (!bb->rcast_support) {
method->rcast = false;
return;
}
/* Can current method be changed ? */
method->expires = jiffies + TIPC_METHOD_EXPIRE;
if (method->mandatory || time_before(jiffies, exp))
return;
/* Determine method to use now */
method->rcast = dests <= bb->bc_threshold;
}
/* tipc_bcast_xmit - broadcast the buffer chain to all external nodes
* @net: the applicable net namespace * @net: the applicable net namespace
* @list: chain of buffers containing message * @pkts: chain of buffers containing message
* @cong_link_cnt: set to 1 if broadcast link is congested, otherwise 0
* Consumes the buffer chain. * Consumes the buffer chain.
* Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE * Returns 0 if success, otherwise errno: -EHOSTUNREACH,-EMSGSIZE
*/ */
int tipc_bcast_xmit(struct net *net, struct sk_buff_head *list) static int tipc_bcast_xmit(struct net *net, struct sk_buff_head *pkts,
u16 *cong_link_cnt)
{ {
struct tipc_link *l = tipc_bc_sndlink(net); struct tipc_link *l = tipc_bc_sndlink(net);
struct sk_buff_head xmitq, inputq, rcvq; struct sk_buff_head xmitq;
int rc = 0; int rc = 0;
__skb_queue_head_init(&rcvq);
__skb_queue_head_init(&xmitq); __skb_queue_head_init(&xmitq);
skb_queue_head_init(&inputq);
/* Prepare message clone for local node */
if (unlikely(!tipc_msg_reassemble(list, &rcvq)))
return -EHOSTUNREACH;
tipc_bcast_lock(net); tipc_bcast_lock(net);
if (tipc_link_bc_peers(l)) if (tipc_link_bc_peers(l))
rc = tipc_link_xmit(l, list, &xmitq); rc = tipc_link_xmit(l, pkts, &xmitq);
tipc_bcast_unlock(net); tipc_bcast_unlock(net);
tipc_bcbase_xmit(net, &xmitq);
/* Don't send to local node if adding to link failed */ __skb_queue_purge(pkts);
if (unlikely(rc && (rc != -ELINKCONG))) { if (rc == -ELINKCONG) {
__skb_queue_purge(&rcvq); *cong_link_cnt = 1;
rc = 0;
}
return rc; return rc;
}
/* tipc_rcast_xmit - replicate and send a message to given destination nodes
* @net: the applicable net namespace
* @pkts: chain of buffers containing message
* @dests: list of destination nodes
* @cong_link_cnt: returns number of congested links
* @cong_links: returns identities of congested links
* Returns 0 if success, otherwise errno
*/
static int tipc_rcast_xmit(struct net *net, struct sk_buff_head *pkts,
struct tipc_nlist *dests, u16 *cong_link_cnt)
{
struct sk_buff_head _pkts;
struct u32_item *n, *tmp;
u32 dst, selector;
selector = msg_link_selector(buf_msg(skb_peek(pkts)));
__skb_queue_head_init(&_pkts);
list_for_each_entry_safe(n, tmp, &dests->list, list) {
dst = n->value;
if (!tipc_msg_pskb_copy(dst, pkts, &_pkts))
return -ENOMEM;
/* Any other return value than -ELINKCONG is ignored */
if (tipc_node_xmit(net, &_pkts, dst, selector) == -ELINKCONG)
(*cong_link_cnt)++;
} }
return 0;
}
/* Broadcast to all nodes, inluding local node */ /* tipc_mcast_xmit - deliver message to indicated destination nodes
tipc_bcbase_xmit(net, &xmitq); * and to identified node local sockets
tipc_sk_mcast_rcv(net, &rcvq, &inputq); * @net: the applicable net namespace
__skb_queue_purge(list); * @pkts: chain of buffers containing message
* @method: send method to be used
* @dests: destination nodes for message.
* @cong_link_cnt: returns number of encountered congested destination links
* Consumes buffer chain.
* Returns 0 if success, otherwise errno
*/
int tipc_mcast_xmit(struct net *net, struct sk_buff_head *pkts,
struct tipc_mc_method *method, struct tipc_nlist *dests,
u16 *cong_link_cnt)
{
struct sk_buff_head inputq, localq;
int rc = 0;
skb_queue_head_init(&inputq);
skb_queue_head_init(&localq);
/* Clone packets before they are consumed by next call */
if (dests->local && !tipc_msg_reassemble(pkts, &localq)) {
rc = -ENOMEM;
goto exit;
}
/* Send according to determined transmit method */
if (dests->remote) {
tipc_bcast_select_xmit_method(net, dests->remote, method);
if (method->rcast)
rc = tipc_rcast_xmit(net, pkts, dests, cong_link_cnt);
else
rc = tipc_bcast_xmit(net, pkts, cong_link_cnt);
}
if (dests->local)
tipc_sk_mcast_rcv(net, &localq, &inputq);
exit:
/* This queue should normally be empty by now */
__skb_queue_purge(pkts);
return rc; return rc;
} }
...@@ -313,6 +423,7 @@ void tipc_bcast_add_peer(struct net *net, struct tipc_link *uc_l, ...@@ -313,6 +423,7 @@ void tipc_bcast_add_peer(struct net *net, struct tipc_link *uc_l,
tipc_bcast_lock(net); tipc_bcast_lock(net);
tipc_link_add_bc_peer(snd_l, uc_l, xmitq); tipc_link_add_bc_peer(snd_l, uc_l, xmitq);
tipc_bcbase_select_primary(net); tipc_bcbase_select_primary(net);
tipc_bcbase_calc_bc_threshold(net);
tipc_bcast_unlock(net); tipc_bcast_unlock(net);
} }
...@@ -331,6 +442,7 @@ void tipc_bcast_remove_peer(struct net *net, struct tipc_link *rcv_l) ...@@ -331,6 +442,7 @@ void tipc_bcast_remove_peer(struct net *net, struct tipc_link *rcv_l)
tipc_bcast_lock(net); tipc_bcast_lock(net);
tipc_link_remove_bc_peer(snd_l, rcv_l, &xmitq); tipc_link_remove_bc_peer(snd_l, rcv_l, &xmitq);
tipc_bcbase_select_primary(net); tipc_bcbase_select_primary(net);
tipc_bcbase_calc_bc_threshold(net);
tipc_bcast_unlock(net); tipc_bcast_unlock(net);
tipc_bcbase_xmit(net, &xmitq); tipc_bcbase_xmit(net, &xmitq);
...@@ -413,6 +525,8 @@ int tipc_bcast_init(struct net *net) ...@@ -413,6 +525,8 @@ int tipc_bcast_init(struct net *net)
goto enomem; goto enomem;
bb->link = l; bb->link = l;
tn->bcl = l; tn->bcl = l;
bb->rc_ratio = 25;
bb->rcast_support = true;
return 0; return 0;
enomem: enomem:
kfree(bb); kfree(bb);
...@@ -428,3 +542,33 @@ void tipc_bcast_stop(struct net *net) ...@@ -428,3 +542,33 @@ void tipc_bcast_stop(struct net *net)
kfree(tn->bcbase); kfree(tn->bcbase);
kfree(tn->bcl); kfree(tn->bcl);
} }
void tipc_nlist_init(struct tipc_nlist *nl, u32 self)
{
memset(nl, 0, sizeof(*nl));
INIT_LIST_HEAD(&nl->list);
nl->self = self;
}
void tipc_nlist_add(struct tipc_nlist *nl, u32 node)
{
if (node == nl->self)
nl->local = true;
else if (u32_push(&nl->list, node))
nl->remote++;
}
void tipc_nlist_del(struct tipc_nlist *nl, u32 node)
{
if (node == nl->self)
nl->local = false;
else if (u32_del(&nl->list, node))
nl->remote--;
}
void tipc_nlist_purge(struct tipc_nlist *nl)
{
u32_list_purge(&nl->list);
nl->remote = 0;
nl->local = 0;
}
...@@ -42,9 +42,35 @@ ...@@ -42,9 +42,35 @@
struct tipc_node; struct tipc_node;
struct tipc_msg; struct tipc_msg;
struct tipc_nl_msg; struct tipc_nl_msg;
struct tipc_node_map; struct tipc_nlist;
struct tipc_nitem;
extern const char tipc_bclink_name[]; extern const char tipc_bclink_name[];
#define TIPC_METHOD_EXPIRE msecs_to_jiffies(5000)
struct tipc_nlist {
struct list_head list;
u32 self;
u16 remote;
bool local;
};
void tipc_nlist_init(struct tipc_nlist *nl, u32 self);
void tipc_nlist_purge(struct tipc_nlist *nl);
void tipc_nlist_add(struct tipc_nlist *nl, u32 node);
void tipc_nlist_del(struct tipc_nlist *nl, u32 node);
/* Cookie to be used between socket and broadcast layer
* @rcast: replicast (instead of broadcast) was used at previous xmit
* @mandatory: broadcast/replicast indication was set by user
* @expires: re-evaluate non-mandatory transmit method if we are past this
*/
struct tipc_mc_method {
bool rcast;
bool mandatory;
unsigned long expires;
};
int tipc_bcast_init(struct net *net); int tipc_bcast_init(struct net *net);
void tipc_bcast_stop(struct net *net); void tipc_bcast_stop(struct net *net);
void tipc_bcast_add_peer(struct net *net, struct tipc_link *l, void tipc_bcast_add_peer(struct net *net, struct tipc_link *l,
...@@ -53,7 +79,10 @@ void tipc_bcast_remove_peer(struct net *net, struct tipc_link *rcv_bcl); ...@@ -53,7 +79,10 @@ void tipc_bcast_remove_peer(struct net *net, struct tipc_link *rcv_bcl);
void tipc_bcast_inc_bearer_dst_cnt(struct net *net, int bearer_id); void tipc_bcast_inc_bearer_dst_cnt(struct net *net, int bearer_id);
void tipc_bcast_dec_bearer_dst_cnt(struct net *net, int bearer_id); void tipc_bcast_dec_bearer_dst_cnt(struct net *net, int bearer_id);
int tipc_bcast_get_mtu(struct net *net); int tipc_bcast_get_mtu(struct net *net);
int tipc_bcast_xmit(struct net *net, struct sk_buff_head *list); void tipc_bcast_disable_rcast(struct net *net);
int tipc_mcast_xmit(struct net *net, struct sk_buff_head *pkts,
struct tipc_mc_method *method, struct tipc_nlist *dests,
u16 *cong_link_cnt);
int tipc_bcast_rcv(struct net *net, struct tipc_link *l, struct sk_buff *skb); int tipc_bcast_rcv(struct net *net, struct tipc_link *l, struct sk_buff *skb);
void tipc_bcast_ack_rcv(struct net *net, struct tipc_link *l, void tipc_bcast_ack_rcv(struct net *net, struct tipc_link *l,
struct tipc_msg *hdr); struct tipc_msg *hdr);
......
...@@ -431,7 +431,7 @@ int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b, ...@@ -431,7 +431,7 @@ int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b,
memset(&b->bcast_addr, 0, sizeof(b->bcast_addr)); memset(&b->bcast_addr, 0, sizeof(b->bcast_addr));
memcpy(b->bcast_addr.value, dev->broadcast, b->media->hwaddr_len); memcpy(b->bcast_addr.value, dev->broadcast, b->media->hwaddr_len);
b->bcast_addr.media_id = b->media->type_id; b->bcast_addr.media_id = b->media->type_id;
b->bcast_addr.broadcast = 1; b->bcast_addr.broadcast = TIPC_BROADCAST_SUPPORT;
b->mtu = dev->mtu; b->mtu = dev->mtu;
b->media->raw2addr(b, &b->addr, (char *)dev->dev_addr); b->media->raw2addr(b, &b->addr, (char *)dev->dev_addr);
rcu_assign_pointer(dev->tipc_ptr, b); rcu_assign_pointer(dev->tipc_ptr, b);
...@@ -482,6 +482,19 @@ int tipc_l2_send_msg(struct net *net, struct sk_buff *skb, ...@@ -482,6 +482,19 @@ int tipc_l2_send_msg(struct net *net, struct sk_buff *skb,
return 0; return 0;
} }
bool tipc_bearer_bcast_support(struct net *net, u32 bearer_id)
{
bool supp = false;
struct tipc_bearer *b;
rcu_read_lock();
b = bearer_get(net, bearer_id);
if (b)
supp = (b->bcast_addr.broadcast == TIPC_BROADCAST_SUPPORT);
rcu_read_unlock();
return supp;
}
int tipc_bearer_mtu(struct net *net, u32 bearer_id) int tipc_bearer_mtu(struct net *net, u32 bearer_id)
{ {
int mtu = 0; int mtu = 0;
......
...@@ -60,9 +60,14 @@ ...@@ -60,9 +60,14 @@
#define TIPC_MEDIA_TYPE_IB 2 #define TIPC_MEDIA_TYPE_IB 2
#define TIPC_MEDIA_TYPE_UDP 3 #define TIPC_MEDIA_TYPE_UDP 3
/* minimum bearer MTU */ /* Minimum bearer MTU */
#define TIPC_MIN_BEARER_MTU (MAX_H_SIZE + INT_H_SIZE) #define TIPC_MIN_BEARER_MTU (MAX_H_SIZE + INT_H_SIZE)
/* Identifiers for distinguishing between broadcast/multicast and replicast
*/
#define TIPC_BROADCAST_SUPPORT 1
#define TIPC_REPLICAST_SUPPORT 2
/** /**
* struct tipc_media_addr - destination address used by TIPC bearers * struct tipc_media_addr - destination address used by TIPC bearers
* @value: address info (format defined by media) * @value: address info (format defined by media)
...@@ -210,6 +215,7 @@ int tipc_bearer_setup(void); ...@@ -210,6 +215,7 @@ int tipc_bearer_setup(void);
void tipc_bearer_cleanup(void); void tipc_bearer_cleanup(void);
void tipc_bearer_stop(struct net *net); void tipc_bearer_stop(struct net *net);
int tipc_bearer_mtu(struct net *net, u32 bearer_id); int tipc_bearer_mtu(struct net *net, u32 bearer_id);
bool tipc_bearer_bcast_support(struct net *net, u32 bearer_id);
void tipc_bearer_xmit_skb(struct net *net, u32 bearer_id, void tipc_bearer_xmit_skb(struct net *net, u32 bearer_id,
struct sk_buff *skb, struct sk_buff *skb,
struct tipc_media_addr *dest); struct tipc_media_addr *dest);
......
...@@ -515,6 +515,10 @@ bool tipc_link_bc_create(struct net *net, u32 ownnode, u32 peer, ...@@ -515,6 +515,10 @@ bool tipc_link_bc_create(struct net *net, u32 ownnode, u32 peer,
if (link_is_bc_sndlink(l)) if (link_is_bc_sndlink(l))
l->state = LINK_ESTABLISHED; l->state = LINK_ESTABLISHED;
/* Disable replicast if even a single peer doesn't support it */
if (link_is_bc_rcvlink(l) && !(peer_caps & TIPC_BCAST_RCAST))
tipc_bcast_disable_rcast(net);
return true; return true;
} }
...@@ -1032,11 +1036,17 @@ int tipc_link_retrans(struct tipc_link *l, u16 from, u16 to, ...@@ -1032,11 +1036,17 @@ int tipc_link_retrans(struct tipc_link *l, u16 from, u16 to,
static bool tipc_data_input(struct tipc_link *l, struct sk_buff *skb, static bool tipc_data_input(struct tipc_link *l, struct sk_buff *skb,
struct sk_buff_head *inputq) struct sk_buff_head *inputq)
{ {
switch (msg_user(buf_msg(skb))) { struct tipc_msg *hdr = buf_msg(skb);
switch (msg_user(hdr)) {
case TIPC_LOW_IMPORTANCE: case TIPC_LOW_IMPORTANCE:
case TIPC_MEDIUM_IMPORTANCE: case TIPC_MEDIUM_IMPORTANCE:
case TIPC_HIGH_IMPORTANCE: case TIPC_HIGH_IMPORTANCE:
case TIPC_CRITICAL_IMPORTANCE: case TIPC_CRITICAL_IMPORTANCE:
if (unlikely(msg_type(hdr) == TIPC_MCAST_MSG)) {
skb_queue_tail(l->bc_rcvlink->inputq, skb);
return true;
}
case CONN_MANAGER: case CONN_MANAGER:
skb_queue_tail(inputq, skb); skb_queue_tail(inputq, skb);
return true; return true;
......
...@@ -607,6 +607,23 @@ bool tipc_msg_reassemble(struct sk_buff_head *list, struct sk_buff_head *rcvq) ...@@ -607,6 +607,23 @@ bool tipc_msg_reassemble(struct sk_buff_head *list, struct sk_buff_head *rcvq)
return false; return false;
} }
bool tipc_msg_pskb_copy(u32 dst, struct sk_buff_head *msg,
struct sk_buff_head *cpy)
{
struct sk_buff *skb, *_skb;
skb_queue_walk(msg, skb) {
_skb = pskb_copy(skb, GFP_ATOMIC);
if (!_skb) {
__skb_queue_purge(cpy);
return false;
}
msg_set_destnode(buf_msg(_skb), dst);
__skb_queue_tail(cpy, _skb);
}
return true;
}
/* tipc_skb_queue_sorted(); sort pkt into list according to sequence number /* tipc_skb_queue_sorted(); sort pkt into list according to sequence number
* @list: list to be appended to * @list: list to be appended to
* @seqno: sequence number of buffer to add * @seqno: sequence number of buffer to add
......
...@@ -631,14 +631,11 @@ static inline void msg_set_bc_netid(struct tipc_msg *m, u32 id) ...@@ -631,14 +631,11 @@ static inline void msg_set_bc_netid(struct tipc_msg *m, u32 id)
static inline u32 msg_link_selector(struct tipc_msg *m) static inline u32 msg_link_selector(struct tipc_msg *m)
{ {
if (msg_user(m) == MSG_FRAGMENTER)
m = (void *)msg_data(m);
return msg_bits(m, 4, 0, 1); return msg_bits(m, 4, 0, 1);
} }
static inline void msg_set_link_selector(struct tipc_msg *m, u32 n)
{
msg_set_bits(m, 4, 0, 1, n);
}
/* /*
* Word 5 * Word 5
*/ */
...@@ -835,6 +832,8 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m, ...@@ -835,6 +832,8 @@ int tipc_msg_build(struct tipc_msg *mhdr, struct msghdr *m,
int offset, int dsz, int mtu, struct sk_buff_head *list); int offset, int dsz, int mtu, struct sk_buff_head *list);
bool tipc_msg_lookup_dest(struct net *net, struct sk_buff *skb, int *err); bool tipc_msg_lookup_dest(struct net *net, struct sk_buff *skb, int *err);
bool tipc_msg_reassemble(struct sk_buff_head *list, struct sk_buff_head *rcvq); bool tipc_msg_reassemble(struct sk_buff_head *list, struct sk_buff_head *rcvq);
bool tipc_msg_pskb_copy(u32 dst, struct sk_buff_head *msg,
struct sk_buff_head *cpy);
void __tipc_skb_queue_sorted(struct sk_buff_head *list, u16 seqno, void __tipc_skb_queue_sorted(struct sk_buff_head *list, u16 seqno,
struct sk_buff *skb); struct sk_buff *skb);
......
...@@ -645,6 +645,39 @@ int tipc_nametbl_mc_translate(struct net *net, u32 type, u32 lower, u32 upper, ...@@ -645,6 +645,39 @@ int tipc_nametbl_mc_translate(struct net *net, u32 type, u32 lower, u32 upper,
return res; return res;
} }
/* tipc_nametbl_lookup_dst_nodes - find broadcast destination nodes
* - Creates list of nodes that overlap the given multicast address
* - Determines if any node local ports overlap
*/
void tipc_nametbl_lookup_dst_nodes(struct net *net, u32 type, u32 lower,
u32 upper, u32 domain,
struct tipc_nlist *nodes)
{
struct sub_seq *sseq, *stop;
struct publication *publ;
struct name_info *info;
struct name_seq *seq;
rcu_read_lock();
seq = nametbl_find_seq(net, type);
if (!seq)
goto exit;
spin_lock_bh(&seq->lock);
sseq = seq->sseqs + nameseq_locate_subseq(seq, lower);
stop = seq->sseqs + seq->first_free;
for (; sseq->lower <= upper && sseq != stop; sseq++) {
info = sseq->info;
list_for_each_entry(publ, &info->zone_list, zone_list) {
if (tipc_in_scope(domain, publ->node))
tipc_nlist_add(nodes, publ->node);
}
}
spin_unlock_bh(&seq->lock);
exit:
rcu_read_unlock();
}
/* /*
* tipc_nametbl_publish - add name publication to network name tables * tipc_nametbl_publish - add name publication to network name tables
*/ */
...@@ -1022,11 +1055,6 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1022,11 +1055,6 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb)
return skb->len; return skb->len;
} }
struct u32_item {
struct list_head list;
u32 value;
};
bool u32_find(struct list_head *l, u32 value) bool u32_find(struct list_head *l, u32 value)
{ {
struct u32_item *item; struct u32_item *item;
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
struct tipc_subscription; struct tipc_subscription;
struct tipc_plist; struct tipc_plist;
struct tipc_nlist;
/* /*
* TIPC name types reserved for internal TIPC use (both current and planned) * TIPC name types reserved for internal TIPC use (both current and planned)
...@@ -100,6 +101,9 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb); ...@@ -100,6 +101,9 @@ int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb);
u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, u32 *node); u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, u32 *node);
int tipc_nametbl_mc_translate(struct net *net, u32 type, u32 lower, u32 upper, int tipc_nametbl_mc_translate(struct net *net, u32 type, u32 lower, u32 upper,
u32 limit, struct list_head *dports); u32 limit, struct list_head *dports);
void tipc_nametbl_lookup_dst_nodes(struct net *net, u32 type, u32 lower,
u32 upper, u32 domain,
struct tipc_nlist *nodes);
struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower, struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower,
u32 upper, u32 scope, u32 port_ref, u32 upper, u32 scope, u32 port_ref,
u32 key); u32 key);
...@@ -116,6 +120,11 @@ void tipc_nametbl_unsubscribe(struct tipc_subscription *s); ...@@ -116,6 +120,11 @@ void tipc_nametbl_unsubscribe(struct tipc_subscription *s);
int tipc_nametbl_init(struct net *net); int tipc_nametbl_init(struct net *net);
void tipc_nametbl_stop(struct net *net); void tipc_nametbl_stop(struct net *net);
struct u32_item {
struct list_head list;
u32 value;
};
bool u32_push(struct list_head *l, u32 value); bool u32_push(struct list_head *l, u32 value);
u32 u32_pop(struct list_head *l); u32 u32_pop(struct list_head *l);
bool u32_find(struct list_head *l, u32 value); bool u32_find(struct list_head *l, u32 value);
......
...@@ -1257,6 +1257,19 @@ void tipc_node_broadcast(struct net *net, struct sk_buff *skb) ...@@ -1257,6 +1257,19 @@ void tipc_node_broadcast(struct net *net, struct sk_buff *skb)
kfree_skb(skb); kfree_skb(skb);
} }
static void tipc_node_mcast_rcv(struct tipc_node *n)
{
struct tipc_bclink_entry *be = &n->bc_entry;
/* 'arrvq' is under inputq2's lock protection */
spin_lock_bh(&be->inputq2.lock);
spin_lock_bh(&be->inputq1.lock);
skb_queue_splice_tail_init(&be->inputq1, &be->arrvq);
spin_unlock_bh(&be->inputq1.lock);
spin_unlock_bh(&be->inputq2.lock);
tipc_sk_mcast_rcv(n->net, &be->arrvq, &be->inputq2);
}
static void tipc_node_bc_sync_rcv(struct tipc_node *n, struct tipc_msg *hdr, static void tipc_node_bc_sync_rcv(struct tipc_node *n, struct tipc_msg *hdr,
int bearer_id, struct sk_buff_head *xmitq) int bearer_id, struct sk_buff_head *xmitq)
{ {
...@@ -1330,15 +1343,8 @@ static void tipc_node_bc_rcv(struct net *net, struct sk_buff *skb, int bearer_id ...@@ -1330,15 +1343,8 @@ static void tipc_node_bc_rcv(struct net *net, struct sk_buff *skb, int bearer_id
if (!skb_queue_empty(&xmitq)) if (!skb_queue_empty(&xmitq))
tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr); tipc_bearer_xmit(net, bearer_id, &xmitq, &le->maddr);
/* Deliver. 'arrvq' is under inputq2's lock protection */ if (!skb_queue_empty(&be->inputq1))
if (!skb_queue_empty(&be->inputq1)) { tipc_node_mcast_rcv(n);
spin_lock_bh(&be->inputq2.lock);
spin_lock_bh(&be->inputq1.lock);
skb_queue_splice_tail_init(&be->inputq1, &be->arrvq);
spin_unlock_bh(&be->inputq1.lock);
spin_unlock_bh(&be->inputq2.lock);
tipc_sk_mcast_rcv(net, &be->arrvq, &be->inputq2);
}
if (rc & TIPC_LINK_DOWN_EVT) { if (rc & TIPC_LINK_DOWN_EVT) {
/* Reception reassembly failure => reset all links to peer */ /* Reception reassembly failure => reset all links to peer */
...@@ -1565,6 +1571,9 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b) ...@@ -1565,6 +1571,9 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b)
if (unlikely(!skb_queue_empty(&n->bc_entry.namedq))) if (unlikely(!skb_queue_empty(&n->bc_entry.namedq)))
tipc_named_rcv(net, &n->bc_entry.namedq); tipc_named_rcv(net, &n->bc_entry.namedq);
if (unlikely(!skb_queue_empty(&n->bc_entry.inputq1)))
tipc_node_mcast_rcv(n);
if (!skb_queue_empty(&le->inputq)) if (!skb_queue_empty(&le->inputq))
tipc_sk_rcv(net, &le->inputq); tipc_sk_rcv(net, &le->inputq);
......
...@@ -47,11 +47,13 @@ ...@@ -47,11 +47,13 @@
enum { enum {
TIPC_BCAST_SYNCH = (1 << 1), TIPC_BCAST_SYNCH = (1 << 1),
TIPC_BCAST_STATE_NACK = (1 << 2), TIPC_BCAST_STATE_NACK = (1 << 2),
TIPC_BLOCK_FLOWCTL = (1 << 3) TIPC_BLOCK_FLOWCTL = (1 << 3),
TIPC_BCAST_RCAST = (1 << 4)
}; };
#define TIPC_NODE_CAPABILITIES (TIPC_BCAST_SYNCH | \ #define TIPC_NODE_CAPABILITIES (TIPC_BCAST_SYNCH | \
TIPC_BCAST_STATE_NACK | \ TIPC_BCAST_STATE_NACK | \
TIPC_BCAST_RCAST | \
TIPC_BLOCK_FLOWCTL) TIPC_BLOCK_FLOWCTL)
#define INVALID_BEARER_ID -1 #define INVALID_BEARER_ID -1
......
...@@ -79,6 +79,7 @@ enum { ...@@ -79,6 +79,7 @@ enum {
* @rcv_unacked: # messages read by user, but not yet acked back to peer * @rcv_unacked: # messages read by user, but not yet acked back to peer
* @peer: 'connected' peer for dgram/rdm * @peer: 'connected' peer for dgram/rdm
* @node: hash table node * @node: hash table node
* @mc_method: cookie for use between socket and broadcast layer
* @rcu: rcu struct for tipc_sock * @rcu: rcu struct for tipc_sock
*/ */
struct tipc_sock { struct tipc_sock {
...@@ -103,6 +104,7 @@ struct tipc_sock { ...@@ -103,6 +104,7 @@ struct tipc_sock {
u16 rcv_win; u16 rcv_win;
struct sockaddr_tipc peer; struct sockaddr_tipc peer;
struct rhash_head node; struct rhash_head node;
struct tipc_mc_method mc_method;
struct rcu_head rcu; struct rcu_head rcu;
}; };
...@@ -740,32 +742,44 @@ static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq, ...@@ -740,32 +742,44 @@ static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq,
struct tipc_msg *hdr = &tsk->phdr; struct tipc_msg *hdr = &tsk->phdr;
struct net *net = sock_net(sk); struct net *net = sock_net(sk);
int mtu = tipc_bcast_get_mtu(net); int mtu = tipc_bcast_get_mtu(net);
struct tipc_mc_method *method = &tsk->mc_method;
u32 domain = addr_domain(net, TIPC_CLUSTER_SCOPE);
struct sk_buff_head pkts; struct sk_buff_head pkts;
struct tipc_nlist dsts;
int rc; int rc;
/* Block or return if any destination link is congested */
rc = tipc_wait_for_cond(sock, &timeout, !tsk->cong_link_cnt); rc = tipc_wait_for_cond(sock, &timeout, !tsk->cong_link_cnt);
if (unlikely(rc)) if (unlikely(rc))
return rc; return rc;
/* Lookup destination nodes */
tipc_nlist_init(&dsts, tipc_own_addr(net));
tipc_nametbl_lookup_dst_nodes(net, seq->type, seq->lower,
seq->upper, domain, &dsts);
if (!dsts.local && !dsts.remote)
return -EHOSTUNREACH;
/* Build message header */
msg_set_type(hdr, TIPC_MCAST_MSG); msg_set_type(hdr, TIPC_MCAST_MSG);
msg_set_hdr_sz(hdr, MCAST_H_SIZE);
msg_set_lookup_scope(hdr, TIPC_CLUSTER_SCOPE); msg_set_lookup_scope(hdr, TIPC_CLUSTER_SCOPE);
msg_set_destport(hdr, 0); msg_set_destport(hdr, 0);
msg_set_destnode(hdr, 0); msg_set_destnode(hdr, 0);
msg_set_nametype(hdr, seq->type); msg_set_nametype(hdr, seq->type);
msg_set_namelower(hdr, seq->lower); msg_set_namelower(hdr, seq->lower);
msg_set_nameupper(hdr, seq->upper); msg_set_nameupper(hdr, seq->upper);
msg_set_hdr_sz(hdr, MCAST_H_SIZE);
/* Build message as chain of buffers */
skb_queue_head_init(&pkts); skb_queue_head_init(&pkts);
rc = tipc_msg_build(hdr, msg, 0, dlen, mtu, &pkts); rc = tipc_msg_build(hdr, msg, 0, dlen, mtu, &pkts);
if (unlikely(rc != dlen))
return rc;
rc = tipc_bcast_xmit(net, &pkts); /* Send message if build was successful */
if (unlikely(rc == -ELINKCONG)) { if (unlikely(rc == dlen))
tsk->cong_link_cnt = 1; rc = tipc_mcast_xmit(net, &pkts, method, &dsts,
rc = 0; &tsk->cong_link_cnt);
}
tipc_nlist_purge(&dsts);
return rc ? rc : dlen; return rc ? rc : dlen;
} }
...@@ -2333,18 +2347,29 @@ static int tipc_setsockopt(struct socket *sock, int lvl, int opt, ...@@ -2333,18 +2347,29 @@ static int tipc_setsockopt(struct socket *sock, int lvl, int opt,
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
struct tipc_sock *tsk = tipc_sk(sk); struct tipc_sock *tsk = tipc_sk(sk);
u32 value; u32 value = 0;
int res; int res;
if ((lvl == IPPROTO_TCP) && (sock->type == SOCK_STREAM)) if ((lvl == IPPROTO_TCP) && (sock->type == SOCK_STREAM))
return 0; return 0;
if (lvl != SOL_TIPC) if (lvl != SOL_TIPC)
return -ENOPROTOOPT; return -ENOPROTOOPT;
switch (opt) {
case TIPC_IMPORTANCE:
case TIPC_SRC_DROPPABLE:
case TIPC_DEST_DROPPABLE:
case TIPC_CONN_TIMEOUT:
if (ol < sizeof(value)) if (ol < sizeof(value))
return -EINVAL; return -EINVAL;
res = get_user(value, (u32 __user *)ov); res = get_user(value, (u32 __user *)ov);
if (res) if (res)
return res; return res;
break;
default:
if (ov || ol)
return -EINVAL;
}
lock_sock(sk); lock_sock(sk);
...@@ -2365,6 +2390,14 @@ static int tipc_setsockopt(struct socket *sock, int lvl, int opt, ...@@ -2365,6 +2390,14 @@ static int tipc_setsockopt(struct socket *sock, int lvl, int opt,
tipc_sk(sk)->conn_timeout = value; tipc_sk(sk)->conn_timeout = value;
/* no need to set "res", since already 0 at this point */ /* no need to set "res", since already 0 at this point */
break; break;
case TIPC_MCAST_BROADCAST:
tsk->mc_method.rcast = false;
tsk->mc_method.mandatory = true;
break;
case TIPC_MCAST_REPLICAST:
tsk->mc_method.rcast = true;
tsk->mc_method.mandatory = true;
break;
default: default:
res = -EINVAL; res = -EINVAL;
} }
......
...@@ -113,7 +113,7 @@ static void tipc_udp_media_addr_set(struct tipc_media_addr *addr, ...@@ -113,7 +113,7 @@ static void tipc_udp_media_addr_set(struct tipc_media_addr *addr,
memcpy(addr->value, ua, sizeof(struct udp_media_addr)); memcpy(addr->value, ua, sizeof(struct udp_media_addr));
if (tipc_udp_is_mcast_addr(ua)) if (tipc_udp_is_mcast_addr(ua))
addr->broadcast = 1; addr->broadcast = TIPC_BROADCAST_SUPPORT;
} }
/* tipc_udp_addr2str - convert ip/udp address to string */ /* tipc_udp_addr2str - convert ip/udp address to string */
...@@ -229,7 +229,7 @@ static int tipc_udp_send_msg(struct net *net, struct sk_buff *skb, ...@@ -229,7 +229,7 @@ static int tipc_udp_send_msg(struct net *net, struct sk_buff *skb,
goto out; goto out;
} }
if (!addr->broadcast || list_empty(&ub->rcast.list)) if (addr->broadcast != TIPC_REPLICAST_SUPPORT)
return tipc_udp_xmit(net, skb, ub, src, dst); return tipc_udp_xmit(net, skb, ub, src, dst);
/* Replicast, send an skb to each configured IP address */ /* Replicast, send an skb to each configured IP address */
...@@ -296,7 +296,7 @@ static int tipc_udp_rcast_add(struct tipc_bearer *b, ...@@ -296,7 +296,7 @@ static int tipc_udp_rcast_add(struct tipc_bearer *b,
else if (ntohs(addr->proto) == ETH_P_IPV6) else if (ntohs(addr->proto) == ETH_P_IPV6)
pr_info("New replicast peer: %pI6\n", &rcast->addr.ipv6); pr_info("New replicast peer: %pI6\n", &rcast->addr.ipv6);
#endif #endif
b->bcast_addr.broadcast = TIPC_REPLICAST_SUPPORT;
list_add_rcu(&rcast->list, &ub->rcast.list); list_add_rcu(&rcast->list, &ub->rcast.list);
return 0; return 0;
} }
...@@ -681,7 +681,7 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b, ...@@ -681,7 +681,7 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b,
goto err; goto err;
b->bcast_addr.media_id = TIPC_MEDIA_TYPE_UDP; b->bcast_addr.media_id = TIPC_MEDIA_TYPE_UDP;
b->bcast_addr.broadcast = 1; b->bcast_addr.broadcast = TIPC_BROADCAST_SUPPORT;
rcu_assign_pointer(b->media_ptr, ub); rcu_assign_pointer(b->media_ptr, ub);
rcu_assign_pointer(ub->bearer, b); rcu_assign_pointer(ub->bearer, b);
tipc_udp_media_addr_set(&b->addr, &local); tipc_udp_media_addr_set(&b->addr, &local);
......
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