History

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.

Jon Maloy committed 8 years ago

Commit 23fd3ea1 parent b89afb18 files · +42 −49Browse files

Unified · Split

8 files
  1. net/tipc/addr.c +3 −3
  2. net/tipc/addr.h +1 −1
  3. net/tipc/discover.c +2 −1
  4. net/tipc/link.c +4 −5
  5. net/tipc/name_distr.c +6 −5
  6. net/tipc/name_table.c +3 −3
  7. net/tipc/net.c +13 −18
  8. net/tipc/socket.c +10 −13
net/tipc/addr.c+3−3
@@ -43,9 +43,7 @@ · 42 unmodified lines
4343 */
4444 int in_own_node(struct net *net, u32 addr)
4545 {
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;
4947 }
5048
5149 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) · 4 unmodified lines
5654 return false;
5755 if (domain == tipc_cluster_mask(addr)) /* domain <Z.C.0> */
5856 return true;
57+ if (domain == (addr & TIPC_ZONE_CLUSTER_MASK)) /* domain <Z.C.0> */
58+ return true;
5959 if (domain == (addr & TIPC_ZONE_MASK)) /* domain <Z.0.0> */
6060 return true;
6161 return false;
net/tipc/addr.h+1−1
@@ -45,7 +45,7 @@ · 44 unmodified lines
4545
4646 static inline u32 tipc_own_addr(struct net *net)
4747 {
48− struct tipc_net *tn = net_generic(net, tipc_net_id);
48+ struct tipc_net *tn = tipc_net(net);
4949
5050 return tn->own_addr;
5151 }
net/tipc/discover.c+2−1
@@ -81,11 +81,12 @@ static void tipc_disc_init_msg(struct net *net, struct sk_buff *skb, · 80 unmodified lines
8181 u32 mtyp, struct tipc_bearer *b)
8282 {
8383 struct tipc_net *tn = tipc_net(net);
84+ u32 self = tipc_own_addr(net);
8485 u32 dest_domain = b->domain;
8586 struct tipc_msg *hdr;
8687
8788 hdr = buf_msg(skb);
88− tipc_msg_init(tn->own_addr, hdr, LINK_CONFIG, mtyp,
89+ tipc_msg_init(self, hdr, LINK_CONFIG, mtyp,
8990 MAX_H_SIZE, dest_domain);
9091 msg_set_non_seq(hdr, 1);
9192 msg_set_node_sig(hdr, tn->random);
net/tipc/link.c+4−5
@@ -1936,11 +1936,11 @@ msg_full: · 1935 unmodified lines
19361936 int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
19371937 struct tipc_link *link, int nlflags)
19381938 {
1939− int err;
1940− void *hdr;
1939+ u32 self = tipc_own_addr(net);
19411940 struct nlattr *attrs;
19421941 struct nlattr *prop;
1943− struct tipc_net *tn = net_generic(net, tipc_net_id);
1942+ void *hdr;
1943+ int err;
19441944
19451945 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
19461946 nlflags, TIPC_NL_LINK_GET);
@@ -1953,8 +1953,7 @@ int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg, · 6 unmodified lines
19531953
19541954 if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, link->name))
19551955 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)))
19581957 goto attr_msg_full;
19591958 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_MTU, link->mtu))
19601959 goto attr_msg_full;
net/tipc/name_distr.c+6−5
@@ -68,14 +68,14 @@ static void publ_to_item(struct distr_item *i, struct publication *p) · 67 unmodified lines
6868 static struct sk_buff *named_prepare_buf(struct net *net, u32 type, u32 size,
6969 u32 dest)
7070 {
71− struct tipc_net *tn = net_generic(net, tipc_net_id);
7271 struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size, GFP_ATOMIC);
72+ u32 self = tipc_own_addr(net);
7373 struct tipc_msg *msg;
7474
7575 if (buf != NULL) {
7676 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);
7979 msg_set_size(msg, INT_H_SIZE + size);
8080 }
8181 return buf;
@@ -382,13 +382,14 @@ void tipc_named_reinit(struct net *net) · 300 unmodified lines
382382 struct name_table *nt = tipc_name_table(net);
383383 struct tipc_net *tn = tipc_net(net);
384384 struct publication *publ;
385+ u32 self = tipc_own_addr(net);
385386
386387 spin_lock_bh(&tn->nametbl_lock);
387388
388389 list_for_each_entry_rcu(publ, &nt->node_scope, binding_node)
389− publ->node = tn->own_addr;
390+ publ->node = self;
390391 list_for_each_entry_rcu(publ, &nt->cluster_scope, binding_node)
391− publ->node = tn->own_addr;
392+ publ->node = self;
392393
393394 spin_unlock_bh(&tn->nametbl_lock);
394395 }
net/tipc/name_table.c+3−3
@@ -540,7 +540,7 @@ u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, · 539 unmodified lines
540540 }
541541
542542 /* Round-Robin Algorithm */
543− else if (*destnode == tn->own_addr) {
543+ else if (*destnode == tipc_own_addr(net)) {
544544 if (list_empty(&info->local_publ))
545545 goto no_match;
546546 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, · 166 unmodified lines
713713 }
714714
715715 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);
717717 if (likely(publ)) {
718718 tn->nametbl->local_publ_count++;
719719 buf = tipc_named_publish(net, publ);
@@ -738,7 +738,7 @@ int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 port, · 18 unmodified lines
738738 struct tipc_net *tn = net_generic(net, tipc_net_id);
739739
740740 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),
742742 port, key);
743743 if (likely(publ)) {
744744 tn->nametbl->local_publ_count--;
net/tipc/net.c+13−18
@@ -106,7 +106,7 @@ · 105 unmodified lines
106106
107107 int tipc_net_start(struct net *net, u32 addr)
108108 {
109− struct tipc_net *tn = net_generic(net, tipc_net_id);
109+ struct tipc_net *tn = tipc_net(net);
110110 char addr_string[16];
111111
112112 tn->own_addr = addr;
@@ -117,25 +117,24 @@ int tipc_net_start(struct net *net, u32 addr) · 4 unmodified lines
117117 tipc_named_reinit(net);
118118 tipc_sk_reinit(net);
119119
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);
122122
123123 pr_info("Started in network mode\n");
124124 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),
126126 tn->net_id);
127127 return 0;
128128 }
129129
130130 void tipc_net_stop(struct net *net)
131131 {
132− struct tipc_net *tn = net_generic(net, tipc_net_id);
132+ u32 self = tipc_own_addr(net);
133133
134− if (!tn->own_addr)
134+ if (!self)
135135 return;
136136
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);
139138 rtnl_lock();
140139 tipc_bearer_stop(net);
141140 tipc_node_stop(net);
@@ -202,9 +201,9 @@ out: · 60 unmodified lines
202201
203202 int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info)
204203 {
205− struct net *net = sock_net(skb->sk);
206− struct tipc_net *tn = net_generic(net, tipc_net_id);
207204 struct nlattr *attrs[TIPC_NLA_NET_MAX + 1];
205+ struct net *net = sock_net(skb->sk);
206+ struct tipc_net *tn = tipc_net(net);
208207 int err;
209208
210209 if (!info->attrs[TIPC_NLA_NET])
@@ -216,13 +215,13 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) · 5 unmodified lines
216215 if (err)
217216 return err;
218217
218+ /* Can't change net id once TIPC has joined a network */
219+ if (tipc_own_addr(net))
220+ return -EPERM;
221+
219222 if (attrs[TIPC_NLA_NET_ID]) {
220223 u32 val;
221224
222− /* Can't change net id once TIPC has joined a network */
223− if (tn->own_addr)
224− return -EPERM;
225−
226225 val = nla_get_u32(attrs[TIPC_NLA_NET_ID]);
227226 if (val < 1 || val > 9999)
228227 return -EINVAL;
@@ -233,10 +232,6 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) · 4 unmodified lines
233232 if (attrs[TIPC_NLA_NET_ADDR]) {
234233 u32 addr;
235234
236− /* Can't change net addr once TIPC has joined a network */
237− if (tn->own_addr)
238− return -EPERM;
239−
240235 addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]);
241236 if (!addr)
242237 return -EINVAL;
net/tipc/socket.c+10−13
@@ -289,10 +289,9 @@ static bool tipc_sk_type_connectionless(struct sock *sk) · 288 unmodified lines
289289 static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg)
290290 {
291291 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));
293293 u32 peer_port = tsk_peer_port(tsk);
294− u32 orig_node;
295− u32 peer_node;
294+ u32 orig_node, peer_node;
296295
297296 if (unlikely(!tipc_sk_connected(sk)))
298297 return false;
@@ -306,10 +305,10 @@ static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) · 7 unmodified lines
306305 if (likely(orig_node == peer_node))
307306 return true;
308307
309− if (!orig_node && (peer_node == tn->own_addr))
308+ if (!orig_node && peer_node == self)
310309 return true;
311310
312− if (!peer_node && (orig_node == tn->own_addr))
311+ if (!peer_node && orig_node == self)
313312 return true;
314313
315314 return false;
@@ -461,8 +460,8 @@ static int tipc_sk_create(struct net *net, struct socket *sock, · 145 unmodified lines
461460 /* Ensure tsk is visible before we read own_addr. */
462461 smp_mb();
463462
464− tipc_msg_init(tn->own_addr, msg, TIPC_LOW_IMPORTANCE, TIPC_NAMED_MSG,
465− NAMED_H_SIZE, 0);
463+ tipc_msg_init(tipc_own_addr(net), msg, TIPC_LOW_IMPORTANCE,
464+ TIPC_NAMED_MSG, NAMED_H_SIZE, 0);
466465
467466 msg_set_origport(msg, tsk->portid);
468467 timer_setup(&sk->sk_timer, tipc_sk_timeout, 0);
@@ -671,7 +670,6 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr, · 202 unmodified lines
671670 struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
672671 struct sock *sk = sock->sk;
673672 struct tipc_sock *tsk = tipc_sk(sk);
674− struct tipc_net *tn = net_generic(sock_net(sock->sk), tipc_net_id);
675673
676674 memset(addr, 0, sizeof(*addr));
677675 if (peer) {
@@ -682,7 +680,7 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr, · 4 unmodified lines
682680 addr->addr.id.node = tsk_peer_node(tsk);
683681 } else {
684682 addr->addr.id.ref = tsk->portid;
685− addr->addr.id.node = tn->own_addr;
683+ addr->addr.id.node = tipc_own_addr(sock_net(sk));
686684 }
687685
688686 addr->addrtype = TIPC_ADDR_ID;
@@ -2667,8 +2665,8 @@ void tipc_sk_reinit(struct net *net) · 1978 unmodified lines
26672665 while ((tsk = rhashtable_walk_next(&iter)) && !IS_ERR(tsk)) {
26682666 spin_lock_bh(&tsk->sk.sk_lock.slock);
26692667 msg = &tsk->phdr;
2670− msg_set_prevnode(msg, tn->own_addr);
2671− msg_set_orignode(msg, tn->own_addr);
2668+ msg_set_prevnode(msg, tipc_own_addr(net));
2669+ msg_set_orignode(msg, tipc_own_addr(net));
26722670 spin_unlock_bh(&tsk->sk.sk_lock.slock);
26732671 }
26742672
@@ -3167,11 +3165,10 @@ static int __tipc_nl_add_sk_info(struct sk_buff *skb, struct tipc_sock · 492 unmodified lines
31673165 *tsk)
31683166 {
31693167 struct net *net = sock_net(skb->sk);
3170− struct tipc_net *tn = tipc_net(net);
31713168 struct sock *sk = &tsk->sk;
31723169
31733170 if (nla_put_u32(skb, TIPC_NLA_SOCK_REF, tsk->portid) ||
3174− nla_put_u32(skb, TIPC_NLA_SOCK_ADDR, tn->own_addr))
3171+ nla_put_u32(skb, TIPC_NLA_SOCK_ADDR, tipc_own_addr(net)))
31753172 return -EMSGSIZE;
31763173
31773174 if (tipc_sk_connected(sk)) {