Commit 3008ba5faa7a63bac2227c56b533c08fa6d54a0b

Authored by David S. Miller

Merge branch 'tipc-obsolete-zone-concept'

Jon Maloy says:

====================
tipc: obsolete zone concept

Functionality related to the 'zone' concept was never implemented in
TIPC. In this series we eliminate the remaining traces of it in the
code, and can hence take a first step in reducing the footprint and
complexity of the binding table.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 11 changed files Side-by-side Diff

include/uapi/linux/tipc.h
... ... @@ -61,50 +61,6 @@
61 61 __u32 upper;
62 62 };
63 63  
64   -/* TIPC Address Size, Offset, Mask specification for Z.C.N
65   - */
66   -#define TIPC_NODE_BITS 12
67   -#define TIPC_CLUSTER_BITS 12
68   -#define TIPC_ZONE_BITS 8
69   -
70   -#define TIPC_NODE_OFFSET 0
71   -#define TIPC_CLUSTER_OFFSET TIPC_NODE_BITS
72   -#define TIPC_ZONE_OFFSET (TIPC_CLUSTER_OFFSET + TIPC_CLUSTER_BITS)
73   -
74   -#define TIPC_NODE_SIZE ((1UL << TIPC_NODE_BITS) - 1)
75   -#define TIPC_CLUSTER_SIZE ((1UL << TIPC_CLUSTER_BITS) - 1)
76   -#define TIPC_ZONE_SIZE ((1UL << TIPC_ZONE_BITS) - 1)
77   -
78   -#define TIPC_NODE_MASK (TIPC_NODE_SIZE << TIPC_NODE_OFFSET)
79   -#define TIPC_CLUSTER_MASK (TIPC_CLUSTER_SIZE << TIPC_CLUSTER_OFFSET)
80   -#define TIPC_ZONE_MASK (TIPC_ZONE_SIZE << TIPC_ZONE_OFFSET)
81   -
82   -#define TIPC_ZONE_CLUSTER_MASK (TIPC_ZONE_MASK | TIPC_CLUSTER_MASK)
83   -
84   -static inline __u32 tipc_addr(unsigned int zone,
85   - unsigned int cluster,
86   - unsigned int node)
87   -{
88   - return (zone << TIPC_ZONE_OFFSET) |
89   - (cluster << TIPC_CLUSTER_OFFSET) |
90   - node;
91   -}
92   -
93   -static inline unsigned int tipc_zone(__u32 addr)
94   -{
95   - return addr >> TIPC_ZONE_OFFSET;
96   -}
97   -
98   -static inline unsigned int tipc_cluster(__u32 addr)
99   -{
100   - return (addr & TIPC_CLUSTER_MASK) >> TIPC_CLUSTER_OFFSET;
101   -}
102   -
103   -static inline unsigned int tipc_node(__u32 addr)
104   -{
105   - return addr & TIPC_NODE_MASK;
106   -}
107   -
108 64 /*
109 65 * Application-accessible port name types
110 66 */
... ... @@ -117,9 +73,10 @@
117 73 /*
118 74 * Publication scopes when binding port names and port name sequences
119 75 */
120   -#define TIPC_ZONE_SCOPE 1
121   -#define TIPC_CLUSTER_SCOPE 2
122   -#define TIPC_NODE_SCOPE 3
  76 +enum tipc_scope {
  77 + TIPC_CLUSTER_SCOPE = 2, /* 0 can also be used */
  78 + TIPC_NODE_SCOPE = 3
  79 +};
123 80  
124 81 /*
125 82 * Limiting values for messages
... ... @@ -243,7 +200,7 @@
243 200 struct tipc_group_req {
244 201 __u32 type; /* group id */
245 202 __u32 instance; /* member id */
246   - __u32 scope; /* zone/cluster/node */
  203 + __u32 scope; /* cluster/node */
247 204 __u32 flags;
248 205 };
249 206  
... ... @@ -268,5 +225,54 @@
268 225 __u32 bearer_id;
269 226 char linkname[TIPC_MAX_LINK_NAME];
270 227 };
  228 +
  229 +
  230 +/* The macros and functions below are deprecated:
  231 + */
  232 +
  233 +#define TIPC_ZONE_SCOPE 1
  234 +
  235 +#define TIPC_NODE_BITS 12
  236 +#define TIPC_CLUSTER_BITS 12
  237 +#define TIPC_ZONE_BITS 8
  238 +
  239 +#define TIPC_NODE_OFFSET 0
  240 +#define TIPC_CLUSTER_OFFSET TIPC_NODE_BITS
  241 +#define TIPC_ZONE_OFFSET (TIPC_CLUSTER_OFFSET + TIPC_CLUSTER_BITS)
  242 +
  243 +#define TIPC_NODE_SIZE ((1UL << TIPC_NODE_BITS) - 1)
  244 +#define TIPC_CLUSTER_SIZE ((1UL << TIPC_CLUSTER_BITS) - 1)
  245 +#define TIPC_ZONE_SIZE ((1UL << TIPC_ZONE_BITS) - 1)
  246 +
  247 +#define TIPC_NODE_MASK (TIPC_NODE_SIZE << TIPC_NODE_OFFSET)
  248 +#define TIPC_CLUSTER_MASK (TIPC_CLUSTER_SIZE << TIPC_CLUSTER_OFFSET)
  249 +#define TIPC_ZONE_MASK (TIPC_ZONE_SIZE << TIPC_ZONE_OFFSET)
  250 +
  251 +#define TIPC_ZONE_CLUSTER_MASK (TIPC_ZONE_MASK | TIPC_CLUSTER_MASK)
  252 +
  253 +static inline __u32 tipc_addr(unsigned int zone,
  254 + unsigned int cluster,
  255 + unsigned int node)
  256 +{
  257 + return (zone << TIPC_ZONE_OFFSET) |
  258 + (cluster << TIPC_CLUSTER_OFFSET) |
  259 + node;
  260 +}
  261 +
  262 +static inline unsigned int tipc_zone(__u32 addr)
  263 +{
  264 + return addr >> TIPC_ZONE_OFFSET;
  265 +}
  266 +
  267 +static inline unsigned int tipc_cluster(__u32 addr)
  268 +{
  269 + return (addr & TIPC_CLUSTER_MASK) >> TIPC_CLUSTER_OFFSET;
  270 +}
  271 +
  272 +static inline unsigned int tipc_node(__u32 addr)
  273 +{
  274 + return addr & TIPC_NODE_MASK;
  275 +}
  276 +
