Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * net/tipc/msg.c: TIPC message header routines |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 3 | * |
Jon Paul Maloy | 37e2216 | 2014-05-14 05:39:12 -0400 | [diff] [blame] | 4 | * Copyright (c) 2000-2006, 2014, Ericsson AB |
Allan Stephens | 741de3e | 2011-01-25 13:33:31 -0500 | [diff] [blame] | 5 | * Copyright (c) 2005, 2010-2011, Wind River Systems |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 8 | * Redistribution and use in source and binary forms, with or without |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. Neither the names of the copyright holders nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 19 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 20 | * Alternatively, this software may be distributed under the terms of the |
| 21 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 22 | * Software Foundation. |
| 23 | * |
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
| 37 | #include "core.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 38 | #include "msg.h" |
Jon Paul Maloy | 5a37907 | 2014-06-25 20:41:36 -0500 | [diff] [blame] | 39 | #include "addr.h" |
| 40 | #include "name_table.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 41 | |
Jon Paul Maloy | 8db1bae | 2014-06-25 20:41:35 -0500 | [diff] [blame] | 42 | #define MAX_FORWARD_SIZE 1024 |
| 43 | |
Jon Paul Maloy | 4f1688b | 2014-06-25 20:41:32 -0500 | [diff] [blame] | 44 | static unsigned int align(unsigned int i) |
Allan Stephens | 23461e8 | 2010-05-11 14:30:18 +0000 | [diff] [blame] | 45 | { |
Jon Paul Maloy | 4f1688b | 2014-06-25 20:41:32 -0500 | [diff] [blame] | 46 | return (i + 3) & ~3u; |
Allan Stephens | 23461e8 | 2010-05-11 14:30:18 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 49 | void tipc_msg_init(struct tipc_msg *m, u32 user, u32 type, u32 hsize, |
| 50 | u32 destnode) |
Allan Stephens | 23461e8 | 2010-05-11 14:30:18 +0000 | [diff] [blame] | 51 | { |
| 52 | memset(m, 0, hsize); |
| 53 | msg_set_version(m); |
| 54 | msg_set_user(m, user); |
| 55 | msg_set_hdr_sz(m, hsize); |
| 56 | msg_set_size(m, hsize); |
| 57 | msg_set_prevnode(m, tipc_own_addr); |
| 58 | msg_set_type(m, type); |
Allan Stephens | 15f4e2b | 2011-05-31 14:35:18 -0400 | [diff] [blame] | 59 | msg_set_orignode(m, tipc_own_addr); |
| 60 | msg_set_destnode(m, destnode); |
Allan Stephens | 23461e8 | 2010-05-11 14:30:18 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /** |
Allan Stephens | 23461e8 | 2010-05-11 14:30:18 +0000 | [diff] [blame] | 64 | * tipc_msg_build - create message using specified header and data |
| 65 | * |
| 66 | * Note: Caller must not hold any locks in case copy_from_user() is interrupted! |
| 67 | * |
| 68 | * Returns message data size or errno |
| 69 | */ |
Allan Stephens | 2689690 | 2011-04-21 10:42:07 -0500 | [diff] [blame] | 70 | int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect, |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 71 | unsigned int len, int max_size, struct sk_buff **buf) |
Allan Stephens | 23461e8 | 2010-05-11 14:30:18 +0000 | [diff] [blame] | 72 | { |
Ying Xue | 5c0a0fc | 2013-10-18 07:23:14 +0200 | [diff] [blame] | 73 | int dsz, sz, hsz; |
| 74 | unsigned char *to; |
Allan Stephens | 23461e8 | 2010-05-11 14:30:18 +0000 | [diff] [blame] | 75 | |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 76 | dsz = len; |
Ying Xue | 5c0a0fc | 2013-10-18 07:23:14 +0200 | [diff] [blame] | 77 | hsz = msg_hdr_sz(hdr); |
Allan Stephens | 23461e8 | 2010-05-11 14:30:18 +0000 | [diff] [blame] | 78 | sz = hsz + dsz; |
| 79 | msg_set_size(hdr, sz); |
| 80 | if (unlikely(sz > max_size)) { |
| 81 | *buf = NULL; |
| 82 | return dsz; |
| 83 | } |
| 84 | |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 85 | *buf = tipc_buf_acquire(sz); |
Allan Stephens | 23461e8 | 2010-05-11 14:30:18 +0000 | [diff] [blame] | 86 | if (!(*buf)) |
| 87 | return -ENOMEM; |
| 88 | skb_copy_to_linear_data(*buf, hdr, hsz); |
Ying Xue | 5c0a0fc | 2013-10-18 07:23:14 +0200 | [diff] [blame] | 89 | to = (*buf)->data + hsz; |
Ying Xue | 9446b87 | 2013-10-18 07:23:15 +0200 | [diff] [blame] | 90 | if (len && memcpy_fromiovecend(to, msg_sect, 0, dsz)) { |
Ying Xue | 5c0a0fc | 2013-10-18 07:23:14 +0200 | [diff] [blame] | 91 | kfree_skb(*buf); |
| 92 | *buf = NULL; |
| 93 | return -EFAULT; |
Allan Stephens | 23461e8 | 2010-05-11 14:30:18 +0000 | [diff] [blame] | 94 | } |
Ying Xue | 5c0a0fc | 2013-10-18 07:23:14 +0200 | [diff] [blame] | 95 | return dsz; |
Allan Stephens | 23461e8 | 2010-05-11 14:30:18 +0000 | [diff] [blame] | 96 | } |
Jon Paul Maloy | 37e2216 | 2014-05-14 05:39:12 -0400 | [diff] [blame] | 97 | |
| 98 | /* tipc_buf_append(): Append a buffer to the fragment list of another buffer |
| 99 | * Let first buffer become head buffer |
| 100 | * Returns 1 and sets *buf to headbuf if chain is complete, otherwise 0 |
| 101 | * Leaves headbuf pointer at NULL if failure |
| 102 | */ |
| 103 | int tipc_buf_append(struct sk_buff **headbuf, struct sk_buff **buf) |
| 104 | { |
| 105 | struct sk_buff *head = *headbuf; |
| 106 | struct sk_buff *frag = *buf; |
| 107 | struct sk_buff *tail; |
| 108 | struct tipc_msg *msg = buf_msg(frag); |
| 109 | u32 fragid = msg_type(msg); |
| 110 | bool headstolen; |
| 111 | int delta; |
| 112 | |
| 113 | skb_pull(frag, msg_hdr_sz(msg)); |
| 114 | |
| 115 | if (fragid == FIRST_FRAGMENT) { |
| 116 | if (head || skb_unclone(frag, GFP_ATOMIC)) |
| 117 | goto out_free; |
| 118 | head = *headbuf = frag; |
| 119 | skb_frag_list_init(head); |
| 120 | return 0; |
| 121 | } |
| 122 | if (!head) |
| 123 | goto out_free; |
| 124 | tail = TIPC_SKB_CB(head)->tail; |
| 125 | if (skb_try_coalesce(head, frag, &headstolen, &delta)) { |
| 126 | kfree_skb_partial(frag, headstolen); |
| 127 | } else { |
| 128 | if (!skb_has_frag_list(head)) |
| 129 | skb_shinfo(head)->frag_list = frag; |
| 130 | else |
| 131 | tail->next = frag; |
| 132 | head->truesize += frag->truesize; |
| 133 | head->data_len += frag->len; |
| 134 | head->len += frag->len; |
| 135 | TIPC_SKB_CB(head)->tail = frag; |
| 136 | } |
| 137 | if (fragid == LAST_FRAGMENT) { |
| 138 | *buf = head; |
| 139 | TIPC_SKB_CB(head)->tail = NULL; |
| 140 | *headbuf = NULL; |
| 141 | return 1; |
| 142 | } |
| 143 | *buf = NULL; |
| 144 | return 0; |
| 145 | out_free: |
| 146 | pr_warn_ratelimited("Unable to build fragment list\n"); |
| 147 | kfree_skb(*buf); |
| 148 | return 0; |
| 149 | } |
Jon Paul Maloy | 4f1688b | 2014-06-25 20:41:32 -0500 | [diff] [blame] | 150 | |
Jon Paul Maloy | 067608e | 2014-06-25 20:41:34 -0500 | [diff] [blame] | 151 | |
| 152 | /** |
| 153 | * tipc_msg_build2 - create buffer chain containing specified header and data |
| 154 | * @mhdr: Message header, to be prepended to data |
| 155 | * @iov: User data |
| 156 | * @offset: Posision in iov to start copying from |
| 157 | * @dsz: Total length of user data |
| 158 | * @pktmax: Max packet size that can be used |
| 159 | * @chain: Buffer or chain of buffers to be returned to caller |
| 160 | * Returns message data size or errno: -ENOMEM, -EFAULT |
| 161 | */ |
| 162 | int tipc_msg_build2(struct tipc_msg *mhdr, struct iovec const *iov, |
| 163 | int offset, int dsz, int pktmax , struct sk_buff **chain) |
| 164 | { |
| 165 | int mhsz = msg_hdr_sz(mhdr); |
| 166 | int msz = mhsz + dsz; |
| 167 | int pktno = 1; |
| 168 | int pktsz; |
| 169 | int pktrem = pktmax; |
| 170 | int drem = dsz; |
| 171 | struct tipc_msg pkthdr; |
| 172 | struct sk_buff *buf, *prev; |
| 173 | char *pktpos; |
| 174 | int rc; |
| 175 | |
| 176 | msg_set_size(mhdr, msz); |
| 177 | |
| 178 | /* No fragmentation needed? */ |
| 179 | if (likely(msz <= pktmax)) { |
| 180 | buf = tipc_buf_acquire(msz); |
| 181 | *chain = buf; |
| 182 | if (unlikely(!buf)) |
| 183 | return -ENOMEM; |
| 184 | skb_copy_to_linear_data(buf, mhdr, mhsz); |
| 185 | pktpos = buf->data + mhsz; |
| 186 | if (!dsz || !memcpy_fromiovecend(pktpos, iov, offset, dsz)) |
| 187 | return dsz; |
| 188 | rc = -EFAULT; |
| 189 | goto error; |
| 190 | } |
| 191 | |
| 192 | /* Prepare reusable fragment header */ |
| 193 | tipc_msg_init(&pkthdr, MSG_FRAGMENTER, FIRST_FRAGMENT, |
| 194 | INT_H_SIZE, msg_destnode(mhdr)); |
| 195 | msg_set_size(&pkthdr, pktmax); |
| 196 | msg_set_fragm_no(&pkthdr, pktno); |
| 197 | |
| 198 | /* Prepare first fragment */ |
| 199 | *chain = buf = tipc_buf_acquire(pktmax); |
| 200 | if (!buf) |
| 201 | return -ENOMEM; |
| 202 | pktpos = buf->data; |
| 203 | skb_copy_to_linear_data(buf, &pkthdr, INT_H_SIZE); |
| 204 | pktpos += INT_H_SIZE; |
| 205 | pktrem -= INT_H_SIZE; |
| 206 | skb_copy_to_linear_data_offset(buf, INT_H_SIZE, mhdr, mhsz); |
| 207 | pktpos += mhsz; |
| 208 | pktrem -= mhsz; |
| 209 | |
| 210 | do { |
| 211 | if (drem < pktrem) |
| 212 | pktrem = drem; |
| 213 | |
| 214 | if (memcpy_fromiovecend(pktpos, iov, offset, pktrem)) { |
| 215 | rc = -EFAULT; |
| 216 | goto error; |
| 217 | } |
| 218 | drem -= pktrem; |
| 219 | offset += pktrem; |
| 220 | |
| 221 | if (!drem) |
| 222 | break; |
| 223 | |
| 224 | /* Prepare new fragment: */ |
| 225 | if (drem < (pktmax - INT_H_SIZE)) |
| 226 | pktsz = drem + INT_H_SIZE; |
| 227 | else |
| 228 | pktsz = pktmax; |
| 229 | prev = buf; |
| 230 | buf = tipc_buf_acquire(pktsz); |
| 231 | if (!buf) { |
| 232 | rc = -ENOMEM; |
| 233 | goto error; |
| 234 | } |
| 235 | prev->next = buf; |
| 236 | msg_set_type(&pkthdr, FRAGMENT); |
| 237 | msg_set_size(&pkthdr, pktsz); |
| 238 | msg_set_fragm_no(&pkthdr, ++pktno); |
| 239 | skb_copy_to_linear_data(buf, &pkthdr, INT_H_SIZE); |
| 240 | pktpos = buf->data + INT_H_SIZE; |
| 241 | pktrem = pktsz - INT_H_SIZE; |
| 242 | |
| 243 | } while (1); |
| 244 | |
| 245 | msg_set_type(buf_msg(buf), LAST_FRAGMENT); |
| 246 | return dsz; |
| 247 | error: |
| 248 | kfree_skb_list(*chain); |
| 249 | *chain = NULL; |
| 250 | return rc; |
| 251 | } |
| 252 | |
Jon Paul Maloy | 4f1688b | 2014-06-25 20:41:32 -0500 | [diff] [blame] | 253 | /** |
| 254 | * tipc_msg_bundle(): Append contents of a buffer to tail of an existing one |
| 255 | * @bbuf: the existing buffer ("bundle") |
| 256 | * @buf: buffer to be appended |
| 257 | * @mtu: max allowable size for the bundle buffer |
| 258 | * Consumes buffer if successful |
| 259 | * Returns true if bundling could be performed, otherwise false |
| 260 | */ |
| 261 | bool tipc_msg_bundle(struct sk_buff *bbuf, struct sk_buff *buf, u32 mtu) |
| 262 | { |
| 263 | struct tipc_msg *bmsg = buf_msg(bbuf); |
| 264 | struct tipc_msg *msg = buf_msg(buf); |
| 265 | unsigned int bsz = msg_size(bmsg); |
| 266 | unsigned int msz = msg_size(msg); |
| 267 | u32 start = align(bsz); |
| 268 | u32 max = mtu - INT_H_SIZE; |
| 269 | u32 pad = start - bsz; |
| 270 | |
| 271 | if (likely(msg_user(msg) == MSG_FRAGMENTER)) |
| 272 | return false; |
| 273 | if (unlikely(msg_user(msg) == CHANGEOVER_PROTOCOL)) |
| 274 | return false; |
| 275 | if (unlikely(msg_user(msg) == BCAST_PROTOCOL)) |
| 276 | return false; |
| 277 | if (likely(msg_user(bmsg) != MSG_BUNDLER)) |
| 278 | return false; |
| 279 | if (likely(msg_type(bmsg) != BUNDLE_OPEN)) |
| 280 | return false; |
| 281 | if (unlikely(skb_tailroom(bbuf) < (pad + msz))) |
| 282 | return false; |
| 283 | if (unlikely(max < (start + msz))) |
| 284 | return false; |
| 285 | |
| 286 | skb_put(bbuf, pad + msz); |
| 287 | skb_copy_to_linear_data_offset(bbuf, start, buf->data, msz); |
| 288 | msg_set_size(bmsg, start + msz); |
| 289 | msg_set_msgcnt(bmsg, msg_msgcnt(bmsg) + 1); |
| 290 | bbuf->next = buf->next; |
| 291 | kfree_skb(buf); |
| 292 | return true; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * tipc_msg_make_bundle(): Create bundle buf and append message to its tail |
| 297 | * @buf: buffer to be appended and replaced |
| 298 | * @mtu: max allowable size for the bundle buffer, inclusive header |
| 299 | * @dnode: destination node for message. (Not always present in header) |
| 300 | * Replaces buffer if successful |
| 301 | * Returns true if sucess, otherwise false |
| 302 | */ |
| 303 | bool tipc_msg_make_bundle(struct sk_buff **buf, u32 mtu, u32 dnode) |
| 304 | { |
| 305 | struct sk_buff *bbuf; |
| 306 | struct tipc_msg *bmsg; |
| 307 | struct tipc_msg *msg = buf_msg(*buf); |
| 308 | u32 msz = msg_size(msg); |
| 309 | u32 max = mtu - INT_H_SIZE; |
| 310 | |
| 311 | if (msg_user(msg) == MSG_FRAGMENTER) |
| 312 | return false; |
| 313 | if (msg_user(msg) == CHANGEOVER_PROTOCOL) |
| 314 | return false; |
| 315 | if (msg_user(msg) == BCAST_PROTOCOL) |
| 316 | return false; |
| 317 | if (msz > (max / 2)) |
| 318 | return false; |
| 319 | |
| 320 | bbuf = tipc_buf_acquire(max); |
| 321 | if (!bbuf) |
| 322 | return false; |
| 323 | |
| 324 | skb_trim(bbuf, INT_H_SIZE); |
| 325 | bmsg = buf_msg(bbuf); |
| 326 | tipc_msg_init(bmsg, MSG_BUNDLER, BUNDLE_OPEN, INT_H_SIZE, dnode); |
| 327 | msg_set_seqno(bmsg, msg_seqno(msg)); |
| 328 | msg_set_ack(bmsg, msg_ack(msg)); |
| 329 | msg_set_bcast_ack(bmsg, msg_bcast_ack(msg)); |
| 330 | bbuf->next = (*buf)->next; |
| 331 | tipc_msg_bundle(bbuf, *buf, mtu); |
| 332 | *buf = bbuf; |
| 333 | return true; |
| 334 | } |
Jon Paul Maloy | 8db1bae | 2014-06-25 20:41:35 -0500 | [diff] [blame] | 335 | |
| 336 | /** |
| 337 | * tipc_msg_reverse(): swap source and destination addresses and add error code |
| 338 | * @buf: buffer containing message to be reversed |
| 339 | * @dnode: return value: node where to send message after reversal |
| 340 | * @err: error code to be set in message |
| 341 | * Consumes buffer if failure |
| 342 | * Returns true if success, otherwise false |
| 343 | */ |
| 344 | bool tipc_msg_reverse(struct sk_buff *buf, u32 *dnode, int err) |
| 345 | { |
| 346 | struct tipc_msg *msg = buf_msg(buf); |
| 347 | uint imp = msg_importance(msg); |
| 348 | struct tipc_msg ohdr; |
| 349 | uint rdsz = min_t(uint, msg_data_sz(msg), MAX_FORWARD_SIZE); |
| 350 | |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame^] | 351 | if (skb_linearize(buf)) |
Jon Paul Maloy | 8db1bae | 2014-06-25 20:41:35 -0500 | [diff] [blame] | 352 | goto exit; |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame^] | 353 | if (msg_dest_droppable(msg)) |
| 354 | goto exit; |
| 355 | if (msg_errcode(msg)) |
Jon Paul Maloy | 8db1bae | 2014-06-25 20:41:35 -0500 | [diff] [blame] | 356 | goto exit; |
| 357 | |
| 358 | memcpy(&ohdr, msg, msg_hdr_sz(msg)); |
Jon Paul Maloy | ac0074e | 2014-06-25 20:41:41 -0500 | [diff] [blame^] | 359 | imp = min_t(uint, imp + 1, TIPC_CRITICAL_IMPORTANCE); |
| 360 | if (msg_isdata(msg)) |
| 361 | msg_set_importance(msg, imp); |
Jon Paul Maloy | 8db1bae | 2014-06-25 20:41:35 -0500 | [diff] [blame] | 362 | msg_set_errcode(msg, err); |
| 363 | msg_set_origport(msg, msg_destport(&ohdr)); |
| 364 | msg_set_destport(msg, msg_origport(&ohdr)); |
| 365 | msg_set_prevnode(msg, tipc_own_addr); |
| 366 | if (!msg_short(msg)) { |
| 367 | msg_set_orignode(msg, msg_destnode(&ohdr)); |
| 368 | msg_set_destnode(msg, msg_orignode(&ohdr)); |
| 369 | } |
| 370 | msg_set_size(msg, msg_hdr_sz(msg) + rdsz); |
| 371 | skb_trim(buf, msg_size(msg)); |
| 372 | skb_orphan(buf); |
| 373 | *dnode = msg_orignode(&ohdr); |
| 374 | return true; |
| 375 | exit: |
| 376 | kfree_skb(buf); |
| 377 | return false; |
| 378 | } |
Jon Paul Maloy | 5a37907 | 2014-06-25 20:41:36 -0500 | [diff] [blame] | 379 | |
| 380 | /** |
| 381 | * tipc_msg_eval: determine fate of message that found no destination |
| 382 | * @buf: the buffer containing the message. |
| 383 | * @dnode: return value: next-hop node, if message to be forwarded |
| 384 | * @err: error code to use, if message to be rejected |
| 385 | * |
| 386 | * Does not consume buffer |
| 387 | * Returns 0 (TIPC_OK) if message ok and we can try again, -TIPC error |
| 388 | * code if message to be rejected |
| 389 | */ |
| 390 | int tipc_msg_eval(struct sk_buff *buf, u32 *dnode) |
| 391 | { |
| 392 | struct tipc_msg *msg = buf_msg(buf); |
| 393 | u32 dport; |
| 394 | |
| 395 | if (msg_type(msg) != TIPC_NAMED_MSG) |
| 396 | return -TIPC_ERR_NO_PORT; |
| 397 | if (skb_linearize(buf)) |
| 398 | return -TIPC_ERR_NO_NAME; |
| 399 | if (msg_data_sz(msg) > MAX_FORWARD_SIZE) |
| 400 | return -TIPC_ERR_NO_NAME; |
| 401 | if (msg_reroute_cnt(msg) > 0) |
| 402 | return -TIPC_ERR_NO_NAME; |
| 403 | |
| 404 | *dnode = addr_domain(msg_lookup_scope(msg)); |
| 405 | dport = tipc_nametbl_translate(msg_nametype(msg), |
| 406 | msg_nameinst(msg), |
| 407 | dnode); |
| 408 | if (!dport) |
| 409 | return -TIPC_ERR_NO_NAME; |
| 410 | msg_incr_reroute_cnt(msg); |
| 411 | msg_set_destnode(msg, *dnode); |
| 412 | msg_set_destport(msg, dport); |
| 413 | return TIPC_OK; |
| 414 | } |