proc->thread stage 4: rework the VFS and DEVICE subsystems to take thread
[dragonfly.git] / sys / emulation / svr4 / svr4_sockio.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1995 Christos Zoulas
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: src/sys/svr4/svr4_sockio.c,v 1.7 1999/12/08 12:00:48 newton Exp $
dadab5e9 29 * $DragonFly: src/sys/emulation/svr4/Attic/svr4_sockio.c,v 1.3 2003/06/25 03:56:10 dillon Exp $
984263bc
MD
30 */
31
32#include <sys/param.h>
33#include <sys/proc.h>
34#include <sys/systm.h>
35#include <sys/file.h>
36#include <sys/filedesc.h>
37#include <sys/sockio.h>
38#include <sys/socket.h>
39#include <net/if.h>
dadab5e9 40#include <sys/file2.h>
984263bc
MD
41
42#include <svr4/svr4.h>
43#include <svr4/svr4_util.h>
44#include <svr4/svr4_ioctl.h>
45#include <svr4/svr4_sockio.h>
46
47static int bsd_to_svr4_flags __P((int));
48
49#define bsd_to_svr4_flag(a) \
50 if (bf & __CONCAT(I,a)) sf |= __CONCAT(SVR4_I,a)
51
52static int
53bsd_to_svr4_flags(bf)
54 int bf;
55{
56 int sf = 0;
57 bsd_to_svr4_flag(FF_UP);
58 bsd_to_svr4_flag(FF_BROADCAST);
59 bsd_to_svr4_flag(FF_DEBUG);
60 bsd_to_svr4_flag(FF_LOOPBACK);
61 bsd_to_svr4_flag(FF_POINTOPOINT);
62#if defined(IFF_NOTRAILERS)
63 bsd_to_svr4_flag(FF_NOTRAILERS);
64#endif
65 bsd_to_svr4_flag(FF_RUNNING);
66 bsd_to_svr4_flag(FF_NOARP);
67 bsd_to_svr4_flag(FF_PROMISC);
68 bsd_to_svr4_flag(FF_ALLMULTI);
69 bsd_to_svr4_flag(FF_MULTICAST);
70 return sf;
71}
72
73int
dadab5e9 74svr4_sock_ioctl(fp, td, retval, fd, cmd, data)
984263bc 75 struct file *fp;
dadab5e9 76 struct thread *td;
984263bc
MD
77 register_t *retval;
78 int fd;
79 u_long cmd;
80 caddr_t data;
81{
82 int error;
83
84 *retval = 0;
85
86 switch (cmd) {
87 case SVR4_SIOCGIFNUM:
88 {
89 struct ifnet *ifp;
90 struct ifaddr *ifa;
91 int ifnum = 0;
92
93 /*
94 * This does not return the number of physical
95 * interfaces (if_index), but the number of interfaces
96 * + addresses like ifconf() does, because this number
97 * is used by code that will call SVR4_SIOCGIFCONF to
98 * find the space needed for SVR4_SIOCGIFCONF. So we
99 * count the number of ifreq entries that the next
100 * SVR4_SIOCGIFCONF will return. Maybe a more correct
101 * fix is to make SVR4_SIOCGIFCONF return only one
102 * entry per physical interface?
103 */
104
105 for (ifp = ifnet.tqh_first;
106 ifp != 0; ifp = ifp->if_link.tqe_next)
107 if ((ifa = ifp->if_addrhead.tqh_first) == NULL)
108 ifnum++;
109 else
110 for (;ifa != NULL;
111 ifa = ifa->ifa_link.tqe_next)
112 ifnum++;
113
114
115 DPRINTF(("SIOCGIFNUM %d\n", ifnum));
116 return copyout(&ifnum, data, sizeof(ifnum));
117 }
118
119 case SVR4_SIOCGIFFLAGS:
120 {
121 struct ifreq br;
122 struct svr4_ifreq sr;
123
124 if ((error = copyin(data, &sr, sizeof(sr))) != 0)
125 return error;
126
127 (void) strncpy(br.ifr_name, sr.svr4_ifr_name,
128 sizeof(br.ifr_name));
129 if ((error = fo_ioctl(fp, SIOCGIFFLAGS,
dadab5e9 130 (caddr_t) &br, td)) != 0) {
984263bc
MD
131 DPRINTF(("SIOCGIFFLAGS (%s) %s: error %d\n",
132 br.ifr_name, sr.svr4_ifr_name, error));
133 return error;
134 }
135
136 sr.svr4_ifr_flags = bsd_to_svr4_flags(br.ifr_flags);
137 DPRINTF(("SIOCGIFFLAGS %s = %x\n",
138 sr.svr4_ifr_name, sr.svr4_ifr_flags));
139 return copyout(&sr, data, sizeof(sr));
140 }
141
142 case SVR4_SIOCGIFCONF:
143 {
144 struct svr4_ifconf sc;
145
146 if ((error = copyin(data, &sc, sizeof(sc))) != 0)
147 return error;
148
149 DPRINTF(("ifreq %d svr4_ifreq %d ifc_len %d\n",
150 sizeof(struct ifreq), sizeof(struct svr4_ifreq),
151 sc.svr4_ifc_len));
152
153 if ((error = fo_ioctl(fp, OSIOCGIFCONF,
dadab5e9 154 (caddr_t) &sc, td)) != 0)
984263bc
MD
155 return error;
156
157 DPRINTF(("SIOCGIFCONF\n"));
158 return 0;
159 }
160
161
162 default:
163 DPRINTF(("Unknown svr4 sockio %lx\n", cmd));
164 return 0; /* ENOSYS really */
165 }
166}