2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 #include "qemu/osdep.h"
18 #include <sys/signalfd.h>
19 #include <linux/unistd.h>
20 #include <linux/audit.h>
22 #include <sys/inotify.h>
24 #include <linux/netlink.h>
25 #ifdef CONFIG_RTNETLINK
26 #include <linux/rtnetlink.h>
27 #include <linux/if_bridge.h>
34 QEMU_IFLA_BR_FORWARD_DELAY
,
35 QEMU_IFLA_BR_HELLO_TIME
,
37 QEMU_IFLA_BR_AGEING_TIME
,
38 QEMU_IFLA_BR_STP_STATE
,
39 QEMU_IFLA_BR_PRIORITY
,
40 QEMU_IFLA_BR_VLAN_FILTERING
,
41 QEMU_IFLA_BR_VLAN_PROTOCOL
,
42 QEMU_IFLA_BR_GROUP_FWD_MASK
,
44 QEMU_IFLA_BR_BRIDGE_ID
,
45 QEMU_IFLA_BR_ROOT_PORT
,
46 QEMU_IFLA_BR_ROOT_PATH_COST
,
47 QEMU_IFLA_BR_TOPOLOGY_CHANGE
,
48 QEMU_IFLA_BR_TOPOLOGY_CHANGE_DETECTED
,
49 QEMU_IFLA_BR_HELLO_TIMER
,
50 QEMU_IFLA_BR_TCN_TIMER
,
51 QEMU_IFLA_BR_TOPOLOGY_CHANGE_TIMER
,
52 QEMU_IFLA_BR_GC_TIMER
,
53 QEMU_IFLA_BR_GROUP_ADDR
,
54 QEMU_IFLA_BR_FDB_FLUSH
,
55 QEMU_IFLA_BR_MCAST_ROUTER
,
56 QEMU_IFLA_BR_MCAST_SNOOPING
,
57 QEMU_IFLA_BR_MCAST_QUERY_USE_IFADDR
,
58 QEMU_IFLA_BR_MCAST_QUERIER
,
59 QEMU_IFLA_BR_MCAST_HASH_ELASTICITY
,
60 QEMU_IFLA_BR_MCAST_HASH_MAX
,
61 QEMU_IFLA_BR_MCAST_LAST_MEMBER_CNT
,
62 QEMU_IFLA_BR_MCAST_STARTUP_QUERY_CNT
,
63 QEMU_IFLA_BR_MCAST_LAST_MEMBER_INTVL
,
64 QEMU_IFLA_BR_MCAST_MEMBERSHIP_INTVL
,
65 QEMU_IFLA_BR_MCAST_QUERIER_INTVL
,
66 QEMU_IFLA_BR_MCAST_QUERY_INTVL
,
67 QEMU_IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
,
68 QEMU_IFLA_BR_MCAST_STARTUP_QUERY_INTVL
,
69 QEMU_IFLA_BR_NF_CALL_IPTABLES
,
70 QEMU_IFLA_BR_NF_CALL_IP6TABLES
,
71 QEMU_IFLA_BR_NF_CALL_ARPTABLES
,
72 QEMU_IFLA_BR_VLAN_DEFAULT_PVID
,
74 QEMU_IFLA_BR_VLAN_STATS_ENABLED
,
75 QEMU_IFLA_BR_MCAST_STATS_ENABLED
,
76 QEMU_IFLA_BR_MCAST_IGMP_VERSION
,
77 QEMU_IFLA_BR_MCAST_MLD_VERSION
,
78 QEMU_IFLA_BR_VLAN_STATS_PER_PORT
,
79 QEMU_IFLA_BR_MULTI_BOOLOPT
,
103 QEMU_IFLA_NET_NS_PID
,
106 QEMU_IFLA_VFINFO_LIST
,
114 QEMU_IFLA_PROMISCUITY
,
115 QEMU_IFLA_NUM_TX_QUEUES
,
116 QEMU_IFLA_NUM_RX_QUEUES
,
118 QEMU_IFLA_PHYS_PORT_ID
,
119 QEMU_IFLA_CARRIER_CHANGES
,
120 QEMU_IFLA_PHYS_SWITCH_ID
,
121 QEMU_IFLA_LINK_NETNSID
,
122 QEMU_IFLA_PHYS_PORT_NAME
,
123 QEMU_IFLA_PROTO_DOWN
,
124 QEMU_IFLA_GSO_MAX_SEGS
,
125 QEMU_IFLA_GSO_MAX_SIZE
,
129 QEMU_IFLA_NEW_NETNSID
,
130 QEMU_IFLA_IF_NETNSID
,
131 QEMU_IFLA_CARRIER_UP_COUNT
,
132 QEMU_IFLA_CARRIER_DOWN_COUNT
,
133 QEMU_IFLA_NEW_IFINDEX
,
140 QEMU_IFLA_BRPORT_UNSPEC
,
141 QEMU_IFLA_BRPORT_STATE
,
142 QEMU_IFLA_BRPORT_PRIORITY
,
143 QEMU_IFLA_BRPORT_COST
,
144 QEMU_IFLA_BRPORT_MODE
,
145 QEMU_IFLA_BRPORT_GUARD
,
146 QEMU_IFLA_BRPORT_PROTECT
,
147 QEMU_IFLA_BRPORT_FAST_LEAVE
,
148 QEMU_IFLA_BRPORT_LEARNING
,
149 QEMU_IFLA_BRPORT_UNICAST_FLOOD
,
150 QEMU_IFLA_BRPORT_PROXYARP
,
151 QEMU_IFLA_BRPORT_LEARNING_SYNC
,
152 QEMU_IFLA_BRPORT_PROXYARP_WIFI
,
153 QEMU_IFLA_BRPORT_ROOT_ID
,
154 QEMU_IFLA_BRPORT_BRIDGE_ID
,
155 QEMU_IFLA_BRPORT_DESIGNATED_PORT
,
156 QEMU_IFLA_BRPORT_DESIGNATED_COST
,
159 QEMU_IFLA_BRPORT_TOPOLOGY_CHANGE_ACK
,
160 QEMU_IFLA_BRPORT_CONFIG_PENDING
,
161 QEMU_IFLA_BRPORT_MESSAGE_AGE_TIMER
,
162 QEMU_IFLA_BRPORT_FORWARD_DELAY_TIMER
,
163 QEMU_IFLA_BRPORT_HOLD_TIMER
,
164 QEMU_IFLA_BRPORT_FLUSH
,
165 QEMU_IFLA_BRPORT_MULTICAST_ROUTER
,
166 QEMU_IFLA_BRPORT_PAD
,
167 QEMU_IFLA_BRPORT_MCAST_FLOOD
,
168 QEMU_IFLA_BRPORT_MCAST_TO_UCAST
,
169 QEMU_IFLA_BRPORT_VLAN_TUNNEL
,
170 QEMU_IFLA_BRPORT_BCAST_FLOOD
,
171 QEMU_IFLA_BRPORT_GROUP_FWD_MASK
,
172 QEMU_IFLA_BRPORT_NEIGH_SUPPRESS
,
173 QEMU_IFLA_BRPORT_ISOLATED
,
174 QEMU_IFLA_BRPORT_BACKUP_PORT
,
175 QEMU___IFLA_BRPORT_MAX
179 QEMU_IFLA_TUN_UNSPEC
,
184 QEMU_IFLA_TUN_VNET_HDR
,
185 QEMU_IFLA_TUN_PERSIST
,
186 QEMU_IFLA_TUN_MULTI_QUEUE
,
187 QEMU_IFLA_TUN_NUM_QUEUES
,
188 QEMU_IFLA_TUN_NUM_DISABLED_QUEUES
,
193 QEMU_IFLA_INFO_UNSPEC
,
196 QEMU_IFLA_INFO_XSTATS
,
197 QEMU_IFLA_INFO_SLAVE_KIND
,
198 QEMU_IFLA_INFO_SLAVE_DATA
,
199 QEMU___IFLA_INFO_MAX
,
203 QEMU_IFLA_INET_UNSPEC
,
205 QEMU___IFLA_INET_MAX
,
209 QEMU_IFLA_INET6_UNSPEC
,
210 QEMU_IFLA_INET6_FLAGS
,
211 QEMU_IFLA_INET6_CONF
,
212 QEMU_IFLA_INET6_STATS
,
213 QEMU_IFLA_INET6_MCAST
,
214 QEMU_IFLA_INET6_CACHEINFO
,
215 QEMU_IFLA_INET6_ICMP6STATS
,
216 QEMU_IFLA_INET6_TOKEN
,
217 QEMU_IFLA_INET6_ADDR_GEN_MODE
,
218 QEMU___IFLA_INET6_MAX
222 QEMU_IFLA_XDP_UNSPEC
,
224 QEMU_IFLA_XDP_ATTACHED
,
226 QEMU_IFLA_XDP_PROG_ID
,
241 QEMU_RTA_PROTOINFO
, /* no longer used */
244 QEMU_RTA_SESSION
, /* no longer used */
245 QEMU_RTA_MP_ALGO
, /* no longer used */
257 QEMU_RTA_TTL_PROPAGATE
,
264 TargetFdTrans
**target_fd_trans
;
265 unsigned int target_fd_max
;
267 static void tswap_nlmsghdr(struct nlmsghdr
*nlh
)
269 nlh
->nlmsg_len
= tswap32(nlh
->nlmsg_len
);
270 nlh
->nlmsg_type
= tswap16(nlh
->nlmsg_type
);
271 nlh
->nlmsg_flags
= tswap16(nlh
->nlmsg_flags
);
272 nlh
->nlmsg_seq
= tswap32(nlh
->nlmsg_seq
);
273 nlh
->nlmsg_pid
= tswap32(nlh
->nlmsg_pid
);
276 static abi_long
host_to_target_for_each_nlmsg(struct nlmsghdr
*nlh
,
278 abi_long (*host_to_target_nlmsg
)
284 while (len
> sizeof(struct nlmsghdr
)) {
286 nlmsg_len
= nlh
->nlmsg_len
;
287 if (nlmsg_len
< sizeof(struct nlmsghdr
) ||
292 switch (nlh
->nlmsg_type
) {
300 struct nlmsgerr
*e
= NLMSG_DATA(nlh
);
301 e
->error
= tswap32(e
->error
);
302 tswap_nlmsghdr(&e
->msg
);
307 ret
= host_to_target_nlmsg(nlh
);
315 len
-= NLMSG_ALIGN(nlmsg_len
);
316 nlh
= (struct nlmsghdr
*)(((char*)nlh
) + NLMSG_ALIGN(nlmsg_len
));
321 static abi_long
target_to_host_for_each_nlmsg(struct nlmsghdr
*nlh
,
323 abi_long (*target_to_host_nlmsg
)
328 while (len
> sizeof(struct nlmsghdr
)) {
329 if (tswap32(nlh
->nlmsg_len
) < sizeof(struct nlmsghdr
) ||
330 tswap32(nlh
->nlmsg_len
) > len
) {
334 switch (nlh
->nlmsg_type
) {
341 struct nlmsgerr
*e
= NLMSG_DATA(nlh
);
342 e
->error
= tswap32(e
->error
);
343 tswap_nlmsghdr(&e
->msg
);
347 ret
= target_to_host_nlmsg(nlh
);
352 len
-= NLMSG_ALIGN(nlh
->nlmsg_len
);
353 nlh
= (struct nlmsghdr
*)(((char *)nlh
) + NLMSG_ALIGN(nlh
->nlmsg_len
));
358 #ifdef CONFIG_RTNETLINK
359 static abi_long
host_to_target_for_each_nlattr(struct nlattr
*nlattr
,
360 size_t len
, void *context
,
361 abi_long (*host_to_target_nlattr
)
365 unsigned short nla_len
;
368 while (len
> sizeof(struct nlattr
)) {
369 nla_len
= nlattr
->nla_len
;
370 if (nla_len
< sizeof(struct nlattr
) ||
374 ret
= host_to_target_nlattr(nlattr
, context
);
375 nlattr
->nla_len
= tswap16(nlattr
->nla_len
);
376 nlattr
->nla_type
= tswap16(nlattr
->nla_type
);
380 len
-= NLA_ALIGN(nla_len
);
381 nlattr
= (struct nlattr
*)(((char *)nlattr
) + NLA_ALIGN(nla_len
));
386 static abi_long
host_to_target_for_each_rtattr(struct rtattr
*rtattr
,
388 abi_long (*host_to_target_rtattr
)
391 unsigned short rta_len
;
394 while (len
> sizeof(struct rtattr
)) {
395 rta_len
= rtattr
->rta_len
;
396 if (rta_len
< sizeof(struct rtattr
) ||
400 ret
= host_to_target_rtattr(rtattr
);
401 rtattr
->rta_len
= tswap16(rtattr
->rta_len
);
402 rtattr
->rta_type
= tswap16(rtattr
->rta_type
);
406 len
-= RTA_ALIGN(rta_len
);
407 rtattr
= (struct rtattr
*)(((char *)rtattr
) + RTA_ALIGN(rta_len
));
412 #define NLA_DATA(nla) ((void *)((char *)(nla)) + NLA_HDRLEN)
414 static abi_long
host_to_target_data_bridge_nlattr(struct nlattr
*nlattr
,
421 switch (nlattr
->nla_type
) {
423 case QEMU_IFLA_BR_FDB_FLUSH
:
426 case QEMU_IFLA_BR_GROUP_ADDR
:
429 case QEMU_IFLA_BR_VLAN_FILTERING
:
430 case QEMU_IFLA_BR_TOPOLOGY_CHANGE
:
431 case QEMU_IFLA_BR_TOPOLOGY_CHANGE_DETECTED
:
432 case QEMU_IFLA_BR_MCAST_ROUTER
:
433 case QEMU_IFLA_BR_MCAST_SNOOPING
:
434 case QEMU_IFLA_BR_MCAST_QUERY_USE_IFADDR
:
435 case QEMU_IFLA_BR_MCAST_QUERIER
:
436 case QEMU_IFLA_BR_NF_CALL_IPTABLES
:
437 case QEMU_IFLA_BR_NF_CALL_IP6TABLES
:
438 case QEMU_IFLA_BR_NF_CALL_ARPTABLES
:
439 case QEMU_IFLA_BR_VLAN_STATS_ENABLED
:
440 case QEMU_IFLA_BR_MCAST_STATS_ENABLED
:
441 case QEMU_IFLA_BR_MCAST_IGMP_VERSION
:
442 case QEMU_IFLA_BR_MCAST_MLD_VERSION
:
443 case QEMU_IFLA_BR_VLAN_STATS_PER_PORT
:
446 case QEMU_IFLA_BR_PRIORITY
:
447 case QEMU_IFLA_BR_VLAN_PROTOCOL
:
448 case QEMU_IFLA_BR_GROUP_FWD_MASK
:
449 case QEMU_IFLA_BR_ROOT_PORT
:
450 case QEMU_IFLA_BR_VLAN_DEFAULT_PVID
:
451 u16
= NLA_DATA(nlattr
);
452 *u16
= tswap16(*u16
);
455 case QEMU_IFLA_BR_FORWARD_DELAY
:
456 case QEMU_IFLA_BR_HELLO_TIME
:
457 case QEMU_IFLA_BR_MAX_AGE
:
458 case QEMU_IFLA_BR_AGEING_TIME
:
459 case QEMU_IFLA_BR_STP_STATE
:
460 case QEMU_IFLA_BR_ROOT_PATH_COST
:
461 case QEMU_IFLA_BR_MCAST_HASH_ELASTICITY
:
462 case QEMU_IFLA_BR_MCAST_HASH_MAX
:
463 case QEMU_IFLA_BR_MCAST_LAST_MEMBER_CNT
:
464 case QEMU_IFLA_BR_MCAST_STARTUP_QUERY_CNT
:
465 u32
= NLA_DATA(nlattr
);
466 *u32
= tswap32(*u32
);
469 case QEMU_IFLA_BR_HELLO_TIMER
:
470 case QEMU_IFLA_BR_TCN_TIMER
:
471 case QEMU_IFLA_BR_GC_TIMER
:
472 case QEMU_IFLA_BR_TOPOLOGY_CHANGE_TIMER
:
473 case QEMU_IFLA_BR_MCAST_LAST_MEMBER_INTVL
:
474 case QEMU_IFLA_BR_MCAST_MEMBERSHIP_INTVL
:
475 case QEMU_IFLA_BR_MCAST_QUERIER_INTVL
:
476 case QEMU_IFLA_BR_MCAST_QUERY_INTVL
:
477 case QEMU_IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
:
478 case QEMU_IFLA_BR_MCAST_STARTUP_QUERY_INTVL
:
479 u64
= NLA_DATA(nlattr
);
480 *u64
= tswap64(*u64
);
482 /* ifla_bridge_id: uin8_t[] */
483 case QEMU_IFLA_BR_ROOT_ID
:
484 case QEMU_IFLA_BR_BRIDGE_ID
:
487 gemu_log("Unknown QEMU_IFLA_BR type %d\n", nlattr
->nla_type
);
493 static abi_long
host_to_target_slave_data_bridge_nlattr(struct nlattr
*nlattr
,
500 switch (nlattr
->nla_type
) {
502 case QEMU_IFLA_BRPORT_STATE
:
503 case QEMU_IFLA_BRPORT_MODE
:
504 case QEMU_IFLA_BRPORT_GUARD
:
505 case QEMU_IFLA_BRPORT_PROTECT
:
506 case QEMU_IFLA_BRPORT_FAST_LEAVE
:
507 case QEMU_IFLA_BRPORT_LEARNING
:
508 case QEMU_IFLA_BRPORT_UNICAST_FLOOD
:
509 case QEMU_IFLA_BRPORT_PROXYARP
:
510 case QEMU_IFLA_BRPORT_LEARNING_SYNC
:
511 case QEMU_IFLA_BRPORT_PROXYARP_WIFI
:
512 case QEMU_IFLA_BRPORT_TOPOLOGY_CHANGE_ACK
:
513 case QEMU_IFLA_BRPORT_CONFIG_PENDING
:
514 case QEMU_IFLA_BRPORT_MULTICAST_ROUTER
:
515 case QEMU_IFLA_BRPORT_MCAST_FLOOD
:
516 case QEMU_IFLA_BRPORT_MCAST_TO_UCAST
:
517 case QEMU_IFLA_BRPORT_VLAN_TUNNEL
:
518 case QEMU_IFLA_BRPORT_BCAST_FLOOD
:
519 case QEMU_IFLA_BRPORT_NEIGH_SUPPRESS
:
520 case QEMU_IFLA_BRPORT_ISOLATED
:
523 case QEMU_IFLA_BRPORT_PRIORITY
:
524 case QEMU_IFLA_BRPORT_DESIGNATED_PORT
:
525 case QEMU_IFLA_BRPORT_DESIGNATED_COST
:
526 case QEMU_IFLA_BRPORT_ID
:
527 case QEMU_IFLA_BRPORT_NO
:
528 case QEMU_IFLA_BRPORT_GROUP_FWD_MASK
:
529 u16
= NLA_DATA(nlattr
);
530 *u16
= tswap16(*u16
);
533 case QEMU_IFLA_BRPORT_COST
:
534 case QEMU_IFLA_BRPORT_BACKUP_PORT
:
535 u32
= NLA_DATA(nlattr
);
536 *u32
= tswap32(*u32
);
539 case QEMU_IFLA_BRPORT_MESSAGE_AGE_TIMER
:
540 case QEMU_IFLA_BRPORT_FORWARD_DELAY_TIMER
:
541 case QEMU_IFLA_BRPORT_HOLD_TIMER
:
542 u64
= NLA_DATA(nlattr
);
543 *u64
= tswap64(*u64
);
545 /* ifla_bridge_id: uint8_t[] */
546 case QEMU_IFLA_BRPORT_ROOT_ID
:
547 case QEMU_IFLA_BRPORT_BRIDGE_ID
:
549 /* br_boolopt_multi { uint32_t, uint32_t } */
550 case QEMU_IFLA_BR_MULTI_BOOLOPT
:
551 u32
= NLA_DATA(nlattr
);
552 u32
[0] = tswap32(u32
[0]); /* optval */
553 u32
[1] = tswap32(u32
[1]); /* optmask */
556 gemu_log("Unknown QEMU_IFLA_BRPORT type %d\n", nlattr
->nla_type
);
562 static abi_long
host_to_target_data_tun_nlattr(struct nlattr
*nlattr
,
567 switch (nlattr
->nla_type
) {
569 case QEMU_IFLA_TUN_TYPE
:
570 case QEMU_IFLA_TUN_PI
:
571 case QEMU_IFLA_TUN_VNET_HDR
:
572 case QEMU_IFLA_TUN_PERSIST
:
573 case QEMU_IFLA_TUN_MULTI_QUEUE
:
576 case QEMU_IFLA_TUN_NUM_QUEUES
:
577 case QEMU_IFLA_TUN_NUM_DISABLED_QUEUES
:
578 case QEMU_IFLA_TUN_OWNER
:
579 case QEMU_IFLA_TUN_GROUP
:
580 u32
= NLA_DATA(nlattr
);
581 *u32
= tswap32(*u32
);
584 gemu_log("Unknown QEMU_IFLA_TUN type %d\n", nlattr
->nla_type
);
590 struct linkinfo_context
{
597 static abi_long
host_to_target_data_linkinfo_nlattr(struct nlattr
*nlattr
,
600 struct linkinfo_context
*li_context
= context
;
602 switch (nlattr
->nla_type
) {
604 case QEMU_IFLA_INFO_KIND
:
605 li_context
->name
= NLA_DATA(nlattr
);
606 li_context
->len
= nlattr
->nla_len
- NLA_HDRLEN
;
608 case QEMU_IFLA_INFO_SLAVE_KIND
:
609 li_context
->slave_name
= NLA_DATA(nlattr
);
610 li_context
->slave_len
= nlattr
->nla_len
- NLA_HDRLEN
;
613 case QEMU_IFLA_INFO_XSTATS
:
614 /* FIXME: only used by CAN */
617 case QEMU_IFLA_INFO_DATA
:
618 if (strncmp(li_context
->name
, "bridge",
619 li_context
->len
) == 0) {
620 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
),
623 host_to_target_data_bridge_nlattr
);
624 } else if (strncmp(li_context
->name
, "tun",
625 li_context
->len
) == 0) {
626 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
),
629 host_to_target_data_tun_nlattr
);
631 gemu_log("Unknown QEMU_IFLA_INFO_KIND %s\n", li_context
->name
);
634 case QEMU_IFLA_INFO_SLAVE_DATA
:
635 if (strncmp(li_context
->slave_name
, "bridge",
636 li_context
->slave_len
) == 0) {
637 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
),
640 host_to_target_slave_data_bridge_nlattr
);
642 gemu_log("Unknown QEMU_IFLA_INFO_SLAVE_KIND %s\n",
643 li_context
->slave_name
);
647 gemu_log("Unknown host QEMU_IFLA_INFO type: %d\n", nlattr
->nla_type
);
654 static abi_long
host_to_target_data_inet_nlattr(struct nlattr
*nlattr
,
660 switch (nlattr
->nla_type
) {
661 case QEMU_IFLA_INET_CONF
:
662 u32
= NLA_DATA(nlattr
);
663 for (i
= 0; i
< (nlattr
->nla_len
- NLA_HDRLEN
) / sizeof(*u32
);
665 u32
[i
] = tswap32(u32
[i
]);
669 gemu_log("Unknown host AF_INET type: %d\n", nlattr
->nla_type
);
674 static abi_long
host_to_target_data_inet6_nlattr(struct nlattr
*nlattr
,
679 struct ifla_cacheinfo
*ci
;
682 switch (nlattr
->nla_type
) {
684 case QEMU_IFLA_INET6_TOKEN
:
687 case QEMU_IFLA_INET6_ADDR_GEN_MODE
:
690 case QEMU_IFLA_INET6_FLAGS
:
691 u32
= NLA_DATA(nlattr
);
692 *u32
= tswap32(*u32
);
695 case QEMU_IFLA_INET6_CONF
:
696 u32
= NLA_DATA(nlattr
);
697 for (i
= 0; i
< (nlattr
->nla_len
- NLA_HDRLEN
) / sizeof(*u32
);
699 u32
[i
] = tswap32(u32
[i
]);
703 case QEMU_IFLA_INET6_CACHEINFO
:
704 ci
= NLA_DATA(nlattr
);
705 ci
->max_reasm_len
= tswap32(ci
->max_reasm_len
);
706 ci
->tstamp
= tswap32(ci
->tstamp
);
707 ci
->reachable_time
= tswap32(ci
->reachable_time
);
708 ci
->retrans_time
= tswap32(ci
->retrans_time
);
711 case QEMU_IFLA_INET6_STATS
:
712 case QEMU_IFLA_INET6_ICMP6STATS
:
713 u64
= NLA_DATA(nlattr
);
714 for (i
= 0; i
< (nlattr
->nla_len
- NLA_HDRLEN
) / sizeof(*u64
);
716 u64
[i
] = tswap64(u64
[i
]);
720 gemu_log("Unknown host AF_INET6 type: %d\n", nlattr
->nla_type
);
725 static abi_long
host_to_target_data_spec_nlattr(struct nlattr
*nlattr
,
728 switch (nlattr
->nla_type
) {
730 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
), nlattr
->nla_len
,
732 host_to_target_data_inet_nlattr
);
734 return host_to_target_for_each_nlattr(NLA_DATA(nlattr
), nlattr
->nla_len
,
736 host_to_target_data_inet6_nlattr
);
738 gemu_log("Unknown host AF_SPEC type: %d\n", nlattr
->nla_type
);
744 static abi_long
host_to_target_data_xdp_nlattr(struct nlattr
*nlattr
,
749 switch (nlattr
->nla_type
) {
751 case QEMU_IFLA_XDP_ATTACHED
:
754 case QEMU_IFLA_XDP_PROG_ID
:
755 u32
= NLA_DATA(nlattr
);
756 *u32
= tswap32(*u32
);
759 gemu_log("Unknown host XDP type: %d\n", nlattr
->nla_type
);
765 static abi_long
host_to_target_data_link_rtattr(struct rtattr
*rtattr
)
768 struct rtnl_link_stats
*st
;
769 struct rtnl_link_stats64
*st64
;
770 struct rtnl_link_ifmap
*map
;
771 struct linkinfo_context li_context
;
773 switch (rtattr
->rta_type
) {
775 case QEMU_IFLA_ADDRESS
:
776 case QEMU_IFLA_BROADCAST
:
778 case QEMU_IFLA_IFNAME
:
779 case QEMU_IFLA_QDISC
:
782 case QEMU_IFLA_OPERSTATE
:
783 case QEMU_IFLA_LINKMODE
:
784 case QEMU_IFLA_CARRIER
:
785 case QEMU_IFLA_PROTO_DOWN
:
790 case QEMU_IFLA_WEIGHT
:
791 case QEMU_IFLA_TXQLEN
:
792 case QEMU_IFLA_CARRIER_CHANGES
:
793 case QEMU_IFLA_NUM_RX_QUEUES
:
794 case QEMU_IFLA_NUM_TX_QUEUES
:
795 case QEMU_IFLA_PROMISCUITY
:
796 case QEMU_IFLA_EXT_MASK
:
797 case QEMU_IFLA_LINK_NETNSID
:
798 case QEMU_IFLA_GROUP
:
799 case QEMU_IFLA_MASTER
:
800 case QEMU_IFLA_NUM_VF
:
801 case QEMU_IFLA_GSO_MAX_SEGS
:
802 case QEMU_IFLA_GSO_MAX_SIZE
:
803 case QEMU_IFLA_CARRIER_UP_COUNT
:
804 case QEMU_IFLA_CARRIER_DOWN_COUNT
:
805 case QEMU_IFLA_MIN_MTU
:
806 case QEMU_IFLA_MAX_MTU
:
807 u32
= RTA_DATA(rtattr
);
808 *u32
= tswap32(*u32
);
810 /* struct rtnl_link_stats */
811 case QEMU_IFLA_STATS
:
812 st
= RTA_DATA(rtattr
);
813 st
->rx_packets
= tswap32(st
->rx_packets
);
814 st
->tx_packets
= tswap32(st
->tx_packets
);
815 st
->rx_bytes
= tswap32(st
->rx_bytes
);
816 st
->tx_bytes
= tswap32(st
->tx_bytes
);
817 st
->rx_errors
= tswap32(st
->rx_errors
);
818 st
->tx_errors
= tswap32(st
->tx_errors
);
819 st
->rx_dropped
= tswap32(st
->rx_dropped
);
820 st
->tx_dropped
= tswap32(st
->tx_dropped
);
821 st
->multicast
= tswap32(st
->multicast
);
822 st
->collisions
= tswap32(st
->collisions
);
824 /* detailed rx_errors: */
825 st
->rx_length_errors
= tswap32(st
->rx_length_errors
);
826 st
->rx_over_errors
= tswap32(st
->rx_over_errors
);
827 st
->rx_crc_errors
= tswap32(st
->rx_crc_errors
);
828 st
->rx_frame_errors
= tswap32(st
->rx_frame_errors
);
829 st
->rx_fifo_errors
= tswap32(st
->rx_fifo_errors
);
830 st
->rx_missed_errors
= tswap32(st
->rx_missed_errors
);
832 /* detailed tx_errors */
833 st
->tx_aborted_errors
= tswap32(st
->tx_aborted_errors
);
834 st
->tx_carrier_errors
= tswap32(st
->tx_carrier_errors
);
835 st
->tx_fifo_errors
= tswap32(st
->tx_fifo_errors
);
836 st
->tx_heartbeat_errors
= tswap32(st
->tx_heartbeat_errors
);
837 st
->tx_window_errors
= tswap32(st
->tx_window_errors
);
840 st
->rx_compressed
= tswap32(st
->rx_compressed
);
841 st
->tx_compressed
= tswap32(st
->tx_compressed
);
843 /* struct rtnl_link_stats64 */
844 case QEMU_IFLA_STATS64
:
845 st64
= RTA_DATA(rtattr
);
846 st64
->rx_packets
= tswap64(st64
->rx_packets
);
847 st64
->tx_packets
= tswap64(st64
->tx_packets
);
848 st64
->rx_bytes
= tswap64(st64
->rx_bytes
);
849 st64
->tx_bytes
= tswap64(st64
->tx_bytes
);
850 st64
->rx_errors
= tswap64(st64
->rx_errors
);
851 st64
->tx_errors
= tswap64(st64
->tx_errors
);
852 st64
->rx_dropped
= tswap64(st64
->rx_dropped
);
853 st64
->tx_dropped
= tswap64(st64
->tx_dropped
);
854 st64
->multicast
= tswap64(st64
->multicast
);
855 st64
->collisions
= tswap64(st64
->collisions
);
857 /* detailed rx_errors: */
858 st64
->rx_length_errors
= tswap64(st64
->rx_length_errors
);
859 st64
->rx_over_errors
= tswap64(st64
->rx_over_errors
);
860 st64
->rx_crc_errors
= tswap64(st64
->rx_crc_errors
);
861 st64
->rx_frame_errors
= tswap64(st64
->rx_frame_errors
);
862 st64
->rx_fifo_errors
= tswap64(st64
->rx_fifo_errors
);
863 st64
->rx_missed_errors
= tswap64(st64
->rx_missed_errors
);
865 /* detailed tx_errors */
866 st64
->tx_aborted_errors
= tswap64(st64
->tx_aborted_errors
);
867 st64
->tx_carrier_errors
= tswap64(st64
->tx_carrier_errors
);
868 st64
->tx_fifo_errors
= tswap64(st64
->tx_fifo_errors
);
869 st64
->tx_heartbeat_errors
= tswap64(st64
->tx_heartbeat_errors
);
870 st64
->tx_window_errors
= tswap64(st64
->tx_window_errors
);
873 st64
->rx_compressed
= tswap64(st64
->rx_compressed
);
874 st64
->tx_compressed
= tswap64(st64
->tx_compressed
);
876 /* struct rtnl_link_ifmap */
878 map
= RTA_DATA(rtattr
);
879 map
->mem_start
= tswap64(map
->mem_start
);
880 map
->mem_end
= tswap64(map
->mem_end
);
881 map
->base_addr
= tswap64(map
->base_addr
);
882 map
->irq
= tswap16(map
->irq
);
885 case QEMU_IFLA_LINKINFO
:
886 memset(&li_context
, 0, sizeof(li_context
));
887 return host_to_target_for_each_nlattr(RTA_DATA(rtattr
), rtattr
->rta_len
,
889 host_to_target_data_linkinfo_nlattr
);
890 case QEMU_IFLA_AF_SPEC
:
891 return host_to_target_for_each_nlattr(RTA_DATA(rtattr
), rtattr
->rta_len
,
893 host_to_target_data_spec_nlattr
);
895 return host_to_target_for_each_nlattr(RTA_DATA(rtattr
), rtattr
->rta_len
,
897 host_to_target_data_xdp_nlattr
);
899 gemu_log("Unknown host QEMU_IFLA type: %d\n", rtattr
->rta_type
);
905 static abi_long
host_to_target_data_addr_rtattr(struct rtattr
*rtattr
)
908 struct ifa_cacheinfo
*ci
;
910 switch (rtattr
->rta_type
) {
911 /* binary: depends on family type */
921 u32
= RTA_DATA(rtattr
);
922 *u32
= tswap32(*u32
);
924 /* struct ifa_cacheinfo */
926 ci
= RTA_DATA(rtattr
);
927 ci
->ifa_prefered
= tswap32(ci
->ifa_prefered
);
928 ci
->ifa_valid
= tswap32(ci
->ifa_valid
);
929 ci
->cstamp
= tswap32(ci
->cstamp
);
930 ci
->tstamp
= tswap32(ci
->tstamp
);
933 gemu_log("Unknown host IFA type: %d\n", rtattr
->rta_type
);
939 static abi_long
host_to_target_data_route_rtattr(struct rtattr
*rtattr
)
942 struct rta_cacheinfo
*ci
;
944 switch (rtattr
->rta_type
) {
945 /* binary: depends on family type */
946 case QEMU_RTA_GATEWAY
:
948 case QEMU_RTA_PREFSRC
:
954 case QEMU_RTA_PRIORITY
:
957 u32
= RTA_DATA(rtattr
);
958 *u32
= tswap32(*u32
);
960 /* struct rta_cacheinfo */
961 case QEMU_RTA_CACHEINFO
:
962 ci
= RTA_DATA(rtattr
);
963 ci
->rta_clntref
= tswap32(ci
->rta_clntref
);
964 ci
->rta_lastuse
= tswap32(ci
->rta_lastuse
);
965 ci
->rta_expires
= tswap32(ci
->rta_expires
);
966 ci
->rta_error
= tswap32(ci
->rta_error
);
967 ci
->rta_used
= tswap32(ci
->rta_used
);
968 #if defined(RTNETLINK_HAVE_PEERINFO)
969 ci
->rta_id
= tswap32(ci
->rta_id
);
970 ci
->rta_ts
= tswap32(ci
->rta_ts
);
971 ci
->rta_tsage
= tswap32(ci
->rta_tsage
);
975 gemu_log("Unknown host RTA type: %d\n", rtattr
->rta_type
);
981 static abi_long
host_to_target_link_rtattr(struct rtattr
*rtattr
,
984 return host_to_target_for_each_rtattr(rtattr
, rtattr_len
,
985 host_to_target_data_link_rtattr
);
988 static abi_long
host_to_target_addr_rtattr(struct rtattr
*rtattr
,
991 return host_to_target_for_each_rtattr(rtattr
, rtattr_len
,
992 host_to_target_data_addr_rtattr
);
995 static abi_long
host_to_target_route_rtattr(struct rtattr
*rtattr
,
998 return host_to_target_for_each_rtattr(rtattr
, rtattr_len
,
999 host_to_target_data_route_rtattr
);
1002 static abi_long
host_to_target_data_route(struct nlmsghdr
*nlh
)
1005 struct ifinfomsg
*ifi
;
1006 struct ifaddrmsg
*ifa
;
1009 nlmsg_len
= nlh
->nlmsg_len
;
1010 switch (nlh
->nlmsg_type
) {
1014 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*ifi
))) {
1015 ifi
= NLMSG_DATA(nlh
);
1016 ifi
->ifi_type
= tswap16(ifi
->ifi_type
);
1017 ifi
->ifi_index
= tswap32(ifi
->ifi_index
);
1018 ifi
->ifi_flags
= tswap32(ifi
->ifi_flags
);
1019 ifi
->ifi_change
= tswap32(ifi
->ifi_change
);
1020 host_to_target_link_rtattr(IFLA_RTA(ifi
),
1021 nlmsg_len
- NLMSG_LENGTH(sizeof(*ifi
)));
1027 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*ifa
))) {
1028 ifa
= NLMSG_DATA(nlh
);
1029 ifa
->ifa_index
= tswap32(ifa
->ifa_index
);
1030 host_to_target_addr_rtattr(IFA_RTA(ifa
),
1031 nlmsg_len
- NLMSG_LENGTH(sizeof(*ifa
)));
1037 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*rtm
))) {
1038 rtm
= NLMSG_DATA(nlh
);
1039 rtm
->rtm_flags
= tswap32(rtm
->rtm_flags
);
1040 host_to_target_route_rtattr(RTM_RTA(rtm
),
1041 nlmsg_len
- NLMSG_LENGTH(sizeof(*rtm
)));
1045 return -TARGET_EINVAL
;
1050 static inline abi_long
host_to_target_nlmsg_route(struct nlmsghdr
*nlh
,
1053 return host_to_target_for_each_nlmsg(nlh
, len
, host_to_target_data_route
);
1056 static abi_long
target_to_host_for_each_rtattr(struct rtattr
*rtattr
,
1058 abi_long (*target_to_host_rtattr
)
1063 while (len
>= sizeof(struct rtattr
)) {
1064 if (tswap16(rtattr
->rta_len
) < sizeof(struct rtattr
) ||
1065 tswap16(rtattr
->rta_len
) > len
) {
1068 rtattr
->rta_len
= tswap16(rtattr
->rta_len
);
1069 rtattr
->rta_type
= tswap16(rtattr
->rta_type
);
1070 ret
= target_to_host_rtattr(rtattr
);
1074 len
-= RTA_ALIGN(rtattr
->rta_len
);
1075 rtattr
= (struct rtattr
*)(((char *)rtattr
) +
1076 RTA_ALIGN(rtattr
->rta_len
));
1081 static abi_long
target_to_host_data_link_rtattr(struct rtattr
*rtattr
)
1083 switch (rtattr
->rta_type
) {
1085 gemu_log("Unknown target QEMU_IFLA type: %d\n", rtattr
->rta_type
);
1091 static abi_long
target_to_host_data_addr_rtattr(struct rtattr
*rtattr
)
1093 switch (rtattr
->rta_type
) {
1094 /* binary: depends on family type */
1099 gemu_log("Unknown target IFA type: %d\n", rtattr
->rta_type
);
1105 static abi_long
target_to_host_data_route_rtattr(struct rtattr
*rtattr
)
1108 switch (rtattr
->rta_type
) {
1109 /* binary: depends on family type */
1112 case QEMU_RTA_GATEWAY
:
1115 case QEMU_RTA_PRIORITY
:
1117 u32
= RTA_DATA(rtattr
);
1118 *u32
= tswap32(*u32
);
1121 gemu_log("Unknown target RTA type: %d\n", rtattr
->rta_type
);
1127 static void target_to_host_link_rtattr(struct rtattr
*rtattr
,
1128 uint32_t rtattr_len
)
1130 target_to_host_for_each_rtattr(rtattr
, rtattr_len
,
1131 target_to_host_data_link_rtattr
);
1134 static void target_to_host_addr_rtattr(struct rtattr
*rtattr
,
1135 uint32_t rtattr_len
)
1137 target_to_host_for_each_rtattr(rtattr
, rtattr_len
,
1138 target_to_host_data_addr_rtattr
);
1141 static void target_to_host_route_rtattr(struct rtattr
*rtattr
,
1142 uint32_t rtattr_len
)
1144 target_to_host_for_each_rtattr(rtattr
, rtattr_len
,
1145 target_to_host_data_route_rtattr
);
1148 static abi_long
target_to_host_data_route(struct nlmsghdr
*nlh
)
1150 struct ifinfomsg
*ifi
;
1151 struct ifaddrmsg
*ifa
;
1154 switch (nlh
->nlmsg_type
) {
1159 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*ifi
))) {
1160 ifi
= NLMSG_DATA(nlh
);
1161 ifi
->ifi_type
= tswap16(ifi
->ifi_type
);
1162 ifi
->ifi_index
= tswap32(ifi
->ifi_index
);
1163 ifi
->ifi_flags
= tswap32(ifi
->ifi_flags
);
1164 ifi
->ifi_change
= tswap32(ifi
->ifi_change
);
1165 target_to_host_link_rtattr(IFLA_RTA(ifi
), nlh
->nlmsg_len
-
1166 NLMSG_LENGTH(sizeof(*ifi
)));
1172 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*ifa
))) {
1173 ifa
= NLMSG_DATA(nlh
);
1174 ifa
->ifa_index
= tswap32(ifa
->ifa_index
);
1175 target_to_host_addr_rtattr(IFA_RTA(ifa
), nlh
->nlmsg_len
-
1176 NLMSG_LENGTH(sizeof(*ifa
)));
1183 if (nlh
->nlmsg_len
>= NLMSG_LENGTH(sizeof(*rtm
))) {
1184 rtm
= NLMSG_DATA(nlh
);
1185 rtm
->rtm_flags
= tswap32(rtm
->rtm_flags
);
1186 target_to_host_route_rtattr(RTM_RTA(rtm
), nlh
->nlmsg_len
-
1187 NLMSG_LENGTH(sizeof(*rtm
)));
1191 return -TARGET_EOPNOTSUPP
;
1196 static abi_long
target_to_host_nlmsg_route(struct nlmsghdr
*nlh
, size_t len
)
1198 return target_to_host_for_each_nlmsg(nlh
, len
, target_to_host_data_route
);
1200 #endif /* CONFIG_RTNETLINK */
1202 static abi_long
host_to_target_data_audit(struct nlmsghdr
*nlh
)
1204 switch (nlh
->nlmsg_type
) {
1206 gemu_log("Unknown host audit message type %d\n",
1208 return -TARGET_EINVAL
;
1213 static inline abi_long
host_to_target_nlmsg_audit(struct nlmsghdr
*nlh
,
1216 return host_to_target_for_each_nlmsg(nlh
, len
, host_to_target_data_audit
);
1219 static abi_long
target_to_host_data_audit(struct nlmsghdr
*nlh
)
1221 switch (nlh
->nlmsg_type
) {
1223 case AUDIT_FIRST_USER_MSG
... AUDIT_LAST_USER_MSG
:
1224 case AUDIT_FIRST_USER_MSG2
... AUDIT_LAST_USER_MSG2
:
1227 gemu_log("Unknown target audit message type %d\n",
1229 return -TARGET_EINVAL
;
1235 static abi_long
target_to_host_nlmsg_audit(struct nlmsghdr
*nlh
, size_t len
)
1237 return target_to_host_for_each_nlmsg(nlh
, len
, target_to_host_data_audit
);
1240 static abi_long
packet_target_to_host_sockaddr(void *host_addr
,
1241 abi_ulong target_addr
,
1244 struct sockaddr
*addr
= host_addr
;
1245 struct target_sockaddr
*target_saddr
;
1247 target_saddr
= lock_user(VERIFY_READ
, target_addr
, len
, 1);
1248 if (!target_saddr
) {
1249 return -TARGET_EFAULT
;
1252 memcpy(addr
, target_saddr
, len
);
1253 addr
->sa_family
= tswap16(target_saddr
->sa_family
);
1254 /* spkt_protocol is big-endian */
1256 unlock_user(target_saddr
, target_addr
, 0);
1260 TargetFdTrans target_packet_trans
= {
1261 .target_to_host_addr
= packet_target_to_host_sockaddr
,
1264 #ifdef CONFIG_RTNETLINK
1265 static abi_long
netlink_route_target_to_host(void *buf
, size_t len
)
1269 ret
= target_to_host_nlmsg_route(buf
, len
);
1277 static abi_long
netlink_route_host_to_target(void *buf
, size_t len
)
1281 ret
= host_to_target_nlmsg_route(buf
, len
);
1289 TargetFdTrans target_netlink_route_trans
= {
1290 .target_to_host_data
= netlink_route_target_to_host
,
1291 .host_to_target_data
= netlink_route_host_to_target
,
1293 #endif /* CONFIG_RTNETLINK */
1295 static abi_long
netlink_audit_target_to_host(void *buf
, size_t len
)
1299 ret
= target_to_host_nlmsg_audit(buf
, len
);
1307 static abi_long
netlink_audit_host_to_target(void *buf
, size_t len
)
1311 ret
= host_to_target_nlmsg_audit(buf
, len
);
1319 TargetFdTrans target_netlink_audit_trans
= {
1320 .target_to_host_data
= netlink_audit_target_to_host
,
1321 .host_to_target_data
= netlink_audit_host_to_target
,
1324 /* signalfd siginfo conversion */
1327 host_to_target_signalfd_siginfo(struct signalfd_siginfo
*tinfo
,
1328 const struct signalfd_siginfo
*info
)
1330 int sig
= host_to_target_signal(info
->ssi_signo
);
1332 /* linux/signalfd.h defines a ssi_addr_lsb
1333 * not defined in sys/signalfd.h but used by some kernels
1336 #ifdef BUS_MCEERR_AO
1337 if (tinfo
->ssi_signo
== SIGBUS
&&
1338 (tinfo
->ssi_code
== BUS_MCEERR_AR
||
1339 tinfo
->ssi_code
== BUS_MCEERR_AO
)) {
1340 uint16_t *ssi_addr_lsb
= (uint16_t *)(&info
->ssi_addr
+ 1);
1341 uint16_t *tssi_addr_lsb
= (uint16_t *)(&tinfo
->ssi_addr
+ 1);
1342 *tssi_addr_lsb
= tswap16(*ssi_addr_lsb
);
1346 tinfo
->ssi_signo
= tswap32(sig
);
1347 tinfo
->ssi_errno
= tswap32(tinfo
->ssi_errno
);
1348 tinfo
->ssi_code
= tswap32(info
->ssi_code
);
1349 tinfo
->ssi_pid
= tswap32(info
->ssi_pid
);
1350 tinfo
->ssi_uid
= tswap32(info
->ssi_uid
);
1351 tinfo
->ssi_fd
= tswap32(info
->ssi_fd
);
1352 tinfo
->ssi_tid
= tswap32(info
->ssi_tid
);
1353 tinfo
->ssi_band
= tswap32(info
->ssi_band
);
1354 tinfo
->ssi_overrun
= tswap32(info
->ssi_overrun
);
1355 tinfo
->ssi_trapno
= tswap32(info
->ssi_trapno
);
1356 tinfo
->ssi_status
= tswap32(info
->ssi_status
);
1357 tinfo
->ssi_int
= tswap32(info
->ssi_int
);
1358 tinfo
->ssi_ptr
= tswap64(info
->ssi_ptr
);
1359 tinfo
->ssi_utime
= tswap64(info
->ssi_utime
);
1360 tinfo
->ssi_stime
= tswap64(info
->ssi_stime
);
1361 tinfo
->ssi_addr
= tswap64(info
->ssi_addr
);
1364 static abi_long
host_to_target_data_signalfd(void *buf
, size_t len
)
1368 for (i
= 0; i
< len
; i
+= sizeof(struct signalfd_siginfo
)) {
1369 host_to_target_signalfd_siginfo(buf
+ i
, buf
+ i
);
1375 TargetFdTrans target_signalfd_trans
= {
1376 .host_to_target_data
= host_to_target_data_signalfd
,
1379 static abi_long
swap_data_eventfd(void *buf
, size_t len
)
1381 uint64_t *counter
= buf
;
1384 if (len
< sizeof(uint64_t)) {
1388 for (i
= 0; i
< len
; i
+= sizeof(uint64_t)) {
1389 *counter
= tswap64(*counter
);
1396 TargetFdTrans target_eventfd_trans
= {
1397 .host_to_target_data
= swap_data_eventfd
,
1398 .target_to_host_data
= swap_data_eventfd
,
1401 #if (defined(TARGET_NR_inotify_init) && defined(__NR_inotify_init)) || \
1402 (defined(CONFIG_INOTIFY1) && defined(TARGET_NR_inotify_init1) && \
1403 defined(__NR_inotify_init1))
1404 static abi_long
host_to_target_data_inotify(void *buf
, size_t len
)
1406 struct inotify_event
*ev
;
1410 for (i
= 0; i
< len
; i
+= sizeof(struct inotify_event
) + name_len
) {
1411 ev
= (struct inotify_event
*)((char *)buf
+ i
);
1414 ev
->wd
= tswap32(ev
->wd
);
1415 ev
->mask
= tswap32(ev
->mask
);
1416 ev
->cookie
= tswap32(ev
->cookie
);
1417 ev
->len
= tswap32(name_len
);
1423 TargetFdTrans target_inotify_trans
= {
1424 .host_to_target_data
= host_to_target_data_inotify
,