summaryrefslogtreecommitdiff
path: root/net/tipc/addr.h
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/addr.h')
-rw-r--r--net/tipc/addr.h113
1 files changed, 77 insertions, 36 deletions
diff --git a/net/tipc/addr.h b/net/tipc/addr.h
index 60b00ab93d74..a113cf7e1f89 100644
--- a/net/tipc/addr.h
+++ b/net/tipc/addr.h
@@ -1,8 +1,9 @@
/*
* net/tipc/addr.h: Include file for TIPC address utility routines
*
- * Copyright (c) 2000-2006, Ericsson AB
+ * Copyright (c) 2000-2006, 2018, Ericsson AB
* Copyright (c) 2004-2005, Wind River Systems
+ * Copyright (c) 2020-2021, Red Hat Inc
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -37,58 +38,98 @@
#ifndef _TIPC_ADDR_H
#define _TIPC_ADDR_H
-#define TIPC_ZONE_MASK 0xff000000u
-#define TIPC_CLUSTER_MASK 0xfffff000u
+#include <linux/types.h>
+#include <linux/tipc.h>
+#include <net/net_namespace.h>
+#include <net/netns/generic.h>
+#include "core.h"
-static inline u32 tipc_zone_mask(u32 addr)
+/* Struct tipc_uaddr: internal version of struct sockaddr_tipc.
+ * Must be kept aligned both regarding field positions and size.
+ */
+struct tipc_uaddr {
+ unsigned short family;
+ unsigned char addrtype;
+ signed char scope;
+ union {
+ struct {
+ struct tipc_service_addr sa;
+ u32 lookup_node;
+ };
+ struct tipc_service_range sr;
+ struct tipc_socket_addr sk;
+ };
+};
+
+static inline void tipc_uaddr(struct tipc_uaddr *ua, u32 atype, u32 scope,
+ u32 type, u32 lower, u32 upper)
{
- return addr & TIPC_ZONE_MASK;
+ ua->family = AF_TIPC;
+ ua->addrtype = atype;
+ ua->scope = scope;
+ ua->sr.type = type;
+ ua->sr.lower = lower;
+ ua->sr.upper = upper;
}
-static inline u32 tipc_cluster_mask(u32 addr)
+static inline bool tipc_uaddr_valid(struct tipc_uaddr *ua, int len)
{
- return addr & TIPC_CLUSTER_MASK;
+ u32 atype;
+
+ if (len < sizeof(struct sockaddr_tipc))
+ return false;
+ atype = ua->addrtype;
+ if (ua->family != AF_TIPC)
+ return false;
+ if (atype == TIPC_SERVICE_ADDR || atype == TIPC_SOCKET_ADDR)
+ return true;
+ if (atype == TIPC_SERVICE_RANGE)
+ return ua->sr.upper >= ua->sr.lower;
+ return false;
}
-static inline int in_own_cluster_exact(u32 addr)
+static inline u32 tipc_own_addr(struct net *net)
{
- return !((addr ^ tipc_own_addr) >> 12);
+ return tipc_net(net)->node_addr;
}
-/**
- * in_own_node - test for node inclusion; <0.0.0> always matches
- */
-static inline int in_own_node(u32 addr)
+static inline u8 *tipc_own_id(struct net *net)
{
- return (addr == tipc_own_addr) || !addr;
+ struct tipc_net *tn = tipc_net(net);
+
+ if (!strlen(tn->node_id_string))
+ return NULL;
+ return tn->node_id;
}
-/**
- * in_own_cluster - test for cluster inclusion; <0.0.0> always matches
- */
-static inline int in_own_cluster(u32 addr)
+static inline char *tipc_own_id_string(struct net *net)
{
- return in_own_cluster_exact(addr) || !addr;
+ return tipc_net(net)->node_id_string;
}
-/**
- * addr_domain - convert 2-bit scope value to equivalent message lookup domain
- *
- * Needed when address of a named message must be looked up a second time
- * after a network hop.
- */
-static inline u32 addr_domain(u32 sc)
+static inline u32 tipc_cluster_mask(u32 addr)
{
- if (likely(sc == TIPC_NODE_SCOPE))
- return tipc_own_addr;
- if (sc == TIPC_CLUSTER_SCOPE)
- return tipc_cluster_mask(tipc_own_addr);
- return tipc_zone_mask(tipc_own_addr);
+ return addr & TIPC_ZONE_CLUSTER_MASK;
}
-int tipc_addr_domain_valid(u32);
-int tipc_addr_node_valid(u32 addr);
-int tipc_in_scope(u32 domain, u32 addr);
-int tipc_addr_scope(u32 domain);
-char *tipc_addr_string_fill(char *string, u32 addr);
+static inline int tipc_node2scope(u32 node)
+{
+ return node ? TIPC_NODE_SCOPE : TIPC_CLUSTER_SCOPE;
+}
+
+static inline int tipc_scope2node(struct net *net, int sc)
+{
+ return sc != TIPC_NODE_SCOPE ? 0 : tipc_own_addr(net);
+}
+
+static inline int in_own_node(struct net *net, u32 addr)
+{
+ return addr == tipc_own_addr(net) || !addr;
+}
+
+bool tipc_in_scope(bool legacy_format, u32 domain, u32 addr);
+void tipc_set_node_id(struct net *net, u8 *id);
+void tipc_set_node_addr(struct net *net, u32 addr);
+int tipc_nodeid2string(char *str, u8 *id);
+
#endif