2 * net/tipc/bearer.c: TIPC bearer code
4 * Copyright (c) 1996-2006, 2013-2016, Ericsson AB
5 * Copyright (c) 2004-2006, 2010-2013, Wind River Systems
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
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.
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.
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.
45 #include "udp_media.h"
47 #define MAX_ADDR_STR 60
49 static struct tipc_media
* const media_info_array
[] = {
51 #ifdef CONFIG_TIPC_MEDIA_IB
54 #ifdef CONFIG_TIPC_MEDIA_UDP
60 static struct tipc_bearer
*bearer_get(struct net
*net
, int bearer_id
)
62 struct tipc_net
*tn
= tipc_net(net
);
64 return rcu_dereference_rtnl(tn
->bearer_list
[bearer_id
]);
67 static void bearer_disable(struct net
*net
, struct tipc_bearer
*b
);
68 static int tipc_l2_rcv_msg(struct sk_buff
*skb
, struct net_device
*dev
,
69 struct packet_type
*pt
, struct net_device
*orig_dev
);
72 * tipc_media_find - locates specified media object by name
74 struct tipc_media
*tipc_media_find(const char *name
)
78 for (i
= 0; media_info_array
[i
] != NULL
; i
++) {
79 if (!strcmp(media_info_array
[i
]->name
, name
))
82 return media_info_array
[i
];
86 * media_find_id - locates specified media object by type identifier
88 static struct tipc_media
*media_find_id(u8 type
)
92 for (i
= 0; media_info_array
[i
] != NULL
; i
++) {
93 if (media_info_array
[i
]->type_id
== type
)
96 return media_info_array
[i
];
100 * tipc_media_addr_printf - record media address in print buffer
102 void tipc_media_addr_printf(char *buf
, int len
, struct tipc_media_addr
*a
)
104 char addr_str
[MAX_ADDR_STR
];
105 struct tipc_media
*m
;
108 m
= media_find_id(a
->media_id
);
110 if (m
&& !m
->addr2str(a
, addr_str
, sizeof(addr_str
)))
111 ret
= scnprintf(buf
, len
, "%s(%s)", m
->name
, addr_str
);
115 ret
= scnprintf(buf
, len
, "UNKNOWN(%u)", a
->media_id
);
116 for (i
= 0; i
< sizeof(a
->value
); i
++)
117 ret
+= scnprintf(buf
- ret
, len
+ ret
,
118 "-%02x", a
->value
[i
]);
123 * bearer_name_validate - validate & (optionally) deconstruct bearer name
124 * @name: ptr to bearer name string
125 * @name_parts: ptr to area for bearer name components (or NULL if not needed)
127 * Returns 1 if bearer name is valid, otherwise 0.
129 static int bearer_name_validate(const char *name
,
130 struct tipc_bearer_names
*name_parts
)
132 char name_copy
[TIPC_MAX_BEARER_NAME
];
138 /* copy bearer name & ensure length is OK */
139 name_copy
[TIPC_MAX_BEARER_NAME
- 1] = 0;
140 /* need above in case non-Posix strncpy() doesn't pad with nulls */
141 strncpy(name_copy
, name
, TIPC_MAX_BEARER_NAME
);
142 if (name_copy
[TIPC_MAX_BEARER_NAME
- 1] != 0)
145 /* ensure all component parts of bearer name are present */
146 media_name
= name_copy
;
147 if_name
= strchr(media_name
, ':');
151 media_len
= if_name
- media_name
;
152 if_len
= strlen(if_name
) + 1;
154 /* validate component parts of bearer name */
155 if ((media_len
<= 1) || (media_len
> TIPC_MAX_MEDIA_NAME
) ||
156 (if_len
<= 1) || (if_len
> TIPC_MAX_IF_NAME
))
159 /* return bearer name components, if necessary */
161 strcpy(name_parts
->media_name
, media_name
);
162 strcpy(name_parts
->if_name
, if_name
);
168 * tipc_bearer_find - locates bearer object with matching bearer name
170 struct tipc_bearer
*tipc_bearer_find(struct net
*net
, const char *name
)
172 struct tipc_net
*tn
= net_generic(net
, tipc_net_id
);
173 struct tipc_bearer
*b
;
176 for (i
= 0; i
< MAX_BEARERS
; i
++) {
177 b
= rtnl_dereference(tn
->bearer_list
[i
]);
178 if (b
&& (!strcmp(b
->name
, name
)))
184 /* tipc_bearer_get_name - get the bearer name from its id.
185 * @net: network namespace
186 * @name: a pointer to the buffer where the name will be stored.
187 * @bearer_id: the id to get the name from.
189 int tipc_bearer_get_name(struct net
*net
, char *name
, u32 bearer_id
)
191 struct tipc_net
*tn
= tipc_net(net
);
192 struct tipc_bearer
*b
;
194 if (bearer_id
>= MAX_BEARERS
)
197 b
= rtnl_dereference(tn
->bearer_list
[bearer_id
]);
201 strcpy(name
, b
->name
);
205 void tipc_bearer_add_dest(struct net
*net
, u32 bearer_id
, u32 dest
)
207 struct tipc_net
*tn
= net_generic(net
, tipc_net_id
);
208 struct tipc_bearer
*b
;
211 b
= rcu_dereference_rtnl(tn
->bearer_list
[bearer_id
]);
213 tipc_disc_add_dest(b
->disc
);
217 void tipc_bearer_remove_dest(struct net
*net
, u32 bearer_id
, u32 dest
)
219 struct tipc_net
*tn
= net_generic(net
, tipc_net_id
);
220 struct tipc_bearer
*b
;
223 b
= rcu_dereference_rtnl(tn
->bearer_list
[bearer_id
]);
225 tipc_disc_remove_dest(b
->disc
);
230 * tipc_enable_bearer - enable bearer with the given name
232 static int tipc_enable_bearer(struct net
*net
, const char *name
,
233 u32 disc_domain
, u32 prio
,
234 struct nlattr
*attr
[])
236 struct tipc_net
*tn
= tipc_net(net
);
237 struct tipc_bearer_names b_names
;
238 int with_this_prio
= 1;
239 struct tipc_bearer
*b
;
240 struct tipc_media
*m
;
246 if (!tipc_own_id(net
)) {
247 errstr
= "not supported in standalone mode";
252 if (!bearer_name_validate(name
, &b_names
)) {
253 errstr
= "illegal name";
257 if (prio
> TIPC_MAX_LINK_PRI
&& prio
!= TIPC_MEDIA_LINK_PRI
) {
258 errstr
= "illegal priority";
262 m
= tipc_media_find(b_names
.media_name
);
264 errstr
= "media not registered";
268 if (prio
== TIPC_MEDIA_LINK_PRI
)
271 /* Check new bearer vs existing ones and find free bearer id if any */
272 while (bearer_id
< MAX_BEARERS
) {
273 b
= rtnl_dereference(tn
->bearer_list
[bearer_id
]);
276 if (!strcmp(name
, b
->name
)) {
277 errstr
= "already enabled";
281 if (b
->priority
!= prio
)
283 if (++with_this_prio
<= 2)
285 pr_warn("Bearer <%s>: already 2 bearers with priority %u\n",
287 if (prio
== TIPC_MIN_LINK_PRI
) {
288 errstr
= "cannot adjust to lower";
291 pr_warn("Bearer <%s>: trying with adjusted priority\n", name
);
297 if (bearer_id
>= MAX_BEARERS
) {
298 errstr
= "max 3 bearers permitted";
302 b
= kzalloc(sizeof(*b
), GFP_ATOMIC
);
306 strcpy(b
->name
, name
);
308 res
= m
->enable_media(net
, b
, attr
);
311 errstr
= "failed to enable media";
315 b
->identity
= bearer_id
;
316 b
->tolerance
= m
->tolerance
;
317 b
->window
= m
->window
;
318 b
->domain
= disc_domain
;
319 b
->net_plane
= bearer_id
+ 'A';
321 test_and_set_bit_lock(0, &b
->up
);
323 res
= tipc_disc_create(net
, b
, &b
->bcast_addr
, &skb
);
325 bearer_disable(net
, b
);
327 errstr
= "failed to create discoverer";
331 rcu_assign_pointer(tn
->bearer_list
[bearer_id
], b
);
333 tipc_bearer_xmit_skb(net
, bearer_id
, skb
, &b
->bcast_addr
);
335 if (tipc_mon_create(net
, bearer_id
)) {
336 bearer_disable(net
, b
);
340 pr_info("Enabled bearer <%s>, priority %u\n", name
, prio
);
344 pr_warn("Enabling of bearer <%s> rejected, %s\n", name
, errstr
);
349 * tipc_reset_bearer - Reset all links established over this bearer
351 static int tipc_reset_bearer(struct net
*net
, struct tipc_bearer
*b
)
353 pr_info("Resetting bearer <%s>\n", b
->name
);
354 tipc_node_delete_links(net
, b
->identity
);
355 tipc_disc_reset(net
, b
);
362 * Note: This routine assumes caller holds RTNL lock.
364 static void bearer_disable(struct net
*net
, struct tipc_bearer
*b
)
366 struct tipc_net
*tn
= tipc_net(net
);
367 int bearer_id
= b
->identity
;
369 pr_info("Disabling bearer <%s>\n", b
->name
);
370 clear_bit_unlock(0, &b
->up
);
371 tipc_node_delete_links(net
, bearer_id
);
372 b
->media
->disable_media(b
);
373 RCU_INIT_POINTER(b
->media_ptr
, NULL
);
375 tipc_disc_delete(b
->disc
);
376 RCU_INIT_POINTER(tn
->bearer_list
[bearer_id
], NULL
);
378 tipc_mon_delete(net
, bearer_id
);
381 int tipc_enable_l2_media(struct net
*net
, struct tipc_bearer
*b
,
382 struct nlattr
*attr
[])
384 struct net_device
*dev
;
385 char *driver_name
= strchr((const char *)b
->name
, ':') + 1;
387 /* Find device with specified name */
388 dev
= dev_get_by_name(net
, driver_name
);
391 if (tipc_mtu_bad(dev
, 0)) {
396 /* Associate TIPC bearer with L2 bearer */
397 rcu_assign_pointer(b
->media_ptr
, dev
);
399 b
->pt
.type
= htons(ETH_P_TIPC
);
400 b
->pt
.func
= tipc_l2_rcv_msg
;
401 dev_add_pack(&b
->pt
);
402 memset(&b
->bcast_addr
, 0, sizeof(b
->bcast_addr
));
403 memcpy(b
->bcast_addr
.value
, dev
->broadcast
, b
->media
->hwaddr_len
);
404 b
->bcast_addr
.media_id
= b
->media
->type_id
;
405 b
->bcast_addr
.broadcast
= TIPC_BROADCAST_SUPPORT
;
407 b
->media
->raw2addr(b
, &b
->addr
, (char *)dev
->dev_addr
);
408 rcu_assign_pointer(dev
->tipc_ptr
, b
);
412 /* tipc_disable_l2_media - detach TIPC bearer from an L2 interface
414 * Mark L2 bearer as inactive so that incoming buffers are thrown away
416 void tipc_disable_l2_media(struct tipc_bearer
*b
)
418 struct net_device
*dev
;
420 dev
= (struct net_device
*)rtnl_dereference(b
->media_ptr
);
421 dev_remove_pack(&b
->pt
);
422 RCU_INIT_POINTER(dev
->tipc_ptr
, NULL
);
428 * tipc_l2_send_msg - send a TIPC packet out over an L2 interface
429 * @skb: the packet to be sent
430 * @b: the bearer through which the packet is to be sent
431 * @dest: peer destination address
433 int tipc_l2_send_msg(struct net
*net
, struct sk_buff
*skb
,
434 struct tipc_bearer
*b
, struct tipc_media_addr
*dest
)
436 struct net_device
*dev
;
439 dev
= (struct net_device
*)rcu_dereference_rtnl(b
->media_ptr
);
443 delta
= SKB_DATA_ALIGN(dev
->hard_header_len
- skb_headroom(skb
));
444 if ((delta
> 0) && pskb_expand_head(skb
, delta
, 0, GFP_ATOMIC
)) {
448 skb_reset_network_header(skb
);
450 skb
->protocol
= htons(ETH_P_TIPC
);
451 dev_hard_header(skb
, dev
, ETH_P_TIPC
, dest
->value
,
452 dev
->dev_addr
, skb
->len
);
457 bool tipc_bearer_bcast_support(struct net
*net
, u32 bearer_id
)
460 struct tipc_bearer
*b
;
463 b
= bearer_get(net
, bearer_id
);
465 supp
= (b
->bcast_addr
.broadcast
== TIPC_BROADCAST_SUPPORT
);
470 int tipc_bearer_mtu(struct net
*net
, u32 bearer_id
)
473 struct tipc_bearer
*b
;
476 b
= rcu_dereference_rtnl(tipc_net(net
)->bearer_list
[bearer_id
]);
483 /* tipc_bearer_xmit_skb - sends buffer to destination over bearer
485 void tipc_bearer_xmit_skb(struct net
*net
, u32 bearer_id
,
487 struct tipc_media_addr
*dest
)
489 struct tipc_msg
*hdr
= buf_msg(skb
);
490 struct tipc_bearer
*b
;
493 b
= bearer_get(net
, bearer_id
);
494 if (likely(b
&& (test_bit(0, &b
->up
) || msg_is_reset(hdr
))))
495 b
->media
->send_msg(net
, skb
, b
, dest
);
501 /* tipc_bearer_xmit() -send buffer to destination over bearer
503 void tipc_bearer_xmit(struct net
*net
, u32 bearer_id
,
504 struct sk_buff_head
*xmitq
,
505 struct tipc_media_addr
*dst
)
507 struct tipc_bearer
*b
;
508 struct sk_buff
*skb
, *tmp
;
510 if (skb_queue_empty(xmitq
))
514 b
= bearer_get(net
, bearer_id
);
516 __skb_queue_purge(xmitq
);
517 skb_queue_walk_safe(xmitq
, skb
, tmp
) {
518 __skb_dequeue(xmitq
);
519 if (likely(test_bit(0, &b
->up
) || msg_is_reset(buf_msg(skb
))))
520 b
->media
->send_msg(net
, skb
, b
, dst
);
527 /* tipc_bearer_bc_xmit() - broadcast buffers to all destinations
529 void tipc_bearer_bc_xmit(struct net
*net
, u32 bearer_id
,
530 struct sk_buff_head
*xmitq
)
532 struct tipc_net
*tn
= tipc_net(net
);
533 int net_id
= tn
->net_id
;
534 struct tipc_bearer
*b
;
535 struct sk_buff
*skb
, *tmp
;
536 struct tipc_msg
*hdr
;
539 b
= bearer_get(net
, bearer_id
);
540 if (unlikely(!b
|| !test_bit(0, &b
->up
)))
541 __skb_queue_purge(xmitq
);
542 skb_queue_walk_safe(xmitq
, skb
, tmp
) {
544 msg_set_non_seq(hdr
, 1);
545 msg_set_mc_netid(hdr
, net_id
);
546 __skb_dequeue(xmitq
);
547 b
->media
->send_msg(net
, skb
, b
, &b
->bcast_addr
);
553 * tipc_l2_rcv_msg - handle incoming TIPC message from an interface
554 * @buf: the received packet
555 * @dev: the net device that the packet was received on
556 * @pt: the packet_type structure which was used to register this handler
557 * @orig_dev: the original receive net device in case the device is a bond
559 * Accept only packets explicitly sent to this node, or broadcast packets;
560 * ignores packets sent using interface multicast, and traffic sent to other
561 * nodes (which can happen if interface is running in promiscuous mode).
563 static int tipc_l2_rcv_msg(struct sk_buff
*skb
, struct net_device
*dev
,
564 struct packet_type
*pt
, struct net_device
*orig_dev
)
566 struct tipc_bearer
*b
;
569 b
= rcu_dereference_rtnl(dev
->tipc_ptr
) ?:
570 rcu_dereference_rtnl(orig_dev
->tipc_ptr
);
571 if (likely(b
&& test_bit(0, &b
->up
) &&
572 (skb
->pkt_type
<= PACKET_MULTICAST
))) {
574 tipc_rcv(dev_net(b
->pt
.dev
), skb
, b
);
576 return NET_RX_SUCCESS
;
584 * tipc_l2_device_event - handle device events from network device
585 * @nb: the context of the notification
586 * @evt: the type of event
587 * @ptr: the net device that the event was on
589 * This function is called by the Ethernet driver in case of link
592 static int tipc_l2_device_event(struct notifier_block
*nb
, unsigned long evt
,
595 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
596 struct net
*net
= dev_net(dev
);
597 struct tipc_bearer
*b
;
599 b
= rtnl_dereference(dev
->tipc_ptr
);
605 if (netif_carrier_ok(dev
))
608 test_and_set_bit_lock(0, &b
->up
);
610 case NETDEV_GOING_DOWN
:
611 clear_bit_unlock(0, &b
->up
);
612 tipc_reset_bearer(net
, b
);
614 case NETDEV_CHANGEMTU
:
615 if (tipc_mtu_bad(dev
, 0)) {
616 bearer_disable(net
, b
);
620 tipc_reset_bearer(net
, b
);
622 case NETDEV_CHANGEADDR
:
623 b
->media
->raw2addr(b
, &b
->addr
,
624 (char *)dev
->dev_addr
);
625 tipc_reset_bearer(net
, b
);
627 case NETDEV_UNREGISTER
:
628 case NETDEV_CHANGENAME
:
629 bearer_disable(net
, b
);
635 static struct notifier_block notifier
= {
636 .notifier_call
= tipc_l2_device_event
,
640 int tipc_bearer_setup(void)
642 return register_netdevice_notifier(¬ifier
);
645 void tipc_bearer_cleanup(void)
647 unregister_netdevice_notifier(¬ifier
);
650 void tipc_bearer_stop(struct net
*net
)
652 struct tipc_net
*tn
= net_generic(net
, tipc_net_id
);
653 struct tipc_bearer
*b
;
656 for (i
= 0; i
< MAX_BEARERS
; i
++) {
657 b
= rtnl_dereference(tn
->bearer_list
[i
]);
659 bearer_disable(net
, b
);
660 tn
->bearer_list
[i
] = NULL
;
665 /* Caller should hold rtnl_lock to protect the bearer */
666 static int __tipc_nl_add_bearer(struct tipc_nl_msg
*msg
,
667 struct tipc_bearer
*bearer
, int nlflags
)
670 struct nlattr
*attrs
;
673 hdr
= genlmsg_put(msg
->skb
, msg
->portid
, msg
->seq
, &tipc_genl_family
,
674 nlflags
, TIPC_NL_BEARER_GET
);
678 attrs
= nla_nest_start(msg
->skb
, TIPC_NLA_BEARER
);
682 if (nla_put_string(msg
->skb
, TIPC_NLA_BEARER_NAME
, bearer
->name
))
685 prop
= nla_nest_start(msg
->skb
, TIPC_NLA_BEARER_PROP
);
688 if (nla_put_u32(msg
->skb
, TIPC_NLA_PROP_PRIO
, bearer
->priority
))
690 if (nla_put_u32(msg
->skb
, TIPC_NLA_PROP_TOL
, bearer
->tolerance
))
692 if (nla_put_u32(msg
->skb
, TIPC_NLA_PROP_WIN
, bearer
->window
))
695 nla_nest_end(msg
->skb
, prop
);
697 #ifdef CONFIG_TIPC_MEDIA_UDP
698 if (bearer
->media
->type_id
== TIPC_MEDIA_TYPE_UDP
) {
699 if (tipc_udp_nl_add_bearer_data(msg
, bearer
))
704 nla_nest_end(msg
->skb
, attrs
);
705 genlmsg_end(msg
->skb
, hdr
);
710 nla_nest_cancel(msg
->skb
, prop
);
712 nla_nest_cancel(msg
->skb
, attrs
);
714 genlmsg_cancel(msg
->skb
, hdr
);
719 int tipc_nl_bearer_dump(struct sk_buff
*skb
, struct netlink_callback
*cb
)
723 struct tipc_bearer
*bearer
;
724 struct tipc_nl_msg msg
;
725 struct net
*net
= sock_net(skb
->sk
);
726 struct tipc_net
*tn
= net_generic(net
, tipc_net_id
);
728 if (i
== MAX_BEARERS
)
732 msg
.portid
= NETLINK_CB(cb
->skb
).portid
;
733 msg
.seq
= cb
->nlh
->nlmsg_seq
;
736 for (i
= 0; i
< MAX_BEARERS
; i
++) {
737 bearer
= rtnl_dereference(tn
->bearer_list
[i
]);
741 err
= __tipc_nl_add_bearer(&msg
, bearer
, NLM_F_MULTI
);
751 int tipc_nl_bearer_get(struct sk_buff
*skb
, struct genl_info
*info
)
756 struct tipc_bearer
*bearer
;
757 struct tipc_nl_msg msg
;
758 struct nlattr
*attrs
[TIPC_NLA_BEARER_MAX
+ 1];
759 struct net
*net
= genl_info_net(info
);
761 if (!info
->attrs
[TIPC_NLA_BEARER
])
764 err
= nla_parse_nested(attrs
, TIPC_NLA_BEARER_MAX
,
765 info
->attrs
[TIPC_NLA_BEARER
],
766 tipc_nl_bearer_policy
, info
->extack
);
770 if (!attrs
[TIPC_NLA_BEARER_NAME
])
772 name
= nla_data(attrs
[TIPC_NLA_BEARER_NAME
]);
774 rep
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
779 msg
.portid
= info
->snd_portid
;
780 msg
.seq
= info
->snd_seq
;
783 bearer
= tipc_bearer_find(net
, name
);
789 err
= __tipc_nl_add_bearer(&msg
, bearer
, 0);
794 return genlmsg_reply(rep
, info
);
802 int __tipc_nl_bearer_disable(struct sk_buff
*skb
, struct genl_info
*info
)
806 struct tipc_bearer
*bearer
;
807 struct nlattr
*attrs
[TIPC_NLA_BEARER_MAX
+ 1];
808 struct net
*net
= sock_net(skb
->sk
);
810 if (!info
->attrs
[TIPC_NLA_BEARER
])
813 err
= nla_parse_nested(attrs
, TIPC_NLA_BEARER_MAX
,
814 info
->attrs
[TIPC_NLA_BEARER
],
815 tipc_nl_bearer_policy
, info
->extack
);
819 if (!attrs
[TIPC_NLA_BEARER_NAME
])
822 name
= nla_data(attrs
[TIPC_NLA_BEARER_NAME
]);
824 bearer
= tipc_bearer_find(net
, name
);
828 bearer_disable(net
, bearer
);
833 int tipc_nl_bearer_disable(struct sk_buff
*skb
, struct genl_info
*info
)
838 err
= __tipc_nl_bearer_disable(skb
, info
);
844 int __tipc_nl_bearer_enable(struct sk_buff
*skb
, struct genl_info
*info
)
848 struct nlattr
*attrs
[TIPC_NLA_BEARER_MAX
+ 1];
849 struct net
*net
= sock_net(skb
->sk
);
853 prio
= TIPC_MEDIA_LINK_PRI
;
855 if (!info
->attrs
[TIPC_NLA_BEARER
])
858 err
= nla_parse_nested(attrs
, TIPC_NLA_BEARER_MAX
,
859 info
->attrs
[TIPC_NLA_BEARER
],
860 tipc_nl_bearer_policy
, info
->extack
);
864 if (!attrs
[TIPC_NLA_BEARER_NAME
])
867 bearer
= nla_data(attrs
[TIPC_NLA_BEARER_NAME
]);
869 if (attrs
[TIPC_NLA_BEARER_DOMAIN
])
870 domain
= nla_get_u32(attrs
[TIPC_NLA_BEARER_DOMAIN
]);
872 if (attrs
[TIPC_NLA_BEARER_PROP
]) {
873 struct nlattr
*props
[TIPC_NLA_PROP_MAX
+ 1];
875 err
= tipc_nl_parse_link_prop(attrs
[TIPC_NLA_BEARER_PROP
],
880 if (props
[TIPC_NLA_PROP_PRIO
])
881 prio
= nla_get_u32(props
[TIPC_NLA_PROP_PRIO
]);
884 return tipc_enable_bearer(net
, bearer
, domain
, prio
, attrs
);
887 int tipc_nl_bearer_enable(struct sk_buff
*skb
, struct genl_info
*info
)
892 err
= __tipc_nl_bearer_enable(skb
, info
);
898 int tipc_nl_bearer_add(struct sk_buff
*skb
, struct genl_info
*info
)
902 struct tipc_bearer
*b
;
903 struct nlattr
*attrs
[TIPC_NLA_BEARER_MAX
+ 1];
904 struct net
*net
= sock_net(skb
->sk
);
906 if (!info
->attrs
[TIPC_NLA_BEARER
])
909 err
= nla_parse_nested(attrs
, TIPC_NLA_BEARER_MAX
,
910 info
->attrs
[TIPC_NLA_BEARER
],
911 tipc_nl_bearer_policy
, info
->extack
);
915 if (!attrs
[TIPC_NLA_BEARER_NAME
])
917 name
= nla_data(attrs
[TIPC_NLA_BEARER_NAME
]);
920 b
= tipc_bearer_find(net
, name
);
926 #ifdef CONFIG_TIPC_MEDIA_UDP
927 if (attrs
[TIPC_NLA_BEARER_UDP_OPTS
]) {
928 err
= tipc_udp_nl_bearer_add(b
,
929 attrs
[TIPC_NLA_BEARER_UDP_OPTS
]);
941 int __tipc_nl_bearer_set(struct sk_buff
*skb
, struct genl_info
*info
)
943 struct tipc_bearer
*b
;
944 struct nlattr
*attrs
[TIPC_NLA_BEARER_MAX
+ 1];
945 struct net
*net
= sock_net(skb
->sk
);
949 if (!info
->attrs
[TIPC_NLA_BEARER
])
952 err
= nla_parse_nested(attrs
, TIPC_NLA_BEARER_MAX
,
953 info
->attrs
[TIPC_NLA_BEARER
],
954 tipc_nl_bearer_policy
, info
->extack
);
958 if (!attrs
[TIPC_NLA_BEARER_NAME
])
960 name
= nla_data(attrs
[TIPC_NLA_BEARER_NAME
]);
962 b
= tipc_bearer_find(net
, name
);
966 if (attrs
[TIPC_NLA_BEARER_PROP
]) {
967 struct nlattr
*props
[TIPC_NLA_PROP_MAX
+ 1];
969 err
= tipc_nl_parse_link_prop(attrs
[TIPC_NLA_BEARER_PROP
],
974 if (props
[TIPC_NLA_PROP_TOL
]) {
975 b
->tolerance
= nla_get_u32(props
[TIPC_NLA_PROP_TOL
]);
976 tipc_node_apply_tolerance(net
, b
);
978 if (props
[TIPC_NLA_PROP_PRIO
])
979 b
->priority
= nla_get_u32(props
[TIPC_NLA_PROP_PRIO
]);
980 if (props
[TIPC_NLA_PROP_WIN
])
981 b
->window
= nla_get_u32(props
[TIPC_NLA_PROP_WIN
]);
987 int tipc_nl_bearer_set(struct sk_buff
*skb
, struct genl_info
*info
)
992 err
= __tipc_nl_bearer_set(skb
, info
);
998 static int __tipc_nl_add_media(struct tipc_nl_msg
*msg
,
999 struct tipc_media
*media
, int nlflags
)
1002 struct nlattr
*attrs
;
1003 struct nlattr
*prop
;
1005 hdr
= genlmsg_put(msg
->skb
, msg
->portid
, msg
->seq
, &tipc_genl_family
,
1006 nlflags
, TIPC_NL_MEDIA_GET
);
1010 attrs
= nla_nest_start(msg
->skb
, TIPC_NLA_MEDIA
);
1014 if (nla_put_string(msg
->skb
, TIPC_NLA_MEDIA_NAME
, media
->name
))
1017 prop
= nla_nest_start(msg
->skb
, TIPC_NLA_MEDIA_PROP
);
1020 if (nla_put_u32(msg
->skb
, TIPC_NLA_PROP_PRIO
, media
->priority
))
1022 if (nla_put_u32(msg
->skb
, TIPC_NLA_PROP_TOL
, media
->tolerance
))
1024 if (nla_put_u32(msg
->skb
, TIPC_NLA_PROP_WIN
, media
->window
))
1027 nla_nest_end(msg
->skb
, prop
);
1028 nla_nest_end(msg
->skb
, attrs
);
1029 genlmsg_end(msg
->skb
, hdr
);
1034 nla_nest_cancel(msg
->skb
, prop
);
1036 nla_nest_cancel(msg
->skb
, attrs
);
1038 genlmsg_cancel(msg
->skb
, hdr
);
1043 int tipc_nl_media_dump(struct sk_buff
*skb
, struct netlink_callback
*cb
)
1046 int i
= cb
->args
[0];
1047 struct tipc_nl_msg msg
;
1053 msg
.portid
= NETLINK_CB(cb
->skb
).portid
;
1054 msg
.seq
= cb
->nlh
->nlmsg_seq
;
1057 for (; media_info_array
[i
] != NULL
; i
++) {
1058 err
= __tipc_nl_add_media(&msg
, media_info_array
[i
],
1069 int tipc_nl_media_get(struct sk_buff
*skb
, struct genl_info
*info
)
1073 struct tipc_nl_msg msg
;
1074 struct tipc_media
*media
;
1075 struct sk_buff
*rep
;
1076 struct nlattr
*attrs
[TIPC_NLA_BEARER_MAX
+ 1];
1078 if (!info
->attrs
[TIPC_NLA_MEDIA
])
1081 err
= nla_parse_nested(attrs
, TIPC_NLA_MEDIA_MAX
,
1082 info
->attrs
[TIPC_NLA_MEDIA
],
1083 tipc_nl_media_policy
, info
->extack
);
1087 if (!attrs
[TIPC_NLA_MEDIA_NAME
])
1089 name
= nla_data(attrs
[TIPC_NLA_MEDIA_NAME
]);
1091 rep
= nlmsg_new(NLMSG_GOODSIZE
, GFP_KERNEL
);
1096 msg
.portid
= info
->snd_portid
;
1097 msg
.seq
= info
->snd_seq
;
1100 media
= tipc_media_find(name
);
1106 err
= __tipc_nl_add_media(&msg
, media
, 0);
1111 return genlmsg_reply(rep
, info
);
1119 int __tipc_nl_media_set(struct sk_buff
*skb
, struct genl_info
*info
)
1123 struct tipc_media
*m
;
1124 struct nlattr
*attrs
[TIPC_NLA_BEARER_MAX
+ 1];
1126 if (!info
->attrs
[TIPC_NLA_MEDIA
])
1129 err
= nla_parse_nested(attrs
, TIPC_NLA_MEDIA_MAX
,
1130 info
->attrs
[TIPC_NLA_MEDIA
],
1131 tipc_nl_media_policy
, info
->extack
);
1133 if (!attrs
[TIPC_NLA_MEDIA_NAME
])
1135 name
= nla_data(attrs
[TIPC_NLA_MEDIA_NAME
]);
1137 m
= tipc_media_find(name
);
1141 if (attrs
[TIPC_NLA_MEDIA_PROP
]) {
1142 struct nlattr
*props
[TIPC_NLA_PROP_MAX
+ 1];
1144 err
= tipc_nl_parse_link_prop(attrs
[TIPC_NLA_MEDIA_PROP
],
1149 if (props
[TIPC_NLA_PROP_TOL
])
1150 m
->tolerance
= nla_get_u32(props
[TIPC_NLA_PROP_TOL
]);
1151 if (props
[TIPC_NLA_PROP_PRIO
])
1152 m
->priority
= nla_get_u32(props
[TIPC_NLA_PROP_PRIO
]);
1153 if (props
[TIPC_NLA_PROP_WIN
])
1154 m
->window
= nla_get_u32(props
[TIPC_NLA_PROP_WIN
]);
1160 int tipc_nl_media_set(struct sk_buff
*skb
, struct genl_info
*info
)
1165 err
= __tipc_nl_media_set(skb
, info
);