Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * include/net/tipc.h: Include file for TIPC message header routines
0003  *
0004  * Copyright (c) 2017 Ericsson AB
0005  * All rights reserved.
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions are met:
0009  *
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  * 3. Neither the names of the copyright holders nor the names of its
0016  *    contributors may be used to endorse or promote products derived from
0017  *    this software without specific prior written permission.
0018  *
0019  * Alternatively, this software may be distributed under the terms of the
0020  * GNU General Public License ("GPL") version 2 as published by the Free
0021  * Software Foundation.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0024  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0025  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0026  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0027  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0028  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0029  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0032  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0033  * POSSIBILITY OF SUCH DAMAGE.
0034  */
0035 
0036 #ifndef _TIPC_HDR_H
0037 #define _TIPC_HDR_H
0038 
0039 #include <linux/random.h>
0040 
0041 #define KEEPALIVE_MSG_MASK 0x0e080000  /* LINK_PROTOCOL + MSG_IS_KEEPALIVE */
0042 
0043 struct tipc_basic_hdr {
0044     __be32 w[4];
0045 };
0046 
0047 static inline __be32 tipc_hdr_rps_key(struct tipc_basic_hdr *hdr)
0048 {
0049     u32 w0 = ntohl(hdr->w[0]);
0050     bool keepalive_msg = (w0 & KEEPALIVE_MSG_MASK) == KEEPALIVE_MSG_MASK;
0051     __be32 key;
0052 
0053     /* Return source node identity as key */
0054     if (likely(!keepalive_msg))
0055         return hdr->w[3];
0056 
0057     /* Spread PROBE/PROBE_REPLY messages across the cores */
0058     get_random_bytes(&key, sizeof(key));
0059     return key;
0060 }
0061 
0062 #endif