271 277 #endif
... ... @@ -64,23 +64,6 @@
64 64 }
65 65  
66 66 /**
67   - * addr_domain - convert 2-bit scope value to equivalent message lookup domain
68   - *
69   - * Needed when address of a named message must be looked up a second time
70   - * after a network hop.
71   - */
72   -u32 addr_domain(struct net *net, u32 sc)
73   -{
74   - struct tipc_net *tn = net_generic(net, tipc_net_id);
75   -
76   - if (likely(sc == TIPC_NODE_SCOPE))
77   - return tn->own_addr;
78   - if (sc == TIPC_CLUSTER_SCOPE)
79   - return tipc_cluster_mask(tn->own_addr);
80   - return tipc_zone_mask(tn->own_addr);
81   -}
82   -
83   -/**
84 67 * tipc_addr_domain_valid - validates a network domain address
85 68 *
86 69 * Accepts <Z.C.N>, <Z.C.0>, <Z.0.0>, and <0.0.0>,
... ... @@ -122,20 +105,6 @@
122 105 if (domain == tipc_zone_mask(addr)) /* domain <Z.0.0> */
123 106 return 1;
124 107 return 0;
125   -}
126   -
127   -/**
128   - * tipc_addr_scope - convert message lookup domain to a 2-bit scope value
129   - */
130   -int tipc_addr_scope(u32 domain)
131   -{
132   - if (likely(!domain))
133   - return TIPC_ZONE_SCOPE;
134   - if (tipc_node(domain))
135   - return TIPC_NODE_SCOPE;
136   - if (tipc_cluster(domain))
137   - return TIPC_CLUSTER_SCOPE;
138   - return TIPC_ZONE_SCOPE;
139 108 }
140 109  
141 110 char *tipc_addr_string_fill(char *string, u32 addr)
... ... @@ -60,6 +60,16 @@
60 60 return addr & TIPC_ZONE_CLUSTER_MASK;
61 61 }
62 62  
  63 +static inline int tipc_node2scope(u32 node)
  64 +{
  65 + return node ? TIPC_NODE_SCOPE : TIPC_CLUSTER_SCOPE;
  66 +}
  67 +
  68 +static inline int tipc_scope2node(struct net *net, int sc)
  69 +{
  70 + return sc != TIPC_NODE_SCOPE ? 0 : tipc_own_addr(net);
  71 +}
  72 +
63 73 u32 tipc_own_addr(struct net *net);
64 74 int in_own_cluster(struct net *net, u32 addr);
65 75 int in_own_cluster_exact(struct net *net, u32 addr);
... ... @@ -131,6 +131,11 @@
131 131 return &tipc_net(net)->node_list;
132 132 }
133 133  
  134 +static inline struct name_table *tipc_name_table(struct net *net)
  135 +{
  136 + return tipc_net(net)->nametbl;
  137 +}
  138 +
