Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-8]: src Pull up following revision(s) (requested by tih in ticket...



details:   https://anonhg.NetBSD.org/src/rev/2be1d978974d
branches:  netbsd-8
changeset: 434757:2be1d978974d
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Mar 18 10:57:01 2018 +0000

description:
Pull up following revision(s) (requested by tih in ticket #639):
        sys/kern/uipc_socket.c: revision 1.258
        sys/kern/uipc_socket.c: revision 1.259
        sys/netinet/ip_input.c: revision 1.364 (via patch)
        sys/netinet/ip_output.c: revision 1.289
        sys/netinet/in.h: revision 1.102
        sys/netinet/in_pcb.c: revision 1.181
        share/man/man9/sockopt.9: revision 1.11
        sys/netinet/in_pcb.h: revision 1.65
        sys/sys/socketvar.h: revision 1.146
        sys/kern/uipc_syscalls.c: revision 1.189
        sys/netinet/ip_output.c: revision 1.290
        share/man/man4/ip.4: revision 1.41
        share/man/man4/ip.4: revision 1.42
        sys/kern/uipc_syscalls.c: revision 1.190

pass valsize for getsockopt like we do for setsockopt
make sure that we have enough space, don't require the exact size
(Tom Ivar Helbekkmo)

1) "#define ipi_spec_dst ipi_addr" in <netinet/in.h>
2) Change the IP_RECVPKTINFO option to control the generation of
   IP_PKTINFO control messages, the way it's done in Solaris.
3) Remove the superfluous IP_RECVPKTINFO control message.
4) Change the IP_PKTINFO option to do different things depending on
   the parameter it's supplied with:
   - If it's sizeof(int), assume it's being used as in Linux:
     - If it's non-zero, turn on the IP_RECVPKTINFO option.
     - If it's zero, turn off the IP_RECVPKTINFO option.
   - If it's sizeof(struct in_pktinfo), assume it's being used as in
     Solaris, to set a default for the source interface and/or
     source address for outgoing packets on the socket.
5) Return what Linux or Solaris compatible code expects, depending
   on data size, and just added a fallback to a Linux (and current NetBSD)
   compatible value if the size is unknown (as it is now), or,
   in the future, if the calling application specifies a receiving
   buffer that doesn't match either data item.

From: Tom Ivar Helbekkmo

new sentence-new line

Remove comment now that the getsockopt code passes the size.

Add a new sockopt member to keep track of the actual size of the option
that should be returned to the caller in getsockopt(2).
(Tom Ivar Helbekkmo)

diffstat:

 share/man/man4/ip.4      |   62 +++++++++++++++++++++-----
 share/man/man9/sockopt.9 |    7 +-
 sys/kern/uipc_socket.c   |   15 ++++-
 sys/kern/uipc_syscalls.c |   11 +++-
 sys/netinet/in.h         |   10 +++-
 sys/netinet/in_pcb.c     |    5 +-
 sys/netinet/in_pcb.h     |    9 +--
 sys/netinet/ip_input.c   |   13 +----
 sys/netinet/ip_output.c  |  108 ++++++++++++++++++++++++++++++++++++++--------
 sys/sys/socketvar.h      |    3 +-
 10 files changed, 179 insertions(+), 64 deletions(-)

diffs (truncated from 565 to 300 lines):

diff -r 8f68db95864f -r 2be1d978974d share/man/man4/ip.4
--- a/share/man/man4/ip.4       Sun Mar 18 10:20:38 2018 +0000
+++ b/share/man/man4/ip.4       Sun Mar 18 10:57:01 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ip.4,v 1.36.20.1 2017/12/21 21:08:13 snj Exp $
+.\"    $NetBSD: ip.4,v 1.36.20.2 2018/03/18 10:57:02 martin Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)ip.4       8.2 (Berkeley) 11/30/93
 .\"
-.Dd August 10, 2017
+.Dd December 31, 2017
 .Dt IP 4
 .Os
 .Sh NAME
@@ -111,8 +111,8 @@
 .Ed
 .Pp
 The
-.Dv IP_PKTINFO
-option can be used to turn on receiving of information about the source
+.Dv IP_RECVPKTINFO
+option can be used to turn on receiving of information about the destination
 address of the packet, and the interface index.
 The information is passed in a
 .Vt struct in_pktinfo
@@ -132,13 +132,25 @@
 .Pp
 For
 .Xr sendmsg 2 ,
-the source address or output interface can be specified by adding
+the source address or output interface can be specified by adding an
 .Dv IP_PKTINFO
-to the control part of the message on a
+message to the control part of the message on a
 .Dv SOCK_DGRAM
 or
 .Dv SOCK_RAW
 socket.
