Skip to content

Commit

Permalink
tipc: involve namespace infrastructure
Browse files Browse the repository at this point in the history
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: Ying Xue <ying.xue@windriver.com>
Tested-by: Tero Aho <Tero.Aho@coriant.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
ying-xue authored and davem330 committed Jan 12, 2015
1 parent 54fef04 commit c93d3ba
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 86 deletions.
15 changes: 10 additions & 5 deletions net/tipc/bcast.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,11 @@ void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked)
*
* 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 tipc_net *tn = net_generic(net, tipc_net_id);

/* Ignore "stale" link state info */
if (less_eq(last_sent, n_ptr->bclink.last_in))
Expand Down Expand Up @@ -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,
INT_H_SIZE, n_ptr->addr);
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_bcgap_after(msg, n_ptr->bclink.last_in);
msg_set_bcgap_to(msg, to);
Expand Down Expand Up @@ -476,16 +478,17 @@ static void bclink_accept_pkt(struct tipc_node *node, u32 seqno)
*
* 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_node *node;
u32 next_in;
u32 seqno;
int deferred = 0;

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

node = tipc_node_find(msg_prevnode(msg));
Expand Down Expand Up @@ -638,6 +641,8 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1,
{
int bp_index;
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,
* if first time trying to send it;
Expand All @@ -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)))) {
bcbuf_set_acks(buf, bclink->bcast_nodes.count);
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++;

if (WARN_ON(!bclink->bcast_nodes.count)) {
Expand Down
5 changes: 3 additions & 2 deletions net/tipc/bcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ void tipc_bclink_add_node(u32 addr);
void tipc_bclink_remove_node(u32 addr);
struct tipc_node *tipc_bclink_retransmit_to(void);
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_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_reset_stats(void);
int tipc_bclink_set_queue_limits(u32 limit);
Expand Down
29 changes: 12 additions & 17 deletions net/tipc/bearer.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ void tipc_bearer_remove_dest(u32 bearer_id, u32 dest)
/**
* 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_media *m_ptr;
Expand Down Expand Up @@ -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->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) {
bearer_disable(b_ptr, false);
pr_warn("Bearer <%s> rejected, discovery object creation failed\n",
Expand All @@ -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
*/
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);
tipc_link_reset_list(b_ptr->identity);
tipc_disc_reset(b_ptr);
tipc_disc_reset(net, b_ptr);
return 0;
}

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

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

rcu_read_lock();
b_ptr = rcu_dereference_rtnl(dev->tipc_ptr);
if (likely(b_ptr)) {
if (likely(buf->pkt_type <= PACKET_BROADCAST)) {
buf->next = NULL;
tipc_rcv(buf, b_ptr);
tipc_rcv(dev_net(dev), buf, b_ptr);
rcu_read_unlock();
return NET_RX_SUCCESS;
}
Expand All @@ -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,
void *ptr)
{
struct tipc_bearer *b_ptr;
struct net_device *dev = netdev_notifier_info_to_dev(ptr);

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

b_ptr = rtnl_dereference(dev->tipc_ptr);
if (!b_ptr)
Expand All @@ -590,12 +584,12 @@ static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
break;
case NETDEV_DOWN:
case NETDEV_CHANGEMTU:
tipc_reset_bearer(b_ptr);
tipc_reset_bearer(net, b_ptr);
break;
case NETDEV_CHANGEADDR:
b_ptr->media->raw2addr(b_ptr, &b_ptr->addr,
(char *)dev->dev_addr);
tipc_reset_bearer(b_ptr);
tipc_reset_bearer(net, b_ptr);
break;
case NETDEV_UNREGISTER:
case NETDEV_CHANGENAME:
Expand Down Expand Up @@ -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)
{
struct net *net = genl_info_net(info);
int err;
char *bearer;
struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
Expand Down Expand Up @@ -847,7 +842,7 @@ int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
}

