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.
Unified · Split
| @@ -43,9 +43,7 @@ · 42 unmodified lines | ||
| 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) |
| @@ -56,6 +54,8 @@ bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr) · 4 unmodified lines | ||
| 56 | 54 | return false; |
| 57 | 55 | if (domain == tipc_cluster_mask(addr)) /* domain <Z.C.0> */ |
| 58 | 56 | return true; |
| 57 | + if (domain == (addr & TIPC_ZONE_CLUSTER_MASK)) /* domain <Z.C.0> */ | |
| 58 | + return true; | |
| 59 | 59 | if (domain == (addr & TIPC_ZONE_MASK)) /* domain <Z.0.0> */ |
| 60 | 60 | return true; |
| 61 | 61 | return false; |
| @@ -45,7 +45,7 @@ · 44 unmodified lines | ||
| 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 | } |
| @@ -81,11 +81,12 @@ static void tipc_disc_init_msg(struct net *net, struct sk_buff *skb, · 80 unmodified lines | ||
| 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); |
| @@ -1936,11 +1936,11 @@ msg_full: · 1935 unmodified lines | ||
| 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,8 +1953,7 @@ int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg, · 6 unmodified lines | ||
| 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; |
| @@ -68,14 +68,14 @@ static void publ_to_item(struct distr_item *i, struct publication *p) · 67 unmodified lines | ||
| 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,13 +382,14 @@ void tipc_named_reinit(struct net *net) · 300 unmodified lines | ||
| 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 | } |
| @@ -540,7 +540,7 @@ u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, · 539 unmodified lines | ||
| 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,7 +713,7 @@ struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower, · 166 unmodified lines | ||
| 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,7 +738,7 @@ int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 port, · 18 unmodified lines | ||
| 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--; |
| @@ -106,7 +106,7 @@ · 105 unmodified lines | ||
| 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,25 +117,24 @@ int tipc_net_start(struct net *net, u32 addr) · 4 unmodified lines | ||
| 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); |
| @@ -202,9 +201,9 @@ out: · 60 unmodified lines | ||
| 202 | 201 | |
| 203 | 202 | int __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 | 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 | 207 | int err; |
| 209 | 208 | |
| 210 | 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 | 215 | if (err) |
| 217 | 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 | 222 | if (attrs[TIPC_NLA_NET_ID]) { |
| 220 | 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 | 225 | val = nla_get_u32(attrs[TIPC_NLA_NET_ID]); |
| 227 | 226 | if (val < 1 || val > 9999) |
| 228 | 227 | return -EINVAL; |
| @@ -233,10 +232,6 @@ int __tipc_nl_net_set(struct sk_buff *skb, struct genl_info *info) · 4 unmodified lines | ||
| 233 | 232 | if (attrs[TIPC_NLA_NET_ADDR]) { |
| 234 | 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 | 235 | addr = nla_get_u32(attrs[TIPC_NLA_NET_ADDR]); |
| 241 | 236 | if (!addr) |
| 242 | 237 | return -EINVAL; |
| @@ -289,10 +289,9 @@ static bool tipc_sk_type_connectionless(struct sock *sk) · 288 unmodified lines | ||
| 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; |
| @@ -306,10 +305,10 @@ static bool tsk_peer_msg(struct tipc_sock *tsk, struct tipc_msg *msg) · 7 unmodified lines | ||
| 306 | 305 | if (likely(orig_node == peer_node)) |
| 307 | 306 | return true; |
| 308 | 307 | |
| 309 | − if (!orig_node && (peer_node == tn->own_addr)) | |
| 308 | + if (!orig_node && peer_node == self) | |
| 310 | 309 | return true; |
| 311 | 310 | |
| 312 | − if (!peer_node && (orig_node == tn->own_addr)) | |
| 311 | + if (!peer_node && orig_node == self) | |
| 313 | 312 | return true; |
| 314 | 313 | |
| 315 | 314 | return false; |
| @@ -461,8 +460,8 @@ static int tipc_sk_create(struct net *net, struct socket *sock, · 145 unmodified lines | ||
| 461 | 460 | /* Ensure tsk is visible before we read own_addr. */ |
| 462 | 461 | smp_mb(); |
| 463 | 462 | |
| 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); | |
| 466 | 465 | |
| 467 | 466 | msg_set_origport(msg, tsk->portid); |
| 468 | 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 | 670 | struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr; |
| 672 | 671 | struct sock *sk = sock->sk; |
| 673 | 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 | 674 | memset(addr, 0, sizeof(*addr)); |
| 677 | 675 | if (peer) { |
| @@ -682,7 +680,7 @@ static int tipc_getname(struct socket *sock, struct sockaddr *uaddr, · 4 unmodified lines | ||
| 682 | 680 | addr->addr.id.node = tsk_peer_node(tsk); |
| 683 | 681 | } else { |
| 684 | 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 | 686 | addr->addrtype = TIPC_ADDR_ID; |
| @@ -2667,8 +2665,8 @@ void tipc_sk_reinit(struct net *net) · 1978 unmodified lines | ||
| 2667 | 2665 | while ((tsk = rhashtable_walk_next(&iter)) && !IS_ERR(tsk)) { |
| 2668 | 2666 | spin_lock_bh(&tsk->sk.sk_lock.slock); |
| 2669 | 2667 | 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)); | |
| 2672 | 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 | 3165 | *tsk) |
| 3168 | 3166 | { |
| 3169 | 3167 | struct net *net = sock_net(skb->sk); |
| 3170 | − struct tipc_net *tn = tipc_net(net); | |
| 3171 | 3168 | struct sock *sk = &tsk->sk; |
| 3172 | 3169 | |
| 3173 | 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 | 3172 | return -EMSGSIZE; |
| 3176 | 3173 | |
| 3177 | 3174 | if (tipc_sk_connected(sk)) { |