xref: /netbsd-src/sys/compat/common/uipc_syscalls_50.c (revision 378e708aed2e9e36f072099778fbc13c3d5c1513)
1*378e708aSmsaitoh /*	$NetBSD: uipc_syscalls_50.c,v 1.12 2022/09/28 15:32:09 msaitoh Exp $	*/
2461a86f9Schristos 
3461a86f9Schristos /*-
4461a86f9Schristos  * Copyright (c) 2008 The NetBSD Foundation, Inc.
5461a86f9Schristos  * All rights reserved.
6461a86f9Schristos  *
7461a86f9Schristos  * This code is derived from software contributed to The NetBSD Foundation
8461a86f9Schristos  * by Christos Zoulas.
9461a86f9Schristos  *
10461a86f9Schristos  * Redistribution and use in source and binary forms, with or without
11461a86f9Schristos  * modification, are permitted provided that the following conditions
12461a86f9Schristos  * are met:
13461a86f9Schristos  * 1. Redistributions of source code must retain the above copyright
14461a86f9Schristos  *    notice, this list of conditions and the following disclaimer.
15461a86f9Schristos  * 2. Redistributions in binary form must reproduce the above copyright
16461a86f9Schristos  *    notice, this list of conditions and the following disclaimer in the
17461a86f9Schristos  *    documentation and/or other materials provided with the distribution.
18461a86f9Schristos  *
19461a86f9Schristos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20461a86f9Schristos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21461a86f9Schristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22461a86f9Schristos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23461a86f9Schristos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24461a86f9Schristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25461a86f9Schristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26461a86f9Schristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27461a86f9Schristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28461a86f9Schristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29461a86f9Schristos  * POSSIBILITY OF SUCH DAMAGE.
30461a86f9Schristos  */
31461a86f9Schristos 
32461a86f9Schristos #include <sys/cdefs.h>
33d91f98a8Spgoyette 
34d91f98a8Spgoyette #if defined(_KERNEL_OPT)
35d91f98a8Spgoyette #include "opt_compat_netbsd.h"
36d91f98a8Spgoyette #endif
37461a86f9Schristos 
38461a86f9Schristos #include <sys/param.h>
39461a86f9Schristos #include <sys/kernel.h>
40461a86f9Schristos #include <sys/msg.h>
41461a86f9Schristos #include <sys/sysctl.h>
42461a86f9Schristos #include <sys/syscallargs.h>
43461a86f9Schristos #include <sys/errno.h>
44461a86f9Schristos #include <sys/kauth.h>
45461a86f9Schristos #include <sys/proc.h>
46461a86f9Schristos #include <sys/time.h>
47d91f98a8Spgoyette #include <sys/compat_stub.h>
48461a86f9Schristos 
49461a86f9Schristos #include <net/if.h>
50461a86f9Schristos 
51*378e708aSmsaitoh #include <compat/net/if.h>
52461a86f9Schristos #include <compat/sys/time.h>
53461a86f9Schristos #include <compat/sys/socket.h>
54461a86f9Schristos #include <compat/sys/sockio.h>
55461a86f9Schristos 
56d91f98a8Spgoyette #include <compat/common/compat_mod.h>
57d91f98a8Spgoyette 
58461a86f9Schristos /*ARGSUSED*/
59061fe5a1Schristos static int
compat_ifdatareq(struct lwp * l,u_long cmd,void * data)60461a86f9Schristos compat_ifdatareq(struct lwp *l, u_long cmd, void *data)
61461a86f9Schristos {
6279b06451Sthorpej 	struct if_data ifi;
63*378e708aSmsaitoh 	struct ifdatareq50 *ifdr = data;
64461a86f9Schristos 	struct ifnet *ifp;
65461a86f9Schristos 	int error;
66461a86f9Schristos 
67e3e276e2Sroy 	/* Validate arguments. */
68e3e276e2Sroy 	switch (cmd) {
69621f6a12Smsaitoh 	case OSIOCGIFDATA:
70621f6a12Smsaitoh 	case OSIOCZIFDATA:
71e3e276e2Sroy 		break;
72e3e276e2Sroy 	default:
73e3e276e2Sroy 		return ENOSYS;
74e3e276e2Sroy 	}
75461a86f9Schristos 
76621f6a12Smsaitoh 	ifp = ifunit(ifdr->ifdr_name);
77621f6a12Smsaitoh 	if (ifp == NULL)
78621f6a12Smsaitoh 		return ENXIO;
79621f6a12Smsaitoh 
80e3e276e2Sroy 	/* Do work. */
81461a86f9Schristos 	switch (cmd) {
82621f6a12Smsaitoh 	case OSIOCGIFDATA:
8379b06451Sthorpej 		if_export_if_data(ifp, &ifi, false);
8479b06451Sthorpej 		ifdatan2o(&ifdr->ifdr_data, &ifi);
85461a86f9Schristos 		return 0;
86461a86f9Schristos 
87621f6a12Smsaitoh 	case OSIOCZIFDATA:
88461a86f9Schristos 		if (l != NULL) {
89461a86f9Schristos 			error = kauth_authorize_network(l->l_cred,
90461a86f9Schristos 			    KAUTH_NETWORK_INTERFACE,
91461a86f9Schristos 			    KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp,
92461a86f9Schristos 			    (void *)cmd, NULL);
93461a86f9Schristos 			if (error != 0)
94461a86f9Schristos 				return error;
95461a86f9Schristos 		}
9679b06451Sthorpej 		if_export_if_data(ifp, &ifi, true);
9779b06451Sthorpej 		ifdatan2o(&ifdr->ifdr_data, &ifi);
9879b06451Sthorpej 		/* XXX if_lastchange? */
99461a86f9Schristos 		return 0;
100461a86f9Schristos 
101461a86f9Schristos 	default:
102e3e276e2Sroy 		/* Impossible due to above validation, but makes gcc happy. */
103061fe5a1Schristos 		return ENOSYS;
104461a86f9Schristos 	}
105461a86f9Schristos }
106061fe5a1Schristos 
107061fe5a1Schristos void
uipc_syscalls_50_init(void)108061fe5a1Schristos uipc_syscalls_50_init(void)
109061fe5a1Schristos {
110d91f98a8Spgoyette 
1118a031a1dSpgoyette 	MODULE_HOOK_SET(uipc_syscalls_50_hook, compat_ifdatareq);
112061fe5a1Schristos }
113061fe5a1Schristos 
114061fe5a1Schristos void
uipc_syscalls_50_fini(void)115061fe5a1Schristos uipc_syscalls_50_fini(void)
116061fe5a1Schristos {
117d91f98a8Spgoyette 
1188c2f80f1Spgoyette 	MODULE_HOOK_UNSET(uipc_syscalls_50_hook);
119061fe5a1Schristos }
120