1607ca46eSDavid Howells /* 28941bbcdSYing Xue * include/uapi/linux/tipc_config.h: Header for TIPC configuration interface 3607ca46eSDavid Howells * 4607ca46eSDavid Howells * Copyright (c) 2003-2006, Ericsson AB 5607ca46eSDavid Howells * Copyright (c) 2005-2007, 2010-2011, Wind River Systems 6607ca46eSDavid Howells * All rights reserved. 7607ca46eSDavid Howells * 8607ca46eSDavid Howells * Redistribution and use in source and binary forms, with or without 9607ca46eSDavid Howells * modification, are permitted provided that the following conditions are met: 10607ca46eSDavid Howells * 11607ca46eSDavid Howells * 1. Redistributions of source code must retain the above copyright 12607ca46eSDavid Howells * notice, this list of conditions and the following disclaimer. 13607ca46eSDavid Howells * 2. Redistributions in binary form must reproduce the above copyright 14607ca46eSDavid Howells * notice, this list of conditions and the following disclaimer in the 15607ca46eSDavid Howells * documentation and/or other materials provided with the distribution. 16607ca46eSDavid Howells * 3. Neither the names of the copyright holders nor the names of its 17607ca46eSDavid Howells * contributors may be used to endorse or promote products derived from 18607ca46eSDavid Howells * this software without specific prior written permission. 19607ca46eSDavid Howells * 20607ca46eSDavid Howells * Alternatively, this software may be distributed under the terms of the 21607ca46eSDavid Howells * GNU General Public License ("GPL") version 2 as published by the Free 22607ca46eSDavid Howells * Software Foundation. 23607ca46eSDavid Howells * 24607ca46eSDavid Howells * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25607ca46eSDavid Howells * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26607ca46eSDavid Howells * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27607ca46eSDavid Howells * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 28607ca46eSDavid Howells * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29607ca46eSDavid Howells * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30607ca46eSDavid Howells * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31607ca46eSDavid Howells * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32607ca46eSDavid Howells * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33607ca46eSDavid Howells * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34607ca46eSDavid Howells * POSSIBILITY OF SUCH DAMAGE. 35607ca46eSDavid Howells */ 36607ca46eSDavid Howells 37607ca46eSDavid Howells #ifndef _LINUX_TIPC_CONFIG_H_ 38607ca46eSDavid Howells #define _LINUX_TIPC_CONFIG_H_ 39607ca46eSDavid Howells 40607ca46eSDavid Howells #include <linux/types.h> 41607ca46eSDavid Howells #include <linux/string.h> 4278acb1f9SErik Hugne #include <linux/tipc.h> 43607ca46eSDavid Howells #include <asm/byteorder.h> 44607ca46eSDavid Howells 45607ca46eSDavid Howells #ifndef __KERNEL__ 46607ca46eSDavid Howells #include <arpa/inet.h> /* for ntohs etc. */ 47607ca46eSDavid Howells #endif 48607ca46eSDavid Howells 49607ca46eSDavid Howells /* 50607ca46eSDavid Howells * Configuration 51607ca46eSDavid Howells * 52607ca46eSDavid Howells * All configuration management messaging involves sending a request message 53607ca46eSDavid Howells * to the TIPC configuration service on a node, which sends a reply message 54607ca46eSDavid Howells * back. (In the future multi-message replies may be supported.) 55607ca46eSDavid Howells * 56607ca46eSDavid Howells * Both request and reply messages consist of a transport header and payload. 57607ca46eSDavid Howells * The transport header contains info about the desired operation; 58607ca46eSDavid Howells * the payload consists of zero or more type/length/value (TLV) items 59607ca46eSDavid Howells * which specify parameters or results for the operation. 60607ca46eSDavid Howells * 61607ca46eSDavid Howells * For many operations, the request and reply messages have a fixed number 62607ca46eSDavid Howells * of TLVs (usually zero or one); however, some reply messages may return 63607ca46eSDavid Howells * a variable number of TLVs. A failed request is denoted by the presence 64607ca46eSDavid Howells * of an "error string" TLV in the reply message instead of the TLV(s) the 65607ca46eSDavid Howells * reply should contain if the request succeeds. 66607ca46eSDavid Howells */ 67607ca46eSDavid Howells 68607ca46eSDavid Howells /* 69607ca46eSDavid Howells * Public commands: 70607ca46eSDavid Howells * May be issued by any process. 71607ca46eSDavid Howells * Accepted by own node, or by remote node only if remote management enabled. 72607ca46eSDavid Howells */ 73607ca46eSDavid Howells 74607ca46eSDavid Howells #define TIPC_CMD_NOOP 0x0000 /* tx none, rx none */ 75607ca46eSDavid Howells #define TIPC_CMD_GET_NODES 0x0001 /* tx net_addr, rx node_info(s) */ 76607ca46eSDavid Howells #define TIPC_CMD_GET_MEDIA_NAMES 0x0002 /* tx none, rx media_name(s) */ 77607ca46eSDavid Howells #define TIPC_CMD_GET_BEARER_NAMES 0x0003 /* tx none, rx bearer_name(s) */ 78607ca46eSDavid Howells #define TIPC_CMD_GET_LINKS 0x0004 /* tx net_addr, rx link_info(s) */ 79607ca46eSDavid Howells #define TIPC_CMD_SHOW_NAME_TABLE 0x0005 /* tx name_tbl_query, rx ultra_string */ 80607ca46eSDavid Howells #define TIPC_CMD_SHOW_PORTS 0x0006 /* tx none, rx ultra_string */ 81607ca46eSDavid Howells #define TIPC_CMD_SHOW_LINK_STATS 0x000B /* tx link_name, rx ultra_string */ 82607ca46eSDavid Howells #define TIPC_CMD_SHOW_STATS 0x000F /* tx unsigned, rx ultra_string */ 83607ca46eSDavid Howells 84607ca46eSDavid Howells /* 85607ca46eSDavid Howells * Protected commands: 86607ca46eSDavid Howells * May only be issued by "network administration capable" process. 87607ca46eSDavid Howells * Accepted by own node, or by remote node only if remote management enabled 88607ca46eSDavid Howells * and this node is zone manager. 89607ca46eSDavid Howells */ 90607ca46eSDavid Howells 91607ca46eSDavid Howells #define TIPC_CMD_GET_REMOTE_MNG 0x4003 /* tx none, rx unsigned */ 92607ca46eSDavid Howells #define TIPC_CMD_GET_MAX_PORTS 0x4004 /* tx none, rx unsigned */ 93607ca46eSDavid Howells #define TIPC_CMD_GET_MAX_PUBL 0x4005 /* obsoleted */ 94607ca46eSDavid Howells #define TIPC_CMD_GET_MAX_SUBSCR 0x4006 /* obsoleted */ 95607ca46eSDavid Howells #define TIPC_CMD_GET_MAX_ZONES 0x4007 /* obsoleted */ 96607ca46eSDavid Howells #define TIPC_CMD_GET_MAX_CLUSTERS 0x4008 /* obsoleted */ 97607ca46eSDavid Howells #define TIPC_CMD_GET_MAX_NODES 0x4009 /* obsoleted */ 98607ca46eSDavid Howells #define TIPC_CMD_GET_MAX_SLAVES 0x400A /* obsoleted */ 99607ca46eSDavid Howells #define TIPC_CMD_GET_NETID 0x400B /* tx none, rx unsigned */ 100607ca46eSDavid Howells 101607ca46eSDavid Howells #define TIPC_CMD_ENABLE_BEARER 0x4101 /* tx bearer_config, rx none */ 102607ca46eSDavid Howells #define TIPC_CMD_DISABLE_BEARER 0x4102 /* tx bearer_name, rx none */ 103607ca46eSDavid Howells #define TIPC_CMD_SET_LINK_TOL 0x4107 /* tx link_config, rx none */ 104607ca46eSDavid Howells #define TIPC_CMD_SET_LINK_PRI 0x4108 /* tx link_config, rx none */ 105607ca46eSDavid Howells #define TIPC_CMD_SET_LINK_WINDOW 0x4109 /* tx link_config, rx none */ 106607ca46eSDavid Howells #define TIPC_CMD_SET_LOG_SIZE 0x410A /* obsoleted */ 107607ca46eSDavid Howells #define TIPC_CMD_DUMP_LOG 0x410B /* obsoleted */ 108607ca46eSDavid Howells #define TIPC_CMD_RESET_LINK_STATS 0x410C /* tx link_name, rx none */ 109607ca46eSDavid Howells 110607ca46eSDavid Howells /* 111607ca46eSDavid Howells * Private commands: 112607ca46eSDavid Howells * May only be issued by "network administration capable" process. 113607ca46eSDavid Howells * Accepted by own node only; cannot be used on a remote node. 114607ca46eSDavid Howells */ 115607ca46eSDavid Howells 116607ca46eSDavid Howells #define TIPC_CMD_SET_NODE_ADDR 0x8001 /* tx net_addr, rx none */ 117607ca46eSDavid Howells #define TIPC_CMD_SET_REMOTE_MNG 0x8003 /* tx unsigned, rx none */ 118607ca46eSDavid Howells #define TIPC_CMD_SET_MAX_PORTS 0x8004 /* tx unsigned, rx none */ 119607ca46eSDavid Howells #define TIPC_CMD_SET_MAX_PUBL 0x8005 /* obsoleted */ 120607ca46eSDavid Howells #define TIPC_CMD_SET_MAX_SUBSCR 0x8006 /* obsoleted */ 121607ca46eSDavid Howells #define TIPC_CMD_SET_MAX_ZONES 0x8007 /* obsoleted */ 122607ca46eSDavid Howells #define TIPC_CMD_SET_MAX_CLUSTERS 0x8008 /* obsoleted */ 123607ca46eSDavid Howells #define TIPC_CMD_SET_MAX_NODES 0x8009 /* obsoleted */ 124607ca46eSDavid Howells #define TIPC_CMD_SET_MAX_SLAVES 0x800A /* obsoleted */ 125607ca46eSDavid Howells #define TIPC_CMD_SET_NETID 0x800B /* tx unsigned, rx none */ 126607ca46eSDavid Howells 127607ca46eSDavid Howells /* 128607ca46eSDavid Howells * Reserved commands: 129607ca46eSDavid Howells * May not be issued by any process. 130607ca46eSDavid Howells * Used internally by TIPC. 131607ca46eSDavid Howells */ 132607ca46eSDavid Howells 133607ca46eSDavid Howells #define TIPC_CMD_NOT_NET_ADMIN 0xC001 /* tx none, rx none */ 134607ca46eSDavid Howells 135607ca46eSDavid Howells /* 136607ca46eSDavid Howells * TLV types defined for TIPC 137607ca46eSDavid Howells */ 138607ca46eSDavid Howells 139607ca46eSDavid Howells #define TIPC_TLV_NONE 0 /* no TLV present */ 140607ca46eSDavid Howells #define TIPC_TLV_VOID 1 /* empty TLV (0 data bytes)*/ 141607ca46eSDavid Howells #define TIPC_TLV_UNSIGNED 2 /* 32-bit integer */ 142607ca46eSDavid Howells #define TIPC_TLV_STRING 3 /* char[128] (max) */ 143607ca46eSDavid Howells #define TIPC_TLV_LARGE_STRING 4 /* char[2048] (max) */ 144607ca46eSDavid Howells #define TIPC_TLV_ULTRA_STRING 5 /* char[32768] (max) */ 145607ca46eSDavid Howells 146607ca46eSDavid Howells #define TIPC_TLV_ERROR_STRING 16 /* char[128] containing "error code" */ 147607ca46eSDavid Howells #define TIPC_TLV_NET_ADDR 17 /* 32-bit integer denoting <Z.C.N> */ 148607ca46eSDavid Howells #define TIPC_TLV_MEDIA_NAME 18 /* char[TIPC_MAX_MEDIA_NAME] */ 149607ca46eSDavid Howells #define TIPC_TLV_BEARER_NAME 19 /* char[TIPC_MAX_BEARER_NAME] */ 150607ca46eSDavid Howells #define TIPC_TLV_LINK_NAME 20 /* char[TIPC_MAX_LINK_NAME] */ 151607ca46eSDavid Howells #define TIPC_TLV_NODE_INFO 21 /* struct tipc_node_info */ 152607ca46eSDavid Howells #define TIPC_TLV_LINK_INFO 22 /* struct tipc_link_info */ 153607ca46eSDavid Howells #define TIPC_TLV_BEARER_CONFIG 23 /* struct tipc_bearer_config */ 154607ca46eSDavid Howells #define TIPC_TLV_LINK_CONFIG 24 /* struct tipc_link_config */ 155607ca46eSDavid Howells #define TIPC_TLV_NAME_TBL_QUERY 25 /* struct tipc_name_table_query */ 156607ca46eSDavid Howells #define TIPC_TLV_PORT_REF 26 /* 32-bit port reference */ 157607ca46eSDavid Howells 158607ca46eSDavid Howells /* 159607ca46eSDavid Howells * Link priority limits (min, default, max, media default) 160607ca46eSDavid Howells */ 161607ca46eSDavid Howells 162607ca46eSDavid Howells #define TIPC_MIN_LINK_PRI 0 163607ca46eSDavid Howells #define TIPC_DEF_LINK_PRI 10 164607ca46eSDavid Howells #define TIPC_MAX_LINK_PRI 31 165607ca46eSDavid Howells #define TIPC_MEDIA_LINK_PRI (TIPC_MAX_LINK_PRI + 1) 166607ca46eSDavid Howells 167607ca46eSDavid Howells /* 168607ca46eSDavid Howells * Link tolerance limits (min, default, max), in ms 169607ca46eSDavid Howells */ 170607ca46eSDavid Howells 171607ca46eSDavid Howells #define TIPC_MIN_LINK_TOL 50 172607ca46eSDavid Howells #define TIPC_DEF_LINK_TOL 1500 173607ca46eSDavid Howells #define TIPC_MAX_LINK_TOL 30000 174607ca46eSDavid Howells 175607ca46eSDavid Howells #if (TIPC_MIN_LINK_TOL < 16) 176607ca46eSDavid Howells #error "TIPC_MIN_LINK_TOL is too small (abort limit may be NaN)" 177607ca46eSDavid Howells #endif 178607ca46eSDavid Howells 179607ca46eSDavid Howells /* 180607ca46eSDavid Howells * Link window limits (min, default, max), in packets 181607ca46eSDavid Howells */ 182607ca46eSDavid Howells 183607ca46eSDavid Howells #define TIPC_MIN_LINK_WIN 16 184607ca46eSDavid Howells #define TIPC_DEF_LINK_WIN 50 185a6eacef7SErik Hugne #define TIPC_MAX_LINK_WIN 8191 186607ca46eSDavid Howells 187607ca46eSDavid Howells 188607ca46eSDavid Howells struct tipc_node_info { 189607ca46eSDavid Howells __be32 addr; /* network address of node */ 190607ca46eSDavid Howells __be32 up; /* 0=down, 1= up */ 191607ca46eSDavid Howells }; 192607ca46eSDavid Howells 193607ca46eSDavid Howells struct tipc_link_info { 194607ca46eSDavid Howells __be32 dest; /* network address of peer node */ 195607ca46eSDavid Howells __be32 up; /* 0=down, 1=up */ 196607ca46eSDavid Howells char str[TIPC_MAX_LINK_NAME]; /* link name */ 197607ca46eSDavid Howells }; 198607ca46eSDavid Howells 199607ca46eSDavid Howells struct tipc_bearer_config { 200607ca46eSDavid Howells __be32 priority; /* Range [1,31]. Override per link */ 201607ca46eSDavid Howells __be32 disc_domain; /* <Z.C.N> describing desired nodes */ 202607ca46eSDavid Howells char name[TIPC_MAX_BEARER_NAME]; 203607ca46eSDavid Howells }; 204607ca46eSDavid Howells 205607ca46eSDavid Howells struct tipc_link_config { 206607ca46eSDavid Howells __be32 value; 207607ca46eSDavid Howells char name[TIPC_MAX_LINK_NAME]; 208607ca46eSDavid Howells }; 209607ca46eSDavid Howells 210607ca46eSDavid Howells #define TIPC_NTQ_ALLTYPES 0x80000000 211607ca46eSDavid Howells 212607ca46eSDavid Howells struct tipc_name_table_query { 213607ca46eSDavid Howells __be32 depth; /* 1:type, 2:+name info, 3:+port info, 4+:+debug info */ 214607ca46eSDavid Howells __be32 type; /* {t,l,u} info ignored if high bit of "depth" is set */ 215607ca46eSDavid Howells __be32 lowbound; /* (i.e. displays all entries of name table) */ 216607ca46eSDavid Howells __be32 upbound; 217607ca46eSDavid Howells }; 218607ca46eSDavid Howells 219607ca46eSDavid Howells /* 220607ca46eSDavid Howells * The error string TLV is a null-terminated string describing the cause 221607ca46eSDavid Howells * of the request failure. To simplify error processing (and to save space) 222607ca46eSDavid Howells * the first character of the string can be a special error code character 223607ca46eSDavid Howells * (lying by the range 0x80 to 0xFF) which represents a pre-defined reason. 224607ca46eSDavid Howells */ 225607ca46eSDavid Howells 226607ca46eSDavid Howells #define TIPC_CFG_TLV_ERROR "\x80" /* request contains incorrect TLV(s) */ 227607ca46eSDavid Howells #define TIPC_CFG_NOT_NET_ADMIN "\x81" /* must be network administrator */ 228607ca46eSDavid Howells #define TIPC_CFG_NOT_ZONE_MSTR "\x82" /* must be zone master */ 229607ca46eSDavid Howells #define TIPC_CFG_NO_REMOTE "\x83" /* remote management not enabled */ 230607ca46eSDavid Howells #define TIPC_CFG_NOT_SUPPORTED "\x84" /* request is not supported by TIPC */ 231607ca46eSDavid Howells #define TIPC_CFG_INVALID_VALUE "\x85" /* request has invalid argument value */ 232607ca46eSDavid Howells 233607ca46eSDavid Howells /* 234607ca46eSDavid Howells * A TLV consists of a descriptor, followed by the TLV value. 235607ca46eSDavid Howells * TLV descriptor fields are stored in network byte order; 236607ca46eSDavid Howells * TLV values must also be stored in network byte order (where applicable). 237607ca46eSDavid Howells * TLV descriptors must be aligned to addresses which are multiple of 4, 238607ca46eSDavid Howells * so up to 3 bytes of padding may exist at the end of the TLV value area. 239607ca46eSDavid Howells * There must not be any padding between the TLV descriptor and its value. 240607ca46eSDavid Howells */ 241607ca46eSDavid Howells 242607ca46eSDavid Howells struct tlv_desc { 243607ca46eSDavid Howells __be16 tlv_len; /* TLV length (descriptor + value) */ 244607ca46eSDavid Howells __be16 tlv_type; /* TLV identifier */ 245607ca46eSDavid Howells }; 246607ca46eSDavid Howells 247607ca46eSDavid Howells #define TLV_ALIGNTO 4 248607ca46eSDavid Howells 249607ca46eSDavid Howells #define TLV_ALIGN(datalen) (((datalen)+(TLV_ALIGNTO-1)) & ~(TLV_ALIGNTO-1)) 250607ca46eSDavid Howells #define TLV_LENGTH(datalen) (sizeof(struct tlv_desc) + (datalen)) 251607ca46eSDavid Howells #define TLV_SPACE(datalen) (TLV_ALIGN(TLV_LENGTH(datalen))) 252607ca46eSDavid Howells #define TLV_DATA(tlv) ((void *)((char *)(tlv) + TLV_LENGTH(0))) 253607ca46eSDavid Howells 254607ca46eSDavid Howells static inline int TLV_OK(const void *tlv, __u16 space) 255607ca46eSDavid Howells { 256607ca46eSDavid Howells /* 257607ca46eSDavid Howells * Would also like to check that "tlv" is a multiple of 4, 258607ca46eSDavid Howells * but don't know how to do this in a portable way. 259607ca46eSDavid Howells * - Tried doing (!(tlv & (TLV_ALIGNTO-1))), but GCC compiler 260607ca46eSDavid Howells * won't allow binary "&" with a pointer. 261607ca46eSDavid Howells * - Tried casting "tlv" to integer type, but causes warning about size 262607ca46eSDavid Howells * mismatch when pointer is bigger than chosen type (int, long, ...). 263607ca46eSDavid Howells */ 264607ca46eSDavid Howells 265607ca46eSDavid Howells return (space >= TLV_SPACE(0)) && 266607ca46eSDavid Howells (ntohs(((struct tlv_desc *)tlv)->tlv_len) <= space); 267607ca46eSDavid Howells } 268607ca46eSDavid Howells 269607ca46eSDavid Howells static inline int TLV_CHECK(const void *tlv, __u16 space, __u16 exp_type) 270607ca46eSDavid Howells { 271607ca46eSDavid Howells return TLV_OK(tlv, space) && 272607ca46eSDavid Howells (ntohs(((struct tlv_desc *)tlv)->tlv_type) == exp_type); 273607ca46eSDavid Howells } 274607ca46eSDavid Howells 275d0796d1eSRichard Alpe static inline int TLV_GET_LEN(struct tlv_desc *tlv) 276d0796d1eSRichard Alpe { 277d0796d1eSRichard Alpe return ntohs(tlv->tlv_len); 278d0796d1eSRichard Alpe } 279d0796d1eSRichard Alpe 280*f2b3b2d4SRichard Alpe static inline void TLV_SET_LEN(struct tlv_desc *tlv, __u16 len) 281*f2b3b2d4SRichard Alpe { 282*f2b3b2d4SRichard Alpe tlv->tlv_len = htons(len); 283*f2b3b2d4SRichard Alpe } 284*f2b3b2d4SRichard Alpe 2859ab15465SRichard Alpe static inline int TLV_CHECK_TYPE(struct tlv_desc *tlv, __u16 type) 2869ab15465SRichard Alpe { 2879ab15465SRichard Alpe return (ntohs(tlv->tlv_type) == type); 2889ab15465SRichard Alpe } 2899ab15465SRichard Alpe 290*f2b3b2d4SRichard Alpe static inline void TLV_SET_TYPE(struct tlv_desc *tlv, __u16 type) 291*f2b3b2d4SRichard Alpe { 292*f2b3b2d4SRichard Alpe tlv->tlv_type = htons(type); 293*f2b3b2d4SRichard Alpe } 294*f2b3b2d4SRichard Alpe 295607ca46eSDavid Howells static inline int TLV_SET(void *tlv, __u16 type, void *data, __u16 len) 296607ca46eSDavid Howells { 297607ca46eSDavid Howells struct tlv_desc *tlv_ptr; 298607ca46eSDavid Howells int tlv_len; 299607ca46eSDavid Howells 300607ca46eSDavid Howells tlv_len = TLV_LENGTH(len); 301607ca46eSDavid Howells tlv_ptr = (struct tlv_desc *)tlv; 302607ca46eSDavid Howells tlv_ptr->tlv_type = htons(type); 303607ca46eSDavid Howells tlv_ptr->tlv_len = htons(tlv_len); 304607ca46eSDavid Howells if (len && data) 305607ca46eSDavid Howells memcpy(TLV_DATA(tlv_ptr), data, tlv_len); 306607ca46eSDavid Howells return TLV_SPACE(len); 307607ca46eSDavid Howells } 308607ca46eSDavid Howells 309607ca46eSDavid Howells /* 310607ca46eSDavid Howells * A TLV list descriptor simplifies processing of messages 311607ca46eSDavid Howells * containing multiple TLVs. 312607ca46eSDavid Howells */ 313607ca46eSDavid Howells 314607ca46eSDavid Howells struct tlv_list_desc { 315607ca46eSDavid Howells struct tlv_desc *tlv_ptr; /* ptr to current TLV */ 316607ca46eSDavid Howells __u32 tlv_space; /* # bytes from curr TLV to list end */ 317607ca46eSDavid Howells }; 318607ca46eSDavid Howells 319607ca46eSDavid Howells static inline void TLV_LIST_INIT(struct tlv_list_desc *list, 320607ca46eSDavid Howells void *data, __u32 space) 321607ca46eSDavid Howells { 322607ca46eSDavid Howells list->tlv_ptr = (struct tlv_desc *)data; 323607ca46eSDavid Howells list->tlv_space = space; 324607ca46eSDavid Howells } 325607ca46eSDavid Howells 326607ca46eSDavid Howells static inline int TLV_LIST_EMPTY(struct tlv_list_desc *list) 327607ca46eSDavid Howells { 328607ca46eSDavid Howells return (list->tlv_space == 0); 329607ca46eSDavid Howells } 330607ca46eSDavid Howells 331607ca46eSDavid Howells static inline int TLV_LIST_CHECK(struct tlv_list_desc *list, __u16 exp_type) 332607ca46eSDavid Howells { 333607ca46eSDavid Howells return TLV_CHECK(list->tlv_ptr, list->tlv_space, exp_type); 334607ca46eSDavid Howells } 335607ca46eSDavid Howells 336607ca46eSDavid Howells static inline void *TLV_LIST_DATA(struct tlv_list_desc *list) 337607ca46eSDavid Howells { 338607ca46eSDavid Howells return TLV_DATA(list->tlv_ptr); 339607ca46eSDavid Howells } 340607ca46eSDavid Howells 341607ca46eSDavid Howells static inline void TLV_LIST_STEP(struct tlv_list_desc *list) 342607ca46eSDavid Howells { 343607ca46eSDavid Howells __u16 tlv_space = TLV_ALIGN(ntohs(list->tlv_ptr->tlv_len)); 344607ca46eSDavid Howells 345607ca46eSDavid Howells list->tlv_ptr = (struct tlv_desc *)((char *)list->tlv_ptr + tlv_space); 346607ca46eSDavid Howells list->tlv_space -= tlv_space; 347607ca46eSDavid Howells } 348607ca46eSDavid Howells 349607ca46eSDavid Howells /* 350607ca46eSDavid Howells * Configuration messages exchanged via NETLINK_GENERIC use the following 351607ca46eSDavid Howells * family id, name, version and command. 352607ca46eSDavid Howells */ 353607ca46eSDavid Howells #define TIPC_GENL_NAME "TIPC" 354607ca46eSDavid Howells #define TIPC_GENL_VERSION 0x1 355607ca46eSDavid Howells #define TIPC_GENL_CMD 0x1 356607ca46eSDavid Howells 357607ca46eSDavid Howells /* 358607ca46eSDavid Howells * TIPC specific header used in NETLINK_GENERIC requests. 359607ca46eSDavid Howells */ 360607ca46eSDavid Howells struct tipc_genlmsghdr { 361607ca46eSDavid Howells __u32 dest; /* Destination address */ 362607ca46eSDavid Howells __u16 cmd; /* Command */ 363607ca46eSDavid Howells __u16 reserved; /* Unused */ 364607ca46eSDavid Howells }; 365607ca46eSDavid Howells 366607ca46eSDavid Howells #define TIPC_GENL_HDRLEN NLMSG_ALIGN(sizeof(struct tipc_genlmsghdr)) 367607ca46eSDavid Howells 368607ca46eSDavid Howells /* 369607ca46eSDavid Howells * Configuration messages exchanged via TIPC sockets use the TIPC configuration 370607ca46eSDavid Howells * message header, which is defined below. This structure is analogous 371607ca46eSDavid Howells * to the Netlink message header, but fields are stored in network byte order 372607ca46eSDavid Howells * and no padding is permitted between the header and the message data 373607ca46eSDavid Howells * that follows. 374607ca46eSDavid Howells */ 375607ca46eSDavid Howells 376607ca46eSDavid Howells struct tipc_cfg_msg_hdr { 377607ca46eSDavid Howells __be32 tcm_len; /* Message length (including header) */ 378607ca46eSDavid Howells __be16 tcm_type; /* Command type */ 379607ca46eSDavid Howells __be16 tcm_flags; /* Additional flags */ 380607ca46eSDavid Howells char tcm_reserved[8]; /* Unused */ 381607ca46eSDavid Howells }; 382607ca46eSDavid Howells 383607ca46eSDavid Howells #define TCM_F_REQUEST 0x1 /* Flag: Request message */ 384607ca46eSDavid Howells #define TCM_F_MORE 0x2 /* Flag: Message to be continued */ 385607ca46eSDavid Howells 386607ca46eSDavid Howells #define TCM_ALIGN(datalen) (((datalen)+3) & ~3) 387607ca46eSDavid Howells #define TCM_LENGTH(datalen) (sizeof(struct tipc_cfg_msg_hdr) + datalen) 388607ca46eSDavid Howells #define TCM_SPACE(datalen) (TCM_ALIGN(TCM_LENGTH(datalen))) 389607ca46eSDavid Howells #define TCM_DATA(tcm_hdr) ((void *)((char *)(tcm_hdr) + TCM_LENGTH(0))) 390607ca46eSDavid Howells 391607ca46eSDavid Howells static inline int TCM_SET(void *msg, __u16 cmd, __u16 flags, 392607ca46eSDavid Howells void *data, __u16 data_len) 393607ca46eSDavid Howells { 394607ca46eSDavid Howells struct tipc_cfg_msg_hdr *tcm_hdr; 395607ca46eSDavid Howells int msg_len; 396607ca46eSDavid Howells 397607ca46eSDavid Howells msg_len = TCM_LENGTH(data_len); 398607ca46eSDavid Howells tcm_hdr = (struct tipc_cfg_msg_hdr *)msg; 399607ca46eSDavid Howells tcm_hdr->tcm_len = htonl(msg_len); 400607ca46eSDavid Howells tcm_hdr->tcm_type = htons(cmd); 401607ca46eSDavid Howells tcm_hdr->tcm_flags = htons(flags); 402607ca46eSDavid Howells if (data_len && data) 403607ca46eSDavid Howells memcpy(TCM_DATA(msg), data, data_len); 404607ca46eSDavid Howells return TCM_SPACE(data_len); 405607ca46eSDavid Howells } 406607ca46eSDavid Howells 407607ca46eSDavid Howells #endif 408