From: Jon Maloy <jma...@redhat.com>

We introduce a simplified version of struct sockaddr_tipc, using
anonymous unions and structures. Apart from being nicer to work with,
this struct will come in handy when we in a later commit add another
address type.

Signed-off-by: Jon Maloy <jma...@redhat.com>
---
 net/tipc/addr.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/net/tipc/addr.h b/net/tipc/addr.h
index 1a11831bef62..2d7992e5da64 100644
--- a/net/tipc/addr.h
+++ b/net/tipc/addr.h
@@ -44,6 +44,50 @@
 #include <net/netns/generic.h>
 #include "core.h"
 
+/* 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)
+{
+       ua->family = AF_TIPC;
+       ua->addrtype = atype;
+       ua->scope = scope;
+       ua->sr.type = type;
+       ua->sr.lower = lower;
+       ua->sr.upper = upper;
+}
+
+static inline bool tipc_uaddr_valid(struct tipc_uaddr *ua, int len)
+{
+       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 u32 tipc_own_addr(struct net *net)
 {
        return tipc_net(net)->node_addr;
-- 
2.28.0



_______________________________________________
tipc-discussion mailing list
tipc-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tipc-discussion

Reply via email to