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