Skip to content

Commit

Permalink
OS-4131 lxbrand AF_NETLINK should be handled consistently
Browse files Browse the repository at this point in the history
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
  • Loading branch information
pfmooney committed Apr 20, 2015
1 parent ba34187 commit fcf0f42
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
26 changes: 12 additions & 14 deletions usr/src/lib/brand/lx/lx_brand/common/socket.c
Expand Up @@ -140,21 +140,24 @@ static const int ltos_family[LX_AF_MAX + 1] = {
AF_PACKET, AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED,
AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED,
AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED,
AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED
AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED,
AF_NOTSUPPORTED
};

#define LX_AF_INET6 10
#define LX_AF_NETLINK 16
#define LX_AF_PACKET 17

static const int stol_family[LX_AF_MAX + 1] = {
AF_UNSPEC, AF_UNIX, AF_INET, AF_NOTSUPPORTED, AF_NOTSUPPORTED,
AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED,
AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED,
AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_LX_NETLINK,
AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED,
AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED,
AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED,
AF_NOTSUPPORTED, LX_AF_INET6, AF_NOTSUPPORTED, AF_NOTSUPPORTED,
AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED, LX_AF_PACKET
AF_NOTSUPPORTED, AF_NOTSUPPORTED, AF_NOTSUPPORTED, LX_AF_PACKET,
LX_AF_NETLINK
};

#define LTOS_FAMILY(d) ((d) <= LX_AF_MAX ? ltos_family[(d)] : AF_INVAL)
Expand Down Expand Up @@ -616,7 +619,6 @@ struct lx_bpf_program {
#define LX_TO_SOL 1
#define SOL_TO_LX 2

#define LX_AF_NETLINK 16
#define LX_NETLINK_KOBJECT_UEVENT 15
#define LX_NETLINK_ROUTE 0

Expand Down Expand Up @@ -1069,7 +1071,6 @@ static int
stol_sockaddr(struct sockaddr *addr, socklen_t *len,
struct sockaddr *inaddr, socklen_t inlen, socklen_t orig)
{
struct sockaddr_in6 stemp;
int size = inlen;

switch (inaddr->sa_family) {
Expand All @@ -1081,17 +1082,12 @@ stol_sockaddr(struct sockaddr *addr, socklen_t *len,
case AF_INET6:
if (inlen != sizeof (struct sockaddr_in6))
return (EINVAL);
size = (sizeof (lx_sockaddr_in6_t));

if (uucopy(inaddr, &stemp, inlen) < 0)
return (errno);
/*
* AF_INET6 is different between Linux/illumos.
* Perform this translation in a temporary sockaddr.
* The linux sockaddr_in6 is shorter than illumos.
* We just truncate the extra field on the way out
*/
stemp.sin6_family = STOL_FAMILY(stemp.sin6_family);
inaddr = (struct sockaddr *)&stemp;
inlen = sizeof (lx_sockaddr_in6_t);
size = (sizeof (lx_sockaddr_in6_t));
inlen = (sizeof (lx_sockaddr_in6_t));
break;

case AF_UNIX:
Expand All @@ -1109,6 +1105,8 @@ stol_sockaddr(struct sockaddr *addr, socklen_t *len,
break;
}

inaddr->sa_family = STOL_FAMILY(inaddr->sa_family);

/*
* If inlen is larger than orig, copy out the maximum amount of
* data possible and then update *len to indicate the actual
Expand Down
2 changes: 1 addition & 1 deletion usr/src/lib/brand/lx/lx_brand/sys/lx_socket.h
Expand Up @@ -63,7 +63,7 @@ extern "C" {
#define LX_AF_PPPOX 24 /* PPPoX sockets */
#define LX_AF_WANPIPE 25 /* Wanpipe API sockets */
#define LX_AF_BLUETOOTH 31 /* Bluetooth sockets */
#define LX_AF_MAX 32 /* MAX socket type */
#define LX_AF_MAX 33 /* MAX socket type */

#define AF_NOTSUPPORTED -1
#define AF_INVAL -2
Expand Down
11 changes: 1 addition & 10 deletions usr/src/uts/common/brand/lx/io/lx_netlink.c
Expand Up @@ -384,20 +384,11 @@ lx_netlink_getsockname(sock_lower_handle_t handle, struct sockaddr *sa,
{
lx_netlink_sock_t *lxsock = (lx_netlink_sock_t *)handle;
lx_netlink_sockaddr_t *lxsa = (lx_netlink_sockaddr_t *)sa;
proc_t *p = curthread->t_procp;

if (*len < sizeof (lx_netlink_sockaddr_t))
return (EINVAL);

/*
* Make sure our lies are consistent with the lies told by other liars.
*/
if (PROC_IS_BRANDED(p) && curthread != p->p_agenttp) {
lxsa->lxnl_family = LX_AF_NETLINK;
} else {
lxsa->lxnl_family = AF_LX_NETLINK;
}

lxsa->lxnl_family = AF_LX_NETLINK;
lxsa->lxnl_pad = 0;
lxsa->lxnl_port = lxsock->lxns_port;
lxsa->lxnl_groups = 0;
Expand Down

0 comments on commit fcf0f42

Please sign in to comment.