1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38#ifndef _TIPC_ADDR_H
39#define _TIPC_ADDR_H
40
41#include <linux/types.h>
42#include <linux/tipc.h>
43#include <net/net_namespace.h>
44#include <net/netns/generic.h>
45#include "core.h"
46
47
48
49
50struct tipc_uaddr {
51 unsigned short family;
52 unsigned char addrtype;
53 signed char scope;
54 union {
55 struct {
56 struct tipc_service_addr sa;
57 u32 lookup_node;
58 };
59 struct tipc_service_range sr;
60 struct tipc_socket_addr sk;
61 };
62};
63
64static inline void tipc_uaddr(struct tipc_uaddr *ua, u32 atype, u32 scope,
65 u32 type, u32 lower, u32 upper)
66{
67 ua->family = AF_TIPC;
68 ua->addrtype = atype;
69 ua->scope = scope;
70 ua->sr.type = type;
71 ua->sr.lower = lower;
72 ua->sr.upper = upper;
73}
74
75static inline bool tipc_uaddr_valid(struct tipc_uaddr *ua, int len)
76{
77 u32 atype;
78
79 if (len < sizeof(struct sockaddr_tipc))
80 return false;
81 atype = ua->addrtype;
82 if (ua->family != AF_TIPC)
83 return false;
84 if (atype == TIPC_SERVICE_ADDR || atype == TIPC_SOCKET_ADDR)
85 return true;
86 if (atype == TIPC_SERVICE_RANGE)
87 return ua->sr.upper >= ua->sr.lower;
88 return false;
89}
90
91static inline u32 tipc_own_addr(struct net *net)
92{
93 return tipc_net(net)->node_addr;
94}
95
96static inline u8 *tipc_own_id(struct net *net)
97{
98 struct tipc_net *tn = tipc_net(net);
99
100 if (!strlen(tn->node_id_string))
101 return NULL;
102 return tn->node_id;
103}
104
105static inline char *tipc_own_id_string(struct net *net)
106{
107 return tipc_net(net)->node_id_string;
108}
109
110static inline u32 tipc_cluster_mask(u32 addr)
111{
112 return addr & TIPC_ZONE_CLUSTER_MASK;
113}
114
115static inline int tipc_node2scope(u32 node)
116{
117 return node ? TIPC_NODE_SCOPE : TIPC_CLUSTER_SCOPE;
118}
119
120static inline int tipc_scope2node(struct net *net, int sc)
121{
122 return sc != TIPC_NODE_SCOPE ? 0 : tipc_own_addr(net);
123}
124
125static inline int in_own_node(struct net *net, u32 addr)
126{
127 return addr == tipc_own_addr(net) || !addr;
128}
129
130bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr);
131void tipc_set_node_id(struct net *net, u8 *id);
132void tipc_set_node_addr(struct net *net, u32 addr);
133char *tipc_nodeid2string(char *str, u8 *id);
134u32 tipc_node_id2hash(u8 *id128);
135
136#endif
137