134 139 static inline struct tipc_topsrv *tipc_topsrv(struct net *net)
135 140 {
136 141 return tipc_net(net)->topsrv;
... ... @@ -580,7 +580,7 @@
580 580 msg = buf_msg(skb);
581 581 if (msg_reroute_cnt(msg))
582 582 return false;
583   - dnode = addr_domain(net, msg_lookup_scope(msg));
  583 + dnode = tipc_scope2node(net, msg_lookup_scope(msg));
584 584 dport = tipc_nametbl_translate(net, msg_nametype(msg),
585 585 msg_nameinst(msg), &dnode);
586 586 if (!dport)
net/tipc/name_distr.c
... ... @@ -56,7 +56,7 @@
56 56 i->type = htonl(p->type);
57 57 i->lower = htonl(p->lower);
58 58 i->upper = htonl(p->upper);
59   - i->ref = htonl(p->ref);
  59 + i->port = htonl(p->port);
60 60 i->key = htonl(p->key);
61 61 }
62 62  
63 63  
64 64  
65 65  
66 66  
67 67  
68 68  
... ... @@ -86,25 +86,25 @@
86 86 */
87 87 struct sk_buff *tipc_named_publish(struct net *net, struct publication *publ)
88 88 {
89   - struct tipc_net *tn = net_generic(net, tipc_net_id);
90   - struct sk_buff *buf;
  89 + struct name_table *nt = tipc_name_table(net);
91 90 struct distr_item *item;
  91 + struct sk_buff *skb;
92 92  
93   - list_add_tail_rcu(&publ->local_list,
94   - &tn->nametbl->publ_list[publ->scope]);
95   -
96   - if (publ->scope == TIPC_NODE_SCOPE)
  93 + if (publ->scope == TIPC_NODE_SCOPE) {
  94 + list_add_tail_rcu(&publ->binding_node, &nt->node_scope);
97 95 return NULL;
  96 + }
  97 + list_add_tail_rcu(&publ->binding_node, &nt->cluster_scope);
98 98  
99   - buf = named_prepare_buf(net, PUBLICATION, ITEM_SIZE, 0);
100   - if (!buf) {
  99 + skb = named_prepare_buf(net, PUBLICATION, ITEM_SIZE, 0);
  100 + if (!skb) {
101 101 pr_warn("Publication distribution failure\n");
102 102 return NULL;
103 103 }
104 104  
105   - item = (struct distr_item *)msg_data(buf_msg(buf));
  105 + item = (struct distr_item *)msg_data(buf_msg(skb));
106 106 publ_to_item(item, publ);
107   - return buf;
  107 + return skb;
108 108 }
109 109  
110 110 /**
... ... @@ -115,7 +115,7 @@
115 115 struct sk_buff *buf;
116 116 struct distr_item *item;
117 117  
118   - list_del(&publ->local_list);
  118 + list_del(&publ->binding_node);
119 119  
120 120 if (publ->scope == TIPC_NODE_SCOPE)
121 121 return NULL;
... ... @@ -147,7 +147,7 @@
147 147 ITEM_SIZE) * ITEM_SIZE;
148 148 u32 msg_rem = msg_dsz;
149 149  
150   - list_for_each_entry(publ, pls, local_list) {
  150 + list_for_each_entry(publ, pls, binding_node) {
151 151 /* Prepare next buffer: */
152 152 if (!skb) {
153 153 skb = named_prepare_buf(net, PUBLICATION, msg_rem,
154 154  
... ... @@ -184,16 +184,13 @@
184 184 */
185 185 void tipc_named_node_up(struct net *net, u32 dnode)
186 186 {
187   - struct tipc_net *tn = net_generic(net, tipc_net_id);
  187 + struct name_table *nt = tipc_name_table(net);
188 188 struct sk_buff_head head;
189 189  
190 190 __skb_queue_head_init(&head);
191 191  
192 192 rcu_read_lock();
193   - named_distribute(net, &head, dnode,
194   - &tn->nametbl->publ_list[TIPC_CLUSTER_SCOPE]);
195   - named_distribute(net, &head, dnode,
196   - &tn->nametbl->publ_list[TIPC_ZONE_SCOPE]);
  193 + named_distribute(net, &head, dnode, &nt->cluster_scope);
197 194 rcu_read_unlock();
198 195  
199 196 tipc_node_xmit(net, &head, dnode, 0);
200 197  
201 198  
... ... @@ -212,15 +209,15 @@
212 209  
213 210 spin_lock_bh(&tn->nametbl_lock);
214 211 p = tipc_nametbl_remove_publ(net, publ->type, publ->lower,
215   - publ->node, publ->ref, publ->key);
  212 + publ->node, publ->port, publ->key);
216 213 if (p)
217   - tipc_node_unsubscribe(net, &p->nodesub_list, addr);
  214 + tipc_node_unsubscribe(net, &p->binding_node, addr);
218 215 spin_unlock_bh(&tn->nametbl_lock);
219 216  
220 217 if (p != publ) {
221 218 pr_err("Unable to remove publication from failed node\n"
222   - " (type=%u, lower=%u, node=0x%x, ref=%u, key=%u)\n",
223   - publ->type, publ->lower, publ->node, publ->ref,
  219 + " (type=%u, lower=%u, node=0x%x, port=%u, key=%u)\n",
  220 + publ->type, publ->lower, publ->node, publ->port,
224 221 publ->key);
225 222 }
226 223  
... ... @@ -249,7 +246,7 @@
249 246 {
250 247 struct publication *publ, *tmp;
251 248  
252   - list_for_each_entry_safe(publ, tmp, nsub_list, nodesub_list)
  249 + list_for_each_entry_safe(publ, tmp, nsub_list, binding_node)
253 250 tipc_publ_purge(net, publ, addr);
254 251 tipc_dist_queue_purge(net, addr);
255 252 }
256 253  
257 254  
258 255  
... ... @@ -271,18 +268,18 @@
271 268 ntohl(i->lower),
272 269 ntohl(i->upper),
273 270 TIPC_CLUSTER_SCOPE, node,
274   - ntohl(i->ref), ntohl(i->key));
  271 + ntohl(i->port), ntohl(i->key));
275 272 if (publ) {
276   - tipc_node_subscribe(net, &publ->nodesub_list, node);
  273 + tipc_node_subscribe(net, &publ->binding_node, node);
277 274 return true;
278 275 }
279 276 } else if (dtype == WITHDRAWAL) {
280 277 publ = tipc_nametbl_remove_publ(net, ntohl(i->type),
281 278 ntohl(i->lower),
282   - node, ntohl(i->ref),
  279 + node, ntohl(i->port),
283 280 ntohl(i->key));
284 281 if (publ) {
285   - tipc_node_unsubscribe(net, &publ->nodesub_list, node);
  282 + tipc_node_unsubscribe(net, &publ->binding_node, node);
286 283 kfree_rcu(publ, rcu);
287 284 return true;
288 285 }
289 286  
290 287  
... ... @@ -382,16 +379,16 @@
382 379 */
383 380 void tipc_named_reinit(struct net *net)
384 381 {
385   - struct tipc_net *tn = net_generic(net, tipc_net_id);
  382 + struct name_table *nt = tipc_name_table(net);
  383 + struct tipc_net *tn = tipc_net(net);
386 384 struct publication *publ;
387   - int scope;
388 385  
389 386 spin_lock_bh(&tn->nametbl_lock);
390 387  
391   - for (scope = TIPC_ZONE_SCOPE; scope <= TIPC_NODE_SCOPE; scope++)
392   - list_for_each_entry_rcu(publ, &tn->nametbl->publ_list[scope],
393   - local_list)
394   - publ->node = tn->own_addr;
  388 + list_for_each_entry_rcu(publ, &nt->node_scope, binding_node)
  389 + publ->node = tn->own_addr;
  390 + list_for_each_entry_rcu(publ, &nt->cluster_scope, binding_node)
  391 + publ->node = tn->own_addr;
395 392  
396 393 spin_unlock_bh(&tn->nametbl_lock);
397 394 }
net/tipc/name_distr.h
... ... @@ -63,7 +63,7 @@
63 63 __be32 type;
64 64 __be32 lower;
65 65 __be32 upper;
66   - __be32 ref;
  66 + __be32 port;
67 67 __be32 key;
68 68 };
69 69  
net/tipc/name_table.c
1 1 /*
2 2 * net/tipc/name_table.c: TIPC name table code
3 3 *
4   - * Copyright (c) 2000-2006, 2014-2015, Ericsson AB
  4 + * Copyright (c) 2000-2006, 2014-2018, Ericsson AB
5 5 * Copyright (c) 2004-2008, 2010-2014, Wind River Systems
6 6 * All rights reserved.
7 7 *
8 8  
... ... @@ -50,24 +50,12 @@
50 50  
51 51 /**
52 52 * struct name_info - name sequence publication info
53   - * @node_list: circular list of publications made by own node
54   - * @cluster_list: circular list of publications made by own cluster
55   - * @zone_list: circular list of publications made by own zone
56   - * @node_list_size: number of entries in "node_list"
57   - * @cluster_list_size: number of entries in "cluster_list"
58   - * @zone_list_size: number of entries in "zone_list"
59   - *
60   - * Note: The zone list always contains at least one entry, since all
61   - * publications of the associated name sequence belong to it.
62   - * (The cluster and node lists may be empty.)
  53 + * @node_list: list of publications on own node of this <type,lower,upper>
  54 + * @all_publ: list of all publications of this <type,lower,upper>
63 55 */
64 56 struct name_info {
65   - struct list_head node_list;
66   - struct list_head cluster_list;
67   - struct list_head zone_list;
68   - u32 node_list_size;
69   - u32 cluster_list_size;
70   - u32 zone_list_size;
  57 + struct list_head local_publ;
  58 + struct list_head all_publ;
71 59 };
72 60  
73 61 /**
... ... @@ -114,7 +102,7 @@
114 102 * publ_create - create a publication structure
115 103 */
116 104 static struct publication *publ_create(u32 type, u32 lower, u32 upper,
117   - u32 scope, u32 node, u32 port_ref,
  105 + u32 scope, u32 node, u32 port,
118 106 u32 key)
119 107 {
120 108 struct publication *publ = kzalloc(sizeof(*publ), GFP_ATOMIC);
121 109  
... ... @@ -128,9 +116,9 @@
128 116 publ->upper = upper;
129 117 publ->scope = scope;
130 118 publ->node = node;
131   - publ->ref = port_ref;
  119 + publ->port = port;
132 120 publ->key = key;
133   - INIT_LIST_HEAD(&publ->pport_list);
  121 + INIT_LIST_HEAD(&publ->binding_sock);
134 122 return publ;
135 123 }
136 124  
... ... @@ -249,9 +237,9 @@
249 237 info = sseq->info;
250 238  
251 239 /* Check if an identical publication already exists */
252   - list_for_each_entry(publ, &info->zone_list, zone_list) {
253   - if ((publ->ref == port) && (publ->key == key) &&
254   - (!publ->node || (publ->node == node)))
  240 + list_for_each_entry(publ, &info->all_publ, all_publ) {
  241 + if (publ->port == port && publ->key == key &&
  242 + (!publ->node || publ->node == node))
255 243 return NULL;
256 244 }
257 245 } else {
... ... @@ -290,9 +278,8 @@
290 278 return NULL;
291 279 }
292 280  
293   - INIT_LIST_HEAD(&info->node_list);
294   - INIT_LIST_HEAD(&info->cluster_list);
295   - INIT_LIST_HEAD(&info->zone_list);
  281 + INIT_LIST_HEAD(&info->local_publ);
  282 + INIT_LIST_HEAD(&info->all_publ);
