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);
70 * tipc_media_find - locates specified media object by name
72 struct tipc_media *tipc_media_find(const char *name)
76 for (i = 0; media_info_array[i] != NULL; i++) {
77 if (!strcmp(media_info_array[i]->name, name))
80 return media_info_array[i];
84 * media_find_id - locates specified media object by type identifier
86 static struct tipc_media *media_find_id(u8 type)
90 for (i = 0; media_info_array[i] != NULL; i++) {
91 if (media_info_array[i]->type_id == type)
94 return media_info_array[i];
98 * tipc_media_addr_printf - record media address in print buffer
100 void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a)
102 char addr_str[MAX_ADDR_STR];
103 struct tipc_media *m;
106 m = media_find_id(a->media_id);
108 if (m && !m->addr2str(a, addr_str, sizeof(addr_str)))
109 ret = scnprintf(buf, len, "%s(%s)", m->name, addr_str);
113 ret = scnprintf(buf, len, "UNKNOWN(%u)", a->media_id);
114 for (i = 0; i < sizeof(a->value); i++)
115 ret += scnprintf(buf - ret, len + ret,
116 "-%02x", a->value[i]);
121 * bearer_name_validate - validate & (optionally) deconstruct bearer name
122 * @name: ptr to bearer name string
123 * @name_parts: ptr to area for bearer name components (or NULL if not needed)
125 * Returns 1 if bearer name is valid, otherwise 0.
127 static int bearer_name_validate(const char *name,
128 struct tipc_bearer_names *name_parts)
130 char name_copy[TIPC_MAX_BEARER_NAME];
136 /* copy bearer name & ensure length is OK */
137 name_copy[TIPC_MAX_BEARER_NAME - 1] = 0;
138 /* need above in case non-Posix strncpy() doesn't pad with nulls */
139 strncpy(name_copy, name, TIPC_MAX_BEARER_NAME);
140 if (name_copy[TIPC_MAX_BEARER_NAME - 1] != 0)
143 /* ensure all component parts of bearer name are present */
144 media_name = name_copy;
145 if_name = strchr(media_name, ':');
149 media_len = if_name - media_name;
150 if_len = strlen(if_name) + 1;
152 /* validate component parts of bearer name */
153 if ((media_len <= 1) || (media_len > TIPC_MAX_MEDIA_NAME) ||
154 (if_len <= 1) || (if_len > TIPC_MAX_IF_NAME))
157 /* return bearer name components, if necessary */
159 strcpy(name_parts->media_name, media_name);
160 strcpy(name_parts->if_name, if_name);
166 * tipc_bearer_find - locates bearer object with matching bearer name
168 struct tipc_bearer *tipc_bearer_find(struct net *net, const char *name)
170 struct tipc_net *tn = net_generic(net, tipc_net_id);
171 struct tipc_bearer *b;
174 for (i = 0; i < MAX_BEARERS; i++) {
175 b = rtnl_dereference(tn->bearer_list[i]);
176 if (b && (!strcmp(b->name, name)))
182 /* tipc_bearer_get_name - get the bearer name from its id.
183 * @net: network namespace
184 * @name: a pointer to the buffer where the name will be stored.
185 * @bearer_id: the id to get the name from.
187 int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id)
189 struct tipc_net *tn = tipc_net(net);
190 struct tipc_bearer *b;
192 if (bearer_id >= MAX_BEARERS)
195 b = rtnl_dereference(tn->bearer_list[bearer_id]);
199 strcpy(name, b->name);
203 void tipc_bearer_add_dest(struct net *net, u32 bearer_id, u32 dest)
205 struct tipc_net *tn = net_generic(net, tipc_net_id);
206 struct tipc_bearer *b;
209 b = rcu_dereference_rtnl(tn->bearer_list[bearer_id]);
211 tipc_disc_add_dest(b->link_req);
215 void tipc_bearer_remove_dest(struct net *net, u32 bearer_id, u32 dest)
217 struct tipc_net *tn = net_generic(net, tipc_net_id);
218 struct tipc_bearer *b;
221 b = rcu_dereference_rtnl(tn->bearer_list[bearer_id]);
223 tipc_disc_remove_dest(b->link_req);
228 * tipc_enable_bearer - enable bearer with the given name
230 static int tipc_enable_bearer(struct net *net, const char *name,
231 u32 disc_domain, u32 priority,
232 struct nlattr *attr[])
234 struct tipc_net *tn = net_generic(net, tipc_net_id);
235 struct tipc_bearer *b;
236 struct tipc_media *m;
237 struct tipc_bearer_names b_names;
239 char addr_string[16];
246 pr_warn("Bearer <%s> rejected, not supported in standalone mode\n",
250 if (!bearer_name_validate(name, &b_names)) {
251 pr_warn("Bearer <%s> rejected, illegal name\n", name);
254 if (tipc_addr_domain_valid(disc_domain) &&
255 (disc_domain != tn->own_addr)) {
256 if (tipc_in_scope(disc_domain, tn->own_addr)) {
257 disc_domain = tn->own_addr & TIPC_ZONE_CLUSTER_MASK;
258 res = 0; /* accept any node in own cluster */
259 } else if (in_own_cluster_exact(net, disc_domain))
260 res = 0; /* accept specified node in own cluster */
263 pr_warn("Bearer <%s> rejected, illegal discovery domain\n",
267 if ((priority > TIPC_MAX_LINK_PRI) &&
268 (priority != TIPC_MEDIA_LINK_PRI)) {
269 pr_warn("Bearer <%s> rejected, illegal priority\n", name);
273 m = tipc_media_find(b_names.media_name);
275 pr_warn("Bearer <%s> rejected, media <%s> not registered\n",
276 name, b_names.media_name);
280 if (priority == TIPC_MEDIA_LINK_PRI)
281 priority = m->priority;
284 bearer_id = MAX_BEARERS;
286 for (i = MAX_BEARERS; i-- != 0; ) {
287 b = rtnl_dereference(tn->bearer_list[i]);
292 if (!strcmp(name, b->name)) {
293 pr_warn("Bearer <%s> rejected, already enabled\n",
297 if ((b->priority == priority) &&
298 (++with_this_prio > 2)) {
299 if (priority-- == 0) {
300 pr_warn("Bearer <%s> rejected, duplicate priority\n",
304 pr_warn("Bearer <%s> priority adjustment required %u->%u\n",
305 name, priority + 1, priority);
309 if (bearer_id >= MAX_BEARERS) {
310 pr_warn("Bearer <%s> rejected, bearer limit reached (%u)\n",
315 b = kzalloc(sizeof(*b), GFP_ATOMIC);
319 strcpy(b->name, name);
321 res = m->enable_media(net, b, attr);
323 pr_warn("Bearer <%s> rejected, enable failure (%d)\n",
329 b->identity = bearer_id;
330 b->tolerance = m->tolerance;
331 b->window = m->window;
332 b->domain = disc_domain;
333 b->net_plane = bearer_id + 'A';
334 b->priority = priority;
335 test_and_set_bit_lock(0, &b->up);
337 res = tipc_disc_create(net, b, &b->bcast_addr, &skb);
339 bearer_disable(net, b);
340 pr_warn("Bearer <%s> rejected, discovery object creation failed\n",
345 rcu_assign_pointer(tn->bearer_list[bearer_id], b);
347 tipc_bearer_xmit_skb(net, bearer_id, skb, &b->bcast_addr);
349 if (tipc_mon_create(net, bearer_id)) {
350 bearer_disable(net, b);
354 pr_info("Enabled bearer <%s>, discovery domain %s, priority %u\n",
356 tipc_addr_string_fill(addr_string, disc_domain), priority);
361 * tipc_reset_bearer - Reset all links established over this bearer
363 static int tipc_reset_bearer(struct net *net, struct tipc_bearer *b)
365 pr_info("Resetting bearer <%s>\n", b->name);
366 tipc_node_delete_links(net, b->identity);
367 tipc_disc_reset(net, b);
371 /* tipc_bearer_reset_all - reset all links on all bearers
373 void tipc_bearer_reset_all(struct net *net)
375 struct tipc_bearer *b;
378 for (i = 0; i < MAX_BEARERS; i++) {
379 b = bearer_get(net, i);
381 clear_bit_unlock(0, &b->up);
383 for (i = 0; i < MAX_BEARERS; i++) {
384 b = bearer_get(net, i);
386 tipc_reset_bearer(net, b);
388 for (i = 0; i < MAX_BEARERS; i++) {
389 b = bearer_get(net, i);
391 test_and_set_bit_lock(0, &b->up);
398 * Note: This routine assumes caller holds RTNL lock.
400 static void bearer_disable(struct net *net, struct tipc_bearer *b)
402 struct tipc_net *tn = tipc_net(net);
403 int bearer_id = b->identity;
405 pr_info("Disabling bearer <%s>\n", b->name);
406 clear_bit_unlock(0, &b->up);
407 tipc_node_delete_links(net, bearer_id);
408 b->media->disable_media(b);
409 RCU_INIT_POINTER(b->media_ptr, NULL);
411 tipc_disc_delete(b->link_req);
412 RCU_INIT_POINTER(tn->bearer_list[bearer_id], NULL);
414 tipc_mon_delete(net, bearer_id);
417 int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b,
418 struct nlattr *attr[])
420 struct net_device *dev;
421 char *driver_name = strchr((const char *)b->name, ':') + 1;
423 /* Find device with specified name */
424 dev = dev_get_by_name(net, driver_name);
427 if (tipc_mtu_bad(dev, 0)) {
432 /* Associate TIPC bearer with L2 bearer */
433 rcu_assign_pointer(b->media_ptr, dev);
434 memset(&b->bcast_addr, 0, sizeof(b->bcast_addr));
435 memcpy(b->bcast_addr.value, dev->broadcast, b->media->hwaddr_len);
436 b->bcast_addr.media_id = b->media->type_id;
437 b->bcast_addr.broadcast = 1;
439 b->media->raw2addr(b, &b->addr, (char *)dev->dev_addr);
440 rcu_assign_pointer(dev->tipc_ptr, b);
444 /* tipc_disable_l2_media - detach TIPC bearer from an L2 interface
446 * Mark L2 bearer as inactive so that incoming buffers are thrown away
448 void tipc_disable_l2_media(struct tipc_bearer *b)
450 struct net_device *dev;
452 dev = (struct net_device *)rtnl_dereference(b->media_ptr);
453 RCU_INIT_POINTER(dev->tipc_ptr, NULL);
459 * tipc_l2_send_msg - send a TIPC packet out over an L2 interface
460 * @skb: the packet to be sent
461 * @b: the bearer through which the packet is to be sent
462 * @dest: peer destination address
464 int tipc_l2_send_msg(struct net *net, struct sk_buff *skb,
465 struct tipc_bearer *b, struct tipc_media_addr *dest)
467 struct net_device *dev;
470 dev = (struct net_device *)rcu_dereference_rtnl(b->media_ptr);
474 delta = SKB_DATA_ALIGN(dev->hard_header_len - skb_headroom(skb));
475 if ((delta > 0) && pskb_expand_head(skb, delta, 0, GFP_ATOMIC)) {
479 skb_reset_network_header(skb);
481 skb->protocol = htons(ETH_P_TIPC);
482 dev_hard_header(skb, dev, ETH_P_TIPC, dest->value,
483 dev->dev_addr, skb->len);
488 int tipc_bearer_mtu(struct net *net, u32 bearer_id)
491 struct tipc_bearer *b;
494 b = rcu_dereference_rtnl(tipc_net(net)->bearer_list[bearer_id]);
501 /* tipc_bearer_xmit_skb - sends buffer to destination over bearer
503 void tipc_bearer_xmit_skb(struct net *net, u32 bearer_id,
505 struct tipc_media_addr *dest)
507 struct tipc_msg *hdr = buf_msg(skb);
508 struct tipc_bearer *b;
511 b = bearer_get(net, bearer_id);
512 if (likely(b && (test_bit(0, &b->up) || msg_is_reset(hdr))))
513 b->media->send_msg(net, skb, b, dest);
519 /* tipc_bearer_xmit() -send buffer to destination over bearer
521 void tipc_bearer_xmit(struct net *net, u32 bearer_id,
522 struct sk_buff_head *xmitq,
523 struct tipc_media_addr *dst)
525 struct tipc_bearer *b;
526 struct sk_buff *skb, *tmp;
528 if (skb_queue_empty(xmitq))
532 b = bearer_get(net, bearer_id);
534 __skb_queue_purge(xmitq);
535 skb_queue_walk_safe(xmitq, skb, tmp) {
536 __skb_dequeue(xmitq);
537 if (likely(test_bit(0, &b->up) || msg_is_reset(buf_msg(skb))))
538 b->media->send_msg(net, skb, b, dst);
545 /* tipc_bearer_bc_xmit() - broadcast buffers to all destinations
547 void tipc_bearer_bc_xmit(struct net *net, u32 bearer_id,
548 struct sk_buff_head *xmitq)
550 struct tipc_net *tn = tipc_net(net);
551 int net_id = tn->net_id;
552 struct tipc_bearer *b;
553 struct sk_buff *skb, *tmp;
554 struct tipc_msg *hdr;
557 b = bearer_get(net, bearer_id);
558 if (unlikely(!b || !test_bit(0, &b->up)))
559 __skb_queue_purge(xmitq);
560 skb_queue_walk_safe(xmitq, skb, tmp) {
562 msg_set_non_seq(hdr, 1);
563 msg_set_mc_netid(hdr, net_id);
564 __skb_dequeue(xmitq);
565 b->media->send_msg(net, skb, b, &b->bcast_addr);
571 * tipc_l2_rcv_msg - handle incoming TIPC message from an interface
572 * @buf: the received packet
573 * @dev: the net device that the packet was received on
574 * @pt: the packet_type structure which was used to register this handler
575 * @orig_dev: the original receive net device in case the device is a bond
577 * Accept only packets explicitly sent to this node, or broadcast packets;
578 * ignores packets sent using interface multicast, and traffic sent to other
579 * nodes (which can happen if interface is running in promiscuous mode).
581 static int tipc_l2_rcv_msg(struct sk_buff *skb, struct net_device *dev,
582 struct packet_type *pt, struct net_device *orig_dev)
584 struct tipc_bearer *b;
587 b = rcu_dereference_rtnl(dev->tipc_ptr);
588 if (likely(b && test_bit(0, &b->up) &&
589 (skb->pkt_type <= PACKET_BROADCAST))) {
591 tipc_rcv(dev_net(dev), skb, b);
593 return NET_RX_SUCCESS;
601 * tipc_l2_device_event - handle device events from network device
602 * @nb: the context of the notification
603 * @evt: the type of event
604 * @ptr: the net device that the event was on
606 * This function is called by the Ethernet driver in case of link
609 static int tipc_l2_device_event(struct notifier_block *nb, unsigned long evt,
612 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
613 struct net *net = dev_net(dev);
614 struct tipc_bearer *b;
616 b = rtnl_dereference(dev->tipc_ptr);
622 if (netif_carrier_ok(dev))
625 test_and_set_bit_lock(0, &b->up);
627 case NETDEV_GOING_DOWN:
628 clear_bit_unlock(0, &b->up);
629 tipc_reset_bearer(net, b);
631 case NETDEV_CHANGEMTU:
632 if (tipc_mtu_bad(dev, 0)) {
633 bearer_disable(net, b);
637 tipc_reset_bearer(net, b);
639 case NETDEV_CHANGEADDR:
640 b->media->raw2addr(b, &b->addr,
641 (char *)dev->dev_addr);
642 tipc_reset_bearer(net, b);
644 case NETDEV_UNREGISTER:
645 case NETDEV_CHANGENAME:
646 bearer_disable(dev_net(dev), b);
652 static struct packet_type tipc_packet_type __read_mostly = {
653 .type = htons(ETH_P_TIPC),
654 .func = tipc_l2_rcv_msg,
657 static struct notifier_block notifier = {
658 .notifier_call = tipc_l2_device_event,
662 int tipc_bearer_setup(void)
666 err = register_netdevice_notifier(¬ifier);
669 dev_add_pack(&tipc_packet_type);
673 void tipc_bearer_cleanup(void)
675 unregister_netdevice_notifier(¬ifier);
676 dev_remove_pack(&tipc_packet_type);
679 void tipc_bearer_stop(struct net *net)
681 struct tipc_net *tn = net_generic(net, tipc_net_id);
682 struct tipc_bearer *b;
685 for (i = 0; i < MAX_BEARERS; i++) {
686 b = rtnl_dereference(tn->bearer_list[i]);
688 bearer_disable(net, b);
689 tn->bearer_list[i] = NULL;
694 /* Caller should hold rtnl_lock to protect the bearer */
695 static int __tipc_nl_add_bearer(struct tipc_nl_msg *msg,
696 struct tipc_bearer *bearer, int nlflags)
699 struct nlattr *attrs;
702 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
703 nlflags, TIPC_NL_BEARER_GET);
707 attrs = nla_nest_start(msg->skb, TIPC_NLA_BEARER);
711 if (nla_put_string(msg->skb, TIPC_NLA_BEARER_NAME, bearer->name))
714 prop = nla_nest_start(msg->skb, TIPC_NLA_BEARER_PROP);
717 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, bearer->priority))
719 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, bearer->tolerance))
721 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, bearer->window))
724 nla_nest_end(msg->skb, prop);
726 #ifdef CONFIG_TIPC_MEDIA_UDP
727 if (bearer->media->type_id == TIPC_MEDIA_TYPE_UDP) {
728 if (tipc_udp_nl_add_bearer_data(msg, bearer))
733 nla_nest_end(msg->skb, attrs);
734 genlmsg_end(msg->skb, hdr);
739 nla_nest_cancel(msg->skb, prop);
741 nla_nest_cancel(msg->skb, attrs);
743 genlmsg_cancel(msg->skb, hdr);
748 int tipc_nl_bearer_dump(struct sk_buff *skb, struct netlink_callback *cb)
752 struct tipc_bearer *bearer;
753 struct tipc_nl_msg msg;
754 struct net *net = sock_net(skb->sk);
755 struct tipc_net *tn = net_generic(net, tipc_net_id);
757 if (i == MAX_BEARERS)
761 msg.portid = NETLINK_CB(cb->skb).portid;
762 msg.seq = cb->nlh->nlmsg_seq;
765 for (i = 0; i < MAX_BEARERS; i++) {
766 bearer = rtnl_dereference(tn->bearer_list[i]);
770 err = __tipc_nl_add_bearer(&msg, bearer, NLM_F_MULTI);
780 int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info)
785 struct tipc_bearer *bearer;
786 struct tipc_nl_msg msg;
787 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
788 struct net *net = genl_info_net(info);
790 if (!info->attrs[TIPC_NLA_BEARER])
793 err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX,
794 info->attrs[TIPC_NLA_BEARER],
795 tipc_nl_bearer_policy);
799 if (!attrs[TIPC_NLA_BEARER_NAME])
801 name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
803 rep = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
808 msg.portid = info->snd_portid;
809 msg.seq = info->snd_seq;
812 bearer = tipc_bearer_find(net, name);
818 err = __tipc_nl_add_bearer(&msg, bearer, 0);
823 return genlmsg_reply(rep, info);
831 int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info)
835 struct tipc_bearer *bearer;
836 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
837 struct net *net = sock_net(skb->sk);
839 if (!info->attrs[TIPC_NLA_BEARER])
842 err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX,
843 info->attrs[TIPC_NLA_BEARER],
844 tipc_nl_bearer_policy);
848 if (!attrs[TIPC_NLA_BEARER_NAME])
851 name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
854 bearer = tipc_bearer_find(net, name);
860 bearer_disable(net, bearer);
866 int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info)
870 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
871 struct net *net = sock_net(skb->sk);
872 struct tipc_net *tn = net_generic(net, tipc_net_id);
876 prio = TIPC_MEDIA_LINK_PRI;
877 domain = tn->own_addr & TIPC_ZONE_CLUSTER_MASK;
879 if (!info->attrs[TIPC_NLA_BEARER])
882 err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX,
883 info->attrs[TIPC_NLA_BEARER],
884 tipc_nl_bearer_policy);
888 if (!attrs[TIPC_NLA_BEARER_NAME])
891 bearer = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
893 if (attrs[TIPC_NLA_BEARER_DOMAIN])
894 domain = nla_get_u32(attrs[TIPC_NLA_BEARER_DOMAIN]);
896 if (attrs[TIPC_NLA_BEARER_PROP]) {
897 struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
899 err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_BEARER_PROP],
904 if (props[TIPC_NLA_PROP_PRIO])
905 prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
909 err = tipc_enable_bearer(net, bearer, domain, prio, attrs);
919 int tipc_nl_bearer_add(struct sk_buff *skb, struct genl_info *info)
923 struct tipc_bearer *b;
924 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
925 struct net *net = sock_net(skb->sk);
927 if (!info->attrs[TIPC_NLA_BEARER])
930 err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX,
931 info->attrs[TIPC_NLA_BEARER],
932 tipc_nl_bearer_policy);
936 if (!attrs[TIPC_NLA_BEARER_NAME])
938 name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
941 b = tipc_bearer_find(net, name);
947 #ifdef CONFIG_TIPC_MEDIA_UDP
948 if (attrs[TIPC_NLA_BEARER_UDP_OPTS]) {
949 err = tipc_udp_nl_bearer_add(b,
950 attrs[TIPC_NLA_BEARER_UDP_OPTS]);
962 int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info)
966 struct tipc_bearer *b;
967 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
968 struct net *net = sock_net(skb->sk);
970 if (!info->attrs[TIPC_NLA_BEARER])
973 err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX,
974 info->attrs[TIPC_NLA_BEARER],
975 tipc_nl_bearer_policy);
979 if (!attrs[TIPC_NLA_BEARER_NAME])
981 name = nla_data(attrs[TIPC_NLA_BEARER_NAME]);
984 b = tipc_bearer_find(net, name);
990 if (attrs[TIPC_NLA_BEARER_PROP]) {
991 struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
993 err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_BEARER_PROP],
1000 if (props[TIPC_NLA_PROP_TOL])
1001 b->tolerance = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
1002 if (props[TIPC_NLA_PROP_PRIO])
1003 b->priority = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
1004 if (props[TIPC_NLA_PROP_WIN])
1005 b->window = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
1012 static int __tipc_nl_add_media(struct tipc_nl_msg *msg,
1013 struct tipc_media *media, int nlflags)
1016 struct nlattr *attrs;
1017 struct nlattr *prop;
1019 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
1020 nlflags, TIPC_NL_MEDIA_GET);
1024 attrs = nla_nest_start(msg->skb, TIPC_NLA_MEDIA);
1028 if (nla_put_string(msg->skb, TIPC_NLA_MEDIA_NAME, media->name))
1031 prop = nla_nest_start(msg->skb, TIPC_NLA_MEDIA_PROP);
1034 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, media->priority))
1036 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, media->tolerance))
1038 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, media->window))
1041 nla_nest_end(msg->skb, prop);
1042 nla_nest_end(msg->skb, attrs);
1043 genlmsg_end(msg->skb, hdr);
1048 nla_nest_cancel(msg->skb, prop);
1050 nla_nest_cancel(msg->skb, attrs);
1052 genlmsg_cancel(msg->skb, hdr);
1057 int tipc_nl_media_dump(struct sk_buff *skb, struct netlink_callback *cb)
1060 int i = cb->args[0];
1061 struct tipc_nl_msg msg;
1067 msg.portid = NETLINK_CB(cb->skb).portid;
1068 msg.seq = cb->nlh->nlmsg_seq;
1071 for (; media_info_array[i] != NULL; i++) {
1072 err = __tipc_nl_add_media(&msg, media_info_array[i],
1083 int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info)
1087 struct tipc_nl_msg msg;
1088 struct tipc_media *media;
1089 struct sk_buff *rep;
1090 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
1092 if (!info->attrs[TIPC_NLA_MEDIA])
1095 err = nla_parse_nested(attrs, TIPC_NLA_MEDIA_MAX,
1096 info->attrs[TIPC_NLA_MEDIA],
1097 tipc_nl_media_policy);
1101 if (!attrs[TIPC_NLA_MEDIA_NAME])
1103 name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]);
1105 rep = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1110 msg.portid = info->snd_portid;
1111 msg.seq = info->snd_seq;
1114 media = tipc_media_find(name);
1120 err = __tipc_nl_add_media(&msg, media, 0);
1125 return genlmsg_reply(rep, info);
1133 int tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
1137 struct tipc_media *m;
1138 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
1140 if (!info->attrs[TIPC_NLA_MEDIA])
1143 err = nla_parse_nested(attrs, TIPC_NLA_MEDIA_MAX,
1144 info->attrs[TIPC_NLA_MEDIA],
1145 tipc_nl_media_policy);
1147 if (!attrs[TIPC_NLA_MEDIA_NAME])
1149 name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]);
1152 m = tipc_media_find(name);
1158 if (attrs[TIPC_NLA_MEDIA_PROP]) {
1159 struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
1161 err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_MEDIA_PROP],
1168 if (props[TIPC_NLA_PROP_TOL])
1169 m->tolerance = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
1170 if (props[TIPC_NLA_PROP_PRIO])
1171 m->priority = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
1172 if (props[TIPC_NLA_PROP_WIN])
1173 m->window = nla_get_u32(props[TIPC_NLA_PROP_WIN]);