18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * include/net/tipc.h: Include file for TIPC message header routines 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2017 Ericsson AB 58c2ecf20Sopenharmony_ci * All rights reserved. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 88c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions are met: 98c2ecf20Sopenharmony_ci * 108c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 118c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 128c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 138c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 148c2ecf20Sopenharmony_ci * documentation and/or other materials provided with the distribution. 158c2ecf20Sopenharmony_ci * 3. Neither the names of the copyright holders nor the names of its 168c2ecf20Sopenharmony_ci * contributors may be used to endorse or promote products derived from 178c2ecf20Sopenharmony_ci * this software without specific prior written permission. 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 208c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free 218c2ecf20Sopenharmony_ci * Software Foundation. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 248c2ecf20Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 258c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 268c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 278c2ecf20Sopenharmony_ci * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 288c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 298c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 308c2ecf20Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 318c2ecf20Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 328c2ecf20Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 338c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGE. 348c2ecf20Sopenharmony_ci */ 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#ifndef _TIPC_HDR_H 378c2ecf20Sopenharmony_ci#define _TIPC_HDR_H 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci#include <linux/random.h> 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#define KEEPALIVE_MSG_MASK 0x0e080000 /* LINK_PROTOCOL + MSG_IS_KEEPALIVE */ 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_cistruct tipc_basic_hdr { 448c2ecf20Sopenharmony_ci __be32 w[4]; 458c2ecf20Sopenharmony_ci}; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cistatic inline __be32 tipc_hdr_rps_key(struct tipc_basic_hdr *hdr) 488c2ecf20Sopenharmony_ci{ 498c2ecf20Sopenharmony_ci u32 w0 = ntohl(hdr->w[0]); 508c2ecf20Sopenharmony_ci bool keepalive_msg = (w0 & KEEPALIVE_MSG_MASK) == KEEPALIVE_MSG_MASK; 518c2ecf20Sopenharmony_ci __be32 key; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci /* Return source node identity as key */ 548c2ecf20Sopenharmony_ci if (likely(!keepalive_msg)) 558c2ecf20Sopenharmony_ci return hdr->w[3]; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci /* Spread PROBE/PROBE_REPLY messages across the cores */ 588c2ecf20Sopenharmony_ci get_random_bytes(&key, sizeof(key)); 598c2ecf20Sopenharmony_ci return key; 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#endif 63