296 283  
297 284 /* Insert new sub-sequence */
298 285 sseq = &nseq->sseqs[inspos];
299 286  
300 287  
301 288  
... ... @@ -311,23 +298,15 @@
311 298 if (!publ)
312 299 return NULL;
313 300  
314   - list_add(&publ->zone_list, &info->zone_list);
315   - info->zone_list_size++;
  301 + list_add(&publ->all_publ, &info->all_publ);
316 302  
317   - if (in_own_cluster(net, node)) {
318   - list_add(&publ->cluster_list, &info->cluster_list);
319   - info->cluster_list_size++;
320   - }
  303 + if (in_own_node(net, node))
  304 + list_add(&publ->local_publ, &info->local_publ);
321 305  
322   - if (in_own_node(net, node)) {
323   - list_add(&publ->node_list, &info->node_list);
324   - info->node_list_size++;
325   - }
326   -
327 306 /* Any subscriptions waiting for notification? */
328 307 list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) {
329 308 tipc_sub_report_overlap(s, publ->lower, publ->upper,
330   - TIPC_PUBLISHED, publ->ref,
  309 + TIPC_PUBLISHED, publ->port,
331 310 publ->node, publ->scope,
332 311 created_subseq);
333 312 }
... ... @@ -348,7 +327,7 @@
348 327 static struct publication *tipc_nameseq_remove_publ(struct net *net,
349 328 struct name_seq *nseq,
350 329 u32 inst, u32 node,
351   - u32 ref, u32 key)
  330 + u32 port, u32 key)