+Setting ipi_ifindex will cause the primary address of that interface
+to be used; setting ipi_addr will directly choose that address.
+The IP_PKTINFO cmsghdr structure from a received message may be
+used unchanged, in which case the outgoing message will be sent
+from the address the incoming message was received on.
+.Pp
+Setting the
+.Dv IP_PKTINFO
+option on a socket, with the same
+.Vt struct in_pktinfo
+structure, will set the default source address to be used until set
+again, unless explicitly overridden on a per-packet basis, as above.
 .Pp
 The
 .Dv IP_PORTALGO
@@ -199,6 +211,19 @@
 cmsg_type = IP_RECVDSTADDR
 .Ed
 .Pp
+For
+.Xr sendmsg 2 ,
+the source address can be specified by adding
+.Dv IP_SENDSRCADDR
+to the control part of the message on a
+.Dv SOCK_DGRAM
+or
+.Dv SOCK_RAW
+socket.
+The IP_RECVDSTADDR cmsghdr structure from a received message may
+be used unchanged, in which case the outgoing message will be sent
+from the address the incoming message was received on.
+.Pp
 If the
 .Dv IP_RECVIF
 option is enabled on a
@@ -219,12 +244,6 @@
 cmsg_type = IP_RECVIF
 .Ed
 .Pp
-The
-.Dv IP_RECVPKTINFO
-option is similar to the
-.Dv IP_PKTINFO
-one, only in this case the inbound information is returned.
-.Pp
 If the
 .Dv IP_RECVTTL
 option is enabled on a
@@ -491,6 +510,25 @@
 The IP option field was improperly formed; an option field was
 shorter than the minimum value or longer than the option buffer provided.
 .El
+.Sh COMPATIBILITY
+The
+.Dv IP_RECVPKTINFO
+option is used because it is directly compatible with Solaris, AIX, etc.,
+and the
+.Dv IP_PKTINFO
+option is intended to be used in their manner, to set the default source
+address for outgoing packets on a
+.Dv SOCK_DGRAM
+or
+.Dv SOCK_RAW
+socket.
+For compatibility with Linux, however, if you attempt to set the
+.Dv IP_PKTINFO
+option, using an integer parameter as a boolean value, this will
+transparently manipulate the
+.Dv IP_RECVPKTINFO
+option instead.
+Source code compatbility with both environments is thus maintained.
 .Sh SEE ALSO
 .Xr getsockopt 2 ,
 .Xr recv 2 ,
diff -r 8f68db95864f -r 2be1d978974d share/man/man9/sockopt.9
--- a/share/man/man9/sockopt.9  Sun Mar 18 10:20:38 2018 +0000
+++ b/share/man/man9/sockopt.9  Sun Mar 18 10:57:01 2018 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: sockopt.9,v 1.10 2017/01/16 12:54:25 njoly Exp $
+.\"    $NetBSD: sockopt.9,v 1.10.4.1 2018/03/18 10:57:01 martin Exp $
 .\"
 .\" Copyright (c) 2008 Iain Hibbert
 .\" All rights reserved.
@@ -23,7 +23,7 @@
 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd September 4, 2009
+.Dd January 3, 2018
 .Dt SOCKOPT 9
 .Os
 .Sh NAME
@@ -57,6 +57,7 @@
        int             sopt_level;             /* option level */
        int             sopt_name;              /* option name */
        size_t          sopt_size;              /* data length */
+       size_t          sopt_retsize;           /* returned data length */
        void *          sopt_data;              /* data pointer */
        uint8_t         sopt_buf[sizeof(int)];  /* internal storage */
 };
@@ -133,7 +134,7 @@
 which will not fail.
 .It Fn sockopt_setint "sopt" "value"
 Common case of set sockopt integer value.
-The sockpt structure must contain an int sized data field or be previously
+The sockopt structure must contain an int sized data field or be previously
 unset, in which case the data pointer will be set to the internal storage.
 .El
 .Sh CODE REFERENCES
diff -r 8f68db95864f -r 2be1d978974d sys/kern/uipc_socket.c
--- a/sys/kern/uipc_socket.c    Sun Mar 18 10:20:38 2018 +0000
+++ b/sys/kern/uipc_socket.c    Sun Mar 18 10:57:01 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_socket.c,v 1.255 2017/05/27 21:02:56 bouyer Exp $ */
+/*     $NetBSD: uipc_socket.c,v 1.255.2.1 2018/03/18 10:57:01 martin Exp $     */
 
 /*-
  * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -71,7 +71,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.255 2017/05/27 21:02:56 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.255.2.1 2018/03/18 10:57:01 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -2109,8 +2109,12 @@
                        return error;
        }
 
-       KASSERT(sopt->sopt_size == len);
+       if (sopt->sopt_size < len)
+               return EINVAL;
+       
        memcpy(sopt->sopt_data, buf, len);
+       sopt->sopt_retsize = len;
+
        return 0;
 }
 
@@ -2169,9 +2173,12 @@
                        return error;
        }
 
-       KASSERT(sopt->sopt_size == len);
+       if (sopt->sopt_size < len)
+               return EINVAL;
+       
        m_copydata(m, 0, len, sopt->sopt_data);
        m_freem(m);
+       sopt->sopt_retsize = len;
 
        return 0;
 }
diff -r 8f68db95864f -r 2be1d978974d sys/kern/uipc_syscalls.c
--- a/sys/kern/uipc_syscalls.c  Sun Mar 18 10:20:38 2018 +0000
+++ b/sys/kern/uipc_syscalls.c  Sun Mar 18 10:57:01 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_syscalls.c,v 1.186 2017/02/03 16:06:45 christos Exp $     */
+/*     $NetBSD: uipc_syscalls.c,v 1.186.6.1 2018/03/18 10:57:01 martin Exp $   */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.186 2017/02/03 16:06:45 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.186.6.1 2018/03/18 10:57:01 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pipe.h"
@@ -1235,7 +1235,10 @@
        if ((error = fd_getsock1(SCARG(uap, s), &so, &fp)) != 0)
                return (error);
 
