Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c93d3baa authored by Ying Xue's avatar Ying Xue Committed by David S. Miller
Browse files

tipc: involve namespace infrastructure



Involve namespace infrastructure, make the "tipc_net_id" global
variable aware of per namespace, and rename it to "net_id". In
order that the conversion can be successfully done, an instance
of networking namespace must be passed to relevant functions,
allowing them to access the "net_id" variable of per namespace.

Signed-off-by: default avatarYing Xue <ying.xue@windriver.com>
Tested-by: default avatarTero Aho <Tero.Aho@coriant.com>
Reviewed-by: default avatarJon Maloy <jon.maloy@ericsson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 54fef04a
Loading
Loading
Loading
Loading
+10 −5
Original line number Original line Diff line number Diff line
@@ -327,9 +327,11 @@ void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked)
 *
 *
 * RCU and node lock set
 * RCU and node lock set
 */
 */
void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent)
void tipc_bclink_update_link_state(struct net *net, struct tipc_node *n_ptr,
				   u32 last_sent)
{
{
	struct sk_buff *buf;
	struct sk_buff *buf;
	struct tipc_net *tn = net_generic(net, tipc_net_id);


	/* Ignore "stale" link state info */
	/* Ignore "stale" link state info */
	if (less_eq(last_sent, n_ptr->bclink.last_in))
	if (less_eq(last_sent, n_ptr->bclink.last_in))
@@ -362,7 +364,7 @@ void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent)
		tipc_msg_init(msg, BCAST_PROTOCOL, STATE_MSG,
		tipc_msg_init(msg, BCAST_PROTOCOL, STATE_MSG,
			      INT_H_SIZE, n_ptr->addr);
			      INT_H_SIZE, n_ptr->addr);
		msg_set_non_seq(msg, 1);
		msg_set_non_seq(msg, 1);
		msg_set_mc_netid(msg, tipc_net_id);
		msg_set_mc_netid(msg, tn->net_id);
		msg_set_bcast_ack(msg, n_ptr->bclink.last_in);
		msg_set_bcast_ack(msg, n_ptr->bclink.last_in);
		msg_set_bcgap_after(msg, n_ptr->bclink.last_in);
		msg_set_bcgap_after(msg, n_ptr->bclink.last_in);
		msg_set_bcgap_to(msg, to);
		msg_set_bcgap_to(msg, to);
@@ -476,8 +478,9 @@ static void bclink_accept_pkt(struct tipc_node *node, u32 seqno)
 *
 *
 * RCU is locked, no other locks set
 * RCU is locked, no other locks set
 */
 */
void tipc_bclink_rcv(struct sk_buff *buf)
void tipc_bclink_rcv(struct net *net, struct sk_buff *buf)
{
{
	struct tipc_net *tn = net_generic(net, tipc_net_id);
	struct tipc_msg *msg = buf_msg(buf);
	struct tipc_msg *msg = buf_msg(buf);
	struct tipc_node *node;
	struct tipc_node *node;
	u32 next_in;
	u32 next_in;
@@ -485,7 +488,7 @@ void tipc_bclink_rcv(struct sk_buff *buf)
	int deferred = 0;
	int deferred = 0;


	/* Screen out unwanted broadcast messages */
	/* Screen out unwanted broadcast messages */
	if (msg_mc_netid(msg) != tipc_net_id)
	if (msg_mc_netid(msg) != tn->net_id)
		goto exit;
		goto exit;


	node = tipc_node_find(msg_prevnode(msg));
	node = tipc_node_find(msg_prevnode(msg));
@@ -638,6 +641,8 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1,
{
{
	int bp_index;
	int bp_index;
	struct tipc_msg *msg = buf_msg(buf);
	struct tipc_msg *msg = buf_msg(buf);
	struct net *net = sock_net(buf->sk);
	struct tipc_net *tn = net_generic(net, tipc_net_id);


	/* Prepare broadcast link message for reliable transmission,
	/* Prepare broadcast link message for reliable transmission,
	 * if first time trying to send it;
	 * if first time trying to send it;
@@ -647,7 +652,7 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1,
	if (likely(!msg_non_seq(buf_msg(buf)))) {
	if (likely(!msg_non_seq(buf_msg(buf)))) {
		bcbuf_set_acks(buf, bclink->bcast_nodes.count);
		bcbuf_set_acks(buf, bclink->bcast_nodes.count);
		msg_set_non_seq(msg, 1);
		msg_set_non_seq(msg, 1);
		msg_set_mc_netid(msg, tipc_net_id);
		msg_set_mc_netid(msg, tn->net_id);
		bcl->stats.sent_info++;
		bcl->stats.sent_info++;


		if (WARN_ON(!bclink->bcast_nodes.count)) {
		if (WARN_ON(!bclink->bcast_nodes.count)) {
+3 −2
Original line number Original line Diff line number Diff line
@@ -91,10 +91,11 @@ void tipc_bclink_add_node(u32 addr);
void tipc_bclink_remove_node(u32 addr);
void tipc_bclink_remove_node(u32 addr);
struct tipc_node *tipc_bclink_retransmit_to(void);
struct tipc_node *tipc_bclink_retransmit_to(void);
void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked);
void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked);
void tipc_bclink_rcv(struct sk_buff *buf);
void tipc_bclink_rcv(struct net *net, struct sk_buff *buf);
u32  tipc_bclink_get_last_sent(void);
u32  tipc_bclink_get_last_sent(void);
u32  tipc_bclink_acks_missing(struct tipc_node *n_ptr);
u32  tipc_bclink_acks_missing(struct tipc_node *n_ptr);
void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent);
void tipc_bclink_update_link_state(struct net *net, struct tipc_node *n_ptr,
				   u32 last_sent);
int  tipc_bclink_stats(char *stats_buf, const u32 buf_size);
int  tipc_bclink_stats(char *stats_buf, const u32 buf_size);
int  tipc_bclink_reset_stats(void);
int  tipc_bclink_reset_stats(void);
int  tipc_bclink_set_queue_limits(u32 limit);
int  tipc_bclink_set_queue_limits(u32 limit);
+12 −17
Original line number Original line Diff line number Diff line
@@ -260,7 +260,8 @@ void tipc_bearer_remove_dest(u32 bearer_id, u32 dest)
/**
/**
 * tipc_enable_bearer - enable bearer with the given name
 * tipc_enable_bearer - enable bearer with the given name
 */
 */
int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
int tipc_enable_bearer(struct net *net, const char *name, u32 disc_domain,
		       u32 priority)
{
{
	struct tipc_bearer *b_ptr;
	struct tipc_bearer *b_ptr;
	struct tipc_media *m_ptr;
	struct tipc_media *m_ptr;
@@ -361,7 +362,7 @@ int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
	b_ptr->net_plane = bearer_id + 'A';
	b_ptr->net_plane = bearer_id + 'A';
	b_ptr->priority = priority;
	b_ptr->priority = priority;


	res = tipc_disc_create(b_ptr, &b_ptr->bcast_addr);
	res = tipc_disc_create(net, b_ptr, &b_ptr->bcast_addr);
	if (res) {
	if (res) {
		bearer_disable(b_ptr, false);
		bearer_disable(b_ptr, false);
		pr_warn("Bearer <%s> rejected, discovery object creation failed\n",
		pr_warn("Bearer <%s> rejected, discovery object creation failed\n",
@@ -380,11 +381,11 @@ int tipc_enable_bearer(const char *name, u32 disc_domain, u32 priority)
/**
/**
 * tipc_reset_bearer - Reset all links established over this bearer
 * tipc_reset_bearer - Reset all links established over this bearer
 */
 */
static int tipc_reset_bearer(struct tipc_bearer *b_ptr)
static int tipc_reset_bearer(struct net *net, struct tipc_bearer *b_ptr)
{
{
	pr_info("Resetting bearer <%s>\n", b_ptr->name);
	pr_info("Resetting bearer <%s>\n", b_ptr->name);
	tipc_link_reset_list(b_ptr->identity);
	tipc_link_reset_list(b_ptr->identity);
	tipc_disc_reset(b_ptr);
	tipc_disc_reset(net, b_ptr);
	return 0;
	return 0;
}
}


@@ -539,17 +540,12 @@ static int tipc_l2_rcv_msg(struct sk_buff *buf, struct net_device *dev,
{
{
	struct tipc_bearer *b_ptr;
	struct tipc_bearer *b_ptr;


	if (!net_eq(dev_net(dev), &init_net)) {
		kfree_skb(buf);
		return NET_RX_DROP;
	}

	rcu_read_lock();
	rcu_read_lock();
	b_ptr = rcu_dereference_rtnl(dev->tipc_ptr);
	b_ptr = rcu_dereference_rtnl(dev->tipc_ptr);
	if (likely(b_ptr)) {
	if (likely(b_ptr)) {
		if (likely(buf->pkt_type <= PACKET_BROADCAST)) {
		if (likely(buf->pkt_type <= PACKET_BROADCAST)) {
			buf->next = NULL;
			buf->next = NULL;
			tipc_rcv(buf, b_ptr);
			tipc_rcv(dev_net(dev), buf, b_ptr);
			rcu_read_unlock();
			rcu_read_unlock();
			return NET_RX_SUCCESS;
			return NET_RX_SUCCESS;
		}
		}
@@ -572,11 +568,9 @@ static int tipc_l2_rcv_msg(struct sk_buff *buf, struct net_device *dev,
static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
				void *ptr)
				void *ptr)
{
{
	struct tipc_bearer *b_ptr;
	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
	struct net_device *dev = netdev_notifier_info_to_dev(ptr);

	struct net *net = dev_net(dev);
	if (!net_eq(dev_net(dev), &init_net))
	struct tipc_bearer *b_ptr;
		return NOTIFY_DONE;


	b_ptr = rtnl_dereference(dev->tipc_ptr);
	b_ptr = rtnl_dereference(dev->tipc_ptr);
	if (!b_ptr)
	if (!b_ptr)
@@ -590,12 +584,12 @@ static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
			break;
			break;
	case NETDEV_DOWN:
	case NETDEV_DOWN:
	case NETDEV_CHANGEMTU:
	case NETDEV_CHANGEMTU:
		tipc_reset_bearer(b_ptr);
		tipc_reset_bearer(net, b_ptr);
		break;
		break;
	case NETDEV_CHANGEADDR:
	case NETDEV_CHANGEADDR:
		b_ptr->media->raw2addr(b_ptr, &b_ptr->addr,
		b_ptr->media->raw2addr(b_ptr, &b_ptr->addr,
				       (char *)dev->dev_addr);
				       (char *)dev->dev_addr);
		tipc_reset_bearer(b_ptr);
		tipc_reset_bearer(net, b_ptr);
		break;
		break;
	case NETDEV_UNREGISTER:
	case NETDEV_UNREGISTER:
	case NETDEV_CHANGENAME:
	case NETDEV_CHANGENAME:
@@ -808,6 +802,7 @@ int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info)


int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
{
{
	struct net *net = genl_info_net(info);
	int err;
	int err;
	char *bearer;
	char *bearer;
	struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
	struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
@@ -847,7 +842,7 @@ int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
	}
	}


	rtnl_lock();
	rtnl_lock();
	err = tipc_enable_bearer(bearer, domain, prio);
	err = tipc_enable_bearer(net, bearer, domain, prio);
	if (err) {
	if (err) {
		rtnl_unlock();
		rtnl_unlock();
		return err;
		return err;
+3 −2
Original line number Original line Diff line number Diff line
@@ -165,8 +165,9 @@ extern struct tipc_bearer __rcu *bearer_list[];
 * TIPC routines available to supported media types
 * TIPC routines available to supported media types
 */
 */


void tipc_rcv(struct sk_buff *skb, struct tipc_bearer *tb_ptr);
void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b_ptr);
int tipc_enable_bearer(const char *bearer_name, u32 disc_domain, u32 priority);
int tipc_enable_bearer(struct net *net, const char *bearer_name,
		       u32 disc_domain, u32 priority);
int tipc_disable_bearer(const char *name);
int tipc_disable_bearer(const char *name);


/*
/*
+16 −13
Original line number Original line Diff line number Diff line
@@ -134,7 +134,7 @@ static struct sk_buff *tipc_show_stats(void)
	return buf;
	return buf;
}
}


static struct sk_buff *cfg_enable_bearer(void)
static struct sk_buff *cfg_enable_bearer(struct net *net)
{
{
	struct tipc_bearer_config *args;
	struct tipc_bearer_config *args;


@@ -142,7 +142,7 @@ static struct sk_buff *cfg_enable_bearer(void)
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);


	args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area);
	args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area);
	if (tipc_enable_bearer(args->name,
	if (tipc_enable_bearer(net, args->name,
			       ntohl(args->disc_domain),
			       ntohl(args->disc_domain),
			       ntohl(args->priority)))
			       ntohl(args->priority)))
		return tipc_cfg_reply_error_string("unable to enable bearer");
		return tipc_cfg_reply_error_string("unable to enable bearer");
@@ -161,7 +161,7 @@ static struct sk_buff *cfg_disable_bearer(void)
	return tipc_cfg_reply_none();
	return tipc_cfg_reply_none();
}
}


static struct sk_buff *cfg_set_own_addr(void)
static struct sk_buff *cfg_set_own_addr(struct net *net)
{
{
	u32 addr;
	u32 addr;


@@ -177,20 +177,21 @@ static struct sk_buff *cfg_set_own_addr(void)
	if (tipc_own_addr)
	if (tipc_own_addr)
		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
						   " (cannot change node address once assigned)");
						   " (cannot change node address once assigned)");
	if (!tipc_net_start(addr))
	if (!tipc_net_start(net, addr))
		return tipc_cfg_reply_none();
		return tipc_cfg_reply_none();


	return tipc_cfg_reply_error_string("cannot change to network mode");
	return tipc_cfg_reply_error_string("cannot change to network mode");
}
}


static struct sk_buff *cfg_set_netid(void)
static struct sk_buff *cfg_set_netid(struct net *net)
{
{
	struct tipc_net *tn = net_generic(net, tipc_net_id);
	u32 value;
	u32 value;


	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
	value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
	value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
	if (value == tipc_net_id)
	if (value == tn->net_id)
		return tipc_cfg_reply_none();
		return tipc_cfg_reply_none();
	if (value < 1 || value > 9999)
	if (value < 1 || value > 9999)
		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
@@ -198,14 +199,16 @@ static struct sk_buff *cfg_set_netid(void)
	if (tipc_own_addr)
	if (tipc_own_addr)
		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
			" (cannot change network id once TIPC has joined a network)");
			" (cannot change network id once TIPC has joined a network)");
	tipc_net_id = value;
	tn->net_id = value;
	return tipc_cfg_reply_none();
	return tipc_cfg_reply_none();
}
}


struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area,
struct sk_buff *tipc_cfg_do_cmd(struct net *net, u32 orig_node, u16 cmd,
				int request_space, int reply_headroom)
				const void *request_area, int request_space,
				int reply_headroom)
{
{
	struct sk_buff *rep_tlv_buf;
	struct sk_buff *rep_tlv_buf;
	struct tipc_net *tn = net_generic(net, tipc_net_id);


	rtnl_lock();
	rtnl_lock();


@@ -261,19 +264,19 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
		rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd);
		rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd);
		break;
		break;
	case TIPC_CMD_ENABLE_BEARER:
	case TIPC_CMD_ENABLE_BEARER:
		rep_tlv_buf = cfg_enable_bearer();
		rep_tlv_buf = cfg_enable_bearer(net);
		break;
		break;
	case TIPC_CMD_DISABLE_BEARER:
	case TIPC_CMD_DISABLE_BEARER:
		rep_tlv_buf = cfg_disable_bearer();
		rep_tlv_buf = cfg_disable_bearer();
		break;
		break;
	case TIPC_CMD_SET_NODE_ADDR:
	case TIPC_CMD_SET_NODE_ADDR:
		rep_tlv_buf = cfg_set_own_addr();
		rep_tlv_buf = cfg_set_own_addr(net);
		break;
		break;
	case TIPC_CMD_SET_NETID:
	case TIPC_CMD_SET_NETID:
		rep_tlv_buf = cfg_set_netid();
		rep_tlv_buf = cfg_set_netid(net);
		break;
		break;
	case TIPC_CMD_GET_NETID:
	case TIPC_CMD_GET_NETID:
		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
		rep_tlv_buf = tipc_cfg_reply_unsigned(tn->net_id);
		break;
		break;
	case TIPC_CMD_NOT_NET_ADMIN:
	case TIPC_CMD_NOT_NET_ADMIN:
		rep_tlv_buf =
		rep_tlv_buf =
Loading