PSARC 2006/712 Extend SO_PROTOTYPE
6500183 Make SO_PROTOTYPE work with non raw socket
--- a/usr/src/cmd/truss/print.c Mon Jan 08 20:19:20 2007 -0800
+++ b/usr/src/cmd/truss/print.c Mon Jan 08 20:32:18 2007 -0800
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -1769,6 +1769,7 @@
case SO_PROTOTYPE: return ("SO_PROTOTYPE");
case SO_ALLZONES: return ("SO_ALLZONES");
case SO_EXCLBIND: return ("SO_EXCLBIND");
+ case SO_DOMAIN: return ("SO_DOMAIN");
default: (void) snprintf(pri->code_buf, CBSIZE,
"0x%lx", val);
--- a/usr/src/uts/common/fs/sockfs/socksctp.c Mon Jan 08 20:19:20 2007 -0800
+++ b/usr/src/uts/common/fs/sockfs/socksctp.c Mon Jan 08 20:32:18 2007 -0800
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -1670,6 +1670,14 @@
if (level == SOL_SOCKET) {
switch (option_name) {
+ /* Not supported options */
+ case SO_SNDTIMEO:
+ case SO_RCVTIMEO:
+ case SO_EXCLBIND:
+ error = ENOPROTOOPT;
+ eprintsoline(so, error);
+ goto done;
+
case SO_TYPE:
case SO_ERROR:
case SO_DEBUG:
@@ -1685,6 +1693,8 @@
case SO_SNDLOWAT:
case SO_RCVLOWAT:
case SO_DGRAM_ERRIND:
+ case SO_PROTOTYPE:
+ case SO_DOMAIN:
if (maxlen < (t_uscalar_t)sizeof (int32_t)) {
error = EINVAL;
eprintsoline(so, error);
@@ -1702,6 +1712,11 @@
len = (t_uscalar_t)sizeof (uint32_t); /* Default */
option = &value;
+ /*
+ * Most of the SOL_SOCKET level option values are also
+ * recorded in sockfs. So we can return the recorded value
+ * here without calling into SCTP.
+ */
switch (option_name) {
case SO_TYPE:
value = so->so_type;
@@ -1727,34 +1742,34 @@
value = (so->so_options & option_name);
goto copyout;
- /*
- * The following options are only returned by sockfs
- * when sctp_get_opt() fails.
- */
+ case SO_SNDBUF:
+ value = so->so_sndbuf;
+ goto copyout;
+
+ case SO_RCVBUF:
+ value = so->so_rcvbuf;
+ goto copyout;
+
+ case SO_SNDLOWAT:
+ value = so->so_sndlowat;
+ goto copyout;
+
+ case SO_RCVLOWAT:
+ value = so->so_rcvlowat;
+ goto copyout;
+
+ case SO_PROTOTYPE:
+ value = IPPROTO_SCTP;
+ goto copyout;
+
+ case SO_DOMAIN:
+ value = so->so_family;
+ goto copyout;
case SO_LINGER:
option = &so->so_linger;
len = (t_uscalar_t)sizeof (struct linger);
break;
- case SO_SNDBUF:
- value = so->so_sndbuf;
- len = (t_uscalar_t)sizeof (int);
- goto copyout;
-
- case SO_RCVBUF:
- value = so->so_rcvbuf;
- len = (t_uscalar_t)sizeof (int);
- goto copyout;
-
- case SO_SNDLOWAT:
- value = so->so_sndlowat;
- len = (t_uscalar_t)sizeof (int);
- goto copyout;
-
- case SO_RCVLOWAT:
- value = so->so_rcvlowat;
- len = (t_uscalar_t)sizeof (int);
- goto copyout;
default:
option = NULL;
@@ -2004,9 +2019,14 @@
#define intvalue (*(int32_t *)optval)
switch (option_name) {
+ case SO_SNDTIMEO:
+ case SO_RCVTIMEO:
+ case SO_EXCLBIND:
case SO_TYPE:
case SO_ERROR:
case SO_ACCEPTCONN:
+ case SO_PROTOTYPE:
+ case SO_DOMAIN:
/* Can't be set */
error = ENOPROTOOPT;
goto done;
--- a/usr/src/uts/common/fs/sockfs/socktpi.c Mon Jan 08 20:19:20 2007 -0800
+++ b/usr/src/uts/common/fs/sockfs/socktpi.c Mon Jan 08 20:32:18 2007 -0800
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -4804,6 +4804,7 @@
case SO_SNDTIMEO:
case SO_RCVTIMEO:
#endif /* notyet */
+ case SO_DOMAIN:
case SO_DGRAM_ERRIND:
if (maxlen < (t_uscalar_t)sizeof (int32_t)) {
error = EINVAL;
@@ -4940,6 +4941,11 @@
len = (t_uscalar_t)sizeof (so->so_rcvbuf);
break;
}
+ case SO_DOMAIN:
+ value = so->so_family;
+ option = &value;
+ goto copyout; /* No need to issue T_SVR4_OPTMGMT_REQ */
+
#ifdef notyet
/*
* We do not implement the semantics of these options
--- a/usr/src/uts/common/inet/ip/icmp.c Mon Jan 08 20:19:20 2007 -0800
+++ b/usr/src/uts/common/inet/ip/icmp.c Mon Jan 08 20:32:18 2007 -0800
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1990 Mentat Inc. */
@@ -1571,6 +1571,10 @@
case SO_MAC_EXEMPT:
*i1 = icmp->icmp_mac_exempt;
break;
+ case SO_DOMAIN:
+ *i1 = icmp->icmp_family;
+ break;
+
/*
* Following four not meaningful for icmp
* Action is same as "default" to which we fallthrough
--- a/usr/src/uts/common/inet/ip/icmp_opt_data.c Mon Jan 08 20:19:20 2007 -0800
+++ b/usr/src/uts/common/inet/ip/icmp_opt_data.c Mon Jan 08 20:32:18 2007 -0800
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -92,6 +92,7 @@
{ SO_ALLZONES, SOL_SOCKET, OA_R, OA_RW, OP_CONFIG, OP_PASSNEXT, sizeof (int),
0 },
+{ SO_DOMAIN, SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
{ IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP,
(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT),
--- a/usr/src/uts/common/inet/ip/rts.c Mon Jan 08 20:19:20 2007 -0800
+++ b/usr/src/uts/common/inet/ip/rts.c Mon Jan 08 20:32:18 2007 -0800
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -540,6 +539,9 @@
ASSERT(q->q_hiwat <= INT_MAX);
*i1 = (int)(RD(q)->q_hiwat);
break;
+ case SO_DOMAIN:
+ *i1 = PF_ROUTE;
+ break;
default:
return (-1);
}
--- a/usr/src/uts/common/inet/ip/rts_opt_data.c Mon Jan 08 20:19:20 2007 -0800
+++ b/usr/src/uts/common/inet/ip/rts_opt_data.c Mon Jan 08 20:32:18 2007 -0800
@@ -2,9 +2,8 @@
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License"). You may not use this file except in compliance
- * with the License.
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
@@ -20,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 1998-2003 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -69,6 +68,7 @@
{ SO_SNDBUF, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
{ SO_RCVBUF, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
{ SO_PROTOTYPE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
+{ SO_DOMAIN, SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
};
/*
--- a/usr/src/uts/common/inet/sctp/sctp_opt_data.c Mon Jan 08 20:19:20 2007 -0800
+++ b/usr/src/uts/common/inet/sctp/sctp_opt_data.c Mon Jan 08 20:32:18 2007 -0800
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -681,6 +681,7 @@
int buflen = *optlen;
conn_t *connp = sctp->sctp_connp;
ip6_pkt_t *ipp = &sctp->sctp_sticky_ipp;
+
/* In most cases, the return buffer is just an int */
*optlen = sizeof (int32_t);
@@ -727,8 +728,14 @@
case SO_MAC_EXEMPT:
*i1 = connp->conn_mac_exempt;
break;
+ case SO_PROTOTYPE:
+ *i1 = IPPROTO_SCTP;
+ break;
+ case SO_DOMAIN:
+ *i1 = sctp->sctp_family;
+ break;
default:
- retval = EINVAL;
+ retval = ENOPROTOOPT;
break;
}
break;
@@ -874,7 +881,7 @@
case SCTP_DISABLE_FRAGMENTS:
/* Not yet supported. */
default:
- retval = EINVAL;
+ retval = ENOPROTOOPT;
break;
}
break;
@@ -940,7 +947,7 @@
}
break;
default:
- retval = EINVAL;
+ retval = ENOPROTOOPT;
break;
}
break;
@@ -1099,13 +1106,13 @@
*i1 = sctp->sctp_connp->conn_ipv6_v6only;
break;
default:
- retval = EINVAL;
+ retval = ENOPROTOOPT;
break;
}
break;
default:
- retval = EINVAL;
+ retval = ENOPROTOOPT;
break;
}
WAKE_SCTP(sctp);
@@ -1242,7 +1249,7 @@
connp->conn_mac_exempt = onoff;
break;
default:
- retval = EINVAL;
+ retval = ENOPROTOOPT;
break;
}
break;
@@ -1373,7 +1380,7 @@
case SCTP_DISABLE_FRAGMENTS:
/* Not yet supported. */
default:
- retval = EINVAL;
+ retval = ENOPROTOOPT;
break;
}
break;
@@ -1453,7 +1460,7 @@
break;
}
default:
- retval = EINVAL;
+ retval = ENOPROTOOPT;
break;
}
break;
@@ -1746,13 +1753,13 @@
}
break;
default:
- retval = EINVAL;
+ retval = ENOPROTOOPT;
break;
}
break;
}
default:
- retval = EINVAL;
+ retval = ENOPROTOOPT;
break;
}
--- a/usr/src/uts/common/inet/tcp/tcp.c Mon Jan 08 20:19:20 2007 -0800
+++ b/usr/src/uts/common/inet/tcp/tcp.c Mon Jan 08 20:32:18 2007 -0800
@@ -20,7 +20,7 @@
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1990 Mentat Inc. */
@@ -9852,6 +9852,12 @@
case SO_EXCLBIND:
*i1 = tcp->tcp_exclbind ? SO_EXCLBIND : 0;
break;
+ case SO_PROTOTYPE:
+ *i1 = IPPROTO_TCP;
+ break;
+ case SO_DOMAIN:
+ *i1 = tcp->tcp_family;
+ break;
default:
return (-1);
}
--- a/usr/src/uts/common/inet/tcp/tcp_opt_data.c Mon Jan 08 20:19:20 2007 -0800
+++ b/usr/src/uts/common/inet/tcp/tcp_opt_data.c Mon Jan 08 20:32:18 2007 -0800
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -82,6 +82,10 @@
0 },
{ SO_EXCLBIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
+{ SO_DOMAIN, SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
+
+{ SO_PROTOTYPE, SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
+
{ TCP_NODELAY, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0
},
{ TCP_MAXSEG, IPPROTO_TCP, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (uint_t),
--- a/usr/src/uts/common/inet/udp/udp.c Mon Jan 08 20:19:20 2007 -0800
+++ b/usr/src/uts/common/inet/udp/udp.c Mon Jan 08 20:32:18 2007 -0800
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1990 Mentat Inc. */
@@ -3143,6 +3143,12 @@
case SO_EXCLBIND:
*i1 = udp->udp_exclbind ? SO_EXCLBIND : 0;
break;
+ case SO_PROTOTYPE:
+ *i1 = IPPROTO_UDP;
+ break;
+ case SO_DOMAIN:
+ *i1 = udp->udp_family;
+ break;
default:
return (-1);
}
--- a/usr/src/uts/common/inet/udp/udp_opt_data.c Mon Jan 08 20:19:20 2007 -0800
+++ b/usr/src/uts/common/inet/udp/udp_opt_data.c Mon Jan 08 20:32:18 2007 -0800
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -81,6 +81,8 @@
0 },
{ SCM_UCRED, SOL_SOCKET, OA_W, OA_W, OP_NP, OP_VARLEN|OP_NODEFAULT, 512, 0 },
{ SO_EXCLBIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
+{ SO_DOMAIN, SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
+{ SO_PROTOTYPE, SOL_SOCKET, OA_R, OA_R, OP_NP, OP_PASSNEXT, sizeof (int), 0 },
{ IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP,
(OP_PASSNEXT|OP_VARLEN|OP_NODEFAULT), 40, -1 /* not initialized */ },
--- a/usr/src/uts/common/sys/socket.h Mon Jan 08 20:19:20 2007 -0800
+++ b/usr/src/uts/common/sys/socket.h Mon Jan 08 20:32:18 2007 -0800
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -144,6 +144,7 @@
#define SO_PROTOTYPE 0x1009 /* get/set protocol type */
#define SO_ANON_MLP 0x100a /* create MLP on anonymous bind */
#define SO_MAC_EXEMPT 0x100b /* allow dominated unlabeled peers */
+#define SO_DOMAIN 0x100c /* get socket domain */
/* "Socket"-level control message types: */
#define SCM_RIGHTS 0x1010 /* access rights (array of int) */