-       sockopt_init(&sopt, SCARG(uap, level), SCARG(uap, name), 0);
+       if (valsize > MCLBYTES)
+               return EINVAL;
+
+       sockopt_init(&sopt, SCARG(uap, level), SCARG(uap, name), valsize);
 
        if (fp->f_flag & FNOSIGPIPE)
                so->so_options |= SO_NOSIGPIPE;
@@ -1246,7 +1249,7 @@
                goto out;
 
        if (valsize > 0) {
-               len = min(valsize, sopt.sopt_size);
+               len = min(valsize, sopt.sopt_retsize);
                error = copyout(sopt.sopt_data, SCARG(uap, val), len);
                if (error)
                        goto out;
diff -r 8f68db95864f -r 2be1d978974d sys/netinet/in.h
--- a/sys/netinet/in.h  Sun Mar 18 10:20:38 2018 +0000
+++ b/sys/netinet/in.h  Sun Mar 18 10:57:01 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in.h,v 1.100.6.2 2018/02/11 21:17:34 snj Exp $ */
+/*     $NetBSD: in.h,v 1.100.6.3 2018/03/18 10:57:01 martin Exp $      */
 
 /*
  * Copyright (c) 1982, 1986, 1990, 1993
@@ -289,8 +289,10 @@
 #define        IP_IPSEC_POLICY         22   /* struct; get/set security policy */
 #define        IP_RECVTTL              23   /* bool; receive IP TTL w/dgram */
 #define        IP_MINTTL               24   /* minimum TTL for packet or drop */
-#define        IP_PKTINFO              25   /* int; send interface and src addr */
-#define        IP_RECVPKTINFO          26   /* int; send interface and dst addr */
+#define        IP_PKTINFO              25   /* struct; set default src if/addr */
+#define        IP_RECVPKTINFO          26   /* int; receive dst if/addr w/dgram */
+
+#define IP_SENDSRCADDR IP_RECVDSTADDR /* FreeBSD compatibility */
 
 /*
  * Information sent in the control message of a datagram socket for
@@ -301,6 +303,8 @@
        unsigned int ipi_ifindex;       /* interface index */
 };
 
+#define ipi_spec_dst ipi_addr  /* Solaris/Linux compatibility */
+
 /*
  * Defaults and limits for options
  */
diff -r 8f68db95864f -r 2be1d978974d sys/netinet/in_pcb.c
--- a/sys/netinet/in_pcb.c      Sun Mar 18 10:20:38 2018 +0000
+++ b/sys/netinet/in_pcb.c      Sun Mar 18 10:57:01 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_pcb.c,v 1.178.4.2 2018/01/02 10:20:34 snj Exp $     */
+/*     $NetBSD: in_pcb.c,v 1.178.4.3 2018/03/18 10:57:01 martin Exp $  */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -93,7 +93,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.178.4.2 2018/01/02 10:20:34 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in_pcb.c,v 1.178.4.3 2018/03/18 10:57:01 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -204,6 +204,7 @@
        inp->inp_errormtu = -1;
        inp->inp_portalgo = PORTALGO_DEFAULT;
        inp->inp_bindportonsend = false;
+       inp->inp_prefsrcip.s_addr = INADDR_ANY;
 #if defined(IPSEC)
        if (ipsec_enabled) {
                int error = ipsec_init_pcbpolicy(so, &inp->inp_sp);
diff -r 8f68db95864f -r 2be1d978974d sys/netinet/in_pcb.h
--- a/sys/netinet/in_pcb.h      Sun Mar 18 10:20:38 2018 +0000
+++ b/sys/netinet/in_pcb.h      Sun Mar 18 10:57:01 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in_pcb.h,v 1.63.6.1 2017/12/21 21:08:13 snj Exp $      */
+/*     $NetBSD: in_pcb.h,v 1.63.6.2 2018/03/18 10:57:01 martin Exp $   */
 



Home | Main Index | Thread Index | Old Index