rtnl_lock();
err = tipc_enable_bearer(bearer, domain, prio);
err = tipc_enable_bearer(net, bearer, domain, prio);
if (err) {
rtnl_unlock();
return err;
Expand Down
5 changes: 3 additions & 2 deletions net/tipc/bearer.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,9 @@ extern struct tipc_bearer __rcu *bearer_list[];
* TIPC routines available to supported media types
*/

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

/*
Expand Down
29 changes: 16 additions & 13 deletions net/tipc/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ static struct sk_buff *tipc_show_stats(void)
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;

if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_CONFIG))
return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);

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->priority)))
return tipc_cfg_reply_error_string("unable to enable bearer");
Expand All @@ -161,7 +161,7 @@ static struct sk_buff *cfg_disable_bearer(void)
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;

Expand All @@ -177,35 +177,38 @@ static struct sk_buff *cfg_set_own_addr(void)
if (tipc_own_addr)
return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
" (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_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;

if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
if (value == tipc_net_id)
if (value == tn->net_id)
return tipc_cfg_reply_none();
if (value < 1 || value > 9999)
return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
" (network id must be 1-9999)");
if (tipc_own_addr)
return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
" (cannot change network id once TIPC has joined a network)");
tipc_net_id = value;
tn->net_id = value;
return tipc_cfg_reply_none();
}

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

rtnl_lock();

Expand Down Expand Up @@ -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);
break;
case TIPC_CMD_ENABLE_BEARER:
rep_tlv_buf = cfg_enable_bearer();
rep_tlv_buf = cfg_enable_bearer(net);
break;
case TIPC_CMD_DISABLE_BEARER:
rep_tlv_buf = cfg_disable_bearer();
break;
case TIPC_CMD_SET_NODE_ADDR:
rep_tlv_buf = cfg_set_own_addr();
rep_tlv_buf = cfg_set_own_addr(net);
break;
case TIPC_CMD_SET_NETID:
rep_tlv_buf = cfg_set_netid();
rep_tlv_buf = cfg_set_netid(net);
break;
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;
case TIPC_CMD_NOT_NET_ADMIN:
rep_tlv_buf =
Expand Down
2 changes: 1 addition & 1 deletion net/tipc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static inline struct sk_buff *tipc_cfg_reply_ultra_string(char *string)
return tipc_cfg_reply_string_type(TIPC_TLV_ULTRA_STRING, string);
}

struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd,
struct sk_buff *tipc_cfg_do_cmd(struct net *net, u32 orig_node, u16 cmd,
const void *req_tlv_area, int req_tlv_space,
int headroom);
#endif
28 changes: 27 additions & 1 deletion net/tipc/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,33 @@ u32 tipc_own_addr __read_mostly;
int tipc_net_id __read_mostly;
int sysctl_tipc_rmem[3] __read_mostly; /* min/default/max */

static int __net_init tipc_init_net(struct net *net)
{
struct tipc_net *tn = net_generic(net, tipc_net_id);

tn->net_id = 4711;

return 0;
}

static void __net_exit tipc_exit_net(struct net *net)
{
}

static struct pernet_operations tipc_net_ops = {
.init = tipc_init_net,
.exit = tipc_exit_net,
.id = &tipc_net_id,
.size = sizeof(struct tipc_net),
};

static int __init tipc_init(void)
{
int err;

pr_info("Activated (version " TIPC_MOD_VER ")\n");

tipc_own_addr = 0;
tipc_net_id = 4711;

sysctl_tipc_rmem[0] = TIPC_CONN_OVERLOAD_LIMIT >> 4 <<
TIPC_LOW_IMPORTANCE;
Expand All @@ -69,6 +88,10 @@ static int __init tipc_init(void)

get_random_bytes(&tipc_random, sizeof(tipc_random));

err = register_pernet_subsys(&tipc_net_ops);
if (err)
goto out_pernet;

err = tipc_sk_rht_init();
if (err)
goto out_reftbl;
Expand Down Expand Up @@ -112,12 +135,15 @@ static int __init tipc_init(void)
out_nametbl:
tipc_sk_rht_destroy();
out_reftbl:
unregister_pernet_subsys(&tipc_net_ops);
out_pernet:
pr_err("Unable to start in single node mode\n");
return err;
}

static void __exit tipc_exit(void)
{
unregister_pernet_subsys(&tipc_net_ops);
tipc_net_stop();
tipc_bearer_cleanup();
tipc_netlink_stop();
Expand Down
5 changes: 5 additions & 0 deletions net/tipc/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include <linux/vmalloc.h>
#include <linux/rtnetlink.h>
#include <linux/etherdevice.h>
#include <net/netns/generic.h>

#define TIPC_MOD_VER "2.0.0"

Expand All @@ -75,6 +76,10 @@ extern int sysctl_tipc_named_timeout __read_mostly;
*/
extern int tipc_random __read_mostly;

struct tipc_net {
int net_id;
};

#ifdef CONFIG_SYSCTL
int tipc_register_sysctl(void);
void tipc_unregister_sysctl(void);
Expand Down
Loading

0 comments on commit c93d3ba

Please sign in to comment.