Commit 23fd3eac authored by Jon Maloy's avatar Jon Maloy Committed by David S. Miller

tipc: remove direct accesses to own_addr field in struct tipc_net

As a preparation to changing the addressing structure of TIPC we replace
all direct accesses to the tipc_net::own_addr field with the function
dedicated for this, tipc_own_addr().

There are no changes to program logics in this commit.
Acked-by: default avatarYing Xue <ying.xue@windriver.com>
Signed-off-by: default avatarJon Maloy <jon.maloy@ericsson.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b89afb11
...@@ -43,9 +43,7 @@ ...@@ -43,9 +43,7 @@
*/ */
int in_own_node(struct net *net, u32 addr) int in_own_node(struct net *net, u32 addr)
{ {
struct tipc_net *tn = net_generic(net, tipc_net_id); return addr == tipc_own_addr(net) || !addr;
return (addr == tn->own_addr) || !addr;
} }
bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr) bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr)
...@@ -56,6 +54,8 @@ bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr) ...@@ -56,6 +54,8 @@ bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr)
return false; return false;
if (domain == tipc_cluster_mask(addr)) /* domain <Z.C.0> */ if (domain == tipc_cluster_mask(addr)) /* domain <Z.C.0> */
return true; return true;
if (domain == (addr & TIPC_ZONE_CLUSTER_MASK)) /* domain <Z.C.0> */
return true;
if (domain == (addr & TIPC_ZONE_MASK)) /* domain <Z.0.0> */ if (domain == (addr & TIPC_ZONE_MASK)) /* domain <Z.0.0> */
return true; return true;
return false; return false;
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
static inline u32 tipc_own_addr(struct net *net) static inline u32 tipc_own_addr(struct net *net)
{ {
struct tipc_net *tn = net_generic(net, tipc_net_id); struct tipc_net *tn = tipc_net(net);
return tn->own_addr; return tn->own_addr;
} }
......
...@@ -81,11 +81,12 @@ static void tipc_disc_init_msg(struct net *net, struct sk_buff *skb, ...@@ -81,11 +81,12 @@ static void tipc_disc_init_msg(struct net *net, struct sk_buff *skb,
u32 mtyp, struct tipc_bearer *b) u32 mtyp, struct tipc_bearer *b)
{ {
struct tipc_net *tn = tipc_net(net); struct tipc_net *tn = tipc_net(net);
u32 self = tipc_own_addr(net);
u32 dest_domain = b->domain; u32 dest_domain = b->domain;
struct tipc_msg *hdr; struct tipc_msg *hdr;
hdr = buf_msg(skb); hdr = buf_msg(skb);
tipc_msg_init(tn->own_addr, hdr, LINK_CONFIG, mtyp, tipc_msg_init(self, hdr, LINK_CONFIG, mtyp,
MAX_H_SIZE, dest_domain); MAX_H_SIZE, dest_domain);
msg_set_non_seq(hdr, 1); msg_set_non_seq(hdr, 1);
msg_set_node_sig(hdr, tn->random); msg_set_node_sig(hdr, tn->random);
......
...@@ -1936,11 +1936,11 @@ static int __tipc_nl_add_stats(struct sk_buff *skb, struct tipc_stats *s) ...@@ -1936,11 +1936,11 @@ static int __tipc_nl_add_stats(struct sk_buff *skb, struct tipc_stats *s)
int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg, int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
struct tipc_link *link, int nlflags) struct tipc_link *link, int nlflags)
{ {
int err; u32 self = tipc_own_addr(net);
void *hdr;
struct nlattr *attrs; struct nlattr *attrs;
struct nlattr *prop; struct nlattr *prop;
struct tipc_net *tn = net_generic(net, tipc_net_id); void *hdr;
int err;
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family, hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
nlflags, TIPC_NL_LINK_GET); nlflags, TIPC_NL_LINK_GET);
...@@ -1953,8 +1953,7 @@ int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg, ...@@ -1953,8 +1953,7 @@ int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name)) if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name))
goto attr_msg_full; goto attr_msg_full;
if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST, if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST, tipc_cluster_mask(self)))
tipc_cluster_mask(tn->own_addr)))
goto attr_msg_full; goto attr_msg_full;
if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->mtu)) if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->mtu))
goto attr_msg_full; goto attr_msg_full;
......
...@@ -68,14 +68,14 @@ static void publ_to_item(struct distr_item *i, struct publication *p) ...@@ -68,14 +68,14 @@ static void publ_to_item(struct distr_item *i, struct publication *p)
static struct sk_buff *named_prepare_buf(struct net *net, u32 type, u32 size, static struct sk_buff *named_prepare_buf(struct net *net, u32 type, u32 size,
u32 dest) u32 dest)
{ {
struct tipc_net *tn = net_generic(net, tipc_net_id);
struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size, GFP_ATOMIC); struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size, GFP_ATOMIC);
u32 self = tipc_own_addr(net);
struct tipc_msg *msg; struct tipc_msg *msg;
if (buf != NULL) { if (buf != NULL) {
msg = buf_msg(buf); msg = buf_msg(buf);
tipc_msg_init(tn->own_addr, msg, NAME_DISTRIBUTOR, type, tipc_msg_init(self, msg, NAME_DISTRIBUTOR,
INT_H_SIZE, dest); type, INT_H_SIZE, dest);
msg_set_size(msg, INT_H_SIZE + size); msg_set_size(msg, INT_H_SIZE + size);
} }
return buf; return buf;
...@@ -382,13 +382,14 @@ void tipc_named_reinit(struct net *net) ...@@ -382,13 +382,14 @@ void tipc_named_reinit(struct net *net)
struct name_table *nt = tipc_name_table(net); struct name_table *nt = tipc_name_table(net);
struct tipc_net *tn = tipc_net(net); struct tipc_net *tn = tipc_net(net);
struct publication *publ; struct publication *publ;
u32 self = tipc_own_addr(net);
spin_lock_bh(&tn->nametbl_lock); spin_lock_bh(&tn->nametbl_lock);
list_for_each_entry_rcu(publ, &nt->node_scope, binding_node) list_for_each_entry_rcu(publ, &nt->node_scope, binding_node)
publ->node = tn->own_addr; publ->node = self;
list_for_each_entry_rcu(publ, &nt->cluster_scope, binding_node) list_for_each_entry_rcu(publ, &nt->cluster_scope, binding_node)
publ->node = tn->own_addr; publ->node = self;
spin_unlock_bh(&tn->nametbl_lock); spin_unlock_bh(&tn->nametbl_lock);
} }
...@@ -540,7 +540,7 @@ u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, ...@@ -540,7 +540,7 @@ u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance,
} }
/* Round-Robin Algorithm */ /* Round-Robin Algorithm */
else if (*destnode == tn->own_addr) { else if (*destnode == tipc_own_addr(net)) {
if (list_empty(&info->local_publ)) if (list_empty(&info->local_publ))
goto no_match; goto no_match;
publ = list_first_entry(&info->local_publ, struct publication, publ = list_first_entry(&info->local_publ, struct publication,
...@@ -713,7 +713,7 @@ struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower, ...@@ -713,7 +713,7 @@ struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower,
} }
publ = tipc_nametbl_insert_publ(net, type, lower, upper, scope, publ = tipc_nametbl_insert_publ(net, type, lower, upper, scope,
tn->own_addr, port_ref, key); tipc_own_addr(net), port_ref, key);
if (likely(publ)) { if (likely(publ)) {
tn->nametbl->local_publ_count++; tn->nametbl->local_publ_count++;
buf = tipc_named_publish(net, publ); buf = tipc_named_publish(net, publ);
...@@ -738,7 +738,7 @@ int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 port, ...@@ -738,7 +738,7 @@ int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 port,
struct tipc_net *tn = net_generic(net, tipc_net_id); struct tipc_net *tn = net_generic(net, tipc_net_id);
spin_lock_bh(&tn->nametbl_lock); spin_lock_bh(&tn->nametbl_lock);
publ = tipc_nametbl_remove_publ(net, type, lower, tn->own_addr, publ = tipc_nametbl_remove_publ(net, type, lower, tipc_own_addr(net),
port, key); port, key);
if (likely(publ)) { if (likely(publ)) {
tn->nametbl->local_publ_count--; tn->nametbl->local_publ_count--;
......
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
int tipc_net_start(struct net *net, u32 addr) int tipc_net_start(struct net *net, u32 addr)
{ {
struct tipc_net *tn = net_generic(net, tipc_net_id); struct tipc_net *tn = tipc_net(net);
char addr_string[16]; char addr_string[16];
tn->own_addr = addr; tn->own_addr = addr;
...@@ -117,25 +117,24 @@ int tipc_net_start(struct net *net, u32 addr) ...@@ -117,25 +117,24 @@ int tipc_net_start(struct net *net, u32 addr)
tipc_named_reinit(net); tipc_named_reinit(net);
tipc_sk_reinit(net); tipc_sk_reinit(net);
tipc_nametbl_publish(net, TIPC_CFG_SRV, tn->own_addr, tn->own_addr, tipc_nametbl_publish(net, TIPC_CFG_SRV, addr, addr,
TIPC_CLUSTER_SCOPE, 0, tn->own_addr); TIPC_CLUSTER_SCOPE, 0, addr);
pr_info("Started in network mode\n"); pr_info("Started in network mode\n");
pr_info("Own node address %s, cluster identity %u\n", pr_info("Own node address %s, cluster identity %u\n",
tipc_addr_string_fill(addr_string, tn->own_addr), tipc_addr_string_fill(addr_string, addr),
tn->net_id); tn->net_id);
return 0; return 0;
} }
void tipc_net_stop(struct net *net) void tipc_net_stop(struct net *net)
{ {
struct tipc_net *tn = net_generic(net, tipc_net_id); u32 self = tipc_own_addr(net);
if (!tn->own_addr) if (!self)
return; return;
tipc_nametbl_withdraw(net, TIPC_CFG_SRV, tn->own_addr, 0, tipc_nametbl_withdraw(net, TIPC_CFG_SRV, self, 0, self);
tn->own_addr);
rtnl_lock(); rtnl_lock();
tipc_bearer_stop(net); tipc_bearer_stop(net);
tipc_node_stop(net); tipc_node_stop(net);
...@@ -202,9 +201,9 @@ int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -202,9 +201,9 @@ int tipc_nl_net_dump(struct sk_buff *skb, struct netlink_callback *cb)
int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
{ {
struct net *net = sock_net(skb->sk);
struct tipc_net *tn = net_generic(net, tipc_net_id);
struct nlattr *attrs[TIPC_NLA_NET_MAX + 1]; struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
struct net *net = sock_net(skb->sk);
struct tipc_net *tn = tipc_net(net);
int err; int err;
if (!info->attrs[TIPC_NLA_NET]) if (!info->attrs[TIPC_NLA_NET])
...@@ -216,13 +215,13 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) ...@@ -216,13 +215,13 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
if (err) if (err)
return err; return err;
/* Can't change net id once TIPC has joined a network */
if (tipc_own_addr(net))
return -EPERM;
if (attrs[TIPC_NLA_NET_ID]) { if (attrs[TIPC_NLA_NET_ID]) {
u32 val; u32 val;
/* Can't change net id once TIPC has joined a network */
if (tn->own_addr)
return -EPERM;
val = nla_get_u32(attrs[TIPC_NLA_NET_ID]); val = nla_get_u32(attrs[TIPC_NLA_NET_ID]);
if (val < 1 || val > 9999) if (val < 1 || val > 9999)
return -EINVAL; return -EINVAL;
...@@ -233,10 +232,6 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) ...@@ -233,10 +232,6 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
if (attrs[TIPC_NLA_NET_ADDR]) { if (attrs[TIPC_NLA_NET_ADDR]) {
u32 addr; u32 addr;
/* Can't change net addr once TIPC has joined a network */
if (tn->own_addr)
return -EPERM;
addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]); addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]);
if (!addr) if (!addr)
return -EINVAL; return -EINVAL;
......
...@@ -289,10 +289,9 @@ static bool tipc_sk_type_connectionless(struct sock *sk) ...@@ -289,10 +289,9 @@ static bool tipc_sk_type_connectionless(struct sock *sk)
static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg)
{ {
struct sock *sk = &tsk->sk; struct sock *sk = &tsk->sk;
struct tipc_net *tn = net_generic(sock_net(sk), tipc_net_id); u32 self = tipc_own_addr(sock_net(sk));
u32 peer_port = tsk_peer_port(tsk); u32 peer_port = tsk_peer_port(tsk);
u32 orig_node; u32 orig_node, peer_node;
u32 peer_node;
if (unlikely(!tipc_sk_connected(sk))) if (unlikely(!tipc_sk_connected(sk)))
return false; return false;
...@@ -306,10 +305,10 @@ static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) ...@@ -306,10 +305,10 @@ static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg)
if (likely(orig_node == peer_node)) if (likely(orig_node == peer_node))
return true; return true;
if (!orig_node && (peer_node == tn->own_addr)) if (!orig_node && peer_node == self)
return true; return true;
if (!peer_node && (orig_node == tn->own_addr)) if (!peer_node && orig_node == self)
return true; return true;
return false; return false;
...@@ -461,8 +460,8 @@ static int tipc_sk_create(struct net *net, struct socket *sock, ...@@ -461,8 +460,8 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
/* Ensure tsk is visible before we read own_addr. */ /* Ensure tsk is visible before we read own_addr. */
smp_mb(); smp_mb();
tipc_msg_init(tn->own_addr, msg, TIPC_LOW_IMPORTANCE, TIPC_NAMED_MSG, tipc_msg_init(tipc_own_addr(net), msg, TIPC_LOW_IMPORTANCE,
NAMED_H_SIZE, 0); TIPC_NAMED_MSG, NAMED_H_SIZE, 0);
msg_set_origport(msg, tsk->portid); msg_set_origport(msg, tsk->portid);
timer_setup(&sk->sk_timer, tipc_sk_timeout, 0); timer_setup(&sk->sk_timer, tipc_sk_timeout, 0);
...@@ -671,7 +670,6 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr, ...@@ -671,7 +670,6 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,
struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
struct tipc_sock *tsk = tipc_sk(sk); struct tipc_sock *tsk = tipc_sk(sk);
struct tipc_net *tn = net_generic(sock_net(sock->sk), tipc_net_id);
memset(addr, 0, sizeof(*addr)); memset(addr, 0, sizeof(*addr));
if (peer) { if (peer) {
...@@ -682,7 +680,7 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr, ...@@ -682,7 +680,7 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,
addr->addr.id.node = tsk_peer_node(tsk); addr->addr.id.node = tsk_peer_node(tsk);
} else { } else {
addr->addr.id.ref = tsk->portid; addr->addr.id.ref = tsk->portid;
addr->addr.id.node = tn->own_addr; addr->addr.id.node = tipc_own_addr(sock_net(sk));
} }
addr->addrtype = TIPC_ADDR_ID; addr->addrtype = TIPC_ADDR_ID;
...@@ -2667,8 +2665,8 @@ void tipc_sk_reinit(struct net *net) ...@@ -2667,8 +2665,8 @@ void tipc_sk_reinit(struct net *net)
while ((tsk = rhashtable_walk_next(&iter)) && !IS_ERR(tsk)) { while ((tsk = rhashtable_walk_next(&iter)) && !IS_ERR(tsk)) {
spin_lock_bh(&tsk->sk.sk_lock.slock); spin_lock_bh(&tsk->sk.sk_lock.slock);
msg = &tsk->phdr; msg = &tsk->phdr;
msg_set_prevnode(msg, tn->own_addr); msg_set_prevnode(msg, tipc_own_addr(net));
msg_set_orignode(msg, tn->own_addr); msg_set_orignode(msg, tipc_own_addr(net));
spin_unlock_bh(&tsk->sk.sk_lock.slock); spin_unlock_bh(&tsk->sk.sk_lock.slock);
} }
...@@ -3167,11 +3165,10 @@ static int __tipc_nl_add_sk_info(struct sk_buff *skb, struct tipc_sock ...@@ -3167,11 +3165,10 @@ static int __tipc_nl_add_sk_info(struct sk_buff *skb, struct tipc_sock
*tsk) *tsk)
{ {
struct net *net = sock_net(skb->sk); struct net *net = sock_net(skb->sk);
struct tipc_net *tn = tipc_net(net);
struct sock *sk = &tsk->sk; struct sock *sk = &tsk->sk;
if (nla_put_u32(skb, TIPC_NLA_SOCK_REF, tsk->portid) || if (nla_put_u32(skb, TIPC_NLA_SOCK_REF, tsk->portid) ||
nla_put_u32(skb, TIPC_NLA_SOCK_ADDR, tn->own_addr)) nla_put_u32(skb, TIPC_NLA_SOCK_ADDR, tipc_own_addr(net)))
return -EMSGSIZE; return -EMSGSIZE;
if (tipc_sk_connected(sk)) { if (tipc_sk_connected(sk)) {
......
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