hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/tipc/net.c
....@@ -41,6 +41,7 @@
4141 #include "socket.h"
4242 #include "node.h"
4343 #include "bcast.h"
44
+#include "link.h"
4445 #include "netlink.h"
4546 #include "monitor.h"
4647
....@@ -105,12 +106,6 @@
105106 * - A local spin_lock protecting the queue of subscriber events.
106107 */
107108
108
-struct tipc_net_work {
109
- struct work_struct work;
110
- struct net *net;
111
- u32 addr;
112
-};
113
-
114109 static void tipc_net_finalize(struct net *net, u32 addr);
115110
116111 int tipc_net_init(struct net *net, u8 *node_id, u32 addr)
....@@ -142,25 +137,11 @@
142137 TIPC_CLUSTER_SCOPE, 0, addr);
143138 }
144139
145
-static void tipc_net_finalize_work(struct work_struct *work)
140
+void tipc_net_finalize_work(struct work_struct *work)
146141 {
147
- struct tipc_net_work *fwork;
142
+ struct tipc_net *tn = container_of(work, struct tipc_net, work);
148143
149
- fwork = container_of(work, struct tipc_net_work, work);
150
- tipc_net_finalize(fwork->net, fwork->addr);
151
- kfree(fwork);
152
-}
153
-
154
-void tipc_sched_net_finalize(struct net *net, u32 addr)
155
-{
156
- struct tipc_net_work *fwork = kzalloc(sizeof(*fwork), GFP_ATOMIC);
157
-
158
- if (!fwork)
159
- return;
160
- INIT_WORK(&fwork->work, tipc_net_finalize_work);
161
- fwork->net = net;
162
- fwork->addr = addr;
163
- schedule_work(&fwork->work);
144
+ tipc_net_finalize(tipc_link_net(tn->bcl), tn->trial_addr);
164145 }
165146
166147 void tipc_net_stop(struct net *net)
....@@ -189,7 +170,7 @@
189170 if (!hdr)
190171 return -EMSGSIZE;
191172
192
- attrs = nla_nest_start(msg->skb, TIPC_NLA_NET);
173
+ attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_NET);
193174 if (!attrs)
194175 goto msg_full;
195176
....@@ -247,9 +228,9 @@
247228 if (!info->attrs[TIPC_NLA_NET])
248229 return -EINVAL;
249230
250
- err = nla_parse_nested(attrs, TIPC_NLA_NET_MAX,
251
- info->attrs[TIPC_NLA_NET], tipc_nl_net_policy,
252
- info->extack);
231
+ err = nla_parse_nested_deprecated(attrs, TIPC_NLA_NET_MAX,
232
+ info->attrs[TIPC_NLA_NET],
233
+ tipc_nl_net_policy, info->extack);
253234
254235 if (err)
255236 return err;
....@@ -302,3 +283,59 @@
302283
303284 return err;
304285 }
286
+
287
+static int __tipc_nl_addr_legacy_get(struct net *net, struct tipc_nl_msg *msg)
288
+{
289
+ struct tipc_net *tn = tipc_net(net);
290
+ struct nlattr *attrs;
291
+ void *hdr;
292
+
293
+ hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
294
+ 0, TIPC_NL_ADDR_LEGACY_GET);
295
+ if (!hdr)
296
+ return -EMSGSIZE;
297
+
298
+ attrs = nla_nest_start(msg->skb, TIPC_NLA_NET);
299
+ if (!attrs)
300
+ goto msg_full;
301
+
302
+ if (tn->legacy_addr_format)
303
+ if (nla_put_flag(msg->skb, TIPC_NLA_NET_ADDR_LEGACY))
304
+ goto attr_msg_full;
305
+
306
+ nla_nest_end(msg->skb, attrs);
307
+ genlmsg_end(msg->skb, hdr);
308
+
309
+ return 0;
310
+
311
+attr_msg_full:
312
+ nla_nest_cancel(msg->skb, attrs);
313
+msg_full:
314
+ genlmsg_cancel(msg->skb, hdr);
315
+
316
+ return -EMSGSIZE;
317
+}
318
+
319
+int tipc_nl_net_addr_legacy_get(struct sk_buff *skb, struct genl_info *info)
320
+{
321
+ struct net *net = sock_net(skb->sk);
322
+ struct tipc_nl_msg msg;
323
+ struct sk_buff *rep;
324
+ int err;
325
+
326
+ rep = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
327
+ if (!rep)
328
+ return -ENOMEM;
329
+
330
+ msg.skb = rep;
331
+ msg.portid = info->snd_portid;
332
+ msg.seq = info->snd_seq;
333
+
334
+ err = __tipc_nl_addr_legacy_get(net, &msg);
335
+ if (err) {
336
+ nlmsg_free(msg.skb);
337
+ return err;
338
+ }
339
+
340
+ return genlmsg_reply(msg.skb, info);
341
+}