bsd-user: Add FreeBSD socket ioctl definitions
Add os-ioctl-sockio.h with network socket and interface control ioctl definitions including SIOCGIFADDR, SIOCSIFADDR, SIOCGIFCONF, and related network interface ioctls with target_ structure definitions. Signed-off-by: Stacey Son <sson@FreeBSD.org> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> Signed-off-by: Warner Losh <imp@bsdimp.com>
Stacey Son committed
Mar 13, 2026 at 22:11 UTC
853481f60ae048c35b775dcadd93423227fb416e
1 file changed
+246
bsd-user/freebsd/os-ioctl-sockio.h
new
+246
@@ -0,0 +1,246 @@
1
+/*
2
+ * FreeBSD sockio.h definitions for ioctl(2) emulation
3
+ *
4
+ * Copyright (c) 2015 Stacey D. Son
5
+ *
6
+ * SPDX-License-Identifier: GPL-2.0-or-later
7
+ */
8
+#ifndef OS_IOCTL_SOCKIO_H
9
+#define OS_IOCTL_SOCKIO_H
10
+
11
+/* See sys/sockio.h */
12
+#define TARGET_SIOCSHIWAT TARGET_IOW('s', 0, int32_t)
13
+#define TARGET_SIOCGHIWAT TARGET_IOR('s', 1, int32_t)
14
+#define TARGET_SIOCSLOWAT TARGET_IOW('s', 2, int32_t)
15
+#define TARGET_SIOCGLOWAT TARGET_IOR('s', 3, int32_t)
16
+#define TARGET_SIOCATMARK TARGET_IOR('s', 7, int32_t)
17
+#define TARGET_SIOCSPGRP TARGET_IOW('s', 8, int32_t)
18
+#define TARGET_SIOCGPGRP TARGET_IOR('s', 9, int32_t)
19
+
20
+/* See net/if.h */
21
+struct target_ifreq_buffer {
22
+ abi_ulong length;
23
+ abi_ulong buffer;
24
+};
25
+
26
+struct target_ifreq_nv_req {
27
+ abi_uint buf_length; /* Total size of buffer */
28
+ abi_uint length; /* Length of the filled part */
29
+ abi_ulong buffer; /* Buffer itself, containing packed nv */
30
+};
31
+
32
+#define TARGET_IFNAMSIZ 16
33
+
34
+struct target_ifreq {
35
+ char ifr_name[TARGET_IFNAMSIZ];
36
+ union {
37
+ struct target_sockaddr ifru_addr;
38
+ struct target_sockaddr ifru_dstaddr;
39
+ struct target_sockaddr ifru_broadaddr;
40
+ struct target_ifreq_buffer ifru_buffer;
41
+ abi_short ifru_flags[2];
42
+ abi_short ifru_index;
43
+ abi_int ifru_jid;
44
+ abi_int ifru_metric;
45
+ abi_int ifru_mtu;
46
+ abi_int ifru_phys;
47
+ abi_int ifru_media;
48
+ abi_ulong ifru_data;
49
+ abi_int ifru_cap[2];
50
+ uint32_t ifru_fib;
51
+ uint8_t ifru_vlan_pcp;
52
+ struct target_ifreq_nv_req ifru_nv;
53
+ } ifr_ifru;
54
+};
55
+
56
+
57
+#define TARGET_SIOCSIFADDR TARGET_IOW('i', 12, struct target_ifreq)
58
+#define TARGET_SIOCGIFADDR TARGET_IOWR('i', 33, struct target_ifreq)
59
+#define TARGET_SIOCSIFDSTADDR TARGET_IOW('i', 14, struct target_ifreq)
60
+#define TARGET_SIOCGIFDSTADDR TARGET_IOWR('i', 34, struct target_ifreq)
61
+#define TARGET_SIOCSIFFLAGS TARGET_IOW('i', 16, struct target_ifreq)
62
+#define TARGET_SIOCGIFFLAGS TARGET_IOWR('i', 17, struct target_ifreq)
63
+#define TARGET_SIOCGIFBRDADDR TARGET_IOWR('i', 35, struct target_ifreq)
64
+#define TARGET_SIOCSIFBRDADDR TARGET_IOW('i', 19, struct target_ifreq)
65
+#define TARGET_SIOCGIFNETMASK TARGET_IOWR('i', 37, struct target_ifreq)
66
+#define TARGET_SIOCSIFNETMASK TARGET_IOW('i', 22, struct target_ifreq)
67
+#define TARGET_SIOCGIFMETRIC TARGET_IOWR('i', 23, struct target_ifreq)
68
+#define TARGET_SIOCSIFMETRIC TARGET_IOW('i', 24, struct target_ifreq)
69
+#define TARGET_SIOCDIFADDR TARGET_IOW('i', 25, struct target_ifreq)
70
+#define TARGET_SIOCSIFCAP TARGET_IOW('i', 30, struct target_ifreq)
71
+#define TARGET_SIOCGIFCAP TARGET_IOWR('i', 31, struct target_ifreq)
72
+#define TARGET_SIOCGIFINDEX TARGET_IOWR('i', 32, struct target_ifreq)
73
+#define TARGET_SIOCGIFMAC TARGET_IOWR('i', 38, struct target_ifreq)
74
+#define TARGET_SIOCSIFMAC TARGET_IOW('i', 39, struct target_ifreq)
75
+#define TARGET_SIOCSIFNAME TARGET_IOW('i', 40, struct target_ifreq)
76
+#define TARGET_SIOCSIFDESCR TARGET_IOW('i', 41, struct target_ifreq)
77
+#define TARGET_SIOCGIFDESCR TARGET_IOWR('i', 42, struct target_ifreq)
78
+#define TARGET_SIOCADDMULTI TARGET_IOW('i', 49, struct target_ifreq)
79
+#define TARGET_SIOCDELMULTI TARGET_IOW('i', 50, struct target_ifreq)
80
+#define TARGET_SIOCGIFMTU TARGET_IOWR('i', 51, struct target_ifreq)
81
+#define TARGET_SIOCSIFMTU TARGET_IOW('i', 52, struct target_ifreq)
82
+#define TARGET_SIOCGIFPHYS TARGET_IOWR('i', 53, struct target_ifreq)
83
+#define TARGET_SIOCSIFPHYS TARGET_IOW('i', 54, struct target_ifreq)
84
+#define TARGET_SIOCSIFMEDIA TARGET_IOWR('i', 55, struct target_ifreq)
85
+#define TARGET_SIOCSIFGENERIC TARGET_IOW('i', 57, struct target_ifreq)
86
+#define TARGET_SIOCGIFGENERIC TARGET_IOWR('i', 58, struct target_ifreq)
87
+#define TARGET_SIOCSIFLLADDR TARGET_IOW('i', 60, struct target_ifreq)
88
+#define TARGET_SIOCGIFPSRCADDR TARGET_IOWR('i', 71, struct target_ifreq)
89
+#define TARGET_SIOCGIFPDSTADDR TARGET_IOWR('i', 72, struct target_ifreq)
90
+#define TARGET_SIOCDIFPHYADDR TARGET_IOW('i', 73, struct target_ifreq)
91
+#define TARGET_SIOCGPRIVATE_0 TARGET_IOWR('i', 80, struct target_ifreq)
92
+#define TARGET_SIOCGPRIVATE_1 TARGET_IOWR('i', 81, struct target_ifreq)
93
+#define TARGET_SIOCSIFVNET TARGET_IOWR('i', 90, struct target_ifreq)
94
+#define TARGET_SIOCSIFRVNET TARGET_IOWR('i', 91, struct target_ifreq)
95
+#define TARGET_SIOCGIFFIB TARGET_IOWR('i', 92, struct target_ifreq)
96
+#define TARGET_SIOCSIFFIB TARGET_IOW('i', 93, struct target_ifreq)
97
+#define TARGET_SIOCGTUNFIB TARGET_IOWR('i', 94, struct target_ifreq)
98
+#define TARGET_SIOCIFCREATE TARGET_IOWR('i', 122, struct target_ifreq)
99
+#define TARGET_SIOCIFCREATE2 TARGET_IOWR('i', 124, struct target_ifreq)
100
+#define TARGET_SIOCIFDESTROY TARGET_IOW('i', 121, struct target_ifreq)
101
+
102
+/* net/if_gre.h */
103
+#define TARGET_GREGKEY TARGET_IOWR('i', 107, struct target_ifreq)
104
+#define TARGET_GREGOPTS TARGET_IOWR('i', 109, struct target_ifreq)
105
+
106
+/* net/if_gif.h */
107
+#define TARGET_GIFGOPTS TARGET_IOWR('i', 150, struct target_ifreq)
108
+
109
+/* netinet/ip_carp.h */
110
+#define TARGET_SIOCGVH TARGET_IOWR('i', 246, struct target_ifreq)
111
+
112
+/* net/if_pfsync.h */
113
+#define TARGET_SIOCGETPFSYNC TARGET_IOWR('i', 248, struct target_ifreq)
114
+
115
+
116
+/* See net/if.h */
117
+struct target_ifconf {
118
+ int32_t ifc_len;
119
+ union {
120
+ abi_ulong ifcu_buf;
121
+ abi_ulong ifcu_req;
122
+ } ifc_ifcu;
123
+};
124
+
125
+#define TARGET_SIOCGIFCONF TARGET_IOWR('i', 36, struct target_ifconf)
126
+
127
+/* See net/if.h */
128
+struct target_ifdrv {
129
+ char ifd_name[TARGET_IFNAMSIZ];
130
+ abi_ulong ifd_cmd;
131
+ abi_ulong ifd_len;
132
+ abi_ulong ifd_data;
133
+};
134
+
135
+#define TARGET_SIOCSDRVSPEC TARGET_IOW('i', 123, struct target_ifdrv)
136
+#define TARGET_SIOCGDRVSPEC TARGET_IOWR('i', 123, struct target_ifdrv)
137
+
138
+/* See net/if.h */
139
+struct target_ifg_req {
140
+ union {
141
+ char ifgrqu_group[TARGET_IFNAMSIZ];
142
+ char ifgrqu_member[TARGET_IFNAMSIZ];
143
+ } ifgrq_ifgrqu;
144
+};
145
+
146
+struct target_ifgroupreq {
147
+ char ifgr_name[TARGET_IFNAMSIZ];
148
+ uint32_t ifgr_len;
149
+ union {
150
+ char ifgru_group[TARGET_IFNAMSIZ];
151
+ abi_ulong ifgru_groups;
152
+ } ifgr_ifgru;
153
+};
154
+
155
+#define TARGET_SIOCGIFGROUP TARGET_IOWR('i', 136, struct target_ifgroupreq)
156
+
157
+struct target_ifmediareq {
158
+ char ifm_name[TARGET_IFNAMSIZ];
159
+ int32_t ifm_current;
160
+ int32_t ifm_mask;
161
+ int32_t ifm_status;
162
+ int32_t ifm_active;
163
+ int32_t ifm_count;
164
+ abi_ulong ifm_ulist;
165
+};
166
+
167
+#define TARGET_SIOCGIFMEDIA TARGET_IOWR('i', 56, struct target_ifmediareq)
168
+#define TARGET_SIOCGIFXMEDIA TARGET_IOWR('i', 139, struct target_ifmediareq)
169
+
170
+#define TARGET_IFSTATMAX 800
171
+struct target_ifstat {
172
+ char ifs_name[TARGET_IFNAMSIZ];
173
+ char ascii[TARGET_IFSTATMAX + 1];
174
+};
175
+
176
+#define TARGET_SIOCGIFSTATUS TARGET_IOWR('i', 59, struct target_ifstat)
177
+
178
+/* net80211/ieee80211_ioctl.h */
179
+struct target_ieee80211req {
180
+ char i_name[TARGET_IFNAMSIZ];
181
+ uint16_t i_type;
182
+ int16_t i_val;
183
+ uint16_t i_len;
184
+ abi_ulong i_data;
185
+};
186
+
187
+#define TARGET_SIOCG80211 TARGET_IOWR('i', 235, struct target_ieee80211req)
188
+
189
+/* net/if_lagg.h */
190
+struct target_lacp_opreq {
191
+ uint16_t actor_prio;
192
+ uint8_t actor_mac[ETHER_ADDR_LEN];
193
+ uint16_t actor_key;
194
+ uint16_t actor_portprio;
195
+ uint16_t actor_portno;
196
+ uint8_t actor_state;
197
+ uint16_t partner_prio;
198
+ uint8_t partner_mac[ETHER_ADDR_LEN];
199
+ uint16_t partner_key;
200
+ uint16_t partner_portprio;
201
+ uint16_t partner_portno;
202
+ uint8_t partner_state;
203
+};
204
+
205
+struct target_lagg_reqport {
206
+ char rp_ifname[TARGET_IFNAMSIZ];
207
+ char rp_portname[TARGET_IFNAMSIZ];
208
+ u_int32_t rp_prio;
209
+ u_int32_t rp_flags;
210
+ union {
211
+ struct target_lacp_opreq rpsc_lacp;
212
+ } rp_psc;
213
+};
214
+#define TARGET_SIOCGLAGGPORT TARGET_IOWR('i', 140, struct target_lagg_reqport)
215
+
216
+struct target_lagg_reqall {
217
+ char ra_ifname[TARGET_IFNAMSIZ];
218
+ abi_uint ra_proto;
219
+
220
+ abi_ulong ra_size;
221
+ abi_ulong ra_port;
222
+ abi_int ra_ports;
223
+ union {
224
+ struct target_lacp_opreq rpsc_lacp;
225
+ } ra_psc;
226
+};
227
+#define TARGET_SIOCGLAGG TARGET_IOWR('i', 143, struct target_lagg_reqall)
228
+
229
+struct target_lagg_reqflags {
230
+ char rf_ifname[TARGET_IFNAMSIZ];
231
+ uint32_t rf_flags;
232
+};
233
+#define TARGET_SIOCGLAGGFLAGS TARGET_IOWR('i', 145, struct target_lagg_reqflags)
234
+
235
+struct target_lagg_reqopts {
236
+ char ro_ifname[TARGET_IFNAMSIZ];
237
+ abi_int ro_opts;
238
+ abi_uint ro_count;
239
+ abi_uint ro_active;
240
+ abi_uint ro_flapping;
241
+ abi_int ro_flowid_shift;
242
+ uint32_t ro_bkt;
243
+};
244
+#define TARGET_SIOCGLAGGOPTS TARGET_IOWR('i', 152, struct target_lagg_reqopts)
245
+
246
+#endif /* OS_IOCTL_SOCKIO_H */