352 331 {
353 332 struct publication *publ;
354 333 struct sub_seq *sseq = nameseq_find_subseq(nseq, inst);
355 334  
356 335  
357 336  
... ... @@ -363,32 +342,20 @@
363 342 info = sseq->info;
364 343  
365 344 /* Locate publication, if it exists */
366   - list_for_each_entry(publ, &info->zone_list, zone_list) {
367   - if ((publ->key == key) && (publ->ref == ref) &&
368   - (!publ->node || (publ->node == node)))
  345 + list_for_each_entry(publ, &info->all_publ, all_publ) {
  346 + if (publ->key == key && publ->port == port &&
  347 + (!publ->node || publ->node == node))
369 348 goto found;
370 349 }
371 350 return NULL;
372 351  
373 352 found:
374   - /* Remove publication from zone scope list */
375   - list_del(&publ->zone_list);
376   - info->zone_list_size--;
  353 + list_del(&publ->all_publ);
  354 + if (in_own_node(net, node))
  355 + list_del(&publ->local_publ);
377 356  
378   - /* Remove publication from cluster scope list, if present */
379   - if (in_own_cluster(net, node)) {
380   - list_del(&publ->cluster_list);
381   - info->cluster_list_size--;
382   - }
383   -
384   - /* Remove publication from node scope list, if present */
385   - if (in_own_node(net, node)) {
386   - list_del(&publ->node_list);
387   - info->node_list_size--;
388   - }
389   -
390 357 /* Contract subseq list if no more publications for that subseq */
391   - if (list_empty(&info->zone_list)) {
  358 + if (list_empty(&info->all_publ)) {
392 359 kfree(info);
393 360 free = &nseq->sseqs[nseq->first_free--];
394 361 memmove(sseq, sseq + 1, (free - (sseq + 1)) * sizeof(*sseq));
... ... @@ -398,8 +365,9 @@
398 365 /* Notify any waiting subscriptions */
399 366 list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) {
400 367 tipc_sub_report_overlap(s, publ->lower, publ->upper,
401   - TIPC_WITHDRAWN, publ->ref, publ->node,
402   - publ->scope, removed_subseq);
  368 + TIPC_WITHDRAWN, publ->port,
  369 + publ->node, publ->scope,
  370 + removed_subseq);
403 371 }
404 372  
405 373 return publ;
406 374  
... ... @@ -435,11 +403,12 @@
435 403 struct name_info *info = sseq->info;
436 404 int must_report = 1;
437 405  
438   - list_for_each_entry(crs, &info->zone_list, zone_list) {
  406 + list_for_each_entry(crs, &info->all_publ, all_publ) {
439 407 tipc_sub_report_overlap(sub, sseq->lower,
440 408 sseq->upper,
441 409 TIPC_PUBLISHED,
442   - crs->ref, crs->node,
  410 + crs->port,
  411 + crs->node,
443 412 crs->scope,
444 413 must_report);
445 414 must_report = 0;
... ... @@ -473,8 +442,7 @@
473 442 struct name_seq *seq = nametbl_find_seq(net, type);
474 443 int index = hash(type);
475 444  
476   - if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE) ||
477   - (lower > upper)) {
  445 + if (scope > TIPC_NODE_SCOPE || lower > upper) {
478 446 pr_debug("Failed to publish illegal {%u,%u,%u} with scope %u\n",
479 447 type, lower, upper, scope);
480 448 return NULL;
... ... @@ -493,7 +461,7 @@
493 461 }
494 462  
495 463 struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type,
496   - u32 lower, u32 node, u32 ref,
  464 + u32 lower, u32 node, u32 port,
497 465 u32 key)
498 466 {
499 467 struct publication *publ;
... ... @@ -503,7 +471,7 @@
503 471 return NULL;
504 472  
505 473 spin_lock_bh(&seq->lock);
506   - publ = tipc_nameseq_remove_publ(net, seq, lower, node, ref, key);
  474 + publ = tipc_nameseq_remove_publ(net, seq, lower, node, port, key);
507 475 if (!seq->first_free && list_empty(&seq->subscriptions)) {
508 476 hlist_del_init_rcu(&seq->ns_list);
509 477 kfree(seq->sseqs);
... ... @@ -536,7 +504,7 @@
536 504 struct name_info *info;
537 505 struct publication *publ;
538 506 struct name_seq *seq;
539   - u32 ref = 0;
  507 + u32 port = 0;
540 508 u32 node = 0;
541 509  
542 510 if (!tipc_in_scope(*destnode, tn->own_addr))
543 511  
544 512  
545 513  
546 514  
547 515  
548 516  
549 517  
550 518  
... ... @@ -554,54 +522,42 @@
554 522  
555 523 /* Closest-First Algorithm */
556 524 if (likely(!*destnode)) {
557   - if (!list_empty(&info->node_list)) {
558   - publ = list_first_entry(&info->node_list,
  525 + if (!list_empty(&info->local_publ)) {
  526 + publ = list_first_entry(&info->local_publ,
559 527 struct publication,
560   - node_list);
561   - list_move_tail(&publ->node_list,
562   - &info->node_list);
563   - } else if (!list_empty(&info->cluster_list)) {
564   - publ = list_first_entry(&info->cluster_list,
565   - struct publication,
566   - cluster_list);
567   - list_move_tail(&publ->cluster_list,
568   - &info->cluster_list);
  528 + local_publ);
  529 + list_move_tail(&publ->local_publ,
  530 + &info->local_publ);
569 531 } else {
570   - publ = list_first_entry(&info->zone_list,
  532 + publ = list_first_entry(&info->all_publ,
571 533 struct publication,
572   - zone_list);
573   - list_move_tail(&publ->zone_list,
574   - &info->zone_list);
  534 + all_publ);
  535 + list_move_tail(&publ->all_publ,
  536 + &info->all_publ);
575 537 }
576 538 }
577 539  
578 540 /* Round-Robin Algorithm */
579 541 else if (*destnode == tn->own_addr) {
580   - if (list_empty(&info->node_list))
  542 + if (list_empty(&info->local_publ))
581 543 goto no_match;
582   - publ = list_first_entry(&info->node_list, struct publication,
583   - node_list);
584   - list_move_tail(&publ->node_list, &info->node_list);
585   - } else if (in_own_cluster_exact(net, *destnode)) {
586   - if (list_empty(&info->cluster_list))
587   - goto no_match;
588   - publ = list_first_entry(&info->cluster_list, struct publication,
589   - cluster_list);
590   - list_move_tail(&publ->cluster_list, &info->cluster_list);
  544 + publ = list_first_entry(&info->local_publ, struct publication,
  545 + local_publ);
  546 + list_move_tail(&publ->local_publ, &info->local_publ);
591 547 } else {
592   - publ = list_first_entry(&info->zone_list, struct publication,
593   - zone_list);
594   - list_move_tail(&publ->zone_list, &info->zone_list);
  548 + publ = list_first_entry(&info->all_publ, struct publication,
  549 + all_publ);
  550 + list_move_tail(&publ->all_publ, &info->all_publ);
595 551 }
596 552  
597   - ref = publ->ref;
  553 + port = publ->port;
598 554 node = publ->node;
599 555 no_match:
600 556 spin_unlock_bh(&seq->lock);
601 557 not_found:
602 558 rcu_read_unlock();
603 559 *destnode = node;
604   - return ref;
  560 + return port;
605 561 }
606 562  
607 563 bool tipc_nametbl_lookup(struct net *net, u32 type, u32 instance, u32 scope,
608 564  
609 565  
610 566  
... ... @@ -623,16 +579,16 @@
623 579 sseq = nameseq_find_subseq(seq, instance);
624 580 if (likely(sseq)) {
625 581 info = sseq->info;
626   - list_for_each_entry(publ, &info->zone_list, zone_list) {
  582 + list_for_each_entry(publ, &info->all_publ, all_publ) {
627 583 if (publ->scope != scope)
628 584 continue;
629   - if (publ->ref == exclude && publ->node == self)
  585 + if (publ->port == exclude && publ->node == self)
630 586 continue;
631   - tipc_dest_push(dsts, publ->node, publ->ref);
  587 + tipc_dest_push(dsts, publ->node, publ->port);
632 588 (*dstcnt)++;
633 589 if (all)
634 590 continue;
635   - list_move_tail(&publ->zone_list, &info->zone_list);
  591 + list_move_tail(&publ->all_publ, &info->all_publ);
636 592 break;
637 593 }
638 594 }
639 595  
... ... @@ -642,15 +598,14 @@
642 598 return !list_empty(dsts);
643 599 }
644 600  
645   -int tipc_nametbl_mc_lookup(struct net *net, u32 type, u32 lower, u32 upper,
646   - u32 scope, bool exact, struct list_head *dports)
  601 +void tipc_nametbl_mc_lookup(struct net *net, u32 type, u32 lower, u32 upper,
  602 + u32 scope, bool exact, struct list_head *dports)
647 603 {
648 604 struct sub_seq *sseq_stop;
649 605 struct name_info *info;
650 606 struct publication *p;
651 607 struct name_seq *seq;
652 608 struct sub_seq *sseq;
653   - int res = 0;
654 609  
655 610 rcu_read_lock();
656 611 seq = nametbl_find_seq(net, type);
657 612  
658 613  
659 614  
... ... @@ -664,18 +619,14 @@
664 619 if (sseq->lower > upper)
665 620 break;
666 621 info = sseq->info;
667   - list_for_each_entry(p, &info->node_list, node_list) {
  622 + list_for_each_entry(p, &info->local_publ, local_publ) {
668 623 if (p->scope == scope || (!exact && p->scope < scope))
669   - tipc_dest_push(dports, 0, p->ref);
  624 + tipc_dest_push(dports, 0, p->port);
670 625 }
671   -
672   - if (info->cluster_list_size != info->node_list_size)
673   - res = 1;
674 626 }
675 627 spin_unlock_bh(&seq->lock);
676 628 exit:
677 629 rcu_read_unlock();
678   - return res;
679 630 }
680 631  
681 632 /* tipc_nametbl_lookup_dst_nodes - find broadcast destination nodes
... ... @@ -700,7 +651,7 @@
700 651 stop = seq->sseqs + seq->first_free;
701 652 for (; sseq != stop && sseq->lower <= upper; sseq++) {
702 653 info = sseq->info;
703   - list_for_each_entry(publ, &info->zone_list, zone_list) {
  654 + list_for_each_entry(publ, &info->all_publ, all_publ) {
704 655 tipc_nlist_add(nodes, publ->node);
705 656 }
706 657 }
707 658  
... ... @@ -729,10 +680,10 @@
729 680 stop = seq->sseqs + seq->first_free;
730 681 for (; sseq != stop; sseq++) {
731 682 info = sseq->info;
732   - list_for_each_entry(p, &info->zone_list, zone_list) {
  683 + list_for_each_entry(p, &info->all_publ, all_publ) {
733 684 if (p->scope != scope)
734 685 continue;
735   - tipc_group_add_member(grp, p->node, p->ref, p->lower);
  686 + tipc_group_add_member(grp, p->node, p->port, p->lower);
736 687 }
737 688 }
738 689 spin_unlock_bh(&seq->lock);
... ... @@ -777,7 +728,7 @@
777 728 /**
778 729 * tipc_nametbl_withdraw - withdraw name publication from network name tables
779 730 */
780   -int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 ref,
  731 +int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 port,
781 732 u32 key)
782 733 {
783 734 struct publication *publ;
784 735  
785 736  
... ... @@ -786,18 +737,18 @@
786 737  
787 738 spin_lock_bh(&tn->nametbl_lock);
788 739 publ = tipc_nametbl_remove_publ(net, type, lower, tn->own_addr,
789   - ref, key);
  740 + port, key);
790 741 if (likely(publ)) {
791 742 tn->nametbl->local_publ_count--;
792 743 skb = tipc_named_withdraw(net, publ);
793 744 /* Any pending external events? */
794 745 tipc_named_process_backlog(net);
795   - list_del_init(&publ->pport_list);
  746 + list_del_init(&publ->binding_sock);
796 747 kfree_rcu(publ, rcu);
797 748 } else {
798 749 pr_err("Unable to remove local publication\n"
799   - "(type=%u, lower=%u, ref=%u, key=%u)\n",
800   - type, lower, ref, key);
  750 + "(type=%u, lower=%u, port=%u, key=%u)\n",
  751 + type, lower, port, key);
801 752 }
802 753 spin_unlock_bh(&tn->nametbl_lock);
803 754  
... ... @@ -879,9 +830,8 @@
879 830 for (i = 0; i < TIPC_NAMETBL_SIZE; i++)
880 831 INIT_HLIST_HEAD(&tipc_nametbl->seq_hlist[i]);
881 832  
882   - INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]);
883   - INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]);
884   - INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_NODE_SCOPE]);
  833 + INIT_LIST_HEAD(&tipc_nametbl->node_scope);
  834 + INIT_LIST_HEAD(&tipc_nametbl->cluster_scope);
