Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * net/tipc/bearer.h: Include file for TIPC bearer code
0003  *
0004  * Copyright (c) 1996-2006, 2013-2016, Ericsson AB
0005  * Copyright (c) 2005, 2010-2011, Wind River Systems
0006  * All rights reserved.
0007  *
0008  * Redistribution and use in source and binary forms, with or without
0009  * modification, are permitted provided that the following conditions are met:
0010  *
0011  * 1. Redistributions of source code must retain the above copyright
0012  *    notice, this list of conditions and the following disclaimer.
0013  * 2. Redistributions in binary form must reproduce the above copyright
0014  *    notice, this list of conditions and the following disclaimer in the
0015  *    documentation and/or other materials provided with the distribution.
0016  * 3. Neither the names of the copyright holders nor the names of its
0017  *    contributors may be used to endorse or promote products derived from
0018  *    this software without specific prior written permission.
0019  *
0020  * Alternatively, this software may be distributed under the terms of the
0021  * GNU General Public License ("GPL") version 2 as published by the Free
0022  * Software Foundation.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #ifndef _TIPC_BEARER_H
0038 #define _TIPC_BEARER_H
0039 
0040 #include "netlink.h"
0041 #include "core.h"
0042 #include "msg.h"
0043 #include <net/genetlink.h>
0044 
0045 #define MAX_MEDIA   3
0046 
0047 /* Identifiers associated with TIPC message header media address info
0048  * - address info field is 32 bytes long
0049  * - the field's actual content and length is defined per media
0050  * - remaining unused bytes in the field are set to zero
0051  */
0052 #define TIPC_MEDIA_INFO_SIZE    32
0053 #define TIPC_MEDIA_TYPE_OFFSET  3
0054 #define TIPC_MEDIA_ADDR_OFFSET  4
0055 
0056 /*
0057  * Identifiers of supported TIPC media types
0058  */
0059 #define TIPC_MEDIA_TYPE_ETH 1
0060 #define TIPC_MEDIA_TYPE_IB  2
0061 #define TIPC_MEDIA_TYPE_UDP 3
0062 
0063 /* Minimum bearer MTU */
0064 #define TIPC_MIN_BEARER_MTU (MAX_H_SIZE + INT_H_SIZE)
0065 
0066 /* Identifiers for distinguishing between broadcast/multicast and replicast
0067  */
0068 #define TIPC_BROADCAST_SUPPORT  1
0069 #define TIPC_REPLICAST_SUPPORT  2
0070 
0071 /**
0072  * struct tipc_media_addr - destination address used by TIPC bearers
0073  * @value: address info (format defined by media)
0074  * @media_id: TIPC media type identifier
0075  * @broadcast: non-zero if address is a broadcast address
0076  */
0077 struct tipc_media_addr {
0078     u8 value[TIPC_MEDIA_INFO_SIZE];
0079     u8 media_id;
0080     u8 broadcast;
0081 };
0082 
0083 struct tipc_bearer;
0084 
0085 /**
0086  * struct tipc_media - Media specific info exposed to generic bearer layer
0087  * @send_msg: routine which handles buffer transmission
0088  * @enable_media: routine which enables a media
0089  * @disable_media: routine which disables a media
0090  * @addr2str: convert media address format to string
0091  * @addr2msg: convert from media addr format to discovery msg addr format
0092  * @msg2addr: convert from discovery msg addr format to media addr format
0093  * @raw2addr: convert from raw addr format to media addr format
0094  * @priority: default link (and bearer) priority
0095  * @tolerance: default time (in ms) before declaring link failure
0096  * @min_win: minimum window (in packets) before declaring link congestion
0097  * @max_win: maximum window (in packets) before declaring link congestion
0098  * @mtu: max packet size bearer can support for media type not dependent on
0099  * underlying device MTU
0100  * @type_id: TIPC media identifier
0101  * @hwaddr_len: TIPC media address len
0102  * @name: media name
0103  */
0104 struct tipc_media {
0105     int (*send_msg)(struct net *net, struct sk_buff *buf,
0106             struct tipc_bearer *b,
0107             struct tipc_media_addr *dest);
0108     int (*enable_media)(struct net *net, struct tipc_bearer *b,
0109                 struct nlattr *attr[]);
0110     void (*disable_media)(struct tipc_bearer *b);
0111     int (*addr2str)(struct tipc_media_addr *addr,
0112             char *strbuf,
0113             int bufsz);
0114     int (*addr2msg)(char *msg, struct tipc_media_addr *addr);
0115     int (*msg2addr)(struct tipc_bearer *b,
0116             struct tipc_media_addr *addr,
0117             char *msg);
0118     int (*raw2addr)(struct tipc_bearer *b,
0119             struct tipc_media_addr *addr,
0120             const char *raw);
0121     u32 priority;
0122     u32 tolerance;
0123     u32 min_win;
0124     u32 max_win;
0125     u32 mtu;
0126     u32 type_id;
0127     u32 hwaddr_len;
0128     char name[TIPC_MAX_MEDIA_NAME];
0129 };
0130 
0131 /**
0132  * struct tipc_bearer - Generic TIPC bearer structure
0133  * @media_ptr: pointer to additional media-specific information about bearer
0134  * @mtu: max packet size bearer can support
0135  * @addr: media-specific address associated with bearer
0136  * @name: bearer name (format = media:interface)
0137  * @media: ptr to media structure associated with bearer
0138  * @bcast_addr: media address used in broadcasting
0139  * @pt: packet type for bearer
0140  * @rcu: rcu struct for tipc_bearer
0141  * @priority: default link priority for bearer
0142  * @min_win: minimum window (in packets) before declaring link congestion
0143  * @max_win: maximum window (in packets) before declaring link congestion
0144  * @tolerance: default link tolerance for bearer
0145  * @domain: network domain to which links can be established
0146  * @identity: array index of this bearer within TIPC bearer array
0147  * @disc: ptr to link setup request
0148  * @net_plane: network plane ('A' through 'H') currently associated with bearer
0149  * @up: bearer up flag (bit 0)
0150  * @refcnt: tipc_bearer reference counter
0151  *
0152  * Note: media-specific code is responsible for initialization of the fields
0153  * indicated below when a bearer is enabled; TIPC's generic bearer code takes
0154  * care of initializing all other fields.
0155  */
0156 struct tipc_bearer {
0157     void __rcu *media_ptr;          /* initialized by media */
0158     u32 mtu;                /* initialized by media */
0159     struct tipc_media_addr addr;        /* initialized by media */
0160     char name[TIPC_MAX_BEARER_NAME];
0161     struct tipc_media *media;
0162     struct tipc_media_addr bcast_addr;
0163     struct packet_type pt;
0164     struct rcu_head rcu;
0165     u32 priority;
0166     u32 min_win;
0167     u32 max_win;
0168     u32 tolerance;
0169     u32 domain;
0170     u32 identity;
0171     struct tipc_discoverer *disc;
0172     char net_plane;
0173     unsigned long up;
0174     refcount_t refcnt;
0175 };
0176 
0177 struct tipc_bearer_names {
0178     char media_name[TIPC_MAX_MEDIA_NAME];
0179     char if_name[TIPC_MAX_IF_NAME];
0180 };
0181 
0182 /*
0183  * TIPC routines available to supported media types
0184  */
0185 
0186 void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b);
0187 
0188 /*
0189  * Routines made available to TIPC by supported media types
0190  */
0191 extern struct tipc_media eth_media_info;
0192 
0193 #ifdef CONFIG_TIPC_MEDIA_IB
0194 extern struct tipc_media ib_media_info;
0195 #endif
0196 #ifdef CONFIG_TIPC_MEDIA_UDP
0197 extern struct tipc_media udp_media_info;
0198 #endif
0199 
0200 int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info);
0201 int __tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info);
0202 int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info);
0203 int __tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info);
0204 int tipc_nl_bearer_dump(struct sk_buff *skb, struct netlink_callback *cb);
0205 int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info);
0206 int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info);
0207 int __tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info);
0208 int tipc_nl_bearer_add(struct sk_buff *skb, struct genl_info *info);
0209 
0210 int tipc_nl_media_dump(struct sk_buff *skb, struct netlink_callback *cb);
0211 int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info);
0212 int tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info);
0213 int __tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info);
0214 
0215 int tipc_media_set_priority(const char *name, u32 new_value);
0216 int tipc_media_set_window(const char *name, u32 new_value);
0217 int tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a);
0218 int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b,
0219              struct nlattr *attrs[]);
0220 bool tipc_bearer_hold(struct tipc_bearer *b);
0221 void tipc_bearer_put(struct tipc_bearer *b);
0222 void tipc_disable_l2_media(struct tipc_bearer *b);
0223 int tipc_l2_send_msg(struct net *net, struct sk_buff *buf,
0224              struct tipc_bearer *b, struct tipc_media_addr *dest);
0225 
0226 void tipc_bearer_add_dest(struct net *net, u32 bearer_id, u32 dest);
0227 void tipc_bearer_remove_dest(struct net *net, u32 bearer_id, u32 dest);
0228 struct tipc_bearer *tipc_bearer_find(struct net *net, const char *name);
0229 int tipc_bearer_get_name(struct net *net, char *name, u32 bearer_id);
0230 struct tipc_media *tipc_media_find(const char *name);
0231 int tipc_bearer_setup(void);
0232 void tipc_bearer_cleanup(void);
0233 void tipc_bearer_stop(struct net *net);
0234 int tipc_bearer_mtu(struct net *net, u32 bearer_id);
0235 bool tipc_bearer_bcast_support(struct net *net, u32 bearer_id);
0236 void tipc_bearer_xmit_skb(struct net *net, u32 bearer_id,
0237               struct sk_buff *skb,
0238               struct tipc_media_addr *dest);
0239 void tipc_bearer_xmit(struct net *net, u32 bearer_id,
0240               struct sk_buff_head *xmitq,
0241               struct tipc_media_addr *dst,
0242               struct tipc_node *__dnode);
0243 void tipc_bearer_bc_xmit(struct net *net, u32 bearer_id,
0244              struct sk_buff_head *xmitq);
0245 void tipc_clone_to_loopback(struct net *net, struct sk_buff_head *pkts);
0246 int tipc_attach_loopback(struct net *net);
0247 void tipc_detach_loopback(struct net *net);
0248 
0249 static inline void tipc_loopback_trace(struct net *net,
0250                        struct sk_buff_head *pkts)
0251 {
0252     if (unlikely(dev_nit_active(net->loopback_dev)))
0253         tipc_clone_to_loopback(net, pkts);
0254 }
0255 
0256 /* check if device MTU is too low for tipc headers */
0257 static inline bool tipc_mtu_bad(struct net_device *dev, unsigned int reserve)
0258 {
0259     if (dev->mtu >= TIPC_MIN_BEARER_MTU + reserve)
0260         return false;
0261     netdev_warn(dev, "MTU too low for tipc bearer\n");
0262     return true;
0263 }
0264 
0265 #endif  /* _TIPC_BEARER_H */