Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jon Maloy and committed by
David S. Miller
23fd3eac b89afb11

+42 -49
+3 -3
net/tipc/addr.c
··· 43 43 */ 44 44 int in_own_node(struct net *net, u32 addr) 45 45 { 46 - struct tipc_net *tn = net_generic(net, tipc_net_id); 47 - 48 - return (addr == tn->own_addr) || !addr; 46 + return addr == tipc_own_addr(net) || !addr; 49 47 } 50 48 51 49 bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr) ··· 53 55 if (!legacy_format) 54 56 return false; 55 57 if (domain == tipc_cluster_mask(addr)) /* domain <Z.C.0> */ 58 + return true; 59 + if (domain == (addr & TIPC_ZONE_CLUSTER_MASK)) /* domain <Z.C.0> */ 56 60 return true; 57 61 if (domain == (addr & TIPC_ZONE_MASK)) /* domain <Z.0.0> */ 58 62 return true;
+1 -1
net/tipc/addr.h
··· 45 45 46 46 static inline u32 tipc_own_addr(struct net *net) 47 47 { 48 - struct tipc_net *tn = net_generic(net, tipc_net_id); 48 + struct tipc_net *tn = tipc_net(net); 49 49 50 50 return tn->own_addr; 51 51 }
+2 -1
net/tipc/discover.c
··· 81 81 u32 mtyp, struct tipc_bearer *b) 82 82 { 83 83 struct tipc_net *tn = tipc_net(net); 84 + u32 self = tipc_own_addr(net); 84 85 u32 dest_domain = b->domain; 85 86 struct tipc_msg *hdr; 86 87 87 88 hdr = buf_msg(skb); 88 - tipc_msg_init(tn->own_addr, hdr, LINK_CONFIG, mtyp, 89 + tipc_msg_init(self, hdr, LINK_CONFIG, mtyp, 89 90 MAX_H_SIZE, dest_domain); 90 91 msg_set_non_seq(hdr, 1); 91 92 msg_set_node_sig(hdr, tn->random);
+4 -5
net/tipc/link.c
··· 1936 1936 int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg, 1937 1937 struct tipc_link *link, int nlflags) 1938 1938 { 1939 - int err; 1940 - void *hdr; 1939 + u32 self = tipc_own_addr(net); 1941 1940 struct nlattr *attrs; 1942 1941 struct nlattr *prop; 1943 - struct tipc_net *tn = net_generic(net, tipc_net_id); 1942 + void *hdr; 1943 + int err; 1944 1944 1945 1945 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family, 1946 1946 nlflags, TIPC_NL_LINK_GET); ··· 1953 1953 1954 1954 if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name)) 1955 1955 goto attr_msg_full; 1956 - if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST, 1957 - tipc_cluster_mask(tn->own_addr))) 1956 + if (nla_put_u32(msg->skb, TIPC_NLA_LINK_DEST, tipc_cluster_mask(self))) 1958 1957 goto attr_msg_full; 1959 1958 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->mtu)) 1960 1959 goto attr_msg_full;
+6 -5
net/tipc/name_distr.c
··· 68 68 static struct sk_buff *named_prepare_buf(struct net *net, u32 type, u32 size, 69 69 u32 dest) 70 70 { 71 - struct tipc_net *tn = net_generic(net, tipc_net_id); 72 71 struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size, GFP_ATOMIC); 72 + u32 self = tipc_own_addr(net); 73 73 struct tipc_msg *msg; 74 74 75 75 if (buf != NULL) { 76 76 msg = buf_msg(buf); 77 - tipc_msg_init(tn->own_addr, msg, NAME_DISTRIBUTOR, type, 78 - INT_H_SIZE, dest); 77 + tipc_msg_init(self, msg, NAME_DISTRIBUTOR, 78 + type, INT_H_SIZE, dest); 79 79 msg_set_size(msg, INT_H_SIZE + size); 80 80 } 81 81 return buf; ··· 382 382 struct name_table *nt = tipc_name_table(net); 383 383 struct tipc_net *tn = tipc_net(net); 384 384 struct publication *publ; 385 + u32 self = tipc_own_addr(net); 385 386 386 387 spin_lock_bh(&tn->nametbl_lock); 387 388 388 389 list_for_each_entry_rcu(publ, &nt->node_scope, binding_node) 389 - publ->node = tn->own_addr; 390 + publ->node = self; 390 391 list_for_each_entry_rcu(publ, &nt->cluster_scope, binding_node) 391 - publ->node = tn->own_addr; 392 + publ->node = self; 392 393 393 394 spin_unlock_bh(&tn->nametbl_lock); 394 395 }
+3 -3
net/tipc/name_table.c
··· 540 540 } 541 541 542 542 /* Round-Robin Algorithm */ 543 - else if (*destnode == tn->own_addr) { 543 + else if (*destnode == tipc_own_addr(net)) { 544 544 if (list_empty(&info->local_publ)) 545 545 goto no_match; 546 546 publ = list_first_entry(&info->local_publ, struct publication, ··· 713 713 } 714 714 715 715 publ = tipc_nametbl_insert_publ(net, type, lower, upper, scope, 716 - tn->own_addr, port_ref, key); 716 + tipc_own_addr(net), port_ref, key); 717 717 if (likely(publ)) { 718 718 tn->nametbl->local_publ_count++; 719 719 buf = tipc_named_publish(net, publ); ··· 738 738 struct tipc_net *tn = net_generic(net, tipc_net_id); 739 739 740 740 spin_lock_bh(&tn->nametbl_lock); 741 - publ = tipc_nametbl_remove_publ(net, type, lower, tn->own_addr, 741 + publ = tipc_nametbl_remove_publ(net, type, lower, tipc_own_addr(net), 742 742 port, key); 743 743 if (likely(publ)) { 744 744 tn->nametbl->local_publ_count--;
+13 -18
net/tipc/net.c
··· 106 106 107 107 int tipc_net_start(struct net *net, u32 addr) 108 108 { 109 - struct tipc_net *tn = net_generic(net, tipc_net_id); 109 + struct tipc_net *tn = tipc_net(net); 110 110 char addr_string[16]; 111 111 112 112 tn->own_addr = addr; ··· 117 117 tipc_named_reinit(net); 118 118 tipc_sk_reinit(net); 119 119 120 - tipc_nametbl_publish(net, TIPC_CFG_SRV, tn->own_addr, tn->own_addr, 121 - TIPC_CLUSTER_SCOPE, 0, tn->own_addr); 120 + tipc_nametbl_publish(net, TIPC_CFG_SRV, addr, addr, 121 + TIPC_CLUSTER_SCOPE, 0, addr); 122 122 123 123 pr_info("Started in network mode\n"); 124 124 pr_info("Own node address %s, cluster identity %u\n", 125 - tipc_addr_string_fill(addr_string, tn->own_addr), 125 + tipc_addr_string_fill(addr_string, addr), 126 126 tn->net_id); 127 127 return 0; 128 128 } 129 129 130 130 void tipc_net_stop(struct net *net) 131 131 { 132 - struct tipc_net *tn = net_generic(net, tipc_net_id); 132 + u32 self = tipc_own_addr(net); 133 133 134 - if (!tn->own_addr) 134 + if (!self) 135 135 return; 136 136 137 - tipc_nametbl_withdraw(net, TIPC_CFG_SRV, tn->own_addr, 0, 138 - tn->own_addr); 137 + tipc_nametbl_withdraw(net, TIPC_CFG_SRV, self, 0, self); 139 138 rtnl_lock(); 140 139 tipc_bearer_stop(net); 141 140 tipc_node_stop(net); ··· 201 202 202 203 int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) 203 204 { 204 - struct net *net = sock_net(skb->sk); 205 - struct tipc_net *tn = net_generic(net, tipc_net_id); 206 205 struct nlattr *attrs[TIPC_NLA_NET_MAX + 1]; 206 + struct net *net = sock_net(skb->sk); 207 + struct tipc_net *tn = tipc_net(net); 207 208 int err; 208 209 209 210 if (!info->attrs[TIPC_NLA_NET]) ··· 215 216 if (err) 216 217 return err; 217 218 219 + /* Can't change net id once TIPC has joined a network */ 220 + if (tipc_own_addr(net)) 221 + return -EPERM; 222 + 218 223 if (attrs[TIPC_NLA_NET_ID]) { 219 224 u32 val; 220 - 221 - /* Can't change net id once TIPC has joined a network */ 222 - if (tn->own_addr) 223 - return -EPERM; 224 225 225 226 val = nla_get_u32(attrs[TIPC_NLA_NET_ID]); 226 227 if (val < 1 || val > 9999) ··· 231 232 232 233 if (attrs[TIPC_NLA_NET_ADDR]) { 233 234 u32 addr; 234 - 235 - /* Can't change net addr once TIPC has joined a network */ 236 - if (tn->own_addr) 237 - return -EPERM; 238 235 239 236 addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]); 240 237 if (!addr)
+10 -13
net/tipc/socket.c
··· 289 289 static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) 290 290 { 291 291 struct sock *sk = &tsk->sk; 292 - struct tipc_net *tn = net_generic(sock_net(sk), tipc_net_id); 292 + u32 self = tipc_own_addr(sock_net(sk)); 293 293 u32 peer_port = tsk_peer_port(tsk); 294 - u32 orig_node; 295 - u32 peer_node; 294 + u32 orig_node, peer_node; 296 295 297 296 if (unlikely(!tipc_sk_connected(sk))) 298 297 return false; ··· 305 306 if (likely(orig_node == peer_node)) 306 307 return true; 307 308 308 - if (!orig_node && (peer_node == tn->own_addr)) 309 + if (!orig_node && peer_node == self) 309 310 return true; 310 311 311 - if (!peer_node && (orig_node == tn->own_addr)) 312 + if (!peer_node && orig_node == self) 312 313 return true; 313 314 314 315 return false; ··· 460 461 /* Ensure tsk is visible before we read own_addr. */ 461 462 smp_mb(); 462 463 463 - tipc_msg_init(tn->own_addr, msg, TIPC_LOW_IMPORTANCE, TIPC_NAMED_MSG, 464 - NAMED_H_SIZE, 0); 464 + tipc_msg_init(tipc_own_addr(net), msg, TIPC_LOW_IMPORTANCE, 465 + TIPC_NAMED_MSG, NAMED_H_SIZE, 0); 465 466 466 467 msg_set_origport(msg, tsk->portid); 467 468 timer_setup(&sk->sk_timer, tipc_sk_timeout, 0); ··· 670 671 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; 671 672 struct sock *sk = sock->sk; 672 673 struct tipc_sock *tsk = tipc_sk(sk); 673 - struct tipc_net *tn = net_generic(sock_net(sock->sk), tipc_net_id); 674 674 675 675 memset(addr, 0, sizeof(*addr)); 676 676 if (peer) { ··· 680 682 addr->addr.id.node = tsk_peer_node(tsk); 681 683 } else { 682 684 addr->addr.id.ref = tsk->portid; 683 - addr->addr.id.node = tn->own_addr; 685 + addr->addr.id.node = tipc_own_addr(sock_net(sk)); 684 686 } 685 687 686 688 addr->addrtype = TIPC_ADDR_ID; ··· 2665 2667 while ((tsk = rhashtable_walk_next(&iter)) && !IS_ERR(tsk)) { 2666 2668 spin_lock_bh(&tsk->sk.sk_lock.slock); 2667 2669 msg = &tsk->phdr; 2668 - msg_set_prevnode(msg, tn->own_addr); 2669 - msg_set_orignode(msg, tn->own_addr); 2670 + msg_set_prevnode(msg, tipc_own_addr(net)); 2671 + msg_set_orignode(msg, tipc_own_addr(net)); 2670 2672 spin_unlock_bh(&tsk->sk.sk_lock.slock); 2671 2673 } 2672 2674 ··· 3165 3167 *tsk) 3166 3168 { 3167 3169 struct net *net = sock_net(skb->sk); 3168 - struct tipc_net *tn = tipc_net(net); 3169 3170 struct sock *sk = &tsk->sk; 3170 3171 3171 3172 if (nla_put_u32(skb, TIPC_NLA_SOCK_REF, tsk->portid) || 3172 - nla_put_u32(skb, TIPC_NLA_SOCK_ADDR, tn->own_addr)) 3173 + nla_put_u32(skb, TIPC_NLA_SOCK_ADDR, tipc_own_addr(net))) 3173 3174 return -EMSGSIZE; 3174 3175 3175 3176 if (tipc_sk_connected(sk)) {