885 835 tn->nametbl = tipc_nametbl;
886 836 spin_lock_init(&tn->nametbl_lock);
887 837 return 0;
888 838  
... ... @@ -901,9 +851,9 @@
901 851 spin_lock_bh(&seq->lock);
902 852 sseq = seq->sseqs;
903 853 info = sseq->info;
904   - list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) {
  854 + list_for_each_entry_safe(publ, safe, &info->all_publ, all_publ) {
905 855 tipc_nameseq_remove_publ(net, seq, publ->lower, publ->node,
906   - publ->ref, publ->key);
  856 + publ->port, publ->key);
907 857 kfree_rcu(publ, rcu);
908 858 }
909 859 hlist_del_init_rcu(&seq->ns_list);
910 860  
911 861  
... ... @@ -950,17 +900,17 @@
950 900 struct publication *p;
951 901  
952 902 if (*last_publ) {
953   - list_for_each_entry(p, &sseq->info->zone_list, zone_list)
  903 + list_for_each_entry(p, &sseq->info->all_publ, all_publ)
954 904 if (p->key == *last_publ)
955 905 break;
956 906 if (p->key != *last_publ)
957 907 return -EPIPE;
958 908 } else {
959   - p = list_first_entry(&sseq->info->zone_list, struct publication,
960   - zone_list);
  909 + p = list_first_entry(&sseq->info->all_publ, struct publication,
  910 + all_publ);
961 911 }
962 912  
963   - list_for_each_entry_from(p, &sseq->info->zone_list, zone_list) {
  913 + list_for_each_entry_from(p, &sseq->info->all_publ, all_publ) {
964 914 *last_publ = p->key;
965 915  
966 916 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq,
... ... @@ -987,7 +937,7 @@
987 937 goto publ_msg_full;
988 938 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_NODE, p->node))
989 939 goto publ_msg_full;
990   - if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_REF, p->ref))
  940 + if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_REF, p->port))
