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