18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * net/tipc/bearer.h: Include file for TIPC bearer code 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 1996-2006, 2013-2016, Ericsson AB 58c2ecf20Sopenharmony_ci * Copyright (c) 2005, 2010-2011, Wind River Systems 68c2ecf20Sopenharmony_ci * All rights reserved. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 98c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions are met: 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 128c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 138c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 148c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 158c2ecf20Sopenharmony_ci * documentation and/or other materials provided with the distribution. 168c2ecf20Sopenharmony_ci * 3. Neither the names of the copyright holders nor the names of its 178c2ecf20Sopenharmony_ci * contributors may be used to endorse or promote products derived from 188c2ecf20Sopenharmony_ci * this software without specific prior written permission. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 218c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free 228c2ecf20Sopenharmony_ci * Software Foundation. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 258c2ecf20Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 268c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 278c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 288c2ecf20Sopenharmony_ci * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 298c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 308c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 318c2ecf20Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 328c2ecf20Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 338c2ecf20Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 348c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGE. 358c2ecf20Sopenharmony_ci */ 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#ifndef _TIPC_BEARER_H 388c2ecf20Sopenharmony_ci#define _TIPC_BEARER_H 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#include "netlink.h" 418c2ecf20Sopenharmony_ci#include "core.h" 428c2ecf20Sopenharmony_ci#include "msg.h" 438c2ecf20Sopenharmony_ci#include <net/genetlink.h> 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define MAX_MEDIA 3 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* Identifiers associated with TIPC message header media address info 488c2ecf20Sopenharmony_ci * - address info field is 32 bytes long 498c2ecf20Sopenharmony_ci * - the field's actual content and length is defined per media 508c2ecf20Sopenharmony_ci * - remaining unused bytes in the field are set to zero 518c2ecf20Sopenharmony_ci */ 528c2ecf20Sopenharmony_ci#define TIPC_MEDIA_INFO_SIZE 32 538c2ecf20Sopenharmony_ci#define TIPC_MEDIA_TYPE_OFFSET 3 548c2ecf20Sopenharmony_ci#define TIPC_MEDIA_ADDR_OFFSET 4 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci/* 578c2ecf20Sopenharmony_ci * Identifiers of supported TIPC media types 588c2ecf20Sopenharmony_ci */ 598c2ecf20Sopenharmony_ci#define TIPC_MEDIA_TYPE_ETH 1 608c2ecf20Sopenharmony_ci#define TIPC_MEDIA_TYPE_IB 2 618c2ecf20Sopenharmony_ci#define TIPC_MEDIA_TYPE_UDP 3 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/* Minimum bearer MTU */ 648c2ecf20Sopenharmony_ci#define TIPC_MIN_BEARER_MTU (MAX_H_SIZE + INT_H_SIZE) 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/* Identifiers for distinguishing between broadcast/multicast and replicast 678c2ecf20Sopenharmony_ci */ 688c2ecf20Sopenharmony_ci#define TIPC_BROADCAST_SUPPORT 1 698c2ecf20Sopenharmony_ci#define TIPC_REPLICAST_SUPPORT 2 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci/** 728c2ecf20Sopenharmony_ci * struct tipc_media_addr - destination address used by TIPC bearers 738c2ecf20Sopenharmony_ci * @value: address info (format defined by media) 748c2ecf20Sopenharmony_ci * @media_id: TIPC media type identifier 758c2ecf20Sopenharmony_ci * @broadcast: non-zero if address is a broadcast address 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_cistruct tipc_media_addr { 788c2ecf20Sopenharmony_ci u8 value[TIPC_MEDIA_INFO_SIZE]; 798c2ecf20Sopenharmony_ci u8 media_id; 808c2ecf20Sopenharmony_ci u8 broadcast; 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_cistruct tipc_bearer; 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/** 868c2ecf20Sopenharmony_ci * struct tipc_media - Media specific info exposed to generic bearer layer 878c2ecf20Sopenharmony_ci * @send_msg: routine which handles buffer transmission 888c2ecf20Sopenharmony_ci * @enable_media: routine which enables a media 898c2ecf20Sopenharmony_ci * @disable_media: routine which disables a media 908c2ecf20Sopenharmony_ci * @addr2str: convert media address format to string 918c2ecf20Sopenharmony_ci * @addr2msg: convert from media addr format to discovery msg addr format 928c2ecf20Sopenharmony_ci * @msg2addr: convert from discovery msg addr format to media addr format 938c2ecf20Sopenharmony_ci * @raw2addr: convert from raw addr format to media addr format 948c2ecf20Sopenharmony_ci * @priority: default link (and bearer) priority 958c2ecf20Sopenharmony_ci * @tolerance: default time (in ms) before declaring link failure 968c2ecf20Sopenharmony_ci * @min_win: minimum window (in packets) before declaring link congestion 978c2ecf20Sopenharmony_ci * @max_win: maximum window (in packets) before declaring link congestion 988c2ecf20Sopenharmony_ci * @mtu: max packet size bearer can support for media type not dependent on 998c2ecf20Sopenharmony_ci * underlying device MTU 1008c2ecf20Sopenharmony_ci * @type_id: TIPC media identifier 1018c2ecf20Sopenharmony_ci * @hwaddr_len: TIPC media address len 1028c2ecf20Sopenharmony_ci * @name: media name 1038c2ecf20Sopenharmony_ci */ 1048c2ecf20Sopenharmony_cistruct tipc_media { 1058c2ecf20Sopenharmony_ci int (*send_msg)(struct net *net, struct sk_buff *buf, 1068c2ecf20Sopenharmony_ci struct tipc_bearer *b, 1078c2ecf20Sopenharmony_ci struct tipc_media_addr *dest); 1088c2ecf20Sopenharmony_ci int (*enable_media)(struct net *net, struct tipc_bearer *b, 1098c2ecf20Sopenharmony_ci struct nlattr *attr[]); 1108c2ecf20Sopenharmony_ci void (*disable_media)(struct tipc_bearer *b); 1118c2ecf20Sopenharmony_ci int (*addr2str)(struct tipc_media_addr *addr, 1128c2ecf20Sopenharmony_ci char *strbuf, 1138c2ecf20Sopenharmony_ci int bufsz); 1148c2ecf20Sopenharmony_ci int (*addr2msg)(char *msg, struct tipc_media_addr *addr); 1158c2ecf20Sopenharmony_ci int (*msg2addr)(struct tipc_bearer *b, 1168c2ecf20Sopenharmony_ci struct tipc_media_addr *addr, 1178c2ecf20Sopenharmony_ci char *msg); 1188c2ecf20Sopenharmony_ci int (*raw2addr)(struct tipc_bearer *b, 1198c2ecf20Sopenharmony_ci struct tipc_media_addr *addr, 1208c2ecf20Sopenharmony_ci char *raw); 1218c2ecf20Sopenharmony_ci u32 priority; 1228c2ecf20Sopenharmony_ci u32 tolerance; 1238c2ecf20Sopenharmony_ci u32 min_win; 1248c2ecf20Sopenharmony_ci u32 max_win; 1258c2ecf20Sopenharmony_ci u32 mtu; 1268c2ecf20Sopenharmony_ci u32 type_id; 1278c2ecf20Sopenharmony_ci u32 hwaddr_len; 1288c2ecf20Sopenharmony_ci char name[TIPC_MAX_MEDIA_NAME]; 1298c2ecf20Sopenharmony_ci}; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci/** 1328c2ecf20Sopenharmony_ci * struct tipc_bearer - Generic TIPC bearer structure 1338c2ecf20Sopenharmony_ci * @media_ptr: pointer to additional media-specific information about bearer 1348c2ecf20Sopenharmony_ci * @mtu: max packet size bearer can support 1358c2ecf20Sopenharmony_ci * @addr: media-specific address associated with bearer 1368c2ecf20Sopenharmony_ci * @name: bearer name (format = media:interface) 1378c2ecf20Sopenharmony_ci * @media: ptr to media structure associated with bearer 1388c2ecf20Sopenharmony_ci * @bcast_addr: media address used in broadcasting 1398c2ecf20Sopenharmony_ci * @pt: packet type for bearer 1408c2ecf20Sopenharmony_ci * @rcu: rcu struct for tipc_bearer 1418c2ecf20Sopenharmony_ci * @priority: default link priority for bearer 1428c2ecf20Sopenharmony_ci * @min_win: minimum window (in packets) before declaring link congestion 1438c2ecf20Sopenharmony_ci * @max_win: maximum window (in packets) before declaring link congestion 1448c2ecf20Sopenharmony_ci * @tolerance: default link tolerance for bearer 1458c2ecf20Sopenharmony_ci * @domain: network domain to which links can be established 1468c2ecf20Sopenharmony_ci * @identity: array index of this bearer within TIPC bearer array 1478c2ecf20Sopenharmony_ci * @disc: ptr to link setup request 1488c2ecf20Sopenharmony_ci * @net_plane: network plane ('A' through 'H') currently associated with bearer 1498c2ecf20Sopenharmony_ci * @encap_hlen: encap headers length 1508c2ecf20Sopenharmony_ci * @up: bearer up flag (bit 0) 1518c2ecf20Sopenharmony_ci * @refcnt: tipc_bearer reference counter 1528c2ecf20Sopenharmony_ci * 1538c2ecf20Sopenharmony_ci * Note: media-specific code is responsible for initialization of the fields 1548c2ecf20Sopenharmony_ci * indicated below when a bearer is enabled; TIPC's generic bearer code takes 1558c2ecf20Sopenharmony_ci * care of initializing all other fields. 1568c2ecf20Sopenharmony_ci */ 1578c2ecf20Sopenharmony_cistruct tipc_bearer { 1588c2ecf20Sopenharmony_ci void __rcu *media_ptr; /* initalized by media */ 1598c2ecf20Sopenharmony_ci u32 mtu; /* initalized by media */ 1608c2ecf20Sopenharmony_ci struct tipc_media_addr addr; /* initalized by media */ 1618c2ecf20Sopenharmony_ci char name[TIPC_MAX_BEARER_NAME]; 1628c2ecf20Sopenharmony_ci struct tipc_media *media; 1638c2ecf20Sopenharmony_ci struct tipc_media_addr bcast_addr; 1648c2ecf20Sopenharmony_ci struct packet_type pt; 1658c2ecf20Sopenharmony_ci struct rcu_head rcu; 1668c2ecf20Sopenharmony_ci u32 priority; 1678c2ecf20Sopenharmony_ci u32 min_win; 1688c2ecf20Sopenharmony_ci u32 max_win; 1698c2ecf20Sopenharmony_ci u32 tolerance; 1708c2ecf20Sopenharmony_ci u32 domain; 1718c2ecf20Sopenharmony_ci u32 identity; 1728c2ecf20Sopenharmony_ci struct tipc_discoverer *disc; 1738c2ecf20Sopenharmony_ci char net_plane; 1748c2ecf20Sopenharmony_ci u16 encap_hlen; 1758c2ecf20Sopenharmony_ci unsigned long up; 1768c2ecf20Sopenharmony_ci refcount_t refcnt; 1778c2ecf20Sopenharmony_ci}; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_cistruct tipc_bearer_names { 1808c2ecf20Sopenharmony_ci char media_name[TIPC_MAX_MEDIA_NAME]; 1818c2ecf20Sopenharmony_ci char if_name[TIPC_MAX_IF_NAME]; 1828c2ecf20Sopenharmony_ci}; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci/* 1858c2ecf20Sopenharmony_ci * TIPC routines available to supported media types 1868c2ecf20Sopenharmony_ci */ 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_civoid tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b); 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci/* 1918c2ecf20Sopenharmony_ci * Routines made available to TIPC by supported media types 1928c2ecf20Sopenharmony_ci */ 1938c2ecf20Sopenharmony_ciextern struct tipc_media eth_media_info; 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci#ifdef CONFIG_TIPC_MEDIA_IB 1968c2ecf20Sopenharmony_ciextern struct tipc_media ib_media_info; 1978c2ecf20Sopenharmony_ci#endif 1988c2ecf20Sopenharmony_ci#ifdef CONFIG_TIPC_MEDIA_UDP 1998c2ecf20Sopenharmony_ciextern struct tipc_media udp_media_info; 2008c2ecf20Sopenharmony_ci#endif 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ciint tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info); 2038c2ecf20Sopenharmony_ciint __tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info); 2048c2ecf20Sopenharmony_ciint tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info); 2058c2ecf20Sopenharmony_ciint __tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info); 2068c2ecf20Sopenharmony_ciint tipc_nl_bearer_dump(struct sk_buff *skb, struct netlink_callback *cb); 2078c2ecf20Sopenharmony_ciint tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info); 2088c2ecf20Sopenharmony_ciint tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info); 2098c2ecf20Sopenharmony_ciint __tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info); 2108c2ecf20Sopenharmony_ciint tipc_nl_bearer_add(struct sk_buff *skb, struct genl_info *info); 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ciint tipc_nl_media_dump(struct sk_buff *skb, struct netlink_callback *cb); 2138c2ecf20Sopenharmony_ciint tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info); 2148c2ecf20Sopenharmony_ciint tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info); 2158c2ecf20Sopenharmony_ciint __tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info); 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ciint tipc_media_set_priority(const char *name, u32 new_value); 2188c2ecf20Sopenharmony_ciint tipc_media_set_window(const char *name, u32 new_value); 2198c2ecf20Sopenharmony_ciint tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); 2208c2ecf20Sopenharmony_ciint tipc_enable_l2_media(struct net *net, struct tipc_bearer *b, 2218c2ecf20Sopenharmony_ci struct nlattr *attrs[]); 2228c2ecf20Sopenharmony_cibool tipc_bearer_hold(struct tipc_bearer *b); 2238c2ecf20Sopenharmony_civoid tipc_bearer_put(struct tipc_bearer *b); 2248c2ecf20Sopenharmony_civoid tipc_disable_l2_media(struct tipc_bearer *b); 2258c2ecf20Sopenharmony_ciint tipc_l2_send_msg(struct net *net, struct sk_buff *buf, 2268c2ecf20Sopenharmony_ci struct tipc_bearer *b, struct tipc_media_addr *dest); 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_civoid tipc_bearer_add_dest(struct net *net, u32 bearer_id, u32 dest); 2298c2ecf20Sopenharmony_civoid tipc_bearer_remove_dest(struct net *net, u32 bearer_id, u32 dest); 2308c2ecf20Sopenharmony_cistruct tipc_bearer *tipc_bearer_find(struct net *net, const char *name); 2318c2ecf20Sopenharmony_ciint tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id); 2328c2ecf20Sopenharmony_cistruct tipc_media *tipc_media_find(const char *name); 2338c2ecf20Sopenharmony_ciint tipc_bearer_setup(void); 2348c2ecf20Sopenharmony_civoid tipc_bearer_cleanup(void); 2358c2ecf20Sopenharmony_civoid tipc_bearer_stop(struct net *net); 2368c2ecf20Sopenharmony_ciint tipc_bearer_mtu(struct net *net, u32 bearer_id); 2378c2ecf20Sopenharmony_ciint tipc_bearer_min_mtu(struct net *net, u32 bearer_id); 2388c2ecf20Sopenharmony_cibool tipc_bearer_bcast_support(struct net *net, u32 bearer_id); 2398c2ecf20Sopenharmony_civoid tipc_bearer_xmit_skb(struct net *net, u32 bearer_id, 2408c2ecf20Sopenharmony_ci struct sk_buff *skb, 2418c2ecf20Sopenharmony_ci struct tipc_media_addr *dest); 2428c2ecf20Sopenharmony_civoid tipc_bearer_xmit(struct net *net, u32 bearer_id, 2438c2ecf20Sopenharmony_ci struct sk_buff_head *xmitq, 2448c2ecf20Sopenharmony_ci struct tipc_media_addr *dst, 2458c2ecf20Sopenharmony_ci struct tipc_node *__dnode); 2468c2ecf20Sopenharmony_civoid tipc_bearer_bc_xmit(struct net *net, u32 bearer_id, 2478c2ecf20Sopenharmony_ci struct sk_buff_head *xmitq); 2488c2ecf20Sopenharmony_civoid tipc_clone_to_loopback(struct net *net, struct sk_buff_head *pkts); 2498c2ecf20Sopenharmony_ciint tipc_attach_loopback(struct net *net); 2508c2ecf20Sopenharmony_civoid tipc_detach_loopback(struct net *net); 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_cistatic inline void tipc_loopback_trace(struct net *net, 2538c2ecf20Sopenharmony_ci struct sk_buff_head *pkts) 2548c2ecf20Sopenharmony_ci{ 2558c2ecf20Sopenharmony_ci if (unlikely(dev_nit_active(net->loopback_dev))) 2568c2ecf20Sopenharmony_ci tipc_clone_to_loopback(net, pkts); 2578c2ecf20Sopenharmony_ci} 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci/* check if device MTU is too low for tipc headers */ 2608c2ecf20Sopenharmony_cistatic inline bool tipc_mtu_bad(struct net_device *dev, unsigned int reserve) 2618c2ecf20Sopenharmony_ci{ 2628c2ecf20Sopenharmony_ci if (dev->mtu >= TIPC_MIN_BEARER_MTU + reserve) 2638c2ecf20Sopenharmony_ci return false; 2648c2ecf20Sopenharmony_ci netdev_warn(dev, "MTU too low for tipc bearer\n"); 2658c2ecf20Sopenharmony_ci return true; 2668c2ecf20Sopenharmony_ci} 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci#endif /* _TIPC_BEARER_H */ 269