991 941 goto publ_msg_full;
992 942 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_KEY, p->key))
993 943 goto publ_msg_full;
net/tipc/name_table.h
1 1 /*
2 2 * net/tipc/name_table.h: Include file for TIPC name table code
3 3 *
4   - * Copyright (c) 2000-2006, 2014-2015, Ericsson AB
  4 + * Copyright (c) 2000-2006, 2014-2018, Ericsson AB
5 5 * Copyright (c) 2004-2005, 2010-2011, Wind River Systems
6 6 * All rights reserved.
7 7 *
8 8  
... ... @@ -54,19 +54,22 @@
54 54 * @type: name sequence type
55 55 * @lower: name sequence lower bound
56 56 * @upper: name sequence upper bound
57   - * @scope: scope of publication
58   - * @node: network address of publishing port's node
59   - * @ref: publishing port
60   - * @key: publication key
61   - * @nodesub_list: subscription to "node down" event (off-node publication only)
62   - * @local_list: adjacent entries in list of publications made by this node
63   - * @pport_list: adjacent entries in list of publications made by this port
64   - * @node_list: adjacent matching name seq publications with >= node scope
65   - * @cluster_list: adjacent matching name seq publications with >= cluster scope
66   - * @zone_list: adjacent matching name seq publications with >= zone scope
  57 + * @scope: scope of publication, TIPC_NODE_SCOPE or TIPC_CLUSTER_SCOPE
  58 + * @node: network address of publishing socket's node
  59 + * @port: publishing port
  60 + * @key: publication key, unique across the cluster
  61 + * @binding_node: all publications from the same node which bound this one
  62 + * - Remote publications: in node->publ_list
  63 + * Used by node/name distr to withdraw publications when node is lost
  64 + * - Local/node scope publications: in name_table->node_scope list
  65 + * - Local/cluster scope publications: in name_table->cluster_scope list
  66 + * @binding_sock: all publications from the same socket which bound this one
  67 + * Used by socket to withdraw publications when socket is unbound/released
  68 + * @local_publ: list of identical publications made from this node
  69 + * Used by closest_first and multicast receive lookup algorithms
  70 + * @all_publ: all publications identical to this one, whatever node and scope
  71 + * Used by round-robin lookup algorithm
67 72 * @rcu: RCU callback head used for deferred freeing
68   - *
69   - * Note that the node list, cluster list, and zone list are circular lists.
70 73 */
71 74 struct publication {
72 75 u32 type;
73 76  
74 77  
75 78  
76 79  
... ... @@ -74,34 +77,37 @@
74 77 u32 upper;
75 78 u32 scope;
76 79 u32 node;
77   - u32 ref;
  80 + u32 port;
78 81 u32 key;
79   - struct list_head nodesub_list;
80   - struct list_head local_list;
81   - struct list_head pport_list;
82   - struct list_head node_list;
83   - struct list_head cluster_list;
84   - struct list_head zone_list;
  82 + struct list_head binding_node;
  83 + struct list_head binding_sock;
  84 + struct list_head local_publ;
  85 + struct list_head all_publ;
85 86 struct rcu_head rcu;
86 87 };
87 88  
88 89 /**
89 90 * struct name_table - table containing all existing port name publications
90 91 * @seq_hlist: name sequence hash lists
91   - * @publ_list: pulication lists
  92 + * @node_scope: all local publications with node scope
  93 + * - used by name_distr during re-init of name table
  94 + * @cluster_scope: all local publications with cluster scope
  95 + * - used by name_distr to send bulk updates to new nodes
  96 + * - used by name_distr during re-init of name table
92 97 * @local_publ_count: number of publications issued by this node
93 98 */
94 99 struct name_table {
95 100 struct hlist_head seq_hlist[TIPC_NAMETBL_SIZE];
96   - struct list_head publ_list[TIPC_PUBL_SCOPE_NUM];
  101 + struct list_head node_scope;
  102 + struct list_head cluster_scope;
97 103 u32 local_publ_count;
98 104 };
99 105  
100 106 int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb);
101 107  
102 108 u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, u32 *node);
103   -int tipc_nametbl_mc_lookup(struct net *net, u32 type, u32 lower, u32 upper,
104   - u32 scope, bool exact, struct list_head *dports);
  109 +void tipc_nametbl_mc_lookup(struct net *net, u32 type, u32 lower, u32 upper,
  110 + u32 scope, bool exact, struct list_head *dports);
