Home | History | Annotate | Line # | Download | only in common
kern_uipc_socket_50.c revision 1.1
      1  1.1  pgoyette /*	$NetBSD: kern_uipc_socket_50.c,v 1.1 2019/04/15 02:07:11 pgoyette Exp $	*/
      2  1.1  pgoyette 
      3  1.1  pgoyette /*
      4  1.1  pgoyette  * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc.
      5  1.1  pgoyette  * All rights reserved.
      6  1.1  pgoyette  *
      7  1.1  pgoyette  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  pgoyette  * by Jason R. Thorpe of Wasabi Systems, Inc, and by Andrew Doran.
      9  1.1  pgoyette  *
     10  1.1  pgoyette  * Redistribution and use in source and binary forms, with or without
     11  1.1  pgoyette  * modification, are permitted provided that the following conditions
     12  1.1  pgoyette  * are met:
     13  1.1  pgoyette  * 1. Redistributions of source code must retain the above copyright
     14  1.1  pgoyette  *    notice, this list of conditions and the following disclaimer.
     15  1.1  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  pgoyette  *    documentation and/or other materials provided with the distribution.
     18  1.1  pgoyette  *
     19  1.1  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  pgoyette  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  pgoyette  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  pgoyette  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  pgoyette  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  pgoyette  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  pgoyette  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  pgoyette  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  pgoyette  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  pgoyette  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  pgoyette  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  pgoyette  */
     31  1.1  pgoyette 
     32  1.1  pgoyette /*
     33  1.1  pgoyette  * Copyright (c) 2004 The FreeBSD Foundation
     34  1.1  pgoyette  * Copyright (c) 2004 Robert Watson
     35  1.1  pgoyette  * Copyright (c) 1982, 1986, 1988, 1990, 1993
     36  1.1  pgoyette  *     The Regents of the University of California.  All rights reserved.
     37  1.1  pgoyette  *
     38  1.1  pgoyette  * Redistribution and use in source and binary forms, with or without
     39  1.1  pgoyette  * modification, are permitted provided that the following conditions
     40  1.1  pgoyette  * are met:
     41  1.1  pgoyette  * 1. Redistributions of source code must retain the above copyright
     42  1.1  pgoyette  *    notice, this list of conditions and the following disclaimer.
     43  1.1  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     44  1.1  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     45  1.1  pgoyette  *    documentation and/or other materials provided with the distribution.
     46  1.1  pgoyette  * 3. Neither the name of the University nor the names of its contributors
     47  1.1  pgoyette  *    may be used to endorse or promote products derived from this software
     48  1.1  pgoyette  *    without specific prior written permission.
     49  1.1  pgoyette  *
     50  1.1  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     51  1.1  pgoyette  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     52  1.1  pgoyette  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     53  1.1  pgoyette  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     54  1.1  pgoyette  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     55  1.1  pgoyette  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     56  1.1  pgoyette  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     57  1.1  pgoyette  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     58  1.1  pgoyette  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     59  1.1  pgoyette  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     60  1.1  pgoyette  * SUCH DAMAGE.
     61  1.1  pgoyette  *
     62  1.1  pgoyette  *     @(#)uipc_socket.c       8.6 (Berkeley) 5/2/95
     63  1.1  pgoyette  */
     64  1.1  pgoyette 
     65  1.1  pgoyette /*
     66  1.1  pgoyette  * Copyright (c) 1988 University of Utah.
     67  1.1  pgoyette  * Copyright (c) 1990, 1993
     68  1.1  pgoyette  *	The Regents of the University of California.  All rights reserved.
     69  1.1  pgoyette  *
     70  1.1  pgoyette  * This code is derived from software contributed to Berkeley by
     71  1.1  pgoyette  * the Systems Programming Group of the University of Utah Computer
     72  1.1  pgoyette  * Science Department.
     73  1.1  pgoyette  *
     74  1.1  pgoyette  * Redistribution and use in source and binary forms, with or without
     75  1.1  pgoyette  * modification, are permitted provided that the following conditions
     76  1.1  pgoyette  * are met:
     77  1.1  pgoyette  * 1. Redistributions of source code must retain the above copyright
     78  1.1  pgoyette  *    notice, this list of conditions and the following disclaimer.
     79  1.1  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     80  1.1  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     81  1.1  pgoyette  *    documentation and/or other materials provided with the distribution.
     82  1.1  pgoyette  * 3. Neither the name of the University nor the names of its contributors
     83  1.1  pgoyette  *    may be used to endorse or promote products derived from this software
     84  1.1  pgoyette  *    without specific prior written permission.
     85  1.1  pgoyette  *
     86  1.1  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     87  1.1  pgoyette  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     88  1.1  pgoyette  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     89  1.1  pgoyette  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     90  1.1  pgoyette  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     91  1.1  pgoyette  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     92  1.1  pgoyette  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     93  1.1  pgoyette  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     94  1.1  pgoyette  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     95  1.1  pgoyette  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     96  1.1  pgoyette  * SUCH DAMAGE.
     97  1.1  pgoyette  *
     98  1.1  pgoyette  * from: Utah $Hdr: vn.c 1.13 94/04/02$
     99  1.1  pgoyette  *
    100  1.1  pgoyette  *	@(#)vn.c	8.9 (Berkeley) 5/14/95
    101  1.1  pgoyette  */
    102  1.1  pgoyette 
    103  1.1  pgoyette #include <sys/cdefs.h>
    104  1.1  pgoyette __KERNEL_RCSID(0, "$NetBSD: kern_uipc_socket_50.c,v 1.1 2019/04/15 02:07:11 pgoyette Exp $");
    105  1.1  pgoyette 
    106  1.1  pgoyette #if defined(_KERNEL_OPT)
    107  1.1  pgoyette #include "opt_compat_netbsd.h"
    108  1.1  pgoyette #endif
    109  1.1  pgoyette 
    110  1.1  pgoyette #include <sys/param.h>
    111  1.1  pgoyette #include <sys/systm.h>
    112  1.1  pgoyette #include <sys/kernel.h>
    113  1.1  pgoyette #include <sys/proc.h>
    114  1.1  pgoyette #include <sys/file.h>
    115  1.1  pgoyette #include <sys/compat_stub.h>
    116  1.1  pgoyette #include <sys/socketvar.h>
    117  1.1  pgoyette 
    118  1.1  pgoyette #include <compat/sys/time.h>
    119  1.1  pgoyette #include <compat/sys/socket.h>
    120  1.1  pgoyette 
    121  1.1  pgoyette #include <compat/common/compat_mod.h>
    122  1.1  pgoyette 
    123  1.1  pgoyette static int
    124  1.1  pgoyette uipc_socket_50_getopt1(int opt, struct socket *so, struct sockopt *sopt,
    125  1.1  pgoyette     struct timeval *tv)
    126  1.1  pgoyette {
    127  1.1  pgoyette 	int optval, error;
    128  1.1  pgoyette 	struct timeval50 otv;
    129  1.1  pgoyette 
    130  1.1  pgoyette 	switch (opt) {
    131  1.1  pgoyette 
    132  1.1  pgoyette 	case SO_OSNDTIMEO:
    133  1.1  pgoyette 	case SO_ORCVTIMEO:
    134  1.1  pgoyette 		optval = (opt == SO_OSNDTIMEO ?
    135  1.1  pgoyette 		    so->so_snd.sb_timeo : so->so_rcv.sb_timeo);
    136  1.1  pgoyette 
    137  1.1  pgoyette 		otv.tv_sec = optval / hz;
    138  1.1  pgoyette 		otv.tv_usec = (optval % hz) * tick;
    139  1.1  pgoyette 
    140  1.1  pgoyette 		error = sockopt_set(sopt, &otv, sizeof(otv));
    141  1.1  pgoyette 		break;
    142  1.1  pgoyette 
    143  1.1  pgoyette 	case SO_OTIMESTAMP:
    144  1.1  pgoyette 		error = sockopt_setint(sopt, (so->so_options & opt) ? 1 : 0);
    145  1.1  pgoyette 		break;
    146  1.1  pgoyette 
    147  1.1  pgoyette 	default:
    148  1.1  pgoyette 		error = EPASSTHROUGH;
    149  1.1  pgoyette 	}
    150  1.1  pgoyette 	return error;
    151  1.1  pgoyette }
    152  1.1  pgoyette 
    153  1.1  pgoyette static int
    154  1.1  pgoyette uipc_socket_50_setopt1(int opt, struct socket *so, const struct sockopt *sopt,
    155  1.1  pgoyette     struct timeval *tv)
    156  1.1  pgoyette {
    157  1.1  pgoyette 	int optval, error;
    158  1.1  pgoyette 	struct timeval50 otv;
    159  1.1  pgoyette 
    160  1.1  pgoyette 	switch (opt) {
    161  1.1  pgoyette 
    162  1.1  pgoyette 	case SO_OSNDTIMEO:
    163  1.1  pgoyette 	case SO_ORCVTIMEO:
    164  1.1  pgoyette 		error = sockopt_get(sopt, &otv, sizeof(otv));
    165  1.1  pgoyette 		if (error) {
    166  1.1  pgoyette 			solock(so);
    167  1.1  pgoyette 			break;
    168  1.1  pgoyette 		}
    169  1.1  pgoyette 		timeval50_to_timeval(&otv, tv);
    170  1.1  pgoyette 		opt = opt == SO_OSNDTIMEO ? SO_SNDTIMEO : SO_RCVTIMEO;
    171  1.1  pgoyette 		/*
    172  1.1  pgoyette 		 * Processing will continue as for SO_SNDTIMEO
    173  1.1  pgoyette 		 * and SO_RCVTIMEO, using the new-format tv
    174  1.1  pgoyette 		 */
    175  1.1  pgoyette 		break;
    176  1.1  pgoyette 
    177  1.1  pgoyette 	case SO_OTIMESTAMP:
    178  1.1  pgoyette 		error = sockopt_getint(sopt, &optval);
    179  1.1  pgoyette 		solock(so);
    180  1.1  pgoyette 		if (error)
    181  1.1  pgoyette 			break;
    182  1.1  pgoyette 		if (optval)
    183  1.1  pgoyette 			so->so_options |= opt;
    184  1.1  pgoyette 		else
    185  1.1  pgoyette 			so->so_options &= ~opt;
    186  1.1  pgoyette 		break;
    187  1.1  pgoyette 
    188  1.1  pgoyette 	default:
    189  1.1  pgoyette 		error = EPASSTHROUGH;
    190  1.1  pgoyette 	}
    191  1.1  pgoyette 	return error;
    192  1.1  pgoyette }
    193  1.1  pgoyette 
    194  1.1  pgoyette static int
    195  1.1  pgoyette uipc_socket_50_sbts(int opt, struct mbuf **mp)
    196  1.1  pgoyette {
    197  1.1  pgoyette 	struct timeval50 tv50;
    198  1.1  pgoyette 	struct timeval tv;
    199  1.1  pgoyette 
    200  1.1  pgoyette 	microtime(&tv);
    201  1.1  pgoyette 
    202  1.1  pgoyette 	if (opt & SO_OTIMESTAMP) {
    203  1.1  pgoyette 
    204  1.1  pgoyette 		timeval_to_timeval50(&tv, &tv50);
    205  1.1  pgoyette 		*mp = sbcreatecontrol(&tv50, sizeof(tv50), SCM_OTIMESTAMP,
    206  1.1  pgoyette 		    SOL_SOCKET);
    207  1.1  pgoyette 		if (*mp)
    208  1.1  pgoyette 			mp = &(*mp)->m_next;
    209  1.1  pgoyette 		return 0;
    210  1.1  pgoyette 	} else
    211  1.1  pgoyette 		return EPASSTHROUGH;
    212  1.1  pgoyette }
    213  1.1  pgoyette 
    214  1.1  pgoyette void
    215  1.1  pgoyette kern_uipc_socket_50_init(void)
    216  1.1  pgoyette {
    217  1.1  pgoyette 
    218  1.1  pgoyette 	MODULE_HOOK_SET(uipc_socket_50_setopt1_hook, "sockop_50",
    219  1.1  pgoyette 	    uipc_socket_50_setopt1);
    220  1.1  pgoyette 	MODULE_HOOK_SET(uipc_socket_50_getopt1_hook, "sockop_50",
    221  1.1  pgoyette 	    uipc_socket_50_getopt1);
    222  1.1  pgoyette 	MODULE_HOOK_SET(uipc_socket_50_sbts_hook, "sbts_50",
    223  1.1  pgoyette 	    uipc_socket_50_sbts);
    224  1.1  pgoyette }
    225  1.1  pgoyette 
    226  1.1  pgoyette void
    227  1.1  pgoyette kern_uipc_socket_50_fini(void)
    228  1.1  pgoyette {
    229  1.1  pgoyette 
    230  1.1  pgoyette 	MODULE_HOOK_UNSET(uipc_socket_50_setopt1_hook);
    231  1.1  pgoyette 	MODULE_HOOK_UNSET(uipc_socket_50_getopt1_hook);
    232  1.1  pgoyette 	MODULE_HOOK_UNSET(uipc_socket_50_sbts_hook);
    233  1.1  pgoyette }
    234