aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/link.c
diff options
context:
space:
mode:
authorJon Paul Maloy <jon.maloy@ericsson.com>2015-11-19 14:30:46 -0500
committerDavid S. Miller <davem@davemloft.net>2015-11-20 14:06:10 -0500
commit38206d5939068415c413ac253be6f364d06e672f (patch)
tree0325222bc72ed1ae0039ccb3f7d8300342b6dff9 /net/tipc/link.c
parent5be9c086715c10fb9ae3ffc0ef580dc3a165f98a (diff)
tipc: narrow down interface towards struct tipc_link
We move the definition of struct tipc_link from link.h to link.c in order to minimize its exposure to the rest of the code. When needed, we define new functions to make it possible for external entities to access and set data in the link. Apart from the above, there are no functional changes. Reviewed-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc/link.c')
-rw-r--r--net/tipc/link.c346
1 files changed, 338 insertions, 8 deletions
diff --git a/net/tipc/link.c b/net/tipc/link.c
index c513a807b3a1..4380eb119796 100644
--- a/net/tipc/link.c
+++ b/net/tipc/link.c
@@ -45,6 +45,151 @@
45 45
46#include <linux/pkt_sched.h> 46#include <linux/pkt_sched.h>
47 47
48struct tipc_stats {
49 u32 sent_info; /* used in counting # sent packets */
50 u32 recv_info; /* used in counting # recv'd packets */
51 u32 sent_states;
52 u32 recv_states;
53 u32 sent_probes;
54 u32 recv_probes;
55 u32 sent_nacks;
56 u32 recv_nacks;
57 u32 sent_acks;
58 u32 sent_bundled;
59 u32 sent_bundles;
60 u32 recv_bundled;
61 u32 recv_bundles;
62 u32 retransmitted;
63 u32 sent_fragmented;
64 u32 sent_fragments;
65 u32 recv_fragmented;
66 u32 recv_fragments;
67 u32 link_congs; /* # port sends blocked by congestion */
68 u32 deferred_recv;
69 u32 duplicates;
70 u32 max_queue_sz; /* send queue size high water mark */
71 u32 accu_queue_sz; /* used for send queue size profiling */
72 u32 queue_sz_counts; /* used for send queue size profiling */
73 u32 msg_length_counts; /* used for message length profiling */
74 u32 msg_lengths_total; /* used for message length profiling */
75 u32 msg_length_profile[7]; /* used for msg. length profiling */
76};
77
78/**
79 * struct tipc_link - TIPC link data structure
80 * @addr: network address of link's peer node
81 * @name: link name character string
82 * @media_addr: media address to use when sending messages over link
83 * @timer: link timer
84 * @net: pointer to namespace struct
85 * @refcnt: reference counter for permanent references (owner node & timer)
86 * @peer_session: link session # being used by peer end of link
87 * @peer_bearer_id: bearer id used by link's peer endpoint
88 * @bearer_id: local bearer id used by link
89 * @tolerance: minimum link continuity loss needed to reset link [in ms]
90 * @keepalive_intv: link keepalive timer interval
91 * @abort_limit: # of unacknowledged continuity probes needed to reset link
92 * @state: current state of link FSM
93 * @peer_caps: bitmap describing capabilities of peer node
94 * @silent_intv_cnt: # of timer intervals without any reception from peer
95 * @proto_msg: template for control messages generated by link
96 * @pmsg: convenience pointer to "proto_msg" field
97 * @priority: current link priority
98 * @net_plane: current link network plane ('A' through 'H')
99 * @backlog_limit: backlog queue congestion thresholds (indexed by importance)
100 * @exp_msg_count: # of tunnelled messages expected during link changeover
101 * @reset_rcv_checkpt: seq # of last acknowledged message at time of link reset
102 * @mtu: current maximum packet size for this link
103 * @advertised_mtu: advertised own mtu when link is being established
104 * @transmitq: queue for sent, non-acked messages
105 * @backlogq: queue for messages waiting to be sent
106 * @snt_nxt: next sequence number to use for outbound messages
107 * @last_retransmitted: sequence number of most recently retransmitted message
108 * @stale_count: # of identical retransmit requests made by peer
109 * @ackers: # of peers that needs to ack each packet before it can be released
110 * @acked: # last packet acked by a certain peer. Used for broadcast.
111 * @rcv_nxt: next sequence number to expect for inbound messages
112 * @deferred_queue: deferred queue saved OOS b'cast message received from node
113 * @unacked_window: # of inbound messages rx'd without ack'ing back to peer
114 * @inputq: buffer queue for messages to be delivered upwards
115 * @namedq: buffer queue for name table messages to be delivered upwards
116 * @next_out: ptr to first unsent outbound message in queue
117 * @wakeupq: linked list of wakeup msgs waiting for link congestion to abate
118 * @long_msg_seq_no: next identifier to use for outbound fragmented messages
119 * @reasm_buf: head of partially reassembled inbound message fragments
120 * @bc_rcvr: marks that this is a broadcast receiver link
121 * @stats: collects statistics regarding link activity
122 */
123struct tipc_link {
124 u32 addr;
125 char name[TIPC_MAX_LINK_NAME];
126 struct tipc_media_addr *media_addr;
127 struct net *net;
128
129 /* Management and link supervision data */
130 u32 peer_session;
131 u32 peer_bearer_id;
132 u32 bearer_id;
133 u32 tolerance;
134 unsigned long keepalive_intv;
135 u32 abort_limit;
136 u32 state;
137 u16 peer_caps;
138 bool active;
139 u32 silent_intv_cnt;
140 struct {
141 unchar hdr[INT_H_SIZE];
142 unchar body[TIPC_MAX_IF_NAME];
143 } proto_msg;
144 struct tipc_msg *pmsg;
145 u32 priority;
146 char net_plane;
147
148 /* Failover/synch */
149 u16 drop_point;
150 struct sk_buff *failover_reasm_skb;
151
152 /* Max packet negotiation */
153 u16 mtu;
154 u16 advertised_mtu;
155
156 /* Sending */
157 struct sk_buff_head transmq;
158 struct sk_buff_head backlogq;
159 struct {
160 u16 len;
161 u16 limit;
162 } backlog[5];
163 u16 snd_nxt;
164 u16 last_retransm;
165 u16 window;
166 u32 stale_count;
167
168 /* Reception */
169 u16 rcv_nxt;
170 u32 rcv_unacked;
171 struct sk_buff_head deferdq;
172 struct sk_buff_head *inputq;
173 struct sk_buff_head *namedq;
174
175 /* Congestion handling */
176 struct sk_buff_head wakeupq;
177
178 /* Fragmentation/reassembly */
179 struct sk_buff *reasm_buf;
180
181 /* Broadcast */
182 u16 ackers;
183 u16 acked;
184 struct tipc_link *bc_rcvlink;
185 struct tipc_link *bc_sndlink;
186 int nack_state;
187 bool bc_peer_is_up;
188
189 /* Statistics */
190 struct tipc_stats stats;
191};
192
48/* 193/*
49 * Error message prefixes 194 * Error message prefixes
50 */ 195 */
@@ -165,6 +310,36 @@ void tipc_link_set_active(struct tipc_link *l, bool active)
165 l->active = active; 310 l->active = active;
166} 311}
167 312
313u32 tipc_link_id(struct tipc_link *l)
314{
315 return l->peer_bearer_id << 16 | l->bearer_id;
316}
317
318int tipc_link_window(struct tipc_link *l)
319{
320 return l->window;
321}
322
323int tipc_link_prio(struct tipc_link *l)
324{
325 return l->priority;
326}
327
328unsigned long tipc_link_tolerance(struct tipc_link *l)
329{
330 return l->tolerance;
331}
332
333struct sk_buff_head *tipc_link_inputq(struct tipc_link *l)
334{
335 return l->inputq;
336}
337
338char tipc_link_plane(struct tipc_link *l)
339{
340 return l->net_plane;
341}
342
168void tipc_link_add_bc_peer(struct tipc_link *snd_l, 343void tipc_link_add_bc_peer(struct tipc_link *snd_l,
169 struct tipc_link *uc_l, 344 struct tipc_link *uc_l,
170 struct sk_buff_head *xmitq) 345 struct sk_buff_head *xmitq)
@@ -207,11 +382,31 @@ int tipc_link_mtu(struct tipc_link *l)
207 return l->mtu; 382 return l->mtu;
208} 383}
209 384
385u16 tipc_link_rcv_nxt(struct tipc_link *l)
386{
387 return l->rcv_nxt;
388}
389
390u16 tipc_link_acked(struct tipc_link *l)
391{
392 return l->acked;
393}
394
395char *tipc_link_name(struct tipc_link *l)
396{
397 return l->name;
398}
399
210static u32 link_own_addr(struct tipc_link *l) 400static u32 link_own_addr(struct tipc_link *l)
211{ 401{
212 return msg_prevnode(l->pmsg); 402 return msg_prevnode(l->pmsg);
213} 403}
214 404
405void tipc_link_reinit(struct tipc_link *l, u32 addr)
406{
407 msg_set_prevnode(l->pmsg, addr);
408}
409
215/** 410/**
216 * tipc_link_create - create a new link 411 * tipc_link_create - create a new link
217 * @n: pointer to associated node 412 * @n: pointer to associated node
@@ -674,7 +869,7 @@ void tipc_link_reset(struct tipc_link *l)
674 l->stats.recv_info = 0; 869 l->stats.recv_info = 0;
675 l->stale_count = 0; 870 l->stale_count = 0;
676 l->bc_peer_is_up = false; 871 l->bc_peer_is_up = false;
677 link_reset_statistics(l); 872 tipc_link_reset_stats(l);
678} 873}
679 874
680/** 875/**
@@ -1067,8 +1262,9 @@ drop:
1067/* 1262/*
1068 * Send protocol message to the other endpoint. 1263 * Send protocol message to the other endpoint.
1069 */ 1264 */
1070void tipc_link_proto_xmit(struct tipc_link *l, u32 msg_typ, int probe_msg, 1265static void tipc_link_proto_xmit(struct tipc_link *l, u32 msg_typ,
1071 u32 gap, u32 tolerance, u32 priority) 1266 int probe_msg, u32 gap, u32 tolerance,
1267 u32 priority)
1072{ 1268{
1073 struct sk_buff *skb = NULL; 1269 struct sk_buff *skb = NULL;
1074 struct sk_buff_head xmitq; 1270 struct sk_buff_head xmitq;
@@ -1510,14 +1706,16 @@ void tipc_link_set_queue_limits(struct tipc_link *l, u32 win)
1510} 1706}
1511 1707
1512/** 1708/**
1513 * link_reset_statistics - reset link statistics 1709 * link_reset_stats - reset link statistics
1514 * @l_ptr: pointer to link 1710 * @l_ptr: pointer to link
1515 */ 1711 */
1516void link_reset_statistics(struct tipc_link *l_ptr) 1712void tipc_link_reset_stats(struct tipc_link *l)
1517{ 1713{
1518 memset(&l_ptr->stats, 0, sizeof(l_ptr->stats)); 1714 memset(&l->stats, 0, sizeof(l->stats));
1519 l_ptr->stats.sent_info = l_ptr->snd_nxt; 1715 if (!link_is_bc_sndlink(l)) {
1520 l_ptr->stats.recv_info = l_ptr->rcv_nxt; 1716 l->stats.sent_info = l->snd_nxt;
1717 l->stats.recv_info = l->rcv_nxt;
1718 }
1521} 1719}
1522 1720
1523static void link_print(struct tipc_link *l, const char *str) 1721static void link_print(struct tipc_link *l, const char *str)
@@ -1705,3 +1903,135 @@ msg_full:
1705 1903
1706 return -EMSGSIZE; 1904 return -EMSGSIZE;
1707} 1905}
1906
1907static int __tipc_nl_add_bc_link_stat(struct sk_buff *skb,
1908 struct tipc_stats *stats)
1909{
1910 int i;
1911 struct nlattr *nest;
1912
1913 struct nla_map {
1914 __u32 key;
1915 __u32 val;
1916 };
1917
1918 struct nla_map map[] = {
1919 {TIPC_NLA_STATS_RX_INFO, stats->recv_info},
1920 {TIPC_NLA_STATS_RX_FRAGMENTS, stats->recv_fragments},
1921 {TIPC_NLA_STATS_RX_FRAGMENTED, stats->recv_fragmented},
1922 {TIPC_NLA_STATS_RX_BUNDLES, stats->recv_bundles},
1923 {TIPC_NLA_STATS_RX_BUNDLED, stats->recv_bundled},
1924 {TIPC_NLA_STATS_TX_INFO, stats->sent_info},
1925 {TIPC_NLA_STATS_TX_FRAGMENTS, stats->sent_fragments},
1926 {TIPC_NLA_STATS_TX_FRAGMENTED, stats->sent_fragmented},
1927 {TIPC_NLA_STATS_TX_BUNDLES, stats->sent_bundles},
1928 {TIPC_NLA_STATS_TX_BUNDLED, stats->sent_bundled},
1929 {TIPC_NLA_STATS_RX_NACKS, stats->recv_nacks},
1930 {TIPC_NLA_STATS_RX_DEFERRED, stats->deferred_recv},
1931 {TIPC_NLA_STATS_TX_NACKS, stats->sent_nacks},
1932 {TIPC_NLA_STATS_TX_ACKS, stats->sent_acks},
1933 {TIPC_NLA_STATS_RETRANSMITTED, stats->retransmitted},
1934 {TIPC_NLA_STATS_DUPLICATES, stats->duplicates},
1935 {TIPC_NLA_STATS_LINK_CONGS, stats->link_congs},
1936 {TIPC_NLA_STATS_MAX_QUEUE, stats->max_queue_sz},
1937 {TIPC_NLA_STATS_AVG_QUEUE, stats->queue_sz_counts ?
1938 (stats->accu_queue_sz / stats->queue_sz_counts) : 0}
1939 };
1940
1941 nest = nla_nest_start(skb, TIPC_NLA_LINK_STATS);
1942 if (!nest)
1943 return -EMSGSIZE;
1944
1945 for (i = 0; i < ARRAY_SIZE(map); i++)
1946 if (nla_put_u32(skb, map[i].key, map[i].val))
1947 goto msg_full;
1948
1949 nla_nest_end(skb, nest);
1950
1951 return 0;
1952msg_full:
1953 nla_nest_cancel(skb, nest);
1954
1955 return -EMSGSIZE;
1956}
1957
1958int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg)
1959{
1960 int err;
1961 void *hdr;
1962 struct nlattr *attrs;
1963 struct nlattr *prop;
1964 struct tipc_net *tn = net_generic(net, tipc_net_id);
1965 struct tipc_link *bcl = tn->bcl;
1966
1967 if (!bcl)
1968 return 0;
1969
1970 tipc_bcast_lock(net);
1971
1972 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
1973 NLM_F_MULTI, TIPC_NL_LINK_GET);
1974 if (!hdr)
1975 return -EMSGSIZE;
1976
1977 attrs = nla_nest_start(msg->skb, TIPC_NLA_LINK);
1978 if (!attrs)
1979 goto msg_full;
1980
1981 /* The broadcast link is always up */
1982 if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP))
1983 goto attr_msg_full;
1984
1985 if (nla_put_flag(msg->skb, TIPC_NLA_LINK_BROADCAST))
1986 goto attr_msg_full;
1987 if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, bcl->name))
1988 goto attr_msg_full;
1989 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, bcl->rcv_nxt))
1990 goto attr_msg_full;
1991 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, bcl->snd_nxt))
1992 goto attr_msg_full;
1993
1994 prop = nla_nest_start(msg->skb, TIPC_NLA_LINK_PROP);
1995 if (!prop)
1996 goto attr_msg_full;
1997 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, bcl->window))
1998 goto prop_msg_full;
1999 nla_nest_end(msg->skb, prop);
2000
2001 err = __tipc_nl_add_bc_link_stat(msg->skb, &bcl->stats);
2002 if (err)
2003 goto attr_msg_full;
2004
2005 tipc_bcast_unlock(net);
2006 nla_nest_end(msg->skb, attrs);
2007 genlmsg_end(msg->skb, hdr);
2008
2009 return 0;
2010
2011prop_msg_full:
2012 nla_nest_cancel(msg->skb, prop);
2013attr_msg_full:
2014 nla_nest_cancel(msg->skb, attrs);
2015msg_full:
2016 tipc_bcast_unlock(net);
2017 genlmsg_cancel(msg->skb, hdr);
2018
2019 return -EMSGSIZE;
2020}
2021
2022void tipc_link_set_tolerance(struct tipc_link *l, u32 tol)
2023{
2024 l->tolerance = tol;
2025 tipc_link_proto_xmit(l, STATE_MSG, 0, 0, tol, 0);
2026}
2027
2028void tipc_link_set_prio(struct tipc_link *l, u32 prio)
2029{
2030 l->priority = prio;
2031 tipc_link_proto_xmit(l, STATE_MSG, 0, 0, 0, prio);
2032}
2033
2034void tipc_link_set_abort_limit(struct tipc_link *l, u32 limit)
2035{
2036 l->abort_limit = limit;
2037}