105 111 void tipc_nametbl_build_group(struct net *net, struct tipc_group *grp,
106 112 u32 type, u32 domain);
107 113 void tipc_nametbl_lookup_dst_nodes(struct net *net, u32 type, u32 lower,
... ... @@ -118,7 +118,7 @@
118 118 tipc_sk_reinit(net);
119 119  
120 120 tipc_nametbl_publish(net, TIPC_CFG_SRV, tn->own_addr, tn->own_addr,
121   - TIPC_ZONE_SCOPE, 0, tn->own_addr);
  121 + TIPC_CLUSTER_SCOPE, 0, tn->own_addr);
122 122  
123 123 pr_info("Started in network mode\n");
124 124 pr_info("Own node address %s, network identity %u\n",
... ... @@ -644,7 +644,7 @@
644 644 goto exit;
645 645 }
646 646  
647   - res = (addr->scope > 0) ?
  647 + res = (addr->scope >= 0) ?
648 648 tipc_sk_publish(tsk, addr->scope, &addr->addr.nameseq) :
649 649 tipc_sk_withdraw(tsk, -addr->scope, &addr->addr.nameseq);
650 650 exit:
651 651  
... ... @@ -1280,8 +1280,8 @@
1280 1280 struct tipc_msg *hdr = &tsk->phdr;
1281 1281 struct tipc_name_seq *seq;
1282 1282 struct sk_buff_head pkts;
1283   - u32 type, inst, domain;
1284 1283 u32 dnode, dport;
  1284 + u32 type, inst;
1285 1285 int mtu, rc;
1286 1286  
1287 1287 if (unlikely(dlen > TIPC_MAX_USER_MSG_SIZE))
1288 1288  
... ... @@ -1332,13 +1332,12 @@
1332 1332 if (dest->addrtype == TIPC_ADDR_NAME) {
1333 1333 type = dest->addr.name.name.type;
1334 1334 inst = dest->addr.name.name.instance;
1335   - domain = dest->addr.name.domain;
1336   - dnode = domain;
  1335 + dnode = dest->addr.name.domain;
1337 1336 msg_set_type(hdr, TIPC_NAMED_MSG);
1338 1337 msg_set_hdr_sz(hdr, NAMED_H_SIZE);
1339 1338 msg_set_nametype(hdr, type);
1340 1339 msg_set_nameinst(hdr, inst);
1341   - msg_set_lookup_scope(hdr, tipc_addr_scope(domain));
  1340 + msg_set_lookup_scope(hdr, tipc_node2scope(dnode));
1342 1341 dport = tipc_nametbl_translate(net, type, inst, &dnode);
1343 1342 msg_set_destnode(hdr, dnode);
1344 1343 msg_set_destport(hdr, dport);
... ... @@ -2592,6 +2591,9 @@
2592 2591 struct publication *publ;
2593 2592 u32 key;
2594 2593  
  2594 + if (scope != TIPC_NODE_SCOPE)
  2595 + scope = TIPC_CLUSTER_SCOPE;
  2596 +
2595 2597 if (tipc_sk_connected(sk))
2596 2598 return -EINVAL;
2597 2599 key = tsk->portid + tsk->pub_count + 1;
... ... @@ -2603,7 +2605,7 @@
2603 2605 if (unlikely(!publ))
2604 2606 return -EINVAL;
2605 2607  
2606   - list_add(&publ->pport_list, &tsk->publications);
  2608 + list_add(&publ->binding_sock, &tsk->publications);
2607 2609 tsk->pub_count++;
2608 2610 tsk->published = 1;
2609 2611 return 0;
... ... @@ -2617,7 +2619,10 @@
2617 2619 struct publication *safe;
2618 2620 int rc = -EINVAL;
2619 2621  
2620   - list_for_each_entry_safe(publ, safe, &tsk->publications, pport_list) {
  2622 + if (scope != TIPC_NODE_SCOPE)
  2623 + scope = TIPC_CLUSTER_SCOPE;
  2624 +
  2625 + list_for_each_entry_safe(publ, safe, &tsk->publications, binding_sock) {
2621 2626 if (seq) {
2622 2627 if (publ->scope != scope)
2623 2628 continue;
2624 2629  
... ... @@ -2628,12 +2633,12 @@
2628 2633 if (publ->upper != seq->upper)
2629 2634 break;
2630 2635 tipc_nametbl_withdraw(net, publ->type, publ->lower,
2631   - publ->ref, publ->key);
  2636 + publ->port, publ->key);
2632 2637 rc = 0;
2633 2638 break;
2634 2639 }
2635 2640 tipc_nametbl_withdraw(net, publ->type, publ->lower,
2636   - publ->ref, publ->key);
  2641 + publ->port, publ->key);
2637 2642 rc = 0;
2638 2643 }
2639 2644 if (list_empty(&tsk->publications))
... ... @@ -3287,7 +3292,7 @@
3287 3292 struct publication *p;
3288 3293  
3289 3294 if (*last_publ) {
3290   - list_for_each_entry(p, &tsk->publications, pport_list) {
  3295 + list_for_each_entry(p, &tsk->publications, binding_sock) {
3291 3296 if (p->key == *last_publ)
3292 3297 break;
3293 3298 }
3294 3299  
... ... @@ -3304,10 +3309,10 @@
3304 3309 }
3305 3310 } else {
3306 3311 p = list_first_entry(&tsk->publications, struct publication,
3307   - pport_list);
  3312 + binding_sock);
3308 3313 }
3309 3314  
3310   - list_for_each_entry_from(p, &tsk->publications, pport_list) {
  3315 + list_for_each_entry_from(p, &tsk->publications, binding_sock) {
3311 3316 err = __tipc_nl_add_sk_publ(skb, cb, p);
3312 3317 if (err) {
3313 3318 *last_publ = p->key;