unix: implement L2TPIP socket address on Linux

Add constants and types to support IP-encapsulated L2TP/RFC3931
tunnels on Linux systems.

The L2TP subsystem for IP encapsulated tunnels hooks into the inet
kernel code using a specific IP protocol value.  In order to handle
this, anyToSockaddr now has to query the socket protocol type using
GetsockoptInt for the AF_INET and AF_INET6 address families.

Although this change is reasonably simple, unit tests have been added
to validate handling of the new types.

Fixes golang/go#37787

Change-Id: I16ae1e24dcced4ccc6ce6a79a90a5a2f6a560967
GitHub-Last-Rev: ca554ad1b6d3a5e55c70f05cf0e542968fa2418c
GitHub-Pull-Request: golang/sys#60
Reviewed-on: https://go-review.googlesource.com/c/sys/+/223157
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Tom Parkin
2020-03-16 20:21:46 +00:00
committed by Ian Lance Taylor
parent 5c8b2ff675
commit 9a0dfc3c55
6 changed files with 295 additions and 21 deletions
+8
View File
@@ -205,6 +205,8 @@ union sockaddr_all {
struct sockaddr_ll s5;
struct sockaddr_nl s6;
struct sockaddr_pppox s7;
struct sockaddr_l2tpip s8;
struct sockaddr_l2tpip6 s9;
};
struct sockaddr_any {
@@ -509,6 +511,10 @@ type RawSockaddrPPPoX [C.sizeof_struct_sockaddr_pppox]byte
type RawSockaddrTIPC C.struct_sockaddr_tipc
type RawSockaddrL2TPIP C.struct_sockaddr_l2tpip
type RawSockaddrL2TPIP6 C.struct_sockaddr_l2tpip6
type RawSockaddr C.struct_sockaddr
type RawSockaddrAny C.struct_sockaddr_any
@@ -561,6 +567,8 @@ const (
SizeofSockaddrXDP = C.sizeof_struct_sockaddr_xdp
SizeofSockaddrPPPoX = C.sizeof_struct_sockaddr_pppox
SizeofSockaddrTIPC = C.sizeof_struct_sockaddr_tipc
SizeofSockaddrL2TPIP = C.sizeof_struct_sockaddr_l2tpip
SizeofSockaddrL2TPIP6 = C.sizeof_struct_sockaddr_l2tpip6
SizeofLinger = C.sizeof_struct_linger
SizeofIovec = C.sizeof_struct_iovec
SizeofIPMreq = C.sizeof_struct_ip_mreq