GNU Linux-libre 5.10.153-gnu1
[releases.git] / net / tipc / bearer.c
1 /*
2  * net/tipc/bearer.c: TIPC bearer code
3  *
4  * Copyright (c) 1996-2006, 2013-2016, Ericsson AB
5  * Copyright (c) 2004-2006, 2010-2013, Wind River Systems
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the names of the copyright holders nor the names of its
17  *    contributors may be used to endorse or promote products derived from
18  *    this software without specific prior written permission.
19  *
20  * Alternatively, this software may be distributed under the terms of the
21  * GNU General Public License ("GPL") version 2 as published by the Free
22  * Software Foundation.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36
37 #include <net/sock.h>
38 #include "core.h"
39 #include "bearer.h"
40 #include "link.h"
41 #include "discover.h"
42 #include "monitor.h"
43 #include "bcast.h"
44 #include "netlink.h"
45 #include "udp_media.h"
46 #include "trace.h"
47 #include "crypto.h"
48
49 #define MAX_ADDR_STR 60
50
51 static struct tipc_media * const media_info_array[] = {
52         &eth_media_info,
53 #ifdef CONFIG_TIPC_MEDIA_IB
54         &ib_media_info,
55 #endif
56 #ifdef CONFIG_TIPC_MEDIA_UDP
57         &udp_media_info,
58 #endif
59         NULL
60 };
61
62 static struct tipc_bearer *bearer_get(struct net *net, int bearer_id)
63 {
64         struct tipc_net *tn = tipc_net(net);
65
66         return rcu_dereference(tn->bearer_list[bearer_id]);
67 }
68
69 static void bearer_disable(struct net *net, struct tipc_bearer *b);
70 static int tipc_l2_rcv_msg(struct sk_buff *skb, struct net_device *dev,
71                            struct packet_type *pt, struct net_device *orig_dev);
72
73 /**
74  * tipc_media_find - locates specified media object by name
75  */
76 struct tipc_media *tipc_media_find(const char *name)
77 {
78         u32 i;
79
80         for (i = 0; media_info_array[i] != NULL; i++) {
81                 if (!strcmp(media_info_array[i]->name, name))
82                         break;
83         }
84         return media_info_array[i];
85 }
86
87 /**
88  * media_find_id - locates specified media object by type identifier
89  */
90 static struct tipc_media *media_find_id(u8 type)
91 {
92         u32 i;
93
94         for (i = 0; media_info_array[i] != NULL; i++) {
95                 if (media_info_array[i]->type_id == type)
96                         break;
97         }
98         return media_info_array[i];
99 }
100
101 /**
102  * tipc_media_addr_printf - record media address in print buffer
103  */
104 int tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a)
105 {
106         char addr_str[MAX_ADDR_STR];
107         struct tipc_media *m;
108         int ret;
109
110         m = media_find_id(a->media_id);
111
112         if (m && !m->addr2str(a, addr_str, sizeof(addr_str)))
113                 ret = scnprintf(buf, len, "%s(%s)", m->name, addr_str);
114         else {
115                 u32 i;
116
117                 ret = scnprintf(buf, len, "UNKNOWN(%u)", a->media_id);
118                 for (i = 0; i < sizeof(a->value); i++)
119                         ret += scnprintf(buf + ret, len - ret,
120                                             "-%x", a->value[i]);
121         }
122         return ret;
123 }
124
125 /**
126  * bearer_name_validate - validate & (optionally) deconstruct bearer name
127  * @name: ptr to bearer name string
128  * @name_parts: ptr to area for bearer name components (or NULL if not needed)
129  *
130  * Returns 1 if bearer name is valid, otherwise 0.
131  */
132 static int bearer_name_validate(const char *name,
133                                 struct tipc_bearer_names *name_parts)
134 {
135         char name_copy[TIPC_MAX_BEARER_NAME];
136         char *media_name;
137         char *if_name;
138         u32 media_len;
139         u32 if_len;
140
141         /* copy bearer name & ensure length is OK */
142         name_copy[TIPC_MAX_BEARER_NAME - 1] = 0;
143         /* need above in case non-Posix strncpy() doesn't pad with nulls */
144         strncpy(name_copy, name, TIPC_MAX_BEARER_NAME);
145         if (name_copy[TIPC_MAX_BEARER_NAME - 1] != 0)
146                 return 0;
147
148         /* ensure all component parts of bearer name are present */
149         media_name = name_copy;
150         if_name = strchr(media_name, ':');
151         if (if_name == NULL)
152                 return 0;
153         *(if_name++) = 0;
154         media_len = if_name - media_name;
155         if_len = strlen(if_name) + 1;
156
157         /* validate component parts of bearer name */
158         if ((media_len <= 1) || (media_len > TIPC_MAX_MEDIA_NAME) ||
159             (if_len <= 1) || (if_len > TIPC_MAX_IF_NAME))
160                 return 0;
161
162         /* return bearer name components, if necessary */
163         if (name_parts) {
164                 strcpy(name_parts->media_name, media_name);
165                 strcpy(name_parts->if_name, if_name);
166         }
167         return 1;
168 }
169
170 /**
171  * tipc_bearer_find - locates bearer object with matching bearer name
172  */
173 struct tipc_bearer *tipc_bearer_find(struct net *net, const char *name)
174 {
175         struct tipc_net *tn = net_generic(net, tipc_net_id);
176         struct tipc_bearer *b;
177         u32 i;
178
179         for (i = 0; i < MAX_BEARERS; i++) {
180                 b = rtnl_dereference(tn->bearer_list[i]);
181                 if (b && (!strcmp(b->name, name)))
182                         return b;
183         }
184         return NULL;
185 }
186
187 /*     tipc_bearer_get_name - get the bearer name from its id.
188  *     @net: network namespace
189  *     @name: a pointer to the buffer where the name will be stored.
190  *     @bearer_id: the id to get the name from.
191  */
192 int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id)
193 {
194         struct tipc_net *tn = tipc_net(net);
195         struct tipc_bearer *b;
196
197         if (bearer_id >= MAX_BEARERS)
198                 return -EINVAL;
199
200         b = rtnl_dereference(tn->bearer_list[bearer_id]);
201         if (!b)
202                 return -EINVAL;
203
204         strcpy(name, b->name);
205         return 0;
206 }
207
208 void tipc_bearer_add_dest(struct net *net, u32 bearer_id, u32 dest)
209 {
210         struct tipc_net *tn = net_generic(net, tipc_net_id);
211         struct tipc_bearer *b;
212
213         rcu_read_lock();
214         b = rcu_dereference(tn->bearer_list[bearer_id]);
215         if (b)
216                 tipc_disc_add_dest(b->disc);
217         rcu_read_unlock();
218 }
219
220 void tipc_bearer_remove_dest(struct net *net, u32 bearer_id, u32 dest)
221 {
222         struct tipc_net *tn = net_generic(net, tipc_net_id);
223         struct tipc_bearer *b;
224
225         rcu_read_lock();
226         b = rcu_dereference(tn->bearer_list[bearer_id]);
227         if (b)
228                 tipc_disc_remove_dest(b->disc);
229         rcu_read_unlock();
230 }
231
232 /**
233  * tipc_enable_bearer - enable bearer with the given name
234  */
235 static int tipc_enable_bearer(struct net *net, const char *name,
236                               u32 disc_domain, u32 prio,
237                               struct nlattr *attr[],
238                               struct netlink_ext_ack *extack)
239 {
240         struct tipc_net *tn = tipc_net(net);
241         struct tipc_bearer_names b_names;
242         int with_this_prio = 1;
243         struct tipc_bearer *b;
244         struct tipc_media *m;
245         struct sk_buff *skb;
246         int bearer_id = 0;
247         int res = -EINVAL;
248         char *errstr = "";
249         u32 i;
250
251         if (!bearer_name_validate(name, &b_names)) {
252                 NL_SET_ERR_MSG(extack, "Illegal name");
253                 return res;
254         }
255
256         if (prio > TIPC_MAX_LINK_PRI && prio != TIPC_MEDIA_LINK_PRI) {
257                 errstr = "illegal priority";
258                 NL_SET_ERR_MSG(extack, "Illegal priority");
259                 goto rejected;
260         }
261
262         m = tipc_media_find(b_names.media_name);
263         if (!m) {
264                 errstr = "media not registered";
265                 NL_SET_ERR_MSG(extack, "Media not registered");
266                 goto rejected;
267         }
268
269         if (prio == TIPC_MEDIA_LINK_PRI)
270                 prio = m->priority;
271
272         /* Check new bearer vs existing ones and find free bearer id if any */
273         bearer_id = MAX_BEARERS;
274         i = MAX_BEARERS;
275         while (i-- != 0) {
276                 b = rtnl_dereference(tn->bearer_list[i]);
277                 if (!b) {
278                         bearer_id = i;
279                         continue;
280                 }
281                 if (!strcmp(name, b->name)) {
282                         errstr = "already enabled";
283                         NL_SET_ERR_MSG(extack, "Already enabled");
284                         goto rejected;
285                 }
286
287                 if (b->priority == prio &&
288                     (++with_this_prio > 2)) {
289                         pr_warn("Bearer <%s>: already 2 bearers with priority %u\n",
290                                 name, prio);
291
292                         if (prio == TIPC_MIN_LINK_PRI) {
293                                 errstr = "cannot adjust to lower";
294                                 NL_SET_ERR_MSG(extack, "Cannot adjust to lower");
295                                 goto rejected;
296                         }
297
298                         pr_warn("Bearer <%s>: trying with adjusted priority\n",
299                                 name);
300                         prio--;
301                         bearer_id = MAX_BEARERS;
302                         i = MAX_BEARERS;
303                         with_this_prio = 1;
304                 }
305         }
306
307         if (bearer_id >= MAX_BEARERS) {
308                 errstr = "max 3 bearers permitted";
309                 NL_SET_ERR_MSG(extack, "Max 3 bearers permitted");
310                 goto rejected;
311         }
312
313         b = kzalloc(sizeof(*b), GFP_ATOMIC);
314         if (!b)
315                 return -ENOMEM;
316
317         strcpy(b->name, name);
318         b->media = m;
319         res = m->enable_media(net, b, attr);
320         if (res) {
321                 kfree(b);
322                 errstr = "failed to enable media";
323                 NL_SET_ERR_MSG(extack, "Failed to enable media");
324                 goto rejected;
325         }
326
327         b->identity = bearer_id;
328         b->tolerance = m->tolerance;
329         b->min_win = m->min_win;
330         b->max_win = m->max_win;
331         b->domain = disc_domain;
332         b->net_plane = bearer_id + 'A';
333         b->priority = prio;
334         refcount_set(&b->refcnt, 1);
335
336         res = tipc_disc_create(net, b, &b->bcast_addr, &skb);
337         if (res) {
338                 bearer_disable(net, b);
339                 errstr = "failed to create discoverer";
340                 NL_SET_ERR_MSG(extack, "Failed to create discoverer");
341                 goto rejected;
342         }
343
344         /* Create monitoring data before accepting activate messages */
345         if (tipc_mon_create(net, bearer_id)) {
346                 bearer_disable(net, b);
347                 kfree_skb(skb);
348                 return -ENOMEM;
349         }
350
351         test_and_set_bit_lock(0, &b->up);
352         rcu_assign_pointer(tn->bearer_list[bearer_id], b);
353         if (skb)
354                 tipc_bearer_xmit_skb(net, bearer_id, skb, &b->bcast_addr);
355
356         pr_info("Enabled bearer <%s>, priority %u\n", name, prio);
357
358         return res;
359 rejected:
360         pr_warn("Enabling of bearer <%s> rejected, %s\n", name, errstr);
361         return res;
362 }
363
364 /**
365  * tipc_reset_bearer - Reset all links established over this bearer
366  */
367 static int tipc_reset_bearer(struct net *net, struct tipc_bearer *b)
368 {
369         pr_info("Resetting bearer <%s>\n", b->name);
370         tipc_node_delete_links(net, b->identity);
371         tipc_disc_reset(net, b);
372         return 0;
373 }
374
375 bool tipc_bearer_hold(struct tipc_bearer *b)
376 {
377         return (b && refcount_inc_not_zero(&b->refcnt));
378 }
379
380 void tipc_bearer_put(struct tipc_bearer *b)
381 {
382         if (b && refcount_dec_and_test(&b->refcnt))
383                 kfree_rcu(b, rcu);
384 }
385
386 /**
387  * bearer_disable
388  *
389  * Note: This routine assumes caller holds RTNL lock.
390  */
391 static void bearer_disable(struct net *net, struct tipc_bearer *b)
392 {
393         struct tipc_net *tn = tipc_net(net);
394         int bearer_id = b->identity;
395
396         pr_info("Disabling bearer <%s>\n", b->name);
397         clear_bit_unlock(0, &b->up);
398         tipc_node_delete_links(net, bearer_id);
399         b->media->disable_media(b);
400         RCU_INIT_POINTER(b->media_ptr, NULL);
401         if (b->disc)
402                 tipc_disc_delete(b->disc);
403         RCU_INIT_POINTER(tn->bearer_list[bearer_id], NULL);
404         tipc_bearer_put(b);
405         tipc_mon_delete(net, bearer_id);
406 }
407
408 int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b,
409                          struct nlattr *attr[])
410 {
411         char *dev_name = strchr((const char *)b->name, ':') + 1;
412         int hwaddr_len = b->media->hwaddr_len;
413         u8 node_id[NODE_ID_LEN] = {0,};
414         struct net_device *dev;
415
416         /* Find device with specified name */
417         dev = dev_get_by_name(net, dev_name);
418         if (!dev)
419                 return -ENODEV;
420         if (tipc_mtu_bad(dev, 0)) {
421                 dev_put(dev);
422                 return -EINVAL;
423         }
424         if (dev == net->loopback_dev) {
425                 dev_put(dev);
426                 pr_info("Enabling <%s> not permitted\n", b->name);
427                 return -EINVAL;
428         }
429
430         /* Autoconfigure own node identity if needed */
431         if (!tipc_own_id(net) && hwaddr_len <= NODE_ID_LEN) {
432                 memcpy(node_id, dev->dev_addr, hwaddr_len);
433                 tipc_net_init(net, node_id, 0);
434         }
435         if (!tipc_own_id(net)) {
436                 dev_put(dev);
437                 pr_warn("Failed to obtain node identity\n");
438                 return -EINVAL;
439         }
440
441         /* Associate TIPC bearer with L2 bearer */
442         rcu_assign_pointer(b->media_ptr, dev);
443         b->pt.dev = dev;
444         b->pt.type = htons(ETH_P_TIPC);
445         b->pt.func = tipc_l2_rcv_msg;
446         dev_add_pack(&b->pt);
447         memset(&b->bcast_addr, 0, sizeof(b->bcast_addr));
448         memcpy(b->bcast_addr.value, dev->broadcast, hwaddr_len);
449         b->bcast_addr.media_id = b->media->type_id;
450         b->bcast_addr.broadcast = TIPC_BROADCAST_SUPPORT;
451         b->mtu = dev->mtu;
452         b->media->raw2addr(b, &b->addr, (char *)dev->dev_addr);
453         rcu_assign_pointer(dev->tipc_ptr, b);
454         return 0;
455 }
456
457 /* tipc_disable_l2_media - detach TIPC bearer from an L2 interface
458  *
459  * Mark L2 bearer as inactive so that incoming buffers are thrown away
460  */
461 void tipc_disable_l2_media(struct tipc_bearer *b)
462 {
463         struct net_device *dev;
464
465         dev = (struct net_device *)rtnl_dereference(b->media_ptr);
466         dev_remove_pack(&b->pt);
467         RCU_INIT_POINTER(dev->tipc_ptr, NULL);
468         synchronize_net();
469         dev_put(dev);
470 }
471
472 /**
473  * tipc_l2_send_msg - send a TIPC packet out over an L2 interface
474  * @skb: the packet to be sent
475  * @b: the bearer through which the packet is to be sent
476  * @dest: peer destination address
477  */
478 int tipc_l2_send_msg(struct net *net, struct sk_buff *skb,
479                      struct tipc_bearer *b, struct tipc_media_addr *dest)
480 {
481         struct net_device *dev;
482         int delta;
483
484         dev = (struct net_device *)rcu_dereference(b->media_ptr);
485         if (!dev)
486                 return 0;
487
488         delta = SKB_DATA_ALIGN(dev->hard_header_len - skb_headroom(skb));
489         if ((delta > 0) && pskb_expand_head(skb, delta, 0, GFP_ATOMIC)) {
490                 kfree_skb(skb);
491                 return 0;
492         }
493         skb_reset_network_header(skb);
494         skb->dev = dev;
495         skb->protocol = htons(ETH_P_TIPC);
496         dev_hard_header(skb, dev, ETH_P_TIPC, dest->value,
497                         dev->dev_addr, skb->len);
498         dev_queue_xmit(skb);
499         return 0;
500 }
501
502 bool tipc_bearer_bcast_support(struct net *net, u32 bearer_id)
503 {
504         bool supp = false;
505         struct tipc_bearer *b;
506
507         rcu_read_lock();
508         b = bearer_get(net, bearer_id);
509         if (b)
510                 supp = (b->bcast_addr.broadcast == TIPC_BROADCAST_SUPPORT);
511         rcu_read_unlock();
512         return supp;
513 }
514
515 int tipc_bearer_mtu(struct net *net, u32 bearer_id)
516 {
517         int mtu = 0;
518         struct tipc_bearer *b;
519
520         rcu_read_lock();
521         b = rcu_dereference(tipc_net(net)->bearer_list[bearer_id]);
522         if (b)
523                 mtu = b->mtu;
524         rcu_read_unlock();
525         return mtu;
526 }
527
528 /* tipc_bearer_xmit_skb - sends buffer to destination over bearer
529  */
530 void tipc_bearer_xmit_skb(struct net *net, u32 bearer_id,
531                           struct sk_buff *skb,
532                           struct tipc_media_addr *dest)
533 {
534         struct tipc_msg *hdr = buf_msg(skb);
535         struct tipc_bearer *b;
536
537         rcu_read_lock();
538         b = bearer_get(net, bearer_id);
539         if (likely(b && (test_bit(0, &b->up) || msg_is_reset(hdr)))) {
540 #ifdef CONFIG_TIPC_CRYPTO
541                 tipc_crypto_xmit(net, &skb, b, dest, NULL);
542                 if (skb)
543 #endif
544                         b->media->send_msg(net, skb, b, dest);
545         } else {
546                 kfree_skb(skb);
547         }
548         rcu_read_unlock();
549 }
550
551 /* tipc_bearer_xmit() -send buffer to destination over bearer
552  */
553 void tipc_bearer_xmit(struct net *net, u32 bearer_id,
554                       struct sk_buff_head *xmitq,
555                       struct tipc_media_addr *dst,
556                       struct tipc_node *__dnode)
557 {
558         struct tipc_bearer *b;
559         struct sk_buff *skb, *tmp;
560
561         if (skb_queue_empty(xmitq))
562                 return;
563
564         rcu_read_lock();
565         b = bearer_get(net, bearer_id);
566         if (unlikely(!b))
567                 __skb_queue_purge(xmitq);
568         skb_queue_walk_safe(xmitq, skb, tmp) {
569                 __skb_dequeue(xmitq);
570                 if (likely(test_bit(0, &b->up) || msg_is_reset(buf_msg(skb)))) {
571 #ifdef CONFIG_TIPC_CRYPTO
572                         tipc_crypto_xmit(net, &skb, b, dst, __dnode);
573                         if (skb)
574 #endif
575                                 b->media->send_msg(net, skb, b, dst);
576                 } else {
577                         kfree_skb(skb);
578                 }
579         }
580         rcu_read_unlock();
581 }
582
583 /* tipc_bearer_bc_xmit() - broadcast buffers to all destinations
584  */
585 void tipc_bearer_bc_xmit(struct net *net, u32 bearer_id,
586                          struct sk_buff_head *xmitq)
587 {
588         struct tipc_net *tn = tipc_net(net);
589         struct tipc_media_addr *dst;
590         int net_id = tn->net_id;
591         struct tipc_bearer *b;
592         struct sk_buff *skb, *tmp;
593         struct tipc_msg *hdr;
594
595         rcu_read_lock();
596         b = bearer_get(net, bearer_id);
597         if (unlikely(!b || !test_bit(0, &b->up)))
598                 __skb_queue_purge(xmitq);
599         skb_queue_walk_safe(xmitq, skb, tmp) {
600                 hdr = buf_msg(skb);
601                 msg_set_non_seq(hdr, 1);
602                 msg_set_mc_netid(hdr, net_id);
603                 __skb_dequeue(xmitq);
604                 dst = &b->bcast_addr;
605 #ifdef CONFIG_TIPC_CRYPTO
606                 tipc_crypto_xmit(net, &skb, b, dst, NULL);
607                 if (skb)
608 #endif
609                         b->media->send_msg(net, skb, b, dst);
610         }
611         rcu_read_unlock();
612 }
613
614 /**
615  * tipc_l2_rcv_msg - handle incoming TIPC message from an interface
616  * @skb: the received message
617  * @dev: the net device that the packet was received on
618  * @pt: the packet_type structure which was used to register this handler
619  * @orig_dev: the original receive net device in case the device is a bond
620  *
621  * Accept only packets explicitly sent to this node, or broadcast packets;
622  * ignores packets sent using interface multicast, and traffic sent to other
623  * nodes (which can happen if interface is running in promiscuous mode).
624  */
625 static int tipc_l2_rcv_msg(struct sk_buff *skb, struct net_device *dev,
626                            struct packet_type *pt, struct net_device *orig_dev)
627 {
628         struct tipc_bearer *b;
629
630         rcu_read_lock();
631         b = rcu_dereference(dev->tipc_ptr) ?:
632                 rcu_dereference(orig_dev->tipc_ptr);
633         if (likely(b && test_bit(0, &b->up) &&
634                    (skb->pkt_type <= PACKET_MULTICAST))) {
635                 skb_mark_not_on_list(skb);
636                 TIPC_SKB_CB(skb)->flags = 0;
637                 tipc_rcv(dev_net(b->pt.dev), skb, b);
638                 rcu_read_unlock();
639                 return NET_RX_SUCCESS;
640         }
641         rcu_read_unlock();
642         kfree_skb(skb);
643         return NET_RX_DROP;
644 }
645
646 /**
647  * tipc_l2_device_event - handle device events from network device
648  * @nb: the context of the notification
649  * @evt: the type of event
650  * @ptr: the net device that the event was on
651  *
652  * This function is called by the Ethernet driver in case of link
653  * change event.
654  */
655 static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
656                                 void *ptr)
657 {
658         struct net_device *dev = netdev_notifier_info_to_dev(ptr);
659         struct net *net = dev_net(dev);
660         struct tipc_bearer *b;
661
662         b = rtnl_dereference(dev->tipc_ptr);
663         if (!b)
664                 return NOTIFY_DONE;
665
666         trace_tipc_l2_device_event(dev, b, evt);
667         switch (evt) {
668         case NETDEV_CHANGE:
669                 if (netif_carrier_ok(dev) && netif_oper_up(dev)) {
670                         test_and_set_bit_lock(0, &b->up);
671                         break;
672                 }
673                 fallthrough;
674         case NETDEV_GOING_DOWN:
675                 clear_bit_unlock(0, &b->up);
676                 tipc_reset_bearer(net, b);
677                 break;
678         case NETDEV_UP:
679                 test_and_set_bit_lock(0, &b->up);
680                 break;
681         case NETDEV_CHANGEMTU:
682                 if (tipc_mtu_bad(dev, 0)) {
683                         bearer_disable(net, b);
684                         break;
685                 }
686                 b->mtu = dev->mtu;
687                 tipc_reset_bearer(net, b);
688                 break;
689         case NETDEV_CHANGEADDR:
690                 b->media->raw2addr(b, &b->addr,
691                                    (char *)dev->dev_addr);
692                 tipc_reset_bearer(net, b);
693                 break;
694         case NETDEV_UNREGISTER:
695         case NETDEV_CHANGENAME:
696                 bearer_disable(net, b);
697                 break;
698         }
699         return NOTIFY_OK;
700 }
701
702 static struct notifier_block notifier = {
703         .notifier_call  = tipc_l2_device_event,
704         .priority       = 0,
705 };
706
707 int tipc_bearer_setup(void)
708 {
709         return register_netdevice_notifier(&notifier);
710 }
711
712 void tipc_bearer_cleanup(void)
713 {
714         unregister_netdevice_notifier(&notifier);
715 }
716
717 void tipc_bearer_stop(struct net *net)
718 {
719         struct tipc_net *tn = net_generic(net, tipc_net_id);
720         struct tipc_bearer *b;
721         u32 i;
722
723         for (i = 0; i < MAX_BEARERS; i++) {
724                 b = rtnl_dereference(tn->bearer_list[i]);
725                 if (b) {
726                         bearer_disable(net, b);
727                         tn->bearer_list[i] = NULL;
728                 }
729         }
730 }
731
732 void tipc_clone_to_loopback(struct net *net, struct sk_buff_head *pkts)
733 {
734         struct net_device *dev = net->loopback_dev;
735         struct sk_buff *skb, *_skb;
736         int exp;
737
738         skb_queue_walk(pkts, _skb) {
739                 skb = pskb_copy(_skb, GFP_ATOMIC);
740                 if (!skb)
741                         continue;
742
743                 exp = SKB_DATA_ALIGN(dev->hard_header_len - skb_headroom(skb));
744                 if (exp > 0 && pskb_expand_head(skb, exp, 0, GFP_ATOMIC)) {
745                         kfree_skb(skb);
746                         continue;
747                 }
748
749                 skb_reset_network_header(skb);
750                 dev_hard_header(skb, dev, ETH_P_TIPC, dev->dev_addr,
751                                 dev->dev_addr, skb->len);
752                 skb->dev = dev;
753                 skb->pkt_type = PACKET_HOST;
754                 skb->ip_summed = CHECKSUM_UNNECESSARY;
755                 skb->protocol = eth_type_trans(skb, dev);
756                 netif_rx_ni(skb);
757         }
758 }
759
760 static int tipc_loopback_rcv_pkt(struct sk_buff *skb, struct net_device *dev,
761                                  struct packet_type *pt, struct net_device *od)
762 {
763         consume_skb(skb);
764         return NET_RX_SUCCESS;
765 }
766
767 int tipc_attach_loopback(struct net *net)
768 {
769         struct net_device *dev = net->loopback_dev;
770         struct tipc_net *tn = tipc_net(net);
771
772         if (!dev)
773                 return -ENODEV;
774
775         dev_hold(dev);
776         tn->loopback_pt.dev = dev;
777         tn->loopback_pt.type = htons(ETH_P_TIPC);
778         tn->loopback_pt.func = tipc_loopback_rcv_pkt;
779         dev_add_pack(&tn->loopback_pt);
780         return 0;
781 }
782
783 void tipc_detach_loopback(struct net *net)
784 {
785         struct tipc_net *tn = tipc_net(net);
786
787         dev_remove_pack(&tn->loopback_pt);
788         dev_put(net->loopback_dev);
789 }
790
791 /* Caller should hold rtnl_lock to protect the bearer */
792 static int __tipc_nl_add_bearer(struct tipc_nl_msg *msg,
793                                 struct tipc_bearer *bearer, int nlflags)
794 {
795         void *hdr;
796         struct nlattr *attrs;
797         struct nlattr *prop;
798
799         hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
800                           nlflags, TIPC_NL_BEARER_GET);
801         if (!hdr)
802                 return -EMSGSIZE;
803
804         attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_BEARER);
805         if (!attrs)
806                 goto msg_full;
807
808         if (nla_put_string(msg->skb, TIPC_NLA_BEARER_NAME, bearer->name))
809                 goto attr_msg_full;
810
811         prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_BEARER_PROP);
812         if (!prop)
813                 goto prop_msg_full;
814         if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, bearer->priority))
815                 goto prop_msg_full;
816         if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, bearer->tolerance))
817                 goto prop_msg_full;
818         if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, bearer->max_win))
819                 goto prop_msg_full;
820         if (bearer->media->type_id == TIPC_MEDIA_TYPE_UDP)
821                 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_MTU, bearer->mtu))
822                         goto prop_msg_full;
823
824         nla_nest_end(msg->skb, prop);
825
826 #ifdef CONFIG_TIPC_MEDIA_UDP
827         if (bearer->media->type_id == TIPC_MEDIA_TYPE_UDP) {
828                 if (tipc_udp_nl_add_bearer_data(msg, bearer))
829                         goto attr_msg_full;
830         }
831 #endif
832
833         nla_nest_end(msg->skb, attrs);
834         genlmsg_end(msg->skb, hdr);
835
836         return 0;
837
838 prop_msg_full:
839         nla_nest_cancel(msg->skb, prop);
840 attr_msg_full:
841         nla_nest_cancel(msg->skb, attrs);
842 msg_full:
843         genlmsg_cancel(msg->skb, hdr);
844
845         return -EMSGSIZE;
846 }
847
848 int tipc_nl_bearer_dump(struct sk_buff *skb, struct netlink_callback *cb)
849 {
850         int err;
851         int i = cb->args[0];
852         struct tipc_bearer *bearer;
853         struct tipc_nl_msg msg;
854         struct net *net = sock_net(skb->sk);
855         struct tipc_net *tn = net_generic(net, tipc_net_id);
856
857         if (i == MAX_BEARERS)
858                 return 0;
859
860         msg.skb = skb;
861         msg.portid = NETLINK_CB(cb->skb).portid;
862         msg.seq = cb->nlh->nlmsg_seq;
863
864         rtnl_lock();
865         for (i = 0; i < MAX_BEARERS; i++) {
866                 bearer = rtnl_dereference(tn->bearer_list[i]);
867                 if (!bearer)
868                         continue;
869
870                 err = __tipc_nl_add_bearer(&msg, bearer, NLM_F_MULTI);
871                 if (err)
872                         break;
873         }
874         rtnl_unlock();
875
876         cb->args[0] = i;
877         return skb->len;
878 }
879
880 int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info)
881 {
882         int err;
883         char *name;
884         struct sk_buff *rep;
885         struct tipc_bearer *bearer;
886         struct tipc_nl_msg msg;
887         struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
888         struct net *net = genl_info_net(info);
889
890         if (!info->attrs[TIPC_NLA_BEARER])
891                 return -EINVAL;
892
893         err = nla_parse_nested_deprecated(attrs, TIPC_NLA_BEARER_MAX,
894                                           info->attrs[TIPC_NLA_BEARER],
895                                           tipc_nl_bearer_policy, info->extack);
896         if (err)
897                 return err;
898
899         if (!attrs[TIPC_NLA_BEARER_NAME])
900                 return -EINVAL;
901         name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
902
903         rep = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
904         if (!rep)
905                 return -ENOMEM;
906
907         msg.skb = rep;
908         msg.portid = info->snd_portid;
909         msg.seq = info->snd_seq;
910
911         rtnl_lock();
912         bearer = tipc_bearer_find(net, name);
913         if (!bearer) {
914                 err = -EINVAL;
915                 NL_SET_ERR_MSG(info->extack, "Bearer not found");
916                 goto err_out;
917         }
918
919         err = __tipc_nl_add_bearer(&msg, bearer, 0);
920         if (err)
921                 goto err_out;
922         rtnl_unlock();
923
924         return genlmsg_reply(rep, info);
925 err_out:
926         rtnl_unlock();
927         nlmsg_free(rep);
928
929         return err;
930 }
931
932 int __tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info)
933 {
934         int err;
935         char *name;
936         struct tipc_bearer *bearer;
937         struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
938         struct net *net = sock_net(skb->sk);
939
940         if (!info->attrs[TIPC_NLA_BEARER])
941                 return -EINVAL;
942
943         err = nla_parse_nested_deprecated(attrs, TIPC_NLA_BEARER_MAX,
944                                           info->attrs[TIPC_NLA_BEARER],
945                                           tipc_nl_bearer_policy, info->extack);
946         if (err)
947                 return err;
948
949         if (!attrs[TIPC_NLA_BEARER_NAME])
950                 return -EINVAL;
951
952         name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
953
954         bearer = tipc_bearer_find(net, name);
955         if (!bearer) {
956                 NL_SET_ERR_MSG(info->extack, "Bearer not found");
957                 return -EINVAL;
958         }
959
960         bearer_disable(net, bearer);
961
962         return 0;
963 }
964
965 int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info)
966 {
967         int err;
968
969         rtnl_lock();
970         err = __tipc_nl_bearer_disable(skb, info);
971         rtnl_unlock();
972
973         return err;
974 }
975
976 int __tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
977 {
978         int err;
979         char *bearer;
980         struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
981         struct net *net = sock_net(skb->sk);
982         u32 domain = 0;
983         u32 prio;
984
985         prio = TIPC_MEDIA_LINK_PRI;
986
987         if (!info->attrs[TIPC_NLA_BEARER])
988                 return -EINVAL;
989
990         err = nla_parse_nested_deprecated(attrs, TIPC_NLA_BEARER_MAX,
991                                           info->attrs[TIPC_NLA_BEARER],
992                                           tipc_nl_bearer_policy, info->extack);
993         if (err)
994                 return err;
995
996         if (!attrs[TIPC_NLA_BEARER_NAME])
997                 return -EINVAL;
998
999         bearer = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
1000
1001         if (attrs[TIPC_NLA_BEARER_DOMAIN])
1002                 domain = nla_get_u32(attrs[TIPC_NLA_BEARER_DOMAIN]);
1003
1004         if (attrs[TIPC_NLA_BEARER_PROP]) {
1005                 struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
1006
1007                 err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_BEARER_PROP],
1008                                               props);
1009                 if (err)
1010                         return err;
1011
1012                 if (props[TIPC_NLA_PROP_PRIO])
1013                         prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
1014         }
1015
1016         return tipc_enable_bearer(net, bearer, domain, prio, attrs,
1017                                   info->extack);
1018 }
1019
1020 int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
1021 {
1022         int err;
1023
1024         rtnl_lock();
1025         err = __tipc_nl_bearer_enable(skb, info);
1026         rtnl_unlock();
1027
1028         return err;
1029 }
1030
1031 int tipc_nl_bearer_add(struct sk_buff *skb, struct genl_info *info)
1032 {
1033         int err;
1034         char *name;
1035         struct tipc_bearer *b;
1036         struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
1037         struct net *net = sock_net(skb->sk);
1038
1039         if (!info->attrs[TIPC_NLA_BEARER])
1040                 return -EINVAL;
1041
1042         err = nla_parse_nested_deprecated(attrs, TIPC_NLA_BEARER_MAX,
1043                                           info->attrs[TIPC_NLA_BEARER],
1044                                           tipc_nl_bearer_policy, info->extack);
1045         if (err)
1046                 return err;
1047
1048         if (!attrs[TIPC_NLA_BEARER_NAME])
1049                 return -EINVAL;
1050         name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
1051
1052         rtnl_lock();
1053         b = tipc_bearer_find(net, name);
1054         if (!b) {
1055                 rtnl_unlock();
1056                 NL_SET_ERR_MSG(info->extack, "Bearer not found");
1057                 return -EINVAL;
1058         }
1059
1060 #ifdef CONFIG_TIPC_MEDIA_UDP
1061         if (attrs[TIPC_NLA_BEARER_UDP_OPTS]) {
1062                 err = tipc_udp_nl_bearer_add(b,
1063                                              attrs[TIPC_NLA_BEARER_UDP_OPTS]);
1064                 if (err) {
1065                         rtnl_unlock();
1066                         return err;
1067                 }
1068         }
1069 #endif
1070         rtnl_unlock();
1071
1072         return 0;
1073 }
1074
1075 int __tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
1076 {
1077         struct tipc_bearer *b;
1078         struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
1079         struct net *net = sock_net(skb->sk);
1080         char *name;
1081         int err;
1082
1083         if (!info->attrs[TIPC_NLA_BEARER])
1084                 return -EINVAL;
1085
1086         err = nla_parse_nested_deprecated(attrs, TIPC_NLA_BEARER_MAX,
1087                                           info->attrs[TIPC_NLA_BEARER],
1088                                           tipc_nl_bearer_policy, info->extack);
1089         if (err)
1090                 return err;
1091
1092         if (!attrs[TIPC_NLA_BEARER_NAME])
1093                 return -EINVAL;
1094         name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
1095
1096         b = tipc_bearer_find(net, name);
1097         if (!b) {
1098                 NL_SET_ERR_MSG(info->extack, "Bearer not found");
1099                 return -EINVAL;
1100         }
1101
1102         if (attrs[TIPC_NLA_BEARER_PROP]) {
1103                 struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
1104
1105                 err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_BEARER_PROP],
1106                                               props);
1107                 if (err)
1108                         return err;
1109
1110                 if (props[TIPC_NLA_PROP_TOL]) {
1111                         b->tolerance = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
1112                         tipc_node_apply_property(net, b, TIPC_NLA_PROP_TOL);
1113                 }
1114                 if (props[TIPC_NLA_PROP_PRIO])
1115                         b->priority = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
1116                 if (props[TIPC_NLA_PROP_WIN])
1117                         b->max_win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
1118                 if (props[TIPC_NLA_PROP_MTU]) {
1119                         if (b->media->type_id != TIPC_MEDIA_TYPE_UDP) {
1120                                 NL_SET_ERR_MSG(info->extack,
1121                                                "MTU property is unsupported");
1122                                 return -EINVAL;
1123                         }
1124 #ifdef CONFIG_TIPC_MEDIA_UDP
1125                         if (tipc_udp_mtu_bad(nla_get_u32
1126                                              (props[TIPC_NLA_PROP_MTU]))) {
1127                                 NL_SET_ERR_MSG(info->extack,
1128                                                "MTU value is out-of-range");
1129                                 return -EINVAL;
1130                         }
1131                         b->mtu = nla_get_u32(props[TIPC_NLA_PROP_MTU]);
1132                         tipc_node_apply_property(net, b, TIPC_NLA_PROP_MTU);
1133 #endif
1134                 }
1135         }
1136
1137         return 0;
1138 }
1139
1140 int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
1141 {
1142         int err;
1143
1144         rtnl_lock();
1145         err = __tipc_nl_bearer_set(skb, info);
1146         rtnl_unlock();
1147
1148         return err;
1149 }
1150
1151 static int __tipc_nl_add_media(struct tipc_nl_msg *msg,
1152                                struct tipc_media *media, int nlflags)
1153 {
1154         void *hdr;
1155         struct nlattr *attrs;
1156         struct nlattr *prop;
1157
1158         hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
1159                           nlflags, TIPC_NL_MEDIA_GET);
1160         if (!hdr)
1161                 return -EMSGSIZE;
1162
1163         attrs = nla_nest_start_noflag(msg->skb, TIPC_NLA_MEDIA);
1164         if (!attrs)
1165                 goto msg_full;
1166
1167         if (nla_put_string(msg->skb, TIPC_NLA_MEDIA_NAME, media->name))
1168                 goto attr_msg_full;
1169
1170         prop = nla_nest_start_noflag(msg->skb, TIPC_NLA_MEDIA_PROP);
1171         if (!prop)
1172                 goto prop_msg_full;
1173         if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, media->priority))
1174                 goto prop_msg_full;
1175         if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, media->tolerance))
1176                 goto prop_msg_full;
1177         if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, media->max_win))
1178                 goto prop_msg_full;
1179         if (media->type_id == TIPC_MEDIA_TYPE_UDP)
1180                 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_MTU, media->mtu))
1181                         goto prop_msg_full;
1182
1183         nla_nest_end(msg->skb, prop);
1184         nla_nest_end(msg->skb, attrs);
1185         genlmsg_end(msg->skb, hdr);
1186
1187         return 0;
1188
1189 prop_msg_full:
1190         nla_nest_cancel(msg->skb, prop);
1191 attr_msg_full:
1192         nla_nest_cancel(msg->skb, attrs);
1193 msg_full:
1194         genlmsg_cancel(msg->skb, hdr);
1195
1196         return -EMSGSIZE;
1197 }
1198
1199 int tipc_nl_media_dump(struct sk_buff *skb, struct netlink_callback *cb)
1200 {
1201         int err;
1202         int i = cb->args[0];
1203         struct tipc_nl_msg msg;
1204
1205         if (i == MAX_MEDIA)
1206                 return 0;
1207
1208         msg.skb = skb;
1209         msg.portid = NETLINK_CB(cb->skb).portid;
1210         msg.seq = cb->nlh->nlmsg_seq;
1211
1212         rtnl_lock();
1213         for (; media_info_array[i] != NULL; i++) {
1214                 err = __tipc_nl_add_media(&msg, media_info_array[i],
1215                                           NLM_F_MULTI);
1216                 if (err)
1217                         break;
1218         }
1219         rtnl_unlock();
1220
1221         cb->args[0] = i;
1222         return skb->len;
1223 }
1224
1225 int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info)
1226 {
1227         int err;
1228         char *name;
1229         struct tipc_nl_msg msg;
1230         struct tipc_media *media;
1231         struct sk_buff *rep;
1232         struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
1233
1234         if (!info->attrs[TIPC_NLA_MEDIA])
1235                 return -EINVAL;
1236
1237         err = nla_parse_nested_deprecated(attrs, TIPC_NLA_MEDIA_MAX,
1238                                           info->attrs[TIPC_NLA_MEDIA],
1239                                           tipc_nl_media_policy, info->extack);
1240         if (err)
1241                 return err;
1242
1243         if (!attrs[TIPC_NLA_MEDIA_NAME])
1244                 return -EINVAL;
1245         name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]);
1246
1247         rep = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1248         if (!rep)
1249                 return -ENOMEM;
1250
1251         msg.skb = rep;
1252         msg.portid = info->snd_portid;
1253         msg.seq = info->snd_seq;
1254
1255         rtnl_lock();
1256         media = tipc_media_find(name);
1257         if (!media) {
1258                 NL_SET_ERR_MSG(info->extack, "Media not found");
1259                 err = -EINVAL;
1260                 goto err_out;
1261         }
1262
1263         err = __tipc_nl_add_media(&msg, media, 0);
1264         if (err)
1265                 goto err_out;
1266         rtnl_unlock();
1267
1268         return genlmsg_reply(rep, info);
1269 err_out:
1270         rtnl_unlock();
1271         nlmsg_free(rep);
1272
1273         return err;
1274 }
1275
1276 int __tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
1277 {
1278         int err;
1279         char *name;
1280         struct tipc_media *m;
1281         struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
1282
1283         if (!info->attrs[TIPC_NLA_MEDIA])
1284                 return -EINVAL;
1285
1286         err = nla_parse_nested_deprecated(attrs, TIPC_NLA_MEDIA_MAX,
1287                                           info->attrs[TIPC_NLA_MEDIA],
1288                                           tipc_nl_media_policy, info->extack);
1289
1290         if (!attrs[TIPC_NLA_MEDIA_NAME])
1291                 return -EINVAL;
1292         name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]);
1293
1294         m = tipc_media_find(name);
1295         if (!m) {
1296                 NL_SET_ERR_MSG(info->extack, "Media not found");
1297                 return -EINVAL;
1298         }
1299         if (attrs[TIPC_NLA_MEDIA_PROP]) {
1300                 struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
1301
1302                 err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_MEDIA_PROP],
1303                                               props);
1304                 if (err)
1305                         return err;
1306
1307                 if (props[TIPC_NLA_PROP_TOL])
1308                         m->tolerance = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
1309                 if (props[TIPC_NLA_PROP_PRIO])
1310                         m->priority = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
1311                 if (props[TIPC_NLA_PROP_WIN])
1312                         m->max_win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
1313                 if (props[TIPC_NLA_PROP_MTU]) {
1314                         if (m->type_id != TIPC_MEDIA_TYPE_UDP) {
1315                                 NL_SET_ERR_MSG(info->extack,
1316                                                "MTU property is unsupported");
1317                                 return -EINVAL;
1318                         }
1319 #ifdef CONFIG_TIPC_MEDIA_UDP
1320                         if (tipc_udp_mtu_bad(nla_get_u32
1321                                              (props[TIPC_NLA_PROP_MTU]))) {
1322                                 NL_SET_ERR_MSG(info->extack,
1323                                                "MTU value is out-of-range");
1324                                 return -EINVAL;
1325                         }
1326                         m->mtu = nla_get_u32(props[TIPC_NLA_PROP_MTU]);
1327 #endif
1328                 }
1329         }
1330
1331         return 0;
1332 }
1333
1334 int tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
1335 {
1336         int err;
1337
1338         rtnl_lock();
1339         err = __tipc_nl_media_set(skb, info);
1340         rtnl_unlock();
1341
1342         return err;
1343 }