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: Ying Xue <ying.xue@windriver.com> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
b89afb116c
commit
23fd3eace0
|
@ -43,9 +43,7 @@
|
|||
*/
|
||||
int in_own_node(struct net *net, u32 addr)
|
||||
{
|
||||
struct tipc_net *tn = net_generic(net, tipc_net_id);
|
||||
|
||||
return (addr == tn->own_addr) || !addr;
|
||||
return addr == tipc_own_addr(net) || !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)
|
|||
return false;
|
||||
if (domain == tipc_cluster_mask(addr)) /* domain <Z.C.0> */
|
||||
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> */
|
||||
return true;
|
||||
return false;
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -81,11 +81,12 @@ static void tipc_disc_init_msg(struct net *net, struct sk_buff *skb,
|
|||
u32 mtyp, struct tipc_bearer *b)
|
||||
{
|
||||
struct tipc_net *tn = tipc_net(net);
|
||||
u32 self = tipc_own_addr(net);
|
||||
u32 dest_domain = b->domain;
|
||||
struct tipc_msg *hdr;
|
||||
|
||||
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);
|
||||
msg_set_non_seq(hdr, 1);
|
||||
msg_set_node_sig(hdr, tn->random);
|
||||
|
|
|
@ -1936,11 +1936,11 @@ msg_full:
|
|||
int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
|
||||
struct tipc_link *link, int nlflags)
|
||||
{
|
||||
int err;
|
||||
void *hdr;
|
||||
u32 self = tipc_own_addr(net);
|
||||
struct nlattr *attrs;
|
||||
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,
|
||||
nlflags, TIPC_NL_LINK_GET);
|
||||
|
@ -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))
|
||||
goto attr_msg_full;
|
||||
if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST,
|
||||
tipc_cluster_mask(tn->own_addr)))
|
||||
if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST, tipc_cluster_mask(self)))
|
||||
goto attr_msg_full;
|
||||
if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->mtu))
|
||||
goto attr_msg_full;
|
||||
|
|
|
@ -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,
|
||||
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);
|
||||
u32 self = tipc_own_addr(net);
|
||||
struct tipc_msg *msg;
|
||||
|
||||
if (buf != NULL) {
|
||||
msg = buf_msg(buf);
|
||||
tipc_msg_init(tn->own_addr, msg, NAME_DISTRIBUTOR, type,
|
||||
INT_H_SIZE, dest);
|
||||
tipc_msg_init(self, msg, NAME_DISTRIBUTOR,
|
||||
type, INT_H_SIZE, dest);
|
||||
msg_set_size(msg, INT_H_SIZE + size);
|
||||
}
|
||||
return buf;
|
||||
|
@ -382,13 +382,14 @@ void tipc_named_reinit(struct net *net)
|
|||
struct name_table *nt = tipc_name_table(net);
|
||||
struct tipc_net *tn = tipc_net(net);
|
||||
struct publication *publ;
|
||||
u32 self = tipc_own_addr(net);
|
||||
|
||||
spin_lock_bh(&tn->nametbl_lock);
|
||||
|
||||
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)
|
||||
publ->node = tn->own_addr;
|
||||
publ->node = self;
|
||||
|
||||
spin_unlock_bh(&tn->nametbl_lock);
|
||||
}
|
||||
|
|
|
@ -540,7 +540,7 @@ u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance,
|
|||
}
|
||||
|
||||
/* Round-Robin Algorithm */
|
||||
else if (*destnode == tn->own_addr) {
|
||||
else if (*destnode == tipc_own_addr(net)) {
|
||||
if (list_empty(&info->local_publ))
|
||||
goto no_match;
|
||||
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,
|
|||
}
|
||||
|
||||
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)) {
|
||||
tn->nametbl->local_publ_count++;
|
||||
buf = tipc_named_publish(net, publ);
|
||||
|
@ -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);
|
||||
|
||||
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);
|
||||
if (likely(publ)) {
|
||||
tn->nametbl->local_publ_count--;
|
||||
|
|
|
@ -106,7 +106,7 @@
|
|||
|
||||
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];
|
||||
|
||||
tn->own_addr = addr;
|
||||
|
@ -117,25 +117,24 @@ int tipc_net_start(struct net *net, u32 addr)
|
|||
tipc_named_reinit(net);
|
||||
tipc_sk_reinit(net);
|
||||
|
||||
tipc_nametbl_publish(net, TIPC_CFG_SRV, tn->own_addr, tn->own_addr,
|
||||
TIPC_CLUSTER_SCOPE, 0, tn->own_addr);
|
||||
tipc_nametbl_publish(net, TIPC_CFG_SRV, addr, addr,
|
||||
TIPC_CLUSTER_SCOPE, 0, addr);
|
||||
|
||||
pr_info("Started in network mode\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);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
tipc_nametbl_withdraw(net, TIPC_CFG_SRV, tn->own_addr, 0,
|
||||
tn->own_addr);
|
||||
tipc_nametbl_withdraw(net, TIPC_CFG_SRV, self, 0, self);
|
||||
rtnl_lock();
|
||||
tipc_bearer_stop(net);
|
||||
tipc_node_stop(net);
|
||||
|
@ -202,9 +201,9 @@ out:
|
|||
|
||||
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 net *net = sock_net(skb->sk);
|
||||
struct tipc_net *tn = tipc_net(net);
|
||||
int err;
|
||||
|
||||
if (!info->attrs[TIPC_NLA_NET])
|
||||
|
@ -216,13 +215,13 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
|
|||
if (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]) {
|
||||
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]);
|
||||
if (val < 1 || val > 9999)
|
||||
return -EINVAL;
|
||||
|
@ -233,10 +232,6 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
|
|||
if (attrs[TIPC_NLA_NET_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]);
|
||||
if (!addr)
|
||||
return -EINVAL;
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
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 orig_node;
|
||||
u32 peer_node;
|
||||
u32 orig_node, peer_node;
|
||||
|
||||
if (unlikely(!tipc_sk_connected(sk)))
|
||||
return false;
|
||||
|
@ -306,10 +305,10 @@ static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg)
|
|||
if (likely(orig_node == peer_node))
|
||||
return true;
|
||||
|
||||
if (!orig_node && (peer_node == tn->own_addr))
|
||||
if (!orig_node && peer_node == self)
|
||||
return true;
|
||||
|
||||
if (!peer_node && (orig_node == tn->own_addr))
|
||||
if (!peer_node && orig_node == self)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -461,8 +460,8 @@ static int tipc_sk_create(struct net *net, struct socket *sock,
|
|||
/* Ensure tsk is visible before we read own_addr. */
|
||||
smp_mb();
|
||||
|
||||
tipc_msg_init(tn->own_addr, msg, TIPC_LOW_IMPORTANCE, TIPC_NAMED_MSG,
|
||||
NAMED_H_SIZE, 0);
|
||||
tipc_msg_init(tipc_own_addr(net), msg, TIPC_LOW_IMPORTANCE,
|
||||
TIPC_NAMED_MSG, NAMED_H_SIZE, 0);
|
||||
|
||||
msg_set_origport(msg, tsk->portid);
|
||||
timer_setup(&sk->sk_timer, tipc_sk_timeout, 0);
|
||||
|
@ -671,7 +670,6 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,
|
|||
struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
|
||||
struct sock *sk = sock->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));
|
||||
if (peer) {
|
||||
|
@ -682,7 +680,7 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr,
|
|||
addr->addr.id.node = tsk_peer_node(tsk);
|
||||
} else {
|
||||
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;
|
||||
|
@ -2667,8 +2665,8 @@ void tipc_sk_reinit(struct net *net)
|
|||
while ((tsk = rhashtable_walk_next(&iter)) && !IS_ERR(tsk)) {
|
||||
spin_lock_bh(&tsk->sk.sk_lock.slock);
|
||||
msg = &tsk->phdr;
|
||||
msg_set_prevnode(msg, tn->own_addr);
|
||||
msg_set_orignode(msg, tn->own_addr);
|
||||
msg_set_prevnode(msg, tipc_own_addr(net));
|
||||
msg_set_orignode(msg, tipc_own_addr(net));
|
||||
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
|
|||
*tsk)
|
||||
{
|
||||
struct net *net = sock_net(skb->sk);
|
||||
struct tipc_net *tn = tipc_net(net);
|
||||
struct sock *sk = &tsk->sk;
|
||||
|
||||
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;
|
||||
|
||||
if (tipc_sk_connected(sk)) {
|
||||
|
|
Loading…
Reference in New Issue