6 #include <net/gen/in.h>
7 #include <net/gen/ether.h>
8 #include <net/gen/eth_io.h>
9 #include <net/gen/arp_io.h>
10 #include <net/gen/ip_io.h>
11 #include <net/gen/route.h>
12 #include <net/gen/tcp.h>
13 #include <net/gen/tcp_io.h>
14 #include <net/gen/udp.h>
15 #include <net/gen/udp_io.h>
16 #include <net/gen/udp_io_hdr.h>
17 #include <net/gen/psip_io.h>
18 #include <arpa/inet.h>
20 #include <net/route.h>
21 #include <netinet6/in6_var.h>
22 #include <netinet6/nd6.h>
23 #include <net80211/ieee80211_ioctl.h>
26 net_ioctl_name(unsigned long req
)
32 NAME(SIOCSHIWAT
); /* TODO: print argument */
33 NAME(SIOCGHIWAT
); /* TODO: print argument */
34 NAME(SIOCSLOWAT
); /* TODO: print argument */
35 NAME(SIOCGLOWAT
); /* TODO: print argument */
36 NAME(SIOCSPGRP
); /* TODO: print argument */
37 NAME(SIOCGPGRP
); /* TODO: print argument */
38 NAME(SIOCADDRT
); /* TODO: print argument */
39 NAME(SIOCDELRT
); /* TODO: print argument */
40 NAME(SIOCSIFADDR
); /* TODO: print argument */
41 NAME(SIOCGIFADDR
); /* TODO: print argument */
42 NAME(SIOCSIFDSTADDR
); /* TODO: print argument */
43 NAME(SIOCGIFDSTADDR
); /* TODO: print argument */
44 NAME(SIOCSIFFLAGS
); /* TODO: print argument */
45 NAME(SIOCGIFFLAGS
); /* TODO: print argument */
46 NAME(SIOCGIFBRDADDR
); /* TODO: print argument */
47 NAME(SIOCSIFBRDADDR
); /* TODO: print argument */
48 NAME(SIOCGIFCONF
); /* TODO: print argument */
49 NAME(SIOCGIFNETMASK
); /* TODO: print argument */
50 NAME(SIOCSIFNETMASK
); /* TODO: print argument */
51 NAME(SIOCGIFMETRIC
); /* TODO: print argument */
52 NAME(SIOCSIFMETRIC
); /* TODO: print argument */
53 NAME(SIOCDIFADDR
); /* TODO: print argument */
54 NAME(SIOCAIFADDR
); /* TODO: print argument */
55 NAME(SIOCGIFALIAS
); /* TODO: print argument */
56 NAME(SIOCGIFAFLAG_IN
); /* TODO: print argument */
57 NAME(SIOCALIFADDR
); /* TODO: print argument */
58 NAME(SIOCGLIFADDR
); /* TODO: print argument */
59 NAME(SIOCDLIFADDR
); /* TODO: print argument */
60 NAME(SIOCSIFADDRPREF
); /* TODO: print argument */
61 NAME(SIOCGIFADDRPREF
); /* TODO: print argument */
62 NAME(SIOCADDMULTI
); /* TODO: print argument */
63 NAME(SIOCDELMULTI
); /* TODO: print argument */
64 NAME(SIOCSIFMEDIA
); /* TODO: print argument */
65 NAME(SIOCGIFMEDIA
); /* TODO: print argument */
66 NAME(SIOCSIFGENERIC
); /* TODO: print argument */
67 NAME(SIOCGIFGENERIC
); /* TODO: print argument */
68 NAME(SIOCSIFPHYADDR
); /* TODO: print argument */
69 NAME(SIOCGIFPSRCADDR
); /* TODO: print argument */
70 NAME(SIOCGIFPDSTADDR
); /* TODO: print argument */
71 NAME(SIOCDIFPHYADDR
); /* TODO: print argument */
72 NAME(SIOCSLIFPHYADDR
); /* TODO: print argument */
73 NAME(SIOCGLIFPHYADDR
); /* TODO: print argument */
74 NAME(SIOCSIFMTU
); /* TODO: print argument */
75 NAME(SIOCGIFMTU
); /* TODO: print argument */
76 NAME(SIOCSDRVSPEC
); /* TODO: print argument */
77 NAME(SIOCGDRVSPEC
); /* TODO: print argument */
78 NAME(SIOCIFCREATE
); /* TODO: print argument */
79 NAME(SIOCIFDESTROY
); /* TODO: print argument */
80 NAME(SIOCIFGCLONERS
); /* TODO: print argument */
81 NAME(SIOCGIFDLT
); /* TODO: print argument */
82 NAME(SIOCGIFCAP
); /* TODO: print argument */
83 NAME(SIOCSIFCAP
); /* TODO: print argument */
84 NAME(SIOCSVH
); /* TODO: print argument */
85 NAME(SIOCGVH
); /* TODO: print argument */
86 NAME(SIOCINITIFADDR
); /* TODO: print argument */
87 NAME(SIOCGIFDATA
); /* TODO: print argument */
88 NAME(SIOCZIFDATA
); /* TODO: print argument */
89 NAME(SIOCGLINKSTR
); /* TODO: print argument */
90 NAME(SIOCSLINKSTR
); /* TODO: print argument */
91 NAME(SIOCGETHERCAP
); /* TODO: print argument */
92 NAME(SIOCGIFINDEX
); /* TODO: print argument */
93 NAME(SIOCSETPFSYNC
); /* TODO: print argument */
94 NAME(SIOCGETPFSYNC
); /* TODO: print argument */
95 /* netinet6/in6_var.h */
96 NAME(SIOCSIFADDR_IN6
); /* TODO: print argument */
97 NAME(SIOCGIFADDR_IN6
); /* TODO: print argument */
98 NAME(SIOCGIFDSTADDR_IN6
); /* TODO: print argument */
99 NAME(SIOCGIFNETMASK_IN6
); /* TODO: print argument */
100 NAME(SIOCDIFADDR_IN6
); /* TODO: print argument */
101 NAME(SIOCGIFPSRCADDR_IN6
); /* TODO: print argument */
102 NAME(SIOCGIFPDSTADDR_IN6
); /* TODO: print argument */
103 NAME(SIOCGIFAFLAG_IN6
); /* TODO: print argument */
104 NAME(SIOCGDRLST_IN6
); /* TODO: print argument */
105 NAME(SIOCSNDFLUSH_IN6
); /* TODO: print argument */
106 NAME(SIOCGNBRINFO_IN6
); /* TODO: print argument */
107 NAME(SIOCSRTRFLUSH_IN6
); /* TODO: print argument */
108 NAME(SIOCGIFSTAT_IN6
); /* TODO: print argument */
109 NAME(SIOCGIFSTAT_ICMP6
); /* TODO: print argument */
110 NAME(SIOCSDEFIFACE_IN6
); /* TODO: print argument */
111 NAME(SIOCGDEFIFACE_IN6
); /* TODO: print argument */
112 NAME(SIOCSIFINFO_FLAGS
); /* TODO: print argument */
113 NAME(SIOCSIFPREFIX_IN6
); /* TODO: print argument */
114 NAME(SIOCGIFPREFIX_IN6
); /* TODO: print argument */
115 NAME(SIOCDIFPREFIX_IN6
); /* TODO: print argument */
116 NAME(SIOCAIFPREFIX_IN6
); /* TODO: print argument */
117 NAME(SIOCCIFPREFIX_IN6
); /* TODO: print argument */
118 NAME(SIOCGIFALIFETIME_IN6
); /* TODO: print argument */
119 NAME(SIOCAIFADDR_IN6
); /* TODO: print argument */
120 NAME(SIOCGIFINFO_IN6
); /* TODO: print argument */
121 NAME(SIOCSIFINFO_IN6
); /* TODO: print argument */
122 NAME(SIOCSIFPHYADDR_IN6
); /* TODO: print argument */
123 NAME(SIOCAADDRCTL_POLICY
); /* TODO: print argument */
124 NAME(SIOCDADDRCTL_POLICY
); /* TODO: print argument */
125 /* net80211/ieee80211_ioctl.h */
126 NAME(SIOCS80211NWID
); /* TODO: print argument */
127 NAME(SIOCG80211NWID
); /* TODO: print argument */
128 /* old MINIX inet ioctls */
129 NAME(NWIOSETHOPT
); /* TODO: print argument */
130 NAME(NWIOGETHOPT
); /* TODO: print argument */
131 NAME(NWIOGETHSTAT
); /* TODO: print argument */
132 NAME(NWIOARPGIP
); /* TODO: print argument */
133 NAME(NWIOARPGNEXT
); /* TODO: print argument */
134 NAME(NWIOARPSIP
); /* TODO: print argument */
135 NAME(NWIOARPDIP
); /* TODO: print argument */
136 NAME(NWIOSIPCONF2
); /* TODO: print argument */
137 NAME(NWIOSIPCONF
); /* TODO: print argument */
138 NAME(NWIOGIPCONF2
); /* TODO: print argument */
139 NAME(NWIOGIPCONF
); /* TODO: print argument */
142 NAME(NWIOGIPOROUTE
); /* TODO: print argument */
143 NAME(NWIOSIPOROUTE
); /* TODO: print argument */
144 NAME(NWIODIPOROUTE
); /* TODO: print argument */
145 NAME(NWIOGIPIROUTE
); /* TODO: print argument */
146 NAME(NWIOSIPIROUTE
); /* TODO: print argument */
147 NAME(NWIODIPIROUTE
); /* TODO: print argument */
152 NAME(NWIOTCPATTACH
); /* TODO: print argument */
153 NAME(NWIOTCPSHUTDOWN
); /* no argument */
156 NAME(NWIOTCPPUSH
); /* no argument */
157 NAME(NWIOTCPLISTENQ
);
158 NAME(NWIOGTCPCOOKIE
);
159 NAME(NWIOTCPACCEPTTO
);
163 NAME(NWIOUDPPEEK
); /* TODO: print argument */
164 NAME(NWIOSPSIPOPT
); /* TODO: print argument */
165 NAME(NWIOGPSIPOPT
); /* TODO: print argument */
176 NAME(NWIOSUDSACCEPT
);
179 NAME(NWIOGUDSSOTYPE
);
180 NAME(NWIOGUDSPEERCRED
);
181 NAME(NWIOGUDSSNDBUF
);
182 NAME(NWIOSUDSSNDBUF
);
183 NAME(NWIOGUDSRCVBUF
);
184 NAME(NWIOSUDSRCVBUF
);
190 static const struct flags ipopt_flags
[] = {
191 FLAG_ZERO(NWIO_NOFLAGS
),
192 FLAG_MASK(NWIO_ACC_MASK
, NWIO_EXCL
),
193 FLAG_MASK(NWIO_ACC_MASK
, NWIO_SHARED
),
194 FLAG_MASK(NWIO_ACC_MASK
, NWIO_COPY
),
201 FLAG(NWIO_PROTOSPEC
),
203 FLAG(NWIO_HDR_O_SPEC
),
204 FLAG(NWIO_HDR_O_ANY
),
205 FLAG(NWIO_RWDATONLY
),
210 put_ipaddr(struct trace_proc
* proc
, const char * name
, ipaddr_t ipaddr
)
216 put_in_addr(proc
, name
, in
);
220 put_ipproto(struct trace_proc
* proc
, const char * name
, ipproto_t proto
)
222 const char *text
= NULL
;
233 put_field(proc
, name
, text
);
235 put_value(proc
, name
, "%u", proto
);
238 static const struct flags tcpconf_flags
[] = {
239 FLAG_ZERO(NWTC_NOFLAGS
),
240 FLAG_MASK(NWTC_ACC_MASK
, NWTC_EXCL
),
241 FLAG_MASK(NWTC_ACC_MASK
, NWTC_SHARED
),
242 FLAG_MASK(NWTC_ACC_MASK
, NWTC_COPY
),
243 FLAG_MASK(NWTC_LOCPORT_MASK
, NWTC_LP_UNSET
),
244 FLAG_MASK(NWTC_LOCPORT_MASK
, NWTC_LP_SET
),
245 FLAG_MASK(NWTC_LOCPORT_MASK
, NWTC_LP_SEL
),
252 #define put_port(proc, name, port) \
253 put_value(proc, name, "%u", ntohs(port))
255 static const struct flags tcpcl_flags
[] = {
256 FLAG_ZERO(TCF_DEFAULT
),
260 static const struct flags tcpopt_flags
[] = {
261 FLAG_ZERO(NWTO_NOFLAG
),
263 FLAG(NWTO_SND_NOTURG
),
265 FLAG(NWTO_RCV_NOTURG
),
267 FLAG(NWTO_NOTBSD_URG
),
273 static const struct flags udpopt_flags
[] = {
274 FLAG_ZERO(NWUO_NOFLAGS
),
275 FLAG_MASK(NWUO_ACC_MASK
, NWUO_EXCL
),
276 FLAG_MASK(NWUO_ACC_MASK
, NWUO_SHARED
),
277 FLAG_MASK(NWUO_ACC_MASK
, NWUO_COPY
),
278 FLAG_MASK(NWUO_LOCPORT_MASK
, NWUO_LP_SET
),
279 FLAG_MASK(NWUO_LOCPORT_MASK
, NWUO_LP_SEL
),
280 FLAG_MASK(NWUO_LOCPORT_MASK
, NWUO_LP_ANY
),
289 FLAG(NWUO_RWDATONLY
),
296 put_struct_uucred(struct trace_proc
* proc
, const char * name
, int flags
,
301 if (!put_open_struct(proc
, name
, flags
, addr
, &cred
, sizeof(cred
)))
304 put_value(proc
, "cr_uid", "%u", cred
.cr_uid
);
306 put_value(proc
, "cr_gid", "%u", cred
.cr_gid
);
308 put_value(proc
, "cr_ngroups", "%d", cred
.cr_ngroups
);
309 put_groups(proc
, "cr_groups", PF_LOCADDR
,
310 (vir_bytes
)&cred
.cr_groups
, cred
.cr_ngroups
);
313 put_close_struct(proc
, verbose
> 0);
317 put_msg_control(struct trace_proc
* proc
, struct msg_control
* ptr
)
320 struct cmsghdr
*cmsg
;
324 if (ptr
->msg_controllen
> sizeof(ptr
->msg_control
)) {
325 put_field(proc
, NULL
, "..");
330 put_open(proc
, NULL
, PF_NONAME
, "[", ", ");
332 memset(&msg
, 0, sizeof(msg
));
333 msg
.msg_control
= ptr
->msg_control
;
334 msg
.msg_controllen
= ptr
->msg_controllen
;
337 * TODO: decide if we need a verbosity-based limit here. The argument
338 * in favor of printing everything is that upon receipt, SCM_RIGHTS
339 * actually creates new file descriptors, which is pretty essential in
340 * terms of figuring out what is happening in a process. In addition,
341 * these calls should be sufficiently rare that the lengthy output is
342 * not really disruptive for the general output flow.
344 for (cmsg
= CMSG_FIRSTHDR(&msg
); cmsg
!= NULL
;
345 cmsg
= CMSG_NXTHDR(&msg
, cmsg
)) {
346 put_open(proc
, NULL
, 0, "{", ", ");
349 put_value(proc
, "cmsg_len", "%u", cmsg
->cmsg_len
);
350 if (!valuesonly
&& cmsg
->cmsg_level
== SOL_SOCKET
)
351 put_field(proc
, "cmsg_level", "SOL_SOCKET");
353 put_value(proc
, "cmsg_level", "%d", cmsg
->cmsg_level
);
354 if (cmsg
->cmsg_level
== SOL_SOCKET
)
355 put_cmsg_type(proc
, "cmsg_type", cmsg
->cmsg_type
);
357 len
= cmsg
->cmsg_len
- CMSG_LEN(0);
359 /* Print the contents of the messages that we know. */
360 if (cmsg
->cmsg_level
== SOL_SOCKET
&&
361 cmsg
->cmsg_type
== SCM_RIGHTS
) {
362 put_open(proc
, NULL
, PF_NONAME
, "[", ", ");
363 for (i
= 0; i
< len
/ sizeof(int); i
++)
365 ((int *)CMSG_DATA(cmsg
))[i
]);
366 put_close(proc
, "]");
367 } else if (cmsg
->cmsg_level
== SOL_SOCKET
&&
368 cmsg
->cmsg_type
== SCM_CREDS
) {
369 put_struct_uucred(proc
, NULL
, PF_LOCADDR
,
370 (vir_bytes
)CMSG_DATA(cmsg
));
372 put_field(proc
, NULL
, "..");
374 put_close(proc
, "}");
377 put_close(proc
, "]");
381 net_ioctl_arg(struct trace_proc
* proc
, unsigned long req
, void * ptr
, int dir
)
385 nwio_tcpconf_t
*nwtc
;
388 tcp_cookie_t
*cookie
;
390 struct sockaddr_un
*sun
;
396 * Arguably this does not belong here, but as of writing, the
397 * network services are the only ones actually implementing
398 * support for this IOCTL, and we don't have a more suitable
399 * place to put it either.
404 put_value(proc
, NULL
, "%d", *(int *)ptr
);
409 if ((ipopt
= (nwio_ipopt_t
*)ptr
) == NULL
)
412 put_flags(proc
, "nwio_flags", ipopt_flags
, COUNT(ipopt_flags
),
413 "0x%x", ipopt
->nwio_flags
);
415 if (ipopt
->nwio_flags
& NWIO_REMSPEC
)
416 put_ipaddr(proc
, "nwio_rem", ipopt
->nwio_rem
);
417 if (ipopt
->nwio_flags
& NWIO_PROTOSPEC
)
418 put_ipproto(proc
, "nwio_proto", ipopt
->nwio_proto
);
420 return 0; /* TODO: the remaining fields */
424 if ((nwtc
= (nwio_tcpconf_t
*)ptr
) == NULL
)
427 put_flags(proc
, "nwtc_flags", tcpconf_flags
,
428 COUNT(tcpconf_flags
), "0x%x", nwtc
->nwtc_flags
);
430 /* The local address cannot be set, just retrieved. */
431 if (req
== NWIOGTCPCONF
)
432 put_ipaddr(proc
, "nwtc_locaddr", nwtc
->nwtc_locaddr
);
434 if ((nwtc
->nwtc_flags
& NWTC_LOCPORT_MASK
) == NWTC_LP_SET
)
435 put_port(proc
, "nwtc_locport", nwtc
->nwtc_locport
);
437 if (nwtc
->nwtc_flags
& NWTC_SET_RA
)
438 put_ipaddr(proc
, "nwtc_remaddr", nwtc
->nwtc_remaddr
);
440 if (nwtc
->nwtc_flags
& NWTC_SET_RP
)
441 put_port(proc
, "nwtc_remport", nwtc
->nwtc_remport
);
447 if ((nwtcl
= (nwio_tcpcl_t
*)ptr
) == NULL
)
450 put_flags(proc
, "nwtcl_flags", tcpcl_flags
,
451 COUNT(tcpcl_flags
), "0x%x", nwtcl
->nwtcl_flags
);
453 /* We pretend the unused nwtcl_ttl field does not exist. */
458 if ((nwto
= (nwio_tcpopt_t
*)ptr
) == NULL
)
461 put_flags(proc
, "nwto_flags", tcpopt_flags
,
462 COUNT(tcpopt_flags
), "0x%x", nwto
->nwto_flags
);
470 put_value(proc
, NULL
, "%d", *(int *)ptr
);
474 case NWIOTCPACCEPTTO
:
475 if ((cookie
= (tcp_cookie_t
*)ptr
) == NULL
)
478 put_value(proc
, "tc_ref", "%"PRIu32
, cookie
->tc_ref
);
480 put_buf(proc
, "tc_secret", PF_LOCADDR
,
481 (vir_bytes
)&cookie
->tc_secret
,
482 sizeof(cookie
->tc_secret
));
483 return (verbose
> 0) ? IF_ALL
: 0;
490 if (!valuesonly
&& (text
= get_error_name(i
)) != NULL
)
491 put_field(proc
, NULL
, text
);
493 put_value(proc
, NULL
, "%d", i
);
498 if ((nwuo
= (nwio_udpopt_t
*)ptr
) == NULL
)
501 put_flags(proc
, "nwuo_flags", udpopt_flags
,
502 COUNT(udpopt_flags
), "0x%x", nwuo
->nwuo_flags
);
504 /* The local address cannot be set, just retrieved. */
505 if (req
== NWIOGUDPOPT
)
506 put_ipaddr(proc
, "nwuo_locaddr", nwuo
->nwuo_locaddr
);
508 if ((nwuo
->nwuo_flags
& NWUO_LOCPORT_MASK
) == NWUO_LP_SET
)
509 put_port(proc
, "nwuo_locport", nwuo
->nwuo_locport
);
511 if (nwuo
->nwuo_flags
& NWUO_RA_SET
)
512 put_ipaddr(proc
, "nwuo_remaddr", nwuo
->nwuo_remaddr
);
514 if (nwuo
->nwuo_flags
& NWUO_RP_SET
)
515 put_port(proc
, "nwuo_remport", nwuo
->nwuo_remport
);
526 if ((sun
= (struct sockaddr_un
*)ptr
) == NULL
)
529 put_socket_family(proc
, "sun_family", sun
->sun_family
);
531 /* This could be extended to a generic sockaddr printer.. */
532 if (sun
->sun_family
== AF_LOCAL
) {
533 put_buf(proc
, "sun_path", PF_LOCADDR
| PF_PATH
,
534 (vir_bytes
)&sun
->sun_path
, sizeof(sun
->sun_path
));
535 return IF_ALL
; /* skipping sun_len, it's unused */
544 put_socket_type(proc
, NULL
, *(int *)ptr
);
551 put_shutdown_how(proc
, NULL
, *(int *)ptr
);
558 put_dev(proc
, NULL
, *(dev_t
*)ptr
);
570 put_msg_control(proc
, (struct msg_control
*)ptr
);
573 case NWIOGUDSPEERCRED
:
577 put_struct_uucred(proc
, NULL
, PF_LOCADDR
, (vir_bytes
)ptr
);
587 put_value(proc
, NULL
, "%zu", *(size_t *)ptr
);