1 /* net/tipc/udp_media.c: IP bearer support for TIPC
3 * Copyright (c) 2015, Ericsson AB
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the names of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * Alternatively, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") version 2 as published by the Free
20 * Software Foundation.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
35 #include <linux/socket.h>
37 #include <linux/udp.h>
38 #include <linux/inet.h>
39 #include <linux/inetdevice.h>
40 #include <linux/igmp.h>
41 #include <linux/kernel.h>
42 #include <linux/workqueue.h>
43 #include <linux/list.h>
46 #include <net/udp_tunnel.h>
47 #include <net/addrconf.h>
48 #include <linux/tipc_netlink.h>
56 /* IANA assigned UDP port */
57 #define UDP_PORT_DEFAULT 6118
59 #define UDP_MIN_HEADROOM 48
62 * struct udp_media_addr - IP/UDP addressing information
64 * This is the bearer level originating address used in neighbor discovery
65 * messages, and all fields should be in network byte order
67 struct udp_media_addr
{
76 /* struct udp_replicast - container for UDP remote addresses */
77 struct udp_replicast
{
78 struct udp_media_addr addr
;
80 struct list_head list
;
84 * struct udp_bearer - ip/udp bearer data structure
85 * @bearer: associated generic tipc bearer
86 * @ubsock: bearer associated socket
87 * @ifindex: local address scope
88 * @work: used to schedule deferred work on a bearer
91 struct tipc_bearer __rcu
*bearer
;
92 struct socket
*ubsock
;
94 struct work_struct work
;
95 struct udp_replicast rcast
;
98 static int tipc_udp_is_mcast_addr(struct udp_media_addr
*addr
)
100 if (ntohs(addr
->proto
) == ETH_P_IP
)
101 return ipv4_is_multicast(addr
->ipv4
.s_addr
);
102 #if IS_ENABLED(CONFIG_IPV6)
104 return ipv6_addr_is_multicast(&addr
->ipv6
);
109 /* udp_media_addr_set - convert a ip/udp address to a TIPC media address */
110 static void tipc_udp_media_addr_set(struct tipc_media_addr
*addr
,
111 struct udp_media_addr
*ua
)
113 memset(addr
, 0, sizeof(struct tipc_media_addr
));
114 addr
->media_id
= TIPC_MEDIA_TYPE_UDP
;
115 memcpy(addr
->value
, ua
, sizeof(struct udp_media_addr
));
117 if (tipc_udp_is_mcast_addr(ua
))
118 addr
->broadcast
= TIPC_BROADCAST_SUPPORT
;
121 /* tipc_udp_addr2str - convert ip/udp address to string */
122 static int tipc_udp_addr2str(struct tipc_media_addr
*a
, char *buf
, int size
)
124 struct udp_media_addr
*ua
= (struct udp_media_addr
*)&a
->value
;
126 if (ntohs(ua
->proto
) == ETH_P_IP
)
127 snprintf(buf
, size
, "%pI4:%u", &ua
->ipv4
, ntohs(ua
->port
));
128 else if (ntohs(ua
->proto
) == ETH_P_IPV6
)
129 snprintf(buf
, size
, "%pI6:%u", &ua
->ipv6
, ntohs(ua
->port
));
131 pr_err("Invalid UDP media address\n");
135 /* tipc_udp_msg2addr - extract an ip/udp address from a TIPC ndisc message */
136 static int tipc_udp_msg2addr(struct tipc_bearer
*b
, struct tipc_media_addr
*a
,
139 struct udp_media_addr
*ua
;
141 ua
= (struct udp_media_addr
*) (msg
+ TIPC_MEDIA_ADDR_OFFSET
);
142 if (msg
[TIPC_MEDIA_TYPE_OFFSET
] != TIPC_MEDIA_TYPE_UDP
)
144 tipc_udp_media_addr_set(a
, ua
);
148 /* tipc_udp_addr2msg - write an ip/udp address to a TIPC ndisc message */
149 static int tipc_udp_addr2msg(char *msg
, struct tipc_media_addr
*a
)
151 memset(msg
, 0, TIPC_MEDIA_INFO_SIZE
);
152 msg
[TIPC_MEDIA_TYPE_OFFSET
] = TIPC_MEDIA_TYPE_UDP
;
153 memcpy(msg
+ TIPC_MEDIA_ADDR_OFFSET
, a
->value
,
154 sizeof(struct udp_media_addr
));
158 /* tipc_send_msg - enqueue a send request */
159 static int tipc_udp_xmit(struct net
*net
, struct sk_buff
*skb
,
160 struct udp_bearer
*ub
, struct udp_media_addr
*src
,
161 struct udp_media_addr
*dst
)
166 if (dst
->proto
== htons(ETH_P_IP
)) {
168 .daddr
= dst
->ipv4
.s_addr
,
169 .saddr
= src
->ipv4
.s_addr
,
170 .flowi4_mark
= skb
->mark
,
171 .flowi4_proto
= IPPROTO_UDP
173 rt
= ip_route_output_key(net
, &fl
);
179 skb
->dev
= rt
->dst
.dev
;
180 ttl
= ip4_dst_hoplimit(&rt
->dst
);
181 udp_tunnel_xmit_skb(rt
, ub
->ubsock
->sk
, skb
, src
->ipv4
.s_addr
,
182 dst
->ipv4
.s_addr
, 0, ttl
, 0, src
->port
,
183 dst
->port
, false, true);
184 #if IS_ENABLED(CONFIG_IPV6)
186 struct dst_entry
*ndst
;
187 struct flowi6 fl6
= {
188 .flowi6_oif
= ub
->ifindex
,
191 .flowi6_proto
= IPPROTO_UDP
193 err
= ipv6_stub
->ipv6_dst_lookup(net
, ub
->ubsock
->sk
, &ndst
,
197 ttl
= ip6_dst_hoplimit(ndst
);
198 err
= udp_tunnel6_xmit_skb(ndst
, ub
->ubsock
->sk
, skb
,
199 ndst
->dev
, &src
->ipv6
,
200 &dst
->ipv6
, 0, ttl
, 0, src
->port
,
211 static int tipc_udp_send_msg(struct net
*net
, struct sk_buff
*skb
,
212 struct tipc_bearer
*b
,
213 struct tipc_media_addr
*addr
)
215 struct udp_media_addr
*src
= (struct udp_media_addr
*)&b
->addr
.value
;
216 struct udp_media_addr
*dst
= (struct udp_media_addr
*)&addr
->value
;
217 struct udp_replicast
*rcast
;
218 struct udp_bearer
*ub
;
221 if (skb_headroom(skb
) < UDP_MIN_HEADROOM
) {
222 err
= pskb_expand_head(skb
, UDP_MIN_HEADROOM
, 0, GFP_ATOMIC
);
227 skb_set_inner_protocol(skb
, htons(ETH_P_TIPC
));
228 ub
= rcu_dereference_rtnl(b
->media_ptr
);
234 if (addr
->broadcast
!= TIPC_REPLICAST_SUPPORT
)
235 return tipc_udp_xmit(net
, skb
, ub
, src
, dst
);
237 /* Replicast, send an skb to each configured IP address */
238 list_for_each_entry_rcu(rcast
, &ub
->rcast
.list
, list
) {
239 struct sk_buff
*_skb
;
241 _skb
= pskb_copy(skb
, GFP_ATOMIC
);
247 err
= tipc_udp_xmit(net
, _skb
, ub
, src
, &rcast
->addr
);
257 static bool tipc_udp_is_known_peer(struct tipc_bearer
*b
,
258 struct udp_media_addr
*addr
)
260 struct udp_replicast
*rcast
, *tmp
;
261 struct udp_bearer
*ub
;
263 ub
= rcu_dereference_rtnl(b
->media_ptr
);
265 pr_err_ratelimited("UDP bearer instance not found\n");
269 list_for_each_entry_safe(rcast
, tmp
, &ub
->rcast
.list
, list
) {
270 if (!memcmp(&rcast
->addr
, addr
, sizeof(struct udp_media_addr
)))
277 static int tipc_udp_rcast_add(struct tipc_bearer
*b
,
278 struct udp_media_addr
*addr
)
280 struct udp_replicast
*rcast
;
281 struct udp_bearer
*ub
;
283 ub
= rcu_dereference_rtnl(b
->media_ptr
);
287 rcast
= kmalloc(sizeof(*rcast
), GFP_ATOMIC
);
291 memcpy(&rcast
->addr
, addr
, sizeof(struct udp_media_addr
));
293 if (ntohs(addr
->proto
) == ETH_P_IP
)
294 pr_info("New replicast peer: %pI4\n", &rcast
->addr
.ipv4
);
295 #if IS_ENABLED(CONFIG_IPV6)
296 else if (ntohs(addr
->proto
) == ETH_P_IPV6
)
297 pr_info("New replicast peer: %pI6\n", &rcast
->addr
.ipv6
);
299 b
->bcast_addr
.broadcast
= TIPC_REPLICAST_SUPPORT
;
300 list_add_rcu(&rcast
->list
, &ub
->rcast
.list
);
304 static int tipc_udp_rcast_disc(struct tipc_bearer
*b
, struct sk_buff
*skb
)
306 struct udp_media_addr src
= {0};
307 struct udp_media_addr
*dst
;
309 dst
= (struct udp_media_addr
*)&b
->bcast_addr
.value
;
310 if (tipc_udp_is_mcast_addr(dst
))
313 src
.port
= udp_hdr(skb
)->source
;
315 if (ip_hdr(skb
)->version
== 4) {
316 struct iphdr
*iphdr
= ip_hdr(skb
);
318 src
.proto
= htons(ETH_P_IP
);
319 src
.ipv4
.s_addr
= iphdr
->saddr
;
320 if (ipv4_is_multicast(iphdr
->daddr
))
322 #if IS_ENABLED(CONFIG_IPV6)
323 } else if (ip_hdr(skb
)->version
== 6) {
324 struct ipv6hdr
*iphdr
= ipv6_hdr(skb
);
326 src
.proto
= htons(ETH_P_IPV6
);
327 src
.ipv6
= iphdr
->saddr
;
328 if (ipv6_addr_is_multicast(&iphdr
->daddr
))
335 if (likely(tipc_udp_is_known_peer(b
, &src
)))
338 return tipc_udp_rcast_add(b
, &src
);
341 /* tipc_udp_recv - read data from bearer socket */
342 static int tipc_udp_recv(struct sock
*sk
, struct sk_buff
*skb
)
344 struct udp_bearer
*ub
;
345 struct tipc_bearer
*b
;
346 struct tipc_msg
*hdr
;
349 ub
= rcu_dereference_sk_user_data(sk
);
351 pr_err_ratelimited("Failed to get UDP bearer reference");
354 skb_pull(skb
, sizeof(struct udphdr
));
358 b
= rcu_dereference_rtnl(ub
->bearer
);
362 if (b
&& test_bit(0, &b
->up
)) {
363 tipc_rcv(sock_net(sk
), skb
, b
);
368 if (unlikely(msg_user(hdr
) == LINK_CONFIG
)) {
369 err
= tipc_udp_rcast_disc(b
, skb
);
381 static int enable_mcast(struct udp_bearer
*ub
, struct udp_media_addr
*remote
)
384 struct ip_mreqn mreqn
;
385 struct sock
*sk
= ub
->ubsock
->sk
;
387 if (ntohs(remote
->proto
) == ETH_P_IP
) {
388 mreqn
.imr_multiaddr
= remote
->ipv4
;
389 mreqn
.imr_ifindex
= ub
->ifindex
;
390 err
= ip_mc_join_group(sk
, &mreqn
);
391 #if IS_ENABLED(CONFIG_IPV6)
393 err
= ipv6_stub
->ipv6_sock_mc_join(sk
, ub
->ifindex
,
400 static int __tipc_nl_add_udp_addr(struct sk_buff
*skb
,
401 struct udp_media_addr
*addr
, int nla_t
)
403 if (ntohs(addr
->proto
) == ETH_P_IP
) {
404 struct sockaddr_in ip4
;
406 memset(&ip4
, 0, sizeof(ip4
));
407 ip4
.sin_family
= AF_INET
;
408 ip4
.sin_port
= addr
->port
;
409 ip4
.sin_addr
.s_addr
= addr
->ipv4
.s_addr
;
410 if (nla_put(skb
, nla_t
, sizeof(ip4
), &ip4
))
413 #if IS_ENABLED(CONFIG_IPV6)
414 } else if (ntohs(addr
->proto
) == ETH_P_IPV6
) {
415 struct sockaddr_in6 ip6
;
417 memset(&ip6
, 0, sizeof(ip6
));
418 ip6
.sin6_family
= AF_INET6
;
419 ip6
.sin6_port
= addr
->port
;
420 memcpy(&ip6
.sin6_addr
, &addr
->ipv6
, sizeof(struct in6_addr
));
421 if (nla_put(skb
, nla_t
, sizeof(ip6
), &ip6
))
429 int tipc_udp_nl_dump_remoteip(struct sk_buff
*skb
, struct netlink_callback
*cb
)
431 u32 bid
= cb
->args
[0];
432 u32 skip_cnt
= cb
->args
[1];
433 u32 portid
= NETLINK_CB(cb
->skb
).portid
;
434 struct udp_replicast
*rcast
, *tmp
;
435 struct tipc_bearer
*b
;
436 struct udp_bearer
*ub
;
441 if (!bid
&& !skip_cnt
) {
442 struct net
*net
= sock_net(skb
->sk
);
443 struct nlattr
*battrs
[TIPC_NLA_BEARER_MAX
+ 1];
444 struct nlattr
**attrs
;
447 err
= tipc_nlmsg_parse(cb
->nlh
, &attrs
);
451 if (!attrs
[TIPC_NLA_BEARER
])
454 err
= nla_parse_nested(battrs
, TIPC_NLA_BEARER_MAX
,
455 attrs
[TIPC_NLA_BEARER
],
456 tipc_nl_bearer_policy
, NULL
);
460 if (!battrs
[TIPC_NLA_BEARER_NAME
])
463 bname
= nla_data(battrs
[TIPC_NLA_BEARER_NAME
]);
466 b
= tipc_bearer_find(net
, bname
);
473 struct net
*net
= sock_net(skb
->sk
);
474 struct tipc_net
*tn
= net_generic(net
, tipc_net_id
);
477 b
= rtnl_dereference(tn
->bearer_list
[bid
]);
484 ub
= rcu_dereference_rtnl(b
->media_ptr
);
491 list_for_each_entry_safe(rcast
, tmp
, &ub
->rcast
.list
, list
) {
495 hdr
= genlmsg_put(skb
, portid
, cb
->nlh
->nlmsg_seq
,
496 &tipc_genl_family
, NLM_F_MULTI
,
501 err
= __tipc_nl_add_udp_addr(skb
, &rcast
->addr
,
502 TIPC_NLA_UDP_REMOTE
);
504 genlmsg_cancel(skb
, hdr
);
507 genlmsg_end(skb
, hdr
);
519 int tipc_udp_nl_add_bearer_data(struct tipc_nl_msg
*msg
, struct tipc_bearer
*b
)
521 struct udp_media_addr
*src
= (struct udp_media_addr
*)&b
->addr
.value
;
522 struct udp_media_addr
*dst
;
523 struct udp_bearer
*ub
;
526 ub
= rcu_dereference_rtnl(b
->media_ptr
);
530 nest
= nla_nest_start(msg
->skb
, TIPC_NLA_BEARER_UDP_OPTS
);
534 if (__tipc_nl_add_udp_addr(msg
->skb
, src
, TIPC_NLA_UDP_LOCAL
))
537 dst
= (struct udp_media_addr
*)&b
->bcast_addr
.value
;
538 if (__tipc_nl_add_udp_addr(msg
->skb
, dst
, TIPC_NLA_UDP_REMOTE
))
541 if (!list_empty(&ub
->rcast
.list
)) {
542 if (nla_put_flag(msg
->skb
, TIPC_NLA_UDP_MULTI_REMOTEIP
))
546 nla_nest_end(msg
->skb
, nest
);
549 nla_nest_cancel(msg
->skb
, nest
);
554 * tipc_parse_udp_addr - build udp media address from netlink data
555 * @nlattr: netlink attribute containing sockaddr storage aligned address
556 * @addr: tipc media address to fill with address, port and protocol type
557 * @scope_id: IPv6 scope id pointer, not NULL indicates it's required
560 static int tipc_parse_udp_addr(struct nlattr
*nla
, struct udp_media_addr
*addr
,
563 struct sockaddr_storage sa
;
565 nla_memcpy(&sa
, nla
, sizeof(sa
));
566 if (sa
.ss_family
== AF_INET
) {
567 struct sockaddr_in
*ip4
= (struct sockaddr_in
*)&sa
;
569 addr
->proto
= htons(ETH_P_IP
);
570 addr
->port
= ip4
->sin_port
;
571 addr
->ipv4
.s_addr
= ip4
->sin_addr
.s_addr
;
574 #if IS_ENABLED(CONFIG_IPV6)
575 } else if (sa
.ss_family
== AF_INET6
) {
576 struct sockaddr_in6
*ip6
= (struct sockaddr_in6
*)&sa
;
578 addr
->proto
= htons(ETH_P_IPV6
);
579 addr
->port
= ip6
->sin6_port
;
580 memcpy(&addr
->ipv6
, &ip6
->sin6_addr
, sizeof(struct in6_addr
));
582 /* Scope ID is only interesting for local addresses */
586 atype
= ipv6_addr_type(&ip6
->sin6_addr
);
587 if (__ipv6_addr_needs_scope_id(atype
) &&
588 !ip6
->sin6_scope_id
) {
592 *scope_id
= ip6
->sin6_scope_id
? : 0;
598 return -EADDRNOTAVAIL
;
601 int tipc_udp_nl_bearer_add(struct tipc_bearer
*b
, struct nlattr
*attr
)
604 struct udp_media_addr addr
= {0};
605 struct nlattr
*opts
[TIPC_NLA_UDP_MAX
+ 1];
606 struct udp_media_addr
*dst
;
608 if (nla_parse_nested(opts
, TIPC_NLA_UDP_MAX
, attr
,
609 tipc_nl_udp_policy
, NULL
))
612 if (!opts
[TIPC_NLA_UDP_REMOTE
])
615 err
= tipc_parse_udp_addr(opts
[TIPC_NLA_UDP_REMOTE
], &addr
, NULL
);
619 dst
= (struct udp_media_addr
*)&b
->bcast_addr
.value
;
620 if (tipc_udp_is_mcast_addr(dst
)) {
621 pr_err("Can't add remote ip to TIPC UDP multicast bearer\n");
625 if (tipc_udp_is_known_peer(b
, &addr
))
628 return tipc_udp_rcast_add(b
, &addr
);
632 * tipc_udp_enable - callback to create a new udp bearer instance
633 * @net: network namespace
634 * @b: pointer to generic tipc_bearer
635 * @attrs: netlink bearer configuration
637 * validate the bearer parameters and initialize the udp bearer
638 * rtnl_lock should be held
640 static int tipc_udp_enable(struct net
*net
, struct tipc_bearer
*b
,
641 struct nlattr
*attrs
[])
644 struct udp_bearer
*ub
;
645 struct udp_media_addr remote
= {0};
646 struct udp_media_addr local
= {0};
647 struct udp_port_cfg udp_conf
= {0};
648 struct udp_tunnel_sock_cfg tuncfg
= {NULL
};
649 struct nlattr
*opts
[TIPC_NLA_UDP_MAX
+ 1];
650 u8 node_id
[NODE_ID_LEN
] = {0,};
653 ub
= kzalloc(sizeof(*ub
), GFP_ATOMIC
);
657 INIT_LIST_HEAD(&ub
->rcast
.list
);
659 if (!attrs
[TIPC_NLA_BEARER_UDP_OPTS
])
662 if (nla_parse_nested(opts
, TIPC_NLA_UDP_MAX
,
663 attrs
[TIPC_NLA_BEARER_UDP_OPTS
],
664 tipc_nl_udp_policy
, NULL
))
667 if (!opts
[TIPC_NLA_UDP_LOCAL
] || !opts
[TIPC_NLA_UDP_REMOTE
]) {
668 pr_err("Invalid UDP bearer configuration");
673 err
= tipc_parse_udp_addr(opts
[TIPC_NLA_UDP_LOCAL
], &local
,
678 err
= tipc_parse_udp_addr(opts
[TIPC_NLA_UDP_REMOTE
], &remote
, NULL
);
682 if (remote
.proto
!= local
.proto
) {
687 /* Checking remote ip address */
688 rmcast
= tipc_udp_is_mcast_addr(&remote
);
690 /* Autoconfigure own node identity if needed */
691 if (!tipc_own_id(net
)) {
692 memcpy(node_id
, local
.ipv6
.in6_u
.u6_addr8
, 16);
693 tipc_net_init(net
, node_id
, 0);
695 if (!tipc_own_id(net
)) {
696 pr_warn("Failed to set node id, please configure manually\n");
701 b
->bcast_addr
.media_id
= TIPC_MEDIA_TYPE_UDP
;
702 b
->bcast_addr
.broadcast
= TIPC_BROADCAST_SUPPORT
;
703 rcu_assign_pointer(b
->media_ptr
, ub
);
704 rcu_assign_pointer(ub
->bearer
, b
);
705 tipc_udp_media_addr_set(&b
->addr
, &local
);
706 if (local
.proto
== htons(ETH_P_IP
)) {
707 struct net_device
*dev
;
709 dev
= __ip_dev_find(net
, local
.ipv4
.s_addr
, false);
714 udp_conf
.family
= AF_INET
;
716 /* Switch to use ANY to receive packets from group */
718 udp_conf
.local_ip
.s_addr
= htonl(INADDR_ANY
);
720 udp_conf
.local_ip
.s_addr
= local
.ipv4
.s_addr
;
721 udp_conf
.use_udp_checksums
= false;
722 ub
->ifindex
= dev
->ifindex
;
723 if (tipc_mtu_bad(dev
, sizeof(struct iphdr
) +
724 sizeof(struct udphdr
))) {
728 b
->mtu
= b
->media
->mtu
;
729 #if IS_ENABLED(CONFIG_IPV6)
730 } else if (local
.proto
== htons(ETH_P_IPV6
)) {
731 udp_conf
.family
= AF_INET6
;
732 udp_conf
.use_udp6_tx_checksums
= true;
733 udp_conf
.use_udp6_rx_checksums
= true;
735 udp_conf
.local_ip6
= in6addr_any
;
737 udp_conf
.local_ip6
= local
.ipv6
;
744 udp_conf
.local_udp_port
= local
.port
;
745 err
= udp_sock_create(net
, &udp_conf
, &ub
->ubsock
);
748 tuncfg
.sk_user_data
= ub
;
749 tuncfg
.encap_type
= 1;
750 tuncfg
.encap_rcv
= tipc_udp_recv
;
751 tuncfg
.encap_destroy
= NULL
;
752 setup_udp_tunnel_sock(net
, ub
->ubsock
, &tuncfg
);
755 * The bcast media address port is used for all peers and the ip
756 * is used if it's a multicast address.
758 memcpy(&b
->bcast_addr
.value
, &remote
, sizeof(remote
));
760 err
= enable_mcast(ub
, &remote
);
762 err
= tipc_udp_rcast_add(b
, &remote
);
769 udp_tunnel_sock_release(ub
->ubsock
);
774 /* cleanup_bearer - break the socket/bearer association */
775 static void cleanup_bearer(struct work_struct
*work
)
777 struct udp_bearer
*ub
= container_of(work
, struct udp_bearer
, work
);
778 struct udp_replicast
*rcast
, *tmp
;
780 list_for_each_entry_safe(rcast
, tmp
, &ub
->rcast
.list
, list
) {
781 list_del_rcu(&rcast
->list
);
782 kfree_rcu(rcast
, rcu
);
786 udp_tunnel_sock_release(ub
->ubsock
);
791 /* tipc_udp_disable - detach bearer from socket */
792 static void tipc_udp_disable(struct tipc_bearer
*b
)
794 struct udp_bearer
*ub
;
796 ub
= rcu_dereference_rtnl(b
->media_ptr
);
798 pr_err("UDP bearer instance not found\n");
802 sock_set_flag(ub
->ubsock
->sk
, SOCK_DEAD
);
803 RCU_INIT_POINTER(ub
->bearer
, NULL
);
805 /* sock_release need to be done outside of rtnl lock */
806 INIT_WORK(&ub
->work
, cleanup_bearer
);
807 schedule_work(&ub
->work
);
810 struct tipc_media udp_media_info
= {
811 .send_msg
= tipc_udp_send_msg
,
812 .enable_media
= tipc_udp_enable
,
813 .disable_media
= tipc_udp_disable
,
814 .addr2str
= tipc_udp_addr2str
,
815 .addr2msg
= tipc_udp_addr2msg
,
816 .msg2addr
= tipc_udp_msg2addr
,
817 .priority
= TIPC_DEF_LINK_PRI
,
818 .tolerance
= TIPC_DEF_LINK_TOL
,
819 .window
= TIPC_DEF_LINK_WIN
,
820 .mtu
= TIPC_DEF_LINK_UDP_MTU
,
821 .type_id
= TIPC_MEDIA_TYPE_UDP
,