blob: 02a16f86defad1386dbf2a77422bf086fc98a863 [file] [log] [blame]
Per Lidenb97bf3f2006-01-02 19:04:38 +01001/*
2 * net/tipc/bearer.h: Include file for TIPC bearer code
3 *
4 * Copyright (c) 2003-2005, Ericsson Research Canada
5 * Copyright (c) 2005, Wind River Systems
6 * Copyright (c) 2005-2006, Ericsson AB
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 * Redistributions of source code must retain the above copyright notice, this
13 * list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * Neither the names of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#ifndef _TIPC_BEARER_H
35#define _TIPC_BEARER_H
36
37#include <net/tipc/tipc_bearer.h>
38#include "bcast.h"
39
40#define MAX_BEARERS 8
41#define MAX_MEDIA 4
42
43
44/**
45 * struct media - TIPC media information available to internal users
46 * @send_msg: routine which handles buffer transmission
47 * @enable_bearer: routine which enables a bearer
48 * @disable_bearer: routine which disables a bearer
49 * @addr2str: routine which converts bearer's address to string form
50 * @bcast_addr: media address used in broadcasting
51 * @bcast: non-zero if media supports broadcasting [currently mandatory]
52 * @priority: default link (and bearer) priority
53 * @tolerance: default time (in ms) before declaring link failure
54 * @window: default window (in packets) before declaring link congestion
55 * @type_id: TIPC media identifier [defined in tipc_bearer.h]
56 * @name: media name
57 */
58
59struct media {
60 int (*send_msg)(struct sk_buff *buf,
61 struct tipc_bearer *b_ptr,
62 struct tipc_media_addr *dest);
63 int (*enable_bearer)(struct tipc_bearer *b_ptr);
64 void (*disable_bearer)(struct tipc_bearer *b_ptr);
65 char *(*addr2str)(struct tipc_media_addr *a,
66 char *str_buf, int str_size);
67 struct tipc_media_addr bcast_addr;
68 int bcast;
69 u32 priority;
70 u32 tolerance;
71 u32 window;
72 u32 type_id;
73 char name[TIPC_MAX_MEDIA_NAME];
74};
75
76/**
77 * struct bearer - TIPC bearer information available to internal users
78 * @publ: bearer information available to privileged users
79 * @media: ptr to media structure associated with bearer
80 * @priority: default link priority for bearer
81 * @detect_scope: network address mask used during automatic link creation
82 * @identity: array index of this bearer within TIPC bearer array
83 * @link_req: ptr to (optional) structure making periodic link setup requests
84 * @links: list of non-congested links associated with bearer
85 * @cong_links: list of congested links associated with bearer
86 * @continue_count: # of times bearer has resumed after congestion or blocking
87 * @active: non-zero if bearer structure is represents a bearer
88 * @net_plane: network plane ('A' through 'H') currently associated with bearer
89 * @nodes: indicates which nodes in cluster can be reached through bearer
90 */
91
92struct bearer {
93 struct tipc_bearer publ;
94 struct media *media;
95 u32 priority;
96 u32 detect_scope;
97 u32 identity;
98 struct link_req *link_req;
99 struct list_head links;
100 struct list_head cong_links;
101 u32 continue_count;
102 int active;
103 char net_plane;
104 struct node_map nodes;
105};
106
107struct bearer_name {
108 char media_name[TIPC_MAX_MEDIA_NAME];
109 char if_name[TIPC_MAX_IF_NAME];
110};
111
112struct link;
113
114extern struct bearer *bearers;
115
116void media_addr_printf(struct print_buf *pb, struct tipc_media_addr *a);
117struct sk_buff *media_get_names(void);
118
119struct sk_buff *bearer_get_names(void);
120void bearer_add_dest(struct bearer *b_ptr, u32 dest);
121void bearer_remove_dest(struct bearer *b_ptr, u32 dest);
122void bearer_schedule(struct bearer *b_ptr, struct link *l_ptr);
123struct bearer *bearer_find_interface(const char *if_name);
124int bearer_resolve_congestion(struct bearer *b_ptr, struct link *l_ptr);
125int bearer_init(void);
126void bearer_stop(void);
127int bearer_broadcast(struct sk_buff *buf, struct tipc_bearer *b_ptr,
128 struct tipc_media_addr *dest);
129void bearer_lock_push(struct bearer *b_ptr);
130
131
132/**
133 * bearer_send- sends buffer to destination over bearer
134 *
135 * Returns true (1) if successful, or false (0) if unable to send
136 *
137 * IMPORTANT:
138 * The media send routine must not alter the buffer being passed in
139 * as it may be needed for later retransmission!
140 *
141 * If the media send routine returns a non-zero value (indicating that
142 * it was unable to send the buffer), it must:
143 * 1) mark the bearer as blocked,
144 * 2) call tipc_continue() once the bearer is able to send again.
145 * Media types that are unable to meet these two critera must ensure their
146 * send routine always returns success -- even if the buffer was not sent --
147 * and let TIPC's link code deal with the undelivered message.
148 */
149
150static inline int bearer_send(struct bearer *b_ptr, struct sk_buff *buf,
151 struct tipc_media_addr *dest)
152{
153 return !b_ptr->media->send_msg(buf, &b_ptr->publ, dest);
154}
155
156/**
157 * bearer_congested - determines if bearer is currently congested
158 */
159
160static inline int bearer_congested(struct bearer *b_ptr, struct link *l_ptr)
161{
162 if (unlikely(b_ptr->publ.blocked))
163 return 1;
164 if (likely(list_empty(&b_ptr->cong_links)))
165 return 0;
166 return !bearer_resolve_congestion(b_ptr, l_ptr);
167}
168
169#endif