unix: implement AF_TIPC sockets on Linux

Adds initial constants and types to use with SockaddrTIPC. For more
information on TIPC, see: http://tipc.sourceforge.net/.

Because the C struct sockaddr_tipc makes use of a union for its addr
field, I have created a wrapping layer in SockaddrTIPC that uses
an interface to determine which variant is in use.

Tests accompany this change due to the complexity of this code. There
is currently little test coverage in the Sockaddr-related code, but
perhaps this is something that could be picked up as a relatively
straightforward task for a new contributor.

Change-Id: I5033a0685cb7128d4b1a23d18aca71c202d0c0aa
Reviewed-on: https://go-review.googlesource.com/c/sys/+/187960
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Matt Layher
2019-09-04 00:50:37 +00:00
parent 1f305c863d
commit 43c01164e9
30 changed files with 2030 additions and 0 deletions
+37
View File
@@ -107,6 +107,7 @@ struct termios2 {
#include <linux/if_xdp.h>
#include <linux/ncsi.h>
#include <linux/cryptouser.h>
#include <linux/tipc.h>
// abi/abi.h generated by mkall.go.
#include "abi/abi.h"
@@ -357,6 +358,16 @@ struct my_blkpg_partition {
unsigned char volname[BLKPG_VOLNAMELTH];
};
// tipc_service_name is a copied and slightly modified form of the "name"
// variant in sockaddr_tipc's union in tipc.h, so it can be exported as part of
// SockaddrTIPC's API.
struct tipc_service_name {
// From tipc_service_addr.
__u32 type;
__u32 instance;
// From the union.
__u32 domain;
};
*/
import "C"
@@ -465,6 +476,8 @@ type RawSockaddrXDP C.struct_sockaddr_xdp
type RawSockaddrPPPoX [C.sizeof_struct_sockaddr_pppox]byte
type RawSockaddrTIPC C.struct_sockaddr_tipc
type RawSockaddr C.struct_sockaddr
type RawSockaddrAny C.struct_sockaddr_any
@@ -516,6 +529,7 @@ const (
SizeofSockaddrVM = C.sizeof_struct_sockaddr_vm
SizeofSockaddrXDP = C.sizeof_struct_sockaddr_xdp
SizeofSockaddrPPPoX = C.sizeof_struct_sockaddr_pppox
SizeofSockaddrTIPC = C.sizeof_struct_sockaddr_tipc
SizeofLinger = C.sizeof_struct_linger
SizeofIovec = C.sizeof_struct_iovec
SizeofIPMreq = C.sizeof_struct_ip_mreq
@@ -2017,3 +2031,26 @@ const (
type LoopInfo C.struct_loop_info
type LoopInfo64 C.struct_loop_info64
// AF_TIPC
type TIPCSocketAddr C.struct_tipc_socket_addr
type TIPCServiceRange C.struct_tipc_service_range
type TIPCServiceName C.struct_tipc_service_name
type TIPCSubscr C.struct_tipc_subscr
type TIPCEvent C.struct_tipc_event
type TIPCGroupReq C.struct_tipc_group_req
type TIPCSIOCLNReq C.struct_tipc_sioc_ln_req
type TIPCSIOCNodeIDReq C.struct_tipc_sioc_nodeid_req
const (
TIPC_CLUSTER_SCOPE = C.TIPC_CLUSTER_SCOPE
TIPC_NODE_SCOPE = C.TIPC_NODE_SCOPE
)